Average Error: 5.6 → 1.5
Time: 9.1s
Precision: binary64
\[ \begin{array}{c}[y, z] = \mathsf{sort}([y, z])\\ [j, k] = \mathsf{sort}([j, k])\\ \end{array} \]
\[\left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k \]
\[\begin{array}{l} t_1 := t \cdot \left(a \cdot -4\right)\\ t_2 := i \cdot \left(x \cdot -4\right)\\ t_3 := \left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t + t_1\right) + b \cdot c\right) + t_2\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;\left(\mathsf{fma}\left(b, c, z \cdot \left(y \cdot \left(18 \cdot \left(x \cdot t\right)\right)\right) + t_1\right) + t_2\right) + k \cdot \left(j \cdot -27\right)\\ \mathbf{elif}\;t_3 \leq 4 \cdot 10^{+284}:\\ \;\;\;\;t_3 + \left(j \cdot k\right) \cdot -27\\ \mathbf{else}:\\ \;\;\;\;\left(\left(b \cdot c + \left(\left(x \cdot 18\right) \cdot \left(y \cdot \left(z \cdot t\right)\right) + t_1\right)\right) + t_2\right) + j \cdot \left(k \cdot -27\right)\\ \end{array} \]
(FPCore (x y z t a b c i j k)
 :precision binary64
 (-
  (-
   (+ (- (* (* (* (* x 18.0) y) z) t) (* (* a 4.0) t)) (* b c))
   (* (* x 4.0) i))
  (* (* j 27.0) k)))
(FPCore (x y z t a b c i j k)
 :precision binary64
 (let* ((t_1 (* t (* a -4.0)))
        (t_2 (* i (* x -4.0)))
        (t_3 (+ (+ (+ (* (* (* (* x 18.0) y) z) t) t_1) (* b c)) t_2)))
   (if (<= t_3 (- INFINITY))
     (+
      (+ (fma b c (+ (* z (* y (* 18.0 (* x t)))) t_1)) t_2)
      (* k (* j -27.0)))
     (if (<= t_3 4e+284)
       (+ t_3 (* (* j k) -27.0))
       (+
        (+ (+ (* b c) (+ (* (* x 18.0) (* y (* z t))) t_1)) t_2)
        (* j (* k -27.0)))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i, double j, double k) {
	return (((((((x * 18.0) * y) * z) * t) - ((a * 4.0) * t)) + (b * c)) - ((x * 4.0) * i)) - ((j * 27.0) * k);
}
double code(double x, double y, double z, double t, double a, double b, double c, double i, double j, double k) {
	double t_1 = t * (a * -4.0);
	double t_2 = i * (x * -4.0);
	double t_3 = ((((((x * 18.0) * y) * z) * t) + t_1) + (b * c)) + t_2;
	double tmp;
	if (t_3 <= -((double) INFINITY)) {
		tmp = (fma(b, c, ((z * (y * (18.0 * (x * t)))) + t_1)) + t_2) + (k * (j * -27.0));
	} else if (t_3 <= 4e+284) {
		tmp = t_3 + ((j * k) * -27.0);
	} else {
		tmp = (((b * c) + (((x * 18.0) * (y * (z * t))) + t_1)) + t_2) + (j * (k * -27.0));
	}
	return tmp;
}
function code(x, y, z, t, a, b, c, i, j, k)
	return Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(x * 18.0) * y) * z) * t) - Float64(Float64(a * 4.0) * t)) + Float64(b * c)) - Float64(Float64(x * 4.0) * i)) - Float64(Float64(j * 27.0) * k))
end
function code(x, y, z, t, a, b, c, i, j, k)
	t_1 = Float64(t * Float64(a * -4.0))
	t_2 = Float64(i * Float64(x * -4.0))
	t_3 = Float64(Float64(Float64(Float64(Float64(Float64(Float64(x * 18.0) * y) * z) * t) + t_1) + Float64(b * c)) + t_2)
	tmp = 0.0
	if (t_3 <= Float64(-Inf))
		tmp = Float64(Float64(fma(b, c, Float64(Float64(z * Float64(y * Float64(18.0 * Float64(x * t)))) + t_1)) + t_2) + Float64(k * Float64(j * -27.0)));
	elseif (t_3 <= 4e+284)
		tmp = Float64(t_3 + Float64(Float64(j * k) * -27.0));
	else
		tmp = Float64(Float64(Float64(Float64(b * c) + Float64(Float64(Float64(x * 18.0) * Float64(y * Float64(z * t))) + t_1)) + t_2) + Float64(j * Float64(k * -27.0)));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_, i_, j_, k_] := N[(N[(N[(N[(N[(N[(N[(N[(x * 18.0), $MachinePrecision] * y), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(b * c), $MachinePrecision]), $MachinePrecision] - N[(N[(x * 4.0), $MachinePrecision] * i), $MachinePrecision]), $MachinePrecision] - N[(N[(j * 27.0), $MachinePrecision] * k), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_, i_, j_, k_] := Block[{t$95$1 = N[(t * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(i * N[(x * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[(N[(N[(x * 18.0), $MachinePrecision] * y), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision] + t$95$1), $MachinePrecision] + N[(b * c), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]}, If[LessEqual[t$95$3, (-Infinity)], N[(N[(N[(b * c + N[(N[(z * N[(y * N[(18.0 * N[(x * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision] + N[(k * N[(j * -27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 4e+284], N[(t$95$3 + N[(N[(j * k), $MachinePrecision] * -27.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(b * c), $MachinePrecision] + N[(N[(N[(x * 18.0), $MachinePrecision] * N[(y * N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision] + N[(j * N[(k * -27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k
\begin{array}{l}
t_1 := t \cdot \left(a \cdot -4\right)\\
t_2 := i \cdot \left(x \cdot -4\right)\\
t_3 := \left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t + t_1\right) + b \cdot c\right) + t_2\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;\left(\mathsf{fma}\left(b, c, z \cdot \left(y \cdot \left(18 \cdot \left(x \cdot t\right)\right)\right) + t_1\right) + t_2\right) + k \cdot \left(j \cdot -27\right)\\

\mathbf{elif}\;t_3 \leq 4 \cdot 10^{+284}:\\
\;\;\;\;t_3 + \left(j \cdot k\right) \cdot -27\\

\mathbf{else}:\\
\;\;\;\;\left(\left(b \cdot c + \left(\left(x \cdot 18\right) \cdot \left(y \cdot \left(z \cdot t\right)\right) + t_1\right)\right) + t_2\right) + j \cdot \left(k \cdot -27\right)\\


\end{array}

Error

Target

Original5.6
Target1.7
Herbie1.5
\[\begin{array}{l} \mathbf{if}\;t < -1.6210815397541398 \cdot 10^{-69}:\\ \;\;\;\;\left(\left(18 \cdot t\right) \cdot \left(\left(x \cdot y\right) \cdot z\right) - \left(a \cdot t + i \cdot x\right) \cdot 4\right) - \left(\left(k \cdot j\right) \cdot 27 - c \cdot b\right)\\ \mathbf{elif}\;t < 165.68027943805222:\\ \;\;\;\;\left(\left(18 \cdot y\right) \cdot \left(x \cdot \left(z \cdot t\right)\right) - \left(a \cdot t + i \cdot x\right) \cdot 4\right) + \left(c \cdot b - 27 \cdot \left(k \cdot j\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(18 \cdot t\right) \cdot \left(\left(x \cdot y\right) \cdot z\right) - \left(a \cdot t + i \cdot x\right) \cdot 4\right) - \left(\left(k \cdot j\right) \cdot 27 - c \cdot b\right)\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (-.f64 (+.f64 (-.f64 (*.f64 (*.f64 (*.f64 (*.f64 x 18) y) z) t) (*.f64 (*.f64 a 4) t)) (*.f64 b c)) (*.f64 (*.f64 x 4) i)) < -inf.0

    1. Initial program 64.0

      \[\left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k \]
    2. Applied egg-rr5.8

      \[\leadsto \left(\left(\left(\color{blue}{\left(0 + \left(x \cdot 18\right) \cdot \left(y \cdot \left(z \cdot t\right)\right)\right)} - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k \]
    3. Applied egg-rr19.1

      \[\leadsto \left(\color{blue}{\mathsf{fma}\left(b, c, x \cdot \left(18 \cdot \left(\left(y \cdot z\right) \cdot t\right)\right) - t \cdot \left(a \cdot 4\right)\right)} - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k \]
    4. Taylor expanded in x around 0 12.3

      \[\leadsto \left(\mathsf{fma}\left(b, c, \color{blue}{18 \cdot \left(y \cdot \left(t \cdot \left(z \cdot x\right)\right)\right)} - t \cdot \left(a \cdot 4\right)\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k \]
    5. Simplified15.5

      \[\leadsto \left(\mathsf{fma}\left(b, c, \color{blue}{z \cdot \left(y \cdot \left(18 \cdot \left(t \cdot x\right)\right)\right)} - t \cdot \left(a \cdot 4\right)\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k \]

    if -inf.0 < (-.f64 (+.f64 (-.f64 (*.f64 (*.f64 (*.f64 (*.f64 x 18) y) z) t) (*.f64 (*.f64 a 4) t)) (*.f64 b c)) (*.f64 (*.f64 x 4) i)) < 4.00000000000000032e284

    1. Initial program 0.4

      \[\left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k \]
    2. Taylor expanded in j around 0 0.3

      \[\leadsto \left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \color{blue}{27 \cdot \left(k \cdot j\right)} \]

    if 4.00000000000000032e284 < (-.f64 (+.f64 (-.f64 (*.f64 (*.f64 (*.f64 (*.f64 x 18) y) z) t) (*.f64 (*.f64 a 4) t)) (*.f64 b c)) (*.f64 (*.f64 x 4) i))

    1. Initial program 35.9

      \[\left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k \]
    2. Applied egg-rr8.6

      \[\leadsto \left(\left(\left(\color{blue}{\left(0 + \left(x \cdot 18\right) \cdot \left(y \cdot \left(z \cdot t\right)\right)\right)} - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \left(j \cdot 27\right) \cdot k \]
    3. Applied egg-rr8.6

      \[\leadsto \left(\left(\left(\left(0 + \left(x \cdot 18\right) \cdot \left(y \cdot \left(z \cdot t\right)\right)\right) - \left(a \cdot 4\right) \cdot t\right) + b \cdot c\right) - \left(x \cdot 4\right) \cdot i\right) - \color{blue}{{\left(j \cdot \left(27 \cdot k\right)\right)}^{1}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t + t \cdot \left(a \cdot -4\right)\right) + b \cdot c\right) + i \cdot \left(x \cdot -4\right) \leq -\infty:\\ \;\;\;\;\left(\mathsf{fma}\left(b, c, z \cdot \left(y \cdot \left(18 \cdot \left(x \cdot t\right)\right)\right) + t \cdot \left(a \cdot -4\right)\right) + i \cdot \left(x \cdot -4\right)\right) + k \cdot \left(j \cdot -27\right)\\ \mathbf{elif}\;\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t + t \cdot \left(a \cdot -4\right)\right) + b \cdot c\right) + i \cdot \left(x \cdot -4\right) \leq 4 \cdot 10^{+284}:\\ \;\;\;\;\left(\left(\left(\left(\left(\left(x \cdot 18\right) \cdot y\right) \cdot z\right) \cdot t + t \cdot \left(a \cdot -4\right)\right) + b \cdot c\right) + i \cdot \left(x \cdot -4\right)\right) + \left(j \cdot k\right) \cdot -27\\ \mathbf{else}:\\ \;\;\;\;\left(\left(b \cdot c + \left(\left(x \cdot 18\right) \cdot \left(y \cdot \left(z \cdot t\right)\right) + t \cdot \left(a \cdot -4\right)\right)\right) + i \cdot \left(x \cdot -4\right)\right) + j \cdot \left(k \cdot -27\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022192 
(FPCore (x y z t a b c i j k)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, E"
  :precision binary64

  :herbie-target
  (if (< t -1.6210815397541398e-69) (- (- (* (* 18.0 t) (* (* x y) z)) (* (+ (* a t) (* i x)) 4.0)) (- (* (* k j) 27.0) (* c b))) (if (< t 165.68027943805222) (+ (- (* (* 18.0 y) (* x (* z t))) (* (+ (* a t) (* i x)) 4.0)) (- (* c b) (* 27.0 (* k j)))) (- (- (* (* 18.0 t) (* (* x y) z)) (* (+ (* a t) (* i x)) 4.0)) (- (* (* k j) 27.0) (* c b)))))

  (- (- (+ (- (* (* (* (* x 18.0) y) z) t) (* (* a 4.0) t)) (* b c)) (* (* x 4.0) i)) (* (* j 27.0) k)))