
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
def code(x): return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
function code(x) return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x)))))) end
function tmp = code(x) tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x))))); end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
def code(x): return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
function code(x) return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x)))))) end
function tmp = code(x) tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x))))); end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\end{array}
(FPCore (x)
:precision binary64
(if (<= (hypot 1.0 x) 1.0002)
(fma (* x 0.125) x (* -0.0859375 (pow x 4.0)))
(/
(*
(/
(- 0.25 (pow (/ 0.015625 (pow (hypot 1.0 x) 6.0)) 0.3333333333333333))
(+ 0.125 (/ 0.125 (pow (hypot 1.0 x) 3.0))))
(+ 0.25 (- (/ 0.25 (+ 1.0 (* x x))) (/ 0.25 (hypot 1.0 x)))))
(+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.0002) {
tmp = fma((x * 0.125), x, (-0.0859375 * pow(x, 4.0)));
} else {
tmp = (((0.25 - pow((0.015625 / pow(hypot(1.0, x), 6.0)), 0.3333333333333333)) / (0.125 + (0.125 / pow(hypot(1.0, x), 3.0)))) * (0.25 + ((0.25 / (1.0 + (x * x))) - (0.25 / hypot(1.0, x))))) / (1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x)))));
}
return tmp;
}
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 1.0002) tmp = fma(Float64(x * 0.125), x, Float64(-0.0859375 * (x ^ 4.0))); else tmp = Float64(Float64(Float64(Float64(0.25 - (Float64(0.015625 / (hypot(1.0, x) ^ 6.0)) ^ 0.3333333333333333)) / Float64(0.125 + Float64(0.125 / (hypot(1.0, x) ^ 3.0)))) * Float64(0.25 + Float64(Float64(0.25 / Float64(1.0 + Float64(x * x))) - Float64(0.25 / hypot(1.0, x))))) / Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x)))))); end return tmp end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0002], N[(N[(x * 0.125), $MachinePrecision] * x + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.25 - N[Power[N[(0.015625 / N[Power[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 6.0], $MachinePrecision]), $MachinePrecision], 0.3333333333333333], $MachinePrecision]), $MachinePrecision] / N[(0.125 + N[(0.125 / N[Power[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.25 + N[(N[(0.25 / N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.25 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0002:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.25 - {\left(\frac{0.015625}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{6}}\right)}^{0.3333333333333333}}{0.125 + \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}} \cdot \left(0.25 + \left(\frac{0.25}{1 + x \cdot x} - \frac{0.25}{\mathsf{hypot}\left(1, x\right)}\right)\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1.0002Initial program 48.1%
distribute-lft-in48.1%
metadata-eval48.1%
associate-*r/48.1%
metadata-eval48.1%
Simplified48.1%
Taylor expanded in x around 0 99.9%
fma-def99.9%
unpow299.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
associate-*r*100.0%
fma-def100.0%
Applied egg-rr100.0%
if 1.0002 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
flip--98.3%
metadata-eval98.3%
add-sqr-sqrt99.8%
associate--r+99.8%
metadata-eval99.8%
Applied egg-rr99.8%
flip--99.8%
flip3-+99.8%
associate-/r/99.8%
Applied egg-rr99.8%
unpow299.8%
+-commutative99.8%
unpow299.8%
associate--l+99.8%
unpow299.8%
+-commutative99.8%
unpow299.8%
Simplified99.8%
add-cbrt-cube99.8%
pow1/399.9%
pow399.9%
cube-div99.9%
metadata-eval99.9%
add-sqr-sqrt99.9%
+-commutative99.9%
hypot-1-def99.9%
+-commutative99.9%
hypot-1-def99.9%
pow-prod-down99.9%
pow-prod-up99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ 0.5 (/ 0.5 (hypot 1.0 x)))))
(if (<= (hypot 1.0 x) 1.0002)
(fma (* x 0.125) x (* -0.0859375 (pow x 4.0)))
(/
(/
(-
0.25
(pow (/ 0.000244140625 (pow (hypot 1.0 x) 12.0)) 0.16666666666666666))
t_0)
(+ 1.0 (sqrt t_0))))))
double code(double x) {
double t_0 = 0.5 + (0.5 / hypot(1.0, x));
double tmp;
if (hypot(1.0, x) <= 1.0002) {
tmp = fma((x * 0.125), x, (-0.0859375 * pow(x, 4.0)));
} else {
tmp = ((0.25 - pow((0.000244140625 / pow(hypot(1.0, x), 12.0)), 0.16666666666666666)) / t_0) / (1.0 + sqrt(t_0));
}
return tmp;
}
function code(x) t_0 = Float64(0.5 + Float64(0.5 / hypot(1.0, x))) tmp = 0.0 if (hypot(1.0, x) <= 1.0002) tmp = fma(Float64(x * 0.125), x, Float64(-0.0859375 * (x ^ 4.0))); else tmp = Float64(Float64(Float64(0.25 - (Float64(0.000244140625 / (hypot(1.0, x) ^ 12.0)) ^ 0.16666666666666666)) / t_0) / Float64(1.0 + sqrt(t_0))); end return tmp end
code[x_] := Block[{t$95$0 = N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0002], N[(N[(x * 0.125), $MachinePrecision] * x + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.25 - N[Power[N[(0.000244140625 / N[Power[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 12.0], $MachinePrecision]), $MachinePrecision], 0.16666666666666666], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] / N[(1.0 + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0002:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.25 - {\left(\frac{0.000244140625}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{12}}\right)}^{0.16666666666666666}}{t_0}}{1 + \sqrt{t_0}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1.0002Initial program 48.1%
distribute-lft-in48.1%
metadata-eval48.1%
associate-*r/48.1%
metadata-eval48.1%
Simplified48.1%
Taylor expanded in x around 0 99.9%
fma-def99.9%
unpow299.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
associate-*r*100.0%
fma-def100.0%
Applied egg-rr100.0%
if 1.0002 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
flip--98.3%
metadata-eval98.3%
add-sqr-sqrt99.8%
associate--r+99.8%
metadata-eval99.8%
Applied egg-rr99.8%
flip--99.8%
metadata-eval99.8%
frac-times99.8%
metadata-eval99.8%
hypot-udef99.8%
hypot-udef99.8%
add-sqr-sqrt99.8%
metadata-eval99.8%
Applied egg-rr99.8%
add-cbrt-cube99.8%
pow1/399.9%
pow399.9%
cube-div99.9%
metadata-eval99.9%
metadata-eval99.9%
sqrt-pow299.9%
hypot-1-def99.9%
sqr-pow99.8%
pow-prod-down99.9%
frac-times99.9%
metadata-eval99.9%
pow-prod-up99.9%
metadata-eval99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(if (<= (hypot 1.0 x) 1.0002)
(fma (* x 0.125) x (* -0.0859375 (pow x 4.0)))
(*
(/ 1.0 (+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))
(+ 0.5 (cbrt (/ -0.125 (pow (hypot 1.0 x) 3.0)))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.0002) {
tmp = fma((x * 0.125), x, (-0.0859375 * pow(x, 4.0)));
} else {
tmp = (1.0 / (1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x)))))) * (0.5 + cbrt((-0.125 / pow(hypot(1.0, x), 3.0))));
}
return tmp;
}
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 1.0002) tmp = fma(Float64(x * 0.125), x, Float64(-0.0859375 * (x ^ 4.0))); else tmp = Float64(Float64(1.0 / Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x)))))) * Float64(0.5 + cbrt(Float64(-0.125 / (hypot(1.0, x) ^ 3.0))))); end return tmp end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0002], N[(N[(x * 0.125), $MachinePrecision] * x + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[Power[N[(-0.125 / N[Power[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0002:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}} \cdot \left(0.5 + \sqrt[3]{\frac{-0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}\right)\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1.0002Initial program 48.1%
distribute-lft-in48.1%
metadata-eval48.1%
associate-*r/48.1%
metadata-eval48.1%
Simplified48.1%
Taylor expanded in x around 0 99.9%
fma-def99.9%
unpow299.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
associate-*r*100.0%
fma-def100.0%
Applied egg-rr100.0%
if 1.0002 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
flip--98.3%
metadata-eval98.3%
add-sqr-sqrt99.8%
associate--r+99.8%
metadata-eval99.8%
Applied egg-rr99.8%
clear-num99.8%
associate-/r/99.8%
sub-neg99.8%
distribute-neg-frac99.8%
metadata-eval99.8%
Applied egg-rr99.8%
add-cbrt-cube99.9%
pow1/363.1%
pow363.1%
cube-div63.9%
metadata-eval63.9%
Applied egg-rr63.9%
unpow1/399.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 0.5 (hypot 1.0 x))))
(if (<= (hypot 1.0 x) 1.0002)
(fma (* x 0.125) x (* -0.0859375 (pow x 4.0)))
(/ (- 0.5 t_0) (+ 1.0 (sqrt (+ 0.5 t_0)))))))
double code(double x) {
double t_0 = 0.5 / hypot(1.0, x);
double tmp;
if (hypot(1.0, x) <= 1.0002) {
tmp = fma((x * 0.125), x, (-0.0859375 * pow(x, 4.0)));
} else {
tmp = (0.5 - t_0) / (1.0 + sqrt((0.5 + t_0)));
}
return tmp;
}
function code(x) t_0 = Float64(0.5 / hypot(1.0, x)) tmp = 0.0 if (hypot(1.0, x) <= 1.0002) tmp = fma(Float64(x * 0.125), x, Float64(-0.0859375 * (x ^ 4.0))); else tmp = Float64(Float64(0.5 - t_0) / Float64(1.0 + sqrt(Float64(0.5 + t_0)))); end return tmp end
code[x_] := Block[{t$95$0 = N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0002], N[(N[(x * 0.125), $MachinePrecision] * x + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 - t$95$0), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0002:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 - t_0}{1 + \sqrt{0.5 + t_0}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1.0002Initial program 48.1%
distribute-lft-in48.1%
metadata-eval48.1%
associate-*r/48.1%
metadata-eval48.1%
Simplified48.1%
Taylor expanded in x around 0 99.9%
fma-def99.9%
unpow299.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
associate-*r*100.0%
fma-def100.0%
Applied egg-rr100.0%
if 1.0002 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
flip--98.3%
metadata-eval98.3%
add-sqr-sqrt99.8%
associate--r+99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= (hypot 1.0 x) 1.0002) (+ (* -0.0859375 (pow x 4.0)) (* 0.125 (* x x))) (- 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x)))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.0002) {
tmp = (-0.0859375 * pow(x, 4.0)) + (0.125 * (x * x));
} else {
tmp = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.hypot(1.0, x) <= 1.0002) {
tmp = (-0.0859375 * Math.pow(x, 4.0)) + (0.125 * (x * x));
} else {
tmp = 1.0 - Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, x))));
}
return tmp;
}
def code(x): tmp = 0 if math.hypot(1.0, x) <= 1.0002: tmp = (-0.0859375 * math.pow(x, 4.0)) + (0.125 * (x * x)) else: tmp = 1.0 - math.sqrt((0.5 + (0.5 / math.hypot(1.0, x)))) return tmp
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 1.0002) tmp = Float64(Float64(-0.0859375 * (x ^ 4.0)) + Float64(0.125 * Float64(x * x))); else tmp = Float64(1.0 - sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (hypot(1.0, x) <= 1.0002) tmp = (-0.0859375 * (x ^ 4.0)) + (0.125 * (x * x)); else tmp = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0002], N[(N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.125 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0002:\\
\;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1.0002Initial program 48.1%
distribute-lft-in48.1%
metadata-eval48.1%
associate-*r/48.1%
metadata-eval48.1%
Simplified48.1%
Taylor expanded in x around 0 99.9%
fma-def99.9%
unpow299.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
if 1.0002 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (<= (hypot 1.0 x) 1.0002) (fma (* x 0.125) x (* -0.0859375 (pow x 4.0))) (- 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x)))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.0002) {
tmp = fma((x * 0.125), x, (-0.0859375 * pow(x, 4.0)));
} else {
tmp = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x))));
}
return tmp;
}
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 1.0002) tmp = fma(Float64(x * 0.125), x, Float64(-0.0859375 * (x ^ 4.0))); else tmp = Float64(1.0 - sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x))))); end return tmp end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0002], N[(N[(x * 0.125), $MachinePrecision] * x + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.0002:\\
\;\;\;\;\mathsf{fma}\left(x \cdot 0.125, x, -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1.0002Initial program 48.1%
distribute-lft-in48.1%
metadata-eval48.1%
associate-*r/48.1%
metadata-eval48.1%
Simplified48.1%
Taylor expanded in x around 0 99.9%
fma-def99.9%
unpow299.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
associate-*r*100.0%
fma-def100.0%
Applied egg-rr100.0%
if 1.0002 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (<= (hypot 1.0 x) 2.0) (+ (* -0.0859375 (pow x 4.0)) (* 0.125 (* x x))) (/ (+ 0.5 (/ 0.5 x)) (+ 1.0 (sqrt (+ 0.5 (/ -0.5 x)))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 2.0) {
tmp = (-0.0859375 * pow(x, 4.0)) + (0.125 * (x * x));
} else {
tmp = (0.5 + (0.5 / x)) / (1.0 + sqrt((0.5 + (-0.5 / x))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.hypot(1.0, x) <= 2.0) {
tmp = (-0.0859375 * Math.pow(x, 4.0)) + (0.125 * (x * x));
} else {
tmp = (0.5 + (0.5 / x)) / (1.0 + Math.sqrt((0.5 + (-0.5 / x))));
}
return tmp;
}
def code(x): tmp = 0 if math.hypot(1.0, x) <= 2.0: tmp = (-0.0859375 * math.pow(x, 4.0)) + (0.125 * (x * x)) else: tmp = (0.5 + (0.5 / x)) / (1.0 + math.sqrt((0.5 + (-0.5 / x)))) return tmp
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 2.0) tmp = Float64(Float64(-0.0859375 * (x ^ 4.0)) + Float64(0.125 * Float64(x * x))); else tmp = Float64(Float64(0.5 + Float64(0.5 / x)) / Float64(1.0 + sqrt(Float64(0.5 + Float64(-0.5 / x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (hypot(1.0, x) <= 2.0) tmp = (-0.0859375 * (x ^ 4.0)) + (0.125 * (x * x)); else tmp = (0.5 + (0.5 / x)) / (1.0 + sqrt((0.5 + (-0.5 / x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 2.0], N[(N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.125 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + N[(0.5 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 2:\\
\;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 + \frac{0.5}{x}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 2Initial program 48.7%
distribute-lft-in48.7%
metadata-eval48.7%
associate-*r/48.7%
metadata-eval48.7%
Simplified48.7%
Taylor expanded in x around 0 99.1%
fma-def99.1%
unpow299.1%
Simplified99.1%
fma-udef99.1%
Applied egg-rr99.1%
if 2 < (hypot.f64 1 x) Initial program 98.5%
distribute-lft-in98.5%
metadata-eval98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in x around -inf 97.5%
associate-*r/97.5%
metadata-eval97.5%
Simplified97.5%
flip--97.5%
div-inv97.5%
metadata-eval97.5%
add-sqr-sqrt99.0%
associate--r-99.0%
metadata-eval99.0%
sub-neg99.0%
distribute-neg-frac99.0%
metadata-eval99.0%
Applied egg-rr99.0%
associate-*r/99.0%
*-rgt-identity99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (<= (hypot 1.0 x) 2.0) (+ (* -0.0859375 (pow x 4.0)) (* 0.125 (* x x))) (/ 0.5 (+ 1.0 (sqrt 0.5)))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 2.0) {
tmp = (-0.0859375 * pow(x, 4.0)) + (0.125 * (x * x));
} else {
tmp = 0.5 / (1.0 + sqrt(0.5));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.hypot(1.0, x) <= 2.0) {
tmp = (-0.0859375 * Math.pow(x, 4.0)) + (0.125 * (x * x));
} else {
tmp = 0.5 / (1.0 + Math.sqrt(0.5));
}
return tmp;
}
def code(x): tmp = 0 if math.hypot(1.0, x) <= 2.0: tmp = (-0.0859375 * math.pow(x, 4.0)) + (0.125 * (x * x)) else: tmp = 0.5 / (1.0 + math.sqrt(0.5)) return tmp
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 2.0) tmp = Float64(Float64(-0.0859375 * (x ^ 4.0)) + Float64(0.125 * Float64(x * x))); else tmp = Float64(0.5 / Float64(1.0 + sqrt(0.5))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (hypot(1.0, x) <= 2.0) tmp = (-0.0859375 * (x ^ 4.0)) + (0.125 * (x * x)); else tmp = 0.5 / (1.0 + sqrt(0.5)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 2.0], N[(N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.125 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(1.0 + N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 2:\\
\;\;\;\;-0.0859375 \cdot {x}^{4} + 0.125 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 2Initial program 48.7%
distribute-lft-in48.7%
metadata-eval48.7%
associate-*r/48.7%
metadata-eval48.7%
Simplified48.7%
Taylor expanded in x around 0 99.1%
fma-def99.1%
unpow299.1%
Simplified99.1%
fma-udef99.1%
Applied egg-rr99.1%
if 2 < (hypot.f64 1 x) Initial program 98.5%
distribute-lft-in98.5%
metadata-eval98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
flip--98.5%
metadata-eval98.5%
add-sqr-sqrt100.0%
associate--r+100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.1%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (<= (hypot 1.0 x) 2.0) (* x (* x 0.125)) (/ 0.5 (+ 1.0 (sqrt 0.5)))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 2.0) {
tmp = x * (x * 0.125);
} else {
tmp = 0.5 / (1.0 + sqrt(0.5));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.hypot(1.0, x) <= 2.0) {
tmp = x * (x * 0.125);
} else {
tmp = 0.5 / (1.0 + Math.sqrt(0.5));
}
return tmp;
}
def code(x): tmp = 0 if math.hypot(1.0, x) <= 2.0: tmp = x * (x * 0.125) else: tmp = 0.5 / (1.0 + math.sqrt(0.5)) return tmp
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 2.0) tmp = Float64(x * Float64(x * 0.125)); else tmp = Float64(0.5 / Float64(1.0 + sqrt(0.5))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (hypot(1.0, x) <= 2.0) tmp = x * (x * 0.125); else tmp = 0.5 / (1.0 + sqrt(0.5)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 2.0], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(1.0 + N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 2:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 2Initial program 48.7%
distribute-lft-in48.7%
metadata-eval48.7%
associate-*r/48.7%
metadata-eval48.7%
Simplified48.7%
flip--48.7%
metadata-eval48.7%
add-sqr-sqrt48.8%
associate--r+48.8%
metadata-eval48.8%
Applied egg-rr48.8%
Taylor expanded in x around 0 98.1%
*-commutative98.1%
unpow298.1%
associate-*l*98.1%
Simplified98.1%
if 2 < (hypot.f64 1 x) Initial program 98.5%
distribute-lft-in98.5%
metadata-eval98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
flip--98.5%
metadata-eval98.5%
add-sqr-sqrt100.0%
associate--r+100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 98.1%
Final simplification98.1%
(FPCore (x) :precision binary64 (if (or (<= x -1.55) (not (<= x 1.5))) (- 1.0 (sqrt 0.5)) (* x (* x 0.125))))
double code(double x) {
double tmp;
if ((x <= -1.55) || !(x <= 1.5)) {
tmp = 1.0 - sqrt(0.5);
} else {
tmp = x * (x * 0.125);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.55d0)) .or. (.not. (x <= 1.5d0))) then
tmp = 1.0d0 - sqrt(0.5d0)
else
tmp = x * (x * 0.125d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.55) || !(x <= 1.5)) {
tmp = 1.0 - Math.sqrt(0.5);
} else {
tmp = x * (x * 0.125);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.55) or not (x <= 1.5): tmp = 1.0 - math.sqrt(0.5) else: tmp = x * (x * 0.125) return tmp
function code(x) tmp = 0.0 if ((x <= -1.55) || !(x <= 1.5)) tmp = Float64(1.0 - sqrt(0.5)); else tmp = Float64(x * Float64(x * 0.125)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.55) || ~((x <= 1.5))) tmp = 1.0 - sqrt(0.5); else tmp = x * (x * 0.125); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.55], N[Not[LessEqual[x, 1.5]], $MachinePrecision]], N[(1.0 - N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \lor \neg \left(x \leq 1.5\right):\\
\;\;\;\;1 - \sqrt{0.5}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\end{array}
\end{array}
if x < -1.55000000000000004 or 1.5 < x Initial program 98.5%
distribute-lft-in98.5%
metadata-eval98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in x around inf 96.6%
if -1.55000000000000004 < x < 1.5Initial program 48.7%
distribute-lft-in48.7%
metadata-eval48.7%
associate-*r/48.7%
metadata-eval48.7%
Simplified48.7%
flip--48.7%
metadata-eval48.7%
add-sqr-sqrt48.8%
associate--r+48.8%
metadata-eval48.8%
Applied egg-rr48.8%
Taylor expanded in x around 0 98.1%
*-commutative98.1%
unpow298.1%
associate-*l*98.1%
Simplified98.1%
Final simplification97.4%
(FPCore (x) :precision binary64 (if (or (<= x -1.25) (not (<= x 1.8))) (+ 0.25 (/ 0.25 x)) (* x (* x 0.125))))
double code(double x) {
double tmp;
if ((x <= -1.25) || !(x <= 1.8)) {
tmp = 0.25 + (0.25 / x);
} else {
tmp = x * (x * 0.125);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.25d0)) .or. (.not. (x <= 1.8d0))) then
tmp = 0.25d0 + (0.25d0 / x)
else
tmp = x * (x * 0.125d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.25) || !(x <= 1.8)) {
tmp = 0.25 + (0.25 / x);
} else {
tmp = x * (x * 0.125);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.25) or not (x <= 1.8): tmp = 0.25 + (0.25 / x) else: tmp = x * (x * 0.125) return tmp
function code(x) tmp = 0.0 if ((x <= -1.25) || !(x <= 1.8)) tmp = Float64(0.25 + Float64(0.25 / x)); else tmp = Float64(x * Float64(x * 0.125)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.25) || ~((x <= 1.8))) tmp = 0.25 + (0.25 / x); else tmp = x * (x * 0.125); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.25], N[Not[LessEqual[x, 1.8]], $MachinePrecision]], N[(0.25 + N[(0.25 / x), $MachinePrecision]), $MachinePrecision], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \lor \neg \left(x \leq 1.8\right):\\
\;\;\;\;0.25 + \frac{0.25}{x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\end{array}
\end{array}
if x < -1.25 or 1.80000000000000004 < x Initial program 98.5%
distribute-lft-in98.5%
metadata-eval98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
flip--98.5%
metadata-eval98.5%
add-sqr-sqrt100.0%
associate--r+100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 22.7%
Taylor expanded in x around -inf 22.7%
associate-*r/22.7%
metadata-eval22.7%
Simplified22.7%
if -1.25 < x < 1.80000000000000004Initial program 48.7%
distribute-lft-in48.7%
metadata-eval48.7%
associate-*r/48.7%
metadata-eval48.7%
Simplified48.7%
flip--48.7%
metadata-eval48.7%
add-sqr-sqrt48.8%
associate--r+48.8%
metadata-eval48.8%
Applied egg-rr48.8%
Taylor expanded in x around 0 98.1%
*-commutative98.1%
unpow298.1%
associate-*l*98.1%
Simplified98.1%
Final simplification62.8%
(FPCore (x) :precision binary64 (* 0.125 (* x x)))
double code(double x) {
return 0.125 * (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.125d0 * (x * x)
end function
public static double code(double x) {
return 0.125 * (x * x);
}
def code(x): return 0.125 * (x * x)
function code(x) return Float64(0.125 * Float64(x * x)) end
function tmp = code(x) tmp = 0.125 * (x * x); end
code[x_] := N[(0.125 * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.125 \cdot \left(x \cdot x\right)
\end{array}
Initial program 72.0%
distribute-lft-in72.0%
metadata-eval72.0%
associate-*r/72.0%
metadata-eval72.0%
Simplified72.0%
Taylor expanded in x around 0 54.1%
unpow254.1%
Simplified54.1%
Final simplification54.1%
(FPCore (x) :precision binary64 (* x (* x 0.125)))
double code(double x) {
return x * (x * 0.125);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * 0.125d0)
end function
public static double code(double x) {
return x * (x * 0.125);
}
def code(x): return x * (x * 0.125)
function code(x) return Float64(x * Float64(x * 0.125)) end
function tmp = code(x) tmp = x * (x * 0.125); end
code[x_] := N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot 0.125\right)
\end{array}
Initial program 72.0%
distribute-lft-in72.0%
metadata-eval72.0%
associate-*r/72.0%
metadata-eval72.0%
Simplified72.0%
flip--72.0%
metadata-eval72.0%
add-sqr-sqrt72.8%
associate--r+72.8%
metadata-eval72.8%
Applied egg-rr72.8%
Taylor expanded in x around 0 54.1%
*-commutative54.1%
unpow254.1%
associate-*l*54.1%
Simplified54.1%
Final simplification54.1%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 72.0%
distribute-lft-in72.0%
metadata-eval72.0%
associate-*r/72.0%
metadata-eval72.0%
Simplified72.0%
Taylor expanded in x around 0 25.9%
Final simplification25.9%
herbie shell --seed 2023240
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))