
(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 7 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}
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* 0.5 (* (* im_m (sqrt (/ -0.5 re))) (sqrt 2.0)))))
(if (<= re -6.7e-25)
t_0
(if (<= re -1.8e-76)
(sqrt (* 0.5 im_m))
(if (<= re -2.2e-81) t_0 (sqrt (* 0.5 (+ re (hypot re im_m)))))))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = 0.5 * ((im_m * sqrt((-0.5 / re))) * sqrt(2.0));
double tmp;
if (re <= -6.7e-25) {
tmp = t_0;
} else if (re <= -1.8e-76) {
tmp = sqrt((0.5 * im_m));
} else if (re <= -2.2e-81) {
tmp = t_0;
} else {
tmp = sqrt((0.5 * (re + hypot(re, im_m))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double t_0 = 0.5 * ((im_m * Math.sqrt((-0.5 / re))) * Math.sqrt(2.0));
double tmp;
if (re <= -6.7e-25) {
tmp = t_0;
} else if (re <= -1.8e-76) {
tmp = Math.sqrt((0.5 * im_m));
} else if (re <= -2.2e-81) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im_m))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): t_0 = 0.5 * ((im_m * math.sqrt((-0.5 / re))) * math.sqrt(2.0)) tmp = 0 if re <= -6.7e-25: tmp = t_0 elif re <= -1.8e-76: tmp = math.sqrt((0.5 * im_m)) elif re <= -2.2e-81: tmp = t_0 else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im_m)))) return tmp
im_m = abs(im) function code(re, im_m) t_0 = Float64(0.5 * Float64(Float64(im_m * sqrt(Float64(-0.5 / re))) * sqrt(2.0))) tmp = 0.0 if (re <= -6.7e-25) tmp = t_0; elseif (re <= -1.8e-76) tmp = sqrt(Float64(0.5 * im_m)); elseif (re <= -2.2e-81) tmp = t_0; else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im_m)))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) t_0 = 0.5 * ((im_m * sqrt((-0.5 / re))) * sqrt(2.0)); tmp = 0.0; if (re <= -6.7e-25) tmp = t_0; elseif (re <= -1.8e-76) tmp = sqrt((0.5 * im_m)); elseif (re <= -2.2e-81) tmp = t_0; else tmp = sqrt((0.5 * (re + hypot(re, im_m)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[(N[(im$95$m * N[Sqrt[N[(-0.5 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -6.7e-25], t$95$0, If[LessEqual[re, -1.8e-76], N[Sqrt[N[(0.5 * im$95$m), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, -2.2e-81], t$95$0, N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(\left(im\_m \cdot \sqrt{\frac{-0.5}{re}}\right) \cdot \sqrt{2}\right)\\
\mathbf{if}\;re \leq -6.7 \cdot 10^{-25}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq -1.8 \cdot 10^{-76}:\\
\;\;\;\;\sqrt{0.5 \cdot im\_m}\\
\mathbf{elif}\;re \leq -2.2 \cdot 10^{-81}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\
\end{array}
\end{array}
if re < -6.70000000000000032e-25 or -1.8e-76 < re < -2.1999999999999999e-81Initial program 12.8%
sqr-neg12.8%
+-commutative12.8%
sqr-neg12.8%
+-commutative12.8%
distribute-rgt-in12.8%
cancel-sign-sub12.8%
distribute-rgt-out--12.8%
sub-neg12.8%
remove-double-neg12.8%
+-commutative12.8%
Simplified32.0%
*-commutative32.0%
hypot-define12.8%
+-commutative12.8%
sqrt-prod12.7%
+-commutative12.7%
hypot-define31.8%
Applied egg-rr31.8%
Taylor expanded in re around -inf 44.3%
*-commutative44.3%
associate-*l/44.3%
Simplified44.3%
pow1/244.3%
associate-/l*44.3%
unpow-prod-down54.5%
pow1/254.5%
sqrt-pow144.8%
metadata-eval44.8%
pow144.8%
Applied egg-rr44.8%
unpow1/244.8%
Simplified44.8%
if -6.70000000000000032e-25 < re < -1.8e-76Initial program 31.9%
sqr-neg31.9%
+-commutative31.9%
sqr-neg31.9%
+-commutative31.9%
distribute-rgt-in31.9%
cancel-sign-sub31.9%
distribute-rgt-out--31.9%
sub-neg31.9%
remove-double-neg31.9%
+-commutative31.9%
Simplified73.0%
*-commutative73.0%
hypot-define31.9%
+-commutative31.9%
*-commutative31.9%
add-sqr-sqrt31.8%
sqrt-unprod31.9%
*-commutative31.9%
*-commutative31.9%
swap-sqr31.9%
Applied egg-rr73.0%
*-commutative73.0%
associate-*r*73.0%
metadata-eval73.0%
Simplified73.0%
Taylor expanded in re around 0 37.2%
if -2.1999999999999999e-81 < re Initial program 53.8%
sqr-neg53.8%
+-commutative53.8%
sqr-neg53.8%
+-commutative53.8%
distribute-rgt-in53.8%
cancel-sign-sub53.8%
distribute-rgt-out--53.8%
sub-neg53.8%
remove-double-neg53.8%
+-commutative53.8%
Simplified98.8%
*-commutative98.8%
hypot-define53.8%
+-commutative53.8%
*-commutative53.8%
add-sqr-sqrt53.4%
sqrt-unprod53.8%
*-commutative53.8%
*-commutative53.8%
swap-sqr53.8%
Applied egg-rr98.8%
*-commutative98.8%
associate-*r*98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification79.2%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* 0.5 (* im_m (* (sqrt (/ -0.5 re)) (sqrt 2.0))))))
(if (<= re -8.8e-25)
t_0
(if (<= re -7.5e-76)
(sqrt (* 0.5 im_m))
(if (<= re -2.9e-86) t_0 (sqrt (* 0.5 (+ re (hypot re im_m)))))))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = 0.5 * (im_m * (sqrt((-0.5 / re)) * sqrt(2.0)));
double tmp;
if (re <= -8.8e-25) {
tmp = t_0;
} else if (re <= -7.5e-76) {
tmp = sqrt((0.5 * im_m));
} else if (re <= -2.9e-86) {
tmp = t_0;
} else {
tmp = sqrt((0.5 * (re + hypot(re, im_m))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double t_0 = 0.5 * (im_m * (Math.sqrt((-0.5 / re)) * Math.sqrt(2.0)));
double tmp;
if (re <= -8.8e-25) {
tmp = t_0;
} else if (re <= -7.5e-76) {
tmp = Math.sqrt((0.5 * im_m));
} else if (re <= -2.9e-86) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im_m))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): t_0 = 0.5 * (im_m * (math.sqrt((-0.5 / re)) * math.sqrt(2.0))) tmp = 0 if re <= -8.8e-25: tmp = t_0 elif re <= -7.5e-76: tmp = math.sqrt((0.5 * im_m)) elif re <= -2.9e-86: tmp = t_0 else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im_m)))) return tmp
im_m = abs(im) function code(re, im_m) t_0 = Float64(0.5 * Float64(im_m * Float64(sqrt(Float64(-0.5 / re)) * sqrt(2.0)))) tmp = 0.0 if (re <= -8.8e-25) tmp = t_0; elseif (re <= -7.5e-76) tmp = sqrt(Float64(0.5 * im_m)); elseif (re <= -2.9e-86) tmp = t_0; else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im_m)))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) t_0 = 0.5 * (im_m * (sqrt((-0.5 / re)) * sqrt(2.0))); tmp = 0.0; if (re <= -8.8e-25) tmp = t_0; elseif (re <= -7.5e-76) tmp = sqrt((0.5 * im_m)); elseif (re <= -2.9e-86) tmp = t_0; else tmp = sqrt((0.5 * (re + hypot(re, im_m)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[(im$95$m * N[(N[Sqrt[N[(-0.5 / re), $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -8.8e-25], t$95$0, If[LessEqual[re, -7.5e-76], N[Sqrt[N[(0.5 * im$95$m), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, -2.9e-86], t$95$0, N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(im\_m \cdot \left(\sqrt{\frac{-0.5}{re}} \cdot \sqrt{2}\right)\right)\\
\mathbf{if}\;re \leq -8.8 \cdot 10^{-25}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq -7.5 \cdot 10^{-76}:\\
\;\;\;\;\sqrt{0.5 \cdot im\_m}\\
\mathbf{elif}\;re \leq -2.9 \cdot 10^{-86}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\
\end{array}
\end{array}
if re < -8.8000000000000008e-25 or -7.4999999999999997e-76 < re < -2.8999999999999999e-86Initial program 12.8%
sqr-neg12.8%
+-commutative12.8%
sqr-neg12.8%
+-commutative12.8%
distribute-rgt-in12.8%
cancel-sign-sub12.8%
distribute-rgt-out--12.8%
sub-neg12.8%
remove-double-neg12.8%
+-commutative12.8%
Simplified32.0%
*-commutative32.0%
hypot-define12.8%
+-commutative12.8%
sqrt-prod12.7%
+-commutative12.7%
hypot-define31.8%
Applied egg-rr31.8%
Taylor expanded in re around -inf 44.3%
*-commutative44.3%
associate-*l/44.3%
Simplified44.3%
pow144.3%
associate-/l*44.3%
sqrt-prod54.5%
sqrt-pow144.8%
metadata-eval44.8%
pow144.8%
Applied egg-rr44.8%
unpow144.8%
unpow1/244.8%
associate-*l*44.8%
unpow1/244.8%
Simplified44.8%
if -8.8000000000000008e-25 < re < -7.4999999999999997e-76Initial program 31.9%
sqr-neg31.9%
+-commutative31.9%
sqr-neg31.9%
+-commutative31.9%
distribute-rgt-in31.9%
cancel-sign-sub31.9%
distribute-rgt-out--31.9%
sub-neg31.9%
remove-double-neg31.9%
+-commutative31.9%
Simplified73.0%
*-commutative73.0%
hypot-define31.9%
+-commutative31.9%
*-commutative31.9%
add-sqr-sqrt31.8%
sqrt-unprod31.9%
*-commutative31.9%
*-commutative31.9%
swap-sqr31.9%
Applied egg-rr73.0%
*-commutative73.0%
associate-*r*73.0%
metadata-eval73.0%
Simplified73.0%
Taylor expanded in re around 0 37.2%
if -2.8999999999999999e-86 < re Initial program 53.8%
sqr-neg53.8%
+-commutative53.8%
sqr-neg53.8%
+-commutative53.8%
distribute-rgt-in53.8%
cancel-sign-sub53.8%
distribute-rgt-out--53.8%
sub-neg53.8%
remove-double-neg53.8%
+-commutative53.8%
Simplified98.8%
*-commutative98.8%
hypot-define53.8%
+-commutative53.8%
*-commutative53.8%
add-sqr-sqrt53.4%
sqrt-unprod53.8%
*-commutative53.8%
*-commutative53.8%
swap-sqr53.8%
Applied egg-rr98.8%
*-commutative98.8%
associate-*r*98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification79.2%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re -7e+102) (* 0.5 (sqrt (/ (pow im_m 2.0) (- re)))) (sqrt (* 0.5 (+ re (hypot re im_m))))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -7e+102) {
tmp = 0.5 * sqrt((pow(im_m, 2.0) / -re));
} else {
tmp = sqrt((0.5 * (re + hypot(re, im_m))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -7e+102) {
tmp = 0.5 * Math.sqrt((Math.pow(im_m, 2.0) / -re));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im_m))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -7e+102: tmp = 0.5 * math.sqrt((math.pow(im_m, 2.0) / -re)) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im_m)))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -7e+102) tmp = Float64(0.5 * sqrt(Float64((im_m ^ 2.0) / Float64(-re)))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im_m)))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -7e+102) tmp = 0.5 * sqrt(((im_m ^ 2.0) / -re)); else tmp = sqrt((0.5 * (re + hypot(re, im_m)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -7e+102], N[(0.5 * N[Sqrt[N[(N[Power[im$95$m, 2.0], $MachinePrecision] / (-re)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -7 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{{im\_m}^{2}}{-re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\
\end{array}
\end{array}
if re < -7.00000000000000021e102Initial program 8.4%
sqr-neg8.4%
+-commutative8.4%
sqr-neg8.4%
+-commutative8.4%
distribute-rgt-in8.4%
cancel-sign-sub8.4%
distribute-rgt-out--8.4%
sub-neg8.4%
remove-double-neg8.4%
+-commutative8.4%
Simplified26.4%
Taylor expanded in re around -inf 58.1%
mul-1-neg58.1%
distribute-neg-frac258.1%
Simplified58.1%
if -7.00000000000000021e102 < re Initial program 47.0%
sqr-neg47.0%
+-commutative47.0%
sqr-neg47.0%
+-commutative47.0%
distribute-rgt-in47.0%
cancel-sign-sub47.0%
distribute-rgt-out--47.0%
sub-neg47.0%
remove-double-neg47.0%
+-commutative47.0%
Simplified88.1%
*-commutative88.1%
hypot-define47.0%
+-commutative47.0%
*-commutative47.0%
add-sqr-sqrt46.7%
sqrt-unprod47.0%
*-commutative47.0%
*-commutative47.0%
swap-sqr47.0%
Applied egg-rr88.1%
*-commutative88.1%
associate-*r*88.1%
metadata-eval88.1%
Simplified88.1%
Final simplification82.9%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re -2.05e+102) (sqrt (* (pow im_m 2.0) (/ -0.25 re))) (sqrt (* 0.5 (+ re (hypot re im_m))))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -2.05e+102) {
tmp = sqrt((pow(im_m, 2.0) * (-0.25 / re)));
} else {
tmp = sqrt((0.5 * (re + hypot(re, im_m))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -2.05e+102) {
tmp = Math.sqrt((Math.pow(im_m, 2.0) * (-0.25 / re)));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im_m))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -2.05e+102: tmp = math.sqrt((math.pow(im_m, 2.0) * (-0.25 / re))) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im_m)))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -2.05e+102) tmp = sqrt(Float64((im_m ^ 2.0) * Float64(-0.25 / re))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im_m)))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -2.05e+102) tmp = sqrt(((im_m ^ 2.0) * (-0.25 / re))); else tmp = sqrt((0.5 * (re + hypot(re, im_m)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -2.05e+102], N[Sqrt[N[(N[Power[im$95$m, 2.0], $MachinePrecision] * N[(-0.25 / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.05 \cdot 10^{+102}:\\
\;\;\;\;\sqrt{{im\_m}^{2} \cdot \frac{-0.25}{re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}\\
\end{array}
\end{array}
if re < -2.05e102Initial program 8.4%
sqr-neg8.4%
+-commutative8.4%
sqr-neg8.4%
+-commutative8.4%
distribute-rgt-in8.4%
cancel-sign-sub8.4%
distribute-rgt-out--8.4%
sub-neg8.4%
remove-double-neg8.4%
+-commutative8.4%
Simplified26.4%
*-commutative26.4%
hypot-define8.4%
+-commutative8.4%
sqrt-prod8.4%
+-commutative8.4%
hypot-define26.3%
Applied egg-rr26.3%
Taylor expanded in re around -inf 57.8%
*-commutative57.8%
associate-*l/57.8%
Simplified57.8%
add-sqr-sqrt57.6%
sqrt-unprod57.8%
*-commutative57.8%
*-commutative57.8%
swap-sqr57.8%
sqrt-unprod57.9%
sqrt-unprod58.0%
add-sqr-sqrt58.0%
associate-/l*57.9%
associate-*l*57.9%
metadata-eval57.9%
Applied egg-rr57.9%
associate-*l*57.9%
associate-*l/57.9%
metadata-eval57.9%
associate-*l/57.9%
metadata-eval57.9%
Simplified57.9%
if -2.05e102 < re Initial program 47.0%
sqr-neg47.0%
+-commutative47.0%
sqr-neg47.0%
+-commutative47.0%
distribute-rgt-in47.0%
cancel-sign-sub47.0%
distribute-rgt-out--47.0%
sub-neg47.0%
remove-double-neg47.0%
+-commutative47.0%
Simplified88.1%
*-commutative88.1%
hypot-define47.0%
+-commutative47.0%
*-commutative47.0%
add-sqr-sqrt46.7%
sqrt-unprod47.0%
*-commutative47.0%
*-commutative47.0%
swap-sqr47.0%
Applied egg-rr88.1%
*-commutative88.1%
associate-*r*88.1%
metadata-eval88.1%
Simplified88.1%
Final simplification82.8%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (sqrt (* 0.5 (+ re (hypot re im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
return sqrt((0.5 * (re + hypot(re, im_m))));
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return Math.sqrt((0.5 * (re + Math.hypot(re, im_m))));
}
im_m = math.fabs(im) def code(re, im_m): return math.sqrt((0.5 * (re + math.hypot(re, im_m))))
im_m = abs(im) function code(re, im_m) return sqrt(Float64(0.5 * Float64(re + hypot(re, im_m)))) end
im_m = abs(im); function tmp = code(re, im_m) tmp = sqrt((0.5 * (re + hypot(re, im_m)))); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\_m\right)\right)}
\end{array}
Initial program 40.2%
sqr-neg40.2%
+-commutative40.2%
sqr-neg40.2%
+-commutative40.2%
distribute-rgt-in40.2%
cancel-sign-sub40.2%
distribute-rgt-out--40.2%
sub-neg40.2%
remove-double-neg40.2%
+-commutative40.2%
Simplified77.3%
*-commutative77.3%
hypot-define40.2%
+-commutative40.2%
*-commutative40.2%
add-sqr-sqrt40.0%
sqrt-unprod40.2%
*-commutative40.2%
*-commutative40.2%
swap-sqr40.2%
Applied egg-rr77.3%
*-commutative77.3%
associate-*r*77.3%
metadata-eval77.3%
Simplified77.3%
Final simplification77.3%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re 4e-48) (sqrt (* 0.5 im_m)) (sqrt re)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= 4e-48) {
tmp = sqrt((0.5 * im_m));
} else {
tmp = sqrt(re);
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= 4d-48) then
tmp = sqrt((0.5d0 * im_m))
else
tmp = sqrt(re)
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= 4e-48) {
tmp = Math.sqrt((0.5 * im_m));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= 4e-48: tmp = math.sqrt((0.5 * im_m)) else: tmp = math.sqrt(re) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= 4e-48) tmp = sqrt(Float64(0.5 * im_m)); else tmp = sqrt(re); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= 4e-48) tmp = sqrt((0.5 * im_m)); else tmp = sqrt(re); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, 4e-48], N[Sqrt[N[(0.5 * im$95$m), $MachinePrecision]], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq 4 \cdot 10^{-48}:\\
\;\;\;\;\sqrt{0.5 \cdot im\_m}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < 3.9999999999999999e-48Initial program 38.2%
sqr-neg38.2%
+-commutative38.2%
sqr-neg38.2%
+-commutative38.2%
distribute-rgt-in38.2%
cancel-sign-sub38.2%
distribute-rgt-out--38.2%
sub-neg38.2%
remove-double-neg38.2%
+-commutative38.2%
Simplified67.9%
*-commutative67.9%
hypot-define38.2%
+-commutative38.2%
*-commutative38.2%
add-sqr-sqrt38.0%
sqrt-unprod38.2%
*-commutative38.2%
*-commutative38.2%
swap-sqr38.2%
Applied egg-rr67.9%
*-commutative67.9%
associate-*r*67.9%
metadata-eval67.9%
Simplified67.9%
Taylor expanded in re around 0 35.4%
if 3.9999999999999999e-48 < re Initial program 45.1%
sqr-neg45.1%
+-commutative45.1%
sqr-neg45.1%
+-commutative45.1%
distribute-rgt-in45.1%
cancel-sign-sub45.1%
distribute-rgt-out--45.1%
sub-neg45.1%
remove-double-neg45.1%
+-commutative45.1%
Simplified100.0%
*-commutative100.0%
hypot-define45.1%
+-commutative45.1%
*-commutative45.1%
add-sqr-sqrt44.8%
sqrt-unprod45.1%
*-commutative45.1%
*-commutative45.1%
swap-sqr45.1%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
pow1/2100.0%
pow-to-exp92.1%
Applied egg-rr92.1%
Taylor expanded in re around inf 76.8%
Final simplification47.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (sqrt re))
im_m = fabs(im);
double code(double re, double im_m) {
return sqrt(re);
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = sqrt(re)
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return Math.sqrt(re);
}
im_m = math.fabs(im) def code(re, im_m): return math.sqrt(re)
im_m = abs(im) function code(re, im_m) return sqrt(re) end
im_m = abs(im); function tmp = code(re, im_m) tmp = sqrt(re); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[Sqrt[re], $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\sqrt{re}
\end{array}
Initial program 40.2%
sqr-neg40.2%
+-commutative40.2%
sqr-neg40.2%
+-commutative40.2%
distribute-rgt-in40.2%
cancel-sign-sub40.2%
distribute-rgt-out--40.2%
sub-neg40.2%
remove-double-neg40.2%
+-commutative40.2%
Simplified77.3%
*-commutative77.3%
hypot-define40.2%
+-commutative40.2%
*-commutative40.2%
add-sqr-sqrt40.0%
sqrt-unprod40.2%
*-commutative40.2%
*-commutative40.2%
swap-sqr40.2%
Applied egg-rr77.3%
*-commutative77.3%
associate-*r*77.3%
metadata-eval77.3%
Simplified77.3%
pow1/277.3%
pow-to-exp71.6%
Applied egg-rr71.6%
Taylor expanded in re around inf 27.9%
Final simplification27.9%
(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 2024112
(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)))))