| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 47236 |
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
(FPCore (x)
:precision binary64
(let* ((t_0 (pow (hypot 1.0 x) 3.0))
(t_1 (+ 0.5 (/ -0.5 (hypot 1.0 x))))
(t_2 (+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x)))))))
(if (<= x -0.00215)
(/
t_1
(+
1.0
(sqrt
(/
(+ 0.015625 (/ -0.015625 (* t_0 t_0)))
(*
(+ 0.125 (/ -0.125 t_0))
(+ (/ 0.25 (+ 1.0 (* x x))) (+ 0.25 (/ -0.25 (hypot 1.0 x)))))))))
(if (<= x 0.0018)
(/ (fma 0.25 (* x x) (* -0.1875 (pow x 4.0))) t_2)
(/ (pow (pow t_1 3.0) 0.3333333333333333) t_2)))))double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
double code(double x) {
double t_0 = pow(hypot(1.0, x), 3.0);
double t_1 = 0.5 + (-0.5 / hypot(1.0, x));
double t_2 = 1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x))));
double tmp;
if (x <= -0.00215) {
tmp = t_1 / (1.0 + sqrt(((0.015625 + (-0.015625 / (t_0 * t_0))) / ((0.125 + (-0.125 / t_0)) * ((0.25 / (1.0 + (x * x))) + (0.25 + (-0.25 / hypot(1.0, x))))))));
} else if (x <= 0.0018) {
tmp = fma(0.25, (x * x), (-0.1875 * pow(x, 4.0))) / t_2;
} else {
tmp = pow(pow(t_1, 3.0), 0.3333333333333333) / t_2;
}
return tmp;
}
function code(x) return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x)))))) end
function code(x) t_0 = hypot(1.0, x) ^ 3.0 t_1 = Float64(0.5 + Float64(-0.5 / hypot(1.0, x))) t_2 = Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x))))) tmp = 0.0 if (x <= -0.00215) tmp = Float64(t_1 / Float64(1.0 + sqrt(Float64(Float64(0.015625 + Float64(-0.015625 / Float64(t_0 * t_0))) / Float64(Float64(0.125 + Float64(-0.125 / t_0)) * Float64(Float64(0.25 / Float64(1.0 + Float64(x * x))) + Float64(0.25 + Float64(-0.25 / hypot(1.0, x))))))))); elseif (x <= 0.0018) tmp = Float64(fma(0.25, Float64(x * x), Float64(-0.1875 * (x ^ 4.0))) / t_2); else tmp = Float64(((t_1 ^ 3.0) ^ 0.3333333333333333) / t_2); end return tmp 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]
code[x_] := Block[{t$95$0 = N[Power[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 3.0], $MachinePrecision]}, Block[{t$95$1 = N[(0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.00215], N[(t$95$1 / N[(1.0 + N[Sqrt[N[(N[(0.015625 + N[(-0.015625 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(0.125 + N[(-0.125 / t$95$0), $MachinePrecision]), $MachinePrecision] * N[(N[(0.25 / N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.25 + N[(-0.25 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0018], N[(N[(0.25 * N[(x * x), $MachinePrecision] + N[(-0.1875 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision], N[(N[Power[N[Power[t$95$1, 3.0], $MachinePrecision], 0.3333333333333333], $MachinePrecision] / t$95$2), $MachinePrecision]]]]]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
t_0 := {\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}\\
t_1 := 0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\\
t_2 := 1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
\mathbf{if}\;x \leq -0.00215:\\
\;\;\;\;\frac{t_1}{1 + \sqrt{\frac{0.015625 + \frac{-0.015625}{t_0 \cdot t_0}}{\left(0.125 + \frac{-0.125}{t_0}\right) \cdot \left(\frac{0.25}{1 + x \cdot x} + \left(0.25 + \frac{-0.25}{\mathsf{hypot}\left(1, x\right)}\right)\right)}}}\\
\mathbf{elif}\;x \leq 0.0018:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.25, x \cdot x, -0.1875 \cdot {x}^{4}\right)}{t_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\left({t_1}^{3}\right)}^{0.3333333333333333}}{t_2}\\
\end{array}
if x < -0.00215Initial program 1.0
Simplified1.0
[Start]1.0 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]1.0 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]1.0 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]1.0 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]1.0 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Applied egg-rr1.0
Simplified0.1
[Start]1.0 | \[ \frac{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
|---|---|
sqr-neg [=>]1.0 | \[ \frac{1 - \color{blue}{\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
rem-square-sqrt [=>]0.1 | \[ \frac{1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
associate--r+ [=>]0.1 | \[ \frac{\color{blue}{\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]0.1 | \[ \frac{\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
Applied egg-rr0.1
Simplified0.1
[Start]0.1 | \[ \frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{\frac{0.015625 - \frac{\frac{0.015625}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{\left(\frac{0.25}{1 + x \cdot x} + \left(0.25 - \frac{0.25}{\mathsf{hypot}\left(1, x\right)}\right)\right) \cdot \left(0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}\right)}}}
\] |
|---|---|
associate-/l/ [=>]0.1 | \[ \frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{\frac{0.015625 - \color{blue}{\frac{0.015625}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3} \cdot {\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}}{\left(\frac{0.25}{1 + x \cdot x} + \left(0.25 - \frac{0.25}{\mathsf{hypot}\left(1, x\right)}\right)\right) \cdot \left(0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}\right)}}}
\] |
*-commutative [=>]0.1 | \[ \frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{\frac{0.015625 - \frac{0.015625}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3} \cdot {\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{\color{blue}{\left(0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}\right) \cdot \left(\frac{0.25}{1 + x \cdot x} + \left(0.25 - \frac{0.25}{\mathsf{hypot}\left(1, x\right)}\right)\right)}}}}
\] |
+-commutative [=>]0.1 | \[ \frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{\frac{0.015625 - \frac{0.015625}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3} \cdot {\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{\left(0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}\right) \cdot \left(\frac{0.25}{\color{blue}{x \cdot x + 1}} + \left(0.25 - \frac{0.25}{\mathsf{hypot}\left(1, x\right)}\right)\right)}}}
\] |
if -0.00215 < x < 0.0018Initial program 30.3
Simplified30.3
[Start]30.3 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]30.3 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]30.3 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]30.3 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]30.3 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Applied egg-rr30.3
Simplified30.2
[Start]30.3 | \[ \frac{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
|---|---|
sqr-neg [=>]30.3 | \[ \frac{1 - \color{blue}{\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
rem-square-sqrt [=>]30.3 | \[ \frac{1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
associate--r+ [=>]30.2 | \[ \frac{\color{blue}{\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]30.2 | \[ \frac{\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
Taylor expanded in x around 0 0.0
Simplified0.0
[Start]0.0 | \[ \frac{0.25 \cdot {x}^{2} + -0.1875 \cdot {x}^{4}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
|---|---|
fma-def [=>]0.0 | \[ \frac{\color{blue}{\mathsf{fma}\left(0.25, {x}^{2}, -0.1875 \cdot {x}^{4}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
unpow2 [=>]0.0 | \[ \frac{\mathsf{fma}\left(0.25, \color{blue}{x \cdot x}, -0.1875 \cdot {x}^{4}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
if 0.0018 < x Initial program 1.0
Simplified1.0
[Start]1.0 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]1.0 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]1.0 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]1.0 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]1.0 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Applied egg-rr1.1
Simplified0.1
[Start]1.1 | \[ \frac{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
|---|---|
sqr-neg [=>]1.1 | \[ \frac{1 - \color{blue}{\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
rem-square-sqrt [=>]0.1 | \[ \frac{1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
associate--r+ [=>]0.1 | \[ \frac{\color{blue}{\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]0.1 | \[ \frac{\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
Applied egg-rr0.1
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 47236 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 39684 |
| Alternative 3 | |
|---|---|
| Error | 0.1 |
| Cost | 33284 |
| Alternative 4 | |
|---|---|
| Error | 0.1 |
| Cost | 26756 |
| Alternative 5 | |
|---|---|
| Error | 0.6 |
| Cost | 19908 |
| Alternative 6 | |
|---|---|
| Error | 0.5 |
| Cost | 13960 |
| Alternative 7 | |
|---|---|
| Error | 0.8 |
| Cost | 13316 |
| Alternative 8 | |
|---|---|
| Error | 0.6 |
| Cost | 7364 |
| Alternative 9 | |
|---|---|
| Error | 1.3 |
| Cost | 6857 |
| Alternative 10 | |
|---|---|
| Error | 24.8 |
| Cost | 968 |
| Alternative 11 | |
|---|---|
| Error | 24.9 |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Error | 24.9 |
| Cost | 584 |
| Alternative 13 | |
|---|---|
| Error | 39.9 |
| Cost | 328 |
| Alternative 14 | |
|---|---|
| Error | 46.4 |
| Cost | 64 |
herbie shell --seed 2023016
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))