2
$\begingroup$

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?

$\endgroup$
8
  • 1
    $\begingroup$ I suspect that z^(1) is interpreted as Power[z,1] and simplifying to z automatically. You could try Trace and FullForm. $\endgroup$
    – mikado
    Sep 3, 2022 at 11:35
  • $\begingroup$ 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. $\endgroup$
    – M.E.
    Sep 3, 2022 at 11:43
  • 3
    $\begingroup$ 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. $\endgroup$
    – MarcoB
    Sep 3, 2022 at 15:02
  • 1
    $\begingroup$ (+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. $\endgroup$
    – Michael E2
    Sep 3, 2022 at 15:42
  • 2
    $\begingroup$ Found one: Does this answer your question? How to use subscript in pattern names? $\endgroup$
    – Michael E2
    Sep 3, 2022 at 15:44

1 Answer 1

4
$\begingroup$
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

$\endgroup$

Your Answer

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

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