arbitrary length input



Fabrizio Caruso wrote on 07/26/2006 11:49:46 AM:

> Hi,
> 
> how can I define a function, say lcm,
> with an input of arbitrary length, e.g.:
> lcd(2,3), lcm(4,5,6,6)?

If you need a lcm function, the lcm function in 
/share/simplification/functs.mac
might work for you:

(%i1) ? lcm;
 - Function: lcm (<expr_1>, ..., <expr_n>)
     Returns the least common multiple of its arguments.  The arguments
     may be general expressions as well as integers.
     `load ("functs")' loads this function.
(%o1) false
(%i2) load(functs)$
(%i3) lcm(4,5,6,6);
(%o3) 60

If not, here is an example of how to define a function that takes an
arbitrary number of arguments:

(%i4) avg([x]) := apply("+",x) / length(x)$
(%i5) avg(a,b);
(%o5) (b+a)/2
(%i6) avg(a,b,c);
(%o6) (c+b+a)/3

Barton