Consider the following:


$1 = 1^2$
$2 + 2 = 2^2$
$3 + 3 + 3 = 3^2$


Therefore,


$\underbrace{x + x + x + \ldots + x}_{x \textrm{ times}}= x^2$


Take the derivative of lhs and rhs and we get:


$\underbrace{1 + 1 + 1 + \ldots + 1}_{x \textrm{ times}} = 2x$


Which simplifies to:


$x = 2x$


and hence 


$1 = 2$.




Clearly something is wrong but I am unable pinpoint my mistake.

You cannot take the derivative of $\underbrace{x + x + x + \dots + x}_{\text{repeated $x$ times}}$ with respect to $x$ one term at a time because the number of terms depends on $x$.

Even beyond that, if you can express $x^2$ as $\underbrace{x + x + x + \dots + x}_{\text{repeated $x$ times}}$, then $x$ must be an integer, and if the domain of the expression is the integers, (continuous) differentiation does not make sense and/or the derivatives do not exist.

(edit: I gave my first reason first because the second reason can be smoothed over by taking "repeated $x$ times" to mean something like $\underset{\lfloor x\rfloor\mathrm{\ addends}}{\underbrace{x+x+\cdots+x}}+(x-\lfloor x\rfloor)\cdot x$.)
