Average Error: 1.6 → 0.2
Time: 4.6s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0634706061927283 \cdot 10^{+39}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 3.866916048457255 \cdot 10^{+58}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \left(z \cdot \frac{1}{y}\right)\right|\\ \end{array}\]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -1.0634706061927283 \cdot 10^{+39}:\\
\;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|\frac{x + 4}{y} - x \cdot \left(z \cdot \frac{1}{y}\right)\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 -1.0634706061927283e+39)
   (fabs (- (/ (+ x 4.0) y) (* x (/ z y))))
   (if (<= x 3.866916048457255e+58)
     (fabs (/ (- (+ x 4.0) (* x z)) y))
     (fabs (- (/ (+ x 4.0) y) (* x (* z (/ 1.0 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 <= -1.0634706061927283e+39) {
		tmp = fabs(((x + 4.0) / y) - (x * (z / y)));
	} else if (x <= 3.866916048457255e+58) {
		tmp = fabs(((x + 4.0) - (x * z)) / y);
	} else {
		tmp = fabs(((x + 4.0) / y) - (x * (z * (1.0 / 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 < -1.06347060619272826e39

    1. Initial program 0.1

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

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\left(x \cdot \frac{1}{y}\right)} \cdot z\right|\]
    4. Applied associate-*l*_binary640.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 -1.06347060619272826e39 < x < 3.86691604845725504e58

    1. Initial program 2.2

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

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

    if 3.86691604845725504e58 < x

    1. Initial program 0.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.0634706061927283 \cdot 10^{+39}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 3.866916048457255 \cdot 10^{+58}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \left(z \cdot \frac{1}{y}\right)\right|\\ \end{array}\]

Alternatives

Reproduce

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