fabs fraction 1

Percentage Accurate: 92.0% → 99.8%
Time: 6.5s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
	return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end function
public static double code(double x, double y, double z) {
	return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z):
	return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z)
	return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z)))
end
function tmp = code(x, y, z)
	tmp = abs((((x + 4.0) / y) - ((x / y) * z)));
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]
\begin{array}{l}

\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 92.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
	return fabs((((x + 4.0) / y) - ((x / y) * z)));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end function
public static double code(double x, double y, double z) {
	return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z):
	return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z)
	return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z)))
end
function tmp = code(x, y, z)
	tmp = abs((((x + 4.0) / y) - ((x / y) * z)));
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]
\begin{array}{l}

\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}

Alternative 1: 99.8% accurate, 0.5× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 5 \cdot 10^{-36}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-4 - x}{y}\right)\right|\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= y 5e-36)
   (fabs (/ (- (+ x 4.0) (* x z)) y))
   (fabs (fma x (/ z y) (/ (- -4.0 x) y)))))
y = abs(y);
double code(double x, double y, double z) {
	double tmp;
	if (y <= 5e-36) {
		tmp = fabs((((x + 4.0) - (x * z)) / y));
	} else {
		tmp = fabs(fma(x, (z / y), ((-4.0 - x) / y)));
	}
	return tmp;
}
y = abs(y)
function code(x, y, z)
	tmp = 0.0
	if (y <= 5e-36)
		tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(x * z)) / y));
	else
		tmp = abs(fma(x, Float64(z / y), Float64(Float64(-4.0 - x) / y)));
	end
	return tmp
end
NOTE: y should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[y, 5e-36], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x * N[(z / y), $MachinePrecision] + N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{-36}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 5.00000000000000004e-36

    1. Initial program 91.9%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. associate-*l/91.4%

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
      2. sub-div98.4%

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

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

    if 5.00000000000000004e-36 < y

    1. Initial program 95.3%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. fabs-sub95.3%

        \[\leadsto \color{blue}{\left|\frac{x}{y} \cdot z - \frac{x + 4}{y}\right|} \]
      2. associate-*l/94.4%

        \[\leadsto \left|\color{blue}{\frac{x \cdot z}{y}} - \frac{x + 4}{y}\right| \]
      3. *-commutative94.4%

        \[\leadsto \left|\frac{\color{blue}{z \cdot x}}{y} - \frac{x + 4}{y}\right| \]
      4. associate-*l/99.8%

        \[\leadsto \left|\color{blue}{\frac{z}{y} \cdot x} - \frac{x + 4}{y}\right| \]
      5. *-commutative99.8%

        \[\leadsto \left|\color{blue}{x \cdot \frac{z}{y}} - \frac{x + 4}{y}\right| \]
      6. fma-neg99.8%

        \[\leadsto \left|\color{blue}{\mathsf{fma}\left(x, \frac{z}{y}, -\frac{x + 4}{y}\right)}\right| \]
      7. distribute-neg-frac99.8%

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

        \[\leadsto \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{-\color{blue}{\left(4 + x\right)}}{y}\right)\right| \]
      9. distribute-neg-in99.8%

        \[\leadsto \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{\left(-4\right) + \left(-x\right)}}{y}\right)\right| \]
      10. unsub-neg99.8%

        \[\leadsto \left|\mathsf{fma}\left(x, \frac{z}{y}, \frac{\color{blue}{\left(-4\right) - x}}{y}\right)\right| \]
      11. metadata-eval99.8%

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

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

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

Alternative 2: 83.3% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} t_0 := \left|z \cdot \frac{x}{y}\right|\\ t_1 := \left|\frac{-4 - x}{y}\right|\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{+167}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 105000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{+69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 10^{+122}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fabs (* z (/ x y)))) (t_1 (fabs (/ (- -4.0 x) y))))
   (if (<= z -1.1e+167)
     t_0
     (if (<= z 105000000000.0)
       t_1
       (if (<= z 5.4e+69) t_0 (if (<= z 1e+122) t_1 (fabs (* x (/ z y)))))))))
y = abs(y);
double code(double x, double y, double z) {
	double t_0 = fabs((z * (x / y)));
	double t_1 = fabs(((-4.0 - x) / y));
	double tmp;
	if (z <= -1.1e+167) {
		tmp = t_0;
	} else if (z <= 105000000000.0) {
		tmp = t_1;
	} else if (z <= 5.4e+69) {
		tmp = t_0;
	} else if (z <= 1e+122) {
		tmp = t_1;
	} else {
		tmp = fabs((x * (z / y)));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = abs((z * (x / y)))
    t_1 = abs((((-4.0d0) - x) / y))
    if (z <= (-1.1d+167)) then
        tmp = t_0
    else if (z <= 105000000000.0d0) then
        tmp = t_1
    else if (z <= 5.4d+69) then
        tmp = t_0
    else if (z <= 1d+122) then
        tmp = t_1
    else
        tmp = abs((x * (z / y)))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
	double t_0 = Math.abs((z * (x / y)));
	double t_1 = Math.abs(((-4.0 - x) / y));
	double tmp;
	if (z <= -1.1e+167) {
		tmp = t_0;
	} else if (z <= 105000000000.0) {
		tmp = t_1;
	} else if (z <= 5.4e+69) {
		tmp = t_0;
	} else if (z <= 1e+122) {
		tmp = t_1;
	} else {
		tmp = Math.abs((x * (z / y)));
	}
	return tmp;
}
y = abs(y)
def code(x, y, z):
	t_0 = math.fabs((z * (x / y)))
	t_1 = math.fabs(((-4.0 - x) / y))
	tmp = 0
	if z <= -1.1e+167:
		tmp = t_0
	elif z <= 105000000000.0:
		tmp = t_1
	elif z <= 5.4e+69:
		tmp = t_0
	elif z <= 1e+122:
		tmp = t_1
	else:
		tmp = math.fabs((x * (z / y)))
	return tmp
y = abs(y)
function code(x, y, z)
	t_0 = abs(Float64(z * Float64(x / y)))
	t_1 = abs(Float64(Float64(-4.0 - x) / y))
	tmp = 0.0
	if (z <= -1.1e+167)
		tmp = t_0;
	elseif (z <= 105000000000.0)
		tmp = t_1;
	elseif (z <= 5.4e+69)
		tmp = t_0;
	elseif (z <= 1e+122)
		tmp = t_1;
	else
		tmp = abs(Float64(x * Float64(z / y)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y, z)
	t_0 = abs((z * (x / y)));
	t_1 = abs(((-4.0 - x) / y));
	tmp = 0.0;
	if (z <= -1.1e+167)
		tmp = t_0;
	elseif (z <= 105000000000.0)
		tmp = t_1;
	elseif (z <= 5.4e+69)
		tmp = t_0;
	elseif (z <= 1e+122)
		tmp = t_1;
	else
		tmp = abs((x * (z / y)));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_, z_] := Block[{t$95$0 = N[Abs[N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[z, -1.1e+167], t$95$0, If[LessEqual[z, 105000000000.0], t$95$1, If[LessEqual[z, 5.4e+69], t$95$0, If[LessEqual[z, 1e+122], t$95$1, N[Abs[N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := \left|z \cdot \frac{x}{y}\right|\\
t_1 := \left|\frac{-4 - x}{y}\right|\\
\mathbf{if}\;z \leq -1.1 \cdot 10^{+167}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 105000000000:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 5.4 \cdot 10^{+69}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 10^{+122}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\left|x \cdot \frac{z}{y}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.10000000000000002e167 or 1.05e11 < z < 5.3999999999999996e69

    1. Initial program 95.9%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Simplified90.6%

      \[\leadsto \color{blue}{\left|\frac{1}{y} \cdot \mathsf{fma}\left(x, z, -4 - x\right)\right|} \]
    3. Taylor expanded in z around inf 76.5%

      \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}}\right| \]
    4. Step-by-step derivation
      1. add-sqr-sqrt46.1%

        \[\leadsto \left|\frac{z \cdot x}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}\right| \]
      2. sqrt-unprod66.9%

        \[\leadsto \left|\frac{z \cdot x}{\color{blue}{\sqrt{y \cdot y}}}\right| \]
      3. sqr-neg66.9%

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

        \[\leadsto \left|\frac{z \cdot x}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}\right| \]
      5. add-sqr-sqrt76.5%

        \[\leadsto \left|\frac{z \cdot x}{\color{blue}{-y}}\right| \]
      6. *-commutative76.5%

        \[\leadsto \left|\frac{\color{blue}{x \cdot z}}{-y}\right| \]
      7. associate-*l/84.0%

        \[\leadsto \left|\color{blue}{\frac{x}{-y} \cdot z}\right| \]
      8. clear-num83.0%

        \[\leadsto \left|\color{blue}{\frac{1}{\frac{-y}{x}}} \cdot z\right| \]
      9. clear-num84.0%

        \[\leadsto \left|\color{blue}{\frac{x}{-y}} \cdot z\right| \]
      10. add-sqr-sqrt32.3%

        \[\leadsto \left|\frac{x}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \cdot z\right| \]
      11. sqrt-unprod69.3%

        \[\leadsto \left|\frac{x}{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}} \cdot z\right| \]
      12. sqr-neg69.3%

        \[\leadsto \left|\frac{x}{\sqrt{\color{blue}{y \cdot y}}} \cdot z\right| \]
      13. sqrt-unprod51.6%

        \[\leadsto \left|\frac{x}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \cdot z\right| \]
      14. add-sqr-sqrt84.0%

        \[\leadsto \left|\frac{x}{\color{blue}{y}} \cdot z\right| \]
    5. Applied egg-rr84.0%

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot z}\right| \]

    if -1.10000000000000002e167 < z < 1.05e11 or 5.3999999999999996e69 < z < 1.00000000000000001e122

    1. Initial program 96.0%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Simplified98.7%

      \[\leadsto \color{blue}{\left|\frac{1}{y} \cdot \mathsf{fma}\left(x, z, -4 - x\right)\right|} \]
    3. Taylor expanded in z around 0 89.0%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{4 + x}{y}}\right| \]
    4. Step-by-step derivation
      1. associate-*r/89.0%

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(4 + x\right)}{y}}\right| \]
      2. distribute-lft-in89.0%

        \[\leadsto \left|\frac{\color{blue}{-1 \cdot 4 + -1 \cdot x}}{y}\right| \]
      3. metadata-eval89.0%

        \[\leadsto \left|\frac{\color{blue}{-4} + -1 \cdot x}{y}\right| \]
      4. neg-mul-189.0%

        \[\leadsto \left|\frac{-4 + \color{blue}{\left(-x\right)}}{y}\right| \]
      5. sub-neg89.0%

        \[\leadsto \left|\frac{\color{blue}{-4 - x}}{y}\right| \]
    5. Simplified89.0%

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

    if 1.00000000000000001e122 < z

    1. Initial program 74.2%

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

      \[\leadsto \color{blue}{\left|\frac{1}{y} \cdot \mathsf{fma}\left(x, z, -4 - x\right)\right|} \]
    3. Taylor expanded in z around inf 79.1%

      \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}}\right| \]
    4. Step-by-step derivation
      1. associate-*l/81.5%

        \[\leadsto \left|\color{blue}{\frac{z}{y} \cdot x}\right| \]
      2. *-commutative81.5%

        \[\leadsto \left|\color{blue}{x \cdot \frac{z}{y}}\right| \]
    5. Simplified81.5%

      \[\leadsto \left|\color{blue}{x \cdot \frac{z}{y}}\right| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification87.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{+167}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;z \leq 105000000000:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{+69}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;z \leq 10^{+122}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \end{array} \]

Alternative 3: 96.8% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -4.2 \cdot 10^{+67}:\\ \;\;\;\;\left|z \cdot \frac{x}{y} - \frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= z -4.2e+67)
   (fabs (- (* z (/ x y)) (/ (+ x 4.0) y)))
   (fabs (/ (- (+ x 4.0) (* x z)) y))))
y = abs(y);
double code(double x, double y, double z) {
	double tmp;
	if (z <= -4.2e+67) {
		tmp = fabs(((z * (x / y)) - ((x + 4.0) / y)));
	} else {
		tmp = fabs((((x + 4.0) - (x * z)) / y));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-4.2d+67)) then
        tmp = abs(((z * (x / y)) - ((x + 4.0d0) / y)))
    else
        tmp = abs((((x + 4.0d0) - (x * z)) / y))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -4.2e+67) {
		tmp = Math.abs(((z * (x / y)) - ((x + 4.0) / y)));
	} else {
		tmp = Math.abs((((x + 4.0) - (x * z)) / y));
	}
	return tmp;
}
y = abs(y)
def code(x, y, z):
	tmp = 0
	if z <= -4.2e+67:
		tmp = math.fabs(((z * (x / y)) - ((x + 4.0) / y)))
	else:
		tmp = math.fabs((((x + 4.0) - (x * z)) / y))
	return tmp
y = abs(y)
function code(x, y, z)
	tmp = 0.0
	if (z <= -4.2e+67)
		tmp = abs(Float64(Float64(z * Float64(x / y)) - Float64(Float64(x + 4.0) / y)));
	else
		tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(x * z)) / y));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -4.2e+67)
		tmp = abs(((z * (x / y)) - ((x + 4.0) / y)));
	else
		tmp = abs((((x + 4.0) - (x * z)) / y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[z, -4.2e+67], N[Abs[N[(N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+67}:\\
\;\;\;\;\left|z \cdot \frac{x}{y} - \frac{x + 4}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4.2000000000000003e67

    1. Initial program 98.8%

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

    if -4.2000000000000003e67 < z

    1. Initial program 91.2%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Step-by-step derivation
      1. associate-*l/92.5%

        \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
      2. sub-div99.0%

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

      \[\leadsto \left|\color{blue}{\frac{\left(x + 4\right) - x \cdot z}{y}}\right| \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.2 \cdot 10^{+67}:\\ \;\;\;\;\left|z \cdot \frac{x}{y} - \frac{x + 4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \]

Alternative 4: 86.4% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+15} \lor \neg \left(x \leq 5.9 \cdot 10^{-22}\right):\\ \;\;\;\;\left|\frac{z + -1}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -2.6e+15) (not (<= x 5.9e-22)))
   (fabs (/ (+ z -1.0) (/ y x)))
   (fabs (/ (- -4.0 x) y))))
y = abs(y);
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -2.6e+15) || !(x <= 5.9e-22)) {
		tmp = fabs(((z + -1.0) / (y / x)));
	} else {
		tmp = fabs(((-4.0 - x) / y));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-2.6d+15)) .or. (.not. (x <= 5.9d-22))) then
        tmp = abs(((z + (-1.0d0)) / (y / x)))
    else
        tmp = abs((((-4.0d0) - x) / y))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -2.6e+15) || !(x <= 5.9e-22)) {
		tmp = Math.abs(((z + -1.0) / (y / x)));
	} else {
		tmp = Math.abs(((-4.0 - x) / y));
	}
	return tmp;
}
y = abs(y)
def code(x, y, z):
	tmp = 0
	if (x <= -2.6e+15) or not (x <= 5.9e-22):
		tmp = math.fabs(((z + -1.0) / (y / x)))
	else:
		tmp = math.fabs(((-4.0 - x) / y))
	return tmp
y = abs(y)
function code(x, y, z)
	tmp = 0.0
	if ((x <= -2.6e+15) || !(x <= 5.9e-22))
		tmp = abs(Float64(Float64(z + -1.0) / Float64(y / x)));
	else
		tmp = abs(Float64(Float64(-4.0 - x) / y));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -2.6e+15) || ~((x <= 5.9e-22)))
		tmp = abs(((z + -1.0) / (y / x)));
	else
		tmp = abs(((-4.0 - x) / y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e+15], N[Not[LessEqual[x, 5.9e-22]], $MachinePrecision]], N[Abs[N[(N[(z + -1.0), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+15} \lor \neg \left(x \leq 5.9 \cdot 10^{-22}\right):\\
\;\;\;\;\left|\frac{z + -1}{\frac{y}{x}}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{-4 - x}{y}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.6e15 or 5.90000000000000008e-22 < x

    1. Initial program 88.5%

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

      \[\leadsto \color{blue}{\left|\frac{1}{y} \cdot \mathsf{fma}\left(x, z, -4 - x\right)\right|} \]
    3. Taylor expanded in x around inf 92.3%

      \[\leadsto \left|\color{blue}{\frac{\left(z - 1\right) \cdot x}{y}}\right| \]
    4. Step-by-step derivation
      1. associate-/l*97.5%

        \[\leadsto \left|\color{blue}{\frac{z - 1}{\frac{y}{x}}}\right| \]
      2. sub-neg97.5%

        \[\leadsto \left|\frac{\color{blue}{z + \left(-1\right)}}{\frac{y}{x}}\right| \]
      3. metadata-eval97.5%

        \[\leadsto \left|\frac{z + \color{blue}{-1}}{\frac{y}{x}}\right| \]
    5. Simplified97.5%

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

    if -2.6e15 < x < 5.90000000000000008e-22

    1. Initial program 96.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Simplified99.8%

      \[\leadsto \color{blue}{\left|\frac{1}{y} \cdot \mathsf{fma}\left(x, z, -4 - x\right)\right|} \]
    3. Taylor expanded in z around 0 77.4%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{4 + x}{y}}\right| \]
    4. Step-by-step derivation
      1. associate-*r/77.4%

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(4 + x\right)}{y}}\right| \]
      2. distribute-lft-in77.4%

        \[\leadsto \left|\frac{\color{blue}{-1 \cdot 4 + -1 \cdot x}}{y}\right| \]
      3. metadata-eval77.4%

        \[\leadsto \left|\frac{\color{blue}{-4} + -1 \cdot x}{y}\right| \]
      4. neg-mul-177.4%

        \[\leadsto \left|\frac{-4 + \color{blue}{\left(-x\right)}}{y}\right| \]
      5. sub-neg77.4%

        \[\leadsto \left|\frac{\color{blue}{-4 - x}}{y}\right| \]
    5. Simplified77.4%

      \[\leadsto \left|\color{blue}{\frac{-4 - x}{y}}\right| \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+15} \lor \neg \left(x \leq 5.9 \cdot 10^{-22}\right):\\ \;\;\;\;\left|\frac{z + -1}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \end{array} \]

Alternative 5: 96.1% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \left|\frac{\left(x + 4\right) - x \cdot z}{y}\right| \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z) :precision binary64 (fabs (/ (- (+ x 4.0) (* x z)) y)))
y = abs(y);
double code(double x, double y, double z) {
	return fabs((((x + 4.0) - (x * z)) / y));
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = abs((((x + 4.0d0) - (x * z)) / y))
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
	return Math.abs((((x + 4.0) - (x * z)) / y));
}
y = abs(y)
def code(x, y, z):
	return math.fabs((((x + 4.0) - (x * z)) / y))
y = abs(y)
function code(x, y, z)
	return abs(Float64(Float64(Float64(x + 4.0) - Float64(x * z)) / y))
end
y = abs(y)
function tmp = code(x, y, z)
	tmp = abs((((x + 4.0) - (x * z)) / y));
end
NOTE: y should be positive before calling this function
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|
\end{array}
Derivation
  1. Initial program 92.8%

    \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
  2. Step-by-step derivation
    1. associate-*l/92.2%

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right| \]
    2. sub-div97.3%

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

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

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

Alternative 6: 68.4% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1.55 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -1.55) (not (<= x 4.0))) (fabs (/ x y)) (fabs (/ 4.0 y))))
y = abs(y);
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.55) || !(x <= 4.0)) {
		tmp = fabs((x / y));
	} else {
		tmp = fabs((4.0 / y));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-1.55d0)) .or. (.not. (x <= 4.0d0))) then
        tmp = abs((x / y))
    else
        tmp = abs((4.0d0 / y))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.55) || !(x <= 4.0)) {
		tmp = Math.abs((x / y));
	} else {
		tmp = Math.abs((4.0 / y));
	}
	return tmp;
}
y = abs(y)
def code(x, y, z):
	tmp = 0
	if (x <= -1.55) or not (x <= 4.0):
		tmp = math.fabs((x / y))
	else:
		tmp = math.fabs((4.0 / y))
	return tmp
y = abs(y)
function code(x, y, z)
	tmp = 0.0
	if ((x <= -1.55) || !(x <= 4.0))
		tmp = abs(Float64(x / y));
	else
		tmp = abs(Float64(4.0 / y));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -1.55) || ~((x <= 4.0)))
		tmp = abs((x / y));
	else
		tmp = abs((4.0 / y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55], N[Not[LessEqual[x, 4.0]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \lor \neg \left(x \leq 4\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{4}{y}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.55000000000000004 or 4 < x

    1. Initial program 88.7%

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

      \[\leadsto \color{blue}{\left|\frac{1}{y} \cdot \mathsf{fma}\left(x, z, -4 - x\right)\right|} \]
    3. Taylor expanded in x around inf 91.5%

      \[\leadsto \left|\color{blue}{\frac{\left(z - 1\right) \cdot x}{y}}\right| \]
    4. Step-by-step derivation
      1. associate-/l*96.6%

        \[\leadsto \left|\color{blue}{\frac{z - 1}{\frac{y}{x}}}\right| \]
      2. sub-neg96.6%

        \[\leadsto \left|\frac{\color{blue}{z + \left(-1\right)}}{\frac{y}{x}}\right| \]
      3. metadata-eval96.6%

        \[\leadsto \left|\frac{z + \color{blue}{-1}}{\frac{y}{x}}\right| \]
    5. Simplified96.6%

      \[\leadsto \left|\color{blue}{\frac{z + -1}{\frac{y}{x}}}\right| \]
    6. Taylor expanded in z around 0 65.3%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x}{y}}\right| \]
    7. Step-by-step derivation
      1. associate-*r/65.3%

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot x}{y}}\right| \]
      2. neg-mul-165.3%

        \[\leadsto \left|\frac{\color{blue}{-x}}{y}\right| \]
    8. Simplified65.3%

      \[\leadsto \left|\color{blue}{\frac{-x}{y}}\right| \]

    if -1.55000000000000004 < x < 4

    1. Initial program 96.8%

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

      \[\leadsto \left|\color{blue}{\frac{4}{y}}\right| \]
  3. Recombined 2 regimes into one program.
  4. Final simplification69.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.55 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \]

Alternative 7: 67.7% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+15}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= x -2.6e+15)
   (fabs (* z (/ x y)))
   (if (<= x 4.0) (fabs (/ 4.0 y)) (fabs (/ x y)))))
y = abs(y);
double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.6e+15) {
		tmp = fabs((z * (x / y)));
	} else if (x <= 4.0) {
		tmp = fabs((4.0 / y));
	} else {
		tmp = fabs((x / y));
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-2.6d+15)) then
        tmp = abs((z * (x / y)))
    else if (x <= 4.0d0) then
        tmp = abs((4.0d0 / y))
    else
        tmp = abs((x / y))
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.6e+15) {
		tmp = Math.abs((z * (x / y)));
	} else if (x <= 4.0) {
		tmp = Math.abs((4.0 / y));
	} else {
		tmp = Math.abs((x / y));
	}
	return tmp;
}
y = abs(y)
def code(x, y, z):
	tmp = 0
	if x <= -2.6e+15:
		tmp = math.fabs((z * (x / y)))
	elif x <= 4.0:
		tmp = math.fabs((4.0 / y))
	else:
		tmp = math.fabs((x / y))
	return tmp
y = abs(y)
function code(x, y, z)
	tmp = 0.0
	if (x <= -2.6e+15)
		tmp = abs(Float64(z * Float64(x / y)));
	elseif (x <= 4.0)
		tmp = abs(Float64(4.0 / y));
	else
		tmp = abs(Float64(x / y));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -2.6e+15)
		tmp = abs((z * (x / y)));
	elseif (x <= 4.0)
		tmp = abs((4.0 / y));
	else
		tmp = abs((x / y));
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[x, -2.6e+15], N[Abs[N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 4.0], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+15}:\\
\;\;\;\;\left|z \cdot \frac{x}{y}\right|\\

\mathbf{elif}\;x \leq 4:\\
\;\;\;\;\left|\frac{4}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.6e15

    1. Initial program 90.5%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Simplified93.8%

      \[\leadsto \color{blue}{\left|\frac{1}{y} \cdot \mathsf{fma}\left(x, z, -4 - x\right)\right|} \]
    3. Taylor expanded in z around inf 55.3%

      \[\leadsto \left|\color{blue}{\frac{z \cdot x}{y}}\right| \]
    4. Step-by-step derivation
      1. add-sqr-sqrt29.2%

        \[\leadsto \left|\frac{z \cdot x}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}\right| \]
      2. sqrt-unprod54.9%

        \[\leadsto \left|\frac{z \cdot x}{\color{blue}{\sqrt{y \cdot y}}}\right| \]
      3. sqr-neg54.9%

        \[\leadsto \left|\frac{z \cdot x}{\sqrt{\color{blue}{\left(-y\right) \cdot \left(-y\right)}}}\right| \]
      4. sqrt-unprod25.9%

        \[\leadsto \left|\frac{z \cdot x}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}\right| \]
      5. add-sqr-sqrt55.3%

        \[\leadsto \left|\frac{z \cdot x}{\color{blue}{-y}}\right| \]
      6. *-commutative55.3%

        \[\leadsto \left|\frac{\color{blue}{x \cdot z}}{-y}\right| \]
      7. associate-*l/70.0%

        \[\leadsto \left|\color{blue}{\frac{x}{-y} \cdot z}\right| \]
      8. clear-num70.0%

        \[\leadsto \left|\color{blue}{\frac{1}{\frac{-y}{x}}} \cdot z\right| \]
      9. clear-num70.0%

        \[\leadsto \left|\color{blue}{\frac{x}{-y}} \cdot z\right| \]
      10. add-sqr-sqrt31.8%

        \[\leadsto \left|\frac{x}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \cdot z\right| \]
      11. sqrt-unprod59.4%

        \[\leadsto \left|\frac{x}{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}} \cdot z\right| \]
      12. sqr-neg59.4%

        \[\leadsto \left|\frac{x}{\sqrt{\color{blue}{y \cdot y}}} \cdot z\right| \]
      13. sqrt-unprod38.0%

        \[\leadsto \left|\frac{x}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \cdot z\right| \]
      14. add-sqr-sqrt70.0%

        \[\leadsto \left|\frac{x}{\color{blue}{y}} \cdot z\right| \]
    5. Applied egg-rr70.0%

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot z}\right| \]

    if -2.6e15 < x < 4

    1. Initial program 96.9%

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

      \[\leadsto \left|\color{blue}{\frac{4}{y}}\right| \]

    if 4 < x

    1. Initial program 85.0%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Simplified94.5%

      \[\leadsto \color{blue}{\left|\frac{1}{y} \cdot \mathsf{fma}\left(x, z, -4 - x\right)\right|} \]
    3. Taylor expanded in x around inf 93.0%

      \[\leadsto \left|\color{blue}{\frac{\left(z - 1\right) \cdot x}{y}}\right| \]
    4. Step-by-step derivation
      1. associate-/l*98.0%

        \[\leadsto \left|\color{blue}{\frac{z - 1}{\frac{y}{x}}}\right| \]
      2. sub-neg98.0%

        \[\leadsto \left|\frac{\color{blue}{z + \left(-1\right)}}{\frac{y}{x}}\right| \]
      3. metadata-eval98.0%

        \[\leadsto \left|\frac{z + \color{blue}{-1}}{\frac{y}{x}}\right| \]
    5. Simplified98.0%

      \[\leadsto \left|\color{blue}{\frac{z + -1}{\frac{y}{x}}}\right| \]
    6. Taylor expanded in z around 0 66.8%

      \[\leadsto \left|\color{blue}{-1 \cdot \frac{x}{y}}\right| \]
    7. Step-by-step derivation
      1. associate-*r/66.8%

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot x}{y}}\right| \]
      2. neg-mul-166.8%

        \[\leadsto \left|\frac{\color{blue}{-x}}{y}\right| \]
    8. Simplified66.8%

      \[\leadsto \left|\color{blue}{\frac{-x}{y}}\right| \]
  3. Recombined 3 regimes into one program.
  4. Final simplification69.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+15}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \end{array} \]

Alternative 8: 39.8% accurate, 1.1× speedup?

\[\begin{array}{l} y = |y|\\ \\ \left|\frac{4}{y}\right| \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z) :precision binary64 (fabs (/ 4.0 y)))
y = abs(y);
double code(double x, double y, double z) {
	return fabs((4.0 / y));
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = abs((4.0d0 / y))
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
	return Math.abs((4.0 / y));
}
y = abs(y)
def code(x, y, z):
	return math.fabs((4.0 / y))
y = abs(y)
function code(x, y, z)
	return abs(Float64(4.0 / y))
end
y = abs(y)
function tmp = code(x, y, z)
	tmp = abs((4.0 / y));
end
NOTE: y should be positive before calling this function
code[x_, y_, z_] := N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\left|\frac{4}{y}\right|
\end{array}
Derivation
  1. Initial program 92.8%

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

    \[\leadsto \left|\color{blue}{\frac{4}{y}}\right| \]
  3. Final simplification40.7%

    \[\leadsto \left|\frac{4}{y}\right| \]

Reproduce

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