Average Error: 1.6 → 0.3
Time: 2.7s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.999698535205023 \cdot 10^{+108} \lor \neg \left(x \leq 4.179457532768889 \cdot 10^{-37}\right):\\ \;\;\;\;\left|\frac{4}{y} + \frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array}\]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -1.999698535205023 \cdot 10^{+108} \lor \neg \left(x \leq 4.179457532768889 \cdot 10^{-37}\right):\\
\;\;\;\;\left|\frac{4}{y} + \frac{x}{y} \cdot \left(1 - z\right)\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot 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 (or (<= x -1.999698535205023e+108) (not (<= x 4.179457532768889e-37)))
   (fabs (+ (/ 4.0 y) (* (/ x y) (- 1.0 z))))
   (fabs (/ (- (+ x 4.0) (* x z)) y))))
double code(double x, double y, double z) {
	return ((double) fabs(((double) ((((double) (x + 4.0)) / y) - ((double) ((x / y) * z))))));
}
double code(double x, double y, double z) {
	double tmp;
	if (((x <= -1.999698535205023e+108) || !(x <= 4.179457532768889e-37))) {
		tmp = ((double) fabs(((double) ((4.0 / y) + ((double) ((x / y) * ((double) (1.0 - z))))))));
	} else {
		tmp = ((double) fabs((((double) (((double) (x + 4.0)) - ((double) (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 2 regimes
  2. if x < -1.99969853520502311e108 or 4.1794575327688886e-37 < x

    1. Initial program 0.1

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

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

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

    if -1.99969853520502311e108 < x < 4.1794575327688886e-37

    1. Initial program 2.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.999698535205023 \cdot 10^{+108} \lor \neg \left(x \leq 4.179457532768889 \cdot 10^{-37}\right):\\ \;\;\;\;\left|\frac{4}{y} + \frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array}\]

Reproduce

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