HP Forums

Full Version: Programming question and strange == result
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Made a very simple test program:

Quote:EXPORT TEST(X,Y)
BEGIN
RETURN CAS.quorem(X,Y);
END;

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?
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.
(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 Wink 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)?
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.
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.
Reference URL's