Average Error: 1.6 → 0.1
Time: 4.7s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \frac{x}{y} \cdot z\\ t_1 := \frac{x + 4}{y} - t_0\\ t_2 := \left|t_0 + \frac{-4 - x}{y}\right|\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-28}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{-60}:\\ \;\;\;\;\left|\frac{\mathsf{fma}\left(x, 1 - z, 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 y) z))
        (t_1 (- (/ (+ x 4.0) y) t_0))
        (t_2 (fabs (+ t_0 (/ (- -4.0 x) y)))))
   (if (<= t_1 -5e-28)
     t_2
     (if (<= t_1 1e-60) (fabs (/ (fma x (- 1.0 z) 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 / y) * z;
	double t_1 = ((x + 4.0) / y) - t_0;
	double t_2 = fabs((t_0 + ((-4.0 - x) / y)));
	double tmp;
	if (t_1 <= -5e-28) {
		tmp = t_2;
	} else if (t_1 <= 1e-60) {
		tmp = fabs((fma(x, (1.0 - z), 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 / y) * z)
	t_1 = Float64(Float64(Float64(x + 4.0) / y) - t_0)
	t_2 = abs(Float64(t_0 + Float64(Float64(-4.0 - x) / y)))
	tmp = 0.0
	if (t_1 <= -5e-28)
		tmp = t_2;
	elseif (t_1 <= 1e-60)
		tmp = abs(Float64(fma(x, Float64(1.0 - z), 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 / y), $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[Abs[N[(t$95$0 + N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -5e-28], t$95$2, If[LessEqual[t$95$1, 1e-60], N[Abs[N[(N[(x * N[(1.0 - z), $MachinePrecision] + 4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], t$95$2]]]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \frac{x}{y} \cdot z\\
t_1 := \frac{x + 4}{y} - t_0\\
t_2 := \left|t_0 + \frac{-4 - x}{y}\right|\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{-28}:\\
\;\;\;\;t_2\\

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

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


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -5.0000000000000002e-28 or 9.9999999999999997e-61 < (-.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| \]

    if -5.0000000000000002e-28 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < 9.9999999999999997e-61

    1. Initial program 4.8

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

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

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

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

Reproduce

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