[Maxima] Non-exclusive pattern matching? e.g. distributiveness of a function, was: Predictable pattern matching?
ms_usenet at gmx.de
Tue Dec 23 14:36:19 CST 2008
Thank you for the detailed description, the definition of a predicate
function was new to me and should be useful. Actually, I think I have
to learn a lot more about Maxima - and maybe forget about Mathematica
while typing in Maxima?
How could I convert, for example, the following Mathematica function
definition, which uses patterns as arguments, into Maxima? It is a
definition of an integration function including (1) distribution of the
function over sums in the first argument, (2) extraction of constants
out of the integral sign, integration of (3) monomials and (4) the constant.
(1) int[a_ + b_, x] := int[a, x] + int[b, x]
(2) int[c_ f_, x] := c int[f, x] /; FreeQ[c, x]
(3) int[x^n_, x] := 1/(n + 1) * x^(n + 1) /; n != -1
(4) int[c_, x] := c x /; FreeQ[c, x]
which results in a useful function,
In:= int[y+const* x^2,x]
Out= (const x^3)/3+x y
(It is useful because sometimes it is faster than the built-in
For the distribution, the sum of any type of expression should be
allowed, so I think non-mutually exclusive patters may/should be used.
Trying to implement the property of distributiveness in Maxima, the
int(a+b, x) := int(a, x) + int(b, x);
yields an error, probably because the + is disturbing in the left hand
side of the definition.
I had no success trying to define the property with a rule,
[a1, a2], all,
int(a1, s1) + int(a2, s1)
a2+a1 partitions `sum'
(%i3) int(y + x^2, x);
Any hints would be appreciated, as well hints to documentation
(currently, I use the Maxima manual - thank you Robert - and MBE by
More information about the Maxima