Why applying this algebraic logarithm identity changes the function output?

I have fear this is an extremely ridiculous and basic question. But let's say we have

$f(x) = \ln(x^2)$

by applying one of the most basic identities for logarithms, it should be possible to say that

$f(x) = \ln(x^2) = 2 \ln(x)$

However, it seems this actually changes the function. If I evaluate $\ln(x^2)$ with a negative number, I will certainly get a real number. However, the second version will result in a complex number. For example:

$\ln((-10)^2) = 4.60517019$

$2 \ln(-10) = 4.60517019 + 6.28318531\text { }i$

Can someone explain where is my error?

• The identity you have used requires $x>0$. Even Wikipedia remembers this en.wikipedia.org/wiki/… (although they put the condition after their block of displayed identities). – Eric Towers Jun 16 '14 at 16:07
• To make this even worse, the logarithm is multivalued in non-positive values. – Alice Ryhl Jun 16 '14 at 17:17

Let $f(x)=\ln x^2$ and $g(x)=2 \ln x$. The domain of $f$ is actually $(-\infty, 0) \cup (0,\infty)$, whereas the domain of $g$ is $(0, \infty)$. They are same only when $x>0$. Hence they will not be the same for a negative input.