
(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 9 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 re)) (sqrt (* 0.5 (- (hypot im re) re)))))
double code(double re, double im) {
double tmp;
if ((sqrt(((re * re) + (im * im))) - re) <= 0.0) {
tmp = (im * 0.5) / sqrt(re);
} else {
tmp = sqrt((0.5 * (hypot(im, re) - 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(re);
} else {
tmp = Math.sqrt((0.5 * (Math.hypot(im, re) - 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(re) else: tmp = math.sqrt((0.5 * (math.hypot(im, re) - 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(Float64(im * 0.5) / sqrt(re)); else tmp = sqrt(Float64(0.5 * Float64(hypot(im, re) - 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(re); else tmp = sqrt((0.5 * (hypot(im, re) - 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[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{re \cdot re + im \cdot im} - re \leq 0:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(im, re\right) - re\right)}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 4.7%
sub-neg4.7%
sqr-neg4.7%
sub-neg4.7%
sqr-neg4.7%
hypot-define7.7%
Simplified7.7%
Taylor expanded in re around inf 43.3%
*-commutative43.3%
sqrt-div51.4%
sqrt-pow197.5%
metadata-eval97.5%
pow197.5%
associate-*l/97.5%
Applied egg-rr97.5%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 42.5%
sub-neg42.5%
sqr-neg42.5%
sub-neg42.5%
sqr-neg42.5%
hypot-define87.1%
Simplified87.1%
*-commutative87.1%
hypot-define42.5%
*-commutative42.5%
add-sqr-sqrt42.2%
sqrt-unprod42.5%
*-commutative42.5%
*-commutative42.5%
swap-sqr42.5%
Applied egg-rr87.1%
associate-*l*87.1%
hypot-undefine42.5%
unpow242.5%
unpow242.5%
+-commutative42.5%
unpow242.5%
unpow242.5%
hypot-undefine87.1%
metadata-eval87.1%
Simplified87.1%
Final simplification88.7%
(FPCore (re im)
:precision binary64
(if (<= re -0.0115)
(sqrt (- re))
(if (<= re 1.6e+75)
(* 0.5 (sqrt (+ (* im 2.0) (* re (- (/ re im) 2.0)))))
(* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -0.0115) {
tmp = sqrt(-re);
} else if (re <= 1.6e+75) {
tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.0))));
} else {
tmp = (im * 0.5) * 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 <= (-0.0115d0)) then
tmp = sqrt(-re)
else if (re <= 1.6d+75) then
tmp = 0.5d0 * sqrt(((im * 2.0d0) + (re * ((re / im) - 2.0d0))))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.0115) {
tmp = Math.sqrt(-re);
} else if (re <= 1.6e+75) {
tmp = 0.5 * Math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0))));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.0115: tmp = math.sqrt(-re) elif re <= 1.6e+75: tmp = 0.5 * math.sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.0115) tmp = sqrt(Float64(-re)); elseif (re <= 1.6e+75) 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) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.0115) tmp = sqrt(-re); elseif (re <= 1.6e+75) tmp = 0.5 * sqrt(((im * 2.0) + (re * ((re / im) - 2.0)))); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.0115], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.6e+75], 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[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.0115:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.6 \cdot 10^{+75}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2 + re \cdot \left(\frac{re}{im} - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -0.0115Initial program 38.9%
sub-neg38.9%
sqr-neg38.9%
sub-neg38.9%
sqr-neg38.9%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define38.9%
*-commutative38.9%
add-sqr-sqrt38.6%
sqrt-unprod38.9%
*-commutative38.9%
*-commutative38.9%
swap-sqr38.9%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine38.9%
unpow238.9%
unpow238.9%
+-commutative38.9%
unpow238.9%
unpow238.9%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 77.2%
neg-mul-177.2%
Simplified77.2%
if -0.0115 < re < 1.59999999999999992e75Initial program 51.2%
sub-neg51.2%
sqr-neg51.2%
sub-neg51.2%
sqr-neg51.2%
hypot-define83.5%
Simplified83.5%
Taylor expanded in re around 0 76.6%
if 1.59999999999999992e75 < re Initial program 3.7%
sub-neg3.7%
sqr-neg3.7%
sub-neg3.7%
sqr-neg3.7%
hypot-define28.3%
Simplified28.3%
Taylor expanded in re around inf 38.1%
*-commutative38.1%
sqrt-div60.4%
sqrt-pow180.9%
metadata-eval80.9%
pow180.9%
associate-*l/80.9%
Applied egg-rr80.9%
clear-num80.7%
associate-/r/80.7%
pow1/280.7%
pow-flip80.9%
metadata-eval80.9%
Applied egg-rr80.9%
Final simplification77.8%
(FPCore (re im)
:precision binary64
(if (<= re -2.45e+48)
(sqrt (- re))
(if (<= re 1.4e+75)
(sqrt (* 0.5 (* im (- 1.0 (/ re im)))))
(* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -2.45e+48) {
tmp = sqrt(-re);
} else if (re <= 1.4e+75) {
tmp = sqrt((0.5 * (im * (1.0 - (re / im)))));
} else {
tmp = (im * 0.5) * 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.45d+48)) then
tmp = sqrt(-re)
else if (re <= 1.4d+75) then
tmp = sqrt((0.5d0 * (im * (1.0d0 - (re / im)))))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.45e+48) {
tmp = Math.sqrt(-re);
} else if (re <= 1.4e+75) {
tmp = Math.sqrt((0.5 * (im * (1.0 - (re / im)))));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.45e+48: tmp = math.sqrt(-re) elif re <= 1.4e+75: tmp = math.sqrt((0.5 * (im * (1.0 - (re / im))))) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.45e+48) tmp = sqrt(Float64(-re)); elseif (re <= 1.4e+75) tmp = sqrt(Float64(0.5 * Float64(im * Float64(1.0 - Float64(re / im))))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.45e+48) tmp = sqrt(-re); elseif (re <= 1.4e+75) tmp = sqrt((0.5 * (im * (1.0 - (re / im))))); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.45e+48], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.4e+75], N[Sqrt[N[(0.5 * N[(im * N[(1.0 - N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.45 \cdot 10^{+48}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.4 \cdot 10^{+75}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im \cdot \left(1 - \frac{re}{im}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -2.45000000000000015e48Initial program 32.8%
sub-neg32.8%
sqr-neg32.8%
sub-neg32.8%
sqr-neg32.8%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define32.8%
*-commutative32.8%
add-sqr-sqrt32.5%
sqrt-unprod32.8%
*-commutative32.8%
*-commutative32.8%
swap-sqr32.8%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine32.8%
unpow232.8%
unpow232.8%
+-commutative32.8%
unpow232.8%
unpow232.8%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.3%
neg-mul-182.3%
Simplified82.3%
if -2.45000000000000015e48 < re < 1.40000000000000006e75Initial program 52.6%
sub-neg52.6%
sqr-neg52.6%
sub-neg52.6%
sqr-neg52.6%
hypot-define84.9%
Simplified84.9%
*-commutative84.9%
hypot-define52.6%
*-commutative52.6%
add-sqr-sqrt52.2%
sqrt-unprod52.6%
*-commutative52.6%
*-commutative52.6%
swap-sqr52.6%
Applied egg-rr84.9%
associate-*l*84.9%
hypot-undefine52.6%
unpow252.6%
unpow252.6%
+-commutative52.6%
unpow252.6%
unpow252.6%
hypot-undefine84.9%
metadata-eval84.9%
Simplified84.9%
Taylor expanded in im around inf 74.1%
mul-1-neg74.1%
unsub-neg74.1%
Simplified74.1%
if 1.40000000000000006e75 < re Initial program 3.7%
sub-neg3.7%
sqr-neg3.7%
sub-neg3.7%
sqr-neg3.7%
hypot-define28.3%
Simplified28.3%
Taylor expanded in re around inf 38.1%
*-commutative38.1%
sqrt-div60.4%
sqrt-pow180.9%
metadata-eval80.9%
pow180.9%
associate-*l/80.9%
Applied egg-rr80.9%
clear-num80.7%
associate-/r/80.7%
pow1/280.7%
pow-flip80.9%
metadata-eval80.9%
Applied egg-rr80.9%
Final simplification77.5%
(FPCore (re im)
:precision binary64
(if (<= re -6.5e+45)
(sqrt (- re))
(if (<= re 1.35e+75)
(sqrt (* 0.5 (- im re)))
(* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -6.5e+45) {
tmp = sqrt(-re);
} else if (re <= 1.35e+75) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * 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 <= (-6.5d+45)) then
tmp = sqrt(-re)
else if (re <= 1.35d+75) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -6.5e+45) {
tmp = Math.sqrt(-re);
} else if (re <= 1.35e+75) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -6.5e+45: tmp = math.sqrt(-re) elif re <= 1.35e+75: tmp = math.sqrt((0.5 * (im - re))) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -6.5e+45) tmp = sqrt(Float64(-re)); elseif (re <= 1.35e+75) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -6.5e+45) tmp = sqrt(-re); elseif (re <= 1.35e+75) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6.5e+45], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.35e+75], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -6.5 \cdot 10^{+45}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.35 \cdot 10^{+75}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -6.50000000000000034e45Initial program 32.8%
sub-neg32.8%
sqr-neg32.8%
sub-neg32.8%
sqr-neg32.8%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define32.8%
*-commutative32.8%
add-sqr-sqrt32.5%
sqrt-unprod32.8%
*-commutative32.8%
*-commutative32.8%
swap-sqr32.8%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine32.8%
unpow232.8%
unpow232.8%
+-commutative32.8%
unpow232.8%
unpow232.8%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.3%
neg-mul-182.3%
Simplified82.3%
if -6.50000000000000034e45 < re < 1.34999999999999999e75Initial program 52.6%
sub-neg52.6%
sqr-neg52.6%
sub-neg52.6%
sqr-neg52.6%
hypot-define84.9%
Simplified84.9%
*-commutative84.9%
hypot-define52.6%
*-commutative52.6%
add-sqr-sqrt52.2%
sqrt-unprod52.6%
*-commutative52.6%
*-commutative52.6%
swap-sqr52.6%
Applied egg-rr84.9%
associate-*l*84.9%
hypot-undefine52.6%
unpow252.6%
unpow252.6%
+-commutative52.6%
unpow252.6%
unpow252.6%
hypot-undefine84.9%
metadata-eval84.9%
Simplified84.9%
Taylor expanded in re around 0 74.1%
neg-mul-174.1%
unsub-neg74.1%
Simplified74.1%
if 1.34999999999999999e75 < re Initial program 3.7%
sub-neg3.7%
sqr-neg3.7%
sub-neg3.7%
sqr-neg3.7%
hypot-define28.3%
Simplified28.3%
Taylor expanded in re around inf 38.1%
*-commutative38.1%
sqrt-div60.4%
sqrt-pow180.9%
metadata-eval80.9%
pow180.9%
associate-*l/80.9%
Applied egg-rr80.9%
clear-num80.7%
associate-/r/80.7%
pow1/280.7%
pow-flip80.9%
metadata-eval80.9%
Applied egg-rr80.9%
Final simplification77.5%
(FPCore (re im) :precision binary64 (if (<= re -1.66e+44) (sqrt (- re)) (if (<= re 1.25e+75) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.66e+44) {
tmp = sqrt(-re);
} else if (re <= 1.25e+75) {
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 <= (-1.66d+44)) then
tmp = sqrt(-re)
else if (re <= 1.25d+75) 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 <= -1.66e+44) {
tmp = Math.sqrt(-re);
} else if (re <= 1.25e+75) {
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 <= -1.66e+44: tmp = math.sqrt(-re) elif re <= 1.25e+75: 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 <= -1.66e+44) tmp = sqrt(Float64(-re)); elseif (re <= 1.25e+75) 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 <= -1.66e+44) tmp = sqrt(-re); elseif (re <= 1.25e+75) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.66e+44], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.25e+75], 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 -1.66 \cdot 10^{+44}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.25 \cdot 10^{+75}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.65999999999999992e44Initial program 32.8%
sub-neg32.8%
sqr-neg32.8%
sub-neg32.8%
sqr-neg32.8%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define32.8%
*-commutative32.8%
add-sqr-sqrt32.5%
sqrt-unprod32.8%
*-commutative32.8%
*-commutative32.8%
swap-sqr32.8%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine32.8%
unpow232.8%
unpow232.8%
+-commutative32.8%
unpow232.8%
unpow232.8%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.3%
neg-mul-182.3%
Simplified82.3%
if -1.65999999999999992e44 < re < 1.2500000000000001e75Initial program 52.6%
sub-neg52.6%
sqr-neg52.6%
sub-neg52.6%
sqr-neg52.6%
hypot-define84.9%
Simplified84.9%
*-commutative84.9%
hypot-define52.6%
*-commutative52.6%
add-sqr-sqrt52.2%
sqrt-unprod52.6%
*-commutative52.6%
*-commutative52.6%
swap-sqr52.6%
Applied egg-rr84.9%
associate-*l*84.9%
hypot-undefine52.6%
unpow252.6%
unpow252.6%
+-commutative52.6%
unpow252.6%
unpow252.6%
hypot-undefine84.9%
metadata-eval84.9%
Simplified84.9%
Taylor expanded in re around 0 74.1%
neg-mul-174.1%
unsub-neg74.1%
Simplified74.1%
if 1.2500000000000001e75 < re Initial program 3.7%
sub-neg3.7%
sqr-neg3.7%
sub-neg3.7%
sqr-neg3.7%
hypot-define28.3%
Simplified28.3%
Taylor expanded in re around inf 38.1%
*-commutative38.1%
sqrt-div60.4%
sqrt-pow180.9%
metadata-eval80.9%
pow180.9%
associate-*l/80.9%
Applied egg-rr80.9%
Final simplification77.5%
(FPCore (re im) :precision binary64 (if (<= re -1.36e+41) (sqrt (- re)) (if (<= re 3.3e+75) (sqrt (* 0.5 (- im re))) (* im (sqrt (/ 0.25 re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.36e+41) {
tmp = sqrt(-re);
} else if (re <= 3.3e+75) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = im * sqrt((0.25 / 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.36d+41)) then
tmp = sqrt(-re)
else if (re <= 3.3d+75) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = im * sqrt((0.25d0 / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.36e+41) {
tmp = Math.sqrt(-re);
} else if (re <= 3.3e+75) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = im * Math.sqrt((0.25 / re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.36e+41: tmp = math.sqrt(-re) elif re <= 3.3e+75: tmp = math.sqrt((0.5 * (im - re))) else: tmp = im * math.sqrt((0.25 / re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.36e+41) tmp = sqrt(Float64(-re)); elseif (re <= 3.3e+75) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(im * sqrt(Float64(0.25 / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.36e+41) tmp = sqrt(-re); elseif (re <= 3.3e+75) tmp = sqrt((0.5 * (im - re))); else tmp = im * sqrt((0.25 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.36e+41], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 3.3e+75], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(im * N[Sqrt[N[(0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.36 \cdot 10^{+41}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 3.3 \cdot 10^{+75}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\end{array}
\end{array}
if re < -1.35999999999999995e41Initial program 32.8%
sub-neg32.8%
sqr-neg32.8%
sub-neg32.8%
sqr-neg32.8%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define32.8%
*-commutative32.8%
add-sqr-sqrt32.5%
sqrt-unprod32.8%
*-commutative32.8%
*-commutative32.8%
swap-sqr32.8%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine32.8%
unpow232.8%
unpow232.8%
+-commutative32.8%
unpow232.8%
unpow232.8%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.3%
neg-mul-182.3%
Simplified82.3%
if -1.35999999999999995e41 < re < 3.29999999999999998e75Initial program 52.6%
sub-neg52.6%
sqr-neg52.6%
sub-neg52.6%
sqr-neg52.6%
hypot-define84.9%
Simplified84.9%
*-commutative84.9%
hypot-define52.6%
*-commutative52.6%
add-sqr-sqrt52.2%
sqrt-unprod52.6%
*-commutative52.6%
*-commutative52.6%
swap-sqr52.6%
Applied egg-rr84.9%
associate-*l*84.9%
hypot-undefine52.6%
unpow252.6%
unpow252.6%
+-commutative52.6%
unpow252.6%
unpow252.6%
hypot-undefine84.9%
metadata-eval84.9%
Simplified84.9%
Taylor expanded in re around 0 74.1%
neg-mul-174.1%
unsub-neg74.1%
Simplified74.1%
if 3.29999999999999998e75 < re Initial program 3.7%
sub-neg3.7%
sqr-neg3.7%
sub-neg3.7%
sqr-neg3.7%
hypot-define28.3%
Simplified28.3%
Taylor expanded in re around inf 38.1%
*-commutative38.1%
sqrt-div60.4%
sqrt-pow180.9%
metadata-eval80.9%
pow180.9%
associate-*l/80.9%
Applied egg-rr80.9%
associate-/l*80.7%
*-commutative80.7%
Applied egg-rr80.7%
*-un-lft-identity80.7%
*-commutative80.7%
add-sqr-sqrt80.5%
sqrt-unprod80.7%
frac-times80.7%
metadata-eval80.7%
add-sqr-sqrt80.8%
Applied egg-rr80.8%
*-rgt-identity80.8%
Simplified80.8%
Final simplification77.5%
(FPCore (re im) :precision binary64 (if (<= re -4.1e-10) (sqrt (- re)) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -4.1e-10) {
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 <= (-4.1d-10)) 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 <= -4.1e-10) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.1e-10: tmp = math.sqrt(-re) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.1e-10) 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 <= -4.1e-10) tmp = sqrt(-re); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.1e-10], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.1 \cdot 10^{-10}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -4.0999999999999998e-10Initial program 38.9%
sub-neg38.9%
sqr-neg38.9%
sub-neg38.9%
sqr-neg38.9%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define38.9%
*-commutative38.9%
add-sqr-sqrt38.6%
sqrt-unprod38.9%
*-commutative38.9%
*-commutative38.9%
swap-sqr38.9%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine38.9%
unpow238.9%
unpow238.9%
+-commutative38.9%
unpow238.9%
unpow238.9%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 77.2%
neg-mul-177.2%
Simplified77.2%
if -4.0999999999999998e-10 < re Initial program 35.9%
sub-neg35.9%
sqr-neg35.9%
sub-neg35.9%
sqr-neg35.9%
hypot-define65.8%
Simplified65.8%
*-commutative65.8%
hypot-define35.9%
*-commutative35.9%
add-sqr-sqrt35.7%
sqrt-unprod35.9%
*-commutative35.9%
*-commutative35.9%
swap-sqr35.9%
Applied egg-rr65.8%
associate-*l*65.8%
hypot-undefine35.9%
unpow235.9%
unpow235.9%
+-commutative35.9%
unpow235.9%
unpow235.9%
hypot-undefine65.8%
metadata-eval65.8%
Simplified65.8%
Taylor expanded in im around inf 58.8%
(FPCore (re im) :precision binary64 (if (<= re -1e-310) (sqrt (- re)) 0.0))
double code(double re, double im) {
double tmp;
if (re <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = Math.sqrt(-re);
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1e-310: tmp = math.sqrt(-re) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -1e-310) tmp = sqrt(Float64(-re)); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1e-310) tmp = sqrt(-re); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1e-310], N[Sqrt[(-re)], $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -9.999999999999969e-311Initial program 51.6%
sub-neg51.6%
sqr-neg51.6%
sub-neg51.6%
sqr-neg51.6%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define51.6%
*-commutative51.6%
add-sqr-sqrt51.2%
sqrt-unprod51.6%
*-commutative51.6%
*-commutative51.6%
swap-sqr51.6%
Applied egg-rr100.0%
associate-*l*100.0%
hypot-undefine51.6%
unpow251.6%
unpow251.6%
+-commutative51.6%
unpow251.6%
unpow251.6%
hypot-undefine100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 54.2%
neg-mul-154.2%
Simplified54.2%
if -9.999999999999969e-311 < re Initial program 24.1%
Taylor expanded in re around inf 5.3%
Taylor expanded in re around 0 5.3%
metadata-eval5.3%
Applied egg-rr5.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 36.7%
Taylor expanded in re around inf 4.2%
Taylor expanded in re around 0 4.2%
metadata-eval4.2%
Applied egg-rr4.2%
herbie shell --seed 2024118
(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)))))