17

Consider the case where a symbol has multiple definitions attached to it,

a /: Subscript[a,2] := 1
a[b_] := 2
a[b_, c_] := 3

How does one clear (/unset/remove) only one of those definitions while leaving the others intact?

rcollyer
  • 33,976
  • 7
  • 92
  • 191
David
  • 14,911
  • 6
  • 51
  • 81

2 Answers2

19

You can use Unset for this, like so:

a[b_, c_] =.

=. works with UpValues too (the full form of this has TagUnset):

a /: Subscript[a,2] =.

You need to use the same pattern in Unset that you used in the definition. Get this using Information (i.e. ?a).

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
16

You can use Unset or =. to remove a single definition. For example, for your above function its DownValues are

DownValues@a
Out[1]= {HoldPattern[a[b_]] :> 2, HoldPattern[a[b_, c_]] :> 3}

Unsetting the definition for a[b_, c_],

a[b_, c_] =.
DownValues@a
Out[2]= {HoldPattern[a[b_]] :> 2}

It works similarly for UpValues too, i.e., you can do a /: Subscript[a,2]=. to clear that particular UpValue

rm -rf
  • 88,781
  • 21
  • 293
  • 472