Given, for example, the expression (3*cos(pi*n/2)+2*sin(pi*n/2))/n**2
and the knowledge that n is a positive odd integer (ie 1,3,5,...), the expression could simplify to 2*(-1)**((n-1)/2)/n**2
because the cos(pi*n/2)
terms all go to zero, and the sin(pi*n/2)
terms go to -1 or +1. Is there any way I can make sympy recognise this fact and perform the simplification?
Asked
Active
Viewed 223 times
0

user10317393
- 1
- 1
1 Answers
0
You can declare n
to be odd
:
In [72]: n = Symbol('n', odd=True)
In [73]: (3*cos(pi*n/2)+2*sin(pi*n/2))/n**2
Out[73]:
n 1
─ - ─
2 2
2⋅(-1)
───────────
2
n

Oscar Benjamin
- 12,649
- 1
- 12
- 14
-
Thanks - perfect. Your reply has prompted me to find a full list of possible assumptions. – user10317393 Jul 05 '20 at 22:16