| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 26756 |
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
(FPCore (x)
:precision binary64
(if (<= (hypot 1.0 x) 1.005)
(+
(* 0.125 (pow x 2.0))
(+ (* 0.0673828125 (pow x 6.0)) (* -0.0859375 (pow x 4.0))))
(/
(/
(- 0.125 (/ 0.125 (pow (hypot 1.0 x) 3.0)))
(+ 0.25 (+ (/ 0.25 (fma x x 1.0)) (/ 0.25 (hypot 1.0 x)))))
(+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))))double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.005) {
tmp = (0.125 * pow(x, 2.0)) + ((0.0673828125 * pow(x, 6.0)) + (-0.0859375 * pow(x, 4.0)));
} else {
tmp = ((0.125 - (0.125 / pow(hypot(1.0, x), 3.0))) / (0.25 + ((0.25 / fma(x, x, 1.0)) + (0.25 / hypot(1.0, x))))) / (1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x)))));
}
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) tmp = 0.0 if (hypot(1.0, x) <= 1.005) tmp = Float64(Float64(0.125 * (x ^ 2.0)) + Float64(Float64(0.0673828125 * (x ^ 6.0)) + Float64(-0.0859375 * (x ^ 4.0)))); else tmp = Float64(Float64(Float64(0.125 - Float64(0.125 / (hypot(1.0, x) ^ 3.0))) / Float64(0.25 + Float64(Float64(0.25 / fma(x, x, 1.0)) + 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_] := 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_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.005], N[(N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.0673828125 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.125 - N[(0.125 / N[Power[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(0.25 + N[(N[(0.25 / N[(x * x + 1.0), $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]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1.005:\\
\;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{0.25}{\mathsf{fma}\left(x, x, 1\right)} + \frac{0.25}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\
\end{array}
if (hypot.f64 1 x) < 1.0049999999999999Initial program 53.2%
Simplified53.2%
[Start]53.2 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]53.2 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]53.2 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]53.2 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]53.2 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Taylor expanded in x around 0 99.9%
if 1.0049999999999999 < (hypot.f64 1 x) Initial program 98.5%
Simplified98.5%
[Start]98.5 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]98.5 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]98.5 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]98.5 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]98.5 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Applied egg-rr100.0%
[Start]98.5 | \[ 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}
\] |
|---|---|
flip-- [=>]98.5 | \[ \color{blue}{\frac{1 \cdot 1 - \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)}}}}
\] |
metadata-eval [=>]98.5 | \[ \frac{\color{blue}{1} - \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)}}}
\] |
add-sqr-sqrt [<=]99.9 | \[ \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+ [=>]100.0 | \[ \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 [=>]100.0 | \[ \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-rr99.9%
[Start]100.0 | \[ \frac{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
|---|---|
flip3-- [=>]99.9 | \[ \frac{\color{blue}{\frac{{0.5}^{3} - {\left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}{0.5 \cdot 0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]99.9 | \[ \frac{\frac{\color{blue}{0.125} - {\left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}{0.5 \cdot 0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
cube-div [=>]99.9 | \[ \frac{\frac{0.125 - \color{blue}{\frac{{0.5}^{3}}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}}{0.5 \cdot 0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]99.9 | \[ \frac{\frac{0.125 - \frac{\color{blue}{0.125}}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.5 \cdot 0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{\color{blue}{0.25} + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
frac-times [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\color{blue}{\frac{0.5 \cdot 0.5}{\mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)}} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{\color{blue}{0.25}}{\mathsf{hypot}\left(1, x\right) \cdot \mathsf{hypot}\left(1, x\right)} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
hypot-udef [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{0.25}{\color{blue}{\sqrt{1 \cdot 1 + x \cdot x}} \cdot \mathsf{hypot}\left(1, x\right)} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
hypot-udef [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{0.25}{\sqrt{1 \cdot 1 + x \cdot x} \cdot \color{blue}{\sqrt{1 \cdot 1 + x \cdot x}}} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
add-sqr-sqrt [<=]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{0.25}{\color{blue}{1 \cdot 1 + x \cdot x}} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{0.25}{\color{blue}{1} + x \cdot x} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
+-commutative [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{0.25}{\color{blue}{x \cdot x + 1}} + 0.5 \cdot \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
fma-def [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{0.25}{\color{blue}{\mathsf{fma}\left(x, x, 1\right)}} + 0.5 \cdot \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/ [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{0.25}{\mathsf{fma}\left(x, x, 1\right)} + \color{blue}{\frac{0.5 \cdot 0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]99.9 | \[ \frac{\frac{0.125 - \frac{0.125}{{\left(\mathsf{hypot}\left(1, x\right)\right)}^{3}}}{0.25 + \left(\frac{0.25}{\mathsf{fma}\left(x, x, 1\right)} + \frac{\color{blue}{0.25}}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 26756 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 20360 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 13576 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 7624 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 7496 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 7305 |
| Alternative 7 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 6985 |
| Alternative 8 | |
|---|---|
| Accuracy | 97.6% |
| Cost | 6857 |
| Alternative 9 | |
|---|---|
| Accuracy | 61.6% |
| Cost | 712 |
| Alternative 10 | |
|---|---|
| Accuracy | 61.6% |
| Cost | 712 |
| Alternative 11 | |
|---|---|
| Accuracy | 61.6% |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Accuracy | 61.6% |
| Cost | 584 |
| Alternative 13 | |
|---|---|
| Accuracy | 13.3% |
| Cost | 64 |
herbie shell --seed 2023151
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))