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

\mathbf{else}:\\
\;\;\;\;\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)\\


\end{array}

Error

Target

Original2.9
Target3.3
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) < -9.9999999999999996e216

    1. Initial program 13.0

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

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

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

      +-commutative [=>]13.0

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

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

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

      \[ \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 -9.9999999999999996e216 < (*.f64 y 9)

    1. Initial program 1.2

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[ \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 -1 \cdot 10^{+217}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]

Alternatives

Alternative 1
Error10.2
Cost1481
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-13} \lor \neg \left(t_1 \leq 5 \cdot 10^{+16}\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 2
Error1.2
Cost1348
\[\begin{array}{l} \mathbf{if}\;y \cdot 9 \leq -2 \cdot 10^{+201}:\\ \;\;\;\;\left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\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 3
Error1.6
Cost1220
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq 4.8 \cdot 10^{+84}:\\ \;\;\;\;\left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 + z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 4
Error28.9
Cost1112
\[\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)\\ \mathbf{if}\;x \leq -520000000000:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.46 \cdot 10^{-108}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -8 \cdot 10^{-162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-270}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 5
Error28.7
Cost1112
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -350000000000:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.82 \cdot 10^{-109}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-162}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-220}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-167}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 6
Error28.6
Cost1112
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -560000000000:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-109}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-162}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-220}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-168}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{+19}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 7
Error19.1
Cost1105
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{if}\;x \leq -1.82 \cdot 10^{-109}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-161}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-186} \lor \neg \left(x \leq 5.5 \cdot 10^{-168}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \end{array} \]
Alternative 8
Error19.2
Cost1104
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \mathbf{if}\;x \leq -1.82 \cdot 10^{-109}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-162}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-187}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-168}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 9
Error28.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -600000000000:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4.05 \cdot 10^{+14}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 10
Error37.4
Cost192
\[x \cdot 2 \]

Error

Reproduce

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