Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5

Percentage Accurate: 100.0% → 100.0%
Time: 4.2s
Alternatives: 6
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 6 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: 58.1% accurate, 13.5× speedup?

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

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

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

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

\mathbf{elif}\;x \leq 2.4 \cdot 10^{+162}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -8.1999999999999999e52

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.1999999999999999e52 < x < -2.15000000000000007e-10 or -1.60000000000000009e-31 < x < 2.40000000000000009e162

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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*1.8%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{y}}{y + x} \]
    12. Simplified70.7%

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

    if -2.15000000000000007e-10 < x < -1.60000000000000009e-31

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.40000000000000009e162 < x

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.2 \cdot 10^{+52}:\\ \;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{-10}:\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-31}:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{x + y}\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+162}:\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} + -1\\ \end{array} \]

Alternative 3: 58.0% accurate, 15.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+52}:\\ \;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-11} \lor \neg \left(x \leq -1.65 \cdot 10^{-31}\right) \land x \leq 5.4 \cdot 10^{+163}:\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} + -1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -8.5e+52)
   (* x (/ (/ x y) (- y x)))
   (if (or (<= x -9.5e-11) (and (not (<= x -1.65e-31)) (<= x 5.4e+163)))
     (/ y (+ x y))
     (+ (/ x y) -1.0))))
double code(double x, double y) {
	double tmp;
	if (x <= -8.5e+52) {
		tmp = x * ((x / y) / (y - x));
	} else if ((x <= -9.5e-11) || (!(x <= -1.65e-31) && (x <= 5.4e+163))) {
		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 (x <= (-8.5d+52)) then
        tmp = x * ((x / y) / (y - x))
    else if ((x <= (-9.5d-11)) .or. (.not. (x <= (-1.65d-31))) .and. (x <= 5.4d+163)) 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 (x <= -8.5e+52) {
		tmp = x * ((x / y) / (y - x));
	} else if ((x <= -9.5e-11) || (!(x <= -1.65e-31) && (x <= 5.4e+163))) {
		tmp = y / (x + y);
	} else {
		tmp = (x / y) + -1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -8.5e+52:
		tmp = x * ((x / y) / (y - x))
	elif (x <= -9.5e-11) or (not (x <= -1.65e-31) and (x <= 5.4e+163)):
		tmp = y / (x + y)
	else:
		tmp = (x / y) + -1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -8.5e+52)
		tmp = Float64(x * Float64(Float64(x / y) / Float64(y - x)));
	elseif ((x <= -9.5e-11) || (!(x <= -1.65e-31) && (x <= 5.4e+163)))
		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 (x <= -8.5e+52)
		tmp = x * ((x / y) / (y - x));
	elseif ((x <= -9.5e-11) || (~((x <= -1.65e-31)) && (x <= 5.4e+163)))
		tmp = y / (x + y);
	else
		tmp = (x / y) + -1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -8.5e+52], N[(x * N[(N[(x / y), $MachinePrecision] / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -9.5e-11], And[N[Not[LessEqual[x, -1.65e-31]], $MachinePrecision], LessEqual[x, 5.4e+163]]], N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -9.5 \cdot 10^{-11} \lor \neg \left(x \leq -1.65 \cdot 10^{-31}\right) \land x \leq 5.4 \cdot 10^{+163}:\\
\;\;\;\;\frac{y}{x + y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -8.49999999999999994e52

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.49999999999999994e52 < x < -9.49999999999999951e-11 or -1.65e-31 < x < 5.39999999999999998e163

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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*1.8%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{y}}{y + x} \]
    12. Simplified70.7%

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

    if -9.49999999999999951e-11 < x < -1.65e-31 or 5.39999999999999998e163 < x

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+52}:\\ \;\;\;\;x \cdot \frac{\frac{x}{y}}{y - x}\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-11} \lor \neg \left(x \leq -1.65 \cdot 10^{-31}\right) \land x \leq 5.4 \cdot 10^{+163}:\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} + -1\\ \end{array} \]

Alternative 4: 57.3% accurate, 22.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.8e-39 or 1.5000000000000001e-12 < 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-sqrt51.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{y}}{y + x} \]
    12. Simplified73.6%

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

    if -1.8e-39 < y < 1.5000000000000001e-12

    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-sqrt44.0%

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

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

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

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

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

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

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

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

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

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

Alternative 5: 25.9% 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-sqrt49.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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