Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5

Percentage Accurate: 100.0% → 100.0%
Time: 4.7s
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|\frac{y - x}{y}\right| \end{array} \]
(FPCore (x y) :precision binary64 (fabs (/ (- y x) y)))
double code(double x, double y) {
	return fabs(((y - x) / y));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = abs(((y - x) / y))
end function
public static double code(double x, double y) {
	return Math.abs(((y - x) / y));
}
def code(x, y):
	return math.fabs(((y - x) / y))
function code(x, y)
	return abs(Float64(Float64(y - x) / y))
end
function tmp = code(x, y)
	tmp = abs(((y - x) / y));
end
code[x_, y_] := N[Abs[N[(N[(y - x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

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

    \[\frac{\left|x - y\right|}{\left|y\right|} \]
  2. 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|} \]
  3. Applied egg-rr100.0%

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

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

Alternative 2: 82.2% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{-58}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{1}{y}\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-48}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \left(\frac{1}{y + x} \cdot \frac{y + x}{y}\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -2.4e-58)
   (* (- y x) (/ 1.0 y))
   (if (<= y 1.2e-48)
     (fabs (/ x y))
     (* (- y x) (* (/ 1.0 (+ y x)) (/ (+ y x) y))))))
double code(double x, double y) {
	double tmp;
	if (y <= -2.4e-58) {
		tmp = (y - x) * (1.0 / y);
	} else if (y <= 1.2e-48) {
		tmp = fabs((x / y));
	} else {
		tmp = (y - x) * ((1.0 / (y + x)) * ((y + x) / y));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-2.4d-58)) then
        tmp = (y - x) * (1.0d0 / y)
    else if (y <= 1.2d-48) then
        tmp = abs((x / y))
    else
        tmp = (y - x) * ((1.0d0 / (y + x)) * ((y + x) / y))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -2.4e-58) {
		tmp = (y - x) * (1.0 / y);
	} else if (y <= 1.2e-48) {
		tmp = Math.abs((x / y));
	} else {
		tmp = (y - x) * ((1.0 / (y + x)) * ((y + x) / y));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -2.4e-58:
		tmp = (y - x) * (1.0 / y)
	elif y <= 1.2e-48:
		tmp = math.fabs((x / y))
	else:
		tmp = (y - x) * ((1.0 / (y + x)) * ((y + x) / y))
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -2.4e-58)
		tmp = Float64(Float64(y - x) * Float64(1.0 / y));
	elseif (y <= 1.2e-48)
		tmp = abs(Float64(x / y));
	else
		tmp = Float64(Float64(y - x) * Float64(Float64(1.0 / Float64(y + x)) * Float64(Float64(y + x) / y)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -2.4e-58)
		tmp = (y - x) * (1.0 / y);
	elseif (y <= 1.2e-48)
		tmp = abs((x / y));
	else
		tmp = (y - x) * ((1.0 / (y + x)) * ((y + x) / y));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -2.4e-58], N[(N[(y - x), $MachinePrecision] * N[(1.0 / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.2e-48], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], N[(N[(y - x), $MachinePrecision] * N[(N[(1.0 / N[(y + x), $MachinePrecision]), $MachinePrecision] * N[(N[(y + x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-58}:\\
\;\;\;\;\left(y - x\right) \cdot \frac{1}{y}\\

\mathbf{elif}\;y \leq 1.2 \cdot 10^{-48}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\

\mathbf{else}:\\
\;\;\;\;\left(y - x\right) \cdot \left(\frac{1}{y + x} \cdot \frac{y + x}{y}\right)\\


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

    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-sqrt90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(x - y\right) \cdot \frac{\color{blue}{y + x}}{y}}{y \cdot y - x \cdot x} \cdot \left(y - x\right) \]
      7. cancel-sign-sub-inv4.9%

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

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

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

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

        \[\leadsto \left(y - x\right) \cdot \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(y, y, \left(-x\right) \cdot x\right)}{\frac{y + x}{y}}}} \]
      3. fma-udef5.0%

        \[\leadsto \left(y - x\right) \cdot \frac{x - y}{\frac{\color{blue}{y \cdot y + \left(-x\right) \cdot x}}{\frac{y + x}{y}}} \]
      4. cancel-sign-sub-inv5.0%

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

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

      \[\leadsto \color{blue}{\left(y - x\right) \cdot \frac{x - y}{\frac{y \cdot y - x \cdot x}{\frac{x + y}{y}}}} \]
    10. Step-by-step derivation
      1. expm1-log1p-u4.9%

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

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

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

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

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

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

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

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

    if -2.4000000000000001e-58 < y < 1.2e-48

    1. Initial program 100.0%

      \[\frac{\left|x - y\right|}{\left|y\right|} \]
    2. 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|} \]
    3. Applied egg-rr100.0%

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

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

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

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

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

    if 1.2e-48 < y

    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-sqrt15.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(x - y\right) \cdot \frac{\color{blue}{y + x}}{y}}{y \cdot y - x \cdot x} \cdot \left(y - x\right) \]
      7. cancel-sign-sub-inv6.8%

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

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

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

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

        \[\leadsto \left(y - x\right) \cdot \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(y, y, \left(-x\right) \cdot x\right)}{\frac{y + x}{y}}}} \]
      3. fma-udef7.0%

        \[\leadsto \left(y - x\right) \cdot \frac{x - y}{\frac{\color{blue}{y \cdot y + \left(-x\right) \cdot x}}{\frac{y + x}{y}}} \]
      4. cancel-sign-sub-inv7.0%

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

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

      \[\leadsto \color{blue}{\left(y - x\right) \cdot \frac{x - y}{\frac{y \cdot y - x \cdot x}{\frac{x + y}{y}}}} \]
    10. Step-by-step derivation
      1. *-un-lft-identity7.0%

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

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

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

        \[\leadsto \left(y - x\right) \cdot \frac{1 \cdot \left(x - y\right)}{\color{blue}{\left(y - x\right)} \cdot y} \]
      5. times-frac16.6%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{-58}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{1}{y}\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-48}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \left(\frac{1}{y + x} \cdot \frac{y + x}{y}\right)\\ \end{array} \]

Alternative 3: 73.6% accurate, 18.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{-203} \lor \neg \left(y \leq 1.9 \cdot 10^{-297}\right):\\
\;\;\;\;\left(y - x\right) \cdot \frac{1}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -8.40000000000000008e-203 or 1.90000000000000002e-297 < y

    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-sqrt48.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \frac{y + x}{y}}{\mathsf{fma}\left(y, y, \left(-x\right) \cdot x\right)} \cdot \left(y - x\right)} \]
    8. Step-by-step derivation
      1. *-commutative12.5%

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

        \[\leadsto \left(y - x\right) \cdot \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(y, y, \left(-x\right) \cdot x\right)}{\frac{y + x}{y}}}} \]
      3. fma-udef11.8%

        \[\leadsto \left(y - x\right) \cdot \frac{x - y}{\frac{\color{blue}{y \cdot y + \left(-x\right) \cdot x}}{\frac{y + x}{y}}} \]
      4. cancel-sign-sub-inv11.8%

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

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

      \[\leadsto \color{blue}{\left(y - x\right) \cdot \frac{x - y}{\frac{y \cdot y - x \cdot x}{\frac{x + y}{y}}}} \]
    10. Step-by-step derivation
      1. expm1-log1p-u5.7%

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

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

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

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

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

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

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

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

    if -8.40000000000000008e-203 < y < 1.90000000000000002e-297

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8.4 \cdot 10^{-203} \lor \neg \left(y \leq 1.9 \cdot 10^{-297}\right):\\ \;\;\;\;\left(y - x\right) \cdot \frac{1}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]

Alternative 4: 57.9% accurate, 22.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-58} \lor \neg \left(y \leq 8 \cdot 10^{-49}\right):\\
\;\;\;\;\frac{y}{y + x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -9.4999999999999994e-58 or 7.99999999999999949e-49 < y

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{y}} \cdot \left(x - y\right) \]
    3. Applied egg-rr13.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. difference-of-squares5.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, -1, x - y\right)}}{y + x} \]
      6. sub-neg1.8%

        \[\leadsto \frac{\mathsf{fma}\left(x, -1, \color{blue}{x + \left(-y\right)}\right)}{y + x} \]
      7. add-sqr-sqrt0.8%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(x, -1, x + \sqrt{\color{blue}{y \cdot y}}\right)}{y + x} \]
      10. sqrt-prod38.9%

        \[\leadsto \frac{\mathsf{fma}\left(x, -1, x + \color{blue}{\sqrt{y} \cdot \sqrt{y}}\right)}{y + x} \]
      11. add-sqr-sqrt79.4%

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, -1, x + y\right)}}{y + x} \]
    9. Step-by-step derivation
      1. fma-udef79.4%

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

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

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

        \[\leadsto \frac{\color{blue}{\left(0 - x\right)} + \left(x + y\right)}{y + x} \]
      5. associate--r-79.4%

        \[\leadsto \frac{\color{blue}{0 - \left(x - \left(x + y\right)\right)}}{y + x} \]
      6. neg-sub079.4%

        \[\leadsto \frac{\color{blue}{-\left(x - \left(x + y\right)\right)}}{y + x} \]
      7. neg-mul-179.4%

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{1} \cdot y}{y + x} \]
      14. *-lft-identity79.5%

        \[\leadsto \frac{\color{blue}{y}}{y + x} \]
    10. Simplified79.5%

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

    if -9.4999999999999994e-58 < y < 7.99999999999999949e-49

    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-sqrt46.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.5 \cdot 10^{-58} \lor \neg \left(y \leq 8 \cdot 10^{-49}\right):\\ \;\;\;\;\frac{y}{y + x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]

Alternative 5: 2.6% accurate, 68.3× speedup?

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

\\
\frac{0}{x}
\end{array}
Derivation
  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-sqrt48.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{x + -1 \cdot x}}{x} \]
    2. mul-1-neg2.7%

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

      \[\leadsto \frac{\color{blue}{x - x}}{x} \]
    4. +-inverses2.7%

      \[\leadsto \frac{\color{blue}{0}}{x} \]
  9. Simplified2.7%

    \[\leadsto \color{blue}{\frac{0}{x}} \]
  10. Final simplification2.7%

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

Alternative 6: 27.7% 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.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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 2023238 
(FPCore (x y)
  :name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
  :precision binary64
  (/ (fabs (- x y)) (fabs y)))