
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}
(FPCore (re im) :precision binary64 (if (<= (+ re (sqrt (+ (* re re) (* im im)))) 0.0) (* 0.5 (sqrt (* (pow (* im (/ (sqrt 2.0) re)) 2.0) (* re -0.5)))) (sqrt (* 0.5 (+ re (hypot re im))))))
double code(double re, double im) {
double tmp;
if ((re + sqrt(((re * re) + (im * im)))) <= 0.0) {
tmp = 0.5 * sqrt((pow((im * (sqrt(2.0) / re)), 2.0) * (re * -0.5)));
} else {
tmp = sqrt((0.5 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if ((re + Math.sqrt(((re * re) + (im * im)))) <= 0.0) {
tmp = 0.5 * Math.sqrt((Math.pow((im * (Math.sqrt(2.0) / re)), 2.0) * (re * -0.5)));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if (re + math.sqrt(((re * re) + (im * im)))) <= 0.0: tmp = 0.5 * math.sqrt((math.pow((im * (math.sqrt(2.0) / re)), 2.0) * (re * -0.5))) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (Float64(re + sqrt(Float64(Float64(re * re) + Float64(im * im)))) <= 0.0) tmp = Float64(0.5 * sqrt(Float64((Float64(im * Float64(sqrt(2.0) / re)) ^ 2.0) * Float64(re * -0.5)))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re + sqrt(((re * re) + (im * im)))) <= 0.0) tmp = 0.5 * sqrt((((im * (sqrt(2.0) / re)) ^ 2.0) * (re * -0.5))); else tmp = sqrt((0.5 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[Sqrt[N[(N[Power[N[(im * N[(N[Sqrt[2.0], $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(re * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re + \sqrt{re \cdot re + im \cdot im} \leq 0:\\
\;\;\;\;0.5 \cdot \sqrt{{\left(im \cdot \frac{\sqrt{2}}{re}\right)}^{2} \cdot \left(re \cdot -0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 10.0%
sqr-neg10.0%
+-commutative10.0%
sqr-neg10.0%
+-commutative10.0%
distribute-rgt-in10.0%
cancel-sign-sub10.0%
distribute-rgt-out--10.0%
sub-neg10.0%
remove-double-neg10.0%
+-commutative10.0%
hypot-define17.0%
Simplified17.0%
hypot-define10.0%
distribute-lft-in10.0%
+-commutative10.0%
*-commutative10.0%
add-sqr-sqrt5.5%
fma-define2.8%
hypot-define2.8%
hypot-define9.8%
Applied egg-rr9.8%
Taylor expanded in re around -inf 5.0%
mul-1-neg5.0%
*-commutative5.0%
distribute-rgt-neg-in5.0%
unpow25.0%
rem-square-sqrt10.0%
associate-+r-40.6%
unpow240.6%
rem-square-sqrt40.9%
associate-*r/40.9%
metadata-eval40.9%
Simplified40.9%
+-rgt-identity40.9%
distribute-rgt-neg-out40.9%
neg-sub040.9%
*-commutative40.9%
associate-*l*41.0%
add-sqr-sqrt40.9%
pow240.9%
sqrt-prod40.9%
sqrt-pow147.1%
metadata-eval47.1%
pow147.1%
sqrt-div47.0%
sqrt-pow155.9%
metadata-eval55.9%
pow155.9%
Applied egg-rr55.9%
neg-sub055.9%
distribute-rgt-neg-in55.9%
distribute-lft-neg-in55.9%
metadata-eval55.9%
Simplified55.9%
if 0.0 < (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 43.1%
sqr-neg43.1%
+-commutative43.1%
sqr-neg43.1%
+-commutative43.1%
distribute-rgt-in43.1%
cancel-sign-sub43.1%
distribute-rgt-out--43.1%
sub-neg43.1%
remove-double-neg43.1%
+-commutative43.1%
hypot-define91.2%
Simplified91.2%
*-commutative91.2%
hypot-define43.1%
+-commutative43.1%
*-commutative43.1%
add-sqr-sqrt42.8%
sqrt-unprod43.1%
*-commutative43.1%
*-commutative43.1%
swap-sqr43.1%
Applied egg-rr91.2%
*-commutative91.2%
associate-*r*91.2%
metadata-eval91.2%
Simplified91.2%
Final simplification84.9%
(FPCore (re im) :precision binary64 (if (<= (sqrt (* (+ re (sqrt (+ (* re re) (* im im)))) 2.0)) 0.0) (* 0.5 (sqrt (/ (pow im 2.0) (- re)))) (sqrt (* 0.5 (+ re (hypot re im))))))
double code(double re, double im) {
double tmp;
if (sqrt(((re + sqrt(((re * re) + (im * im)))) * 2.0)) <= 0.0) {
tmp = 0.5 * sqrt((pow(im, 2.0) / -re));
} else {
tmp = sqrt((0.5 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.sqrt(((re + Math.sqrt(((re * re) + (im * im)))) * 2.0)) <= 0.0) {
tmp = 0.5 * Math.sqrt((Math.pow(im, 2.0) / -re));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt(((re + math.sqrt(((re * re) + (im * im)))) * 2.0)) <= 0.0: tmp = 0.5 * math.sqrt((math.pow(im, 2.0) / -re)) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(Float64(re + sqrt(Float64(Float64(re * re) + Float64(im * im)))) * 2.0)) <= 0.0) tmp = Float64(0.5 * sqrt(Float64((im ^ 2.0) / Float64(-re)))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (sqrt(((re + sqrt(((re * re) + (im * im)))) * 2.0)) <= 0.0) tmp = 0.5 * sqrt(((im ^ 2.0) / -re)); else tmp = sqrt((0.5 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision], 0.0], N[(0.5 * N[Sqrt[N[(N[Power[im, 2.0], $MachinePrecision] / (-re)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{\left(re + \sqrt{re \cdot re + im \cdot im}\right) \cdot 2} \leq 0:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{{im}^{2}}{-re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 12.1%
sqr-neg12.1%
+-commutative12.1%
sqr-neg12.1%
+-commutative12.1%
distribute-rgt-in12.1%
cancel-sign-sub12.1%
distribute-rgt-out--12.1%
sub-neg12.1%
remove-double-neg12.1%
+-commutative12.1%
hypot-define12.1%
Simplified12.1%
Taylor expanded in re around -inf 51.9%
mul-1-neg51.9%
distribute-neg-frac251.9%
Simplified51.9%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 41.5%
sqr-neg41.5%
+-commutative41.5%
sqr-neg41.5%
+-commutative41.5%
distribute-rgt-in41.5%
cancel-sign-sub41.5%
distribute-rgt-out--41.5%
sub-neg41.5%
remove-double-neg41.5%
+-commutative41.5%
hypot-define89.4%
Simplified89.4%
*-commutative89.4%
hypot-define41.5%
+-commutative41.5%
*-commutative41.5%
add-sqr-sqrt41.2%
sqrt-unprod41.5%
*-commutative41.5%
*-commutative41.5%
swap-sqr41.5%
Applied egg-rr89.4%
*-commutative89.4%
associate-*r*89.4%
metadata-eval89.4%
Simplified89.4%
Final simplification83.8%
(FPCore (re im) :precision binary64 (sqrt (* 0.5 (+ re (hypot re im)))))
double code(double re, double im) {
return sqrt((0.5 * (re + hypot(re, im))));
}
public static double code(double re, double im) {
return Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
def code(re, im): return math.sqrt((0.5 * (re + math.hypot(re, im))))
function code(re, im) return sqrt(Float64(0.5 * Float64(re + hypot(re, im)))) end
function tmp = code(re, im) tmp = sqrt((0.5 * (re + hypot(re, im)))); end
code[re_, im_] := N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}
\end{array}
Initial program 37.1%
sqr-neg37.1%
+-commutative37.1%
sqr-neg37.1%
+-commutative37.1%
distribute-rgt-in37.1%
cancel-sign-sub37.1%
distribute-rgt-out--37.1%
sub-neg37.1%
remove-double-neg37.1%
+-commutative37.1%
hypot-define77.9%
Simplified77.9%
*-commutative77.9%
hypot-define37.1%
+-commutative37.1%
*-commutative37.1%
add-sqr-sqrt36.9%
sqrt-unprod37.1%
*-commutative37.1%
*-commutative37.1%
swap-sqr37.1%
Applied egg-rr77.9%
*-commutative77.9%
associate-*r*77.9%
metadata-eval77.9%
Simplified77.9%
(FPCore (re im) :precision binary64 (if (<= re 1.4e-13) (sqrt (* im 0.5)) (sqrt re)))
double code(double re, double im) {
double tmp;
if (re <= 1.4e-13) {
tmp = sqrt((im * 0.5));
} else {
tmp = sqrt(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 1.4d-13) then
tmp = sqrt((im * 0.5d0))
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 1.4e-13) {
tmp = Math.sqrt((im * 0.5));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.4e-13: tmp = math.sqrt((im * 0.5)) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.4e-13) tmp = sqrt(Float64(im * 0.5)); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.4e-13) tmp = sqrt((im * 0.5)); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.4e-13], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.4 \cdot 10^{-13}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < 1.4000000000000001e-13Initial program 37.0%
sqr-neg37.0%
+-commutative37.0%
sqr-neg37.0%
+-commutative37.0%
distribute-rgt-in37.0%
cancel-sign-sub37.0%
distribute-rgt-out--37.0%
sub-neg37.0%
remove-double-neg37.0%
+-commutative37.0%
hypot-define70.2%
Simplified70.2%
Taylor expanded in re around 0 29.0%
associate-*r*29.0%
Simplified29.0%
add-sqr-sqrt28.8%
pow228.8%
associate-*l*28.8%
sqrt-unprod28.9%
Applied egg-rr28.9%
unpow228.9%
sqrt-unprod29.2%
*-commutative29.2%
*-commutative29.2%
swap-sqr29.2%
add-sqr-sqrt29.2%
metadata-eval29.2%
Applied egg-rr29.2%
associate-*l*29.2%
metadata-eval29.2%
Simplified29.2%
if 1.4000000000000001e-13 < re Initial program 37.6%
sqr-neg37.6%
+-commutative37.6%
sqr-neg37.6%
+-commutative37.6%
distribute-rgt-in37.6%
cancel-sign-sub37.6%
distribute-rgt-out--37.6%
sub-neg37.6%
remove-double-neg37.6%
+-commutative37.6%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 74.8%
*-commutative74.8%
unpow274.8%
rem-square-sqrt76.3%
associate-*r*76.3%
metadata-eval76.3%
Simplified76.3%
Final simplification41.3%
(FPCore (re im) :precision binary64 (sqrt (* im 0.5)))
double code(double re, double im) {
return sqrt((im * 0.5));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((im * 0.5d0))
end function
public static double code(double re, double im) {
return Math.sqrt((im * 0.5));
}
def code(re, im): return math.sqrt((im * 0.5))
function code(re, im) return sqrt(Float64(im * 0.5)) end
function tmp = code(re, im) tmp = sqrt((im * 0.5)); end
code[re_, im_] := N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{im \cdot 0.5}
\end{array}
Initial program 37.1%
sqr-neg37.1%
+-commutative37.1%
sqr-neg37.1%
+-commutative37.1%
distribute-rgt-in37.1%
cancel-sign-sub37.1%
distribute-rgt-out--37.1%
sub-neg37.1%
remove-double-neg37.1%
+-commutative37.1%
hypot-define77.9%
Simplified77.9%
Taylor expanded in re around 0 25.2%
associate-*r*25.2%
Simplified25.2%
add-sqr-sqrt25.1%
pow225.1%
associate-*l*25.1%
sqrt-unprod25.2%
Applied egg-rr25.2%
unpow225.2%
sqrt-unprod25.4%
*-commutative25.4%
*-commutative25.4%
swap-sqr25.4%
add-sqr-sqrt25.4%
metadata-eval25.4%
Applied egg-rr25.4%
associate-*l*25.4%
metadata-eval25.4%
Simplified25.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (+ (* re re) (* im im)))))
(if (< re 0.0)
(* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- t_0 re)))))
(* 0.5 (sqrt (* 2.0 (+ t_0 re)))))))
double code(double re, double im) {
double t_0 = sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((re * re) + (im * im)))
if (re < 0.0d0) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(((im * im) / (t_0 - re))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (t_0 + re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt(((re * re) + (im * im))) tmp = 0 if re < 0.0: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(((im * im) / (t_0 - re)))) else: tmp = 0.5 * math.sqrt((2.0 * (t_0 + re))) return tmp
function code(re, im) t_0 = sqrt(Float64(Float64(re * re) + Float64(im * im))) tmp = 0.0 if (re < 0.0) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(Float64(im * im) / Float64(t_0 - re))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(t_0 + re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt(((re * re) + (im * im))); tmp = 0.0; if (re < 0.0) tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re)))); else tmp = 0.5 * sqrt((2.0 * (t_0 + re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[re, 0.0], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(N[(im * im), $MachinePrecision] / N[(t$95$0 - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(t$95$0 + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{re \cdot re + im \cdot im}\\
\mathbf{if}\;re < 0:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{t\_0 - re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(t\_0 + re\right)}\\
\end{array}
\end{array}
herbie shell --seed 2024101
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:alt
(if (< re 0.0) (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))