| Alternative 1 | |
|---|---|
| Error | 0.21% |
| Cost | 6848 |
\[\mathsf{fma}\left(x, x, 3 \cdot \left(y \cdot y\right)\right)
\]
(FPCore (x y) :precision binary64 (+ (+ (+ (* x x) (* y y)) (* y y)) (* y y)))
(FPCore (x y) :precision binary64 (fma y y (fma x x (* y (+ y y)))))
double code(double x, double y) {
return (((x * x) + (y * y)) + (y * y)) + (y * y);
}
double code(double x, double y) {
return fma(y, y, fma(x, x, (y * (y + y))));
}
function code(x, y) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(y * y)) + Float64(y * y)) end
function code(x, y) return fma(y, y, fma(x, x, Float64(y * Float64(y + y)))) end
code[x_, y_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(y * y + N[(x * x + N[(y * N[(y + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, y \cdot \left(y + y\right)\right)\right)
| Original | 0.22% |
|---|---|
| Target | 0.2% |
| Herbie | 0.09% |
Initial program 0.22
Simplified0.09
[Start]0.22 | \[ \left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\] |
|---|---|
+-commutative [=>]0.22 | \[ \color{blue}{y \cdot y + \left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right)}
\] |
fma-def [=>]0.1 | \[ \color{blue}{\mathsf{fma}\left(y, y, \left(x \cdot x + y \cdot y\right) + y \cdot y\right)}
\] |
associate-+l+ [=>]0.09 | \[ \mathsf{fma}\left(y, y, \color{blue}{x \cdot x + \left(y \cdot y + y \cdot y\right)}\right)
\] |
fma-def [=>]0.09 | \[ \mathsf{fma}\left(y, y, \color{blue}{\mathsf{fma}\left(x, x, y \cdot y + y \cdot y\right)}\right)
\] |
distribute-lft-out [=>]0.09 | \[ \mathsf{fma}\left(y, y, \mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y + y\right)}\right)\right)
\] |
Final simplification0.09
| Alternative 1 | |
|---|---|
| Error | 0.21% |
| Cost | 6848 |
| Alternative 2 | |
|---|---|
| Error | 19.94% |
| Cost | 1241 |
| Alternative 3 | |
|---|---|
| Error | 0.22% |
| Cost | 960 |
| Alternative 4 | |
|---|---|
| Error | 20.63% |
| Cost | 850 |
| Alternative 5 | |
|---|---|
| Error | 20.67% |
| Cost | 848 |
| Alternative 6 | |
|---|---|
| Error | 0.22% |
| Cost | 576 |
| Alternative 7 | |
|---|---|
| Error | 41.31% |
| Cost | 456 |
| Alternative 8 | |
|---|---|
| Error | 43.46% |
| Cost | 192 |
herbie shell --seed 2023090
(FPCore (x y)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, E"
:precision binary64
:herbie-target
(+ (* x x) (* y (+ y (+ y y))))
(+ (+ (+ (* x x) (* y y)) (* y y)) (* y y)))