| The two expression should be equal but when I write bool(arcsin(x) == 2*arctan(x/(1+sqrt(1-x^2)))) it returns false. Any clue - Why it does that? Any get around? |
| I can answer the "why it does that" question, anyway: Sage follows Maxima's conventions on equality testing. That is, it only returns True if it's convinced the equality holds. "False" here translates as "False or unknown". I actually couldn't find a good workaround-- I'm not sure what the right way to fake new rewrite rules is. I guess you could confirm that the lhs and rhs agree via something like this: And if you had several cases where the "agree at one point and derivatives equal" trick works, you could put it in a function, maybe with something like this: Warning: untested code! Will probably break when given unexpected input! giving UPDATE: For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:
thanks for your answer. I liked you workaround. Just one thing, to find the point at which it agree can I use
y=find_root(eq, -1000, 1000) and use that y.
Shu (Nov 15 '10)
If the two expressions are really equal then they should agree everywhere, so it doesn't matter what point you choose. I'd avoid looking for a root, though: (1) it's slower, (2) it's generally a good idea to stay symbolic (i.e. not floating-point) as long as possible, and (3) there might not even be a root to find..
DSM (Nov 15 '10)
What if the two functions are not defined at the point I choose. e.g. in the above equation if I use
bool(eq.subs(x=2))
It will return "False"
Shu (Nov 15 '10)
Then depending on the function, it could crash, give you "nan == nan" which is False, or maybe even return True (if the function is undefined but evaluating the expression gave Infinity on both sides, for example). I'm afraid you're going to have to consider the functions involved.
DSM (Nov 15 '10)
Do you have any idea to work around for
bool( sin(x) == 2*sin(x/2)*cos(x/2) )
?
The differentiation equality check also fails in sage for this one.
Shu (Nov 16 '10) |
Asked: Nov 12 '10
Seen: 353 times
Last updated: Nov 16 '10
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.