When is it correct to treat differential(e.g. $dx$) as regular number Many times I saw that people tread differentials as regular numbers. They for example multiply by them or divide. E.g. below there is multiplication of $\frac{df(x)}{d (x^2)}$ by $\frac{1/dx}{1/dx}$
$$\frac{df(x)}{d (x^2)} = \frac{df(x)/dx}{d(x^2)/dx} = \frac{1}{2 x} \frac{df(x)}{dx}$$
My question is when it is legal to do such things? Always in some specific cases? Are there some formal theories that formalize this nice trick?
 A: The symbols $dx$, $dy$, etc. can be thought of as "infinitesimals," which is how Newton thought of these (roughly speaking).  As the article below states, a rigorous approach to infinitesimals was undertaken in the 1960s.
http://www.sjsu.edu/faculty/watkins/infincalc.htm
There are many other references; just search nonstandard analysis.
And to answer the original question, as long as you treat $dx$ as a nonzero number smaller than any real number and such that $(dx)^2$ is equivalent to $0$ when taking sums, you can get away with the construction you showed in your question.
For example, if $f(x) = x^2$, then 
$$df = (x+dx)^2 - x^2 = x^2 + 2xdx + (dx)^2 - x^2 \equiv 2xdx$$
A: You have the chain rule $\frac{\mathrm d (f\circ g)}{\mathrm dx} = \frac{\mathrm df}{\mathrm dg}\frac{\mathrm dg}{\mathrm dx}$, which gives you $\frac{\mathrm df}{\mathrm dg} = \frac{\mathrm df}{\mathrm dx}\left(\frac{\mathrm dg}{\mathrm dx}\right)^{-1}$ whenever $f,\ g\in C^1$ (and possibly some other assumption on the derivative of g in x).
A: I have said this before, but it works out because the derivative is the limit of a ratio of 2 very small numbers.  So, the numbers may be maniuplated, so that $dy$ and $dx$ represent small quantities.  But the derivative is just that, and the notation $dy/dx$ is a mnemonic.  It is a testament to the clear thinking behind this notation that the Chain Rule resembles cancellation, thus making calculus that much easier for generations of students.
