Average Error: 1.7 → 0.1
Time: 4.6s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} t_0 := \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\ \mathbf{if}\;x \leq -0.013284199379893075:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.07597955292762652:\\ \;\;\;\;\left|\frac{\mathsf{fma}\left(x, z, -4\right) - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z)))))
   (if (<= x -0.013284199379893075)
     t_0
     (if (<= x 0.07597955292762652) (fabs (/ (- (fma x z -4.0) x) y)) t_0))))
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 = fabs((((x + 4.0) / y) - ((x / y) * z)));
	double tmp;
	if (x <= -0.013284199379893075) {
		tmp = t_0;
	} else if (x <= 0.07597955292762652) {
		tmp = fabs(((fma(x, z, -4.0) - x) / y));
	} else {
		tmp = t_0;
	}
	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 = abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z)))
	tmp = 0.0
	if (x <= -0.013284199379893075)
		tmp = t_0;
	elseif (x <= 0.07597955292762652)
		tmp = abs(Float64(Float64(fma(x, z, -4.0) - x) / y));
	else
		tmp = t_0;
	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[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -0.013284199379893075], t$95$0, If[LessEqual[x, 0.07597955292762652], N[Abs[N[(N[(N[(x * z + -4.0), $MachinePrecision] - x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
t_0 := \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\\
\mathbf{if}\;x \leq -0.013284199379893075:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 0.07597955292762652:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(x, z, -4\right) - x}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Derivation

  1. Split input into 2 regimes
  2. if x < -0.013284199379893075 or 0.075979552927626523 < x

    1. Initial program 0.1

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

    if -0.013284199379893075 < x < 0.075979552927626523

    1. Initial program 2.8

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

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

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

Reproduce

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