Average Error: 5.3 → 2.2
Time: 3.8s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;y \leq -9.558233736210092 \cdot 10^{-113}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\mathsf{fma}\left(x, 1 - z, 4\right)}{y}\right|\\ \end{array} \]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;y \leq -9.558233736210092 \cdot 10^{-113}:\\
\;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(x, 1 - z, 4\right)}{y}\right|\\


\end{array}
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= y -9.558233736210092e-113)
   (fabs (- (/ (+ x 4.0) y) (* (/ x y) z)))
   (fabs (/ (fma x (- 1.0 z) 4.0) y))))
double code(double x, double y, double z) {
	return fabs(((x + 4.0) / y) - ((x / y) * z));
}
double code(double x, double y, double z) {
	double tmp;
	if (y <= -9.558233736210092e-113) {
		tmp = fabs(((x + 4.0) / y) - ((x / y) * z));
	} else {
		tmp = fabs(fma(x, (1.0 - z), 4.0) / y);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Derivation

  1. Split input into 2 regimes
  2. if y < -9.5582337362100922e-113

    1. Initial program 2.8

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]

    if -9.5582337362100922e-113 < y

    1. Initial program 6.6

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Simplified1.9

      \[\leadsto \color{blue}{\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|} \]
    3. Applied add-cube-cbrt_binary642.6

      \[\leadsto \left|\frac{x - \color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}}}{y}\right| \]
    4. Applied add-cube-cbrt_binary642.8

      \[\leadsto \left|\frac{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}} - \left(\sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}}{y}\right| \]
    5. Applied prod-diff_binary648.9

      \[\leadsto \left|\frac{\color{blue}{\mathsf{fma}\left(\sqrt[3]{x} \cdot \sqrt[3]{x}, \sqrt[3]{x}, -\sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \left(\sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}, \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}, \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \left(\sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}\right)\right)}}{y}\right| \]
    6. Simplified8.1

      \[\leadsto \left|\frac{\color{blue}{\mathsf{fma}\left(x, 1 - z, 4\right)} + \mathsf{fma}\left(-\sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}, \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}, \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \left(\sqrt[3]{\mathsf{fma}\left(x, z, -4\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x, z, -4\right)}\right)\right)}{y}\right| \]
    7. Simplified1.9

      \[\leadsto \left|\frac{\mathsf{fma}\left(x, 1 - z, 4\right) + \color{blue}{0}}{y}\right| \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.558233736210092 \cdot 10^{-113}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\mathsf{fma}\left(x, 1 - z, 4\right)}{y}\right|\\ \end{array} \]

Reproduce

herbie shell --seed 2022068 
(FPCore (x y z)
  :name "fabs fraction 1"
  :precision binary64
  (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))