Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5

Percentage Accurate: 100.0% → 100.0%
Time: 4.6s
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: 59.3% accurate, 11.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\frac{x}{y}}{x + y} \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -1.25 \cdot 10^{+171}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.4 \cdot 10^{+142}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -1 \cdot 10^{+59} \lor \neg \left(x \leq 3.75 \cdot 10^{+65}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x + y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* (/ (/ x y) (+ x y)) (- x))))
   (if (<= x -1.25e+171)
     t_0
     (if (<= x -5.4e+142)
       (/ x y)
       (if (or (<= x -1e+59) (not (<= x 3.75e+65))) t_0 (/ y (+ x y)))))))
double code(double x, double y) {
	double t_0 = ((x / y) / (x + y)) * -x;
	double tmp;
	if (x <= -1.25e+171) {
		tmp = t_0;
	} else if (x <= -5.4e+142) {
		tmp = x / y;
	} else if ((x <= -1e+59) || !(x <= 3.75e+65)) {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = ((x / y) / (x + y)) * -x
    if (x <= (-1.25d+171)) then
        tmp = t_0
    else if (x <= (-5.4d+142)) then
        tmp = x / y
    else if ((x <= (-1d+59)) .or. (.not. (x <= 3.75d+65))) then
        tmp = t_0
    else
        tmp = y / (x + y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = ((x / y) / (x + y)) * -x;
	double tmp;
	if (x <= -1.25e+171) {
		tmp = t_0;
	} else if (x <= -5.4e+142) {
		tmp = x / y;
	} else if ((x <= -1e+59) || !(x <= 3.75e+65)) {
		tmp = t_0;
	} else {
		tmp = y / (x + y);
	}
	return tmp;
}
def code(x, y):
	t_0 = ((x / y) / (x + y)) * -x
	tmp = 0
	if x <= -1.25e+171:
		tmp = t_0
	elif x <= -5.4e+142:
		tmp = x / y
	elif (x <= -1e+59) or not (x <= 3.75e+65):
		tmp = t_0
	else:
		tmp = y / (x + y)
	return tmp
function code(x, y)
	t_0 = Float64(Float64(Float64(x / y) / Float64(x + y)) * Float64(-x))
	tmp = 0.0
	if (x <= -1.25e+171)
		tmp = t_0;
	elseif (x <= -5.4e+142)
		tmp = Float64(x / y);
	elseif ((x <= -1e+59) || !(x <= 3.75e+65))
		tmp = t_0;
	else
		tmp = Float64(y / Float64(x + y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = ((x / y) / (x + y)) * -x;
	tmp = 0.0;
	if (x <= -1.25e+171)
		tmp = t_0;
	elseif (x <= -5.4e+142)
		tmp = x / y;
	elseif ((x <= -1e+59) || ~((x <= 3.75e+65)))
		tmp = t_0;
	else
		tmp = y / (x + y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x / y), $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision] * (-x)), $MachinePrecision]}, If[LessEqual[x, -1.25e+171], t$95$0, If[LessEqual[x, -5.4e+142], N[(x / y), $MachinePrecision], If[Or[LessEqual[x, -1e+59], N[Not[LessEqual[x, 3.75e+65]], $MachinePrecision]], t$95$0, N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\frac{x}{y}}{x + y} \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -1.25 \cdot 10^{+171}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -5.4 \cdot 10^{+142}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{elif}\;x \leq -1 \cdot 10^{+59} \lor \neg \left(x \leq 3.75 \cdot 10^{+65}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.2500000000000001e171 or -5.39999999999999965e142 < x < -9.99999999999999972e58 or 3.75000000000000003e65 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Step-by-step derivation
      1. div-inv99.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Step-by-step derivation
      1. flip--14.2%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{{x}^{2}}{y}}}{y + x} \]
    7. Step-by-step derivation
      1. unpow214.9%

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

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

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot x}}{y + x} \]
    8. Simplified19.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -\color{blue}{\frac{\frac{x}{y}}{y + x} \cdot x} \]
      19. +-commutative53.3%

        \[\leadsto -\frac{\frac{x}{y}}{\color{blue}{x + y}} \cdot x \]
    10. Applied egg-rr53.3%

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

    if -1.2500000000000001e171 < x < -5.39999999999999965e142

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Step-by-step derivation
      1. div-inv99.5%

        \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{\left|y\right|}} \]
      2. add-sqr-sqrt29.8%

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

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

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

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

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

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

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

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

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

    if -9.99999999999999972e58 < x < 3.75000000000000003e65

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Step-by-step derivation
      1. div-inv99.7%

        \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{\left|y\right|}} \]
      2. add-sqr-sqrt47.0%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\left|y\right|} \cdot \left(x - y\right)} \]
      6. add-sqr-sqrt9.0%

        \[\leadsto \frac{1}{\left|\color{blue}{\sqrt{y} \cdot \sqrt{y}}\right|} \cdot \left(x - y\right) \]
      7. fabs-sqr9.0%

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

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Step-by-step derivation
      1. flip--16.9%

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

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

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

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

      \[\leadsto \frac{\frac{1}{y} \cdot \color{blue}{\left(-1 \cdot {y}^{2}\right)}}{y + x} \]
    7. Step-by-step derivation
      1. unpow21.8%

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

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

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

      \[\leadsto \frac{\frac{1}{y} \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)}}{y + x} \]
    9. Step-by-step derivation
      1. associate-*r*2.1%

        \[\leadsto \frac{\color{blue}{\left(\frac{1}{y} \cdot y\right) \cdot \left(-y\right)}}{y + x} \]
      2. lft-mult-inverse2.1%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{0} + \left(-y\right)}{y + x} \]
      8. add-sqr-sqrt1.0%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{y + x} \]
      9. sqrt-unprod23.4%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{y + x} \]
      10. sqr-neg23.4%

        \[\leadsto \frac{0 + \sqrt{\color{blue}{y \cdot y}}}{y + x} \]
      11. sqrt-unprod35.3%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{y} \cdot \sqrt{y}}}{y + x} \]
      12. add-sqr-sqrt67.5%

        \[\leadsto \frac{0 + \color{blue}{y}}{y + x} \]
    10. Applied egg-rr67.5%

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

        \[\leadsto \frac{\color{blue}{y}}{y + x} \]
    12. Simplified67.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{+171}:\\ \;\;\;\;\frac{\frac{x}{y}}{x + y} \cdot \left(-x\right)\\ \mathbf{elif}\;x \leq -5.4 \cdot 10^{+142}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -1 \cdot 10^{+59} \lor \neg \left(x \leq 3.75 \cdot 10^{+65}\right):\\ \;\;\;\;\frac{\frac{x}{y}}{x + y} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x + y}\\ \end{array} \]

Alternative 3: 59.5% accurate, 11.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{if}\;x \leq -8.5 \cdot 10^{+173}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{+137}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{+58} \lor \neg \left(x \leq 2.55 \cdot 10^{+65}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x + y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* x (/ (/ x y) (- y x)))))
   (if (<= x -8.5e+173)
     t_0
     (if (<= x -9.2e+137)
       (/ x y)
       (if (or (<= x -8.5e+58) (not (<= x 2.55e+65))) t_0 (/ y (+ x y)))))))
double code(double x, double y) {
	double t_0 = x * ((x / y) / (y - x));
	double tmp;
	if (x <= -8.5e+173) {
		tmp = t_0;
	} else if (x <= -9.2e+137) {
		tmp = x / y;
	} else if ((x <= -8.5e+58) || !(x <= 2.55e+65)) {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = x * ((x / y) / (y - x))
    if (x <= (-8.5d+173)) then
        tmp = t_0
    else if (x <= (-9.2d+137)) then
        tmp = x / y
    else if ((x <= (-8.5d+58)) .or. (.not. (x <= 2.55d+65))) then
        tmp = t_0
    else
        tmp = y / (x + y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = x * ((x / y) / (y - x));
	double tmp;
	if (x <= -8.5e+173) {
		tmp = t_0;
	} else if (x <= -9.2e+137) {
		tmp = x / y;
	} else if ((x <= -8.5e+58) || !(x <= 2.55e+65)) {
		tmp = t_0;
	} else {
		tmp = y / (x + y);
	}
	return tmp;
}
def code(x, y):
	t_0 = x * ((x / y) / (y - x))
	tmp = 0
	if x <= -8.5e+173:
		tmp = t_0
	elif x <= -9.2e+137:
		tmp = x / y
	elif (x <= -8.5e+58) or not (x <= 2.55e+65):
		tmp = t_0
	else:
		tmp = y / (x + y)
	return tmp
function code(x, y)
	t_0 = Float64(x * Float64(Float64(x / y) / Float64(y - x)))
	tmp = 0.0
	if (x <= -8.5e+173)
		tmp = t_0;
	elseif (x <= -9.2e+137)
		tmp = Float64(x / y);
	elseif ((x <= -8.5e+58) || !(x <= 2.55e+65))
		tmp = t_0;
	else
		tmp = Float64(y / Float64(x + y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = x * ((x / y) / (y - x));
	tmp = 0.0;
	if (x <= -8.5e+173)
		tmp = t_0;
	elseif (x <= -9.2e+137)
		tmp = x / y;
	elseif ((x <= -8.5e+58) || ~((x <= 2.55e+65)))
		tmp = t_0;
	else
		tmp = y / (x + y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(N[(x / y), $MachinePrecision] / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.5e+173], t$95$0, If[LessEqual[x, -9.2e+137], N[(x / y), $MachinePrecision], If[Or[LessEqual[x, -8.5e+58], N[Not[LessEqual[x, 2.55e+65]], $MachinePrecision]], t$95$0, N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -9.2 \cdot 10^{+137}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{elif}\;x \leq -8.5 \cdot 10^{+58} \lor \neg \left(x \leq 2.55 \cdot 10^{+65}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -8.5000000000000003e173 or -9.19999999999999997e137 < x < -8.50000000000000015e58 or 2.54999999999999994e65 < x

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Step-by-step derivation
      1. div-inv99.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Step-by-step derivation
      1. flip--14.2%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{{x}^{2}}{y}}}{y + x} \]
    7. Step-by-step derivation
      1. unpow214.9%

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

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

        \[\leadsto \frac{\color{blue}{\frac{x}{y} \cdot x}}{y + x} \]
    8. Simplified19.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\color{blue}{y} + \left(-x\right)} \]
      22. sub-neg32.4%

        \[\leadsto \left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{\color{blue}{y - x}} \]
    10. Applied egg-rr32.4%

      \[\leadsto \color{blue}{\left(x \cdot \frac{x}{y}\right) \cdot \frac{1}{y - x}} \]
    11. Step-by-step derivation
      1. associate-*l*52.8%

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

        \[\leadsto x \cdot \color{blue}{\frac{\frac{x}{y} \cdot 1}{y - x}} \]
      3. *-rgt-identity52.9%

        \[\leadsto x \cdot \frac{\color{blue}{\frac{x}{y}}}{y - x} \]
    12. Simplified52.9%

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

    if -8.5000000000000003e173 < x < -9.19999999999999997e137

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Step-by-step derivation
      1. div-inv99.5%

        \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{\left|y\right|}} \]
      2. add-sqr-sqrt29.8%

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

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

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

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

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

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

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

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

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

    if -8.50000000000000015e58 < x < 2.54999999999999994e65

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Step-by-step derivation
      1. div-inv99.7%

        \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{\left|y\right|}} \]
      2. add-sqr-sqrt47.0%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\left|y\right|} \cdot \left(x - y\right)} \]
      6. add-sqr-sqrt9.0%

        \[\leadsto \frac{1}{\left|\color{blue}{\sqrt{y} \cdot \sqrt{y}}\right|} \cdot \left(x - y\right) \]
      7. fabs-sqr9.0%

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

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Step-by-step derivation
      1. flip--16.9%

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

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

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

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

      \[\leadsto \frac{\frac{1}{y} \cdot \color{blue}{\left(-1 \cdot {y}^{2}\right)}}{y + x} \]
    7. Step-by-step derivation
      1. unpow21.8%

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

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

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

      \[\leadsto \frac{\frac{1}{y} \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)}}{y + x} \]
    9. Step-by-step derivation
      1. associate-*r*2.1%

        \[\leadsto \frac{\color{blue}{\left(\frac{1}{y} \cdot y\right) \cdot \left(-y\right)}}{y + x} \]
      2. lft-mult-inverse2.1%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{0} + \left(-y\right)}{y + x} \]
      8. add-sqr-sqrt1.0%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{y + x} \]
      9. sqrt-unprod23.4%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{y + x} \]
      10. sqr-neg23.4%

        \[\leadsto \frac{0 + \sqrt{\color{blue}{y \cdot y}}}{y + x} \]
      11. sqrt-unprod35.3%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{y} \cdot \sqrt{y}}}{y + x} \]
      12. add-sqr-sqrt67.5%

        \[\leadsto \frac{0 + \color{blue}{y}}{y + x} \]
    10. Applied egg-rr67.5%

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

        \[\leadsto \frac{\color{blue}{y}}{y + x} \]
    12. Simplified67.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+173}:\\ \;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{+137}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{+58} \lor \neg \left(x \leq 2.55 \cdot 10^{+65}\right):\\ \;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x + y}\\ \end{array} \]

Alternative 4: 57.4% accurate, 18.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-71}:\\
\;\;\;\;\frac{y}{x + y}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.8e-71

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Step-by-step derivation
      1. div-inv99.6%

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

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

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

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

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

        \[\leadsto \frac{1}{\left|\color{blue}{\sqrt{y} \cdot \sqrt{y}}\right|} \cdot \left(x - y\right) \]
      7. fabs-sqr0.0%

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

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Step-by-step derivation
      1. flip--5.3%

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

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

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

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

      \[\leadsto \frac{\frac{1}{y} \cdot \color{blue}{\left(-1 \cdot {y}^{2}\right)}}{y + x} \]
    7. Step-by-step derivation
      1. unpow21.8%

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

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

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

      \[\leadsto \frac{\frac{1}{y} \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)}}{y + x} \]
    9. Step-by-step derivation
      1. associate-*r*2.2%

        \[\leadsto \frac{\color{blue}{\left(\frac{1}{y} \cdot y\right) \cdot \left(-y\right)}}{y + x} \]
      2. lft-mult-inverse2.2%

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

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

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

        \[\leadsto \frac{\color{blue}{\log 1} - y}{y + x} \]
      6. sub-neg2.2%

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

        \[\leadsto \frac{\color{blue}{0} + \left(-y\right)}{y + x} \]
      8. add-sqr-sqrt2.2%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{y + x} \]
      9. sqrt-unprod1.8%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{\left(-y\right) \cdot \left(-y\right)}}}{y + x} \]
      10. sqr-neg1.8%

        \[\leadsto \frac{0 + \sqrt{\color{blue}{y \cdot y}}}{y + x} \]
      11. sqrt-unprod0.0%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{y} \cdot \sqrt{y}}}{y + x} \]
      12. add-sqr-sqrt60.5%

        \[\leadsto \frac{0 + \color{blue}{y}}{y + x} \]
    10. Applied egg-rr60.5%

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

        \[\leadsto \frac{\color{blue}{y}}{y + x} \]
    12. Simplified60.5%

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

    if -4.8e-71 < y < 3.4999999999999999e-199

    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-sqrt49.7%

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

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

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

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

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

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

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

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

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

    if 3.4999999999999999e-199 < y

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Step-by-step derivation
      1. div-inv99.6%

        \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{\left|y\right|}} \]
      2. add-sqr-sqrt14.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Step-by-step derivation
      1. flip--7.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{y} \cdot \frac{1}{-\left(y + x\right)} \]
      4. distribute-neg-in2.3%

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

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

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

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

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

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

        \[\leadsto y \cdot \frac{1}{\color{blue}{y - x}} \]
    10. Applied egg-rr61.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.8 \cdot 10^{-71}:\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-199}:\\ \;\;\;\;\frac{x}{y} + -1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{1}{y - x}\\ \end{array} \]

Alternative 5: 57.6% accurate, 22.4× speedup?

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

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. Step-by-step derivation
      1. div-inv99.6%

        \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{\left|y\right|}} \]
      2. add-sqr-sqrt41.4%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\left|y\right|} \cdot \left(x - y\right)} \]
      6. add-sqr-sqrt8.8%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \left(x - y\right)} \]
    4. Step-by-step derivation
      1. flip--6.7%

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

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

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

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

      \[\leadsto \frac{\frac{1}{y} \cdot \color{blue}{\left(-1 \cdot {y}^{2}\right)}}{y + x} \]
    7. Step-by-step derivation
      1. unpow21.8%

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

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

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

      \[\leadsto \frac{\frac{1}{y} \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)}}{y + x} \]
    9. Step-by-step derivation
      1. associate-*r*2.3%

        \[\leadsto \frac{\color{blue}{\left(\frac{1}{y} \cdot y\right) \cdot \left(-y\right)}}{y + x} \]
      2. lft-mult-inverse2.3%

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

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

        \[\leadsto \frac{\color{blue}{0 - y}}{y + x} \]
      5. metadata-eval2.3%

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

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

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

        \[\leadsto \frac{0 + \color{blue}{\sqrt{-y} \cdot \sqrt{-y}}}{y + x} \]
      9. sqrt-unprod20.1%

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

        \[\leadsto \frac{0 + \sqrt{\color{blue}{y \cdot y}}}{y + x} \]
      11. sqrt-unprod35.4%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{y} \cdot \sqrt{y}}}{y + x} \]
      12. add-sqr-sqrt61.0%

        \[\leadsto \frac{0 + \color{blue}{y}}{y + x} \]
    10. Applied egg-rr61.0%

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

        \[\leadsto \frac{\color{blue}{y}}{y + x} \]
    12. Simplified61.0%

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

    if -3.79999999999999992e-71 < y < 3.4999999999999999e-199

    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-sqrt49.7%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.8 \cdot 10^{-71} \lor \neg \left(y \leq 3.5 \cdot 10^{-199}\right):\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} + -1\\ \end{array} \]

Alternative 6: 26.2% 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. Step-by-step derivation
    1. div-inv99.6%

      \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{\left|y\right|}} \]
    2. add-sqr-sqrt45.4%

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

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

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

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

      \[\leadsto \frac{1}{\left|\color{blue}{\sqrt{y} \cdot \sqrt{y}}\right|} \cdot \left(x - y\right) \]
    7. fabs-sqr11.7%

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

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

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

    \[\leadsto \color{blue}{\frac{x}{y}} \]
  5. Final simplification27.3%

    \[\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. Step-by-step derivation
    1. div-inv99.6%

      \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{\left|y\right|}} \]
    2. add-sqr-sqrt45.4%

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

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

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

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

      \[\leadsto \frac{1}{\left|\color{blue}{\sqrt{y} \cdot \sqrt{y}}\right|} \cdot \left(x - y\right) \]
    7. fabs-sqr11.7%

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

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

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

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

    \[\leadsto -1 \]

Reproduce

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