Average Error: 1.7 → 0.1
Time: 5.8s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
\[\begin{array}{l} \mathbf{if}\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \leq 7.332908020110629 \cdot 10^{-47}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\left(\frac{x}{y} + \frac{4}{y}\right) - \frac{x}{y} \cdot z\right|\\ \end{array}\]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \leq 7.332908020110629 \cdot 10^{-47}:\\
\;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\left(\frac{x}{y} + \frac{4}{y}\right) - \frac{x}{y} \cdot z\right|\\

\end{array}
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))) 7.332908020110629e-47)
   (fabs (- (/ (+ x 4.0) y) (/ (* x z) y)))
   (fabs (- (+ (/ x y) (/ 4.0 y)) (* (/ x y) 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 (fabs(((x + 4.0) / y) - ((x / y) * z)) <= 7.332908020110629e-47) {
		tmp = fabs(((x + 4.0) / y) - ((x * z) / y));
	} else {
		tmp = fabs(((x / y) + (4.0 / y)) - ((x / y) * z));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))) < 7.33290802011062923e-47

    1. Initial program 5.0

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

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

    if 7.33290802011062923e-47 < (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)))

    1. Initial program 0.1

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
    2. 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|\]
    3. Simplified0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \leq 7.332908020110629 \cdot 10^{-47}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\left(\frac{x}{y} + \frac{4}{y}\right) - \frac{x}{y} \cdot z\right|\\ \end{array}\]

Reproduce

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