?

Average Accuracy: 70.0% → 72.5%
Time: 23.4s
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 -7.5 \cdot 10^{-216}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - t \cdot \left(z \cdot \left(9 \cdot y\right)\right)\right) + b \cdot \left(a \cdot 27\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 -7.5e-216)
   (fma a (* 27.0 b) (- (* x 2.0) (* 9.0 (* y (* z t)))))
   (+ (- (* x 2.0) (* t (* z (* 9.0 y)))) (* b (* a 27.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 tmp;
	if (z <= -7.5e-216) {
		tmp = fma(a, (27.0 * b), ((x * 2.0) - (9.0 * (y * (z * t)))));
	} else {
		tmp = ((x * 2.0) - (t * (z * (9.0 * y)))) + (b * (a * 27.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)
	tmp = 0.0
	if (z <= -7.5e-216)
		tmp = fma(a, Float64(27.0 * b), Float64(Float64(x * 2.0) - Float64(9.0 * Float64(y * Float64(z * t)))));
	else
		tmp = Float64(Float64(Float64(x * 2.0) - Float64(t * Float64(z * Float64(9.0 * y)))) + Float64(b * Float64(a * 27.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_] := If[LessEqual[z, -7.5e-216], N[(a * N[(27.0 * b), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] - N[(9.0 * N[(y * N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] - N[(t * N[(z * N[(9.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(a * 27.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}
\mathbf{if}\;z \leq -7.5 \cdot 10^{-216}:\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\right)\\

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


\end{array}

Error?

Target

Original70.0%
Target69.6%
Herbie72.5%
\[\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 < -7.50000000000000064e-216

    1. Initial program 62.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. Simplified64.9%

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

      [Start]62.4

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

      +-commutative [=>]62.4

      \[ \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* [=>]62.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 [=>]62.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* [=>]64.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) \]

      *-commutative [=>]64.9

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

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

    if -7.50000000000000064e-216 < z

    1. Initial program 72.8%

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

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

Alternatives

Alternative 1
Accuracy70.1%
Cost1476
\[\begin{array}{l} t_1 := z \cdot \left(9 \cdot y\right)\\ \mathbf{if}\;t_1 \leq 10^{+269}:\\ \;\;\;\;\left(x \cdot 2 - t \cdot t_1\right) + b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 - \left(a \cdot b\right) \cdot -27\\ \end{array} \]
Alternative 2
Accuracy72.6%
Cost1476
\[\begin{array}{l} t_1 := z \cdot \left(9 \cdot y\right)\\ \mathbf{if}\;t_1 \leq 5 \cdot 10^{+184}:\\ \;\;\;\;\left(x \cdot 2 - t \cdot t_1\right) + b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(a \cdot \left(27 \cdot b\right) - \left(z \cdot t\right) \cdot \left(9 \cdot y\right)\right)\\ \end{array} \]
Alternative 3
Accuracy59.6%
Cost1352
\[\begin{array}{l} t_1 := 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{if}\;x \cdot 2 \leq -5 \cdot 10^{-80}:\\ \;\;\;\;x \cdot 2 - t_1\\ \mathbf{elif}\;x \cdot 2 \leq 10^{-73}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) - t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 - \left(a \cdot b\right) \cdot -27\\ \end{array} \]
Alternative 4
Accuracy59.5%
Cost1352
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \leq -5 \cdot 10^{-80}:\\ \;\;\;\;x \cdot 2 - 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \cdot 2 \leq 10^{-73}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) - y \cdot \left(z \cdot \left(9 \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 - \left(a \cdot b\right) \cdot -27\\ \end{array} \]
Alternative 5
Accuracy52.4%
Cost1105
\[\begin{array}{l} t_1 := x \cdot 2 - \left(a \cdot b\right) \cdot -27\\ \mathbf{if}\;z \leq -8.6 \cdot 10^{+83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-27}:\\ \;\;\;\;\left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{+21} \lor \neg \left(z \leq 2.9 \cdot 10^{+105}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 6
Accuracy57.5%
Cost969
\[\begin{array}{l} \mathbf{if}\;b \leq -6.2 \cdot 10^{-159} \lor \neg \left(b \leq 3 \cdot 10^{-49}\right):\\ \;\;\;\;x \cdot 2 - \left(a \cdot b\right) \cdot -27\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 - 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 7
Accuracy40.5%
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -6.9 \cdot 10^{+103}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{+56}:\\ \;\;\;\;t \cdot \left(-9 \cdot \left(z \cdot y\right)\right)\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-100}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 8
Accuracy40.5%
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -1.12 \cdot 10^{+104}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq -8 \cdot 10^{+55}:\\ \;\;\;\;t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-100}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 9
Accuracy41.0%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{-80}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-100}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 10
Accuracy41.0%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.4 \cdot 10^{-87}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-100}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 11
Accuracy31.2%
Cost192
\[x + x \]

Error

Reproduce?

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