
(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) (* (pow re -0.5) (* im 0.5)) (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 = pow(re, -0.5) * (im * 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(((re * re) + (im * im))) - re) <= 0.0) {
tmp = Math.pow(re, -0.5) * (im * 0.5);
} 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 = math.pow(re, -0.5) * (im * 0.5) 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((re ^ -0.5) * Float64(im * 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(((re * re) + (im * im))) - re) <= 0.0) tmp = (re ^ -0.5) * (im * 0.5); 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[Power[re, -0.5], $MachinePrecision] * N[(im * 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{re \cdot re + im \cdot im} - re \leq 0:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\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 6.1%
pow16.1%
Applied egg-rr16.9%
unpow116.9%
*-commutative16.9%
associate-*r*16.9%
metadata-eval16.9%
Simplified16.9%
Taylor expanded in re around inf 89.4%
*-commutative89.4%
unpow289.4%
rem-square-sqrt90.8%
Simplified90.8%
*-un-lft-identity90.8%
inv-pow90.8%
sqrt-pow191.0%
metadata-eval91.0%
Applied egg-rr91.0%
*-lft-identity91.0%
Simplified91.0%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 50.8%
pow150.8%
Applied egg-rr92.4%
unpow192.4%
*-commutative92.4%
associate-*r*92.4%
metadata-eval92.4%
Simplified92.4%
(FPCore (re im)
:precision binary64
(if (<= re -2.75e-58)
(sqrt (- re))
(if (<= re 3.25)
(* 0.5 (sqrt (+ (* im 2.0) (* re (- (/ re im) 2.0)))))
(* (pow re -0.5) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -2.75e-58) {
tmp = sqrt(-re);
} else if (re <= 3.25) {
tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.0))));
} else {
tmp = pow(re, -0.5) * (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 <= (-2.75d-58)) then
tmp = sqrt(-re)
else if (re <= 3.25d0) then
tmp = 0.5d0 * sqrt(((im * 2.0d0) + (re * ((re / im) - 2.0d0))))
else
tmp = (re ** (-0.5d0)) * (im * 0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.75e-58) {
tmp = Math.sqrt(-re);
} else if (re <= 3.25) {
tmp = 0.5 * Math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0))));
} else {
tmp = Math.pow(re, -0.5) * (im * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.75e-58: tmp = math.sqrt(-re) elif re <= 3.25: tmp = 0.5 * math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))) else: tmp = math.pow(re, -0.5) * (im * 0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.75e-58) tmp = sqrt(Float64(-re)); elseif (re <= 3.25) tmp = Float64(0.5 * sqrt(Float64(Float64(im * 2.0) + Float64(re * Float64(Float64(re / im) - 2.0))))); else tmp = Float64((re ^ -0.5) * Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.75e-58) tmp = sqrt(-re); elseif (re <= 3.25) tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))); else tmp = (re ^ -0.5) * (im * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.75e-58], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 3.25], 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[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.75 \cdot 10^{-58}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 3.25:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2 + re \cdot \left(\frac{re}{im} - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -2.74999999999999998e-58Initial program 53.8%
pow153.8%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 78.7%
neg-mul-178.7%
Simplified78.7%
if -2.74999999999999998e-58 < re < 3.25Initial program 51.8%
Taylor expanded in re around 0 76.0%
if 3.25 < re Initial program 5.6%
pow15.6%
Applied egg-rr34.0%
unpow134.0%
*-commutative34.0%
associate-*r*34.0%
metadata-eval34.0%
Simplified34.0%
Taylor expanded in re around inf 78.7%
*-commutative78.7%
unpow278.7%
rem-square-sqrt79.8%
Simplified79.8%
*-un-lft-identity79.8%
inv-pow79.8%
sqrt-pow179.8%
metadata-eval79.8%
Applied egg-rr79.8%
*-lft-identity79.8%
Simplified79.8%
Final simplification77.7%
(FPCore (re im) :precision binary64 (if (<= re -1.2e-56) (sqrt (- re)) (if (<= re 0.055) (sqrt (* im 0.5)) (* (pow re -0.5) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.2e-56) {
tmp = sqrt(-re);
} else if (re <= 0.055) {
tmp = sqrt((im * 0.5));
} else {
tmp = pow(re, -0.5) * (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 <= (-1.2d-56)) then
tmp = sqrt(-re)
else if (re <= 0.055d0) then
tmp = sqrt((im * 0.5d0))
else
tmp = (re ** (-0.5d0)) * (im * 0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.2e-56) {
tmp = Math.sqrt(-re);
} else if (re <= 0.055) {
tmp = Math.sqrt((im * 0.5));
} else {
tmp = Math.pow(re, -0.5) * (im * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.2e-56: tmp = math.sqrt(-re) elif re <= 0.055: tmp = math.sqrt((im * 0.5)) else: tmp = math.pow(re, -0.5) * (im * 0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.2e-56) tmp = sqrt(Float64(-re)); elseif (re <= 0.055) tmp = sqrt(Float64(im * 0.5)); else tmp = Float64((re ^ -0.5) * Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.2e-56) tmp = sqrt(-re); elseif (re <= 0.055) tmp = sqrt((im * 0.5)); else tmp = (re ^ -0.5) * (im * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.2e-56], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 0.055], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], N[(N[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.2 \cdot 10^{-56}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 0.055:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -1.2e-56Initial program 53.8%
pow153.8%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 78.7%
neg-mul-178.7%
Simplified78.7%
if -1.2e-56 < re < 0.0550000000000000003Initial program 51.8%
pow151.8%
Applied egg-rr84.4%
unpow184.4%
*-commutative84.4%
associate-*r*84.4%
metadata-eval84.4%
Simplified84.4%
Taylor expanded in re around 0 75.7%
*-commutative75.7%
Simplified75.7%
if 0.0550000000000000003 < re Initial program 5.6%
pow15.6%
Applied egg-rr34.0%
unpow134.0%
*-commutative34.0%
associate-*r*34.0%
metadata-eval34.0%
Simplified34.0%
Taylor expanded in re around inf 78.7%
*-commutative78.7%
unpow278.7%
rem-square-sqrt79.8%
Simplified79.8%
*-un-lft-identity79.8%
inv-pow79.8%
sqrt-pow179.8%
metadata-eval79.8%
Applied egg-rr79.8%
*-lft-identity79.8%
Simplified79.8%
(FPCore (re im) :precision binary64 (if (<= re -6e-58) (sqrt (- re)) (if (<= re 0.04) (sqrt (* im 0.5)) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -6e-58) {
tmp = sqrt(-re);
} else if (re <= 0.04) {
tmp = sqrt((im * 0.5));
} 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-58)) then
tmp = sqrt(-re)
else if (re <= 0.04d0) then
tmp = sqrt((im * 0.5d0))
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-58) {
tmp = Math.sqrt(-re);
} else if (re <= 0.04) {
tmp = Math.sqrt((im * 0.5));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -6e-58: tmp = math.sqrt(-re) elif re <= 0.04: tmp = math.sqrt((im * 0.5)) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -6e-58) tmp = sqrt(Float64(-re)); elseif (re <= 0.04) tmp = sqrt(Float64(im * 0.5)); 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-58) tmp = sqrt(-re); elseif (re <= 0.04) tmp = sqrt((im * 0.5)); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6e-58], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 0.04], N[Sqrt[N[(im * 0.5), $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^{-58}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 0.04:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -6.00000000000000015e-58Initial program 53.8%
pow153.8%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 78.7%
neg-mul-178.7%
Simplified78.7%
if -6.00000000000000015e-58 < re < 0.0400000000000000008Initial program 51.8%
pow151.8%
Applied egg-rr84.4%
unpow184.4%
*-commutative84.4%
associate-*r*84.4%
metadata-eval84.4%
Simplified84.4%
Taylor expanded in re around 0 75.7%
*-commutative75.7%
Simplified75.7%
if 0.0400000000000000008 < re Initial program 5.6%
pow15.6%
Applied egg-rr34.0%
unpow134.0%
*-commutative34.0%
associate-*r*34.0%
metadata-eval34.0%
Simplified34.0%
Taylor expanded in re around inf 78.7%
*-commutative78.7%
unpow278.7%
rem-square-sqrt79.8%
Simplified79.8%
*-commutative79.8%
sqrt-div79.6%
metadata-eval79.6%
un-div-inv79.7%
Applied egg-rr79.7%
(FPCore (re im) :precision binary64 (if (<= re -9e-57) (sqrt (- re)) (if (<= re 0.038) (sqrt (* im 0.5)) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -9e-57) {
tmp = sqrt(-re);
} else if (re <= 0.038) {
tmp = sqrt((im * 0.5));
} 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 <= (-9d-57)) then
tmp = sqrt(-re)
else if (re <= 0.038d0) then
tmp = sqrt((im * 0.5d0))
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 <= -9e-57) {
tmp = Math.sqrt(-re);
} else if (re <= 0.038) {
tmp = Math.sqrt((im * 0.5));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -9e-57: tmp = math.sqrt(-re) elif re <= 0.038: tmp = math.sqrt((im * 0.5)) else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -9e-57) tmp = sqrt(Float64(-re)); elseif (re <= 0.038) tmp = sqrt(Float64(im * 0.5)); else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -9e-57) tmp = sqrt(-re); elseif (re <= 0.038) tmp = sqrt((im * 0.5)); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -9e-57], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 0.038], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -9 \cdot 10^{-57}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 0.038:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -8.99999999999999945e-57Initial program 53.8%
pow153.8%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 78.7%
neg-mul-178.7%
Simplified78.7%
if -8.99999999999999945e-57 < re < 0.0379999999999999991Initial program 51.8%
pow151.8%
Applied egg-rr84.4%
unpow184.4%
*-commutative84.4%
associate-*r*84.4%
metadata-eval84.4%
Simplified84.4%
Taylor expanded in re around 0 75.7%
*-commutative75.7%
Simplified75.7%
if 0.0379999999999999991 < re Initial program 5.6%
pow15.6%
Applied egg-rr34.0%
unpow134.0%
*-commutative34.0%
associate-*r*34.0%
metadata-eval34.0%
Simplified34.0%
Taylor expanded in re around inf 78.7%
*-commutative78.7%
unpow278.7%
rem-square-sqrt79.8%
Simplified79.8%
*-commutative79.8%
sqrt-div79.6%
metadata-eval79.6%
un-div-inv79.7%
Applied egg-rr79.7%
associate-/l*79.6%
Simplified79.6%
(FPCore (re im) :precision binary64 (if (<= re -3.55e-56) (sqrt (- re)) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -3.55e-56) {
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 <= (-3.55d-56)) 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 <= -3.55e-56) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.55e-56: tmp = math.sqrt(-re) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.55e-56) 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 <= -3.55e-56) tmp = sqrt(-re); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.55e-56], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.55 \cdot 10^{-56}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -3.55e-56Initial program 53.8%
pow153.8%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 78.7%
neg-mul-178.7%
Simplified78.7%
if -3.55e-56 < re Initial program 37.4%
pow137.4%
Applied egg-rr68.7%
unpow168.7%
*-commutative68.7%
associate-*r*68.7%
metadata-eval68.7%
Simplified68.7%
Taylor expanded in re around 0 59.7%
*-commutative59.7%
Simplified59.7%
(FPCore (re im) :precision binary64 (if (<= re -5e-310) (sqrt (- re)) (sqrt 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -5e-310) {
tmp = sqrt(-re);
} else {
tmp = sqrt(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 <= (-5d-310)) then
tmp = sqrt(-re)
else
tmp = sqrt(0.0d0)
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(0.0);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5e-310: tmp = math.sqrt(-re) else: tmp = math.sqrt(0.0) return tmp
function code(re, im) tmp = 0.0 if (re <= -5e-310) tmp = sqrt(Float64(-re)); else tmp = sqrt(0.0); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5e-310) tmp = sqrt(-re); else tmp = sqrt(0.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5e-310], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[0.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0}\\
\end{array}
\end{array}
if re < -4.999999999999985e-310Initial program 58.6%
pow158.6%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 56.3%
neg-mul-156.3%
Simplified56.3%
if -4.999999999999985e-310 < re Initial program 24.7%
pow124.7%
Applied egg-rr54.8%
unpow154.8%
*-commutative54.8%
associate-*r*54.8%
metadata-eval54.8%
Simplified54.8%
add-sqr-sqrt52.9%
add-sqr-sqrt54.7%
difference-of-squares54.7%
Applied egg-rr54.7%
Taylor expanded in re around inf 7.4%
(FPCore (re im) :precision binary64 (sqrt 0.0))
double code(double re, double im) {
return sqrt(0.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt(0.0d0)
end function
public static double code(double re, double im) {
return Math.sqrt(0.0);
}
def code(re, im): return math.sqrt(0.0)
function code(re, im) return sqrt(0.0) end
function tmp = code(re, im) tmp = sqrt(0.0); end
code[re_, im_] := N[Sqrt[0.0], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0}
\end{array}
Initial program 42.7%
pow142.7%
Applied egg-rr78.8%
unpow178.8%
*-commutative78.8%
associate-*r*78.8%
metadata-eval78.8%
Simplified78.8%
add-sqr-sqrt77.8%
add-sqr-sqrt25.6%
difference-of-squares25.7%
Applied egg-rr25.7%
Taylor expanded in re around inf 5.0%
herbie shell --seed 2024181
(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)))))