arctanh
02-25-2024, 05:23 PM
Post: #1
 robmio Member Posts: 172 Joined: Jan 2020
arctanh
Good morning everyone, I discovered that the results of "arctanh" in Home and in CAS are different. For example:

arctanh(2) = ln(3)/2 - i*pi/2 --> Home
arctanh(2) = ln(3)/2 + i*pi/2 --> CAS.

Can anyone clarify this fact?
02-26-2024, 07:17 AM (This post was last modified: 02-26-2024 07:25 AM by hp-zl.)
Post: #2
 hp-zl Junior Member Posts: 15 Joined: May 2023
RE: arctanh
Because it's the same.
This follows from the definition of logarithm for complex numbers.
The complex part is k*fi, where k is any integer.
Enter e.g. tanh( ln(3)/2 - i*pi/2*5) and press Shift-Enter - you will get 2.

Regards.

PS.
Ln(r *exp(i*fi) = ln r + i*(fi + 2*k*pi)
02-26-2024, 01:56 PM
Post: #3
 Albert Chan Senior Member Posts: 2,704 Joined: Jul 2018
RE: arctanh
(02-26-2024 07:17 AM)hp-zl Wrote:  Enter e.g. tanh( ln(3)/2 - i*pi/2*5) and press Shift-Enter - you will get 2.

atanh(z) only return principal value, above does not imply its reverse is true.
(same reason (-1)^2 = 1 does not imply sqrt(1) = -1)

With signed zero, atanh argument real/imag part sign matched its result.

atanh(2 ± 0i) = ln(3)/2 ± (pi/2)*i

We get 2 answers because HP Prime does not have signed zero.
There is a discontinuity with "true" 0 imag part, its limit does not exist.

Cas> atanh(2+1e-10*i)      → 0.549306144334+1.57079632676*i
Cas> atanh(2−1e-10*i)      → 0.549306144334−1.57079632676*i

We may arbitrarily pick a side for this slit, as long as it is applied consistently.
The side picked at the slit depends on formula used.

atanh(z) = 1/2 * ln( (1+z)/(1-z) )         // XCas atanh
atanh(2) = 1/2 * ln(3/-1) = 1/2 * (ln(3) + pi*i) = ln(3)/2 + pi/2*i

atanh(z) = 1/2 * (ln(1+z) - ln(1-z))      // mpmath mpc_atanh
atanh(2) = 1/2 * (ln(3) - ln(-1)) = 1/2 * (ln(3) - pi*i) = ln(3)/2 - pi/2*i

Again, without signed zero, there is no right answer, it is just an arbitrary pick.
02-27-2024, 02:10 PM
Post: #4
 Albert Chan Senior Member Posts: 2,704 Joined: Jul 2018
RE: arctanh
(02-26-2024 01:56 PM)Albert Chan Wrote:  With signed zero, atanh argument real/imag part sign matched its result.

Prove: (note: with signed zero, sign(x) = ±1)

atanh(z) = 1/2 * ln( (1+z)/(1-z) )

Let z = (x, y)

(1+z)/(1-z) = (1+x, y) / (1-x, -y) = ((1+x)*(1-x)-y^2, 2y) / ((1-x)^2 + y^2) = t / b

im(atanh(z)) = 1/2 * arg(t), with range = sign(y) * (0 .. pi/2)

--> sign(im(atanh(z))) = sign(y)

b = (1-x)^2 + y^2 = (1+x^2+y^2) - 2x
t = ((1+x)*(1-x)-y^2, 2y) = (2-(1+x^2+y^2), 2y) = (-b+2*(1-x), 2y)

re(atanh(z))
= 1/2 * ln(|t/b|)
= 1/4 * ln(|t|^2 / b^2)
= 1/4 * ln((b^2 - 4b*(1-x) + 4*(1-x)^2 + 4y^2) / b^2)
= 1/4 * ln((b^2 - 4b*(1-x) + 4b) / b^2)
= 1/4 * ln((b^2 + 4b*x) / b^2)
= 1/4 * log1p(4x/b)

--> sign(re(atanh(z))) = sign(x)

Bonus, this gives Kahan's accurate catanh algorithm
Bonus, we get atan(z) algorithm for free, atan(z) = swap(atanh(swap(z)))
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)