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


Groups > comp.soft-sys.math.mathematica > #15267 > unrolled thread

Re: Pattern with powers

Started byBill Rowe <readnews@sbcglobal.net>
First post2013-07-31 08:48 +0000
Last post2013-08-01 04:11 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Pattern with powers Bill Rowe <readnews@sbcglobal.net> - 2013-07-31 08:48 +0000
    Re: Pattern with powers "Dr. Wolfgang Hintze" <weh@snafu.de> - 2013-08-01 04:11 +0000

#15267 — Re: Pattern with powers

FromBill Rowe <readnews@sbcglobal.net>
Date2013-07-31 08:48 +0000
SubjectRe: Pattern with powers
Message-ID<ktaj1b$ll6$1@smc.vnet.net>
On 7/30/13 at 6:40 AM, weh@snafu.de (Dr. Wolfgang Hintze) wrote:

>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

It is not necessary to convert the polynomial to a List since
Cases can be applied directly to the polynomial. That is:

In[1]:= ls = Expand[5 (x + y)^3];
a = 2; Cases[ls, (_.)*x^(u_.)*y^(v_.) /; u >= a && v < a]

Out[2]= {15*x^2*y}

yields the same result as you get below after making ls a List

Why use Cases? It appears you want an output with with all terms
of the form a x^u y^v with v either 1 or 0. Although this isn't
what you state initially, it does seem to accurately describe
what you indicate is your desired result. If this is what you
want then how about

In[3]:= CoefficientList[ls, y][[;; 2]] {1, y}

Out[3]= {5*x^3, 15*x^2*y}

[toc] | [next] | [standalone]


#15270

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2013-08-01 04:11 +0000
Message-ID<ktcn5b$r1o$1@smc.vnet.net>
In reply to#15267
Am Mittwoch, 31. Juli 2013 10:48:43 UTC+2 schrieb Bill Rowe:
> On 7/30/13 at 6:40 AM, weh@snafu.de (Dr. Wolfgang Hintze) wrote:
> 
> 
> 
> >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
> 
> 
> 
> It is not necessary to convert the polynomial to a List since
> 
> Cases can be applied directly to the polynomial. That is:
> 
> 
> 
> In[1]:= ls = Expand[5 (x + y)^3];
> 
> a = 2; Cases[ls, (_.)*x^(u_.)*y^(v_.) /; u >= a && v < a]
> 
> 
> 
> Out[2]= {15*x^2*y}
> 
> 
> 
> yields the same result as you get below after making ls a List
> 
> 
> 
> Why use Cases? It appears you want an output with with all terms
> 
> of the form a x^u y^v with v either 1 or 0. Although this isn't
> 
> what you state initially, it does seem to accurately describe
> 
> what you indicate is your desired result. If this is what you
> 
> want then how about
> 
> 
> 
> In[3]:= CoefficientList[ls, y][[;; 2]] {1, y}
> 
> 
> 
> Out[3]= {5*x^3, 15*x^2*y}

Bill,

many thanks for your reply.

My example was just an easy way to generate a list of powers in two varibales, and sometimes I prefer lists over polynomials in order not to lose terms which might vanish because of sums.

I have just described again in detail to Alexei what I'm looking for, so I please refer to that message.

Your proposed function lookes interesting and is new to me in this form.
I'm not sure if it can be parametrized to take into account the inequalities u>=a and v<a for the powers x^u y^v.

Best regards,
Wolfgang

u and v are not 0 or 1 but they are integers >=0. What I want is a pattern that works also for the values 0 and 1 of u and v. As I saind, I have no difficulties with values >=2.

Best regards,
Wolfgang

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web