Open postmath opened 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.
And of course for the second and third formula, it's better to use acos(1/x) and asin(1/x), respectively.
+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.
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.
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 + ...).
It would be nice to have:
for both
arb_t
andacb_t
. We might want to use asymptotic series nearx=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.