Average Error: 1.6 → 0.7
Time: 4.1s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \frac{x + 4}{y}\\ \mathbf{if}\;y \leq -1.5209272263734793 \cdot 10^{+151}:\\ \;\;\;\;\left|t_0 - x \cdot \left(\frac{1}{y} \cdot z\right)\right|\\ \mathbf{elif}\;y \leq 7.17864311788996 \cdot 10^{-100}:\\ \;\;\;\;\left|\mathsf{fma}\left(1, t_0, -\frac{x \cdot z}{y}\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|t_0 - x \cdot \frac{z}{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}\;y \leq -1.5209272263734793 \cdot 10^{+151}:\\
\;\;\;\;\left|t_0 - x \cdot \left(\frac{1}{y} \cdot z\right)\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|t_0 - x \cdot \frac{z}{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 (<= y -1.5209272263734793e+151)
     (fabs (- t_0 (* x (* (/ 1.0 y) z))))
     (if (<= y 7.17864311788996e-100)
       (fabs (fma 1.0 t_0 (- (/ (* x z) y))))
       (fabs (- t_0 (* x (/ z 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 (y <= -1.5209272263734793e+151) {
		tmp = fabs(t_0 - (x * ((1.0 / y) * z)));
	} else if (y <= 7.17864311788996e-100) {
		tmp = fabs(fma(1.0, t_0, -((x * z) / y)));
	} else {
		tmp = fabs(t_0 - (x * (z / 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 y < -1.52092722637347932e151

    1. Initial program 4.4

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

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

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

    if -1.52092722637347932e151 < y < 7.1786431178899603e-100

    1. Initial program 0.4

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Applied *-un-lft-identity_binary640.4

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

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

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

    if 7.1786431178899603e-100 < y

    1. Initial program 1.9

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

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

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

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

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

Reproduce

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