| Alternative 1 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 15944 |
(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 (* (* a 27.0) b))
(t_2 (+ (+ (* x 2.0) (* t (* z (* y -9.0)))) t_1)))
(if (<= t_2 -5e+304)
(+ (+ (* x 2.0) (* (* z t) (* y -9.0))) (* a (* 27.0 b)))
(if (<= t_2 4e+225)
(fma x 2.0 (fma t (* y (* z -9.0)) t_1))
(fma x 2.0 (fma y (* t (* z -9.0)) t_1))))))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 = (a * 27.0) * b;
double t_2 = ((x * 2.0) + (t * (z * (y * -9.0)))) + t_1;
double tmp;
if (t_2 <= -5e+304) {
tmp = ((x * 2.0) + ((z * t) * (y * -9.0))) + (a * (27.0 * b));
} else if (t_2 <= 4e+225) {
tmp = fma(x, 2.0, fma(t, (y * (z * -9.0)), t_1));
} else {
tmp = fma(x, 2.0, fma(y, (t * (z * -9.0)), t_1));
}
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(a * 27.0) * b) t_2 = Float64(Float64(Float64(x * 2.0) + Float64(t * Float64(z * Float64(y * -9.0)))) + t_1) tmp = 0.0 if (t_2 <= -5e+304) tmp = Float64(Float64(Float64(x * 2.0) + Float64(Float64(z * t) * Float64(y * -9.0))) + Float64(a * Float64(27.0 * b))); elseif (t_2 <= 4e+225) tmp = fma(x, 2.0, fma(t, Float64(y * Float64(z * -9.0)), t_1)); else tmp = fma(x, 2.0, fma(y, Float64(t * Float64(z * -9.0)), t_1)); 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[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * 2.0), $MachinePrecision] + N[(t * N[(z * N[(y * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+304], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] * N[(y * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 4e+225], N[(x * 2.0 + N[(t * N[(y * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], N[(x * 2.0 + N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + t$95$1), $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(a \cdot 27\right) \cdot b\\
t_2 := \left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + t_1\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{+304}:\\
\;\;\;\;\left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right) + a \cdot \left(27 \cdot b\right)\\
\mathbf{elif}\;t_2 \leq 4 \cdot 10^{+225}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, y \cdot \left(z \cdot -9\right), t_1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), t_1\right)\right)\\
\end{array}
| Original | 95.2% |
|---|---|
| Target | 94.4% |
| Herbie | 98.1% |
if (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b)) < -4.9999999999999997e304Initial program 21.6%
Simplified95.4%
[Start]21.6 | \[ \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* [=>]93.0 | \[ \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* [=>]95.4 | \[ \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)}
\] |
if -4.9999999999999997e304 < (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b)) < 3.99999999999999971e225Initial program 99.1%
Simplified99.1%
[Start]99.1 | \[ \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- [=>]99.1 | \[ \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 [=>]99.1 | \[ \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 [=>]99.1 | \[ \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- [<=]99.1 | \[ \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 [<=]99.1 | \[ \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)
\] |
distribute-lft-neg-in [=>]99.1 | \[ \mathsf{fma}\left(x, 2, \color{blue}{\left(-\left(y \cdot 9\right) \cdot z\right) \cdot t} + \left(a \cdot 27\right) \cdot b\right)
\] |
*-commutative [=>]99.1 | \[ \mathsf{fma}\left(x, 2, \color{blue}{t \cdot \left(-\left(y \cdot 9\right) \cdot z\right)} + \left(a \cdot 27\right) \cdot b\right)
\] |
fma-def [=>]99.1 | \[ \mathsf{fma}\left(x, 2, \color{blue}{\mathsf{fma}\left(t, -\left(y \cdot 9\right) \cdot z, \left(a \cdot 27\right) \cdot b\right)}\right)
\] |
associate-*l* [=>]99.1 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, -\color{blue}{y \cdot \left(9 \cdot z\right)}, \left(a \cdot 27\right) \cdot b\right)\right)
\] |
distribute-rgt-neg-in [=>]99.1 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, \color{blue}{y \cdot \left(-9 \cdot z\right)}, \left(a \cdot 27\right) \cdot b\right)\right)
\] |
*-commutative [=>]99.1 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, y \cdot \left(-\color{blue}{z \cdot 9}\right), \left(a \cdot 27\right) \cdot b\right)\right)
\] |
distribute-rgt-neg-in [=>]99.1 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, y \cdot \color{blue}{\left(z \cdot \left(-9\right)\right)}, \left(a \cdot 27\right) \cdot b\right)\right)
\] |
metadata-eval [=>]99.1 | \[ \mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, y \cdot \left(z \cdot \color{blue}{-9}\right), \left(a \cdot 27\right) \cdot b\right)\right)
\] |
if 3.99999999999999971e225 < (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b)) Initial program 86.5%
Simplified93.0%
[Start]86.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- [=>]86.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 [=>]86.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 [=>]86.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- [<=]86.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 [<=]86.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 [=>]86.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 [=>]86.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* [=>]86.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 [=>]86.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* [=>]93.0 | \[ \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 [=>]93.0 | \[ \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 [=>]93.0 | \[ \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 [<=]93.0 | \[ \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 [=>]93.0 | \[ \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 [=>]93.0 | \[ \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 [=>]93.0 | \[ \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 [=>]93.0 | \[ \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 simplification98.1%
| Alternative 1 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 15944 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 9672 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 3401 |
| Alternative 4 | |
|---|---|
| Accuracy | 52.5% |
| Cost | 1900 |
| Alternative 5 | |
|---|---|
| Accuracy | 54.0% |
| Cost | 1376 |
| Alternative 6 | |
|---|---|
| Accuracy | 73.7% |
| Cost | 1366 |
| Alternative 7 | |
|---|---|
| Accuracy | 75.0% |
| Cost | 1365 |
| Alternative 8 | |
|---|---|
| Accuracy | 82.0% |
| Cost | 1233 |
| Alternative 9 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 1220 |
| Alternative 10 | |
|---|---|
| Accuracy | 73.7% |
| Cost | 1104 |
| Alternative 11 | |
|---|---|
| Accuracy | 55.2% |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Accuracy | 55.2% |
| Cost | 584 |
| Alternative 13 | |
|---|---|
| Accuracy | 41.3% |
| Cost | 192 |
herbie shell --seed 2023138
(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)))