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

(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
(FPCore (x y) :precision binary64 (fma x (- 1.0 y) y))
double code(double x, double y) {
return (x + y) - (x * y);
}
double code(double x, double y) {
return fma(x, (1.0 - y), y);
}
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function code(x, y) return fma(x, Float64(1.0 - y), y) end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(x * N[(1.0 - y), $MachinePrecision] + y), $MachinePrecision]
\left(x + y\right) - x \cdot y
\begin{array}{l}
\\
\mathsf{fma}\left(x, 1 - y, y\right)
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 100.0%
Simplified100.0%
[Start]100.0% | \[ \left(x + y\right) - x \cdot y
\] |
|---|---|
+-commutative [=>]100.0% | \[ \color{blue}{\left(y + x\right)} - x \cdot y
\] |
associate--l+ [=>]100.0% | \[ \color{blue}{y + \left(x - x \cdot y\right)}
\] |
+-commutative [=>]100.0% | \[ \color{blue}{\left(x - x \cdot y\right) + y}
\] |
*-rgt-identity [<=]100.0% | \[ \left(\color{blue}{x \cdot 1} - x \cdot y\right) + y
\] |
distribute-lft-out-- [=>]100.0% | \[ \color{blue}{x \cdot \left(1 - y\right)} + y
\] |
unsub-neg [<=]100.0% | \[ x \cdot \color{blue}{\left(1 + \left(-y\right)\right)} + y
\] |
+-commutative [<=]100.0% | \[ x \cdot \color{blue}{\left(\left(-y\right) + 1\right)} + y
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(x, \left(-y\right) + 1, y\right)}
\] |
+-commutative [=>]100.0% | \[ \mathsf{fma}\left(x, \color{blue}{1 + \left(-y\right)}, y\right)
\] |
unsub-neg [=>]100.0% | \[ \mathsf{fma}\left(x, \color{blue}{1 - y}, y\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6720 |
| Alternative 2 | |
|---|---|
| Accuracy | 62.0% |
| Cost | 1180 |
| Alternative 3 | |
|---|---|
| Accuracy | 71.2% |
| Cost | 584 |
| Alternative 4 | |
|---|---|
| Accuracy | 71.6% |
| Cost | 452 |
| Alternative 5 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 448 |
| Alternative 6 | |
|---|---|
| Accuracy | 47.4% |
| Cost | 196 |
| Alternative 7 | |
|---|---|
| Accuracy | 37.5% |
| Cost | 64 |
herbie shell --seed 2023167
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))