sympy.simplify doesn't work on "tanh^2(x-y) + sech^2(x-y)"

Viewed 70

I use sympy (ver1.9).

I calculate the following expressions((1)~(4)) by sympy.simplify(). All of them are expected to be identical to 1 analytically.

but (4) did not return 1, and the expression isn't simplified.

https://i.imgur.com/Yl5VGQX.png

Why does this happen?

1 Answers

Try rewriting to exp and then simplifying:

>>> eq=tanh(x-y)**2 + sech(x-y)**2
>>> eq.rewrite(exp).simplify()
1

or use the function to rewrite hyperbolics to trigonometric functions before simplifying, e.g. with fu:

>>> from sympy.simplify.fu import hyper_as_trig
>>> e,f=hyper_as_trig(eq)
>>> f(fu(e))
1

See also hyper_as_trig in simplify/fu.py.

Related