1 | initial version |
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/3pi + 2pi*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/6pi + 2pi*z402]]
bool(fr.subs(solve(L2,y)[0])*k==f)
True
This second expression is the "original" sought solution.