A common refrain is not to define Subscript
as a variable. For instance, Subscript[x, j]
is an expression that depends on x
and j
, as though Subscript
were a function. You cannot treat x
and Subscript[x, 0]
as independent variables. The following give errors:
Solve[x == Subscript[x, 0], x]
x = Subscript[x, 0]
Clear[x]
You can use Clear[Subscript]
or ClearAll[Subscript]
to clear the definitions, but it clears all of them. Maybe you don't want to clear all of them and lose the previous definitions of your other Subscript
variables. In that case, you have to use Unset
on each definition you wish to clear, which Marvin Ray Burns has shown.
This can be inconvenient for complicated function definitions.
Subscript[f, 1][x_, n_Integer, n_Integer] := 1 + x/n;
Subscript[f, 1][x_, m_Integer, n_Integer] /; m < n :=
1 + x*Subscript[f, 1][x, m + 1, n]/m;
Subscript[f, 1][x_, n_Integer?NonNegative] := Subscript[f, 1][x, 1, n];
Subscript[f, 1][1., 17] - E
(* 0. *)
To clear the definitions of Subscript[f, 1]
, I have to unset each of the three definitions.
Subscript[f, 1][x_, n_Integer, n_Integer] =.
Subscript[f, 1][x_, m_Integer, n_Integer] /; m < n =.
Subscript[f, 1][x_, n_Integer?NonNegative] =.
The main problem here is if I make a typo, execute, fix the typo, and reexecute, I have a definition that is hidden, that I have to find in order to unset it. I can find the definition with the following:
?? Subscript
Another problem with Subscript
definitions is that Attributes
are attributed only to symbols, not expressions. I cannot make Subscript[f, 1]
have the attributes Listable
, HoldAll
, etc.