fabs fraction 1

Percentage Accurate: 91.6% → 99.6%
Time: 6.0s
Alternatives: 8
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

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

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

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


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

    1. Initial program 90.4%

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

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

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

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

    if 1.6e-78 < y

    1. Initial program 88.0%

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

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

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

Alternative 2: 86.3% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.26e68 or -1.1e36 < z < -1.7e16 or 1.2999999999999999e68 < z

    1. Initial program 82.7%

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

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
      3. expm1-log1p-u46.5%

        \[\leadsto \left|\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x}{y} \cdot \left(-z\right)\right)\right)}\right| \]
      4. expm1-udef37.0%

        \[\leadsto \left|\color{blue}{e^{\mathsf{log1p}\left(\frac{x}{y} \cdot \left(-z\right)\right)} - 1}\right| \]
      5. associate-*l/32.7%

        \[\leadsto \left|e^{\mathsf{log1p}\left(\color{blue}{\frac{x \cdot \left(-z\right)}{y}}\right)} - 1\right| \]
      6. div-inv32.7%

        \[\leadsto \left|e^{\mathsf{log1p}\left(\color{blue}{\left(x \cdot \left(-z\right)\right) \cdot \frac{1}{y}}\right)} - 1\right| \]
      7. associate-*r*35.7%

        \[\leadsto \left|e^{\mathsf{log1p}\left(\color{blue}{x \cdot \left(\left(-z\right) \cdot \frac{1}{y}\right)}\right)} - 1\right| \]
      8. div-inv35.7%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \color{blue}{\frac{-z}{y}}\right)} - 1\right| \]
      9. add-sqr-sqrt20.0%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\color{blue}{\sqrt{-z} \cdot \sqrt{-z}}}{y}\right)} - 1\right| \]
      10. sqrt-unprod26.1%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}}}{y}\right)} - 1\right| \]
      11. sqr-neg26.1%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\sqrt{\color{blue}{z \cdot z}}}{y}\right)} - 1\right| \]
      12. sqrt-unprod16.2%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}{y}\right)} - 1\right| \]
      13. add-sqr-sqrt32.4%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\color{blue}{z}}{y}\right)} - 1\right| \]
    6. Applied egg-rr32.4%

      \[\leadsto \left|\color{blue}{e^{\mathsf{log1p}\left(x \cdot \frac{z}{y}\right)} - 1}\right| \]
    7. Step-by-step derivation
      1. expm1-def49.0%

        \[\leadsto \left|\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x \cdot \frac{z}{y}\right)\right)}\right| \]
      2. expm1-log1p85.7%

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

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

    if -1.26e68 < z < -1.1e36 or -1.7e16 < z < 1.2999999999999999e68

    1. Initial program 94.2%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.26 \cdot 10^{+68} \lor \neg \left(z \leq -1.1 \cdot 10^{+36}\right) \land \left(z \leq -1.7 \cdot 10^{+16} \lor \neg \left(z \leq 1.3 \cdot 10^{+68}\right)\right):\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{-4 - x}{y}\right|\\ \end{array} \]

Alternative 3: 69.3% accurate, 1.0× speedup?

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

\mathbf{elif}\;x \leq -1.25 \cdot 10^{-15}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;x \leq 5.8 \cdot 10^{+170}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.1999999999999999e32 or 5.8000000000000001e170 < x

    1. Initial program 79.5%

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

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

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

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

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

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

    if -3.1999999999999999e32 < x < -1.25e-15 or 3.0000000000000001e-27 < x < 5.8000000000000001e170

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
      3. expm1-log1p-u43.2%

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

        \[\leadsto \left|\color{blue}{e^{\mathsf{log1p}\left(\frac{x}{y} \cdot \left(-z\right)\right)} - 1}\right| \]
      5. associate-*l/29.5%

        \[\leadsto \left|e^{\mathsf{log1p}\left(\color{blue}{\frac{x \cdot \left(-z\right)}{y}}\right)} - 1\right| \]
      6. div-inv29.5%

        \[\leadsto \left|e^{\mathsf{log1p}\left(\color{blue}{\left(x \cdot \left(-z\right)\right) \cdot \frac{1}{y}}\right)} - 1\right| \]
      7. associate-*r*34.9%

        \[\leadsto \left|e^{\mathsf{log1p}\left(\color{blue}{x \cdot \left(\left(-z\right) \cdot \frac{1}{y}\right)}\right)} - 1\right| \]
      8. div-inv34.9%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \color{blue}{\frac{-z}{y}}\right)} - 1\right| \]
      9. add-sqr-sqrt16.6%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\color{blue}{\sqrt{-z} \cdot \sqrt{-z}}}{y}\right)} - 1\right| \]
      10. sqrt-unprod23.6%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}}}{y}\right)} - 1\right| \]
      11. sqr-neg23.6%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\sqrt{\color{blue}{z \cdot z}}}{y}\right)} - 1\right| \]
      12. sqrt-unprod14.6%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\color{blue}{\sqrt{z} \cdot \sqrt{z}}}{y}\right)} - 1\right| \]
      13. add-sqr-sqrt33.2%

        \[\leadsto \left|e^{\mathsf{log1p}\left(x \cdot \frac{\color{blue}{z}}{y}\right)} - 1\right| \]
    6. Applied egg-rr33.2%

      \[\leadsto \left|\color{blue}{e^{\mathsf{log1p}\left(x \cdot \frac{z}{y}\right)} - 1}\right| \]
    7. Step-by-step derivation
      1. expm1-def41.5%

        \[\leadsto \left|\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x \cdot \frac{z}{y}\right)\right)}\right| \]
      2. expm1-log1p79.0%

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

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

    if -1.25e-15 < x < 3.0000000000000001e-27

    1. Initial program 92.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{+32}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-15}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-27}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{+170}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \end{array} \]

Alternative 4: 99.7% accurate, 1.0× speedup?

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

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


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

    1. Initial program 91.4%

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

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

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

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

    if 9.99999999999999972e58 < y

    1. Initial program 82.6%

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

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

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

Alternative 5: 69.1% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;x \leq 3.2 \cdot 10^{+171}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.2000000000000002e-16 or 1.15e-27 < x < 3.20000000000000011e171

    1. Initial program 91.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{x}{\frac{y}{z}}}\right| \]
      2. associate-/r/73.7%

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

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

    if -4.2000000000000002e-16 < x < 1.15e-27

    1. Initial program 92.7%

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

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

    if 3.20000000000000011e171 < x

    1. Initial program 72.4%

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

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

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

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

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

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

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

Alternative 6: 95.9% accurate, 1.0× speedup?

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

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

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

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

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

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

Alternative 7: 69.0% accurate, 1.0× speedup?

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

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


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

    1. Initial program 85.8%

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

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

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

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

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

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

    if -1.5 < x < 4

    1. Initial program 93.2%

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

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

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

Alternative 8: 39.7% accurate, 1.1× speedup?

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

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

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

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

Reproduce

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