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

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


\end{array}

Error

Target

Original3.1
Target3.4
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 t < 4.99999999999999954e-22

    1. Initial program 6.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. Applied egg-rr0.3

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

    if 4.99999999999999954e-22 < t

    1. Initial program 0.7

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Taylor expanded in y around 0 0.7

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

Alternatives

Alternative 1
Error0.7
Cost9672
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ t_2 := t_1 + \left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right)\\ t_3 := \mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(t \cdot z\right)\right)\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 10^{+272}:\\ \;\;\;\;\left(x \cdot 2 - t \cdot \left(9 \cdot \left(z \cdot y\right)\right)\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Error1.1
Cost2120
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right) + \left(y \cdot \left(t \cdot z\right)\right) \cdot -9\\ t_2 := t \cdot \left(z \cdot \left(y \cdot 9\right)\right)\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+272}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+291}:\\ \;\;\;\;\left(x \cdot 2 - t \cdot \left(9 \cdot \left(z \cdot y\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error36.3
Cost1636
\[\begin{array}{l} t_1 := -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;z \leq -3 \cdot 10^{-41}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;z \leq -4.7 \cdot 10^{-135}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-172}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-180}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;z \leq -7.4 \cdot 10^{-209}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-243}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;z \leq -6 \cdot 10^{-295}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-182}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-35}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error36.3
Cost1636
\[\begin{array}{l} t_1 := -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;z \leq -2.2 \cdot 10^{-41}:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(t \cdot y\right)\right)\\ \mathbf{elif}\;z \leq -4.7 \cdot 10^{-135}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-172}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{-180}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;z \leq -3.3 \cdot 10^{-208}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq -6.1 \cdot 10^{-242}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;z \leq -1.76 \cdot 10^{-295}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-182}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-35}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error16.1
Cost1624
\[\begin{array}{l} t_1 := 27 \cdot \left(a \cdot b\right)\\ t_2 := t_1 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\\ t_3 := t_1 + \left(y \cdot \left(t \cdot z\right)\right) \cdot -9\\ t_4 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{-41}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-134}:\\ \;\;\;\;x + \left(x + t_4\right)\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{-191}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-153}:\\ \;\;\;\;x \cdot 2 + t_4\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-142}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-68}:\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error15.7
Cost1492
\[\begin{array}{l} t_1 := \left(y \cdot \left(t \cdot z\right)\right) \cdot -9\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ t_3 := t_2 + t_1\\ t_4 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq -1.2 \cdot 10^{-41}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-129}:\\ \;\;\;\;x + \left(x + t_4\right)\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-172}:\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-153}:\\ \;\;\;\;x \cdot 2 + t_4\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-142}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{+22}:\\ \;\;\;\;x \cdot 2 + t_2\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 7
Error36.2
Cost1376
\[\begin{array}{l} t_1 := -9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;b \leq -2.6 \cdot 10^{-45}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;b \leq -3.9 \cdot 10^{-215}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;b \leq -2.8 \cdot 10^{-302}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 3.4 \cdot 10^{-239}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;b \leq 5 \cdot 10^{-168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 1.3 \cdot 10^{-57}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;b \leq 1.5 \cdot 10^{+179}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;b \leq 1.35 \cdot 10^{+215}:\\ \;\;\;\;x + x\\ \mathbf{else}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 8
Error36.0
Cost1376
\[\begin{array}{l} t_1 := t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{if}\;b \leq -2.6 \cdot 10^{-45}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;b \leq -3.7 \cdot 10^{-215}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;b \leq -1.2 \cdot 10^{-286}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 3.8 \cdot 10^{-239}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;b \leq 5.8 \cdot 10^{-167}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b \leq 2.8 \cdot 10^{-57}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;b \leq 4.2 \cdot 10^{+178}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;b \leq 5.2 \cdot 10^{+214}:\\ \;\;\;\;x + x\\ \mathbf{else}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 9
Error0.5
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{-104}:\\ \;\;\;\;x \cdot 2 + \left(a \cdot \left(27 \cdot b\right) + \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - t \cdot \left(9 \cdot \left(z \cdot y\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \end{array} \]
Alternative 10
Error17.4
Cost1104
\[\begin{array}{l} t_1 := x + \left(x + a \cdot \left(27 \cdot b\right)\right)\\ \mathbf{if}\;z \leq -7400000000000:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(t \cdot y\right)\right)\\ \mathbf{elif}\;z \leq -4.7 \cdot 10^{-135}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6.4 \cdot 10^{-155}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{+22}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 11
Error17.3
Cost1104
\[\begin{array}{l} \mathbf{if}\;z \leq -12500000000000:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(t \cdot y\right)\right)\\ \mathbf{elif}\;z \leq -4.7 \cdot 10^{-135}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq -6.4 \cdot 10^{-155}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+22}:\\ \;\;\;\;x + \left(x + a \cdot \left(27 \cdot b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 12
Error17.4
Cost1104
\[\begin{array}{l} \mathbf{if}\;z \leq -20000000000000:\\ \;\;\;\;z \cdot \left(-9 \cdot \left(t \cdot y\right)\right)\\ \mathbf{elif}\;z \leq -4.7 \cdot 10^{-135}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq -6.4 \cdot 10^{-155}:\\ \;\;\;\;t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+22}:\\ \;\;\;\;x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 13
Error15.4
Cost1104
\[\begin{array}{l} t_1 := x \cdot 2 + \left(y \cdot \left(t \cdot z\right)\right) \cdot -9\\ \mathbf{if}\;z \leq -28000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-129}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{-173}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+22}:\\ \;\;\;\;x \cdot 2 + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;-9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 14
Error28.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+38}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 9 \cdot 10^{+83}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 15
Error29.0
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+38}:\\ \;\;\;\;x + x\\ \mathbf{elif}\;x \leq 2.45 \cdot 10^{+98}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x + x\\ \end{array} \]
Alternative 16
Error37.0
Cost192
\[x + x \]

Error

Reproduce

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