?

Average Accuracy: 95.6% → 99.2%
Time: 20.2s
Precision: binary64
Cost: 7492

?

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

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


\end{array}

Error?

Target

Original95.6%
Target95.2%
Herbie99.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 z < 4.9999999999999996e-41

    1. Initial program 95.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. Simplified99.1%

      \[\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]95.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 [=>]95.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* [=>]95.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 [=>]95.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* [=>]98.9

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

      \[ \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. Taylor expanded in z around 0 99.1%

      \[\leadsto \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \color{blue}{\left(9 \cdot \left(t \cdot z\right)\right)}\right) \]
    4. Simplified99.1%

      \[\leadsto \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \color{blue}{\left(t \cdot \left(9 \cdot z\right)\right)}\right) \]
      Proof

      [Start]99.1

      \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(t \cdot z\right)\right)\right) \]

      *-commutative [<=]99.1

      \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \color{blue}{\left(z \cdot t\right)}\right)\right) \]

      associate-*r* [=>]99.1

      \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \color{blue}{\left(\left(9 \cdot z\right) \cdot t\right)}\right) \]

      *-commutative [=>]99.1

      \[ \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \color{blue}{\left(t \cdot \left(9 \cdot z\right)\right)}\right) \]

    if 4.9999999999999996e-41 < z

    1. Initial program 99.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. Applied egg-rr99.4%

      \[\leadsto \left(x \cdot 2 - \color{blue}{{\left(y \cdot \left(9 \cdot z\right)\right)}^{1}} \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
      Proof

      [Start]99.4

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

      pow1 [=>]99.4

      \[ \left(x \cdot 2 - \color{blue}{{\left(\left(y \cdot 9\right) \cdot z\right)}^{1}} \cdot t\right) + \left(a \cdot 27\right) \cdot b \]

      associate-*l* [=>]99.4

      \[ \left(x \cdot 2 - {\color{blue}{\left(y \cdot \left(9 \cdot z\right)\right)}}^{1} \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.2%

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

Alternatives

Alternative 1
Accuracy99.2%
Cost7492
\[\begin{array}{l} \mathbf{if}\;z \leq 1.5 \cdot 10^{-40}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(t \cdot \left(z \cdot 9\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
Accuracy77.7%
Cost1492
\[\begin{array}{l} t_1 := x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ t_3 := t_2 + x \cdot 2\\ \mathbf{if}\;b \leq -1.6 \cdot 10^{-176}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \leq 1.5 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 7 \cdot 10^{+17}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \leq 3 \cdot 10^{+87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 5.5 \cdot 10^{+115}:\\ \;\;\;\;t_2 - 9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Accuracy77.5%
Cost1492
\[\begin{array}{l} t_1 := x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ t_3 := t_2 + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ t_4 := t_2 + x \cdot 2\\ \mathbf{if}\;b \leq -5.2 \cdot 10^{-177}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-8}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 400:\\ \;\;\;\;t_3\\ \mathbf{elif}\;b \leq 1.02 \cdot 10^{+86}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 3.8 \cdot 10^{+115}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_4\\ \end{array} \]
Alternative 4
Accuracy97.6%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 2.1 \cdot 10^{+57}:\\ \;\;\;\;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}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \end{array} \]
Alternative 5
Accuracy98.9%
Cost1220
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq 2 \cdot 10^{-57}:\\ \;\;\;\;t_1 + \left(x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(x \cdot 2 + \left(z \cdot y\right) \cdot \left(t \cdot -9\right)\right)\\ \end{array} \]
Alternative 6
Accuracy99.0%
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 2.8 \cdot 10^{-58}:\\ \;\;\;\;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 7
Accuracy55.1%
Cost1112
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{if}\;x \leq -7000000:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-270}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-297}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-173}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-79}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 8
Accuracy54.4%
Cost1112
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -4800000:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{-270}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-298}:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(y \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-254}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.4 \cdot 10^{-83}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 9
Accuracy53.6%
Cost1108
\[\begin{array}{l} \mathbf{if}\;x \leq -3800000:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.7 \cdot 10^{-270}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-298}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 1.42 \cdot 10^{-260}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-69}:\\ \;\;\;\;y \cdot \left(\left(z \cdot t\right) \cdot -9\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 10
Accuracy53.6%
Cost1108
\[\begin{array}{l} \mathbf{if}\;x \leq -4200000:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-270}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-299}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-254}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-69}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 11
Accuracy74.1%
Cost1104
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right) + x \cdot 2\\ t_2 := x \cdot 2 + \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{if}\;z \leq -2.1 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-211}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{-44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 12
Accuracy55.4%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -5800000 \lor \neg \left(x \leq 3.3 \cdot 10^{-150}\right) \land \left(x \leq 2.3 \cdot 10^{-83} \lor \neg \left(x \leq 2 \cdot 10^{+16}\right)\right):\\ \;\;\;\;x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 13
Accuracy73.0%
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -2.9 \cdot 10^{-33}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+16}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
Alternative 14
Accuracy41.3%
Cost192
\[x \cdot 2 \]

Error

Reproduce?

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