Ask Your Question

# 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

## 2 answers

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

## Comments

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 12:29:16 -0500 )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 13:13:17 -0500 )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

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2012-11-08 10:43:39 -0500

Seen: 228 times

Last updated: Nov 09 '12
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}