I'm trying to figure out if I can use the letters contained in Alphabet[] as variables for a function. As a simplified example, I'd like to do something like:
g[a_] := f[Alphabet[][[1]]]
Which however doesn't work since if I call, for example, g[3] it returns again f[a], rather than f[3].
Does anyone know a way out?
Thanks!
EDIT:
To explain better what I need this for. I have a defined a function which, given a Lagrangian, computes the corresponding Feynman rules. The function is such that when it is called, for example, as:
FeynRule[dot[\[DoubledPi]]^3]
It returns:
6 \!\(\*SubscriptBox[\(\[Omega]\), \("a"\)]\) \!\(\*SubscriptBox[\(\[Omega]\), \("b"\)]\) \!\(\*SubscriptBox[\(\[Omega]\), \("c"\)]\)
Which is actually correct.
However, I would like user to be able to replace the a,b,c,... labels with whatever they want; including sums of labels.
The solution of using Symbol@Alphbet[][[1]] does work, but as anticipated by Lucas Lang, it does not work with SetDelayed[].
Is there a better way of doing it?
EDIT 2
As a practical example, I've simplified my function, which now looks like this:
FeynRule[L_] := Do[
n = Exponent[L, del[x].del[x]];
y = Product[
Sprod[Alphabet[][[i]], Alphabet[][[i + 1]]], {i, 1, n}];
Return[y];
, 1]
where Sprod[,] is a function I have defined somewhere else, whose only properties I'm interested in are that Sprod[x+y,z]=Sprod[x,z]+Sprod[y,z], and that it's symmetric on its two arguments.
Now, if I run a simple example for the FeynRule function:
FeynRule[del[x].del[x]]
it correctly gives:
Sprod[Alphabet[][[1]], Alphabet[][[2]]]
Now, I would like to be able to define a function by simply doing
f[a_,b_]:=FeynRule[del[x].del[x]]
So that, for example, f[a+b,c] returns Sprod[a,c]+Sprod[b,c]. This is the part that does not work. The only work around I've found so far is to do:
f[c_, d_] :=
FeynRule[del[x].del[x]] /.
Sprod[Alphabet[][[1]], Alphabet[][[2]]] -> Sprod[c, d]
This does work, but it is a bit cumbersome and it would require to explain the user how to do it.
f[3]
orf["c"]
? $\endgroup$SetDelayed
, since the substitution of argument values happens too early for you to catch. I would suggest you explain your usecase for this, then we can probably help you to find a cleaner solution for your problem. (Because as it stands, you will for example still have to type out all your variable names on the left side of the function definition) $\endgroup$