# How to define a function of z[bar], etc

Using Displaying index as subscript on output: e.g. C[i] -> C_i with Notation[...] or Interpretation[..]? I have often ended up wanting to define functions of annotated variables to better match my whiteboard mathematics. Naively, I would want to do things like:

f[z[bar]_] := z[bar]^2;
relativez[z_, z[bar]_] := z / z[bar];


However, this doesn't work. Obviously, I can do things like

f[zbar_] := zbar^2;
f[z[bar]]


But I would prefer to have it map to my math better if a simple variation of this pattern works.

-
Which is more important: the entry of this function definition, or the way the definition displays with e.g. Definition[f]? – Mr.Wizard Sep 19 '13 at 19:38
If it isn't possible to do both at the same time, then I think that current answer gives a possible tradeoff where I can choose as appropriate. – jlperla Sep 19 '13 at 20:46

f[z_[bar_]] := z[bar]^2;

a[b]^2

So close. Also note that the following works: f2[z_, z_[bar_]] := z/z[bar]; f2[a, a[bar]] – jlperla Sep 19 '13 at 17:58
Just a confirmation though, in your original version the following does not work f[zb], presumably because it needs to match a pattern with a [_]. In this sense, I am not getting exactly what I am want (which is z[bar] as a complete placeholder on its own. However, for my purposes this may be sufficient. – jlperla Sep 19 '13 at 18:00