TransWikia.com

Collect terms in inverse powers of three variables

Mathematica Asked on April 6, 2021

I have the following expression

enter image description here

-(((-(L/r1) + L/r2)^2*(L/r1 - L/r3)^2*(-(L/r2) + L/r3)^2)/(1 + 1/r1 + 1/r2 + 1/r3)^2) + (1 + L^2/r1 + ((-(L/r1) + L/r2)*(L/r1 - L/r3))/(1 + 1/r1 + 1/r2 + 1/r3))*
   (1 + L^2/r2 + ((-(L/r1) + L/r2)*(-(L/r2) + L/r3))/(1 + 1/r1 + 1/r2 + 1/r3))*(1 + 1/r1 + 1/r2 + 1/r3)*(1 + ((L/r1 - L/r3)*(-(L/r2) + L/r3))/(1 + 1/r1 + 1/r2 + 1/r3) + 
    L^2/r3)

Which I want to rewrite by collecting according to the inverse powers of r1, r2 and r3. That is, I want to get

enter image description here

1 + (1 + L^2)/r1 + (1 + L^2)/r2 + (1 + L^2)/r3 + (3*L^2 + L^4)/(r1*r2) + (3*L^2 + L^4)/(r1*r3) + (3*L^2 + L^4)/(r2*r3) + (9*L^4 + L^6)/(r1*r2*r3) - 
   L^6/(r1^2*r2^2) - L^6/(r1^2*r3^2) - L^6/(r2^2*r3^2) + (2*L^6)/(r1*r2*r3^2) + (2*L^6)/(r1*r2^2*r3) + (2*L^6)/(r1^2*r2*r3)

I have done this by hand, but for more complciated expressions I want to use Mathematica. I tried Collect[expression,{r1,r2,r3},Simplify] but it did nothing for me. Also, I do not want to collect in powers of L.

2 Answers

Total @ Factor @ MonomialList[Simplify @ expr, 1/{r1, r2, r3}]

![enter image description here

To have the terms in a specific order, sort the monomials as you like and wrap the resulting list with Apply[Defer @* Plus]:

Apply[Defer @* Plus] @ 
  SortBy[Through @ {Total, Sort} @ Exponent[#, 1/{r1, r2, r3}] &] @
    Factor @ MonomialList[Simplify @ expr, 1/{r1, r2, r3}]

enter image description here

Using an alternative ordering of terms:

Apply[Defer @* Plus] @ Factor @ 
   MonomialList[Simplify @ expr, 1/{r1, r2, r3}, "NegativeDegreeReverseLexicographic"]

enter image description here

Correct answer by kglr on April 6, 2021

Here is a pretty manual approach:

Total[
  Simplify@*Total /@
    GatherBy[
      List @@ Expand[FullSimplify@expr],
      Denominator
    ]
]

collected

Answered by MarcoB on April 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP