fabs fraction 1

Percentage Accurate: 92.1% → 99.8%
Time: 7.7s
Alternatives: 11
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 11 alternatives:

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

Initial Program: 92.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.5× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} \mathbf{if}\;y_m \leq 2 \cdot 10^{+35}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{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 2e+35)
   (fabs (/ (- (+ 4.0 x) (* x z)) 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 <= 2e+35) {
		tmp = fabs((((4.0 + x) - (x * z)) / 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 <= 2e+35)
		tmp = abs(Float64(Float64(Float64(4.0 + x) - Float64(x * z)) / 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, 2e+35], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] - N[(x * z), $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 2 \cdot 10^{+35}:\\
\;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{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 < 1.9999999999999999e35

    1. Initial program 91.9%

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

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

    if 1.9999999999999999e35 < y

    1. Initial program 94.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2 \cdot 10^{+35}:\\ \;\;\;\;\left|\frac{\left(4 + x\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: 97.4% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := \frac{4 + x}{y_m} - z \cdot \frac{x}{y_m}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+82}:\\ \;\;\;\;\left|t_0\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - x \cdot z}{y_m}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (let* ((t_0 (- (/ (+ 4.0 x) y_m) (* z (/ x y_m)))))
   (if (<= t_0 -2e+82) (fabs t_0) (fabs (/ (- (+ 4.0 x) (* x z)) y_m)))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double t_0 = ((4.0 + x) / y_m) - (z * (x / y_m));
	double tmp;
	if (t_0 <= -2e+82) {
		tmp = fabs(t_0);
	} else {
		tmp = fabs((((4.0 + x) - (x * z)) / 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) :: t_0
    real(8) :: tmp
    t_0 = ((4.0d0 + x) / y_m) - (z * (x / y_m))
    if (t_0 <= (-2d+82)) then
        tmp = abs(t_0)
    else
        tmp = abs((((4.0d0 + x) - (x * z)) / 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 t_0 = ((4.0 + x) / y_m) - (z * (x / y_m));
	double tmp;
	if (t_0 <= -2e+82) {
		tmp = Math.abs(t_0);
	} else {
		tmp = Math.abs((((4.0 + x) - (x * z)) / y_m));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	t_0 = ((4.0 + x) / y_m) - (z * (x / y_m))
	tmp = 0
	if t_0 <= -2e+82:
		tmp = math.fabs(t_0)
	else:
		tmp = math.fabs((((4.0 + x) - (x * z)) / y_m))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	t_0 = Float64(Float64(Float64(4.0 + x) / y_m) - Float64(z * Float64(x / y_m)))
	tmp = 0.0
	if (t_0 <= -2e+82)
		tmp = abs(t_0);
	else
		tmp = abs(Float64(Float64(Float64(4.0 + x) - Float64(x * z)) / y_m));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	t_0 = ((4.0 + x) / y_m) - (z * (x / y_m));
	tmp = 0.0;
	if (t_0 <= -2e+82)
		tmp = abs(t_0);
	else
		tmp = abs((((4.0 + x) - (x * z)) / y_m));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := Block[{t$95$0 = N[(N[(N[(4.0 + x), $MachinePrecision] / y$95$m), $MachinePrecision] - N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+82], N[Abs[t$95$0], $MachinePrecision], N[Abs[N[(N[(N[(4.0 + x), $MachinePrecision] - N[(x * z), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := \frac{4 + x}{y_m} - z \cdot \frac{x}{y_m}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+82}:\\
\;\;\;\;\left|t_0\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z)) < -1.9999999999999999e82

    1. Initial program 99.9%

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

    if -1.9999999999999999e82 < (-.f64 (/.f64 (+.f64 x 4) y) (*.f64 (/.f64 x y) z))

    1. Initial program 89.5%

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

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

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

Alternative 3: 68.7% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := \left|z \cdot \frac{x}{y_m}\right|\\ t_1 := \left|\frac{x}{y_m}\right|\\ \mathbf{if}\;x \leq -8.6 \cdot 10^{+189}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -8 \cdot 10^{+34}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-35}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-25}:\\ \;\;\;\;\left|\frac{4}{y_m}\right|\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{+208} \lor \neg \left(x \leq 1.9 \cdot 10^{+295}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (let* ((t_0 (fabs (* z (/ x y_m)))) (t_1 (fabs (/ x y_m))))
   (if (<= x -8.6e+189)
     t_0
     (if (<= x -8e+34)
       t_1
       (if (<= x -5.8e-35)
         t_0
         (if (<= x 1.75e-25)
           (fabs (/ 4.0 y_m))
           (if (or (<= x 7.2e+208) (not (<= x 1.9e+295))) t_0 t_1)))))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double t_0 = fabs((z * (x / y_m)));
	double t_1 = fabs((x / y_m));
	double tmp;
	if (x <= -8.6e+189) {
		tmp = t_0;
	} else if (x <= -8e+34) {
		tmp = t_1;
	} else if (x <= -5.8e-35) {
		tmp = t_0;
	} else if (x <= 1.75e-25) {
		tmp = fabs((4.0 / y_m));
	} else if ((x <= 7.2e+208) || !(x <= 1.9e+295)) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = abs((z * (x / y_m)))
    t_1 = abs((x / y_m))
    if (x <= (-8.6d+189)) then
        tmp = t_0
    else if (x <= (-8d+34)) then
        tmp = t_1
    else if (x <= (-5.8d-35)) then
        tmp = t_0
    else if (x <= 1.75d-25) then
        tmp = abs((4.0d0 / y_m))
    else if ((x <= 7.2d+208) .or. (.not. (x <= 1.9d+295))) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double t_0 = Math.abs((z * (x / y_m)));
	double t_1 = Math.abs((x / y_m));
	double tmp;
	if (x <= -8.6e+189) {
		tmp = t_0;
	} else if (x <= -8e+34) {
		tmp = t_1;
	} else if (x <= -5.8e-35) {
		tmp = t_0;
	} else if (x <= 1.75e-25) {
		tmp = Math.abs((4.0 / y_m));
	} else if ((x <= 7.2e+208) || !(x <= 1.9e+295)) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	t_0 = math.fabs((z * (x / y_m)))
	t_1 = math.fabs((x / y_m))
	tmp = 0
	if x <= -8.6e+189:
		tmp = t_0
	elif x <= -8e+34:
		tmp = t_1
	elif x <= -5.8e-35:
		tmp = t_0
	elif x <= 1.75e-25:
		tmp = math.fabs((4.0 / y_m))
	elif (x <= 7.2e+208) or not (x <= 1.9e+295):
		tmp = t_0
	else:
		tmp = t_1
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	t_0 = abs(Float64(z * Float64(x / y_m)))
	t_1 = abs(Float64(x / y_m))
	tmp = 0.0
	if (x <= -8.6e+189)
		tmp = t_0;
	elseif (x <= -8e+34)
		tmp = t_1;
	elseif (x <= -5.8e-35)
		tmp = t_0;
	elseif (x <= 1.75e-25)
		tmp = abs(Float64(4.0 / y_m));
	elseif ((x <= 7.2e+208) || !(x <= 1.9e+295))
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	t_0 = abs((z * (x / y_m)));
	t_1 = abs((x / y_m));
	tmp = 0.0;
	if (x <= -8.6e+189)
		tmp = t_0;
	elseif (x <= -8e+34)
		tmp = t_1;
	elseif (x <= -5.8e-35)
		tmp = t_0;
	elseif (x <= 1.75e-25)
		tmp = abs((4.0 / y_m));
	elseif ((x <= 7.2e+208) || ~((x <= 1.9e+295)))
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := Block[{t$95$0 = N[Abs[N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -8.6e+189], t$95$0, If[LessEqual[x, -8e+34], t$95$1, If[LessEqual[x, -5.8e-35], t$95$0, If[LessEqual[x, 1.75e-25], N[Abs[N[(4.0 / y$95$m), $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[x, 7.2e+208], N[Not[LessEqual[x, 1.9e+295]], $MachinePrecision]], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := \left|z \cdot \frac{x}{y_m}\right|\\
t_1 := \left|\frac{x}{y_m}\right|\\
\mathbf{if}\;x \leq -8.6 \cdot 10^{+189}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -8 \cdot 10^{+34}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -5.8 \cdot 10^{-35}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;x \leq 7.2 \cdot 10^{+208} \lor \neg \left(x \leq 1.9 \cdot 10^{+295}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -8.59999999999999995e189 or -7.99999999999999956e34 < x < -5.8000000000000004e-35 or 1.7500000000000001e-25 < x < 7.20000000000000005e208 or 1.9000000000000001e295 < x

    1. Initial program 92.1%

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

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

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

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

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

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    5. Step-by-step derivation
      1. add-sqr-sqrt36.4%

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

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

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

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

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

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

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

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

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

    if -8.59999999999999995e189 < x < -7.99999999999999956e34 or 7.20000000000000005e208 < x < 1.9000000000000001e295

    1. Initial program 85.7%

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

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

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

        \[\leadsto \left|\frac{\color{blue}{4}}{y} + \frac{x}{y}\right| \]
    4. Simplified77.9%

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

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

    if -5.8000000000000004e-35 < x < 1.7500000000000001e-25

    1. Initial program 95.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.6 \cdot 10^{+189}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -8 \cdot 10^{+34}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{-35}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 1.75 \cdot 10^{-25}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{+208} \lor \neg \left(x \leq 1.9 \cdot 10^{+295}\right):\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \end{array} \]

Alternative 4: 68.6% accurate, 0.9× speedup?

\[\begin{array}{l} y_m = \left|y\right| \\ \begin{array}{l} t_0 := \left|z \cdot \frac{x}{y_m}\right|\\ t_1 := \left|\frac{x}{y_m}\right|\\ \mathbf{if}\;x \leq -4.4 \cdot 10^{+191}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3 \cdot 10^{+34}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.8 \cdot 10^{-36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-25}:\\ \;\;\;\;\left|\frac{4}{y_m}\right|\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{+209}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{+296}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y_m}{x}}\right|\\ \end{array} \end{array} \]
y_m = (fabs.f64 y)
(FPCore (x y_m z)
 :precision binary64
 (let* ((t_0 (fabs (* z (/ x y_m)))) (t_1 (fabs (/ x y_m))))
   (if (<= x -4.4e+191)
     t_0
     (if (<= x -3e+34)
       t_1
       (if (<= x -7.8e-36)
         t_0
         (if (<= x 6.5e-25)
           (fabs (/ 4.0 y_m))
           (if (<= x 1.55e+209)
             t_0
             (if (<= x 1.1e+296) t_1 (fabs (/ z (/ y_m x)))))))))))
y_m = fabs(y);
double code(double x, double y_m, double z) {
	double t_0 = fabs((z * (x / y_m)));
	double t_1 = fabs((x / y_m));
	double tmp;
	if (x <= -4.4e+191) {
		tmp = t_0;
	} else if (x <= -3e+34) {
		tmp = t_1;
	} else if (x <= -7.8e-36) {
		tmp = t_0;
	} else if (x <= 6.5e-25) {
		tmp = fabs((4.0 / y_m));
	} else if (x <= 1.55e+209) {
		tmp = t_0;
	} else if (x <= 1.1e+296) {
		tmp = t_1;
	} else {
		tmp = fabs((z / (y_m / x)));
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = abs((z * (x / y_m)))
    t_1 = abs((x / y_m))
    if (x <= (-4.4d+191)) then
        tmp = t_0
    else if (x <= (-3d+34)) then
        tmp = t_1
    else if (x <= (-7.8d-36)) then
        tmp = t_0
    else if (x <= 6.5d-25) then
        tmp = abs((4.0d0 / y_m))
    else if (x <= 1.55d+209) then
        tmp = t_0
    else if (x <= 1.1d+296) then
        tmp = t_1
    else
        tmp = abs((z / (y_m / x)))
    end if
    code = tmp
end function
y_m = Math.abs(y);
public static double code(double x, double y_m, double z) {
	double t_0 = Math.abs((z * (x / y_m)));
	double t_1 = Math.abs((x / y_m));
	double tmp;
	if (x <= -4.4e+191) {
		tmp = t_0;
	} else if (x <= -3e+34) {
		tmp = t_1;
	} else if (x <= -7.8e-36) {
		tmp = t_0;
	} else if (x <= 6.5e-25) {
		tmp = Math.abs((4.0 / y_m));
	} else if (x <= 1.55e+209) {
		tmp = t_0;
	} else if (x <= 1.1e+296) {
		tmp = t_1;
	} else {
		tmp = Math.abs((z / (y_m / x)));
	}
	return tmp;
}
y_m = math.fabs(y)
def code(x, y_m, z):
	t_0 = math.fabs((z * (x / y_m)))
	t_1 = math.fabs((x / y_m))
	tmp = 0
	if x <= -4.4e+191:
		tmp = t_0
	elif x <= -3e+34:
		tmp = t_1
	elif x <= -7.8e-36:
		tmp = t_0
	elif x <= 6.5e-25:
		tmp = math.fabs((4.0 / y_m))
	elif x <= 1.55e+209:
		tmp = t_0
	elif x <= 1.1e+296:
		tmp = t_1
	else:
		tmp = math.fabs((z / (y_m / x)))
	return tmp
y_m = abs(y)
function code(x, y_m, z)
	t_0 = abs(Float64(z * Float64(x / y_m)))
	t_1 = abs(Float64(x / y_m))
	tmp = 0.0
	if (x <= -4.4e+191)
		tmp = t_0;
	elseif (x <= -3e+34)
		tmp = t_1;
	elseif (x <= -7.8e-36)
		tmp = t_0;
	elseif (x <= 6.5e-25)
		tmp = abs(Float64(4.0 / y_m));
	elseif (x <= 1.55e+209)
		tmp = t_0;
	elseif (x <= 1.1e+296)
		tmp = t_1;
	else
		tmp = abs(Float64(z / Float64(y_m / x)));
	end
	return tmp
end
y_m = abs(y);
function tmp_2 = code(x, y_m, z)
	t_0 = abs((z * (x / y_m)));
	t_1 = abs((x / y_m));
	tmp = 0.0;
	if (x <= -4.4e+191)
		tmp = t_0;
	elseif (x <= -3e+34)
		tmp = t_1;
	elseif (x <= -7.8e-36)
		tmp = t_0;
	elseif (x <= 6.5e-25)
		tmp = abs((4.0 / y_m));
	elseif (x <= 1.55e+209)
		tmp = t_0;
	elseif (x <= 1.1e+296)
		tmp = t_1;
	else
		tmp = abs((z / (y_m / x)));
	end
	tmp_2 = tmp;
end
y_m = N[Abs[y], $MachinePrecision]
code[x_, y$95$m_, z_] := Block[{t$95$0 = N[Abs[N[(z * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(x / y$95$m), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -4.4e+191], t$95$0, If[LessEqual[x, -3e+34], t$95$1, If[LessEqual[x, -7.8e-36], t$95$0, If[LessEqual[x, 6.5e-25], N[Abs[N[(4.0 / y$95$m), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 1.55e+209], t$95$0, If[LessEqual[x, 1.1e+296], t$95$1, N[Abs[N[(z / N[(y$95$m / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]]]
\begin{array}{l}
y_m = \left|y\right|

\\
\begin{array}{l}
t_0 := \left|z \cdot \frac{x}{y_m}\right|\\
t_1 := \left|\frac{x}{y_m}\right|\\
\mathbf{if}\;x \leq -4.4 \cdot 10^{+191}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -3 \cdot 10^{+34}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -7.8 \cdot 10^{-36}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 6.5 \cdot 10^{-25}:\\
\;\;\;\;\left|\frac{4}{y_m}\right|\\

\mathbf{elif}\;x \leq 1.55 \cdot 10^{+209}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 1.1 \cdot 10^{+296}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -4.4e191 or -3.00000000000000018e34 < x < -7.8000000000000001e-36 or 6.5e-25 < x < 1.55e209

    1. Initial program 92.0%

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

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

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

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

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

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    5. Step-by-step derivation
      1. add-sqr-sqrt36.0%

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

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

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

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

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

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

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

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

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

    if -4.4e191 < x < -3.00000000000000018e34 or 1.55e209 < x < 1.10000000000000007e296

    1. Initial program 85.7%

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

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

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

        \[\leadsto \left|\frac{\color{blue}{4}}{y} + \frac{x}{y}\right| \]
    4. Simplified77.9%

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

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

    if -7.8000000000000001e-36 < x < 6.5e-25

    1. Initial program 95.8%

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

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

    if 1.10000000000000007e296 < x

    1. Initial program 99.2%

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

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

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

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

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

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    5. Step-by-step derivation
      1. add-sqr-sqrt50.0%

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{x \cdot z}{y}}\right| \]
      7. expm1-log1p-u0.0%

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

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

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

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

        \[\leadsto \left|e^{\mathsf{log1p}\left(\color{blue}{\frac{1 \cdot z}{\frac{y}{x}}}\right)} - 1\right| \]
      12. *-un-lft-identity0.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.4 \cdot 10^{+191}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -3 \cdot 10^{+34}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -7.8 \cdot 10^{-36}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-25}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{+209}:\\ \;\;\;\;\left|z \cdot \frac{x}{y}\right|\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{+296}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{z}{\frac{y}{x}}\right|\\ \end{array} \]

Alternative 5: 67.9% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;x \leq -4.8 \cdot 10^{-36}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 3.1 \cdot 10^{-25}:\\
\;\;\;\;\left|\frac{4}{y_m}\right|\\

\mathbf{elif}\;x \leq 5.5 \cdot 10^{+155}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.04999999999999998e34 or 5.5000000000000001e155 < x

    1. Initial program 87.0%

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

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

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

        \[\leadsto \left|\frac{\color{blue}{4}}{y} + \frac{x}{y}\right| \]
    4. Simplified70.8%

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

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

    if -3.04999999999999998e34 < x < -4.8e-36 or 3.09999999999999995e-25 < x < 5.5000000000000001e155

    1. Initial program 95.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|e^{\mathsf{log1p}\left(\color{blue}{\frac{1 \cdot z}{\frac{y}{x}}}\right)} - 1\right| \]
      12. *-un-lft-identity15.3%

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

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

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

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

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

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

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

    if -4.8e-36 < x < 3.09999999999999995e-25

    1. Initial program 95.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.05 \cdot 10^{+34}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-36}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-25}:\\ \;\;\;\;\left|\frac{4}{y}\right|\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+155}:\\ \;\;\;\;\left|x \cdot \frac{z}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \end{array} \]

Alternative 6: 99.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+16} \lor \neg \left(x \leq 7.2 \cdot 10^{+15}\right):\\
\;\;\;\;\left|\frac{x}{\frac{y_m}{1 - z}}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.4e16 or 7.2e15 < x

    1. Initial program 88.0%

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

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

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

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

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

    if -2.4e16 < x < 7.2e15

    1. Initial program 96.3%

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

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

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

Alternative 7: 86.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{-35} \lor \neg \left(x \leq 6.2 \cdot 10^{-25}\right):\\
\;\;\;\;\left|x \cdot \frac{z + -1}{y_m}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.49999999999999994e-35 or 6.19999999999999989e-25 < x

    1. Initial program 89.5%

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

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

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

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

    if -1.49999999999999994e-35 < x < 6.19999999999999989e-25

    1. Initial program 95.8%

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

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

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

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

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

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

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

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

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

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

Alternative 8: 86.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-35} \lor \neg \left(x \leq 8.5 \cdot 10^{-26}\right):\\
\;\;\;\;\left|\frac{x}{\frac{y_m}{1 - z}}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.8000000000000001e-35 or 8.50000000000000004e-26 < x

    1. Initial program 89.5%

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

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

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

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

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

    if -3.8000000000000001e-35 < x < 8.50000000000000004e-26

    1. Initial program 95.8%

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

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

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

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

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

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

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

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

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

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

Alternative 9: 84.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.9 \cdot 10^{+66}:\\
\;\;\;\;\left|z \cdot \frac{x}{y_m}\right|\\

\mathbf{elif}\;z \leq 1.45 \cdot 10^{+155}:\\
\;\;\;\;\left|\frac{-4 - x}{y_m}\right|\\

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


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

    1. Initial program 97.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.9000000000000004e66 < z < 1.45e155

    1. Initial program 92.8%

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right| \]
    2. Simplified97.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 89.4%

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

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

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

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

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

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

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

    if 1.45e155 < z

    1. Initial program 83.8%

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

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

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

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

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

      \[\leadsto \left|\color{blue}{\frac{x}{y} \cdot \left(-z\right)}\right| \]
    5. Step-by-step derivation
      1. add-sqr-sqrt0.0%

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{x \cdot z}{y}}\right| \]
      7. expm1-log1p-u42.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 68.7% accurate, 1.0× speedup?

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

    1. Initial program 88.5%

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

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

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

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

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

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

    if -10.5 < x < 4

    1. Initial program 96.1%

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

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

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

Alternative 11: 39.8% 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 92.5%

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

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

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

Reproduce

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