Programming question and strange == result - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Calculators (and very old HP Computers) ( /forum-3.html)+--- Forum: HP Prime ( /forum-5.html)+--- Thread: Programming question and strange == result ( /thread-2257.html) |

Programming question and strange == result - pr0 - 10-08-2014 10:14 PM
Made a very simple test program: Quote:EXPORT TEST(X,Y) Running; TEST(x^2+x-3,x-1) Results in: {(x^2+x-3)/(x-1),0} Running: quorem(x^2+x-3,x-1) Results in: [x+2 -1] Why does the program give me that result? Have spent ALOT of time trying to figure this out..any ideas? Another very strange thing I noticed: 2x-2==2(x-1) results in 0 2x-2==2x-2 results in 1 simplify(2x-2==2(x-1)) results in true simplify(2x-2==2x-2) results in 1 Any reasonable explanation for this? RE: Programming question and strange == result - parisse - 10-09-2014 06:12 PM
a==b checks if a and b have the same representation, it does not check if they are mathematically equivalent. For that the best is simplify(a-b)==0. RE: Programming question and strange == result - pr0 - 10-09-2014 06:59 PM
(10-09-2014 06:12 PM)parisse Wrote: a==b checks if a and b have the same representation, it does not check if they are mathematically equivalent. For that the best is simplify(a-b)==0. Thanks for your answer! What exactly does "the same representation" mean in this situation? Neither english or math is my native language.. Shouldn't at least this give the same result (true or 1 in both cases)? simplify(2x-2==2(x-1)) results in true simplify(2x-2==2x-2) results in 1 Any idea why quorem gives a different result inside/outside a program (and how to make it work within a program)? RE: Programming question and strange == result - parisse - 10-10-2014 05:47 AM
Same representation = same internal tree representation. simplify(2x-2==2x-2) returns true in Xcas, I don't know why it does not on the Prime, maybe something fixed since last firmware release. For programs using CAS instructions, I would recommend using a CAS program not a HOME program. RE: Programming question and strange == result - parisse - 11-01-2014 07:08 AM
By the way, if you do a==b, the current version of Xcas does now compute the autosimplification function on a-b and checks if it's 0 or not. Therefore setting autosimplification to none, minimum or maximum might affect the == test on the Prime. |