The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Dr. Wolfgang Hintze

Posts: 195
Registered: 12/8/04
Pattern with powers
Posted: Jul 30, 2013 6:39 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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]
but misses the term

Example 2: this would be the form I would like most
Cases[ls, (_.)*x^_?(#1 >= a & )*y^_?(#1 < a & )]
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,

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.