
(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 10 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 -6.8e+172)
(pow
(*
(*
(exp (* 0.25 (+ (log (* 0.5 (pow im 2.0))) (log (/ -1.0 re)))))
(sqrt 0.5))
(sqrt (sqrt 2.0)))
2.0)
(sqrt (* 0.5 (+ re (hypot re im))))))
double code(double re, double im) {
double tmp;
if (re <= -6.8e+172) {
tmp = pow(((exp((0.25 * (log((0.5 * pow(im, 2.0))) + log((-1.0 / re))))) * sqrt(0.5)) * sqrt(sqrt(2.0))), 2.0);
} else {
tmp = sqrt((0.5 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -6.8e+172) {
tmp = Math.pow(((Math.exp((0.25 * (Math.log((0.5 * Math.pow(im, 2.0))) + Math.log((-1.0 / re))))) * Math.sqrt(0.5)) * Math.sqrt(Math.sqrt(2.0))), 2.0);
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -6.8e+172: tmp = math.pow(((math.exp((0.25 * (math.log((0.5 * math.pow(im, 2.0))) + math.log((-1.0 / re))))) * math.sqrt(0.5)) * math.sqrt(math.sqrt(2.0))), 2.0) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (re <= -6.8e+172) tmp = Float64(Float64(exp(Float64(0.25 * Float64(log(Float64(0.5 * (im ^ 2.0))) + log(Float64(-1.0 / re))))) * sqrt(0.5)) * sqrt(sqrt(2.0))) ^ 2.0; else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -6.8e+172) tmp = ((exp((0.25 * (log((0.5 * (im ^ 2.0))) + log((-1.0 / re))))) * sqrt(0.5)) * sqrt(sqrt(2.0))) ^ 2.0; else tmp = sqrt((0.5 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6.8e+172], N[Power[N[(N[(N[Exp[N[(0.25 * N[(N[Log[N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Log[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Sqrt[2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -6.8 \cdot 10^{+172}:\\
\;\;\;\;{\left(\left(e^{0.25 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)} \cdot \sqrt{0.5}\right) \cdot \sqrt{\sqrt{2}}\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if re < -6.7999999999999996e172Initial program 2.7%
sqr-neg2.7%
+-commutative2.7%
sqr-neg2.7%
+-commutative2.7%
distribute-rgt-in2.7%
cancel-sign-sub2.7%
distribute-rgt-out--2.7%
sub-neg2.7%
remove-double-neg2.7%
+-commutative2.7%
hypot-define16.9%
Simplified16.9%
*-commutative16.9%
hypot-define2.7%
+-commutative2.7%
*-commutative2.7%
add-sqr-sqrt2.7%
pow22.7%
+-commutative2.7%
hypot-define16.9%
Applied egg-rr16.9%
Taylor expanded in re around -inf 65.6%
if -6.7999999999999996e172 < re Initial program 45.3%
sqr-neg45.3%
+-commutative45.3%
sqr-neg45.3%
+-commutative45.3%
distribute-rgt-in45.3%
cancel-sign-sub45.3%
distribute-rgt-out--45.3%
sub-neg45.3%
remove-double-neg45.3%
+-commutative45.3%
hypot-define85.1%
Simplified85.1%
*-commutative85.1%
hypot-define45.3%
+-commutative45.3%
*-commutative45.3%
add-sqr-sqrt45.0%
sqrt-unprod45.3%
*-commutative45.3%
*-commutative45.3%
swap-sqr45.3%
Applied egg-rr85.1%
*-commutative85.1%
associate-*r*85.1%
metadata-eval85.1%
Simplified85.1%
(FPCore (re im) :precision binary64 (if (<= re -2.85e+167) (pow (exp 0.5) (+ (log (/ -1.0 re)) (log (* 0.25 (pow im 2.0))))) (sqrt (* 0.5 (+ re (hypot re im))))))
double code(double re, double im) {
double tmp;
if (re <= -2.85e+167) {
tmp = pow(exp(0.5), (log((-1.0 / re)) + log((0.25 * pow(im, 2.0)))));
} else {
tmp = sqrt((0.5 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -2.85e+167) {
tmp = Math.pow(Math.exp(0.5), (Math.log((-1.0 / re)) + Math.log((0.25 * Math.pow(im, 2.0)))));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.85e+167: tmp = math.pow(math.exp(0.5), (math.log((-1.0 / re)) + math.log((0.25 * math.pow(im, 2.0))))) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.85e+167) tmp = exp(0.5) ^ Float64(log(Float64(-1.0 / re)) + log(Float64(0.25 * (im ^ 2.0)))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.85e+167) tmp = exp(0.5) ^ (log((-1.0 / re)) + log((0.25 * (im ^ 2.0)))); else tmp = sqrt((0.5 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.85e+167], N[Power[N[Exp[0.5], $MachinePrecision], N[(N[Log[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision] + N[Log[N[(0.25 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.85 \cdot 10^{+167}:\\
\;\;\;\;{\left(e^{0.5}\right)}^{\left(\log \left(\frac{-1}{re}\right) + \log \left(0.25 \cdot {im}^{2}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if re < -2.85000000000000008e167Initial program 2.7%
sqr-neg2.7%
+-commutative2.7%
sqr-neg2.7%
+-commutative2.7%
distribute-rgt-in2.7%
cancel-sign-sub2.7%
distribute-rgt-out--2.7%
sub-neg2.7%
remove-double-neg2.7%
+-commutative2.7%
hypot-define16.9%
Simplified16.9%
*-commutative16.9%
hypot-define2.7%
+-commutative2.7%
*-commutative2.7%
add-sqr-sqrt2.7%
sqrt-unprod2.7%
*-commutative2.7%
*-commutative2.7%
swap-sqr2.7%
Applied egg-rr16.9%
*-commutative16.9%
associate-*r*16.9%
metadata-eval16.9%
Simplified16.9%
*-commutative16.9%
sqrt-prod16.9%
Applied egg-rr16.9%
sqrt-unprod16.9%
*-commutative16.9%
pow1/216.9%
exp-to-pow16.6%
*-commutative16.6%
exp-prod16.5%
*-commutative16.5%
Applied egg-rr16.5%
Taylor expanded in re around -inf 64.8%
exp-prod65.3%
+-commutative65.3%
*-commutative65.3%
Simplified65.3%
if -2.85000000000000008e167 < re Initial program 45.3%
sqr-neg45.3%
+-commutative45.3%
sqr-neg45.3%
+-commutative45.3%
distribute-rgt-in45.3%
cancel-sign-sub45.3%
distribute-rgt-out--45.3%
sub-neg45.3%
remove-double-neg45.3%
+-commutative45.3%
hypot-define85.1%
Simplified85.1%
*-commutative85.1%
hypot-define45.3%
+-commutative45.3%
*-commutative45.3%
add-sqr-sqrt45.0%
sqrt-unprod45.3%
*-commutative45.3%
*-commutative45.3%
swap-sqr45.3%
Applied egg-rr85.1%
*-commutative85.1%
associate-*r*85.1%
metadata-eval85.1%
Simplified85.1%
Final simplification82.8%
(FPCore (re im) :precision binary64 (if (<= (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))) 0.0) (* 0.5 (sqrt (/ (pow im 2.0) (- re)))) (sqrt (* 0.5 (+ re (hypot re im))))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) {
tmp = 0.5 * sqrt((pow(im, 2.0) / -re));
} else {
tmp = sqrt((0.5 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.sqrt((2.0 * (re + Math.sqrt(((re * re) + (im * im)))))) <= 0.0) {
tmp = 0.5 * Math.sqrt((Math.pow(im, 2.0) / -re));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt((2.0 * (re + math.sqrt(((re * re) + (im * im)))))) <= 0.0: tmp = 0.5 * math.sqrt((math.pow(im, 2.0) / -re)) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(re + sqrt(Float64(Float64(re * re) + Float64(im * im)))))) <= 0.0) tmp = Float64(0.5 * sqrt(Float64((im ^ 2.0) / Float64(-re)))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) tmp = 0.5 * sqrt(((im ^ 2.0) / -re)); else tmp = sqrt((0.5 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(0.5 * N[Sqrt[N[(N[Power[im, 2.0], $MachinePrecision] / (-re)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\right)} \leq 0:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{{im}^{2}}{-re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\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 7.1%
sqr-neg7.1%
+-commutative7.1%
sqr-neg7.1%
+-commutative7.1%
distribute-rgt-in7.1%
cancel-sign-sub7.1%
distribute-rgt-out--7.1%
sub-neg7.1%
remove-double-neg7.1%
+-commutative7.1%
hypot-define7.1%
Simplified7.1%
Taylor expanded in re around -inf 51.7%
mul-1-neg51.7%
distribute-neg-frac251.7%
Simplified51.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 44.7%
sqr-neg44.7%
+-commutative44.7%
sqr-neg44.7%
+-commutative44.7%
distribute-rgt-in44.7%
cancel-sign-sub44.7%
distribute-rgt-out--44.7%
sub-neg44.7%
remove-double-neg44.7%
+-commutative44.7%
hypot-define86.4%
Simplified86.4%
*-commutative86.4%
hypot-define44.7%
+-commutative44.7%
*-commutative44.7%
add-sqr-sqrt44.4%
sqrt-unprod44.7%
*-commutative44.7%
*-commutative44.7%
swap-sqr44.7%
Applied egg-rr86.4%
*-commutative86.4%
associate-*r*86.4%
metadata-eval86.4%
Simplified86.4%
Final simplification82.3%
(FPCore (re im) :precision binary64 (if (<= re -3.2e+167) (* 0.5 (exp (* 0.5 (+ (log (/ -1.0 re)) (log (pow im 2.0)))))) (sqrt (* 0.5 (+ re (hypot re im))))))
double code(double re, double im) {
double tmp;
if (re <= -3.2e+167) {
tmp = 0.5 * exp((0.5 * (log((-1.0 / re)) + log(pow(im, 2.0)))));
} else {
tmp = sqrt((0.5 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -3.2e+167) {
tmp = 0.5 * Math.exp((0.5 * (Math.log((-1.0 / re)) + Math.log(Math.pow(im, 2.0)))));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.2e+167: tmp = 0.5 * math.exp((0.5 * (math.log((-1.0 / re)) + math.log(math.pow(im, 2.0))))) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.2e+167) tmp = Float64(0.5 * exp(Float64(0.5 * Float64(log(Float64(-1.0 / re)) + log((im ^ 2.0)))))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.2e+167) tmp = 0.5 * exp((0.5 * (log((-1.0 / re)) + log((im ^ 2.0))))); else tmp = sqrt((0.5 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.2e+167], N[(0.5 * N[Exp[N[(0.5 * N[(N[Log[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision] + N[Log[N[Power[im, 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.2 \cdot 10^{+167}:\\
\;\;\;\;0.5 \cdot e^{0.5 \cdot \left(\log \left(\frac{-1}{re}\right) + \log \left({im}^{2}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if re < -3.19999999999999981e167Initial program 2.7%
sqr-neg2.7%
+-commutative2.7%
sqr-neg2.7%
+-commutative2.7%
distribute-rgt-in2.7%
cancel-sign-sub2.7%
distribute-rgt-out--2.7%
sub-neg2.7%
remove-double-neg2.7%
+-commutative2.7%
hypot-define16.9%
Simplified16.9%
*-commutative16.9%
hypot-define2.7%
+-commutative2.7%
sqrt-prod2.7%
+-commutative2.7%
hypot-define16.9%
Applied egg-rr16.9%
*-commutative16.9%
sqrt-prod16.9%
pow1/216.9%
pow-to-exp16.6%
*-commutative16.6%
Applied egg-rr16.6%
Taylor expanded in re around -inf 65.2%
if -3.19999999999999981e167 < re Initial program 45.3%
sqr-neg45.3%
+-commutative45.3%
sqr-neg45.3%
+-commutative45.3%
distribute-rgt-in45.3%
cancel-sign-sub45.3%
distribute-rgt-out--45.3%
sub-neg45.3%
remove-double-neg45.3%
+-commutative45.3%
hypot-define85.1%
Simplified85.1%
*-commutative85.1%
hypot-define45.3%
+-commutative45.3%
*-commutative45.3%
add-sqr-sqrt45.0%
sqrt-unprod45.3%
*-commutative45.3%
*-commutative45.3%
swap-sqr45.3%
Applied egg-rr85.1%
*-commutative85.1%
associate-*r*85.1%
metadata-eval85.1%
Simplified85.1%
Final simplification82.8%
(FPCore (re im) :precision binary64 (if (<= re -2.85e+167) (exp (* 0.5 (+ (log (/ -1.0 re)) (log (* 0.25 (pow im 2.0)))))) (sqrt (* 0.5 (+ re (hypot re im))))))
double code(double re, double im) {
double tmp;
if (re <= -2.85e+167) {
tmp = exp((0.5 * (log((-1.0 / re)) + log((0.25 * pow(im, 2.0))))));
} else {
tmp = sqrt((0.5 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -2.85e+167) {
tmp = Math.exp((0.5 * (Math.log((-1.0 / re)) + Math.log((0.25 * Math.pow(im, 2.0))))));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.85e+167: tmp = math.exp((0.5 * (math.log((-1.0 / re)) + math.log((0.25 * math.pow(im, 2.0)))))) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.85e+167) tmp = exp(Float64(0.5 * Float64(log(Float64(-1.0 / re)) + log(Float64(0.25 * (im ^ 2.0)))))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.85e+167) tmp = exp((0.5 * (log((-1.0 / re)) + log((0.25 * (im ^ 2.0)))))); else tmp = sqrt((0.5 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.85e+167], N[Exp[N[(0.5 * N[(N[Log[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision] + N[Log[N[(0.25 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.85 \cdot 10^{+167}:\\
\;\;\;\;e^{0.5 \cdot \left(\log \left(\frac{-1}{re}\right) + \log \left(0.25 \cdot {im}^{2}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if re < -2.85000000000000008e167Initial program 2.7%
sqr-neg2.7%
+-commutative2.7%
sqr-neg2.7%
+-commutative2.7%
distribute-rgt-in2.7%
cancel-sign-sub2.7%
distribute-rgt-out--2.7%
sub-neg2.7%
remove-double-neg2.7%
+-commutative2.7%
hypot-define16.9%
Simplified16.9%
*-commutative16.9%
hypot-define2.7%
+-commutative2.7%
*-commutative2.7%
add-sqr-sqrt2.7%
sqrt-unprod2.7%
*-commutative2.7%
*-commutative2.7%
swap-sqr2.7%
Applied egg-rr16.9%
*-commutative16.9%
associate-*r*16.9%
metadata-eval16.9%
Simplified16.9%
pow1/216.9%
pow-to-exp16.6%
Applied egg-rr16.6%
Taylor expanded in re around -inf 64.8%
if -2.85000000000000008e167 < re Initial program 45.3%
sqr-neg45.3%
+-commutative45.3%
sqr-neg45.3%
+-commutative45.3%
distribute-rgt-in45.3%
cancel-sign-sub45.3%
distribute-rgt-out--45.3%
sub-neg45.3%
remove-double-neg45.3%
+-commutative45.3%
hypot-define85.1%
Simplified85.1%
*-commutative85.1%
hypot-define45.3%
+-commutative45.3%
*-commutative45.3%
add-sqr-sqrt45.0%
sqrt-unprod45.3%
*-commutative45.3%
*-commutative45.3%
swap-sqr45.3%
Applied egg-rr85.1%
*-commutative85.1%
associate-*r*85.1%
metadata-eval85.1%
Simplified85.1%
Final simplification82.7%
(FPCore (re im) :precision binary64 (if (<= re -2.85e+167) (sqrt (* -0.25 (/ (pow im 2.0) re))) (sqrt (* 0.5 (+ re (hypot re im))))))
double code(double re, double im) {
double tmp;
if (re <= -2.85e+167) {
tmp = sqrt((-0.25 * (pow(im, 2.0) / re)));
} else {
tmp = sqrt((0.5 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -2.85e+167) {
tmp = Math.sqrt((-0.25 * (Math.pow(im, 2.0) / re)));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.85e+167: tmp = math.sqrt((-0.25 * (math.pow(im, 2.0) / re))) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.85e+167) tmp = sqrt(Float64(-0.25 * Float64((im ^ 2.0) / re))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.85e+167) tmp = sqrt((-0.25 * ((im ^ 2.0) / re))); else tmp = sqrt((0.5 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.85e+167], N[Sqrt[N[(-0.25 * N[(N[Power[im, 2.0], $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.85 \cdot 10^{+167}:\\
\;\;\;\;\sqrt{-0.25 \cdot \frac{{im}^{2}}{re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if re < -2.85000000000000008e167Initial program 2.7%
sqr-neg2.7%
+-commutative2.7%
sqr-neg2.7%
+-commutative2.7%
distribute-rgt-in2.7%
cancel-sign-sub2.7%
distribute-rgt-out--2.7%
sub-neg2.7%
remove-double-neg2.7%
+-commutative2.7%
hypot-define16.9%
Simplified16.9%
*-commutative16.9%
hypot-define2.7%
+-commutative2.7%
*-commutative2.7%
add-sqr-sqrt2.7%
sqrt-unprod2.7%
*-commutative2.7%
*-commutative2.7%
swap-sqr2.7%
Applied egg-rr16.9%
*-commutative16.9%
associate-*r*16.9%
metadata-eval16.9%
Simplified16.9%
Taylor expanded in re around -inf 50.8%
if -2.85000000000000008e167 < re Initial program 45.3%
sqr-neg45.3%
+-commutative45.3%
sqr-neg45.3%
+-commutative45.3%
distribute-rgt-in45.3%
cancel-sign-sub45.3%
distribute-rgt-out--45.3%
sub-neg45.3%
remove-double-neg45.3%
+-commutative45.3%
hypot-define85.1%
Simplified85.1%
*-commutative85.1%
hypot-define45.3%
+-commutative45.3%
*-commutative45.3%
add-sqr-sqrt45.0%
sqrt-unprod45.3%
*-commutative45.3%
*-commutative45.3%
swap-sqr45.3%
Applied egg-rr85.1%
*-commutative85.1%
associate-*r*85.1%
metadata-eval85.1%
Simplified85.1%
(FPCore (re im) :precision binary64 (if (<= re -1.35e+168) (sqrt (* -0.25 (/ (pow im 2.0) re))) (if (<= re 1.05e-5) (sqrt (* 0.5 im)) (sqrt re))))
double code(double re, double im) {
double tmp;
if (re <= -1.35e+168) {
tmp = sqrt((-0.25 * (pow(im, 2.0) / re)));
} else if (re <= 1.05e-5) {
tmp = sqrt((0.5 * im));
} else {
tmp = 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.35d+168)) then
tmp = sqrt(((-0.25d0) * ((im ** 2.0d0) / re)))
else if (re <= 1.05d-5) then
tmp = sqrt((0.5d0 * im))
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.35e+168) {
tmp = Math.sqrt((-0.25 * (Math.pow(im, 2.0) / re)));
} else if (re <= 1.05e-5) {
tmp = Math.sqrt((0.5 * im));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.35e+168: tmp = math.sqrt((-0.25 * (math.pow(im, 2.0) / re))) elif re <= 1.05e-5: tmp = math.sqrt((0.5 * im)) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.35e+168) tmp = sqrt(Float64(-0.25 * Float64((im ^ 2.0) / re))); elseif (re <= 1.05e-5) tmp = sqrt(Float64(0.5 * im)); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.35e+168) tmp = sqrt((-0.25 * ((im ^ 2.0) / re))); elseif (re <= 1.05e-5) tmp = sqrt((0.5 * im)); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.35e+168], N[Sqrt[N[(-0.25 * N[(N[Power[im, 2.0], $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, 1.05e-5], N[Sqrt[N[(0.5 * im), $MachinePrecision]], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.35 \cdot 10^{+168}:\\
\;\;\;\;\sqrt{-0.25 \cdot \frac{{im}^{2}}{re}}\\
\mathbf{elif}\;re \leq 1.05 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{0.5 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.35000000000000008e168Initial program 2.7%
sqr-neg2.7%
+-commutative2.7%
sqr-neg2.7%
+-commutative2.7%
distribute-rgt-in2.7%
cancel-sign-sub2.7%
distribute-rgt-out--2.7%
sub-neg2.7%
remove-double-neg2.7%
+-commutative2.7%
hypot-define16.9%
Simplified16.9%
*-commutative16.9%
hypot-define2.7%
+-commutative2.7%
*-commutative2.7%
add-sqr-sqrt2.7%
sqrt-unprod2.7%
*-commutative2.7%
*-commutative2.7%
swap-sqr2.7%
Applied egg-rr16.9%
*-commutative16.9%
associate-*r*16.9%
metadata-eval16.9%
Simplified16.9%
Taylor expanded in re around -inf 50.8%
if -1.35000000000000008e168 < re < 1.04999999999999994e-5Initial program 46.4%
sqr-neg46.4%
+-commutative46.4%
sqr-neg46.4%
+-commutative46.4%
distribute-rgt-in46.4%
cancel-sign-sub46.4%
distribute-rgt-out--46.4%
sub-neg46.4%
remove-double-neg46.4%
+-commutative46.4%
hypot-define78.1%
Simplified78.1%
*-commutative78.1%
hypot-define46.4%
+-commutative46.4%
*-commutative46.4%
add-sqr-sqrt46.1%
sqrt-unprod46.4%
*-commutative46.4%
*-commutative46.4%
swap-sqr46.4%
Applied egg-rr78.1%
*-commutative78.1%
associate-*r*78.1%
metadata-eval78.1%
Simplified78.1%
Taylor expanded in re around 0 36.4%
if 1.04999999999999994e-5 < re Initial program 42.8%
sqr-neg42.8%
+-commutative42.8%
sqr-neg42.8%
+-commutative42.8%
distribute-rgt-in42.8%
cancel-sign-sub42.8%
distribute-rgt-out--42.8%
sub-neg42.8%
remove-double-neg42.8%
+-commutative42.8%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define42.8%
+-commutative42.8%
*-commutative42.8%
add-sqr-sqrt42.6%
sqrt-unprod42.8%
*-commutative42.8%
*-commutative42.8%
swap-sqr42.8%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around inf 76.7%
(FPCore (re im) :precision binary64 (if (<= re 2e-6) (sqrt (* 0.5 im)) (sqrt re)))
double code(double re, double im) {
double tmp;
if (re <= 2e-6) {
tmp = sqrt((0.5 * im));
} else {
tmp = 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 <= 2d-6) then
tmp = sqrt((0.5d0 * im))
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 2e-6) {
tmp = Math.sqrt((0.5 * im));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2e-6: tmp = math.sqrt((0.5 * im)) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= 2e-6) tmp = sqrt(Float64(0.5 * im)); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 2e-6) tmp = sqrt((0.5 * im)); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2e-6], N[Sqrt[N[(0.5 * im), $MachinePrecision]], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2 \cdot 10^{-6}:\\
\;\;\;\;\sqrt{0.5 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < 1.99999999999999991e-6Initial program 39.3%
sqr-neg39.3%
+-commutative39.3%
sqr-neg39.3%
+-commutative39.3%
distribute-rgt-in39.3%
cancel-sign-sub39.3%
distribute-rgt-out--39.3%
sub-neg39.3%
remove-double-neg39.3%
+-commutative39.3%
hypot-define68.2%
Simplified68.2%
*-commutative68.2%
hypot-define39.3%
+-commutative39.3%
*-commutative39.3%
add-sqr-sqrt39.0%
sqrt-unprod39.3%
*-commutative39.3%
*-commutative39.3%
swap-sqr39.3%
Applied egg-rr68.2%
*-commutative68.2%
associate-*r*68.2%
metadata-eval68.2%
Simplified68.2%
Taylor expanded in re around 0 31.4%
if 1.99999999999999991e-6 < re Initial program 42.8%
sqr-neg42.8%
+-commutative42.8%
sqr-neg42.8%
+-commutative42.8%
distribute-rgt-in42.8%
cancel-sign-sub42.8%
distribute-rgt-out--42.8%
sub-neg42.8%
remove-double-neg42.8%
+-commutative42.8%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define42.8%
+-commutative42.8%
*-commutative42.8%
add-sqr-sqrt42.6%
sqrt-unprod42.8%
*-commutative42.8%
*-commutative42.8%
swap-sqr42.8%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around inf 76.7%
(FPCore (re im) :precision binary64 (if (<= re -4e-310) 0.0 (sqrt re)))
double code(double re, double im) {
double tmp;
if (re <= -4e-310) {
tmp = 0.0;
} else {
tmp = 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 <= (-4d-310)) then
tmp = 0.0d0
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4e-310) {
tmp = 0.0;
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4e-310: tmp = 0.0 else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -4e-310) tmp = 0.0; else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4e-310) tmp = 0.0; else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4e-310], 0.0, N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4 \cdot 10^{-310}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -3.999999999999988e-310Initial program 30.0%
Taylor expanded in re around -inf 6.7%
mul-1-neg6.7%
Simplified6.7%
Taylor expanded in re around 0 6.7%
metadata-eval6.7%
Applied egg-rr6.7%
if -3.999999999999988e-310 < re Initial program 49.5%
sqr-neg49.5%
+-commutative49.5%
sqr-neg49.5%
+-commutative49.5%
distribute-rgt-in49.5%
cancel-sign-sub49.5%
distribute-rgt-out--49.5%
sub-neg49.5%
remove-double-neg49.5%
+-commutative49.5%
hypot-define100.0%
Simplified100.0%
*-commutative100.0%
hypot-define49.5%
+-commutative49.5%
*-commutative49.5%
add-sqr-sqrt49.2%
sqrt-unprod49.5%
*-commutative49.5%
*-commutative49.5%
swap-sqr49.5%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around inf 50.7%
(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 40.3%
Taylor expanded in re around -inf 4.6%
mul-1-neg4.6%
Simplified4.6%
Taylor expanded in re around 0 4.6%
metadata-eval4.6%
Applied egg-rr4.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (+ (* re re) (* im im)))))
(if (< re 0.0)
(* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- t_0 re)))))
(* 0.5 (sqrt (* 2.0 (+ t_0 re)))))))
double code(double re, double im) {
double t_0 = sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * sqrt((2.0 * (t_0 + 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(((re * re) + (im * im)))
if (re < 0.0d0) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(((im * im) / (t_0 - re))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (t_0 + re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt(((re * re) + (im * im))) tmp = 0 if re < 0.0: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(((im * im) / (t_0 - re)))) else: tmp = 0.5 * math.sqrt((2.0 * (t_0 + re))) return tmp
function code(re, im) t_0 = sqrt(Float64(Float64(re * re) + Float64(im * im))) tmp = 0.0 if (re < 0.0) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(Float64(im * im) / Float64(t_0 - re))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(t_0 + re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt(((re * re) + (im * im))); tmp = 0.0; if (re < 0.0) tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re)))); else tmp = 0.5 * sqrt((2.0 * (t_0 + re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[re, 0.0], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(N[(im * im), $MachinePrecision] / N[(t$95$0 - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(t$95$0 + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{re \cdot re + im \cdot im}\\
\mathbf{if}\;re < 0:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{t\_0 - re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(t\_0 + re\right)}\\
\end{array}
\end{array}
herbie shell --seed 2024110
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:alt
(if (< re 0.0) (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))