Sympy: Trigonometric Sum Product Identities

I have an expression: sin(x)+sin(y)

A trigger expression is known that expresses this as the product of sin and cos.

Is there a way to get sympy to apply this identity?

simplify and trigsimp do nothing.

+5
source share
1 answer

trigsimp , as Aristocrat points out, does the opposite, because sin(x) + sin(y) simpler than 2*sin((x + y)/2)*cos((x - y)/2) .

trigsimp internally uses an algorithm based on Fu, et. al. which matches the pattern according to various trigonometric identities. If you look at the source code , all identifiers are written in separate functions (functions are named after sections in the Fu document).

Look at the list of simplifications at the top of the file that you probably need.

 TR9 - contract sums of sin-cos to products 

Checking this, it looks like it works

 In [1]: from sympy.simplify.fu import TR9 In [2]: TR9(sin(x) + sin(y)) Out[2]: βŽ›xy⎞ βŽ›xy⎞ 2β‹…sinβŽœβ”€ + β”€βŽŸβ‹…cosβŽœβ”€ - β”€βŽŸ ⎝2 2⎠ ⎝2 2⎠ 

Ultimately, we would like to include them in more user-friendly functions, but at the moment the fu.py file fu.py well-documented, even if all the function names are not particularly memorized.

+5
source

Source: https://habr.com/ru/post/1200557/


All Articles