ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 12 Mar 2017 15:57:46 -0500How to get sage to simplify sin(pi/16)?https://ask.sagemath.org/question/36919/how-to-get-sage-to-simplify-sinpi16/I'm trying to look at numbers of the form sin(pi/2^n), but when I ask for a list of the first 10, I get [0,1, 1/2*sqrt(2), 1/2*sqrt(-sqrt(2) + 2), sin(1/16*pi), sin(1/32*pi)...]
Why are these not being reduced, even when I call sin(1/16*pi).simplify_full()? How can I make sage simplify them?Sat, 11 Mar 2017 23:00:03 -0600https://ask.sagemath.org/question/36919/how-to-get-sage-to-simplify-sinpi16/Answer by mforets for <p>I'm trying to look at numbers of the form sin(pi/2^n), but when I ask for a list of the first 10, I get [0,1, 1/2<em>sqrt(2), 1/2</em>sqrt(-sqrt(2) + 2), sin(1/16<em>pi), sin(1/32</em>pi)...]
Why are these not being reduced, even when I call sin(1/16*pi).simplify_full()? How can I make sage simplify them?</p>
https://ask.sagemath.org/question/36919/how-to-get-sage-to-simplify-sinpi16/?answer=36923#post-id-36923Two extra ideas:
Try the method [radical_expression()](http://doc.sagemath.org/html/en/reference/number_fields/sage/rings/qqbar.html#sage.rings.qqbar.AlgebraicNumber_base.radical_expression):
sage: QQbar(sin(pi/16)).radical_expression()
sqrt(-1/2*sqrt(1/4*sqrt(2) + 1/2) + 1/2)
Try with the [giac package](http://doc.sagemath.org/html/en/reference/interfaces/sage/interfaces/giac.html#tutorial):
sage: giac('norm(trig2exp(sin(pi/16)))')._sage_()
1/2*sqrt(-sqrt(sqrt(2) + 2) + 2)
(the expressions are the same).Sun, 12 Mar 2017 15:57:46 -0500https://ask.sagemath.org/question/36919/how-to-get-sage-to-simplify-sinpi16/?answer=36923#post-id-36923Answer by calc314 for <p>I'm trying to look at numbers of the form sin(pi/2^n), but when I ask for a list of the first 10, I get [0,1, 1/2<em>sqrt(2), 1/2</em>sqrt(-sqrt(2) + 2), sin(1/16<em>pi), sin(1/32</em>pi)...]
Why are these not being reduced, even when I call sin(1/16*pi).simplify_full()? How can I make sage simplify them?</p>
https://ask.sagemath.org/question/36919/how-to-get-sage-to-simplify-sinpi16/?answer=36921#post-id-36921I can't get Sage to do this directly either. Perhaps there is a way that I'm missing.
However, you can use SymPy to do it. The following code does the job.
import sympy as sp
sp.expand_trig(sin(pi/16))
However, the resulting object is not a Sage object. To get it in the appropriate ring for Sage computations, you can convert it to the Symbolic Ring as follows.
SR( sp.expand_trig(sin(pi/16)) )
The result will then have the type: sage.symbolic.expression.Expression.
You can check this by doing:
q = sp.expand_trig(sin(pi/16))
type(q)
Sun, 12 Mar 2017 12:52:14 -0500https://ask.sagemath.org/question/36919/how-to-get-sage-to-simplify-sinpi16/?answer=36921#post-id-36921