# Simplify trig expressions with the double angle formula

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?

edit retag close merge delete

Sort by » oldest newest most voted

With the algorithm by Fu et al, implemented as fu.py in Sympy:

import sympy as sy

f = sqrt(3)/3*cos(x)+1/3*sin(x)
f_reduced = SR(sy.fu(sy.sympify(f))); f_reduced


gives 2/3*sin(1/3*pi + x) (which is $\frac{\pi}{2}$-close to the answer you expected!).

From my own experience, this type of functionality is very useful (1). I'd define this reduction as: "try to get a formula with the smaller number of terms as possible". This is the type of simplification that often looks nicer, or simpler (to a physicist, say), and it is what I often want from a CAS -- though in many real cases a trained human does better and faster. A step forward would be that the program introduces new useful auxiliary variables, I ignore if this exists in some form already.

In the case at hand, there is a single specific reduction which works, sy.FU['TR10i'](expr), while using sy.fu(expr) runs through several reductions and picks the one which gives a "simpler" expression, as explained in the doc.

(1) The use case is solving physics/engineering problems that involve formulas with many trig functions/complex exponentials. As a concrete example, consider a determinant in Fourier space arising from the normal modes of a discrete system.

more

Thanks, I will have to look more into the fu.py algorithm. That gets me where I need to be.

( 2016-10-22 10:09:08 -0500 )edit

Well, it is hard to decide which is a simplified version of the other. For many, the first expression is simpler than the second since the involved trigonometric functions are eveluated on x, not pi/6-x. But i agree that something might be missing to express what kind of modification the user expect from Sage.

However, Sage somehow knows that the two expressions are equal:

sage: bool((sqrt(3)/3*cos(x)+1/3*sin(x)) == 2/3*cos(pi/6-x))
True


sage: (sqrt(3)/3*cos(x)+1/3*sin(x)).full_simplify()
1/9*sqrt(3)*(sqrt(3)*sin(x) + 3*cos(x))
sage: ( 2/3*cos(pi/6-x)).full_simplify()
1/9*sqrt(3)*(sqrt(3)*sin(x) + 3*cos(x))

more

Thanks for your response. I understand that sage knows they are equal. However, getting the answer in the single term form helps me see a relationship more easily.

( 2016-10-22 10:08:25 -0500 )edit