rtoy / maxima

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

comparing sets having abs( ) #979

Open rtoy opened 3 months ago

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 15:53:52 Created by numiri on 2016-05-27 04:38:52 Original: https://sourceforge.net/p/maxima/bugs/3169


The crux of the problem is that maxima does not recognize the 2 sets below as equal: { abs(m), -abs(m) } and { m, -m } I expect the 2 sets to be equal. (if we make the assignment m:5, Maxima recognize it as equal). Here is some background.

My program writes Maxima commands to confirm the correctness of manipulating an equation.
eg. in deriving the quadratic formula, after completing the squares, this is a common step step 1 is: ( x - b/(2*a) )^2 = ( b^2 - 4*a*c ) / ( 4*a^2 ) step 2 is: x - b/(2*a) = +- sqrt( ( b^2 - 4*a*c ) / ( 4*a^2 ) ). (note the +- plus/minus sign) I deem the move from step 1 to step 2 is correct if the { solutions of step 1 } = { solutions of step 2 }

Here's the transcript:

(%i13) L: x - b/(2*a);
.                                        b
(%o13)                              x - ---
.                                       2 a
(%i14) R:  ( b^2 - 4*a*c ) / ( 4*a^2 );
.                                   2
.                                  b  - 4 a c
(%o14)                             ----------
.                                        2
.                                     4 a

(%i21) step1: setify( solve( L ^2 = R , [x] ) );
.                         2                         2
.                   sqrt(b  - 4 a c) - b      sqrt(b  - 4 a c) + b
(%o21)       {x = - --------------------, x = --------------------}
.                           2 a                       2 a
(%i22) step2: union( setify( solve( L = sqrt( R ), [x] ) ), setify( solve( L = -sqrt( R ), [x] ) ) );
.                      2                                  2
.              a sqrt(b  - 4 a c) - abs(a) b      a sqrt(b  - 4 a c) + abs(a) b
(%o22)  {x = - -----------------------------, x = -----------------------------}
.                       2 a abs(a)                         2 a abs(a)
(%i23) setequalp( step1, step2 );
(%o23)                               false

I expected the final output to be TRUE. Thank you for your help.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 15:53:53 Created by willisbl on 2016-05-28 11:23:29 Original: https://sourceforge.net/p/maxima/bugs/3169/#d880


setequal({ abs(m), -abs(m) } , { m, -m }) --> false is consistent with the user documentation:

-- Function: setequalp (, ) Returns 'true' if sets and have the same number of elements and 'is( = )' is 'true' for 'x' in the elements of and 'y' in the elements of , considered in the order determined by 'listify'. Otherwise, 'setequalp' returns 'false'.

Of course it would be terrific if setqual was better about detecting sematic equality of sets. Maybe you could suggest an algorithm?

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 15:53:57 Created by tomasriker on 2016-06-02 07:27:02 Original: https://sourceforge.net/p/maxima/bugs/3169/#013c


An interesting problem (and not a bug, as Barton mentioned). If this was my problem, I'd probably write a function that simplifies sets of the form {abs(m), -abs(m), ...} to {m, -m, ...} and apply that function before comparing the sets. I don't think that this functionality is needed in setequalp.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 15:54:00 Created by kjak on 2016-06-03 01:39:12 Original: https://sourceforge.net/p/maxima/bugs/3169/#360d/a1d6


Hi, Sebastian. I think you will more clearly see what's happening if you look at the resulting set alone (without immediately passing it to setequalp):

(%i1) {abs(m),-abs(m)};
(%o1) {-abs(m),abs(m)}

(%i2) assume(m>0)$

(%i3) {abs(m),-abs(m)};
(%o3) {-m,m}

So in your example with this assumption setequalp is just comparing {-m,m} to {-m,m}.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 15:54:04 Created by robert_dodier on 2016-06-11 20:01:05 Original: https://sourceforge.net/p/maxima/bugs/3169/#488a


  • labels: abs, setequal --> abs, setequal, not a bug
  • Description has changed:

Diff:


--- old
+++ new
@@ -1,11 +1,11 @@
 The crux of the problem is that maxima does not recognize the 2 sets below as equal:
-    { abs(m), -abs(m) }   and    { m, -m }
+    `{ abs(m), -abs(m) }`   and    `{ m, -m }`
 I expect the 2 sets to be equal.  (if we make the assignment m:5, Maxima recognize it as equal).  Here is some background.

 My program writes Maxima commands to confirm the correctness of manipulating an equation.  
 eg. in deriving the quadratic formula, after completing the squares, this is a common step 
-   step 1 is:  ( x - b/(2*a) )^2 =          ( b^2 - 4*a*c ) / ( 4*a^2  )
-   step 2 is:    x - b/(2*a)     = +- sqrt( ( b^2 - 4*a*c ) / ( 4*a^2  ) ).  (note the +- plus/minus sign)
+   step 1 is:  `( x - b/(2*a) )^2 =          ( b^2 - 4*a*c ) / ( 4*a^2  )`
+   step 2 is:    `x - b/(2*a)     = +- sqrt( ( b^2 - 4*a*c ) / ( 4*a^2  ) )`.  (note the +- plus/minus sign)
 I deem the move from step 1 to step 2 is correct if the { solutions of step 1 } = { solutions of step 2 }

 Here's the transcript:
  • status: open --> wont-fix
rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 15:54:07 Created by robert_dodier on 2016-06-11 20:01:06 Original: https://sourceforge.net/p/maxima/bugs/3169/#36c8


Since setequalp is working as documented, I'm closing this report as "won't fix".

I agree that there is an opportunity here for setequalp to be strengthened. If OP or anyone has an idea about how to proceed with that, my advice is to open a feature enhancement ticket or raise the issue on the maxima-discuss mailing list.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-03 15:54:11 Created by macrakis on 2018-07-02 15:14:19 Original: https://sourceforge.net/p/maxima/bugs/3169/#cc7e


Of course, even these fancier comparison techniques wouldn't help in the case of {m,-m} vs. {abs(m),-abs(m)}, where the sets are always equal even though the individual elements are not.