rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

equality on make_arrays is wrong #2704

Open rtoy opened 3 months ago

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-06 18:12:11 Created by macrakis on 2024-04-08 13:57:39 Original: https://sourceforge.net/p/maxima/bugs/4283


qq: make_array('any,4) => {Lisp Array: #(NIL NIL NIL NIL)}
rr: make_array('any,4) => {Lisp Array: #(NIL NIL NIL NIL)}
ss: make_array('any,4) => {Lisp Array: #(NIL NIL NIL NIL)}
qq[2]:3$
rr[1]:5$
ss[2]:3$
qq  =>  {Lisp Array: #(NIL NIL 3 NIL)}
rr  =>  {Lisp Array: #(NIL 5 NIL NIL)}
ss  =>  {Lisp Array: #(NIL NIL 3 NIL)}
is(equal(qq,ss)) => true
is(equal(qq,rr)) => unknown  << should be false

alike1 correctly returns T and NIL in these cases, but array-meqp messes up.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-06 18:12:12 Created by robert_dodier on 2024-04-09 04:57:12 Original: https://sourceforge.net/p/maxima/bugs/4283/#b8eb


ARRAY-MEQP calls MEQP, and MEQP is the one saying it doesn't know if NIL is equal to 5.

(%i16) is(equal(false,5));
  0: (MAXIMA::MEQP NIL 5)
  0: MEQP returned (($EQUAL) NIL 5)
(%o16)                                 unknown
(%i17) is(equal(a,b));
  0: (MAXIMA::MEQP #(NIL NIL 3 NIL) #(NIL 5 NIL NIL))
    1: (MAXIMA::ARRAY-MEQP #(NIL NIL 3 NIL) #(NIL 5 NIL NIL))
      2: (MAXIMA::MEQP NIL NIL)
      2: MEQP returned T
      2: (MAXIMA::MEQP NIL 5)
      2: MEQP returned (($EQUAL) NIL 5)
    1: ARRAY-MEQP returned (($EQUAL) #(NIL NIL 3 NIL) #(NIL 5 NIL NIL))
  0: MEQP returned (($EQUAL) #(NIL NIL 3 NIL) #(NIL 5 NIL NIL))
(%o17)                                 unknown

So from what I can tell the bug is in MEQP.

I'm kind of confused by the comments. The problem isn't in ALIKE1, right? ALIKE1 correctly returns true or false. "Evidence that the array comparison in alike1 isn't used anywhere" ... what?? I don't get it. If it's incorrect we should fix it. But anyway ALIKE1 is correct in this case.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-06 18:12:15 Created by macrakis on 2024-04-09 14:30:56 Original: https://sourceforge.net/p/maxima/bugs/4283/#2909


Diff:


--- old
+++ new
@@ -12,5 +12,3 @@
 is(equal(qq,rr)) =&gt; unknown  &lt;&lt; should be false

alike1 correctly returns T and NIL in these cases, but array-meqp messes up.

-This seems like good evidence that the array comparison in alike1 is not used anywhere!

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-06 18:12:19 Created by macrakis on 2024-04-09 14:30:56 Original: https://sourceforge.net/p/maxima/bugs/4283/#090f


You're right. I've removed the incorrect comment.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-06 18:12:22 Created by robert_dodier on 2024-04-14 05:31:07 Original: https://sourceforge.net/p/maxima/bugs/4283/#ae8c


I think I can fix this if we figure out what's the correct result for comparisons to true and false.

Considering is(equal(x, b)) where b is a Boolean value (true or false) and x is anything other than a Boolean value, I guess we want that to be true if and only if x is known to be equal to b (via assume(equal(x, true)) or assume(equal(x, false)), unless I've overlooked another way to declare a value), false if and only if x is known to be not equal to b (either by its assume value or because x is known to be a non-Boolean value), and undetermined otherwise. Does that sound right?