Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

clearing a variable with a dummy subscript

273 views
Skip to first unread message

Andre Hautot

unread,
May 18, 2012, 5:27:53 AM5/18/12
to

Hi !
Here is something very simple I don't understand :

f[x_] := x; f[2] (*A function*)
2

Clear[f]; f[2] (*The same perfectly cleared as expected*)
f[2]


Subscript[u, k_] := k; Subscript[u, 2] (*u with subscript k_
entered via the palette*)
2

Clear[u]; Subscript[u, 2] (*I found no way to clear u; a
suggestion ?)
2

Thanks in advance,

ahautot


Bill Rowe

unread,
May 19, 2012, 5:47:06 AM5/19/12
to
Simply put, Subscript[u,2] is not a symbol (does not have head
Symbol) in Mathematica. Consequently, things designed to work
with symbols often don't work well with Subscript[u,2].

If you want to use Subscript[u,2] or something similar as a
variable your best choice is to load the Notation package. Use
the documentation center to locate the usage guide by searching
on notation package.


djmpark

unread,
May 19, 2012, 5:42:30 AM5/19/12
to
Use Unset.

Subscript[u, k_] =.


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/index.html



From: Andre Hautot [mailto:aha...@ulg.ac.be]


Hi !
Here is something very simple I don't understand :

f[x_] := x; f[2] (*A function*)
2

Clear[f]; f[2] (*The same perfectly cleared as expected*)
f[2]


Subscript[u, k_] := k; Subscript[u, 2] (*u with subscript k_
entered via the palette*)
2

Clear[u]; Subscript[u, 2] (*I found no way to clear u; a
suggestion ?)
2

Thanks in advance,

ahautot



A Retey

unread,
May 19, 2012, 5:44:02 AM5/19/12
to
Use:

Subscript[u, k_] =.

or (if you don't have other definitions for Subscript you want to keep):

Clear[Subscript]

the deeper reason is that this rule is stored in the DownValues of
Subscript:

Subscript[u, k_] := k;
DownValues[Subscript]

What you probably want to do is to store it as an UpValue to u instead
of a DownValue of Subscript:

u /: Subscript[u, k_] := k

DownValues[Subscript]
UpValues[u]

now you can get rid of the definition as expected:

Clear[u]

Subscript[u,2]


hth,

albert

Bob Hanlon

unread,
May 19, 2012, 5:45:03 AM5/19/12
to
Subscript[u, k_] := k

Subscript[u, 2]

2

This assignment is associated with Subscript rather than with u

You would need to clear Subscript.

Clear[Subscript]

Subscript[u, 2]

Subscript[u, 2]

However, if you had made multiple assignments with Subscript this
would clear all of them rather than just u

To associate the assignment with just u, use an upvalue (see help for
UpValues, UpSet, UpSetDelayed)

u /: Subscript[u, k_] := k

Subscript[u, 2]

2

Now Clear will work as you intended

Clear[u];

Subscript[u, 2]

Subscript[u, 2]


Bob Hanlon


On Fri, May 18, 2012 at 5:25 AM, Andre Hautot <aha...@ulg.ac.be> wrote:
>
> Hi !
> Here is something very simple I don't understand :
>
> f[x_] := x; f[2] (*A function*)
> 2
>
> Clear[f]; f[2] (*The same perfectly cleared as expected*)
> f[2]
>
>
> Subscript[u, k_] := k; Subscript[u, 2] (*u with subscrip=
t k_
> entered via the palette*)
> 2
>
> Clear[u]; Subscript[u, 2] (*I found no way to clear u;=

Peter Breitfeld

unread,
May 20, 2012, 2:34:56 AM5/20/12
to
The values of supcripted Variables are not associated with u, but to
Subscript:

Subscript[u,2]=123

DownValues[u] returns: {}

DownValues[Subscript] returns: {HoldPattern[u_2]:>123}

So to Clear, you must call:

Clear[Subscript]

(but then *all* subscripted variables are cleared)

--
_________________________________________________________________
Peter Breitfeld | Bad Saulgau, Germany | http://www.pBreitfeld.de

Christoph Lhotka

unread,
May 21, 2012, 5:59:07 AM5/21/12
to
Hello,

a workaround could be to delete just the entries of DownValues
which contain the symbol u.

To demonstrate I add to your example

Subscript[u, k_] := k; Subscript[u, 2]
2

another one of similar form:

Subscript[v, k_] := k; Subscript[v, 2]
2

Here are the values stored in the down values list of subscript:

DownValues[Subscript]

{HoldPattern[Subscript[v, k_]] :> k, HoldPattern[Subscript[u, k_]] :> k}

To delete definitions made just to u use something like

DownValues[Subscript] = Select[DownValues[Subscript], FreeQ[#, u,
\[Infinity]] &]
{HoldPattern[Subscript[v, k_]] :> k}

Now the definition for u_k is deleted

Subscript[u, 2]
Subscript[u, 2]

while the definition for v_k is still present

Subscript[v, 2]
2

To this end you could define something like:

myClear[x_Symbol] := Block[{},
DownValues[Subscript] = Select[DownValues[Subscript], FreeQ[#, x,
\[Infinity]] &]];

which works as expected:

myClear[v];Subscript[v,2]
Subscript[v,2]

Hope that helps,

Christoph



On 05/20/2012 08:34 AM, Peter Breitfeld wrote:
0 new messages