Having a parameter with index and superscript

I would like to define an object / symbol in mathematics that will have several parameters, for example, something like: S=(1-t)({b_i}^x,{b_i}^y)+t({b_{i+1}}^x,{b_{i+1}}^y) (a type of LaTeX notation). In the example, I am trying to describe a line segment connecting two points b_i and b_{i+1} .

How can I define such an object in mathematica ?

I found the following two questions:

But I'm not sure that I use them correctly. I did the following. At first I called:

 Needs["Notation`"]; Symbolize[ ParsedBoxWrapper[ SubscriptBox["\[SelectionPlaceholder]", "\[Placeholder]"]]] Symbolize[ ParsedBoxWrapper[ SuperscriptBox["\[SelectionPlaceholder]", "\[Placeholder]"]]] 

Then I actually defined the object:

 (1 - t) {Subscript[b, i]^x, Subscript[b, i]^y} + t {Subscript[b, i + 1]^x, Subscript[b, i + 1]^y} 

Is this the right way to do what I want?

+4
source share
2 answers

I'm not quite sure that I understand what you want. The "object" you are talking about

 (1 - t) {Subscript[b, i]^x, Subscript[b, i]^y} + t {Subscript[b, i + 1]^x, Subscript[b, i + 1]^y} 

in fact, it is not a single entity, but the sum of two lists, each of which consists of two components. Therefore, I assume that you really want to define Subscript[b, i]^x as a character.

You can do this with Symbolize from the Notation package. However, it is absolutely important that you use the template generated when you click the Symbolize button in the Notation panel (you get this when you start << Notation` ). Then enter your compound variable. I will assume that the superscript x and y are fixed characters, and the subscript i is variable:

enter image description here


One more thing:

It may not be a good idea to use Subscript[b, i]^y , because you will lose the ability to raise indexed variables by the power of x and y (a slight loss, but still). Instead, you can use Subsuperscript[b,i,y] . Note that the suggestion in the "More Information" section of the Subsuperscript documentation Subsuperscript seems to be clearly erroneous . It says:

To enter a subscriber into notepad, use Ctrl + _ to start a regular index or Ctrl + ^ to start a regular superscript. After typing the first script, use Ctrl +% to jump to the opposite script position. Ctrl + Space moves from index or superscript to position.

If you do FullForm on the resulting object, you will see that you did Subscript[b, i]^y instead. To get the symbol to be inserted in the Symbolize template, I see no other solution than entering Subsuperscript[b, i_, y] , evaluating and copying the result into the template.

+6
source

In addition to Sjoerd's answer: since you say that the character S takes various parameters, I think you can study the SetDelayed method to define a function with parameters. Assuming you want S be vector-valued with two dots, then something like the following will define S way you want it.

 S[x_,y_,t_,i_]:= (1-t) * {b[i]^x,b[i]^y} + t * {(b[i+1])^x,(b[i+1])^y} 

The question is whether you really need a subscriber. Sjoerd's answer shows how this is done with the Notation package, but you should consider whether this is an additional complication for your analysis.

EDIT in response to a very useful comment rcollyer You can use Format to define TraditionalForm views for a user-defined function. This is similar to the definition of UpValues , but refers to the view, not the UpValues rules.

Something like the following should work:

 Format[S[x_,y_,t_,i_],TraditionalForm] := (1 - t) {Subscript[b, i]^x, Subscript[b, i]^y} + t {Subscript[b, i + 1]^x, Subscript[b, i + 1]^y} 
+1
source

Source: https://habr.com/ru/post/1381304/


All Articles