Average Error: 1.6 → 0.2
Time: 3.2s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -3.7938758802322557 \cdot 10^{-50}:\\ \;\;\;\;\left|\frac{-4 - x}{-y} - \frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq 48880875414.55884:\\ \;\;\;\;\left|\frac{1}{\frac{y}{\mathsf{fma}\left(x, 1 - z, 4\right)}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} \cdot \left(1 - z\right)\right|\\ \end{array} \]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -3.7938758802322557 \cdot 10^{-50}:\\
\;\;\;\;\left|\frac{-4 - x}{-y} - \frac{x}{y} \cdot z\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|\frac{x}{y} \cdot \left(1 - 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 -3.7938758802322557e-50)
   (fabs (- (/ (- -4.0 x) (- y)) (* (/ x y) z)))
   (if (<= x 48880875414.55884)
     (fabs (/ 1.0 (/ y (fma x (- 1.0 z) 4.0))))
     (fabs (* (/ x y) (- 1.0 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 <= -3.7938758802322557e-50) {
		tmp = fabs(((-4.0 - x) / -y) - ((x / y) * z));
	} else if (x <= 48880875414.55884) {
		tmp = fabs(1.0 / (y / fma(x, (1.0 - z), 4.0)));
	} else {
		tmp = fabs((x / y) * (1.0 - 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 < -3.79387588023225575e-50

    1. Initial program 0.3

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Applied frac-2neg_binary640.3

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

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

    if -3.79387588023225575e-50 < x < 48880875414.55884

    1. Initial program 2.7

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Applied div-inv_binary642.7

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

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

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

      \[\leadsto \left|\color{blue}{\frac{\mathsf{fma}\left(x, 1 - z, 4\right)}{y}}\right| \]
    6. Applied clear-num_binary640.1

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

    if 48880875414.55884 < x

    1. Initial program 0.1

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Taylor expanded in x around inf 0.4

      \[\leadsto \left|\color{blue}{\left(\frac{1}{y} - \frac{z}{y}\right) \cdot x}\right| \]
    3. Simplified0.3

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

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

Reproduce

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