
(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 (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))) 0.0) (* (* im 0.5) (pow re -0.5)) (sqrt (* 0.5 (- (hypot re im) re)))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = (im * 0.5) * pow(re, -0.5);
} else {
tmp = sqrt((0.5 * (hypot(re, im) - re)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = (im * 0.5) * Math.pow(re, -0.5);
} else {
tmp = Math.sqrt((0.5 * (Math.hypot(re, im) - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re))) <= 0.0: tmp = (im * 0.5) * math.pow(re, -0.5) else: tmp = math.sqrt((0.5 * (math.hypot(re, im) - re))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) <= 0.0) tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); 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((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) tmp = (im * 0.5) * (re ^ -0.5); else tmp = sqrt((0.5 * (hypot(re, im) - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $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{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \leq 0:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 5.3%
Taylor expanded in re around inf 98.4%
associate-*l*98.3%
*-commutative98.3%
associate-*r*98.8%
Simplified98.8%
pow198.8%
add-log-exp13.6%
associate-*l*13.6%
exp-prod13.6%
sqrt-unprod13.6%
metadata-eval13.6%
metadata-eval13.6%
pow113.6%
add-log-exp99.5%
inv-pow99.5%
sqrt-pow199.7%
metadata-eval99.7%
Applied egg-rr99.7%
unpow199.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 49.9%
pow149.9%
Applied egg-rr90.8%
unpow190.8%
*-commutative90.8%
associate-*r*90.8%
metadata-eval90.8%
Simplified90.8%
(FPCore (re im) :precision binary64 (if (<= re -4.5e+17) (sqrt (- re)) (if (<= re 5.8e-36) (sqrt (* 0.5 (- im re))) (* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -4.5e+17) {
tmp = sqrt(-re);
} else if (re <= 5.8e-36) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * pow(re, -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 <= (-4.5d+17)) then
tmp = sqrt(-re)
else if (re <= 5.8d-36) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.5e+17) {
tmp = Math.sqrt(-re);
} else if (re <= 5.8e-36) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.5e+17: tmp = math.sqrt(-re) elif re <= 5.8e-36: tmp = math.sqrt((0.5 * (im - re))) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.5e+17) tmp = sqrt(Float64(-re)); elseif (re <= 5.8e-36) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.5e+17) tmp = sqrt(-re); elseif (re <= 5.8e-36) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.5e+17], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 5.8e-36], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.5 \cdot 10^{+17}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 5.8 \cdot 10^{-36}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -4.5e17Initial program 41.5%
pow141.5%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 76.2%
neg-mul-176.2%
Simplified76.2%
if -4.5e17 < re < 5.80000000000000026e-36Initial program 60.9%
pow160.9%
Applied egg-rr91.8%
unpow191.8%
*-commutative91.8%
associate-*r*91.8%
metadata-eval91.8%
Simplified91.8%
Taylor expanded in re around 0 82.4%
neg-mul-182.4%
sub-neg82.4%
Simplified82.4%
if 5.80000000000000026e-36 < re Initial program 11.2%
Taylor expanded in re around inf 71.5%
associate-*l*71.5%
*-commutative71.5%
associate-*r*71.7%
Simplified71.7%
pow171.7%
add-log-exp17.9%
associate-*l*17.9%
exp-prod17.9%
sqrt-unprod17.9%
metadata-eval17.9%
metadata-eval17.9%
pow117.9%
add-log-exp72.2%
inv-pow72.2%
sqrt-pow172.2%
metadata-eval72.2%
Applied egg-rr72.2%
unpow172.2%
associate-*r*72.2%
*-commutative72.2%
Simplified72.2%
(FPCore (re im) :precision binary64 (if (<= re -1.46e+18) (sqrt (- re)) (if (<= re 1.12e-34) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.46e+18) {
tmp = sqrt(-re);
} else if (re <= 1.12e-34) {
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.46d+18)) then
tmp = sqrt(-re)
else if (re <= 1.12d-34) 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.46e+18) {
tmp = Math.sqrt(-re);
} else if (re <= 1.12e-34) {
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.46e+18: tmp = math.sqrt(-re) elif re <= 1.12e-34: 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.46e+18) tmp = sqrt(Float64(-re)); elseif (re <= 1.12e-34) 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 <= -1.46e+18) tmp = sqrt(-re); elseif (re <= 1.12e-34) 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.46e+18], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.12e-34], 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 -1.46 \cdot 10^{+18}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.12 \cdot 10^{-34}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.46e18Initial program 41.5%
pow141.5%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 76.2%
neg-mul-176.2%
Simplified76.2%
if -1.46e18 < re < 1.12e-34Initial program 60.9%
pow160.9%
Applied egg-rr91.8%
unpow191.8%
*-commutative91.8%
associate-*r*91.8%
metadata-eval91.8%
Simplified91.8%
Taylor expanded in re around 0 82.4%
neg-mul-182.4%
sub-neg82.4%
Simplified82.4%
if 1.12e-34 < re Initial program 11.2%
Taylor expanded in re around inf 71.5%
associate-*l*71.5%
*-commutative71.5%
associate-*r*71.7%
Simplified71.7%
add-log-exp17.9%
associate-*l*17.9%
exp-prod17.9%
sqrt-unprod17.9%
metadata-eval17.9%
metadata-eval17.9%
pow117.9%
add-log-exp72.2%
sqrt-div72.0%
metadata-eval72.0%
Applied egg-rr72.0%
associate-*r*72.0%
un-div-inv72.2%
Applied egg-rr72.2%
Final simplification78.8%
(FPCore (re im) :precision binary64 (if (<= re -2.6e+18) (sqrt (- re)) (if (<= re 3.05e-34) (sqrt (* 0.5 (- im re))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -2.6e+18) {
tmp = sqrt(-re);
} else if (re <= 3.05e-34) {
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 <= (-2.6d+18)) then
tmp = sqrt(-re)
else if (re <= 3.05d-34) 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 <= -2.6e+18) {
tmp = Math.sqrt(-re);
} else if (re <= 3.05e-34) {
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 <= -2.6e+18: tmp = math.sqrt(-re) elif re <= 3.05e-34: 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 <= -2.6e+18) tmp = sqrt(Float64(-re)); elseif (re <= 3.05e-34) 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 <= -2.6e+18) tmp = sqrt(-re); elseif (re <= 3.05e-34) tmp = sqrt((0.5 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.6e+18], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 3.05e-34], 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 -2.6 \cdot 10^{+18}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 3.05 \cdot 10^{-34}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.6e18Initial program 41.5%
pow141.5%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 76.2%
neg-mul-176.2%
Simplified76.2%
if -2.6e18 < re < 3.0499999999999999e-34Initial program 60.9%
pow160.9%
Applied egg-rr91.8%
unpow191.8%
*-commutative91.8%
associate-*r*91.8%
metadata-eval91.8%
Simplified91.8%
Taylor expanded in re around 0 82.4%
neg-mul-182.4%
sub-neg82.4%
Simplified82.4%
if 3.0499999999999999e-34 < re Initial program 11.2%
Taylor expanded in re around inf 71.5%
associate-*l*71.5%
*-commutative71.5%
associate-*r*71.7%
Simplified71.7%
add-log-exp17.9%
associate-*l*17.9%
exp-prod17.9%
sqrt-unprod17.9%
metadata-eval17.9%
metadata-eval17.9%
pow117.9%
add-log-exp72.2%
sqrt-div72.0%
metadata-eval72.0%
Applied egg-rr72.0%
Taylor expanded in im around 0 72.2%
associate-*r*72.2%
unpow-172.2%
metadata-eval72.2%
pow-sqr72.2%
rem-sqrt-square72.2%
metadata-eval72.2%
pow-sqr72.1%
fabs-sqr72.1%
pow-sqr72.2%
metadata-eval72.2%
exp-to-pow68.2%
metadata-eval68.2%
distribute-rgt-neg-in68.2%
rec-exp68.2%
exp-to-pow72.0%
unpow1/272.0%
associate-/l*72.2%
*-rgt-identity72.2%
*-commutative72.2%
associate-/l*72.0%
Simplified72.0%
(FPCore (re im) :precision binary64 (if (<= re -4.6e+17) (sqrt (- re)) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -4.6e+17) {
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 <= (-4.6d+17)) 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 <= -4.6e+17) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.6e+17: tmp = math.sqrt(-re) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.6e+17) 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 <= -4.6e+17) tmp = sqrt(-re); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.6e+17], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.6 \cdot 10^{+17}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -4.6e17Initial program 41.5%
pow141.5%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 76.2%
neg-mul-176.2%
Simplified76.2%
if -4.6e17 < re Initial program 46.9%
pow146.9%
Applied egg-rr78.2%
unpow178.2%
*-commutative78.2%
associate-*r*78.2%
metadata-eval78.2%
Simplified78.2%
Taylor expanded in re around 0 67.8%
*-commutative67.8%
Simplified67.8%
(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 57.6%
pow157.6%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 44.0%
neg-mul-144.0%
Simplified44.0%
if -4.999999999999985e-310 < re Initial program 32.3%
pow132.3%
Applied egg-rr63.3%
unpow163.3%
*-commutative63.3%
associate-*r*63.3%
metadata-eval63.3%
Simplified63.3%
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%
associate-*r*0.0%
*-commutative0.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-sqrt6.0%
pow-sqr6.0%
metadata-eval6.0%
unpow1/26.0%
neg-mul-16.0%
fabs-neg6.0%
unpow1/26.0%
metadata-eval6.0%
pow-sqr6.0%
fabs-sqr6.0%
Simplified6.0%
(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 45.7%
pow145.7%
Applied egg-rr82.8%
unpow182.8%
*-commutative82.8%
associate-*r*82.8%
metadata-eval82.8%
Simplified82.8%
Taylor expanded in re around -inf 23.4%
neg-mul-123.4%
Simplified23.4%
Taylor expanded in re around 0 23.4%
mul-1-neg23.4%
rem-square-sqrt0.0%
distribute-rgt-neg-out0.0%
neg-mul-10.0%
associate-*r*0.0%
*-commutative0.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.8%
pow-sqr2.8%
metadata-eval2.8%
unpow1/22.8%
neg-mul-12.8%
fabs-neg2.8%
unpow1/22.8%
metadata-eval2.8%
pow-sqr2.8%
fabs-sqr2.8%
Simplified2.8%
herbie shell --seed 2024135
(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)))))