ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 17 Nov 2010 05:32:47 -0600bool returns false with arcsin(x) and 2*arctan(x/(1+sqrt(1-x^2)))http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/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?Fri, 12 Nov 2010 07:40:25 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/Answer by DSM for <p>The two expression should be equal
but when I write
bool(arcsin(x) == 2*arctan(x/(1+sqrt(1-x^2))))
it returns false.</p>
<p>Any clue - Why it does that? Any get around?</p>
http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?answer=11783#post-id-11783I 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:
<pre><code>sage: eq = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: bool(eq)
False
sage: # but..
sage: bool(eq.subs(x=0))
True
sage: bool(diff(eq, x))
True
</code></pre>
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:
<b>Warning: untested code! Will probably break when given unexpected input!</b>
<pre><code>
def tryharder_bool(some_expr):
# hack hack hack
if some_expr:
return True
if type(some_expr) == Expression and some_expr.is_relational():
v = some_expr.variables()
if len(v) == 1:
if some_expr.subs({v[0]:0}) and diff(some_expr, v[0]):
return True
return False
</code></pre>
giving
<pre><code>sage: bool(eq)
False
sage: tryharder_bool(eq)
True
</code></pre>
UPDATE:
For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:
<pre><code>sage: eq1 = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: eq2 = sin(x) == 2*sin(x/2)*cos(x/2)
sage: eq3 = sin(2*x) == 2*sin(x)*cos(x)
sage: eq4 = tan(x/2) == sin(x)/(1+cos(x))
sage: eqs = eq1, eq2, eq3, eq4
sage: [bool(q) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_reduce()) for q in eqs]
[False, True, True, False]
sage: [bool(q.trig_expand()) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_expand(half_angles=True)) for q in eqs]
[False, False, True, True]
sage:
sage:
sage: eq2.maxima_methods().exponentialize()
1/2*I*e^(-I*x) - 1/2*I*e^(I*x) == 1/2*(I*e^(-1/2*I*x) - I*e^(1/2*I*x))*(e^(-1/2*I*x) + e^(1/2*I*x))
sage: eq1.maxima_methods().exponentialize()
arcsin(x) == 2*arctan(x/(sqrt(-x^2 + 1) + 1))
sage: [bool(q.maxima_methods().exponentialize()) for q in eqs]
[False, True, True, True]
sage:
sage: def trig_xeq_check(eq):
....: return bool(eq) or bool(eq.maxima_methods().exponentialize()) or (bool(eq.subs(x=0)) and bool(diff(eq,x)))
....:
sage:
sage: [trig_xeq_check(q) for q in eqs]
[True, True, True, True]
</code></pre>
Fri, 12 Nov 2010 14:53:14 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?answer=11783#post-id-11783Comment by Shu for <p>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".</p>
<p>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:</p>
<pre><code>sage: eq = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: bool(eq)
False
sage: # but..
sage: bool(eq.subs(x=0))
True
sage: bool(diff(eq, x))
True
</code></pre>
<p>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:</p>
<p><b>Warning: untested code! Will probably break when given unexpected input!</b></p>
<pre><code>
def tryharder_bool(some_expr):
# hack hack hack
if some_expr:
return True
if type(some_expr) == Expression and some_expr.is_relational():
v = some_expr.variables()
if len(v) == 1:
if some_expr.subs({v[0]:0}) and diff(some_expr, v[0]):
return True
return False
</code></pre>
<p>giving</p>
<pre><code>sage: bool(eq)
False
sage: tryharder_bool(eq)
True
</code></pre>
<p>UPDATE:</p>
<p>For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:</p>
<pre><code>sage: eq1 = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: eq2 = sin(x) == 2*sin(x/2)*cos(x/2)
sage: eq3 = sin(2*x) == 2*sin(x)*cos(x)
sage: eq4 = tan(x/2) == sin(x)/(1+cos(x))
sage: eqs = eq1, eq2, eq3, eq4
sage: [bool(q) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_reduce()) for q in eqs]
[False, True, True, False]
sage: [bool(q.trig_expand()) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_expand(half_angles=True)) for q in eqs]
[False, False, True, True]
sage:
sage:
sage: eq2.maxima_methods().exponentialize()
1/2*I*e^(-I*x) - 1/2*I*e^(I*x) == 1/2*(I*e^(-1/2*I*x) - I*e^(1/2*I*x))*(e^(-1/2*I*x) + e^(1/2*I*x))
sage: eq1.maxima_methods().exponentialize()
arcsin(x) == 2*arctan(x/(sqrt(-x^2 + 1) + 1))
sage: [bool(q.maxima_methods().exponentialize()) for q in eqs]
[False, True, True, True]
sage:
sage: def trig_xeq_check(eq):
....: return bool(eq) or bool(eq.maxima_methods().exponentialize()) or (bool(eq.subs(x=0)) and bool(diff(eq,x)))
....:
sage:
sage: [trig_xeq_check(q) for q in eqs]
[True, True, True, True]
</code></pre>
http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22504#post-id-22504thanks 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. Mon, 15 Nov 2010 05:00:23 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22504#post-id-22504Comment by Shu for <p>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".</p>
<p>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:</p>
<pre><code>sage: eq = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: bool(eq)
False
sage: # but..
sage: bool(eq.subs(x=0))
True
sage: bool(diff(eq, x))
True
</code></pre>
<p>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:</p>
<p><b>Warning: untested code! Will probably break when given unexpected input!</b></p>
<pre><code>
def tryharder_bool(some_expr):
# hack hack hack
if some_expr:
return True
if type(some_expr) == Expression and some_expr.is_relational():
v = some_expr.variables()
if len(v) == 1:
if some_expr.subs({v[0]:0}) and diff(some_expr, v[0]):
return True
return False
</code></pre>
<p>giving</p>
<pre><code>sage: bool(eq)
False
sage: tryharder_bool(eq)
True
</code></pre>
<p>UPDATE:</p>
<p>For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:</p>
<pre><code>sage: eq1 = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: eq2 = sin(x) == 2*sin(x/2)*cos(x/2)
sage: eq3 = sin(2*x) == 2*sin(x)*cos(x)
sage: eq4 = tan(x/2) == sin(x)/(1+cos(x))
sage: eqs = eq1, eq2, eq3, eq4
sage: [bool(q) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_reduce()) for q in eqs]
[False, True, True, False]
sage: [bool(q.trig_expand()) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_expand(half_angles=True)) for q in eqs]
[False, False, True, True]
sage:
sage:
sage: eq2.maxima_methods().exponentialize()
1/2*I*e^(-I*x) - 1/2*I*e^(I*x) == 1/2*(I*e^(-1/2*I*x) - I*e^(1/2*I*x))*(e^(-1/2*I*x) + e^(1/2*I*x))
sage: eq1.maxima_methods().exponentialize()
arcsin(x) == 2*arctan(x/(sqrt(-x^2 + 1) + 1))
sage: [bool(q.maxima_methods().exponentialize()) for q in eqs]
[False, True, True, True]
sage:
sage: def trig_xeq_check(eq):
....: return bool(eq) or bool(eq.maxima_methods().exponentialize()) or (bool(eq.subs(x=0)) and bool(diff(eq,x)))
....:
sage:
sage: [trig_xeq_check(q) for q in eqs]
[True, True, True, True]
</code></pre>
http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22500#post-id-22500What 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"Mon, 15 Nov 2010 10:42:19 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22500#post-id-22500Comment by Shu for <p>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".</p>
<p>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:</p>
<pre><code>sage: eq = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: bool(eq)
False
sage: # but..
sage: bool(eq.subs(x=0))
True
sage: bool(diff(eq, x))
True
</code></pre>
<p>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:</p>
<p><b>Warning: untested code! Will probably break when given unexpected input!</b></p>
<pre><code>
def tryharder_bool(some_expr):
# hack hack hack
if some_expr:
return True
if type(some_expr) == Expression and some_expr.is_relational():
v = some_expr.variables()
if len(v) == 1:
if some_expr.subs({v[0]:0}) and diff(some_expr, v[0]):
return True
return False
</code></pre>
<p>giving</p>
<pre><code>sage: bool(eq)
False
sage: tryharder_bool(eq)
True
</code></pre>
<p>UPDATE:</p>
<p>For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:</p>
<pre><code>sage: eq1 = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: eq2 = sin(x) == 2*sin(x/2)*cos(x/2)
sage: eq3 = sin(2*x) == 2*sin(x)*cos(x)
sage: eq4 = tan(x/2) == sin(x)/(1+cos(x))
sage: eqs = eq1, eq2, eq3, eq4
sage: [bool(q) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_reduce()) for q in eqs]
[False, True, True, False]
sage: [bool(q.trig_expand()) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_expand(half_angles=True)) for q in eqs]
[False, False, True, True]
sage:
sage:
sage: eq2.maxima_methods().exponentialize()
1/2*I*e^(-I*x) - 1/2*I*e^(I*x) == 1/2*(I*e^(-1/2*I*x) - I*e^(1/2*I*x))*(e^(-1/2*I*x) + e^(1/2*I*x))
sage: eq1.maxima_methods().exponentialize()
arcsin(x) == 2*arctan(x/(sqrt(-x^2 + 1) + 1))
sage: [bool(q.maxima_methods().exponentialize()) for q in eqs]
[False, True, True, True]
sage:
sage: def trig_xeq_check(eq):
....: return bool(eq) or bool(eq.maxima_methods().exponentialize()) or (bool(eq.subs(x=0)) and bool(diff(eq,x)))
....:
sage:
sage: [trig_xeq_check(q) for q in eqs]
[True, True, True, True]
</code></pre>
http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22495#post-id-22495Do 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.
Tue, 16 Nov 2010 13:17:21 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22495#post-id-22495Comment by Shu for <p>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".</p>
<p>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:</p>
<pre><code>sage: eq = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: bool(eq)
False
sage: # but..
sage: bool(eq.subs(x=0))
True
sage: bool(diff(eq, x))
True
</code></pre>
<p>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:</p>
<p><b>Warning: untested code! Will probably break when given unexpected input!</b></p>
<pre><code>
def tryharder_bool(some_expr):
# hack hack hack
if some_expr:
return True
if type(some_expr) == Expression and some_expr.is_relational():
v = some_expr.variables()
if len(v) == 1:
if some_expr.subs({v[0]:0}) and diff(some_expr, v[0]):
return True
return False
</code></pre>
<p>giving</p>
<pre><code>sage: bool(eq)
False
sage: tryharder_bool(eq)
True
</code></pre>
<p>UPDATE:</p>
<p>For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:</p>
<pre><code>sage: eq1 = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: eq2 = sin(x) == 2*sin(x/2)*cos(x/2)
sage: eq3 = sin(2*x) == 2*sin(x)*cos(x)
sage: eq4 = tan(x/2) == sin(x)/(1+cos(x))
sage: eqs = eq1, eq2, eq3, eq4
sage: [bool(q) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_reduce()) for q in eqs]
[False, True, True, False]
sage: [bool(q.trig_expand()) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_expand(half_angles=True)) for q in eqs]
[False, False, True, True]
sage:
sage:
sage: eq2.maxima_methods().exponentialize()
1/2*I*e^(-I*x) - 1/2*I*e^(I*x) == 1/2*(I*e^(-1/2*I*x) - I*e^(1/2*I*x))*(e^(-1/2*I*x) + e^(1/2*I*x))
sage: eq1.maxima_methods().exponentialize()
arcsin(x) == 2*arctan(x/(sqrt(-x^2 + 1) + 1))
sage: [bool(q.maxima_methods().exponentialize()) for q in eqs]
[False, True, True, True]
sage:
sage: def trig_xeq_check(eq):
....: return bool(eq) or bool(eq.maxima_methods().exponentialize()) or (bool(eq.subs(x=0)) and bool(diff(eq,x)))
....:
sage:
sage: [trig_xeq_check(q) for q in eqs]
[True, True, True, True]
</code></pre>
http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22492#post-id-22492Thanks for your answers. I will approach you again if I find more such equality check that bool cannot handle in first place.Wed, 17 Nov 2010 05:32:47 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22492#post-id-22492Comment by Shu for <p>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".</p>
<p>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:</p>
<pre><code>sage: eq = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: bool(eq)
False
sage: # but..
sage: bool(eq.subs(x=0))
True
sage: bool(diff(eq, x))
True
</code></pre>
<p>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:</p>
<p><b>Warning: untested code! Will probably break when given unexpected input!</b></p>
<pre><code>
def tryharder_bool(some_expr):
# hack hack hack
if some_expr:
return True
if type(some_expr) == Expression and some_expr.is_relational():
v = some_expr.variables()
if len(v) == 1:
if some_expr.subs({v[0]:0}) and diff(some_expr, v[0]):
return True
return False
</code></pre>
<p>giving</p>
<pre><code>sage: bool(eq)
False
sage: tryharder_bool(eq)
True
</code></pre>
<p>UPDATE:</p>
<p>For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:</p>
<pre><code>sage: eq1 = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: eq2 = sin(x) == 2*sin(x/2)*cos(x/2)
sage: eq3 = sin(2*x) == 2*sin(x)*cos(x)
sage: eq4 = tan(x/2) == sin(x)/(1+cos(x))
sage: eqs = eq1, eq2, eq3, eq4
sage: [bool(q) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_reduce()) for q in eqs]
[False, True, True, False]
sage: [bool(q.trig_expand()) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_expand(half_angles=True)) for q in eqs]
[False, False, True, True]
sage:
sage:
sage: eq2.maxima_methods().exponentialize()
1/2*I*e^(-I*x) - 1/2*I*e^(I*x) == 1/2*(I*e^(-1/2*I*x) - I*e^(1/2*I*x))*(e^(-1/2*I*x) + e^(1/2*I*x))
sage: eq1.maxima_methods().exponentialize()
arcsin(x) == 2*arctan(x/(sqrt(-x^2 + 1) + 1))
sage: [bool(q.maxima_methods().exponentialize()) for q in eqs]
[False, True, True, True]
sage:
sage: def trig_xeq_check(eq):
....: return bool(eq) or bool(eq.maxima_methods().exponentialize()) or (bool(eq.subs(x=0)) and bool(diff(eq,x)))
....:
sage:
sage: [trig_xeq_check(q) for q in eqs]
[True, True, True, True]
</code></pre>
http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22494#post-id-22494Surprisingly bool(sin(2*x) == 2*sin(x)*cos(x)) works.
Same problem with bool( tan(x/2) == sin(x)/(1+cos(x)) ), does not work?
Sage does not handle fractional angles in trig?Tue, 16 Nov 2010 13:21:36 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22494#post-id-22494Comment by DSM for <p>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".</p>
<p>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:</p>
<pre><code>sage: eq = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: bool(eq)
False
sage: # but..
sage: bool(eq.subs(x=0))
True
sage: bool(diff(eq, x))
True
</code></pre>
<p>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:</p>
<p><b>Warning: untested code! Will probably break when given unexpected input!</b></p>
<pre><code>
def tryharder_bool(some_expr):
# hack hack hack
if some_expr:
return True
if type(some_expr) == Expression and some_expr.is_relational():
v = some_expr.variables()
if len(v) == 1:
if some_expr.subs({v[0]:0}) and diff(some_expr, v[0]):
return True
return False
</code></pre>
<p>giving</p>
<pre><code>sage: bool(eq)
False
sage: tryharder_bool(eq)
True
</code></pre>
<p>UPDATE:</p>
<p>For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:</p>
<pre><code>sage: eq1 = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: eq2 = sin(x) == 2*sin(x/2)*cos(x/2)
sage: eq3 = sin(2*x) == 2*sin(x)*cos(x)
sage: eq4 = tan(x/2) == sin(x)/(1+cos(x))
sage: eqs = eq1, eq2, eq3, eq4
sage: [bool(q) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_reduce()) for q in eqs]
[False, True, True, False]
sage: [bool(q.trig_expand()) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_expand(half_angles=True)) for q in eqs]
[False, False, True, True]
sage:
sage:
sage: eq2.maxima_methods().exponentialize()
1/2*I*e^(-I*x) - 1/2*I*e^(I*x) == 1/2*(I*e^(-1/2*I*x) - I*e^(1/2*I*x))*(e^(-1/2*I*x) + e^(1/2*I*x))
sage: eq1.maxima_methods().exponentialize()
arcsin(x) == 2*arctan(x/(sqrt(-x^2 + 1) + 1))
sage: [bool(q.maxima_methods().exponentialize()) for q in eqs]
[False, True, True, True]
sage:
sage: def trig_xeq_check(eq):
....: return bool(eq) or bool(eq.maxima_methods().exponentialize()) or (bool(eq.subs(x=0)) and bool(diff(eq,x)))
....:
sage:
sage: [trig_xeq_check(q) for q in eqs]
[True, True, True, True]
</code></pre>
http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22493#post-id-22493See my update.Tue, 16 Nov 2010 17:09:00 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22493#post-id-22493Comment by DSM for <p>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".</p>
<p>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:</p>
<pre><code>sage: eq = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: bool(eq)
False
sage: # but..
sage: bool(eq.subs(x=0))
True
sage: bool(diff(eq, x))
True
</code></pre>
<p>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:</p>
<p><b>Warning: untested code! Will probably break when given unexpected input!</b></p>
<pre><code>
def tryharder_bool(some_expr):
# hack hack hack
if some_expr:
return True
if type(some_expr) == Expression and some_expr.is_relational():
v = some_expr.variables()
if len(v) == 1:
if some_expr.subs({v[0]:0}) and diff(some_expr, v[0]):
return True
return False
</code></pre>
<p>giving</p>
<pre><code>sage: bool(eq)
False
sage: tryharder_bool(eq)
True
</code></pre>
<p>UPDATE:</p>
<p>For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:</p>
<pre><code>sage: eq1 = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: eq2 = sin(x) == 2*sin(x/2)*cos(x/2)
sage: eq3 = sin(2*x) == 2*sin(x)*cos(x)
sage: eq4 = tan(x/2) == sin(x)/(1+cos(x))
sage: eqs = eq1, eq2, eq3, eq4
sage: [bool(q) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_reduce()) for q in eqs]
[False, True, True, False]
sage: [bool(q.trig_expand()) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_expand(half_angles=True)) for q in eqs]
[False, False, True, True]
sage:
sage:
sage: eq2.maxima_methods().exponentialize()
1/2*I*e^(-I*x) - 1/2*I*e^(I*x) == 1/2*(I*e^(-1/2*I*x) - I*e^(1/2*I*x))*(e^(-1/2*I*x) + e^(1/2*I*x))
sage: eq1.maxima_methods().exponentialize()
arcsin(x) == 2*arctan(x/(sqrt(-x^2 + 1) + 1))
sage: [bool(q.maxima_methods().exponentialize()) for q in eqs]
[False, True, True, True]
sage:
sage: def trig_xeq_check(eq):
....: return bool(eq) or bool(eq.maxima_methods().exponentialize()) or (bool(eq.subs(x=0)) and bool(diff(eq,x)))
....:
sage:
sage: [trig_xeq_check(q) for q in eqs]
[True, True, True, True]
</code></pre>
http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22502#post-id-22502If 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..Mon, 15 Nov 2010 05:38:42 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22502#post-id-22502Comment by DSM for <p>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".</p>
<p>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:</p>
<pre><code>sage: eq = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: bool(eq)
False
sage: # but..
sage: bool(eq.subs(x=0))
True
sage: bool(diff(eq, x))
True
</code></pre>
<p>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:</p>
<p><b>Warning: untested code! Will probably break when given unexpected input!</b></p>
<pre><code>
def tryharder_bool(some_expr):
# hack hack hack
if some_expr:
return True
if type(some_expr) == Expression and some_expr.is_relational():
v = some_expr.variables()
if len(v) == 1:
if some_expr.subs({v[0]:0}) and diff(some_expr, v[0]):
return True
return False
</code></pre>
<p>giving</p>
<pre><code>sage: bool(eq)
False
sage: tryharder_bool(eq)
True
</code></pre>
<p>UPDATE:</p>
<p>For some of the other cases mentioned in the comments, playing around with the trig_* functions and/or converting to exponential form works:</p>
<pre><code>sage: eq1 = arcsin(x) == 2*arctan(x/(sqrt(-x*x+1)+1))
sage: eq2 = sin(x) == 2*sin(x/2)*cos(x/2)
sage: eq3 = sin(2*x) == 2*sin(x)*cos(x)
sage: eq4 = tan(x/2) == sin(x)/(1+cos(x))
sage: eqs = eq1, eq2, eq3, eq4
sage: [bool(q) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_reduce()) for q in eqs]
[False, True, True, False]
sage: [bool(q.trig_expand()) for q in eqs]
[False, False, True, False]
sage: [bool(q.trig_expand(half_angles=True)) for q in eqs]
[False, False, True, True]
sage:
sage:
sage: eq2.maxima_methods().exponentialize()
1/2*I*e^(-I*x) - 1/2*I*e^(I*x) == 1/2*(I*e^(-1/2*I*x) - I*e^(1/2*I*x))*(e^(-1/2*I*x) + e^(1/2*I*x))
sage: eq1.maxima_methods().exponentialize()
arcsin(x) == 2*arctan(x/(sqrt(-x^2 + 1) + 1))
sage: [bool(q.maxima_methods().exponentialize()) for q in eqs]
[False, True, True, True]
sage:
sage: def trig_xeq_check(eq):
....: return bool(eq) or bool(eq.maxima_methods().exponentialize()) or (bool(eq.subs(x=0)) and bool(diff(eq,x)))
....:
sage:
sage: [trig_xeq_check(q) for q in eqs]
[True, True, True, True]
</code></pre>
http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22499#post-id-22499Then 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.Mon, 15 Nov 2010 11:50:04 -0600http://ask.sagemath.org/question/7762/bool-returns-false-with-arcsinx-and-2arctanx1sqrt1-x2/?comment=22499#post-id-22499