
(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) (/ (* im 0.5) (sqrt re)) (sqrt (* 0.5 (- (hypot im re) 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(im, re) - 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(im, re) - 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(im, re) - 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(im, re) - 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(im, re) - 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[im ^ 2 + re ^ 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(im, re\right) - re\right)}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 7.8%
Taylor expanded in re around inf 46.3%
*-commutative46.3%
sqrt-div49.7%
sqrt-pow199.8%
metadata-eval99.8%
pow199.8%
associate-*l/99.8%
Applied egg-rr99.8%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 52.6%
pow152.6%
Applied egg-rr92.2%
unpow192.2%
*-commutative92.2%
associate-*r*92.2%
metadata-eval92.2%
hypot-undefine52.6%
unpow252.6%
unpow252.6%
+-commutative52.6%
unpow252.6%
unpow252.6%
hypot-undefine92.2%
Simplified92.2%
(FPCore (re im)
:precision binary64
(if (<= re -0.033)
(sqrt (- re))
(if (<= re 3.2e+46)
(sqrt (* im (+ 0.5 (* -0.5 (/ re im)))))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -0.033) {
tmp = sqrt(-re);
} else if (re <= 3.2e+46) {
tmp = sqrt((im * (0.5 + (-0.5 * (re / im)))));
} 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 <= (-0.033d0)) then
tmp = sqrt(-re)
else if (re <= 3.2d+46) then
tmp = sqrt((im * (0.5d0 + ((-0.5d0) * (re / im)))))
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 <= -0.033) {
tmp = Math.sqrt(-re);
} else if (re <= 3.2e+46) {
tmp = Math.sqrt((im * (0.5 + (-0.5 * (re / im)))));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.033: tmp = math.sqrt(-re) elif re <= 3.2e+46: tmp = math.sqrt((im * (0.5 + (-0.5 * (re / im))))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.033) tmp = sqrt(Float64(-re)); elseif (re <= 3.2e+46) tmp = sqrt(Float64(im * Float64(0.5 + Float64(-0.5 * Float64(re / im))))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.033) tmp = sqrt(-re); elseif (re <= 3.2e+46) tmp = sqrt((im * (0.5 + (-0.5 * (re / im))))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.033], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 3.2e+46], N[Sqrt[N[(im * N[(0.5 + N[(-0.5 * N[(re / im), $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 -0.033:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 3.2 \cdot 10^{+46}:\\
\;\;\;\;\sqrt{im \cdot \left(0.5 + -0.5 \cdot \frac{re}{im}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -0.033000000000000002Initial program 43.4%
pow143.4%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine43.4%
unpow243.4%
unpow243.4%
+-commutative43.4%
unpow243.4%
unpow243.4%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 77.2%
neg-mul-177.2%
Simplified77.2%
if -0.033000000000000002 < re < 3.1999999999999998e46Initial program 59.5%
pow159.5%
Applied egg-rr86.5%
unpow186.5%
*-commutative86.5%
associate-*r*86.5%
metadata-eval86.5%
hypot-undefine59.5%
unpow259.5%
unpow259.5%
+-commutative59.5%
unpow259.5%
unpow259.5%
hypot-undefine86.5%
Simplified86.5%
Taylor expanded in im around inf 76.0%
if 3.1999999999999998e46 < re Initial program 8.5%
Taylor expanded in re around inf 49.5%
*-commutative49.5%
sqrt-div59.2%
sqrt-pow173.4%
metadata-eval73.4%
pow173.4%
associate-*l/73.4%
Applied egg-rr73.4%
(FPCore (re im) :precision binary64 (if (<= re -0.0105) (sqrt (- re)) (if (<= re 8.2e+46) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -0.0105) {
tmp = sqrt(-re);
} else if (re <= 8.2e+46) {
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 <= (-0.0105d0)) then
tmp = sqrt(-re)
else if (re <= 8.2d+46) 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 <= -0.0105) {
tmp = Math.sqrt(-re);
} else if (re <= 8.2e+46) {
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 <= -0.0105: tmp = math.sqrt(-re) elif re <= 8.2e+46: 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 <= -0.0105) tmp = sqrt(Float64(-re)); elseif (re <= 8.2e+46) 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 <= -0.0105) tmp = sqrt(-re); elseif (re <= 8.2e+46) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.0105], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 8.2e+46], 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 -0.0105:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 8.2 \cdot 10^{+46}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -0.0105000000000000007Initial program 43.4%
pow143.4%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine43.4%
unpow243.4%
unpow243.4%
+-commutative43.4%
unpow243.4%
unpow243.4%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 77.2%
neg-mul-177.2%
Simplified77.2%
if -0.0105000000000000007 < re < 8.19999999999999999e46Initial program 59.5%
pow159.5%
Applied egg-rr86.5%
unpow186.5%
*-commutative86.5%
associate-*r*86.5%
metadata-eval86.5%
hypot-undefine59.5%
unpow259.5%
unpow259.5%
+-commutative59.5%
unpow259.5%
unpow259.5%
hypot-undefine86.5%
Simplified86.5%
Taylor expanded in re around 0 76.0%
neg-mul-176.0%
unsub-neg76.0%
Simplified76.0%
if 8.19999999999999999e46 < re Initial program 8.5%
Taylor expanded in re around inf 49.5%
*-commutative49.5%
sqrt-div59.2%
sqrt-pow173.4%
metadata-eval73.4%
pow173.4%
associate-*l/73.4%
Applied egg-rr73.4%
(FPCore (re im) :precision binary64 (if (<= re -0.00029) (sqrt (- re)) (if (<= re 2.9e+46) (sqrt (* 0.5 (- im re))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -0.00029) {
tmp = sqrt(-re);
} else if (re <= 2.9e+46) {
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 <= (-0.00029d0)) then
tmp = sqrt(-re)
else if (re <= 2.9d+46) 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 <= -0.00029) {
tmp = Math.sqrt(-re);
} else if (re <= 2.9e+46) {
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 <= -0.00029: tmp = math.sqrt(-re) elif re <= 2.9e+46: 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 <= -0.00029) tmp = sqrt(Float64(-re)); elseif (re <= 2.9e+46) 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 <= -0.00029) tmp = sqrt(-re); elseif (re <= 2.9e+46) tmp = sqrt((0.5 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.00029], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 2.9e+46], 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 -0.00029:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 2.9 \cdot 10^{+46}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.9e-4Initial program 43.4%
pow143.4%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine43.4%
unpow243.4%
unpow243.4%
+-commutative43.4%
unpow243.4%
unpow243.4%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 77.2%
neg-mul-177.2%
Simplified77.2%
if -2.9e-4 < re < 2.9000000000000002e46Initial program 59.5%
pow159.5%
Applied egg-rr86.5%
unpow186.5%
*-commutative86.5%
associate-*r*86.5%
metadata-eval86.5%
hypot-undefine59.5%
unpow259.5%
unpow259.5%
+-commutative59.5%
unpow259.5%
unpow259.5%
hypot-undefine86.5%
Simplified86.5%
Taylor expanded in re around 0 76.0%
neg-mul-176.0%
unsub-neg76.0%
Simplified76.0%
if 2.9000000000000002e46 < re Initial program 8.5%
Taylor expanded in re around inf 49.5%
sqrt-div59.2%
sqrt-pow173.4%
metadata-eval73.4%
pow173.4%
associate-*r/73.4%
Applied egg-rr73.4%
*-commutative73.4%
associate-/l*73.3%
Simplified73.3%
(FPCore (re im) :precision binary64 (if (<= re -0.033) (sqrt (- re)) (if (<= re 2.7e+46) (sqrt (* 0.5 (- im re))) (* im (sqrt (/ 0.25 re))))))
double code(double re, double im) {
double tmp;
if (re <= -0.033) {
tmp = sqrt(-re);
} else if (re <= 2.7e+46) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = im * sqrt((0.25 / re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-0.033d0)) then
tmp = sqrt(-re)
else if (re <= 2.7d+46) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = im * sqrt((0.25d0 / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.033) {
tmp = Math.sqrt(-re);
} else if (re <= 2.7e+46) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = im * Math.sqrt((0.25 / re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.033: tmp = math.sqrt(-re) elif re <= 2.7e+46: tmp = math.sqrt((0.5 * (im - re))) else: tmp = im * math.sqrt((0.25 / re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.033) tmp = sqrt(Float64(-re)); elseif (re <= 2.7e+46) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(im * sqrt(Float64(0.25 / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.033) tmp = sqrt(-re); elseif (re <= 2.7e+46) tmp = sqrt((0.5 * (im - re))); else tmp = im * sqrt((0.25 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.033], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 2.7e+46], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(im * N[Sqrt[N[(0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.033:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 2.7 \cdot 10^{+46}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\end{array}
\end{array}
if re < -0.033000000000000002Initial program 43.4%
pow143.4%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine43.4%
unpow243.4%
unpow243.4%
+-commutative43.4%
unpow243.4%
unpow243.4%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 77.2%
neg-mul-177.2%
Simplified77.2%
if -0.033000000000000002 < re < 2.7000000000000002e46Initial program 59.5%
pow159.5%
Applied egg-rr86.5%
unpow186.5%
*-commutative86.5%
associate-*r*86.5%
metadata-eval86.5%
hypot-undefine59.5%
unpow259.5%
unpow259.5%
+-commutative59.5%
unpow259.5%
unpow259.5%
hypot-undefine86.5%
Simplified86.5%
Taylor expanded in re around 0 76.0%
neg-mul-176.0%
unsub-neg76.0%
Simplified76.0%
if 2.7000000000000002e46 < re Initial program 8.5%
Taylor expanded in re around inf 49.5%
sqrt-div59.2%
sqrt-pow173.4%
metadata-eval73.4%
pow173.4%
associate-*r/73.4%
Applied egg-rr73.4%
*-commutative73.4%
associate-/l*73.3%
Simplified73.3%
add-sqr-sqrt73.1%
sqrt-unprod73.3%
frac-times73.3%
metadata-eval73.3%
add-sqr-sqrt73.2%
Applied egg-rr73.2%
(FPCore (re im) :precision binary64 (if (<= re -0.0054) (sqrt (- re)) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -0.0054) {
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 <= (-0.0054d0)) 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 <= -0.0054) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.0054: tmp = math.sqrt(-re) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.0054) 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 <= -0.0054) tmp = sqrt(-re); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.0054], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.0054:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -0.0054000000000000003Initial program 43.4%
pow143.4%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine43.4%
unpow243.4%
unpow243.4%
+-commutative43.4%
unpow243.4%
unpow243.4%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 77.2%
neg-mul-177.2%
Simplified77.2%
if -0.0054000000000000003 < re Initial program 49.0%
pow149.0%
Applied egg-rr76.7%
unpow176.7%
*-commutative76.7%
associate-*r*76.7%
metadata-eval76.7%
hypot-undefine49.0%
unpow249.0%
unpow249.0%
+-commutative49.0%
unpow249.0%
unpow249.0%
hypot-undefine76.7%
Simplified76.7%
Taylor expanded in im around inf 66.3%
*-commutative66.3%
Simplified66.3%
(FPCore (re im) :precision binary64 (if (<= re -2e-310) (sqrt (- re)) (sqrt re)))
double code(double re, double im) {
double tmp;
if (re <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2e-310: tmp = math.sqrt(-re) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -2e-310) tmp = sqrt(Float64(-re)); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2e-310) tmp = sqrt(-re); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2e-310], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.999999999999994e-310Initial program 54.8%
pow154.8%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine54.8%
unpow254.8%
unpow254.8%
+-commutative54.8%
unpow254.8%
unpow254.8%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 50.1%
neg-mul-150.1%
Simplified50.1%
if -1.999999999999994e-310 < re Initial program 38.7%
pow138.7%
Applied egg-rr61.6%
unpow161.6%
*-commutative61.6%
associate-*r*61.6%
metadata-eval61.6%
hypot-undefine38.7%
unpow238.7%
unpow238.7%
+-commutative38.7%
unpow238.7%
unpow238.7%
hypot-undefine61.6%
Simplified61.6%
Taylor expanded in re around -inf 0.0%
neg-mul-10.0%
Simplified0.0%
neg-sub00.0%
sub-neg0.0%
add-sqr-sqrt0.0%
sqrt-unprod4.5%
sqr-neg4.5%
sqrt-unprod6.0%
add-sqr-sqrt6.0%
Applied egg-rr6.0%
+-lft-identity6.0%
Simplified6.0%
(FPCore (re im) :precision binary64 0.0)
double code(double re, double im) {
return 0.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.0d0
end function
public static double code(double re, double im) {
return 0.0;
}
def code(re, im): return 0.0
function code(re, im) return 0.0 end
function tmp = code(re, im) tmp = 0.0; end
code[re_, im_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 47.6%
Taylor expanded in re around inf 4.0%
Taylor expanded in re around 0 4.0%
herbie shell --seed 2024153
(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)))))