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.Thu, 19 Jul 2018 05:43:59 -0500Commentary on "Simplify trig expressions with the double angle formula"https://ask.sagemath.org/question/43076/commentary-on-simplify-trig-expressions-with-the-double-angle-formula/A bit of reflexion leads me to propose a "brute force" answer to a question wher the answer could be divined with a bit of "intuition".
The [original question](https://ask.sagemath.org/question/35213/simplify-trig-expressions-with-the-double-angle-formula/) was :
> I am trying to simplify the following
> expression in sage:
>
> (sqrt(3)/3*cos(x)+1/3*sin(x))
>
> the resulting expression should be:
>
> 2/3*cos(pi/6-x) .simplify_full(),
> trig_reduce(), or simplify_trig()
> cannot produce this simplification.
>
> Is sage currently capable of doing
> this?
See below for the steps of the solution. Comments, criticisms and even lazzi welcome...Thu, 19 Jul 2018 05:12:48 -0500https://ask.sagemath.org/question/43076/commentary-on-simplify-trig-expressions-with-the-double-angle-formula/Answer by Emmanuel Charpentier for <p>A bit of reflexion leads me to propose a "brute force" answer to a question wher the answer could be divined with a bit of "intuition".</p>
<p>The <a href="https://ask.sagemath.org/question/35213/simplify-trig-expressions-with-the-double-angle-formula/">original question</a> was :</p>
<blockquote>
<p>I am trying to simplify the following
expression in sage:</p>
<p>(sqrt(3)/3<em>cos(x)+1/3</em>sin(x))</p>
<p>the resulting expression should be:</p>
<p>2/3*cos(pi/6-x) .simplify_full(),
trig_reduce(), or simplify_trig()
cannot produce this simplification.</p>
<p>Is sage currently capable of doing
this?</p>
</blockquote>
<p>See below for the steps of the solution. Comments, criticisms and even lazzi welcome...</p>
https://ask.sagemath.org/question/43076/commentary-on-simplify-trig-expressions-with-the-double-angle-formula/?answer=43077#post-id-43077 var("x,y,k")
f=(sqrt(3)/3*cos(x)+1/3*sin(x))
The original expression is of the form $a\cos x + b\sin x$. if it turns out that $a^2+b^2=1$, we can rewrite this as either $\sin(x+y)$ or $\cos(x+y)$, which will give us a solution. So, let's factor out a constant leaving the sum of squares of the coeffs of `trig_function(x)` at 1 :
k=sum([f.coefficient(g(x),1)^2 for g in [sin,cos]]).sqrt()
print k
2/3
Now that this is out of the way, let's search systematically :
fr=f/k
h1=sin(x+y).trig_expand()
L1=[fr.coefficient(g(x),1)==h.coefficient(g(x),1) for g in [sin,cos]]
print L1
[(1/2) == cos(y), 1/2*sqrt(3) == sin(y)]
print solve(L1,y)
[[y == 1/3*pi + 2*pi*z388]]
Check that solution :
bool(fr.subs(solve(L1,y)[0])*k==f)
True
One notes with interest that this check does *not* require the specification of the free integer constant `z248`.
Similarly:
h2=cos(x+y).trig_expand()
L2=[fr.coefficient(g(x),1)==h.coefficient(g(x),1) for g in [sin,cos]]
print solve(L2,y)
[[y == -1/6*pi + 2*pi*z402]]
bool(fr.subs(solve(L2,y)[0])*k==f)
True
This second expression is the "original" sought solution.Thu, 19 Jul 2018 05:43:59 -0500https://ask.sagemath.org/question/43076/commentary-on-simplify-trig-expressions-with-the-double-angle-formula/?answer=43077#post-id-43077