On 10/27/2020 3:58 PM, Roger Hui wrote:
> The Dyalog implementation follows Penfield 1981 (_Principal Values and Branch Cuts in Complex APL_,
https://doi.org/10.1145/800142.805368), equation 12:
>
> arctanh←{⍟(1+⍵)×(÷1-⍵*2)*0.5}
>
> arctanh ¯2
> ¯0.5493061443J¯1.570796327
>
> ¯7 ○ ¯2
> ¯0.5493061443J¯1.570796327
There is some disagreement about Paul Penfield's choice in his 1981
paper of branch cut direction (CW vs. CCW) on arctan (and by extension,
arctanh) with which I agree. For a more detailed analysis, see Kahan[1]
(search for "APL") and Steele[2].
The latter reference recommends the definitions
atan ←{((⍟1+⍵×0J1)-⍟1-⍵×0J1)÷0J2}
atanh←{((⍟1+⍵ )-⍟1-⍵ )÷ 2}
More importantly, note that Steele[2] ends with the following sentence:
"Paul Penfield of MIT, after whose article the Common Lisp branch cuts
were originally patterned, endorses this change."
If you accept the argument to use the other branch cut direction on both
arctan and arctanh, then the above formulation of arctanh yields
atanh ¯2
¯0.5493061443J1.570796327
which produces the result (on the positive imaginary axis) chosen by
various implementations including NARS2000, APL2, GNU APL, J, Common
Lisp, GSL, MPC, Octave, and Wolfram Alpha. One small reason I prefer
the form in atanh is that it doesn't rely upon the default choice of the
positive result of square root that arctanh uses, but this is not a big
deal.
I don't know the rationale behind other implementations, but this is why
NARS2000 produces that result.
References
[1] Kahan, W. "Branch Cuts for Complex Elementary
Functions, or Much Ado About Nothing's Sign Bit"
in Iserles and Powell (eds.) "The State of the Art
in Numerical Analysis", pp. 165-211, Clarendon
Press, 1987,
https://people.freebsd.org/~das/kahan86branch.pdf
[2] Steele, "Complex ATAN Branch Cut"
http://clhs.lisp.se/Issues/iss069_w.htm
--
_________________________________________
Bob Smith --
bsm...@sudleydeplacespam.com
http://www.sudleyplace.com -
http://www.nars2000.org
To reply to me directly, delete "despam".