4
$\begingroup$

I have the following expressions:

R[1, 1] R[2, 1] R[3, 1] R[4, 1] 
sum[FF[3, ak[1] - ak[2], 1], EE[2, ak[2] - ak[3], 0], EE[2, ak[3] - ak[4], 0]]

By what procedure can I convert such expressions into expression:

sum[R[1, 1], FF[3, ak[2] - ak[2], 1], R[2, 1] , EE[2, ak[2] - ak[3], 0], R[3, 1] , EE[2, ak[3] - ak[4], 0] , R[4, 1]]
$\endgroup$
1
  • $\begingroup$ Perhaps you should look at Riffle. $\endgroup$
    – m_goldberg
    Feb 28, 2019 at 14:29

1 Answer 1

5
$\begingroup$
expr = R[1, 1] R[2, 1] R[3, 1] R[4, 1] sum[FF[3, ak[1] - ak[2], 1], 
    EE[2, ak[2] - ak[3], 0], EE[2, ak[3] - ak[4], 0]];

expr /. a_ sum[b__] :> sum @@ Riffle[List @@ a, {b}]

sum[R[1, 1], FF[3, ak[1] - ak[2], 1], R[2, 1], EE[2, ak[2] - ak[3], 0], R[3, 1], EE[2, ak[3] - ak[4], 0], R[4, 1]]

$\endgroup$

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.