Post Reply 
Programming question and strange == result
10-08-2014, 10:14 PM
Post: #1
Programming question and strange == result
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?
Find all posts by this user
Quote this message in a reply
10-09-2014, 06:12 PM
Post: #2
RE: Programming question and strange == result
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.
Find all posts by this user
Quote this message in a reply
10-09-2014, 06:59 PM
Post: #3
RE: Programming question and strange == result
(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)?
Find all posts by this user
Quote this message in a reply
10-10-2014, 05:47 AM
Post: #4
RE: Programming question and strange == result
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.
Find all posts by this user
Quote this message in a reply
11-01-2014, 07:08 AM
Post: #5
RE: Programming question and strange == result
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.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)