explaining the derivative of $x^x$ You set the following exercise to your calculus class:

Q1. Differentiate $y(x) = x^x$.

A student submits the following solution:

Let $g(a)=a^x$ and $f(x)=x$.  Then $y(x) = g(f(x))$, so by the chain rule, $y'(x) = f'(x) g'(f(x)) = 1 \cdot x \cdot (x^{x-1}) = x^x$.

How would you explain to the student why their solution is incorrect?
To be clear, I know why this is wrong but am interested in good ways to explain it to undergraduate or high school students.
In this question someone has problems differentiating $x^x$, but they didn't take the approach of my hypothetical student.
 A: Well, an important first step is to convince them that their argument is, in fact, wrong.  A simple appeal to the geometric meaning of the derivative can be very useful in this regard.  Not only does this provide a very clear and easy to understand demonstration of the incorrectness of their result but it also encourages them to think about the derivative in more than one way.  All too often students at this level think purely algebraically, without serious geometric consideration.
So start with a simple plot of the graph of $x^x$, which any reasonable mathematical software should be able to provide:

Now, the graph lies completely above the $x$-axis, so the function value is always positive.  The slope of the graph is clearly negative, however, just to the right of the $y$-axis. Thus, there is no way that this function can be its own derivative.
A: I would try to explain that the notation $h'$ doesn't just mean the derivative of $h$ but the derivative of $h$ with respect to some particular variable, the variable being determined by the context. In the student's answer, $y'$ is $dy/dx$, but $g'$ is $dg/da$, when what's needed is $dg/dx$. 
A: The $g(a) = a^x$ is invalid, because the argument is $a$ and $x$ appears as a free variable. If a function's body has a free variable, that has to be defined somewhere as a constant or a globally understood parameter.
A function cannot have a free variable that refers to the argument of another function.
The correct version of $g$ is $g(a) = a^a$.
The function $g$ raises the argument to itself; it does not raise its argument to $x$. $x$ is a dummy variable in the definition of $f(x)$, which is another function. And what if the dummy variable in $f(x)$ is some thing else, like $f(b) = b$? 
Think about how this would work in some functional programming language in computing:
function f(x)
   return x

function g(a)
   return pow(a, x)

Look, g is referring to x, but the only x that we see is local in another function's scope! There is no visible binding for x in the scope of g's body, so it is a free variable. Moreover, we can edit f into:
function f(b)
   return b

without changing the meaning of the program. So now there isn't an x anywhere.
In mathematics, functions can often be regarded as macros! But they are not blind, textual macros; they are hygienic macros. Substitution in math formulas is on structure not text, and it obeys scoping rules by maintaining lexical transparency.
For instance consider this following student reasoning error. Let $f(x) = x\times x$ and let $g(y) = y + y$. Therefore, since manipulation of mathematic formulas is just dumb textual substitution like preprocessor macros in the C language, $f(g(3)) = 3 + 3 * 3 + 3$, and so the value is $f(g(3)) = 3 + 9 + 3 = 15$. And in general $f(g(z)) = z^2 + 2z$. What is wrong?
Since substitution in math formulas follows structure, $f(g(z))$ cannot be $z^2 + 2z$. $f$ multiplies whatever object comes out of $g$ without breaking apart its syntax, and so the necessary parentheses have to be shown when it is all put together: $f(g(z)) = (z + z)(z + z) = 4z^2$.
The rule of lexical transparency is this: that when we substitute a formula $\alpha$ as a replacement for some symbol in another formula $\beta$, all of the symbols in $\beta$, all of the symbols in $\alpha$ continue to have exactly the same meaning. Even if $\beta$ has symbols which have the same names, those symbols do not capture any of the references in $\alpha$.
To prevent confusion, if such a situation arises where there is a confusion between symbols in an inserted formula and in the target of insertion, we should perform a variable renaming.
A: Try going through the incorrect argument with $g(a) = \dfrac ax$.
Then we have $g(f(x)) = 1$ but $f'(x)\cdot g'(f(x)) = \dfrac 1x$.
At this point most students will try to explain why your argument is different from theirs, and why their argument works but yours doesn't. If not you can give them a little encouragement to find the hole in your version of the argument.
That way the student will do all the work for you, which is a good way of learning.
A: My attempt would proceed along the following lines.

You defined $g(a) = a^x$; since the $x$ does not occur as an argument to the function, it is taken to be constant. This is not consistent with differentiating our expression with respect to $x$.
Therefore, the function $g$ should actually admit $x$ as a parameter as well: $g(a,x) = a^x$.

At which point we run into the difficulty of the chain rule for partial differentiation being unavailable (despite this approach giving a very clean, universal solution to differentiating expressions with multiple occurrences of the relevant variable).
I can imagine two reasonable courses of action from here:

*

*Indicate the "standard" high school solution via $x^x = \exp(x\log x)$;

*Introduce the more complicated chain rule, illustrating it e.g. by deriving the product rule.

A: I think the easiest way is to show why $g'(a) = x * a^{x-1}$ is incorrect
Its common for students to think that this can be done because of the similar differentiation rule.
for
$y = x^n$
$y' = n * x^{n-1}$
The key is to understand that the function g in NOT in the form of $y = x^n$
See here for the neatest three line proof of the power rule I've ever seen
A: You already have several good answers to your question, but here's a related incorrect solution.
We know these derivatives:


*

*$(x^n)' = n\cdot x^{n-1}$

*$(a^x)' = a^x \ln a$


Misunderstanding the problem then leads to two incorrect answers:


*

*$(x^x)' = x\cdot x^{x-1} = x^x$

*$(x^x)' = x^x\ln x$


The correct answer, of course, is $(x^x)'= x^x(1 + \ln x)$. Whaddya know? Two wrongs don't make a right, but in this case the sum of two wrongs does make a right.
A: First of all, the student introduces the function $g$ that is dependent on $a$ and $x$. But he overlooks the $x$ dependence in his solution. But if he had done it correctly it could have worked:
$$g:\mathbb{R}^2 \to \mathbb{R}:(a,x)\to a^x$$
Then $h(x)=g(f(x),x)$ and
$$h'(x)=\frac{\partial g}{\partial a}\!\! \left(f(x),x\right)\frac{df}{dx}+\frac{\partial g}{\partial x}\!\! \left(f(x),x\right)\frac{dx}{dx}\\
= x x^{x-1}+x^x \ln x = x^x(1+\ln x) \; .$$
Of course, this is an explanation he might only get completely if he is familiar with partial derivatives.
A: First, ask them whether $a^x \circ y^2$ is $y^{2x}$ or $a^{y^2}$. Now, ask them to find $(\frac{d}{dx} a^x) \circ y$. Is this $ln(y)y^x$ or $ln(a)a^x$? In contrast, take $\frac{d}{da} a^x$. In each of these derivatives, one of $\{a, x\}$ is treated as a constant.
Take a right triangle, and extrude it to a triangular prism. The change in the hypotenuse with respect to a base is a constant. The change along the core of the prism is 0 for any point along the hypotenuse. Let $f(a,x)=x.$ What's the change along the a-axis? The x-axis? These are not equivalent to the change in height as one moves from one corner to the other of the extruded hypotenuse - compare $f(a,x)=a^2x$ and its derivatives in $a$ and $x$ to $f(x,x)=x^3$, and its derivative with respect to $x$.
When the chain rule says $(f\circ g(x))'=f'(g(x))g'(x),$ what is the variable of differentiation and what are the variables of composition? Recalling the derivatives of $a^x$, how does one infer the variables of composition from the variable of differentiation?
A: whenever there is a function in which the variable is in the power of the function then we use the transformation to the exponential basis i.e :
a^x = e^(x*lna)
here a is also a F(x) =x;
so,
x^x= e^(x*lnx)
now take the derivative of RHS it is:
d(e^y)/dx=e^y.d(y)/dx;
so,
d(e^(xlnx))/dx=e^(xlnx).d(xlnx)/dx; eq -------(A)
since, d(xlnx)/dx = x.(1/x)+lnx.(1); by parts eq----------(B)
and x^x= e^(x*lnx)
so eq(A) becomes,
d(x^x)/dx= x^x* (1+lnx); from eqA and eqB
..... answer
A: At times of doubt, it helps to abandon the shorthand  used for functions, and state everything completely explicitly. Here, the argument being presented is as follows:

Let $g$ be a function such that there is a number $x$ for which $g(a)=a^x$ for all $a$, and let $f$ be the identity function: $f(x)=x$ for all $x$. Then, $\color{red}{y(x)=g(f(x))}$, so by the chain rule...

It is the final line highlighted in red that is problematic. Generally, when we write something like "$y(x)=g(f(x))$", it is understood that this equation is true for all $x$. So $y(x)=g(f(x))$ actually means $y=g \circ f$; that is, the composition of $g$ and $f$ is the same function as $y$. This means that $y'(x)=(g \circ f)'(x)$ for all $x$.
In this case, however, the functions $y$ and $g \circ f$ just happen to have the same value at a particular point $x$, and so while it is true that $y(x)=g(f(x))$, there is no reason to believe that $y'(x)=(g \circ f)'(x)$. Remember that
$$
y'(x)=\lim_{h \to 0}\frac{(x+h)^{x+h}-x^x}{h} \, ,
$$
whereas
$$
(g \circ f)'(x)=g'(x)=\lim_{h \to 0}\frac{(a+h)^{x}-a^x}{h}\Biggr|_{a=x}=xa^{x-1}\Biggr|_{a=x}=x^x \, .
$$
The chain rule computes $(g \circ f)'(x)$, but not $y'(x)$.
