Average Error: 3.0 → 0.7
Time: 24.9s
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 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq -1.9393210643229773 \cdot 10^{-89}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, -9 \cdot \left(z \cdot t\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 (* a (* 27.0 b))))
   (if (<= z -1.9393210643229773e-89)
     (fma x 2.0 (fma y (* -9.0 (* z t)) 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 = a * (27.0 * b);
	double tmp;
	if (z <= -1.9393210643229773e-89) {
		tmp = fma(x, 2.0, fma(y, (-9.0 * (z * t)), 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(a * Float64(27.0 * b))
	tmp = 0.0
	if (z <= -1.9393210643229773e-89)
		tmp = fma(x, 2.0, fma(y, Float64(-9.0 * Float64(z * t)), 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[(a * N[(27.0 * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.9393210643229773e-89], N[(x * 2.0 + N[(y * N[(-9.0 * N[(z * t), $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 := a \cdot \left(27 \cdot b\right)\\
\mathbf{if}\;z \leq -1.9393210643229773 \cdot 10^{-89}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, -9 \cdot \left(z \cdot t\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

Original3.0
Target3.4
Herbie0.7
\[\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.9393210643229773e-89

    1. Initial program 12.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. Simplified0.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, t \cdot \left(z \cdot -9\right), a \cdot \left(27 \cdot b\right)\right)\right)} \]
      Proof
      (fma.f64 x 2 (fma.f64 y (*.f64 t (*.f64 z -9)) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (*.f64 t (*.f64 z (Rewrite<= metadata-eval (neg.f64 9)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (*.f64 t (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 z 9)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (*.f64 t (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 9 z)))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 (*.f64 9 z)) t)) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (Rewrite=> distribute-lft-neg-out_binary64 (neg.f64 (*.f64 (*.f64 9 z) t))) (*.f64 a (*.f64 27 b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (fma.f64 y (neg.f64 (*.f64 (*.f64 9 z) t)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b)))): 12 points increase in error, 14 points decrease in error
      (fma.f64 x 2 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (neg.f64 (*.f64 (*.f64 9 z) t))) (*.f64 (*.f64 a 27) b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y (*.f64 (*.f64 9 z) t)))) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y (*.f64 9 z)) t))) (*.f64 (*.f64 a 27) b))): 28 points increase in error, 20 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (*.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y 9) z)) t)) (*.f64 (*.f64 a 27) b))): 10 points increase in error, 13 points decrease in error
      (fma.f64 x 2 (+.f64 (neg.f64 (*.f64 (*.f64 (*.f64 y 9) z) t)) (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (*.f64 (*.f64 a 27) b)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (neg.f64 (*.f64 (*.f64 a 27) b)))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x 2 (neg.f64 (Rewrite<= sub-neg_binary64 (-.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (*.f64 (*.f64 a 27) b))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x 2) (-.f64 (*.f64 (*.f64 (*.f64 y 9) z) t) (*.f64 (*.f64 a 27) b)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in t around 0 0.4

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

    if -1.9393210643229773e-89 < z

    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. Applied egg-rr0.7

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

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

Alternatives

Alternative 1
Error10.2
Cost2256
\[\begin{array}{l} t_1 := x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ t_2 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+65}:\\ \;\;\;\;t_2 + x \cdot 2\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{-45}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+35}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 2
Error10.1
Cost2256
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+62}:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{+37}:\\ \;\;\;\;t_1 + y \cdot \left(z \cdot \left(-9 \cdot t\right)\right)\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-45}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+35}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 3
Error10.1
Cost2256
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+62}:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{+37}:\\ \;\;\;\;t_1 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-45}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+35}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 4
Error10.1
Cost2256
\[\begin{array}{l} t_1 := -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ t_2 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+62}:\\ \;\;\;\;t_2 + x \cdot 2\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{+37}:\\ \;\;\;\;t_2 + t_1\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{-45}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+35}:\\ \;\;\;\;x \cdot 2 + t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 5
Error1.6
Cost1476
\[\begin{array}{l} \mathbf{if}\;z \cdot \left(y \cdot 9\right) \leq 2 \cdot 10^{+210}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + \left(x \cdot 2 + t \cdot \left(-9 \cdot \left(z \cdot y\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 6
Error20.0
Cost1236
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right) + x \cdot 2\\ t_2 := -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{if}\;y \leq -5 \cdot 10^{+255}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.7 \cdot 10^{+244}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{+201}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;y \leq -5.4 \cdot 10^{+184}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{+164}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error20.0
Cost1236
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right) + x \cdot 2\\ t_2 := -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{if}\;y \leq -5 \cdot 10^{+255}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.7 \cdot 10^{+244}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{+201}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;y \leq -5.4 \cdot 10^{+184}:\\ \;\;\;\;x \cdot 2 + 27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{+164}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error0.6
Cost1220
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;z \leq -1.1211504406557512 \cdot 10^{-76}:\\ \;\;\;\;\left(x \cdot 2 - y \cdot \left(t \cdot \left(z \cdot 9\right)\right)\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + t_1\\ \end{array} \]
Alternative 9
Error0.7
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1211504406557512 \cdot 10^{-76}:\\ \;\;\;\;\left(x \cdot 2 - y \cdot \left(t \cdot \left(z \cdot 9\right)\right)\right) + b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 + t \cdot \left(z \cdot \left(y \cdot -9\right)\right)\right) + a \cdot \left(27 \cdot b\right)\\ \end{array} \]
Alternative 10
Error30.1
Cost980
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ t_2 := t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \mathbf{if}\;x \leq -1.1264537695477771 \cdot 10^{+106}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.1230900437403062 \cdot 10^{-111}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.9084054062554244 \cdot 10^{-183}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.927192572884876 \cdot 10^{-51}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.251185876748583 \cdot 10^{+35}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 11
Error30.4
Cost980
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ t_2 := \left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{if}\;x \leq -4.001495490213498 \cdot 10^{+127}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.1230900437403062 \cdot 10^{-111}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.9084054062554244 \cdot 10^{-183}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.4577005818140006 \cdot 10^{-45}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.251185876748583 \cdot 10^{+35}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 12
Error30.4
Cost980
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ t_2 := y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{if}\;x \leq -4.001495490213498 \cdot 10^{+127}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.1230900437403062 \cdot 10^{-111}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.9084054062554244 \cdot 10^{-183}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.4577005818140006 \cdot 10^{-45}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.251185876748583 \cdot 10^{+35}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 13
Error30.4
Cost980
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -4.001495490213498 \cdot 10^{+127}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -3.1230900437403062 \cdot 10^{-111}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 6.9084054062554244 \cdot 10^{-183}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.4577005818140006 \cdot 10^{-45}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 2.251185876748583 \cdot 10^{+35}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 14
Error28.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.040289158578555 \cdot 10^{+87}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 2.251185876748583 \cdot 10^{+35}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 15
Error28.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.040289158578555 \cdot 10^{+87}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 2.251185876748583 \cdot 10^{+35}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 16
Error38.3
Cost192
\[x \cdot 2 \]

Error

Reproduce

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