-
MathType
-
Wiris Quizzes
-
Learning Lemur
-
CalcMe
-
MathPlayer
-
Store FAQ
-
VPAT for the electronic documentation
-
MathFlow
-
BF FAQ
-
Miscellaneous
Examples
Reading time: 4min👉Want to access to the examples within LearningLemur? Check the Quiz we have created with the examples we explain in this section.
Sum of two random irreducible fractions
Consider creating an exercise where students must calculate the sum of two randomly generated irreducible fractions.
# Generate the first fraction
# Choose a random numerator "a" from 1 to 9
a = random(1,9)
# Define set "B" of denominators that are coprime with "a"
B = { b with b in 2..9 where gcd(a,b)=1 }
# Choose random denominator "b" from set B
b = random(B)
# Generate the second fraction
# Choose another random numerator "c" from 1 to 9
c = random(1,9)
# Define set "D" of denominators coprime with "c", different from "b"
D = { d with d in 2..9 where gcd(c,d)=1 && d!=b }
# Choose random denominator "d" from set "D"
d = random(D)
# Calculate the sum of the two irreducible fractions
# The solution the students will calculate
sol = a/b + c/d
Solving linear equations with integer solutions
Consider creating a linear equation with random coefficients, ensuring that the solution is an integer.
# Generate a quadratic equation ax^2 + bx + c = 0
# with integer/rational solutions by ensuring discriminant is a perfect square.
# Generate random values for the coefficients
a = random([-10..10]/[0])
b = random([-10..10]/[0])
c = random([-10..10]/[0])
# Ensure the discriminant=b^2-4*a*c is a perfect square. If not, regenerate value "c".
while square?(b^2-4*a*c) == false
do c = random([-10..10]/[0])
end
# At this point, we have a valid quadratic equation with rational solutions
sol1 = (-b + sqrt(b^2-4*a*c)) / (2*a)
sol2 = (-b - sqrt(b^2-4*a*c)) / (2*a)
Tip: When you're using the same logic multiple times—like generating random numbers with the same rules—you can define a function to avoid repeating yourself. This makes your code easier to read and maintain.
r():= random([-10..10]/[0])
a=r()
b=r()
c=r()
Note: The answer box highlights the entry in red. This is because the system is designed to check for single mathematical formulas syntax, but here we are entering a list. This is normal for this type of question and will not impact the score.
Greatest common divisor of two random integers
Consider creating an exercise where students must calculate the GCD of two random integers.
# Randomly select target GCD between 2 and 10
target_gcd = random(2,10)
# Select two random integers that are coprime (so gcd=1)
repeat
m = random(2,10)
n = random([2,10]/[m])
until gcd(m, n) == 1
# Generate integers ensuring exact GCD is target_gcd
x = m * target_gcd
y = n * target_gcd
# Students should find the gcd of "x" and "y"
solution = target_gcd
Division with no remainder (exact division)
Consider creating an exercise where students divide two integers, ensuring that the result is an exact integer without remainder
# Select a random divisor from 2 to 12
div = random(2,12)
# Choose a random integer quotient between 2 and 10
quot = random(2,10)
# Compute dividend ensuring exact division
dividend = div * quot
# Students perform the division: dividend ÷ divisor
solution = quot
Generating a right-angled triangle with integer sides (Pythagorean Triple)
Create an exercise involving a right-angled triangle where side lengths are integers (a Pythagorean triple).
# Generate two random integers m and n for Euclid's formula (m > n)
n_val = random(1,5)
m_val = random(n_val + 1, n_val + 5) # Ensure m > n
# Ensure m and n are coprime and not both odd (to avoid common factors in a,b,c)
while gcd(m_val, n_val) != 1 || (odd?(m_val)=true && odd?(n_val)=true)
n_val = random(1,5)
m_val = random(n_val + 1, n_val + 5)
end
# Use Euclid's formula to generate a Pythagorean triple
a = m_val^2 - n_val^2
b = 2 * m_val * n_val
c = m_val^2 + n_val^2
# Optionally, scale the triple by a random factor k
k = random(1,3)
a = k*a
b = k*b
c = k*c
# Variables a and b are the legs, and c is the hypotenuse.
# These can be used for problems on Pythagorean theorem, trigonometry, etc.
This algorithm uses Euclid's formula for generating Pythagorean triples: a=m2−n2
, b=2mn
, c=m2+n2
.
- It generates two integersÂ
m_val
andÂn_val
withÂm_val > n_val
. - AÂ while loop ensures thatÂ
m_val
andÂn_val
are coprime (gcd(m_val, n_val) == 1
) and that they are not both odd (this condition, along with coprimality, ensures a primitive Pythagorean triple, which can then be scaled). If the conditions aren't met, newÂm_val
andÂn_val
are generated. - The sidesÂ
a
,Âb
, andÂc
are calculated. - Optionally, these sides are scaled by a random integerÂ
k
to produce non-primitive triples as well.
Â
Generating a 3x3 system of linear equations with a unique integer solution
Create a system of three linear equations in three variables that is guaranteed to have a unique solution, and all solution components are integers.
Â
# Define a function to generate random integers, excluding zero if needed
r() := random([-5..5]/[0])
# Generate a coefficient matrix A with a non-zero determinant
repeat
A = [ [r(), r(), r()],
[r(), r(), r()],
[r(), r(), r()] ]
until determinant(A) != 0
# Generate a unique integer solution vector 's'
sx = r() # Ensure solution components are non-zero for more interesting problems
sy = r()
sz = r()
solution_vect = [ sx, sy, sz ]
# Calculate the right-hand side vector 'b' such that A*solution_vector = b
b_vect = A * solution_vect
# Extract coefficients for the question
a11 = A subindex_operator(1,1)
a12 = A subindex_operator(1,2)
a13 = A subindex_operator(1,3)
a21 = A subindex_operator(2,1)
a22 = A subindex_operator(2,2)
a23 = A subindex_operator(2,3)
a31 = A subindex_operator(3,1)
a32 = A subindex_operator(3,2)
a33 = A subindex_operator(3,3)
b1 = b_vect subindex_operator(1)
b2 = b_vect subindex_operator(2)
b3 = b_vect subindex_operator(3)
# The system for students to solve is:
# a11*x + a12*y + a13*z = b1
# a21*x + a22*y + a23*z = b2
# a31*x + a32*y + a33*z = b3
# The solution is (sx, sy, sz)
Generating Linearly Independent/Dependent 3D Vectors
Create an exercise where students need to determine if a set of three 3D vectors is linearly independent or dependent, with a controlled outcome.
# Generate two linearly independent 3D vectors u and v
u1 = random([-5..5] / [0])
u2 = random([-5..5] / [0])
u3 = random([-5..5] / [0])
u = [u1, u2, u3]
v1 = random([-5..5] / [0])
v2 = random([-5..5] / [0])
v3 = random([-5..5] / [0])
# Ensure v is not a multiple of u
while vectorial_product(u,[v1,v2,v3])==[0,0,0]
v1 = random([-5..5] / [0])
v2 = random([-5..5] / [0])
v3 = random([-5..5] / [0])
end
v = [v1, v2, v3]
# Generate random non-zero scalars k1 and k2
k1 = random([-3..3] / [0])
k2 = random([-3..3] / [0])
# Create vector w as a linear combination of u and v, ensuring it's dependent
w = k1 * u + k2 * v
# The set {u, v, w} is now linearly dependent.
# To generate a linearly independent set, ensure the third vector is is NOT a linear combination. Let's create a new third vector t
t1 = random([-5..5] / [0])
t2 = random([-5..5] / [0])
t3 = random([-5..5] / [0])
#Ensure t is not linear dependent to u and v
while determinant([u,v,[t1,t2,t3]]) == 0
t1 = random([-5..5] / [0])
t2 = random([-5..5] / [0])
t3 = random([-5..5] / [0])
end
t = [t1, t2, t3]
# The set {t1, t2, t3} is now linearly independent.
Â
Â