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

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


\end{array}

Error

Target

Original2.9
Target3.2
Herbie1.0
\[\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 y 9) < -2.0000000000000001e-133

    1. Initial program 3.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. Simplified1.0

      \[\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)))): 13 points increase in error, 11 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)))): 1 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))): 18 points increase in error, 30 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))): 16 points increase in error, 10 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 1.0

      \[\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) \]
    4. Simplified1.1

      \[\leadsto \mathsf{fma}\left(x, 2, \mathsf{fma}\left(y, \color{blue}{\left(-9 \cdot t\right) \cdot z}, a \cdot \left(27 \cdot b\right)\right)\right) \]
      Proof
      (*.f64 (*.f64 -9 t) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 -9 (*.f64 t z))): 36 points increase in error, 36 points decrease in error

    if -2.0000000000000001e-133 < (*.f64 y 9)

    1. Initial program 0.9

      \[\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 7.3

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

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(9 \cdot y\right) \cdot \left(t \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      Proof
      (*.f64 (*.f64 9 y) (*.f64 t z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 9 (*.f64 y (*.f64 t z)))): 44 points increase in error, 40 points decrease in error
    4. Applied egg-rr0.9

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

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

Alternatives

Alternative 1
Error0.8
Cost13764
\[\begin{array}{l} \mathbf{if}\;z \leq 4.962361526206968 \cdot 10^{-164}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, \mathsf{fma}\left(x, 2, \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(27 \cdot \left(a \cdot b\right) + x \cdot 2\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 2
Error10.3
Cost1480
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-111}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + x \cdot 2\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{-15}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \end{array} \]
Alternative 3
Error28.8
Cost1376
\[\begin{array}{l} t_1 := \left(-9 \cdot z\right) \cdot \left(y \cdot t\right)\\ t_2 := 27 \cdot \left(a \cdot b\right)\\ \mathbf{if}\;x \leq -7.505582448073294 \cdot 10^{+53}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -4.199887451673762 \cdot 10^{-259}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 5.405503710775662 \cdot 10^{-253}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.064275521164422 \cdot 10^{-209}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 1.989772626158376 \cdot 10^{-167}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.1329766710299995 \cdot 10^{-28}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 9.972346393826359 \cdot 10^{+95}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 1.21294081123649 \cdot 10^{+116}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 4
Error29.5
Cost1240
\[\begin{array}{l} t_1 := -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{if}\;x \leq -5.506637226516612 \cdot 10^{-17}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.1976048137871202 \cdot 10^{-98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.199887451673762 \cdot 10^{-259}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 6.083659616518642 \cdot 10^{-261}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.064275521164422 \cdot 10^{-209}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 8.804031296365783 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 5
Error29.5
Cost1240
\[\begin{array}{l} t_1 := -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{if}\;x \leq -0.010647618339048634:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.1976048137871202 \cdot 10^{-98}:\\ \;\;\;\;t \cdot \left(y \cdot \left(-9 \cdot z\right)\right)\\ \mathbf{elif}\;x \leq -4.199887451673762 \cdot 10^{-259}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 6.083659616518642 \cdot 10^{-261}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.064275521164422 \cdot 10^{-209}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 8.804031296365783 \cdot 10^{-48}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 6
Error29.5
Cost1240
\[\begin{array}{l} \mathbf{if}\;x \leq -0.010647618339048634:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.1976048137871202 \cdot 10^{-98}:\\ \;\;\;\;t \cdot \left(y \cdot \left(-9 \cdot z\right)\right)\\ \mathbf{elif}\;x \leq -4.199887451673762 \cdot 10^{-259}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{elif}\;x \leq 6.083659616518642 \cdot 10^{-261}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{elif}\;x \leq 1.064275521164422 \cdot 10^{-209}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{elif}\;x \leq 8.804031296365783 \cdot 10^{-48}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 7
Error1.3
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+85}:\\ \;\;\;\;x \cdot 2 + y \cdot \left(-9 \cdot \left(t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(27 \cdot \left(a \cdot b\right) + x \cdot 2\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 8
Error0.8
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 9.409972789677326 \cdot 10^{-171}:\\ \;\;\;\;\left(x \cdot 2 + \left(t \cdot z\right) \cdot \left(y \cdot -9\right)\right) + b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;\left(27 \cdot \left(a \cdot b\right) + x \cdot 2\right) + -9 \cdot \left(t \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 9
Error12.0
Cost1096
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -2.8865027062402304:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;x \leq 1.1754918429092955 \cdot 10^{+51}:\\ \;\;\;\;t_1 + t \cdot \left(-9 \cdot \left(y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \end{array} \]
Alternative 10
Error12.1
Cost1096
\[\begin{array}{l} t_1 := -9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{if}\;x \leq -5.506637226516612 \cdot 10^{-17}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \mathbf{elif}\;x \leq 1.1754918429092955 \cdot 10^{+51}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + t_1\\ \end{array} \]
Alternative 11
Error16.3
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -9.2 \cdot 10^{+24}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\\ \mathbf{elif}\;z \leq 2.55 \cdot 10^{+14}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(-9 \cdot z\right)\right)\\ \end{array} \]
Alternative 12
Error27.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -7.505582448073294 \cdot 10^{+53}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 1.1329766710299995 \cdot 10^{-28}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 13
Error27.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -7.505582448073294 \cdot 10^{+53}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq 1.1329766710299995 \cdot 10^{-28}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 14
Error36.9
Cost192
\[x \cdot 2 \]

Error

Reproduce

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