fabs fraction 1

Percentage Accurate: 91.7% → 99.0%
Time: 6.9s
Alternatives: 8
Speedup: 0.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 91.7% 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.0% accurate, 0.5× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;y\_m \leq 7.2 \cdot 10^{+143}:\\ \;\;\;\;\left|\frac{x \cdot z - \left(x + 4\right)}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\mathsf{fma}\left(x, \frac{z}{y\_m}, \frac{-4 - x}{y\_m}\right)\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (<= y_m 7.2e+143)
   (fabs (/ (- (* x z) (+ x 4.0)) y_m))
   (fabs (fma x (/ z y_m) (/ (- -4.0 x) y_m)))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if (y_m <= 7.2e+143) {
		tmp = fabs((((x * z) - (x + 4.0)) / y_m));
	} else {
		tmp = fabs(fma(x, (z / y_m), ((-4.0 - x) / y_m)));
	}
	return tmp;
}
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if (y_m <= 7.2e+143)
		tmp = abs(Float64(Float64(Float64(x * z) - Float64(x + 4.0)) / y_m));
	else
		tmp = abs(fma(x, Float64(z / y_m), Float64(Float64(-4.0 - x) / y_m)));
	end
	return tmp
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[LessEqual[y$95$m, 7.2e+143], N[Abs[N[(N[(N[(x * z), $MachinePrecision] - N[(x + 4.0), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(x * N[(z / y$95$m), $MachinePrecision] + N[(N[(-4.0 - x), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;y\_m \leq 7.2 \cdot 10^{+143}:\\
\;\;\;\;\left|\frac{x \cdot z - \left(x + 4\right)}{y\_m}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 7.1999999999999998e143

    1. Initial program 90.1%

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

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

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

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

    if 7.1999999999999998e143 < y

    1. Initial program 92.9%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.7% accurate, 0.5× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;\left|\frac{x + 4}{y\_m} - z \cdot \frac{x}{y\_m}\right| \leq 5 \cdot 10^{+34}:\\ \;\;\;\;\left|\frac{x \cdot z - \left(x + 4\right)}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y\_m} \cdot \left(\frac{4}{x} + \left(1 - z\right)\right)\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (<= (fabs (- (/ (+ x 4.0) y_m) (* z (/ x y_m)))) 5e+34)
   (fabs (/ (- (* x z) (+ x 4.0)) y_m))
   (fabs (* (/ x y_m) (+ (/ 4.0 x) (- 1.0 z))))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if (fabs((((x + 4.0) / y_m) - (z * (x / y_m)))) <= 5e+34) {
		tmp = fabs((((x * z) - (x + 4.0)) / y_m));
	} else {
		tmp = fabs(((x / y_m) * ((4.0 / x) + (1.0 - z))));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (abs((((x + 4.0d0) / y_m) - (z * (x / y_m)))) <= 5d+34) then
        tmp = abs((((x * z) - (x + 4.0d0)) / y_m))
    else
        tmp = abs(((x / y_m) * ((4.0d0 / x) + (1.0d0 - z))))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if (Math.abs((((x + 4.0) / y_m) - (z * (x / y_m)))) <= 5e+34) {
		tmp = Math.abs((((x * z) - (x + 4.0)) / y_m));
	} else {
		tmp = Math.abs(((x / y_m) * ((4.0 / x) + (1.0 - z))));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if math.fabs((((x + 4.0) / y_m) - (z * (x / y_m)))) <= 5e+34:
		tmp = math.fabs((((x * z) - (x + 4.0)) / y_m))
	else:
		tmp = math.fabs(((x / y_m) * ((4.0 / x) + (1.0 - z))))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if (abs(Float64(Float64(Float64(x + 4.0) / y_m) - Float64(z * Float64(x / y_m)))) <= 5e+34)
		tmp = abs(Float64(Float64(Float64(x * z) - Float64(x + 4.0)) / y_m));
	else
		tmp = abs(Float64(Float64(x / y_m) * Float64(Float64(4.0 / x) + Float64(1.0 - z))));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if (abs((((x + 4.0) / y_m) - (z * (x / y_m)))) <= 5e+34)
		tmp = abs((((x * z) - (x + 4.0)) / y_m));
	else
		tmp = abs(((x / y_m) * ((4.0 / x) + (1.0 - z))));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[LessEqual[N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y$95$m), $MachinePrecision] - N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 5e+34], N[Abs[N[(N[(N[(x * z), $MachinePrecision] - N[(x + 4.0), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(x / y$95$m), $MachinePrecision] * N[(N[(4.0 / x), $MachinePrecision] + N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;\left|\frac{x + 4}{y\_m} - z \cdot \frac{x}{y\_m}\right| \leq 5 \cdot 10^{+34}:\\
\;\;\;\;\left|\frac{x \cdot z - \left(x + 4\right)}{y\_m}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (fabs.f64 (-.f64 (/.f64 (+.f64 x #s(literal 4 binary64)) y) (*.f64 (/.f64 x y) z))) < 4.9999999999999998e34

    1. Initial program 95.5%

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

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

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

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

    if 4.9999999999999998e34 < (fabs.f64 (-.f64 (/.f64 (+.f64 x #s(literal 4 binary64)) y) (*.f64 (/.f64 x y) z)))

    1. Initial program 87.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 69.5% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -3.5 \cdot 10^{+160}:\\ \;\;\;\;\left|\frac{x}{y\_m}\right|\\ \mathbf{elif}\;x \leq -4.3 \cdot 10^{-66} \lor \neg \left(x \leq 5.6 \cdot 10^{-6}\right):\\ \;\;\;\;\left|z \cdot \frac{x}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y\_m}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (<= x -3.5e+160)
   (fabs (/ x y_m))
   (if (or (<= x -4.3e-66) (not (<= x 5.6e-6)))
     (fabs (* z (/ x y_m)))
     (fabs (/ 4.0 y_m)))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if (x <= -3.5e+160) {
		tmp = fabs((x / y_m));
	} else if ((x <= -4.3e-66) || !(x <= 5.6e-6)) {
		tmp = fabs((z * (x / y_m)));
	} else {
		tmp = fabs((4.0 / y_m));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-3.5d+160)) then
        tmp = abs((x / y_m))
    else if ((x <= (-4.3d-66)) .or. (.not. (x <= 5.6d-6))) then
        tmp = abs((z * (x / y_m)))
    else
        tmp = abs((4.0d0 / y_m))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if (x <= -3.5e+160) {
		tmp = Math.abs((x / y_m));
	} else if ((x <= -4.3e-66) || !(x <= 5.6e-6)) {
		tmp = Math.abs((z * (x / y_m)));
	} else {
		tmp = Math.abs((4.0 / y_m));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if x <= -3.5e+160:
		tmp = math.fabs((x / y_m))
	elif (x <= -4.3e-66) or not (x <= 5.6e-6):
		tmp = math.fabs((z * (x / y_m)))
	else:
		tmp = math.fabs((4.0 / y_m))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if (x <= -3.5e+160)
		tmp = abs(Float64(x / y_m));
	elseif ((x <= -4.3e-66) || !(x <= 5.6e-6))
		tmp = abs(Float64(z * Float64(x / y_m)));
	else
		tmp = abs(Float64(4.0 / y_m));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if (x <= -3.5e+160)
		tmp = abs((x / y_m));
	elseif ((x <= -4.3e-66) || ~((x <= 5.6e-6)))
		tmp = abs((z * (x / y_m)));
	else
		tmp = abs((4.0 / y_m));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[LessEqual[x, -3.5e+160], N[Abs[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, -4.3e-66], N[Not[LessEqual[x, 5.6e-6]], $MachinePrecision]], N[Abs[N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(4.0 / y$95$m), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|

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

\mathbf{elif}\;x \leq -4.3 \cdot 10^{-66} \lor \neg \left(x \leq 5.6 \cdot 10^{-6}\right):\\
\;\;\;\;\left|z \cdot \frac{x}{y\_m}\right|\\

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


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

    1. Initial program 89.7%

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

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

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

    if -3.50000000000000026e160 < x < -4.30000000000000013e-66 or 5.59999999999999975e-6 < x

    1. Initial program 84.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.30000000000000013e-66 < x < 5.59999999999999975e-6

    1. Initial program 96.6%

      \[\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. Add Preprocessing
    4. Taylor expanded in x around 0 81.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.5 \cdot 10^{+160}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -4.3 \cdot 10^{-66} \lor \neg \left(x \leq 5.6 \cdot 10^{-6}\right):\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.5% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{+62} \lor \neg \left(x \leq 1.95 \cdot 10^{+81}\right):\\ \;\;\;\;\left|x \cdot \frac{1 - z}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x \cdot z - \left(x + 4\right)}{y\_m}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (or (<= x -7.2e+62) (not (<= x 1.95e+81)))
   (fabs (* x (/ (- 1.0 z) y_m)))
   (fabs (/ (- (* x z) (+ x 4.0)) y_m))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if ((x <= -7.2e+62) || !(x <= 1.95e+81)) {
		tmp = fabs((x * ((1.0 - z) / y_m)));
	} else {
		tmp = fabs((((x * z) - (x + 4.0)) / y_m));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-7.2d+62)) .or. (.not. (x <= 1.95d+81))) then
        tmp = abs((x * ((1.0d0 - z) / y_m)))
    else
        tmp = abs((((x * z) - (x + 4.0d0)) / y_m))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if ((x <= -7.2e+62) || !(x <= 1.95e+81)) {
		tmp = Math.abs((x * ((1.0 - z) / y_m)));
	} else {
		tmp = Math.abs((((x * z) - (x + 4.0)) / y_m));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if (x <= -7.2e+62) or not (x <= 1.95e+81):
		tmp = math.fabs((x * ((1.0 - z) / y_m)))
	else:
		tmp = math.fabs((((x * z) - (x + 4.0)) / y_m))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if ((x <= -7.2e+62) || !(x <= 1.95e+81))
		tmp = abs(Float64(x * Float64(Float64(1.0 - z) / y_m)));
	else
		tmp = abs(Float64(Float64(Float64(x * z) - Float64(x + 4.0)) / y_m));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if ((x <= -7.2e+62) || ~((x <= 1.95e+81)))
		tmp = abs((x * ((1.0 - z) / y_m)));
	else
		tmp = abs((((x * z) - (x + 4.0)) / y_m));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[Or[LessEqual[x, -7.2e+62], N[Not[LessEqual[x, 1.95e+81]], $MachinePrecision]], N[Abs[N[(x * N[(N[(1.0 - z), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(x * z), $MachinePrecision] - N[(x + 4.0), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+62} \lor \neg \left(x \leq 1.95 \cdot 10^{+81}\right):\\
\;\;\;\;\left|x \cdot \frac{1 - z}{y\_m}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.2e62 or 1.95e81 < x

    1. Initial program 79.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|x \cdot \frac{\color{blue}{0 - \left(z - 1\right)}}{y}\right| \]
      8. associate-+l-99.8%

        \[\leadsto \left|x \cdot \frac{\color{blue}{\left(0 - z\right) + 1}}{y}\right| \]
      9. neg-sub099.8%

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

        \[\leadsto \left|x \cdot \frac{\color{blue}{1 + \left(-z\right)}}{y}\right| \]
      11. unsub-neg99.8%

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

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

    if -7.2e62 < x < 1.95e81

    1. Initial program 96.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{+62} \lor \neg \left(x \leq 1.95 \cdot 10^{+81}\right):\\ \;\;\;\;\left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x \cdot z - \left(x + 4\right)}{y}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 86.7% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{-66} \lor \neg \left(x \leq 7.3 \cdot 10^{-6}\right):\\ \;\;\;\;\left|x \cdot \frac{1 - z}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x - -4}{y\_m}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (or (<= x -2.7e-66) (not (<= x 7.3e-6)))
   (fabs (* x (/ (- 1.0 z) y_m)))
   (fabs (/ (- x -4.0) y_m))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if ((x <= -2.7e-66) || !(x <= 7.3e-6)) {
		tmp = fabs((x * ((1.0 - z) / y_m)));
	} else {
		tmp = fabs(((x - -4.0) / y_m));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-2.7d-66)) .or. (.not. (x <= 7.3d-6))) then
        tmp = abs((x * ((1.0d0 - z) / y_m)))
    else
        tmp = abs(((x - (-4.0d0)) / y_m))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if ((x <= -2.7e-66) || !(x <= 7.3e-6)) {
		tmp = Math.abs((x * ((1.0 - z) / y_m)));
	} else {
		tmp = Math.abs(((x - -4.0) / y_m));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if (x <= -2.7e-66) or not (x <= 7.3e-6):
		tmp = math.fabs((x * ((1.0 - z) / y_m)))
	else:
		tmp = math.fabs(((x - -4.0) / y_m))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if ((x <= -2.7e-66) || !(x <= 7.3e-6))
		tmp = abs(Float64(x * Float64(Float64(1.0 - z) / y_m)));
	else
		tmp = abs(Float64(Float64(x - -4.0) / y_m));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if ((x <= -2.7e-66) || ~((x <= 7.3e-6)))
		tmp = abs((x * ((1.0 - z) / y_m)));
	else
		tmp = abs(((x - -4.0) / y_m));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[Or[LessEqual[x, -2.7e-66], N[Not[LessEqual[x, 7.3e-6]], $MachinePrecision]], N[Abs[N[(x * N[(N[(1.0 - z), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(x - -4.0), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-66} \lor \neg \left(x \leq 7.3 \cdot 10^{-6}\right):\\
\;\;\;\;\left|x \cdot \frac{1 - z}{y\_m}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.69999999999999996e-66 or 7.30000000000000041e-6 < x

    1. Initial program 85.3%

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|x \cdot \frac{\color{blue}{0 - \left(z - 1\right)}}{y}\right| \]
      8. associate-+l-96.5%

        \[\leadsto \left|x \cdot \frac{\color{blue}{\left(0 - z\right) + 1}}{y}\right| \]
      9. neg-sub096.5%

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

        \[\leadsto \left|x \cdot \frac{\color{blue}{1 + \left(-z\right)}}{y}\right| \]
      11. unsub-neg96.5%

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

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

    if -2.69999999999999996e-66 < x < 7.30000000000000041e-6

    1. Initial program 96.6%

      \[\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. Add Preprocessing
    4. Taylor expanded in z around 0 81.9%

      \[\leadsto \left|\color{blue}{\frac{4 + x}{y}}\right| \]
    5. Step-by-step derivation
      1. +-commutative81.9%

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y}\right| \]
      2. rem-square-sqrt44.2%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}}\right| \]
      3. fabs-sqr44.2%

        \[\leadsto \left|\color{blue}{\left|\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}\right|}\right| \]
      4. rem-square-sqrt81.9%

        \[\leadsto \left|\left|\color{blue}{\frac{x + 4}{y}}\right|\right| \]
      5. fabs-neg81.9%

        \[\leadsto \left|\color{blue}{\left|-\frac{x + 4}{y}\right|}\right| \]
      6. distribute-neg-frac81.9%

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

        \[\leadsto \left|\left|\frac{\color{blue}{\left(-x\right) + \left(-4\right)}}{y}\right|\right| \]
      8. metadata-eval81.9%

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

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

        \[\leadsto \left|\left|\frac{\color{blue}{-4 - x}}{y}\right|\right| \]
      11. rem-square-sqrt37.1%

        \[\leadsto \left|\left|\color{blue}{\sqrt{\frac{-4 - x}{y}} \cdot \sqrt{\frac{-4 - x}{y}}}\right|\right| \]
      12. fabs-sqr37.1%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{-4 - x}{y}} \cdot \sqrt{\frac{-4 - x}{y}}}\right| \]
      13. rem-square-sqrt81.9%

        \[\leadsto \left|\color{blue}{\frac{-4 - x}{y}}\right| \]
    6. Simplified81.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{-66} \lor \neg \left(x \leq 7.3 \cdot 10^{-6}\right):\\ \;\;\;\;\left|x \cdot \frac{1 - z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x - -4}{y}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 84.0% accurate, 1.0× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{+109}:\\ \;\;\;\;\left|\frac{x \cdot z}{y\_m}\right|\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{+111}:\\ \;\;\;\;\left|\frac{x - -4}{y\_m}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y\_m}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (if (<= z -8.5e+109)
   (fabs (/ (* x z) y_m))
   (if (<= z 3.6e+111) (fabs (/ (- x -4.0) y_m)) (fabs (* z (/ x y_m))))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double tmp;
	if (z <= -8.5e+109) {
		tmp = fabs(((x * z) / y_m));
	} else if (z <= 3.6e+111) {
		tmp = fabs(((x - -4.0) / y_m));
	} else {
		tmp = fabs((z * (x / y_m)));
	}
	return tmp;
}
y_m = abs(y)
real(8) function code(x, y_m, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-8.5d+109)) then
        tmp = abs(((x * z) / y_m))
    else if (z <= 3.6d+111) then
        tmp = abs(((x - (-4.0d0)) / y_m))
    else
        tmp = abs((z * (x / y_m)))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double tmp;
	if (z <= -8.5e+109) {
		tmp = Math.abs(((x * z) / y_m));
	} else if (z <= 3.6e+111) {
		tmp = Math.abs(((x - -4.0) / y_m));
	} else {
		tmp = Math.abs((z * (x / y_m)));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	tmp = 0
	if z <= -8.5e+109:
		tmp = math.fabs(((x * z) / y_m))
	elif z <= 3.6e+111:
		tmp = math.fabs(((x - -4.0) / y_m))
	else:
		tmp = math.fabs((z * (x / y_m)))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	tmp = 0.0
	if (z <= -8.5e+109)
		tmp = abs(Float64(Float64(x * z) / y_m));
	elseif (z <= 3.6e+111)
		tmp = abs(Float64(Float64(x - -4.0) / y_m));
	else
		tmp = abs(Float64(z * Float64(x / y_m)));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	tmp = 0.0;
	if (z <= -8.5e+109)
		tmp = abs(((x * z) / y_m));
	elseif (z <= 3.6e+111)
		tmp = abs(((x - -4.0) / y_m));
	else
		tmp = abs((z * (x / y_m)));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := If[LessEqual[z, -8.5e+109], N[Abs[N[(N[(x * z), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 3.6e+111], N[Abs[N[(N[(x - -4.0), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision], N[Abs[N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|

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

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

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


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

    1. Initial program 93.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.5000000000000004e109 < z < 3.6000000000000002e111

    1. Initial program 92.7%

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

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

      \[\leadsto \left|\color{blue}{\frac{4 + x}{y}}\right| \]
    5. Step-by-step derivation
      1. +-commutative89.4%

        \[\leadsto \left|\frac{\color{blue}{x + 4}}{y}\right| \]
      2. rem-square-sqrt52.7%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}}\right| \]
      3. fabs-sqr52.7%

        \[\leadsto \left|\color{blue}{\left|\sqrt{\frac{x + 4}{y}} \cdot \sqrt{\frac{x + 4}{y}}\right|}\right| \]
      4. rem-square-sqrt89.4%

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

        \[\leadsto \left|\color{blue}{\left|-\frac{x + 4}{y}\right|}\right| \]
      6. distribute-neg-frac89.4%

        \[\leadsto \left|\left|\color{blue}{\frac{-\left(x + 4\right)}{y}}\right|\right| \]
      7. distribute-neg-in89.4%

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

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

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

        \[\leadsto \left|\left|\frac{\color{blue}{-4 - x}}{y}\right|\right| \]
      11. rem-square-sqrt36.1%

        \[\leadsto \left|\left|\color{blue}{\sqrt{\frac{-4 - x}{y}} \cdot \sqrt{\frac{-4 - x}{y}}}\right|\right| \]
      12. fabs-sqr36.1%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{-4 - x}{y}} \cdot \sqrt{\frac{-4 - x}{y}}}\right| \]
      13. rem-square-sqrt89.4%

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

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

    if 3.6000000000000002e111 < z

    1. Initial program 79.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{+109}:\\ \;\;\;\;\left|\frac{x \cdot z}{y}\right|\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{+111}:\\ \;\;\;\;\left|\frac{x - -4}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 68.8% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 84.1%

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

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

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

    if -1.55000000000000004 < x < 4

    1. Initial program 96.8%

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

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

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

    \[\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} \]
  5. Add Preprocessing

Alternative 8: 40.4% accurate, 1.1× speedup?

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

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

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

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

    \[\leadsto \left|\color{blue}{\frac{4}{y}}\right| \]
  5. Add Preprocessing

Reproduce

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