
(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 (<= (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im_m im_m)))))) 0.0) (/ im_m (sqrt (* re -4.0))) (sqrt (* (+ re (hypot re im_m)) 0.5))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (sqrt((2.0 * (re + sqrt(((re * re) + (im_m * im_m)))))) <= 0.0) {
tmp = im_m / sqrt((re * -4.0));
} else {
tmp = sqrt(((re + hypot(re, im_m)) * 0.5));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (Math.sqrt((2.0 * (re + Math.sqrt(((re * re) + (im_m * im_m)))))) <= 0.0) {
tmp = im_m / Math.sqrt((re * -4.0));
} else {
tmp = Math.sqrt(((re + Math.hypot(re, im_m)) * 0.5));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if math.sqrt((2.0 * (re + math.sqrt(((re * re) + (im_m * im_m)))))) <= 0.0: tmp = im_m / math.sqrt((re * -4.0)) else: tmp = math.sqrt(((re + math.hypot(re, im_m)) * 0.5)) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(re + sqrt(Float64(Float64(re * re) + Float64(im_m * im_m)))))) <= 0.0) tmp = Float64(im_m / sqrt(Float64(re * -4.0))); else tmp = sqrt(Float64(Float64(re + hypot(re, im_m)) * 0.5)); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (sqrt((2.0 * (re + sqrt(((re * re) + (im_m * im_m)))))) <= 0.0) tmp = im_m / sqrt((re * -4.0)); else tmp = sqrt(((re + hypot(re, im_m)) * 0.5)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im$95$m * im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(im$95$m / N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[(re + N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im_m \cdot im_m}\right)} \leq 0:\\
\;\;\;\;\frac{im_m}{\sqrt{re \cdot -4}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(re + \mathsf{hypot}\left(re, im_m\right)\right) \cdot 0.5}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 9.8%
sqr-neg9.8%
+-commutative9.8%
sqr-neg9.8%
+-commutative9.8%
distribute-rgt-in9.8%
cancel-sign-sub9.8%
distribute-rgt-out--9.8%
sub-neg9.8%
remove-double-neg9.8%
+-commutative9.8%
hypot-def9.8%
Simplified9.8%
*-commutative9.8%
+-commutative9.8%
hypot-udef9.8%
*-commutative9.8%
add-cbrt-cube9.8%
add-sqr-sqrt9.8%
hypot-udef9.8%
+-commutative9.8%
pow19.8%
pow1/29.8%
Applied egg-rr9.8%
Taylor expanded in re around -inf 42.0%
*-commutative42.0%
associate-*l/42.0%
Simplified42.0%
add-sqr-sqrt41.9%
sqrt-unprod42.0%
*-commutative42.0%
*-commutative42.0%
swap-sqr42.0%
Applied egg-rr50.4%
associate-*l/50.4%
associate-*l*50.4%
metadata-eval50.4%
Simplified50.4%
expm1-log1p-u50.4%
expm1-udef11.9%
associate-/l*11.9%
sqrt-div11.9%
unpow211.9%
sqrt-prod5.5%
add-sqr-sqrt9.7%
div-inv9.7%
metadata-eval9.7%
Applied egg-rr9.7%
expm1-def62.9%
expm1-log1p62.9%
Simplified62.9%
if 0.0 < (sqrt.f64 (*.f64 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 42.7%
sqr-neg42.7%
+-commutative42.7%
sqr-neg42.7%
+-commutative42.7%
distribute-rgt-in42.7%
cancel-sign-sub42.7%
distribute-rgt-out--42.7%
sub-neg42.7%
remove-double-neg42.7%
+-commutative42.7%
hypot-def84.8%
Simplified84.8%
add-sqr-sqrt84.1%
sqrt-unprod84.8%
*-commutative84.8%
*-commutative84.8%
swap-sqr84.8%
add-sqr-sqrt84.8%
*-commutative84.8%
metadata-eval84.8%
Applied egg-rr84.8%
associate-*l*85.3%
metadata-eval85.3%
Simplified85.3%
Final simplification82.0%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (/ im_m (sqrt (* re -4.0)))) (t_1 (sqrt (* im_m 0.5))))
(if (<= re -65000000000.0)
t_0
(if (<= re -3e-22)
t_1
(if (<= re -1.2e-48)
t_0
(if (<= re -1.45e-105)
t_1
(if (<= re -3.5e-153)
t_0
(if (<= re 95000000000000.0)
(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((re * -4.0));
double t_1 = sqrt((im_m * 0.5));
double tmp;
if (re <= -65000000000.0) {
tmp = t_0;
} else if (re <= -3e-22) {
tmp = t_1;
} else if (re <= -1.2e-48) {
tmp = t_0;
} else if (re <= -1.45e-105) {
tmp = t_1;
} else if (re <= -3.5e-153) {
tmp = t_0;
} else if (re <= 95000000000000.0) {
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) :: t_1
real(8) :: tmp
t_0 = im_m / sqrt((re * (-4.0d0)))
t_1 = sqrt((im_m * 0.5d0))
if (re <= (-65000000000.0d0)) then
tmp = t_0
else if (re <= (-3d-22)) then
tmp = t_1
else if (re <= (-1.2d-48)) then
tmp = t_0
else if (re <= (-1.45d-105)) then
tmp = t_1
else if (re <= (-3.5d-153)) then
tmp = t_0
else if (re <= 95000000000000.0d0) 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((re * -4.0));
double t_1 = Math.sqrt((im_m * 0.5));
double tmp;
if (re <= -65000000000.0) {
tmp = t_0;
} else if (re <= -3e-22) {
tmp = t_1;
} else if (re <= -1.2e-48) {
tmp = t_0;
} else if (re <= -1.45e-105) {
tmp = t_1;
} else if (re <= -3.5e-153) {
tmp = t_0;
} else if (re <= 95000000000000.0) {
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((re * -4.0)) t_1 = math.sqrt((im_m * 0.5)) tmp = 0 if re <= -65000000000.0: tmp = t_0 elif re <= -3e-22: tmp = t_1 elif re <= -1.2e-48: tmp = t_0 elif re <= -1.45e-105: tmp = t_1 elif re <= -3.5e-153: tmp = t_0 elif re <= 95000000000000.0: 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(re * -4.0))) t_1 = sqrt(Float64(im_m * 0.5)) tmp = 0.0 if (re <= -65000000000.0) tmp = t_0; elseif (re <= -3e-22) tmp = t_1; elseif (re <= -1.2e-48) tmp = t_0; elseif (re <= -1.45e-105) tmp = t_1; elseif (re <= -3.5e-153) tmp = t_0; elseif (re <= 95000000000000.0) 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((re * -4.0)); t_1 = sqrt((im_m * 0.5)); tmp = 0.0; if (re <= -65000000000.0) tmp = t_0; elseif (re <= -3e-22) tmp = t_1; elseif (re <= -1.2e-48) tmp = t_0; elseif (re <= -1.45e-105) tmp = t_1; elseif (re <= -3.5e-153) tmp = t_0; elseif (re <= 95000000000000.0) 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[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(im$95$m * 0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -65000000000.0], t$95$0, If[LessEqual[re, -3e-22], t$95$1, If[LessEqual[re, -1.2e-48], t$95$0, If[LessEqual[re, -1.45e-105], t$95$1, If[LessEqual[re, -3.5e-153], t$95$0, If[LessEqual[re, 95000000000000.0], 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 := \frac{im_m}{\sqrt{re \cdot -4}}\\
t_1 := \sqrt{im_m \cdot 0.5}\\
\mathbf{if}\;re \leq -65000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -3 \cdot 10^{-22}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -1.2 \cdot 10^{-48}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -1.45 \cdot 10^{-105}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -3.5 \cdot 10^{-153}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 95000000000000:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + im_m\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -6.5e10 or -2.9999999999999999e-22 < re < -1.2e-48 or -1.45000000000000002e-105 < re < -3.49999999999999981e-153Initial program 11.0%
sqr-neg11.0%
+-commutative11.0%
sqr-neg11.0%
+-commutative11.0%
distribute-rgt-in11.0%
cancel-sign-sub11.0%
distribute-rgt-out--11.0%
sub-neg11.0%
remove-double-neg11.0%
+-commutative11.0%
hypot-def33.4%
Simplified33.4%
*-commutative33.4%
+-commutative33.4%
hypot-udef11.0%
*-commutative11.0%
add-cbrt-cube10.9%
add-sqr-sqrt11.0%
hypot-udef10.0%
+-commutative10.0%
pow110.0%
pow1/210.0%
Applied egg-rr21.7%
Taylor expanded in re around -inf 38.5%
*-commutative38.5%
associate-*l/38.5%
Simplified38.5%
add-sqr-sqrt38.5%
sqrt-unprod38.5%
*-commutative38.5%
*-commutative38.5%
swap-sqr38.5%
Applied egg-rr47.1%
associate-*l/47.1%
associate-*l*47.1%
metadata-eval47.1%
Simplified47.1%
expm1-log1p-u46.9%
expm1-udef20.4%
associate-/l*20.4%
sqrt-div20.4%
unpow220.4%
sqrt-prod9.5%
add-sqr-sqrt15.6%
div-inv15.6%
metadata-eval15.6%
Applied egg-rr15.6%
expm1-def49.5%
expm1-log1p49.7%
Simplified49.7%
if -6.5e10 < re < -2.9999999999999999e-22 or -1.2e-48 < re < -1.45000000000000002e-105Initial program 61.0%
sqr-neg61.0%
+-commutative61.0%
sqr-neg61.0%
+-commutative61.0%
distribute-rgt-in61.0%
cancel-sign-sub61.0%
distribute-rgt-out--61.0%
sub-neg61.0%
remove-double-neg61.0%
+-commutative61.0%
hypot-def87.1%
Simplified87.1%
Taylor expanded in re around 0 50.6%
*-commutative50.6%
associate-*l*50.6%
Simplified50.6%
expm1-log1p-u47.7%
expm1-udef46.3%
add-sqr-sqrt46.3%
sqrt-unprod46.3%
swap-sqr46.3%
add-sqr-sqrt46.3%
swap-sqr46.3%
rem-square-sqrt46.3%
metadata-eval46.3%
metadata-eval46.3%
Applied egg-rr46.3%
expm1-def47.8%
expm1-log1p50.9%
Simplified50.9%
if -3.49999999999999981e-153 < re < 9.5e13Initial program 56.2%
sqr-neg56.2%
+-commutative56.2%
sqr-neg56.2%
+-commutative56.2%
distribute-rgt-in56.2%
cancel-sign-sub56.2%
distribute-rgt-out--56.2%
sub-neg56.2%
remove-double-neg56.2%
+-commutative56.2%
hypot-def95.6%
Simplified95.6%
add-sqr-sqrt94.8%
sqrt-unprod95.6%
*-commutative95.6%
*-commutative95.6%
swap-sqr95.6%
add-sqr-sqrt95.6%
*-commutative95.6%
metadata-eval95.6%
Applied egg-rr95.6%
associate-*l*96.7%
metadata-eval96.7%
Simplified96.7%
Taylor expanded in re around 0 35.2%
if 9.5e13 < re Initial program 43.9%
sqr-neg43.9%
+-commutative43.9%
sqr-neg43.9%
+-commutative43.9%
distribute-rgt-in43.9%
cancel-sign-sub43.9%
distribute-rgt-out--43.9%
sub-neg43.9%
remove-double-neg43.9%
+-commutative43.9%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 80.3%
*-commutative80.3%
unpow280.3%
rem-square-sqrt82.0%
associate-*r*82.0%
metadata-eval82.0%
*-lft-identity82.0%
Simplified82.0%
Final simplification52.2%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= re 1.6e-119)
(sqrt (* im_m 0.5))
(if (or (<= re 1.65e-71) (not (<= re 1.2e+15)))
(sqrt re)
(sqrt (* 0.5 (+ re im_m))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= 1.6e-119) {
tmp = sqrt((im_m * 0.5));
} else if ((re <= 1.65e-71) || !(re <= 1.2e+15)) {
tmp = sqrt(re);
} else {
tmp = sqrt((0.5 * (re + im_m)));
}
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 <= 1.6d-119) then
tmp = sqrt((im_m * 0.5d0))
else if ((re <= 1.65d-71) .or. (.not. (re <= 1.2d+15))) then
tmp = sqrt(re)
else
tmp = sqrt((0.5d0 * (re + im_m)))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= 1.6e-119) {
tmp = Math.sqrt((im_m * 0.5));
} else if ((re <= 1.65e-71) || !(re <= 1.2e+15)) {
tmp = Math.sqrt(re);
} else {
tmp = Math.sqrt((0.5 * (re + im_m)));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= 1.6e-119: tmp = math.sqrt((im_m * 0.5)) elif (re <= 1.65e-71) or not (re <= 1.2e+15): tmp = math.sqrt(re) else: tmp = math.sqrt((0.5 * (re + im_m))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= 1.6e-119) tmp = sqrt(Float64(im_m * 0.5)); elseif ((re <= 1.65e-71) || !(re <= 1.2e+15)) tmp = sqrt(re); else tmp = sqrt(Float64(0.5 * Float64(re + im_m))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= 1.6e-119) tmp = sqrt((im_m * 0.5)); elseif ((re <= 1.65e-71) || ~((re <= 1.2e+15))) tmp = sqrt(re); else tmp = sqrt((0.5 * (re + im_m))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, 1.6e-119], N[Sqrt[N[(im$95$m * 0.5), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[re, 1.65e-71], N[Not[LessEqual[re, 1.2e+15]], $MachinePrecision]], N[Sqrt[re], $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.6 \cdot 10^{-119}:\\
\;\;\;\;\sqrt{im_m \cdot 0.5}\\
\mathbf{elif}\;re \leq 1.65 \cdot 10^{-71} \lor \neg \left(re \leq 1.2 \cdot 10^{+15}\right):\\
\;\;\;\;\sqrt{re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + im_m\right)}\\
\end{array}
\end{array}
if re < 1.59999999999999997e-119Initial program 31.7%
sqr-neg31.7%
+-commutative31.7%
sqr-neg31.7%
+-commutative31.7%
distribute-rgt-in31.7%
cancel-sign-sub31.7%
distribute-rgt-out--31.7%
sub-neg31.7%
remove-double-neg31.7%
+-commutative31.7%
hypot-def62.6%
Simplified62.6%
Taylor expanded in re around 0 26.4%
*-commutative26.4%
associate-*l*26.4%
Simplified26.4%
expm1-log1p-u25.0%
expm1-udef22.7%
add-sqr-sqrt22.7%
sqrt-unprod22.7%
swap-sqr22.7%
add-sqr-sqrt22.7%
swap-sqr22.7%
rem-square-sqrt22.7%
metadata-eval22.7%
metadata-eval22.7%
Applied egg-rr22.7%
expm1-def25.1%
expm1-log1p26.6%
Simplified26.6%
if 1.59999999999999997e-119 < re < 1.6500000000000001e-71 or 1.2e15 < re Initial program 48.5%
sqr-neg48.5%
+-commutative48.5%
sqr-neg48.5%
+-commutative48.5%
distribute-rgt-in48.5%
cancel-sign-sub48.5%
distribute-rgt-out--48.5%
sub-neg48.5%
remove-double-neg48.5%
+-commutative48.5%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 80.8%
*-commutative80.8%
unpow280.8%
rem-square-sqrt82.4%
associate-*r*82.4%
metadata-eval82.4%
*-lft-identity82.4%
Simplified82.4%
if 1.6500000000000001e-71 < re < 1.2e15Initial program 70.5%
sqr-neg70.5%
+-commutative70.5%
sqr-neg70.5%
+-commutative70.5%
distribute-rgt-in70.5%
cancel-sign-sub70.5%
distribute-rgt-out--70.5%
sub-neg70.5%
remove-double-neg70.5%
+-commutative70.5%
hypot-def100.0%
Simplified100.0%
add-sqr-sqrt99.5%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
*-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-*l*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 21.6%
Final simplification40.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (or (<= re 1.6e-119) (and (not (<= re 5.3e-71)) (<= re 460.0))) (sqrt (* im_m 0.5)) (sqrt re)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if ((re <= 1.6e-119) || (!(re <= 5.3e-71) && (re <= 460.0))) {
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 <= 1.6d-119) .or. (.not. (re <= 5.3d-71)) .and. (re <= 460.0d0)) 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 <= 1.6e-119) || (!(re <= 5.3e-71) && (re <= 460.0))) {
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 <= 1.6e-119) or (not (re <= 5.3e-71) and (re <= 460.0)): 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 <= 1.6e-119) || (!(re <= 5.3e-71) && (re <= 460.0))) 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 <= 1.6e-119) || (~((re <= 5.3e-71)) && (re <= 460.0))) 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[Or[LessEqual[re, 1.6e-119], And[N[Not[LessEqual[re, 5.3e-71]], $MachinePrecision], LessEqual[re, 460.0]]], 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 1.6 \cdot 10^{-119} \lor \neg \left(re \leq 5.3 \cdot 10^{-71}\right) \land re \leq 460:\\
\;\;\;\;\sqrt{im_m \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < 1.59999999999999997e-119 or 5.29999999999999999e-71 < re < 460Initial program 33.6%
sqr-neg33.6%
+-commutative33.6%
sqr-neg33.6%
+-commutative33.6%
distribute-rgt-in33.6%
cancel-sign-sub33.6%
distribute-rgt-out--33.6%
sub-neg33.6%
remove-double-neg33.6%
+-commutative33.6%
hypot-def64.8%
Simplified64.8%
Taylor expanded in re around 0 25.5%
*-commutative25.5%
associate-*l*25.5%
Simplified25.5%
expm1-log1p-u24.1%
expm1-udef21.9%
add-sqr-sqrt21.9%
sqrt-unprod21.9%
swap-sqr21.9%
add-sqr-sqrt21.9%
swap-sqr21.9%
rem-square-sqrt21.9%
metadata-eval21.9%
metadata-eval21.9%
Applied egg-rr21.9%
expm1-def24.1%
expm1-log1p25.6%
Simplified25.6%
if 1.59999999999999997e-119 < re < 5.29999999999999999e-71 or 460 < re Initial program 50.0%
sqr-neg50.0%
+-commutative50.0%
sqr-neg50.0%
+-commutative50.0%
distribute-rgt-in50.0%
cancel-sign-sub50.0%
distribute-rgt-out--50.0%
sub-neg50.0%
remove-double-neg50.0%
+-commutative50.0%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 80.0%
*-commutative80.0%
unpow280.0%
rem-square-sqrt81.6%
associate-*r*81.6%
metadata-eval81.6%
*-lft-identity81.6%
Simplified81.6%
Final simplification40.3%
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 37.9%
sqr-neg37.9%
+-commutative37.9%
sqr-neg37.9%
+-commutative37.9%
distribute-rgt-in37.9%
cancel-sign-sub37.9%
distribute-rgt-out--37.9%
sub-neg37.9%
remove-double-neg37.9%
+-commutative37.9%
hypot-def74.0%
Simplified74.0%
Taylor expanded in im around 0 23.9%
*-commutative23.9%
unpow223.9%
rem-square-sqrt24.3%
associate-*r*24.3%
metadata-eval24.3%
*-lft-identity24.3%
Simplified24.3%
Final simplification24.3%
(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 2023319
(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)))))