?

Average Error: 4.87% → 1.07%
Time: 14.7s
Precision: binary64
Cost: 7748

?

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

\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

Original4.87%
Target5.51%
Herbie1.07%
\[\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) < 4.9999999999999997e165

    1. Initial program 1.1

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

    if 4.9999999999999997e165 < (*.f64 (*.f64 y 9) z)

    1. Initial program 36.39

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

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

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

      +-commutative [=>]36.39

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \leq 5 \cdot 10^{+165}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\ \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
Error1.16%
Cost1476
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \leq 5 \cdot 10^{+146}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 2
Error45.42%
Cost1376
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ t_2 := y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ t_3 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -2.05 \cdot 10^{+37}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.55 \cdot 10^{-21}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-199}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-267}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.1 \cdot 10^{-286}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-210}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 3
Error45.35%
Cost1376
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ t_2 := y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ t_3 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -3.4 \cdot 10^{+37}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -4.1 \cdot 10^{-19}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-197}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{-264}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{-286}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.12 \cdot 10^{-209}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-125}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 4
Error45.36%
Cost1376
\[\begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ t_2 := -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ t_3 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -1.7 \cdot 10^{+37}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.85 \cdot 10^{-21}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-195}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-265}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-285}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-210}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 5
Error31.25%
Cost1370
\[\begin{array}{l} t_1 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -1.15 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.8 \cdot 10^{-216}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq -6.6 \cdot 10^{-255} \lor \neg \left(x \leq -2.1 \cdot 10^{-285}\right) \land \left(x \leq 1.35 \cdot 10^{-209} \lor \neg \left(x \leq 5.1 \cdot 10^{-126}\right)\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 6
Error23.44%
Cost1365
\[\begin{array}{l} t_1 := x \cdot 2 + t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\\ \mathbf{if}\;z \leq -3.3 \cdot 10^{+125}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-160}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.7 \cdot 10^{-181}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-219} \lor \neg \left(z \leq 10^{-97}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 7
Error23.34%
Cost1365
\[\begin{array}{l} \mathbf{if}\;z \leq -3.1 \cdot 10^{+124}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-154}:\\ \;\;\;\;x \cdot 2 + t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\\ \mathbf{elif}\;z \leq -4.7 \cdot 10^{-181}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-219} \lor \neg \left(z \leq 1.7 \cdot 10^{-93}\right):\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 8
Error20.89%
Cost1233
\[\begin{array}{l} \mathbf{if}\;z \leq -4.1 \cdot 10^{-49}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;z \leq -4.7 \cdot 10^{-181}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-220} \lor \neg \left(z \leq 5 \cdot 10^{-93}\right):\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 9
Error19.32%
Cost1232
\[\begin{array}{l} t_1 := x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -2.3 \cdot 10^{-47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-26}:\\ \;\;\;\;\left(t \cdot -9\right) \cdot \left(y \cdot z\right) + \left(a \cdot 27\right) \cdot b\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{+180}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right) + x \cdot 2\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{+232}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 10
Error2.79%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -2.7 \cdot 10^{+133}:\\ \;\;\;\;x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\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 11
Error0.94%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{-8}:\\ \;\;\;\;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}:\\ \;\;\;\;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 12
Error26.76%
Cost972
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{+26}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{+14}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-12}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 13
Error43.83%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{+37}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-26}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 14
Error43.85%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{+37}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 1.02 \cdot 10^{-25}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 15
Error43.9%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+37}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-26}:\\ \;\;\;\;\left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 16
Error58.48%
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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