As with all the others, I do not understand what are you after. However, in the past, I met a comparable problem myself, where I had a good reason to do something like this. Of course, without a clear understanding of your aim, I can give a useless solution. Anyway, let us try.
You defined the function which acts only on tensors with the head a
transforming them into a string and then into a symbol:
a[i_, j_] := Symbol["a" <> ToString[i] <> ToString[j]]
Let us check
a[i, j] // FullForm
a[i, j] // Head
returns aij and Symbol correspondingly. That's OK.
Let us introduce the function
toTensor[expr_Symbol] :=
Module[{x, y, z},
ToExpression@Characters[ToString[expr]] /. {x_, y_, z_} :> x[y, z]]
Now let us apply it to aij
:
Clear[a];
toTensor[aij]
(* a[i, j] *)
The key point here is to first apply Clear[a]
. It is because you have already previously defined a[i,j]
such that it immediately transforms into aij
. Therefore, without clearing it will always return aij
. The symbol with a different first letter you can transform without clearing
toTensor[bij]
(* b[i, j] *)
Hope this helps.
Have fun!
a12
toa[1,2]
for example? can you give an explicit example of an input and what the output should be? $\endgroup$ReleaseHold[With[{symbol = Symbol["a" <> ToString[i] <> ToString[j]]},HoldForm[symbol = a[i, j]]] ]
might work. $\endgroup$