?

Average Error: 4.62% → 0.73%
Time: 19.5s
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 1.2 \cdot 10^{-58}:\\ \;\;\;\;\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 1.2e-58)
     (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 <= 1.2e-58) {
		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 <= 1.2e-58)
		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, 1.2e-58], 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 1.2 \cdot 10^{-58}:\\
\;\;\;\;\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

Original4.62%
Target5.37%
Herbie0.73%
\[\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 < 1.2e-58

    1. Initial program 5.44

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[ \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 1.2e-58 < z

    1. Initial program 0.51

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 1.2 \cdot 10^{-58}:\\ \;\;\;\;\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.72%
Cost7492
\[\begin{array}{l} \mathbf{if}\;z \leq 1.85 \cdot 10^{-45}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(-9 \cdot \left(z \cdot t\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} \]
Alternative 2
Error30.82%
Cost1369
\[\begin{array}{l} t_1 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;a \leq -8 \cdot 10^{-60}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.2 \cdot 10^{-66}:\\ \;\;\;\;\left(z \cdot -9\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;a \leq -1.3 \cdot 10^{-178}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.95 \cdot 10^{-249}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;a \leq 7.5 \cdot 10^{-276} \lor \neg \left(a \leq 1.7 \cdot 10^{-259}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 3
Error21.19%
Cost1352
\[\begin{array}{l} t_1 := y \cdot \left(z \cdot t\right)\\ \mathbf{if}\;x \cdot 2 \leq -8.9 \cdot 10^{-26}:\\ \;\;\;\;z \cdot \left(t \cdot \left(y \cdot -9\right)\right) + x \cdot 2\\ \mathbf{elif}\;x \cdot 2 \leq 5 \cdot 10^{-99}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + -9 \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 - 9 \cdot t_1\\ \end{array} \]
Alternative 4
Error2.83%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -1.56 \cdot 10^{-9}:\\ \;\;\;\;z \cdot \left(t \cdot \left(y \cdot -9\right)\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right) + \left(x \cdot 2 + 27 \cdot \left(a \cdot b\right)\right)\\ \end{array} \]
Alternative 5
Error1.44%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 1.35 \cdot 10^{+73}:\\ \;\;\;\;\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}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right) + \left(x \cdot 2 + 27 \cdot \left(a \cdot b\right)\right)\\ \end{array} \]
Alternative 6
Error0.82%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 1.6 \cdot 10^{-45}:\\ \;\;\;\;\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(z \cdot \left(y \cdot -9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 7
Error44%
Cost1108
\[\begin{array}{l} t_1 := -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;x \leq -4.45 \cdot 10^{-26}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.15 \cdot 10^{-193}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-232}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-95}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-29}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 8
Error44.09%
Cost1108
\[\begin{array}{l} t_1 := y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{if}\;x \leq -4.45 \cdot 10^{-26}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{-192}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq -2.45 \cdot 10^{-232}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.6 \cdot 10^{-97}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-28}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 9
Error44.14%
Cost1108
\[\begin{array}{l} \mathbf{if}\;x \leq -4.45 \cdot 10^{-26}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-189}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-232}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{-99}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-28}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 10
Error44.09%
Cost1108
\[\begin{array}{l} \mathbf{if}\;x \leq -4.45 \cdot 10^{-26}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{-196}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq -2.35 \cdot 10^{-232}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-98}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-28}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 11
Error19.37%
Cost969
\[\begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{-23} \lor \neg \left(z \leq 3 \cdot 10^{-24}\right):\\ \;\;\;\;z \cdot \left(t \cdot \left(y \cdot -9\right)\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 12
Error24.94%
Cost969
\[\begin{array}{l} \mathbf{if}\;a \leq -1.1 \cdot 10^{+19} \lor \neg \left(a \leq 6 \cdot 10^{-257}\right):\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 - 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 13
Error44.02%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.45 \cdot 10^{-26}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-96}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 14
Error44.07%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.45 \cdot 10^{-26}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-96}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 15
Error58.47%
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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