Hello,
I am trying to understand how equality tests for lists,
matrices, & other composite objects works in Maxima, and
also how it should work.
I would expect that two lists, say, are equal if they have
the same number of elements and corresponding elements are equal.
I find that IS(EQUAL(a,b)) => TRUE if a and b are indeed
equivalent lists, but IS(EQUAL(a,b)) => UNKNOWN otherwise.
Maxima appears to be attempting to compare the differences
between pairs of elements to zero, but somewhere along the
line it goes off track.
IS(EQUAL(a,b)) calls LIKE along the way, so if the structures
match bit by bit then it yields TRUE as expected. Otherwise
the difference a - b is computed, and it appears that an
attempt is made, which always fails, to compare a - b to 0.
The relevant functions are in compar.lisp: MEVALP, MEQP,
SIGN1, DCOMPARE, and DCOMP. The difference is computed by
MEQP and passed along to SIGN1, which passes it to DCOMPARE,
and then to DCOMP, which calls DINTERNP, which clobbers the
difference. Then DCOMP returns $PNZ ("I don't know") and the
eventual result is UNKNOWN.
What is the purpose of DINTERNP ? I see DEQ appears to have
some code to walk down a list and compare elements, but it's
never called because the differences list is clobbered.
Any light you can shed on these issues will be very helpful.
regards,
Robert Dodier
PS. Transcript below was generated using Maxima 5.9.0 on cmucl.
------------------ begin transcript ------------------
(C1) :lisp (trace dcomp) (trace dinternp) (trace meqp) (trace sign1)
(trace dcompare) (trace compare) (trace mevalp)
(C1) prederror:false$
(C2) is(equal(88,55));
0: (MEVALP (($EQUAL) 88 55))
1: (MEQP 88 55)
2: (SIGN1 33)
2: SIGN1 returned $POS
1: MEQP returned NIL
0: MEVALP returned NIL
(D2) FALSE
(C3) is(equal([88],[88]));
0: (MEVALP (($EQUAL) (# 88) (# 88)))
1: (MEQP ((MLIST SIMP) 88) ((MLIST SIMP) 88))
1: MEQP returned T
0: MEVALP returned T
(D3) TRUE
(C4) is(equal([88],[55]));
0: (MEVALP (($EQUAL) (# 88) (# 55)))
1: (MEQP ((MLIST SIMP) 88) ((MLIST SIMP) 55))
2: (SIGN1 ((MLIST SIMP) 33))
3: (DCOMPARE ((MLIST SIMP) 33) 0)
4: (DCOMP ((MLIST SIMP) 33) 0)
5: (DINTERNP ((MLIST SIMP) 33))
5: DINTERNP returned NIL
5: (DINTERNP 0)
5: DINTERNP returned (0 DATA (#))
4: DCOMP returned $PNZ
3: DCOMPARE returned $PNZ
3: (DCOMPARE ((MLIST SIMP) 33) 0)
4: (DCOMP ((MLIST SIMP) 33) 0)
5: (DINTERNP ((MLIST SIMP) 33))
5: DINTERNP returned NIL
5: (DINTERNP 0)
5: DINTERNP returned (0 DATA (#))
4: DCOMP returned $PNZ
3: DCOMPARE returned $PNZ
2: SIGN1 returned $PNZ
1: MEQP returned (($EQUAL) (# 33) 0)
0: MEVALP returned $UNKNOWN
(D4) UNKNOWN
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/