
(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) (* 0.5 (* im (pow re -0.5))) (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 = 0.5 * (im * pow(re, -0.5));
} 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 = 0.5 * (im * Math.pow(re, -0.5));
} 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 = 0.5 * (im * math.pow(re, -0.5)) 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(0.5 * Float64(im * (re ^ -0.5))); 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 = 0.5 * (im * (re ^ -0.5)); 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[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $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:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\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 8.4%
sub-neg8.4%
sqr-neg8.4%
sub-neg8.4%
sqr-neg8.4%
hypot-define11.5%
Simplified11.5%
Taylor expanded in re around inf 38.9%
div-inv39.0%
sqrt-prod45.5%
sqrt-pow197.3%
metadata-eval97.3%
pow197.3%
*-commutative97.3%
inv-pow97.3%
sqrt-pow197.4%
metadata-eval97.4%
Applied egg-rr97.4%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 43.3%
sub-neg43.3%
sqr-neg43.3%
sub-neg43.3%
sqr-neg43.3%
hypot-define88.6%
Simplified88.6%
*-commutative88.6%
hypot-define43.3%
*-commutative43.3%
add-sqr-sqrt42.9%
sqrt-unprod43.3%
*-commutative43.3%
*-commutative43.3%
swap-sqr43.3%
Applied egg-rr88.6%
associate-*l*88.6%
hypot-undefine43.3%
unpow243.3%
unpow243.3%
+-commutative43.3%
unpow243.3%
unpow243.3%
hypot-undefine88.6%
metadata-eval88.6%
Simplified88.6%
Final simplification89.9%
(FPCore (re im) :precision binary64 (if (<= re -6e+87) (sqrt (- re)) (if (<= re 1.1e-49) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -6e+87) {
tmp = sqrt(-re);
} else if (re <= 1.1e-49) {
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 <= (-6d+87)) then
tmp = sqrt(-re)
else if (re <= 1.1d-49) 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 <= -6e+87) {
tmp = Math.sqrt(-re);
} else if (re <= 1.1e-49) {
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 <= -6e+87: tmp = math.sqrt(-re) elif re <= 1.1e-49: 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 <= -6e+87) tmp = sqrt(Float64(-re)); elseif (re <= 1.1e-49) 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 <= -6e+87) tmp = sqrt(-re); elseif (re <= 1.1e-49) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6e+87], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.1e-49], 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 -6 \cdot 10^{+87}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.1 \cdot 10^{-49}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -5.9999999999999998e87Initial program 26.2%
sub-neg26.2%
sqr-neg26.2%
sub-neg26.2%
sqr-neg26.2%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define26.2%
*-commutative26.2%
add-sqr-sqrt26.1%
sqrt-unprod26.2%
*-commutative26.2%
*-commutative26.2%
swap-sqr26.2%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine26.2%
unpow226.2%
unpow226.2%
+-commutative26.2%
unpow226.2%
unpow226.2%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 86.8%
neg-mul-186.8%
Simplified86.8%
if -5.9999999999999998e87 < re < 1.09999999999999995e-49Initial program 55.9%
sub-neg55.9%
sqr-neg55.9%
sub-neg55.9%
sqr-neg55.9%
hypot-define90.7%
Simplified90.7%
*-commutative90.7%
hypot-define55.9%
*-commutative55.9%
add-sqr-sqrt55.5%
sqrt-unprod55.9%
*-commutative55.9%
*-commutative55.9%
swap-sqr55.9%
Applied egg-rr90.7%
associate-*l*90.7%
hypot-undefine55.9%
unpow255.9%
unpow255.9%
+-commutative55.9%
unpow255.9%
unpow255.9%
hypot-undefine90.7%
metadata-eval90.7%
Simplified90.7%
Taylor expanded in re around 0 75.7%
neg-mul-175.7%
unsub-neg75.7%
Simplified75.7%
if 1.09999999999999995e-49 < re Initial program 14.6%
sub-neg14.6%
sqr-neg14.6%
sub-neg14.6%
sqr-neg14.6%
hypot-define39.7%
Simplified39.7%
Taylor expanded in re around inf 45.5%
*-commutative45.5%
sqrt-div58.1%
sqrt-pow176.9%
metadata-eval76.9%
pow176.9%
associate-*l/76.9%
Applied egg-rr76.9%
Final simplification78.1%
(FPCore (re im) :precision binary64 (if (<= re -4.2e+86) (sqrt (- re)) (if (<= re 8.2e-50) (sqrt (* 0.5 (- im re))) (* im (sqrt (/ 0.25 re))))))
double code(double re, double im) {
double tmp;
if (re <= -4.2e+86) {
tmp = sqrt(-re);
} else if (re <= 8.2e-50) {
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 <= (-4.2d+86)) then
tmp = sqrt(-re)
else if (re <= 8.2d-50) 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 <= -4.2e+86) {
tmp = Math.sqrt(-re);
} else if (re <= 8.2e-50) {
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 <= -4.2e+86: tmp = math.sqrt(-re) elif re <= 8.2e-50: 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 <= -4.2e+86) tmp = sqrt(Float64(-re)); elseif (re <= 8.2e-50) 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 <= -4.2e+86) tmp = sqrt(-re); elseif (re <= 8.2e-50) tmp = sqrt((0.5 * (im - re))); else tmp = im * sqrt((0.25 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.2e+86], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 8.2e-50], 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 -4.2 \cdot 10^{+86}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 8.2 \cdot 10^{-50}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\end{array}
\end{array}
if re < -4.1999999999999998e86Initial program 26.2%
sub-neg26.2%
sqr-neg26.2%
sub-neg26.2%
sqr-neg26.2%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define26.2%
*-commutative26.2%
add-sqr-sqrt26.1%
sqrt-unprod26.2%
*-commutative26.2%
*-commutative26.2%
swap-sqr26.2%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine26.2%
unpow226.2%
unpow226.2%
+-commutative26.2%
unpow226.2%
unpow226.2%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 86.8%
neg-mul-186.8%
Simplified86.8%
if -4.1999999999999998e86 < re < 8.19999999999999971e-50Initial program 55.9%
sub-neg55.9%
sqr-neg55.9%
sub-neg55.9%
sqr-neg55.9%
hypot-define90.7%
Simplified90.7%
*-commutative90.7%
hypot-define55.9%
*-commutative55.9%
add-sqr-sqrt55.5%
sqrt-unprod55.9%
*-commutative55.9%
*-commutative55.9%
swap-sqr55.9%
Applied egg-rr90.7%
associate-*l*90.7%
hypot-undefine55.9%
unpow255.9%
unpow255.9%
+-commutative55.9%
unpow255.9%
unpow255.9%
hypot-undefine90.7%
metadata-eval90.7%
Simplified90.7%
Taylor expanded in re around 0 75.7%
neg-mul-175.7%
unsub-neg75.7%
Simplified75.7%
if 8.19999999999999971e-50 < re Initial program 14.6%
sub-neg14.6%
sqr-neg14.6%
sub-neg14.6%
sqr-neg14.6%
hypot-define39.7%
Simplified39.7%
Taylor expanded in re around inf 75.9%
*-commutative75.9%
associate-*l*75.9%
*-commutative75.9%
associate-*r*75.9%
associate-*l*75.9%
*-commutative75.9%
Simplified75.9%
add-sqr-sqrt75.8%
sqrt-unprod75.9%
sqrt-unprod76.4%
metadata-eval76.4%
metadata-eval76.4%
metadata-eval76.4%
sqrt-unprod76.9%
metadata-eval76.9%
metadata-eval76.9%
metadata-eval76.9%
swap-sqr76.9%
add-sqr-sqrt76.9%
metadata-eval76.9%
Applied egg-rr76.9%
associate-*l/76.9%
metadata-eval76.9%
Simplified76.9%
Final simplification78.1%
(FPCore (re im) :precision binary64 (if (<= re -1.6e+86) (sqrt (- re)) (if (<= re 7e+237) (sqrt (* 0.5 (- im re))) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -1.6e+86) {
tmp = sqrt(-re);
} else if (re <= 7e+237) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.6d+86)) then
tmp = sqrt(-re)
else if (re <= 7d+237) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.6e+86) {
tmp = Math.sqrt(-re);
} else if (re <= 7e+237) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.6e+86: tmp = math.sqrt(-re) elif re <= 7e+237: tmp = math.sqrt((0.5 * (im - re))) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -1.6e+86) tmp = sqrt(Float64(-re)); elseif (re <= 7e+237) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.6e+86) tmp = sqrt(-re); elseif (re <= 7e+237) tmp = sqrt((0.5 * (im - re))); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.6e+86], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 7e+237], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.6 \cdot 10^{+86}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 7 \cdot 10^{+237}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -1.6e86Initial program 26.2%
sub-neg26.2%
sqr-neg26.2%
sub-neg26.2%
sqr-neg26.2%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define26.2%
*-commutative26.2%
add-sqr-sqrt26.1%
sqrt-unprod26.2%
*-commutative26.2%
*-commutative26.2%
swap-sqr26.2%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine26.2%
unpow226.2%
unpow226.2%
+-commutative26.2%
unpow226.2%
unpow226.2%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 86.8%
neg-mul-186.8%
Simplified86.8%
if -1.6e86 < re < 6.99999999999999976e237Initial program 45.3%
sub-neg45.3%
sqr-neg45.3%
sub-neg45.3%
sqr-neg45.3%
hypot-define75.9%
Simplified75.9%
*-commutative75.9%
hypot-define45.3%
*-commutative45.3%
add-sqr-sqrt45.0%
sqrt-unprod45.3%
*-commutative45.3%
*-commutative45.3%
swap-sqr45.3%
Applied egg-rr75.9%
associate-*l*75.9%
hypot-undefine45.3%
unpow245.3%
unpow245.3%
+-commutative45.3%
unpow245.3%
unpow245.3%
hypot-undefine75.9%
metadata-eval75.9%
Simplified75.9%
Taylor expanded in re around 0 63.0%
neg-mul-163.0%
unsub-neg63.0%
Simplified63.0%
if 6.99999999999999976e237 < re Initial program 2.6%
Taylor expanded in re around inf 31.3%
Taylor expanded in re around 0 31.3%
metadata-eval31.3%
Applied egg-rr31.3%
Final simplification64.8%
(FPCore (re im) :precision binary64 (if (<= re -3.2e+60) (sqrt (- re)) (if (<= re 6.8e+238) (sqrt (* im 0.5)) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -3.2e+60) {
tmp = sqrt(-re);
} else if (re <= 6.8e+238) {
tmp = sqrt((im * 0.5));
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.2d+60)) then
tmp = sqrt(-re)
else if (re <= 6.8d+238) then
tmp = sqrt((im * 0.5d0))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.2e+60) {
tmp = Math.sqrt(-re);
} else if (re <= 6.8e+238) {
tmp = Math.sqrt((im * 0.5));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.2e+60: tmp = math.sqrt(-re) elif re <= 6.8e+238: tmp = math.sqrt((im * 0.5)) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -3.2e+60) tmp = sqrt(Float64(-re)); elseif (re <= 6.8e+238) tmp = sqrt(Float64(im * 0.5)); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.2e+60) tmp = sqrt(-re); elseif (re <= 6.8e+238) tmp = sqrt((im * 0.5)); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.2e+60], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 6.8e+238], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.2 \cdot 10^{+60}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 6.8 \cdot 10^{+238}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -3.19999999999999991e60Initial program 30.0%
sub-neg30.0%
sqr-neg30.0%
sub-neg30.0%
sqr-neg30.0%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define30.0%
*-commutative30.0%
add-sqr-sqrt29.8%
sqrt-unprod30.0%
*-commutative30.0%
*-commutative30.0%
swap-sqr30.0%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine30.0%
unpow230.0%
unpow230.0%
+-commutative30.0%
unpow230.0%
unpow230.0%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 84.3%
neg-mul-184.3%
Simplified84.3%
if -3.19999999999999991e60 < re < 6.7999999999999995e238Initial program 44.6%
sub-neg44.6%
sqr-neg44.6%
sub-neg44.6%
sqr-neg44.6%
hypot-define75.3%
Simplified75.3%
*-commutative75.3%
hypot-define44.6%
*-commutative44.6%
add-sqr-sqrt44.3%
sqrt-unprod44.6%
*-commutative44.6%
*-commutative44.6%
swap-sqr44.6%
Applied egg-rr75.3%
associate-*l*75.3%
hypot-undefine44.6%
unpow244.6%
unpow244.6%
+-commutative44.6%
unpow244.6%
unpow244.6%
hypot-undefine75.3%
metadata-eval75.3%
Simplified75.3%
Taylor expanded in im around inf 62.9%
if 6.7999999999999995e238 < re Initial program 2.6%
Taylor expanded in re around inf 31.3%
Taylor expanded in re around 0 31.3%
metadata-eval31.3%
Applied egg-rr31.3%
(FPCore (re im) :precision binary64 (if (<= re -1e-310) (sqrt (- re)) 0.0))
double code(double re, double im) {
double tmp;
if (re <= -1e-310) {
tmp = sqrt(-re);
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1d-310)) then
tmp = sqrt(-re)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1e-310) {
tmp = Math.sqrt(-re);
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1e-310: tmp = math.sqrt(-re) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -1e-310) tmp = sqrt(Float64(-re)); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1e-310) tmp = sqrt(-re); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1e-310], N[Sqrt[(-re)], $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -9.999999999999969e-311Initial program 46.7%
sub-neg46.7%
sqr-neg46.7%
sub-neg46.7%
sqr-neg46.7%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define46.7%
*-commutative46.7%
add-sqr-sqrt46.3%
sqrt-unprod46.7%
*-commutative46.7%
*-commutative46.7%
swap-sqr46.7%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine46.7%
unpow246.7%
unpow246.7%
+-commutative46.7%
unpow246.7%
unpow246.7%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 53.1%
neg-mul-153.1%
Simplified53.1%
if -9.999999999999969e-311 < re Initial program 30.0%
Taylor expanded in re around inf 10.1%
Taylor expanded in re around 0 10.1%
metadata-eval10.1%
Applied egg-rr10.1%
(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 38.2%
Taylor expanded in re around inf 6.5%
Taylor expanded in re around 0 6.5%
metadata-eval6.5%
Applied egg-rr6.5%
herbie shell --seed 2024112
(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)))))