7 #include "cln/complex.h"
18 // Wert und Branch Cuts nach der Formel CLTL2, S. 313:
19 // arsinh(z) = log(z+sqrt(1+z^2))
20 // z=x+iy, Ergebnis u+iv.
21 // Falls x=0 und y=0: u=0, v=0.
22 // Falls x=0: arsinh(iy) = i arcsin(y).
24 // Bei y=1: u = 0, v = pi/2.
25 // Bei y=1/2: u = 0, v = pi/6.
26 // Bei y=0: u = 0, v = 0.
27 // Bei y=-1/2: u = 0, v = -pi/6.
28 // Bei y=-1: u = 0, v = -pi/2.
29 // Sonst y in Float umwandeln.
30 // e := Exponent aus (decode-float y), d := (float-digits y)
31 // Bei y=0.0 oder e<=-d/2 liefere u = 0, v = y
32 // (denn bei e<=-d/2 ist y^2/3 < y^2/2 < 2^(-d)/2 = 2^(-d-1), also
33 // 1 <= asin(y)/y < 1+y^2/3 < 1+2^(-d-1) < 1+2^(-d),
34 // also ist asin(y)/y, auf d Bits gerundet, gleich 1.0).
36 // Bei y>1 liefere u = ln(y+sqrt(y^2-1)), v = pi/2.
37 // Bei y<-1 liefere u = -ln(|y|+sqrt(|y|^2-1)), v = -pi/2.
38 // Bei |y|<=1 liefere u = 0, v = atan(X=sqrt(1-y^2),Y=y).
40 // x rational -> x in Float umwandeln.
41 // |x|<1/2: u = atanh(x/sqrt(1+x^2)),
42 // x>=1/2: u = ln(x+sqrt(1+x^2)),
43 // x<=-1/2: u = -ln(-x+sqrt(1+x^2)).
46 // z in Bild(sqrt) -> log(sqrt(1+z^2)+z) = (!) = 2 artanh(z/(1+sqrt(1+z^2))).
47 // z nicht in Bild(sqrt) ->
48 // arsinh(z) = -arsinh(-z).
49 // (Denn arsinh(z)+arsinh(-z) == log((z+sqrt(1+z^2))(-z+sqrt(1+z^2)))
50 // = log((1+z^2)-z^2) = log(1) = 0 mod 2 pi i, und links ist
51 // der Imaginärteil betragsmäßig <=pi.)
52 // Also arsinh(z) = -arsinh(-z) = - 2 artanh(-z/(1+sqrt(1+z^2)))
53 // = (wegen -artanh(-w) = artanh(w)) = 2 artanh(z/(1+sqrt(1+z^2))).
54 // Real- und Imaginärteil des Ergebnisses sind Floats, außer wenn z reell oder
57 // Um für zwei Zahlen u,v mit u^2-v^2=1 und u,v beide in Bild(sqrt)
58 // (d.h. Realteil>0.0 oder Realteil=0.0 und Imaginärteil>=0.0)
59 // log(u+v) zu berechnen:
60 // log(u+v) = 2 artanh(v/(u+1)) (!)
61 // (Beweis: 2 artanh(v/(u+1)) = log(1+(v/(u+1))) - log(1-(v/(u+1)))
62 // = log((1+u+v)/(u+1)) - log((1+u-v)/(u+1)) == log((1+u+v)/(1+u-v))
63 // = log(u+v) mod 2 pi i, und beider Imaginärteil ist > -pi und <= pi.)
65 inline const cl_C_R _asinh (const cl_N& z)
72 return asinh(realpart(z),imagpart(z));
76 const cl_N asinh (const cl_N& z)
78 var cl_C_R u_v = _asinh(z);
79 var cl_R& u = u_v.realpart;
80 var cl_R& v = u_v.imagpart;