Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subscripted variables

Is there any way to force Mathematica to treat subscripted variables independently of their unsubscripted counterparts? More specifically. Say, I have the following definitions:

Subscript[b, 1] = {{1, 2}}
Subscript[b, 2] = {{3, 4}}
b = Join[Subscript[b, 1], Subscript[b, 2]]

Now when I use

Subscript[b, 1] 

Mathematica will substitute it with

Subscript[{{1, 2}, {3, 4}},1]

when I want these to be three independent values, so changing b will not affect Subscript[b, ..]. Is it possible?

like image 655
Max Avatar asked Mar 30 '11 02:03

Max


1 Answers

In an answer to a previous SO question, Mathematica Notation and syntax mods, telefunkenvf14 mentioned that he was

hoping to use Notations to force MMA to treat subscripted variables as a symbol

which is essentially what this question is about.

WReach pointed out that the Notation package can do this quite simply using Symbolize

Needs["Notation`"];
Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]]

Where (as in Daniel's answer) don't worry too much about the Box structure above as you can use the Notation palette to enter this stuff in more simply.

Check that it all works as wanted:

In[3]:= Subscript[a, b]//Head
        a = 1
        Subscript[a, b]

Out[3]= Symbol
Out[4]= 1
Out[5]= Subscript[a, b]

and

In[6]:= Subscript[b, 1] = {{1, 2}}
        Subscript[b, 2] = {{3, 4}}
        b = Join[Subscript[b, 1], Subscript[b, 2]]
Out[6]= {{1, 2}}
Out[7]= {{3, 4}}
Out[8]= {{1, 2}, {3, 4}}

Note: all of the above code has been copied as Input Text, so the typeset SubscriptBoxs have been converted to the input form Subscripts. However, the Symbolize works at the box level, so the tests need to be converted back to their 2d forms. To do this, select the code (or cells) and convert it to standard form by using the Cell menu or the shortcut Ctrl-Shift-N. The notebook with all the above code should look like screenshot

like image 148
Simon Avatar answered Sep 25 '22 06:09

Simon