Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
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
add comment

1 Answer 1

You are close to the truth

f[z_[bar_]] := z[bar]^2;
f[a[b]]
a[b]^2
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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