Average Error: 2.9 → 0.6
Time: 7.2s
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} t_1 := \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\\ t_2 := y \cdot \left(z \cdot t\right)\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+298}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(t_2, -9, a \cdot \left(27 \cdot b\right)\right)\right)\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+299}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, 27 \cdot \left(a \cdot b\right) + -9 \cdot t_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 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))
        (t_2 (* y (* z t))))
   (if (<= t_1 -5e+298)
     (fma x 2.0 (fma t_2 -9.0 (* a (* 27.0 b))))
     (if (<= t_1 4e+299) t_1 (fma x 2.0 (+ (* 27.0 (* a b)) (* -9.0 t_2)))))))
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 = ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
	double t_2 = y * (z * t);
	double tmp;
	if (t_1 <= -5e+298) {
		tmp = fma(x, 2.0, fma(t_2, -9.0, (a * (27.0 * b))));
	} else if (t_1 <= 4e+299) {
		tmp = t_1;
	} else {
		tmp = fma(x, 2.0, ((27.0 * (a * b)) + (-9.0 * t_2)));
	}
	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(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + Float64(Float64(a * 27.0) * b))
	t_2 = Float64(y * Float64(z * t))
	tmp = 0.0
	if (t_1 <= -5e+298)
		tmp = fma(x, 2.0, fma(t_2, -9.0, Float64(a * Float64(27.0 * b))));
	elseif (t_1 <= 4e+299)
		tmp = t_1;
	else
		tmp = fma(x, 2.0, Float64(Float64(27.0 * Float64(a * b)) + Float64(-9.0 * t_2)));
	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[(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]}, Block[{t$95$2 = N[(y * N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+298], N[(x * 2.0 + N[(t$95$2 * -9.0 + N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e+299], t$95$1, N[(x * 2.0 + N[(N[(27.0 * N[(a * b), $MachinePrecision]), $MachinePrecision] + N[(-9.0 * t$95$2), $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(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\\
t_2 := y \cdot \left(z \cdot t\right)\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+298}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(t_2, -9, a \cdot \left(27 \cdot b\right)\right)\right)\\

\mathbf{elif}\;t_1 \leq 4 \cdot 10^{+299}:\\
\;\;\;\;t_1\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

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 3 regimes
  2. if (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b)) < -5.0000000000000003e298

    1. Initial program 37.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. Simplified3.1

      \[\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)} \]
    3. Applied egg-rr4.8

      \[\leadsto \mathsf{fma}\left(x, 2, \color{blue}{{\left(\sqrt[3]{\mathsf{fma}\left(y, z \cdot \left(t \cdot -9\right), b \cdot \left(a \cdot 27\right)\right)}\right)}^{3}}\right) \]
    4. Applied egg-rr3.0

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

    if -5.0000000000000003e298 < (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b)) < 4.0000000000000002e299

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

    if 4.0000000000000002e299 < (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b))

    1. Initial program 36.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. Simplified1.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)} \]
    3. Taylor expanded in y around 0 1.7

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

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

Reproduce

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