| Alternative 1 | |
|---|---|
| Accuracy | 98.7% |
| 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
(let* ((t_1 (fma (* b -27.0) a (* a (* b 27.0)))))
(if (<= z -1.25e+50)
(- (* x 2.0) (+ (fma y (* (* z 9.0) t) (* a (* b -27.0))) (+ t_1 t_1)))
(fma a (* b 27.0) (- (* x 2.0) (* 9.0 (* t (* z y))))))))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 = fma((b * -27.0), a, (a * (b * 27.0)));
double tmp;
if (z <= -1.25e+50) {
tmp = (x * 2.0) - (fma(y, ((z * 9.0) * t), (a * (b * -27.0))) + (t_1 + t_1));
} else {
tmp = fma(a, (b * 27.0), ((x * 2.0) - (9.0 * (t * (z * y)))));
}
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 = fma(Float64(b * -27.0), a, Float64(a * Float64(b * 27.0))) tmp = 0.0 if (z <= -1.25e+50) tmp = Float64(Float64(x * 2.0) - Float64(fma(y, Float64(Float64(z * 9.0) * t), Float64(a * Float64(b * -27.0))) + Float64(t_1 + t_1))); else tmp = fma(a, Float64(b * 27.0), Float64(Float64(x * 2.0) - Float64(9.0 * Float64(t * Float64(z * y))))); 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[(b * -27.0), $MachinePrecision] * a + N[(a * N[(b * 27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.25e+50], N[(N[(x * 2.0), $MachinePrecision] - N[(N[(y * N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision] + N[(a * N[(b * -27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(b * 27.0), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] - N[(9.0 * N[(t * N[(z * y), $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}
t_1 := \mathsf{fma}\left(b \cdot -27, a, a \cdot \left(b \cdot 27\right)\right)\\
\mathbf{if}\;z \leq -1.25 \cdot 10^{+50}:\\
\;\;\;\;x \cdot 2 - \left(\mathsf{fma}\left(y, \left(z \cdot 9\right) \cdot t, a \cdot \left(b \cdot -27\right)\right) + \left(t_1 + t_1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b \cdot 27, x \cdot 2 - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\\
\end{array}
| Original | 95.3% |
|---|---|
| Target | 94.6% |
| Herbie | 98.7% |
if z < -1.25e50Initial program 46.8%
Simplified99.0%
[Start]46.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- [=>]46.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)}
\] |
sub-neg [=>]46.8 | \[ \color{blue}{x \cdot 2 + \left(-\left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)\right)}
\] |
neg-mul-1 [=>]46.8 | \[ x \cdot 2 + \color{blue}{-1 \cdot \left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)}
\] |
metadata-eval [<=]46.8 | \[ x \cdot 2 + \color{blue}{\left(-1\right)} \cdot \left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)
\] |
metadata-eval [<=]46.8 | \[ x \cdot 2 + \left(-\color{blue}{\left(--1\right)}\right) \cdot \left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)
\] |
cancel-sign-sub-inv [<=]46.8 | \[ \color{blue}{x \cdot 2 - \left(--1\right) \cdot \left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)}
\] |
metadata-eval [=>]46.8 | \[ x \cdot 2 - \color{blue}{1} \cdot \left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)
\] |
*-lft-identity [=>]46.8 | \[ x \cdot 2 - \color{blue}{\left(\left(\left(y \cdot 9\right) \cdot z\right) \cdot t - \left(a \cdot 27\right) \cdot b\right)}
\] |
associate-*l* [=>]99.0 | \[ x \cdot 2 - \left(\color{blue}{\left(y \cdot 9\right) \cdot \left(z \cdot t\right)} - \left(a \cdot 27\right) \cdot b\right)
\] |
associate-*l* [=>]99.0 | \[ x \cdot 2 - \left(\left(y \cdot 9\right) \cdot \left(z \cdot t\right) - \color{blue}{a \cdot \left(27 \cdot b\right)}\right)
\] |
Applied egg-rr99.4%
[Start]99.0 | \[ x \cdot 2 - \left(\left(y \cdot 9\right) \cdot \left(z \cdot t\right) - a \cdot \left(27 \cdot b\right)\right)
\] |
|---|---|
prod-diff [=>]99.0 | \[ x \cdot 2 - \color{blue}{\left(\mathsf{fma}\left(y \cdot 9, z \cdot t, -\left(27 \cdot b\right) \cdot a\right) + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right)}
\] |
*-commutative [<=]99.0 | \[ x \cdot 2 - \left(\mathsf{fma}\left(y \cdot 9, z \cdot t, -\color{blue}{a \cdot \left(27 \cdot b\right)}\right) + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right)
\] |
fma-neg [<=]99.0 | \[ x \cdot 2 - \left(\color{blue}{\left(\left(y \cdot 9\right) \cdot \left(z \cdot t\right) - a \cdot \left(27 \cdot b\right)\right)} + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right)
\] |
prod-diff [=>]99.0 | \[ x \cdot 2 - \left(\color{blue}{\left(\mathsf{fma}\left(y \cdot 9, z \cdot t, -\left(27 \cdot b\right) \cdot a\right) + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right)} + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right)
\] |
*-commutative [<=]99.0 | \[ x \cdot 2 - \left(\left(\mathsf{fma}\left(y \cdot 9, z \cdot t, -\color{blue}{a \cdot \left(27 \cdot b\right)}\right) + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right) + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right)
\] |
fma-neg [<=]99.0 | \[ x \cdot 2 - \left(\left(\color{blue}{\left(\left(y \cdot 9\right) \cdot \left(z \cdot t\right) - a \cdot \left(27 \cdot b\right)\right)} + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right) + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right)
\] |
associate-+l+ [=>]98.9 | \[ x \cdot 2 - \color{blue}{\left(\left(\left(y \cdot 9\right) \cdot \left(z \cdot t\right) - a \cdot \left(27 \cdot b\right)\right) + \left(\mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right) + \mathsf{fma}\left(-27 \cdot b, a, \left(27 \cdot b\right) \cdot a\right)\right)\right)}
\] |
if -1.25e50 < z Initial program 98.5%
Simplified95.3%
[Start]98.5 | \[ \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\] |
|---|---|
+-commutative [=>]98.5 | \[ \color{blue}{\left(a \cdot 27\right) \cdot b + \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}
\] |
associate-*l* [=>]98.4 | \[ \color{blue}{a \cdot \left(27 \cdot b\right)} + \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)
\] |
fma-def [=>]98.4 | \[ \color{blue}{\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}
\] |
associate-*l* [=>]95.1 | \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \color{blue}{\left(y \cdot 9\right) \cdot \left(z \cdot t\right)}\right)
\] |
*-commutative [=>]95.1 | \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \color{blue}{\left(9 \cdot y\right)} \cdot \left(z \cdot t\right)\right)
\] |
associate-*l* [=>]95.3 | \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \color{blue}{9 \cdot \left(y \cdot \left(z \cdot t\right)\right)}\right)
\] |
Taylor expanded in y around 0 95.3%
Simplified98.6%
[Start]95.3 | \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right)
\] |
|---|---|
*-commutative [=>]95.3 | \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - 9 \cdot \color{blue}{\left(\left(t \cdot z\right) \cdot y\right)}\right)
\] |
associate-*l* [=>]98.6 | \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - 9 \cdot \color{blue}{\left(t \cdot \left(z \cdot y\right)\right)}\right)
\] |
*-commutative [<=]98.6 | \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - 9 \cdot \left(t \cdot \color{blue}{\left(y \cdot z\right)}\right)\right)
\] |
Final simplification98.7%
| Alternative 1 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7492 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.0% |
| Cost | 2384 |
| Alternative 3 | |
|---|---|
| Accuracy | 67.3% |
| Cost | 2137 |
| Alternative 4 | |
|---|---|
| Accuracy | 52.7% |
| Cost | 1636 |
| Alternative 5 | |
|---|---|
| Accuracy | 52.9% |
| Cost | 1636 |
| Alternative 6 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 1480 |
| Alternative 7 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 1480 |
| Alternative 8 | |
|---|---|
| Accuracy | 52.9% |
| Cost | 1372 |
| Alternative 9 | |
|---|---|
| Accuracy | 53.0% |
| Cost | 1372 |
| Alternative 10 | |
|---|---|
| Accuracy | 67.5% |
| Cost | 1369 |
| Alternative 11 | |
|---|---|
| Accuracy | 96.7% |
| Cost | 1220 |
| Alternative 12 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 1220 |
| Alternative 13 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 584 |
| Alternative 14 | |
|---|---|
| Accuracy | 40.7% |
| Cost | 192 |
| Alternative 15 | |
|---|---|
| Accuracy | 3.2% |
| Cost | 64 |
herbie shell --seed 2023151
(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)))