
(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}
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (+ re (sqrt (+ (* re re) (* im_m im_m)))) 0.0) (* im_m (sqrt (/ -0.25 re))) (sqrt (* 0.5 (+ re (hypot im_m re))))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if ((re + sqrt(((re * re) + (im_m * im_m)))) <= 0.0) {
tmp = im_m * sqrt((-0.25 / re));
} else {
tmp = sqrt((0.5 * (re + hypot(im_m, re))));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if ((re + Math.sqrt(((re * re) + (im_m * im_m)))) <= 0.0) {
tmp = im_m * Math.sqrt((-0.25 / re));
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(im_m, re))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if (re + math.sqrt(((re * re) + (im_m * im_m)))) <= 0.0: tmp = im_m * math.sqrt((-0.25 / re)) else: tmp = math.sqrt((0.5 * (re + math.hypot(im_m, re)))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(re + sqrt(Float64(Float64(re * re) + Float64(im_m * im_m)))) <= 0.0) tmp = Float64(im_m * sqrt(Float64(-0.25 / re))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(im_m, re)))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if ((re + sqrt(((re * re) + (im_m * im_m)))) <= 0.0) tmp = im_m * sqrt((-0.25 / re)); else tmp = sqrt((0.5 * (re + hypot(im_m, re)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im$95$m * im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0], N[(im$95$m * N[Sqrt[N[(-0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[im$95$m ^ 2 + re ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re + \sqrt{re \cdot re + im\_m \cdot im\_m} \leq 0:\\
\;\;\;\;im\_m \cdot \sqrt{\frac{-0.25}{re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(im\_m, re\right)\right)}\\
\end{array}
\end{array}
if (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 4.1%
sqr-neg4.1%
+-commutative4.1%
sqr-neg4.1%
+-commutative4.1%
distribute-rgt-in4.1%
cancel-sign-sub4.1%
distribute-rgt-out--4.1%
sub-neg4.1%
remove-double-neg4.1%
+-commutative4.1%
hypot-define12.6%
Simplified12.6%
*-commutative12.6%
hypot-define4.1%
+-commutative4.1%
*-commutative4.1%
add-sqr-sqrt4.1%
sqrt-unprod4.1%
*-commutative4.1%
*-commutative4.1%
swap-sqr4.1%
Applied egg-rr12.6%
*-commutative12.6%
associate-*r*12.6%
metadata-eval12.6%
hypot-undefine4.1%
unpow24.1%
unpow24.1%
+-commutative4.1%
unpow24.1%
unpow24.1%
hypot-undefine12.6%
Simplified12.6%
Taylor expanded in re around -inf 41.1%
*-commutative41.1%
associate-*l/41.1%
Simplified41.1%
*-un-lft-identity41.1%
*-commutative41.1%
associate-*r/41.1%
*-commutative41.1%
associate-*r*41.1%
metadata-eval41.1%
Applied egg-rr41.1%
*-rgt-identity41.1%
*-commutative41.1%
associate-/l*41.1%
Simplified41.1%
*-commutative41.1%
sqrt-prod48.8%
sqrt-pow150.5%
metadata-eval50.5%
pow150.5%
Applied egg-rr50.5%
if 0.0 < (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 46.8%
sqr-neg46.8%
+-commutative46.8%
sqr-neg46.8%
+-commutative46.8%
distribute-rgt-in46.8%
cancel-sign-sub46.8%
distribute-rgt-out--46.8%
sub-neg46.8%
remove-double-neg46.8%
+-commutative46.8%
hypot-define90.4%
Simplified90.4%
*-commutative90.4%
hypot-define46.8%
+-commutative46.8%
*-commutative46.8%
add-sqr-sqrt46.5%
sqrt-unprod46.8%
*-commutative46.8%
*-commutative46.8%
swap-sqr46.8%
Applied egg-rr90.4%
*-commutative90.4%
associate-*r*90.4%
metadata-eval90.4%
hypot-undefine46.8%
unpow246.8%
unpow246.8%
+-commutative46.8%
unpow246.8%
unpow246.8%
hypot-undefine90.4%
Simplified90.4%
Final simplification84.7%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* im_m (sqrt (/ -0.25 re)))))
(if (<= re -4.2e+30)
t_0
(if (<= re -5.8e-64)
(sqrt (* im_m 0.5))
(if (<= re -1.3e-105)
t_0
(if (<= re 1.7e+70) (sqrt (* 0.5 (+ re im_m))) (sqrt re)))))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = im_m * sqrt((-0.25 / re));
double tmp;
if (re <= -4.2e+30) {
tmp = t_0;
} else if (re <= -5.8e-64) {
tmp = sqrt((im_m * 0.5));
} else if (re <= -1.3e-105) {
tmp = t_0;
} else if (re <= 1.7e+70) {
tmp = sqrt((0.5 * (re + im_m)));
} else {
tmp = 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 = im_m * sqrt(((-0.25d0) / re))
if (re <= (-4.2d+30)) then
tmp = t_0
else if (re <= (-5.8d-64)) then
tmp = sqrt((im_m * 0.5d0))
else if (re <= (-1.3d-105)) then
tmp = t_0
else if (re <= 1.7d+70) then
tmp = sqrt((0.5d0 * (re + im_m)))
else
tmp = 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 = im_m * Math.sqrt((-0.25 / re));
double tmp;
if (re <= -4.2e+30) {
tmp = t_0;
} else if (re <= -5.8e-64) {
tmp = Math.sqrt((im_m * 0.5));
} else if (re <= -1.3e-105) {
tmp = t_0;
} else if (re <= 1.7e+70) {
tmp = Math.sqrt((0.5 * (re + im_m)));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): t_0 = im_m * math.sqrt((-0.25 / re)) tmp = 0 if re <= -4.2e+30: tmp = t_0 elif re <= -5.8e-64: tmp = math.sqrt((im_m * 0.5)) elif re <= -1.3e-105: tmp = t_0 elif re <= 1.7e+70: tmp = math.sqrt((0.5 * (re + im_m))) else: tmp = math.sqrt(re) return tmp
im_m = abs(im) function code(re, im_m) t_0 = Float64(im_m * sqrt(Float64(-0.25 / re))) tmp = 0.0 if (re <= -4.2e+30) tmp = t_0; elseif (re <= -5.8e-64) tmp = sqrt(Float64(im_m * 0.5)); elseif (re <= -1.3e-105) tmp = t_0; elseif (re <= 1.7e+70) tmp = sqrt(Float64(0.5 * Float64(re + im_m))); else tmp = sqrt(re); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) t_0 = im_m * sqrt((-0.25 / re)); tmp = 0.0; if (re <= -4.2e+30) tmp = t_0; elseif (re <= -5.8e-64) tmp = sqrt((im_m * 0.5)); elseif (re <= -1.3e-105) tmp = t_0; elseif (re <= 1.7e+70) tmp = sqrt((0.5 * (re + im_m))); else tmp = sqrt(re); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(im$95$m * N[Sqrt[N[(-0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -4.2e+30], t$95$0, If[LessEqual[re, -5.8e-64], N[Sqrt[N[(im$95$m * 0.5), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, -1.3e-105], t$95$0, If[LessEqual[re, 1.7e+70], N[Sqrt[N[(0.5 * N[(re + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := im\_m \cdot \sqrt{\frac{-0.25}{re}}\\
\mathbf{if}\;re \leq -4.2 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq -5.8 \cdot 10^{-64}:\\
\;\;\;\;\sqrt{im\_m \cdot 0.5}\\
\mathbf{elif}\;re \leq -1.3 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 1.7 \cdot 10^{+70}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + im\_m\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -4.2e30 or -5.7999999999999998e-64 < re < -1.2999999999999999e-105Initial program 8.4%
sqr-neg8.4%
+-commutative8.4%
sqr-neg8.4%
+-commutative8.4%
distribute-rgt-in8.4%
cancel-sign-sub8.4%
distribute-rgt-out--8.4%
sub-neg8.4%
remove-double-neg8.4%
+-commutative8.4%
hypot-define33.4%
Simplified33.4%
*-commutative33.4%
hypot-define8.4%
+-commutative8.4%
*-commutative8.4%
add-sqr-sqrt8.3%
sqrt-unprod8.4%
*-commutative8.4%
*-commutative8.4%
swap-sqr8.4%
Applied egg-rr33.4%
*-commutative33.4%
associate-*r*33.4%
metadata-eval33.4%
hypot-undefine8.4%
unpow28.4%
unpow28.4%
+-commutative8.4%
unpow28.4%
unpow28.4%
hypot-undefine33.4%
Simplified33.4%
Taylor expanded in re around -inf 38.5%
*-commutative38.5%
associate-*l/38.5%
Simplified38.5%
*-un-lft-identity38.5%
*-commutative38.5%
associate-*r/38.5%
*-commutative38.5%
associate-*r*38.5%
metadata-eval38.5%
Applied egg-rr38.5%
*-rgt-identity38.5%
*-commutative38.5%
associate-/l*38.5%
Simplified38.5%
*-commutative38.5%
sqrt-prod55.2%
sqrt-pow151.2%
metadata-eval51.2%
pow151.2%
Applied egg-rr51.2%
if -4.2e30 < re < -5.7999999999999998e-64Initial program 40.2%
sqr-neg40.2%
+-commutative40.2%
sqr-neg40.2%
+-commutative40.2%
distribute-rgt-in40.2%
cancel-sign-sub40.2%
distribute-rgt-out--40.2%
sub-neg40.2%
remove-double-neg40.2%
+-commutative40.2%
hypot-define72.1%
Simplified72.1%
*-commutative72.1%
hypot-define40.2%
+-commutative40.2%
*-commutative40.2%
add-sqr-sqrt40.0%
sqrt-unprod40.2%
*-commutative40.2%
*-commutative40.2%
swap-sqr40.2%
Applied egg-rr72.1%
*-commutative72.1%
associate-*r*72.1%
metadata-eval72.1%
hypot-undefine40.2%
unpow240.2%
unpow240.2%
+-commutative40.2%
unpow240.2%
unpow240.2%
hypot-undefine72.1%
Simplified72.1%
Taylor expanded in re around 0 34.0%
if -1.2999999999999999e-105 < re < 1.7e70Initial program 56.4%
sqr-neg56.4%
+-commutative56.4%
sqr-neg56.4%
+-commutative56.4%
distribute-rgt-in56.4%
cancel-sign-sub56.4%
distribute-rgt-out--56.4%
sub-neg56.4%
remove-double-neg56.4%
+-commutative56.4%
hypot-define93.7%
Simplified93.7%
*-commutative93.7%
hypot-define56.4%
+-commutative56.4%
*-commutative56.4%
add-sqr-sqrt55.9%
sqrt-unprod56.4%
*-commutative56.4%
*-commutative56.4%
swap-sqr56.4%
Applied egg-rr93.7%
*-commutative93.7%
associate-*r*93.7%
metadata-eval93.7%
hypot-undefine56.4%
unpow256.4%
unpow256.4%
+-commutative56.4%
unpow256.4%
unpow256.4%
hypot-undefine93.7%
Simplified93.7%
Taylor expanded in re around 0 39.5%
if 1.7e70 < re Initial program 41.9%
sqr-neg41.9%
+-commutative41.9%
sqr-neg41.9%
+-commutative41.9%
distribute-rgt-in41.9%
cancel-sign-sub41.9%
distribute-rgt-out--41.9%
sub-neg41.9%
remove-double-neg41.9%
+-commutative41.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 77.3%
*-commutative77.3%
unpow277.3%
rem-square-sqrt78.7%
associate-*r*78.7%
metadata-eval78.7%
*-lft-identity78.7%
Simplified78.7%
Final simplification50.5%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* im_m (sqrt (/ -0.25 re)))))
(if (<= re -4.8e+29)
t_0
(if (<= re -1.65e-57)
(sqrt (* 0.5 (+ im_m (* re (+ 1.0 (* 0.5 (/ re im_m)))))))
(if (<= re -1.3e-105)
t_0
(if (<= re 1.1e+70) (sqrt (* 0.5 (+ re im_m))) (sqrt re)))))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = im_m * sqrt((-0.25 / re));
double tmp;
if (re <= -4.8e+29) {
tmp = t_0;
} else if (re <= -1.65e-57) {
tmp = sqrt((0.5 * (im_m + (re * (1.0 + (0.5 * (re / im_m)))))));
} else if (re <= -1.3e-105) {
tmp = t_0;
} else if (re <= 1.1e+70) {
tmp = sqrt((0.5 * (re + im_m)));
} else {
tmp = 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 = im_m * sqrt(((-0.25d0) / re))
if (re <= (-4.8d+29)) then
tmp = t_0
else if (re <= (-1.65d-57)) then
tmp = sqrt((0.5d0 * (im_m + (re * (1.0d0 + (0.5d0 * (re / im_m)))))))
else if (re <= (-1.3d-105)) then
tmp = t_0
else if (re <= 1.1d+70) then
tmp = sqrt((0.5d0 * (re + im_m)))
else
tmp = 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 = im_m * Math.sqrt((-0.25 / re));
double tmp;
if (re <= -4.8e+29) {
tmp = t_0;
} else if (re <= -1.65e-57) {
tmp = Math.sqrt((0.5 * (im_m + (re * (1.0 + (0.5 * (re / im_m)))))));
} else if (re <= -1.3e-105) {
tmp = t_0;
} else if (re <= 1.1e+70) {
tmp = Math.sqrt((0.5 * (re + im_m)));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): t_0 = im_m * math.sqrt((-0.25 / re)) tmp = 0 if re <= -4.8e+29: tmp = t_0 elif re <= -1.65e-57: tmp = math.sqrt((0.5 * (im_m + (re * (1.0 + (0.5 * (re / im_m))))))) elif re <= -1.3e-105: tmp = t_0 elif re <= 1.1e+70: tmp = math.sqrt((0.5 * (re + im_m))) else: tmp = math.sqrt(re) return tmp
im_m = abs(im) function code(re, im_m) t_0 = Float64(im_m * sqrt(Float64(-0.25 / re))) tmp = 0.0 if (re <= -4.8e+29) tmp = t_0; elseif (re <= -1.65e-57) tmp = sqrt(Float64(0.5 * Float64(im_m + Float64(re * Float64(1.0 + Float64(0.5 * Float64(re / im_m))))))); elseif (re <= -1.3e-105) tmp = t_0; elseif (re <= 1.1e+70) tmp = sqrt(Float64(0.5 * Float64(re + im_m))); else tmp = sqrt(re); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) t_0 = im_m * sqrt((-0.25 / re)); tmp = 0.0; if (re <= -4.8e+29) tmp = t_0; elseif (re <= -1.65e-57) tmp = sqrt((0.5 * (im_m + (re * (1.0 + (0.5 * (re / im_m))))))); elseif (re <= -1.3e-105) tmp = t_0; elseif (re <= 1.1e+70) tmp = sqrt((0.5 * (re + im_m))); else tmp = sqrt(re); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(im$95$m * N[Sqrt[N[(-0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -4.8e+29], t$95$0, If[LessEqual[re, -1.65e-57], N[Sqrt[N[(0.5 * N[(im$95$m + N[(re * N[(1.0 + N[(0.5 * N[(re / im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, -1.3e-105], t$95$0, If[LessEqual[re, 1.1e+70], N[Sqrt[N[(0.5 * N[(re + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := im\_m \cdot \sqrt{\frac{-0.25}{re}}\\
\mathbf{if}\;re \leq -4.8 \cdot 10^{+29}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq -1.65 \cdot 10^{-57}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im\_m + re \cdot \left(1 + 0.5 \cdot \frac{re}{im\_m}\right)\right)}\\
\mathbf{elif}\;re \leq -1.3 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 1.1 \cdot 10^{+70}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + im\_m\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -4.8000000000000002e29 or -1.6499999999999999e-57 < re < -1.2999999999999999e-105Initial program 8.4%
sqr-neg8.4%
+-commutative8.4%
sqr-neg8.4%
+-commutative8.4%
distribute-rgt-in8.4%
cancel-sign-sub8.4%
distribute-rgt-out--8.4%
sub-neg8.4%
remove-double-neg8.4%
+-commutative8.4%
hypot-define33.4%
Simplified33.4%
*-commutative33.4%
hypot-define8.4%
+-commutative8.4%
*-commutative8.4%
add-sqr-sqrt8.3%
sqrt-unprod8.4%
*-commutative8.4%
*-commutative8.4%
swap-sqr8.4%
Applied egg-rr33.4%
*-commutative33.4%
associate-*r*33.4%
metadata-eval33.4%
hypot-undefine8.4%
unpow28.4%
unpow28.4%
+-commutative8.4%
unpow28.4%
unpow28.4%
hypot-undefine33.4%
Simplified33.4%
Taylor expanded in re around -inf 38.5%
*-commutative38.5%
associate-*l/38.5%
Simplified38.5%
*-un-lft-identity38.5%
*-commutative38.5%
associate-*r/38.5%
*-commutative38.5%
associate-*r*38.5%
metadata-eval38.5%
Applied egg-rr38.5%
*-rgt-identity38.5%
*-commutative38.5%
associate-/l*38.5%
Simplified38.5%
*-commutative38.5%
sqrt-prod55.2%
sqrt-pow151.2%
metadata-eval51.2%
pow151.2%
Applied egg-rr51.2%
if -4.8000000000000002e29 < re < -1.6499999999999999e-57Initial program 40.2%
sqr-neg40.2%
+-commutative40.2%
sqr-neg40.2%
+-commutative40.2%
distribute-rgt-in40.2%
cancel-sign-sub40.2%
distribute-rgt-out--40.2%
sub-neg40.2%
remove-double-neg40.2%
+-commutative40.2%
hypot-define72.1%
Simplified72.1%
*-commutative72.1%
hypot-define40.2%
+-commutative40.2%
*-commutative40.2%
add-sqr-sqrt40.0%
sqrt-unprod40.2%
*-commutative40.2%
*-commutative40.2%
swap-sqr40.2%
Applied egg-rr72.1%
*-commutative72.1%
associate-*r*72.1%
metadata-eval72.1%
hypot-undefine40.2%
unpow240.2%
unpow240.2%
+-commutative40.2%
unpow240.2%
unpow240.2%
hypot-undefine72.1%
Simplified72.1%
Taylor expanded in re around 0 33.8%
if -1.2999999999999999e-105 < re < 1.1e70Initial program 56.4%
sqr-neg56.4%
+-commutative56.4%
sqr-neg56.4%
+-commutative56.4%
distribute-rgt-in56.4%
cancel-sign-sub56.4%
distribute-rgt-out--56.4%
sub-neg56.4%
remove-double-neg56.4%
+-commutative56.4%
hypot-define93.7%
Simplified93.7%
*-commutative93.7%
hypot-define56.4%
+-commutative56.4%
*-commutative56.4%
add-sqr-sqrt55.9%
sqrt-unprod56.4%
*-commutative56.4%
*-commutative56.4%
swap-sqr56.4%
Applied egg-rr93.7%
*-commutative93.7%
associate-*r*93.7%
metadata-eval93.7%
hypot-undefine56.4%
unpow256.4%
unpow256.4%
+-commutative56.4%
unpow256.4%
unpow256.4%
hypot-undefine93.7%
Simplified93.7%
Taylor expanded in re around 0 39.5%
if 1.1e70 < re Initial program 41.9%
sqr-neg41.9%
+-commutative41.9%
sqr-neg41.9%
+-commutative41.9%
distribute-rgt-in41.9%
cancel-sign-sub41.9%
distribute-rgt-out--41.9%
sub-neg41.9%
remove-double-neg41.9%
+-commutative41.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 77.3%
*-commutative77.3%
unpow277.3%
rem-square-sqrt78.7%
associate-*r*78.7%
metadata-eval78.7%
*-lft-identity78.7%
Simplified78.7%
Final simplification50.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re 9.2e+70) (sqrt (* im_m 0.5)) (sqrt re)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= 9.2e+70) {
tmp = sqrt((im_m * 0.5));
} else {
tmp = 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 <= 9.2d+70) then
tmp = sqrt((im_m * 0.5d0))
else
tmp = 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 <= 9.2e+70) {
tmp = Math.sqrt((im_m * 0.5));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= 9.2e+70: tmp = math.sqrt((im_m * 0.5)) else: tmp = math.sqrt(re) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= 9.2e+70) tmp = sqrt(Float64(im_m * 0.5)); else tmp = sqrt(re); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= 9.2e+70) tmp = sqrt((im_m * 0.5)); else tmp = sqrt(re); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, 9.2e+70], N[Sqrt[N[(im$95$m * 0.5), $MachinePrecision]], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq 9.2 \cdot 10^{+70}:\\
\;\;\;\;\sqrt{im\_m \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < 9.19999999999999975e70Initial program 40.3%
sqr-neg40.3%
+-commutative40.3%
sqr-neg40.3%
+-commutative40.3%
distribute-rgt-in40.3%
cancel-sign-sub40.3%
distribute-rgt-out--40.3%
sub-neg40.3%
remove-double-neg40.3%
+-commutative40.3%
hypot-define73.4%
Simplified73.4%
*-commutative73.4%
hypot-define40.3%
+-commutative40.3%
*-commutative40.3%
add-sqr-sqrt40.0%
sqrt-unprod40.3%
*-commutative40.3%
*-commutative40.3%
swap-sqr40.3%
Applied egg-rr73.4%
*-commutative73.4%
associate-*r*73.4%
metadata-eval73.4%
hypot-undefine40.3%
unpow240.3%
unpow240.3%
+-commutative40.3%
unpow240.3%
unpow240.3%
hypot-undefine73.4%
Simplified73.4%
Taylor expanded in re around 0 30.5%
if 9.19999999999999975e70 < re Initial program 41.9%
sqr-neg41.9%
+-commutative41.9%
sqr-neg41.9%
+-commutative41.9%
distribute-rgt-in41.9%
cancel-sign-sub41.9%
distribute-rgt-out--41.9%
sub-neg41.9%
remove-double-neg41.9%
+-commutative41.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 77.3%
*-commutative77.3%
unpow277.3%
rem-square-sqrt78.7%
associate-*r*78.7%
metadata-eval78.7%
*-lft-identity78.7%
Simplified78.7%
Final simplification41.1%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (sqrt re))
im_m = fabs(im);
double code(double re, double im_m) {
return sqrt(re);
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = sqrt(re)
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return Math.sqrt(re);
}
im_m = math.fabs(im) def code(re, im_m): return math.sqrt(re)
im_m = abs(im) function code(re, im_m) return sqrt(re) end
im_m = abs(im); function tmp = code(re, im_m) tmp = sqrt(re); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[Sqrt[re], $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\sqrt{re}
\end{array}
Initial program 40.6%
sqr-neg40.6%
+-commutative40.6%
sqr-neg40.6%
+-commutative40.6%
distribute-rgt-in40.6%
cancel-sign-sub40.6%
distribute-rgt-out--40.6%
sub-neg40.6%
remove-double-neg40.6%
+-commutative40.6%
hypot-define79.2%
Simplified79.2%
Taylor expanded in re around inf 23.6%
*-commutative23.6%
unpow223.6%
rem-square-sqrt24.1%
associate-*r*24.1%
metadata-eval24.1%
*-lft-identity24.1%
Simplified24.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 2024078
(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)))))