
(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 6 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) (* im (* 0.5 (sqrt (/ 1.0 re)))) (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 = im * (0.5 * sqrt((1.0 / re)));
} 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 = im * (0.5 * Math.sqrt((1.0 / re)));
} 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 = im * (0.5 * math.sqrt((1.0 / re))) 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(im * Float64(0.5 * sqrt(Float64(1.0 / re)))); 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 = im * (0.5 * sqrt((1.0 / re))); 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[(im * N[(0.5 * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $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:\\
\;\;\;\;im \cdot \left(0.5 \cdot \sqrt{\frac{1}{re}}\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 5.3%
hypot-def11.7%
Simplified11.7%
add-sqr-sqrt11.7%
sqrt-unprod11.7%
*-commutative11.7%
*-commutative11.7%
swap-sqr11.7%
add-sqr-sqrt11.7%
metadata-eval11.7%
Applied egg-rr11.7%
*-commutative11.7%
associate-*r*11.7%
metadata-eval11.7%
Simplified11.7%
Taylor expanded in im around 0 93.0%
*-commutative93.0%
unpow293.0%
rem-square-sqrt94.5%
associate-*l*94.5%
Simplified94.5%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 50.7%
hypot-def90.2%
Simplified90.2%
add-sqr-sqrt89.6%
sqrt-unprod90.2%
*-commutative90.2%
*-commutative90.2%
swap-sqr90.2%
add-sqr-sqrt90.2%
metadata-eval90.2%
Applied egg-rr90.2%
*-commutative90.2%
associate-*r*90.2%
metadata-eval90.2%
Simplified90.2%
Final simplification90.8%
(FPCore (re im)
:precision binary64
(if (<= re -1.4e+56)
(sqrt (- re))
(if (<= re 6.8e-44)
(sqrt (* 0.5 (- im re)))
(if (or (<= re 3.5e-18) (not (<= re 3e+121)))
(* 0.5 (sqrt (/ im (/ re im))))
(sqrt (* im 0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -1.4e+56) {
tmp = sqrt(-re);
} else if (re <= 6.8e-44) {
tmp = sqrt((0.5 * (im - re)));
} else if ((re <= 3.5e-18) || !(re <= 3e+121)) {
tmp = 0.5 * sqrt((im / (re / im)));
} 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 <= (-1.4d+56)) then
tmp = sqrt(-re)
else if (re <= 6.8d-44) then
tmp = sqrt((0.5d0 * (im - re)))
else if ((re <= 3.5d-18) .or. (.not. (re <= 3d+121))) then
tmp = 0.5d0 * sqrt((im / (re / im)))
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.4e+56) {
tmp = Math.sqrt(-re);
} else if (re <= 6.8e-44) {
tmp = Math.sqrt((0.5 * (im - re)));
} else if ((re <= 3.5e-18) || !(re <= 3e+121)) {
tmp = 0.5 * Math.sqrt((im / (re / im)));
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.4e+56: tmp = math.sqrt(-re) elif re <= 6.8e-44: tmp = math.sqrt((0.5 * (im - re))) elif (re <= 3.5e-18) or not (re <= 3e+121): tmp = 0.5 * math.sqrt((im / (re / im))) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.4e+56) tmp = sqrt(Float64(-re)); elseif (re <= 6.8e-44) tmp = sqrt(Float64(0.5 * Float64(im - re))); elseif ((re <= 3.5e-18) || !(re <= 3e+121)) tmp = Float64(0.5 * sqrt(Float64(im / Float64(re / im)))); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.4e+56) tmp = sqrt(-re); elseif (re <= 6.8e-44) tmp = sqrt((0.5 * (im - re))); elseif ((re <= 3.5e-18) || ~((re <= 3e+121))) tmp = 0.5 * sqrt((im / (re / im))); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.4e+56], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 6.8e-44], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[re, 3.5e-18], N[Not[LessEqual[re, 3e+121]], $MachinePrecision]], N[(0.5 * N[Sqrt[N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.4 \cdot 10^{+56}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 6.8 \cdot 10^{-44}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 3.5 \cdot 10^{-18} \lor \neg \left(re \leq 3 \cdot 10^{+121}\right):\\
\;\;\;\;0.5 \cdot \sqrt{\frac{im}{\frac{re}{im}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -1.40000000000000004e56Initial program 33.6%
hypot-def100.0%
Simplified100.0%
add-sqr-sqrt99.2%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 84.8%
neg-mul-184.8%
Simplified84.8%
if -1.40000000000000004e56 < re < 6.80000000000000033e-44Initial program 65.0%
hypot-def89.5%
Simplified89.5%
add-sqr-sqrt88.9%
sqrt-unprod89.5%
*-commutative89.5%
*-commutative89.5%
swap-sqr89.5%
add-sqr-sqrt89.5%
metadata-eval89.5%
Applied egg-rr89.5%
*-commutative89.5%
associate-*r*89.5%
metadata-eval89.5%
Simplified89.5%
Taylor expanded in re around 0 73.2%
neg-mul-173.2%
+-commutative73.2%
unsub-neg73.2%
Simplified73.2%
if 6.80000000000000033e-44 < re < 3.4999999999999999e-18 or 3.0000000000000002e121 < re Initial program 2.9%
Taylor expanded in re around inf 58.1%
unpow258.1%
associate-/l*70.2%
Simplified70.2%
if 3.4999999999999999e-18 < re < 3.0000000000000002e121Initial program 27.5%
hypot-def67.3%
Simplified67.3%
add-sqr-sqrt66.9%
sqrt-unprod67.3%
*-commutative67.3%
*-commutative67.3%
swap-sqr67.3%
add-sqr-sqrt67.3%
metadata-eval67.3%
Applied egg-rr67.3%
*-commutative67.3%
associate-*r*67.3%
metadata-eval67.3%
Simplified67.3%
Taylor expanded in re around 0 58.9%
*-commutative58.9%
Simplified58.9%
Final simplification73.5%
(FPCore (re im)
:precision binary64
(if (<= re -7.6e+59)
(sqrt (- re))
(if (or (<= re 4.2e-44) (and (not (<= re 6.2e+46)) (<= re 2.3e+106)))
(sqrt (* 0.5 (- im re)))
(* im (* 0.5 (sqrt (/ 1.0 re)))))))
double code(double re, double im) {
double tmp;
if (re <= -7.6e+59) {
tmp = sqrt(-re);
} else if ((re <= 4.2e-44) || (!(re <= 6.2e+46) && (re <= 2.3e+106))) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = im * (0.5 * sqrt((1.0 / re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-7.6d+59)) then
tmp = sqrt(-re)
else if ((re <= 4.2d-44) .or. (.not. (re <= 6.2d+46)) .and. (re <= 2.3d+106)) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = im * (0.5d0 * sqrt((1.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -7.6e+59) {
tmp = Math.sqrt(-re);
} else if ((re <= 4.2e-44) || (!(re <= 6.2e+46) && (re <= 2.3e+106))) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = im * (0.5 * Math.sqrt((1.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -7.6e+59: tmp = math.sqrt(-re) elif (re <= 4.2e-44) or (not (re <= 6.2e+46) and (re <= 2.3e+106)): tmp = math.sqrt((0.5 * (im - re))) else: tmp = im * (0.5 * math.sqrt((1.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -7.6e+59) tmp = sqrt(Float64(-re)); elseif ((re <= 4.2e-44) || (!(re <= 6.2e+46) && (re <= 2.3e+106))) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(im * Float64(0.5 * sqrt(Float64(1.0 / re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -7.6e+59) tmp = sqrt(-re); elseif ((re <= 4.2e-44) || (~((re <= 6.2e+46)) && (re <= 2.3e+106))) tmp = sqrt((0.5 * (im - re))); else tmp = im * (0.5 * sqrt((1.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -7.6e+59], N[Sqrt[(-re)], $MachinePrecision], If[Or[LessEqual[re, 4.2e-44], And[N[Not[LessEqual[re, 6.2e+46]], $MachinePrecision], LessEqual[re, 2.3e+106]]], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(im * N[(0.5 * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -7.6 \cdot 10^{+59}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 4.2 \cdot 10^{-44} \lor \neg \left(re \leq 6.2 \cdot 10^{+46}\right) \land re \leq 2.3 \cdot 10^{+106}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(0.5 \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
\end{array}
if re < -7.6000000000000002e59Initial program 33.6%
hypot-def100.0%
Simplified100.0%
add-sqr-sqrt99.2%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 84.8%
neg-mul-184.8%
Simplified84.8%
if -7.6000000000000002e59 < re < 4.20000000000000003e-44 or 6.1999999999999995e46 < re < 2.3000000000000002e106Initial program 62.8%
hypot-def89.0%
Simplified89.0%
add-sqr-sqrt88.3%
sqrt-unprod89.0%
*-commutative89.0%
*-commutative89.0%
swap-sqr89.0%
add-sqr-sqrt89.0%
metadata-eval89.0%
Applied egg-rr89.0%
*-commutative89.0%
associate-*r*89.0%
metadata-eval89.0%
Simplified89.0%
Taylor expanded in re around 0 72.9%
neg-mul-172.9%
+-commutative72.9%
unsub-neg72.9%
Simplified72.9%
if 4.20000000000000003e-44 < re < 6.1999999999999995e46 or 2.3000000000000002e106 < re Initial program 7.6%
hypot-def38.1%
Simplified38.1%
add-sqr-sqrt37.9%
sqrt-unprod38.1%
*-commutative38.1%
*-commutative38.1%
swap-sqr38.1%
add-sqr-sqrt38.1%
metadata-eval38.1%
Applied egg-rr38.1%
*-commutative38.1%
associate-*r*38.1%
metadata-eval38.1%
Simplified38.1%
Taylor expanded in im around 0 80.9%
*-commutative80.9%
unpow280.9%
rem-square-sqrt81.9%
associate-*l*81.9%
Simplified81.9%
Final simplification77.3%
(FPCore (re im)
:precision binary64
(if (or (<= re -1.1e+56)
(and (not (<= re -3000000000000.0)) (<= re -6.5e-77)))
(sqrt (- re))
(sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if ((re <= -1.1e+56) || (!(re <= -3000000000000.0) && (re <= -6.5e-77))) {
tmp = sqrt(-re);
} 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 <= (-1.1d+56)) .or. (.not. (re <= (-3000000000000.0d0))) .and. (re <= (-6.5d-77))) then
tmp = sqrt(-re)
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -1.1e+56) || (!(re <= -3000000000000.0) && (re <= -6.5e-77))) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -1.1e+56) or (not (re <= -3000000000000.0) and (re <= -6.5e-77)): tmp = math.sqrt(-re) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if ((re <= -1.1e+56) || (!(re <= -3000000000000.0) && (re <= -6.5e-77))) tmp = sqrt(Float64(-re)); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -1.1e+56) || (~((re <= -3000000000000.0)) && (re <= -6.5e-77))) tmp = sqrt(-re); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -1.1e+56], And[N[Not[LessEqual[re, -3000000000000.0]], $MachinePrecision], LessEqual[re, -6.5e-77]]], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+56} \lor \neg \left(re \leq -3000000000000\right) \land re \leq -6.5 \cdot 10^{-77}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -1.10000000000000008e56 or -3e12 < re < -6.4999999999999999e-77Initial program 57.4%
hypot-def100.0%
Simplified100.0%
add-sqr-sqrt99.3%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.8%
neg-mul-175.8%
Simplified75.8%
if -1.10000000000000008e56 < re < -3e12 or -6.4999999999999999e-77 < re Initial program 38.2%
hypot-def69.5%
Simplified69.5%
add-sqr-sqrt69.0%
sqrt-unprod69.5%
*-commutative69.5%
*-commutative69.5%
swap-sqr69.5%
add-sqr-sqrt69.5%
metadata-eval69.5%
Applied egg-rr69.5%
*-commutative69.5%
associate-*r*69.5%
metadata-eval69.5%
Simplified69.5%
Taylor expanded in re around 0 59.5%
*-commutative59.5%
Simplified59.5%
Final simplification64.7%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (- re))))
(if (<= re -2.3e+58)
t_0
(if (<= re -3600000000000.0)
(sqrt (* 0.5 (- im re)))
(if (<= re -6.5e-77) t_0 (sqrt (* im 0.5)))))))
double code(double re, double im) {
double t_0 = sqrt(-re);
double tmp;
if (re <= -2.3e+58) {
tmp = t_0;
} else if (re <= -3600000000000.0) {
tmp = sqrt((0.5 * (im - re)));
} else if (re <= -6.5e-77) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = sqrt(-re)
if (re <= (-2.3d+58)) then
tmp = t_0
else if (re <= (-3600000000000.0d0)) then
tmp = sqrt((0.5d0 * (im - re)))
else if (re <= (-6.5d-77)) then
tmp = t_0
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(-re);
double tmp;
if (re <= -2.3e+58) {
tmp = t_0;
} else if (re <= -3600000000000.0) {
tmp = Math.sqrt((0.5 * (im - re)));
} else if (re <= -6.5e-77) {
tmp = t_0;
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt(-re) tmp = 0 if re <= -2.3e+58: tmp = t_0 elif re <= -3600000000000.0: tmp = math.sqrt((0.5 * (im - re))) elif re <= -6.5e-77: tmp = t_0 else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) t_0 = sqrt(Float64(-re)) tmp = 0.0 if (re <= -2.3e+58) tmp = t_0; elseif (re <= -3600000000000.0) tmp = sqrt(Float64(0.5 * Float64(im - re))); elseif (re <= -6.5e-77) tmp = t_0; else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt(-re); tmp = 0.0; if (re <= -2.3e+58) tmp = t_0; elseif (re <= -3600000000000.0) tmp = sqrt((0.5 * (im - re))); elseif (re <= -6.5e-77) tmp = t_0; else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[(-re)], $MachinePrecision]}, If[LessEqual[re, -2.3e+58], t$95$0, If[LessEqual[re, -3600000000000.0], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, -6.5e-77], t$95$0, N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{-re}\\
\mathbf{if}\;re \leq -2.3 \cdot 10^{+58}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -3600000000000:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq -6.5 \cdot 10^{-77}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -2.30000000000000002e58 or -3.6e12 < re < -6.4999999999999999e-77Initial program 57.4%
hypot-def100.0%
Simplified100.0%
add-sqr-sqrt99.3%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.8%
neg-mul-175.8%
Simplified75.8%
if -2.30000000000000002e58 < re < -3.6e12Initial program 52.1%
hypot-def100.0%
Simplified100.0%
add-sqr-sqrt99.1%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 84.1%
neg-mul-184.1%
+-commutative84.1%
unsub-neg84.1%
Simplified84.1%
if -6.4999999999999999e-77 < re Initial program 37.4%
hypot-def67.7%
Simplified67.7%
add-sqr-sqrt67.2%
sqrt-unprod67.7%
*-commutative67.7%
*-commutative67.7%
swap-sqr67.7%
add-sqr-sqrt67.7%
metadata-eval67.7%
Applied egg-rr67.7%
*-commutative67.7%
associate-*r*67.7%
metadata-eval67.7%
Simplified67.7%
Taylor expanded in re around 0 58.2%
*-commutative58.2%
Simplified58.2%
Final simplification64.8%
(FPCore (re im) :precision binary64 (sqrt (- re)))
double code(double re, double im) {
return sqrt(-re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt(-re)
end function
public static double code(double re, double im) {
return Math.sqrt(-re);
}
def code(re, im): return math.sqrt(-re)
function code(re, im) return sqrt(Float64(-re)) end
function tmp = code(re, im) tmp = sqrt(-re); end
code[re_, im_] := N[Sqrt[(-re)], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{-re}
\end{array}
Initial program 44.3%
hypot-def79.1%
Simplified79.1%
add-sqr-sqrt78.6%
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 -inf 28.2%
neg-mul-128.2%
Simplified28.2%
Final simplification28.2%
herbie shell --seed 2023238
(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)))))