-1
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ Try: list /. {HoldPattern[a : _[x] -> b___] :> a -> b + \[Epsilon]^Exponent[b, \[Epsilon]] flag a} $\endgroup$ Commented Dec 5, 2023 at 11:32
  • $\begingroup$ 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. $\endgroup$
    – Syed
    Commented Dec 6, 2023 at 8:32

1 Answer 1

0
$\begingroup$
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@#, 
    Head@Keys@# flag Power[ϵ, 
      1 + Cases[Values@#, Power[ϵ, a_] :> a, {2}] // Max]] &;

f /@ list

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.