Periodicity of SymPy trigonometric function

Viewed 155

Sympy's trigonometric functions takes periodic argument into account.

from sympy import pi, sin, Symbol

n = Symbol('n', integer=True)

>>> sin(2*pi + 4)
sin(4)

>>> sin(n*pi)
0

However, it seems that it does not support this feature...

n = Symbol('n', integer=True)

>>> sin(2*n*pi + 4)
sin(2*n*pi + 4)  # Expected sin(4)

.simplify() or .doit() was not working. Is there any function or method to convert sin(2*n*pi + 4) to sin(4)?

1 Answers

You could use trigsimp or seemingly clunky expansion and rewriting:

>>> eq = sin(2*n*pi + 4)
>>> eq.rewrite(exp).expand().rewrite(sin).expand()
sin(4)
>>> trigsimp(eq)
sin(4)
Related