| Alternative 1 | |
|---|---|
| Error | 1.1 |
| Cost | 14664 |
(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
(let* ((t_1 (* (* (* y 9.0) z) t)) (t_2 (* (* a 27.0) b)))
(if (<= t_1 (- INFINITY))
(+ (+ (* x 2.0) (* (* z (* y t)) -9.0)) t_2)
(if (<= t_1 5e+268)
(fma t (* (* y z) -9.0) (fma x 2.0 (* 27.0 (* a b))))
(fma x 2.0 (fma y (* t (* z -9.0)) t_2))))))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 t_1 = ((y * 9.0) * z) * t;
double t_2 = (a * 27.0) * b;
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = ((x * 2.0) + ((z * (y * t)) * -9.0)) + t_2;
} else if (t_1 <= 5e+268) {
tmp = fma(t, ((y * z) * -9.0), fma(x, 2.0, (27.0 * (a * b))));
} else {
tmp = fma(x, 2.0, fma(y, (t * (z * -9.0)), t_2));
}
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) t_1 = Float64(Float64(Float64(y * 9.0) * z) * t) t_2 = Float64(Float64(a * 27.0) * b) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(Float64(Float64(x * 2.0) + Float64(Float64(z * Float64(y * t)) * -9.0)) + t_2); elseif (t_1 <= 5e+268) tmp = fma(t, Float64(Float64(y * z) * -9.0), fma(x, 2.0, Float64(27.0 * Float64(a * b)))); else tmp = fma(x, 2.0, fma(y, Float64(t * Float64(z * -9.0)), t_2)); 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_] := Block[{t$95$1 = N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(N[(z * N[(y * t), $MachinePrecision]), $MachinePrecision] * -9.0), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], If[LessEqual[t$95$1, 5e+268], N[(t * N[(N[(y * z), $MachinePrecision] * -9.0), $MachinePrecision] + N[(x * 2.0 + N[(27.0 * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * 2.0 + N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + t$95$2), $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}
t_1 := \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\\
t_2 := \left(a \cdot 27\right) \cdot b\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\left(x \cdot 2 + \left(z \cdot \left(y \cdot t\right)\right) \cdot -9\right) + t_2\\
\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+268}:\\
\;\;\;\;\mathsf{fma}\left(t, \left(y \cdot z\right) \cdot -9, \mathsf{fma}\left(x, 2, 27 \cdot \left(a \cdot b\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), t_2\right)\right)\\
\end{array}
| Original | 3.2 |
|---|---|
| Target | 3.5 |
| Herbie | 0.7 |
if (*.f64 (*.f64 (*.f64 y 9) z) t) < -inf.0Initial program 64.0
Taylor expanded in y around 0 0.3
Simplified1.0
[Start]0.3 | \[ \left(x \cdot 2 - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right) + \left(a \cdot 27\right) \cdot b
\] |
|---|---|
associate-*r* [=>]1.0 | \[ \left(x \cdot 2 - 9 \cdot \color{blue}{\left(\left(y \cdot t\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b
\] |
*-commutative [=>]1.0 | \[ \left(x \cdot 2 - 9 \cdot \color{blue}{\left(z \cdot \left(y \cdot t\right)\right)}\right) + \left(a \cdot 27\right) \cdot b
\] |
if -inf.0 < (*.f64 (*.f64 (*.f64 y 9) z) t) < 5.0000000000000002e268Initial program 0.5
Simplified0.4
[Start]0.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.5 | \[ \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.4 | \[ \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)
\] |
if 5.0000000000000002e268 < (*.f64 (*.f64 (*.f64 y 9) z) t) Initial program 35.5
Simplified7.7
[Start]35.5 | \[ \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- [=>]35.5 | \[ \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 [=>]35.5 | \[ \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 [=>]35.5 | \[ \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- [<=]35.5 | \[ \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 [<=]35.5 | \[ \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 [=>]35.5 | \[ \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 [=>]35.5 | \[ \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* [=>]34.8 | \[ \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 [=>]34.8 | \[ \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* [=>]7.7 | \[ \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 [=>]7.7 | \[ \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 [=>]7.7 | \[ \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 [<=]7.7 | \[ \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 [=>]7.7 | \[ \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 [=>]7.7 | \[ \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 [=>]7.7 | \[ \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 [=>]7.7 | \[ \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)
\] |
Final simplification0.7
| Alternative 1 | |
|---|---|
| Error | 1.1 |
| Cost | 14664 |
| Alternative 2 | |
|---|---|
| Error | 0.9 |
| Cost | 14020 |
| Alternative 3 | |
|---|---|
| Error | 1.1 |
| Cost | 2120 |
| Alternative 4 | |
|---|---|
| Error | 21.3 |
| Cost | 1369 |
| Alternative 5 | |
|---|---|
| Error | 0.6 |
| Cost | 1220 |
| Alternative 6 | |
|---|---|
| Error | 11.8 |
| Cost | 1097 |
| Alternative 7 | |
|---|---|
| Error | 5.0 |
| Cost | 1088 |
| Alternative 8 | |
|---|---|
| Error | 29.6 |
| Cost | 980 |
| Alternative 9 | |
|---|---|
| Error | 29.6 |
| Cost | 980 |
| Alternative 10 | |
|---|---|
| Error | 29.5 |
| Cost | 980 |
| Alternative 11 | |
|---|---|
| Error | 14.4 |
| Cost | 969 |
| Alternative 12 | |
|---|---|
| Error | 14.6 |
| Cost | 969 |
| Alternative 13 | |
|---|---|
| Error | 28.9 |
| Cost | 584 |
| Alternative 14 | |
|---|---|
| Error | 37.4 |
| Cost | 192 |
herbie shell --seed 2023060
(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)))