Average Error: 2.9 → 0.6
Time: 6.7s
Precision: binary64
\[ \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 1.1235595568962029 \cdot 10^{-33}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, z \cdot \left(t \cdot -9\right), a \cdot \left(27 \cdot b\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(y \cdot \left(z \cdot -9\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 1.1235595568962029e-33)
   (fma x 2.0 (fma y (* z (* t -9.0)) (* a (* 27.0 b))))
   (+ (+ (* x 2.0) (* t (* y (* z -9.0)))) (* 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 <= 1.1235595568962029e-33) {
		tmp = fma(x, 2.0, fma(y, (z * (t * -9.0)), (a * (27.0 * b))));
	} else {
		tmp = ((x * 2.0) + (t * (y * (z * -9.0)))) + (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 <= 1.1235595568962029e-33)
		tmp = fma(x, 2.0, fma(y, Float64(z * Float64(t * -9.0)), Float64(a * Float64(27.0 * b))));
	else
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(t * Float64(y * Float64(z * -9.0)))) + 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, 1.1235595568962029e-33], N[(x * 2.0 + N[(y * N[(z * N[(t * -9.0), $MachinePrecision]), $MachinePrecision] + N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(t * N[(y * N[(z * -9.0), $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 1.1235595568962029 \cdot 10^{-33}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, z \cdot \left(t \cdot -9\right), a \cdot \left(27 \cdot b\right)\right)\right)\\

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


\end{array}

Error

Target

Original2.9
Target3.4
Herbie0.6
\[\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 < 1.12355955689620286e-33

    1. Initial program 3.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. Simplified0.7

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

    if 1.12355955689620286e-33 < z

    1. Initial program 0.3

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

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

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

Reproduce

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