?

Average Accuracy: 95.7% → 99.2%
Time: 16.4s
Precision: binary64
Cost: 14020

?

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

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


\end{array}

Error?

Target

Original95.7%
Target95.0%
Herbie99.2%
\[\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 (*.f64 (*.f64 y 9) z) < 4.00000000000000039e199

    1. Initial program 99.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.2%

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

      [Start]99.2

      \[ \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.2

      \[ \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.2

      \[ \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.2

      \[ \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.2

      \[ \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.2

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

      \[ \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-rgt-neg-in [=>]99.2

      \[ \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.2

      \[ \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) \]

      *-commutative [=>]99.2

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

      associate-*r* [=>]99.2

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

      distribute-rgt-neg-in [=>]99.2

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

      *-commutative [=>]99.2

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

      metadata-eval [=>]99.2

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

    if 4.00000000000000039e199 < (*.f64 (*.f64 y 9) z)

    1. Initial program 59.7%

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

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

      [Start]59.7

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

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

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

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

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

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

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

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

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

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

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

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

Alternatives

Alternative 1
Accuracy78.4%
Cost1609
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-83} \lor \neg \left(t_1 \leq 10^{+19}\right):\\ \;\;\;\;t_1 + y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 2
Accuracy78.4%
Cost1608
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-83}:\\ \;\;\;\;t_1 + y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;t_1 \leq 10^{+19}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \end{array} \]
Alternative 3
Accuracy78.2%
Cost1498
\[\begin{array}{l} \mathbf{if}\;t \leq -3.6 \cdot 10^{-169}:\\ \;\;\;\;x \cdot 2 - 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;t \leq 2.4 \cdot 10^{+22} \lor \neg \left(t \leq 4.05 \cdot 10^{+83}\right) \land \left(t \leq 4.5 \cdot 10^{+115} \lor \neg \left(t \leq 3.6 \cdot 10^{+187}\right) \land t \leq 5 \cdot 10^{+191}\right):\\ \;\;\;\;x \cdot 2 - b \cdot \left(a \cdot -27\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 4
Accuracy78.0%
Cost1496
\[\begin{array}{l} t_1 := \left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ t_2 := x \cdot 2 - b \cdot \left(a \cdot -27\right)\\ \mathbf{if}\;t \leq -3.6 \cdot 10^{-169}:\\ \;\;\;\;x \cdot 2 - 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{+22}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{+84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3 \cdot 10^{+115}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.3 \cdot 10^{+181}:\\ \;\;\;\;x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;t \leq 5.1 \cdot 10^{+191}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy98.3%
Cost1476
\[\begin{array}{l} t_1 := \left(y \cdot 9\right) \cdot z\\ t_2 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq 5 \cdot 10^{+283}:\\ \;\;\;\;t_2 + \left(x \cdot 2 - t_1 \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_2 + y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 6
Accuracy77.1%
Cost1366
\[\begin{array}{l} \mathbf{if}\;t \leq 2.8 \cdot 10^{+22} \lor \neg \left(t \leq 4.8 \cdot 10^{+83}\right) \land \left(t \leq 5.2 \cdot 10^{+114} \lor \neg \left(t \leq 5.7 \cdot 10^{+187}\right) \land t \leq 6.2 \cdot 10^{+191}\right):\\ \;\;\;\;x \cdot 2 - b \cdot \left(a \cdot -27\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 7
Accuracy99.1%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -2.8 \cdot 10^{-11}:\\ \;\;\;\;x \cdot 2 + \left(a \cdot \left(27 \cdot b\right) - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)\\ \end{array} \]
Alternative 8
Accuracy47.3%
Cost1112
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;b \leq -1.45 \cdot 10^{-149}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.92 \cdot 10^{-144}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;b \leq 2.45 \cdot 10^{-93}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \mathbf{elif}\;b \leq 2.85 \cdot 10^{-39}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;b \leq 0.46:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;b \leq 2.15 \cdot 10^{+51}:\\ \;\;\;\;x + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Accuracy48.6%
Cost850
\[\begin{array}{l} \mathbf{if}\;b \leq -1.45 \cdot 10^{-149} \lor \neg \left(b \leq 5 \cdot 10^{-40} \lor \neg \left(b \leq 0.026\right) \land b \leq 4.4 \cdot 10^{+51}\right):\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 10
Accuracy48.4%
Cost848
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;b \leq -1.4 \cdot 10^{-149}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.85 \cdot 10^{-43}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;b \leq 1.45:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;b \leq 4 \cdot 10^{+50}:\\ \;\;\;\;x + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Accuracy75.5%
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1.22 \cdot 10^{+61}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+14}:\\ \;\;\;\;x \cdot 2 - a \cdot \left(b \cdot -27\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \end{array} \]
Alternative 12
Accuracy75.6%
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1.5 \cdot 10^{+62}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{+14}:\\ \;\;\;\;x \cdot 2 - b \cdot \left(a \cdot -27\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \end{array} \]
Alternative 13
Accuracy42.5%
Cost192
\[x + x \]

Error

Reproduce?

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