
(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}
(FPCore (re im) :precision binary64 (if (<= (- (sqrt (+ (* re re) (* im im))) re) 0.0) (/ (* im 0.5) (sqrt 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(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(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(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(Float64(im * 0.5) / sqrt(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(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[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $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:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\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 7.1%
pow17.1%
Applied egg-rr12.4%
unpow112.4%
*-commutative12.4%
associate-*r*12.4%
metadata-eval12.4%
Simplified12.4%
Taylor expanded in re around inf 93.9%
unpow293.9%
rem-square-sqrt95.4%
Simplified95.4%
sqrt-div95.1%
metadata-eval95.1%
un-div-inv95.5%
*-commutative95.5%
Applied egg-rr95.5%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 52.4%
pow152.4%
Applied egg-rr91.2%
unpow191.2%
*-commutative91.2%
associate-*r*91.2%
metadata-eval91.2%
Simplified91.2%
Final simplification91.9%
(FPCore (re im)
:precision binary64
(if (<= re -1.1e+28)
(sqrt (- re))
(if (<= re 3.6e-33)
(* 0.5 (sqrt (+ (* im 2.0) (* re (- (/ re im) 2.0)))))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e+28) {
tmp = sqrt(-re);
} else if (re <= 3.6e-33) {
tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.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) :: tmp
if (re <= (-1.1d+28)) then
tmp = sqrt(-re)
else if (re <= 3.6d-33) then
tmp = 0.5d0 * sqrt(((im * 2.0d0) + (re * ((re / im) - 2.0d0))))
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 <= -1.1e+28) {
tmp = Math.sqrt(-re);
} else if (re <= 3.6e-33) {
tmp = 0.5 * Math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0))));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.1e+28: tmp = math.sqrt(-re) elif re <= 3.6e-33: tmp = 0.5 * math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.1e+28) tmp = sqrt(Float64(-re)); elseif (re <= 3.6e-33) tmp = Float64(0.5 * sqrt(Float64(Float64(im * 2.0) + Float64(re * Float64(Float64(re / im) - 2.0))))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.1e+28) tmp = sqrt(-re); elseif (re <= 3.6e-33) tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.1e+28], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 3.6e-33], N[(0.5 * N[Sqrt[N[(N[(im * 2.0), $MachinePrecision] + N[(re * N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+28}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 3.6 \cdot 10^{-33}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2 + re \cdot \left(\frac{re}{im} - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.09999999999999993e28Initial program 38.3%
pow138.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
if -1.09999999999999993e28 < re < 3.60000000000000034e-33Initial program 65.4%
Taylor expanded in re around 0 79.5%
if 3.60000000000000034e-33 < re Initial program 14.9%
pow114.9%
Applied egg-rr39.9%
unpow139.9%
*-commutative39.9%
associate-*r*39.9%
metadata-eval39.9%
Simplified39.9%
Taylor expanded in re around inf 71.9%
unpow271.9%
rem-square-sqrt72.8%
Simplified72.8%
sqrt-div72.7%
metadata-eval72.7%
un-div-inv73.0%
*-commutative73.0%
Applied egg-rr73.0%
Final simplification76.6%
(FPCore (re im) :precision binary64 (if (<= re -3e+29) (sqrt (- re)) (if (<= re 3.6e-33) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -3e+29) {
tmp = sqrt(-re);
} else if (re <= 3.6e-33) {
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 <= (-3d+29)) then
tmp = sqrt(-re)
else if (re <= 3.6d-33) 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 <= -3e+29) {
tmp = Math.sqrt(-re);
} else if (re <= 3.6e-33) {
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 <= -3e+29: tmp = math.sqrt(-re) elif re <= 3.6e-33: 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 <= -3e+29) tmp = sqrt(Float64(-re)); elseif (re <= 3.6e-33) 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 <= -3e+29) tmp = sqrt(-re); elseif (re <= 3.6e-33) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3e+29], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 3.6e-33], 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 -3 \cdot 10^{+29}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 3.6 \cdot 10^{-33}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.9999999999999999e29Initial program 38.3%
pow138.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
if -2.9999999999999999e29 < re < 3.60000000000000034e-33Initial program 65.4%
pow165.4%
Applied egg-rr90.1%
unpow190.1%
*-commutative90.1%
associate-*r*90.1%
metadata-eval90.1%
Simplified90.1%
Taylor expanded in re around 0 79.1%
neg-mul-179.1%
sub-neg79.1%
Simplified79.1%
if 3.60000000000000034e-33 < re Initial program 14.9%
pow114.9%
Applied egg-rr39.9%
unpow139.9%
*-commutative39.9%
associate-*r*39.9%
metadata-eval39.9%
Simplified39.9%
Taylor expanded in re around inf 71.9%
unpow271.9%
rem-square-sqrt72.8%
Simplified72.8%
sqrt-div72.7%
metadata-eval72.7%
un-div-inv73.0%
*-commutative73.0%
Applied egg-rr73.0%
Final simplification76.4%
(FPCore (re im) :precision binary64 (if (<= re -3e+28) (sqrt (- re)) (if (<= re 3.6e-33) (sqrt (* 0.5 (- im re))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -3e+28) {
tmp = sqrt(-re);
} else if (re <= 3.6e-33) {
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 <= (-3d+28)) then
tmp = sqrt(-re)
else if (re <= 3.6d-33) 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 <= -3e+28) {
tmp = Math.sqrt(-re);
} else if (re <= 3.6e-33) {
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 <= -3e+28: tmp = math.sqrt(-re) elif re <= 3.6e-33: 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 <= -3e+28) tmp = sqrt(Float64(-re)); elseif (re <= 3.6e-33) 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 <= -3e+28) tmp = sqrt(-re); elseif (re <= 3.6e-33) tmp = sqrt((0.5 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3e+28], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 3.6e-33], 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 -3 \cdot 10^{+28}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 3.6 \cdot 10^{-33}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -3.0000000000000001e28Initial program 38.3%
pow138.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
if -3.0000000000000001e28 < re < 3.60000000000000034e-33Initial program 65.4%
pow165.4%
Applied egg-rr90.1%
unpow190.1%
*-commutative90.1%
associate-*r*90.1%
metadata-eval90.1%
Simplified90.1%
Taylor expanded in re around 0 79.1%
neg-mul-179.1%
sub-neg79.1%
Simplified79.1%
if 3.60000000000000034e-33 < re Initial program 14.9%
pow114.9%
Applied egg-rr39.9%
unpow139.9%
*-commutative39.9%
associate-*r*39.9%
metadata-eval39.9%
Simplified39.9%
Taylor expanded in re around inf 71.9%
unpow271.9%
rem-square-sqrt72.8%
Simplified72.8%
sqrt-div72.7%
metadata-eval72.7%
un-div-inv73.0%
*-commutative73.0%
Applied egg-rr73.0%
div-inv72.7%
pow1/272.7%
pow-flip72.9%
metadata-eval72.9%
add-log-exp13.0%
*-commutative13.0%
*-un-lft-identity13.0%
log-prod13.0%
metadata-eval13.0%
add-log-exp72.9%
*-commutative72.9%
metadata-eval72.9%
pow-flip72.7%
pow1/272.7%
div-inv73.0%
*-commutative73.0%
associate-/l*72.7%
Applied egg-rr72.7%
+-lft-identity72.7%
Simplified72.7%
(FPCore (re im) :precision binary64 (if (<= re -7e+30) (sqrt (- re)) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -7e+30) {
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 <= (-7d+30)) 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 <= -7e+30) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -7e+30: tmp = math.sqrt(-re) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -7e+30) 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 <= -7e+30) tmp = sqrt(-re); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -7e+30], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -7 \cdot 10^{+30}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -7.00000000000000042e30Initial program 38.3%
pow138.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
if -7.00000000000000042e30 < re Initial program 46.9%
Taylor expanded in re around 0 61.5%
*-commutative61.5%
Simplified61.5%
add-sqr-sqrt61.1%
sqrt-unprod61.5%
*-commutative61.5%
*-commutative61.5%
swap-sqr61.5%
add-sqr-sqrt61.5%
metadata-eval61.5%
Applied egg-rr61.5%
associate-*l*61.5%
metadata-eval61.5%
Simplified61.5%
(FPCore (re im) :precision binary64 (if (<= re -5e-310) (sqrt (- re)) (sqrt re)))
double code(double re, double im) {
double tmp;
if (re <= -5e-310) {
tmp = sqrt(-re);
} 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 <= (-5d-310)) then
tmp = sqrt(-re)
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -5e-310) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5e-310: tmp = math.sqrt(-re) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -5e-310) tmp = sqrt(Float64(-re)); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5e-310) tmp = sqrt(-re); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5e-310], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -4.999999999999985e-310Initial program 55.9%
pow155.9%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 47.5%
neg-mul-147.5%
Simplified47.5%
if -4.999999999999985e-310 < re Initial program 33.7%
pow133.7%
Applied egg-rr55.8%
unpow155.8%
*-commutative55.8%
associate-*r*55.8%
metadata-eval55.8%
Simplified55.8%
Taylor expanded in re around -inf 0.0%
neg-mul-10.0%
Simplified0.0%
add-sqr-sqrt0.0%
sqrt-unprod4.6%
sqr-neg4.6%
sqrt-unprod5.7%
add-sqr-sqrt5.7%
*-un-lft-identity5.7%
Applied egg-rr5.7%
*-lft-identity5.7%
Simplified5.7%
(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(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.9%
pow144.9%
Applied egg-rr78.2%
unpow178.2%
*-commutative78.2%
associate-*r*78.2%
metadata-eval78.2%
Simplified78.2%
Taylor expanded in re around -inf 24.1%
neg-mul-124.1%
Simplified24.1%
add-sqr-sqrt24.1%
sqrt-unprod14.6%
sqr-neg14.6%
sqrt-unprod2.8%
add-sqr-sqrt2.8%
*-un-lft-identity2.8%
Applied egg-rr2.8%
*-lft-identity2.8%
Simplified2.8%
herbie shell --seed 2024182
(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)))))