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

\mathbf{elif}\;t_2 \leq -2 \cdot 10^{+86}:\\
\;\;\;\;\left(x \cdot 2 - \left(y \cdot z\right) \cdot \left(9 \cdot t\right)\right) + b \cdot \left(a \cdot 27\right)\\

\mathbf{elif}\;t_2 \leq 10^{+248}:\\
\;\;\;\;\mathsf{fma}\left(2, x, a \cdot \left(b \cdot 27\right) - t_2\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\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

Original3.2
Target3.7
Herbie1.1
\[\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 y 9) z) t) < -2.0000000000000001e300 or 1.00000000000000005e248 < (*.f64 (*.f64 (*.f64 y 9) z) t)

    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. Taylor expanded in y around 0 6.1

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

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

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

    if -2.0000000000000001e300 < (*.f64 (*.f64 (*.f64 y 9) z) t) < -2e86

    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. Taylor expanded in y around 0 0.3

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(9 \cdot \left(y \cdot z\right)\right)} \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    3. Taylor expanded in y around 0 8.1

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

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

    if -2e86 < (*.f64 (*.f64 (*.f64 y 9) z) t) < 1.00000000000000005e248

    1. Initial program 0.6

      \[\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 y around 0 1.8

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

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

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

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

Reproduce

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