Re: remove higher orders terms from mathemtica's result

• To: mathgroup at smc.vnet.net
• Subject: [mg90932] Re: remove higher orders terms from mathemtica's result
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Wed, 30 Jul 2008 03:52:35 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <g6mqap\$nt8\$1@smc.vnet.net>

```kem wrote:

> Given this:
>
> K = (1+vy) (zx+wx)  + vx (zy+wy);
> Expand[K^2]
>
> Is it possible to remove automatically the 3rd and 4th orders from the
> result of  'Expand[K^2]' ?
>
> By 3rd order I mean terms like: 2 wy zy vx^2  etc. (all terms with sum
> of the degrees of derivatives of u,v,w is = 3)
> By 4th order:  wy^2 vx^2  etc.   (sum of degrees of u,v,w = 4)

The following expression will do it:

Plus @@ Pick[List @@ expr,
Total@Exponent[#, Variables[expr]] & /@ List @@ expr, 0 | 1 | 2]

Here a step by step, visual, explanation of how it works:

In[1]:= K = (1 + vy) (zx + wx) + vx (zy + wy);

In[2]:= expr = Expand[K^2]

Out[2]= wx^2 + 2 vy wx^2 + vy^2 wx^2 + 2 vx wx wy + 2 vx vy wx wy +
vx^2 wy^2 + 2 wx zx + 4 vy wx zx + 2 vy^2 wx zx + 2 vx wy zx +
2 vx vy wy zx + zx^2 + 2 vy zx^2 + vy^2 zx^2 + 2 vx wx zy +
2 vx vy wx zy + 2 vx^2 wy zy + 2 vx zx zy + 2 vx vy zx zy + vx^2 zy^2

In[3]:= Variables[expr]

Out[3]= {wx, vy, vx, wy, zx, zy}

In[4]:= List @@ expr

Out[4]= {wx^2, 2 vy wx^2, vy^2 wx^2, 2 vx wx wy, 2 vx vy wx wy, vx^2
wy^2, 2 wx zx, 4 vy wx zx, 2 vy^2 wx zx, 2 vx wy zx, 2 vx vy wy zx,
zx^2, 2 vy zx^2, vy^2 zx^2, 2 vx wx zy, 2 vx vy wx zy, 2 vx^2 wy zy,
2 vx zx zy, 2 vx vy zx zy, vx^2 zy^2}

In[5]:= Exponent[#, Variables[expr]] & /@ List @@ expr

Out[5]=
{{2, 0, 0, 0, 0, 0}, {2, 1, 0, 0, 0, 0}, {2, 2, 0, 0, 0, 0},
{1, 0, 1, 1, 0, 0}, {1, 1, 1, 1, 0, 0}, {0, 0, 2, 2, 0, 0},
{1, 0, 0, 0, 1, 0}, {1, 1, 0, 0, 1, 0}, {1, 2, 0, 0, 1, 0},
{0, 0, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 0}, {0, 0, 0, 0, 2, 0},
{0, 1, 0, 0, 2, 0}, {0, 2, 0, 0, 2, 0}, {1, 0, 1, 0, 0, 1},
{1, 1, 1, 0, 0, 1}, {0, 0, 2, 1, 0, 1}, {0, 0, 1, 0, 1, 1},
{0, 1, 1, 0, 1, 1}, {0, 0, 2, 0, 0, 2}}

In[6]:= Total@Exponent[#, Variables[expr]] & /@ List @@ expr

Out[6]= {2, 3, 4, 3, 4, 4, 2, 3, 4, 3, 4, 2, 3, 4, 3, 4, 4, 3, 4, 4}

In[7]:= Pick[List @@ expr, Total@Exponent[#, Variables[expr]] & /@ List
@@ expr, 0 | 1 | 2]

Out[7]= {wx^2, 2 wx zx, zx^2}

In[8]:= Plus @@ Pick[List @@ expr,
Total@Exponent[#, Variables[expr]] & /@ List @@ expr, 0 | 1 | 2]

Out[8]= wx^2 + 2 wx zx + zx^2

Regards,
-- Jean-Marc

```

• Prev by Date: Re: bug? f'[x]'
• Next by Date: Re: Problem with BinCounts
• Previous by thread: Re: remove higher orders terms from mathemtica's result
• Next by thread: Denoting a Cartesian Product