Message Boards Message Boards

1
|
20983 Views
|
7 Replies
|
10 Total Likes
View groups...
Share
Share this post:

Am I allowed to use subscript in function arguments?

Posted 11 years ago

Mathematica seems to allow function arguments with subscript but the coloring (typesetting seems to be different). Does anyone have experience with that?

Please check the screenshot.enter image description here

Kind Regards, Mathias Breuss

POSTED BY: Mathias Breuss
7 Replies

Sander, what Bruce didn't mention in the text of his post (but which he does show in his notebook) is that one has to load the Notation` package and use the Symbolize function before using his approach.

POSTED BY: David Reiss

I see now, thanks for clarifying!

POSTED BY: Sander Huisman

It can be done by putting a colon between the subscripted object and the underscore.

f[ Subscript[k, 1]:_, Subscript[k, 2]:_ ] := 1- (Subscript[k, 1] Subscript[k, 2] ) / (Subscript[k, 1] - Subscript[k, 2])

StandardForm version of above code

Subscripted objects can be used in executable code, but doing it robustly takes work.
See the attached notebook for a mini-tutorial.

If you can postpone subscripted variables for the presentations, after the calculations are finished, it might be much less trouble.

Hi Matthias,

This is generally not a good idea: WR_ (subscripted) is seen as:

Times[Blank[],Subscript[W,R]]

while WR_ (no subscript) is seen as:

Pattern[WR,Blank[]]

Which are fundamentally different. Moreover, the first argument of Pattern must be a symbol, i.e. not something with a Head different from Symbol (e.g. Subscript). Try not to use subscripts in Mathematica, it doesn't work very nice. See for example:

r=2;
r+Subscript[r, a]

outputs:

2+Subscript[2, a]

I.e. the ra (subscript) is seen as variable r with a subscript, not a new variable by itself.

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract

Be respectful. Review our Community Guidelines to understand your role and responsibilities. Community Terms of Use