Average Error: 1.6 → 0.2
Time: 3.9s
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.0757937571568445 \cdot 10^{-110}:\\ \;\;\;\;\left|t_0 - \frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq 5.121491754412143 \cdot 10^{-14}:\\ \;\;\;\;\left|\frac{x}{y} - \frac{\mathsf{fma}\left(x, z, -4\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\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.0757937571568445 \cdot 10^{-110}:\\
\;\;\;\;\left|t_0 - \frac{x}{y} \cdot z\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|t_0 - \frac{z}{\frac{y}{x}}\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.0757937571568445e-110)
     (fabs (- t_0 (* (/ x y) z)))
     (if (<= x 5.121491754412143e-14)
       (fabs (- (/ x y) (/ (fma x z -4.0) y)))
       (fabs (- t_0 (/ z (/ y x))))))))
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.0757937571568445e-110) {
		tmp = fabs((t_0 - ((x / y) * z)));
	} else if (x <= 5.121491754412143e-14) {
		tmp = fabs(((x / y) - (fma(x, z, -4.0) / y)));
	} else {
		tmp = fabs((t_0 - (z / (y / x))));
	}
	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.0757937571568445e-110

    1. Initial program 0.6

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

    if -5.0757937571568445e-110 < x < 5.12149175441214306e-14

    1. Initial program 2.9

      \[\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|} \]
    3. Applied egg-rr0.1

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

    if 5.12149175441214306e-14 < x

    1. Initial program 0.1

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

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

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

Reproduce

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