# Can you use superscripts as variable and function names?

I want to express the following function:

$$z^{(1)}=w^{(1)}a^{(0)}+b^{(1)}$$

I have read in Mathematica documentation that Symbolize can be used to define variables with superscripts. I would like to define a function that uses $$w^{(1)}$$, $$a^{(0)}$$ and $$b^{(1)}$$ as dependent variables.

This is what I have tried:

<< Notation
Symbolize[NotationTemplateTag[z^(1)]]
Symbolize[NotationTemplateTag[w^(1)]]
Symbolize[NotationTemplateTag[a^(0)]]
Symbolize[NotationTemplateTag[a^(1)]]
Symbolize[NotationTemplateTag[b^(1)]]


And then I try to define the variable as:

(z^(1))[w^(1)_, a^(0)_, b^(1)_] := w^(1) a^(0) + b^(1)


but I get \$Failed.

Specifically:

Is it possible to define a function named with a superscript and having as dependent variables symbols with superscripts? I so, what is not properly done above?

• I suspect that z^(1) is interpreted as Power[z,1] and simplifying to z automatically. You could try Trace and FullForm. Sep 3, 2022 at 11:35
• I am actually entering z^(1) using control+^, so that z^(1) shall be theoretically treated as a single symbol. I have attached a screenshot.
– M.E.
Sep 3, 2022 at 11:43
• I strongly encourage you to use another notation. This may look good, but you are setting yourself up for a lot of unnecessary work and restrictions down the road when you actually have to do any computation on these symbols. The best way is normally indexed variables such as z[1] instead. Sep 3, 2022 at 15:02
• (+1) I think the generalized question, How can one use symbols created by the Notation package as pattern names?, is good. I wouldn't be surprised if there's already a similar Q&A on site, given how often the Notation package is used. (Bob Hanlon's answer seems to address output formatting only, which is not the same as input formatting.) I generally avoid programming with the Notation package for the reasons @MarcoB points out. But it does have its uses, which shouldn't be dismissed. Sep 3, 2022 at 15:42
• Found one: Does this answer your question? How to use subscript in pattern names? Sep 3, 2022 at 15:44

ClearAll["Global*"]


Format indexed variables

(Format[#[n_]] := Superscript[#, Row[{"(", n, ")"}]]) & /@
{z, w, a, b};


The function definition is

z[1][x_, y_, z_] := x*y + z


z[1][w[1], a[0], b[1]]