Average Error: 1.7 → 1.0
Time: 3.7s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \frac{x + 4}{y}\\ t_1 := t_0 - \frac{x}{y} \cdot z\\ t_2 := \left|\mathsf{fma}\left(\frac{x}{y}, -z, t_0\right)\right|\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+160}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{-240}:\\ \;\;\;\;\left|\frac{x}{y} + \frac{\mathsf{fma}\left(-z, x, 4\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (+ x 4.0) y))
        (t_1 (- t_0 (* (/ x y) z)))
        (t_2 (fabs (fma (/ x y) (- z) t_0))))
   (if (<= t_1 -2e+160)
     t_2
     (if (<= t_1 1e-240) (fabs (+ (/ x y) (/ (fma (- z) x 4.0) y))) t_2))))
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 t_0 = (x + 4.0) / y;
	double t_1 = t_0 - ((x / y) * z);
	double t_2 = fabs(fma((x / y), -z, t_0));
	double tmp;
	if (t_1 <= -2e+160) {
		tmp = t_2;
	} else if (t_1 <= 1e-240) {
		tmp = fabs(((x / y) + (fma(-z, x, 4.0) / y)));
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(x, y, z)
	return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z)))
end
function code(x, y, z)
	t_0 = Float64(Float64(x + 4.0) / y)
	t_1 = Float64(t_0 - Float64(Float64(x / y) * z))
	t_2 = abs(fma(Float64(x / y), Float64(-z), t_0))
	tmp = 0.0
	if (t_1 <= -2e+160)
		tmp = t_2;
	elseif (t_1 <= 1e-240)
		tmp = abs(Float64(Float64(x / y) + Float64(fma(Float64(-z), x, 4.0) / y)));
	else
		tmp = t_2;
	end
	return tmp
end
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Abs[N[(N[(x / y), $MachinePrecision] * (-z) + t$95$0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -2e+160], t$95$2, If[LessEqual[t$95$1, 1e-240], N[Abs[N[(N[(x / y), $MachinePrecision] + N[(N[((-z) * x + 4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$2]]]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \frac{x + 4}{y}\\
t_1 := t_0 - \frac{x}{y} \cdot z\\
t_2 := \left|\mathsf{fma}\left(\frac{x}{y}, -z, t_0\right)\right|\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+160}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 10^{-240}:\\
\;\;\;\;\left|\frac{x}{y} + \frac{\mathsf{fma}\left(-z, x, 4\right)}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -2.00000000000000001e160 or 9.9999999999999997e-241 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))

    1. Initial program 0.7

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Applied egg-rr0.7

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

    if -2.00000000000000001e160 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 9.9999999999999997e-241

    1. Initial program 3.2

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

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

      \[\leadsto \left|\color{blue}{\frac{x}{y} + \frac{4 - z \cdot x}{y}}\right| \]
    4. Applied egg-rr1.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + 4}{y} - \frac{x}{y} \cdot z \leq -2 \cdot 10^{+160}:\\ \;\;\;\;\left|\mathsf{fma}\left(\frac{x}{y}, -z, \frac{x + 4}{y}\right)\right|\\ \mathbf{elif}\;\frac{x + 4}{y} - \frac{x}{y} \cdot z \leq 10^{-240}:\\ \;\;\;\;\left|\frac{x}{y} + \frac{\mathsf{fma}\left(-z, x, 4\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\mathsf{fma}\left(\frac{x}{y}, -z, \frac{x + 4}{y}\right)\right|\\ \end{array} \]

Reproduce

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