| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 13248 |
\[\mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 4\right), x\right)
\]

(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
(FPCore (x y z) :precision binary64 (fma (- y x) (fma z -6.0 4.0) x))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
double code(double x, double y, double z) {
return fma((y - x), fma(z, -6.0, 4.0), x);
}
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function code(x, y, z) return fma(Float64(y - x), fma(z, -6.0, 4.0), x) end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(z * -6.0 + 4.0), $MachinePrecision] + x), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 4\right), x\right)
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 99.5%
Simplified99.8%
[Start]99.5% | \[ x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\] |
|---|---|
+-commutative [=>]99.5% | \[ \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) + x}
\] |
associate-*l* [=>]99.7% | \[ \color{blue}{\left(y - x\right) \cdot \left(6 \cdot \left(\frac{2}{3} - z\right)\right)} + x
\] |
fma-def [=>]99.7% | \[ \color{blue}{\mathsf{fma}\left(y - x, 6 \cdot \left(\frac{2}{3} - z\right), x\right)}
\] |
sub-neg [=>]99.7% | \[ \mathsf{fma}\left(y - x, 6 \cdot \color{blue}{\left(\frac{2}{3} + \left(-z\right)\right)}, x\right)
\] |
+-commutative [=>]99.7% | \[ \mathsf{fma}\left(y - x, 6 \cdot \color{blue}{\left(\left(-z\right) + \frac{2}{3}\right)}, x\right)
\] |
distribute-lft-in [=>]99.8% | \[ \mathsf{fma}\left(y - x, \color{blue}{6 \cdot \left(-z\right) + 6 \cdot \frac{2}{3}}, x\right)
\] |
neg-mul-1 [=>]99.8% | \[ \mathsf{fma}\left(y - x, 6 \cdot \color{blue}{\left(-1 \cdot z\right)} + 6 \cdot \frac{2}{3}, x\right)
\] |
associate-*r* [=>]99.8% | \[ \mathsf{fma}\left(y - x, \color{blue}{\left(6 \cdot -1\right) \cdot z} + 6 \cdot \frac{2}{3}, x\right)
\] |
*-commutative [=>]99.8% | \[ \mathsf{fma}\left(y - x, \color{blue}{z \cdot \left(6 \cdot -1\right)} + 6 \cdot \frac{2}{3}, x\right)
\] |
fma-def [=>]99.8% | \[ \mathsf{fma}\left(y - x, \color{blue}{\mathsf{fma}\left(z, 6 \cdot -1, 6 \cdot \frac{2}{3}\right)}, x\right)
\] |
metadata-eval [=>]99.8% | \[ \mathsf{fma}\left(y - x, \mathsf{fma}\left(z, \color{blue}{-6}, 6 \cdot \frac{2}{3}\right), x\right)
\] |
metadata-eval [=>]99.8% | \[ \mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 6 \cdot \color{blue}{0.6666666666666666}\right), x\right)
\] |
metadata-eval [=>]99.8% | \[ \mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, \color{blue}{4}\right), x\right)
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 1240 |
| Alternative 3 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 1240 |
| Alternative 4 | |
|---|---|
| Accuracy | 74.2% |
| Cost | 1240 |
| Alternative 5 | |
|---|---|
| Accuracy | 51.5% |
| Cost | 1112 |
| Alternative 6 | |
|---|---|
| Accuracy | 51.5% |
| Cost | 1112 |
| Alternative 7 | |
|---|---|
| Accuracy | 50.8% |
| Cost | 1112 |
| Alternative 8 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 960 |
| Alternative 9 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 840 |
| Alternative 10 | |
|---|---|
| Accuracy | 74.6% |
| Cost | 713 |
| Alternative 11 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 713 |
| Alternative 12 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 704 |
| Alternative 13 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 704 |
| Alternative 14 | |
|---|---|
| Accuracy | 37.5% |
| Cost | 456 |
| Alternative 15 | |
|---|---|
| Accuracy | 25.4% |
| Cost | 192 |
| Alternative 16 | |
|---|---|
| Accuracy | 2.6% |
| Cost | 64 |
herbie shell --seed 2023272
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, D"
:precision binary64
(+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))