
(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 (<= re -1.05e+94)
(*
0.5
(*
(pow (exp (* 0.25 (+ (log (* 0.5 (pow im 2.0))) (log (/ -1.0 re))))) 2.0)
(sqrt 2.0)))
(* 0.5 (sqrt (* 2.0 (+ re (hypot re im)))))))
double code(double re, double im) {
double tmp;
if (re <= -1.05e+94) {
tmp = 0.5 * (pow(exp((0.25 * (log((0.5 * pow(im, 2.0))) + log((-1.0 / re))))), 2.0) * sqrt(2.0));
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -1.05e+94) {
tmp = 0.5 * (Math.pow(Math.exp((0.25 * (Math.log((0.5 * Math.pow(im, 2.0))) + Math.log((-1.0 / re))))), 2.0) * Math.sqrt(2.0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.05e+94: tmp = 0.5 * (math.pow(math.exp((0.25 * (math.log((0.5 * math.pow(im, 2.0))) + math.log((-1.0 / re))))), 2.0) * math.sqrt(2.0)) else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.05e+94) tmp = Float64(0.5 * Float64((exp(Float64(0.25 * Float64(log(Float64(0.5 * (im ^ 2.0))) + log(Float64(-1.0 / re))))) ^ 2.0) * sqrt(2.0))); 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 (re <= -1.05e+94) tmp = 0.5 * ((exp((0.25 * (log((0.5 * (im ^ 2.0))) + log((-1.0 / re))))) ^ 2.0) * sqrt(2.0)); else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.05e+94], N[(0.5 * N[(N[Power[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], 2.0], $MachinePrecision] * N[Sqrt[2.0], $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}\;re \leq -1.05 \cdot 10^{+94}:\\
\;\;\;\;0.5 \cdot \left({\left(e^{0.25 \cdot \left(\log \left(0.5 \cdot {im}^{2}\right) + \log \left(\frac{-1}{re}\right)\right)}\right)}^{2} \cdot \sqrt{2}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if re < -1.04999999999999995e94Initial program 7.0%
sqr-neg7.0%
+-commutative7.0%
sqr-neg7.0%
+-commutative7.0%
distribute-rgt-in7.0%
cancel-sign-sub7.0%
distribute-rgt-out--7.0%
sub-neg7.0%
remove-double-neg7.0%
+-commutative7.0%
hypot-define34.0%
Simplified34.0%
sqrt-prod36.1%
hypot-define7.0%
+-commutative7.0%
*-commutative7.0%
+-commutative7.0%
hypot-define36.1%
Applied egg-rr36.1%
add-sqr-sqrt36.1%
pow236.1%
pow1/236.1%
sqrt-pow136.1%
metadata-eval36.1%
Applied egg-rr36.1%
Taylor expanded in re around -inf 60.0%
if -1.04999999999999995e94 < re Initial program 50.2%
sqr-neg50.2%
+-commutative50.2%
sqr-neg50.2%
+-commutative50.2%
distribute-rgt-in50.2%
cancel-sign-sub50.2%
distribute-rgt-out--50.2%
sub-neg50.2%
remove-double-neg50.2%
+-commutative50.2%
hypot-define89.2%
Simplified89.2%
(FPCore (re im) :precision binary64 (if (<= re -4.3e+98) (* 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 (re <= -4.3e+98) {
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 (re <= -4.3e+98) {
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 re <= -4.3e+98: 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 (re <= -4.3e+98) 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 (re <= -4.3e+98) 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[re, -4.3e+98], 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}\;re \leq -4.3 \cdot 10^{+98}:\\
\;\;\;\;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 re < -4.3000000000000001e98Initial program 7.0%
sqr-neg7.0%
+-commutative7.0%
sqr-neg7.0%
+-commutative7.0%
distribute-rgt-in7.0%
cancel-sign-sub7.0%
distribute-rgt-out--7.0%
sub-neg7.0%
remove-double-neg7.0%
+-commutative7.0%
hypot-define34.7%
Simplified34.7%
Taylor expanded in re around -inf 55.0%
mul-1-neg55.0%
distribute-neg-frac255.0%
Simplified55.0%
if -4.3000000000000001e98 < re Initial program 49.9%
sqr-neg49.9%
+-commutative49.9%
sqr-neg49.9%
+-commutative49.9%
distribute-rgt-in49.9%
cancel-sign-sub49.9%
distribute-rgt-out--49.9%
sub-neg49.9%
remove-double-neg49.9%
+-commutative49.9%
hypot-define88.8%
Simplified88.8%
(FPCore (re im)
:precision binary64
(if (<= re -3.3e+93)
(* 0.5 (sqrt (/ (pow im 2.0) (- re))))
(if (<= re 5.4e+68)
(sqrt (* 0.5 (+ im (* re (+ 1.0 (* 0.5 (/ re im)))))))
(* 0.5 (* 2.0 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -3.3e+93) {
tmp = 0.5 * sqrt((pow(im, 2.0) / -re));
} else if (re <= 5.4e+68) {
tmp = sqrt((0.5 * (im + (re * (1.0 + (0.5 * (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) :: tmp
if (re <= (-3.3d+93)) then
tmp = 0.5d0 * sqrt(((im ** 2.0d0) / -re))
else if (re <= 5.4d+68) then
tmp = sqrt((0.5d0 * (im + (re * (1.0d0 + (0.5d0 * (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 tmp;
if (re <= -3.3e+93) {
tmp = 0.5 * Math.sqrt((Math.pow(im, 2.0) / -re));
} else if (re <= 5.4e+68) {
tmp = Math.sqrt((0.5 * (im + (re * (1.0 + (0.5 * (re / im)))))));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.3e+93: tmp = 0.5 * math.sqrt((math.pow(im, 2.0) / -re)) elif re <= 5.4e+68: tmp = math.sqrt((0.5 * (im + (re * (1.0 + (0.5 * (re / im))))))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.3e+93) tmp = Float64(0.5 * sqrt(Float64((im ^ 2.0) / Float64(-re)))); elseif (re <= 5.4e+68) tmp = sqrt(Float64(0.5 * Float64(im + Float64(re * Float64(1.0 + Float64(0.5 * Float64(re / 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 <= -3.3e+93) tmp = 0.5 * sqrt(((im ^ 2.0) / -re)); elseif (re <= 5.4e+68) tmp = sqrt((0.5 * (im + (re * (1.0 + (0.5 * (re / im))))))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.3e+93], N[(0.5 * N[Sqrt[N[(N[Power[im, 2.0], $MachinePrecision] / (-re)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.4e+68], N[Sqrt[N[(0.5 * N[(im + N[(re * N[(1.0 + N[(0.5 * N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -3.3 \cdot 10^{+93}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{{im}^{2}}{-re}}\\
\mathbf{elif}\;re \leq 5.4 \cdot 10^{+68}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im + re \cdot \left(1 + 0.5 \cdot \frac{re}{im}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -3.30000000000000009e93Initial program 7.0%
sqr-neg7.0%
+-commutative7.0%
sqr-neg7.0%
+-commutative7.0%
distribute-rgt-in7.0%
cancel-sign-sub7.0%
distribute-rgt-out--7.0%
sub-neg7.0%
remove-double-neg7.0%
+-commutative7.0%
hypot-define34.0%
Simplified34.0%
Taylor expanded in re around -inf 53.9%
mul-1-neg53.9%
distribute-neg-frac253.9%
Simplified53.9%
if -3.30000000000000009e93 < re < 5.39999999999999982e68Initial program 53.1%
sqr-neg53.1%
+-commutative53.1%
sqr-neg53.1%
+-commutative53.1%
distribute-rgt-in53.1%
cancel-sign-sub53.1%
distribute-rgt-out--53.1%
sub-neg53.1%
remove-double-neg53.1%
+-commutative53.1%
hypot-define85.5%
Simplified85.5%
sqrt-prod84.9%
hypot-define52.8%
+-commutative52.8%
*-commutative52.8%
+-commutative52.8%
hypot-define84.9%
Applied egg-rr84.9%
Taylor expanded in re around 0 41.2%
add-sqr-sqrt41.1%
sqrt-unprod41.2%
swap-sqr41.2%
metadata-eval41.2%
sqrt-unprod41.4%
sqrt-unprod41.5%
add-sqr-sqrt41.5%
*-commutative41.5%
+-commutative41.5%
fma-define41.5%
+-commutative41.5%
fma-define41.5%
Applied egg-rr41.5%
associate-*r*41.5%
metadata-eval41.5%
Simplified41.5%
Taylor expanded in re around 0 41.5%
if 5.39999999999999982e68 < re Initial program 41.5%
sqr-neg41.5%
+-commutative41.5%
sqr-neg41.5%
+-commutative41.5%
distribute-rgt-in41.5%
cancel-sign-sub41.5%
distribute-rgt-out--41.5%
sub-neg41.5%
remove-double-neg41.5%
+-commutative41.5%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 84.3%
*-commutative84.3%
unpow284.3%
rem-square-sqrt85.8%
Simplified85.8%
(FPCore (re im) :precision binary64 (if (<= re 1.7e+69) (sqrt (* 0.5 (+ im (* re (+ 1.0 (* 0.5 (/ re im))))))) (* 0.5 (* 2.0 (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= 1.7e+69) {
tmp = sqrt((0.5 * (im + (re * (1.0 + (0.5 * (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) :: tmp
if (re <= 1.7d+69) then
tmp = sqrt((0.5d0 * (im + (re * (1.0d0 + (0.5d0 * (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 tmp;
if (re <= 1.7e+69) {
tmp = Math.sqrt((0.5 * (im + (re * (1.0 + (0.5 * (re / im)))))));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.7e+69: tmp = math.sqrt((0.5 * (im + (re * (1.0 + (0.5 * (re / im))))))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.7e+69) tmp = sqrt(Float64(0.5 * Float64(im + Float64(re * Float64(1.0 + Float64(0.5 * Float64(re / 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 <= 1.7e+69) tmp = sqrt((0.5 * (im + (re * (1.0 + (0.5 * (re / im))))))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.7e+69], N[Sqrt[N[(0.5 * N[(im + N[(re * N[(1.0 + N[(0.5 * N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 1.7 \cdot 10^{+69}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im + re \cdot \left(1 + 0.5 \cdot \frac{re}{im}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < 1.69999999999999993e69Initial program 43.1%
sqr-neg43.1%
+-commutative43.1%
sqr-neg43.1%
+-commutative43.1%
distribute-rgt-in43.1%
cancel-sign-sub43.1%
distribute-rgt-out--43.1%
sub-neg43.1%
remove-double-neg43.1%
+-commutative43.1%
hypot-define74.3%
Simplified74.3%
sqrt-prod74.3%
hypot-define42.8%
+-commutative42.8%
*-commutative42.8%
+-commutative42.8%
hypot-define74.3%
Applied egg-rr74.3%
Taylor expanded in re around 0 34.2%
add-sqr-sqrt34.1%
sqrt-unprod34.2%
swap-sqr33.8%
metadata-eval33.8%
sqrt-unprod33.9%
sqrt-unprod34.0%
add-sqr-sqrt34.0%
*-commutative34.0%
+-commutative34.0%
fma-define34.0%
+-commutative34.0%
fma-define34.0%
Applied egg-rr34.0%
associate-*r*34.5%
metadata-eval34.5%
Simplified34.5%
Taylor expanded in re around 0 34.5%
if 1.69999999999999993e69 < re Initial program 41.5%
sqr-neg41.5%
+-commutative41.5%
sqr-neg41.5%
+-commutative41.5%
distribute-rgt-in41.5%
cancel-sign-sub41.5%
distribute-rgt-out--41.5%
sub-neg41.5%
remove-double-neg41.5%
+-commutative41.5%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 84.3%
*-commutative84.3%
unpow284.3%
rem-square-sqrt85.8%
Simplified85.8%
(FPCore (re im) :precision binary64 (if (<= re 1.65e+84) (sqrt (* 0.5 (+ re im))) (* 0.5 (* 2.0 (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= 1.65e+84) {
tmp = sqrt((0.5 * (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) :: tmp
if (re <= 1.65d+84) then
tmp = sqrt((0.5d0 * (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 tmp;
if (re <= 1.65e+84) {
tmp = Math.sqrt((0.5 * (re + im)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.65e+84: tmp = math.sqrt((0.5 * (re + im))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.65e+84) tmp = sqrt(Float64(0.5 * Float64(re + 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 <= 1.65e+84) tmp = sqrt((0.5 * (re + im))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.65e+84], N[Sqrt[N[(0.5 * N[(re + 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 1.65 \cdot 10^{+84}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + im\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < 1.65000000000000008e84Initial program 44.2%
sqr-neg44.2%
+-commutative44.2%
sqr-neg44.2%
+-commutative44.2%
distribute-rgt-in44.2%
cancel-sign-sub44.2%
distribute-rgt-out--44.2%
sub-neg44.2%
remove-double-neg44.2%
+-commutative44.2%
hypot-define75.0%
Simplified75.0%
sqrt-prod75.0%
hypot-define44.0%
+-commutative44.0%
*-commutative44.0%
+-commutative44.0%
hypot-define75.0%
Applied egg-rr75.0%
Taylor expanded in re around 0 34.2%
add-sqr-sqrt34.1%
sqrt-unprod34.2%
swap-sqr33.8%
metadata-eval33.8%
sqrt-unprod33.9%
sqrt-unprod34.0%
add-sqr-sqrt34.0%
*-commutative34.0%
+-commutative34.0%
fma-define34.0%
+-commutative34.0%
fma-define34.0%
Applied egg-rr34.0%
associate-*r*34.5%
metadata-eval34.5%
Simplified34.5%
Taylor expanded in re around 0 34.9%
if 1.65000000000000008e84 < re Initial program 36.2%
sqr-neg36.2%
+-commutative36.2%
sqr-neg36.2%
+-commutative36.2%
distribute-rgt-in36.2%
cancel-sign-sub36.2%
distribute-rgt-out--36.2%
sub-neg36.2%
remove-double-neg36.2%
+-commutative36.2%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 88.2%
*-commutative88.2%
unpow288.2%
rem-square-sqrt89.7%
Simplified89.7%
Final simplification45.2%
(FPCore (re im) :precision binary64 (sqrt (* 0.5 (+ re im))))
double code(double re, double im) {
return sqrt((0.5 * (re + im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((0.5d0 * (re + im)))
end function
public static double code(double re, double im) {
return Math.sqrt((0.5 * (re + im)));
}
def code(re, im): return math.sqrt((0.5 * (re + im)))
function code(re, im) return sqrt(Float64(0.5 * Float64(re + im))) end
function tmp = code(re, im) tmp = sqrt((0.5 * (re + im))); end
code[re_, im_] := N[Sqrt[N[(0.5 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(re + im\right)}
\end{array}
Initial program 42.7%
sqr-neg42.7%
+-commutative42.7%
sqr-neg42.7%
+-commutative42.7%
distribute-rgt-in42.7%
cancel-sign-sub42.7%
distribute-rgt-out--42.7%
sub-neg42.7%
remove-double-neg42.7%
+-commutative42.7%
hypot-define79.7%
Simplified79.7%
sqrt-prod79.6%
hypot-define42.5%
+-commutative42.5%
*-commutative42.5%
+-commutative42.5%
hypot-define79.6%
Applied egg-rr79.6%
Taylor expanded in re around 0 29.1%
add-sqr-sqrt29.0%
sqrt-unprod29.1%
swap-sqr28.7%
metadata-eval28.7%
sqrt-unprod28.9%
sqrt-unprod29.0%
add-sqr-sqrt29.0%
*-commutative29.0%
+-commutative29.0%
fma-define29.0%
+-commutative29.0%
fma-define29.0%
Applied egg-rr29.0%
associate-*r*29.3%
metadata-eval29.3%
Simplified29.3%
Taylor expanded in re around 0 32.6%
Final simplification32.6%
(FPCore (re im) :precision binary64 (sqrt (* 0.5 im)))
double code(double re, double im) {
return sqrt((0.5 * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((0.5d0 * im))
end function
public static double code(double re, double im) {
return Math.sqrt((0.5 * im));
}
def code(re, im): return math.sqrt((0.5 * im))
function code(re, im) return sqrt(Float64(0.5 * im)) end
function tmp = code(re, im) tmp = sqrt((0.5 * im)); end
code[re_, im_] := N[Sqrt[N[(0.5 * im), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot im}
\end{array}
Initial program 42.7%
sqr-neg42.7%
+-commutative42.7%
sqr-neg42.7%
+-commutative42.7%
distribute-rgt-in42.7%
cancel-sign-sub42.7%
distribute-rgt-out--42.7%
sub-neg42.7%
remove-double-neg42.7%
+-commutative42.7%
hypot-define79.7%
Simplified79.7%
sqrt-prod79.6%
hypot-define42.5%
+-commutative42.5%
*-commutative42.5%
+-commutative42.5%
hypot-define79.6%
Applied egg-rr79.6%
Taylor expanded in re around 0 29.1%
add-sqr-sqrt29.0%
sqrt-unprod29.1%
swap-sqr28.7%
metadata-eval28.7%
sqrt-unprod28.9%
sqrt-unprod29.0%
add-sqr-sqrt29.0%
*-commutative29.0%
+-commutative29.0%
fma-define29.0%
+-commutative29.0%
fma-define29.0%
Applied egg-rr29.0%
associate-*r*29.3%
metadata-eval29.3%
Simplified29.3%
Taylor expanded in re around 0 29.2%
(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 2024118
(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)))))