Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Fix sign of derivative of hyperbolic cotangent #605

wants to merge 4 commits into from

3 participants


There was a minus sign missing in the derivative of the hyperbolic cotangent. Taking the derivative of the ratio of hyperbolic cosine and sine gave the correct (negative) value.


Looks good. Usually we add a test to keep this error from ever creeping back in. Can you do so? Also, is this your first pull request/contribution?


Yes, this is my first pull request. As far as a test is concerned, I have to confess that I have not written many tests yet but I can give it a try. This would presumably go into Should it be a separate test or should it rather go into an existing one?


Please compare to my trig branch. Currently I do much work on the trigonometric and hyperbolic functions.
Your change is on my todo list anyway but this can be merged to master w/o troubles for me.


Maybe in the file a single test at the end could be added with the correct values confirmed for the following:

def test_derivs():
    assert [f(x).diff(x) for f in [coth, sinh, cosh, tanh, acoth, asinh, acosh, atanh]] == \
     -tanh(x)**2 + 1,
     1/(-x**2 + 1),
     1/sqrt(x**2 + 1), 
     1/sqrt(x**2 - 1), 
     1/(-x**2 + 1)]

I followed your second suggestion (of course with the minus sign added in the derivative of the coth). However, in the trigonometric tests, the derivatives are part of the tests of the respective functions. Is there any preference for one or the other solution?


Not hearing anything, I went ahead and pushed this after running all passing tests. When something is known to be broken I like to see it get fixed. Any further changes can be made as a new pull request. Thanks, and welcome to SymPy!

@smichr smichr closed this

When something is known to be broken I like to see it get fixed.

Yes this is of course ok.

And rebasing is no problem for me. I will still need some days before
submitting a pull request for the new trig/hyperbolic stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  sympy/functions/elementary/
@@ -402,7 +402,7 @@ class coth(HyperbolicFunction):
def fdiff(self, argindex=1):
if argindex == 1:
- return 1/sinh(self.args[0])**2
+ return -1/sinh(self.args[0])**2
raise ArgumentIndexError(self, argindex)
12 sympy/functions/elementary/tests/
@@ -472,3 +472,15 @@ def test_coth_rewrite():
assert coth(x).rewrite(sinh) == -I*sinh(I*pi/2-x)/sinh(x)
assert coth(x).rewrite(cosh) == -I*cosh(x)/cosh(I*pi/2-x)
assert coth(x).rewrite(tanh) == 1/tanh(x)
+def test_derivs():
+ x = Symbol('x')
+ assert coth(x).diff(x) == -sinh(x)**(-2)
+ assert sinh(x).diff(x) == cosh(x)
+ assert cosh(x).diff(x) == sinh(x)
+ assert tanh(x).diff(x) == -tanh(x)**2 + 1
+ assert acoth(x).diff(x) == 1/(-x**2 + 1)
+ assert asinh(x).diff(x) == 1/sqrt(x**2 + 1)
+ assert acosh(x).diff(x) == 1/sqrt(x**2 - 1)
+ assert atanh(x).diff(x) == 1/(-x**2 + 1)
Something went wrong with that request. Please try again.