?

Average Accuracy: 95.3% → 99.0%
Time: 16.9s
Precision: binary64
Cost: 13764

?

\[ \begin{array}{c}[y, z, t] = \mathsf{sort}([y, z, t])\\ \end{array} \]
\[\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}\;z \leq -5.2 \cdot 10^{-126}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t, \left(z \cdot y\right) \cdot -9, \mathsf{fma}\left(x, 2, 27 \cdot \left(a \cdot b\right)\right)\right)\\ \end{array} \]
(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 (<= z -5.2e-126)
   (+ (* a (* 27.0 b)) (+ (* x 2.0) (* (* z t) (* y -9.0))))
   (fma t (* (* z y) -9.0) (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 (z <= -5.2e-126) {
		tmp = (a * (27.0 * b)) + ((x * 2.0) + ((z * t) * (y * -9.0)));
	} else {
		tmp = fma(t, ((z * y) * -9.0), 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 (z <= -5.2e-126)
		tmp = Float64(Float64(a * Float64(27.0 * b)) + Float64(Float64(x * 2.0) + Float64(Float64(z * t) * Float64(y * -9.0))));
	else
		tmp = fma(t, Float64(Float64(z * y) * -9.0), 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[z, -5.2e-126], N[(N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] * N[(y * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(N[(z * y), $MachinePrecision] * -9.0), $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}\;z \leq -5.2 \cdot 10^{-126}:\\
\;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, \left(z \cdot y\right) \cdot -9, \mathsf{fma}\left(x, 2, 27 \cdot \left(a \cdot b\right)\right)\right)\\


\end{array}

Error?

Target

Original95.3%
Target94.7%
Herbie99.0%
\[\begin{array}{l} \mathbf{if}\;y < 7.590524218811189 \cdot 10^{-161}:\\ \;\;\;\;\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if z < -5.19999999999999998e-126

    1. Initial program 84.0%

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Simplified98.5%

      \[\leadsto \color{blue}{\left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right) + a \cdot \left(27 \cdot b\right)} \]
      Proof

      [Start]84.0

      \[ \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* [=>]98.7

      \[ \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* [=>]98.5

      \[ \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 -5.19999999999999998e-126 < z

    1. Initial program 98.9%

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Simplified99.2%

      \[\leadsto \color{blue}{\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)} \]
      Proof

      [Start]98.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 [=>]98.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 [=>]98.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+ [=>]98.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 [=>]98.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 [<=]98.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 [=>]98.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 [=>]98.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 [=>]98.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* [=>]99.1

      \[ \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 [=>]99.1

      \[ \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 [=>]99.1

      \[ \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 [=>]99.1

      \[ \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 [=>]99.1

      \[ \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 [=>]99.1

      \[ \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 [=>]99.1

      \[ \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* [=>]99.2

      \[ \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) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.2 \cdot 10^{-126}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t, \left(z \cdot y\right) \cdot -9, \mathsf{fma}\left(x, 2, 27 \cdot \left(a \cdot b\right)\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy98.9%
Cost7492
\[\begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{-240}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 2
Accuracy99.0%
Cost7492
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{-126}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, 27 \cdot \left(a \cdot b\right) + -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\\ \end{array} \]
Alternative 3
Accuracy97.9%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{+58}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 + t \cdot \left(\left(z \cdot y\right) \cdot -9\right)\right)\\ \end{array} \]
Alternative 4
Accuracy98.9%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -3.4 \cdot 10^{-208}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 + t \cdot \left(\left(z \cdot y\right) \cdot -9\right)\right)\\ \end{array} \]
Alternative 5
Accuracy98.8%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -2.2 \cdot 10^{-208}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 6
Accuracy71.8%
Cost1104
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right) + x \cdot 2\\ \mathbf{if}\;y \leq -1.6 \cdot 10^{+283}:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{+245}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -9 \cdot 10^{+214}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 7
Accuracy82.1%
Cost1097
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -4.9 \cdot 10^{-60} \lor \neg \left(x \leq 39000000000000\right):\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t_1 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 8
Accuracy54.1%
Cost980
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -8.5 \cdot 10^{+54}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-60}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-304}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 9
Accuracy53.6%
Cost980
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -6.2 \cdot 10^{+55}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.7 \cdot 10^{-58}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-305}:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{+19}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 10
Accuracy53.6%
Cost980
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -4.2 \cdot 10^{+48}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.1 \cdot 10^{-58}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{-305}:\\ \;\;\;\;z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 11
Accuracy53.6%
Cost980
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -1.6 \cdot 10^{+45}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-59}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-306}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 9.6 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 12
Accuracy76.6%
Cost969
\[\begin{array}{l} \mathbf{if}\;a \leq -8.5 \cdot 10^{+85} \lor \neg \left(a \leq 9 \cdot 10^{-180}\right):\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \end{array} \]
Alternative 13
Accuracy56.8%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.02 \cdot 10^{+46}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 9.6 \cdot 10^{+18}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 14
Accuracy41.8%
Cost192
\[x \cdot 2 \]

Error

Reproduce?

herbie shell --seed 2023130 
(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)))