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

(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
(FPCore (x y z) :precision binary64 (fma x (+ y 0.5) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
double code(double x, double y, double z) {
return fma(x, (y + 0.5), z);
}
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function code(x, y, z) return fma(x, Float64(y + 0.5), z) end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
code[x_, y_, z_] := N[(x * N[(y + 0.5), $MachinePrecision] + z), $MachinePrecision]
\left(\frac{x}{2} + y \cdot x\right) + z
\mathsf{fma}\left(x, y + 0.5, z\right)
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 100.0%
Simplified100.0%
[Start]100.0% | \[ \left(\frac{x}{2} + y \cdot x\right) + z
\] |
|---|---|
associate-+l+ [=>]100.0% | \[ \color{blue}{\frac{x}{2} + \left(y \cdot x + z\right)}
\] |
*-commutative [=>]100.0% | \[ \frac{x}{2} + \left(\color{blue}{x \cdot y} + z\right)
\] |
Taylor expanded in x around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ z + \left(0.5 + y\right) \cdot x
\] |
|---|---|
+-commutative [=>]100.0% | \[ \color{blue}{\left(0.5 + y\right) \cdot x + z}
\] |
*-commutative [=>]100.0% | \[ \color{blue}{x \cdot \left(0.5 + y\right)} + z
\] |
fma-udef [<=]100.0% | \[ \color{blue}{\mathsf{fma}\left(x, 0.5 + y, z\right)}
\] |
+-commutative [=>]100.0% | \[ \mathsf{fma}\left(x, \color{blue}{y + 0.5}, z\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6720 |
| Alternative 2 | |
|---|---|
| Accuracy | 60.2% |
| Cost | 1116 |
| Alternative 3 | |
|---|---|
| Accuracy | 73.4% |
| Cost | 849 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.6% |
| Cost | 585 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 585 |
| Alternative 6 | |
|---|---|
| Accuracy | 48.9% |
| Cost | 456 |
| Alternative 7 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 448 |
| Alternative 8 | |
|---|---|
| Accuracy | 41.1% |
| Cost | 64 |
herbie shell --seed 2023272
(FPCore (x y z)
:name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
:precision binary64
(+ (+ (/ x 2.0) (* y x)) z))