How to "fix" $\int_{-1}^1 \frac {dx}{x^2}$ with complex numbers?

You are right that the integral is infinity and there isn't anything complex variables is going to do to change this. However, going to the complex numbers allows us to consider related integrals that are finite.

We can imagine the integral you wrote down as an integral over a path along the real axis in the complex plane. The function $1/z^2$ has a divergence at the origin $z=0$ and the fact that the path goes through this point is what is making the integral come out to infinity. When considering a real variable, if you're trying to get from positive to negative territory, you have no choice but to go through the origin. However in the complex plane you can move the integration path so that it "goes around" the origin.

The simplest way to do this is to shift the integration path up slightly in the imaginary direction. To that end, we consider $$ \int_{-1}^1\frac{1}{(x-i\epsilon)^2}dx$$ where $\epsilon$ is some arbitrariliy small positive integer. Now that you aren't going through any bad points, it turns out that naive use of the usual rules of integration is valid and we get $$\int_{-1}^1 \frac{1}{(x-i\epsilon)^2}dx = \left.\frac{-1}{x-i\epsilon}\right|_{-1}^1=-\frac{1}{1-i\epsilon}-\frac{1}{1+i\epsilon} = -\frac{2}{1+\epsilon^2}.$$

If you take the limit $\epsilon \to 0$ of this result you get $-2,$ your wrong answer from above. This means that we have a limit and integral that don't commute: $$ -2=\lim_{\epsilon\to0} \int_{-1}^1 \frac{1}{(x-i\epsilon)^2}dx \ne \int_{-1}^1 \lim_{\epsilon\to 0}\frac{1}{(x-i\epsilon)^2}dx=\infty.$$

So the $-2$ does seem to have a special meaning for the integral, although it is not its value. In fact, what is going on is that the integral along any complex path from $-1$ to $1$ that does not go through the origin has the value $-2$ (the reason for this is similar to the reason why conservative vector fields have path-independent integrals, if you're familiar. The antiderivative $-1/z$ is like a potential field). Seriously, the integral over any complex path is $-2$ provided it starts and ends at $-1$ and $1$, no matter what it does in between... except if it touches the origin. I should add that this isn't the case with any integrand (just like not all vector fields are conservative).

Granted this rather amazing path-independence property, it's no longer surprising that we don't see any inkling of an infinite divergence as we take $\epsilon\to 0.$ None of those lines from $-1+i\epsilon$ to $1+i\epsilon$ pass through the origin, since we have path independence, the limit is just taking the endpoints down to $-1$ and $1$ and anything can happen in the middle except touching the origin.

Going back to the real integral at hand, we have its definition as an improper integral $$ \int_{-1}^1\frac{dx}{x^2} = \lim_{a,b\to 0^+} \int_{-1}^{-b}\frac{dx}{x^2} + \int_a^1 \frac{dx}{x^2} = \lim_{a,b\to 0^+} -2 +\frac{1}{a}+\frac{1}{b} $$ which we can see takes the form $-2+\text{divergence}$ and in this case the divergence has a well-defined limit of $\infty.$ (Contrast this to the case where you're integrating, say, $1/x$ instead of $1/x^2$ and you'll see that the divergence takes the indeterminate form $\ln(a/b)$ so the improper integral does not exist.) So the $-2$ is sort of a residual when we disregard the divergence at the origin, in accord with it being the path-independent value of the complex integral.

Others have mentioned the Cauchy principal value which is a way of handling the divergence at the origin that is a little more forgiving than the improper integral since it restricts the above limit to be symmetric (i.e. along the line $a=b$) where behavior might be well-defined. Here, for the integral of $1/x^2,$ this just turns the divergence to $\lim_{a\to0^+} 2/a$ so we still just get infinity. (But in the case of $1/x$ mentioned above, the $\ln(a/b)$ becomes zero, which means the Cauchy principal value is defined.) Even though the principal value by this definition has no direct relationship to complex variables, it comes up so much in that arena that it is effectively part of that subject, so its possible this, and not the above path shifting, is what your TA was referring to, although as we've seen it does nothing for this particular integral.

However, the principal value is quite related to the integration along a particular complex path that avoids the divergence. Instead of shifting the whole path up as before, keep the path as normal from $-1$ until you get within a distance of $\epsilon$ of the origin, and then go around the origin in a semicircle. Then continue from $\epsilon$ to $1$ along the real axis. I'll take the semicircle above the origin rather than below, though it doesn't matter.

We know from path independence that this integral needs to come out to $-2$. We can split it up into two parts: the semicircle and the pieces along the real axis. The second part has the value $$ \int_{-1}^{-\epsilon}\frac{dx}{x^2}+ \int_\epsilon^1\frac{dx}{x^2} = -2+\frac{2}{\epsilon}$$ which we see is just like the principal value, only before you take the limit $\epsilon\to0.$ The integral around the semicircle must be $-2/\epsilon$ in order for the whole integral to come out to $-2$. So we see that the divergence from the principal part and the divergence from the integral around the circle cancel out. This gives a detailed view of how path independence is preserved for this integral, even when we get as close to the divergence as possible without touching it.


A way to give a value to such integral is to consider a principal value:

$$\text{PV}\int_{-1}^{1}\frac{dx}{x^2}=\lim_{\varepsilon\to 0^+}\left(\int_{-1}^{-\varepsilon}\frac{dx}{x^2}+\int_{\varepsilon}^{1}\frac{dx}{x^2}\right)=\lim_{\varepsilon\to 0^+} 2\left(-1+\frac{1}{\varepsilon}\right)=+\infty. $$ In general, you may "integrate through singularities" by deforming the integration path, avoiding the singularities through arcs of circles with radius $\varepsilon$, then considering the limit as $\varepsilon\to 0^+$.
For instance $\text{PV}\int_{-1}^{1}\frac{dx}{x}=0$, even if $\frac{1}{x}$ is not integrable over $(-1,1)$, strictly speaking.


Denote the path $\Gamma$ on the real line with a deformed contour that approaches zero around the origin

enter image description here Consider the following function

$$f(z) = \frac{1}{z^2}$$ Now to integrate

$$\int_{\Gamma} \frac{dz}{z^2} = \lim_{\varepsilon\to 0^+}\left(\int_{-1}^{-\varepsilon}\frac{dx}{x^2}+\int_{\varepsilon}^{1}\frac{dx}{x^2} +\int_{C_{\varepsilon}} \frac{dz}{z^2}\,dz\right)$$

Note that

$$\int_{C_{\varepsilon}} \frac{dz}{z^2}\,dz =-i \frac{1}{\varepsilon}\int^{\pi}_0 \frac{e^{i\theta}}{e^{2i\theta}} d \theta = -\frac{2}{\varepsilon} $$

This can be simplified to the following using the princpal value

$$\int_{\Gamma} \frac{dz}{z^2} = \lim_{\varepsilon\to 0^+}\left(-2+\frac{2}{\varepsilon}-\frac{2}{\varepsilon}\right) = -2$$

EDIT:

I made a mistake in evaluating the limit around the semi-circle.