| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 13248 |
\[\mathsf{fma}\left(z, \frac{y}{-2}, \mathsf{fma}\left(0.125, x, t\right)\right)
\]

(FPCore (x y z t) :precision binary64 (+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))
(FPCore (x y z t) :precision binary64 (fma z (/ y -2.0) (fma 0.125 x t)))
double code(double x, double y, double z, double t) {
return (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t;
}
double code(double x, double y, double z, double t) {
return fma(z, (y / -2.0), fma(0.125, x, t));
}
function code(x, y, z, t) return Float64(Float64(Float64(Float64(1.0 / 8.0) * x) - Float64(Float64(y * z) / 2.0)) + t) end
function code(x, y, z, t) return fma(z, Float64(y / -2.0), fma(0.125, x, t)) end
code[x_, y_, z_, t_] := N[(N[(N[(N[(1.0 / 8.0), $MachinePrecision] * x), $MachinePrecision] - N[(N[(y * z), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := N[(z * N[(y / -2.0), $MachinePrecision] + N[(0.125 * x + t), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t
\mathsf{fma}\left(z, \frac{y}{-2}, \mathsf{fma}\left(0.125, x, t\right)\right)
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 100.0% |
|---|---|
| Target | 100.0% |
| Herbie | 100.0% |
Initial program 100.0%
Simplified100.0%
[Start]100.0% | \[ \left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t
\] |
|---|---|
remove-double-neg [<=]100.0% | \[ \left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + \color{blue}{\left(-\left(-t\right)\right)}
\] |
sub-neg [<=]100.0% | \[ \color{blue}{\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) - \left(-t\right)}
\] |
sub-neg [=>]100.0% | \[ \color{blue}{\left(\frac{1}{8} \cdot x + \left(-\frac{y \cdot z}{2}\right)\right)} - \left(-t\right)
\] |
+-commutative [=>]100.0% | \[ \color{blue}{\left(\left(-\frac{y \cdot z}{2}\right) + \frac{1}{8} \cdot x\right)} - \left(-t\right)
\] |
associate--l+ [=>]100.0% | \[ \color{blue}{\left(-\frac{y \cdot z}{2}\right) + \left(\frac{1}{8} \cdot x - \left(-t\right)\right)}
\] |
*-commutative [=>]100.0% | \[ \left(-\frac{\color{blue}{z \cdot y}}{2}\right) + \left(\frac{1}{8} \cdot x - \left(-t\right)\right)
\] |
associate-*r/ [<=]100.0% | \[ \left(-\color{blue}{z \cdot \frac{y}{2}}\right) + \left(\frac{1}{8} \cdot x - \left(-t\right)\right)
\] |
distribute-rgt-neg-in [=>]100.0% | \[ \color{blue}{z \cdot \left(-\frac{y}{2}\right)} + \left(\frac{1}{8} \cdot x - \left(-t\right)\right)
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(z, -\frac{y}{2}, \frac{1}{8} \cdot x - \left(-t\right)\right)}
\] |
neg-mul-1 [=>]100.0% | \[ \mathsf{fma}\left(z, \color{blue}{-1 \cdot \frac{y}{2}}, \frac{1}{8} \cdot x - \left(-t\right)\right)
\] |
*-commutative [=>]100.0% | \[ \mathsf{fma}\left(z, \color{blue}{\frac{y}{2} \cdot -1}, \frac{1}{8} \cdot x - \left(-t\right)\right)
\] |
associate-*l/ [=>]100.0% | \[ \mathsf{fma}\left(z, \color{blue}{\frac{y \cdot -1}{2}}, \frac{1}{8} \cdot x - \left(-t\right)\right)
\] |
associate-/l* [=>]100.0% | \[ \mathsf{fma}\left(z, \color{blue}{\frac{y}{\frac{2}{-1}}}, \frac{1}{8} \cdot x - \left(-t\right)\right)
\] |
metadata-eval [=>]100.0% | \[ \mathsf{fma}\left(z, \frac{y}{\color{blue}{-2}}, \frac{1}{8} \cdot x - \left(-t\right)\right)
\] |
fma-neg [=>]100.0% | \[ \mathsf{fma}\left(z, \frac{y}{-2}, \color{blue}{\mathsf{fma}\left(\frac{1}{8}, x, -\left(-t\right)\right)}\right)
\] |
remove-double-neg [=>]100.0% | \[ \mathsf{fma}\left(z, \frac{y}{-2}, \mathsf{fma}\left(\frac{1}{8}, x, \color{blue}{t}\right)\right)
\] |
metadata-eval [=>]100.0% | \[ \mathsf{fma}\left(z, \frac{y}{-2}, \mathsf{fma}\left(\color{blue}{0.125}, x, t\right)\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Accuracy | 51.9% |
| Cost | 1116 |
| Alternative 3 | |
|---|---|
| Accuracy | 87.5% |
| Cost | 969 |
| Alternative 4 | |
|---|---|
| Accuracy | 84.1% |
| Cost | 712 |
| Alternative 5 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 704 |
| Alternative 6 | |
|---|---|
| Accuracy | 69.0% |
| Cost | 585 |
| Alternative 7 | |
|---|---|
| Accuracy | 50.0% |
| Cost | 456 |
| Alternative 8 | |
|---|---|
| Accuracy | 33.0% |
| Cost | 64 |
herbie shell --seed 2023243
(FPCore (x y z t)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, B"
:precision binary64
:herbie-target
(- (+ (/ x 8.0) t) (* (/ z 2.0) y))
(+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))