The previous post looked at why Mathematica does not simplify the expression Sinh[ArcCosh[x]] the way you might think it should. This post will be a sort of Python analog of the previous post.
SymPy is a Python library that among other things will simplify mathematical expressions. As before, we seek to verify the entries in the table below, this time using SymPy.
Here’s the code:
from sympy import *
x = symbols('x')
print( simplify(sinh(asinh(x))) )
print( simplify(sinh(acosh(x))) )
print( simplify(sinh(atanh(x))) )
print( simplify(cosh(asinh(x))) )
print( simplify(cosh(acosh(x))) )
print( simplify(cosh(atanh(x))) )
print( simplify(tanh(asinh(x))) )
print( simplify(tanh(acosh(x))) )
print( simplify(tanh(atanh(x))) )
As before, the results are mostly as we’d expect:
x sqrt(x - 1)*sqrt(x + 1) x/sqrt(1 - x**2) sqrt(x**2 + 1) x 1/sqrt(1 - x**2) x/sqrt(x**2 + 1) sqrt(x - 1)*sqrt(x + 1)/x x
Also as before, sinh(acosh(x)) and tanh(acosh(x)) return more complicated expressions than in the table above. Why doesn’t
√(x − 1) √(x + 1)
simplify to
√(x² − 1)
as you’d expect? Because the equation
√(x − 1) √(x + 1) = √(x² − 1)
does not hold for all x. See the previous post for the subtleties of defining arccosh and sqrt for complex numbers. The equation above does not hold, for example, when x = −2.
As in Mathematica, you can specify the range of variables in SymPy. If we specify that x ≥ 0 we get the result we expect. The code
x = symbols('x', real=True, nonnegative=True)
print( simplify(sinh(acosh(x))) )
prints
sqrt(x**2 - 1)
as expected.