3
$\begingroup$

I've got the following result from an operation in Mathematica:

(c3 + a3*t)^2*(\[DifferentialD]t)^2 - ((2 + z)^2*((\[DifferentialD]xC)^2 + (\[DifferentialD]xM)^2 + (\[DifferentialD]xY)^2))/(4*(1 + z)^2)

It looks like this in standard form:

$$(c3+a3\space t)^2 (dt)^2-\frac{(2+z)^2((dxC)^2+(dxM)^2+(dxY)^2)}{4(1+z)^2}$$

The $\frac{(2+z)^2}{4(1+z)^2}$ term is a factor. Is there any way to force this into a more readable form:

$$(c3+a3\space t)^2 (dt)^2-\frac{(2+z)^2}{4(1+z)^2}\space ((dxC)^2+(dxM)^2+(dxY)^2)$$

$\endgroup$
0

1 Answer 1

3
$\begingroup$
expr = ((2 + z)^2*((\[DifferentialD]xC)^2 + (\[DifferentialD]xM)^2 +
   (\[DifferentialD]xY)^2))/(4*(1 + z)^2);

Collect[expr, HoldPattern@Plus[__Power], Defer]

enter image description here

TeXForm @ %

$$\frac{(z+2)^2}{4 (z+1)^2} \left((d\text{xC})^2+(d\text{xM})^2+(d\text{xY})^2\right)$$

$\endgroup$
3
  • $\begingroup$ @kilgor - This almost works. I edited the question to show the full version of the equation I'm trying to re-organize. There's a negative sign that seems to be skewing the answer. Your solution gives me something that looks like:$$(c3+a3\space t)^2 (dt)^2+-\frac{(2+z)^2}{4(1+z)^2}\space ((dxC)^2+(dxM)^2+(dxY)^2)$$Any ideas how to get rid of the + - mess? Other than that, this is exactly what I need. $\endgroup$
    – Quark Soup
    Commented May 25, 2020 at 19:14
  • $\begingroup$ @Quarkly, maybe something like: Collect[expr2, HoldPattern@Plus[__Power], Defer] /. Defer[ Times[Rational[a_?InternalSyntacticNegativeQ, b_], c___]] :> a Defer[Times[1/b, c]]`? $\endgroup$
    – kglr
    Commented May 25, 2020 at 21:00
  • $\begingroup$ meant Collect[expr2, HoldPattern@Plus[__Power], Defer] /. Defer[ Times[Rational[a_?InternalSyntacticNegativeQ, b_], c___]] :> a Defer[Times[1/b, c]] $\endgroup$
    – kglr
    Commented May 27, 2020 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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