
(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) (* 0.5 (/ im (sqrt 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 = 0.5 * (im / sqrt(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 = 0.5 * (im / Math.sqrt(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 = 0.5 * (im / math.sqrt(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(0.5 * Float64(im / sqrt(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 = 0.5 * (im / sqrt(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[(0.5 * N[(im / N[Sqrt[re], $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:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\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.6%
Taylor expanded in re around inf 39.9%
sqrt-div50.3%
sqrt-pow192.3%
metadata-eval92.3%
pow192.3%
div-inv91.9%
Applied egg-rr91.9%
associate-*r/92.3%
*-rgt-identity92.3%
Simplified92.3%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 45.0%
pow145.0%
Applied egg-rr91.4%
unpow191.4%
*-commutative91.4%
associate-*r*91.4%
metadata-eval91.4%
Simplified91.4%
(FPCore (re im)
:precision binary64
(if (<= re -9e-71)
(sqrt (- re))
(if (<= re 7.5e-180)
(sqrt (* 0.5 (- im re)))
(if (<= re 1.5e-148)
(/ 0.5 (/ (sqrt re) im))
(if (<= re 1.46e-36)
(sqrt (* im 0.5))
(if (<= re 1e+53)
(* 0.5 (/ im (sqrt re)))
(if (<= re 5e+94)
(* 0.5 (sqrt (+ (* im 2.0) (* re (- (/ re im) 2.0)))))
(/ (* im 0.5) (sqrt re)))))))))
double code(double re, double im) {
double tmp;
if (re <= -9e-71) {
tmp = sqrt(-re);
} else if (re <= 7.5e-180) {
tmp = sqrt((0.5 * (im - re)));
} else if (re <= 1.5e-148) {
tmp = 0.5 / (sqrt(re) / im);
} else if (re <= 1.46e-36) {
tmp = sqrt((im * 0.5));
} else if (re <= 1e+53) {
tmp = 0.5 * (im / sqrt(re));
} else if (re <= 5e+94) {
tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.0))));
} 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-71)) then
tmp = sqrt(-re)
else if (re <= 7.5d-180) then
tmp = sqrt((0.5d0 * (im - re)))
else if (re <= 1.5d-148) then
tmp = 0.5d0 / (sqrt(re) / im)
else if (re <= 1.46d-36) then
tmp = sqrt((im * 0.5d0))
else if (re <= 1d+53) then
tmp = 0.5d0 * (im / sqrt(re))
else if (re <= 5d+94) then
tmp = 0.5d0 * sqrt(((im * 2.0d0) + (re * ((re / im) - 2.0d0))))
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-71) {
tmp = Math.sqrt(-re);
} else if (re <= 7.5e-180) {
tmp = Math.sqrt((0.5 * (im - re)));
} else if (re <= 1.5e-148) {
tmp = 0.5 / (Math.sqrt(re) / im);
} else if (re <= 1.46e-36) {
tmp = Math.sqrt((im * 0.5));
} else if (re <= 1e+53) {
tmp = 0.5 * (im / Math.sqrt(re));
} else if (re <= 5e+94) {
tmp = 0.5 * Math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0))));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -9e-71: tmp = math.sqrt(-re) elif re <= 7.5e-180: tmp = math.sqrt((0.5 * (im - re))) elif re <= 1.5e-148: tmp = 0.5 / (math.sqrt(re) / im) elif re <= 1.46e-36: tmp = math.sqrt((im * 0.5)) elif re <= 1e+53: tmp = 0.5 * (im / math.sqrt(re)) elif re <= 5e+94: tmp = 0.5 * math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -9e-71) tmp = sqrt(Float64(-re)); elseif (re <= 7.5e-180) tmp = sqrt(Float64(0.5 * Float64(im - re))); elseif (re <= 1.5e-148) tmp = Float64(0.5 / Float64(sqrt(re) / im)); elseif (re <= 1.46e-36) tmp = sqrt(Float64(im * 0.5)); elseif (re <= 1e+53) tmp = Float64(0.5 * Float64(im / sqrt(re))); elseif (re <= 5e+94) tmp = Float64(0.5 * sqrt(Float64(Float64(im * 2.0) + Float64(re * Float64(Float64(re / im) - 2.0))))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -9e-71) tmp = sqrt(-re); elseif (re <= 7.5e-180) tmp = sqrt((0.5 * (im - re))); elseif (re <= 1.5e-148) tmp = 0.5 / (sqrt(re) / im); elseif (re <= 1.46e-36) tmp = sqrt((im * 0.5)); elseif (re <= 1e+53) tmp = 0.5 * (im / sqrt(re)); elseif (re <= 5e+94) tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -9e-71], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 7.5e-180], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, 1.5e-148], N[(0.5 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.46e-36], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, 1e+53], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5e+94], 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[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -9 \cdot 10^{-71}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 7.5 \cdot 10^{-180}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 1.5 \cdot 10^{-148}:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\
\mathbf{elif}\;re \leq 1.46 \cdot 10^{-36}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{elif}\;re \leq 10^{+53}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{elif}\;re \leq 5 \cdot 10^{+94}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2 + re \cdot \left(\frac{re}{im} - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -9.0000000000000004e-71Initial program 44.2%
Taylor expanded in re around -inf 81.8%
*-commutative81.8%
Simplified81.8%
add-sqr-sqrt81.4%
sqrt-unprod81.8%
*-commutative81.8%
*-commutative81.8%
swap-sqr81.8%
add-sqr-sqrt81.8%
metadata-eval81.8%
Applied egg-rr81.8%
associate-*l*81.8%
metadata-eval81.8%
*-commutative81.8%
mul-1-neg81.8%
Simplified81.8%
if -9.0000000000000004e-71 < re < 7.50000000000000015e-180Initial program 56.1%
pow156.1%
Applied egg-rr97.3%
unpow197.3%
*-commutative97.3%
associate-*r*97.3%
metadata-eval97.3%
Simplified97.3%
Taylor expanded in re around 0 82.5%
neg-mul-182.5%
unsub-neg82.5%
Simplified82.5%
if 7.50000000000000015e-180 < re < 1.49999999999999999e-148Initial program 2.4%
Taylor expanded in re around inf 5.0%
sqrt-div5.0%
sqrt-pow183.6%
metadata-eval83.6%
pow183.6%
clear-num84.1%
Applied egg-rr84.1%
un-div-inv84.1%
Applied egg-rr84.1%
if 1.49999999999999999e-148 < re < 1.4599999999999999e-36Initial program 38.9%
pow138.9%
Applied egg-rr61.8%
unpow161.8%
*-commutative61.8%
associate-*r*61.8%
metadata-eval61.8%
Simplified61.8%
Taylor expanded in re around 0 63.2%
if 1.4599999999999999e-36 < re < 9.9999999999999999e52Initial program 21.9%
Taylor expanded in re around inf 35.3%
sqrt-div43.4%
sqrt-pow171.5%
metadata-eval71.5%
pow171.5%
div-inv71.3%
Applied egg-rr71.3%
associate-*r/71.5%
*-rgt-identity71.5%
Simplified71.5%
if 9.9999999999999999e52 < re < 5.0000000000000001e94Initial program 40.2%
Taylor expanded in re around 0 87.3%
if 5.0000000000000001e94 < re Initial program 9.1%
Taylor expanded in re around inf 54.2%
sqrt-div70.1%
sqrt-pow193.1%
metadata-eval93.1%
pow193.1%
clear-num90.1%
Applied egg-rr90.1%
un-div-inv90.1%
Applied egg-rr90.1%
associate-/r/93.0%
associate-*l/93.1%
*-commutative93.1%
Simplified93.1%
Final simplification81.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (* 0.5 (- im re)))))
(if (<= re -3.9e-73)
(sqrt (- re))
(if (<= re 7.5e-180)
t_0
(if (<= re 8e-149)
(/ 0.5 (/ (sqrt re) im))
(if (<= re 6.6e-37)
(sqrt (* im 0.5))
(if (or (<= re 1.6e+53) (not (<= re 5.8e+93)))
(* 0.5 (/ im (sqrt re)))
t_0)))))))
double code(double re, double im) {
double t_0 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -3.9e-73) {
tmp = sqrt(-re);
} else if (re <= 7.5e-180) {
tmp = t_0;
} else if (re <= 8e-149) {
tmp = 0.5 / (sqrt(re) / im);
} else if (re <= 6.6e-37) {
tmp = sqrt((im * 0.5));
} else if ((re <= 1.6e+53) || !(re <= 5.8e+93)) {
tmp = 0.5 * (im / sqrt(re));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((0.5d0 * (im - re)))
if (re <= (-3.9d-73)) then
tmp = sqrt(-re)
else if (re <= 7.5d-180) then
tmp = t_0
else if (re <= 8d-149) then
tmp = 0.5d0 / (sqrt(re) / im)
else if (re <= 6.6d-37) then
tmp = sqrt((im * 0.5d0))
else if ((re <= 1.6d+53) .or. (.not. (re <= 5.8d+93))) then
tmp = 0.5d0 * (im / sqrt(re))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -3.9e-73) {
tmp = Math.sqrt(-re);
} else if (re <= 7.5e-180) {
tmp = t_0;
} else if (re <= 8e-149) {
tmp = 0.5 / (Math.sqrt(re) / im);
} else if (re <= 6.6e-37) {
tmp = Math.sqrt((im * 0.5));
} else if ((re <= 1.6e+53) || !(re <= 5.8e+93)) {
tmp = 0.5 * (im / Math.sqrt(re));
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -3.9e-73: tmp = math.sqrt(-re) elif re <= 7.5e-180: tmp = t_0 elif re <= 8e-149: tmp = 0.5 / (math.sqrt(re) / im) elif re <= 6.6e-37: tmp = math.sqrt((im * 0.5)) elif (re <= 1.6e+53) or not (re <= 5.8e+93): tmp = 0.5 * (im / math.sqrt(re)) else: tmp = t_0 return tmp
function code(re, im) t_0 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -3.9e-73) tmp = sqrt(Float64(-re)); elseif (re <= 7.5e-180) tmp = t_0; elseif (re <= 8e-149) tmp = Float64(0.5 / Float64(sqrt(re) / im)); elseif (re <= 6.6e-37) tmp = sqrt(Float64(im * 0.5)); elseif ((re <= 1.6e+53) || !(re <= 5.8e+93)) tmp = Float64(0.5 * Float64(im / sqrt(re))); else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -3.9e-73) tmp = sqrt(-re); elseif (re <= 7.5e-180) tmp = t_0; elseif (re <= 8e-149) tmp = 0.5 / (sqrt(re) / im); elseif (re <= 6.6e-37) tmp = sqrt((im * 0.5)); elseif ((re <= 1.6e+53) || ~((re <= 5.8e+93))) tmp = 0.5 * (im / sqrt(re)); else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -3.9e-73], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 7.5e-180], t$95$0, If[LessEqual[re, 8e-149], N[(0.5 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.6e-37], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[re, 1.6e+53], N[Not[LessEqual[re, 5.8e+93]], $MachinePrecision]], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -3.9 \cdot 10^{-73}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 7.5 \cdot 10^{-180}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 8 \cdot 10^{-149}:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\
\mathbf{elif}\;re \leq 6.6 \cdot 10^{-37}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{elif}\;re \leq 1.6 \cdot 10^{+53} \lor \neg \left(re \leq 5.8 \cdot 10^{+93}\right):\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if re < -3.89999999999999982e-73Initial program 44.2%
Taylor expanded in re around -inf 81.8%
*-commutative81.8%
Simplified81.8%
add-sqr-sqrt81.4%
sqrt-unprod81.8%
*-commutative81.8%
*-commutative81.8%
swap-sqr81.8%
add-sqr-sqrt81.8%
metadata-eval81.8%
Applied egg-rr81.8%
associate-*l*81.8%
metadata-eval81.8%
*-commutative81.8%
mul-1-neg81.8%
Simplified81.8%
if -3.89999999999999982e-73 < re < 7.50000000000000015e-180 or 1.6e53 < re < 5.7999999999999997e93Initial program 54.5%
pow154.5%
Applied egg-rr96.4%
unpow196.4%
*-commutative96.4%
associate-*r*96.4%
metadata-eval96.4%
Simplified96.4%
Taylor expanded in re around 0 82.4%
neg-mul-182.4%
unsub-neg82.4%
Simplified82.4%
if 7.50000000000000015e-180 < re < 7.99999999999999983e-149Initial program 2.4%
Taylor expanded in re around inf 5.0%
sqrt-div5.0%
sqrt-pow183.6%
metadata-eval83.6%
pow183.6%
clear-num84.1%
Applied egg-rr84.1%
un-div-inv84.1%
Applied egg-rr84.1%
if 7.99999999999999983e-149 < re < 6.59999999999999964e-37Initial program 38.9%
pow138.9%
Applied egg-rr61.8%
unpow161.8%
*-commutative61.8%
associate-*r*61.8%
metadata-eval61.8%
Simplified61.8%
Taylor expanded in re around 0 63.2%
if 6.59999999999999964e-37 < re < 1.6e53 or 5.7999999999999997e93 < re Initial program 13.5%
Taylor expanded in re around inf 47.7%
sqrt-div61.0%
sqrt-pow185.7%
metadata-eval85.7%
pow185.7%
div-inv85.5%
Applied egg-rr85.5%
associate-*r/85.7%
*-rgt-identity85.7%
Simplified85.7%
Final simplification81.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (/ im (sqrt re)))) (t_1 (sqrt (* 0.5 (- im re)))))
(if (<= re -3.75e-70)
(sqrt (- re))
(if (<= re 7.5e-180)
t_1
(if (<= re 7.6e-149)
t_0
(if (<= re 1.28e-36)
(sqrt (* im 0.5))
(if (or (<= re 1.65e+53) (not (<= re 5.8e+93))) t_0 t_1)))))))
double code(double re, double im) {
double t_0 = 0.5 * (im / sqrt(re));
double t_1 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -3.75e-70) {
tmp = sqrt(-re);
} else if (re <= 7.5e-180) {
tmp = t_1;
} else if (re <= 7.6e-149) {
tmp = t_0;
} else if (re <= 1.28e-36) {
tmp = sqrt((im * 0.5));
} else if ((re <= 1.65e+53) || !(re <= 5.8e+93)) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * (im / sqrt(re))
t_1 = sqrt((0.5d0 * (im - re)))
if (re <= (-3.75d-70)) then
tmp = sqrt(-re)
else if (re <= 7.5d-180) then
tmp = t_1
else if (re <= 7.6d-149) then
tmp = t_0
else if (re <= 1.28d-36) then
tmp = sqrt((im * 0.5d0))
else if ((re <= 1.65d+53) .or. (.not. (re <= 5.8d+93))) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * (im / Math.sqrt(re));
double t_1 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -3.75e-70) {
tmp = Math.sqrt(-re);
} else if (re <= 7.5e-180) {
tmp = t_1;
} else if (re <= 7.6e-149) {
tmp = t_0;
} else if (re <= 1.28e-36) {
tmp = Math.sqrt((im * 0.5));
} else if ((re <= 1.65e+53) || !(re <= 5.8e+93)) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = 0.5 * (im / math.sqrt(re)) t_1 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -3.75e-70: tmp = math.sqrt(-re) elif re <= 7.5e-180: tmp = t_1 elif re <= 7.6e-149: tmp = t_0 elif re <= 1.28e-36: tmp = math.sqrt((im * 0.5)) elif (re <= 1.65e+53) or not (re <= 5.8e+93): tmp = t_0 else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(0.5 * Float64(im / sqrt(re))) t_1 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -3.75e-70) tmp = sqrt(Float64(-re)); elseif (re <= 7.5e-180) tmp = t_1; elseif (re <= 7.6e-149) tmp = t_0; elseif (re <= 1.28e-36) tmp = sqrt(Float64(im * 0.5)); elseif ((re <= 1.65e+53) || !(re <= 5.8e+93)) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * (im / sqrt(re)); t_1 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -3.75e-70) tmp = sqrt(-re); elseif (re <= 7.5e-180) tmp = t_1; elseif (re <= 7.6e-149) tmp = t_0; elseif (re <= 1.28e-36) tmp = sqrt((im * 0.5)); elseif ((re <= 1.65e+53) || ~((re <= 5.8e+93))) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -3.75e-70], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 7.5e-180], t$95$1, If[LessEqual[re, 7.6e-149], t$95$0, If[LessEqual[re, 1.28e-36], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[re, 1.65e+53], N[Not[LessEqual[re, 5.8e+93]], $MachinePrecision]], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{im}{\sqrt{re}}\\
t_1 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -3.75 \cdot 10^{-70}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 7.5 \cdot 10^{-180}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;re \leq 7.6 \cdot 10^{-149}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 1.28 \cdot 10^{-36}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{elif}\;re \leq 1.65 \cdot 10^{+53} \lor \neg \left(re \leq 5.8 \cdot 10^{+93}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if re < -3.74999999999999986e-70Initial program 44.2%
Taylor expanded in re around -inf 81.8%
*-commutative81.8%
Simplified81.8%
add-sqr-sqrt81.4%
sqrt-unprod81.8%
*-commutative81.8%
*-commutative81.8%
swap-sqr81.8%
add-sqr-sqrt81.8%
metadata-eval81.8%
Applied egg-rr81.8%
associate-*l*81.8%
metadata-eval81.8%
*-commutative81.8%
mul-1-neg81.8%
Simplified81.8%
if -3.74999999999999986e-70 < re < 7.50000000000000015e-180 or 1.6500000000000001e53 < re < 5.7999999999999997e93Initial program 54.5%
pow154.5%
Applied egg-rr96.4%
unpow196.4%
*-commutative96.4%
associate-*r*96.4%
metadata-eval96.4%
Simplified96.4%
Taylor expanded in re around 0 82.4%
neg-mul-182.4%
unsub-neg82.4%
Simplified82.4%
if 7.50000000000000015e-180 < re < 7.6000000000000001e-149 or 1.28e-36 < re < 1.6500000000000001e53 or 5.7999999999999997e93 < re Initial program 12.6%
Taylor expanded in re around inf 44.2%
sqrt-div56.4%
sqrt-pow185.5%
metadata-eval85.5%
pow185.5%
div-inv85.4%
Applied egg-rr85.4%
associate-*r/85.5%
*-rgt-identity85.5%
Simplified85.5%
if 7.6000000000000001e-149 < re < 1.28e-36Initial program 38.9%
pow138.9%
Applied egg-rr61.8%
unpow161.8%
*-commutative61.8%
associate-*r*61.8%
metadata-eval61.8%
Simplified61.8%
Taylor expanded in re around 0 63.2%
Final simplification81.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (* 0.5 (- im re)))))
(if (<= re -4.5e-70)
(sqrt (- re))
(if (<= re 7.4e-180)
t_0
(if (<= re 7.6e-149)
(/ 0.5 (/ (sqrt re) im))
(if (<= re 5.6e-37)
(sqrt (* im 0.5))
(if (<= re 2.8e+52)
(* 0.5 (/ im (sqrt re)))
(if (<= re 5.8e+93) t_0 (/ (* im 0.5) (sqrt re))))))))))
double code(double re, double im) {
double t_0 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -4.5e-70) {
tmp = sqrt(-re);
} else if (re <= 7.4e-180) {
tmp = t_0;
} else if (re <= 7.6e-149) {
tmp = 0.5 / (sqrt(re) / im);
} else if (re <= 5.6e-37) {
tmp = sqrt((im * 0.5));
} else if (re <= 2.8e+52) {
tmp = 0.5 * (im / sqrt(re));
} else if (re <= 5.8e+93) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = sqrt((0.5d0 * (im - re)))
if (re <= (-4.5d-70)) then
tmp = sqrt(-re)
else if (re <= 7.4d-180) then
tmp = t_0
else if (re <= 7.6d-149) then
tmp = 0.5d0 / (sqrt(re) / im)
else if (re <= 5.6d-37) then
tmp = sqrt((im * 0.5d0))
else if (re <= 2.8d+52) then
tmp = 0.5d0 * (im / sqrt(re))
else if (re <= 5.8d+93) then
tmp = t_0
else
tmp = (im * 0.5d0) / sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -4.5e-70) {
tmp = Math.sqrt(-re);
} else if (re <= 7.4e-180) {
tmp = t_0;
} else if (re <= 7.6e-149) {
tmp = 0.5 / (Math.sqrt(re) / im);
} else if (re <= 5.6e-37) {
tmp = Math.sqrt((im * 0.5));
} else if (re <= 2.8e+52) {
tmp = 0.5 * (im / Math.sqrt(re));
} else if (re <= 5.8e+93) {
tmp = t_0;
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): t_0 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -4.5e-70: tmp = math.sqrt(-re) elif re <= 7.4e-180: tmp = t_0 elif re <= 7.6e-149: tmp = 0.5 / (math.sqrt(re) / im) elif re <= 5.6e-37: tmp = math.sqrt((im * 0.5)) elif re <= 2.8e+52: tmp = 0.5 * (im / math.sqrt(re)) elif re <= 5.8e+93: tmp = t_0 else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) t_0 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -4.5e-70) tmp = sqrt(Float64(-re)); elseif (re <= 7.4e-180) tmp = t_0; elseif (re <= 7.6e-149) tmp = Float64(0.5 / Float64(sqrt(re) / im)); elseif (re <= 5.6e-37) tmp = sqrt(Float64(im * 0.5)); elseif (re <= 2.8e+52) tmp = Float64(0.5 * Float64(im / sqrt(re))); elseif (re <= 5.8e+93) tmp = t_0; else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -4.5e-70) tmp = sqrt(-re); elseif (re <= 7.4e-180) tmp = t_0; elseif (re <= 7.6e-149) tmp = 0.5 / (sqrt(re) / im); elseif (re <= 5.6e-37) tmp = sqrt((im * 0.5)); elseif (re <= 2.8e+52) tmp = 0.5 * (im / sqrt(re)); elseif (re <= 5.8e+93) tmp = t_0; else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -4.5e-70], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 7.4e-180], t$95$0, If[LessEqual[re, 7.6e-149], N[(0.5 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.6e-37], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, 2.8e+52], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.8e+93], t$95$0, N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -4.5 \cdot 10^{-70}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 7.4 \cdot 10^{-180}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 7.6 \cdot 10^{-149}:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\
\mathbf{elif}\;re \leq 5.6 \cdot 10^{-37}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{elif}\;re \leq 2.8 \cdot 10^{+52}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{elif}\;re \leq 5.8 \cdot 10^{+93}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -4.50000000000000022e-70Initial program 44.2%
Taylor expanded in re around -inf 81.8%
*-commutative81.8%
Simplified81.8%
add-sqr-sqrt81.4%
sqrt-unprod81.8%
*-commutative81.8%
*-commutative81.8%
swap-sqr81.8%
add-sqr-sqrt81.8%
metadata-eval81.8%
Applied egg-rr81.8%
associate-*l*81.8%
metadata-eval81.8%
*-commutative81.8%
mul-1-neg81.8%
Simplified81.8%
if -4.50000000000000022e-70 < re < 7.40000000000000032e-180 or 2.8e52 < re < 5.7999999999999997e93Initial program 54.5%
pow154.5%
Applied egg-rr96.4%
unpow196.4%
*-commutative96.4%
associate-*r*96.4%
metadata-eval96.4%
Simplified96.4%
Taylor expanded in re around 0 82.4%
neg-mul-182.4%
unsub-neg82.4%
Simplified82.4%
if 7.40000000000000032e-180 < re < 7.6000000000000001e-149Initial program 2.4%
Taylor expanded in re around inf 5.0%
sqrt-div5.0%
sqrt-pow183.6%
metadata-eval83.6%
pow183.6%
clear-num84.1%
Applied egg-rr84.1%
un-div-inv84.1%
Applied egg-rr84.1%
if 7.6000000000000001e-149 < re < 5.6000000000000002e-37Initial program 38.9%
pow138.9%
Applied egg-rr61.8%
unpow161.8%
*-commutative61.8%
associate-*r*61.8%
metadata-eval61.8%
Simplified61.8%
Taylor expanded in re around 0 63.2%
if 5.6000000000000002e-37 < re < 2.8e52Initial program 21.9%
Taylor expanded in re around inf 35.3%
sqrt-div43.4%
sqrt-pow171.5%
metadata-eval71.5%
pow171.5%
div-inv71.3%
Applied egg-rr71.3%
associate-*r/71.5%
*-rgt-identity71.5%
Simplified71.5%
if 5.7999999999999997e93 < re Initial program 9.1%
Taylor expanded in re around inf 54.2%
sqrt-div70.1%
sqrt-pow193.1%
metadata-eval93.1%
pow193.1%
clear-num90.1%
Applied egg-rr90.1%
un-div-inv90.1%
Applied egg-rr90.1%
associate-/r/93.0%
associate-*l/93.1%
*-commutative93.1%
Simplified93.1%
Final simplification81.3%
(FPCore (re im) :precision binary64 (if (<= re -2.9e-133) (sqrt (- re)) (if (<= re 1.05e+143) (sqrt (* im 0.5)) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -2.9e-133) {
tmp = sqrt(-re);
} else if (re <= 1.05e+143) {
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.9d-133)) then
tmp = sqrt(-re)
else if (re <= 1.05d+143) 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.9e-133) {
tmp = Math.sqrt(-re);
} else if (re <= 1.05e+143) {
tmp = Math.sqrt((im * 0.5));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.9e-133: tmp = math.sqrt(-re) elif re <= 1.05e+143: tmp = math.sqrt((im * 0.5)) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -2.9e-133) tmp = sqrt(Float64(-re)); elseif (re <= 1.05e+143) 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.9e-133) tmp = sqrt(-re); elseif (re <= 1.05e+143) tmp = sqrt((im * 0.5)); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.9e-133], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.05e+143], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.9 \cdot 10^{-133}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.05 \cdot 10^{+143}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -2.8999999999999998e-133Initial program 50.0%
Taylor expanded in re around -inf 78.0%
*-commutative78.0%
Simplified78.0%
add-sqr-sqrt77.6%
sqrt-unprod78.0%
*-commutative78.0%
*-commutative78.0%
swap-sqr78.0%
add-sqr-sqrt78.0%
metadata-eval78.0%
Applied egg-rr78.0%
associate-*l*78.0%
metadata-eval78.0%
*-commutative78.0%
mul-1-neg78.0%
Simplified78.0%
if -2.8999999999999998e-133 < re < 1.04999999999999994e143Initial program 38.7%
pow138.7%
Applied egg-rr71.1%
unpow171.1%
*-commutative71.1%
associate-*r*71.1%
metadata-eval71.1%
Simplified71.1%
Taylor expanded in re around 0 64.4%
if 1.04999999999999994e143 < re Initial program 2.7%
Taylor expanded in re around inf 35.0%
Taylor expanded in re around 0 35.0%
Final simplification65.3%
(FPCore (re im) :precision binary64 (if (<= re -5e-310) (sqrt (- re)) 0.0))
double code(double re, double im) {
double tmp;
if (re <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = Math.sqrt(-re);
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5e-310: tmp = math.sqrt(-re) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -5e-310) tmp = sqrt(Float64(-re)); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5e-310) tmp = sqrt(-re); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5e-310], N[Sqrt[(-re)], $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -4.999999999999985e-310Initial program 49.7%
Taylor expanded in re around -inf 64.4%
*-commutative64.4%
Simplified64.4%
add-sqr-sqrt64.0%
sqrt-unprod64.4%
*-commutative64.4%
*-commutative64.4%
swap-sqr64.4%
add-sqr-sqrt64.4%
metadata-eval64.4%
Applied egg-rr64.4%
associate-*l*64.4%
metadata-eval64.4%
*-commutative64.4%
mul-1-neg64.4%
Simplified64.4%
if -4.999999999999985e-310 < re Initial program 27.1%
Taylor expanded in re around inf 13.0%
Taylor expanded in re around 0 13.0%
(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.9%
Taylor expanded in re around inf 8.1%
Taylor expanded in re around 0 8.1%
herbie shell --seed 2024111
(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)))))