matchdeclare and defrule not working as in documentation.
Subject: matchdeclare and defrule not working as in documentation.
From: Bernard Hurley
Date: Mon, 11 Jul 2011 12:58:55 +0100
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