Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15268

Re: Pattern with powers

From Alexei Boulbitch <Alexei.Boulbitch@iee.lu>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Pattern with powers
Date 2013-07-31 08:49 +0000
Message-ID <ktaj20$llc$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


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



Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: Pattern with powers Alexei Boulbitch <Alexei.Boulbitch@iee.lu> - 2013-07-31 08:49 +0000
  Re: Pattern with powers "Dr. Wolfgang Hintze" <weh@snafu.de> - 2013-08-01 04:14 +0000
    Re: Pattern with powers danl@wolfram.com - 2013-08-02 06:49 +0000
    Cases or Select? W Craig Carter <ccarter@MIT.EDU> - 2013-08-08 04:02 +0000

csiph-web