Average Error: 1.9 → 1.3
Time: 5.6s
Precision: binary64
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
\[\begin{array}{l} \mathbf{if}\;z \leq 2.231734751983997 \cdot 10^{-117}:\\ \;\;\;\;\left(\mathsf{fma}\left(z, y, x\right) + a \cdot t\right) + \left(z \cdot a\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), 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}\;z \leq 2.231734751983997 \cdot 10^{-117}:\\
\;\;\;\;\left(\mathsf{fma}\left(z, y, x\right) + a \cdot t\right) + \left(z \cdot a\right) \cdot b\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), 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
 (if (<= z 2.231734751983997e-117)
   (+ (+ (fma z y x) (* a t)) (* (* z a) b))
   (fma a t (fma z (fma a b y) 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 tmp;
	if (z <= 2.231734751983997e-117) {
		tmp = (fma(z, y, x) + (a * t)) + ((z * a) * b);
	} else {
		tmp = fma(a, t, fma(z, fma(a, b, y), 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

Original1.9
Target0.4
Herbie1.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 2 regimes
  2. if z < 2.2317347519839971e-117

    1. Initial program 1.4

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b \]
    2. Using strategy rm
    3. Applied add-log-exp_binary6427.6

      \[\leadsto \left(\left(x + y \cdot z\right) + \color{blue}{\log \left(e^{t \cdot a}\right)}\right) + \left(a \cdot z\right) \cdot b \]
    4. Applied add-log-exp_binary6442.5

      \[\leadsto \left(\left(x + \color{blue}{\log \left(e^{y \cdot z}\right)}\right) + \log \left(e^{t \cdot a}\right)\right) + \left(a \cdot z\right) \cdot b \]
    5. Applied add-log-exp_binary6459.7

      \[\leadsto \left(\left(\color{blue}{\log \left(e^{x}\right)} + \log \left(e^{y \cdot z}\right)\right) + \log \left(e^{t \cdot a}\right)\right) + \left(a \cdot z\right) \cdot b \]
    6. Applied sum-log_binary6459.7

      \[\leadsto \left(\color{blue}{\log \left(e^{x} \cdot e^{y \cdot z}\right)} + \log \left(e^{t \cdot a}\right)\right) + \left(a \cdot z\right) \cdot b \]
    7. Applied sum-log_binary6459.7

      \[\leadsto \color{blue}{\log \left(\left(e^{x} \cdot e^{y \cdot z}\right) \cdot e^{t \cdot a}\right)} + \left(a \cdot z\right) \cdot b \]
    8. Applied log-prod_binary6459.7

      \[\leadsto \color{blue}{\left(\log \left(e^{x} \cdot e^{y \cdot z}\right) + \log \left(e^{t \cdot a}\right)\right)} + \left(a \cdot z\right) \cdot b \]
    9. Simplified27.6

      \[\leadsto \left(\color{blue}{\mathsf{fma}\left(z, y, x\right)} + \log \left(e^{t \cdot a}\right)\right) + \left(a \cdot z\right) \cdot b \]
    10. Simplified1.4

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

    if 2.2317347519839971e-117 < z

    1. Initial program 3.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 add-log-exp_binary6429.8

      \[\leadsto \left(\left(x + y \cdot z\right) + t \cdot a\right) + \color{blue}{\log \left(e^{\left(a \cdot z\right) \cdot b}\right)} \]
    4. Applied add-log-exp_binary6441.6

      \[\leadsto \left(\left(x + y \cdot z\right) + \color{blue}{\log \left(e^{t \cdot a}\right)}\right) + \log \left(e^{\left(a \cdot z\right) \cdot b}\right) \]
    5. Applied add-log-exp_binary6455.7

      \[\leadsto \left(\left(x + \color{blue}{\log \left(e^{y \cdot z}\right)}\right) + \log \left(e^{t \cdot a}\right)\right) + \log \left(e^{\left(a \cdot z\right) \cdot b}\right) \]
    6. Applied add-log-exp_binary6463.0

      \[\leadsto \left(\left(\color{blue}{\log \left(e^{x}\right)} + \log \left(e^{y \cdot z}\right)\right) + \log \left(e^{t \cdot a}\right)\right) + \log \left(e^{\left(a \cdot z\right) \cdot b}\right) \]
    7. Applied sum-log_binary6463.0

      \[\leadsto \left(\color{blue}{\log \left(e^{x} \cdot e^{y \cdot z}\right)} + \log \left(e^{t \cdot a}\right)\right) + \log \left(e^{\left(a \cdot z\right) \cdot b}\right) \]
    8. Applied sum-log_binary6463.0

      \[\leadsto \color{blue}{\log \left(\left(e^{x} \cdot e^{y \cdot z}\right) \cdot e^{t \cdot a}\right)} + \log \left(e^{\left(a \cdot z\right) \cdot b}\right) \]
    9. Applied sum-log_binary6463.0

      \[\leadsto \color{blue}{\log \left(\left(\left(e^{x} \cdot e^{y \cdot z}\right) \cdot e^{t \cdot a}\right) \cdot e^{\left(a \cdot z\right) \cdot b}\right)} \]
    10. Applied log-prod_binary6463.0

      \[\leadsto \color{blue}{\log \left(\left(e^{x} \cdot e^{y \cdot z}\right) \cdot e^{t \cdot a}\right) + \log \left(e^{\left(a \cdot z\right) \cdot b}\right)} \]
    11. Simplified29.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, \mathsf{fma}\left(a, t, x\right)\right)} + \log \left(e^{\left(a \cdot z\right) \cdot b}\right) \]
    12. Simplified4.4

      \[\leadsto \mathsf{fma}\left(z, y, \mathsf{fma}\left(a, t, x\right)\right) + \color{blue}{a \cdot \left(z \cdot b\right)} \]
    13. Taylor expanded around 0 4.4

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

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

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

Reproduce

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