# How do I convert Subscript[a, 1] Subscript[e, 1] into Subscript[a, 1] Subscript[f, 1]?

I have a series expression like x = a0 + a1 e1 + a2 e2 + a3 e1 e2 and I wish to convert all instances of e1 into f1. The series is subscripted. If there are no subscripts, then the following answer previously provided in this forum works for me.

x1 = ToExpression[StringReplace[ToString[x], "e1" -> "f1"]]

• You mean like, x /. Subscript[e, 1] :> Subscript[f, 1]? Commented Sep 2, 2016 at 21:33

Do not convert to a String and just work on the original expression

Clear[x];
x = Sum[Subscript[a, i] Subscript[e, i], {i, 0, 4}]


Now do a replacement:

x /. {Subscript[e, s_] :> Subscript[f, s]}


Notice the pattern s_ which matches the subscript and is used on the f

• Thank you. That works. Can I do something similar for exponents? When I multiply two such x expressions I will have some squares of f1 and e2. I would like to set f1^2 = -1 and e2^2 = +1. Without subscripts, using x = a0 + a1 f1 +a2 e2 +a3 f1 e2 and y = b0 + b1 f1 +b2 e2 +b3 f1 e2, I was able to use rule5 = {Power[f_, 2] /; First[Characters[ToString [f]]] === "f" -> -1, Power[e_, 2] /; First[Characters[ToString [e, InputForm]]] === "e" -> 1}; xy = Expand[x y] //. rule5; Commented Sep 3, 2016 at 0:47
• Yes. The pattern matching and delayed :> replacement can do lots of operations for you. Just do not convert to string first! Also check out CoefficientList You can generate a list of coefficients then rebuild your expression as you see fit. Commented Sep 3, 2016 at 0:53
• Whoops. Back to the original question. The pattern changes all e's into f's. I only want to change the e1's, not the e2's, e3's, or e4's. But replacing both s_ by 1's fixes it, so I am good. Strangely, I can't get a similar thing to work for replacing f1^2 with -1 and e2^2 by +1 while leaving e2 and f1 (to the first power) alone. I tried xy /. {Power [ f, 2] -> -1, Power [e, 2] -> 1 }. Any suggestion? Commented Sep 3, 2016 at 2:02

I finally got it. Your response c186282 was right on. Please ignore my earlier questions. The following multiplies x and y and changes e1^2 to -1 and ek^2 to +1 for k>1. An intermediate step is to change e1 to f1, then f1^2 to -1 and other ek^2 to +1, then change f1 back to e1. This is for working space-time geometric algebra (a.k.a Clifford algebra).

x = Sum[Subscript[a, i] Subscript[e, i], {i, 0, 4}]  (* Build x series *)
y = Sum[Subscript[b, i] Subscript[e, i], {i, 0, 4}]  (* Build y series *)
Expand[x y]   (* Multiply the 2 series *)
% /. {Subscript[e, 1] :> Subscript[f, 1]   (* change all e1 to f1 *)
% /. {Power[Subscript[f, 1], 2] :> -1, Power[Subscript[e, s_], 2] :> 1}
(* change all f1^2 to -1, all ek^2 to +1  *)
% /. {Subscript[f, 1] :> Subscript[e, 1]}  (* change f1 back to e1  *)