| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6848 |
\[\mathsf{fma}\left(y, y, x \cdot \left(x + 2\right)\right)
\]

(FPCore (x y) :precision binary64 (+ (+ (* x 2.0) (* x x)) (* y y)))
(FPCore (x y) :precision binary64 (fma y y (* x (+ x 2.0))))
double code(double x, double y) {
return ((x * 2.0) + (x * x)) + (y * y);
}
double code(double x, double y) {
return fma(y, y, (x * (x + 2.0)));
}
function code(x, y) return Float64(Float64(Float64(x * 2.0) + Float64(x * x)) + Float64(y * y)) end
function code(x, y) return fma(y, y, Float64(x * Float64(x + 2.0))) end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(y * y + N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot 2 + x \cdot x\right) + y \cdot y
\mathsf{fma}\left(y, y, x \cdot \left(x + 2\right)\right)
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 100.0% |
|---|---|
| Target | 100.0% |
| Herbie | 100.0% |
Initial program 100.0%
Simplified100.0%
[Start]100.0% | \[ \left(x \cdot 2 + x \cdot x\right) + y \cdot y
\] |
|---|---|
distribute-lft-out [=>]100.0% | \[ \color{blue}{x \cdot \left(2 + x\right)} + y \cdot y
\] |
Applied egg-rr100.0%
[Start]100.0% | \[ x \cdot \left(2 + x\right) + y \cdot y
\] |
|---|---|
+-commutative [=>]100.0% | \[ \color{blue}{y \cdot y + x \cdot \left(2 + x\right)}
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(y, y, x \cdot \left(2 + x\right)\right)}
\] |
+-commutative [=>]100.0% | \[ \mathsf{fma}\left(y, y, x \cdot \color{blue}{\left(x + 2\right)}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6848 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 713 |
| Alternative 3 | |
|---|---|
| Accuracy | 96.3% |
| Cost | 708 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 580 |
| Alternative 5 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 576 |
| Alternative 6 | |
|---|---|
| Accuracy | 72.6% |
| Cost | 456 |
| Alternative 7 | |
|---|---|
| Accuracy | 42.1% |
| Cost | 192 |
herbie shell --seed 2023249
(FPCore (x y)
:name "Numeric.Log:$clog1p from log-domain-0.10.2.1, A"
:precision binary64
:herbie-target
(+ (* y y) (+ (* 2.0 x) (* x x)))
(+ (+ (* x 2.0) (* x x)) (* y y)))