Average Error: 2.0 → 0.7
Time: 8.6s
Precision: 64
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
\[\begin{array}{l} \mathbf{if}\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b = -\infty \lor \neg \left(\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \le 1.8357449125512327 \cdot 10^{262}\right):\\ \;\;\;\;\mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), \mathsf{fma}\left(y, z, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \end{array}\]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
\mathbf{if}\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b = -\infty \lor \neg \left(\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \le 1.8357449125512327 \cdot 10^{262}\right):\\
\;\;\;\;\mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), \mathsf{fma}\left(y, z, x\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r610634 = x;
        double r610635 = y;
        double r610636 = z;
        double r610637 = r610635 * r610636;
        double r610638 = r610634 + r610637;
        double r610639 = t;
        double r610640 = a;
        double r610641 = r610639 * r610640;
        double r610642 = r610638 + r610641;
        double r610643 = r610640 * r610636;
        double r610644 = b;
        double r610645 = r610643 * r610644;
        double r610646 = r610642 + r610645;
        return r610646;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r610647 = x;
        double r610648 = y;
        double r610649 = z;
        double r610650 = r610648 * r610649;
        double r610651 = r610647 + r610650;
        double r610652 = t;
        double r610653 = a;
        double r610654 = r610652 * r610653;
        double r610655 = r610651 + r610654;
        double r610656 = r610653 * r610649;
        double r610657 = b;
        double r610658 = r610656 * r610657;
        double r610659 = r610655 + r610658;
        double r610660 = -inf.0;
        bool r610661 = r610659 <= r610660;
        double r610662 = 1.8357449125512327e+262;
        bool r610663 = r610659 <= r610662;
        double r610664 = !r610663;
        bool r610665 = r610661 || r610664;
        double r610666 = fma(r610649, r610657, r610652);
        double r610667 = fma(r610648, r610649, r610647);
        double r610668 = fma(r610653, r610666, r610667);
        double r610669 = r610665 ? r610668 : r610659;
        return r610669;
}

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.0
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;z \lt -11820553527347888000:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z \lt 4.75897431883642871 \cdot 10^{-122}:\\ \;\;\;\;\left(b \cdot z + t\right) \cdot a + \left(z \cdot y + x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)) < -inf.0 or 1.8357449125512327e+262 < (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b))

    1. Initial program 16.7

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
    2. Simplified3.8

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

    if -inf.0 < (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)) < 1.8357449125512327e+262

    1. Initial program 0.3

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b = -\infty \lor \neg \left(\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \le 1.8357449125512327 \cdot 10^{262}\right):\\ \;\;\;\;\mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), \mathsf{fma}\left(y, z, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \end{array}\]

Reproduce

herbie shell --seed 2020046 +o rules:numerics
(FPCore (x y z t a b)
  :name "Graphics.Rasterific.CubicBezier:cachedBezierAt from Rasterific-0.6.1"
  :precision binary64

  :herbie-target
  (if (< z -11820553527347888000) (+ (* z (+ (* b a) y)) (+ x (* t a))) (if (< z 4.7589743188364287e-122) (+ (* (+ (* b z) t) a) (+ (* z y) x)) (+ (* z (+ (* b a) y)) (+ x (* t a)))))

  (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))