matchdeclare and defrule not working as in documentation.
Subject: matchdeclare and defrule not working as in documentation.
From: Robert Dodier
Date: Mon, 11 Jul 2011 14:06:53 -0600
Well, I see that 8*2^n simplifies to 2^(n + 3) (dunno when that
was implemented). That changes the expression so 8*%pi doesn't
appear. Try changing 8 to 7 -- I think you'll get the
expected result.
In general matching is a little tricky because Maxima
can simplify expressions before passing them to the match
function. This is especially true with "*" and its friends
"/" and "^".
best,
Robert Dodier
On 7/11/11, Bernard Hurley <bernard at marcade.biz> wrote:
> Hi all,
>
> In the documentation for matchdeclare we read:
>
> When matching arguments of + and *, if all match predicates are mutually
> exclusive, the match result is insensitive to ordering, as one match
> predicate cannot accept terms matched by another.
>
> (%i1) matchdeclare (aa, atom, bb, lambda ([x], not atom(x)));
> (%o1) done
> (%i2) defrule (r1, aa + bb, ["all atoms" = aa, "all nonatoms" =
> bb]);
> bb + aa partitions `sum'
> (%o2) r1 : bb + aa -> [all atoms = aa, all nonatoms = bb]
> (%i3) r1 (8 + a*b + %pi + sin(x) - c + 2^n);
> n
> (%o3) [all atoms = %pi + 8, all nonatoms = sin(x) + 2 - c + a b]
> (%i4) defrule (r2, aa * bb, ["all atoms" = aa, "all nonatoms" =
> bb]);
> bb aa partitions `product'
> (%o4) r2 : aa bb -> [all atoms = aa, all nonatoms = bb]
> (%i5) r2 (8 * (a + b) * %pi * sin(x) / c * 2^n);
> n
> (b + a) 2 sin(x)
> (%o5) [all atoms = 8 %pi, all nonatoms = -----------------]
> c
>
> However when I try this I get:
>
> n + 1
> (b + a) 2 sin(x)
> (%o5) [all atoms = %pi, all nonatoms = ---------------------]
> c
>
> The output indicated in the documentation is what I would expect and
> presumably it is what happened at one time. The problem seems to be with
> defrule as atom(8) and atom(2^n) evaluate as "true" and "false"
> respectively.
>
> regards
>
> Bernard
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>