# weird behavior with trigonometric equation

Has anybody an explanation for this output?

print bool( tan(pi/6) == sin(pi/6)/cos(pi/6) )
print bool( tan(pi/5) == sin(pi/5)/cos(pi/5) )
print bool( tan(pi/5).n() == sin(pi/5).n()/cos(pi/5).n() )

True
False
True

edit retag close merge delete

Sort by ยป oldest newest most voted

Looks like a bug to me. I do get True for the following.

eq=tan(pi/5) == sin(pi/5)/cos(pi/5)
bool(eq.simplify_trig())


Note that eq.simplify_trig() gives:

4*sin(1/5*pi)/(sqrt(5) + 1) == 4*sin(1/5*pi)/(sqrt(5) + 1)

more

On the same line, one can check that things like sin((n-1)*pi/n) == sin(pi/n) give False for a general n, and there simplify_trig does not help :(. The origin is different, anyway: probably Sage should send every angle inside a trig function to the first quadrant, as Mathematica does: e.g. sin((n-1)*pi/n) returns sin(pi/n), for a general n.

( 2012-11-08 19:29:16 +0200 )edit

This problem is likely related to the one I reported at: http://ask.sagemath.org/question/1850/odd-trig-function-behavior

( 2012-11-08 20:13:17 +0200 )edit

Sage (through Pynac and GiNaC) automatically evaluates sin(pi/6), cos(pi/6), tan(pi/6):

sage: sin(pi/6)
1/2
sage: cos(pi/6)
1/2*sqrt(3)
sage: tan(pi/6)
1/3*sqrt(3)


For the comparison, it checks if tan(pi/6) - sin(pi/6)/cos(pi/6) is 0:

sage: t = tan(pi/6) - sin(pi/6)/cos(pi/6)
sage: t
0
sage: t.is_trivial_zero()
True


For pi/5, tan() and sin() are left unevaluated, while cos() is:

sage: tan(pi/5)
tan(1/5*pi)
sage: sin(pi/5)
sin(1/5*pi)
sage: cos(pi/5)
1/4*sqrt(5) + 1/4


This makes the difference tan(pi/5) - sin(pi/5)/cos(pi/5) a symbolic expression not trivially equal to 0:

sage: t = tan(pi/5) - sin(pi/5)/cos(pi/5)
sage: t
-4*sin(1/5*pi)/(sqrt(5) + 1) + tan(1/5*pi)
sage: t.is_trivial_zero()
False
sage: t.n()
1.11022302462516e-16


Any patches to improve this behavior would be more than welcome.

more