Integrate $1/x$ by parts.

The antiderivative is well-defined only up to adding in a local* constant. To be more precise, we might explicitly specify an equivalence relation rather than writing equality. That is, we might write something like

$$ \int \frac{1}{x} \, \mathrm{d}x \equiv \ln x $$

where the equivalence sign means

$ f \equiv g$ if and only if there exists a local constant $C$ such that, for all values of $x$, $g(x)-f(x) = C$

(note that a single value of $C$ is supposed to work for all $x$)

Now, with this convention, your equation should be written

$$ \int \frac{1}{x} \, \mathrm{d}x \equiv 1 + \int \frac{1}{x} \, \mathrm{d}x $$

And then when we subtract off the integral from both sides (which we can do, because $\int f \mathrm{d}x \equiv \int f \mathrm{d}x$), we get

$$ 0 \equiv 1 $$

And this is true: e.g. we could pick $C=1$ if we substitute in the definition of equivalence.

By convention we know that if an antiderivative appears in an equation, that equation is supposed to be an equivalence, not an equality. By writing the equivalence relation explicitly, it helps us avoid a mistake -- when we cancel out the antiderivative, we might mistakenly forget that the result is still only supposed to be an equivalence.


*: In many situations, "local constant" simply means "constant". However, in situations where we are interested in a domain that is made up of disconnected intervals -- e.g. when considering the function $1/x$ on the domain of all nonzero real numbers -- there can be different constants on each interval. e.g. $f'(x) = 1/x$ if and only if there are constants $A$ and $B$ such that

$$ f(x) = \begin{cases} \ln(x) + A & x > 0 \\ \ln(-x) + B & x < 0 \end{cases} $$

or put differently, $ f(x) = \ln |x| + C(x)$, where $C$ is the function

$$ C(x) = \begin{cases} A & x > 0 \\ B & x < 0 \end{cases} $$

The terminology "local constant" is in reference to the idea that near any particular point in the domain -- i.e. 'local' to that point -- the function actually is constant. e.g. near $a = 0.01$, $C(x)$ is simply the constant value $A$ for any $x$ with $|x-a| < 0.01$.


You cannot cancel out $\int \frac{1}{x}dx$ on both sides, because $\int \frac{1}{x}dx$ is a family of functions (up to a constant factor $C$).