Average Error: 1.6 → 0.6
Time: 2.9s
Precision: 64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
\[\begin{array}{l} \mathbf{if}\;\frac{x + 4}{y} - \frac{x}{y} \cdot z \le -2.15195677319828921 \cdot 10^{-53} \lor \neg \left(\frac{x + 4}{y} - \frac{x}{y} \cdot z \le 6.1198321354959944 \cdot 10^{138}\right):\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\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}\;\frac{x + 4}{y} - \frac{x}{y} \cdot z \le -2.15195677319828921 \cdot 10^{-53} \lor \neg \left(\frac{x + 4}{y} - \frac{x}{y} \cdot z \le 6.1198321354959944 \cdot 10^{138}\right):\\
\;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\

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

\end{array}
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 temp;
	if ((((((x + 4.0) / y) - ((x / y) * z)) <= -2.151956773198289e-53) || !((((x + 4.0) / y) - ((x / y) * z)) <= 6.119832135495994e+138))) {
		temp = fabs((((x + 4.0) / y) - ((x / y) * z)));
	} else {
		temp = fabs((((x + 4.0) - (x * z)) / y));
	}
	return temp;
}

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 4.0) y) (* (/ x y) z)) < -2.151956773198289e-53 or 6.119832135495994e+138 < (- (/ (+ x 4.0) y) (* (/ x y) z))

    1. Initial program 0.1

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

    if -2.151956773198289e-53 < (- (/ (+ x 4.0) y) (* (/ x y) z)) < 6.119832135495994e+138

    1. Initial program 3.1

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
    2. Using strategy rm
    3. Applied associate-*l/1.0

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right|\]
    4. Applied sub-div1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + 4}{y} - \frac{x}{y} \cdot z \le -2.15195677319828921 \cdot 10^{-53} \lor \neg \left(\frac{x + 4}{y} - \frac{x}{y} \cdot z \le 6.1198321354959944 \cdot 10^{138}\right):\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array}\]

Reproduce

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