I was comparing integrals to their equivalent riemann sums, specifically the harmonic series and I derived that:
$$\displaystyle{\lim_{n \to \infty}} \int_{1/n}^{1} \frac{1}{x}dx = \displaystyle{\lim_{n \to \infty}}\sum_{k=1}^{n} \frac{1}{k}$$
The issue is that they are not equal and I don't know why. I found when I plugged in large numbers for n into the above expressions, the difference between $\int_{1/n}^{1} \frac{1}{x}dx$ and $\sum_{k=1}^{n} \frac{1}{k}$ approached, gamma, the Euler Mascheroni. I rewrote my equation to accomodate for the discrepancy:
$$\gamma +\displaystyle{\lim_{n \to \infty}} \int_{1/n}^{1} \frac{1}{x}dx = \displaystyle{\lim_{n \to \infty}}\sum_{k=1}^{n} \frac{1}{k}$$
And when I further simplified I found the main identity of gamma:
$$\gamma=\lim_{n \to \infty} \left ( -\ln(n)- \sum_{k=1}^{n} \frac{1}{k} \right ) $$
How could I have possibly known that there would be a constant difference between the two expressions without entering large numbers into my calculator? And what error did I make in my initial derivation?



IIRC, the first term of all summations are equal to the integral of the function within the sum. You can find the other terms of the sum by subtracting that integral from the sum.
Under your assumption:
$$\sum_{k=1}^{x} k = \frac{1}{2} x^{2}$$
This is incorrect and only an approximation of the function.
If you calculate what function approximates
$$-\frac{1}{2} x^{2} +\sum_{k=1}^{x} k$$
You would find the second term of the function, $\frac{1}{2} x$