
(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 (/ 1.0 re)))) (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 = im * (0.5 * sqrt((1.0 / re)));
} 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 = im * (0.5 * Math.sqrt((1.0 / re)));
} 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 = im * (0.5 * math.sqrt((1.0 / re))) 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(im * Float64(0.5 * sqrt(Float64(1.0 / re)))); 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 = im * (0.5 * sqrt((1.0 / re))); 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[(im * N[(0.5 * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $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:\\
\;\;\;\;im \cdot \left(0.5 \cdot \sqrt{\frac{1}{re}}\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 7.4%
pow17.4%
Applied egg-rr15.6%
unpow115.6%
*-commutative15.6%
associate-*r*15.6%
metadata-eval15.6%
Simplified15.6%
Taylor expanded in re around inf 92.1%
associate-*l*92.0%
unpow292.0%
rem-square-sqrt93.5%
Simplified93.5%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 50.3%
pow150.3%
Applied egg-rr92.0%
unpow192.0%
*-commutative92.0%
associate-*r*92.0%
metadata-eval92.0%
Simplified92.0%
(FPCore (re im)
:precision binary64
(if (<= re -1e-52)
(sqrt (- re))
(if (<= re 1620000000.0)
(* 0.5 (sqrt (+ (* im 2.0) (* re (- (/ re im) 2.0)))))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -1e-52) {
tmp = sqrt(-re);
} else if (re <= 1620000000.0) {
tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.0))));
} else {
tmp = 0.5 * (im * 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 <= (-1d-52)) then
tmp = sqrt(-re)
else if (re <= 1620000000.0d0) then
tmp = 0.5d0 * sqrt(((im * 2.0d0) + (re * ((re / im) - 2.0d0))))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1e-52) {
tmp = Math.sqrt(-re);
} else if (re <= 1620000000.0) {
tmp = 0.5 * Math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0))));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1e-52: tmp = math.sqrt(-re) elif re <= 1620000000.0: tmp = 0.5 * math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1e-52) tmp = sqrt(Float64(-re)); elseif (re <= 1620000000.0) tmp = Float64(0.5 * sqrt(Float64(Float64(im * 2.0) + Float64(re * Float64(Float64(re / im) - 2.0))))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1e-52) tmp = sqrt(-re); elseif (re <= 1620000000.0) tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1e-52], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1620000000.0], 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[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1 \cdot 10^{-52}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1620000000:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2 + re \cdot \left(\frac{re}{im} - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -1e-52Initial program 47.3%
pow147.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 72.2%
neg-mul-172.2%
Simplified72.2%
if -1e-52 < re < 1.62e9Initial program 53.8%
Taylor expanded in re around 0 79.2%
if 1.62e9 < re Initial program 19.6%
Taylor expanded in re around inf 70.0%
associate-*l*70.1%
*-commutative70.1%
Simplified70.1%
sqrt-unprod70.9%
metadata-eval70.9%
sqrt-prod70.9%
*-un-lft-identity70.9%
inv-pow70.9%
sqrt-pow170.9%
metadata-eval70.9%
Applied egg-rr70.9%
Final simplification75.2%
(FPCore (re im)
:precision binary64
(if (<= re -2.6e-52)
(sqrt (- re))
(if (<= re 32500000.0)
(sqrt (* 0.5 (- im re)))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -2.6e-52) {
tmp = sqrt(-re);
} else if (re <= 32500000.0) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = 0.5 * (im * 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 <= (-2.6d-52)) then
tmp = sqrt(-re)
else if (re <= 32500000.0d0) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.6e-52) {
tmp = Math.sqrt(-re);
} else if (re <= 32500000.0) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.6e-52: tmp = math.sqrt(-re) elif re <= 32500000.0: tmp = math.sqrt((0.5 * (im - re))) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.6e-52) tmp = sqrt(Float64(-re)); elseif (re <= 32500000.0) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.6e-52) tmp = sqrt(-re); elseif (re <= 32500000.0) tmp = sqrt((0.5 * (im - re))); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.6e-52], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 32500000.0], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.6 \cdot 10^{-52}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 32500000:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -2.5999999999999999e-52Initial program 47.3%
pow147.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 72.2%
neg-mul-172.2%
Simplified72.2%
if -2.5999999999999999e-52 < re < 3.25e7Initial program 53.8%
pow153.8%
Applied egg-rr85.5%
unpow185.5%
*-commutative85.5%
associate-*r*85.5%
metadata-eval85.5%
Simplified85.5%
Taylor expanded in re around 0 78.3%
neg-mul-178.3%
Simplified78.3%
Taylor expanded in im around 0 78.3%
+-commutative78.3%
metadata-eval78.3%
cancel-sign-sub-inv78.3%
distribute-lft-out--78.3%
Simplified78.3%
if 3.25e7 < re Initial program 19.6%
Taylor expanded in re around inf 70.0%
associate-*l*70.1%
*-commutative70.1%
Simplified70.1%
sqrt-unprod70.9%
metadata-eval70.9%
sqrt-prod70.9%
*-un-lft-identity70.9%
inv-pow70.9%
sqrt-pow170.9%
metadata-eval70.9%
Applied egg-rr70.9%
(FPCore (re im) :precision binary64 (if (<= re -2.6e-52) (sqrt (- re)) (if (<= re 200000000.0) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -2.6e-52) {
tmp = sqrt(-re);
} else if (re <= 200000000.0) {
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-52)) then
tmp = sqrt(-re)
else if (re <= 200000000.0d0) 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-52) {
tmp = Math.sqrt(-re);
} else if (re <= 200000000.0) {
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-52: tmp = math.sqrt(-re) elif re <= 200000000.0: 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-52) tmp = sqrt(Float64(-re)); elseif (re <= 200000000.0) 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 <= -2.6e-52) tmp = sqrt(-re); elseif (re <= 200000000.0) 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-52], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 200000000.0], 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 -2.6 \cdot 10^{-52}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 200000000:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.5999999999999999e-52Initial program 47.3%
pow147.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 72.2%
neg-mul-172.2%
Simplified72.2%
if -2.5999999999999999e-52 < re < 2e8Initial program 53.8%
pow153.8%
Applied egg-rr85.5%
unpow185.5%
*-commutative85.5%
associate-*r*85.5%
metadata-eval85.5%
Simplified85.5%
Taylor expanded in re around 0 78.3%
neg-mul-178.3%
Simplified78.3%
Taylor expanded in im around 0 78.3%
+-commutative78.3%
metadata-eval78.3%
cancel-sign-sub-inv78.3%
distribute-lft-out--78.3%
Simplified78.3%
if 2e8 < re Initial program 19.6%
pow119.6%
Applied egg-rr45.2%
unpow145.2%
*-commutative45.2%
associate-*r*45.2%
metadata-eval45.2%
Simplified45.2%
add-sqr-sqrt45.0%
pow245.0%
pow1/245.0%
sqrt-pow145.0%
metadata-eval45.0%
Applied egg-rr45.0%
Taylor expanded in re around inf 70.9%
associate-*r*70.9%
unpow1/270.9%
exp-to-pow67.1%
log-rec67.1%
distribute-lft-neg-out67.1%
rec-exp67.1%
exp-to-pow70.7%
unpow1/270.7%
associate-/l*70.7%
*-rgt-identity70.7%
*-commutative70.7%
Simplified70.7%
(FPCore (re im) :precision binary64 (if (<= re -2.6e-52) (sqrt (- re)) (if (<= re 7000000.0) (sqrt (* 0.5 (- im re))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -2.6e-52) {
tmp = sqrt(-re);
} else if (re <= 7000000.0) {
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-52)) then
tmp = sqrt(-re)
else if (re <= 7000000.0d0) 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-52) {
tmp = Math.sqrt(-re);
} else if (re <= 7000000.0) {
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-52: tmp = math.sqrt(-re) elif re <= 7000000.0: 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-52) tmp = sqrt(Float64(-re)); elseif (re <= 7000000.0) 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-52) tmp = sqrt(-re); elseif (re <= 7000000.0) 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-52], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 7000000.0], 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^{-52}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 7000000:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.5999999999999999e-52Initial program 47.3%
pow147.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 72.2%
neg-mul-172.2%
Simplified72.2%
if -2.5999999999999999e-52 < re < 7e6Initial program 53.8%
pow153.8%
Applied egg-rr85.5%
unpow185.5%
*-commutative85.5%
associate-*r*85.5%
metadata-eval85.5%
Simplified85.5%
Taylor expanded in re around 0 78.3%
neg-mul-178.3%
Simplified78.3%
Taylor expanded in im around 0 78.3%
+-commutative78.3%
metadata-eval78.3%
cancel-sign-sub-inv78.3%
distribute-lft-out--78.3%
Simplified78.3%
if 7e6 < re Initial program 19.6%
Taylor expanded in re around inf 70.0%
associate-*l*70.1%
*-commutative70.1%
Simplified70.1%
sqrt-unprod70.9%
metadata-eval70.9%
sqrt-prod70.9%
*-un-lft-identity70.9%
inv-pow70.9%
sqrt-pow170.9%
metadata-eval70.9%
Applied egg-rr70.9%
*-commutative70.9%
metadata-eval70.9%
pow-flip70.7%
pow1/270.7%
associate-/r/67.0%
un-div-inv67.0%
Applied egg-rr67.0%
associate-/r/70.7%
Simplified70.7%
Final simplification74.7%
(FPCore (re im) :precision binary64 (if (<= re -2.2e-52) (sqrt (- re)) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -2.2e-52) {
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 <= (-2.2d-52)) 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 <= -2.2e-52) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.2e-52: tmp = math.sqrt(-re) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.2e-52) 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 <= -2.2e-52) tmp = sqrt(-re); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.2e-52], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.2 \cdot 10^{-52}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -2.20000000000000009e-52Initial program 47.3%
pow147.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 72.2%
neg-mul-172.2%
Simplified72.2%
if -2.20000000000000009e-52 < re Initial program 42.9%
pow142.9%
Applied egg-rr72.7%
unpow172.7%
*-commutative72.7%
associate-*r*72.7%
metadata-eval72.7%
Simplified72.7%
Taylor expanded in re around 0 63.5%
*-commutative63.5%
Simplified63.5%
(FPCore (re im) :precision binary64 (if (<= re -1e-310) (sqrt (- re)) (sqrt re)))
double code(double re, double im) {
double tmp;
if (re <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1e-310: tmp = math.sqrt(-re) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1e-310) tmp = sqrt(Float64(-re)); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1e-310) tmp = sqrt(-re); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1e-310], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -9.999999999999969e-311Initial program 56.7%
pow156.7%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 51.1%
neg-mul-151.1%
Simplified51.1%
if -9.999999999999969e-311 < re Initial program 31.1%
pow131.1%
Applied egg-rr61.2%
unpow161.2%
*-commutative61.2%
associate-*r*61.2%
metadata-eval61.2%
Simplified61.2%
Taylor expanded in re around -inf 0.0%
neg-mul-10.0%
Simplified0.0%
*-un-lft-identity0.0%
*-commutative0.0%
add-sqr-sqrt0.0%
sqrt-unprod5.0%
sqr-neg5.0%
sqrt-unprod6.1%
add-sqr-sqrt6.1%
Applied egg-rr6.1%
*-rgt-identity6.1%
Simplified6.1%
(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.3%
pow144.3%
Applied egg-rr81.2%
unpow181.2%
*-commutative81.2%
associate-*r*81.2%
metadata-eval81.2%
Simplified81.2%
Taylor expanded in re around -inf 26.3%
neg-mul-126.3%
Simplified26.3%
*-un-lft-identity26.3%
*-commutative26.3%
add-sqr-sqrt26.3%
sqrt-unprod18.4%
sqr-neg18.4%
sqrt-unprod3.0%
add-sqr-sqrt3.0%
Applied egg-rr3.0%
*-rgt-identity3.0%
Simplified3.0%
herbie shell --seed 2024157
(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)))))