
(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 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}
(FPCore (re im)
:precision binary64
(if (<= (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))) 0.0)
(*
0.5
(* (hypot im (/ (sqrt (* (pow im 4.0) -0.25)) re)) (sqrt (/ -1.0 re))))
(* 0.5 (sqrt (* 2.0 (+ 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 * (hypot(im, (sqrt((pow(im, 4.0) * -0.25)) / re)) * sqrt((-1.0 / re)));
} else {
tmp = 0.5 * sqrt((2.0 * (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.hypot(im, (Math.sqrt((Math.pow(im, 4.0) * -0.25)) / re)) * Math.sqrt((-1.0 / re)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (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.hypot(im, (math.sqrt((math.pow(im, 4.0) * -0.25)) / re)) * math.sqrt((-1.0 / re))) else: tmp = 0.5 * math.sqrt((2.0 * (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 * Float64(hypot(im, Float64(sqrt(Float64((im ^ 4.0) * -0.25)) / re)) * sqrt(Float64(-1.0 / re)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 * (hypot(im, (sqrt(((im ^ 4.0) * -0.25)) / re)) * sqrt((-1.0 / re))); else tmp = 0.5 * sqrt((2.0 * (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[(N[Sqrt[im ^ 2 + N[(N[Sqrt[N[(N[Power[im, 4.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision] / re), $MachinePrecision] ^ 2], $MachinePrecision] * N[Sqrt[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $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 \left(\mathsf{hypot}\left(im, \frac{\sqrt{{im}^{4} \cdot -0.25}}{re}\right) \cdot \sqrt{\frac{-1}{re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \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 13.2%
sqr-neg13.2%
+-commutative13.2%
sqr-neg13.2%
+-commutative13.2%
distribute-rgt-in13.2%
cancel-sign-sub13.2%
distribute-rgt-out--13.2%
sub-neg13.2%
remove-double-neg13.2%
+-commutative13.2%
hypot-define13.2%
Simplified13.2%
Taylor expanded in re around -inf 59.6%
add-sqr-sqrt59.6%
sqrt-unprod31.6%
mul-1-neg31.6%
mul-1-neg31.6%
sqr-neg31.6%
sqrt-unprod11.3%
add-sqr-sqrt11.3%
div-inv11.3%
sqrt-prod0.0%
Applied egg-rr72.5%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 47.0%
sqr-neg47.0%
+-commutative47.0%
sqr-neg47.0%
+-commutative47.0%
distribute-rgt-in47.0%
cancel-sign-sub47.0%
distribute-rgt-out--47.0%
sub-neg47.0%
remove-double-neg47.0%
+-commutative47.0%
hypot-define88.8%
Simplified88.8%
Final simplification86.7%
(FPCore (re im) :precision binary64 (if (<= (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))) 0.0) (* 0.5 (sqrt (* re (* (pow (* im (/ (sqrt 2.0) re)) 2.0) -0.5)))) (* 0.5 (sqrt (* 2.0 (+ 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((re * (pow((im * (sqrt(2.0) / re)), 2.0) * -0.5)));
} else {
tmp = 0.5 * sqrt((2.0 * (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((re * (Math.pow((im * (Math.sqrt(2.0) / re)), 2.0) * -0.5)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (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((re * (math.pow((im * (math.sqrt(2.0) / re)), 2.0) * -0.5))) else: tmp = 0.5 * math.sqrt((2.0 * (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(re * Float64((Float64(im * Float64(sqrt(2.0) / re)) ^ 2.0) * -0.5)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * 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((re * (((im * (sqrt(2.0) / re)) ^ 2.0) * -0.5))); else tmp = 0.5 * sqrt((2.0 * (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[(re * N[(N[Power[N[(im * N[(N[Sqrt[2.0], $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $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{re \cdot \left({\left(im \cdot \frac{\sqrt{2}}{re}\right)}^{2} \cdot -0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \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 13.2%
sqr-neg13.2%
+-commutative13.2%
sqr-neg13.2%
+-commutative13.2%
distribute-rgt-in13.2%
cancel-sign-sub13.2%
distribute-rgt-out--13.2%
sub-neg13.2%
remove-double-neg13.2%
+-commutative13.2%
hypot-define13.2%
Simplified13.2%
hypot-define13.2%
+-commutative13.2%
distribute-rgt-in13.2%
add-sqr-sqrt10.2%
*-commutative10.2%
fma-define2.7%
*-commutative2.7%
hypot-define2.7%
*-commutative2.7%
hypot-define2.7%
*-commutative2.7%
Applied egg-rr2.7%
Taylor expanded in re around -inf 5.5%
mul-1-neg5.5%
*-commutative5.5%
distribute-rgt-neg-in5.5%
associate--l+5.5%
fma-define5.5%
associate-/l*5.5%
unpow25.5%
rem-square-sqrt5.5%
unpow25.5%
rem-square-sqrt59.8%
metadata-eval59.8%
Simplified59.8%
distribute-rgt-neg-out59.8%
neg-sub059.8%
*-commutative59.8%
fma-undefine59.8%
+-rgt-identity59.8%
add-sqr-sqrt59.4%
pow259.4%
sqrt-prod59.4%
sqrt-pow172.4%
metadata-eval72.4%
pow172.4%
sqrt-div72.5%
sqrt-pow172.5%
metadata-eval72.5%
pow172.5%
Applied egg-rr72.5%
neg-sub072.5%
distribute-rgt-neg-in72.5%
*-commutative72.5%
distribute-rgt-neg-in72.5%
metadata-eval72.5%
Simplified72.5%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 47.0%
sqr-neg47.0%
+-commutative47.0%
sqr-neg47.0%
+-commutative47.0%
distribute-rgt-in47.0%
cancel-sign-sub47.0%
distribute-rgt-out--47.0%
sub-neg47.0%
remove-double-neg47.0%
+-commutative47.0%
hypot-define88.8%
Simplified88.8%
Final simplification86.7%
(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)))) (* 0.5 (sqrt (* 2.0 (+ 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 = 0.5 * sqrt((2.0 * (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 = 0.5 * Math.sqrt((2.0 * (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 = 0.5 * math.sqrt((2.0 * (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 = Float64(0.5 * sqrt(Float64(2.0 * 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 = 0.5 * sqrt((2.0 * (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[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $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}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \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 13.2%
sqr-neg13.2%
+-commutative13.2%
sqr-neg13.2%
+-commutative13.2%
distribute-rgt-in13.2%
cancel-sign-sub13.2%
distribute-rgt-out--13.2%
sub-neg13.2%
remove-double-neg13.2%
+-commutative13.2%
hypot-define13.2%
Simplified13.2%
Taylor expanded in re around -inf 62.7%
mul-1-neg62.7%
distribute-neg-frac262.7%
Simplified62.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 47.0%
sqr-neg47.0%
+-commutative47.0%
sqr-neg47.0%
+-commutative47.0%
distribute-rgt-in47.0%
cancel-sign-sub47.0%
distribute-rgt-out--47.0%
sub-neg47.0%
remove-double-neg47.0%
+-commutative47.0%
hypot-define88.8%
Simplified88.8%
Final simplification85.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (/ (pow im 2.0) (- re))))))
(if (<= re -2.7e+56)
t_0
(if (<= re -520000.0)
(* 0.5 (sqrt (+ (* 2.0 im) (* re (+ 2.0 (/ re im))))))
(if (<= re -9e-43)
t_0
(if (<= re 5.3e+57)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(* 0.5 (* 2.0 (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((pow(im, 2.0) / -re));
double tmp;
if (re <= -2.7e+56) {
tmp = t_0;
} else if (re <= -520000.0) {
tmp = 0.5 * sqrt(((2.0 * im) + (re * (2.0 + (re / im)))));
} else if (re <= -9e-43) {
tmp = t_0;
} else if (re <= 5.3e+57) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * 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 = 0.5d0 * sqrt(((im ** 2.0d0) / -re))
if (re <= (-2.7d+56)) then
tmp = t_0
else if (re <= (-520000.0d0)) then
tmp = 0.5d0 * sqrt(((2.0d0 * im) + (re * (2.0d0 + (re / im)))))
else if (re <= (-9d-43)) then
tmp = t_0
else if (re <= 5.3d+57) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((Math.pow(im, 2.0) / -re));
double tmp;
if (re <= -2.7e+56) {
tmp = t_0;
} else if (re <= -520000.0) {
tmp = 0.5 * Math.sqrt(((2.0 * im) + (re * (2.0 + (re / im)))));
} else if (re <= -9e-43) {
tmp = t_0;
} else if (re <= 5.3e+57) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((math.pow(im, 2.0) / -re)) tmp = 0 if re <= -2.7e+56: tmp = t_0 elif re <= -520000.0: tmp = 0.5 * math.sqrt(((2.0 * im) + (re * (2.0 + (re / im))))) elif re <= -9e-43: tmp = t_0 elif re <= 5.3e+57: tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64((im ^ 2.0) / Float64(-re)))) tmp = 0.0 if (re <= -2.7e+56) tmp = t_0; elseif (re <= -520000.0) tmp = Float64(0.5 * sqrt(Float64(Float64(2.0 * im) + Float64(re * Float64(2.0 + Float64(re / im)))))); elseif (re <= -9e-43) tmp = t_0; elseif (re <= 5.3e+57) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt(((im ^ 2.0) / -re)); tmp = 0.0; if (re <= -2.7e+56) tmp = t_0; elseif (re <= -520000.0) tmp = 0.5 * sqrt(((2.0 * im) + (re * (2.0 + (re / im))))); elseif (re <= -9e-43) tmp = t_0; elseif (re <= 5.3e+57) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(N[Power[im, 2.0], $MachinePrecision] / (-re)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -2.7e+56], t$95$0, If[LessEqual[re, -520000.0], N[(0.5 * N[Sqrt[N[(N[(2.0 * im), $MachinePrecision] + N[(re * N[(2.0 + N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -9e-43], t$95$0, If[LessEqual[re, 5.3e+57], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{\frac{{im}^{2}}{-re}}\\
\mathbf{if}\;re \leq -2.7 \cdot 10^{+56}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq -520000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im + re \cdot \left(2 + \frac{re}{im}\right)}\\
\mathbf{elif}\;re \leq -9 \cdot 10^{-43}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 5.3 \cdot 10^{+57}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -2.7000000000000001e56 or -5.2e5 < re < -9.0000000000000005e-43Initial program 11.6%
sqr-neg11.6%
+-commutative11.6%
sqr-neg11.6%
+-commutative11.6%
distribute-rgt-in11.6%
cancel-sign-sub11.6%
distribute-rgt-out--11.6%
sub-neg11.6%
remove-double-neg11.6%
+-commutative11.6%
hypot-define29.0%
Simplified29.0%
Taylor expanded in re around -inf 65.6%
mul-1-neg65.6%
distribute-neg-frac265.6%
Simplified65.6%
if -2.7000000000000001e56 < re < -5.2e5Initial program 29.9%
sqr-neg29.9%
+-commutative29.9%
sqr-neg29.9%
+-commutative29.9%
distribute-rgt-in29.9%
cancel-sign-sub29.9%
distribute-rgt-out--29.9%
sub-neg29.9%
remove-double-neg29.9%
+-commutative29.9%
hypot-define61.8%
Simplified61.8%
Taylor expanded in re around 0 33.7%
if -9.0000000000000005e-43 < re < 5.29999999999999986e57Initial program 61.2%
sqr-neg61.2%
+-commutative61.2%
sqr-neg61.2%
+-commutative61.2%
distribute-rgt-in61.2%
cancel-sign-sub61.2%
distribute-rgt-out--61.2%
sub-neg61.2%
remove-double-neg61.2%
+-commutative61.2%
hypot-define91.8%
Simplified91.8%
Taylor expanded in re around 0 37.0%
distribute-lft-out37.0%
*-commutative37.0%
Simplified37.0%
if 5.29999999999999986e57 < re Initial program 30.4%
sqr-neg30.4%
+-commutative30.4%
sqr-neg30.4%
+-commutative30.4%
distribute-rgt-in30.4%
cancel-sign-sub30.4%
distribute-rgt-out--30.4%
sub-neg30.4%
remove-double-neg30.4%
+-commutative30.4%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 81.7%
*-commutative81.7%
unpow281.7%
rem-square-sqrt83.3%
Simplified83.3%
Final simplification52.6%
(FPCore (re im) :precision binary64 (if (<= re -8.8e+216) (* 0.5 (sqrt (* re 0.0))) (if (<= re 2.3e+49) (* 0.5 (sqrt (* 2.0 im))) (* 0.5 (* 2.0 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -8.8e+216) {
tmp = 0.5 * sqrt((re * 0.0));
} else if (re <= 2.3e+49) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = 0.5 * (2.0 * 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 <= (-8.8d+216)) then
tmp = 0.5d0 * sqrt((re * 0.0d0))
else if (re <= 2.3d+49) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -8.8e+216) {
tmp = 0.5 * Math.sqrt((re * 0.0));
} else if (re <= 2.3e+49) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -8.8e+216: tmp = 0.5 * math.sqrt((re * 0.0)) elif re <= 2.3e+49: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -8.8e+216) tmp = Float64(0.5 * sqrt(Float64(re * 0.0))); elseif (re <= 2.3e+49) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -8.8e+216) tmp = 0.5 * sqrt((re * 0.0)); elseif (re <= 2.3e+49) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -8.8e+216], N[(0.5 * N[Sqrt[N[(re * 0.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.3e+49], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -8.8 \cdot 10^{+216}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot 0}\\
\mathbf{elif}\;re \leq 2.3 \cdot 10^{+49}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -8.8e216Initial program 2.4%
sqr-neg2.4%
+-commutative2.4%
sqr-neg2.4%
+-commutative2.4%
distribute-rgt-in2.4%
cancel-sign-sub2.4%
distribute-rgt-out--2.4%
sub-neg2.4%
remove-double-neg2.4%
+-commutative2.4%
hypot-define35.4%
Simplified35.4%
hypot-define2.4%
+-commutative2.4%
distribute-rgt-in2.4%
add-sqr-sqrt2.4%
*-commutative2.4%
fma-define2.4%
*-commutative2.4%
hypot-define2.4%
*-commutative2.4%
hypot-define7.3%
*-commutative7.3%
Applied egg-rr7.3%
Taylor expanded in re around -inf 4.1%
mul-1-neg4.1%
distribute-rgt-neg-in4.1%
unpow24.1%
rem-square-sqrt29.9%
metadata-eval29.9%
metadata-eval29.9%
Simplified29.9%
if -8.8e216 < re < 2.30000000000000002e49Initial program 50.3%
sqr-neg50.3%
+-commutative50.3%
sqr-neg50.3%
+-commutative50.3%
distribute-rgt-in50.3%
cancel-sign-sub50.3%
distribute-rgt-out--50.3%
sub-neg50.3%
remove-double-neg50.3%
+-commutative50.3%
hypot-define76.8%
Simplified76.8%
Taylor expanded in re around 0 30.8%
*-commutative30.8%
Simplified30.8%
if 2.30000000000000002e49 < re Initial program 31.1%
sqr-neg31.1%
+-commutative31.1%
sqr-neg31.1%
+-commutative31.1%
distribute-rgt-in31.1%
cancel-sign-sub31.1%
distribute-rgt-out--31.1%
sub-neg31.1%
remove-double-neg31.1%
+-commutative31.1%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 80.7%
*-commutative80.7%
unpow280.7%
rem-square-sqrt82.3%
Simplified82.3%
Final simplification42.2%
(FPCore (re im) :precision binary64 (if (<= im 2.5e-211) (* 0.5 (sqrt (* re 0.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (im <= 2.5e-211) {
tmp = 0.5 * sqrt((re * 0.0));
} else {
tmp = 0.5 * sqrt((2.0 * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.5d-211) then
tmp = 0.5d0 * sqrt((re * 0.0d0))
else
tmp = 0.5d0 * sqrt((2.0d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.5e-211) {
tmp = 0.5 * Math.sqrt((re * 0.0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.5e-211: tmp = 0.5 * math.sqrt((re * 0.0)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 2.5e-211) tmp = Float64(0.5 * sqrt(Float64(re * 0.0))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.5e-211) tmp = 0.5 * sqrt((re * 0.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.5e-211], N[(0.5 * N[Sqrt[N[(re * 0.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.5 \cdot 10^{-211}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot 0}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if im < 2.5000000000000001e-211Initial program 41.7%
sqr-neg41.7%
+-commutative41.7%
sqr-neg41.7%
+-commutative41.7%
distribute-rgt-in41.7%
cancel-sign-sub41.7%
distribute-rgt-out--41.7%
sub-neg41.7%
remove-double-neg41.7%
+-commutative41.7%
hypot-define77.7%
Simplified77.7%
hypot-define41.7%
+-commutative41.7%
distribute-rgt-in41.7%
add-sqr-sqrt41.0%
*-commutative41.0%
fma-define39.3%
*-commutative39.3%
hypot-define39.4%
*-commutative39.4%
hypot-define71.9%
*-commutative71.9%
Applied egg-rr71.9%
Taylor expanded in re around -inf 3.0%
mul-1-neg3.0%
distribute-rgt-neg-in3.0%
unpow23.0%
rem-square-sqrt8.5%
metadata-eval8.5%
metadata-eval8.5%
Simplified8.5%
if 2.5000000000000001e-211 < im Initial program 43.8%
sqr-neg43.8%
+-commutative43.8%
sqr-neg43.8%
+-commutative43.8%
distribute-rgt-in43.8%
cancel-sign-sub43.8%
distribute-rgt-out--43.8%
sub-neg43.8%
remove-double-neg43.8%
+-commutative43.8%
hypot-define80.8%
Simplified80.8%
Taylor expanded in re around 0 54.8%
*-commutative54.8%
Simplified54.8%
Final simplification28.4%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 im))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * im))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * im));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * im))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * im))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * im)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot im}
\end{array}
Initial program 42.6%
sqr-neg42.6%
+-commutative42.6%
sqr-neg42.6%
+-commutative42.6%
distribute-rgt-in42.6%
cancel-sign-sub42.6%
distribute-rgt-out--42.6%
sub-neg42.6%
remove-double-neg42.6%
+-commutative42.6%
hypot-define79.0%
Simplified79.0%
Taylor expanded in re around 0 24.3%
*-commutative24.3%
Simplified24.3%
Final simplification24.3%
(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 2024087
(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)))))