Average Error: 1.5 → 0.2
Time: 4.2s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \frac{x}{y} \cdot z\\ t_1 := \frac{x + 4}{y} - t_0\\ \mathbf{if}\;t_1 \leq -1.3368572763257305 \cdot 10^{+41}:\\ \;\;\;\;\left|\left(\frac{x}{y} + \frac{4}{y}\right) - t_0\right|\\ \mathbf{elif}\;t_1 \leq 1.417342327058317 \cdot 10^{-88}:\\ \;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-4 - x}{-y} - t_0\right|\\ \end{array} \]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \frac{x}{y} \cdot z\\
t_1 := \frac{x + 4}{y} - t_0\\
\mathbf{if}\;t_1 \leq -1.3368572763257305 \cdot 10^{+41}:\\
\;\;\;\;\left|\left(\frac{x}{y} + \frac{4}{y}\right) - t_0\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|\frac{-4 - x}{-y} - t_0\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 y) z)) (t_1 (- (/ (+ x 4.0) y) t_0)))
   (if (<= t_1 -1.3368572763257305e+41)
     (fabs (- (+ (/ x y) (/ 4.0 y)) t_0))
     (if (<= t_1 1.417342327058317e-88)
       (fabs (/ (- x (fma x z -4.0)) y))
       (fabs (- (/ (- -4.0 x) (- y)) t_0))))))
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 / y) * z;
	double t_1 = ((x + 4.0) / y) - t_0;
	double tmp;
	if (t_1 <= -1.3368572763257305e+41) {
		tmp = fabs(((x / y) + (4.0 / y)) - t_0);
	} else if (t_1 <= 1.417342327058317e-88) {
		tmp = fabs((x - fma(x, z, -4.0)) / y);
	} else {
		tmp = fabs(((-4.0 - x) / -y) - t_0);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Derivation

  1. Split input into 3 regimes
  2. if (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -1.3368572763257305e41

    1. Initial program 0.1

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Using strategy rm
    3. Applied flip3-+_binary6420.6

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

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

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

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

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

    if -1.3368572763257305e41 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 1.41734232705831705e-88

    1. Initial program 3.9

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

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

    if 1.41734232705831705e-88 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))

    1. Initial program 0.2

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

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

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

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

Reproduce

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