
(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 11.4%
pow111.4%
Applied egg-rr19.6%
unpow119.6%
*-commutative19.6%
associate-*r*19.6%
metadata-eval19.6%
Simplified19.6%
Taylor expanded in re around inf 91.9%
*-commutative91.9%
rem-exp-log88.1%
exp-neg88.1%
unpow1/288.1%
exp-prod88.1%
distribute-lft-neg-out88.1%
distribute-rgt-neg-in88.1%
metadata-eval88.1%
exp-to-pow92.0%
unpow292.0%
rem-square-sqrt93.4%
Simplified93.4%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 42.6%
pow142.6%
Applied egg-rr91.0%
unpow191.0%
*-commutative91.0%
associate-*r*91.0%
metadata-eval91.0%
Simplified91.0%
(FPCore (re im)
:precision binary64
(if (<= re -3.9e-19)
(sqrt (- re))
(if (<= re 1.15e-79)
(sqrt (* 0.5 (- im re)))
(* (pow re -0.5) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -3.9e-19) {
tmp = sqrt(-re);
} else if (re <= 1.15e-79) {
tmp = sqrt((0.5 * (im - re)));
} 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 <= (-3.9d-19)) then
tmp = sqrt(-re)
else if (re <= 1.15d-79) then
tmp = sqrt((0.5d0 * (im - re)))
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 <= -3.9e-19) {
tmp = Math.sqrt(-re);
} else if (re <= 1.15e-79) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = Math.pow(re, -0.5) * (im * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.9e-19: tmp = math.sqrt(-re) elif re <= 1.15e-79: tmp = math.sqrt((0.5 * (im - re))) else: tmp = math.pow(re, -0.5) * (im * 0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.9e-19) tmp = sqrt(Float64(-re)); elseif (re <= 1.15e-79) tmp = sqrt(Float64(0.5 * Float64(im - re))); 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 <= -3.9e-19) tmp = sqrt(-re); elseif (re <= 1.15e-79) tmp = sqrt((0.5 * (im - re))); else tmp = (re ^ -0.5) * (im * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.9e-19], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.15e-79], N[Sqrt[N[(0.5 * N[(im - re), $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 -3.9 \cdot 10^{-19}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.15 \cdot 10^{-79}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -3.89999999999999995e-19Initial program 37.2%
pow137.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 84.7%
neg-mul-184.7%
Simplified84.7%
if -3.89999999999999995e-19 < re < 1.15000000000000006e-79Initial program 50.6%
pow150.6%
Applied egg-rr90.8%
unpow190.8%
*-commutative90.8%
associate-*r*90.8%
metadata-eval90.8%
Simplified90.8%
Taylor expanded in re around 0 78.3%
neg-mul-178.3%
unsub-neg78.3%
Simplified78.3%
if 1.15000000000000006e-79 < re Initial program 18.7%
pow118.7%
Applied egg-rr47.7%
unpow147.7%
*-commutative47.7%
associate-*r*47.7%
metadata-eval47.7%
Simplified47.7%
Taylor expanded in re around inf 68.3%
*-commutative68.3%
rem-exp-log65.4%
exp-neg65.4%
unpow1/265.4%
exp-prod65.4%
distribute-lft-neg-out65.4%
distribute-rgt-neg-in65.4%
metadata-eval65.4%
exp-to-pow68.2%
unpow268.2%
rem-square-sqrt69.0%
Simplified69.0%
(FPCore (re im) :precision binary64 (if (<= re -6e-21) (sqrt (- re)) (if (<= re 1.25e-79) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -6e-21) {
tmp = sqrt(-re);
} else if (re <= 1.25e-79) {
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-21)) then
tmp = sqrt(-re)
else if (re <= 1.25d-79) 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-21) {
tmp = Math.sqrt(-re);
} else if (re <= 1.25e-79) {
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-21: tmp = math.sqrt(-re) elif re <= 1.25e-79: 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-21) tmp = sqrt(Float64(-re)); elseif (re <= 1.25e-79) 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-21) tmp = sqrt(-re); elseif (re <= 1.25e-79) 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-21], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.25e-79], 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^{-21}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.25 \cdot 10^{-79}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -5.99999999999999982e-21Initial program 37.2%
pow137.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 84.7%
neg-mul-184.7%
Simplified84.7%
if -5.99999999999999982e-21 < re < 1.25e-79Initial program 50.6%
pow150.6%
Applied egg-rr90.8%
unpow190.8%
*-commutative90.8%
associate-*r*90.8%
metadata-eval90.8%
Simplified90.8%
Taylor expanded in re around 0 78.3%
neg-mul-178.3%
unsub-neg78.3%
Simplified78.3%
if 1.25e-79 < re Initial program 18.7%
Taylor expanded in re around inf 37.2%
div-inv37.2%
sqrt-prod49.2%
sqrt-pow168.9%
metadata-eval68.9%
pow168.9%
*-un-lft-identity68.9%
metadata-eval68.9%
metadata-eval68.9%
sqrt-unprod68.1%
associate-*r*68.1%
sqrt-unprod68.9%
metadata-eval68.9%
metadata-eval68.9%
*-un-lft-identity68.9%
sqrt-div68.9%
metadata-eval68.9%
un-div-inv68.9%
Applied egg-rr68.9%
Final simplification77.0%
(FPCore (re im) :precision binary64 (if (<= re -5.8e-21) (sqrt (- re)) (if (<= re 1.2e-79) (sqrt (* 0.5 (- im re))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -5.8e-21) {
tmp = sqrt(-re);
} else if (re <= 1.2e-79) {
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 <= (-5.8d-21)) then
tmp = sqrt(-re)
else if (re <= 1.2d-79) 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 <= -5.8e-21) {
tmp = Math.sqrt(-re);
} else if (re <= 1.2e-79) {
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 <= -5.8e-21: tmp = math.sqrt(-re) elif re <= 1.2e-79: 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 <= -5.8e-21) tmp = sqrt(Float64(-re)); elseif (re <= 1.2e-79) 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 <= -5.8e-21) tmp = sqrt(-re); elseif (re <= 1.2e-79) tmp = sqrt((0.5 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5.8e-21], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.2e-79], 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 -5.8 \cdot 10^{-21}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.2 \cdot 10^{-79}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -5.8e-21Initial program 37.2%
pow137.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 84.7%
neg-mul-184.7%
Simplified84.7%
if -5.8e-21 < re < 1.20000000000000003e-79Initial program 50.6%
pow150.6%
Applied egg-rr90.8%
unpow190.8%
*-commutative90.8%
associate-*r*90.8%
metadata-eval90.8%
Simplified90.8%
Taylor expanded in re around 0 78.3%
neg-mul-178.3%
unsub-neg78.3%
Simplified78.3%
if 1.20000000000000003e-79 < re Initial program 18.7%
Taylor expanded in re around inf 37.2%
div-inv37.2%
sqrt-prod49.2%
sqrt-pow168.9%
metadata-eval68.9%
pow168.9%
*-un-lft-identity68.9%
metadata-eval68.9%
metadata-eval68.9%
sqrt-unprod68.1%
associate-*r*68.1%
sqrt-unprod68.9%
metadata-eval68.9%
metadata-eval68.9%
*-un-lft-identity68.9%
sqrt-div68.9%
metadata-eval68.9%
un-div-inv68.9%
Applied egg-rr68.9%
*-commutative68.9%
associate-/l*68.9%
Simplified68.9%
(FPCore (re im) :precision binary64 (if (<= re -3.6e-19) (sqrt (- re)) (if (<= re 1.8e+191) (sqrt (* 0.5 (- im re))) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -3.6e-19) {
tmp = sqrt(-re);
} else if (re <= 1.8e+191) {
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 <= (-3.6d-19)) then
tmp = sqrt(-re)
else if (re <= 1.8d+191) 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 <= -3.6e-19) {
tmp = Math.sqrt(-re);
} else if (re <= 1.8e+191) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.6e-19: tmp = math.sqrt(-re) elif re <= 1.8e+191: tmp = math.sqrt((0.5 * (im - re))) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -3.6e-19) tmp = sqrt(Float64(-re)); elseif (re <= 1.8e+191) 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 <= -3.6e-19) tmp = sqrt(-re); elseif (re <= 1.8e+191) tmp = sqrt((0.5 * (im - re))); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.6e-19], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.8e+191], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.6 \cdot 10^{-19}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.8 \cdot 10^{+191}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -3.6000000000000001e-19Initial program 37.2%
pow137.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 84.7%
neg-mul-184.7%
Simplified84.7%
if -3.6000000000000001e-19 < re < 1.8e191Initial program 42.8%
pow142.8%
Applied egg-rr79.3%
unpow179.3%
*-commutative79.3%
associate-*r*79.3%
metadata-eval79.3%
Simplified79.3%
Taylor expanded in re around 0 68.2%
neg-mul-168.2%
unsub-neg68.2%
Simplified68.2%
if 1.8e191 < re Initial program 2.4%
Taylor expanded in re around inf 28.3%
Taylor expanded in re around 0 28.3%
(FPCore (re im) :precision binary64 (if (<= re -2.05e-19) (sqrt (- re)) (if (<= re 1.8e+195) (sqrt (* im 0.5)) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -2.05e-19) {
tmp = sqrt(-re);
} else if (re <= 1.8e+195) {
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 <= (-2.05d-19)) then
tmp = sqrt(-re)
else if (re <= 1.8d+195) 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 <= -2.05e-19) {
tmp = Math.sqrt(-re);
} else if (re <= 1.8e+195) {
tmp = Math.sqrt((im * 0.5));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.05e-19: tmp = math.sqrt(-re) elif re <= 1.8e+195: tmp = math.sqrt((im * 0.5)) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -2.05e-19) tmp = sqrt(Float64(-re)); elseif (re <= 1.8e+195) 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 <= -2.05e-19) tmp = sqrt(-re); elseif (re <= 1.8e+195) tmp = sqrt((im * 0.5)); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.05e-19], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.8e+195], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.05 \cdot 10^{-19}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.8 \cdot 10^{+195}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -2.04999999999999993e-19Initial program 37.2%
pow137.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 84.7%
neg-mul-184.7%
Simplified84.7%
if -2.04999999999999993e-19 < re < 1.7999999999999999e195Initial program 42.6%
pow142.6%
Applied egg-rr78.9%
unpow178.9%
*-commutative78.9%
associate-*r*78.9%
metadata-eval78.9%
Simplified78.9%
Taylor expanded in re around 0 67.7%
*-commutative67.7%
Simplified67.7%
if 1.7999999999999999e195 < re Initial program 2.4%
Taylor expanded in re around inf 29.4%
Taylor expanded in re around 0 29.4%
(FPCore (re im) :precision binary64 (if (<= re -5e-311) (sqrt (- re)) 0.0))
double code(double re, double im) {
double tmp;
if (re <= -5e-311) {
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 <= (-5d-311)) 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 <= -5e-311) {
tmp = Math.sqrt(-re);
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5e-311: tmp = math.sqrt(-re) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -5e-311) tmp = sqrt(Float64(-re)); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5e-311) tmp = sqrt(-re); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5e-311], N[Sqrt[(-re)], $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -5.00000000000023e-311Initial program 50.3%
pow150.3%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 56.0%
neg-mul-156.0%
Simplified56.0%
if -5.00000000000023e-311 < re Initial program 25.8%
Taylor expanded in re around inf 10.3%
Taylor expanded in re around 0 10.3%
(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 37.7%
Taylor expanded in re around inf 6.7%
Taylor expanded in re around 0 6.7%
herbie shell --seed 2024166
(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)))))