<s>[INST] How to derive identities For example:
$(a+b)^2 = a^2 + b^2 + 2ab$
$(a+b)^3 = a^3 + b^3 + 3ab(a+b)$
So my doubt regarding these identities are why does the identity differ when the power is changed and is there any derivation for it? 
 [/INST] You can use distribution, association, and commutation rules:
$$\begin{align}(a+b)^2 ~=~& (a+b)~(a+b)
\\ ~=~& a~(a+b)+b~(a+b)
\\ ~=~& a^2+ab+ba+b^2
\\ ~=~& a^2+b^2+2ab
\\[2ex]
(a+b)^3 ~=~& (a+b)^2~(a+b)
\\ ~=~& (a^2+b^2+2ab)~(a+b)
\\ ~=~& a(a^2+b^2+2ab)+b(a^2+b^2+2ab)
\\ ~=~& (a^3+ab^2+2a^2b)+(a^2b+b^3+2ab^2)
\\ ~=~& a^3+ 3a^2b + 3ab^3+ b^3
\\ ~=~& a^3+b^3+3ab~(a+b)
\\[3ex]
(a+b)^4 ~=~& a^4+b^4 + 2ab~\big(2(a^2+b^2)+3ab\big)
\end{align}$$
More generally, we go to the Binomial Theorem. $$(a+b)^n = \sum\limits_{k=1}^n {^{n}\mathsf C_{k}} ~a^k ~b^{n-k} $$
So $(a+b)^2 = a^2+ 2ab+b^2\\ (a+b)^3= a^3+3a^2b+3ab^2+b^3\\(a+b)^4 = a^4+4a^3b+6a^2b^2+4ab^3+b^4$
</s>