?

Average Error: 2.8 → 1.3
Time: 11.9s
Precision: binary64
Cost: 14020

?

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

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


\end{array}

Error?

Target

Original2.8
Target3.1
Herbie1.3
\[\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 (*.f64 y 9) z) < 5e-83

    1. Initial program 0.6

      \[\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(x, 2, \mathsf{fma}\left(t, y \cdot \left(z \cdot -9\right), \left(a \cdot 27\right) \cdot b\right)\right)} \]
      Proof

      [Start]0.6

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

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

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

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

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

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

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

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

      *-commutative [=>]0.6

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

      fma-def [=>]0.6

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

      associate-*l* [=>]0.6

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

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

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

      *-commutative [=>]0.6

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

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

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

      metadata-eval [=>]0.6

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

    if 5e-83 < (*.f64 (*.f64 y 9) z)

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

      \[\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]7.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* [=>]2.7

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

      \[ \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. Recombined 2 regimes into one program.
  4. Final simplification1.3

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

Alternatives

Alternative 1
Error13.3
Cost1496
\[\begin{array}{l} t_1 := -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ t_3 := t_2 + t_1\\ t_4 := x \cdot 2 + t_2\\ \mathbf{if}\;x \leq -1.3 \cdot 10^{+110}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-22}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \mathbf{elif}\;x \leq 7.6 \cdot 10^{-81}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 7.6 \cdot 10^{+19}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq 7.6 \cdot 10^{+111}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+190}:\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array} \]
Alternative 2
Error1.3
Cost1476
\[\begin{array}{l} t_1 := \left(y \cdot 9\right) \cdot z\\ \mathbf{if}\;t_1 \leq 5 \cdot 10^{-83}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b + \left(x \cdot 2 - t_1 \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right) + a \cdot \left(27 \cdot b\right)\\ \end{array} \]
Alternative 3
Error0.6
Cost1348
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;y \cdot 9 \leq -5 \cdot 10^{-26}:\\ \;\;\;\;\left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(x \cdot 2 + -9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\right)\\ \end{array} \]
Alternative 4
Error5.3
Cost1220
\[\begin{array}{l} \mathbf{if}\;t \leq 3.9 \cdot 10^{+207}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + -9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 5
Error13.2
Cost1101
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{+85}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-75} \lor \neg \left(z \leq 2.1 \cdot 10^{-90}\right):\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 6
Error12.3
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{-73}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-88}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 7
Error12.4
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -4.4 \cdot 10^{-75}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-88}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 8
Error16.6
Cost708
\[\begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{+47}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 9
Error28.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{-22}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{+115}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 10
Error37.2
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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