Average Error: 1.6 → 0.1
Time: 7.1s
Precision: binary64
\[\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 \leq -2.593780501472562 \cdot 10^{+48}:\\ \;\;\;\;\left|\frac{4}{y} + \frac{x}{y} \cdot \left(1 - z\right)\right|\\ \mathbf{elif}\;\frac{x + 4}{y} - \frac{x}{y} \cdot z \leq 1.9132480395880643 \cdot 10^{+32}:\\ \;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\left(\frac{x}{y} + 4 \cdot \frac{1}{y}\right) - \frac{x}{y} \cdot z\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 \leq -2.593780501472562 \cdot 10^{+48}:\\
\;\;\;\;\left|\frac{4}{y} + \frac{x}{y} \cdot \left(1 - z\right)\right|\\

\mathbf{elif}\;\frac{x + 4}{y} - \frac{x}{y} \cdot z \leq 1.9132480395880643 \cdot 10^{+32}:\\
\;\;\;\;\left|\frac{x + 4}{y} - x \cdot \frac{z}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\left(\frac{x}{y} + 4 \cdot \frac{1}{y}\right) - \frac{x}{y} \cdot z\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 4.0) y) (* (/ x y) z)) -2.593780501472562e+48)
   (fabs (+ (/ 4.0 y) (* (/ x y) (- 1.0 z))))
   (if (<= (- (/ (+ x 4.0) y) (* (/ x y) z)) 1.9132480395880643e+32)
     (fabs (- (/ (+ x 4.0) y) (* x (/ z y))))
     (fabs (- (+ (/ x y) (* 4.0 (/ 1.0 y))) (* (/ x y) z))))))
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 + 4.0) / y) - ((x / y) * z)) <= -2.593780501472562e+48) {
		tmp = fabs((4.0 / y) + ((x / y) * (1.0 - z)));
	} else if ((((x + 4.0) / y) - ((x / y) * z)) <= 1.9132480395880643e+32) {
		tmp = fabs(((x + 4.0) / y) - (x * (z / y)));
	} else {
		tmp = fabs(((x / y) + (4.0 * (1.0 / y))) - ((x / y) * z));
	}
	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 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -2.59378050147256204e48

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

      \[\leadsto \left|\color{blue}{\left(\frac{4}{y} + \frac{x}{y}\right)} - \frac{x}{y} \cdot z\right|\]
    4. Using strategy rm
    5. Applied associate--l+_binary64_150.1

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

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

    if -2.59378050147256204e48 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 1.9132480395880643e32

    1. Initial program 3.3

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

      \[\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 1.9132480395880643e32 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))

    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(\frac{x}{y} + 4 \cdot \frac{1}{y}\right)} - \frac{x}{y} \cdot z\right|\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

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

Alternatives

Reproduce

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