三角标识

时间:2016-07-02 18:54:54

标签: python math trigonometry sympy

我有一个包含正弦和余弦的表达式,并且只想使用正弦(或余弦)来编写它,可能使用power-reduction formula

我尝试使用SymPy,但我无法进行#34;重写"到期望的输出:

angle = symbols('angle')
print (sin(angle)**2).rewrite(sin, cos) # (1 - cos(2*angle))/2
print ((1 - cos(2*angle))/2).rewrite(cos, sin) # sin(angle)**2

有没有办法告诉Sympy只使用正弦(或余弦)重写这样的表达式?

1 个答案:

答案 0 :(得分:4)

The sympy.simplify.fu module根据trig标识定义了许多转换:

TR0 - simplify expression
TR1 - sec-csc to cos-sin
TR2 - tan-cot to sin-cos ratio
TR2i - sin-cos ratio to tan
TR3 - angle canonicalization
TR4 - functions at special angles
TR5 - powers of sin to powers of cos
TR6 - powers of cos to powers of sin
TR7 - reduce cos power (increase angle)
TR8 - expand products of sin-cos to sums
TR9 - contract sums of sin-cos to products
TR10 - separate sin-cos arguments
TR10i - collect sin-cos arguments
TR11 - reduce double angles
TR12 - separate tan arguments
TR12i - collect tan arguments
TR13 - expand product of tan-cot
TRmorrie - prod(cos(x*2**i), (i, 0, k - 1)) -> sin(2**k*x)/(2**k*sin(x))
TR14 - factored powers of sin or cos to cos or sin power
TR15 - negative powers of sin to cot power
TR16 - negative powers of cos to tan power
TR22 - tan-cot powers to negative powers of sec-csc functions
TR111 - negative sin-cos-tan powers to csc-sec-cot

我从this threadthis post by asmeurer了解了这些功能。

import sympy as sy
from sympy import sin, cos
FU = sy.FU

angle = sy.symbols('angle')
expr = sin(angle)**2

print(FU['TR8'](expr))
# -cos(2*angle)/2 + 1/2

print(FU['TR5'](expr))
# -cos(angle)**2 + 1