
(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 8 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 (<= (- (sqrt (+ (* re re) (* im im))) re) 0.0) (* (pow re -0.5) (* im 0.5)) (sqrt (* 0.5 (- (hypot re im) re)))))
double code(double re, double im) {
double tmp;
if ((sqrt(((re * re) + (im * im))) - re) <= 0.0) {
tmp = pow(re, -0.5) * (im * 0.5);
} else {
tmp = sqrt((0.5 * (hypot(re, im) - re)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if ((Math.sqrt(((re * re) + (im * im))) - re) <= 0.0) {
tmp = Math.pow(re, -0.5) * (im * 0.5);
} else {
tmp = Math.sqrt((0.5 * (Math.hypot(re, im) - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if (math.sqrt(((re * re) + (im * im))) - re) <= 0.0: tmp = math.pow(re, -0.5) * (im * 0.5) else: tmp = math.sqrt((0.5 * (math.hypot(re, im) - re))) return tmp
function code(re, im) tmp = 0.0 if (Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re) <= 0.0) tmp = Float64((re ^ -0.5) * Float64(im * 0.5)); else tmp = sqrt(Float64(0.5 * Float64(hypot(re, im) - re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((sqrt(((re * re) + (im * im))) - re) <= 0.0) tmp = (re ^ -0.5) * (im * 0.5); else tmp = sqrt((0.5 * (hypot(re, im) - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision], 0.0], N[(N[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{re \cdot re + im \cdot im} - re \leq 0:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 8.3%
sub-neg8.3%
sqr-neg8.3%
sub-neg8.3%
sqr-neg8.3%
hypot-def14.6%
Simplified14.6%
Taylor expanded in im around 0 93.9%
associate-*r*93.9%
*-commutative93.9%
associate-*r*94.4%
associate-*r*94.4%
Simplified94.4%
expm1-log1p-u94.4%
expm1-udef10.9%
associate-*r*10.9%
*-commutative10.9%
sqrt-div10.9%
metadata-eval10.9%
associate-*l/10.9%
*-un-lft-identity10.9%
*-commutative10.9%
*-commutative10.9%
associate-*l*10.9%
Applied egg-rr10.9%
expm1-def94.5%
expm1-log1p94.5%
associate-*r/94.4%
associate-*r*93.9%
*-commutative93.9%
associate-*l*93.9%
*-commutative93.9%
associate-*r*94.4%
associate-*l*94.4%
Simplified94.4%
clear-num93.5%
associate-/r/94.3%
pow1/294.3%
pow-flip94.3%
metadata-eval94.3%
associate-*l*93.9%
add-sqr-sqrt93.9%
sqrt-unprod93.9%
swap-sqr93.9%
rem-square-sqrt93.9%
metadata-eval93.9%
metadata-eval93.9%
rem-square-sqrt95.4%
Applied egg-rr95.4%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 47.5%
sub-neg47.5%
sqr-neg47.5%
sub-neg47.5%
sqr-neg47.5%
hypot-def90.6%
Simplified90.6%
add-sqr-sqrt90.0%
sqrt-unprod90.6%
*-commutative90.6%
*-commutative90.6%
swap-sqr90.6%
add-sqr-sqrt90.6%
metadata-eval90.6%
Applied egg-rr90.6%
*-commutative90.6%
associate-*r*90.6%
metadata-eval90.6%
Simplified90.6%
Final simplification91.4%
(FPCore (re im)
:precision binary64
(if (<= re -9.5e-10)
(* 0.5 (sqrt (* re -4.0)))
(if (or (<= re 1.55e-74) (and (not (<= re 8.5e+142)) (<= re 6.5e+172)))
(sqrt (* 0.5 (- im re)))
(* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -9.5e-10) {
tmp = 0.5 * sqrt((re * -4.0));
} else if ((re <= 1.55e-74) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = im * (0.5 / 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 <= (-9.5d-10)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if ((re <= 1.55d-74) .or. (.not. (re <= 8.5d+142)) .and. (re <= 6.5d+172)) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = im * (0.5d0 / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -9.5e-10) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if ((re <= 1.55e-74) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -9.5e-10: tmp = 0.5 * math.sqrt((re * -4.0)) elif (re <= 1.55e-74) or (not (re <= 8.5e+142) and (re <= 6.5e+172)): tmp = math.sqrt((0.5 * (im - re))) else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -9.5e-10) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif ((re <= 1.55e-74) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -9.5e-10) tmp = 0.5 * sqrt((re * -4.0)); elseif ((re <= 1.55e-74) || (~((re <= 8.5e+142)) && (re <= 6.5e+172))) tmp = sqrt((0.5 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -9.5e-10], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 1.55e-74], And[N[Not[LessEqual[re, 8.5e+142]], $MachinePrecision], LessEqual[re, 6.5e+172]]], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -9.5 \cdot 10^{-10}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.55 \cdot 10^{-74} \lor \neg \left(re \leq 8.5 \cdot 10^{+142}\right) \land re \leq 6.5 \cdot 10^{+172}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -9.50000000000000028e-10Initial program 37.1%
Taylor expanded in re around -inf 76.6%
*-commutative76.6%
Simplified76.6%
if -9.50000000000000028e-10 < re < 1.5500000000000001e-74 or 8.49999999999999955e142 < re < 6.4999999999999997e172Initial program 55.5%
sub-neg55.5%
sqr-neg55.5%
sub-neg55.5%
sqr-neg55.5%
hypot-def92.2%
Simplified92.2%
add-sqr-sqrt91.6%
sqrt-unprod92.2%
*-commutative92.2%
*-commutative92.2%
swap-sqr92.2%
add-sqr-sqrt92.2%
metadata-eval92.2%
Applied egg-rr92.2%
*-commutative92.2%
associate-*r*92.2%
metadata-eval92.2%
Simplified92.2%
Taylor expanded in re around 0 79.5%
neg-mul-179.5%
unsub-neg79.5%
Simplified79.5%
if 1.5500000000000001e-74 < re < 8.49999999999999955e142 or 6.4999999999999997e172 < re Initial program 20.4%
sub-neg20.4%
sqr-neg20.4%
sub-neg20.4%
sqr-neg20.4%
hypot-def34.1%
Simplified34.1%
Taylor expanded in im around 0 77.8%
associate-*r*77.8%
*-commutative77.8%
associate-*r*78.2%
associate-*r*78.2%
Simplified78.2%
expm1-log1p-u77.7%
expm1-udef26.0%
associate-*r*26.0%
*-commutative26.0%
sqrt-div26.0%
metadata-eval26.0%
associate-*l/26.0%
*-un-lft-identity26.0%
*-commutative26.0%
*-commutative26.0%
associate-*l*26.0%
Applied egg-rr26.0%
expm1-def77.8%
expm1-log1p78.3%
associate-*r/78.3%
associate-*r*77.9%
*-commutative77.9%
associate-*l*77.9%
*-commutative77.9%
associate-*r*78.3%
associate-*l*78.3%
Simplified78.3%
expm1-log1p-u77.7%
expm1-udef26.0%
Applied egg-rr26.0%
expm1-def78.3%
expm1-log1p78.9%
associate-/l*78.9%
associate-*r/78.8%
Simplified78.8%
Final simplification78.5%
(FPCore (re im)
:precision binary64
(if (<= re -4.5e-9)
(* 0.5 (sqrt (* re -4.0)))
(if (or (<= re 1.3e-76) (and (not (<= re 8.5e+142)) (<= re 6.5e+172)))
(sqrt (* 0.5 (- im re)))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -4.5e-9) {
tmp = 0.5 * sqrt((re * -4.0));
} else if ((re <= 1.3e-76) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) / 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 <= (-4.5d-9)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if ((re <= 1.3d-76) .or. (.not. (re <= 8.5d+142)) .and. (re <= 6.5d+172)) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = (im * 0.5d0) / sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.5e-9) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if ((re <= 1.3e-76) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.5e-9: tmp = 0.5 * math.sqrt((re * -4.0)) elif (re <= 1.3e-76) or (not (re <= 8.5e+142) and (re <= 6.5e+172)): tmp = math.sqrt((0.5 * (im - re))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.5e-9) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif ((re <= 1.3e-76) || (!(re <= 8.5e+142) && (re <= 6.5e+172))) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.5e-9) tmp = 0.5 * sqrt((re * -4.0)); elseif ((re <= 1.3e-76) || (~((re <= 8.5e+142)) && (re <= 6.5e+172))) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.5e-9], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 1.3e-76], And[N[Not[LessEqual[re, 8.5e+142]], $MachinePrecision], LessEqual[re, 6.5e+172]]], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.5 \cdot 10^{-9}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.3 \cdot 10^{-76} \lor \neg \left(re \leq 8.5 \cdot 10^{+142}\right) \land re \leq 6.5 \cdot 10^{+172}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -4.49999999999999976e-9Initial program 37.1%
Taylor expanded in re around -inf 76.6%
*-commutative76.6%
Simplified76.6%
if -4.49999999999999976e-9 < re < 1.3e-76 or 8.49999999999999955e142 < re < 6.4999999999999997e172Initial program 55.5%
sub-neg55.5%
sqr-neg55.5%
sub-neg55.5%
sqr-neg55.5%
hypot-def92.2%
Simplified92.2%
add-sqr-sqrt91.6%
sqrt-unprod92.2%
*-commutative92.2%
*-commutative92.2%
swap-sqr92.2%
add-sqr-sqrt92.2%
metadata-eval92.2%
Applied egg-rr92.2%
*-commutative92.2%
associate-*r*92.2%
metadata-eval92.2%
Simplified92.2%
Taylor expanded in re around 0 79.5%
neg-mul-179.5%
unsub-neg79.5%
Simplified79.5%
if 1.3e-76 < re < 8.49999999999999955e142 or 6.4999999999999997e172 < re Initial program 20.4%
sub-neg20.4%
sqr-neg20.4%
sub-neg20.4%
sqr-neg20.4%
hypot-def34.1%
Simplified34.1%
Taylor expanded in im around 0 77.8%
associate-*r*77.8%
*-commutative77.8%
associate-*r*78.2%
associate-*r*78.2%
Simplified78.2%
expm1-log1p-u77.7%
expm1-udef26.0%
associate-*r*26.0%
*-commutative26.0%
sqrt-div26.0%
metadata-eval26.0%
associate-*l/26.0%
*-un-lft-identity26.0%
*-commutative26.0%
*-commutative26.0%
associate-*l*26.0%
Applied egg-rr26.0%
expm1-def77.8%
expm1-log1p78.3%
associate-*r/78.3%
associate-*r*77.9%
*-commutative77.9%
associate-*l*77.9%
*-commutative77.9%
associate-*r*78.3%
associate-*l*78.3%
Simplified78.3%
associate-*l*77.9%
add-sqr-sqrt77.9%
sqrt-unprod77.9%
swap-sqr77.9%
rem-square-sqrt77.9%
metadata-eval77.9%
metadata-eval77.9%
rem-square-sqrt78.9%
expm1-log1p-u77.2%
expm1-udef35.7%
Applied egg-rr35.7%
expm1-def77.2%
expm1-log1p78.9%
Simplified78.9%
Final simplification78.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (* 0.5 (- im re)))))
(if (<= re -8.5e-9)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.45e-74)
t_0
(if (<= re 8.5e+142)
(* 0.5 (* im (pow re -0.5)))
(if (<= re 6.5e+172) t_0 (/ (* im 0.5) (sqrt re))))))))
double code(double re, double im) {
double t_0 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -8.5e-9) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.45e-74) {
tmp = t_0;
} else if (re <= 8.5e+142) {
tmp = 0.5 * (im * pow(re, -0.5));
} else if (re <= 6.5e+172) {
tmp = t_0;
} else {
tmp = (im * 0.5) / sqrt(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((0.5d0 * (im - re)))
if (re <= (-8.5d-9)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.45d-74) then
tmp = t_0
else if (re <= 8.5d+142) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else if (re <= 6.5d+172) then
tmp = t_0
else
tmp = (im * 0.5d0) / sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -8.5e-9) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.45e-74) {
tmp = t_0;
} else if (re <= 8.5e+142) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else if (re <= 6.5e+172) {
tmp = t_0;
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): t_0 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -8.5e-9: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.45e-74: tmp = t_0 elif re <= 8.5e+142: tmp = 0.5 * (im * math.pow(re, -0.5)) elif re <= 6.5e+172: tmp = t_0 else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) t_0 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -8.5e-9) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.45e-74) tmp = t_0; elseif (re <= 8.5e+142) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); elseif (re <= 6.5e+172) tmp = t_0; else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -8.5e-9) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.45e-74) tmp = t_0; elseif (re <= 8.5e+142) tmp = 0.5 * (im * (re ^ -0.5)); elseif (re <= 6.5e+172) tmp = t_0; else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -8.5e-9], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.45e-74], t$95$0, If[LessEqual[re, 8.5e+142], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.5e+172], t$95$0, N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -8.5 \cdot 10^{-9}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.45 \cdot 10^{-74}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 8.5 \cdot 10^{+142}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{elif}\;re \leq 6.5 \cdot 10^{+172}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -8.5e-9Initial program 37.1%
Taylor expanded in re around -inf 76.6%
*-commutative76.6%
Simplified76.6%
if -8.5e-9 < re < 1.45e-74 or 8.49999999999999955e142 < re < 6.4999999999999997e172Initial program 55.5%
sub-neg55.5%
sqr-neg55.5%
sub-neg55.5%
sqr-neg55.5%
hypot-def92.2%
Simplified92.2%
add-sqr-sqrt91.6%
sqrt-unprod92.2%
*-commutative92.2%
*-commutative92.2%
swap-sqr92.2%
add-sqr-sqrt92.2%
metadata-eval92.2%
Applied egg-rr92.2%
*-commutative92.2%
associate-*r*92.2%
metadata-eval92.2%
Simplified92.2%
Taylor expanded in re around 0 79.5%
neg-mul-179.5%
unsub-neg79.5%
Simplified79.5%
if 1.45e-74 < re < 8.49999999999999955e142Initial program 32.9%
sub-neg32.9%
sqr-neg32.9%
sub-neg32.9%
sqr-neg32.9%
hypot-def35.5%
Simplified35.5%
add-sqr-sqrt35.4%
sqrt-unprod35.5%
*-commutative35.5%
*-commutative35.5%
swap-sqr35.5%
add-sqr-sqrt35.5%
metadata-eval35.5%
Applied egg-rr35.5%
*-commutative35.5%
associate-*r*35.5%
metadata-eval35.5%
Simplified35.5%
Taylor expanded in im around 0 73.7%
*-commutative73.7%
unpow273.7%
rem-square-sqrt74.9%
associate-*l*74.9%
unpow1/274.9%
exp-to-pow70.8%
*-commutative70.8%
log-rec70.8%
neg-mul-170.8%
associate-*r*70.8%
metadata-eval70.8%
log-pow70.8%
rem-exp-log74.9%
Simplified74.9%
if 6.4999999999999997e172 < re Initial program 3.0%
sub-neg3.0%
sqr-neg3.0%
sub-neg3.0%
sqr-neg3.0%
hypot-def32.2%
Simplified32.2%
Taylor expanded in im around 0 83.5%
associate-*r*83.5%
*-commutative83.5%
associate-*r*84.0%
associate-*r*84.0%
Simplified84.0%
expm1-log1p-u82.8%
expm1-udef44.2%
associate-*r*44.2%
*-commutative44.2%
sqrt-div44.2%
metadata-eval44.2%
associate-*l/44.2%
*-un-lft-identity44.2%
*-commutative44.2%
*-commutative44.2%
associate-*l*44.2%
Applied egg-rr44.2%
expm1-def82.8%
expm1-log1p84.1%
associate-*r/84.1%
associate-*r*83.6%
*-commutative83.6%
associate-*l*83.6%
*-commutative83.6%
associate-*r*84.1%
associate-*l*84.1%
Simplified84.1%
associate-*l*83.6%
add-sqr-sqrt83.6%
sqrt-unprod83.6%
swap-sqr83.6%
rem-square-sqrt83.6%
metadata-eval83.6%
metadata-eval83.6%
rem-square-sqrt84.7%
expm1-log1p-u80.9%
expm1-udef57.6%
Applied egg-rr57.6%
expm1-def80.9%
expm1-log1p84.7%
Simplified84.7%
Final simplification78.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (* 0.5 (- im re)))))
(if (<= re -4.4e-11)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 8.4e-75)
t_0
(if (<= re 8.5e+142)
(* (pow re -0.5) (* im 0.5))
(if (<= re 6.5e+172) t_0 (/ (* im 0.5) (sqrt re))))))))
double code(double re, double im) {
double t_0 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -4.4e-11) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 8.4e-75) {
tmp = t_0;
} else if (re <= 8.5e+142) {
tmp = pow(re, -0.5) * (im * 0.5);
} else if (re <= 6.5e+172) {
tmp = t_0;
} else {
tmp = (im * 0.5) / sqrt(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((0.5d0 * (im - re)))
if (re <= (-4.4d-11)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 8.4d-75) then
tmp = t_0
else if (re <= 8.5d+142) then
tmp = (re ** (-0.5d0)) * (im * 0.5d0)
else if (re <= 6.5d+172) then
tmp = t_0
else
tmp = (im * 0.5d0) / sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -4.4e-11) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 8.4e-75) {
tmp = t_0;
} else if (re <= 8.5e+142) {
tmp = Math.pow(re, -0.5) * (im * 0.5);
} else if (re <= 6.5e+172) {
tmp = t_0;
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): t_0 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -4.4e-11: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 8.4e-75: tmp = t_0 elif re <= 8.5e+142: tmp = math.pow(re, -0.5) * (im * 0.5) elif re <= 6.5e+172: tmp = t_0 else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) t_0 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -4.4e-11) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 8.4e-75) tmp = t_0; elseif (re <= 8.5e+142) tmp = Float64((re ^ -0.5) * Float64(im * 0.5)); elseif (re <= 6.5e+172) tmp = t_0; else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -4.4e-11) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 8.4e-75) tmp = t_0; elseif (re <= 8.5e+142) tmp = (re ^ -0.5) * (im * 0.5); elseif (re <= 6.5e+172) tmp = t_0; else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -4.4e-11], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.4e-75], t$95$0, If[LessEqual[re, 8.5e+142], N[(N[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.5e+172], t$95$0, N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -4.4 \cdot 10^{-11}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 8.4 \cdot 10^{-75}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 8.5 \cdot 10^{+142}:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\mathbf{elif}\;re \leq 6.5 \cdot 10^{+172}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -4.4000000000000003e-11Initial program 37.1%
Taylor expanded in re around -inf 76.6%
*-commutative76.6%
Simplified76.6%
if -4.4000000000000003e-11 < re < 8.4000000000000004e-75 or 8.49999999999999955e142 < re < 6.4999999999999997e172Initial program 55.5%
sub-neg55.5%
sqr-neg55.5%
sub-neg55.5%
sqr-neg55.5%
hypot-def92.2%
Simplified92.2%
add-sqr-sqrt91.6%
sqrt-unprod92.2%
*-commutative92.2%
*-commutative92.2%
swap-sqr92.2%
add-sqr-sqrt92.2%
metadata-eval92.2%
Applied egg-rr92.2%
*-commutative92.2%
associate-*r*92.2%
metadata-eval92.2%
Simplified92.2%
Taylor expanded in re around 0 79.5%
neg-mul-179.5%
unsub-neg79.5%
Simplified79.5%
if 8.4000000000000004e-75 < re < 8.49999999999999955e142Initial program 32.9%
sub-neg32.9%
sqr-neg32.9%
sub-neg32.9%
sqr-neg32.9%
hypot-def35.5%
Simplified35.5%
Taylor expanded in im around 0 73.7%
associate-*r*73.7%
*-commutative73.7%
associate-*r*74.1%
associate-*r*74.1%
Simplified74.1%
expm1-log1p-u74.1%
expm1-udef12.9%
associate-*r*12.9%
*-commutative12.9%
sqrt-div12.9%
metadata-eval12.9%
associate-*l/12.9%
*-un-lft-identity12.9%
*-commutative12.9%
*-commutative12.9%
associate-*l*12.9%
Applied egg-rr12.9%
expm1-def74.2%
expm1-log1p74.2%
associate-*r/74.1%
associate-*r*73.7%
*-commutative73.7%
associate-*l*73.7%
*-commutative73.7%
associate-*r*74.1%
associate-*l*74.1%
Simplified74.1%
clear-num73.2%
associate-/r/74.0%
pow1/274.0%
pow-flip74.1%
metadata-eval74.1%
associate-*l*73.8%
add-sqr-sqrt73.8%
sqrt-unprod73.8%
swap-sqr73.8%
rem-square-sqrt73.8%
metadata-eval73.8%
metadata-eval73.8%
rem-square-sqrt74.9%
Applied egg-rr74.9%
if 6.4999999999999997e172 < re Initial program 3.0%
sub-neg3.0%
sqr-neg3.0%
sub-neg3.0%
sqr-neg3.0%
hypot-def32.2%
Simplified32.2%
Taylor expanded in im around 0 83.5%
associate-*r*83.5%
*-commutative83.5%
associate-*r*84.0%
associate-*r*84.0%
Simplified84.0%
expm1-log1p-u82.8%
expm1-udef44.2%
associate-*r*44.2%
*-commutative44.2%
sqrt-div44.2%
metadata-eval44.2%
associate-*l/44.2%
*-un-lft-identity44.2%
*-commutative44.2%
*-commutative44.2%
associate-*l*44.2%
Applied egg-rr44.2%
expm1-def82.8%
expm1-log1p84.1%
associate-*r/84.1%
associate-*r*83.6%
*-commutative83.6%
associate-*l*83.6%
*-commutative83.6%
associate-*r*84.1%
associate-*l*84.1%
Simplified84.1%
associate-*l*83.6%
add-sqr-sqrt83.6%
sqrt-unprod83.6%
swap-sqr83.6%
rem-square-sqrt83.6%
metadata-eval83.6%
metadata-eval83.6%
rem-square-sqrt84.7%
expm1-log1p-u80.9%
expm1-udef57.6%
Applied egg-rr57.6%
expm1-def80.9%
expm1-log1p84.7%
Simplified84.7%
Final simplification78.6%
(FPCore (re im) :precision binary64 (if (<= re -3.95e-13) (* 0.5 (sqrt (* re -4.0))) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -3.95e-13) {
tmp = 0.5 * sqrt((re * -4.0));
} else {
tmp = sqrt((im * 0.5));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.95d-13)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.95e-13) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.95e-13: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.95e-13) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.95e-13) tmp = 0.5 * sqrt((re * -4.0)); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.95e-13], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.95 \cdot 10^{-13}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -3.94999999999999983e-13Initial program 37.1%
Taylor expanded in re around -inf 76.6%
*-commutative76.6%
Simplified76.6%
if -3.94999999999999983e-13 < re Initial program 43.0%
sub-neg43.0%
sqr-neg43.0%
sub-neg43.0%
sqr-neg43.0%
hypot-def71.6%
Simplified71.6%
add-sqr-sqrt71.2%
sqrt-unprod71.6%
*-commutative71.6%
*-commutative71.6%
swap-sqr71.6%
add-sqr-sqrt71.6%
metadata-eval71.6%
Applied egg-rr71.6%
*-commutative71.6%
associate-*r*71.6%
metadata-eval71.6%
Simplified71.6%
Taylor expanded in re around 0 58.5%
Final simplification63.2%
(FPCore (re im) :precision binary64 (sqrt (* 0.5 (- im re))))
double code(double re, double im) {
return sqrt((0.5 * (im - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((0.5d0 * (im - re)))
end function
public static double code(double re, double im) {
return Math.sqrt((0.5 * (im - re)));
}
def code(re, im): return math.sqrt((0.5 * (im - re)))
function code(re, im) return sqrt(Float64(0.5 * Float64(im - re))) end
function tmp = code(re, im) tmp = sqrt((0.5 * (im - re))); end
code[re_, im_] := N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(im - re\right)}
\end{array}
Initial program 41.5%
sub-neg41.5%
sqr-neg41.5%
sub-neg41.5%
sqr-neg41.5%
hypot-def79.1%
Simplified79.1%
add-sqr-sqrt78.5%
sqrt-unprod79.1%
*-commutative79.1%
*-commutative79.1%
swap-sqr79.1%
add-sqr-sqrt79.1%
metadata-eval79.1%
Applied egg-rr79.1%
*-commutative79.1%
associate-*r*79.1%
metadata-eval79.1%
Simplified79.1%
Taylor expanded in re around 0 53.6%
neg-mul-153.6%
unsub-neg53.6%
Simplified53.6%
Final simplification53.6%
(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 41.5%
sub-neg41.5%
sqr-neg41.5%
sub-neg41.5%
sqr-neg41.5%
hypot-def79.1%
Simplified79.1%
add-sqr-sqrt78.5%
sqrt-unprod79.1%
*-commutative79.1%
*-commutative79.1%
swap-sqr79.1%
add-sqr-sqrt79.1%
metadata-eval79.1%
Applied egg-rr79.1%
*-commutative79.1%
associate-*r*79.1%
metadata-eval79.1%
Simplified79.1%
Taylor expanded in re around 0 50.9%
Final simplification50.9%
herbie shell --seed 2023322
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
:pre (> im 0.0)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))