| Alternative 1 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 19913 |

(FPCore (x y z t a b) :precision binary64 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))
(FPCore (x y z t a b)
:precision binary64
(if (<= a -1.65e-104)
(fma y z (fma a (fma z b t) x))
(if (<= a 1e-16)
(fma z (fma a b y) (fma t a x))
(fma a (+ t (* z b)) (fma y z x)))))double code(double x, double y, double z, double t, double a, double b) {
return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (a <= -1.65e-104) {
tmp = fma(y, z, fma(a, fma(z, b, t), x));
} else if (a <= 1e-16) {
tmp = fma(z, fma(a, b, y), fma(t, a, x));
} else {
tmp = fma(a, (t + (z * b)), fma(y, z, x));
}
return tmp;
}
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x + Float64(y * z)) + Float64(t * a)) + Float64(Float64(a * z) * b)) end
function code(x, y, z, t, a, b) tmp = 0.0 if (a <= -1.65e-104) tmp = fma(y, z, fma(a, fma(z, b, t), x)); elseif (a <= 1e-16) tmp = fma(z, fma(a, b, y), fma(t, a, x)); else tmp = fma(a, Float64(t + Float64(z * b)), fma(y, z, x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(t * a), $MachinePrecision]), $MachinePrecision] + N[(N[(a * z), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[a, -1.65e-104], N[(y * z + N[(a * N[(z * b + t), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1e-16], N[(z * N[(a * b + y), $MachinePrecision] + N[(t * a + x), $MachinePrecision]), $MachinePrecision], N[(a * N[(t + N[(z * b), $MachinePrecision]), $MachinePrecision] + N[(y * z + x), $MachinePrecision]), $MachinePrecision]]]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
\mathbf{if}\;a \leq -1.65 \cdot 10^{-104}:\\
\;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\
\mathbf{elif}\;a \leq 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \mathsf{fma}\left(t, a, x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t + z \cdot b, \mathsf{fma}\left(y, z, x\right)\right)\\
\end{array}
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 92.6% |
|---|---|
| Target | 97.4% |
| Herbie | 98.0% |
if a < -1.65000000000000001e-104Initial program 90.2%
Simplified100.0%
[Start]90.2 | \[ \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\] |
|---|---|
associate-+l+ [=>]90.2 | \[ \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + \left(a \cdot z\right) \cdot b\right)}
\] |
+-commutative [=>]90.2 | \[ \color{blue}{\left(y \cdot z + x\right)} + \left(t \cdot a + \left(a \cdot z\right) \cdot b\right)
\] |
associate-+l+ [=>]90.2 | \[ \color{blue}{y \cdot z + \left(x + \left(t \cdot a + \left(a \cdot z\right) \cdot b\right)\right)}
\] |
fma-def [=>]91.6 | \[ \color{blue}{\mathsf{fma}\left(y, z, x + \left(t \cdot a + \left(a \cdot z\right) \cdot b\right)\right)}
\] |
+-commutative [=>]91.6 | \[ \mathsf{fma}\left(y, z, \color{blue}{\left(t \cdot a + \left(a \cdot z\right) \cdot b\right) + x}\right)
\] |
*-commutative [=>]91.6 | \[ \mathsf{fma}\left(y, z, \left(\color{blue}{a \cdot t} + \left(a \cdot z\right) \cdot b\right) + x\right)
\] |
associate-*l* [=>]93.0 | \[ \mathsf{fma}\left(y, z, \left(a \cdot t + \color{blue}{a \cdot \left(z \cdot b\right)}\right) + x\right)
\] |
distribute-lft-out [=>]100.0 | \[ \mathsf{fma}\left(y, z, \color{blue}{a \cdot \left(t + z \cdot b\right)} + x\right)
\] |
fma-def [=>]100.0 | \[ \mathsf{fma}\left(y, z, \color{blue}{\mathsf{fma}\left(a, t + z \cdot b, x\right)}\right)
\] |
+-commutative [=>]100.0 | \[ \mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \color{blue}{z \cdot b + t}, x\right)\right)
\] |
fma-def [=>]100.0 | \[ \mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \color{blue}{\mathsf{fma}\left(z, b, t\right)}, x\right)\right)
\] |
if -1.65000000000000001e-104 < a < 9.9999999999999998e-17Initial program 96.5%
Simplified100.0%
[Start]96.5 | \[ \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\] |
|---|---|
+-commutative [=>]96.5 | \[ \color{blue}{\left(a \cdot z\right) \cdot b + \left(\left(x + y \cdot z\right) + t \cdot a\right)}
\] |
+-commutative [=>]96.5 | \[ \left(a \cdot z\right) \cdot b + \left(\color{blue}{\left(y \cdot z + x\right)} + t \cdot a\right)
\] |
associate-+l+ [=>]96.5 | \[ \left(a \cdot z\right) \cdot b + \color{blue}{\left(y \cdot z + \left(x + t \cdot a\right)\right)}
\] |
associate-+r+ [=>]96.5 | \[ \color{blue}{\left(\left(a \cdot z\right) \cdot b + y \cdot z\right) + \left(x + t \cdot a\right)}
\] |
*-commutative [=>]96.5 | \[ \left(\color{blue}{\left(z \cdot a\right)} \cdot b + y \cdot z\right) + \left(x + t \cdot a\right)
\] |
associate-*l* [=>]97.3 | \[ \left(\color{blue}{z \cdot \left(a \cdot b\right)} + y \cdot z\right) + \left(x + t \cdot a\right)
\] |
*-commutative [=>]97.3 | \[ \left(z \cdot \left(a \cdot b\right) + \color{blue}{z \cdot y}\right) + \left(x + t \cdot a\right)
\] |
distribute-lft-out [=>]100.0 | \[ \color{blue}{z \cdot \left(a \cdot b + y\right)} + \left(x + t \cdot a\right)
\] |
fma-def [=>]100.0 | \[ \color{blue}{\mathsf{fma}\left(z, a \cdot b + y, x + t \cdot a\right)}
\] |
fma-def [=>]100.0 | \[ \mathsf{fma}\left(z, \color{blue}{\mathsf{fma}\left(a, b, y\right)}, x + t \cdot a\right)
\] |
+-commutative [<=]100.0 | \[ \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \color{blue}{t \cdot a + x}\right)
\] |
fma-def [=>]100.0 | \[ \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), \color{blue}{\mathsf{fma}\left(t, a, x\right)}\right)
\] |
if 9.9999999999999998e-17 < a Initial program 91.7%
Simplified99.9%
[Start]91.7 | \[ \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\] |
|---|---|
associate-+l+ [=>]91.7 | \[ \color{blue}{\left(x + y \cdot z\right) + \left(t \cdot a + \left(a \cdot z\right) \cdot b\right)}
\] |
+-commutative [=>]91.7 | \[ \color{blue}{\left(t \cdot a + \left(a \cdot z\right) \cdot b\right) + \left(x + y \cdot z\right)}
\] |
*-commutative [=>]91.7 | \[ \left(\color{blue}{a \cdot t} + \left(a \cdot z\right) \cdot b\right) + \left(x + y \cdot z\right)
\] |
associate-*l* [=>]97.1 | \[ \left(a \cdot t + \color{blue}{a \cdot \left(z \cdot b\right)}\right) + \left(x + y \cdot z\right)
\] |
distribute-lft-out [=>]99.9 | \[ \color{blue}{a \cdot \left(t + z \cdot b\right)} + \left(x + y \cdot z\right)
\] |
fma-def [=>]99.9 | \[ \color{blue}{\mathsf{fma}\left(a, t + z \cdot b, x + y \cdot z\right)}
\] |
+-commutative [=>]99.9 | \[ \mathsf{fma}\left(a, t + z \cdot b, \color{blue}{y \cdot z + x}\right)
\] |
fma-def [=>]99.9 | \[ \mathsf{fma}\left(a, t + z \cdot b, \color{blue}{\mathsf{fma}\left(y, z, x\right)}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 19913 |
| Alternative 2 | |
|---|---|
| Accuracy | 95.5% |
| Cost | 13640 |
| Alternative 3 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 1988 |
| Alternative 4 | |
|---|---|
| Accuracy | 39.4% |
| Cost | 1772 |
| Alternative 5 | |
|---|---|
| Accuracy | 37.0% |
| Cost | 1640 |
| Alternative 6 | |
|---|---|
| Accuracy | 72.6% |
| Cost | 1240 |
| Alternative 7 | |
|---|---|
| Accuracy | 85.3% |
| Cost | 1105 |
| Alternative 8 | |
|---|---|
| Accuracy | 92.2% |
| Cost | 1092 |
| Alternative 9 | |
|---|---|
| Accuracy | 60.0% |
| Cost | 980 |
| Alternative 10 | |
|---|---|
| Accuracy | 39.3% |
| Cost | 852 |
| Alternative 11 | |
|---|---|
| Accuracy | 58.6% |
| Cost | 849 |
| Alternative 12 | |
|---|---|
| Accuracy | 82.1% |
| Cost | 841 |
| Alternative 13 | |
|---|---|
| Accuracy | 85.6% |
| Cost | 841 |
| Alternative 14 | |
|---|---|
| Accuracy | 73.3% |
| Cost | 713 |
| Alternative 15 | |
|---|---|
| Accuracy | 39.3% |
| Cost | 456 |
| Alternative 16 | |
|---|---|
| Accuracy | 25.9% |
| Cost | 64 |
herbie shell --seed 2023160
(FPCore (x y z t a b)
:name "Graphics.Rasterific.CubicBezier:cachedBezierAt from Rasterific-0.6.1"
:precision binary64
:herbie-target
(if (< z -11820553527347888000.0) (+ (* z (+ (* b a) y)) (+ x (* t a))) (if (< z 4.7589743188364287e-122) (+ (* (+ (* b z) t) a) (+ (* z y) x)) (+ (* z (+ (* b a) y)) (+ x (* t a)))))
(+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))