Average Error: 3.1 → 0.7
Time: 12.9s
Precision: binary64
Cost: 7620
\[ \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} \mathbf{if}\;y \cdot 9 \leq -4000000:\\ \;\;\;\;x \cdot 2 + \left(\left(z \cdot t\right) \cdot \left(y \cdot -9\right) - a \cdot \left(b \cdot -27\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 + z \cdot \left(t \cdot \left(y \cdot -9\right)\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
 (if (<= (* y 9.0) -4000000.0)
   (+ (* x 2.0) (- (* (* z t) (* y -9.0)) (* a (* b -27.0))))
   (fma (* a 27.0) b (+ (* x 2.0) (* z (* t (* y -9.0)))))))
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 tmp;
	if ((y * 9.0) <= -4000000.0) {
		tmp = (x * 2.0) + (((z * t) * (y * -9.0)) - (a * (b * -27.0)));
	} else {
		tmp = fma((a * 27.0), b, ((x * 2.0) + (z * (t * (y * -9.0)))));
	}
	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)
	tmp = 0.0
	if (Float64(y * 9.0) <= -4000000.0)
		tmp = Float64(Float64(x * 2.0) + Float64(Float64(Float64(z * t) * Float64(y * -9.0)) - Float64(a * Float64(b * -27.0))));
	else
		tmp = fma(Float64(a * 27.0), b, Float64(Float64(x * 2.0) + Float64(z * Float64(t * Float64(y * -9.0)))));
	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_] := If[LessEqual[N[(y * 9.0), $MachinePrecision], -4000000.0], N[(N[(x * 2.0), $MachinePrecision] + N[(N[(N[(z * t), $MachinePrecision] * N[(y * -9.0), $MachinePrecision]), $MachinePrecision] - N[(a * N[(b * -27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a * 27.0), $MachinePrecision] * b + N[(N[(x * 2.0), $MachinePrecision] + N[(z * N[(t * N[(y * -9.0), $MachinePrecision]), $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}
\mathbf{if}\;y \cdot 9 \leq -4000000:\\
\;\;\;\;x \cdot 2 + \left(\left(z \cdot t\right) \cdot \left(y \cdot -9\right) - a \cdot \left(b \cdot -27\right)\right)\\

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


\end{array}

Error

Target

Original3.1
Target3.4
Herbie0.7
\[\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 2 regimes
  2. if (*.f64 y 9) < -4e6

    1. Initial program 5.1

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

      \[\leadsto \color{blue}{x \cdot 2 - \left(\left(y \cdot 9\right) \cdot \left(z \cdot t\right) - a \cdot \left(27 \cdot b\right)\right)} \]
      Proof
      (-.f64 (*.f64 x 2) (-.f64 (*.f64 (*.f64 y 9) (*.f64 z t)) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 x 2) (-.f64 (*.f64 (*.f64 y 9) (*.f64 z t)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b)))): 10 points increase in error, 18 points decrease in error
      (-.f64 (*.f64 x 2) (-.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b))): 25 points increase in error, 20 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

    if -4e6 < (*.f64 y 9)

    1. Initial program 0.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. Applied egg-rr0.3

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

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

Alternatives

Alternative 1
Error1.0
Cost2120
\[\begin{array}{l} t_1 := \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ t_2 := t \cdot \left(\left(y \cdot 9\right) \cdot z\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+305}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + t_1\\ \end{array} \]
Alternative 2
Error0.8
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{-177}:\\ \;\;\;\;x \cdot 2 + \left(\left(z \cdot t\right) \cdot \left(y \cdot -9\right) - a \cdot \left(b \cdot -27\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 3
Error29.1
Cost1108
\[\begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{+88}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-276}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-212}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 2.05 \cdot 10^{-29}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+48}:\\ \;\;\;\;t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 4
Error15.4
Cost1100
\[\begin{array}{l} t_1 := x \cdot 2 + \left(t \cdot \left(y \cdot z\right)\right) \cdot -9\\ \mathbf{if}\;z \leq -3.35 \cdot 10^{+78}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;z \leq -1.08 \cdot 10^{-198}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-9}:\\ \;\;\;\;x + \left(x - \left(a \cdot b\right) \cdot -27\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error15.3
Cost1100
\[\begin{array}{l} t_1 := \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{if}\;z \leq -7.5 \cdot 10^{-122}:\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{elif}\;z \leq -1.15 \cdot 10^{-195}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + t_1\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-19}:\\ \;\;\;\;x + \left(x - \left(a \cdot b\right) \cdot -27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(t \cdot \left(y \cdot z\right)\right) \cdot -9\\ \end{array} \]
Alternative 6
Error14.6
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{-195}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-21}:\\ \;\;\;\;x + \left(x - \left(a \cdot b\right) \cdot -27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(t \cdot \left(y \cdot z\right)\right) \cdot -9\\ \end{array} \]
Alternative 7
Error28.6
Cost844
\[\begin{array}{l} \mathbf{if}\;x \leq -1.65 \cdot 10^{+91}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-41}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 5.1 \cdot 10^{+48}:\\ \;\;\;\;t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 8
Error15.9
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{+56}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{+47}:\\ \;\;\;\;x + \left(x - \left(a \cdot b\right) \cdot -27\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 9
Error28.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{+88}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+34}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 10
Error28.2
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.38 \cdot 10^{+88}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{+36}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 11
Error37.6
Cost192
\[x + x \]

Error

Reproduce

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