# Rule for manipulate an expression

like as my precedent post
I have this Expression:

 (5 Subscript[e, 2] Subscript[e, 6])/(
5 Subscript[e, 1] Subscript[e, 2] +
89 Subscript[e, 14] Subscript[e, 5] +
7 Subscript[e, 92] Subscript[e, 56] Subscript[e, 6]) + 6/(
8 Subscript[e, 1] Subscript[e, 6] +
89 Subscript[e, 1] Subscript[e, 9] Subscript[e, 5] + 2) + (
89 Subscript[e, 3] Subscript[e, 4])/(
8 Subscript[e, 1] Subscript[e, 8] +
89 Subscript[e, 1] Subscript[e, 9] Subscript[e, 5] +
7 Subscript[e, 6] Subscript[e, 92] Subscript[e, 56]) + ... + Other simils terms


through a rule I want obtain :

((5 Subscript[e, 26])/(
5 Subscript[e, 12] + 89 Subscript[e, 145] +
7 Subscript[e, 92566])) + (6/(
8 Subscript[e, 16] + 89 Subscript[e, 195] + 2)) + ((
89 Subscript[e, 34])/(
8 Subscript[e, 18] + 89 Subscript[e, 195] + 7 Subscript[e, 69256])) + ..+


Like a my precedent post i tried :

expr /. HoldPattern[Times[s : Repeated[Subscript[e, _]]]] :> Subscript[e, StringJoin @@ ToString /@ Last /@ {s}];


but not work :(

Any idea?

I apologize if the question is not clear.

• @Dr. belisarius I'm sorry, what do you mean ? Mar 20, 2016 at 20:32
• @Dr. belisarius nothing ;) Mar 20, 2016 at 20:35

Let's look at the FullForm of an example expression, (expr):

FullForm of this expression is

Observe that it has many sub-expressions with either three or two multiplications of a subscripted e:

Times[integer_Integer, Subscript[e, a_], Subscript[e, b_],Subscript[e, c_]]
Times[integer_Integer, Subscript[e, a_], Subscript[e, b_], mult___]


mult can be a Power term or not present, either is OK.

The strategy is to do replace the subscripted terms with a single subscript with the integers concatenated.

For example in the two subscript case we form ab by converting a and b to strings, joining them and then converting back to an integer.

All we need do is use ReplaceRepeated rather than ReplaceAll which will repeatedly apply the rule until there is no further change.

expr //. {
Times[integer_Integer, Subscript[e, a_], Subscript[e, b_],
Subscript[e, c_]] :>
Times[integer,
Subscript[e, ToExpression[ToString[a] <> ToString[b] <> ToString[c]]]],

Times[integer_Integer, Subscript[e, a_], Subscript[e, b_], mult___] :>
Times[integer,
Subscript[e, ToExpression[ToString[a] <> ToString[b]]], mult]
}


produces

• Jack LaVigne you have been very clear , thanks ! :D Mar 21, 2016 at 8:51