Average Error: 2.8 → 0.9
Time: 15.4s
Precision: binary64
Cost: 14788
\[ \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 := b \cdot \left(a \cdot 27\right)\\ t_2 := \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + t_1\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\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)\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+283}:\\ \;\;\;\;t_1 + \left(x \cdot 2 + t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + 27 \cdot \left(a \cdot b\right)\right) + -9 \cdot \left(z \cdot \left(y \cdot t\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
 (let* ((t_1 (* b (* a 27.0)))
        (t_2 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) t_1)))
   (if (<= t_2 (- INFINITY))
     (fma x 2.0 (fma y (* z (* t -9.0)) (* a (* 27.0 b))))
     (if (<= t_2 4e+283)
       (+ t_1 (+ (* x 2.0) (* t (* -9.0 (* y z)))))
       (+ (+ (* x 2.0) (* 27.0 (* a b))) (* -9.0 (* z (* y t))))))))
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 = b * (a * 27.0);
	double t_2 = ((x * 2.0) - (((y * 9.0) * z) * t)) + t_1;
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = fma(x, 2.0, fma(y, (z * (t * -9.0)), (a * (27.0 * b))));
	} else if (t_2 <= 4e+283) {
		tmp = t_1 + ((x * 2.0) + (t * (-9.0 * (y * z))));
	} else {
		tmp = ((x * 2.0) + (27.0 * (a * b))) + (-9.0 * (z * (y * t)));
	}
	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(b * Float64(a * 27.0))
	t_2 = Float64(Float64(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + t_1)
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = fma(x, 2.0, fma(y, Float64(z * Float64(t * -9.0)), Float64(a * Float64(27.0 * b))));
	elseif (t_2 <= 4e+283)
		tmp = Float64(t_1 + Float64(Float64(x * 2.0) + Float64(t * Float64(-9.0 * Float64(y * z)))));
	else
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(27.0 * Float64(a * b))) + Float64(-9.0 * Float64(z * Float64(y * t))));
	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]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(x * 2.0 + N[(y * N[(z * N[(t * -9.0), $MachinePrecision]), $MachinePrecision] + N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 4e+283], N[(t$95$1 + N[(N[(x * 2.0), $MachinePrecision] + N[(t * N[(-9.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(27.0 * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-9.0 * N[(z * N[(y * t), $MachinePrecision]), $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 := b \cdot \left(a \cdot 27\right)\\
t_2 := \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + t_1\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\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)\\

\mathbf{elif}\;t_2 \leq 4 \cdot 10^{+283}:\\
\;\;\;\;t_1 + \left(x \cdot 2 + t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\right)\\

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


\end{array}

Error

Target

Original2.8
Target3.2
Herbie0.9
\[\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)) < -inf.0

    1. Initial program 64.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. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), a \cdot \left(27 \cdot b\right)\right)\right)} \]
      Proof
      (fma.f64 x 2 (fma.f64 y (*.f64 t (*.f64 z -9)) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (*.f64 t (*.f64 z (Rewrite<= metadata-eval (neg.f64 9)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (*.f64 t (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 z 9)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (*.f64 t (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 9 z)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 (*.f64 9 z)) t)) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (Rewrite=> distribute-lft-neg-out_binary64 (neg.f64 (*.f64 (*.f64 9 z) t))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (neg.f64 (*.f64 (*.f64 9 z) t)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b)))): 8 points increase in error, 17 points decrease in error
      (fma.f64 x 2 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (neg.f64 (*.f64 (*.f64 9 z) t))) (*.f64 (*.f64 a 27) b)))): 1 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y (*.f64 (*.f64 9 z) t)))) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y (*.f64 9 z)) t))) (*.f64 (*.f64 a 27) b))): 27 points increase in error, 25 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (*.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y 9) z)) t)) (*.f64 (*.f64 a 27) b))): 10 points increase in error, 12 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (*.f64 (*.f64 (*.f64 y 9) z) t)) (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (*.f64 (*.f64 a 27) b)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (neg.f64 (*.f64 (*.f64 a 27) b)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (neg.f64 (Rewrite<= sub-neg_binary64 (-.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (*.f64 (*.f64 a 27) b))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x 2) (-.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (*.f64 (*.f64 a 27) b)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in t around 0 0.3

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

      \[\leadsto \mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, \color{blue}{\left(-9 \cdot t\right) \cdot z}, a \cdot \left(27 \cdot b\right)\right)\right) \]
      Proof
      (*.f64 (*.f64 -9 t) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 -9 (*.f64 t z))): 34 points increase in error, 45 points decrease in error

    if -inf.0 < (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b)) < 3.99999999999999982e283

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

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

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

    1. Initial program 20.9

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

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(9 \cdot y\right) \cdot \left(t \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      Proof
      (*.f64 (*.f64 9 y) (*.f64 t z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 9 (*.f64 y (*.f64 t z)))): 32 points increase in error, 30 points decrease in error
    4. Applied egg-rr18.9

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

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

      \[\leadsto \left(27 \cdot \left(a \cdot b\right) + x \cdot 2\right) - 9 \cdot \color{blue}{\left(\left(y \cdot t\right) \cdot z\right)} \]
      Proof
      (*.f64 (*.f64 y t) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 t z))): 45 points increase in error, 54 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + b \cdot \left(a \cdot 27\right) \leq -\infty:\\ \;\;\;\;\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)\\ \mathbf{elif}\;\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + b \cdot \left(a \cdot 27\right) \leq 4 \cdot 10^{+283}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 + t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + 27 \cdot \left(a \cdot b\right)\right) + -9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error29.0
Cost1376
\[\begin{array}{l} t_1 := \left(y \cdot t\right) \cdot \left(z \cdot -9\right)\\ t_2 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -1.5136252139870452 \cdot 10^{+69}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.814492891866308 \cdot 10^{-209}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.6166056098330847 \cdot 10^{-278}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 9.751872027444886 \cdot 10^{-233}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.1998839398020824 \cdot 10^{-201}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.761180967648495 \cdot 10^{-162}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 8.760687571845481 \cdot 10^{-127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.2770245847765305 \cdot 10^{+33}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 2
Error12.6
Cost1096
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -1.2127054440277283 \cdot 10^{+87}:\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{elif}\;x \leq 266309312284779260:\\ \;\;\;\;t_1 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]

Error

Reproduce

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