Issue 210838: Inverse hyperbolic functions in cmath module (PR#231) (original) (raw)

Created on 2000-08-01 21:15 by anonymous, last changed 2022-04-10 16:02 by admin. This issue is now closed.

Messages (10)
msg771 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-08-01 21:15
Jitterbug-Id: 231 Submitted-By: nadavh@envision.co.il Date: Fri, 10 Mar 2000 18:35:07 -0500 (EST) Version: 1.52 OS: NT 4.0 SP4 1. The function cmath.acosh provides the negative branch with low precision. For example: >>> cmath.acosh(cmath.cosh(10.0)) (-10.0000000135+0j) Proposed solution --- use the following formula which is precise and avoids singularities with complex arguments: def acosh(x): return 2.0*log(sqrt(x+1.0) + sqrt(x-1.0)) - log(2.0) 2. The function cmath.sinh does not handle moderately large arguments. For example: >>> cmath.asinh(cmath.sinh(20.0)) (1.#INF+0j) Proposed solution: Use the textbook formula: def asinh(x): return log(x+sqrt(x*x+1.0)) This calculation is more limited then the acosh calculation, but still works fine. ==================================================================== Audit trail: Mon Apr 03 18:38:28 2000 guido changed notes Mon Apr 03 18:38:28 2000 guido moved from incoming to request
msg772 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-08-01 21:15
From: Guido van Rossum <guido@python.org> Subject: Re: [Python-bugs-list] Inverse hyperbolic functions in cmath module (PR#231) Date: Fri, 10 Mar 2000 18:44:01 -0500 > Full_Name: Nadav Horesh > Version: 1.52 > OS: NT 4.0 SP4 > Submission from: (NULL) (212.25.119.223) > > > 1. The function cmath.acosh provides the negative branch with low > precision. For example: > > >>> cmath.acosh(cmath.cosh(10.0)) > (-10.0000000135+0j) > > Proposed solution --- use the following formula which is precise and > avoids singularities with complex arguments: > > def acosh(x): > return 2.0*log(sqrt(x+1.0) + sqrt(x-1.0)) - log(2.0) > > 2. The function cmath.sinh does not handle moderately large > arguments. For example: > > >>> cmath.asinh(cmath.sinh(20.0)) > (1.#INF+0j) > > Proposed solution: > > Use the textbook formula: > def asinh(x): > return log(x+sqrt(x*x+1.0)) > > This calculation is more limited then the acosh calculation, but > still works fine. We're just using the VC++ C library. I suggest you send your bug report to Microsoft. --Guido van Rossum (home page: http://www.python.org/~guido/)
msg773 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-08-01 21:15
From: "David Ascher" <DavidA@ActiveState.com> Subject: RE: [Python-bugs-list] Inverse hyperbolic functions in cmath module (PR#231) Date: Fri, 10 Mar 2000 16:47:23 -0800 > We're just using the VC++ C library. I suggest you send your bug > report to Microsoft. FWIW: the Perl folks are more and more (it seems to me) redoing things themselves if the C library tends to be broken or slow. I'm not suggesting that it's a good decision, just commenting. --david
msg774 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-08-01 21:15
From: "Tim Peters" <tim_one@email.msn.com> Subject: RE: [Python-bugs-list] Inverse hyperbolic functions in cmath module (PR#231) Date: Fri, 10 Mar 2000 22:05:07 -0500 [Nadav Horesh, suggests different algorithms in cmath, for some complex inverse hyperbolics] [Guido, misfires] > We're just using the VC++ C library. C doesn't define any functions on complex numbers -- cmathmodule.c implements these all on its own. I can't make time to look at this now, but complaining to Microsoft about this will do Nadav even less good than when it *is* their problem .
msg775 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-08-01 21:15
From: "David Ascher" <DavidA@ActiveState.com> Subject: RE: [Python-bugs-list] Inverse hyperbolic functions in cmath module (PR#231) Date: Fri, 10 Mar 2000 21:49:27 -0800 > [Nadav Horesh, suggests different algorithms in cmath, for some complex > inverse hyperbolics] > > [Guido, misfires] > > We're just using the VC++ C library. > > C doesn't define any functions on complex numbers -- cmathmodule.c > implements these all on its own. I can't make time to look at > this now, but > complaining to Microsoft about this will do Nadav even less good than when > it *is* their problem . As an aside, if anyone ever wants to trim the number of builtin C modules, I found that it was much easier to write cmath.py than to write cmath.java (for JPython). The same cmath.py should work fine in CPython. I can dig it up, but I can't swear that I used the most numerically stable algorithms. It did give the same numbers as CPython's cmath on a test set. -david
msg776 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-08-01 21:15
From: "Tim Peters" <tim_one@email.msn.com> Subject: RE: [Python-bugs-list] Inverse hyperbolic functions in cmath module (PR#231) Date: Sat, 11 Mar 2000 13:47:25 -0500 [Tim] > C doesn't define any functions on complex numbers -- cmathmodule.c > implements these all on its own. [David Ascher] > As an aside, if anyone ever wants to trim the number of builtin C > modules, I found that it was much easier to write cmath.py than to > write cmath.java (for JPython). The same cmath.py should work fine > in CPython. Yes, I don't see anything in cmathmodule.c that *needs* to be coded in C; & coding would be much clearer in Python, using infix notation for the basic complex binary ops. Two possible reasons for leaving it in C: 1. Lower internal call overheads (i.e., speed). 2. Improving quality -- complex libraries are very difficult to get right in all cases if they're made IEEE-754 aware, and doing so requires fiddling with the processor-level 754 control & status features. But there's no portable way to do that now, and won't be until the next iteration of C. > I can dig it up, but I can't swear that I used the most numerically stable > algorithms. I can: you didn't . Doesn't matter, though! cmathmodule.c is naive too, and achieving good accuracy across the whole domain is a major undertaking. That gives the best reason to write it in Python: 3. There's a long way to go to make this "industrial strength", so the current cmath is really just a prototype. Everyone knows prototyping is much easier in Python. QED . > It did give the same numbers as CPython's cmath on a test set. So ship it .
msg777 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-08-01 21:15
Might be a good idea. Waiting for patches.
msg778 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2000-08-02 00:38
I think this bug should be left open, but perhaps a new bug should be created for the general feature request "re-write cmath in python." It's up to you, Tim.
msg779 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2000-12-12 20:54
I've added this feature request to PEP 42.
msg780 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2000-12-13 02:28
Hmm! According to CVS, Guido checked in Nadav's changes at the end of June, cmathmodule.c rev 2.13. Changing to Closed and Fixed accordingly.
History
Date User Action Args
2022-04-10 16:02:14 admin set github: 32839
2000-08-01 21:15:00 anonymous create