Average Error: 3.1 → 0.5
Time: 17.8s
Precision: binary64
Cost: 7492
\[ \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 1500000000000:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\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 (<= z 1500000000000.0)
   (fma a (* 27.0 b) (- (* x 2.0) (* y (* 9.0 (* z t)))))
   (+ (- (* 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 (z <= 1500000000000.0) {
		tmp = fma(a, (27.0 * b), ((x * 2.0) - (y * (9.0 * (z * t)))));
	} 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 (z <= 1500000000000.0)
		tmp = fma(a, Float64(27.0 * b), Float64(Float64(x * 2.0) - Float64(y * Float64(9.0 * Float64(z * t)))));
	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[z, 1500000000000.0], N[(a * N[(27.0 * b), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] - N[(y * N[(9.0 * N[(z * t), $MachinePrecision]), $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}\;z \leq 1500000000000:\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\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.4
Herbie0.5
\[\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 < 1.5e12

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

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

      [Start]3.3

      \[ \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]

      +-commutative [=>]3.3

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

      associate-*l* [=>]3.4

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

      fma-def [=>]3.4

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

      associate-*l* [=>]0.6

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

      associate-*l* [=>]0.5

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

    if 1.5e12 < z

    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 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 1500000000000:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\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
Error21.5
Cost1633
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ t_2 := t_1 + x \cdot 2\\ \mathbf{if}\;x \leq -1.26 \cdot 10^{+17}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-10}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq -1.02 \cdot 10^{-270}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 8.4 \cdot 10^{-290}:\\ \;\;\;\;\left(z \cdot -9\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \leq 2.35 \cdot 10^{-237}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{-143} \lor \neg \left(x \leq 4.5 \cdot 10^{-117}\right) \land x \leq 5.6 \cdot 10^{-43}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error21.5
Cost1633
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ t_2 := t_1 + x \cdot 2\\ \mathbf{if}\;x \leq -7.8 \cdot 10^{+16}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-10}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-272}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{-286}:\\ \;\;\;\;\left(z \cdot -9\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-234}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-141} \lor \neg \left(x \leq 2.6 \cdot 10^{-117}\right) \land x \leq 5.6 \cdot 10^{-43}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error30.3
Cost1504
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+27}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-45}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-209}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-286}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-235}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-142}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{-117}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{+71}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 4
Error30.4
Cost1504
\[\begin{array}{l} t_1 := -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -2.85 \cdot 10^{+19}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.02 \cdot 10^{-44}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-208}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-286}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.48 \cdot 10^{-238}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq 2.25 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-119}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 7 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 5
Error30.4
Cost1504
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;x \leq -1.1 \cdot 10^{+23}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -8.4 \cdot 10^{-45}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.65 \cdot 10^{-287}:\\ \;\;\;\;\left(z \cdot -9\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-237}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-142}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-117}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.6 \cdot 10^{+71}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 6
Error13.2
Cost1492
\[\begin{array}{l} t_1 := -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ t_2 := x \cdot 2 + t_1\\ t_3 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;x \leq -1.02 \cdot 10^{+17}:\\ \;\;\;\;t_3 + x \cdot 2\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-20}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + t_1\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-32}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{-240}:\\ \;\;\;\;t_3 + z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 7 \cdot 10^{+73}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) - t \cdot \left(z \cdot \left(y \cdot 9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error10.0
Cost1481
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+14} \lor \neg \left(t_1 \leq 4 \cdot 10^{-9}\right):\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 8
Error1.6
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 2.85 \cdot 10^{+94}:\\ \;\;\;\;\left(x \cdot 2 - \left(z \cdot t\right) \cdot \left(y \cdot 9\right)\right) + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) - t \cdot \left(z \cdot \left(y \cdot 9\right)\right)\\ \end{array} \]
Alternative 9
Error0.7
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 4 \cdot 10^{-145}:\\ \;\;\;\;\left(x \cdot 2 - \left(z \cdot t\right) \cdot \left(y \cdot 9\right)\right) + a \cdot \left(27 \cdot b\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 10
Error12.6
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{+29}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+76}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 11
Error28.4
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{+46} \lor \neg \left(x \leq 5.2 \cdot 10^{+75}\right):\\ \;\;\;\;x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \end{array} \]
Alternative 12
Error28.3
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{+46}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 10^{+74}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 13
Error37.4
Cost192
\[x \cdot 2 \]

Error

Reproduce

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