2

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: Failed function definition

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?

Michael E2
  • 235,386
  • 17
  • 334
  • 747
M.E.
  • 333
  • 1
  • 7
  • 1
    I suspect that z^(1) is interpreted as Power[z,1] and simplifying to z automatically. You could try Trace and FullForm. – mikado Sep 03 '22 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 03 '22 at 11:43
  • 3
    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. – MarcoB Sep 03 '22 at 15:02
  • Your code gives me $Failed. Using the Notations pallete to create the Symbolize[] command, I achieved this: https://i.stack.imgur.com/OnwNr.png -- It seems key here to use symbol : Blank[] instead of symbol_. I guess the latter is not parsed correctly when symbol is a box structure that is supposed to be symbolized. – Michael E2 Sep 03 '22 at 15:19
  • 1
    (+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. – Michael E2 Sep 03 '22 at 15:42
  • 2
    Found one: Does this answer your question? How to use subscript in pattern names? – Michael E2 Sep 03 '22 at 15:44
  • To clarify, your Symbolize[...] code fails each of the four times. – Michael E2 Sep 03 '22 at 15:46
  • @MichaelE2 For Symbolise I had to use the tool palette, just typing the code did not work. I will check the suggestion on indexed variables, I am pretty new to Mathematica and I am still learning how the different options are and which are the most sensible approaches to use Mathematica. – M.E. Sep 03 '22 at 17:47

1 Answers1

4
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

With your specific arguments

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

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198