Average Error: 1.6 → 0.1
Time: 11.1s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -4.980485186604296 \cdot 10^{-32}:\\ \;\;\;\;\left|\frac{x + 4}{y} - z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 27202980690870932:\\ \;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\sqrt[3]{64}}{y} + \frac{x}{y} \cdot \left(\sqrt[3]{64} \cdot 0.25 - z\right)\right|\\ \end{array} \]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -4.980485186604296 \cdot 10^{-32}:\\
\;\;\;\;\left|\frac{x + 4}{y} - z \cdot \frac{x}{y}\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|\frac{\sqrt[3]{64}}{y} + \frac{x}{y} \cdot \left(\sqrt[3]{64} \cdot 0.25 - z\right)\right|\\


\end{array}
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= x -4.980485186604296e-32)
   (fabs (- (/ (+ x 4.0) y) (* z (/ x y))))
   (if (<= x 27202980690870932.0)
     (fabs (/ (- x (fma x z -4.0)) y))
     (fabs (+ (/ (cbrt 64.0) y) (* (/ x y) (- (* (cbrt 64.0) 0.25) z)))))))
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 (x <= -4.980485186604296e-32) {
		tmp = fabs(((x + 4.0) / y) - (z * (x / y)));
	} else if (x <= 27202980690870932.0) {
		tmp = fabs((x - fma(x, z, -4.0)) / y);
	} else {
		tmp = fabs((cbrt(64.0) / y) + ((x / y) * ((cbrt(64.0) * 0.25) - z)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Derivation

  1. Split input into 3 regimes
  2. if x < -4.9804851866042962e-32

    1. Initial program 0.2

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Applied add-cube-cbrt_binary640.6

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\left(\sqrt[3]{\frac{x}{y} \cdot z} \cdot \sqrt[3]{\frac{x}{y} \cdot z}\right) \cdot \sqrt[3]{\frac{x}{y} \cdot z}}\right| \]
    3. Taylor expanded in x around 0 8.0

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z \cdot x}{y}}\right| \]
    4. Simplified0.2

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

    if -4.9804851866042962e-32 < x < 27202980690870932

    1. Initial program 2.7

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

      \[\leadsto \color{blue}{\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|} \]

    if 27202980690870932 < x

    1. Initial program 0.1

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Applied add-cube-cbrt_binary640.9

      \[\leadsto \left|\color{blue}{\left(\sqrt[3]{\frac{x + 4}{y}} \cdot \sqrt[3]{\frac{x + 4}{y}}\right) \cdot \sqrt[3]{\frac{x + 4}{y}}} - \frac{x}{y} \cdot z\right| \]
    3. Applied fma-neg_binary640.9

      \[\leadsto \left|\color{blue}{\mathsf{fma}\left(\sqrt[3]{\frac{x + 4}{y}} \cdot \sqrt[3]{\frac{x + 4}{y}}, \sqrt[3]{\frac{x + 4}{y}}, -\frac{x}{y} \cdot z\right)}\right| \]
    4. Taylor expanded in x around 0 10.4

      \[\leadsto \left|\color{blue}{\left(0.25 \cdot \left({64}^{0.3333333333333333} \cdot \frac{x}{y}\right) + {64}^{0.3333333333333333} \cdot \frac{1}{y}\right) - \frac{z \cdot x}{y}}\right| \]
    5. Simplified0.1

      \[\leadsto \left|\color{blue}{\frac{\sqrt[3]{64}}{y} + \frac{x}{y} \cdot \left(\sqrt[3]{64} \cdot 0.25 - z\right)}\right| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.980485186604296 \cdot 10^{-32}:\\ \;\;\;\;\left|\frac{x + 4}{y} - z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 27202980690870932:\\ \;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\sqrt[3]{64}}{y} + \frac{x}{y} \cdot \left(\sqrt[3]{64} \cdot 0.25 - z\right)\right|\\ \end{array} \]

Reproduce

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