How to find the elasticity of substitution for the general CES-function? I have to find the EOS for the general CES-function defined as

$$
y = (a_1x_1^p+a_2x_2^p)^{1/p}
$$

I first find $MP_1$ and $MP_2$ to find $MRTS$. We have that

$MP_1 = \frac{\partial y} {\partial x_1} = \frac{1}{p} (a_1x_1^p+a_2x_2^p)^{1/p} \cdot pa_1x_1^{p-1}$

$MP_2 = \frac{\partial y} {\partial x_2} = \frac{1}{p} (a_1x_1^p+a_2x_2^p)^{1/p} \cdot pa_2x_2^{p-1}$

and thus 

$MTRS = - \frac{MP_1}{MP_2} = - \frac{a_1x_1^{p-1}}{a_2x_2^{p-1}}$

By definition EOS is given by

$$
\sigma = \frac{d(x_2/x_1)}{dMTRS} \frac{MTRS}{(x_2/x_1)}
$$
so to find $x_2/x_1$ I have done the following. Let $\theta = - \frac{a_1x_1^{p-1}}{a_2x_2^{p-1}}$ then we have
$$
\frac{1}{\theta} = - \frac{a_2x_2^{p-1}}{a_1x_1^{p-1}} \Rightarrow \frac{x_2^{p-1}}{x_1^{p-1}} = - \frac{1}{\theta} \frac{a_1}{a_2} \Rightarrow \frac{x_2}{x_1} = (- \frac{1}{\theta} \frac{a_1}{a_2})^{\frac{1}{p-1}}
$$
Thus
$$
\sigma = \frac{d(- \frac{1}{\theta} \frac{a_1}{a_2})^{\frac{1}{p-1}}}{d \theta} \cdot \frac{\theta}{(- \frac{1}{\theta} \frac{a_1}{a_2})^{\frac{1}{p-1}}} = -\frac{1}{p-1}
$$
which does not give the desired result that $\sigma = \frac{1}{p+1}$. Where am I doing wrong?
four things :


The desired result is actually
 which is the answer you are getting if you multiply the negative into the denominator( you can cross-check on https://en.wikipedia.org/wiki/Constant_elasticity_of_substitution)
. However, you have made the following mistakes. 
NON CONSEQUENTIAL ERROR: Your first error is when you differentiate to get MP1 and MP2. In both these cases, the long term should have power : (1/p - 1 ). This term gets canceled hence doesn't affect the solution. 


Further MRTS(marginal rate of technical sub) = MP1/MP2 and not - MP1/MP2. This is because MRTS is the absolute number of factor x2 that has to be given up to employ one more unit of factor x1 while keeping the production constant( moving along the same isoquant curve). MRTS is always taken as positive. This is because the negative sign of the slope simply implies the "giving up" which is implicit in the definition of opportunity cost. 
However, in both of your mistakes, your error got canceled due to the symmetry of the numerator and denominator. Hence you are actually getting the right answer.  Your method is a little long. I am posting here the way I do it :