
(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}
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= re -5.7e+59)
(* 0.5 (/ im_m (sqrt (- re))))
(if (<= re -4.2e-10)
(* 0.5 (* (sqrt im_m) (sqrt 2.0)))
(if (<= re -4.9e-60)
(* 0.5 (* (* im_m (sqrt 2.0)) (sqrt (/ -0.5 re))))
(* 0.5 (sqrt (* 2.0 (+ re (hypot re im_m)))))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -5.7e+59) {
tmp = 0.5 * (im_m / sqrt(-re));
} else if (re <= -4.2e-10) {
tmp = 0.5 * (sqrt(im_m) * sqrt(2.0));
} else if (re <= -4.9e-60) {
tmp = 0.5 * ((im_m * sqrt(2.0)) * sqrt((-0.5 / re)));
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -5.7e+59) {
tmp = 0.5 * (im_m / Math.sqrt(-re));
} else if (re <= -4.2e-10) {
tmp = 0.5 * (Math.sqrt(im_m) * Math.sqrt(2.0));
} else if (re <= -4.9e-60) {
tmp = 0.5 * ((im_m * Math.sqrt(2.0)) * Math.sqrt((-0.5 / re)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im_m))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -5.7e+59: tmp = 0.5 * (im_m / math.sqrt(-re)) elif re <= -4.2e-10: tmp = 0.5 * (math.sqrt(im_m) * math.sqrt(2.0)) elif re <= -4.9e-60: tmp = 0.5 * ((im_m * math.sqrt(2.0)) * math.sqrt((-0.5 / re))) else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im_m)))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -5.7e+59) tmp = Float64(0.5 * Float64(im_m / sqrt(Float64(-re)))); elseif (re <= -4.2e-10) tmp = Float64(0.5 * Float64(sqrt(im_m) * sqrt(2.0))); elseif (re <= -4.9e-60) tmp = Float64(0.5 * Float64(Float64(im_m * sqrt(2.0)) * sqrt(Float64(-0.5 / re)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im_m))))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -5.7e+59) tmp = 0.5 * (im_m / sqrt(-re)); elseif (re <= -4.2e-10) tmp = 0.5 * (sqrt(im_m) * sqrt(2.0)); elseif (re <= -4.9e-60) tmp = 0.5 * ((im_m * sqrt(2.0)) * sqrt((-0.5 / re))); else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -5.7e+59], N[(0.5 * N[(im$95$m / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -4.2e-10], N[(0.5 * N[(N[Sqrt[im$95$m], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -4.9e-60], N[(0.5 * N[(N[(im$95$m * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(-0.5 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5.7 \cdot 10^{+59}:\\
\;\;\;\;0.5 \cdot \frac{im_m}{\sqrt{-re}}\\
\mathbf{elif}\;re \leq -4.2 \cdot 10^{-10}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{im_m} \cdot \sqrt{2}\right)\\
\mathbf{elif}\;re \leq -4.9 \cdot 10^{-60}:\\
\;\;\;\;0.5 \cdot \left(\left(im_m \cdot \sqrt{2}\right) \cdot \sqrt{\frac{-0.5}{re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im_m\right)\right)}\\
\end{array}
\end{array}
if re < -5.7000000000000001e59Initial program 6.2%
sqr-neg6.2%
+-commutative6.2%
sqr-neg6.2%
+-commutative6.2%
distribute-rgt-in6.2%
cancel-sign-sub6.2%
distribute-rgt-out--6.2%
sub-neg6.2%
remove-double-neg6.2%
+-commutative6.2%
Simplified30.0%
Taylor expanded in re around -inf 58.8%
associate-*r/58.8%
associate-/l*58.7%
Simplified58.7%
*-un-lft-identity58.7%
unpow258.7%
times-frac64.0%
Applied egg-rr64.0%
associate-*r/64.0%
metadata-eval64.0%
frac-times58.7%
*-un-lft-identity58.7%
unpow258.7%
associate-/l*58.8%
neg-mul-158.8%
frac-2neg58.8%
sqrt-div78.4%
remove-double-neg78.4%
unpow278.4%
sqrt-prod40.6%
add-sqr-sqrt56.1%
Applied egg-rr56.1%
if -5.7000000000000001e59 < re < -4.2e-10Initial program 42.5%
sqr-neg42.5%
+-commutative42.5%
sqr-neg42.5%
+-commutative42.5%
distribute-rgt-in42.5%
cancel-sign-sub42.5%
distribute-rgt-out--42.5%
sub-neg42.5%
remove-double-neg42.5%
+-commutative42.5%
Simplified80.9%
Taylor expanded in re around 0 50.3%
if -4.2e-10 < re < -4.89999999999999988e-60Initial program 18.2%
sqr-neg18.2%
+-commutative18.2%
sqr-neg18.2%
+-commutative18.2%
distribute-rgt-in18.2%
cancel-sign-sub18.2%
distribute-rgt-out--18.2%
sub-neg18.2%
remove-double-neg18.2%
+-commutative18.2%
Simplified40.3%
Taylor expanded in re around -inf 44.1%
associate-*r/44.1%
associate-/l*44.1%
Simplified44.1%
sqrt-prod43.9%
associate-/r/43.9%
sqrt-prod43.9%
sqrt-pow128.1%
metadata-eval28.1%
pow128.1%
Applied egg-rr28.1%
*-commutative28.1%
associate-*r*28.1%
*-commutative28.1%
Simplified28.1%
if -4.89999999999999988e-60 < re Initial program 54.6%
sqr-neg54.6%
+-commutative54.6%
sqr-neg54.6%
+-commutative54.6%
distribute-rgt-in54.6%
cancel-sign-sub54.6%
distribute-rgt-out--54.6%
sub-neg54.6%
remove-double-neg54.6%
+-commutative54.6%
Simplified96.0%
Final simplification81.9%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* 0.5 (/ im_m (sqrt (- re))))))
(if (<= re -5.5e+57)
t_0
(if (<= re -5.5e-10)
(* 0.5 (* (sqrt im_m) (sqrt 2.0)))
(if (<= re -1.7e-54)
t_0
(* 0.5 (sqrt (* 2.0 (+ re (hypot re im_m))))))))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = 0.5 * (im_m / sqrt(-re));
double tmp;
if (re <= -5.5e+57) {
tmp = t_0;
} else if (re <= -5.5e-10) {
tmp = 0.5 * (sqrt(im_m) * sqrt(2.0));
} else if (re <= -1.7e-54) {
tmp = t_0;
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double t_0 = 0.5 * (im_m / Math.sqrt(-re));
double tmp;
if (re <= -5.5e+57) {
tmp = t_0;
} else if (re <= -5.5e-10) {
tmp = 0.5 * (Math.sqrt(im_m) * Math.sqrt(2.0));
} else if (re <= -1.7e-54) {
tmp = t_0;
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im_m))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): t_0 = 0.5 * (im_m / math.sqrt(-re)) tmp = 0 if re <= -5.5e+57: tmp = t_0 elif re <= -5.5e-10: tmp = 0.5 * (math.sqrt(im_m) * math.sqrt(2.0)) elif re <= -1.7e-54: tmp = t_0 else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im_m)))) return tmp
im_m = abs(im) function code(re, im_m) t_0 = Float64(0.5 * Float64(im_m / sqrt(Float64(-re)))) tmp = 0.0 if (re <= -5.5e+57) tmp = t_0; elseif (re <= -5.5e-10) tmp = Float64(0.5 * Float64(sqrt(im_m) * sqrt(2.0))); elseif (re <= -1.7e-54) tmp = t_0; else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im_m))))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) t_0 = 0.5 * (im_m / sqrt(-re)); tmp = 0.0; if (re <= -5.5e+57) tmp = t_0; elseif (re <= -5.5e-10) tmp = 0.5 * (sqrt(im_m) * sqrt(2.0)); elseif (re <= -1.7e-54) tmp = t_0; else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im_m)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[(im$95$m / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -5.5e+57], t$95$0, If[LessEqual[re, -5.5e-10], N[(0.5 * N[(N[Sqrt[im$95$m], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.7e-54], t$95$0, N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{im_m}{\sqrt{-re}}\\
\mathbf{if}\;re \leq -5.5 \cdot 10^{+57}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -5.5 \cdot 10^{-10}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{im_m} \cdot \sqrt{2}\right)\\
\mathbf{elif}\;re \leq -1.7 \cdot 10^{-54}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im_m\right)\right)}\\
\end{array}
\end{array}
if re < -5.5000000000000002e57 or -5.4999999999999996e-10 < re < -1.69999999999999994e-54Initial program 8.5%
sqr-neg8.5%
+-commutative8.5%
sqr-neg8.5%
+-commutative8.5%
distribute-rgt-in8.5%
cancel-sign-sub8.5%
distribute-rgt-out--8.5%
sub-neg8.5%
remove-double-neg8.5%
+-commutative8.5%
Simplified31.9%
Taylor expanded in re around -inf 56.1%
associate-*r/56.1%
associate-/l*56.0%
Simplified56.0%
*-un-lft-identity56.0%
unpow256.0%
times-frac61.7%
Applied egg-rr61.7%
associate-*r/61.7%
metadata-eval61.7%
frac-times56.0%
*-un-lft-identity56.0%
unpow256.0%
associate-/l*56.1%
neg-mul-156.1%
frac-2neg56.1%
sqrt-div72.0%
remove-double-neg72.0%
unpow272.0%
sqrt-prod38.0%
add-sqr-sqrt50.9%
Applied egg-rr50.9%
if -5.5000000000000002e57 < re < -5.4999999999999996e-10Initial program 42.5%
sqr-neg42.5%
+-commutative42.5%
sqr-neg42.5%
+-commutative42.5%
distribute-rgt-in42.5%
cancel-sign-sub42.5%
distribute-rgt-out--42.5%
sub-neg42.5%
remove-double-neg42.5%
+-commutative42.5%
Simplified80.9%
Taylor expanded in re around 0 50.3%
if -1.69999999999999994e-54 < re Initial program 54.6%
sqr-neg54.6%
+-commutative54.6%
sqr-neg54.6%
+-commutative54.6%
distribute-rgt-in54.6%
cancel-sign-sub54.6%
distribute-rgt-out--54.6%
sub-neg54.6%
remove-double-neg54.6%
+-commutative54.6%
Simplified96.0%
Final simplification81.9%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* 0.5 (/ im_m (sqrt (- re))))))
(if (<= re -1.02e+59)
t_0
(if (<= re -7e-10)
(* 0.5 (* (sqrt im_m) (sqrt 2.0)))
(if (<= re -1.3e-57)
t_0
(if (<= re 7e-44)
(* 0.5 (sqrt (* 2.0 (+ re im_m))))
(* 0.5 (* 2.0 (sqrt re)))))))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = 0.5 * (im_m / sqrt(-re));
double tmp;
if (re <= -1.02e+59) {
tmp = t_0;
} else if (re <= -7e-10) {
tmp = 0.5 * (sqrt(im_m) * sqrt(2.0));
} else if (re <= -1.3e-57) {
tmp = t_0;
} else if (re <= 7e-44) {
tmp = 0.5 * sqrt((2.0 * (re + im_m)));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * (im_m / sqrt(-re))
if (re <= (-1.02d+59)) then
tmp = t_0
else if (re <= (-7d-10)) then
tmp = 0.5d0 * (sqrt(im_m) * sqrt(2.0d0))
else if (re <= (-1.3d-57)) then
tmp = t_0
else if (re <= 7d-44) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im_m)))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double t_0 = 0.5 * (im_m / Math.sqrt(-re));
double tmp;
if (re <= -1.02e+59) {
tmp = t_0;
} else if (re <= -7e-10) {
tmp = 0.5 * (Math.sqrt(im_m) * Math.sqrt(2.0));
} else if (re <= -1.3e-57) {
tmp = t_0;
} else if (re <= 7e-44) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im_m)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): t_0 = 0.5 * (im_m / math.sqrt(-re)) tmp = 0 if re <= -1.02e+59: tmp = t_0 elif re <= -7e-10: tmp = 0.5 * (math.sqrt(im_m) * math.sqrt(2.0)) elif re <= -1.3e-57: tmp = t_0 elif re <= 7e-44: tmp = 0.5 * math.sqrt((2.0 * (re + im_m))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
im_m = abs(im) function code(re, im_m) t_0 = Float64(0.5 * Float64(im_m / sqrt(Float64(-re)))) tmp = 0.0 if (re <= -1.02e+59) tmp = t_0; elseif (re <= -7e-10) tmp = Float64(0.5 * Float64(sqrt(im_m) * sqrt(2.0))); elseif (re <= -1.3e-57) tmp = t_0; elseif (re <= 7e-44) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im_m)))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) t_0 = 0.5 * (im_m / sqrt(-re)); tmp = 0.0; if (re <= -1.02e+59) tmp = t_0; elseif (re <= -7e-10) tmp = 0.5 * (sqrt(im_m) * sqrt(2.0)); elseif (re <= -1.3e-57) tmp = t_0; elseif (re <= 7e-44) tmp = 0.5 * sqrt((2.0 * (re + im_m))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[(im$95$m / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.02e+59], t$95$0, If[LessEqual[re, -7e-10], N[(0.5 * N[(N[Sqrt[im$95$m], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.3e-57], t$95$0, If[LessEqual[re, 7e-44], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{im_m}{\sqrt{-re}}\\
\mathbf{if}\;re \leq -1.02 \cdot 10^{+59}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -7 \cdot 10^{-10}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{im_m} \cdot \sqrt{2}\right)\\
\mathbf{elif}\;re \leq -1.3 \cdot 10^{-57}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 7 \cdot 10^{-44}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im_m\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -1.02000000000000002e59 or -6.99999999999999961e-10 < re < -1.29999999999999993e-57Initial program 8.5%
sqr-neg8.5%
+-commutative8.5%
sqr-neg8.5%
+-commutative8.5%
distribute-rgt-in8.5%
cancel-sign-sub8.5%
distribute-rgt-out--8.5%
sub-neg8.5%
remove-double-neg8.5%
+-commutative8.5%
Simplified31.9%
Taylor expanded in re around -inf 56.1%
associate-*r/56.1%
associate-/l*56.0%
Simplified56.0%
*-un-lft-identity56.0%
unpow256.0%
times-frac61.7%
Applied egg-rr61.7%
associate-*r/61.7%
metadata-eval61.7%
frac-times56.0%
*-un-lft-identity56.0%
unpow256.0%
associate-/l*56.1%
neg-mul-156.1%
frac-2neg56.1%
sqrt-div72.0%
remove-double-neg72.0%
unpow272.0%
sqrt-prod38.0%
add-sqr-sqrt50.9%
Applied egg-rr50.9%
if -1.02000000000000002e59 < re < -6.99999999999999961e-10Initial program 42.5%
sqr-neg42.5%
+-commutative42.5%
sqr-neg42.5%
+-commutative42.5%
distribute-rgt-in42.5%
cancel-sign-sub42.5%
distribute-rgt-out--42.5%
sub-neg42.5%
remove-double-neg42.5%
+-commutative42.5%
Simplified80.9%
Taylor expanded in re around 0 50.3%
if -1.29999999999999993e-57 < re < 6.9999999999999995e-44Initial program 61.9%
sqr-neg61.9%
+-commutative61.9%
sqr-neg61.9%
+-commutative61.9%
distribute-rgt-in61.9%
cancel-sign-sub61.9%
distribute-rgt-out--61.9%
sub-neg61.9%
remove-double-neg61.9%
+-commutative61.9%
Simplified93.5%
Taylor expanded in re around 0 41.4%
if 6.9999999999999995e-44 < re Initial program 42.8%
sqr-neg42.8%
+-commutative42.8%
sqr-neg42.8%
+-commutative42.8%
distribute-rgt-in42.8%
cancel-sign-sub42.8%
distribute-rgt-out--42.8%
sub-neg42.8%
remove-double-neg42.8%
+-commutative42.8%
Simplified100.0%
Taylor expanded in im around 0 74.5%
*-commutative74.5%
unpow274.5%
rem-square-sqrt76.0%
Simplified76.0%
Final simplification53.4%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* 0.5 (/ im_m (sqrt (- re))))))
(if (<= re -7.4e+57)
t_0
(if (<= re -3.8e-10)
(* 0.5 (sqrt (* im_m 2.0)))
(if (<= re -1.3e-57)
t_0
(if (<= re 8.2e-43)
(* 0.5 (sqrt (* 2.0 (+ re im_m))))
(* 0.5 (* 2.0 (sqrt re)))))))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = 0.5 * (im_m / sqrt(-re));
double tmp;
if (re <= -7.4e+57) {
tmp = t_0;
} else if (re <= -3.8e-10) {
tmp = 0.5 * sqrt((im_m * 2.0));
} else if (re <= -1.3e-57) {
tmp = t_0;
} else if (re <= 8.2e-43) {
tmp = 0.5 * sqrt((2.0 * (re + im_m)));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * (im_m / sqrt(-re))
if (re <= (-7.4d+57)) then
tmp = t_0
else if (re <= (-3.8d-10)) then
tmp = 0.5d0 * sqrt((im_m * 2.0d0))
else if (re <= (-1.3d-57)) then
tmp = t_0
else if (re <= 8.2d-43) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im_m)))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double t_0 = 0.5 * (im_m / Math.sqrt(-re));
double tmp;
if (re <= -7.4e+57) {
tmp = t_0;
} else if (re <= -3.8e-10) {
tmp = 0.5 * Math.sqrt((im_m * 2.0));
} else if (re <= -1.3e-57) {
tmp = t_0;
} else if (re <= 8.2e-43) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im_m)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): t_0 = 0.5 * (im_m / math.sqrt(-re)) tmp = 0 if re <= -7.4e+57: tmp = t_0 elif re <= -3.8e-10: tmp = 0.5 * math.sqrt((im_m * 2.0)) elif re <= -1.3e-57: tmp = t_0 elif re <= 8.2e-43: tmp = 0.5 * math.sqrt((2.0 * (re + im_m))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
im_m = abs(im) function code(re, im_m) t_0 = Float64(0.5 * Float64(im_m / sqrt(Float64(-re)))) tmp = 0.0 if (re <= -7.4e+57) tmp = t_0; elseif (re <= -3.8e-10) tmp = Float64(0.5 * sqrt(Float64(im_m * 2.0))); elseif (re <= -1.3e-57) tmp = t_0; elseif (re <= 8.2e-43) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im_m)))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) t_0 = 0.5 * (im_m / sqrt(-re)); tmp = 0.0; if (re <= -7.4e+57) tmp = t_0; elseif (re <= -3.8e-10) tmp = 0.5 * sqrt((im_m * 2.0)); elseif (re <= -1.3e-57) tmp = t_0; elseif (re <= 8.2e-43) tmp = 0.5 * sqrt((2.0 * (re + im_m))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[(im$95$m / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -7.4e+57], t$95$0, If[LessEqual[re, -3.8e-10], N[(0.5 * N[Sqrt[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.3e-57], t$95$0, If[LessEqual[re, 8.2e-43], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{im_m}{\sqrt{-re}}\\
\mathbf{if}\;re \leq -7.4 \cdot 10^{+57}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -3.8 \cdot 10^{-10}:\\
\;\;\;\;0.5 \cdot \sqrt{im_m \cdot 2}\\
\mathbf{elif}\;re \leq -1.3 \cdot 10^{-57}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 8.2 \cdot 10^{-43}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im_m\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -7.40000000000000011e57 or -3.7999999999999998e-10 < re < -1.29999999999999993e-57Initial program 8.5%
sqr-neg8.5%
+-commutative8.5%
sqr-neg8.5%
+-commutative8.5%
distribute-rgt-in8.5%
cancel-sign-sub8.5%
distribute-rgt-out--8.5%
sub-neg8.5%
remove-double-neg8.5%
+-commutative8.5%
Simplified31.9%
Taylor expanded in re around -inf 56.1%
associate-*r/56.1%
associate-/l*56.0%
Simplified56.0%
*-un-lft-identity56.0%
unpow256.0%
times-frac61.7%
Applied egg-rr61.7%
associate-*r/61.7%
metadata-eval61.7%
frac-times56.0%
*-un-lft-identity56.0%
unpow256.0%
associate-/l*56.1%
neg-mul-156.1%
frac-2neg56.1%
sqrt-div72.0%
remove-double-neg72.0%
unpow272.0%
sqrt-prod38.0%
add-sqr-sqrt50.9%
Applied egg-rr50.9%
if -7.40000000000000011e57 < re < -3.7999999999999998e-10Initial program 42.5%
sqr-neg42.5%
+-commutative42.5%
sqr-neg42.5%
+-commutative42.5%
distribute-rgt-in42.5%
cancel-sign-sub42.5%
distribute-rgt-out--42.5%
sub-neg42.5%
remove-double-neg42.5%
+-commutative42.5%
Simplified80.9%
Taylor expanded in re around 0 41.1%
if -1.29999999999999993e-57 < re < 8.1999999999999996e-43Initial program 61.9%
sqr-neg61.9%
+-commutative61.9%
sqr-neg61.9%
+-commutative61.9%
distribute-rgt-in61.9%
cancel-sign-sub61.9%
distribute-rgt-out--61.9%
sub-neg61.9%
remove-double-neg61.9%
+-commutative61.9%
Simplified93.5%
Taylor expanded in re around 0 41.4%
if 8.1999999999999996e-43 < re Initial program 42.8%
sqr-neg42.8%
+-commutative42.8%
sqr-neg42.8%
+-commutative42.8%
distribute-rgt-in42.8%
cancel-sign-sub42.8%
distribute-rgt-out--42.8%
sub-neg42.8%
remove-double-neg42.8%
+-commutative42.8%
Simplified100.0%
Taylor expanded in im around 0 74.5%
*-commutative74.5%
unpow274.5%
rem-square-sqrt76.0%
Simplified76.0%
Final simplification53.1%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* 0.5 (/ im_m (sqrt (- re))))) (t_1 (* 0.5 (sqrt (* im_m 2.0)))))
(if (<= re -2.05e+60)
t_0
(if (<= re -7.8e-10)
t_1
(if (<= re -2.05e-60)
t_0
(if (<= re 3e-43) t_1 (* 0.5 (* 2.0 (sqrt re)))))))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = 0.5 * (im_m / sqrt(-re));
double t_1 = 0.5 * sqrt((im_m * 2.0));
double tmp;
if (re <= -2.05e+60) {
tmp = t_0;
} else if (re <= -7.8e-10) {
tmp = t_1;
} else if (re <= -2.05e-60) {
tmp = t_0;
} else if (re <= 3e-43) {
tmp = t_1;
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * (im_m / sqrt(-re))
t_1 = 0.5d0 * sqrt((im_m * 2.0d0))
if (re <= (-2.05d+60)) then
tmp = t_0
else if (re <= (-7.8d-10)) then
tmp = t_1
else if (re <= (-2.05d-60)) then
tmp = t_0
else if (re <= 3d-43) then
tmp = t_1
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double t_0 = 0.5 * (im_m / Math.sqrt(-re));
double t_1 = 0.5 * Math.sqrt((im_m * 2.0));
double tmp;
if (re <= -2.05e+60) {
tmp = t_0;
} else if (re <= -7.8e-10) {
tmp = t_1;
} else if (re <= -2.05e-60) {
tmp = t_0;
} else if (re <= 3e-43) {
tmp = t_1;
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): t_0 = 0.5 * (im_m / math.sqrt(-re)) t_1 = 0.5 * math.sqrt((im_m * 2.0)) tmp = 0 if re <= -2.05e+60: tmp = t_0 elif re <= -7.8e-10: tmp = t_1 elif re <= -2.05e-60: tmp = t_0 elif re <= 3e-43: tmp = t_1 else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
im_m = abs(im) function code(re, im_m) t_0 = Float64(0.5 * Float64(im_m / sqrt(Float64(-re)))) t_1 = Float64(0.5 * sqrt(Float64(im_m * 2.0))) tmp = 0.0 if (re <= -2.05e+60) tmp = t_0; elseif (re <= -7.8e-10) tmp = t_1; elseif (re <= -2.05e-60) tmp = t_0; elseif (re <= 3e-43) tmp = t_1; else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) t_0 = 0.5 * (im_m / sqrt(-re)); t_1 = 0.5 * sqrt((im_m * 2.0)); tmp = 0.0; if (re <= -2.05e+60) tmp = t_0; elseif (re <= -7.8e-10) tmp = t_1; elseif (re <= -2.05e-60) tmp = t_0; elseif (re <= 3e-43) tmp = t_1; else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[(im$95$m / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -2.05e+60], t$95$0, If[LessEqual[re, -7.8e-10], t$95$1, If[LessEqual[re, -2.05e-60], t$95$0, If[LessEqual[re, 3e-43], t$95$1, N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{im_m}{\sqrt{-re}}\\
t_1 := 0.5 \cdot \sqrt{im_m \cdot 2}\\
\mathbf{if}\;re \leq -2.05 \cdot 10^{+60}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -7.8 \cdot 10^{-10}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -2.05 \cdot 10^{-60}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 3 \cdot 10^{-43}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -2.05e60 or -7.7999999999999999e-10 < re < -2.05000000000000006e-60Initial program 8.5%
sqr-neg8.5%
+-commutative8.5%
sqr-neg8.5%
+-commutative8.5%
distribute-rgt-in8.5%
cancel-sign-sub8.5%
distribute-rgt-out--8.5%
sub-neg8.5%
remove-double-neg8.5%
+-commutative8.5%
Simplified31.9%
Taylor expanded in re around -inf 56.1%
associate-*r/56.1%
associate-/l*56.0%
Simplified56.0%
*-un-lft-identity56.0%
unpow256.0%
times-frac61.7%
Applied egg-rr61.7%
associate-*r/61.7%
metadata-eval61.7%
frac-times56.0%
*-un-lft-identity56.0%
unpow256.0%
associate-/l*56.1%
neg-mul-156.1%
frac-2neg56.1%
sqrt-div72.0%
remove-double-neg72.0%
unpow272.0%
sqrt-prod38.0%
add-sqr-sqrt50.9%
Applied egg-rr50.9%
if -2.05e60 < re < -7.7999999999999999e-10 or -2.05000000000000006e-60 < re < 3.00000000000000003e-43Initial program 60.3%
sqr-neg60.3%
+-commutative60.3%
sqr-neg60.3%
+-commutative60.3%
distribute-rgt-in60.3%
cancel-sign-sub60.3%
distribute-rgt-out--60.3%
sub-neg60.3%
remove-double-neg60.3%
+-commutative60.3%
Simplified92.5%
Taylor expanded in re around 0 40.4%
if 3.00000000000000003e-43 < re Initial program 42.8%
sqr-neg42.8%
+-commutative42.8%
sqr-neg42.8%
+-commutative42.8%
distribute-rgt-in42.8%
cancel-sign-sub42.8%
distribute-rgt-out--42.8%
sub-neg42.8%
remove-double-neg42.8%
+-commutative42.8%
Simplified100.0%
Taylor expanded in im around 0 74.5%
*-commutative74.5%
unpow274.5%
rem-square-sqrt76.0%
Simplified76.0%
Final simplification52.6%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re 8.2e-43) (* 0.5 (sqrt (* im_m 2.0))) (* 0.5 (* 2.0 (sqrt re)))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= 8.2e-43) {
tmp = 0.5 * sqrt((im_m * 2.0));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= 8.2d-43) then
tmp = 0.5d0 * sqrt((im_m * 2.0d0))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= 8.2e-43) {
tmp = 0.5 * Math.sqrt((im_m * 2.0));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= 8.2e-43: tmp = 0.5 * math.sqrt((im_m * 2.0)) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= 8.2e-43) tmp = Float64(0.5 * sqrt(Float64(im_m * 2.0))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= 8.2e-43) tmp = 0.5 * sqrt((im_m * 2.0)); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, 8.2e-43], N[(0.5 * N[Sqrt[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq 8.2 \cdot 10^{-43}:\\
\;\;\;\;0.5 \cdot \sqrt{im_m \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < 8.1999999999999996e-43Initial program 41.1%
sqr-neg41.1%
+-commutative41.1%
sqr-neg41.1%
+-commutative41.1%
distribute-rgt-in41.1%
cancel-sign-sub41.1%
distribute-rgt-out--41.1%
sub-neg41.1%
remove-double-neg41.1%
+-commutative41.1%
Simplified70.0%
Taylor expanded in re around 0 28.3%
if 8.1999999999999996e-43 < re Initial program 42.8%
sqr-neg42.8%
+-commutative42.8%
sqr-neg42.8%
+-commutative42.8%
distribute-rgt-in42.8%
cancel-sign-sub42.8%
distribute-rgt-out--42.8%
sub-neg42.8%
remove-double-neg42.8%
+-commutative42.8%
Simplified100.0%
Taylor expanded in im around 0 74.5%
*-commutative74.5%
unpow274.5%
rem-square-sqrt76.0%
Simplified76.0%
Final simplification40.8%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (* 0.5 (sqrt (* im_m 2.0))))
im_m = fabs(im);
double code(double re, double im_m) {
return 0.5 * sqrt((im_m * 2.0));
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = 0.5d0 * sqrt((im_m * 2.0d0))
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return 0.5 * Math.sqrt((im_m * 2.0));
}
im_m = math.fabs(im) def code(re, im_m): return 0.5 * math.sqrt((im_m * 2.0))
im_m = abs(im) function code(re, im_m) return Float64(0.5 * sqrt(Float64(im_m * 2.0))) end
im_m = abs(im); function tmp = code(re, im_m) tmp = 0.5 * sqrt((im_m * 2.0)); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(0.5 * N[Sqrt[N[(im$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
0.5 \cdot \sqrt{im_m \cdot 2}
\end{array}
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%
Simplified77.9%
Taylor expanded in re around 0 24.1%
Final simplification24.1%
(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 2024017
(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)))))