# Alternative notation to [[i]], [[i,j]], etc. for the elements of a Table?

GROUPS:
 Gernot H 1 Vote Hi,since I am finding the notation {...}[] or {{...},...{...}}[[i,j]], etc, to address the elements of Tables very cumbersome, I am looking for an alternative. Isn't there a possibility to enter the indices in a 2-D math way, as a subscript? All these square brackets make expressions often hard to overlook. I am wasting a lot of time hunting down bracket errors. This would be so much better in a 2-D notation.Does anyone know such a way of notation?Thanks!
10 months ago
10 Replies
 Hi,you can try to generalize the following idea:f[arg_] := Module[{}, arg /. Subscript[a_, b_] :>  data[[b]]];x_\[CircleDot]y_ := f[y];data = {a, b, c};f\[CircleDot]Subscript[x, 1]f\[CircleDot]Subscript[x, 2]f\[CircleDot]Subscript[x, 3]I.M.
10 months ago
 Bill Simpson 2 Votes A word of caution, you may end up replacing your wasted time hunting down bracket errors with an even greater amount of wasted time hunting down subscript problems. There is even a tutorial that someone wrote to try to explain how to avoid some of the problems with subscriptshttp://forums.wolfram.com/student-support/filedownload.cgi?CommentAttachment=1376428543-30335-4493.nb&CommentAttachmentName=SubscriptedVariables101.nband some have even advised not using these at all.Subscripted variables are not "real variables", that has nothing to do with Real versus Complex numbers. I don't think anyone has ever really given the history of these, but my guess was that these were sort of glued onto the system after a lot of other incompatible and barely compatible decisions had been made and could not be changed.Sometimes they work. In a complicated piece of code filled with subscripted variables that actually works I am always very surprised. In a complicated piece of code filled with subscripted variables that doesn't work the first thing I do is try to eliminate all the subscripts and see if the code works then.
10 months ago
 Completely agree with Bill's argument, such manipulations should be generally avoided.I'm just curious, why the code below fails to work? In[4]:= data = {a, b, c};  f[arg_] := Module[{}, arg /. Subscript[a_, b_] :> data[[b]]]; Subscript[x_, y_] := Apply[f, {Subscript[x, y]}]; Subscript[x, 1]  During evaluation of In[4]:= $RecursionLimit::reclim: Recursion depth of 256 exceeded. >> During evaluation of In[4]:=$RecursionLimit::reclim: Recursion depth of 256 exceeded. >> During evaluation of In[4]:= $RecursionLimit::reclim: Recursion depth of 256 exceeded. >>During evaluation of In[4]:= General::stop: Further output of$RecursionLimit::reclim will be suppressed during this calculation. >>...Out[7]= \$Aborted
10 months ago
 1. Evaluate Subscript[x,1]2. which evaluates Subscript[x_,y_]3. which evaluates Apply[f,{Subscript[x,y]}]which starts step 2 all over again.That doesn't even really rise to the level of criticizing Subscript, you need to find a completely incomprehensible Subscript failure to qualify for that.
10 months ago
 Thank you,  Bill, now it's clear to me
10 months ago
 You can type it in many ways: You really need more??
 The very first thing I do after installing a new version of Mathematica is setting up keyboard shortcuts for typing the double brackets you get with ESC [[ ESC.You can find the file named KeyEventTranslations.tr in the installation directory and add the following after the line EventTranslations[{ Item[KeyEvent["[", Modifiers -> {Command}], FrontEndExecute[{FrontEndNotebookWrite[FrontEndInputNotebook[], "\[LeftDoubleBracket]", After]}]], Item[KeyEvent["]", Modifiers -> {Command}], FrontEndExecute[{FrontEndNotebookWrite[FrontEndInputNotebook[], "\[RightDoubleBracket]", After]}]], Do make a backup of the file before doing any modifications and put the backup outside of the Mathematica installation directory (or at least make sure you don't add extra files with a .tr extension).On Windows/Linux I use the Control modifier instead of Command.Now you can use Command-[ and Command-] to type these double brackets.  I'm so used to this at this point that I almost can't work at all with Mathematica without this modification.