Average Error: 2.1 → 0.5
Time: 6.6s
Precision: binary64
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} t_1 := \left(z \cdot a\right) \cdot b\\ t_2 := \left(\left(x + y \cdot z\right) + t \cdot a\right) + t_1\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{elif}\;t_2 \leq 6.9118361704355144 \cdot 10^{+305}:\\ \;\;\;\;t_1 + \mathsf{fma}\left(z, y, \mathsf{fma}\left(a, t, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(a, z \cdot b, 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}
t_1 := \left(z \cdot a\right) \cdot b\\
t_2 := \left(\left(x + y \cdot z\right) + t \cdot a\right) + t_1\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\

\mathbf{elif}\;t_2 \leq 6.9118361704355144 \cdot 10^{+305}:\\
\;\;\;\;t_1 + \mathsf{fma}\left(z, y, \mathsf{fma}\left(a, t, x\right)\right)\\

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


\end{array}
(FPCore (x y z t a b)
 :precision binary64
 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* (* z a) b)) (t_2 (+ (+ (+ x (* y z)) (* t a)) t_1)))
   (if (<= t_2 (- INFINITY))
     (fma y z (fma a (fma z b t) x))
     (if (<= t_2 6.9118361704355144e+305)
       (+ t_1 (fma z y (fma a t x)))
       (fma a t (fma a (* z b) x))))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x + (y * z)) + (t * a)) + ((a * z) * b);
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (z * a) * b;
	double t_2 = ((x + (y * z)) + (t * a)) + t_1;
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = fma(y, z, fma(a, fma(z, b, t), x));
	} else if (t_2 <= 6.9118361704355144e+305) {
		tmp = t_1 + fma(z, y, fma(a, t, x));
	} else {
		tmp = fma(a, t, fma(a, (z * b), x));
	}
	return tmp;
}

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
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;z < -11820553527347888000:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z < 4.7589743188364287 \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 3 regimes
  2. if (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < -inf.0

    1. Initial program 64.0

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

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

    if -inf.0 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b)) < 6.9118361704355144e305

    1. Initial program 0.3

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Taylor expanded in x around 0 0.3

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

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

    if 6.9118361704355144e305 < (+.f64 (+.f64 (+.f64 x (*.f64 y z)) (*.f64 t a)) (*.f64 (*.f64 a z) b))

    1. Initial program 48.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)} \]
    3. Taylor expanded in y around 0 0.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), x\right)\right)} \]
    5. Taylor expanded in y around 0 11.6

      \[\leadsto \mathsf{fma}\left(a, t, \color{blue}{a \cdot \left(b \cdot z\right) + x}\right) \]
    6. Simplified11.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(z \cdot a\right) \cdot b \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), x\right)\right)\\ \mathbf{elif}\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(z \cdot a\right) \cdot b \leq 6.9118361704355144 \cdot 10^{+305}:\\ \;\;\;\;\left(z \cdot a\right) \cdot b + \mathsf{fma}\left(z, y, \mathsf{fma}\left(a, t, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(a, z \cdot b, x\right)\right)\\ \end{array} \]

Reproduce

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

  :herbie-target
  (if (< z -11820553527347888000.0) (+ (* 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)))