Where is the problem?
Subscript[k, 0] := 1;
Subscript[k, 1] := 2;
ClearAll["Global`*"]
Subscript[k, 0]
Subscript[k, 1]
Clear[Subscript[k, 0]]
Clear[Subscript[k, 1]]
Where is the problem?
Subscript[k, 0] := 1;
Subscript[k, 1] := 2;
ClearAll["Global`*"]
Subscript[k, 0]
Subscript[k, 1]
Clear[Subscript[k, 0]]
Clear[Subscript[k, 1]]
The problem is that your definitions are associated with Subscript not k.
Subscript is in the System context. I suspect that
(* ClearAll["System`*"] *)
would be a bad idea.
You could modify the definition of your symbols, so that they are associated with k
k /: Subscript[k, 0] := 1;
k /: Subscript[k, 1] := 2;
{Subscript[k, 0], Subscript[k, 1]}
(* {1, 2} *)
These can then be cleared
ClearAll["Global`*"]
{Subscript[k, 0], Subscript[k, 1]}
(* {Subscript[k, 0], Subscript[k, 1]} *)
Less drastically
Clear[k]
also works (don't specify the subscript, because the results isn't a symbol).
Subscript is in the System context. Thank you. How to show all subscripts in a notebook? Is there any code such as ?Global`* and ?System`*
– RF_1
Jun 21 '21 at 20:13
?Subscript will report subscripts - though I think you will need to click to expand the box containing the symbol information.
– mikado
Jun 21 '21 at 20:24
There is a very useful answer here: StackExchange 2017 by Michael E2 (I shouldn't get credit for this answer...)
Subscript[symbol, 1] = 1
Subscript[symbol, 2] = 2
Now you see it.
Subscript[symbol, 1]
Then you clear it by only retaining downvalues that don't depend on symbol
DownValues[Subscript] =
Cases[DownValues[Subscript], dv_ /; FreeQ[dv, symbol]]
Now you don't.
Subscript[symbol, 1]
One more way if you want to clear individual values.
Subscript[k, 0] := 1
Subscript[k, 1] := 2
You can clear one at a time this way:
Subscript[k, 0] =.
which clears the first one but leaves the second one alone.
Subscript[k, 0]
(*Subscript[k, 0]*)
Subscript[k, 1]
(2)
k[0]andk[1]. After assigning values the subscripted form would not appear in the output anyway. Prior to assigning values, if you want the subscripted form displayed, useFormat[k[n_]] := Subscript[k, n]to control the subsequent display. – Bob Hanlon Jun 21 '21 at 18:18