fabs fraction 1

Percentage Accurate: 92.3% → 99.8%
Time: 6.3s
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: 92.3% 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 1.2 \cdot 10^{+34}:\\ \;\;\;\;\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 1.2e+34)
   (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 <= 1.2e+34) {
		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 <= 1.2e+34)
		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, 1.2e+34], 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 1.2 \cdot 10^{+34}:\\
\;\;\;\;\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 < 1.19999999999999993e34

    1. Initial program 91.2%

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

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

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

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

    if 1.19999999999999993e34 < y

    1. Initial program 96.8%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.2 \cdot 10^{+34}:\\ \;\;\;\;\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: 67.8% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \left|x \cdot \frac{z}{y}\right|\\ \mathbf{if}\;x \leq -34000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{+70} \lor \neg \left(x \leq 1.06 \cdot 10^{+159}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fabs (/ x y))) (t_1 (fabs (* x (/ z y)))))
   (if (<= x -34000000.0)
     t_0
     (if (<= x -1.8e-64)
       t_1
       (if (<= x 4.0)
         (fabs (/ 4.0 y))
         (if (or (<= x 1.5e+70) (not (<= x 1.06e+159))) t_0 t_1))))))
y = abs(y);
double code(double x, double y, double z) {
	double t_0 = fabs((x / y));
	double t_1 = fabs((x * (z / y)));
	double tmp;
	if (x <= -34000000.0) {
		tmp = t_0;
	} else if (x <= -1.8e-64) {
		tmp = t_1;
	} else if (x <= 4.0) {
		tmp = fabs((4.0 / y));
	} else if ((x <= 1.5e+70) || !(x <= 1.06e+159)) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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((x / y))
    t_1 = abs((x * (z / y)))
    if (x <= (-34000000.0d0)) then
        tmp = t_0
    else if (x <= (-1.8d-64)) then
        tmp = t_1
    else if (x <= 4.0d0) then
        tmp = abs((4.0d0 / y))
    else if ((x <= 1.5d+70) .or. (.not. (x <= 1.06d+159))) then
        tmp = t_0
    else
        tmp = t_1
    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((x / y));
	double t_1 = Math.abs((x * (z / y)));
	double tmp;
	if (x <= -34000000.0) {
		tmp = t_0;
	} else if (x <= -1.8e-64) {
		tmp = t_1;
	} else if (x <= 4.0) {
		tmp = Math.abs((4.0 / y));
	} else if ((x <= 1.5e+70) || !(x <= 1.06e+159)) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
y = abs(y)
def code(x, y, z):
	t_0 = math.fabs((x / y))
	t_1 = math.fabs((x * (z / y)))
	tmp = 0
	if x <= -34000000.0:
		tmp = t_0
	elif x <= -1.8e-64:
		tmp = t_1
	elif x <= 4.0:
		tmp = math.fabs((4.0 / y))
	elif (x <= 1.5e+70) or not (x <= 1.06e+159):
		tmp = t_0
	else:
		tmp = t_1
	return tmp
y = abs(y)
function code(x, y, z)
	t_0 = abs(Float64(x / y))
	t_1 = abs(Float64(x * Float64(z / y)))
	tmp = 0.0
	if (x <= -34000000.0)
		tmp = t_0;
	elseif (x <= -1.8e-64)
		tmp = t_1;
	elseif (x <= 4.0)
		tmp = abs(Float64(4.0 / y));
	elseif ((x <= 1.5e+70) || !(x <= 1.06e+159))
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y, z)
	t_0 = abs((x / y));
	t_1 = abs((x * (z / y)));
	tmp = 0.0;
	if (x <= -34000000.0)
		tmp = t_0;
	elseif (x <= -1.8e-64)
		tmp = t_1;
	elseif (x <= 4.0)
		tmp = abs((4.0 / y));
	elseif ((x <= 1.5e+70) || ~((x <= 1.06e+159)))
		tmp = t_0;
	else
		tmp = t_1;
	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[(x / y), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -34000000.0], t$95$0, If[LessEqual[x, -1.8e-64], t$95$1, If[LessEqual[x, 4.0], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, 1.5e+70], N[Not[LessEqual[x, 1.06e+159]], $MachinePrecision]], t$95$0, t$95$1]]]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := \left|\frac{x}{y}\right|\\
t_1 := \left|x \cdot \frac{z}{y}\right|\\
\mathbf{if}\;x \leq -34000000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -1.8 \cdot 10^{-64}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;x \leq 1.5 \cdot 10^{+70} \lor \neg \left(x \leq 1.06 \cdot 10^{+159}\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.4e7 or 4 < x < 1.49999999999999988e70 or 1.06000000000000006e159 < x

    1. Initial program 84.0%

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

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

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

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

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

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

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

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

    if -3.4e7 < x < -1.7999999999999999e-64 or 1.49999999999999988e70 < x < 1.06000000000000006e159

    1. Initial program 99.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 inf 75.4%

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

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

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

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

    if -1.7999999999999999e-64 < x < 4

    1. Initial program 98.3%

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

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

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

Alternative 3: 67.8% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -30500000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-65}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{+71} \lor \neg \left(x \leq 1.38 \cdot 10^{+159}\right):\\ \;\;\;\;t_0\\ \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 (/ x y))))
   (if (<= x -30500000.0)
     t_0
     (if (<= x -1.3e-65)
       (fabs (* z (/ x y)))
       (if (<= x 4.0)
         (fabs (/ 4.0 y))
         (if (or (<= x 5.8e+71) (not (<= x 1.38e+159)))
           t_0
           (fabs (* x (/ z y)))))))))
y = abs(y);
double code(double x, double y, double z) {
	double t_0 = fabs((x / y));
	double tmp;
	if (x <= -30500000.0) {
		tmp = t_0;
	} else if (x <= -1.3e-65) {
		tmp = fabs((z * (x / y)));
	} else if (x <= 4.0) {
		tmp = fabs((4.0 / y));
	} else if ((x <= 5.8e+71) || !(x <= 1.38e+159)) {
		tmp = t_0;
	} 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) :: tmp
    t_0 = abs((x / y))
    if (x <= (-30500000.0d0)) then
        tmp = t_0
    else if (x <= (-1.3d-65)) then
        tmp = abs((z * (x / y)))
    else if (x <= 4.0d0) then
        tmp = abs((4.0d0 / y))
    else if ((x <= 5.8d+71) .or. (.not. (x <= 1.38d+159))) then
        tmp = t_0
    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((x / y));
	double tmp;
	if (x <= -30500000.0) {
		tmp = t_0;
	} else if (x <= -1.3e-65) {
		tmp = Math.abs((z * (x / y)));
	} else if (x <= 4.0) {
		tmp = Math.abs((4.0 / y));
	} else if ((x <= 5.8e+71) || !(x <= 1.38e+159)) {
		tmp = t_0;
	} else {
		tmp = Math.abs((x * (z / y)));
	}
	return tmp;
}
y = abs(y)
def code(x, y, z):
	t_0 = math.fabs((x / y))
	tmp = 0
	if x <= -30500000.0:
		tmp = t_0
	elif x <= -1.3e-65:
		tmp = math.fabs((z * (x / y)))
	elif x <= 4.0:
		tmp = math.fabs((4.0 / y))
	elif (x <= 5.8e+71) or not (x <= 1.38e+159):
		tmp = t_0
	else:
		tmp = math.fabs((x * (z / y)))
	return tmp
y = abs(y)
function code(x, y, z)
	t_0 = abs(Float64(x / y))
	tmp = 0.0
	if (x <= -30500000.0)
		tmp = t_0;
	elseif (x <= -1.3e-65)
		tmp = abs(Float64(z * Float64(x / y)));
	elseif (x <= 4.0)
		tmp = abs(Float64(4.0 / y));
	elseif ((x <= 5.8e+71) || !(x <= 1.38e+159))
		tmp = t_0;
	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((x / y));
	tmp = 0.0;
	if (x <= -30500000.0)
		tmp = t_0;
	elseif (x <= -1.3e-65)
		tmp = abs((z * (x / y)));
	elseif (x <= 4.0)
		tmp = abs((4.0 / y));
	elseif ((x <= 5.8e+71) || ~((x <= 1.38e+159)))
		tmp = t_0;
	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[(x / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -30500000.0], t$95$0, If[LessEqual[x, -1.3e-65], N[Abs[N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 4.0], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, 5.8e+71], N[Not[LessEqual[x, 1.38e+159]], $MachinePrecision]], t$95$0, N[Abs[N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := \left|\frac{x}{y}\right|\\
\mathbf{if}\;x \leq -30500000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -1.3 \cdot 10^{-65}:\\
\;\;\;\;\left|z \cdot \frac{x}{y}\right|\\

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

\mathbf{elif}\;x \leq 5.8 \cdot 10^{+71} \lor \neg \left(x \leq 1.38 \cdot 10^{+159}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -3.05e7 or 4 < x < 5.80000000000000014e71 or 1.38000000000000001e159 < x

    1. Initial program 84.0%

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

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

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

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

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

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

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

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

    if -3.05e7 < x < -1.30000000000000005e-65

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -1.30000000000000005e-65 < x < 4

    1. Initial program 98.3%

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

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

    if 5.80000000000000014e71 < x < 1.38000000000000001e159

    1. Initial program 99.5%

      \[\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 inf 85.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -30500000:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-65}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{+71} \lor \neg \left(x \leq 1.38 \cdot 10^{+159}\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \end{array} \]

Alternative 4: 68.2% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -13500000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-64}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 4:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 10^{+69} \lor \neg \left(x \leq 1.8 \cdot 10^{+179}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fabs (/ x y))))
   (if (<= x -13500000.0)
     t_0
     (if (<= x -1.9e-64)
       (fabs (* z (/ x y)))
       (if (<= x 4.0)
         (fabs (/ 4.0 y))
         (if (or (<= x 1e+69) (not (<= x 1.8e+179)))
           t_0
           (fabs (/ z (/ y x)))))))))
y = abs(y);
double code(double x, double y, double z) {
	double t_0 = fabs((x / y));
	double tmp;
	if (x <= -13500000.0) {
		tmp = t_0;
	} else if (x <= -1.9e-64) {
		tmp = fabs((z * (x / y)));
	} else if (x <= 4.0) {
		tmp = fabs((4.0 / y));
	} else if ((x <= 1e+69) || !(x <= 1.8e+179)) {
		tmp = t_0;
	} else {
		tmp = fabs((z / (y / x)));
	}
	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) :: tmp
    t_0 = abs((x / y))
    if (x <= (-13500000.0d0)) then
        tmp = t_0
    else if (x <= (-1.9d-64)) then
        tmp = abs((z * (x / y)))
    else if (x <= 4.0d0) then
        tmp = abs((4.0d0 / y))
    else if ((x <= 1d+69) .or. (.not. (x <= 1.8d+179))) then
        tmp = t_0
    else
        tmp = abs((z / (y / x)))
    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((x / y));
	double tmp;
	if (x <= -13500000.0) {
		tmp = t_0;
	} else if (x <= -1.9e-64) {
		tmp = Math.abs((z * (x / y)));
	} else if (x <= 4.0) {
		tmp = Math.abs((4.0 / y));
	} else if ((x <= 1e+69) || !(x <= 1.8e+179)) {
		tmp = t_0;
	} else {
		tmp = Math.abs((z / (y / x)));
	}
	return tmp;
}
y = abs(y)
def code(x, y, z):
	t_0 = math.fabs((x / y))
	tmp = 0
	if x <= -13500000.0:
		tmp = t_0
	elif x <= -1.9e-64:
		tmp = math.fabs((z * (x / y)))
	elif x <= 4.0:
		tmp = math.fabs((4.0 / y))
	elif (x <= 1e+69) or not (x <= 1.8e+179):
		tmp = t_0
	else:
		tmp = math.fabs((z / (y / x)))
	return tmp
y = abs(y)
function code(x, y, z)
	t_0 = abs(Float64(x / y))
	tmp = 0.0
	if (x <= -13500000.0)
		tmp = t_0;
	elseif (x <= -1.9e-64)
		tmp = abs(Float64(z * Float64(x / y)));
	elseif (x <= 4.0)
		tmp = abs(Float64(4.0 / y));
	elseif ((x <= 1e+69) || !(x <= 1.8e+179))
		tmp = t_0;
	else
		tmp = abs(Float64(z / Float64(y / x)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y, z)
	t_0 = abs((x / y));
	tmp = 0.0;
	if (x <= -13500000.0)
		tmp = t_0;
	elseif (x <= -1.9e-64)
		tmp = abs((z * (x / y)));
	elseif (x <= 4.0)
		tmp = abs((4.0 / y));
	elseif ((x <= 1e+69) || ~((x <= 1.8e+179)))
		tmp = t_0;
	else
		tmp = abs((z / (y / x)));
	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[(x / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -13500000.0], t$95$0, If[LessEqual[x, -1.9e-64], N[Abs[N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 4.0], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, 1e+69], N[Not[LessEqual[x, 1.8e+179]], $MachinePrecision]], t$95$0, N[Abs[N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
t_0 := \left|\frac{x}{y}\right|\\
\mathbf{if}\;x \leq -13500000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -1.9 \cdot 10^{-64}:\\
\;\;\;\;\left|z \cdot \frac{x}{y}\right|\\

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

\mathbf{elif}\;x \leq 10^{+69} \lor \neg \left(x \leq 1.8 \cdot 10^{+179}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -1.35e7 or 4 < x < 1.0000000000000001e69 or 1.7999999999999999e179 < x

    1. Initial program 84.0%

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

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

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

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

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

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

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

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

    if -1.35e7 < x < -1.9000000000000001e-64

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -1.9000000000000001e-64 < x < 4

    1. Initial program 98.3%

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

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

    if 1.0000000000000001e69 < x < 1.7999999999999999e179

    1. Initial program 94.3%

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

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

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

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

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

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

      \[\leadsto \left|\color{blue}{z \cdot \frac{x}{y}}\right| \]
    6. Step-by-step derivation
      1. clear-num79.8%

        \[\leadsto \left|z \cdot \color{blue}{\frac{1}{\frac{y}{x}}}\right| \]
      2. un-div-inv79.8%

        \[\leadsto \left|\color{blue}{\frac{z}{\frac{y}{x}}}\right| \]
    7. Applied egg-rr79.8%

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

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

Alternative 5: 85.3% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 97.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 inf 79.7%

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

    if -5.8000000000000004e44 < z < 3.2000000000000001e31

    1. Initial program 91.3%

      \[\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 98.0%

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

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

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

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

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

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

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

    if 3.2000000000000001e31 < z

    1. Initial program 91.4%

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

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

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

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

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

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

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

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

Alternative 6: 85.3% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 97.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 inf 79.7%

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

    if -5.8000000000000004e44 < z < 2.9e31

    1. Initial program 91.3%

      \[\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 98.0%

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

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

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

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

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

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

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

    if 2.9e31 < z

    1. Initial program 91.4%

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

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

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

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

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

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

      \[\leadsto \left|\color{blue}{z \cdot \frac{x}{y}}\right| \]
    6. Step-by-step derivation
      1. clear-num77.5%

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

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

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

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

Alternative 7: 95.9% 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.5%

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

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

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

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

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

Alternative 8: 68.5% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -10.2 \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 -10.2) (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 <= -10.2) || !(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 <= (-10.2d0)) .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 <= -10.2) || !(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 <= -10.2) 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 <= -10.2) || !(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 <= -10.2) || ~((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, -10.2], 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 -10.2 \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 < -10.199999999999999 or 4 < x

    1. Initial program 85.9%

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

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

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

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

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

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

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

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

    if -10.199999999999999 < x < 4

    1. Initial program 98.5%

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

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

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

Alternative 9: 40.5% 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.5%

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

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

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

Reproduce

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