On the simplest level, the difference is that x
is a symbol, which is an atomic object to a Mathematica kernel, while subscripting x
makes it an non-atomic expression, in this case an object with head Subscript
.
Clear[x]
{Head[x], AtomQ[x]}
{Symbol, True}
The FullForm
of a subscripted variable with subscript i
is
Subscript[x, i]
Its head is clearly Subscript
and it's not an atom.
Clear[x, i]; AtomQ[Subscript[x, i]]
False
On a deeper level, there is a difference in how assignments to symbols and subscripted objects are handled. In both cases, an expression of the form
{HoldPattern[...] :> a + b}
is recorded by the kernel. However, they are stored in different kinds of internal lists. An assignment to a symbol is stored as an own-value of the symbol; All assignments to subscripted variables are stored as down-values of Subscript
.
Clear[x]; x = a + b; OwnValues @ x
{HoldPattern[x] :> a + b}
Clear[Subscript, x, i]; Subscript[x, i] = a + b; DownValues @ Subscript
{HoldPattern[Subscript[x, i]] :> a + b}
If you were use many subscripted variables in a Mathematica session, you would build up a big list of rules in the down-values of Subscript
, slowing down references to subscripted variables. But this is probably not the worst problem encountered with Subscript
. Consider doing a long computation with subscripted variables. Somewhere in the notebook, you evaluate
Subscript[x, i] = a + b;
Now, much later later and in a distant cell, you want to take a symbolic derivative. Like so:
Clear[x, i]; D[Subscript[x, i][t], {t, 2}]
Derivative[2][a + b][t]
Not what you expected? It is so easy to forget that it is Subscript
that must be cleared.
Clear[Subscript]; D[Subscript[x, i][t], {t, 2}]
Derivative[2][Subscript[x, i]][t]
which will be rendered as $\tt{x_i''[t]}$. Looks good now, but how many other subscripted variables have you cleared along with $\tt{x_i}$?
AtomQ
andHead
around your variables to see the difference. This might be useful: mathematica.stackexchange.com/questions/38622/… $\endgroup$Subscript[x]
, so your definition is actually more about definingSubscript
than aboutx
. $\endgroup$?? Subscript
to see what Mathematica has done with your definition. It may also suggest to you why subscripted variables are fine for text formatting, but not so good for computation. $\endgroup$