?

Average Error: 2.9 → 0.5
Time: 13.8s
Precision: binary64
Cost: 13764

?

\[ \begin{array}{c}[y, z, t] = \mathsf{sort}([y, z, t])\\ \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} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;z \leq 2 \cdot 10^{-52}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), t_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + t_1\\ \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
 (let* ((t_1 (* b (* a 27.0))))
   (if (<= z 2e-52)
     (fma x 2.0 (fma y (* t (* z -9.0)) t_1))
     (+ (+ (* x 2.0) (* t (* z (* y -9.0)))) t_1))))
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 t_1 = b * (a * 27.0);
	double tmp;
	if (z <= 2e-52) {
		tmp = fma(x, 2.0, fma(y, (t * (z * -9.0)), t_1));
	} else {
		tmp = ((x * 2.0) + (t * (z * (y * -9.0)))) + t_1;
	}
	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)
	t_1 = Float64(b * Float64(a * 27.0))
	tmp = 0.0
	if (z <= 2e-52)
		tmp = fma(x, 2.0, fma(y, Float64(t * Float64(z * -9.0)), t_1));
	else
		tmp = Float64(Float64(Float64(x * 2.0) + Float64(t * Float64(z * Float64(y * -9.0)))) + t_1);
	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_] := Block[{t$95$1 = N[(b * N[(a * 27.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 2e-52], N[(x * 2.0 + N[(y * N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] + N[(t * N[(z * N[(y * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $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}
t_1 := b \cdot \left(a \cdot 27\right)\\
\mathbf{if}\;z \leq 2 \cdot 10^{-52}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), t_1\right)\right)\\

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


\end{array}

Error?

Target

Original2.9
Target3.3
Herbie0.5
\[\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 < 2e-52

    1. Initial program 3.4

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

      [Start]3.4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[ \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 2e-52 < 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 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 2 \cdot 10^{-52}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), b \cdot \left(a \cdot 27\right)\right)\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} \]

Alternatives

Alternative 1
Error0.6
Cost13764
\[\begin{array}{l} \mathbf{if}\;z \leq 2 \cdot 10^{-17}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]
Alternative 2
Error13.0
Cost1360
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := y \cdot \left(z \cdot t\right)\\ t_3 := t_1 + -9 \cdot t_2\\ \mathbf{if}\;x \leq -9.2 \cdot 10^{-17}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;x \leq 5.1 \cdot 10^{-61}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+28}:\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+58}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 - 9 \cdot t_2\\ \end{array} \]
Alternative 3
Error2.0
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 1.5 \cdot 10^{+123}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 4
Error0.6
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 9 \cdot 10^{-56}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\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 5
Error28.8
Cost1108
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{-17}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 1.14 \cdot 10^{-122}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{-57}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+27}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+62}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 6
Error28.8
Cost1108
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-17}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 2.45 \cdot 10^{-176}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-58}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{+25}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+61}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 7
Error28.8
Cost1108
\[\begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{-17}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{-176}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 7 \cdot 10^{-62}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+27}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{+61}:\\ \;\;\;\;\left(t \cdot -9\right) \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 8
Error14.8
Cost1100
\[\begin{array}{l} t_1 := x \cdot 2 - 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{if}\;z \leq -2.3 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-172}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{+122}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 9
Error14.8
Cost1100
\[\begin{array}{l} t_1 := x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{if}\;z \leq -2.45 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-172}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+123}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 10
Error28.4
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -9.8 \cdot 10^{-17}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 6.9 \cdot 10^{-123}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-57}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{+22}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 11
Error16.0
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1600:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{+60}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(z \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 12
Error28.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{-18}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+21}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 13
Error28.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -6.6 \cdot 10^{-18}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 400000000:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 14
Error37.3
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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