22
$\begingroup$

For example I want to define a function with parameters σx and σy, that is, the function will be declared as:

f[σx_y_] := . . .

I tried Symbolize but it doesn't work. How can I use Subscript in pattern names?

$\endgroup$
0

3 Answers 3

19
$\begingroup$

You can use Symbolize, from the Notation package following the tutorial as you did.

Then, just take the precaution of writing the pattern with its head explicit, such as:

Pattern[xr, _]

The problem is that Mathematica can't interpret the short notation for patterns (xr_ for example) if it has a box structure before the "_"

$\endgroup$
6
$\begingroup$

As mentioned by Rojo in the answer above,

xr_
can't be interpreted as desired even after Symbolize is used, but one doesn't need to write Pattern in its FullForm to circumvent the problem, actually you just need one more : i.e.

xr:_

Example:

enter image description here


Another work-around is to use my allowNonSymbol. Example:

allowNonSymbol[
 f[Subscript[σ, x] _, Subscript[σ, y] _] := Sin[Subscript[σ, x]] + 2^Subscript[σ, y]]

f[a, b]

enter image description here

$\endgroup$
4
  • $\begingroup$ I am using mathematica 11.0, and after loading the Notation package and entering Symbolize[<keystrokes>], where <keystrokes> was Shift+_ then Control+_ then Shift +_, I got the error message "Symbolize::noboxtag: The Symbolize boxes Subscript[ _ , _ ] do not have an embedded TemplateBox with tag NotationTemplateTag. The Symbolize statement Symbolize[Subscript[ _ , _ ]] may not have been entered using the palette, or the embedded TemplateBox may have been deleted. The embedded TemplateBox ensures correct parsing and retention of proper styling and grouping information." $\endgroup$ Sep 14, 2016 at 14:37
  • 1
    $\begingroup$ @NowIGetToLearnWhatAHeadIs As mentioned in the document: When defining your own notations it is critically important to use the notation templates. So don't type Symbolize directly, use the Notation Palette popping up when you execute <<Notation`. $\endgroup$
    – xzczd
    Sep 14, 2016 at 14:44
  • $\begingroup$ Thanks. I have been looking through the documentation since I posted the comment, and I just now stumbled upon that. $\endgroup$ Sep 14, 2016 at 14:47
  • $\begingroup$ Thanks for this answer, it really saved me. $\endgroup$ Apr 11, 2020 at 6:20
-1
$\begingroup$

You can also use the input form in the definition

f[Subscript[σ, x_], Subscript[σ, y_]] := ...

$\endgroup$
1
  • 3
    $\begingroup$ CarloB, welcome to the site. I don't believe this works in the way the OP wants. It would require entering your values as subscripts to sigma for each argument. $\endgroup$
    – Mr.Wizard
    Mar 13, 2012 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.