tellsimpafter strangeness with operands that satisfy the same predicates
Subject: tellsimpafter strangeness with operands that satisfy the same predicates
From: Robert Dodier
Date: Sat, 5 Mar 2005 08:08:50 -0800 (PST)
Hello,
With this preamble --
atomp (x) := block ([r: atom(x)],
display (["atomp", x, r]), r);
nonatomp (x) := block ([r: not atom(x)],
display (["nonatomp", x, r]), r);
matchdeclare ([a, b], atomp, [x, y], nonatomp);
simp: false;
tellsimpafter (a + x, add_atom_nonatom(a, x));
tellsimpafter (a + b, add_2atoms (a, b));
tellsimpafter (x + y, add_2nonatoms (x, y));
simp: true;
I've observed the following:
(%i9) cos(pp) + qq;
[nonatomp, x, r] = [nonatomp, cos(pp), true]
[nonatomp, x, r] = [nonatomp, qq, false]
[atomp, x, r] = [atomp, qq, true]
(%o9) add_atom_nonatom(qq, cos(pp))
Perfect! Now let's try again:
(%i10) pp + qq;
[nonatomp, x, r] = [nonatomp, pp, false]
[nonatomp, x, r] = [nonatomp, qq, false]
[nonatomp, x, r] = [nonatomp, 0, false]
[atomp, x, r] = [atomp, pp, true]
[atomp, x, r] = [atomp, qq, true]
[atomp, x, r] = [atomp, 0, true]
(%o10) add_2atoms(0, qq + pp)
Oops! Maxima seems to have correctly identified pp and qq
as atoms, but then it forgot about that and started working
with 0 and pp + qq instead. The result can't be right since
pp + qq is not an atom.
In fact, if test in atomp is changed to atom(x) and x#0,
then pp + qq doesn't simplify because 0 fails the revised test:
(%i12) atomp (x) := block ([r: atom(x) and x#0],
display (["atomp", x, r]), r);
(%o12) atomp(x) := block([r : atom(x) and x # 0],
display(["atomp", x, r]), r)
(%i13) pp + qq;
[nonatomp, x, r] = [nonatomp, pp, false]
[nonatomp, x, r] = [nonatomp, qq, false]
[nonatomp, x, r] = [nonatomp, 0, false]
[atomp, x, r] = [atomp, pp, true]
[atomp, x, r] = [atomp, qq, true]
[atomp, x, r] = [atomp, 0, false]
[nonatomp, x, r] = [nonatomp, pp, false]
[nonatomp, x, r] = [nonatomp, qq, false]
[nonatomp, x, r] = [nonatomp, 0, false]
(%o13) qq + pp
This strangeness seems like a bug to me. The key seems to be
that the operands of "+" both satisfy the same predicate --
if they satisfy different predicates then tellsimpafter seems
to do the right thing.
Various permutations of this situation show the same effect.
In particular the problem is not an interaction between rules:
if there is only one rule and the operands satisfy the same
predicate, the bug is triggered.
Incidentally I observed this when working with base 60 objects:
I can get tellsimpafter to simplify (base 60) + (ordinary integer)
but not (base 60) + (base 60).
I searched the mailing list archive and although tellsimpafter
is mentioned every now and then, I didn't find a description
of this problem. I didn't find anything in the bug reports either.
Thanks a lot for any light you can shed on this.
Robert Dodier
__________________________________
Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web
http://birthday.yahoo.com/netrospective/