
(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 (* 2.0 (- (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((2.0 * (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((2.0 * (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((2.0 * (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 (sqrt(Float64(2.0 * 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((2.0 * (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[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[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{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \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 (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 12.6%
Taylor expanded in re around inf 98.2%
*-commutative98.2%
*-commutative98.2%
associate-*r*98.3%
associate-*l*98.4%
*-commutative98.4%
associate-*l*98.4%
*-commutative98.4%
*-commutative98.4%
Simplified98.4%
sqrt-unprod99.7%
metadata-eval99.7%
sqrt-prod99.7%
*-un-lft-identity99.7%
inv-pow99.7%
sqrt-pow199.7%
metadata-eval99.7%
Applied egg-rr99.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 46.8%
pow146.8%
Applied egg-rr88.3%
unpow188.3%
*-commutative88.3%
associate-*r*88.3%
metadata-eval88.3%
Simplified88.3%
Final simplification90.0%
(FPCore (re im)
:precision binary64
(if (<= re -2.1e-23)
(sqrt (- re))
(if (<= re 1.15e+49)
(* 0.5 (sqrt (+ (* 2.0 im) (* re (- (/ re im) 2.0)))))
(* (pow re -0.5) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -2.1e-23) {
tmp = sqrt(-re);
} else if (re <= 1.15e+49) {
tmp = 0.5 * sqrt(((2.0 * im) + (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.1d-23)) then
tmp = sqrt(-re)
else if (re <= 1.15d+49) then
tmp = 0.5d0 * sqrt(((2.0d0 * im) + (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.1e-23) {
tmp = Math.sqrt(-re);
} else if (re <= 1.15e+49) {
tmp = 0.5 * Math.sqrt(((2.0 * im) + (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.1e-23: tmp = math.sqrt(-re) elif re <= 1.15e+49: tmp = 0.5 * math.sqrt(((2.0 * im) + (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.1e-23) tmp = sqrt(Float64(-re)); elseif (re <= 1.15e+49) tmp = Float64(0.5 * sqrt(Float64(Float64(2.0 * im) + 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.1e-23) tmp = sqrt(-re); elseif (re <= 1.15e+49) tmp = 0.5 * sqrt(((2.0 * im) + (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.1e-23], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.15e+49], N[(0.5 * N[Sqrt[N[(N[(2.0 * im), $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.1 \cdot 10^{-23}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.15 \cdot 10^{+49}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im + 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.1000000000000001e-23Initial program 53.6%
pow153.6%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.5%
neg-mul-175.5%
Simplified75.5%
if -2.1000000000000001e-23 < re < 1.15000000000000001e49Initial program 49.3%
Taylor expanded in re around 0 79.8%
if 1.15000000000000001e49 < re Initial program 9.4%
Taylor expanded in re around inf 81.9%
*-commutative81.9%
*-commutative81.9%
associate-*r*81.9%
associate-*l*82.0%
*-commutative82.0%
associate-*l*82.0%
*-commutative82.0%
*-commutative82.0%
Simplified82.0%
sqrt-unprod83.1%
metadata-eval83.1%
sqrt-prod83.1%
*-un-lft-identity83.1%
inv-pow83.1%
sqrt-pow183.1%
metadata-eval83.1%
Applied egg-rr83.1%
Final simplification79.4%
(FPCore (re im) :precision binary64 (if (<= re -4.9e-23) (sqrt (- re)) (if (<= re 3.9e+49) (sqrt (* im 0.5)) (* (pow re -0.5) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -4.9e-23) {
tmp = sqrt(-re);
} else if (re <= 3.9e+49) {
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 <= (-4.9d-23)) then
tmp = sqrt(-re)
else if (re <= 3.9d+49) 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 <= -4.9e-23) {
tmp = Math.sqrt(-re);
} else if (re <= 3.9e+49) {
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 <= -4.9e-23: tmp = math.sqrt(-re) elif re <= 3.9e+49: 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 <= -4.9e-23) tmp = sqrt(Float64(-re)); elseif (re <= 3.9e+49) 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 <= -4.9e-23) tmp = sqrt(-re); elseif (re <= 3.9e+49) tmp = sqrt((im * 0.5)); else tmp = (re ^ -0.5) * (im * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.9e-23], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 3.9e+49], 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 -4.9 \cdot 10^{-23}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 3.9 \cdot 10^{+49}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -4.8999999999999998e-23Initial program 53.6%
pow153.6%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.5%
neg-mul-175.5%
Simplified75.5%
if -4.8999999999999998e-23 < re < 3.9000000000000001e49Initial program 49.3%
pow149.3%
Applied egg-rr84.5%
unpow184.5%
*-commutative84.5%
associate-*r*84.5%
metadata-eval84.5%
Simplified84.5%
Taylor expanded in re around 0 79.2%
*-commutative79.2%
Simplified79.2%
if 3.9000000000000001e49 < re Initial program 9.4%
Taylor expanded in re around inf 81.9%
*-commutative81.9%
*-commutative81.9%
associate-*r*81.9%
associate-*l*82.0%
*-commutative82.0%
associate-*l*82.0%
*-commutative82.0%
*-commutative82.0%
Simplified82.0%
sqrt-unprod83.1%
metadata-eval83.1%
sqrt-prod83.1%
*-un-lft-identity83.1%
inv-pow83.1%
sqrt-pow183.1%
metadata-eval83.1%
Applied egg-rr83.1%
Final simplification79.1%
(FPCore (re im) :precision binary64 (if (<= re -4.8e-23) (sqrt (- re)) (if (<= re 1.5e+49) (sqrt (* im 0.5)) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -4.8e-23) {
tmp = sqrt(-re);
} else if (re <= 1.5e+49) {
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 <= (-4.8d-23)) then
tmp = sqrt(-re)
else if (re <= 1.5d+49) 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 <= -4.8e-23) {
tmp = Math.sqrt(-re);
} else if (re <= 1.5e+49) {
tmp = Math.sqrt((im * 0.5));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.8e-23: tmp = math.sqrt(-re) elif re <= 1.5e+49: 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 <= -4.8e-23) tmp = sqrt(Float64(-re)); elseif (re <= 1.5e+49) 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 <= -4.8e-23) tmp = sqrt(-re); elseif (re <= 1.5e+49) tmp = sqrt((im * 0.5)); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.8e-23], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.5e+49], 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 -4.8 \cdot 10^{-23}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.5 \cdot 10^{+49}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -4.79999999999999993e-23Initial program 53.6%
pow153.6%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.5%
neg-mul-175.5%
Simplified75.5%
if -4.79999999999999993e-23 < re < 1.5000000000000001e49Initial program 49.3%
pow149.3%
Applied egg-rr84.5%
unpow184.5%
*-commutative84.5%
associate-*r*84.5%
metadata-eval84.5%
Simplified84.5%
Taylor expanded in re around 0 79.2%
*-commutative79.2%
Simplified79.2%
if 1.5000000000000001e49 < re Initial program 9.4%
Taylor expanded in re around inf 81.9%
*-commutative81.9%
*-commutative81.9%
associate-*r*81.9%
associate-*l*82.0%
*-commutative82.0%
associate-*l*82.0%
*-commutative82.0%
*-commutative82.0%
Simplified82.0%
*-commutative82.0%
sqrt-unprod83.1%
metadata-eval83.1%
metadata-eval83.1%
*-un-lft-identity83.1%
sqrt-div82.8%
metadata-eval82.8%
un-div-inv82.9%
Applied egg-rr82.9%
*-commutative82.9%
Simplified82.9%
(FPCore (re im) :precision binary64 (if (<= re -1.8e-26) (sqrt (- re)) (if (<= re 1.75e+49) (sqrt (* im 0.5)) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e-26) {
tmp = sqrt(-re);
} else if (re <= 1.75e+49) {
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 <= (-1.8d-26)) then
tmp = sqrt(-re)
else if (re <= 1.75d+49) 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 <= -1.8e-26) {
tmp = Math.sqrt(-re);
} else if (re <= 1.75e+49) {
tmp = Math.sqrt((im * 0.5));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e-26: tmp = math.sqrt(-re) elif re <= 1.75e+49: 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 <= -1.8e-26) tmp = sqrt(Float64(-re)); elseif (re <= 1.75e+49) 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 <= -1.8e-26) tmp = sqrt(-re); elseif (re <= 1.75e+49) tmp = sqrt((im * 0.5)); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e-26], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.75e+49], 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 -1.8 \cdot 10^{-26}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.75 \cdot 10^{+49}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.8000000000000001e-26Initial program 53.6%
pow153.6%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.5%
neg-mul-175.5%
Simplified75.5%
if -1.8000000000000001e-26 < re < 1.74999999999999987e49Initial program 49.3%
pow149.3%
Applied egg-rr84.5%
unpow184.5%
*-commutative84.5%
associate-*r*84.5%
metadata-eval84.5%
Simplified84.5%
Taylor expanded in re around 0 79.2%
*-commutative79.2%
Simplified79.2%
if 1.74999999999999987e49 < re Initial program 9.4%
Taylor expanded in re around inf 81.9%
*-commutative81.9%
*-commutative81.9%
associate-*r*81.9%
associate-*l*82.0%
*-commutative82.0%
associate-*l*82.0%
*-commutative82.0%
*-commutative82.0%
Simplified82.0%
expm1-log1p-u81.4%
expm1-undefine24.5%
associate-*r*24.5%
*-commutative24.5%
sqrt-unprod24.5%
metadata-eval24.5%
metadata-eval24.5%
*-un-lft-identity24.5%
sqrt-div24.5%
metadata-eval24.5%
associate-*l/24.5%
metadata-eval24.5%
Applied egg-rr24.5%
expm1-define82.1%
associate-*r/82.2%
Simplified82.2%
expm1-log1p-u82.9%
associate-/l*82.8%
*-commutative82.8%
Applied egg-rr82.8%
Final simplification79.0%
(FPCore (re im) :precision binary64 (if (<= re -8.5e-27) (sqrt (- re)) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -8.5e-27) {
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 <= (-8.5d-27)) 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 <= -8.5e-27) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -8.5e-27: tmp = math.sqrt(-re) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -8.5e-27) 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 <= -8.5e-27) tmp = sqrt(-re); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -8.5e-27], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -8.5 \cdot 10^{-27}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -8.50000000000000033e-27Initial program 53.6%
pow153.6%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.5%
neg-mul-175.5%
Simplified75.5%
if -8.50000000000000033e-27 < re Initial program 37.8%
pow137.8%
Applied egg-rr69.5%
unpow169.5%
*-commutative69.5%
associate-*r*69.5%
metadata-eval69.5%
Simplified69.5%
Taylor expanded in re around 0 62.9%
*-commutative62.9%
Simplified62.9%
(FPCore (re im) :precision binary64 (if (<= re -2e-310) (sqrt (- re)) 0.0))
double code(double re, double im) {
double tmp;
if (re <= -2e-310) {
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 <= (-2d-310)) 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 <= -2e-310) {
tmp = Math.sqrt(-re);
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2e-310: tmp = math.sqrt(-re) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -2e-310) tmp = sqrt(Float64(-re)); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2e-310) tmp = sqrt(-re); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2e-310], N[Sqrt[(-re)], $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -1.999999999999994e-310Initial program 52.7%
pow152.7%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 50.9%
neg-mul-150.9%
Simplified50.9%
if -1.999999999999994e-310 < re Initial program 33.4%
Taylor expanded in re around inf 8.3%
Taylor expanded in re around 0 8.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 41.8%
Taylor expanded in re around inf 5.9%
Taylor expanded in re around 0 5.9%
herbie shell --seed 2024144
(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)))))