Average Error: 2.3 → 0.9
Time: 23.8s
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}\;b \le -1.443214701284468144706652585960774616249 \cdot 10^{-84} \lor \neg \left(b \le 1.66963206289420839225539623091866545351 \cdot 10^{-233}\right):\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, \mathsf{fma}\left(\mathsf{fma}\left(z, b, t\right), a, x\right)\right)\\ \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}\;b \le -1.443214701284468144706652585960774616249 \cdot 10^{-84} \lor \neg \left(b \le 1.66963206289420839225539623091866545351 \cdot 10^{-233}\right):\\
\;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r319649 = x;
        double r319650 = y;
        double r319651 = z;
        double r319652 = r319650 * r319651;
        double r319653 = r319649 + r319652;
        double r319654 = t;
        double r319655 = a;
        double r319656 = r319654 * r319655;
        double r319657 = r319653 + r319656;
        double r319658 = r319655 * r319651;
        double r319659 = b;
        double r319660 = r319658 * r319659;
        double r319661 = r319657 + r319660;
        return r319661;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r319662 = b;
        double r319663 = -1.4432147012844681e-84;
        bool r319664 = r319662 <= r319663;
        double r319665 = 1.6696320628942084e-233;
        bool r319666 = r319662 <= r319665;
        double r319667 = !r319666;
        bool r319668 = r319664 || r319667;
        double r319669 = x;
        double r319670 = y;
        double r319671 = z;
        double r319672 = r319670 * r319671;
        double r319673 = r319669 + r319672;
        double r319674 = t;
        double r319675 = a;
        double r319676 = r319674 * r319675;
        double r319677 = r319673 + r319676;
        double r319678 = r319675 * r319671;
        double r319679 = r319678 * r319662;
        double r319680 = r319677 + r319679;
        double r319681 = fma(r319671, r319662, r319674);
        double r319682 = fma(r319681, r319675, r319669);
        double r319683 = fma(r319671, r319670, r319682);
        double r319684 = r319668 ? r319680 : r319683;
        return r319684;
}

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.3
Target0.3
Herbie0.9
\[\begin{array}{l} \mathbf{if}\;z \lt -11820553527347888128:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z \lt 4.758974318836428710669076838657752600596 \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 b < -1.4432147012844681e-84 or 1.6696320628942084e-233 < b

    1. Initial program 1.3

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]

    if -1.4432147012844681e-84 < b < 1.6696320628942084e-233

    1. Initial program 4.9

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

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

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

Reproduce

herbie shell --seed 2019322 +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)))