Average Error: 5.8 → 1.6
Time: 40.5s
Precision: binary64
\[[y, z] = \mathsf{sort}([y, z]) \[j, k] = \mathsf{sort}([j, k]) \\]
\[\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 := \mathsf{fma}\left(18, y \cdot \left(z \cdot t\right), i \cdot -4\right)\\ t_2 := \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) - \left(x \cdot 4\right) \cdot i\\ t_3 := \mathsf{fma}\left(-27, j \cdot k, b \cdot c\right)\\ \mathbf{if}\;t_2 \leq -2.6221347697340514 \cdot 10^{+302}:\\ \;\;\;\;\mathsf{fma}\left(x, t_1, \mathsf{fma}\left(a, t \cdot -4, {\left(\sqrt[3]{t_3}\right)}^{3}\right)\right)\\ \mathbf{elif}\;t_2 \leq 1.9650273340037626 \cdot 10^{+266}:\\ \;\;\;\;t_2 - k \cdot \left(j \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, t_1, \mathsf{fma}\left(a, t \cdot -4, t_3\right)\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 (fma 18.0 (* y (* z t)) (* i -4.0)))
        (t_2
         (-
          (+ (- (* (* (* (* x 18.0) y) z) t) (* t (* a 4.0))) (* b c))
          (* (* x 4.0) i)))
        (t_3 (fma -27.0 (* j k) (* b c))))
   (if (<= t_2 -2.6221347697340514e+302)
     (fma x t_1 (fma a (* t -4.0) (pow (cbrt t_3) 3.0)))
     (if (<= t_2 1.9650273340037626e+266)
       (- t_2 (* k (* j 27.0)))
       (fma x t_1 (fma a (* t -4.0) t_3))))))
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 = fma(18.0, (y * (z * t)), (i * -4.0));
	double t_2 = ((((((x * 18.0) * y) * z) * t) - (t * (a * 4.0))) + (b * c)) - ((x * 4.0) * i);
	double t_3 = fma(-27.0, (j * k), (b * c));
	double tmp;
	if (t_2 <= -2.6221347697340514e+302) {
		tmp = fma(x, t_1, fma(a, (t * -4.0), pow(cbrt(t_3), 3.0)));
	} else if (t_2 <= 1.9650273340037626e+266) {
		tmp = t_2 - (k * (j * 27.0));
	} else {
		tmp = fma(x, t_1, fma(a, (t * -4.0), t_3));
	}
	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 = fma(18.0, Float64(y * Float64(z * t)), Float64(i * -4.0))
	t_2 = Float64(Float64(Float64(Float64(Float64(Float64(Float64(x * 18.0) * y) * z) * t) - Float64(t * Float64(a * 4.0))) + Float64(b * c)) - Float64(Float64(x * 4.0) * i))
	t_3 = fma(-27.0, Float64(j * k), Float64(b * c))
	tmp = 0.0
	if (t_2 <= -2.6221347697340514e+302)
		tmp = fma(x, t_1, fma(a, Float64(t * -4.0), (cbrt(t_3) ^ 3.0)));
	elseif (t_2 <= 1.9650273340037626e+266)
		tmp = Float64(t_2 - Float64(k * Float64(j * 27.0)));
	else
		tmp = fma(x, t_1, fma(a, Float64(t * -4.0), t_3));
	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[(18.0 * N[(y * N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(i * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[(N[(N[(x * 18.0), $MachinePrecision] * y), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision] - N[(t * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * c), $MachinePrecision]), $MachinePrecision] - N[(N[(x * 4.0), $MachinePrecision] * i), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(-27.0 * N[(j * k), $MachinePrecision] + N[(b * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -2.6221347697340514e+302], N[(x * t$95$1 + N[(a * N[(t * -4.0), $MachinePrecision] + N[Power[N[Power[t$95$3, 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1.9650273340037626e+266], N[(t$95$2 - N[(k * N[(j * 27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * t$95$1 + N[(a * N[(t * -4.0), $MachinePrecision] + t$95$3), $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 := \mathsf{fma}\left(18, y \cdot \left(z \cdot t\right), i \cdot -4\right)\\
t_2 := \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) - \left(x \cdot 4\right) \cdot i\\
t_3 := \mathsf{fma}\left(-27, j \cdot k, b \cdot c\right)\\
\mathbf{if}\;t_2 \leq -2.6221347697340514 \cdot 10^{+302}:\\
\;\;\;\;\mathsf{fma}\left(x, t_1, \mathsf{fma}\left(a, t \cdot -4, {\left(\sqrt[3]{t_3}\right)}^{3}\right)\right)\\

\mathbf{elif}\;t_2 \leq 1.9650273340037626 \cdot 10^{+266}:\\
\;\;\;\;t_2 - k \cdot \left(j \cdot 27\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, t_1, \mathsf{fma}\left(a, t \cdot -4, t_3\right)\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

Bits error versus c

Bits error versus i

Bits error versus j

Bits error versus k

Target

Original5.8
Target1.6
Herbie1.6
\[\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)) < -2.62213476973405143e302

    1. Initial program 53.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. Simplified6.7

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

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

    if -2.62213476973405143e302 < (-.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.9650273340037626e266

    1. Initial program 0.3

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

    if 1.9650273340037626e266 < (-.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 27.3

      \[\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. Simplified9.4

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

    \[\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) - \left(x \cdot 4\right) \cdot i \leq -2.6221347697340514 \cdot 10^{+302}:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(18, y \cdot \left(z \cdot t\right), i \cdot -4\right), \mathsf{fma}\left(a, t \cdot -4, {\left(\sqrt[3]{\mathsf{fma}\left(-27, j \cdot k, b \cdot c\right)}\right)}^{3}\right)\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) - \left(x \cdot 4\right) \cdot i \leq 1.9650273340037626 \cdot 10^{+266}:\\ \;\;\;\;\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) - \left(x \cdot 4\right) \cdot i\right) - k \cdot \left(j \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(18, y \cdot \left(z \cdot t\right), i \cdot -4\right), \mathsf{fma}\left(a, t \cdot -4, \mathsf{fma}\left(-27, j \cdot k, b \cdot c\right)\right)\right)\\ \end{array} \]

Reproduce

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