Average Error: 2.2 → 0.1
Time: 4.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}\;a \le -0.527665773500409663 \lor \neg \left(a \le 125421.218259876026\right):\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + a \cdot \left(z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, 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}\;a \le -0.527665773500409663 \lor \neg \left(a \le 125421.218259876026\right):\\
\;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + a \cdot \left(z \cdot b\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r606703 = x;
        double r606704 = y;
        double r606705 = z;
        double r606706 = r606704 * r606705;
        double r606707 = r606703 + r606706;
        double r606708 = t;
        double r606709 = a;
        double r606710 = r606708 * r606709;
        double r606711 = r606707 + r606710;
        double r606712 = r606709 * r606705;
        double r606713 = b;
        double r606714 = r606712 * r606713;
        double r606715 = r606711 + r606714;
        return r606715;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r606716 = a;
        double r606717 = -0.5276657735004097;
        bool r606718 = r606716 <= r606717;
        double r606719 = 125421.21825987603;
        bool r606720 = r606716 <= r606719;
        double r606721 = !r606720;
        bool r606722 = r606718 || r606721;
        double r606723 = x;
        double r606724 = y;
        double r606725 = z;
        double r606726 = r606724 * r606725;
        double r606727 = r606723 + r606726;
        double r606728 = t;
        double r606729 = r606728 * r606716;
        double r606730 = r606727 + r606729;
        double r606731 = b;
        double r606732 = r606725 * r606731;
        double r606733 = r606716 * r606732;
        double r606734 = r606730 + r606733;
        double r606735 = fma(r606716, r606731, r606724);
        double r606736 = fma(r606716, r606728, r606723);
        double r606737 = fma(r606735, r606725, r606736);
        double r606738 = r606722 ? r606734 : r606737;
        return r606738;
}

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.2
Target0.4
Herbie0.1
\[\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 a < -0.5276657735004097 or 125421.21825987603 < a

    1. Initial program 5.0

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

      \[\leadsto \left(\left(x + y \cdot z\right) + t \cdot a\right) + \color{blue}{a \cdot \left(z \cdot b\right)}\]

    if -0.5276657735004097 < a < 125421.21825987603

    1. Initial program 0.5

      \[\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(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

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

Reproduce

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