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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\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 (*.f64 (*.f64 y 9) z) < 2.0000000000000001e167

    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 2.0000000000000001e167 < (*.f64 (*.f64 y 9) z)

    1. Initial program 22.8

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

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

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

      +-commutative [=>]22.8

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

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

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

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

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

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

Alternatives

Alternative 1
Error0.6
Cost7748
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \leq 2 \cdot 10^{+167}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\ \end{array} \]
Alternative 2
Error33.7
Cost1636
\[\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 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;b \leq -8.2 \cdot 10^{-85}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 2 \cdot 10^{-68}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 1.85 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 4 \cdot 10^{+57}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{+70}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 2.6 \cdot 10^{+91}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 4.9 \cdot 10^{+126}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \leq 1.8 \cdot 10^{+145}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 6.5 \cdot 10^{+163}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error33.7
Cost1636
\[\begin{array}{l} t_1 := y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ t_3 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;b \leq -8.2 \cdot 10^{-85}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 2.8 \cdot 10^{-68}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 2.2 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 2.8 \cdot 10^{+56}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 3.6 \cdot 10^{+70}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 1.9 \cdot 10^{+91}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{+126}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \leq 7.8 \cdot 10^{+143}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 2.1 \cdot 10^{+164}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 4
Error33.7
Cost1636
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;b \leq -8.2 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 9.5 \cdot 10^{-69}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 3 \cdot 10^{-8}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{+59}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 1.42 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 3 \cdot 10^{+91}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 5.4 \cdot 10^{+126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 1.4 \cdot 10^{+145}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 9.2 \cdot 10^{+163}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error33.6
Cost1636
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;b \leq -8 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-66}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 1.7 \cdot 10^{-7}:\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(t \cdot -9\right)\\ \mathbf{elif}\;b \leq 1.3 \cdot 10^{+59}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 2 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 2.7 \cdot 10^{+91}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{+126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;b \leq 6 \cdot 10^{+144}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;b \leq 6.5 \cdot 10^{+163}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error10.7
Cost1480
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+35}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-6}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + t_1\\ \end{array} \]
Alternative 7
Error1.3
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{+75}:\\ \;\;\;\;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(y \cdot z\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 8
Error0.7
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+34}:\\ \;\;\;\;\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(9 \cdot \left(y \cdot z\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 9
Error16.2
Cost1105
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{+60}:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-79} \lor \neg \left(z \leq -2.4 \cdot 10^{-94}\right) \land z \leq 1.12 \cdot 10^{+29}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(t \cdot -9\right)\\ \end{array} \]
Alternative 10
Error16.1
Cost1105
\[\begin{array}{l} \mathbf{if}\;z \leq -7.5 \cdot 10^{+50}:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-79}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{elif}\;z \leq -2.4 \cdot 10^{-94} \lor \neg \left(z \leq 2.25 \cdot 10^{+30}\right):\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(t \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 11
Error27.9
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -16500 \lor \neg \left(x \leq 3.6 \cdot 10^{+48}\right):\\ \;\;\;\;x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 12
Error27.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -185000:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+48}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 13
Error37.8
Cost192
\[x \cdot 2 \]

Error

Reproduce

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