From:  Andrew Sengul <ml@scenariotech.invalid>
Date:  12 Oct 2020 10:55:39 Hong Kong Time
Newsgroup:  news.alt119.net/comp.lang.apl
Subject:  

Re: Problem with Dyalog's arctanh function?

NNTP-Posting-Host:  null

On 10/11/20 9:45 AM, eki...@gmail.com wrote:
> On Sunday, October 11, 2020 at 12:29:47 PM UTC-4, eki...@gmail.com wrote:
>> On Saturday, October 10, 2020 at 6:24:33 PM UTC-4, Sam Sirlin wrote: 
>>> On Friday, October 9, 2020 at 5:37:44 AM UTC-7, Andrew Sengul wrote: 
>>>> In Dyalog: 
>>>> ¯7○¯2 
>>>> 0.5493061443J¯1.570796327 
>>>>
>>>> In GNU APL: 
>>>> ¯7○¯2 
>>>> ¯0.5493061443J1.570796327 
>>>>
>>>> In Common Lisp: 
>>>> * (atanh -2) 
>>>> #C(-0.54930615 1.5707964) 
>>>>
>>>> In Wolfram Alpha: 
>>>> arctanh(-2) 
>>>>
>>>> Decimal approximation: 
>>>>
>>>> -0.54930614433405484569762261846126285232374527891137472586734716... + 
>>>> 1.5707963267948966192313216916397514420985846996875529104874722... i 
>>>>
>>>> Why is Dyalog's result negated and conjugated? 
>>>>
>>>> Andrew 
>>> A Bug. Is the tanh of the result correct? In J 
>>>
>>> _7 o. _2 
>>> _0.549306j1.5708 
>>> a=. _7 o. _2 
>>> 7 o. a 
>>> _2 
>>> 7 o. -a 
>>> 2 
>>>
>>> Also in octave: 
>>>
>>> octave:2> a = atanh(-2) 
>>> a = -5.4931e-01 + 1.5708e+00i 
>>> octave:3> tanh(a) 
>>> ans = -2.0000e+00 + 1.8370e-16i 
>>> octave:4> tanh(-a) 
>>> ans = 2.0000e+00 - 1.8370e-16i 
>>>
>>> Note there is ambiguity on the imaginary part: 
>>>
>>> octave:12> A = log( 1/sqrt(3)) 
>>> A = -5.4931e-01 
>>> octave:16> tanh( A + i*pi/2) 
>>> ans = -2.0000e+00 + 1.8370e-16i 
>>> octave:17> tanh( A - i*pi/2) 
>>> ans = -2.0000e+00 - 1.8370e-16i
>> Circular and hyperbolic functions are all periodic, so for each such function f , 
>> there are infinitely many choice for f x for each x. The same is true (in the complex 
>> plane) for the exponential function. It's not possible to define inverses for these 
>> functions that are both single valued and continuous on the complex plane. It is 
>> possible, though too specify where the discontinuities should be, and what values 
>> should be taken at points of discontinuity, in a way that is consistent across all 
>> the inverses. 
>>
>> IIRC the APL Extended standard follows Paul Penfield's APL 81 paper "Principal 
>> values and branch cuts in complex APL" in specifying how these choice are to be 
>> made, where the discontinuities should be and values at the points of discontinuity. 
>> There is a long discussion (which cites and is largely based on the Penfield paper), 
>> with illustrations, in Guy Steele's "Common Lisp, The Language (2nd Ed.)", 
>> at section 12.5.3. 
>>
>> IMHO the J implementation is almost certainly correct, because ... Roger.
> 
> Or maybe not, since J and CL differ.
> 
J and CL are the same: negative real part, positive imaginary.