Where is the flaw in this "proof" that 1=2? (Derivative of repeated addition) 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.
 A: You cannot differentiate the LHS of your equation

$x + x + x + \cdots$ (repeated $x$ times) = $x^2$

This is because the LHS is not a continuous function; the number of terms depends on $x$ so the LHS is not well defined when $x$ is not an integer. We can only differentiate continuous functions, so this is not valid.
A: 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$.)
A: Lets define what is x+x+x+... x times for x - real. Natural definition is x+x+x.. := x*x (note - just the same as Isaac has wrote in his edit).  
Suppose we want left our initial definition as is. We don't know what is x+x+.. repeat x times for x - real (and note we don't have rule how to obtain derivative from such func). So lets use definition of derivative. f(x):=x+x+x.. repeat x times, Df(x)=(f(x+h)-f(x))/h, h->0. Df(x)=((x+h+x+h+x+h.. repeat x+h times) - (x+x+x.. repeat x times))/h, h->0. Suppose x+x+... repeat a+b times := (x+x+.. repeat a times) + (x+x+.. repeat b times) we have Df(x)=((x+h+x+h+x+h.. repeat x times) - (x+x+x.. repeat x times) + (x+h+x+h+x+h.. repeat h times))/h, h->0, Df(x)=((h+h+h.. repeat x times) + (x+h+x+h+x+h.. repeat h times))/h, h->0, or Df(x)=(1+1+1.. repeat x times) + (x+h+x+h+x+h.. repeat 1 times), h->0 and at last Df(x)=x + x+h, h->0 = 2x
A: Applying the sum rule in differentiation we get:
$$\forall k \in \mathbb {N} \,(k\,f(x))' = k\,f'(x).$$
The symbol $x$ does not represent any value, it is simply a placeholder meaning that $$\forall x \,(kf)'(x)=(kf')(x).$$
I skip the mention that $x\in X$, where $X \in dom(f)$ to make it look more simple.
So we get
$$\forall k \in \mathbb {N} \,\bigl( \forall x \,(kf)'(x)=(kf')(x)\bigr).$$
As we see now, we can't substitute $k$ with $x$, because $x$ is from  the scope of the quantifier $\forall x$.
But we can substitute $k$ and $x$ with the same number, for example, with 4, and get the right state. We get
$$(4f)'(4)=(4f')(4),$$ so $$(4id)'(4)=\textbf{4} (4)=4= (4\,\mathbf{1})(4)=(4\, id')(4),$$  where $\textbf{1}$ and $\textbf{4}$ are constant functions.
A: Here is a nice way to write this joke ...
$$
x^2 = \underbrace{\color{red}{x} + \color{red}{x} + \color{red}{x} + \dots + \color{red}{x}}_{\text{repeated $\color{blue}{x}$ times}}
$$ 
To differentiate the right side, use the chain rule for partial derivatives.  We get two terms.  One where we differentiate the red $x$ in the top line, the other when we differentiate the blue $x$ in the bottom line:
$$
\underbrace{1 + 1 + 1 + \dots + 1}_{\text{repeated $x$ times}}\quad
+\quad
\underbrace{x + x + x + \dots + x}_{\text{repeated $1$ times}}
$$
and this is of course the right answer
$$
\frac{d}{dx}(x^2) = x + x = 2x,
$$
A: Here's my explanation from an old sci.math post:

Zachary Turner  wrote on 26 Jul 2002:

Let D = d/dx = derivative wrt x. Then
D[x^2] = D[x  +   x  + ... +   x  (x times)]
       = D[x] + D[x] + ... + D[x] (x times)
       =   1  +   1  + ... +   1  (x times)
       =   x


An obvious analogous fallacious argument proves both


*

*$ $ D[x f(x)]  =  Df(x) (x  times) = x Df(x)

*$ $ D[x f(x)]  =   Dx (f(x) times) = f(x), via  Dx = 1
vs.  the correct result: their sum  $\rm\:f(x) + x\, Df(x)\:$
as given by the Leibniz product rule (= chain rule for times).
The error arises from overlooking the dependence upon x in both
arguments of the product  $\rm\: x \ f(x)\:$  when applying the chain rule.
The source of the error becomes clearer if we consider a
discrete analog. This will also eliminate any tangential
concerns on the meaning of "(x times)" for non-integer x.
Namely, we consider the shift operator  $\rm\ S:\, n \to n+1\ $  on polynomials  $\rm\:p(n)\:$ with integer coefficients, where  $\rm\:S p(n) = p(n+1).\:$ Here is a similar fallacy
  S[n^2] =  S[n  +   n  + ... +   n  (n times)]
         =  S[n] + S[n] + ... + S[n] (n times)
         =  1+n  + 1+n  + ... + 1+n  (n times)
         = (1+n)n

But correct is  $\rm\ S[n^2] = (n+1)^2.\:$ Here the "product rule" is
 $\rm\ S[fg] = S[f]\, S[g],\ $ not  $\rm\: S[f] g\:$  as above.
The fallacy actually boils down to operator noncommutativity.
On the space of functions $\rm\:f(x),\:$ consider "x" as the linear
operator of multiplication by  x, so  $\rm\ x:\, f(x) \to x f(x).\:$ Then
the linear operators  $\rm\:D\:$  and  $\rm\:x\:$  generate an operator algebra
 of polynomials  $\rm\:p(x,D)\:$ in NON-commutative indeterminates $\rm\:x,D\:$
since we have
  (Dx)[f] = D[xf] = xD[f] + f = (xD+1)[f], so  Dx = xD + 1 ≠ xD

  (Sn)[f] = S[nf] = (n+1)S[f], so  Sn = (n+1)S ≠ nS

This view reveals the error as mistakenly
assuming commutativity of the operators  $\rm\:x,D\:$  or  $\rm\:n,S.$
Perhaps something to ponder on boring commutes !
A: We can create the same "paradox" with finite differences over integers.
Given $f: \mathbb Z \to \mathbb Z$ define the "discrete derivative"
$$
\Delta f (n)=f(n+1)-f(n)
$$
we have the following obvious "theorems":


*

*$\Delta(n)=n+1-n=1$

*$\Delta(n^2)=(n+1)^2-n^2=2n+1$

*$\Delta (f_1+\cdots +f_k)=\Delta f_1 + \cdots +\Delta f_k$

*$f(n)=g(n) \; \forall n \quad \implies \quad \Delta f(n)=\Delta g(n) \; \forall n$


So we can start with the correct equality:
$$
\underbrace{n + n + n + \ldots + n}_{n \textrm{ times}}= n^2
$$
and we apply $\Delta$ on both sides taking advantage from the "theorems" above: we get
$$
\underbrace{1 + 1 + 1 + \ldots + 1}_{n \textrm{ times}} = 2n+1
$$
so we conclude $n=2n+1$ and we have the paradox.
Here maybe the mistake is more clear: the rule $\Delta (f_1+\cdots +f_k)=\Delta f_1 + \cdots +\Delta f_k$ doesn't work when $k$ is a function (of the same variable of the $f_i$), in fact it amounts to do a computation like this:
$$
\Delta(\underbrace{n + \ldots + n}_{n \textrm{ times}})=
\underbrace{(n+1) + \ldots + (n+1)}_{\color{Red}{n \textrm{ times}}}-(\underbrace{n + \ldots + n}_{n \textrm{ times}})=n
$$
that is wrong, the right way being this:
$$
\Delta(\underbrace{n + \ldots + n}_{n \textrm{ times}})=
\underbrace{(n+1) + \ldots + (n+1)}_{\color{Green}{(n+1) \textrm{ times}}}-(\underbrace{n + \ldots + n}_{n \textrm{ times}})=n+(n+1).
$$
A: I think the discrete/continuous issue is sort of a red herring.  To me, the problem is forgetting to use the chain rule!
To un-discretize, think of the function $F(u,v) = uv$, which we could think of as $u + \dots + u$, $v$ times.  Then $x^2 = F(x,x)$.  Differentiating both sides gives $2x = F_u(x,x) + F_v(x,x)$, which is perfectly true.  In the fallacious example, the problem is essentially that the $F_v$ term has been omitted.  In some sense, one has forgotten to differentiate the operation "$x$ times" with respect to $x$!  Of course, the notation makes this easier to do.
A: It has already been pointed out that “$x$ times” makes sense only for integer $x$, and several ways of salvaging the example for continuous $x$ have been given.  Here is another informal interpretation that seems fitting for first-semester calculus.  The continuous analog of a discrete sum is a definite integral.  So let’s define adding up a constant quantity $f(x)$ “$x$ times” by the integral
$$\int_0^x f(x) \; dt \,.$$
Differentiating* this yields
$$\int_0^x f’(x) \; dt + f(x) \,.$$
For $f(x)=x$, we get
$${d \over dx} \int_0^x x \; dt = \int_0^x 1 \; dt + x \,.$$
In words, the derivative equals $1$ added $x$ times plus $x$ added once, which is exactly what @GEdgar derived and similar to @arena-ru.

*There are two ways to explain the differentiation.  One is through the product rule applied to $\int_0^x f(x)\,dt=f(x) \int_0^x dt$, and the other is through the multivariate chain rule applied to $G(u,v)=\int_0^u v\,dt$.
A: That differentiation step is invalid, because that equation is not actually differentiable, because its domain is comprised of isolated points, because $x\in\mathbb Z_0^+;$ to wit:

In general, if a theorem's condition(s) have not been fulfilled, then its consequence is not guaranteed.
P.S. A note on the above notation: What does $\mathbb{R}_0^+$ mean?
A: The problem is that the equation $x + \cdots + x = x^2$ only holds for two values of $x$, namely if you added $x$ with itself $n$ times, it holds at $x=0$ and $x=n$. Therefore your equation becomes $nx = x^2$, the differential is $n = 2x$ (the number of terms in the LHS of the equation should not depend on the real/complex parameter $x$) and the only thing you can deduce from this is that the first equation is equivalent to $x^2 - nx = x(x-n) = 0$ and the second equation is $x=n/2$, so when $x=0$ or $x=n$ then the sum of the $x$'s and $x^2$ are equal, and when $x=n/2$ the derivative of the sum and $x^2$ are equal. The deduction that $1=2$ is simply not true. The equality $nx = x^2$ is not comparable to an equality like $\sin x^2 = 1 - \cos x^2$ : the equation $nx = x^2$ holds for only two values of $x$, where as the trigonometric equation holds for any real/complex value of $x$.
Hope that helps,
