# Recursion problem

I try to make designation

a = {Subscript[a,1], Subscript[a,2], Subscript[a,3]}


\$RecursionLimit::reclim: Recursion depth of 1024 exceeded.

Whats the problem?

• Don't use subscripts until you're an expert. A subscripted symbol isn't a symbol – Dr. belisarius Mar 18 '15 at 17:53
• @belisarius: Given Mathematica's formatting palettes etc., users are actually lead into using that quite common mathematical notation, especially when it comes to vectors, matrices etc... – Jinxed Mar 18 '15 at 19:02
• @Jinxed That's true, but it doesn't make the advice less valid. Subscripted variables should be usually avoided. If one really cannot live without them use the Notation package. – Sjoerd C. de Vries Mar 18 '15 at 23:13
• So what is subscripted stuff used for (except typsetting, of course)? I've browsed around for links, but all I found was warnings for beginners never to use them or to use the Notation package. – LLlAMnYP Mar 19 '15 at 0:00
• Its a little strange situation: its possible to Superscript (not the Power) but impossible to Subscript (not index). Its not good. In any case. Many thanks for all. Where to find wish list for mma? – SergeyFomin Mar 19 '15 at 5:13

The reason is, that while assigning, the a in Subscript[a,_] is replaced by the whole list of subscripts, and so on and so on, until the recursion limit is reached: Subscripts are no symbols by themselves.

To avoid this, you can either use another variable to assign to (b e.g.), or define the subscripts as proper symbols:

Needs["Notation"]

makesymbol[obj_]:=With[{},
If[NameQ@ToString@Unevaluated@obj,Remove@obj]; (* remove possibly existing symbol first *)
Symbolize@ParsedBoxWrapper@ToBoxes@obj;]       (* then create the new symbol *)


With this function, you can create a symbol like so:

makesymbol[Subscript[a,1]]


Mathematica will now treat it the same as any other (simpler) symbol.

Be sure to put the formatted variables into the list here, not the Subscript-form:

makesymbol /@ {Subscript[a, 1], Subscript[a, 2], Subscript[a, 3]}


and then your assignment will work without problems.

• makesymbol[Subscript[a,1]] doesnt return any result, makesymbol /@ {Subscript[a, 1], Subscript[a, 2], Subscript[a, 3]} return {Null,Null,Null} – SergeyFomin Mar 19 '15 at 5:22
• @SergeyFomin It's not supposed to return a result. However, after executing the above commands you are now able to use the subscripted variables treated with it as real variables. Look at the FullForm of a_1 with the subscript entered using the keyboard (using ctrl + _ on my US International keyboard) – Sjoerd C. de Vries Mar 19 '15 at 7:41
• @SergeyFomin: Did my answer work out for you? – Jinxed Mar 21 '15 at 16:17

My favorite approach when it's unavoidable to use such formatting is this simple trick:

a = {Subscript["a", 1], Subscript["a", 2], Subscript["a", 3]}

(* ==> {Subscript["a", 1], Subscript["a", 2], Subscript["a", 3]} *)


Just make the subscripted names into strings. You can then do things like a[[1]] or even Subscript["a", 1] = 10 without getting in trouble. The quotation marks also remind you that you're dealing with something more subtle: The value in the last assignment is stored in DownValues[Subscript]. This is the big difference in using Subscript versus regular symbol names, and one should never forget it.

As usual, you can find most of this by searching the following giant Q&A: What are the most common pitfalls awaiting new users?.