| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 7492 |
(FPCore (x y z t a b) :precision binary64 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))
(FPCore (x y z t a b) :precision binary64 (if (<= (* y 9.0) -3.2e-182) (fma x 2.0 (fma y (* t (* z -9.0)) (* (* a 27.0) b))) (fma t (* -9.0 (* y z)) (fma x 2.0 (* 27.0 (* a b))))))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((y * 9.0) <= -3.2e-182) {
tmp = fma(x, 2.0, fma(y, (t * (z * -9.0)), ((a * 27.0) * b)));
} else {
tmp = fma(t, (-9.0 * (y * z)), fma(x, 2.0, (27.0 * (a * b))));
}
return tmp;
}
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + Float64(Float64(a * 27.0) * b)) end
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(y * 9.0) <= -3.2e-182) tmp = fma(x, 2.0, fma(y, Float64(t * Float64(z * -9.0)), Float64(Float64(a * 27.0) * b))); else tmp = fma(t, Float64(-9.0 * Float64(y * z)), fma(x, 2.0, Float64(27.0 * Float64(a * b)))); end return tmp end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(y * 9.0), $MachinePrecision], -3.2e-182], N[(x * 2.0 + N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(-9.0 * N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0 + N[(27.0 * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\begin{array}{l}
\mathbf{if}\;y \cdot 9 \leq -3.2 \cdot 10^{-182}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), \left(a \cdot 27\right) \cdot b\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, -9 \cdot \left(y \cdot z\right), \mathsf{fma}\left(x, 2, 27 \cdot \left(a \cdot b\right)\right)\right)\\
\end{array}
| Original | 3.0 |
|---|---|
| Target | 3.4 |
| Herbie | 1.2 |
if (*.f64 y 9) < -3.20000000000000002e-182Initial program 3.7
Simplified1.3
[Start]3.7 | \[ \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\] |
|---|---|
associate-+l- [=>]3.7 | \[ \color{blue}{x \cdot 2 - \left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)}
\] |
fma-neg [=>]3.7 | \[ \color{blue}{\mathsf{fma}\left(x, 2, -\left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)\right)}
\] |
neg-sub0 [=>]3.7 | \[ \mathsf{fma}\left(x, 2, \color{blue}{0 - \left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)}\right)
\] |
associate-+l- [<=]3.7 | \[ \mathsf{fma}\left(x, 2, \color{blue}{\left(0 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b}\right)
\] |
neg-sub0 [<=]3.7 | \[ \mathsf{fma}\left(x, 2, \color{blue}{\left(-\left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)} + \left(a \cdot 27\right) \cdot b\right)
\] |
*-commutative [=>]3.7 | \[ \mathsf{fma}\left(x, 2, \left(-\color{blue}{t \cdot \left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b\right)
\] |
distribute-lft-neg-in [=>]3.7 | \[ \mathsf{fma}\left(x, 2, \color{blue}{\left(-t\right) \cdot \left(\left(y \cdot 9\right) \cdot z\right)} + \left(a \cdot 27\right) \cdot b\right)
\] |
associate-*l* [=>]3.6 | \[ \mathsf{fma}\left(x, 2, \left(-t\right) \cdot \color{blue}{\left(y \cdot \left(9 \cdot z\right)\right)} + \left(a \cdot 27\right) \cdot b\right)
\] |
*-commutative [=>]3.6 | \[ \mathsf{fma}\left(x, 2, \left(-t\right) \cdot \color{blue}{\left(\left(9 \cdot z\right) \cdot y\right)} + \left(a \cdot 27\right) \cdot b\right)
\] |
associate-*r* [=>]1.3 | \[ \mathsf{fma}\left(x, 2, \color{blue}{\left(\left(-t\right) \cdot \left(9 \cdot z\right)\right) \cdot y} + \left(a \cdot 27\right) \cdot b\right)
\] |
*-commutative [=>]1.3 | \[ \mathsf{fma}\left(x, 2, \color{blue}{y \cdot \left(\left(-t\right) \cdot \left(9 \cdot z\right)\right)} + \left(a \cdot 27\right) \cdot b\right)
\] |
fma-def [=>]1.3 | \[ \mathsf{fma}\left(x, 2, \color{blue}{\mathsf{fma}\left(y, \left(-t\right) \cdot \left(9 \cdot z\right), \left(a \cdot 27\right) \cdot b\right)}\right)
\] |
distribute-lft-neg-in [<=]1.3 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, \color{blue}{-t \cdot \left(9 \cdot z\right)}, \left(a \cdot 27\right) \cdot b\right)\right)
\] |
distribute-rgt-neg-in [=>]1.3 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, \color{blue}{t \cdot \left(-9 \cdot z\right)}, \left(a \cdot 27\right) \cdot b\right)\right)
\] |
*-commutative [=>]1.3 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(-\color{blue}{z \cdot 9}\right), \left(a \cdot 27\right) \cdot b\right)\right)
\] |
distribute-rgt-neg-in [=>]1.3 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \color{blue}{\left(z \cdot \left(-9\right)\right)}, \left(a \cdot 27\right) \cdot b\right)\right)
\] |
metadata-eval [=>]1.3 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot \color{blue}{-9}\right), \left(a \cdot 27\right) \cdot b\right)\right)
\] |
if -3.20000000000000002e-182 < (*.f64 y 9) Initial program 0.9
Simplified0.8
[Start]0.9 | \[ \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\] |
|---|---|
sub-neg [=>]0.9 | \[ \color{blue}{\left(x \cdot 2 + \left(-\left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)\right)} + \left(a \cdot 27\right) \cdot b
\] |
+-commutative [=>]0.9 | \[ \color{blue}{\left(\left(-\left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + x \cdot 2\right)} + \left(a \cdot 27\right) \cdot b
\] |
associate-+l+ [=>]0.9 | \[ \color{blue}{\left(-\left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(x \cdot 2 + \left(a \cdot 27\right) \cdot b\right)}
\] |
distribute-lft-neg-in [=>]0.9 | \[ \color{blue}{\left(-\left(y \cdot 9\right) \cdot z\right) \cdot t} + \left(x \cdot 2 + \left(a \cdot 27\right) \cdot b\right)
\] |
+-commutative [<=]0.9 | \[ \left(-\left(y \cdot 9\right) \cdot z\right) \cdot t + \color{blue}{\left(\left(a \cdot 27\right) \cdot b + x \cdot 2\right)}
\] |
*-commutative [=>]0.9 | \[ \color{blue}{t \cdot \left(-\left(y \cdot 9\right) \cdot z\right)} + \left(\left(a \cdot 27\right) \cdot b + x \cdot 2\right)
\] |
fma-def [=>]0.9 | \[ \color{blue}{\mathsf{fma}\left(t, -\left(y \cdot 9\right) \cdot z, \left(a \cdot 27\right) \cdot b + x \cdot 2\right)}
\] |
*-commutative [=>]0.9 | \[ \mathsf{fma}\left(t, -\color{blue}{\left(9 \cdot y\right)} \cdot z, \left(a \cdot 27\right) \cdot b + x \cdot 2\right)
\] |
associate-*l* [=>]0.9 | \[ \mathsf{fma}\left(t, -\color{blue}{9 \cdot \left(y \cdot z\right)}, \left(a \cdot 27\right) \cdot b + x \cdot 2\right)
\] |
*-commutative [=>]0.9 | \[ \mathsf{fma}\left(t, -\color{blue}{\left(y \cdot z\right) \cdot 9}, \left(a \cdot 27\right) \cdot b + x \cdot 2\right)
\] |
distribute-rgt-neg-in [=>]0.9 | \[ \mathsf{fma}\left(t, \color{blue}{\left(y \cdot z\right) \cdot \left(-9\right)}, \left(a \cdot 27\right) \cdot b + x \cdot 2\right)
\] |
metadata-eval [=>]0.9 | \[ \mathsf{fma}\left(t, \left(y \cdot z\right) \cdot \color{blue}{-9}, \left(a \cdot 27\right) \cdot b + x \cdot 2\right)
\] |
+-commutative [=>]0.9 | \[ \mathsf{fma}\left(t, \left(y \cdot z\right) \cdot -9, \color{blue}{x \cdot 2 + \left(a \cdot 27\right) \cdot b}\right)
\] |
fma-def [=>]0.9 | \[ \mathsf{fma}\left(t, \left(y \cdot z\right) \cdot -9, \color{blue}{\mathsf{fma}\left(x, 2, \left(a \cdot 27\right) \cdot b\right)}\right)
\] |
*-commutative [=>]0.9 | \[ \mathsf{fma}\left(t, \left(y \cdot z\right) \cdot -9, \mathsf{fma}\left(x, 2, \color{blue}{\left(27 \cdot a\right)} \cdot b\right)\right)
\] |
associate-*l* [=>]0.8 | \[ \mathsf{fma}\left(t, \left(y \cdot z\right) \cdot -9, \mathsf{fma}\left(x, 2, \color{blue}{27 \cdot \left(a \cdot b\right)}\right)\right)
\] |
Final simplification1.2
| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 7492 |
| Alternative 2 | |
|---|---|
| Error | 10.7 |
| Cost | 2257 |
| Alternative 3 | |
|---|---|
| Error | 10.6 |
| Cost | 2257 |
| Alternative 4 | |
|---|---|
| Error | 1.6 |
| Cost | 1220 |
| Alternative 5 | |
|---|---|
| Error | 0.7 |
| Cost | 1220 |
| Alternative 6 | |
|---|---|
| Error | 0.7 |
| Cost | 1220 |
| Alternative 7 | |
|---|---|
| Error | 28.5 |
| Cost | 1112 |
| Alternative 8 | |
|---|---|
| Error | 28.5 |
| Cost | 1112 |
| Alternative 9 | |
|---|---|
| Error | 18.9 |
| Cost | 1105 |
| Alternative 10 | |
|---|---|
| Error | 18.9 |
| Cost | 1104 |
| Alternative 11 | |
|---|---|
| Error | 28.1 |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Error | 37.3 |
| Cost | 192 |
herbie shell --seed 2022354
(FPCore (x y z t a b)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, A"
:precision binary64
:herbie-target
(if (< y 7.590524218811189e-161) (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* a (* 27.0 b))) (+ (- (* x 2.0) (* 9.0 (* y (* t z)))) (* (* a 27.0) b)))
(+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))