fabs fraction 1

Percentage Accurate: 91.9% → 99.8%
Time: 6.0s
Alternatives: 9
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 9 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: 91.9% 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, 1.0× speedup?

\[\begin{array}{l} \\ \left|\frac{1 - \frac{x}{\frac{x + 4}{z}}}{\frac{y}{x + 4}}\right| \end{array} \]
(FPCore (x y z)
 :precision binary64
 (fabs (/ (- 1.0 (/ x (/ (+ x 4.0) z))) (/ y (+ x 4.0)))))
double code(double x, double y, double z) {
	return fabs(((1.0 - (x / ((x + 4.0) / z))) / (y / (x + 4.0))));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = abs(((1.0d0 - (x / ((x + 4.0d0) / z))) / (y / (x + 4.0d0))))
end function
public static double code(double x, double y, double z) {
	return Math.abs(((1.0 - (x / ((x + 4.0) / z))) / (y / (x + 4.0))));
}
def code(x, y, z):
	return math.fabs(((1.0 - (x / ((x + 4.0) / z))) / (y / (x + 4.0))))
function code(x, y, z)
	return abs(Float64(Float64(1.0 - Float64(x / Float64(Float64(x + 4.0) / z))) / Float64(y / Float64(x + 4.0))))
end
function tmp = code(x, y, z)
	tmp = abs(((1.0 - (x / ((x + 4.0) / z))) / (y / (x + 4.0))));
end
code[x_, y_, z_] := N[Abs[N[(N[(1.0 - N[(x / N[(N[(x + 4.0), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y / N[(x + 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\left|\frac{1 - \frac{x}{\frac{x + 4}{z}}}{\frac{y}{x + 4}}\right|
\end{array}
Derivation
  1. Initial program 91.6%

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

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

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

      \[\leadsto \left|\color{blue}{\frac{1 \cdot y - \frac{y}{x + 4} \cdot \left(x \cdot z\right)}{\frac{y}{x + 4} \cdot y}}\right| \]
    4. *-un-lft-identity61.1%

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

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

      \[\leadsto \left|\frac{y - \frac{y}{x + 4} \cdot \left(x \cdot z\right)}{\color{blue}{\frac{y \cdot y}{x + 4}}}\right| \]
    2. associate-/r/59.9%

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

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

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

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

    \[\leadsto \left|\color{blue}{\frac{y - z \cdot \left(x \cdot \frac{y}{x + 4}\right)}{y \cdot y} \cdot \left(x + 4\right)}\right| \]
  6. Taylor expanded in y around 0 96.9%

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

      \[\leadsto \left|\color{blue}{\frac{1 - \frac{z \cdot x}{4 + x}}{\frac{y}{4 + x}}}\right| \]
    2. *-commutative96.9%

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

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

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

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

    \[\leadsto \left|\color{blue}{\frac{1 - \frac{x}{\frac{4 + x}{z}}}{\frac{y}{4 + x}}}\right| \]
  9. Final simplification99.8%

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

Alternative 2: 85.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -125000000:\\ \;\;\;\;\left|\frac{x}{y}\right| \cdot \left|z\right|\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+108}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -125000000.0)
   (* (fabs (/ x y)) (fabs z))
   (if (<= z 7e+108) (fabs (/ (- -4.0 x) y)) (fabs (* x (/ z y))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -125000000.0) {
		tmp = fabs((x / y)) * fabs(z);
	} else if (z <= 7e+108) {
		tmp = fabs(((-4.0 - x) / y));
	} else {
		tmp = fabs((x * (z / y)));
	}
	return tmp;
}
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 <= (-125000000.0d0)) then
        tmp = abs((x / y)) * abs(z)
    else if (z <= 7d+108) then
        tmp = abs((((-4.0d0) - x) / y))
    else
        tmp = abs((x * (z / y)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -125000000.0) {
		tmp = Math.abs((x / y)) * Math.abs(z);
	} else if (z <= 7e+108) {
		tmp = Math.abs(((-4.0 - x) / y));
	} else {
		tmp = Math.abs((x * (z / y)));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -125000000.0:
		tmp = math.fabs((x / y)) * math.fabs(z)
	elif z <= 7e+108:
		tmp = math.fabs(((-4.0 - x) / y))
	else:
		tmp = math.fabs((x * (z / y)))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -125000000.0)
		tmp = Float64(abs(Float64(x / y)) * abs(z));
	elseif (z <= 7e+108)
		tmp = abs(Float64(Float64(-4.0 - x) / y));
	else
		tmp = abs(Float64(x * Float64(z / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -125000000.0)
		tmp = abs((x / y)) * abs(z);
	elseif (z <= 7e+108)
		tmp = abs(((-4.0 - x) / y));
	else
		tmp = abs((x * (z / y)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -125000000.0], N[(N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision] * N[Abs[z], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 7e+108], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -125000000:\\
\;\;\;\;\left|\frac{x}{y}\right| \cdot \left|z\right|\\

\mathbf{elif}\;z \leq 7 \cdot 10^{+108}:\\
\;\;\;\;\left|\frac{-4 - x}{y}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.25e8

    1. Initial program 98.3%

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

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

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(z \cdot x\right)}{y}}\right| \]
      2. mul-1-neg68.8%

        \[\leadsto \left|\frac{\color{blue}{-z \cdot x}}{y}\right| \]
      3. distribute-rgt-neg-out68.8%

        \[\leadsto \left|\frac{\color{blue}{z \cdot \left(-x\right)}}{y}\right| \]
      4. associate-*r/76.1%

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

        \[\leadsto \left|z \cdot \color{blue}{\left(-\frac{x}{y}\right)}\right| \]
      6. mul-1-neg76.1%

        \[\leadsto \left|z \cdot \color{blue}{\left(-1 \cdot \frac{x}{y}\right)}\right| \]
      7. metadata-eval76.1%

        \[\leadsto \left|z \cdot \left(\color{blue}{\frac{1}{-1}} \cdot \frac{x}{y}\right)\right| \]
      8. times-frac76.1%

        \[\leadsto \left|z \cdot \color{blue}{\frac{1 \cdot x}{-1 \cdot y}}\right| \]
      9. *-lft-identity76.1%

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

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

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

    if -1.25e8 < z < 7.0000000000000005e108

    1. Initial program 94.1%

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

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

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

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

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

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

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

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

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

    if 7.0000000000000005e108 < z

    1. Initial program 73.7%

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

      \[\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.9%

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

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

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

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

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

Alternative 3: 87.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -350 \lor \neg \left(x \leq 1.1 \cdot 10^{-10}\right):\\ \;\;\;\;\left|\frac{z + -1}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -350.0) (not (<= x 1.1e-10)))
   (fabs (/ (+ z -1.0) (/ y x)))
   (fabs (/ (- -4.0 x) y))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -350.0) || !(x <= 1.1e-10)) {
		tmp = fabs(((z + -1.0) / (y / x)));
	} else {
		tmp = fabs(((-4.0 - x) / y));
	}
	return tmp;
}
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 <= (-350.0d0)) .or. (.not. (x <= 1.1d-10))) then
        tmp = abs(((z + (-1.0d0)) / (y / x)))
    else
        tmp = abs((((-4.0d0) - x) / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -350.0) || !(x <= 1.1e-10)) {
		tmp = Math.abs(((z + -1.0) / (y / x)));
	} else {
		tmp = Math.abs(((-4.0 - x) / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -350.0) or not (x <= 1.1e-10):
		tmp = math.fabs(((z + -1.0) / (y / x)))
	else:
		tmp = math.fabs(((-4.0 - x) / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -350.0) || !(x <= 1.1e-10))
		tmp = abs(Float64(Float64(z + -1.0) / Float64(y / x)));
	else
		tmp = abs(Float64(Float64(-4.0 - x) / y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -350.0) || ~((x <= 1.1e-10)))
		tmp = abs(((z + -1.0) / (y / x)));
	else
		tmp = abs(((-4.0 - x) / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -350.0], N[Not[LessEqual[x, 1.1e-10]], $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}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -350 \lor \neg \left(x \leq 1.1 \cdot 10^{-10}\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 < -350 or 1.09999999999999995e-10 < x

    1. Initial program 87.6%

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

      \[\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.5%

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

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

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

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

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

    if -350 < x < 1.09999999999999995e-10

    1. Initial program 95.9%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 97.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{+56}:\\ \;\;\;\;\left|\frac{z + -1}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(x + 4\right) - x \cdot z}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -6e+56)
   (fabs (/ (+ z -1.0) (/ y x)))
   (fabs (/ (- (+ x 4.0) (* x z)) y))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -6e+56) {
		tmp = fabs(((z + -1.0) / (y / x)));
	} else {
		tmp = fabs((((x + 4.0) - (x * z)) / y));
	}
	return tmp;
}
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 <= (-6d+56)) then
        tmp = abs(((z + (-1.0d0)) / (y / x)))
    else
        tmp = abs((((x + 4.0d0) - (x * z)) / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -6e+56) {
		tmp = Math.abs(((z + -1.0) / (y / x)));
	} else {
		tmp = Math.abs((((x + 4.0) - (x * z)) / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -6e+56:
		tmp = math.fabs(((z + -1.0) / (y / x)))
	else:
		tmp = math.fabs((((x + 4.0) - (x * z)) / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -6e+56)
		tmp = abs(Float64(Float64(z + -1.0) / Float64(y / x)));
	else
		tmp = abs(Float64(Float64(Float64(x + 4.0) - Float64(x * z)) / y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -6e+56)
		tmp = abs(((z + -1.0) / (y / x)));
	else
		tmp = abs((((x + 4.0) - (x * z)) / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -6e+56], N[Abs[N[(N[(z + -1.0), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{+56}:\\
\;\;\;\;\left|\frac{z + -1}{\frac{y}{x}}\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 x < -6.00000000000000012e56

    1. Initial program 87.3%

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

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

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

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

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

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

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

    if -6.00000000000000012e56 < x

    1. Initial program 92.9%

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

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

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

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

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

Alternative 5: 66.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7.4 \cdot 10^{+56}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq -1.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -7.4e+56)
   (fabs (* x (/ z y)))
   (if (or (<= x -1.5) (not (<= x 4.0))) (fabs (/ x y)) (fabs (/ 4.0 y)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -7.4e+56) {
		tmp = fabs((x * (z / y)));
	} else if ((x <= -1.5) || !(x <= 4.0)) {
		tmp = fabs((x / y));
	} else {
		tmp = fabs((4.0 / y));
	}
	return tmp;
}
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 <= (-7.4d+56)) then
        tmp = abs((x * (z / y)))
    else if ((x <= (-1.5d0)) .or. (.not. (x <= 4.0d0))) then
        tmp = abs((x / y))
    else
        tmp = abs((4.0d0 / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -7.4e+56) {
		tmp = Math.abs((x * (z / y)));
	} else if ((x <= -1.5) || !(x <= 4.0)) {
		tmp = Math.abs((x / y));
	} else {
		tmp = Math.abs((4.0 / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -7.4e+56:
		tmp = math.fabs((x * (z / y)))
	elif (x <= -1.5) or not (x <= 4.0):
		tmp = math.fabs((x / y))
	else:
		tmp = math.fabs((4.0 / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -7.4e+56)
		tmp = abs(Float64(x * Float64(z / y)));
	elseif ((x <= -1.5) || !(x <= 4.0))
		tmp = abs(Float64(x / y));
	else
		tmp = abs(Float64(4.0 / y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -7.4e+56)
		tmp = abs((x * (z / y)));
	elseif ((x <= -1.5) || ~((x <= 4.0)))
		tmp = abs((x / y));
	else
		tmp = abs((4.0 / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -7.4e+56], N[Abs[N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, -1.5], 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}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.4 \cdot 10^{+56}:\\
\;\;\;\;\left|x \cdot \frac{z}{y}\right|\\

\mathbf{elif}\;x \leq -1.5 \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 3 regimes
  2. if x < -7.39999999999999994e56

    1. Initial program 87.3%

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

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

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

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

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

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

    if -7.39999999999999994e56 < x < -1.5 or 4 < x

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

    if -1.5 < x < 4

    1. Initial program 95.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.4 \cdot 10^{+56}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq -1.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \]

Alternative 6: 67.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+43}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq -1.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.8e+43)
   (fabs (/ z (/ y x)))
   (if (or (<= x -1.5) (not (<= x 4.0))) (fabs (/ x y)) (fabs (/ 4.0 y)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.8e+43) {
		tmp = fabs((z / (y / x)));
	} else if ((x <= -1.5) || !(x <= 4.0)) {
		tmp = fabs((x / y));
	} else {
		tmp = fabs((4.0 / y));
	}
	return tmp;
}
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.8d+43)) then
        tmp = abs((z / (y / x)))
    else if ((x <= (-1.5d0)) .or. (.not. (x <= 4.0d0))) then
        tmp = abs((x / y))
    else
        tmp = abs((4.0d0 / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.8e+43) {
		tmp = Math.abs((z / (y / x)));
	} else if ((x <= -1.5) || !(x <= 4.0)) {
		tmp = Math.abs((x / y));
	} else {
		tmp = Math.abs((4.0 / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.8e+43:
		tmp = math.fabs((z / (y / x)))
	elif (x <= -1.5) or not (x <= 4.0):
		tmp = math.fabs((x / y))
	else:
		tmp = math.fabs((4.0 / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.8e+43)
		tmp = abs(Float64(z / Float64(y / x)));
	elseif ((x <= -1.5) || !(x <= 4.0))
		tmp = abs(Float64(x / y));
	else
		tmp = abs(Float64(4.0 / y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1.8e+43)
		tmp = abs((z / (y / x)));
	elseif ((x <= -1.5) || ~((x <= 4.0)))
		tmp = abs((x / y));
	else
		tmp = abs((4.0 / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.8e+43], N[Abs[N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, -1.5], 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}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+43}:\\
\;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\

\mathbf{elif}\;x \leq -1.5 \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 3 regimes
  2. if x < -1.80000000000000005e43

    1. Initial program 88.1%

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

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

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(z \cdot x\right)}{y}}\right| \]
      2. mul-1-neg56.1%

        \[\leadsto \left|\frac{\color{blue}{-z \cdot x}}{y}\right| \]
      3. distribute-rgt-neg-out56.1%

        \[\leadsto \left|\frac{\color{blue}{z \cdot \left(-x\right)}}{y}\right| \]
      4. associate-*r/73.2%

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

        \[\leadsto \left|z \cdot \color{blue}{\left(-\frac{x}{y}\right)}\right| \]
      6. mul-1-neg73.2%

        \[\leadsto \left|z \cdot \color{blue}{\left(-1 \cdot \frac{x}{y}\right)}\right| \]
      7. metadata-eval73.2%

        \[\leadsto \left|z \cdot \left(\color{blue}{\frac{1}{-1}} \cdot \frac{x}{y}\right)\right| \]
      8. times-frac73.2%

        \[\leadsto \left|z \cdot \color{blue}{\frac{1 \cdot x}{-1 \cdot y}}\right| \]
      9. *-lft-identity73.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
    6. Applied egg-rr73.3%

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

    if -1.80000000000000005e43 < x < -1.5 or 4 < x

    1. Initial program 86.8%

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

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

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

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

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

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

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

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

    if -1.5 < x < 4

    1. Initial program 95.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+43}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;x \leq -1.5 \lor \neg \left(x \leq 4\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \]

Alternative 7: 85.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -300000000:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+112}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -300000000.0)
   (fabs (/ z (/ y x)))
   (if (<= z 1.8e+112) (fabs (/ (- -4.0 x) y)) (fabs (* x (/ z y))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -300000000.0) {
		tmp = fabs((z / (y / x)));
	} else if (z <= 1.8e+112) {
		tmp = fabs(((-4.0 - x) / y));
	} else {
		tmp = fabs((x * (z / y)));
	}
	return tmp;
}
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 <= (-300000000.0d0)) then
        tmp = abs((z / (y / x)))
    else if (z <= 1.8d+112) then
        tmp = abs((((-4.0d0) - x) / y))
    else
        tmp = abs((x * (z / y)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -300000000.0) {
		tmp = Math.abs((z / (y / x)));
	} else if (z <= 1.8e+112) {
		tmp = Math.abs(((-4.0 - x) / y));
	} else {
		tmp = Math.abs((x * (z / y)));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -300000000.0:
		tmp = math.fabs((z / (y / x)))
	elif z <= 1.8e+112:
		tmp = math.fabs(((-4.0 - x) / y))
	else:
		tmp = math.fabs((x * (z / y)))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -300000000.0)
		tmp = abs(Float64(z / Float64(y / x)));
	elseif (z <= 1.8e+112)
		tmp = abs(Float64(Float64(-4.0 - x) / y));
	else
		tmp = abs(Float64(x * Float64(z / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -300000000.0)
		tmp = abs((z / (y / x)));
	elseif (z <= 1.8e+112)
		tmp = abs(((-4.0 - x) / y));
	else
		tmp = abs((x * (z / y)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -300000000.0], N[Abs[N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 1.8e+112], N[Abs[N[(N[(-4.0 - x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -300000000:\\
\;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\

\mathbf{elif}\;z \leq 1.8 \cdot 10^{+112}:\\
\;\;\;\;\left|\frac{-4 - x}{y}\right|\\

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


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

    1. Initial program 98.3%

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

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

        \[\leadsto \left|\color{blue}{\frac{-1 \cdot \left(z \cdot x\right)}{y}}\right| \]
      2. mul-1-neg68.8%

        \[\leadsto \left|\frac{\color{blue}{-z \cdot x}}{y}\right| \]
      3. distribute-rgt-neg-out68.8%

        \[\leadsto \left|\frac{\color{blue}{z \cdot \left(-x\right)}}{y}\right| \]
      4. associate-*r/76.1%

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

        \[\leadsto \left|z \cdot \color{blue}{\left(-\frac{x}{y}\right)}\right| \]
      6. mul-1-neg76.1%

        \[\leadsto \left|z \cdot \color{blue}{\left(-1 \cdot \frac{x}{y}\right)}\right| \]
      7. metadata-eval76.1%

        \[\leadsto \left|z \cdot \left(\color{blue}{\frac{1}{-1}} \cdot \frac{x}{y}\right)\right| \]
      8. times-frac76.1%

        \[\leadsto \left|z \cdot \color{blue}{\frac{1 \cdot x}{-1 \cdot y}}\right| \]
      9. *-lft-identity76.1%

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

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

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

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

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

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

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

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

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

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

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

    if -3e8 < z < 1.8e112

    1. Initial program 94.1%

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

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

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

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

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

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

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

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

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

    if 1.8e112 < z

    1. Initial program 73.7%

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

      \[\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.9%

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

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

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

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

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

Alternative 8: 68.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -1.55) (not (<= x 4.0))) (fabs (/ x y)) (fabs (/ 4.0 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;
}
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
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;
}
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
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
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
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}

\\
\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 87.4%

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

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

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

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

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

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

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

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

    if -1.55000000000000004 < x < 4

    1. Initial program 95.9%

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

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

    \[\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 9: 39.3% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \left|\frac{4}{y}\right| \end{array} \]
(FPCore (x y z) :precision binary64 (fabs (/ 4.0 y)))
double code(double x, double y, double z) {
	return fabs((4.0 / y));
}
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
public static double code(double x, double y, double z) {
	return Math.abs((4.0 / y));
}
def code(x, y, z):
	return math.fabs((4.0 / y))
function code(x, y, z)
	return abs(Float64(4.0 / y))
end
function tmp = code(x, y, z)
	tmp = abs((4.0 / y));
end
code[x_, y_, z_] := N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\left|\frac{4}{y}\right|
\end{array}
Derivation
  1. Initial program 91.6%

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

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

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

Reproduce

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