Apparent dimensional mismatch after taking derivative Suppose I have a variable $x$ and a constant $a$, each having the dimension of length. That is $[x]=[a]=[L]$ where square brackets denote the dimension of the physical quantity contained within them. 
Now, we wish to take the derivative of $u = log (\frac{x^2}{a^2})-log (\frac{a^2}{x^2})$. Here, we have taken the natural logarithm. It is clear that $u$ is a dimensionless function. 
$$\frac{du}{dx} = \frac{a^2}{x^2}.\frac{2x}{a^2} - \frac{x^2}{a^2}.(-2a^2).\frac{2x}{x^3} \\
= \frac{1}{x} - 4. $$
Here, the dimensions of the two terms on the right do not match. The dimension of the first term is what I expected. Where am I going wrong? 


Where am I going wrong?

Recall
$$\frac{d}{dx}f(g(x))=f'(g(x))g'(x)$$
with
$$f(\cdot) = \ln(\cdot) \rightarrow f'(\cdot) = \frac{1}{\cdot}$$
and
$$g(x) = \frac{a^2}{x^2} \rightarrow g'(x) = \frac{-2a^2}{x^3}$$
Thus
$$\frac{d}{dx}\ln\frac{a^2}{x^2} = \frac{1}{\frac{a^2}{x^2}}\frac{-2a^2}{x^3} = -\frac{2}{x}$$

An alternative approach is to recognize
$$\ln x^{-2} = -2\ln x$$
thus
$$ \ln\frac{a^2}{x^2} = \ln a^2 + \ln x^{-2} = \ln a^2 -2 \ln x$$
for which we can immediately write the derivative.
