# Dividing rational expressions

How come I am able to divide the following:

$$\frac{2}{2} = 1$$

Yet I am not allowed to divide the $2x$'s in the following:

$$x^2 + \frac{2x}{2x} = x^2 + 1$$

Why can't I divide the $2x$ in numerator with $2x$ in denominator to get $1$? They are both equal parts, and just like in the first example should be allowed to be divided.

The functions $f(x)=x^2+\frac{2x}{2x}$ and $g(x)=x^2+1$ are in fact equal wherever they are both defined, but they’re not defined on the same subsets of $\Bbb R$: $g$ is defined on all of $\Bbb R$, while $f$ is not defined at $x=0$. Thus, they are not the same function, despite agreeing at every point except $0$.