Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
4  
=. works nicely for removing any of the last two definitions. You need TagUnset[] to remove the first one. –  J. M. Jan 18 '12 at 0:32
add comment

2 Answers 2

up vote 16 down vote accepted

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).

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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