
(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 (<= re 1.5e+91) (sqrt (* 0.5 (- (hypot im re) re))) (/ (* 0.5 im) (sqrt re))))
double code(double re, double im) {
double tmp;
if (re <= 1.5e+91) {
tmp = sqrt((0.5 * (hypot(im, re) - re)));
} else {
tmp = (0.5 * im) / sqrt(re);
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 1.5e+91) {
tmp = Math.sqrt((0.5 * (Math.hypot(im, re) - re)));
} else {
tmp = (0.5 * im) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.5e+91: tmp = math.sqrt((0.5 * (math.hypot(im, re) - re))) else: tmp = (0.5 * im) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.5e+91) tmp = sqrt(Float64(0.5 * Float64(hypot(im, re) - re))); else tmp = Float64(Float64(0.5 * im) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.5e+91) tmp = sqrt((0.5 * (hypot(im, re) - re))); else tmp = (0.5 * im) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.5e+91], N[Sqrt[N[(0.5 * N[(N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(0.5 * im), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.5 \cdot 10^{+91}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(im, re\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 1.50000000000000003e91Initial program 53.7%
pow153.7%
Applied egg-rr93.6%
unpow193.6%
*-commutative93.6%
associate-*r*93.6%
metadata-eval93.6%
hypot-undefine53.7%
unpow253.7%
unpow253.7%
+-commutative53.7%
unpow253.7%
unpow253.7%
hypot-undefine93.6%
Simplified93.6%
if 1.50000000000000003e91 < re Initial program 6.2%
pow16.2%
Applied egg-rr33.0%
unpow133.0%
*-commutative33.0%
associate-*r*33.0%
metadata-eval33.0%
hypot-undefine6.2%
unpow26.2%
unpow26.2%
+-commutative6.2%
unpow26.2%
unpow26.2%
hypot-undefine33.0%
Simplified33.0%
Taylor expanded in im around 0 84.3%
associate-*l*84.2%
unpow284.2%
rem-square-sqrt85.2%
Simplified85.2%
sqrt-div85.1%
metadata-eval85.1%
div-inv85.1%
clear-num85.1%
un-div-inv85.2%
div-inv85.2%
metadata-eval85.2%
Applied egg-rr85.2%
*-rgt-identity85.2%
times-frac85.2%
metadata-eval85.2%
*-commutative85.2%
associate-*r/85.2%
Simplified85.2%
(FPCore (re im) :precision binary64 (if (<= re -1.5e-23) (sqrt (- re)) (if (<= re 7.4e+90) (sqrt (* 0.5 (- im re))) (/ (* 0.5 im) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.5e-23) {
tmp = sqrt(-re);
} else if (re <= 7.4e+90) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = (0.5 * im) / 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.5d-23)) then
tmp = sqrt(-re)
else if (re <= 7.4d+90) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = (0.5d0 * im) / sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.5e-23) {
tmp = Math.sqrt(-re);
} else if (re <= 7.4e+90) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (0.5 * im) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.5e-23: tmp = math.sqrt(-re) elif re <= 7.4e+90: tmp = math.sqrt((0.5 * (im - re))) else: tmp = (0.5 * im) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.5e-23) tmp = sqrt(Float64(-re)); elseif (re <= 7.4e+90) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(0.5 * im) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.5e-23) tmp = sqrt(-re); elseif (re <= 7.4e+90) tmp = sqrt((0.5 * (im - re))); else tmp = (0.5 * im) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.5e-23], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 7.4e+90], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(0.5 * im), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.5 \cdot 10^{-23}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 7.4 \cdot 10^{+90}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.50000000000000001e-23Initial program 49.9%
pow149.9%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine49.9%
unpow249.9%
unpow249.9%
+-commutative49.9%
unpow249.9%
unpow249.9%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 73.1%
neg-mul-173.1%
Simplified73.1%
if -1.50000000000000001e-23 < re < 7.4e90Initial program 55.5%
pow155.5%
Applied egg-rr90.7%
unpow190.7%
*-commutative90.7%
associate-*r*90.7%
metadata-eval90.7%
hypot-undefine55.5%
unpow255.5%
unpow255.5%
+-commutative55.5%
unpow255.5%
unpow255.5%
hypot-undefine90.7%
Simplified90.7%
Taylor expanded in re around 0 79.1%
neg-mul-179.1%
unsub-neg79.1%
Simplified79.1%
if 7.4e90 < re Initial program 6.2%
pow16.2%
Applied egg-rr33.0%
unpow133.0%
*-commutative33.0%
associate-*r*33.0%
metadata-eval33.0%
hypot-undefine6.2%
unpow26.2%
unpow26.2%
+-commutative6.2%
unpow26.2%
unpow26.2%
hypot-undefine33.0%
Simplified33.0%
Taylor expanded in im around 0 84.3%
associate-*l*84.2%
unpow284.2%
rem-square-sqrt85.2%
Simplified85.2%
sqrt-div85.1%
metadata-eval85.1%
div-inv85.1%
clear-num85.1%
un-div-inv85.2%
div-inv85.2%
metadata-eval85.2%
Applied egg-rr85.2%
*-rgt-identity85.2%
times-frac85.2%
metadata-eval85.2%
*-commutative85.2%
associate-*r/85.2%
Simplified85.2%
(FPCore (re im) :precision binary64 (if (<= re -5.2e-24) (sqrt (- re)) (if (<= re 4.2e+90) (sqrt (* 0.5 (- im re))) (* im (sqrt (/ 0.25 re))))))
double code(double re, double im) {
double tmp;
if (re <= -5.2e-24) {
tmp = sqrt(-re);
} else if (re <= 4.2e+90) {
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 <= (-5.2d-24)) then
tmp = sqrt(-re)
else if (re <= 4.2d+90) 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 <= -5.2e-24) {
tmp = Math.sqrt(-re);
} else if (re <= 4.2e+90) {
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 <= -5.2e-24: tmp = math.sqrt(-re) elif re <= 4.2e+90: 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 <= -5.2e-24) tmp = sqrt(Float64(-re)); elseif (re <= 4.2e+90) 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 <= -5.2e-24) tmp = sqrt(-re); elseif (re <= 4.2e+90) tmp = sqrt((0.5 * (im - re))); else tmp = im * sqrt((0.25 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5.2e-24], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 4.2e+90], 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 -5.2 \cdot 10^{-24}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 4.2 \cdot 10^{+90}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\end{array}
\end{array}
if re < -5.2e-24Initial program 49.9%
pow149.9%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine49.9%
unpow249.9%
unpow249.9%
+-commutative49.9%
unpow249.9%
unpow249.9%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 73.1%
neg-mul-173.1%
Simplified73.1%
if -5.2e-24 < re < 4.19999999999999961e90Initial program 55.5%
pow155.5%
Applied egg-rr90.7%
unpow190.7%
*-commutative90.7%
associate-*r*90.7%
metadata-eval90.7%
hypot-undefine55.5%
unpow255.5%
unpow255.5%
+-commutative55.5%
unpow255.5%
unpow255.5%
hypot-undefine90.7%
Simplified90.7%
Taylor expanded in re around 0 79.1%
neg-mul-179.1%
unsub-neg79.1%
Simplified79.1%
if 4.19999999999999961e90 < re Initial program 6.2%
Taylor expanded in re around inf 84.3%
*-commutative84.3%
associate-*l*84.3%
*-commutative84.3%
*-commutative84.3%
associate-*l*84.5%
Simplified84.5%
add-cube-cbrt83.9%
pow383.9%
associate-*r*83.9%
sqrt-unprod83.6%
metadata-eval83.6%
metadata-eval83.6%
*-un-lft-identity83.6%
*-commutative83.6%
sqrt-div83.5%
metadata-eval83.5%
un-div-inv83.5%
Applied egg-rr83.5%
rem-cube-cbrt85.1%
*-commutative85.1%
add-sqr-sqrt84.9%
sqrt-unprod85.1%
frac-times85.0%
metadata-eval85.0%
add-sqr-sqrt85.2%
Applied egg-rr85.2%
Final simplification78.7%
(FPCore (re im) :precision binary64 (if (<= re -1.2e-23) (sqrt (- re)) (if (<= re 4.2e+90) (sqrt (* 0.5 (- im re))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.2e-23) {
tmp = sqrt(-re);
} else if (re <= 4.2e+90) {
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 <= (-1.2d-23)) then
tmp = sqrt(-re)
else if (re <= 4.2d+90) 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 <= -1.2e-23) {
tmp = Math.sqrt(-re);
} else if (re <= 4.2e+90) {
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 <= -1.2e-23: tmp = math.sqrt(-re) elif re <= 4.2e+90: 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 <= -1.2e-23) tmp = sqrt(Float64(-re)); elseif (re <= 4.2e+90) 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 <= -1.2e-23) tmp = sqrt(-re); elseif (re <= 4.2e+90) tmp = sqrt((0.5 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.2e-23], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 4.2e+90], 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 -1.2 \cdot 10^{-23}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 4.2 \cdot 10^{+90}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.19999999999999998e-23Initial program 49.9%
pow149.9%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine49.9%
unpow249.9%
unpow249.9%
+-commutative49.9%
unpow249.9%
unpow249.9%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 73.1%
neg-mul-173.1%
Simplified73.1%
if -1.19999999999999998e-23 < re < 4.19999999999999961e90Initial program 55.5%
pow155.5%
Applied egg-rr90.7%
unpow190.7%
*-commutative90.7%
associate-*r*90.7%
metadata-eval90.7%
hypot-undefine55.5%
unpow255.5%
unpow255.5%
+-commutative55.5%
unpow255.5%
unpow255.5%
hypot-undefine90.7%
Simplified90.7%
Taylor expanded in re around 0 79.1%
neg-mul-179.1%
unsub-neg79.1%
Simplified79.1%
if 4.19999999999999961e90 < re Initial program 6.2%
Taylor expanded in re around inf 84.3%
*-commutative84.3%
associate-*l*84.3%
*-commutative84.3%
*-commutative84.3%
associate-*l*84.5%
Simplified84.5%
pow184.5%
associate-*r*84.3%
sqrt-unprod85.2%
metadata-eval85.2%
metadata-eval85.2%
*-un-lft-identity85.2%
*-commutative85.2%
sqrt-div85.1%
metadata-eval85.1%
un-div-inv85.1%
Applied egg-rr85.1%
unpow185.1%
Simplified85.1%
(FPCore (re im) :precision binary64 (if (<= im 4.5e-152) (sqrt (- re)) (sqrt (* 0.5 (- im re)))))
double code(double re, double im) {
double tmp;
if (im <= 4.5e-152) {
tmp = sqrt(-re);
} else {
tmp = sqrt((0.5 * (im - re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 4.5d-152) then
tmp = sqrt(-re)
else
tmp = sqrt((0.5d0 * (im - re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.5e-152) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((0.5 * (im - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.5e-152: tmp = math.sqrt(-re) else: tmp = math.sqrt((0.5 * (im - re))) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.5e-152) tmp = sqrt(Float64(-re)); else tmp = sqrt(Float64(0.5 * Float64(im - re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.5e-152) tmp = sqrt(-re); else tmp = sqrt((0.5 * (im - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.5e-152], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.5 \cdot 10^{-152}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\end{array}
\end{array}
if im < 4.5000000000000004e-152Initial program 45.3%
pow145.3%
Applied egg-rr79.9%
unpow179.9%
*-commutative79.9%
associate-*r*79.9%
metadata-eval79.9%
hypot-undefine45.3%
unpow245.3%
unpow245.3%
+-commutative45.3%
unpow245.3%
unpow245.3%
hypot-undefine79.9%
Simplified79.9%
Taylor expanded in re around -inf 57.3%
neg-mul-157.3%
Simplified57.3%
if 4.5000000000000004e-152 < im Initial program 44.7%
pow144.7%
Applied egg-rr83.1%
unpow183.1%
*-commutative83.1%
associate-*r*83.1%
metadata-eval83.1%
hypot-undefine44.7%
unpow244.7%
unpow244.7%
+-commutative44.7%
unpow244.7%
unpow244.7%
hypot-undefine83.1%
Simplified83.1%
Taylor expanded in re around 0 70.8%
neg-mul-170.8%
unsub-neg70.8%
Simplified70.8%
(FPCore (re im) :precision binary64 (if (<= im 8.6e-151) (sqrt (- re)) (sqrt (* 0.5 im))))
double code(double re, double im) {
double tmp;
if (im <= 8.6e-151) {
tmp = sqrt(-re);
} else {
tmp = sqrt((0.5 * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 8.6d-151) then
tmp = sqrt(-re)
else
tmp = sqrt((0.5d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 8.6e-151) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((0.5 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 8.6e-151: tmp = math.sqrt(-re) else: tmp = math.sqrt((0.5 * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 8.6e-151) tmp = sqrt(Float64(-re)); else tmp = sqrt(Float64(0.5 * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 8.6e-151) tmp = sqrt(-re); else tmp = sqrt((0.5 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 8.6e-151], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(0.5 * im), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8.6 \cdot 10^{-151}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot im}\\
\end{array}
\end{array}
if im < 8.60000000000000035e-151Initial program 45.3%
pow145.3%
Applied egg-rr79.9%
unpow179.9%
*-commutative79.9%
associate-*r*79.9%
metadata-eval79.9%
hypot-undefine45.3%
unpow245.3%
unpow245.3%
+-commutative45.3%
unpow245.3%
unpow245.3%
hypot-undefine79.9%
Simplified79.9%
Taylor expanded in re around -inf 57.3%
neg-mul-157.3%
Simplified57.3%
if 8.60000000000000035e-151 < im Initial program 44.7%
pow144.7%
Applied egg-rr83.1%
unpow183.1%
*-commutative83.1%
associate-*r*83.1%
metadata-eval83.1%
hypot-undefine44.7%
unpow244.7%
unpow244.7%
+-commutative44.7%
unpow244.7%
unpow244.7%
hypot-undefine83.1%
Simplified83.1%
Taylor expanded in im around inf 69.7%
*-commutative69.7%
Simplified69.7%
Final simplification66.4%
(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 59.4%
pow159.4%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
hypot-undefine59.4%
unpow259.4%
unpow259.4%
+-commutative59.4%
unpow259.4%
unpow259.4%
hypot-undefine100.0%
Simplified100.0%
Taylor expanded in re around -inf 50.2%
neg-mul-150.2%
Simplified50.2%
if -4.999999999999985e-310 < re Initial program 28.1%
pow128.1%
Applied egg-rr61.8%
unpow161.8%
*-commutative61.8%
associate-*r*61.8%
metadata-eval61.8%
hypot-undefine28.1%
unpow228.1%
unpow228.1%
+-commutative28.1%
unpow228.1%
unpow228.1%
hypot-undefine61.8%
Simplified61.8%
Taylor expanded in re around -inf 0.0%
neg-mul-10.0%
Simplified0.0%
Taylor expanded in re around 0 0.0%
mul-1-neg0.0%
rem-square-sqrt0.0%
distribute-rgt-neg-out0.0%
neg-mul-10.0%
rem-square-sqrt0.0%
unpow1/20.0%
metadata-eval0.0%
pow-sqr0.0%
unswap-sqr0.0%
fabs-sqr0.0%
unswap-sqr0.0%
rem-square-sqrt5.9%
pow-sqr5.9%
metadata-eval5.9%
unpow1/25.9%
neg-mul-15.9%
fabs-neg5.9%
rem-sqrt-square5.9%
rem-square-sqrt5.9%
rem-square-sqrt5.9%
Simplified5.9%
(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.8%
pow144.8%
Applied egg-rr82.3%
unpow182.3%
*-commutative82.3%
associate-*r*82.3%
metadata-eval82.3%
hypot-undefine44.8%
unpow244.8%
unpow244.8%
+-commutative44.8%
unpow244.8%
unpow244.8%
hypot-undefine82.3%
Simplified82.3%
Taylor expanded in re around -inf 26.9%
neg-mul-126.9%
Simplified26.9%
Taylor expanded in re around 0 26.9%
mul-1-neg26.9%
rem-square-sqrt0.0%
distribute-rgt-neg-out0.0%
neg-mul-10.0%
rem-square-sqrt0.0%
unpow1/20.0%
metadata-eval0.0%
pow-sqr0.0%
unswap-sqr0.0%
fabs-sqr0.0%
unswap-sqr0.0%
rem-square-sqrt2.7%
pow-sqr2.7%
metadata-eval2.7%
unpow1/22.7%
neg-mul-12.7%
fabs-neg2.7%
rem-sqrt-square2.7%
rem-square-sqrt2.7%
rem-square-sqrt2.7%
Simplified2.7%
herbie shell --seed 2024188
(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)))))