Average Error: 3.0 → 1.2
Time: 16.8s
Precision: binary64
Cost: 13892
\[ \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 -3.2 \cdot 10^{-182}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), \left(a \cdot 27\right) \cdot b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t, -9 \cdot \left(y \cdot z\right), \mathsf{fma}\left(x, 2, 27 \cdot \left(a \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 (<= (* y 9.0) -3.2e-182)
   (fma x 2.0 (fma y (* t (* z -9.0)) (* (* a 27.0) b)))
   (fma t (* -9.0 (* y z)) (fma x 2.0 (* 27.0 (* a 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 ((y * 9.0) <= -3.2e-182) {
		tmp = fma(x, 2.0, fma(y, (t * (z * -9.0)), ((a * 27.0) * b)));
	} else {
		tmp = fma(t, (-9.0 * (y * z)), fma(x, 2.0, (27.0 * (a * 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 (Float64(y * 9.0) <= -3.2e-182)
		tmp = fma(x, 2.0, fma(y, Float64(t * Float64(z * -9.0)), Float64(Float64(a * 27.0) * b)));
	else
		tmp = fma(t, Float64(-9.0 * Float64(y * z)), fma(x, 2.0, Float64(27.0 * Float64(a * 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[N[(y * 9.0), $MachinePrecision], -3.2e-182], N[(x * 2.0 + N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(-9.0 * N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0 + N[(27.0 * N[(a * 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}\;y \cdot 9 \leq -3.2 \cdot 10^{-182}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), \left(a \cdot 27\right) \cdot b\right)\right)\\

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


\end{array}

Error

Target

Original3.0
Target3.4
Herbie1.2
\[\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) < -3.20000000000000002e-182

    1. Initial program 3.7

      \[\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), \left(a \cdot 27\right) \cdot b\right)\right)} \]
      Proof

      [Start]3.7

      \[ \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- [=>]3.7

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

      fma-neg [=>]3.7

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

      neg-sub0 [=>]3.7

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

      associate-+l- [<=]3.7

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

      neg-sub0 [<=]3.7

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

      *-commutative [=>]3.7

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

      distribute-lft-neg-in [=>]3.7

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

      associate-*l* [=>]3.6

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

      *-commutative [=>]3.6

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

      associate-*r* [=>]1.3

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

      *-commutative [=>]1.3

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

      fma-def [=>]1.3

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

      distribute-lft-neg-in [<=]1.3

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

      distribute-rgt-neg-in [=>]1.3

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

      *-commutative [=>]1.3

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

      distribute-rgt-neg-in [=>]1.3

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

      metadata-eval [=>]1.3

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

    if -3.20000000000000002e-182 < (*.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. Simplified0.8

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

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

      sub-neg [=>]0.9

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

      +-commutative [=>]0.9

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

      associate-+l+ [=>]0.9

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

      distribute-lft-neg-in [=>]0.9

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

      +-commutative [<=]0.9

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

      *-commutative [=>]0.9

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

      fma-def [=>]0.9

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

      *-commutative [=>]0.9

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

      associate-*l* [=>]0.9

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

      *-commutative [=>]0.9

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

      distribute-rgt-neg-in [=>]0.9

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

      metadata-eval [=>]0.9

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

      +-commutative [=>]0.9

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

      fma-def [=>]0.9

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

      *-commutative [=>]0.9

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

      associate-*l* [=>]0.8

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

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

Alternatives

Alternative 1
Error0.6
Cost7492
\[\begin{array}{l} \mathbf{if}\;z \leq 8 \cdot 10^{-189}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(-9 \cdot \left(t \cdot z\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b + \left(x \cdot 2 - t \cdot \left(y \cdot \left(9 \cdot z\right)\right)\right)\\ \end{array} \]
Alternative 2
Error10.7
Cost2257
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+71}:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;t_1 \leq -2 \cdot 10^{+32} \lor \neg \left(t_1 \leq -5 \cdot 10^{-79}\right) \land t_1 \leq 2 \cdot 10^{-9}:\\ \;\;\;\;x \cdot 2 + \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 3
Error10.6
Cost2257
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+71}:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;t_1 \leq -2 \cdot 10^{+32} \lor \neg \left(t_1 \leq -5 \cdot 10^{-79}\right) \land t_1 \leq 2 \cdot 10^{-9}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 4
Error1.6
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -5.5 \cdot 10^{+15}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b + \left(x \cdot 2 - t \cdot \left(9 \cdot \left(y \cdot z\right)\right)\right)\\ \end{array} \]
Alternative 5
Error0.7
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 7.5 \cdot 10^{-189}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b + \left(x \cdot 2 - t \cdot \left(9 \cdot \left(y \cdot z\right)\right)\right)\\ \end{array} \]
Alternative 6
Error0.7
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 5 \cdot 10^{-190}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b + \left(x \cdot 2 - t \cdot \left(y \cdot \left(9 \cdot z\right)\right)\right)\\ \end{array} \]
Alternative 7
Error28.5
Cost1112
\[\begin{array}{l} t_1 := -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -6.5 \cdot 10^{-38}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-277}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-307}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-205}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 9.6 \cdot 10^{-167}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{-9}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 8
Error28.5
Cost1112
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -6 \cdot 10^{-38}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-276}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-305}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.42 \cdot 10^{-166}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-13}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 9
Error18.9
Cost1105
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{if}\;x \leq -6.8 \cdot 10^{-277}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{-308}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-205} \lor \neg \left(x \leq 9.5 \cdot 10^{-167}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \end{array} \]
Alternative 10
Error18.9
Cost1104
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b + x \cdot 2\\ \mathbf{if}\;x \leq -7.4 \cdot 10^{-277}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-307}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-205}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.02 \cdot 10^{-166}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 11
Error28.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -7.6 \cdot 10^{-38}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-10}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 12
Error37.3
Cost192
\[x \cdot 2 \]

Error

Reproduce

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