?

Average Error: 3.0 → 0.6
Time: 18.6s
Precision: binary64
Cost: 7492

?

\[ \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}\;z \leq 5 \cdot 10^{-12}:\\ \;\;\;\;\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 + \left(z \cdot y\right) \cdot \left(t \cdot -9\right)\right) + a \cdot \left(27 \cdot b\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 5e-12)
   (fma a (* 27.0 b) (+ (* x 2.0) (* y (* -9.0 (* z t)))))
   (+ (+ (* x 2.0) (* (* z y) (* t -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 <= 5e-12) {
		tmp = fma(a, (27.0 * b), ((x * 2.0) + (y * (-9.0 * (z * t)))));
	} else {
		tmp = ((x * 2.0) + ((z * y) * (t * -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 <= 5e-12)
		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(Float64(z * y) * Float64(t * -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, 5e-12], 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[(N[(z * y), $MachinePrecision] * N[(t * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a * N[(27.0 * b), $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 5 \cdot 10^{-12}:\\
\;\;\;\;\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 + \left(z \cdot y\right) \cdot \left(t \cdot -9\right)\right) + a \cdot \left(27 \cdot b\right)\\


\end{array}

Error?

Target

Original3.0
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 < 4.9999999999999997e-12

    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.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

      [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.8

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

      \[ \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 4.9999999999999997e-12 < 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. Simplified19.5

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

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

      associate-*l* [=>]19.4

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

      associate-*l* [=>]19.5

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

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

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

      [Start]19.5

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

      *-commutative [<=]19.5

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

      associate-*r* [=>]0.5

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

      associate-*l* [<=]0.4

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

      *-commutative [=>]0.4

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

      associate-*l* [=>]0.6

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

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

Alternatives

Alternative 1
Error29.9
Cost1376
\[\begin{array}{l} t_1 := y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -5.4 \cdot 10^{+82}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-138}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.32 \cdot 10^{-199}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.1 \cdot 10^{-280}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{-275}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-220}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-66}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 2
Error30.0
Cost1376
\[\begin{array}{l} t_1 := y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+83}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.7 \cdot 10^{-143}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-199}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{-279}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-274}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-220}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 10^{-99}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-66}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 3
Error30.1
Cost1376
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -1.08 \cdot 10^{+84}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{-140}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.75 \cdot 10^{-199}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq -8.2 \cdot 10^{-280}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-274}:\\ \;\;\;\;z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-223}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-101}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-67}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 4
Error30.1
Cost1376
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -5.1 \cdot 10^{+82}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-202}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{-278}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-274}:\\ \;\;\;\;z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-218}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 10^{-100}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-67}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 5
Error1.2
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 7.2 \cdot 10^{+61}:\\ \;\;\;\;x \cdot 2 + \left(27 \cdot \left(a \cdot b\right) + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot t\right) \cdot \left(z \cdot -9\right)\\ \end{array} \]
Alternative 6
Error0.5
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 1.25 \cdot 10^{+23}:\\ \;\;\;\;x \cdot 2 + \left(27 \cdot \left(a \cdot b\right) + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot y\right) \cdot \left(t \cdot -9\right)\right) + a \cdot \left(27 \cdot b\right)\\ \end{array} \]
Alternative 7
Error17.0
Cost1104
\[\begin{array}{l} t_1 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;z \leq -1.7 \cdot 10^{-16}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-66}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;z \leq 680000000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 8
Error14.1
Cost1101
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;a \leq -6.8 \cdot 10^{+227}:\\ \;\;\;\;t_1 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;a \leq -1.7 \cdot 10^{-7} \lor \neg \left(a \leq 1.05 \cdot 10^{-113}\right):\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 9
Error13.1
Cost1100
\[\begin{array}{l} t_1 := x \cdot 2 + \left(y \cdot t\right) \cdot \left(z \cdot -9\right)\\ \mathbf{if}\;z \leq -1.5 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-126}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-18}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error15.0
Cost969
\[\begin{array}{l} \mathbf{if}\;a \leq -4 \cdot 10^{-6} \lor \neg \left(a \leq 4.8 \cdot 10^{-83}\right):\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + \left(y \cdot t\right) \cdot \left(z \cdot -9\right)\\ \end{array} \]
Alternative 11
Error29.4
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{+82}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 2.25 \cdot 10^{-69}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 12
Error37.7
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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