Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5

Percentage Accurate: 100.0% → 100.0%
Time: 4.4s
Alternatives: 8
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 8 alternatives:

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

Initial Program: 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. Add Preprocessing
  3. Step-by-step derivation
    1. fabs-sub100.0%

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

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

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

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

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

    \[\leadsto \left|\color{blue}{1 - \frac{x}{y}}\right| \]
  7. Add Preprocessing

Alternative 2: 83.4% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{+89} \lor \neg \left(x \leq 6.5 \cdot 10^{+93}\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.80000000000000021e89 or 6.4999999999999998e93 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. fabs-sub100.0%

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

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

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

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

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

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

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

    if -7.80000000000000021e89 < x < 6.4999999999999998e93

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt47.3%

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

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

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

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt7.5%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
      6. add-sqr-sqrt16.3%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    4. Applied egg-rr16.3%

      \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    5. Step-by-step derivation
      1. div-inv16.3%

        \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    6. Applied egg-rr16.3%

      \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    7. Step-by-step derivation
      1. *-commutative16.3%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{x - y} \cdot y}} \]
      2. associate-/r/16.3%

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

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

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

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\frac{x}{y} - \color{blue}{1}}} \]
      6. sub-neg16.3%

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

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

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

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

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{-1 \cdot -1 + -1 \cdot \frac{x}{y}}}} \]
      11. metadata-eval16.3%

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

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

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{1 - \frac{x}{y}}}} \]
      14. rem-square-sqrt1.2%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}}}} \]
      15. fabs-sqr1.2%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}\right|}}} \]
      16. rem-square-sqrt1.3%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{1 - \frac{x}{y}}\right|}} \]
      17. fabs-sub1.3%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\frac{x}{y} - 1\right|}}} \]
      18. sub-neg1.3%

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

        \[\leadsto \frac{1}{\frac{-1}{\left|\frac{x}{y} + \color{blue}{-1}\right|}} \]
      20. rem-square-sqrt0.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}\right|}} \]
      21. fabs-sqr0.1%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}}} \]
      22. rem-square-sqrt84.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{1} - \frac{x}{y} \]
    11. Simplified85.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.8 \cdot 10^{+89} \lor \neg \left(x \leq 6.5 \cdot 10^{+93}\right):\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 59.0% accurate, 6.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{-y}\\ t_1 := \frac{x}{y} + -1\\ \mathbf{if}\;x \leq -7 \cdot 10^{+113}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+16}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+43}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{+111}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{+182}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ x (- y))) (t_1 (+ (/ x y) -1.0)))
   (if (<= x -7e+113)
     t_1
     (if (<= x 1.6e+16)
       1.0
       (if (<= x 1.4e+43)
         t_0
         (if (<= x 2.7e+111) 1.0 (if (<= x 3.5e+182) t_1 t_0)))))))
double code(double x, double y) {
	double t_0 = x / -y;
	double t_1 = (x / y) + -1.0;
	double tmp;
	if (x <= -7e+113) {
		tmp = t_1;
	} else if (x <= 1.6e+16) {
		tmp = 1.0;
	} else if (x <= 1.4e+43) {
		tmp = t_0;
	} else if (x <= 2.7e+111) {
		tmp = 1.0;
	} else if (x <= 3.5e+182) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = x / -y
    t_1 = (x / y) + (-1.0d0)
    if (x <= (-7d+113)) then
        tmp = t_1
    else if (x <= 1.6d+16) then
        tmp = 1.0d0
    else if (x <= 1.4d+43) then
        tmp = t_0
    else if (x <= 2.7d+111) then
        tmp = 1.0d0
    else if (x <= 3.5d+182) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = x / -y;
	double t_1 = (x / y) + -1.0;
	double tmp;
	if (x <= -7e+113) {
		tmp = t_1;
	} else if (x <= 1.6e+16) {
		tmp = 1.0;
	} else if (x <= 1.4e+43) {
		tmp = t_0;
	} else if (x <= 2.7e+111) {
		tmp = 1.0;
	} else if (x <= 3.5e+182) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = x / -y
	t_1 = (x / y) + -1.0
	tmp = 0
	if x <= -7e+113:
		tmp = t_1
	elif x <= 1.6e+16:
		tmp = 1.0
	elif x <= 1.4e+43:
		tmp = t_0
	elif x <= 2.7e+111:
		tmp = 1.0
	elif x <= 3.5e+182:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(x / Float64(-y))
	t_1 = Float64(Float64(x / y) + -1.0)
	tmp = 0.0
	if (x <= -7e+113)
		tmp = t_1;
	elseif (x <= 1.6e+16)
		tmp = 1.0;
	elseif (x <= 1.4e+43)
		tmp = t_0;
	elseif (x <= 2.7e+111)
		tmp = 1.0;
	elseif (x <= 3.5e+182)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = x / -y;
	t_1 = (x / y) + -1.0;
	tmp = 0.0;
	if (x <= -7e+113)
		tmp = t_1;
	elseif (x <= 1.6e+16)
		tmp = 1.0;
	elseif (x <= 1.4e+43)
		tmp = t_0;
	elseif (x <= 2.7e+111)
		tmp = 1.0;
	elseif (x <= 3.5e+182)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(x / (-y)), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[x, -7e+113], t$95$1, If[LessEqual[x, 1.6e+16], 1.0, If[LessEqual[x, 1.4e+43], t$95$0, If[LessEqual[x, 2.7e+111], 1.0, If[LessEqual[x, 3.5e+182], t$95$1, t$95$0]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{-y}\\
t_1 := \frac{x}{y} + -1\\
\mathbf{if}\;x \leq -7 \cdot 10^{+113}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq 1.6 \cdot 10^{+16}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 1.4 \cdot 10^{+43}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 2.7 \cdot 10^{+111}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 3.5 \cdot 10^{+182}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -7.0000000000000001e113 or 2.6999999999999999e111 < x < 3.50000000000000023e182

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-1 + \frac{x}{y}} \]
    5. Simplified55.1%

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

    if -7.0000000000000001e113 < x < 1.6e16 or 1.40000000000000009e43 < x < 2.6999999999999999e111

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt46.1%

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

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

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

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt6.4%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
      6. add-sqr-sqrt15.9%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    4. Applied egg-rr15.9%

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

        \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    6. Applied egg-rr15.9%

      \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    7. Step-by-step derivation
      1. *-commutative15.9%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{x - y} \cdot y}} \]
      2. associate-/r/15.9%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{x - y}{y}}}} \]
      3. metadata-eval15.9%

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

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

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\frac{x}{y} - \color{blue}{1}}} \]
      6. sub-neg15.9%

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

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

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

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

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{-1 \cdot -1 + -1 \cdot \frac{x}{y}}}} \]
      11. metadata-eval15.9%

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

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

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{1 - \frac{x}{y}}}} \]
      14. rem-square-sqrt1.2%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}}}} \]
      15. fabs-sqr1.2%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}\right|}}} \]
      16. rem-square-sqrt1.3%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{1 - \frac{x}{y}}\right|}} \]
      17. fabs-sub1.3%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\frac{x}{y} - 1\right|}}} \]
      18. sub-neg1.3%

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

        \[\leadsto \frac{1}{\frac{-1}{\left|\frac{x}{y} + \color{blue}{-1}\right|}} \]
      20. rem-square-sqrt0.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}\right|}} \]
      21. fabs-sqr0.1%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}}} \]
      22. rem-square-sqrt85.3%

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

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

      \[\leadsto \color{blue}{1} \]

    if 1.6e16 < x < 1.40000000000000009e43 or 3.50000000000000023e182 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt93.6%

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

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

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

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt27.3%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
      6. add-sqr-sqrt27.6%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    4. Applied egg-rr27.6%

      \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    5. Step-by-step derivation
      1. div-inv27.6%

        \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    6. Applied egg-rr27.6%

      \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    7. Step-by-step derivation
      1. *-commutative27.6%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{x - y} \cdot y}} \]
      2. associate-/r/27.6%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{x - y}{y}}}} \]
      3. metadata-eval27.6%

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{-1}{-1}}}{\frac{x - y}{y}}} \]
      4. div-sub27.6%

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\color{blue}{\frac{x}{y} - \frac{y}{y}}}} \]
      5. *-inverses27.6%

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\frac{x}{y} - \color{blue}{1}}} \]
      6. sub-neg27.6%

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\color{blue}{\frac{x}{y} + \left(-1\right)}}} \]
      7. metadata-eval27.6%

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

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

        \[\leadsto \frac{1}{\frac{-1}{-1 \cdot \color{blue}{\left(-1 + \frac{x}{y}\right)}}} \]
      10. distribute-lft-in27.6%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{-1 \cdot -1 + -1 \cdot \frac{x}{y}}}} \]
      11. metadata-eval27.6%

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

        \[\leadsto \frac{1}{\frac{-1}{1 + \color{blue}{\left(-\frac{x}{y}\right)}}} \]
      13. sub-neg27.6%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{1 - \frac{x}{y}}}} \]
      14. rem-square-sqrt0.3%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}}}} \]
      15. fabs-sqr0.3%

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

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{1 - \frac{x}{y}}\right|}} \]
      17. fabs-sub0.4%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\frac{x}{y} - 1\right|}}} \]
      18. sub-neg0.4%

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

        \[\leadsto \frac{1}{\frac{-1}{\left|\frac{x}{y} + \color{blue}{-1}\right|}} \]
      20. rem-square-sqrt0.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}\right|}} \]
      21. fabs-sqr0.1%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}}} \]
      22. rem-square-sqrt72.7%

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{y}} \]
      2. neg-mul-166.8%

        \[\leadsto \frac{\color{blue}{-x}}{y} \]
    11. Simplified66.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{+113}:\\ \;\;\;\;\frac{x}{y} + -1\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+16}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+43}:\\ \;\;\;\;\frac{x}{-y}\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{+111}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{+182}:\\ \;\;\;\;\frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{-y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 59.0% accurate, 7.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{-y}\\ \mathbf{if}\;x \leq -8.8 \cdot 10^{+111}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+16}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{+43}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+111}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+182}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ x (- y))))
   (if (<= x -8.8e+111)
     (/ x y)
     (if (<= x 1.6e+16)
       1.0
       (if (<= x 4.8e+43)
         t_0
         (if (<= x 1.35e+111) 1.0 (if (<= x 4e+182) (/ x y) t_0)))))))
double code(double x, double y) {
	double t_0 = x / -y;
	double tmp;
	if (x <= -8.8e+111) {
		tmp = x / y;
	} else if (x <= 1.6e+16) {
		tmp = 1.0;
	} else if (x <= 4.8e+43) {
		tmp = t_0;
	} else if (x <= 1.35e+111) {
		tmp = 1.0;
	} else if (x <= 4e+182) {
		tmp = x / y;
	} 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 = x / -y
    if (x <= (-8.8d+111)) then
        tmp = x / y
    else if (x <= 1.6d+16) then
        tmp = 1.0d0
    else if (x <= 4.8d+43) then
        tmp = t_0
    else if (x <= 1.35d+111) then
        tmp = 1.0d0
    else if (x <= 4d+182) then
        tmp = x / y
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = x / -y;
	double tmp;
	if (x <= -8.8e+111) {
		tmp = x / y;
	} else if (x <= 1.6e+16) {
		tmp = 1.0;
	} else if (x <= 4.8e+43) {
		tmp = t_0;
	} else if (x <= 1.35e+111) {
		tmp = 1.0;
	} else if (x <= 4e+182) {
		tmp = x / y;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = x / -y
	tmp = 0
	if x <= -8.8e+111:
		tmp = x / y
	elif x <= 1.6e+16:
		tmp = 1.0
	elif x <= 4.8e+43:
		tmp = t_0
	elif x <= 1.35e+111:
		tmp = 1.0
	elif x <= 4e+182:
		tmp = x / y
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(x / Float64(-y))
	tmp = 0.0
	if (x <= -8.8e+111)
		tmp = Float64(x / y);
	elseif (x <= 1.6e+16)
		tmp = 1.0;
	elseif (x <= 4.8e+43)
		tmp = t_0;
	elseif (x <= 1.35e+111)
		tmp = 1.0;
	elseif (x <= 4e+182)
		tmp = Float64(x / y);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = x / -y;
	tmp = 0.0;
	if (x <= -8.8e+111)
		tmp = x / y;
	elseif (x <= 1.6e+16)
		tmp = 1.0;
	elseif (x <= 4.8e+43)
		tmp = t_0;
	elseif (x <= 1.35e+111)
		tmp = 1.0;
	elseif (x <= 4e+182)
		tmp = x / y;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(x / (-y)), $MachinePrecision]}, If[LessEqual[x, -8.8e+111], N[(x / y), $MachinePrecision], If[LessEqual[x, 1.6e+16], 1.0, If[LessEqual[x, 4.8e+43], t$95$0, If[LessEqual[x, 1.35e+111], 1.0, If[LessEqual[x, 4e+182], N[(x / y), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 1.6 \cdot 10^{+16}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 4.8 \cdot 10^{+43}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 1.35 \cdot 10^{+111}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 4 \cdot 10^{+182}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -8.79999999999999994e111 or 1.3499999999999999e111 < x < 4.0000000000000003e182

    1. Initial program 99.9%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt39.4%

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

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

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

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt20.8%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
      6. add-sqr-sqrt55.0%

        \[\leadsto \frac{\color{blue}{x - y}}{y} \]
    4. Applied egg-rr55.0%

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

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

    if -8.79999999999999994e111 < x < 1.6e16 or 4.80000000000000046e43 < x < 1.3499999999999999e111

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt46.1%

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

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

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

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt6.4%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
      6. add-sqr-sqrt15.9%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    4. Applied egg-rr15.9%

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

        \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    6. Applied egg-rr15.9%

      \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    7. Step-by-step derivation
      1. *-commutative15.9%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{x - y} \cdot y}} \]
      2. associate-/r/15.9%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{x - y}{y}}}} \]
      3. metadata-eval15.9%

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

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

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\frac{x}{y} - \color{blue}{1}}} \]
      6. sub-neg15.9%

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

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

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

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

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{-1 \cdot -1 + -1 \cdot \frac{x}{y}}}} \]
      11. metadata-eval15.9%

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

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

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{1 - \frac{x}{y}}}} \]
      14. rem-square-sqrt1.2%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}}}} \]
      15. fabs-sqr1.2%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}\right|}}} \]
      16. rem-square-sqrt1.3%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{1 - \frac{x}{y}}\right|}} \]
      17. fabs-sub1.3%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\frac{x}{y} - 1\right|}}} \]
      18. sub-neg1.3%

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

        \[\leadsto \frac{1}{\frac{-1}{\left|\frac{x}{y} + \color{blue}{-1}\right|}} \]
      20. rem-square-sqrt0.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}\right|}} \]
      21. fabs-sqr0.1%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}}} \]
      22. rem-square-sqrt85.3%

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

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

      \[\leadsto \color{blue}{1} \]

    if 1.6e16 < x < 4.80000000000000046e43 or 4.0000000000000003e182 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt93.6%

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

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

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

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt27.3%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
      6. add-sqr-sqrt27.6%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    4. Applied egg-rr27.6%

      \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    5. Step-by-step derivation
      1. div-inv27.6%

        \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    6. Applied egg-rr27.6%

      \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    7. Step-by-step derivation
      1. *-commutative27.6%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{x - y} \cdot y}} \]
      2. associate-/r/27.6%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{x - y}{y}}}} \]
      3. metadata-eval27.6%

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{-1}{-1}}}{\frac{x - y}{y}}} \]
      4. div-sub27.6%

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\color{blue}{\frac{x}{y} - \frac{y}{y}}}} \]
      5. *-inverses27.6%

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\frac{x}{y} - \color{blue}{1}}} \]
      6. sub-neg27.6%

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\color{blue}{\frac{x}{y} + \left(-1\right)}}} \]
      7. metadata-eval27.6%

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

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

        \[\leadsto \frac{1}{\frac{-1}{-1 \cdot \color{blue}{\left(-1 + \frac{x}{y}\right)}}} \]
      10. distribute-lft-in27.6%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{-1 \cdot -1 + -1 \cdot \frac{x}{y}}}} \]
      11. metadata-eval27.6%

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

        \[\leadsto \frac{1}{\frac{-1}{1 + \color{blue}{\left(-\frac{x}{y}\right)}}} \]
      13. sub-neg27.6%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{1 - \frac{x}{y}}}} \]
      14. rem-square-sqrt0.3%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}}}} \]
      15. fabs-sqr0.3%

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

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{1 - \frac{x}{y}}\right|}} \]
      17. fabs-sub0.4%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\frac{x}{y} - 1\right|}}} \]
      18. sub-neg0.4%

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

        \[\leadsto \frac{1}{\frac{-1}{\left|\frac{x}{y} + \color{blue}{-1}\right|}} \]
      20. rem-square-sqrt0.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}\right|}} \]
      21. fabs-sqr0.1%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}}} \]
      22. rem-square-sqrt72.7%

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{y}} \]
      2. neg-mul-166.8%

        \[\leadsto \frac{\color{blue}{-x}}{y} \]
    11. Simplified66.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.8 \cdot 10^{+111}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+16}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{+43}:\\ \;\;\;\;\frac{x}{-y}\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+111}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+182}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{-y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 74.5% accurate, 13.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{-252} \lor \neg \left(y \leq 2.25 \cdot 10^{-287}\right):\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} + -1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -3.5e-252) (not (<= y 2.25e-287)))
   (- 1.0 (/ x y))
   (+ (/ x y) -1.0)))
double code(double x, double y) {
	double tmp;
	if ((y <= -3.5e-252) || !(y <= 2.25e-287)) {
		tmp = 1.0 - (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 <= (-3.5d-252)) .or. (.not. (y <= 2.25d-287))) then
        tmp = 1.0d0 - (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 <= -3.5e-252) || !(y <= 2.25e-287)) {
		tmp = 1.0 - (x / y);
	} else {
		tmp = (x / y) + -1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -3.5e-252) or not (y <= 2.25e-287):
		tmp = 1.0 - (x / y)
	else:
		tmp = (x / y) + -1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -3.5e-252) || !(y <= 2.25e-287))
		tmp = Float64(1.0 - 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 <= -3.5e-252) || ~((y <= 2.25e-287)))
		tmp = 1.0 - (x / y);
	else
		tmp = (x / y) + -1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -3.5e-252], N[Not[LessEqual[y, 2.25e-287]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{-252} \lor \neg \left(y \leq 2.25 \cdot 10^{-287}\right):\\
\;\;\;\;1 - \frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.49999999999999986e-252 or 2.25000000000000008e-287 < y

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt52.2%

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

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

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

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt12.4%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
      6. add-sqr-sqrt21.9%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    4. Applied egg-rr21.9%

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

        \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    6. Applied egg-rr21.9%

      \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    7. Step-by-step derivation
      1. *-commutative21.9%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{x - y} \cdot y}} \]
      2. associate-/r/21.9%

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{x - y}{y}}}} \]
      3. metadata-eval21.9%

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

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

        \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\frac{x}{y} - \color{blue}{1}}} \]
      6. sub-neg21.9%

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

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

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

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

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{-1 \cdot -1 + -1 \cdot \frac{x}{y}}}} \]
      11. metadata-eval21.9%

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

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

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{1 - \frac{x}{y}}}} \]
      14. rem-square-sqrt1.0%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}}}} \]
      15. fabs-sqr1.0%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}\right|}}} \]
      16. rem-square-sqrt1.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{1 - \frac{x}{y}}\right|}} \]
      17. fabs-sub1.1%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\frac{x}{y} - 1\right|}}} \]
      18. sub-neg1.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\frac{x}{y} + \left(-1\right)}\right|}} \]
      19. metadata-eval1.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\frac{x}{y} + \color{blue}{-1}\right|}} \]
      20. rem-square-sqrt0.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}\right|}} \]
      21. fabs-sqr0.1%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}}} \]
      22. rem-square-sqrt79.1%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{y}{y} - \frac{x}{y}} \]
      4. *-inverses79.2%

        \[\leadsto \color{blue}{1} - \frac{x}{y} \]
    11. Simplified79.2%

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

    if -3.49999999999999986e-252 < y < 2.25000000000000008e-287

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
    4. 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.4%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{-252} \lor \neg \left(y \leq 2.25 \cdot 10^{-287}\right):\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 59.4% accurate, 15.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.9 \cdot 10^{+107} \lor \neg \left(x \leq 1.45 \cdot 10^{+110}\right):\\
\;\;\;\;\frac{x}{y}\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.9000000000000001e107 or 1.45e110 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt56.9%

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

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

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

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt22.1%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
      6. add-sqr-sqrt45.7%

        \[\leadsto \frac{\color{blue}{x - y}}{y} \]
    4. Applied egg-rr45.7%

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

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

    if -4.9000000000000001e107 < x < 1.45e110

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt48.2%

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

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

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

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
      5. add-sqr-sqrt7.8%

        \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
      6. add-sqr-sqrt16.8%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
    4. Applied egg-rr16.8%

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

        \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
    6. Applied egg-rr16.8%

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{x - y} \cdot y}} \]
      2. associate-/r/16.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{-1}{-1 \cdot \color{blue}{\left(-1 + \frac{x}{y}\right)}}} \]
      10. distribute-lft-in16.8%

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

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

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

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{1 - \frac{x}{y}}}} \]
      14. rem-square-sqrt1.2%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}}}} \]
      15. fabs-sqr1.2%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}\right|}}} \]
      16. rem-square-sqrt1.3%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{1 - \frac{x}{y}}\right|}} \]
      17. fabs-sub1.3%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\frac{x}{y} - 1\right|}}} \]
      18. sub-neg1.3%

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

        \[\leadsto \frac{1}{\frac{-1}{\left|\frac{x}{y} + \color{blue}{-1}\right|}} \]
      20. rem-square-sqrt0.1%

        \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}\right|}} \]
      21. fabs-sqr0.1%

        \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}}} \]
      22. rem-square-sqrt84.4%

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

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

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.9 \cdot 10^{+107} \lor \neg \left(x \leq 1.45 \cdot 10^{+110}\right):\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 51.7% 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. Add Preprocessing
  3. Step-by-step derivation
    1. add-sqr-sqrt50.8%

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

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

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

      \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
    5. add-sqr-sqrt12.1%

      \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
    6. add-sqr-sqrt25.5%

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

      \[\leadsto \color{blue}{\frac{1}{\frac{y}{x - y}}} \]
  4. Applied egg-rr25.5%

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

      \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
  6. Applied egg-rr25.5%

    \[\leadsto \frac{1}{\color{blue}{y \cdot \frac{1}{x - y}}} \]
  7. Step-by-step derivation
    1. *-commutative25.5%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{x - y} \cdot y}} \]
    2. associate-/r/25.5%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{x - y}{y}}}} \]
    3. metadata-eval25.5%

      \[\leadsto \frac{1}{\frac{\color{blue}{\frac{-1}{-1}}}{\frac{x - y}{y}}} \]
    4. div-sub25.5%

      \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\color{blue}{\frac{x}{y} - \frac{y}{y}}}} \]
    5. *-inverses25.5%

      \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\frac{x}{y} - \color{blue}{1}}} \]
    6. sub-neg25.5%

      \[\leadsto \frac{1}{\frac{\frac{-1}{-1}}{\color{blue}{\frac{x}{y} + \left(-1\right)}}} \]
    7. metadata-eval25.5%

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

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

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

      \[\leadsto \frac{1}{\frac{-1}{\color{blue}{-1 \cdot -1 + -1 \cdot \frac{x}{y}}}} \]
    11. metadata-eval25.5%

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

      \[\leadsto \frac{1}{\frac{-1}{1 + \color{blue}{\left(-\frac{x}{y}\right)}}} \]
    13. sub-neg25.5%

      \[\leadsto \frac{1}{\frac{-1}{\color{blue}{1 - \frac{x}{y}}}} \]
    14. rem-square-sqrt0.9%

      \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}}}} \]
    15. fabs-sqr0.9%

      \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\sqrt{1 - \frac{x}{y}} \cdot \sqrt{1 - \frac{x}{y}}\right|}}} \]
    16. rem-square-sqrt1.1%

      \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{1 - \frac{x}{y}}\right|}} \]
    17. fabs-sub1.1%

      \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\left|\frac{x}{y} - 1\right|}}} \]
    18. sub-neg1.1%

      \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\frac{x}{y} + \left(-1\right)}\right|}} \]
    19. metadata-eval1.1%

      \[\leadsto \frac{1}{\frac{-1}{\left|\frac{x}{y} + \color{blue}{-1}\right|}} \]
    20. rem-square-sqrt0.1%

      \[\leadsto \frac{1}{\frac{-1}{\left|\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}\right|}} \]
    21. fabs-sqr0.1%

      \[\leadsto \frac{1}{\frac{-1}{\color{blue}{\sqrt{\frac{x}{y} + -1} \cdot \sqrt{\frac{x}{y} + -1}}}} \]
    22. rem-square-sqrt75.5%

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

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

    \[\leadsto \color{blue}{1} \]
  10. Add Preprocessing

Alternative 8: 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. Add Preprocessing
  3. Step-by-step derivation
    1. add-sqr-sqrt50.8%

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

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

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

      \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{\sqrt{y} \cdot \sqrt{y}}} \]
    5. add-sqr-sqrt12.1%

      \[\leadsto \frac{\sqrt{x - y} \cdot \sqrt{x - y}}{\color{blue}{y}} \]
    6. add-sqr-sqrt25.5%

      \[\leadsto \frac{\color{blue}{x - y}}{y} \]
  4. Applied egg-rr25.5%

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

    \[\leadsto \color{blue}{-1} \]
  6. Add Preprocessing

Reproduce

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