# Unique Replacement of Symbol

I have

formular = a*e + a*e + b*e + c*e


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

formularNew = UniqueReplacement[formular]
formularNew = a*uu + a*uu  + b*uu + c*uu


I have tried:

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


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

formularNew = 2 a*uu + b*uu + c*uu


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*e + a*e + b*e + c*e;
evars = Union[Cases[formular, e[_], Infinity]]
replaced =
formular /. Thread[evars -> Table[Unique[uu], Length[evars]]]

(* Out= {e, e}


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

replacedB =
formular /.
Out= uu$8369 a + uu$8370 a + uu$8369 b + uu$8370 c *)