fabs fraction 1

Percentage Accurate: 91.8% → 95.9%
Time: 7.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: 91.8% 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: 95.9% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

Alternative 2: 67.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|\frac{4}{y}\right|\\ t_1 := \left|\frac{x \cdot z}{y}\right|\\ \mathbf{if}\;x \leq -2.5 \cdot 10^{+34}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -4.4 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-206}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.95 \cdot 10^{-217}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-90}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fabs (/ 4.0 y))) (t_1 (fabs (/ (* x z) y))))
   (if (<= x -2.5e+34)
     (fabs (/ x y))
     (if (<= x -4.4e-72)
       t_1
       (if (<= x -2.8e-206)
         t_0
         (if (<= x -2.95e-217)
           t_1
           (if (<= x 1.75e-90) t_0 (fabs (* z (/ x y))))))))))
double code(double x, double y, double z) {
	double t_0 = fabs((4.0 / y));
	double t_1 = fabs(((x * z) / y));
	double tmp;
	if (x <= -2.5e+34) {
		tmp = fabs((x / y));
	} else if (x <= -4.4e-72) {
		tmp = t_1;
	} else if (x <= -2.8e-206) {
		tmp = t_0;
	} else if (x <= -2.95e-217) {
		tmp = t_1;
	} else if (x <= 1.75e-90) {
		tmp = t_0;
	} else {
		tmp = fabs((z * (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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = abs((4.0d0 / y))
    t_1 = abs(((x * z) / y))
    if (x <= (-2.5d+34)) then
        tmp = abs((x / y))
    else if (x <= (-4.4d-72)) then
        tmp = t_1
    else if (x <= (-2.8d-206)) then
        tmp = t_0
    else if (x <= (-2.95d-217)) then
        tmp = t_1
    else if (x <= 1.75d-90) then
        tmp = t_0
    else
        tmp = abs((z * (x / y)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = Math.abs((4.0 / y));
	double t_1 = Math.abs(((x * z) / y));
	double tmp;
	if (x <= -2.5e+34) {
		tmp = Math.abs((x / y));
	} else if (x <= -4.4e-72) {
		tmp = t_1;
	} else if (x <= -2.8e-206) {
		tmp = t_0;
	} else if (x <= -2.95e-217) {
		tmp = t_1;
	} else if (x <= 1.75e-90) {
		tmp = t_0;
	} else {
		tmp = Math.abs((z * (x / y)));
	}
	return tmp;
}
def code(x, y, z):
	t_0 = math.fabs((4.0 / y))
	t_1 = math.fabs(((x * z) / y))
	tmp = 0
	if x <= -2.5e+34:
		tmp = math.fabs((x / y))
	elif x <= -4.4e-72:
		tmp = t_1
	elif x <= -2.8e-206:
		tmp = t_0
	elif x <= -2.95e-217:
		tmp = t_1
	elif x <= 1.75e-90:
		tmp = t_0
	else:
		tmp = math.fabs((z * (x / y)))
	return tmp
function code(x, y, z)
	t_0 = abs(Float64(4.0 / y))
	t_1 = abs(Float64(Float64(x * z) / y))
	tmp = 0.0
	if (x <= -2.5e+34)
		tmp = abs(Float64(x / y));
	elseif (x <= -4.4e-72)
		tmp = t_1;
	elseif (x <= -2.8e-206)
		tmp = t_0;
	elseif (x <= -2.95e-217)
		tmp = t_1;
	elseif (x <= 1.75e-90)
		tmp = t_0;
	else
		tmp = abs(Float64(z * Float64(x / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = abs((4.0 / y));
	t_1 = abs(((x * z) / y));
	tmp = 0.0;
	if (x <= -2.5e+34)
		tmp = abs((x / y));
	elseif (x <= -4.4e-72)
		tmp = t_1;
	elseif (x <= -2.8e-206)
		tmp = t_0;
	elseif (x <= -2.95e-217)
		tmp = t_1;
	elseif (x <= 1.75e-90)
		tmp = t_0;
	else
		tmp = abs((z * (x / y)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -2.5e+34], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, -4.4e-72], t$95$1, If[LessEqual[x, -2.8e-206], t$95$0, If[LessEqual[x, -2.95e-217], t$95$1, If[LessEqual[x, 1.75e-90], t$95$0, N[Abs[N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|\frac{4}{y}\right|\\
t_1 := \left|\frac{x \cdot z}{y}\right|\\
\mathbf{if}\;x \leq -2.5 \cdot 10^{+34}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\

\mathbf{elif}\;x \leq -4.4 \cdot 10^{-72}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -2.8 \cdot 10^{-206}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -2.95 \cdot 10^{-217}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 1.75 \cdot 10^{-90}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 80.2%

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

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

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

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

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

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

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

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

    if -2.4999999999999999e34 < x < -4.40000000000000005e-72 or -2.8000000000000001e-206 < x < -2.9499999999999999e-217

    1. Initial program 90.0%

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

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

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

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

    if -4.40000000000000005e-72 < x < -2.8000000000000001e-206 or -2.9499999999999999e-217 < x < 1.7499999999999999e-90

    1. Initial program 93.9%

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

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

    if 1.7499999999999999e-90 < x

    1. Initial program 93.9%

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot z}\right| \]
    6. Simplified60.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+34}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -4.4 \cdot 10^{-72}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-206}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq -2.95 \cdot 10^{-217}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-90}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]

Alternative 3: 68.9% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;x \leq -4.1 \cdot 10^{-63} \lor \neg \left(x \leq 1.25 \cdot 10^{-78}\right):\\
\;\;\;\;\left|z \cdot \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 < -3.6e35

    1. Initial program 80.2%

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

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

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

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

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

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

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

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

    if -3.6e35 < x < -4.0999999999999998e-63 or 1.2499999999999999e-78 < x

    1. Initial program 94.3%

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

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

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

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

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

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

    if -4.0999999999999998e-63 < x < 1.2499999999999999e-78

    1. Initial program 92.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{+35}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -4.1 \cdot 10^{-63} \lor \neg \left(x \leq 1.25 \cdot 10^{-78}\right):\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \]

Alternative 4: 68.5% accurate, 1.0× speedup?

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

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

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

\mathbf{elif}\;x \leq 1.75 \cdot 10^{-90}:\\
\;\;\;\;\left|\frac{4}{y}\right|\\

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


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

    1. Initial program 80.2%

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

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

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

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

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

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

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

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

    if -9.0000000000000001e34 < x < -4.0999999999999998e-63

    1. Initial program 95.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.0999999999999998e-63 < x < 1.7499999999999999e-90

    1. Initial program 92.2%

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

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

    if 1.7499999999999999e-90 < x

    1. Initial program 93.9%

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot z}\right| \]
    6. Simplified60.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{+34}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -4.1 \cdot 10^{-63}:\\ \;\;\;\;\left|\frac{x}{\frac{y}{z}}\right|\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-90}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]

Alternative 5: 85.1% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 91.6%

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

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

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

    if -5.5e7 < z < 9.99999999999999946e48

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999946e48 < z

    1. Initial program 88.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 85.0% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 91.6%

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

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

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

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

    if -1.26e8 < z < 4.20000000000000022e49

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

    if 4.20000000000000022e49 < z

    1. Initial program 88.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 85.0% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 91.6%

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{1}{\frac{y}{x \cdot \left(-z\right)}}}\right| \]
      3. add-sqr-sqrt83.2%

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

        \[\leadsto \left|\frac{1}{\frac{y}{x \cdot \color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}}}}\right| \]
      5. sqr-neg62.8%

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

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

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

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

    if -1.18e8 < z < 2.59999999999999989e49

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

    if 2.59999999999999989e49 < z

    1. Initial program 88.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 69.0% 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 86.7%

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

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

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

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

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

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

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

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

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

    if -1.55000000000000004 < x < 4

    1. Initial program 93.8%

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

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

    \[\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: 40.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 90.2%

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

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

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

Reproduce

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