sympy: trigonometric sum-product identities

爱⌒轻易说出口 提交于 2019-11-28 11:18:31

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

trigsimp internally uses an algorithm based on a paper by Fu, et. al., which does pattern matching on various trigonometric identities. If you look at the source code, all the identities are written out in individual functions (the functions are named after the sections in Fu's paper).

Looking at the list of simplifications at the top of the file, the one you want is probably

TR9 - contract sums of sin-cos to products

Testing it out, it looks like it works

In [1]: from sympy.simplify.fu import TR9

In [2]: TR9(sin(x) + sin(y))
Out[2]:
     ⎛x   y⎞    ⎛x   y⎞
2⋅sin⎜─ + ─⎟⋅cos⎜─ - ─⎟
     ⎝2   2⎠    ⎝2   2⎠

We would eventually like to factor these out into more user-friendly functions, but for now, the fu.py file is pretty well documented, even if all the function names are not particularly memorable.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!