# [Maxima] Predictable pattern matching?

martin ms_usenet at gmx.de
Mon Dec 22 03:09:39 CST 2008

```Hello,
I try to recocnize a certain derivative and it's coefficient (for
testing the pattern matching, just return what whas found in the
function 'found'):

kill(all)\$

matchdeclare(
sym1_pat, symbolp,
int1_pat, integerp,
all1_pat, all
)\$

expr1: 25 * a * 'diff(f(x),x)\$
expr2: 25 * a * 'diff(f(x),x) * 'diff(g(x),x)\$

defrule(
findrule,
all1_pat * 'diff(f(x), sym1_pat, int1_pat),
block([var1,var2],
var1: all1_pat,
var2: [f(x), int1_pat, sym1_pat],
found(var1, var2)
)
)\$

apply1(expr1, findrule);
>>> found(25*a,[f(x),1,x])

apply1(expr2, findrule);
>>> 25*found(1,[f(x),1,x])*a*('diff(g(x),x,1))

In the first case, the whole coefficient was found to match all1_pat, in
the second case, only a 1 was matched.

How could I convince Maxima to match the whole coefficient in any case,
to be able to operate further on them?

Thanks and regards,
Martin

( I was using:
wxMaxima 0.7.6 http://wxmaxima.sourceforge.net
Maxima 5.16.3 http://maxima.sourceforge.net
Using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (aka GCL)
)

```