Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5

Percentage Accurate: 100.0% → 100.0%
Time: 4.8s
Alternatives: 7
Speedup: 2.0×

Specification

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

\\
\frac{\left|x - y\right|}{\left|y\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 7 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: 100.0% accurate, 1.0× speedup?

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

\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}

Alternative 1: 100.0% accurate, 2.0× speedup?

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

\\
\left|1 - \frac{x}{y}\right|
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{\left|x - y\right|}{\left|y\right|} \]
  2. Taylor expanded in x around -inf 100.0%

    \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
  3. Step-by-step derivation
    1. fabs-neg100.0%

      \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
    2. mul-1-neg100.0%

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

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

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

      \[\leadsto \left|\color{blue}{\frac{y}{y} - \frac{x}{y}}\right| \]
    6. *-inverses100.0%

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

    \[\leadsto \color{blue}{\left|1 - \frac{x}{y}\right|} \]
  5. Final simplification100.0%

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

Alternative 2: 74.3% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.25 \cdot 10^{+79} \lor \neg \left(y \leq 1.8 \cdot 10^{-37}\right):\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -1.25e+79) (not (<= y 1.8e-37))) (/ y (+ x y)) (fabs (/ x y))))
double code(double x, double y) {
	double tmp;
	if ((y <= -1.25e+79) || !(y <= 1.8e-37)) {
		tmp = y / (x + y);
	} else {
		tmp = fabs((x / y));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y <= (-1.25d+79)) .or. (.not. (y <= 1.8d-37))) then
        tmp = y / (x + y)
    else
        tmp = abs((x / y))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -1.25e+79) || !(y <= 1.8e-37)) {
		tmp = y / (x + y);
	} else {
		tmp = Math.abs((x / y));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -1.25e+79) or not (y <= 1.8e-37):
		tmp = y / (x + y)
	else:
		tmp = math.fabs((x / y))
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -1.25e+79) || !(y <= 1.8e-37))
		tmp = Float64(y / Float64(x + y));
	else
		tmp = abs(Float64(x / y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -1.25e+79) || ~((y <= 1.8e-37)))
		tmp = y / (x + y);
	else
		tmp = abs((x / y));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -1.25e+79], N[Not[LessEqual[y, 1.8e-37]], $MachinePrecision]], N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{+79} \lor \neg \left(y \leq 1.8 \cdot 10^{-37}\right):\\
\;\;\;\;\frac{y}{x + y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.25e79 or 1.80000000000000004e-37 < y

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{x - y}{y}\right|} \]
      6. rem-square-sqrt12.5%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
      7. fabs-sqr12.5%

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt13.9%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub13.9%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg13.9%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses13.9%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval13.9%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative13.9%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified13.9%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    5. Step-by-step derivation
      1. +-commutative13.9%

        \[\leadsto \color{blue}{\frac{x}{y} + -1} \]
      2. metadata-eval13.9%

        \[\leadsto \frac{x}{y} + \color{blue}{\left(-1\right)} \]
      3. sub-neg13.9%

        \[\leadsto \color{blue}{\frac{x}{y} - 1} \]
      4. *-inverses13.9%

        \[\leadsto \frac{x}{y} - \color{blue}{\frac{y}{y}} \]
      5. div-sub13.9%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      6. clear-num13.8%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
      7. associate-/r/13.9%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
      8. flip--4.2%

        \[\leadsto \frac{1}{y} \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \]
      9. associate-*r/4.2%

        \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    6. Applied egg-rr4.2%

      \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    7. Taylor expanded in y around inf 1.8%

      \[\leadsto \frac{\color{blue}{-1 \cdot y}}{x + y} \]
    8. Step-by-step derivation
      1. neg-mul-11.8%

        \[\leadsto \frac{\color{blue}{-y}}{x + y} \]
    9. Simplified1.8%

      \[\leadsto \frac{\color{blue}{-y}}{x + y} \]
    10. Step-by-step derivation
      1. expm1-log1p-u1.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-y}{x + y}\right)\right)} \]
      2. expm1-udef1.7%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{-y}{x + y}\right)} - 1} \]
      3. *-un-lft-identity1.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{1 \cdot \left(-y\right)}}{x + y}\right)} - 1 \]
      4. *-commutative1.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\left(-y\right) \cdot 1}}{x + y}\right)} - 1 \]
      5. *-commutative1.7%

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{-y}}{x + y}\right)} - 1 \]
      7. add-sqr-sqrt0.6%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{x + y}\right)} - 1 \]
      8. sqrt-unprod24.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{x + y}\right)} - 1 \]
      9. sqr-neg24.0%

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{x + y}\right)} - 1 \]
      11. add-sqr-sqrt80.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{y}}{x + y}\right)} - 1 \]
    11. Applied egg-rr80.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{y}{x + y}\right)} - 1} \]
    12. Step-by-step derivation
      1. expm1-def80.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y}{x + y}\right)\right)} \]
      2. expm1-log1p80.9%

        \[\leadsto \color{blue}{\frac{y}{x + y}} \]
    13. Simplified80.9%

      \[\leadsto \color{blue}{\frac{y}{x + y}} \]

    if -1.25e79 < y < 1.80000000000000004e-37

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

        \[\leadsto \left|\color{blue}{\frac{y}{y} - \frac{x}{y}}\right| \]
      6. *-inverses100.0%

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

      \[\leadsto \color{blue}{\left|1 - \frac{x}{y}\right|} \]
    5. Taylor expanded in x around inf 77.5%

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

        \[\leadsto \left|\color{blue}{-\frac{x}{y}}\right| \]
      2. distribute-frac-neg77.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.25 \cdot 10^{+79} \lor \neg \left(y \leq 1.8 \cdot 10^{-37}\right):\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \end{array} \]

Alternative 3: 58.4% accurate, 13.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y}{x + y}\\ \mathbf{if}\;y \leq -9.8 \cdot 10^{-132}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.1 \cdot 10^{-252}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-71}:\\ \;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-39}:\\ \;\;\;\;\frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ y (+ x y))))
   (if (<= y -9.8e-132)
     t_0
     (if (<= y 5.1e-252)
       (/ x y)
       (if (<= y 6.5e-71)
         (* x (/ (/ x y) (- y x)))
         (if (<= y 3.4e-39) (+ (/ x y) -1.0) t_0))))))
double code(double x, double y) {
	double t_0 = y / (x + y);
	double tmp;
	if (y <= -9.8e-132) {
		tmp = t_0;
	} else if (y <= 5.1e-252) {
		tmp = x / y;
	} else if (y <= 6.5e-71) {
		tmp = x * ((x / y) / (y - x));
	} else if (y <= 3.4e-39) {
		tmp = (x / y) + -1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = y / (x + y)
    if (y <= (-9.8d-132)) then
        tmp = t_0
    else if (y <= 5.1d-252) then
        tmp = x / y
    else if (y <= 6.5d-71) then
        tmp = x * ((x / y) / (y - x))
    else if (y <= 3.4d-39) then
        tmp = (x / y) + (-1.0d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = y / (x + y);
	double tmp;
	if (y <= -9.8e-132) {
		tmp = t_0;
	} else if (y <= 5.1e-252) {
		tmp = x / y;
	} else if (y <= 6.5e-71) {
		tmp = x * ((x / y) / (y - x));
	} else if (y <= 3.4e-39) {
		tmp = (x / y) + -1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = y / (x + y)
	tmp = 0
	if y <= -9.8e-132:
		tmp = t_0
	elif y <= 5.1e-252:
		tmp = x / y
	elif y <= 6.5e-71:
		tmp = x * ((x / y) / (y - x))
	elif y <= 3.4e-39:
		tmp = (x / y) + -1.0
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(y / Float64(x + y))
	tmp = 0.0
	if (y <= -9.8e-132)
		tmp = t_0;
	elseif (y <= 5.1e-252)
		tmp = Float64(x / y);
	elseif (y <= 6.5e-71)
		tmp = Float64(x * Float64(Float64(x / y) / Float64(y - x)));
	elseif (y <= 3.4e-39)
		tmp = Float64(Float64(x / y) + -1.0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = y / (x + y);
	tmp = 0.0;
	if (y <= -9.8e-132)
		tmp = t_0;
	elseif (y <= 5.1e-252)
		tmp = x / y;
	elseif (y <= 6.5e-71)
		tmp = x * ((x / y) / (y - x));
	elseif (y <= 3.4e-39)
		tmp = (x / y) + -1.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.8e-132], t$95$0, If[LessEqual[y, 5.1e-252], N[(x / y), $MachinePrecision], If[LessEqual[y, 6.5e-71], N[(x * N[(N[(x / y), $MachinePrecision] / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.4e-39], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{y}{x + y}\\
\mathbf{if}\;y \leq -9.8 \cdot 10^{-132}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 5.1 \cdot 10^{-252}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{elif}\;y \leq 6.5 \cdot 10^{-71}:\\
\;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\

\mathbf{elif}\;y \leq 3.4 \cdot 10^{-39}:\\
\;\;\;\;\frac{x}{y} + -1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -9.79999999999999961e-132 or 3.3999999999999999e-39 < y

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{x - y}{y}\right|} \]
      6. rem-square-sqrt15.5%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
      7. fabs-sqr15.5%

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt16.8%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub16.8%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg16.8%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses16.8%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval16.8%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative16.8%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified16.8%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    5. Step-by-step derivation
      1. +-commutative16.8%

        \[\leadsto \color{blue}{\frac{x}{y} + -1} \]
      2. metadata-eval16.8%

        \[\leadsto \frac{x}{y} + \color{blue}{\left(-1\right)} \]
      3. sub-neg16.8%

        \[\leadsto \color{blue}{\frac{x}{y} - 1} \]
      4. *-inverses16.8%

        \[\leadsto \frac{x}{y} - \color{blue}{\frac{y}{y}} \]
      5. div-sub16.8%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      6. clear-num16.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
      7. associate-/r/16.7%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
      8. flip--6.4%

        \[\leadsto \frac{1}{y} \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \]
      9. associate-*r/6.3%

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

      \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    7. Taylor expanded in y around inf 2.0%

      \[\leadsto \frac{\color{blue}{-1 \cdot y}}{x + y} \]
    8. Step-by-step derivation
      1. neg-mul-12.0%

        \[\leadsto \frac{\color{blue}{-y}}{x + y} \]
    9. Simplified2.0%

      \[\leadsto \frac{\color{blue}{-y}}{x + y} \]
    10. Step-by-step derivation
      1. expm1-log1p-u2.0%

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{-y}{x + y}\right)} - 1} \]
      3. *-un-lft-identity1.8%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{1 \cdot \left(-y\right)}}{x + y}\right)} - 1 \]
      4. *-commutative1.8%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\left(-y\right) \cdot 1}}{x + y}\right)} - 1 \]
      5. *-commutative1.8%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{1 \cdot \left(-y\right)}}{x + y}\right)} - 1 \]
      6. *-un-lft-identity1.8%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{-y}}{x + y}\right)} - 1 \]
      7. add-sqr-sqrt1.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{x + y}\right)} - 1 \]
      8. sqrt-unprod18.2%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{x + y}\right)} - 1 \]
      9. sqr-neg18.2%

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{x + y}\right)} - 1 \]
      11. add-sqr-sqrt70.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{y}}{x + y}\right)} - 1 \]
    11. Applied egg-rr70.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{y}{x + y}\right)} - 1} \]
    12. Step-by-step derivation
      1. expm1-def70.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y}{x + y}\right)\right)} \]
      2. expm1-log1p70.2%

        \[\leadsto \color{blue}{\frac{y}{x + y}} \]
    13. Simplified70.2%

      \[\leadsto \color{blue}{\frac{y}{x + y}} \]

    if -9.79999999999999961e-132 < y < 5.1000000000000004e-252

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{x - y}{y}\right|} \]
      6. rem-square-sqrt64.8%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
      7. fabs-sqr64.8%

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt65.2%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub65.2%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg65.2%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses65.2%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval65.2%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative65.2%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified65.2%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    5. Taylor expanded in x around inf 65.4%

      \[\leadsto \color{blue}{\frac{x}{y}} \]

    if 5.1000000000000004e-252 < y < 6.50000000000000005e-71

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

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

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
      7. fabs-sqr31.2%

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt31.9%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub31.9%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg31.9%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses31.9%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval31.9%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative31.9%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified31.9%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    5. Step-by-step derivation
      1. +-commutative31.9%

        \[\leadsto \color{blue}{\frac{x}{y} + -1} \]
      2. metadata-eval31.9%

        \[\leadsto \frac{x}{y} + \color{blue}{\left(-1\right)} \]
      3. sub-neg31.9%

        \[\leadsto \color{blue}{\frac{x}{y} - 1} \]
      4. *-inverses31.9%

        \[\leadsto \frac{x}{y} - \color{blue}{\frac{y}{y}} \]
      5. div-sub31.9%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      6. clear-num31.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
      7. associate-/r/31.8%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
      8. flip--28.9%

        \[\leadsto \frac{1}{y} \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \]
      9. associate-*r/23.2%

        \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    6. Applied egg-rr23.2%

      \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    7. Taylor expanded in y around 0 24.0%

      \[\leadsto \frac{\color{blue}{\frac{{x}^{2}}{y}}}{x + y} \]
    8. Step-by-step derivation
      1. unpow224.0%

        \[\leadsto \frac{\frac{\color{blue}{x \cdot x}}{y}}{x + y} \]
      2. associate-/l*27.5%

        \[\leadsto \frac{\color{blue}{\frac{x}{\frac{y}{x}}}}{x + y} \]
      3. associate-/r/27.5%

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot x}}{x + y} \]
    9. Simplified27.5%

      \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot x}}{x + y} \]
    10. Step-by-step derivation
      1. associate-*l/24.0%

        \[\leadsto \frac{\color{blue}{\frac{x \cdot x}{y}}}{x + y} \]
      2. *-un-lft-identity24.0%

        \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(x \cdot x\right)}}{y}}{x + y} \]
      3. associate-*l/24.0%

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

        \[\leadsto \color{blue}{\frac{-\frac{1}{y} \cdot \left(x \cdot x\right)}{-\left(x + y\right)}} \]
      5. div-inv24.0%

        \[\leadsto \color{blue}{\left(-\frac{1}{y} \cdot \left(x \cdot x\right)\right) \cdot \frac{1}{-\left(x + y\right)}} \]
      6. associate-*l/24.0%

        \[\leadsto \left(-\color{blue}{\frac{1 \cdot \left(x \cdot x\right)}{y}}\right) \cdot \frac{1}{-\left(x + y\right)} \]
      7. *-un-lft-identity24.0%

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

        \[\leadsto \color{blue}{\frac{-x \cdot x}{y}} \cdot \frac{1}{-\left(x + y\right)} \]
      9. add-sqr-sqrt24.0%

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

        \[\leadsto \frac{-x \cdot x}{\color{blue}{\sqrt{y \cdot y}}} \cdot \frac{1}{-\left(x + y\right)} \]
      11. sqr-neg17.5%

        \[\leadsto \frac{-x \cdot x}{\sqrt{\color{blue}{\left(-y\right) \cdot \left(-y\right)}}} \cdot \frac{1}{-\left(x + y\right)} \]
      12. sqrt-unprod0.0%

        \[\leadsto \frac{-x \cdot x}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \cdot \frac{1}{-\left(x + y\right)} \]
      13. add-sqr-sqrt38.8%

        \[\leadsto \frac{-x \cdot x}{\color{blue}{-y}} \cdot \frac{1}{-\left(x + y\right)} \]
      14. frac-2neg38.8%

        \[\leadsto \color{blue}{\frac{x \cdot x}{y}} \cdot \frac{1}{-\left(x + y\right)} \]
      15. associate-*r/38.7%

        \[\leadsto \color{blue}{\left(x \cdot \frac{x}{y}\right)} \cdot \frac{1}{-\left(x + y\right)} \]
      16. distribute-neg-in38.7%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\color{blue}{\left(-x\right) + \left(-y\right)}} \]
      17. neg-mul-138.7%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\color{blue}{-1 \cdot x} + \left(-y\right)} \]
      18. add-sqr-sqrt0.0%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \]
      19. sqrt-unprod39.5%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}} \]
      20. sqr-neg39.5%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \sqrt{\color{blue}{y \cdot y}}} \]
      21. sqrt-unprod39.4%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      22. add-sqr-sqrt39.4%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \color{blue}{y}} \]
      23. fma-def39.4%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\color{blue}{\mathsf{fma}\left(-1, x, y\right)}} \]
    11. Applied egg-rr39.4%

      \[\leadsto \color{blue}{\left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\mathsf{fma}\left(-1, x, y\right)}} \]
    12. Step-by-step derivation
      1. associate-*l*45.3%

        \[\leadsto \color{blue}{x \cdot \left(\frac{x}{y} \cdot \frac{1}{\mathsf{fma}\left(-1, x, y\right)}\right)} \]
      2. associate-*r/45.3%

        \[\leadsto x \cdot \color{blue}{\frac{\frac{x}{y} \cdot 1}{\mathsf{fma}\left(-1, x, y\right)}} \]
      3. *-rgt-identity45.3%

        \[\leadsto x \cdot \frac{\color{blue}{\frac{x}{y}}}{\mathsf{fma}\left(-1, x, y\right)} \]
      4. fma-udef45.3%

        \[\leadsto x \cdot \frac{\frac{x}{y}}{\color{blue}{-1 \cdot x + y}} \]
      5. neg-mul-145.3%

        \[\leadsto x \cdot \frac{\frac{x}{y}}{\color{blue}{\left(-x\right)} + y} \]
      6. +-commutative45.3%

        \[\leadsto x \cdot \frac{\frac{x}{y}}{\color{blue}{y + \left(-x\right)}} \]
      7. sub-neg45.3%

        \[\leadsto x \cdot \frac{\frac{x}{y}}{\color{blue}{y - x}} \]
    13. Simplified45.3%

      \[\leadsto \color{blue}{x \cdot \frac{\frac{x}{y}}{y - x}} \]

    if 6.50000000000000005e-71 < y < 3.3999999999999999e-39

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

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

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
      7. fabs-sqr63.2%

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt64.0%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub64.0%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg64.0%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses64.0%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval64.0%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative64.0%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified64.0%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification66.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.8 \cdot 10^{-132}:\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{elif}\;y \leq 5.1 \cdot 10^{-252}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-71}:\\ \;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-39}:\\ \;\;\;\;\frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x + y}\\ \end{array} \]

Alternative 4: 58.6% accurate, 13.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{-132}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-255}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{-73}:\\ \;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-39}:\\ \;\;\;\;\frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x + y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.45e-132)
   1.0
   (if (<= y 4.5e-255)
     (/ x y)
     (if (<= y 2.7e-73)
       (* x (/ (/ x y) (- y x)))
       (if (<= y 3.8e-39) (+ (/ x y) -1.0) (/ y (+ x y)))))))
double code(double x, double y) {
	double tmp;
	if (y <= -1.45e-132) {
		tmp = 1.0;
	} else if (y <= 4.5e-255) {
		tmp = x / y;
	} else if (y <= 2.7e-73) {
		tmp = x * ((x / y) / (y - x));
	} else if (y <= 3.8e-39) {
		tmp = (x / y) + -1.0;
	} else {
		tmp = y / (x + y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-1.45d-132)) then
        tmp = 1.0d0
    else if (y <= 4.5d-255) then
        tmp = x / y
    else if (y <= 2.7d-73) then
        tmp = x * ((x / y) / (y - x))
    else if (y <= 3.8d-39) then
        tmp = (x / y) + (-1.0d0)
    else
        tmp = y / (x + y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.45e-132) {
		tmp = 1.0;
	} else if (y <= 4.5e-255) {
		tmp = x / y;
	} else if (y <= 2.7e-73) {
		tmp = x * ((x / y) / (y - x));
	} else if (y <= 3.8e-39) {
		tmp = (x / y) + -1.0;
	} else {
		tmp = y / (x + y);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.45e-132:
		tmp = 1.0
	elif y <= 4.5e-255:
		tmp = x / y
	elif y <= 2.7e-73:
		tmp = x * ((x / y) / (y - x))
	elif y <= 3.8e-39:
		tmp = (x / y) + -1.0
	else:
		tmp = y / (x + y)
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.45e-132)
		tmp = 1.0;
	elseif (y <= 4.5e-255)
		tmp = Float64(x / y);
	elseif (y <= 2.7e-73)
		tmp = Float64(x * Float64(Float64(x / y) / Float64(y - x)));
	elseif (y <= 3.8e-39)
		tmp = Float64(Float64(x / y) + -1.0);
	else
		tmp = Float64(y / Float64(x + y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.45e-132)
		tmp = 1.0;
	elseif (y <= 4.5e-255)
		tmp = x / y;
	elseif (y <= 2.7e-73)
		tmp = x * ((x / y) / (y - x));
	elseif (y <= 3.8e-39)
		tmp = (x / y) + -1.0;
	else
		tmp = y / (x + y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.45e-132], 1.0, If[LessEqual[y, 4.5e-255], N[(x / y), $MachinePrecision], If[LessEqual[y, 2.7e-73], N[(x * N[(N[(x / y), $MachinePrecision] / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.8e-39], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision], N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{-132}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 4.5 \cdot 10^{-255}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{elif}\;y \leq 2.7 \cdot 10^{-73}:\\
\;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\

\mathbf{elif}\;y \leq 3.8 \cdot 10^{-39}:\\
\;\;\;\;\frac{x}{y} + -1\\

\mathbf{else}:\\
\;\;\;\;\frac{y}{x + y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if y < -1.44999999999999992e-132

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

        \[\leadsto \left|\color{blue}{\frac{y}{y} - \frac{x}{y}}\right| \]
      6. *-inverses100.0%

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

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

      \[\leadsto \left|\color{blue}{1}\right| \]

    if -1.44999999999999992e-132 < y < 4.49999999999999979e-255

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{x - y}{y}\right|} \]
      6. rem-square-sqrt64.8%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
      7. fabs-sqr64.8%

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt65.2%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub65.2%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg65.2%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses65.2%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval65.2%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative65.2%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified65.2%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    5. Taylor expanded in x around inf 65.4%

      \[\leadsto \color{blue}{\frac{x}{y}} \]

    if 4.49999999999999979e-255 < y < 2.69999999999999994e-73

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

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

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
      7. fabs-sqr31.2%

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt31.9%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub31.9%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg31.9%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses31.9%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval31.9%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative31.9%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified31.9%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    5. Step-by-step derivation
      1. +-commutative31.9%

        \[\leadsto \color{blue}{\frac{x}{y} + -1} \]
      2. metadata-eval31.9%

        \[\leadsto \frac{x}{y} + \color{blue}{\left(-1\right)} \]
      3. sub-neg31.9%

        \[\leadsto \color{blue}{\frac{x}{y} - 1} \]
      4. *-inverses31.9%

        \[\leadsto \frac{x}{y} - \color{blue}{\frac{y}{y}} \]
      5. div-sub31.9%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      6. clear-num31.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
      7. associate-/r/31.8%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
      8. flip--28.9%

        \[\leadsto \frac{1}{y} \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \]
      9. associate-*r/23.2%

        \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    6. Applied egg-rr23.2%

      \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    7. Taylor expanded in y around 0 24.0%

      \[\leadsto \frac{\color{blue}{\frac{{x}^{2}}{y}}}{x + y} \]
    8. Step-by-step derivation
      1. unpow224.0%

        \[\leadsto \frac{\frac{\color{blue}{x \cdot x}}{y}}{x + y} \]
      2. associate-/l*27.5%

        \[\leadsto \frac{\color{blue}{\frac{x}{\frac{y}{x}}}}{x + y} \]
      3. associate-/r/27.5%

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot x}}{x + y} \]
    9. Simplified27.5%

      \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot x}}{x + y} \]
    10. Step-by-step derivation
      1. associate-*l/24.0%

        \[\leadsto \frac{\color{blue}{\frac{x \cdot x}{y}}}{x + y} \]
      2. *-un-lft-identity24.0%

        \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(x \cdot x\right)}}{y}}{x + y} \]
      3. associate-*l/24.0%

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

        \[\leadsto \color{blue}{\frac{-\frac{1}{y} \cdot \left(x \cdot x\right)}{-\left(x + y\right)}} \]
      5. div-inv24.0%

        \[\leadsto \color{blue}{\left(-\frac{1}{y} \cdot \left(x \cdot x\right)\right) \cdot \frac{1}{-\left(x + y\right)}} \]
      6. associate-*l/24.0%

        \[\leadsto \left(-\color{blue}{\frac{1 \cdot \left(x \cdot x\right)}{y}}\right) \cdot \frac{1}{-\left(x + y\right)} \]
      7. *-un-lft-identity24.0%

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

        \[\leadsto \color{blue}{\frac{-x \cdot x}{y}} \cdot \frac{1}{-\left(x + y\right)} \]
      9. add-sqr-sqrt24.0%

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

        \[\leadsto \frac{-x \cdot x}{\color{blue}{\sqrt{y \cdot y}}} \cdot \frac{1}{-\left(x + y\right)} \]
      11. sqr-neg17.5%

        \[\leadsto \frac{-x \cdot x}{\sqrt{\color{blue}{\left(-y\right) \cdot \left(-y\right)}}} \cdot \frac{1}{-\left(x + y\right)} \]
      12. sqrt-unprod0.0%

        \[\leadsto \frac{-x \cdot x}{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \cdot \frac{1}{-\left(x + y\right)} \]
      13. add-sqr-sqrt38.8%

        \[\leadsto \frac{-x \cdot x}{\color{blue}{-y}} \cdot \frac{1}{-\left(x + y\right)} \]
      14. frac-2neg38.8%

        \[\leadsto \color{blue}{\frac{x \cdot x}{y}} \cdot \frac{1}{-\left(x + y\right)} \]
      15. associate-*r/38.7%

        \[\leadsto \color{blue}{\left(x \cdot \frac{x}{y}\right)} \cdot \frac{1}{-\left(x + y\right)} \]
      16. distribute-neg-in38.7%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\color{blue}{\left(-x\right) + \left(-y\right)}} \]
      17. neg-mul-138.7%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\color{blue}{-1 \cdot x} + \left(-y\right)} \]
      18. add-sqr-sqrt0.0%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}} \]
      19. sqrt-unprod39.5%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}} \]
      20. sqr-neg39.5%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \sqrt{\color{blue}{y \cdot y}}} \]
      21. sqrt-unprod39.4%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      22. add-sqr-sqrt39.4%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{-1 \cdot x + \color{blue}{y}} \]
      23. fma-def39.4%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\color{blue}{\mathsf{fma}\left(-1, x, y\right)}} \]
    11. Applied egg-rr39.4%

      \[\leadsto \color{blue}{\left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\mathsf{fma}\left(-1, x, y\right)}} \]
    12. Step-by-step derivation
      1. associate-*l*45.3%

        \[\leadsto \color{blue}{x \cdot \left(\frac{x}{y} \cdot \frac{1}{\mathsf{fma}\left(-1, x, y\right)}\right)} \]
      2. associate-*r/45.3%

        \[\leadsto x \cdot \color{blue}{\frac{\frac{x}{y} \cdot 1}{\mathsf{fma}\left(-1, x, y\right)}} \]
      3. *-rgt-identity45.3%

        \[\leadsto x \cdot \frac{\color{blue}{\frac{x}{y}}}{\mathsf{fma}\left(-1, x, y\right)} \]
      4. fma-udef45.3%

        \[\leadsto x \cdot \frac{\frac{x}{y}}{\color{blue}{-1 \cdot x + y}} \]
      5. neg-mul-145.3%

        \[\leadsto x \cdot \frac{\frac{x}{y}}{\color{blue}{\left(-x\right)} + y} \]
      6. +-commutative45.3%

        \[\leadsto x \cdot \frac{\frac{x}{y}}{\color{blue}{y + \left(-x\right)}} \]
      7. sub-neg45.3%

        \[\leadsto x \cdot \frac{\frac{x}{y}}{\color{blue}{y - x}} \]
    13. Simplified45.3%

      \[\leadsto \color{blue}{x \cdot \frac{\frac{x}{y}}{y - x}} \]

    if 2.69999999999999994e-73 < y < 3.8000000000000002e-39

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

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

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
      7. fabs-sqr63.2%

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt64.0%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub64.0%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg64.0%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses64.0%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval64.0%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative64.0%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified64.0%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]

    if 3.8000000000000002e-39 < y

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{x - y}{y}\right|} \]
      6. rem-square-sqrt13.6%

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

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt15.0%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub15.0%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg15.0%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses15.0%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval15.0%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative15.0%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified15.0%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    5. Step-by-step derivation
      1. +-commutative15.0%

        \[\leadsto \color{blue}{\frac{x}{y} + -1} \]
      2. metadata-eval15.0%

        \[\leadsto \frac{x}{y} + \color{blue}{\left(-1\right)} \]
      3. sub-neg15.0%

        \[\leadsto \color{blue}{\frac{x}{y} - 1} \]
      4. *-inverses15.0%

        \[\leadsto \frac{x}{y} - \color{blue}{\frac{y}{y}} \]
      5. div-sub15.0%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      6. clear-num14.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
      7. associate-/r/14.9%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
      8. flip--6.7%

        \[\leadsto \frac{1}{y} \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \]
      9. associate-*r/6.6%

        \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    6. Applied egg-rr6.6%

      \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    7. Taylor expanded in y around inf 1.8%

      \[\leadsto \frac{\color{blue}{-1 \cdot y}}{x + y} \]
    8. Step-by-step derivation
      1. neg-mul-11.8%

        \[\leadsto \frac{\color{blue}{-y}}{x + y} \]
    9. Simplified1.8%

      \[\leadsto \frac{\color{blue}{-y}}{x + y} \]
    10. Step-by-step derivation
      1. expm1-log1p-u1.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-y}{x + y}\right)\right)} \]
      2. expm1-udef1.7%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{-y}{x + y}\right)} - 1} \]
      3. *-un-lft-identity1.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{1 \cdot \left(-y\right)}}{x + y}\right)} - 1 \]
      4. *-commutative1.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\left(-y\right) \cdot 1}}{x + y}\right)} - 1 \]
      5. *-commutative1.7%

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{-y}}{x + y}\right)} - 1 \]
      7. add-sqr-sqrt0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{x + y}\right)} - 1 \]
      8. sqrt-unprod41.3%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{x + y}\right)} - 1 \]
      9. sqr-neg41.3%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{y}}{x + y}\right)} - 1 \]
    11. Applied egg-rr78.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{y}{x + y}\right)} - 1} \]
    12. Step-by-step derivation
      1. expm1-def78.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y}{x + y}\right)\right)} \]
      2. expm1-log1p78.6%

        \[\leadsto \color{blue}{\frac{y}{x + y}} \]
    13. Simplified78.6%

      \[\leadsto \color{blue}{\frac{y}{x + y}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification66.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{-132}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-255}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{-73}:\\ \;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-39}:\\ \;\;\;\;\frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x + y}\\ \end{array} \]

Alternative 5: 58.2% accurate, 22.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.08 \cdot 10^{-131} \lor \neg \left(y \leq 3.4 \cdot 10^{-39}\right):\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} + -1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -1.08e-131) (not (<= y 3.4e-39)))
   (/ y (+ x y))
   (+ (/ x y) -1.0)))
double code(double x, double y) {
	double tmp;
	if ((y <= -1.08e-131) || !(y <= 3.4e-39)) {
		tmp = y / (x + y);
	} else {
		tmp = (x / y) + -1.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y <= (-1.08d-131)) .or. (.not. (y <= 3.4d-39))) then
        tmp = y / (x + y)
    else
        tmp = (x / y) + (-1.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -1.08e-131) || !(y <= 3.4e-39)) {
		tmp = y / (x + y);
	} else {
		tmp = (x / y) + -1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -1.08e-131) or not (y <= 3.4e-39):
		tmp = y / (x + y)
	else:
		tmp = (x / y) + -1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -1.08e-131) || !(y <= 3.4e-39))
		tmp = Float64(y / Float64(x + y));
	else
		tmp = Float64(Float64(x / y) + -1.0);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -1.08e-131) || ~((y <= 3.4e-39)))
		tmp = y / (x + y);
	else
		tmp = (x / y) + -1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -1.08e-131], N[Not[LessEqual[y, 3.4e-39]], $MachinePrecision]], N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.08 \cdot 10^{-131} \lor \neg \left(y \leq 3.4 \cdot 10^{-39}\right):\\
\;\;\;\;\frac{y}{x + y}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{y} + -1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.07999999999999996e-131 or 3.3999999999999999e-39 < y

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{x - y}{y}\right|} \]
      6. rem-square-sqrt15.5%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
      7. fabs-sqr15.5%

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt16.8%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub16.8%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg16.8%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses16.8%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval16.8%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative16.8%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified16.8%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    5. Step-by-step derivation
      1. +-commutative16.8%

        \[\leadsto \color{blue}{\frac{x}{y} + -1} \]
      2. metadata-eval16.8%

        \[\leadsto \frac{x}{y} + \color{blue}{\left(-1\right)} \]
      3. sub-neg16.8%

        \[\leadsto \color{blue}{\frac{x}{y} - 1} \]
      4. *-inverses16.8%

        \[\leadsto \frac{x}{y} - \color{blue}{\frac{y}{y}} \]
      5. div-sub16.8%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      6. clear-num16.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
      7. associate-/r/16.7%

        \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
      8. flip--6.4%

        \[\leadsto \frac{1}{y} \cdot \color{blue}{\frac{x \cdot x - y \cdot y}{x + y}} \]
      9. associate-*r/6.3%

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

      \[\leadsto \color{blue}{\frac{\frac{1}{y} \cdot \left(x \cdot x - y \cdot y\right)}{x + y}} \]
    7. Taylor expanded in y around inf 2.0%

      \[\leadsto \frac{\color{blue}{-1 \cdot y}}{x + y} \]
    8. Step-by-step derivation
      1. neg-mul-12.0%

        \[\leadsto \frac{\color{blue}{-y}}{x + y} \]
    9. Simplified2.0%

      \[\leadsto \frac{\color{blue}{-y}}{x + y} \]
    10. Step-by-step derivation
      1. expm1-log1p-u2.0%

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{-y}{x + y}\right)} - 1} \]
      3. *-un-lft-identity1.8%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{1 \cdot \left(-y\right)}}{x + y}\right)} - 1 \]
      4. *-commutative1.8%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\left(-y\right) \cdot 1}}{x + y}\right)} - 1 \]
      5. *-commutative1.8%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{1 \cdot \left(-y\right)}}{x + y}\right)} - 1 \]
      6. *-un-lft-identity1.8%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{-y}}{x + y}\right)} - 1 \]
      7. add-sqr-sqrt1.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{x + y}\right)} - 1 \]
      8. sqrt-unprod18.2%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{x + y}\right)} - 1 \]
      9. sqr-neg18.2%

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{y} \cdot \sqrt{y}}}{x + y}\right)} - 1 \]
      11. add-sqr-sqrt70.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{y}}{x + y}\right)} - 1 \]
    11. Applied egg-rr70.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{y}{x + y}\right)} - 1} \]
    12. Step-by-step derivation
      1. expm1-def70.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{y}{x + y}\right)\right)} \]
      2. expm1-log1p70.2%

        \[\leadsto \color{blue}{\frac{y}{x + y}} \]
    13. Simplified70.2%

      \[\leadsto \color{blue}{\frac{y}{x + y}} \]

    if -1.07999999999999996e-131 < y < 3.3999999999999999e-39

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Taylor expanded in x around -inf 100.0%

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    3. Step-by-step derivation
      1. fabs-neg100.0%

        \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
      2. mul-1-neg100.0%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{x - y}{y}\right|} \]
      6. rem-square-sqrt51.6%

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

        \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
      8. rem-square-sqrt52.2%

        \[\leadsto \color{blue}{\frac{x - y}{y}} \]
      9. div-sub52.2%

        \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
      10. sub-neg52.2%

        \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
      11. *-inverses52.2%

        \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
      12. metadata-eval52.2%

        \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
      13. +-commutative52.2%

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    4. Simplified52.2%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.08 \cdot 10^{-131} \lor \neg \left(y \leq 3.4 \cdot 10^{-39}\right):\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} + -1\\ \end{array} \]

Alternative 6: 26.0% accurate, 68.3× speedup?

\[\begin{array}{l} \\ \frac{x}{y} \end{array} \]
(FPCore (x y) :precision binary64 (/ x y))
double code(double x, double y) {
	return x / y;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x / y
end function
public static double code(double x, double y) {
	return x / y;
}
def code(x, y):
	return x / y
function code(x, y)
	return Float64(x / y)
end
function tmp = code(x, y)
	tmp = x / y;
end
code[x_, y_] := N[(x / y), $MachinePrecision]
\begin{array}{l}

\\
\frac{x}{y}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{\left|x - y\right|}{\left|y\right|} \]
  2. Taylor expanded in x around -inf 100.0%

    \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
  3. Step-by-step derivation
    1. fabs-neg100.0%

      \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
    2. mul-1-neg100.0%

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

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

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

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

      \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
    7. fabs-sqr27.2%

      \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
    8. rem-square-sqrt28.3%

      \[\leadsto \color{blue}{\frac{x - y}{y}} \]
    9. div-sub28.3%

      \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
    10. sub-neg28.3%

      \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
    11. *-inverses28.3%

      \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
    12. metadata-eval28.3%

      \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
    13. +-commutative28.3%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
  4. Simplified28.3%

    \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
  5. Taylor expanded in x around inf 29.0%

    \[\leadsto \color{blue}{\frac{x}{y}} \]
  6. Final simplification29.0%

    \[\leadsto \frac{x}{y} \]

Alternative 7: 1.3% accurate, 205.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
	return -1.0;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = -1.0d0
end function
public static double code(double x, double y) {
	return -1.0;
}
def code(x, y):
	return -1.0
function code(x, y)
	return -1.0
end
function tmp = code(x, y)
	tmp = -1.0;
end
code[x_, y_] := -1.0
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{\left|x - y\right|}{\left|y\right|} \]
  2. Taylor expanded in x around -inf 100.0%

    \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
  3. Step-by-step derivation
    1. fabs-neg100.0%

      \[\leadsto \frac{\color{blue}{\left|y + -1 \cdot x\right|}}{\left|y\right|} \]
    2. mul-1-neg100.0%

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

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

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

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

      \[\leadsto \left|\color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}}\right| \]
    7. fabs-sqr27.2%

      \[\leadsto \color{blue}{\sqrt{\frac{x - y}{y}} \cdot \sqrt{\frac{x - y}{y}}} \]
    8. rem-square-sqrt28.3%

      \[\leadsto \color{blue}{\frac{x - y}{y}} \]
    9. div-sub28.3%

      \[\leadsto \color{blue}{\frac{x}{y} - \frac{y}{y}} \]
    10. sub-neg28.3%

      \[\leadsto \color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)} \]
    11. *-inverses28.3%

      \[\leadsto \frac{x}{y} + \left(-\color{blue}{1}\right) \]
    12. metadata-eval28.3%

      \[\leadsto \frac{x}{y} + \color{blue}{-1} \]
    13. +-commutative28.3%

      \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
  4. Simplified28.3%

    \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
  5. Taylor expanded in x around 0 1.3%

    \[\leadsto \color{blue}{-1} \]
  6. Final simplification1.3%

    \[\leadsto -1 \]

Reproduce

?
herbie shell --seed 2023293 
(FPCore (x y)
  :name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
  :precision binary64
  (/ (fabs (- x y)) (fabs y)))