3

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.

Jerry Guern
  • 4,602
  • 18
  • 47

1 Answers1

3

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.

Jens
  • 97,245
  • 7
  • 213
  • 499
  • Will ClearAll[Derivative] only clear the derivs that I defined? Or will it mess up MMa built-in functions? – Jerry Guern Mar 05 '15 at 07:09
  • 1
    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... – Jens Mar 05 '15 at 14:41
  • Is the reason you recommend patterns here incase he tries to find a function with different variable names (than x,v)? – user106860 Oct 20 '20 at 15:56