commands → lcm

lcm(A,B)
lcm(A,B,P)

The lcm command computes the least common multiple of A and B, which can be integers or polynomials. An optional third argument specifies the modulus for polynomial computations modulo a prime.

Examples

# integers
lcm(10,15);
	30

# polynomials
lcm(x^2-1,x^3-1);
	-1-x+x^3+x^4

# polynomials mod p
lcm(x^2-1,x^3-1,11);
	10+10*x+x^3+x^4

Algorithm

The algorithm for integers and polynomials computes the product A*B and divides by their gcd.

References

Gullberg, Jan. Mathematics: From the Birth of Numbers. Norton, 1996.