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

\mathbf{else}:\\
\;\;\;\;\left|\mathsf{fma}\left(1, t_0, t_1\right) + \mathsf{fma}\left(z, \frac{-x}{y}, \frac{x}{y} \cdot \left(-z\right)\right)\right|\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Derivation

  1. Split input into 2 regimes
  2. if (fabs.f64 (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))) < 30568797.64318812

    1. Initial program 3.6

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

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
    3. Taylor expanded in x around 0 0.1

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

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

    if 30568797.64318812 < (fabs.f64 (-.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. Applied egg-rr0.2

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

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

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

Reproduce

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