
(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 (<= re 1.1e-49) (sqrt (* (- (hypot re im) re) 0.5)) (* im (* 0.5 (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= 1.1e-49) {
tmp = sqrt(((hypot(re, im) - re) * 0.5));
} else {
tmp = im * (0.5 * pow(re, -0.5));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 1.1e-49) {
tmp = Math.sqrt(((Math.hypot(re, im) - re) * 0.5));
} else {
tmp = im * (0.5 * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.1e-49: tmp = math.sqrt(((math.hypot(re, im) - re) * 0.5)) else: tmp = im * (0.5 * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.1e-49) tmp = sqrt(Float64(Float64(hypot(re, im) - re) * 0.5)); else tmp = Float64(im * Float64(0.5 * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.1e-49) tmp = sqrt(((hypot(re, im) - re) * 0.5)); else tmp = im * (0.5 * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.1e-49], N[Sqrt[N[(N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision], N[(im * N[(0.5 * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.1 \cdot 10^{-49}:\\
\;\;\;\;\sqrt{\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(0.5 \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < 1.09999999999999995e-49Initial program 53.1%
add-sqr-sqrt52.7%
sqrt-unprod53.1%
*-commutative53.1%
*-commutative53.1%
swap-sqr53.1%
add-sqr-sqrt53.1%
*-commutative53.1%
hypot-define93.6%
metadata-eval93.6%
Applied egg-rr93.6%
associate-*l*93.6%
metadata-eval93.6%
Simplified93.6%
if 1.09999999999999995e-49 < re Initial program 11.0%
add-sqr-sqrt11.0%
sqrt-unprod11.0%
*-commutative11.0%
*-commutative11.0%
swap-sqr11.0%
add-sqr-sqrt11.0%
*-commutative11.0%
hypot-define35.6%
metadata-eval35.6%
Applied egg-rr35.6%
associate-*l*35.6%
metadata-eval35.6%
Simplified35.6%
Taylor expanded in re around inf 78.5%
associate-*l*78.4%
unpow278.4%
rem-square-sqrt79.4%
unpow1/279.4%
rem-exp-log74.8%
exp-neg74.8%
exp-prod74.8%
distribute-lft-neg-out74.8%
distribute-rgt-neg-in74.8%
metadata-eval74.8%
exp-to-pow79.4%
Simplified79.4%
(FPCore (re im)
:precision binary64
(if (<= re -4.6e+29)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 8e-50)
(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 <= -4.6e+29) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 8e-50) {
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 <= (-4.6d+29)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 8d-50) 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 <= -4.6e+29) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 8e-50) {
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 <= -4.6e+29: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 8e-50: 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 <= -4.6e+29) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 8e-50) tmp = sqrt(Float64(0.5 * Float64(im * Float64(1.0 - Float64(re / im))))); else tmp = Float64(im * Float64(0.5 * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.6e+29) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 8e-50) 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, -4.6e+29], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8e-50], N[Sqrt[N[(0.5 * N[(im * N[(1.0 - N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(im * N[(0.5 * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.6 \cdot 10^{+29}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 8 \cdot 10^{-50}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im \cdot \left(1 - \frac{re}{im}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(0.5 \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -4.6000000000000002e29Initial program 42.9%
sub-neg42.9%
sqr-neg42.9%
sub-neg42.9%
sqr-neg42.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.5%
*-commutative82.5%
Simplified82.5%
if -4.6000000000000002e29 < re < 8.00000000000000006e-50Initial program 57.1%
add-sqr-sqrt56.7%
sqrt-unprod57.1%
*-commutative57.1%
*-commutative57.1%
swap-sqr57.1%
add-sqr-sqrt57.1%
*-commutative57.1%
hypot-define91.1%
metadata-eval91.1%
Applied egg-rr91.1%
associate-*l*91.1%
metadata-eval91.1%
Simplified91.1%
Taylor expanded in im around inf 80.1%
mul-1-neg80.1%
unsub-neg80.1%
Simplified80.1%
if 8.00000000000000006e-50 < re Initial program 11.0%
add-sqr-sqrt11.0%
sqrt-unprod11.0%
*-commutative11.0%
*-commutative11.0%
swap-sqr11.0%
add-sqr-sqrt11.0%
*-commutative11.0%
hypot-define35.6%
metadata-eval35.6%
Applied egg-rr35.6%
associate-*l*35.6%
metadata-eval35.6%
Simplified35.6%
Taylor expanded in re around inf 78.5%
associate-*l*78.4%
unpow278.4%
rem-square-sqrt79.4%
unpow1/279.4%
rem-exp-log74.8%
exp-neg74.8%
exp-prod74.8%
distribute-lft-neg-out74.8%
distribute-rgt-neg-in74.8%
metadata-eval74.8%
exp-to-pow79.4%
Simplified79.4%
Final simplification80.4%
(FPCore (re im) :precision binary64 (if (<= re -4e+29) (* 0.5 (sqrt (* re -4.0))) (if (<= re 3.1e-51) (sqrt (* 0.5 (- im re))) (* im (* 0.5 (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -4e+29) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 3.1e-51) {
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 <= (-4d+29)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 3.1d-51) 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 <= -4e+29) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 3.1e-51) {
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 <= -4e+29: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 3.1e-51: 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 <= -4e+29) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 3.1e-51) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(im * Float64(0.5 * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4e+29) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 3.1e-51) 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, -4e+29], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.1e-51], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(im * N[(0.5 * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4 \cdot 10^{+29}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 3.1 \cdot 10^{-51}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(0.5 \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -3.99999999999999966e29Initial program 42.9%
sub-neg42.9%
sqr-neg42.9%
sub-neg42.9%
sqr-neg42.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.5%
*-commutative82.5%
Simplified82.5%
if -3.99999999999999966e29 < re < 3.0999999999999997e-51Initial program 57.1%
add-sqr-sqrt56.7%
sqrt-unprod57.1%
*-commutative57.1%
*-commutative57.1%
swap-sqr57.1%
add-sqr-sqrt57.1%
*-commutative57.1%
hypot-define91.1%
metadata-eval91.1%
Applied egg-rr91.1%
associate-*l*91.1%
metadata-eval91.1%
Simplified91.1%
Taylor expanded in re around 0 80.1%
neg-mul-180.1%
unsub-neg80.1%
Simplified80.1%
if 3.0999999999999997e-51 < re Initial program 11.0%
add-sqr-sqrt11.0%
sqrt-unprod11.0%
*-commutative11.0%
*-commutative11.0%
swap-sqr11.0%
add-sqr-sqrt11.0%
*-commutative11.0%
hypot-define35.6%
metadata-eval35.6%
Applied egg-rr35.6%
associate-*l*35.6%
metadata-eval35.6%
Simplified35.6%
Taylor expanded in re around inf 78.5%
associate-*l*78.4%
unpow278.4%
rem-square-sqrt79.4%
unpow1/279.4%
rem-exp-log74.8%
exp-neg74.8%
exp-prod74.8%
distribute-lft-neg-out74.8%
distribute-rgt-neg-in74.8%
metadata-eval74.8%
exp-to-pow79.4%
Simplified79.4%
Final simplification80.4%
(FPCore (re im) :precision binary64 (if (<= re -3.25e+30) (* 0.5 (sqrt (* re -4.0))) (if (<= re 9.5e-51) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -3.25e+30) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 9.5e-51) {
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 <= (-3.25d+30)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 9.5d-51) 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 <= -3.25e+30) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 9.5e-51) {
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 <= -3.25e+30: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 9.5e-51: 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 <= -3.25e+30) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 9.5e-51) 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 <= -3.25e+30) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 9.5e-51) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.25e+30], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 9.5e-51], 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 -3.25 \cdot 10^{+30}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 9.5 \cdot 10^{-51}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -3.25e30Initial program 42.9%
sub-neg42.9%
sqr-neg42.9%
sub-neg42.9%
sqr-neg42.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.5%
*-commutative82.5%
Simplified82.5%
if -3.25e30 < re < 9.4999999999999998e-51Initial program 57.1%
add-sqr-sqrt56.7%
sqrt-unprod57.1%
*-commutative57.1%
*-commutative57.1%
swap-sqr57.1%
add-sqr-sqrt57.1%
*-commutative57.1%
hypot-define91.1%
metadata-eval91.1%
Applied egg-rr91.1%
associate-*l*91.1%
metadata-eval91.1%
Simplified91.1%
Taylor expanded in re around 0 80.1%
neg-mul-180.1%
unsub-neg80.1%
Simplified80.1%
if 9.4999999999999998e-51 < re Initial program 11.0%
sub-neg11.0%
sqr-neg11.0%
sub-neg11.0%
sqr-neg11.0%
hypot-define35.6%
Simplified35.6%
Taylor expanded in re around inf 50.9%
div-inv50.9%
sqrt-prod60.9%
sqrt-pow179.4%
metadata-eval79.4%
pow179.4%
sqrt-div79.3%
metadata-eval79.3%
div-inv79.4%
associate-*r/79.4%
Applied egg-rr79.4%
*-commutative79.4%
Simplified79.4%
Final simplification80.4%
(FPCore (re im) :precision binary64 (if (<= re -6.8e+29) (* 0.5 (sqrt (* re -4.0))) (if (<= re 6.5e-54) (sqrt (* 0.5 (- im re))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -6.8e+29) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.5e-54) {
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 <= (-6.8d+29)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.5d-54) 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 <= -6.8e+29) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.5e-54) {
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 <= -6.8e+29: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.5e-54: 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 <= -6.8e+29) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.5e-54) 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 <= -6.8e+29) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.5e-54) tmp = sqrt((0.5 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6.8e+29], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.5e-54], 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 -6.8 \cdot 10^{+29}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.5 \cdot 10^{-54}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -6.79999999999999963e29Initial program 42.9%
sub-neg42.9%
sqr-neg42.9%
sub-neg42.9%
sqr-neg42.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.5%
*-commutative82.5%
Simplified82.5%
if -6.79999999999999963e29 < re < 6.49999999999999991e-54Initial program 57.1%
add-sqr-sqrt56.7%
sqrt-unprod57.1%
*-commutative57.1%
*-commutative57.1%
swap-sqr57.1%
add-sqr-sqrt57.1%
*-commutative57.1%
hypot-define91.1%
metadata-eval91.1%
Applied egg-rr91.1%
associate-*l*91.1%
metadata-eval91.1%
Simplified91.1%
Taylor expanded in re around 0 80.1%
neg-mul-180.1%
unsub-neg80.1%
Simplified80.1%
if 6.49999999999999991e-54 < re Initial program 11.0%
sub-neg11.0%
sqr-neg11.0%
sub-neg11.0%
sqr-neg11.0%
hypot-define35.6%
Simplified35.6%
Taylor expanded in re around inf 50.9%
div-inv50.9%
sqrt-prod60.9%
sqrt-pow179.4%
metadata-eval79.4%
pow179.4%
sqrt-div79.3%
metadata-eval79.3%
div-inv79.4%
associate-*r/79.4%
Applied egg-rr79.4%
*-commutative79.4%
Simplified79.4%
associate-/l*79.3%
*-commutative79.3%
Applied egg-rr79.3%
Final simplification80.4%
(FPCore (re im) :precision binary64 (if (<= re -5.4e+29) (* 0.5 (sqrt (* re -4.0))) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -5.4e+29) {
tmp = 0.5 * sqrt((re * -4.0));
} 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 <= (-5.4d+29)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -5.4e+29) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5.4e+29: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -5.4e+29) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5.4e+29) tmp = 0.5 * sqrt((re * -4.0)); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5.4e+29], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5.4 \cdot 10^{+29}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -5.4e29Initial program 42.9%
sub-neg42.9%
sqr-neg42.9%
sub-neg42.9%
sqr-neg42.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.5%
*-commutative82.5%
Simplified82.5%
if -5.4e29 < re Initial program 40.6%
add-sqr-sqrt40.4%
sqrt-unprod40.6%
*-commutative40.6%
*-commutative40.6%
swap-sqr40.6%
add-sqr-sqrt40.6%
*-commutative40.6%
hypot-define71.3%
metadata-eval71.3%
Applied egg-rr71.3%
associate-*l*71.3%
metadata-eval71.3%
Simplified71.3%
Taylor expanded in re around 0 60.2%
(FPCore (re im) :precision binary64 (if (<= re 1e-232) (sqrt (* 0.5 (- im re))) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= 1e-232) {
tmp = sqrt((0.5 * (im - 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 <= 1d-232) then
tmp = sqrt((0.5d0 * (im - 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 <= 1e-232) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1e-232: tmp = math.sqrt((0.5 * (im - re))) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= 1e-232) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1e-232) tmp = sqrt((0.5 * (im - re))); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1e-232], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 10^{-232}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < 1.00000000000000002e-232Initial program 54.9%
add-sqr-sqrt54.5%
sqrt-unprod54.9%
*-commutative54.9%
*-commutative54.9%
swap-sqr54.9%
add-sqr-sqrt54.9%
*-commutative54.9%
hypot-define99.3%
metadata-eval99.3%
Applied egg-rr99.3%
associate-*l*99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in re around 0 65.4%
neg-mul-165.4%
unsub-neg65.4%
Simplified65.4%
if 1.00000000000000002e-232 < re Initial program 24.7%
add-sqr-sqrt24.6%
sqrt-unprod24.7%
*-commutative24.7%
*-commutative24.7%
swap-sqr24.7%
add-sqr-sqrt24.7%
*-commutative24.7%
hypot-define50.7%
metadata-eval50.7%
Applied egg-rr50.7%
associate-*l*50.7%
metadata-eval50.7%
Simplified50.7%
Taylor expanded in re around 0 44.7%
Final simplification55.9%
(FPCore (re im) :precision binary64 (sqrt (* im 0.5)))
double code(double re, double im) {
return sqrt((im * 0.5));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((im * 0.5d0))
end function
public static double code(double re, double im) {
return Math.sqrt((im * 0.5));
}
def code(re, im): return math.sqrt((im * 0.5))
function code(re, im) return sqrt(Float64(im * 0.5)) end
function tmp = code(re, im) tmp = sqrt((im * 0.5)); end
code[re_, im_] := N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{im \cdot 0.5}
\end{array}
Initial program 41.1%
add-sqr-sqrt40.8%
sqrt-unprod41.1%
*-commutative41.1%
*-commutative41.1%
swap-sqr41.1%
add-sqr-sqrt41.1%
*-commutative41.1%
hypot-define77.1%
metadata-eval77.1%
Applied egg-rr77.1%
associate-*l*77.1%
metadata-eval77.1%
Simplified77.1%
Taylor expanded in re around 0 52.5%
herbie shell --seed 2024108
(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)))))