Average Error: 1.7 → 0.3
Time: 4.4s
Precision: binary64
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
\[\begin{array}{l} \mathbf{if}\;x \leq -5.829815448466412 \cdot 10^{+32}:\\ \;\;\;\;\left|\frac{x + 4}{y} - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq 3.883658016843068 \cdot 10^{+67}:\\ \;\;\;\;\left|\frac{x - \mathsf{fma}\left(x, z, -4\right)}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y} - {\left(\frac{\frac{y}{x}}{z}\right)}^{-1}\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 -5.829815448466412e+32)
   (fabs (- (/ (+ x 4.0) y) (/ z (/ y x))))
   (if (<= x 3.883658016843068e+67)
     (fabs (/ (- x (fma x z -4.0)) y))
     (fabs (- (/ x y) (pow (/ (/ y x) z) -1.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 tmp;
	if (x <= -5.829815448466412e+32) {
		tmp = fabs((((x + 4.0) / y) - (z / (y / x))));
	} else if (x <= 3.883658016843068e+67) {
		tmp = fabs(((x - fma(x, z, -4.0)) / y));
	} else {
		tmp = fabs(((x / y) - pow(((y / x) / z), -1.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)
	tmp = 0.0
	if (x <= -5.829815448466412e+32)
		tmp = abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(z / Float64(y / x))));
	elseif (x <= 3.883658016843068e+67)
		tmp = abs(Float64(Float64(x - fma(x, z, -4.0)) / y));
	else
		tmp = abs(Float64(Float64(x / y) - (Float64(Float64(y / x) / z) ^ -1.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_] := If[LessEqual[x, -5.829815448466412e+32], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 3.883658016843068e+67], N[Abs[N[(N[(x - N[(x * z + -4.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(x / y), $MachinePrecision] - N[Power[N[(N[(y / x), $MachinePrecision] / z), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\begin{array}{l}
\mathbf{if}\;x \leq -5.829815448466412 \cdot 10^{+32}:\\
\;\;\;\;\left|\frac{x + 4}{y} - \frac{z}{\frac{y}{x}}\right|\\

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

\mathbf{else}:\\
\;\;\;\;\left|\frac{x}{y} - {\left(\frac{\frac{y}{x}}{z}\right)}^{-1}\right|\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Derivation

  1. Split input into 3 regimes
  2. if x < -5.8298154484664119e32

    1. Initial program 0.1

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

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

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

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

    if -5.8298154484664119e32 < x < 3.8836580168430678e67

    1. Initial program 2.4

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

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

    if 3.8836580168430678e67 < x

    1. Initial program 0.1

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

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
    3. Applied egg-rr0.2

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{{\left(\frac{\frac{y}{x}}{z}\right)}^{-1}}\right| \]
    4. Taylor expanded in x around inf 0.2

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

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

Reproduce

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