Average Error: 2.9 → 0.6
Time: 13.6s
Precision: binary64
Cost: 13764
\[ \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}\;z \leq 10000000000:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, y \cdot \left(z \cdot -9\right), a \cdot \left(27 \cdot b\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 (<= z 10000000000.0)
   (fma a (* 27.0 b) (+ (* x 2.0) (* y (* (* z t) -9.0))))
   (fma x 2.0 (fma t (* y (* z -9.0)) (* a (* 27.0 b))))))
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 (z <= 10000000000.0) {
		tmp = fma(a, (27.0 * b), ((x * 2.0) + (y * ((z * t) * -9.0))));
	} else {
		tmp = fma(x, 2.0, fma(t, (y * (z * -9.0)), (a * (27.0 * b))));
	}
	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 (z <= 10000000000.0)
		tmp = fma(a, Float64(27.0 * b), Float64(Float64(x * 2.0) + Float64(y * Float64(Float64(z * t) * -9.0))));
	else
		tmp = fma(x, 2.0, fma(t, Float64(y * Float64(z * -9.0)), Float64(a * Float64(27.0 * b))));
	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[z, 10000000000.0], N[(a * N[(27.0 * b), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] + N[(y * N[(N[(z * t), $MachinePrecision] * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * 2.0 + N[(t * N[(y * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + N[(a * N[(27.0 * b), $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}\;z \leq 10000000000:\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\right)\\

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


\end{array}

Error

Target

Original2.9
Target3.3
Herbie0.6
\[\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 z < 1e10

    1. Initial program 3.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)} \]
      Proof
      (fma.f64 a (*.f64 27 b) (-.f64 (*.f64 x 2) (*.f64 y (*.f64 9 (*.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 a (*.f64 27 b) (-.f64 (*.f64 x 2) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y 9) (*.f64 z t))))): 12 points increase in error, 12 points decrease in error
      (fma.f64 a (*.f64 27 b) (-.f64 (*.f64 x 2) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (*.f64 y 9) z) t)))): 30 points increase in error, 18 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (*.f64 27 b)) (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)))): 1 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b)) (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t))): 17 points increase in error, 12 points decrease in error
      (Rewrite<= +-commutative_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 1e10 < z

    1. Initial program 0.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, y \cdot \left(z \cdot -9\right), a \cdot \left(27 \cdot b\right)\right)\right)} \]
      Proof
      (fma.f64 x 2 (fma.f64 t (*.f64 y (*.f64 z -9)) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 t (*.f64 y (*.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 t (*.f64 y (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 t (*.f64 y (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 t (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y (*.f64 9 z)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 t (neg.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y 9) z))) (*.f64 a (*.f64 27 b)))): 13 points increase in error, 5 points decrease in error
      (fma.f64 x 2 (fma.f64 t (neg.f64 (*.f64 (*.f64 y 9) z)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b)))): 17 points increase in error, 12 points decrease in error
      (fma.f64 x 2 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 t (neg.f64 (*.f64 (*.f64 y 9) z))) (*.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 t (*.f64 (*.f64 y 9) z)))) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 (*.f64 y 9) z) t))) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 (*.f64 (*.f64 (*.f64 y 9) z) t))) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (*.f64 (*.f64 a 27) b))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.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. Recombined 2 regimes into one program.
  4. Final simplification0.6

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

Alternatives

Alternative 1
Error0.5
Cost7492
\[\begin{array}{l} \mathbf{if}\;z \leq 0.01:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(-9 \cdot \left(z \cdot y\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 2
Error12.3
Cost1872
\[\begin{array}{l} t_1 := x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ t_2 := b \cdot \left(a \cdot 27\right) + -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;x \cdot 2 \leq -5 \cdot 10^{-24}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \cdot 2 \leq 5 \cdot 10^{-127}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot 2 \leq 4 \cdot 10^{-83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot 2 \leq 2 \cdot 10^{-7}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error0.8
Cost1476
\[\begin{array}{l} \mathbf{if}\;z \cdot \left(y \cdot 9\right) \leq 5 \cdot 10^{+306}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 4
Error1.3
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{+64}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(-9 \cdot \left(z \cdot y\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 5
Error0.6
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 0.01:\\ \;\;\;\;x \cdot 2 + \left(a \cdot \left(27 \cdot b\right) + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(-9 \cdot \left(z \cdot y\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 6
Error14.6
Cost968
\[\begin{array}{l} t_1 := x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;a \leq -6.5 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 4.95 \cdot 10^{-166}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error28.5
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -8.9 \cdot 10^{-29}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-289}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 4.9 \cdot 10^{-170}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-7}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 8
Error28.5
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -1.26 \cdot 10^{-27}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-289}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-167}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-6}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 9
Error28.5
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -7.6 \cdot 10^{-27}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-289}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-168}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-6}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 10
Error16.7
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{-13}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+127}:\\ \;\;\;\;x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 11
Error29.6
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -2.15 \cdot 10^{-54}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-202}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-6}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 12
Error27.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-26}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-6}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 13
Error27.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{-25}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-7}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 14
Error37.2
Cost192
\[x + x \]

Error

Reproduce

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