xrange SciMax Toolbox xthru

SciMax Toolbox >> xreduce

xreduce

Maxima Function

Calling Sequence

xreduce (F, s)
xreduce(F,s,s_0)

Description

Extends the function F to an n-ary function by composition, or, if F is already n-ary, applies F to s. When F is not n-ary, xreduce is the same as lreduce. The argument s is a list.

Functions known to be n-ary include addition +, multiplication *, and, or, max, min, and append. Functions may also be declared n-ary by declare(F, nary). For these functions, xreduce is expected to be faster than either rreduce or lreduce.

When the optional argument s_0 is present, the result is equivalent to xreduce(s, cons(s_0, s)).

Floating point addition is not exactly associative; be that as it may, xreduce applies Maxima's n-ary addition when s contains floating point numbers.

Examples:

xreduce applied to a function known to be n-ary. F is called once, with all arguments.

(%i1) declare (F, nary);
(%o1)                         done
(%i2) F ([L]) := L;
(%o2)                      F([L]) := L
(%i3) xreduce (F, [a, b, c, d, e]);
(%o3)         [[[[[("[", simp), a], b], c], d], e]

xreduce applied to a function not known to be n-ary. G is called several times, with two arguments each time.

(%i1) G ([L]) := L;
(%o1)                      G([L]) := L
(%i2) xreduce (G, [a, b, c, d, e]);
(%o2)         [[[[[("[", simp), a], b], c], d], e]
(%i3) lreduce (G, [a, b, c, d, e]);
(%o3)                 [[[[a, b], c], d], e]
xrange SciMax Toolbox xthru