1
$\begingroup$

I can't find a Clear or ClearAll command that gets rid of Derivative definitions I created. this code:

ClearAll["Global`*"];
gau[x_, v_] = (1/Sqrt[2*Pi*v])*E^-((x^2)/(2*v));
Derivative[0, n_][p][x, v] := Simplify[D[gau[z, v], {v, n}]];
ClearAll["Global`*"];
gau[x_, v_] = (1/Sqrt[2*Pi*v])*E^-((x^2)/(2*v));
Derivative[0, n_][p][x, v] := Simplify[D[gau[z, v], {v, n}]/gau[z, v]];
D[p[x, v], {v, 2}]

produces output consistent with the 1st definition, not the second.

$\endgroup$
1
$\begingroup$

First of all you most likely want to define your functions with patterns x_, y_ instead of fixed symbols x, y. Second, you can use Unset to achieve what (I think) you want. This is needed because Derivative is not in the Global context, but instead in the System context. So your ClearAll command doesn't affect it. But you also don't want to just say ClearAll[Derivative] because that may remove definitions you still need. Unset is more specific. You use it as follows:

Derivative[0,n_][p][x_,v_]=.

This can still be combined with the ClearAll["Global*"]; that you already had, to make sure other definitions are removed.

$\endgroup$
  • $\begingroup$ Will ClearAll[Derivative] only clear the derivs that I defined? Or will it mess up MMa built-in functions? $\endgroup$ – Jerry Guern Mar 5 '15 at 7:09
  • 1
    $\begingroup$ Since Derivative is not protected, ClearAll[Derivative] would indeed affect its properties. E.g., I checked SubValues[Derivative] before and after, and there is a difference... $\endgroup$ – Jens Mar 5 '15 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.