Subject: Pattern of (aa+nn*bb), matchdeclare, defmatch
From: Richard Fateman
Date: Tue, 23 Nov 2010 20:12:57 -0800
On 11/23/2010 6:36 PM, Rhys Pratt wrote:
> On Tue, 23 Nov 2010 07:59:54 -0800
> Richard Fateman<fateman at cs.berkeley.edu> wrote:
>
>> Maybe you should describe your pattern better.
>
> Thanks for the reminder. I want to design such a pattern, a non-numeric component (or a symbol) plus another form "constant * symbol ". In other words, I want to extract a, b, n in the form of "a+n*b" which contains constant n.
>
> (%i1) matchdeclare([aa, bb], all, nn, numberp);
> (%o1) done
>
> (%i2) defmatch(m1, aa+nn*bb);
> defmatch: nn*bb will be matched uniquely since sub-parts would otherwise be ambigious.
> (%o2) m1
>
> I don't know how to define the aa and bb to eliminate the error message in step %i2
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
as you have written it, given an expression x+4*y,
one perfectly correct way of matching m1 is aa=x+4*y, bb=0, nn=0.
another way (which is related to the message, not an error message but
a factual statement),
is to insist that there be a "*" in the expression , therefore NOT
matching x+y with nn=1.
I think you should start your processing by making a list of all
symbols, s1, s2, ... sn.
then look for aa*s1+bb, and within bb, look for cc*s2+dd, etc.
you really need only one pattern defmatch(LinearInS,aa*s+bb,s);
RJF