Average Error: 3.1 → 0.9
Time: 21.8s
Precision: binary64
Cost: 13892
\[ \begin{array}{c}[y, z, t] = \mathsf{sort}([y, z, t])\\ \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 -5 \cdot 10^{+187}:\\ \;\;\;\;\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)\\ \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} \]
(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) -5e+187)
   (fma x 2.0 (fma y (* t (* z -9.0)) (* a (* 27.0 b))))
   (+ (+ (* x 2.0) (* t (* z (* y -9.0)))) (* b (* a 27.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) <= -5e+187) {
		tmp = fma(x, 2.0, fma(y, (t * (z * -9.0)), (a * (27.0 * b))));
	} else {
		tmp = ((x * 2.0) + (t * (z * (y * -9.0)))) + (b * (a * 27.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) <= -5e+187)
		tmp = fma(x, 2.0, fma(y, Float64(t * Float64(z * -9.0)), Float64(a * Float64(27.0 * b))));
	else
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(t * Float64(z * Float64(y * -9.0)))) + Float64(b * Float64(a * 27.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], -5e+187], N[(x * 2.0 + N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + N[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(t * N[(z * N[(y * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(a * 27.0), $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 -5 \cdot 10^{+187}:\\
\;\;\;\;\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)\\

\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}

Error

Target

Original3.1
Target3.5
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 2 regimes
  2. if (*.f64 y 9) < -5.0000000000000001e187

    1. Initial program 12.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. Simplified1.3

      \[\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)))): 19 points increase in error, 10 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)))): 0 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))): 18 points increase in error, 17 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))): 11 points increase in error, 11 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

    if -5.0000000000000001e187 < (*.f64 y 9)

    1. Initial program 0.8

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot 9 \leq -5 \cdot 10^{+187}:\\ \;\;\;\;\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)\\ \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} \]

Alternatives

Alternative 1
Error0.5
Cost7492
\[\begin{array}{l} \mathbf{if}\;t \leq 7.304885871702798 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, b \cdot \left(a \cdot 27\right) + \left(z \cdot -9\right) \cdot \left(y \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + 27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 2
Error9.9
Cost1480
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -4.5 \cdot 10^{-38}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + x \cdot 2\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{-24}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + x \cdot 2\\ \end{array} \]
Alternative 3
Error9.9
Cost1480
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -4.5 \cdot 10^{-38}:\\ \;\;\;\;x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{-24}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + x \cdot 2\\ \end{array} \]
Alternative 4
Error0.8
Cost1476
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \leq 2 \cdot 10^{+285}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 5
Error0.9
Cost1476
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \leq 5 \cdot 10^{+277}:\\ \;\;\;\;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}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \end{array} \]
Alternative 6
Error0.9
Cost1476
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \leq 2 \cdot 10^{+285}:\\ \;\;\;\;\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}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 7
Error28.2
Cost1376
\[\begin{array}{l} t_1 := \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\\ t_2 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -9.209817605139342 \cdot 10^{-66}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -6.904521862192657 \cdot 10^{-103}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -7.934922646190734 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.334893229084465 \cdot 10^{-296}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq 6.984497329259241 \cdot 10^{-286}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.3761227065439425 \cdot 10^{-207}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.1331063190187006 \cdot 10^{-147}:\\ \;\;\;\;t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\\ \mathbf{elif}\;x \leq 8.325770079038133 \cdot 10^{-42}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 8
Error28.2
Cost1376
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -9.209817605139342 \cdot 10^{-66}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -6.904521862192657 \cdot 10^{-103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.934922646190734 \cdot 10^{-116}:\\ \;\;\;\;\left(t \cdot z\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;x \leq -3.334893229084465 \cdot 10^{-296}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq 6.984497329259241 \cdot 10^{-286}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 4.3761227065439425 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.1331063190187006 \cdot 10^{-147}:\\ \;\;\;\;t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\\ \mathbf{elif}\;x \leq 8.325770079038133 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 9
Error19.0
Cost1368
\[\begin{array}{l} t_1 := t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\\ t_2 := b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \mathbf{if}\;t \leq 4.1 \cdot 10^{+90}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.8 \cdot 10^{+120}:\\ \;\;\;\;\left(t \cdot z\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;t \leq 3.15 \cdot 10^{+189}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{+202}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.35 \cdot 10^{+244}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 4.7 \cdot 10^{+293}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 10
Error13.2
Cost1364
\[\begin{array}{l} t_1 := x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{if}\;x \leq -1.4076422715938843 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.793211996510185 \cdot 10^{-174}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 8.325770079038133 \cdot 10^{-42}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(z \cdot -9\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \leq 3.5061589444665925 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.073984704131038 \cdot 10^{-9}:\\ \;\;\;\;x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 11
Error13.2
Cost1364
\[\begin{array}{l} t_1 := x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ t_2 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;x \leq -1.4076422715938843 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.793211996510185 \cdot 10^{-174}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right) + t_2\\ \mathbf{elif}\;x \leq 8.325770079038133 \cdot 10^{-42}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(z \cdot -9\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \leq 3.5061589444665925 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.073984704131038 \cdot 10^{-9}:\\ \;\;\;\;x \cdot 2 + t_2\\ \mathbf{else}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 12
Error28.2
Cost1112
\[\begin{array}{l} t_1 := t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\\ t_2 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -9.209817605139342 \cdot 10^{-66}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -6.904521862192657 \cdot 10^{-103}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -7.934922646190734 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.3761227065439425 \cdot 10^{-207}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq 4.1331063190187006 \cdot 10^{-147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.325770079038133 \cdot 10^{-42}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 13
Error13.4
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4076422715938843 \cdot 10^{-63}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{elif}\;x \leq 1.6839163991057112 \cdot 10^{-72}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 14
Error13.2
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4076422715938843 \cdot 10^{-63}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{elif}\;x \leq 8.884407652583637 \cdot 10^{-47}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + x\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 15
Error27.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -9.209817605139342 \cdot 10^{-66}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 8.325770079038133 \cdot 10^{-42}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 16
Error27.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -9.209817605139342 \cdot 10^{-66}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 8.325770079038133 \cdot 10^{-42}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 17
Error36.3
Cost192
\[x \cdot 2 \]

Error

Reproduce

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