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

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


\end{array}

Error

Target

Original2.9
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 (*.f64 (*.f64 y 9) z) < 2.0000000000000001e149

    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. Simplified3.0

      \[\leadsto \color{blue}{\left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right) + a \cdot \left(27 \cdot b\right)} \]
      Proof
      (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 y 9) (*.f64 z t))) (*.f64 a (*.f64 27 b))): 0 points increase in error, 0 points decrease in error
      (+.f64 (-.f64 (*.f64 x 2) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (*.f64 y 9) z) t))) (*.f64 a (*.f64 27 b))): 0 points increase in error, 3 points decrease in error
      (+.f64 (-.f64 (*.f64 x 2) (*.f64 (*.f64 (*.f64 y 9) z) t)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a 27) b))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around 0 3.0

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

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

    if 2.0000000000000001e149 < (*.f64 (*.f64 y 9) z)

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

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

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

Alternatives

Alternative 1
Error0.7
Cost7748
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \leq 10^{+172}:\\ \;\;\;\;\left(x \cdot 2 - \left(y \cdot z\right) \cdot \left(9 \cdot t\right)\right) + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 + y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\right)\\ \end{array} \]
Alternative 2
Error10.7
Cost1481
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+68} \lor \neg \left(t_1 \leq 10^{-23}\right):\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\\ \end{array} \]
Alternative 3
Error10.7
Cost1481
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+68} \lor \neg \left(t_1 \leq 10^{-23}\right):\\ \;\;\;\;a \cdot \left(27 \cdot b\right) + x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 4
Error21.0
Cost1369
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ t_2 := t_1 + x \cdot 2\\ \mathbf{if}\;x \leq -6 \cdot 10^{-74}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-183}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-231}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.1 \cdot 10^{-293}:\\ \;\;\;\;-9 \cdot \left(\left(y \cdot z\right) \cdot t\right)\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-183} \lor \neg \left(x \leq 4.4 \cdot 10^{-124}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 5
Error21.0
Cost1368
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ t_2 := t_1 + x \cdot 2\\ \mathbf{if}\;x \leq -1.15 \cdot 10^{-70}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-183}:\\ \;\;\;\;z \cdot \left(y \cdot \left(t \cdot -9\right)\right)\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-231}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-293}:\\ \;\;\;\;-9 \cdot \left(\left(y \cdot z\right) \cdot t\right)\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-182}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-125}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \end{array} \]
Alternative 6
Error30.0
Cost1244
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ t_2 := -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{if}\;x \leq -1.4 \cdot 10^{+77}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -1.95 \cdot 10^{-183}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-230}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-293}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-183}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-124}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3850000000:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 7
Error30.1
Cost1244
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ t_2 := -9 \cdot \left(\left(y \cdot z\right) \cdot t\right)\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+81}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-183}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-231}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{-293}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-183}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-123}:\\ \;\;\;\;-9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 5200000000:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 8
Error30.1
Cost1244
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ t_2 := -9 \cdot \left(\left(y \cdot z\right) \cdot t\right)\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+79}:\\ \;\;\;\;x \cdot 2\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-183}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{-231}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.1 \cdot 10^{-293}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-182}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{-125}:\\ \;\;\;\;y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;x \leq 4600000000:\\ \;\;\;\;b \cdot \left(a \cdot 27\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2\\ \end{array} \]
Alternative 9
Error12.8
Cost1229
\[\begin{array}{l} t_1 := b \cdot \left(a \cdot 27\right)\\ \mathbf{if}\;x \leq -1.16 \cdot 10^{+164}:\\ \;\;\;\;t_1 + x \cdot 2\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{+73} \lor \neg \left(x \leq 1150\right):\\ \;\;\;\;x \cdot 2 + -9 \cdot \left(y \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + y \cdot \left(-9 \cdot \left(z \cdot t\right)\right)\\ \end{array} \]
Alternative 10
Error12.8
Cost1228
\[\begin{array}{l} t_1 := y \cdot \left(z \cdot t\right)\\ \mathbf{if}\;x \leq -1.4 \cdot 10^{+167}:\\ \;\;\;\;b \cdot \left(a \cdot 27\right) + x \cdot 2\\ \mathbf{elif}\;x \leq -1.4 \cdot 10^{+79}:\\ \;\;\;\;x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\\ \mathbf{elif}\;x \leq 900:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) - 9 \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot 2 + -9 \cdot t_1\\ \end{array} \]
Alternative 11
Error1.8
Cost1220
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq 1.6 \cdot 10^{+28}:\\ \;\;\;\;t_1 + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + z \cdot \left(t \cdot \left(y \cdot -9\right)\right)\\ \end{array} \]
Alternative 12
Error0.6
Cost1220
\[\begin{array}{l} t_1 := a \cdot \left(27 \cdot b\right)\\ \mathbf{if}\;z \leq -5 \cdot 10^{-48}:\\ \;\;\;\;t_1 + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - \left(y \cdot z\right) \cdot \left(9 \cdot t\right)\right) + t_1\\ \end{array} \]
Alternative 13
Error28.4
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+78} \lor \neg \left(x \leq 5000000000\right):\\ \;\;\;\;x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right)\\ \end{array} \]
Alternative 14
Error28.4
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1.95 \cdot 10^{+77} \lor \neg \left(x \leq 3800000000\right):\\ \;\;\;\;x \cdot 2\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(27 \cdot b\right)\\ \end{array} \]
Alternative 15
Error37.3
Cost192
\[x \cdot 2 \]

Error

Reproduce

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