Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Pattern with powers
Replies: 7   Last Post: Aug 8, 2013 12:02 AM

 Messages: [ Previous | Next ]
 Dr. Wolfgang Hintze Posts: 195 Registered: 12/8/04
Re: Pattern with powers
Posted: Aug 1, 2013 12:14 AM

Am Mittwoch, 31. Juli 2013 10:49:04 UTC+2 schrieb Alexei Boulbitch:
> I must admit that I am an absolute beginner in patterns, as I cannot cope with a little problem with patterns consisting of powers of variables x and y.
>
>
>
> Specifically, I would like to select from a list all terms of the form
>
>
>
> c x^u y^v (numerical coefficient c times x to the power u times y to the power v)
>
>
>
> where u and v are allowed to take the values 0 and 1.
>
>
>
> How can I do this using Cases?
>
>
>
> I have already accomplished the first non trivial step using _. (blank followed by a dot) in order to get first powers of the variables:
>
>
>
> ls = List@@Expand[5 (x + y)^3]
>
> {5*x^3, 15*x^2*y, 15*x*y^2, 5*y^3}
>
>
>
> Example 1
>
> a = 2; Cases[ls, (_.)*x^(u_.)*y^(v_.) /; u >= a && v < a]
>
> gives
>
> {15*x^2*y}
>
> but misses the term
>
> 5*x^3
>
>
>
> Example 2: this would be the form I would like most
>
> Cases[ls, (_.)*x^_?(#1 >= a & )*y^_?(#1 < a & )]
>
> gives
>
> {}
>
> Here even I didn't get the dot behind the blank before the test, so it misses first powers.
>
>
>
> Thanks in advance for any help.
>
>
>
> Best regards,
>
> Wolfgang
>
>
>
>
>
>
>
> Hi, Wolfgang,
>
>
>
> Your explanation is not quite clear. Have a look:
>
>
>
> Clear[a, u, v, b];
>
>
>
> a = 2;
>
> Cases[ls, (Times[_, x, Power[y, v_]] /;
>
> v <= a) | (Times[_, Power[x, u_]] /; u >= a)]
>
>
>
> {5 x^3, 15 x^2 y, 15 x y^2}
>
>
>
> Is it, what you are after? Or this:
>
>
>
> Clear[a, u, v, b];
>
> a = 2;
>
> Cases[ls, (Times[_, x, Power[y, v_]] /;
>
> v < a) | (Times[_, Power[x, u_]] /; u >= a)]
>
>
>
> {5 x^3, 15 x^2 y}
>
>
>
> ??
>
>
>
> Have fun, Alexei
>
>
>
> Alexei BOULBITCH, Dr., habil.
>
> IEE S.A.
>
> ZAE Weiergewan,
>
> 11, rue Edmond Reuter,
>
> L-5326 Contern, LUXEMBOURG
>
>
>
> Office phone : +352-2454-2566
>
> Office fax: +352-2454-3566
>
> mobile phone: +49 151 52 40 66 44
>
>
>
> e-mail: alexei.boulbitch@iee.lu

Alexei,

As I tried to explain, I wish to extract from the list ls all terms of the form
c x^u y^v, with c a numerical factor, u and v integers subject to the conditions u>=a and v<a with integer a>0.

I have no problem as long as all terms in the list are "true" powers, i.e. as long as u>=2, v>=2.
Therefore I asked for a solution which also covers the values 0 and 1 for the powers.

Your first solution contains the wrong conditions, and the second one fails for a term x^2 y^3 which is selected by your proposal but it shouldn't be selected because v>2.

Best regards,
Wolfgang

Date Subject Author
7/30/13 Dr. Wolfgang Hintze
7/31/13 Bill Rowe
8/1/13 Dr. Wolfgang Hintze
7/31/13 Alexei Boulbitch
8/1/13 Dr. Wolfgang Hintze
8/2/13 Daniel Lichtblau
8/8/13 W. Craig Carter