Average Error: 1.5 → 0.6
Time: 3.6s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
\[\begin{array}{l} \mathbf{if}\;x \leq -5.06235049948775 \cdot 10^{+122}:\\ \;\;\;\;\left|\left(\frac{x}{y} + \frac{4}{y}\right) - \frac{x}{y} \cdot z\right|\\ \mathbf{elif}\;x \leq 3.648782790610929 \cdot 10^{-98}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\ \end{array}\]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -5.06235049948775 \cdot 10^{+122}:\\
\;\;\;\;\left|\left(\frac{x}{y} + \frac{4}{y}\right) - \frac{x}{y} \cdot z\right|\\

\mathbf{elif}\;x \leq 3.648782790610929 \cdot 10^{-98}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{x + 4}{y} - 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
 (if (<= x -5.06235049948775e+122)
   (fabs (- (+ (/ x y) (/ 4.0 y)) (* (/ x y) z)))
   (if (<= x 3.648782790610929e-98)
     (fabs (/ (- (+ x 4.0) (* x z)) y))
     (fabs (- (/ (+ x 4.0) y) (* 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 tmp;
	if (x <= -5.06235049948775e+122) {
		tmp = fabs(((x / y) + (4.0 / y)) - ((x / y) * z));
	} else if (x <= 3.648782790610929e-98) {
		tmp = fabs(((x + 4.0) - (x * z)) / y);
	} else {
		tmp = fabs(((x + 4.0) / y) - (x * (z / y)));
	}
	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 3 regimes
  2. if x < -5.06235049948774971e122

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

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

    if -5.06235049948774971e122 < x < 3.6487827906109293e-98

    1. Initial program 2.1

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

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

    if 3.6487827906109293e-98 < x

    1. Initial program 0.6

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

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

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

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

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

Reproduce

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