| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 13892 |
(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) -5e+57) (fma x 2.0 (fma y (* t (* z -9.0)) (* (* a 27.0) b))) (fma 2.0 x (fma a (* 27.0 b) (* z (* t (* y -9.0)))))))
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) <= -5e+57) {
tmp = fma(x, 2.0, fma(y, (t * (z * -9.0)), ((a * 27.0) * b)));
} else {
tmp = fma(2.0, x, fma(a, (27.0 * b), (z * (t * (y * -9.0)))));
}
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) <= -5e+57) tmp = fma(x, 2.0, fma(y, Float64(t * Float64(z * -9.0)), Float64(Float64(a * 27.0) * b))); else tmp = fma(2.0, x, fma(a, Float64(27.0 * b), Float64(z * Float64(t * Float64(y * -9.0))))); 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], -5e+57], 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[(2.0 * x + N[(a * N[(27.0 * b), $MachinePrecision] + N[(z * N[(t * N[(y * -9.0), $MachinePrecision]), $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 -5 \cdot 10^{+57}:\\
\;\;\;\;\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(2, x, \mathsf{fma}\left(a, 27 \cdot b, z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\right)\right)\\
\end{array}
| Original | 3.0 |
|---|---|
| Target | 3.4 |
| Herbie | 0.8 |
if (*.f64 y 9) < -4.99999999999999972e57Initial program 5.8
Simplified1.1
[Start]5.8 | \[ \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- [=>]5.8 | \[ \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 [=>]5.8 | \[ \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 [=>]5.8 | \[ \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- [<=]5.8 | \[ \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 [<=]5.8 | \[ \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 [=>]5.8 | \[ \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 [=>]5.8 | \[ \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* [=>]5.7 | \[ \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 [=>]5.7 | \[ \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.1 | \[ \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.1 | \[ \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.1 | \[ \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.1 | \[ \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.1 | \[ \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.1 | \[ \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.1 | \[ \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.1 | \[ \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 -4.99999999999999972e57 < (*.f64 y 9) Initial program 0.9
Simplified4.2
[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
\] |
|---|---|
associate-*l* [=>]4.2 | \[ \left(x \cdot 2 - \color{blue}{\left(y \cdot 9\right) \cdot \left(z \cdot t\right)}\right) + \left(a \cdot 27\right) \cdot b
\] |
associate-*l* [=>]4.2 | \[ \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right) + \color{blue}{a \cdot \left(27 \cdot b\right)}
\] |
Taylor expanded in x around 0 4.1
Simplified0.6
[Start]4.1 | \[ \left(2 \cdot x + 27 \cdot \left(a \cdot b\right)\right) - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
|---|---|
*-commutative [<=]4.1 | \[ \left(\color{blue}{x \cdot 2} + 27 \cdot \left(a \cdot b\right)\right) - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
associate-*r* [=>]4.2 | \[ \left(x \cdot 2 + \color{blue}{\left(27 \cdot a\right) \cdot b}\right) - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
*-commutative [<=]4.2 | \[ \left(x \cdot 2 + \color{blue}{\left(a \cdot 27\right)} \cdot b\right) - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
associate-*r* [<=]4.2 | \[ \left(x \cdot 2 + \color{blue}{a \cdot \left(27 \cdot b\right)}\right) - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
*-commutative [<=]4.2 | \[ \left(x \cdot 2 + a \cdot \left(27 \cdot b\right)\right) - 9 \cdot \left(y \cdot \color{blue}{\left(z \cdot t\right)}\right)
\] |
associate-*r* [=>]4.2 | \[ \left(x \cdot 2 + a \cdot \left(27 \cdot b\right)\right) - \color{blue}{\left(9 \cdot y\right) \cdot \left(z \cdot t\right)}
\] |
*-commutative [<=]4.2 | \[ \left(x \cdot 2 + a \cdot \left(27 \cdot b\right)\right) - \color{blue}{\left(y \cdot 9\right)} \cdot \left(z \cdot t\right)
\] |
associate--l+ [=>]4.2 | \[ \color{blue}{x \cdot 2 + \left(a \cdot \left(27 \cdot b\right) - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)}
\] |
*-commutative [=>]4.2 | \[ \color{blue}{2 \cdot x} + \left(a \cdot \left(27 \cdot b\right) - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)
\] |
*-commutative [=>]4.2 | \[ 2 \cdot x + \left(a \cdot \left(27 \cdot b\right) - \color{blue}{\left(9 \cdot y\right)} \cdot \left(z \cdot t\right)\right)
\] |
associate-*r* [<=]4.2 | \[ 2 \cdot x + \left(a \cdot \left(27 \cdot b\right) - \color{blue}{9 \cdot \left(y \cdot \left(z \cdot t\right)\right)}\right)
\] |
*-commutative [=>]4.2 | \[ 2 \cdot x + \left(a \cdot \left(27 \cdot b\right) - 9 \cdot \left(y \cdot \color{blue}{\left(t \cdot z\right)}\right)\right)
\] |
cancel-sign-sub-inv [=>]4.2 | \[ 2 \cdot x + \color{blue}{\left(a \cdot \left(27 \cdot b\right) + \left(-9\right) \cdot \left(y \cdot \left(t \cdot z\right)\right)\right)}
\] |
associate-*r* [=>]4.2 | \[ 2 \cdot x + \left(\color{blue}{\left(a \cdot 27\right) \cdot b} + \left(-9\right) \cdot \left(y \cdot \left(t \cdot z\right)\right)\right)
\] |
*-commutative [=>]4.2 | \[ 2 \cdot x + \left(\color{blue}{\left(27 \cdot a\right)} \cdot b + \left(-9\right) \cdot \left(y \cdot \left(t \cdot z\right)\right)\right)
\] |
associate-*r* [<=]4.1 | \[ 2 \cdot x + \left(\color{blue}{27 \cdot \left(a \cdot b\right)} + \left(-9\right) \cdot \left(y \cdot \left(t \cdot z\right)\right)\right)
\] |
metadata-eval [=>]4.1 | \[ 2 \cdot x + \left(27 \cdot \left(a \cdot b\right) + \color{blue}{-9} \cdot \left(y \cdot \left(t \cdot z\right)\right)\right)
\] |
+-commutative [<=]4.1 | \[ 2 \cdot x + \color{blue}{\left(-9 \cdot \left(y \cdot \left(t \cdot z\right)\right) + 27 \cdot \left(a \cdot b\right)\right)}
\] |
Final simplification0.8
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 13892 |
| Alternative 2 | |
|---|---|
| Error | 0.8 |
| Cost | 7492 |
| Alternative 3 | |
|---|---|
| Error | 19.1 |
| Cost | 2020 |
| Alternative 4 | |
|---|---|
| Error | 19.2 |
| Cost | 2020 |
| Alternative 5 | |
|---|---|
| Error | 18.1 |
| Cost | 1497 |
| Alternative 6 | |
|---|---|
| Error | 19.1 |
| Cost | 1369 |
| Alternative 7 | |
|---|---|
| Error | 28.3 |
| Cost | 1244 |
| Alternative 8 | |
|---|---|
| Error | 28.5 |
| Cost | 1244 |
| Alternative 9 | |
|---|---|
| Error | 28.5 |
| Cost | 1244 |
| Alternative 10 | |
|---|---|
| Error | 28.5 |
| Cost | 1244 |
| Alternative 11 | |
|---|---|
| Error | 0.7 |
| Cost | 1220 |
| Alternative 12 | |
|---|---|
| Error | 3.0 |
| Cost | 1088 |
| Alternative 13 | |
|---|---|
| Error | 13.7 |
| Cost | 969 |
| Alternative 14 | |
|---|---|
| Error | 27.9 |
| Cost | 584 |
| Alternative 15 | |
|---|---|
| Error | 27.9 |
| Cost | 584 |
| Alternative 16 | |
|---|---|
| Error | 37.1 |
| Cost | 192 |
herbie shell --seed 2023041
(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)))