
(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 5 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 (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 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 10.4%
sqr-neg10.4%
+-commutative10.4%
sqr-neg10.4%
+-commutative10.4%
distribute-rgt-in10.4%
cancel-sign-sub10.4%
distribute-rgt-out--10.4%
sub-neg10.4%
remove-double-neg10.4%
+-commutative10.4%
hypot-define10.4%
Simplified10.4%
Taylor expanded in re around -inf 51.3%
mul-1-neg51.3%
distribute-neg-frac251.3%
Simplified51.3%
if 0.0 < (sqrt.f64 (*.f64 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 48.4%
sqr-neg48.4%
+-commutative48.4%
sqr-neg48.4%
+-commutative48.4%
distribute-rgt-in48.4%
cancel-sign-sub48.4%
distribute-rgt-out--48.4%
sub-neg48.4%
remove-double-neg48.4%
+-commutative48.4%
hypot-define89.2%
Simplified89.2%
Final simplification84.9%
(FPCore (re im)
:precision binary64
(if (<= re -6.2e+117)
(* 0.5 (sqrt (/ (pow im 2.0) (- re))))
(if (<= re 86000000.0)
(* 0.5 (sqrt (* 2.0 im)))
(* 0.5 (* 2.0 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -6.2e+117) {
tmp = 0.5 * sqrt((pow(im, 2.0) / -re));
} else if (re <= 86000000.0) {
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 <= (-6.2d+117)) then
tmp = 0.5d0 * sqrt(((im ** 2.0d0) / -re))
else if (re <= 86000000.0d0) 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 <= -6.2e+117) {
tmp = 0.5 * Math.sqrt((Math.pow(im, 2.0) / -re));
} else if (re <= 86000000.0) {
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 <= -6.2e+117: tmp = 0.5 * math.sqrt((math.pow(im, 2.0) / -re)) elif re <= 86000000.0: 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 <= -6.2e+117) tmp = Float64(0.5 * sqrt(Float64((im ^ 2.0) / Float64(-re)))); elseif (re <= 86000000.0) 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 <= -6.2e+117) tmp = 0.5 * sqrt(((im ^ 2.0) / -re)); elseif (re <= 86000000.0) 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, -6.2e+117], N[(0.5 * N[Sqrt[N[(N[Power[im, 2.0], $MachinePrecision] / (-re)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 86000000.0], 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 -6.2 \cdot 10^{+117}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{{im}^{2}}{-re}}\\
\mathbf{elif}\;re \leq 86000000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -6.1999999999999995e117Initial program 5.5%
sqr-neg5.5%
+-commutative5.5%
sqr-neg5.5%
+-commutative5.5%
distribute-rgt-in5.5%
cancel-sign-sub5.5%
distribute-rgt-out--5.5%
sub-neg5.5%
remove-double-neg5.5%
+-commutative5.5%
hypot-define36.4%
Simplified36.4%
Taylor expanded in re around -inf 55.7%
mul-1-neg55.7%
distribute-neg-frac255.7%
Simplified55.7%
if -6.1999999999999995e117 < re < 8.6e7Initial program 54.2%
sqr-neg54.2%
+-commutative54.2%
sqr-neg54.2%
+-commutative54.2%
distribute-rgt-in54.2%
cancel-sign-sub54.2%
distribute-rgt-out--54.2%
sub-neg54.2%
remove-double-neg54.2%
+-commutative54.2%
hypot-define84.2%
Simplified84.2%
Taylor expanded in re around 0 36.4%
*-commutative36.4%
Simplified36.4%
if 8.6e7 < re Initial program 42.9%
sqr-neg42.9%
+-commutative42.9%
sqr-neg42.9%
+-commutative42.9%
distribute-rgt-in42.9%
cancel-sign-sub42.9%
distribute-rgt-out--42.9%
sub-neg42.9%
remove-double-neg42.9%
+-commutative42.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 74.3%
*-commutative74.3%
unpow274.3%
rem-square-sqrt75.8%
Simplified75.8%
Final simplification48.2%
(FPCore (re im)
:precision binary64
(if (<= re -1.8e-97)
(* 0.5 (+ 1.0 (+ (sqrt (* 2.0 im)) -1.0)))
(if (<= re 2000000000.0)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(* 0.5 (* 2.0 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e-97) {
tmp = 0.5 * (1.0 + (sqrt((2.0 * im)) + -1.0));
} else if (re <= 2000000000.0) {
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) :: tmp
if (re <= (-1.8d-97)) then
tmp = 0.5d0 * (1.0d0 + (sqrt((2.0d0 * im)) + (-1.0d0)))
else if (re <= 2000000000.0d0) 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 tmp;
if (re <= -1.8e-97) {
tmp = 0.5 * (1.0 + (Math.sqrt((2.0 * im)) + -1.0));
} else if (re <= 2000000000.0) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e-97: tmp = 0.5 * (1.0 + (math.sqrt((2.0 * im)) + -1.0)) elif re <= 2000000000.0: tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e-97) tmp = Float64(0.5 * Float64(1.0 + Float64(sqrt(Float64(2.0 * im)) + -1.0))); elseif (re <= 2000000000.0) 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) tmp = 0.0; if (re <= -1.8e-97) tmp = 0.5 * (1.0 + (sqrt((2.0 * im)) + -1.0)); elseif (re <= 2000000000.0) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e-97], N[(0.5 * N[(1.0 + N[(N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2000000000.0], 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}
\mathbf{if}\;re \leq -1.8 \cdot 10^{-97}:\\
\;\;\;\;0.5 \cdot \left(1 + \left(\sqrt{2 \cdot im} + -1\right)\right)\\
\mathbf{elif}\;re \leq 2000000000:\\
\;\;\;\;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 < -1.79999999999999999e-97Initial program 19.9%
sqr-neg19.9%
+-commutative19.9%
sqr-neg19.9%
+-commutative19.9%
distribute-rgt-in19.9%
cancel-sign-sub19.9%
distribute-rgt-out--19.9%
sub-neg19.9%
remove-double-neg19.9%
+-commutative19.9%
hypot-define49.2%
Simplified49.2%
Taylor expanded in re around 0 22.5%
add-exp-log21.0%
sqrt-unprod21.0%
Applied egg-rr21.0%
*-un-lft-identity21.0%
metadata-eval21.0%
*-commutative21.0%
log1p-expm1-u26.0%
log1p-undefine26.0%
exp-to-pow26.0%
metadata-eval26.0%
metadata-eval26.0%
pow126.0%
metadata-eval26.0%
expm1-undefine26.0%
rem-exp-log27.6%
Applied egg-rr27.6%
if -1.79999999999999999e-97 < re < 2e9Initial program 63.9%
sqr-neg63.9%
+-commutative63.9%
sqr-neg63.9%
+-commutative63.9%
distribute-rgt-in63.9%
cancel-sign-sub63.9%
distribute-rgt-out--63.9%
sub-neg63.9%
remove-double-neg63.9%
+-commutative63.9%
hypot-define94.8%
Simplified94.8%
Taylor expanded in re around 0 39.7%
distribute-lft-out39.7%
*-commutative39.7%
Simplified39.7%
if 2e9 < re Initial program 42.9%
sqr-neg42.9%
+-commutative42.9%
sqr-neg42.9%
+-commutative42.9%
distribute-rgt-in42.9%
cancel-sign-sub42.9%
distribute-rgt-out--42.9%
sub-neg42.9%
remove-double-neg42.9%
+-commutative42.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 74.3%
*-commutative74.3%
unpow274.3%
rem-square-sqrt75.8%
Simplified75.8%
Final simplification43.6%
(FPCore (re im) :precision binary64 (if (<= re 1850000000.0) (* 0.5 (sqrt (* 2.0 im))) (* 0.5 (* 2.0 (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= 1850000000.0) {
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 <= 1850000000.0d0) 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 <= 1850000000.0) {
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 <= 1850000000.0: 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 <= 1850000000.0) 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 <= 1850000000.0) 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, 1850000000.0], 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 1850000000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < 1.85e9Initial program 44.4%
sqr-neg44.4%
+-commutative44.4%
sqr-neg44.4%
+-commutative44.4%
distribute-rgt-in44.4%
cancel-sign-sub44.4%
distribute-rgt-out--44.4%
sub-neg44.4%
remove-double-neg44.4%
+-commutative44.4%
hypot-define74.6%
Simplified74.6%
Taylor expanded in re around 0 31.2%
*-commutative31.2%
Simplified31.2%
if 1.85e9 < re Initial program 42.9%
sqr-neg42.9%
+-commutative42.9%
sqr-neg42.9%
+-commutative42.9%
distribute-rgt-in42.9%
cancel-sign-sub42.9%
distribute-rgt-out--42.9%
sub-neg42.9%
remove-double-neg42.9%
+-commutative42.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 74.3%
*-commutative74.3%
unpow274.3%
rem-square-sqrt75.8%
Simplified75.8%
Final simplification41.1%
(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 44.1%
sqr-neg44.1%
+-commutative44.1%
sqr-neg44.1%
+-commutative44.1%
distribute-rgt-in44.1%
cancel-sign-sub44.1%
distribute-rgt-out--44.1%
sub-neg44.1%
remove-double-neg44.1%
+-commutative44.1%
hypot-define80.3%
Simplified80.3%
Taylor expanded in re around 0 28.7%
*-commutative28.7%
Simplified28.7%
Final simplification28.7%
(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 2024055
(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)))))