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

\mathbf{elif}\;x \leq 8.95711979789483 \cdot 10^{-75}:\\
\;\;\;\;\left|\mathsf{fma}\left(x, 1 - z, 4\right) \cdot \frac{1}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|t_0 - z \cdot \frac{x}{y}\right|\\


\end{array}
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (+ x 4.0) y)))
   (if (<= x -5.654014599181771e-9)
     (fabs (- t_0 (* x (/ z y))))
     (if (<= x 8.95711979789483e-75)
       (fabs (* (fma x (- 1.0 z) 4.0) (/ 1.0 y)))
       (fabs (- t_0 (* z (/ x 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 t_0 = (x + 4.0) / y;
	double tmp;
	if (x <= -5.654014599181771e-9) {
		tmp = fabs(t_0 - (x * (z / y)));
	} else if (x <= 8.95711979789483e-75) {
		tmp = fabs(fma(x, (1.0 - z), 4.0) * (1.0 / y));
	} else {
		tmp = fabs(t_0 - (z * (x / y)));
	}
	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 < -5.6540145991817714e-9

    1. Initial program 0.1

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

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\left(x \cdot \frac{1}{y}\right)} \cdot z\right| \]
    3. Applied associate-*l*_binary640.2

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

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

    if -5.6540145991817714e-9 < x < 8.9571197978948292e-75

    1. Initial program 2.8

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

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

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

      \[\leadsto \left|\frac{x + 4}{y} - x \cdot \color{blue}{\frac{z}{y}}\right| \]
    5. 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| \]
    6. Simplified0.1

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

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

    if 8.9571197978948292e-75 < x

    1. Initial program 0.3

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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