Average Error: 2.7 → 1.6
Time: 3.8s
Precision: binary64
\[[y, z, t] = \mathsf{sort}([y, z, t]) \[a, b] = \mathsf{sort}([a, b]) \\]
\[\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 := \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\\ t_2 := \mathsf{fma}\left(2, x, \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\right)\\ \mathbf{if}\;t_1 \leq -3.076527558128274 \cdot 10^{+253}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2.2582250355497793 \cdot 10^{+230}:\\ \;\;\;\;\left(2 \cdot x - t_1\right) + \left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, t_2\right)\\ \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 := \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\\
t_2 := \mathsf{fma}\left(2, x, \left(y \cdot \left(z \cdot t\right)\right) \cdot -9\right)\\
\mathbf{if}\;t_1 \leq -3.076527558128274 \cdot 10^{+253}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 2.2582250355497793 \cdot 10^{+230}:\\
\;\;\;\;\left(2 \cdot x - t_1\right) + \left(a \cdot 27\right) \cdot b\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(27, a \cdot b, t_2\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
 (let* ((t_1 (* (* (* y 9.0) z) t)) (t_2 (fma 2.0 x (* (* y (* z t)) -9.0))))
   (if (<= t_1 -3.076527558128274e+253)
     t_2
     (if (<= t_1 2.2582250355497793e+230)
       (+ (- (* 2.0 x) t_1) (* (* a 27.0) b))
       (fma 27.0 (* a b) t_2)))))
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 = ((y * 9.0) * z) * t;
	double t_2 = fma(2.0, x, ((y * (z * t)) * -9.0));
	double tmp;
	if (t_1 <= -3.076527558128274e+253) {
		tmp = t_2;
	} else if (t_1 <= 2.2582250355497793e+230) {
		tmp = ((2.0 * x) - t_1) + ((a * 27.0) * b);
	} else {
		tmp = fma(27.0, (a * b), t_2);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

Target

Original2.7
Target3.1
Herbie1.6
\[\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 3 regimes
  2. if (*.f64 (*.f64 (*.f64 y 9) z) t) < -3.076527558128274e253

    1. Initial program 11.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \left(z \cdot t\right) \cdot -9, \mathsf{fma}\left(x, 2, \left(a \cdot 27\right) \cdot b\right)\right)} \]
    3. Taylor expanded in a around 0 6.2

      \[\leadsto \color{blue}{2 \cdot x - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)} \]
    4. Simplified6.2

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

    if -3.076527558128274e253 < (*.f64 (*.f64 (*.f64 y 9) z) t) < 2.2582250355497793e230

    1. Initial program 0.3

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]

    if 2.2582250355497793e230 < (*.f64 (*.f64 (*.f64 y 9) z) t)

    1. Initial program 9.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \left(z \cdot t\right) \cdot -9, \mathsf{fma}\left(x, 2, \left(a \cdot 27\right) \cdot b\right)\right)} \]
    3. Taylor expanded in y around 0 4.8

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

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

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

Reproduce

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