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?
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?
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 "_"
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:
Another work-around is to use my allowNonSymbol
. Example:
allowNonSymbol[
f[Subscript[σ, x] _, Subscript[σ, y] _] := Sin[Subscript[σ, x]] + 2^Subscript[σ, y]]
f[a, b]
Symbolize
directly, use the Notation Palette popping up when you execute <<Notation`
.
$\endgroup$
You can also use the input form in the definition
f[Subscript[σ, x_], Subscript[σ, y_]] := ...