Ask Your Question
1

weird behavior with trigonometric equation

asked 2012-11-08 17:43:39 +0200

ndomes gravatar image

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-11-08 19:07:52 +0200

calc314 gravatar image

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)
edit flag offensive delete link 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.

Jesustc gravatar imageJesustc ( 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

calc314 gravatar imagecalc314 ( 2012-11-08 20:13:17 +0200 )edit
0

answered 2012-11-10 01:37:12 +0200

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.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-11-08 17:43:39 +0200

Seen: 587 times

Last updated: Nov 10 '12