%mathpiper,def="Minimum"

/*  this is disabled because some functions seem to implicitly define Min / Max with a different number of args, 
and then MathPiper is confused if it hasn't loaded all the Function() declarations beforehand.
FIXME
/// Min, Max with many arguments
*/

//Retract("Minimum", 1);
//Retract("Minimum", 2);
//Retract("Minimum", 3);

//Function() Minimum(list);

//Function() Minimum(l1, l2)

Function() Minimum(l1, l2, l3, ...);

10 # Minimum(_l1, _l2, l3_IsList) <-- Minimum(Concat({l1, l2}, l3));
20 # Minimum(_l1, _l2, _l3) <-- Minimum({l1, l2, l3});

10 # Minimum(l1_IsList,l2_IsList) <-- Map("Minimum",{l1,l2});

20 # Minimum(l1_IsRationalOrNumber,l2_IsRationalOrNumber) <-- If(l1<l2,l1,l2);

30 # Minimum(l1_IsConstant,l2_IsConstant) <-- If(N(Eval(l1-l2))<0,l1,l2);

//Min on an empty list.
10 # Minimum({}) <-- Undefined;

20 # Minimum(list_IsList) <--
[
  Local(result);
  result:= list[1];
  ForEach(item,Rest(list)) result:=Minimum(result,item);
  result;
];

30 # Minimum(_x) <-- x;

%/mathpiper



%mathpiper_docs,name="Minimum",categories="User Functions;Numbers (Operations)"
*CMD Minimum --- minimum of a number of values
*STD
*CALL
	Minimum(x,y)
	Minimum(list)

*PARMS

{x}, {y} -- pair of values to determine the minimum of

{list} -- list of values from which the minimum is sought

*DESC

This function returns the minimum value of its argument(s). If the
first calling sequence is used, the smaller of "x" and "y" is
returned. If one uses the second form, the smallest of the entries in
"list" is returned. In both cases, this function can only be used
with numerical values and not with symbolic arguments.

*E.G.

In> Minimum(2,3);
Result: 2;
In> Minimum({5,8,4});
Result: 4;

*SEE Maximum, Sum
%/mathpiper_docs