# Assigning flag to the end of a collection of series

I have a large number of series(in the form of Rules) and want to assign flag at the highest order of each of the rules. What I mean, is following. Take the list of two series with respect to $$\epsilon$$: one ends at $$\epsilon^2$$ and another at $$\epsilon^3$$

list = {a[x] ->
Subscript[C, -2]/ϵ^2 + Subscript[C, -1]/ϵ +
Subscript[C,
0] + ϵ Subscript[C, 1] + ϵ^2 Subscript[C, 2],
b[x] -> Subscript[D, -2]/ϵ^2 + Subscript[
D, -1]/ϵ + Subscript[D,
0] + ϵ Subscript[D, 1] + ϵ^2 Subscript[D,
2] + ϵ^3 Subscript[D, 3]}


For the first list, I want to give a flag \[Epsilon]^3*flag*a where a is the name at left. Similarly the second series should be flagged as \[Epsilon]^4*flag*b. But I can not autodetect the order of $$\epsilon$$, hence what I could do

list[[1, #]] -> list[[#, 2]] + ϵ^3*flag*list[[#, 1]] & /@ {1,
2}


which is true for lists with same order of highest $$\epsilon$$. How to generalize it?

• Try: list /. {HoldPattern[a : _[x] -> b___] :> a -> b + \[Epsilon]^Exponent[b, \[Epsilon]] flag a} Commented Dec 5, 2023 at 11:32
• It seems that you have never accepted an answer. You can do so once per question asked by clicking the check mark next to the answer of your choice. It is customary to provide feedback once answer(s) are posted. Thanks.
– Syed
Commented Dec 6, 2023 at 8:32

Clear["Global*"];
list = {a[x] ->
Subscript[C, -2]/ϵ^2 + Subscript[C, -1]/ϵ +
Subscript[C,
0] + ϵ Subscript[C, 1] + ϵ^2 Subscript[C, 2],
b[x] -> Subscript[D, -2]/ϵ^2 +
Subscript[D, -1]/ϵ +
Subscript[D,
0] + ϵ Subscript[D, 1] + ϵ^2 Subscript[D,
2] + ϵ^3 Subscript[D, 3]}

f = Append[Values@#,
`