
(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 9 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}
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (pow (* (sqrt im) (pow (/ -1.0 re) 0.25)) 2.0))))
(if (<= re -1.45e+63)
t_0
(if (<= re -1e+37)
(* 0.5 (sqrt (* im 2.0)))
(if (<= re -3.5e-93)
t_0
(* 0.5 (sqrt (* 2.0 (+ re (hypot re im))))))))))im = abs(im);
double code(double re, double im) {
double t_0 = 0.5 * pow((sqrt(im) * pow((-1.0 / re), 0.25)), 2.0);
double tmp;
if (re <= -1.45e+63) {
tmp = t_0;
} else if (re <= -1e+37) {
tmp = 0.5 * sqrt((im * 2.0));
} else if (re <= -3.5e-93) {
tmp = t_0;
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im))));
}
return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
double t_0 = 0.5 * Math.pow((Math.sqrt(im) * Math.pow((-1.0 / re), 0.25)), 2.0);
double tmp;
if (re <= -1.45e+63) {
tmp = t_0;
} else if (re <= -1e+37) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else if (re <= -3.5e-93) {
tmp = t_0;
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im))));
}
return tmp;
}
im = abs(im) def code(re, im): t_0 = 0.5 * math.pow((math.sqrt(im) * math.pow((-1.0 / re), 0.25)), 2.0) tmp = 0 if re <= -1.45e+63: tmp = t_0 elif re <= -1e+37: tmp = 0.5 * math.sqrt((im * 2.0)) elif re <= -3.5e-93: tmp = t_0 else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im)))) return tmp
im = abs(im) function code(re, im) t_0 = Float64(0.5 * (Float64(sqrt(im) * (Float64(-1.0 / re) ^ 0.25)) ^ 2.0)) tmp = 0.0 if (re <= -1.45e+63) tmp = t_0; elseif (re <= -1e+37) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); elseif (re <= -3.5e-93) tmp = t_0; else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im))))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) t_0 = 0.5 * ((sqrt(im) * ((-1.0 / re) ^ 0.25)) ^ 2.0); tmp = 0.0; if (re <= -1.45e+63) tmp = t_0; elseif (re <= -1e+37) tmp = 0.5 * sqrt((im * 2.0)); elseif (re <= -3.5e-93) tmp = t_0; else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im)))); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Power[N[(N[Sqrt[im], $MachinePrecision] * N[Power[N[(-1.0 / re), $MachinePrecision], 0.25], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.45e+63], t$95$0, If[LessEqual[re, -1e+37], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -3.5e-93], t$95$0, N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
t_0 := 0.5 \cdot {\left(\sqrt{im} \cdot {\left(\frac{-1}{re}\right)}^{0.25}\right)}^{2}\\
\mathbf{if}\;re \leq -1.45 \cdot 10^{+63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -1 \cdot 10^{+37}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{elif}\;re \leq -3.5 \cdot 10^{-93}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if re < -1.45e63 or -9.99999999999999954e36 < re < -3.5e-93Initial program 16.3%
sqr-neg16.3%
+-commutative16.3%
sqr-neg16.3%
distribute-rgt-in16.3%
cancel-sign-sub16.3%
distribute-rgt-out--16.3%
sub-neg16.3%
remove-double-neg16.3%
hypot-def35.0%
Simplified35.0%
add-sqr-sqrt34.8%
pow234.8%
pow1/234.8%
sqrt-pow134.9%
*-commutative34.9%
metadata-eval34.9%
Applied egg-rr34.9%
Taylor expanded in re around -inf 54.6%
exp-prod53.3%
+-commutative53.3%
log-pow28.9%
fma-def28.9%
Simplified28.9%
Taylor expanded in im around 0 29.9%
distribute-lft-in29.9%
prod-exp30.2%
exp-prod29.4%
exp-prod29.0%
*-commutative29.0%
exp-prod29.4%
*-commutative29.4%
remove-double-neg29.4%
*-commutative29.4%
associate-*l*29.4%
metadata-eval29.4%
remove-double-neg29.4%
exp-to-pow29.5%
unpow1/229.5%
exp-prod30.6%
*-commutative30.6%
exp-to-pow32.4%
Simplified32.4%
if -1.45e63 < re < -9.99999999999999954e36Initial program 17.7%
sqr-neg17.7%
+-commutative17.7%
sqr-neg17.7%
distribute-rgt-in17.7%
cancel-sign-sub17.7%
distribute-rgt-out--17.7%
sub-neg17.7%
remove-double-neg17.7%
hypot-def86.2%
Simplified86.2%
Taylor expanded in re around 0 72.5%
if -3.5e-93 < re Initial program 47.8%
sqr-neg47.8%
+-commutative47.8%
sqr-neg47.8%
distribute-rgt-in47.8%
cancel-sign-sub47.8%
distribute-rgt-out--47.8%
sub-neg47.8%
remove-double-neg47.8%
hypot-def94.9%
Simplified94.9%
Final simplification74.5%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (<= re -3.2e+68) (* 0.5 (sqrt (* 2.0 (* (/ im (/ re im)) -0.5)))) (* 0.5 (sqrt (* 2.0 (+ re (hypot re im)))))))
im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= -3.2e+68) {
tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im))));
}
return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= -3.2e+68) {
tmp = 0.5 * Math.sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im))));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= -3.2e+68: tmp = 0.5 * math.sqrt((2.0 * ((im / (re / im)) * -0.5))) else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im)))) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= -3.2e+68) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(im / Float64(re / im)) * -0.5)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im))))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.2e+68) tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5))); else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im)))); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, -3.2e+68], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[(im / N[(re / im), $MachinePrecision]), $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}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.2 \cdot 10^{+68}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \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 re < -3.19999999999999994e68Initial program 7.7%
sqr-neg7.7%
+-commutative7.7%
sqr-neg7.7%
distribute-rgt-in7.7%
cancel-sign-sub7.7%
distribute-rgt-out--7.7%
sub-neg7.7%
remove-double-neg7.7%
hypot-def30.9%
Simplified30.9%
Taylor expanded in re around -inf 56.6%
*-commutative56.6%
unpow256.6%
associate-/l*63.9%
Simplified63.9%
if -3.19999999999999994e68 < re Initial program 44.7%
sqr-neg44.7%
+-commutative44.7%
sqr-neg44.7%
distribute-rgt-in44.7%
cancel-sign-sub44.7%
distribute-rgt-out--44.7%
sub-neg44.7%
remove-double-neg44.7%
hypot-def87.4%
Simplified87.4%
Final simplification82.5%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* 2.0 (+ re im))))))
(if (<= re -1.5e+62)
(* 0.5 (sqrt (* 2.0 (* (/ im (/ re im)) -0.5))))
(if (<= re 6.5e-20)
t_0
(if (<= re 6.2e+69)
(* 0.5 (sqrt (* 2.0 (+ re (+ re (/ (* 0.5 (* im im)) re))))))
(if (<= re 2.12e+120) t_0 (* 0.5 (* 2.0 (sqrt re)))))))))im = abs(im);
double code(double re, double im) {
double t_0 = 0.5 * sqrt((2.0 * (re + im)));
double tmp;
if (re <= -1.5e+62) {
tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else if (re <= 6.5e-20) {
tmp = t_0;
} else if (re <= 6.2e+69) {
tmp = 0.5 * sqrt((2.0 * (re + (re + ((0.5 * (im * im)) / re)))));
} else if (re <= 2.12e+120) {
tmp = t_0;
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
NOTE: im should be positive before calling this function
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((2.0d0 * (re + im)))
if (re <= (-1.5d+62)) then
tmp = 0.5d0 * sqrt((2.0d0 * ((im / (re / im)) * (-0.5d0))))
else if (re <= 6.5d-20) then
tmp = t_0
else if (re <= 6.2d+69) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + (re + ((0.5d0 * (im * im)) / re)))))
else if (re <= 2.12d+120) then
tmp = t_0
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((2.0 * (re + im)));
double tmp;
if (re <= -1.5e+62) {
tmp = 0.5 * Math.sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else if (re <= 6.5e-20) {
tmp = t_0;
} else if (re <= 6.2e+69) {
tmp = 0.5 * Math.sqrt((2.0 * (re + (re + ((0.5 * (im * im)) / re)))));
} else if (re <= 2.12e+120) {
tmp = t_0;
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
im = abs(im) def code(re, im): t_0 = 0.5 * math.sqrt((2.0 * (re + im))) tmp = 0 if re <= -1.5e+62: tmp = 0.5 * math.sqrt((2.0 * ((im / (re / im)) * -0.5))) elif re <= 6.5e-20: tmp = t_0 elif re <= 6.2e+69: tmp = 0.5 * math.sqrt((2.0 * (re + (re + ((0.5 * (im * im)) / re))))) elif re <= 2.12e+120: tmp = t_0 else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
im = abs(im) function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))) tmp = 0.0 if (re <= -1.5e+62) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(im / Float64(re / im)) * -0.5)))); elseif (re <= 6.5e-20) tmp = t_0; elseif (re <= 6.2e+69) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + Float64(re + Float64(Float64(0.5 * Float64(im * im)) / re)))))); elseif (re <= 2.12e+120) tmp = t_0; else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((2.0 * (re + im))); tmp = 0.0; if (re <= -1.5e+62) tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5))); elseif (re <= 6.5e-20) tmp = t_0; elseif (re <= 6.2e+69) tmp = 0.5 * sqrt((2.0 * (re + (re + ((0.5 * (im * im)) / re))))); elseif (re <= 2.12e+120) tmp = t_0; else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.5e+62], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.5e-20], t$95$0, If[LessEqual[re, 6.2e+69], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[(re + N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.12e+120], t$95$0, N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{if}\;re \leq -1.5 \cdot 10^{+62}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \cdot -0.5\right)}\\
\mathbf{elif}\;re \leq 6.5 \cdot 10^{-20}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 6.2 \cdot 10^{+69}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \left(re + \frac{0.5 \cdot \left(im \cdot im\right)}{re}\right)\right)}\\
\mathbf{elif}\;re \leq 2.12 \cdot 10^{+120}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -1.5e62Initial program 7.7%
sqr-neg7.7%
+-commutative7.7%
sqr-neg7.7%
distribute-rgt-in7.7%
cancel-sign-sub7.7%
distribute-rgt-out--7.7%
sub-neg7.7%
remove-double-neg7.7%
hypot-def30.4%
Simplified30.4%
Taylor expanded in re around -inf 55.7%
*-commutative55.7%
unpow255.7%
associate-/l*62.8%
Simplified62.8%
if -1.5e62 < re < 6.50000000000000032e-20 or 6.1999999999999997e69 < re < 2.11999999999999989e120Initial program 47.3%
sqr-neg47.3%
+-commutative47.3%
sqr-neg47.3%
distribute-rgt-in47.3%
cancel-sign-sub47.3%
distribute-rgt-out--47.3%
sub-neg47.3%
remove-double-neg47.3%
hypot-def84.1%
Simplified84.1%
Taylor expanded in re around 0 36.3%
if 6.50000000000000032e-20 < re < 6.1999999999999997e69Initial program 100.0%
Taylor expanded in re around inf 91.6%
associate-*r/91.6%
unpow291.6%
Simplified91.6%
if 2.11999999999999989e120 < re Initial program 15.2%
sqr-neg15.2%
+-commutative15.2%
sqr-neg15.2%
distribute-rgt-in15.2%
cancel-sign-sub15.2%
distribute-rgt-out--15.2%
sub-neg15.2%
remove-double-neg15.2%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 80.5%
*-commutative80.5%
unpow280.5%
rem-square-sqrt82.0%
Simplified82.0%
Final simplification50.7%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= re -3.8e+160)
(* 0.5 (sqrt (* 2.0 (- re re))))
(if (<= re 2.5e-20)
(* 0.5 (sqrt (* im 2.0)))
(if (or (<= re 4.4e+74) (not (<= re 2.12e+120)))
(* 0.5 (* 2.0 (sqrt re)))
(* 0.5 (sqrt (* 2.0 (+ re im))))))))im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= -3.8e+160) {
tmp = 0.5 * sqrt((2.0 * (re - re)));
} else if (re <= 2.5e-20) {
tmp = 0.5 * sqrt((im * 2.0));
} else if ((re <= 4.4e+74) || !(re <= 2.12e+120)) {
tmp = 0.5 * (2.0 * sqrt(re));
} else {
tmp = 0.5 * sqrt((2.0 * (re + im)));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.8d+160)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re - re)))
else if (re <= 2.5d-20) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else if ((re <= 4.4d+74) .or. (.not. (re <= 2.12d+120))) then
tmp = 0.5d0 * (2.0d0 * sqrt(re))
else
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= -3.8e+160) {
tmp = 0.5 * Math.sqrt((2.0 * (re - re)));
} else if (re <= 2.5e-20) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else if ((re <= 4.4e+74) || !(re <= 2.12e+120)) {
tmp = 0.5 * (2.0 * Math.sqrt(re));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= -3.8e+160: tmp = 0.5 * math.sqrt((2.0 * (re - re))) elif re <= 2.5e-20: tmp = 0.5 * math.sqrt((im * 2.0)) elif (re <= 4.4e+74) or not (re <= 2.12e+120): tmp = 0.5 * (2.0 * math.sqrt(re)) else: tmp = 0.5 * math.sqrt((2.0 * (re + im))) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= -3.8e+160) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - re)))); elseif (re <= 2.5e-20) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); elseif ((re <= 4.4e+74) || !(re <= 2.12e+120)) tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.8e+160) tmp = 0.5 * sqrt((2.0 * (re - re))); elseif (re <= 2.5e-20) tmp = 0.5 * sqrt((im * 2.0)); elseif ((re <= 4.4e+74) || ~((re <= 2.12e+120))) tmp = 0.5 * (2.0 * sqrt(re)); else tmp = 0.5 * sqrt((2.0 * (re + im))); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, -3.8e+160], N[(0.5 * N[Sqrt[N[(2.0 * N[(re - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.5e-20], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 4.4e+74], N[Not[LessEqual[re, 2.12e+120]], $MachinePrecision]], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.8 \cdot 10^{+160}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - re\right)}\\
\mathbf{elif}\;re \leq 2.5 \cdot 10^{-20}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{elif}\;re \leq 4.4 \cdot 10^{+74} \lor \neg \left(re \leq 2.12 \cdot 10^{+120}\right):\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\end{array}
\end{array}
if re < -3.80000000000000012e160Initial program 2.4%
Taylor expanded in re around -inf 26.5%
mul-1-neg26.5%
Simplified26.5%
if -3.80000000000000012e160 < re < 2.4999999999999999e-20Initial program 43.2%
sqr-neg43.2%
+-commutative43.2%
sqr-neg43.2%
distribute-rgt-in43.2%
cancel-sign-sub43.2%
distribute-rgt-out--43.2%
sub-neg43.2%
remove-double-neg43.2%
hypot-def77.6%
Simplified77.6%
Taylor expanded in re around 0 32.0%
if 2.4999999999999999e-20 < re < 4.4000000000000002e74 or 2.11999999999999989e120 < re Initial program 36.8%
sqr-neg36.8%
+-commutative36.8%
sqr-neg36.8%
distribute-rgt-in36.8%
cancel-sign-sub36.8%
distribute-rgt-out--36.8%
sub-neg36.8%
remove-double-neg36.8%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 81.7%
*-commutative81.7%
unpow281.7%
rem-square-sqrt83.2%
Simplified83.2%
if 4.4000000000000002e74 < re < 2.11999999999999989e120Initial program 56.4%
sqr-neg56.4%
+-commutative56.4%
sqr-neg56.4%
distribute-rgt-in56.4%
cancel-sign-sub56.4%
distribute-rgt-out--56.4%
sub-neg56.4%
remove-double-neg56.4%
hypot-def99.9%
Simplified99.9%
Taylor expanded in re around 0 45.1%
Final simplification41.2%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= re -2.1e+63)
(* 0.5 (sqrt (* (/ im re) (- im))))
(if (or (<= re 1.16e-18) (and (not (<= re 7.5e+74)) (<= re 2.12e+120)))
(* 0.5 (sqrt (* 2.0 (+ re im))))
(* 0.5 (* 2.0 (sqrt re))))))im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= -2.1e+63) {
tmp = 0.5 * sqrt(((im / re) * -im));
} else if ((re <= 1.16e-18) || (!(re <= 7.5e+74) && (re <= 2.12e+120))) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-2.1d+63)) then
tmp = 0.5d0 * sqrt(((im / re) * -im))
else if ((re <= 1.16d-18) .or. (.not. (re <= 7.5d+74)) .and. (re <= 2.12d+120)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= -2.1e+63) {
tmp = 0.5 * Math.sqrt(((im / re) * -im));
} else if ((re <= 1.16e-18) || (!(re <= 7.5e+74) && (re <= 2.12e+120))) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= -2.1e+63: tmp = 0.5 * math.sqrt(((im / re) * -im)) elif (re <= 1.16e-18) or (not (re <= 7.5e+74) and (re <= 2.12e+120)): tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= -2.1e+63) tmp = Float64(0.5 * sqrt(Float64(Float64(im / re) * Float64(-im)))); elseif ((re <= 1.16e-18) || (!(re <= 7.5e+74) && (re <= 2.12e+120))) 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
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.1e+63) tmp = 0.5 * sqrt(((im / re) * -im)); elseif ((re <= 1.16e-18) || (~((re <= 7.5e+74)) && (re <= 2.12e+120))) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, -2.1e+63], N[(0.5 * N[Sqrt[N[(N[(im / re), $MachinePrecision] * (-im)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 1.16e-18], And[N[Not[LessEqual[re, 7.5e+74]], $MachinePrecision], LessEqual[re, 2.12e+120]]], 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}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.1 \cdot 10^{+63}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{im}{re} \cdot \left(-im\right)}\\
\mathbf{elif}\;re \leq 1.16 \cdot 10^{-18} \lor \neg \left(re \leq 7.5 \cdot 10^{+74}\right) \land re \leq 2.12 \cdot 10^{+120}:\\
\;\;\;\;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.1000000000000002e63Initial program 7.7%
sqr-neg7.7%
+-commutative7.7%
sqr-neg7.7%
distribute-rgt-in7.7%
cancel-sign-sub7.7%
distribute-rgt-out--7.7%
sub-neg7.7%
remove-double-neg7.7%
hypot-def30.4%
Simplified30.4%
Taylor expanded in re around -inf 55.7%
*-commutative55.7%
unpow255.7%
associate-/l*62.8%
Simplified62.8%
expm1-log1p-u61.7%
expm1-udef38.5%
associate-*l/38.5%
div-inv38.5%
clear-num38.5%
Applied egg-rr38.5%
expm1-def61.7%
expm1-log1p62.8%
associate-*l*62.8%
*-commutative62.8%
associate-*r*62.8%
metadata-eval62.8%
neg-mul-162.8%
*-commutative62.8%
Simplified62.8%
if -2.1000000000000002e63 < re < 1.16e-18 or 7.5e74 < re < 2.11999999999999989e120Initial program 47.3%
sqr-neg47.3%
+-commutative47.3%
sqr-neg47.3%
distribute-rgt-in47.3%
cancel-sign-sub47.3%
distribute-rgt-out--47.3%
sub-neg47.3%
remove-double-neg47.3%
hypot-def84.1%
Simplified84.1%
Taylor expanded in re around 0 36.3%
if 1.16e-18 < re < 7.5e74 or 2.11999999999999989e120 < re Initial program 36.8%
sqr-neg36.8%
+-commutative36.8%
sqr-neg36.8%
distribute-rgt-in36.8%
cancel-sign-sub36.8%
distribute-rgt-out--36.8%
sub-neg36.8%
remove-double-neg36.8%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 81.7%
*-commutative81.7%
unpow281.7%
rem-square-sqrt83.2%
Simplified83.2%
Final simplification50.5%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= re -3.8e+62)
(* 0.5 (sqrt (* 2.0 (* (/ im (/ re im)) -0.5))))
(if (or (<= re 1.3e-19) (and (not (<= re 5.2e+72)) (<= re 2.45e+120)))
(* 0.5 (sqrt (* 2.0 (+ re im))))
(* 0.5 (* 2.0 (sqrt re))))))im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= -3.8e+62) {
tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else if ((re <= 1.3e-19) || (!(re <= 5.2e+72) && (re <= 2.45e+120))) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.8d+62)) then
tmp = 0.5d0 * sqrt((2.0d0 * ((im / (re / im)) * (-0.5d0))))
else if ((re <= 1.3d-19) .or. (.not. (re <= 5.2d+72)) .and. (re <= 2.45d+120)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= -3.8e+62) {
tmp = 0.5 * Math.sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else if ((re <= 1.3e-19) || (!(re <= 5.2e+72) && (re <= 2.45e+120))) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= -3.8e+62: tmp = 0.5 * math.sqrt((2.0 * ((im / (re / im)) * -0.5))) elif (re <= 1.3e-19) or (not (re <= 5.2e+72) and (re <= 2.45e+120)): tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= -3.8e+62) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(im / Float64(re / im)) * -0.5)))); elseif ((re <= 1.3e-19) || (!(re <= 5.2e+72) && (re <= 2.45e+120))) 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
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.8e+62) tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5))); elseif ((re <= 1.3e-19) || (~((re <= 5.2e+72)) && (re <= 2.45e+120))) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, -3.8e+62], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 1.3e-19], And[N[Not[LessEqual[re, 5.2e+72]], $MachinePrecision], LessEqual[re, 2.45e+120]]], 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}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.8 \cdot 10^{+62}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \cdot -0.5\right)}\\
\mathbf{elif}\;re \leq 1.3 \cdot 10^{-19} \lor \neg \left(re \leq 5.2 \cdot 10^{+72}\right) \land re \leq 2.45 \cdot 10^{+120}:\\
\;\;\;\;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 < -3.79999999999999984e62Initial program 7.7%
sqr-neg7.7%
+-commutative7.7%
sqr-neg7.7%
distribute-rgt-in7.7%
cancel-sign-sub7.7%
distribute-rgt-out--7.7%
sub-neg7.7%
remove-double-neg7.7%
hypot-def30.4%
Simplified30.4%
Taylor expanded in re around -inf 55.7%
*-commutative55.7%
unpow255.7%
associate-/l*62.8%
Simplified62.8%
if -3.79999999999999984e62 < re < 1.30000000000000006e-19 or 5.19999999999999963e72 < re < 2.45000000000000005e120Initial program 47.3%
sqr-neg47.3%
+-commutative47.3%
sqr-neg47.3%
distribute-rgt-in47.3%
cancel-sign-sub47.3%
distribute-rgt-out--47.3%
sub-neg47.3%
remove-double-neg47.3%
hypot-def84.1%
Simplified84.1%
Taylor expanded in re around 0 36.3%
if 1.30000000000000006e-19 < re < 5.19999999999999963e72 or 2.45000000000000005e120 < re Initial program 36.8%
sqr-neg36.8%
+-commutative36.8%
sqr-neg36.8%
distribute-rgt-in36.8%
cancel-sign-sub36.8%
distribute-rgt-out--36.8%
sub-neg36.8%
remove-double-neg36.8%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 81.7%
*-commutative81.7%
unpow281.7%
rem-square-sqrt83.2%
Simplified83.2%
Final simplification50.5%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= re 2.6e-19)
(* 0.5 (sqrt (* im 2.0)))
(if (or (<= re 4.5e+68) (not (<= re 2.12e+120)))
(* 0.5 (* 2.0 (sqrt re)))
(* 0.5 (sqrt (* 2.0 (+ re im)))))))im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= 2.6e-19) {
tmp = 0.5 * sqrt((im * 2.0));
} else if ((re <= 4.5e+68) || !(re <= 2.12e+120)) {
tmp = 0.5 * (2.0 * sqrt(re));
} else {
tmp = 0.5 * sqrt((2.0 * (re + im)));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 2.6d-19) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else if ((re <= 4.5d+68) .or. (.not. (re <= 2.12d+120))) then
tmp = 0.5d0 * (2.0d0 * sqrt(re))
else
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= 2.6e-19) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else if ((re <= 4.5e+68) || !(re <= 2.12e+120)) {
tmp = 0.5 * (2.0 * Math.sqrt(re));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= 2.6e-19: tmp = 0.5 * math.sqrt((im * 2.0)) elif (re <= 4.5e+68) or not (re <= 2.12e+120): tmp = 0.5 * (2.0 * math.sqrt(re)) else: tmp = 0.5 * math.sqrt((2.0 * (re + im))) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= 2.6e-19) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); elseif ((re <= 4.5e+68) || !(re <= 2.12e+120)) tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= 2.6e-19) tmp = 0.5 * sqrt((im * 2.0)); elseif ((re <= 4.5e+68) || ~((re <= 2.12e+120))) tmp = 0.5 * (2.0 * sqrt(re)); else tmp = 0.5 * sqrt((2.0 * (re + im))); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, 2.6e-19], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 4.5e+68], N[Not[LessEqual[re, 2.12e+120]], $MachinePrecision]], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.6 \cdot 10^{-19}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{elif}\;re \leq 4.5 \cdot 10^{+68} \lor \neg \left(re \leq 2.12 \cdot 10^{+120}\right):\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\end{array}
\end{array}
if re < 2.60000000000000013e-19Initial program 36.0%
sqr-neg36.0%
+-commutative36.0%
sqr-neg36.0%
distribute-rgt-in36.0%
cancel-sign-sub36.0%
distribute-rgt-out--36.0%
sub-neg36.0%
remove-double-neg36.0%
hypot-def68.5%
Simplified68.5%
Taylor expanded in re around 0 26.7%
if 2.60000000000000013e-19 < re < 4.5000000000000003e68 or 2.11999999999999989e120 < re Initial program 36.8%
sqr-neg36.8%
+-commutative36.8%
sqr-neg36.8%
distribute-rgt-in36.8%
cancel-sign-sub36.8%
distribute-rgt-out--36.8%
sub-neg36.8%
remove-double-neg36.8%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 81.7%
*-commutative81.7%
unpow281.7%
rem-square-sqrt83.2%
Simplified83.2%
if 4.5000000000000003e68 < re < 2.11999999999999989e120Initial program 56.4%
sqr-neg56.4%
+-commutative56.4%
sqr-neg56.4%
distribute-rgt-in56.4%
cancel-sign-sub56.4%
distribute-rgt-out--56.4%
sub-neg56.4%
remove-double-neg56.4%
hypot-def99.9%
Simplified99.9%
Taylor expanded in re around 0 45.1%
Final simplification37.8%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (<= re 4e-19) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (* 2.0 (sqrt re)))))
im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= 4e-19) {
tmp = 0.5 * sqrt((im * 2.0));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 4d-19) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= 4e-19) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= 4e-19: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= 4e-19) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= 4e-19) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, 4e-19], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq 4 \cdot 10^{-19}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < 3.9999999999999999e-19Initial program 36.0%
sqr-neg36.0%
+-commutative36.0%
sqr-neg36.0%
distribute-rgt-in36.0%
cancel-sign-sub36.0%
distribute-rgt-out--36.0%
sub-neg36.0%
remove-double-neg36.0%
hypot-def68.5%
Simplified68.5%
Taylor expanded in re around 0 26.7%
if 3.9999999999999999e-19 < re Initial program 40.5%
sqr-neg40.5%
+-commutative40.5%
sqr-neg40.5%
distribute-rgt-in40.5%
cancel-sign-sub40.5%
distribute-rgt-out--40.5%
sub-neg40.5%
remove-double-neg40.5%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 72.5%
*-commutative72.5%
unpow272.5%
rem-square-sqrt73.8%
Simplified73.8%
Final simplification37.4%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (* 0.5 (sqrt (* im 2.0))))
im = abs(im);
double code(double re, double im) {
return 0.5 * sqrt((im * 2.0));
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((im * 2.0d0))
end function
im = Math.abs(im);
public static double code(double re, double im) {
return 0.5 * Math.sqrt((im * 2.0));
}
im = abs(im) def code(re, im): return 0.5 * math.sqrt((im * 2.0))
im = abs(im) function code(re, im) return Float64(0.5 * sqrt(Float64(im * 2.0))) end
im = abs(im) function tmp = code(re, im) tmp = 0.5 * sqrt((im * 2.0)); end
NOTE: im should be positive before calling this function code[re_, im_] := N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
0.5 \cdot \sqrt{im \cdot 2}
\end{array}
Initial program 37.0%
sqr-neg37.0%
+-commutative37.0%
sqr-neg37.0%
distribute-rgt-in37.0%
cancel-sign-sub37.0%
distribute-rgt-out--37.0%
sub-neg37.0%
remove-double-neg37.0%
hypot-def75.7%
Simplified75.7%
Taylor expanded in re around 0 24.0%
Final simplification24.0%
(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 2023282
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:herbie-target
(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)))))