Q:

SetDelayed error for Derivative rule

Having a delayed assignment of the form
Derivative[1][f][x_] := HoldForm[f[x]]

works. But if there is a delayed assignment for f as in
f[x_] := g[x]
Derivative[1][f][x_] := HoldForm[f[x]]

the error
SetDelayed::write: Tag Function in ((g^\[Prime])[#1]&)[x_] is Protected.

occurs. Why is f[x] evaluated despite HoldForm and how can I write a delayed assignment of this form?

A:

The problem is that Derivative has a built-in definition that applies whenever f gets a DownValues. For example, suppose you define:
f[x_] := x^2

Then, f`, or in FullForm, Derivative[1][f] already has a definition:
Derivative[1][f]

2 #1 &

which, as you can see, is a pure function. So, trying to define:
Derivative[1][f][x_] := rhs

is equivalent to doing:
(2 #1 &)[x_] := rhs

and this is why you get an error, since it is not possible to define a definition for the protected symbol Function. If you want to overwrite the default derivative of a function, you need to use:
Derivative[1][f] = g;

Then:
f'[x]

g[x]

