Average Error: 4.0 → 2.3
Time: 4.5s
Precision: 64
\[\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 \le -4.49142761552870707 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \left(y \cdot \left(9 \cdot z\right)\right) \cdot t\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}
\mathbf{if}\;y \cdot 9 \le -4.49142761552870707 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(\left(9 \cdot z\right) \cdot t\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r817635 = x;
        double r817636 = 2.0;
        double r817637 = r817635 * r817636;
        double r817638 = y;
        double r817639 = 9.0;
        double r817640 = r817638 * r817639;
        double r817641 = z;
        double r817642 = r817640 * r817641;
        double r817643 = t;
        double r817644 = r817642 * r817643;
        double r817645 = r817637 - r817644;
        double r817646 = a;
        double r817647 = 27.0;
        double r817648 = r817646 * r817647;
        double r817649 = b;
        double r817650 = r817648 * r817649;
        double r817651 = r817645 + r817650;
        return r817651;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r817652 = y;
        double r817653 = 9.0;
        double r817654 = r817652 * r817653;
        double r817655 = -4.491427615528707e-07;
        bool r817656 = r817654 <= r817655;
        double r817657 = a;
        double r817658 = 27.0;
        double r817659 = b;
        double r817660 = r817658 * r817659;
        double r817661 = x;
        double r817662 = 2.0;
        double r817663 = r817661 * r817662;
        double r817664 = z;
        double r817665 = r817653 * r817664;
        double r817666 = t;
        double r817667 = r817665 * r817666;
        double r817668 = r817652 * r817667;
        double r817669 = r817663 - r817668;
        double r817670 = fma(r817657, r817660, r817669);
        double r817671 = r817652 * r817665;
        double r817672 = r817671 * r817666;
        double r817673 = r817663 - r817672;
        double r817674 = fma(r817657, r817660, r817673);
        double r817675 = r817656 ? r817670 : r817674;
        return r817675;
}

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

Original4.0
Target2.9
Herbie2.3
\[\begin{array}{l} \mathbf{if}\;y \lt 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 (* y 9.0) < -4.491427615528707e-07

    1. Initial program 8.4

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
    2. Using strategy rm
    3. Applied associate-*l*8.3

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(y \cdot \left(9 \cdot z\right)\right)} \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
    4. Using strategy rm
    5. Applied associate-*l*0.7

      \[\leadsto \left(x \cdot 2 - \color{blue}{y \cdot \left(\left(9 \cdot z\right) \cdot t\right)}\right) + \left(a \cdot 27\right) \cdot b\]
    6. Taylor expanded around inf 8.1

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

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

    if -4.491427615528707e-07 < (* y 9.0)

    1. Initial program 2.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. Using strategy rm
    3. Applied associate-*l*2.7

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(y \cdot \left(9 \cdot z\right)\right)} \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
    4. Taylor expanded around inf 2.5

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

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

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

Reproduce

herbie shell --seed 2020081 +o rules:numerics
(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) (* (* (* y 9) z) t)) (* a (* 27 b))) (+ (- (* x 2) (* 9 (* y (* t z)))) (* (* a 27) b)))

  (+ (- (* x 2) (* (* (* y 9) z) t)) (* (* a 27) b)))