Average Error: 2.0 → 0.3
Time: 6.8s
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 := b \cdot \left(z \cdot a\right)\\ \mathbf{if}\;b \leq -2.0887889302975253 \cdot 10^{+26}:\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + t_1\\ \mathbf{elif}\;b \leq 8.306771119277255 \cdot 10^{-64}:\\ \;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \mathsf{fma}\left(z, y, \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}
t_1 := b \cdot \left(z \cdot a\right)\\
\mathbf{if}\;b \leq -2.0887889302975253 \cdot 10^{+26}:\\
\;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + t_1\\

\mathbf{elif}\;b \leq 8.306771119277255 \cdot 10^{-64}:\\
\;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t_1 + \mathsf{fma}\left(z, y, \mathsf{fma}\left(a, t, 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 (* b (* z a))))
   (if (<= b -2.0887889302975253e+26)
     (+ (+ (+ x (* y z)) (* t a)) t_1)
     (if (<= b 8.306771119277255e-64)
       (fma a t (fma z (fma a b y) x))
       (+ t_1 (fma z y (fma a t 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 = b * (z * a);
	double tmp;
	if (b <= -2.0887889302975253e+26) {
		tmp = ((x + (y * z)) + (t * a)) + t_1;
	} else if (b <= 8.306771119277255e-64) {
		tmp = fma(a, t, fma(z, fma(a, b, y), x));
	} else {
		tmp = t_1 + fma(z, y, fma(a, t, 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.0
Target0.3
Herbie0.3
\[\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 b < -2.0887889302975253e26

    1. Initial program 0.4

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

    if -2.0887889302975253e26 < b < 8.3067711192772547e-64

    1. Initial program 3.2

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

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

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

    if 8.3067711192772547e-64 < b

    1. Initial program 0.9

      \[\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.9

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

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

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

Reproduce

herbie shell --seed 2022020 
(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)))