# Substitution rule for sums of similar objects?

Consider objects like

obj= (Sum[Subscript[A, i], {i, 1, 5}] Sum[Subscript[A, i], {i, 3, 6}] Sum[Subscript[A, i], {i, 2, 3}])/(
Sum[Subscript[A, i], {i, 3, 8}] Sum[Subscript[A, i], {i, 1, 2}] Sum[Subscript[A, i], {i, 4, 6}]) I would like to have a substitution rule myRule that would perform the following replacement

obj /. myRule for sequences of sums of $$A_i$$ of any lengths, and with indices not necessarily consecutive and not necessarily integer. How can this be done?

Try the following:

obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ {a}]


It can be even shorter:

obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ {a}]


Here's an alternative that will work with subscripted As that have more than one subscript, which may (or may not) be what you want:

obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
Subscript[A, Sequence @@ Cases[{seq}, Subscript[A, inds__] :> inds]]

Block[{Plus = Subscript[#[], ## & @@ (#2 & @@@ {##})] &},  obj] // TeXForm


$$\LARGE\frac{A_{2,3} A_{3,4,5,6} A_{1,2,3,4,5}}{A_{1,2} A_{4,5,6} A_{3,4,5,6,7,8}}$$

Alternatively,

obj /. Plus -> (Subscript[#[], ##&@@(#2&@@@{##})]&) // TeXForm


$$\LARGE\frac{A_{2,3} A_{3,4,5,6} A_{1,2,3,4,5}}{A_{1,2} A_{4,5,6} A_{3,4,5,6,7,8}}$$