?

Average Accuracy: 95.4% → 99.0%
Time: 18.3s
Precision: binary64
Cost: 13892.00

?

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

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


\end{array}

Error?

Target

Original95.4%
Target94.8%
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 (*.f64 y 9) < -1.00000000000000004e36

    1. Initial program 91.4%

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

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

      [Start]91.4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.00000000000000004e36 < (*.f64 y 9)

    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. Applied egg-rr99.3%

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

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

Alternatives

Alternative 1
Accuracy99.0%
Cost7620.00
\[\begin{array}{l} \mathbf{if}\;y \cdot 9 \leq -1 \cdot 10^{+36}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(-9 \cdot \left(t \cdot z\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b + \left(\left(z \cdot -9\right) \cdot \left(y \cdot t\right) + x \cdot 2\right)\\ \end{array} \]
Alternative 2
Accuracy74.5%
Cost1492.00
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ t_2 := t_1 + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ t_3 := x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;t \leq 4.4 \cdot 10^{+51}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 4.5 \cdot 10^{+79}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 5.8 \cdot 10^{+129}:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;t \leq 1.02 \cdot 10^{+152}:\\ \;\;\;\;x \cdot 2 + \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;t \leq 1.05 \cdot 10^{+161}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Accuracy74.7%
Cost1492.00
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ t_2 := x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;t \leq 1.1 \cdot 10^{+55}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 4.6 \cdot 10^{+79}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{elif}\;t \leq 1.95 \cdot 10^{+131}:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;t \leq 1.95 \cdot 10^{+152}:\\ \;\;\;\;x \cdot 2 + \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;t \leq 1.15 \cdot 10^{+161}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1 + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \end{array} \]
Alternative 4
Accuracy83.6%
Cost1480.00
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-101}:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-55}:\\ \;\;\;\;x \cdot 2 + \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \end{array} \]
Alternative 5
Accuracy83.6%
Cost1480.00
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-101}:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-55}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \end{array} \]
Alternative 6
Accuracy91.2%
Cost1220.00
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ \mathbf{if}\;t \leq 1.35 \cdot 10^{+252}:\\ \;\;\;\;t_1 + \left(\left(z \cdot -9\right) \cdot \left(y \cdot t\right) + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \end{array} \]
Alternative 7
Accuracy99.1%
Cost1220.00
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ \mathbf{if}\;z \leq -1.7 \cdot 10^{-46}:\\ \;\;\;\;t_1 + \left(\left(z \cdot -9\right) \cdot \left(y \cdot t\right) + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(x \cdot 2 + t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\right)\\ \end{array} \]
Alternative 8
Accuracy74.4%
Cost1104.00
\[\begin{array}{l} t_1 := x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ t_2 := -9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{if}\;z \leq -1.55 \cdot 10^{+54}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-59}:\\ \;\;\;\;\left(t \cdot z\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;z \leq 2 \cdot 10^{+59}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 9
Accuracy74.5%
Cost1104.00
\[\begin{array}{l} t_1 := -9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{if}\;z \leq -2.6 \cdot 10^{+55}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-71}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b + x \cdot 2\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-59}:\\ \;\;\;\;\left(t \cdot z\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+59}:\\ \;\;\;\;x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Accuracy55.7%
Cost848.00
\[\begin{array}{l} \mathbf{if}\;x \leq -0.13:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-105}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq -1.34 \cdot 10^{-188}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{elif}\;x \leq 1.52 \cdot 10^{-18}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 11
Accuracy56.6%
Cost584.00
\[\begin{array}{l} \mathbf{if}\;x \leq -0.054:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 1.12 \cdot 10^{-17}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 12
Accuracy56.5%
Cost584.00
\[\begin{array}{l} \mathbf{if}\;x \leq -0.0305:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-19}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 13
Accuracy56.5%
Cost584.00
\[\begin{array}{l} \mathbf{if}\;x \leq -0.066:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 1.52 \cdot 10^{-18}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 14
Accuracy41.5%
Cost192.00
\[x \cdot 2 \]

Error

Reproduce?

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