?

Average Accuracy: 95.5% → 99.0%
Time: 19.5s
Precision: binary64
Cost: 7492

?

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

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


\end{array}

Error?

Target

Original95.5%
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.00000000000000013e-147

    1. Initial program 94.2%

      \[\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.0%

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

      [Start]94.2

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

      +-commutative [=>]94.2

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

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

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

      \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \color{blue}{\left(y \cdot 9\right) \cdot \left(z \cdot t\right)}\right) \]

      associate-*l* [=>]99.0

      \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \color{blue}{y \cdot \left(9 \cdot \left(z \cdot t\right)\right)}\right) \]

    if 5.00000000000000013e-147 < z

    1. Initial program 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 \]
    2. Simplified85.8%

      \[\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]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* [=>]85.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* [=>]85.8

      \[ \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)} \]
    3. Taylor expanded in y around 0 85.8%

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

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

      [Start]85.8

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

      *-commutative [<=]85.8

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

      associate-*r* [=>]99.2

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

      associate-*l* [<=]99.2

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

      *-commutative [=>]99.2

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

      associate-*l* [=>]99.1

      \[ \left(x \cdot 2 - \color{blue}{\left(y \cdot z\right) \cdot \left(9 \cdot t\right)}\right) + a \cdot \left(27 \cdot b\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.0%

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

Alternatives

Alternative 1
Accuracy95.4%
Cost1609
\[\begin{array}{l} \mathbf{if}\;y \cdot 9 \leq -1 \cdot 10^{-206} \lor \neg \left(y \cdot 9 \leq 5 \cdot 10^{-234}\right):\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 2
Accuracy77.1%
Cost1232
\[\begin{array}{l} t_1 := x \cdot 2 + \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ t_2 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;b \leq -4.3 \cdot 10^{-166}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 9.5 \cdot 10^{+44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 9.6 \cdot 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 3
Accuracy77.1%
Cost1232
\[\begin{array}{l} t_1 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;b \leq -1.85 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 2.1 \cdot 10^{-139}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 9.6 \cdot 10^{+73}:\\ \;\;\;\;x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 4
Accuracy99.0%
Cost1220
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq 5 \cdot 10^{-37}:\\ \;\;\;\;t_1 + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot y\right) \cdot \left(t \cdot -9\right)\right) + t_1\\ \end{array} \]
Alternative 5
Accuracy69.2%
Cost1105
\[\begin{array}{l} t_1 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;b \leq -1.4 \cdot 10^{-307}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 2.15 \cdot 10^{-271}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;b \leq 1.85 \cdot 10^{-202} \lor \neg \left(b \leq 1.45 \cdot 10^{-186}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \end{array} \]
Alternative 6
Accuracy69.2%
Cost1104
\[\begin{array}{l} t_1 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;b \leq -6.2 \cdot 10^{-303}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 7 \cdot 10^{-272}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;b \leq 4.6 \cdot 10^{-200}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.45 \cdot 10^{-186}:\\ \;\;\;\;\left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 7
Accuracy81.7%
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -26000000:\\ \;\;\;\;x \cdot 2 + b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-67}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 8
Accuracy81.8%
Cost1096
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -420:\\ \;\;\;\;x \cdot 2 + b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-67}:\\ \;\;\;\;t_1 + \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + t_1\\ \end{array} \]
Alternative 9
Accuracy54.1%
Cost980
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\\ \mathbf{if}\;x \leq -2.1 \cdot 10^{+34}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-260}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-257}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-214}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 10000000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 10
Accuracy54.1%
Cost980
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -2.05 \cdot 10^{+34}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.05 \cdot 10^{-259}:\\ \;\;\;\;\left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-216}:\\ \;\;\;\;y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\\ \mathbf{elif}\;x \leq 11000000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 11
Accuracy55.7%
Cost848
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -2.1 \cdot 10^{+34}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.12 \cdot 10^{-206}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{-259}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{elif}\;x \leq 8200000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 12
Accuracy55.9%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.05 \cdot 10^{+34}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 2000000000:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 13
Accuracy40.8%
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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