Pattern with powers
- To: mathgroup at smc.vnet.net
- Subject: [mg131469] Pattern with powers
- From: "Dr. Wolfgang Hintze" <weh at snafu.de>
- Date: Tue, 30 Jul 2013 06:40:55 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
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