flintlib / arb

Arb has been merged into FLINT -- use https://github.com/flintlib/flint/ instead
http://arblib.org/
GNU Lesser General Public License v2.1
457 stars 137 forks source link

Implement the 6 missing inverse trig and inverse hyperbolic functions #411

Open postmath opened 2 years ago

postmath commented 2 years ago

It would be nice to have:

for both arb_t and acb_t. We might want to use asymptotic series near x=0 for all except the arccotangent, and a series near the zeroes of the arctrigs, and otherwise use the definition above, or something like that.

postmath commented 2 years ago

Of course we don't need the series near 0 because none of those functions are continuous there. And I see that arb_acos is implemented by just computing pi/2 minus the expression for arb_asin, so we can do a similar thing for all of these. That would make it relatively little work: just a straightforward implementation of the formulas here.

postmath commented 2 years ago

And of course for the second and third formula, it's better to use acos(1/x) and asin(1/x), respectively.

fredrik-johansson commented 2 years ago

+1

I believe all cases of these functions can be implemented in numerically stable ways in terms of the existing functions. Of course for the complex versions one has to be careful with branch cuts.

postmath commented 2 years ago

Ugh. I looked into this a little bit more and found something ugly.

The DLMF defines acot, asec, and acsc in https://dlmf.nist.gov/4.23:

It defined acoth, asech, and acsch in https://dlmf.nist.gov/4.37:

This is the same as what I (eventually) wrote above except for the arccotangent... and that's where the rub is. I realize now that there are two common definitions of the arccotangent, and they differ even on the (negative) real numbers. The DLMF definition is also used by Mathematica, gsl, julia, and your own mpmath in Python. The other definition is used on the wikipedia page and the ISO 80000 standard (which discusses the function only in terms of real numbers). So it seems that it might be most appropriate to use the DLMF definitions here.

postmath commented 1 year ago

One correction: acoth(x) is continuous at x=0, at least within the half planes Im(x) >= 0 and Im(x) < 0. For Im(x) >= 0, it behaves like pi * i / 2 + x + x^3/3 + x^5/5 + ...; for Im(x) < 0, the sign of the constant term is opposite. The other five all diverge to some form of infinity at x=0 (unless you use the wikipedia/ISO 80000/Maple definition of acot(x); then that one is also continuous and it behaves like pi/2 - x + x^3/3 - x^5/5 + ...).