Average Error: 1.8 → 0.6
Time: 4.1s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
\[\begin{array}{l} \mathbf{if}\;y \leq -8.278448837687982 \cdot 10^{+145}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;y \leq -2.2732327689230565 \cdot 10^{-282}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{elif}\;y \leq 1.532546704293406 \cdot 10^{+136}:\\ \;\;\;\;\left|\frac{4}{y} + \frac{x}{y} \cdot \left(1 - z\right)\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}\;y \leq -8.278448837687982 \cdot 10^{+145}:\\
\;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\

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

\mathbf{elif}\;y \leq 1.532546704293406 \cdot 10^{+136}:\\
\;\;\;\;\left|\frac{4}{y} + \frac{x}{y} \cdot \left(1 - z\right)\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 (<= y -8.278448837687982e+145)
   (fabs (- (/ (+ x 4.0) y) (* x (/ z y))))
   (if (<= y -2.2732327689230565e-282)
     (fabs (/ (- (+ x 4.0) (* x z)) y))
     (if (<= y 1.532546704293406e+136)
       (fabs (+ (/ 4.0 y) (* (/ x y) (- 1.0 z))))
       (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 (y <= -8.278448837687982e+145) {
		tmp = fabs(((x + 4.0) / y) - (x * (z / y)));
	} else if (y <= -2.2732327689230565e-282) {
		tmp = fabs(((x + 4.0) - (x * z)) / y);
	} else if (y <= 1.532546704293406e+136) {
		tmp = fabs((4.0 / y) + ((x / y) * (1.0 - z)));
	} 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 y < -8.2784488376879818e145 or 1.53254670429340598e136 < y

    1. Initial program 4.6

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

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

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

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

    if -8.2784488376879818e145 < y < -2.2732327689230565e-282

    1. Initial program 0.3

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

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

    if -2.2732327689230565e-282 < y < 1.53254670429340598e136

    1. Initial program 0.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8.278448837687982 \cdot 10^{+145}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;y \leq -2.2732327689230565 \cdot 10^{-282}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{elif}\;y \leq 1.532546704293406 \cdot 10^{+136}:\\ \;\;\;\;\left|\frac{4}{y} + \frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\ \end{array}\]

Reproduce

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