Average Error: 3.1 → 0.5
Time: 6.1s
Precision: binary64
\[ \begin{array}{c}[y, z, t] = \mathsf{sort}([y, z, t])\\ \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 5 \cdot 10^{+266}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), \mathsf{fma}\left(27, a \cdot b, x \cdot 2\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) 5e+266)
   (+ (+ (* x 2.0) (* t (* y (* z -9.0)))) (* (* a 27.0) b))
   (fma y (* t (* z -9.0)) (fma 27.0 (* a b) (* 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 tmp;
	if (((y * 9.0) * z) <= 5e+266) {
		tmp = ((x * 2.0) + (t * (y * (z * -9.0)))) + ((a * 27.0) * b);
	} else {
		tmp = fma(y, (t * (z * -9.0)), fma(27.0, (a * b), (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)
	tmp = 0.0
	if (Float64(Float64(y * 9.0) * z) <= 5e+266)
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(t * Float64(y * Float64(z * -9.0)))) + Float64(Float64(a * 27.0) * b));
	else
		tmp = fma(y, Float64(t * Float64(z * -9.0)), fma(27.0, Float64(a * b), 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_] := If[LessEqual[N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision], 5e+266], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(t * N[(y * N[(z * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision], N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + N[(27.0 * N[(a * b), $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}
\mathbf{if}\;\left(y \cdot 9\right) \cdot z \leq 5 \cdot 10^{+266}:\\
\;\;\;\;\left(x \cdot 2 + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\

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


\end{array}

Error

Target

Original3.1
Target3.5
Herbie0.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 (*.f64 (*.f64 y 9) z) < 4.9999999999999999e266

    1. Initial program 0.5

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

      \[\leadsto \left(x \cdot 2 - \color{blue}{{\left(\sqrt[3]{y \cdot \left(9 \cdot z\right)}\right)}^{3}} \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    3. Applied egg-rr0.5

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

    if 4.9999999999999999e266 < (*.f64 (*.f64 y 9) z)

    1. Initial program 44.0

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Taylor expanded in x around 0 0.3

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

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

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

Reproduce

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