I have made a function which takes any expression and should replace it with one whose variables are identical, but replaced by those with a chosen subscript (inside the "{}" part goes a set of variables which I don't want to be labelled).
At[expr_, i_] :=
Module[{varsD},
varsD = Variables[expr],{}];
ReplaceAll[expr, # -> Subscript[#, i] & /@ varsD] ]
However, what I am noticing is that, when I take functions (such as sines or derivatives etc), that the whole function is subscripted rather than just the variable.
I want them both to be $\sin(\theta _l)$ and $\dfrac{\partial F_l}{\partial y}$. I need some way of ensuring that this only happens to the function at the highest depth, but I am not sure how to do this.
EDIT: An answer to this has been provided, but what I would also like to do is the following:
- If the expression contains an unknown function (e.g. $F(x,y)$) then the function $F$ should receive the labelling as opposed to $x$ and $y$).
- Specify a set of variables or functions which should remain untouched by the labelling procedure (for example $H(z)$) - I had a previous solution which did this (which was omitted from the script I provided in this post, for simplicity).
Could somebody point me in the right direction?
at[expr_, l_] := expr /. h_[x_] :> h[Subscript[x, l]]
, then it works at least with examples given. $\endgroup$