1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ @Dr. belisarius I'm sorry, what do you mean ? $\endgroup$ – plus91 Mar 20 '16 at 20:32
  • $\begingroup$ @Dr. belisarius nothing ;) $\endgroup$ – plus91 Mar 20 '16 at 20:35
3
$\begingroup$

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

Mathematica graphics

FullForm of this expression is

Mathematica graphics

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

Mathematica graphics

$\endgroup$
  • $\begingroup$ Jack LaVigne you have been very clear , thanks ! :D $\endgroup$ – plus91 Mar 21 '16 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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