%mathpiper,def="Lcm"

/* Least common multiple */
5  # Lcm(a_IsInteger,b_IsInteger) <-- Quotient(a*b,Gcd(a,b));

10 # Lcm(list_IsList)_(Length(list)>2) <--
[
	Local(first);
	first:=Lcm(list[1],list[2]);
	Lcm(first:Rest(Rest(list)));
];

10 # Lcm(list_IsList)_(Length(list)=2) <-- Lcm(list[1],list[2]);

// We handle lists with just one element to avoid special-casing 
// all the calls. 
10 # Lcm(list_IsList)_(Length(list)=1) <-- Lcm(list[1],1);

%/mathpiper



%mathpiper_docs,name="Lcm",categories="User Functions;Numbers (Operations)"
*CMD Lcm --- least common multiple
*STD
*CALL
	Lcm(n,m)
	Lcm(list)

*PARMS

{n}, {m} -- integers or univariate polynomials
{list}	 -- list of integers

*DESC

This command returns the least common multiple of "n" and "m" or all of
the integers in the list {list}.
The least common multiple of two numbers "n" and "m" is the lowest
number which is an integer multiple of both "n" and "m".
It is calculated with the formula
$$Lcm(n,m) = Quotient(n*m,Gcd(n,m))$$.

This means it also works on polynomials, since {Div}, {Gcd} and multiplication are also defined for
them.

*E.G.

In> Lcm(60,24)
Result: 120;
In> Lcm({3,5,7,9})
Result: 315;


*SEE Gcd

%/mathpiper_docs
