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

(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
(FPCore (x y z) :precision binary64 (fma x (- z y) y))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
double code(double x, double y, double z) {
return fma(x, (z - y), y);
}
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function code(x, y, z) return fma(x, Float64(z - y), y) end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(x * N[(z - y), $MachinePrecision] + y), $MachinePrecision]
\left(1 - x\right) \cdot y + x \cdot z
\mathsf{fma}\left(x, z - y, y\right)
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 97.7% |
|---|---|
| Target | 100.0% |
| Herbie | 100.0% |
Initial program 96.8%
Simplified100.0%
[Start]96.8% | \[ \left(1 - x\right) \cdot y + x \cdot z
\] |
|---|---|
sub-neg [=>]96.8% | \[ \color{blue}{\left(1 + \left(-x\right)\right)} \cdot y + x \cdot z
\] |
+-commutative [=>]96.8% | \[ \color{blue}{\left(\left(-x\right) + 1\right)} \cdot y + x \cdot z
\] |
distribute-rgt1-in [<=]96.9% | \[ \color{blue}{\left(y + \left(-x\right) \cdot y\right)} + x \cdot z
\] |
associate-+l+ [=>]96.9% | \[ \color{blue}{y + \left(\left(-x\right) \cdot y + x \cdot z\right)}
\] |
+-commutative [=>]96.9% | \[ \color{blue}{\left(\left(-x\right) \cdot y + x \cdot z\right) + y}
\] |
*-commutative [=>]96.9% | \[ \left(\color{blue}{y \cdot \left(-x\right)} + x \cdot z\right) + y
\] |
neg-mul-1 [=>]96.9% | \[ \left(y \cdot \color{blue}{\left(-1 \cdot x\right)} + x \cdot z\right) + y
\] |
associate-*r* [=>]96.9% | \[ \left(\color{blue}{\left(y \cdot -1\right) \cdot x} + x \cdot z\right) + y
\] |
*-commutative [=>]96.9% | \[ \left(\left(y \cdot -1\right) \cdot x + \color{blue}{z \cdot x}\right) + y
\] |
distribute-rgt-out [=>]100.0% | \[ \color{blue}{x \cdot \left(y \cdot -1 + z\right)} + y
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(x, y \cdot -1 + z, y\right)}
\] |
+-commutative [=>]100.0% | \[ \mathsf{fma}\left(x, \color{blue}{z + y \cdot -1}, y\right)
\] |
*-commutative [=>]100.0% | \[ \mathsf{fma}\left(x, z + \color{blue}{-1 \cdot y}, y\right)
\] |
neg-mul-1 [<=]100.0% | \[ \mathsf{fma}\left(x, z + \color{blue}{\left(-y\right)}, y\right)
\] |
unsub-neg [=>]100.0% | \[ \mathsf{fma}\left(x, \color{blue}{z - y}, y\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6720 |
| Alternative 2 | |
|---|---|
| Accuracy | 60.7% |
| Cost | 1313 |
| Alternative 3 | |
|---|---|
| Accuracy | 84.7% |
| Cost | 585 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 585 |
| Alternative 5 | |
|---|---|
| Accuracy | 61.6% |
| Cost | 456 |
| Alternative 6 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 448 |
| Alternative 7 | |
|---|---|
| Accuracy | 35.2% |
| Cost | 64 |
herbie shell --seed 2023243
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:herbie-target
(- y (* x (- y z)))
(+ (* (- 1.0 x) y) (* x z)))