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

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


\end{array}

Error

Target

Original2.8
Target3.2
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 z < 2.69999999999999981e-155

    1. Initial program 3.8

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

      \[\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
      (fma.f64 a (*.f64 27 b) (-.f64 (*.f64 x 2) (*.f64 y (*.f64 9 (*.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 a (*.f64 27 b) (-.f64 (*.f64 x 2) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y 9) (*.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 a (*.f64 27 b) (-.f64 (*.f64 x 2) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (*.f64 y 9) z) t)))): 2 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (*.f64 27 b)) (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)))): 2 points increase in error, 2 points decrease in error
      (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b)) (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t))): 0 points increase in error, 3 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b))): 5 points increase in error, 1 points decrease in error
    3. Taylor expanded in a around 0 0.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, z \cdot \left(t \cdot -9\right), \mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right)\right)\right)} \]
      Proof
      (fma.f64 y (*.f64 z (*.f64 t -9)) (fma.f64 2 x (*.f64 27 (*.f64 a b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z t) -9)) (fma.f64 2 x (*.f64 27 (*.f64 a b)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (*.f64 (*.f64 z t) -9) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 2 x) (*.f64 27 (*.f64 a b))))): 20 points increase in error, 0 points decrease in error
      (fma.f64 y (*.f64 (*.f64 z t) -9) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 x 2)) (*.f64 27 (*.f64 a b)))): 0 points increase in error, 20 points decrease in error
      (fma.f64 y (*.f64 (*.f64 z t) -9) (+.f64 (*.f64 x 2) (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 a b) 27)))): 0 points increase in error, 5 points decrease in error
      (fma.f64 y (*.f64 (*.f64 z t) -9) (+.f64 (*.f64 x 2) (Rewrite<= associate-*r*_binary64 (*.f64 a (*.f64 b 27))))): 19 points increase in error, 0 points decrease in error
      (fma.f64 y (*.f64 (*.f64 z t) -9) (+.f64 (*.f64 x 2) (*.f64 a (Rewrite<= *-commutative_binary64 (*.f64 27 b))))): 0 points increase in error, 14 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (*.f64 (*.f64 z t) -9)) (+.f64 (*.f64 x 2) (*.f64 a (*.f64 27 b))))): 5 points increase in error, 5 points decrease in error
      (Rewrite=> associate-+r+_binary64 (+.f64 (+.f64 (*.f64 y (*.f64 (*.f64 z t) -9)) (*.f64 x 2)) (*.f64 a (*.f64 27 b)))): 10 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (*.f64 y (*.f64 (*.f64 z t) -9)) (*.f64 x 2)) (*.f64 a (Rewrite=> *-commutative_binary64 (*.f64 b 27)))): 0 points increase in error, 15 points decrease in error
      (+.f64 (+.f64 (*.f64 y (*.f64 (*.f64 z t) -9)) (*.f64 x 2)) (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 a b) 27))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (*.f64 y (*.f64 (*.f64 z t) -9)) (*.f64 x 2)) (Rewrite<= *-commutative_binary64 (*.f64 27 (*.f64 a b)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-+l+_binary64 (+.f64 (*.f64 y (*.f64 (*.f64 z t) -9)) (+.f64 (*.f64 x 2) (*.f64 27 (*.f64 a b))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 y (*.f64 (*.f64 z t) -9)) (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 2 x)) (*.f64 27 (*.f64 a b)))): 15 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 (*.f64 2 x) (*.f64 27 (*.f64 a b))) (*.f64 y (*.f64 (*.f64 z t) -9)))): 0 points increase in error, 15 points decrease in error
      (+.f64 (+.f64 (*.f64 2 x) (*.f64 27 (*.f64 a b))) (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 y (*.f64 z t)) -9))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (*.f64 2 x) (*.f64 27 (*.f64 a b))) (*.f64 (*.f64 y (Rewrite=> *-commutative_binary64 (*.f64 t z))) -9)): 5 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (*.f64 2 x) (*.f64 27 (*.f64 a b))) (Rewrite<= *-commutative_binary64 (*.f64 -9 (*.f64 y (*.f64 t z))))): 0 points increase in error, 5 points decrease in error
      (+.f64 (+.f64 (*.f64 2 x) (*.f64 27 (*.f64 a b))) (*.f64 (Rewrite<= metadata-eval (neg.f64 9)) (*.f64 y (*.f64 t z)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (+.f64 (*.f64 2 x) (*.f64 27 (*.f64 a b))) (*.f64 9 (*.f64 y (*.f64 t z))))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr0.5

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

    if 2.69999999999999981e-155 < z

    1. Initial program 0.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 2, \mathsf{fma}\left(t, y \cdot \left(z \cdot -9\right), \left(a \cdot 27\right) \cdot b\right)\right)} \]
      Proof
      (fma.f64 a (*.f64 27 b) (-.f64 (*.f64 x 2) (*.f64 y (*.f64 9 (*.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 a (*.f64 27 b) (-.f64 (*.f64 x 2) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y 9) (*.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 a (*.f64 27 b) (-.f64 (*.f64 x 2) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (*.f64 y 9) z) t)))): 2 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a (*.f64 27 b)) (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)))): 2 points increase in error, 2 points decrease in error
      (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b)) (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t))): 0 points increase in error, 3 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (*.f64 (*.f64 a 27) b))): 5 points increase in error, 1 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

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

Alternatives

Alternative 1
Error0.6
Cost7492
\[\begin{array}{l} \mathbf{if}\;z \leq 5 \cdot 10^{-157}:\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot \left(t \cdot -9\right), 27 \cdot \left(a \cdot b\right) + 2 \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(27 \cdot a\right) + \left(2 \cdot x + t \cdot \left(-9 \cdot \left(z \cdot y\right)\right)\right)\\ \end{array} \]
Alternative 2
Error11.6
Cost2384
\[\begin{array}{l} t_1 := 2 \cdot x - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\\ t_2 := b \cdot \left(27 \cdot a\right)\\ \mathbf{if}\;t_2 \leq -5 \cdot 10^{+42}:\\ \;\;\;\;2 \cdot x + a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;t_2 \leq -2 \cdot 10^{-32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq -4 \cdot 10^{-70}:\\ \;\;\;\;2 \cdot x + t_2\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{-41}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2 + t \cdot \left(y \cdot \left(z \cdot -9\right)\right)\\ \end{array} \]
Alternative 3
Error10.1
Cost2257
\[\begin{array}{l} t_1 := b \cdot \left(27 \cdot a\right)\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+42}:\\ \;\;\;\;2 \cdot x + a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;t_1 \leq -2 \cdot 10^{-32} \lor \neg \left(t_1 \leq -4 \cdot 10^{-70}\right) \land t_1 \leq 5 \cdot 10^{-41}:\\ \;\;\;\;2 \cdot x - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot x + t_1\\ \end{array} \]
Alternative 4
Error1.6
Cost1220
\[\begin{array}{l} t_1 := b \cdot \left(27 \cdot a\right)\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{+57}:\\ \;\;\;\;t_1 + y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(2 \cdot x + t \cdot \left(-9 \cdot \left(z \cdot y\right)\right)\right)\\ \end{array} \]
Alternative 5
Error0.7
Cost1220
\[\begin{array}{l} \mathbf{if}\;z \leq 1.6 \cdot 10^{-163}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + \left(2 \cdot x - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(27 \cdot a\right) + \left(2 \cdot x + t \cdot \left(-9 \cdot \left(z \cdot y\right)\right)\right)\\ \end{array} \]
Alternative 6
Error18.8
Cost1104
\[\begin{array}{l} t_1 := 2 \cdot x + a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;y \leq -2.1 \cdot 10^{+227}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(y \cdot -9\right)\\ \mathbf{elif}\;y \leq -6 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.9 \cdot 10^{+37}:\\ \;\;\;\;y \cdot \left(t \cdot \left(z \cdot -9\right)\right)\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-135}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 7
Error29.8
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -4.7 \cdot 10^{+71}:\\ \;\;\;\;2 \cdot x\\ \mathbf{elif}\;x \leq -1.22 \cdot 10^{-85}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq 7.6 \cdot 10^{-281}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{+14}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot x\\ \end{array} \]
Alternative 8
Error29.9
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -4.7 \cdot 10^{+71}:\\ \;\;\;\;2 \cdot x\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-86}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{-284}:\\ \;\;\;\;y \cdot \left(z \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+14}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot x\\ \end{array} \]
Alternative 9
Error28.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{+71}:\\ \;\;\;\;2 \cdot x\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{+14}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot x\\ \end{array} \]
Alternative 10
Error37.2
Cost192
\[2 \cdot x \]

Error

Reproduce

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