# Unique Replacement of Symbol

I have

formular = a[0]*e[0] + a[0]*e[1] + b[1]*e[0] + c[0]*e[1]


and I want to replace every e[_] into some unique symbol:

formularNew = UniqueReplacement[formular]
formularNew = a[0]*uu[1092873] + a[0]*uu[76341]  + b[1]*uu[3451] + c[0]*uu[97415]


I have tried:

formularNew = formular/. {e[_] -> uu[], f[_] -> ll[RandomInteger[1000000]]}


but it applies the random number directly, thus it leads to

formularNew = 2 a[0]*uu[885866] + b[1]*uu[885866] + c[0]*uu[885866]


I would be grateful for any hint.

• Use :> instead of -> for the replacement rule. This is analogous to = vs :=. – Szabolcs Nov 4 '16 at 15:30
• I would do something like Module[{i = 1}, formularNew = formular/. {e[_] :> ll[i++]}] – march Nov 4 '16 at 15:31

Here is one possibility. Gather the variables of interest e.g. using Cases, then do a replacement using Unique to create the new symbols.

formular = a[0]*e[0] + a[0]*e[1] + b[1]*e[0] + c[0]*e[1];
evars = Union[Cases[formular, e[_], Infinity]]
replaced =
formular /. Thread[evars -> Table[Unique[uu], Length[evars]]]

(* Out[92]= {e[0], e[1]}


If you really want the uu[randominteger] style of replacement variable, could do as below.

replacedB =
formular /.
Out[93]= uu$8369 a[0] + uu$8370 a[0] + uu$8369 b[1] + uu$8370 c[0] *)