Re: Mathematica Collect function

• To: mathgroup at smc.vnet.net
• Subject: [mg110728] Re: Mathematica Collect function
• From: "David Park" <djmpark at comcast.net>
• Date: Sat, 3 Jul 2010 08:19:56 -0400 (EDT)

```One of the experts may give you a regular Mathematica method for doing this,
but I would do it with the Presentations package MapLevelParts routine. This
allows us to pick out a list of sub-terms in a sum to operate on, in this
case to factor.

expr0 = ((1 + Sqrt[2]) i - 1)/4*(P10 - P11) - (1 + Sqrt[2] + i)/
4*(P20 - P21);
expr1 = Expand[expr0];

Needs["Presentations`Master`"]

Simplify[expr1]
% // MapLevelParts[Factor, {2, {1, 2}}]
% // MapLevelParts[Factor, {2, 1, 1, {2, 3}}]
Distribute[%]
% === expr0

giving:

1/4 ((-1 + i + Sqrt[2] i) P10 - (-1 + i + Sqrt[2] i) P11 - (1 + Sqrt[
2] + i) (P20 - P21))

1/4 ((-1 + i + Sqrt[2] i) (P10 - P11) - (1 + Sqrt[2] + i) (P20 - P21))

1/4 ((-1 + (1 + Sqrt[2]) i) (P10 - P11) - (1 + Sqrt[2] + i) (P20 -
P21))

1/4 (-1 + (1 + Sqrt[2]) i) (P10 - P11) -
1/4 (1 + Sqrt[2] + i) (P20 - P21)

True

David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/

From: Minh [mailto:dminhle at gmail.com]

Given that:
Expand[((1 + Sqrt[2]) i - 1)/4*(P10 - P11) - (1 + Sqrt[2] + i)/
4*(P20 - P21)]

will output
-(P10/4) + (i P10)/4 + (i P10)/(2 Sqrt[2]) + P11/4 - (i P11)/4 - (
i P11)/(2 Sqrt[2]) - P20/4 - P20/(2 Sqrt[2]) - (
i P20)/4 + P21/4 + P21/(2 Sqrt[2]) + (i P21)/4

How do I get from:
-(P10/4) + (i P10)/4 + (i P10)/(2 Sqrt[2]) + P11/4 - (i P11)/4 - (
i P11)/(2 Sqrt[2]) - P20/4 - P20/(2 Sqrt[2]) - (
i P20)/4 + P21/4 + P21/(2 Sqrt[2]) + (i P21)/4

back to
((1 + Sqrt[2]) i - 1)/4*(P10 - P11) - (1 + Sqrt[2] + i)/
4*(P20 - P21)

I've tried using the Collect function as follows:
Collect[-(P10/4) + (i P10)/4 + (i P10)/(2 Sqrt[2]) + P11/4 - (i P11)/
4 - (i P11)/(2 Sqrt[2]) - P20/4 - P20/(2 Sqrt[2]) - (i P20)/4 + P21/
4 + P21/(2 Sqrt[2]) + (i P21)/4, {(P10 - P11), (P20 - P21)}]
but it doesn't seem to collect the terms {(P10 - P11), (P20 - P21)}.

Got any suggestions?

```

• Prev by Date: Re: Mathematica Collect function
• Next by Date: Re: boolean variable with contours
• Previous by thread: Re: Mathematica Collect function
• Next by thread: Re: Mathematica Collect function