Average Error: 2.1 → 1.1
Time: 18.1s
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 -6.010092830342159068026797631733328371903 \cdot 10^{91} \lor \neg \left(b \le 2.523072191078696760108259564699709727871 \cdot 10^{-269}\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 -6.010092830342159068026797631733328371903 \cdot 10^{91} \lor \neg \left(b \le 2.523072191078696760108259564699709727871 \cdot 10^{-269}\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 r362625 = x;
        double r362626 = y;
        double r362627 = z;
        double r362628 = r362626 * r362627;
        double r362629 = r362625 + r362628;
        double r362630 = t;
        double r362631 = a;
        double r362632 = r362630 * r362631;
        double r362633 = r362629 + r362632;
        double r362634 = r362631 * r362627;
        double r362635 = b;
        double r362636 = r362634 * r362635;
        double r362637 = r362633 + r362636;
        return r362637;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r362638 = b;
        double r362639 = -6.010092830342159e+91;
        bool r362640 = r362638 <= r362639;
        double r362641 = 2.5230721910786968e-269;
        bool r362642 = r362638 <= r362641;
        double r362643 = !r362642;
        bool r362644 = r362640 || r362643;
        double r362645 = x;
        double r362646 = y;
        double r362647 = z;
        double r362648 = r362646 * r362647;
        double r362649 = r362645 + r362648;
        double r362650 = t;
        double r362651 = a;
        double r362652 = r362650 * r362651;
        double r362653 = r362649 + r362652;
        double r362654 = r362651 * r362647;
        double r362655 = r362654 * r362638;
        double r362656 = r362653 + r362655;
        double r362657 = fma(r362647, r362638, r362650);
        double r362658 = fma(r362657, r362651, r362645);
        double r362659 = fma(r362647, r362646, r362658);
        double r362660 = r362644 ? r362656 : r362659;
        return r362660;
}

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.1
Target0.3
Herbie1.1
\[\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 < -6.010092830342159e+91 or 2.5230721910786968e-269 < b

    1. Initial program 1.5

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

    if -6.010092830342159e+91 < b < 2.5230721910786968e-269

    1. Initial program 3.0

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

      \[\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 simplification1.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.010092830342159068026797631733328371903 \cdot 10^{91} \lor \neg \left(b \le 2.523072191078696760108259564699709727871 \cdot 10^{-269}\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 2019323 +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)))