This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Generates an n-ary associative operator from a binary one

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


misc::genassop(binaryop, zeroelement)


misc::genassop(binaryop, zeroelement) generates an n-ary associative operator from the binary operator binaryop, where zeroelement is a neutral element for binaryop.

binaryop must be a function taking two arguments (no matter of what kind) and returning a valid argument to itself. It must satisfy the associative law binaryop(binaryop(a, b), c) = binaryop(a, binaryop(b, c)).

zeroelement is an object such that binaryop(a, zeroelement) = a holds for every a.

misc::genassop returns a procedure which returns zeroelement if it is called without arguments and the argument if it is called with one argument.


misc::genassop doesn't check whether binaryop is really associative and whether zeroelement is really a neutral element for binaryop.


Example 1

We know that _plus is an n-ary operator anyway, but let us assume that _plus was only a binary operator. We can create an own n-ary addition as follows:

myplus := misc::genassop(_plus, 0)

Now we make myplus add some values.

myplus(3, 4, 8), myplus(-5), myplus()

As mentioned in the “Details” section, myplus returns the argument if is called with exactly one argument, and it returns the zeroelement 0 if it is called without arguments.



A function


An object

Return Values

misc::genassop returns a procedure f. That procedure accepts an arbitrary number of arguments of the same kind binaryop does; it returns zeroelement if it is called without argument, and its only argument if it is called with one argument; its value on n arguments is inductively defined by f(x1, ..., xn)=f(binaryop(x1,x2), x3,...,xn).

See Also

MuPAD Functions

Was this topic helpful?