Re: MonomialQ
- To: mathgroup at smc.vnet.net
- Subject: [mg33559] Re: [mg33542] MonomialQ
- From: Rob Pratt <rpratt at email.unc.edu>
- Date: Sun, 31 Mar 2002 04:09:08 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
On Fri, 29 Mar 2002, Detlef Mueller wrote: > Hello, > > I want to test, wether an expression is a Monomial > with respect to a List of Variables. > Here a Monomial is defined as some coefficient > multiplied by a product of powers of the > Variables: c*v1^p1*... vn^pn, > where c must not depend on any of v1,..vn. > (this is sometimes called "term"). > > Similar to the build in Function PolynomialQ. > > Say > > MonomialQ[(a b)^3/(b c),{a,b}] -> True > MonomialQ[(a b)^3/(b c),{a,c}] -> False > MonomialQ[(a b)^3/(b c)-c,{a,b}] -> False > MonomialQ[(a+b)(a+c),{a}] -> False > MonomialQ[(a+b)(a+c)-(a^2+bc),{a}]->True > > My current Implementation is > > MonomialQ[a_,L_List] := > PolynomialQ[a, L] && (* must be Polynomial and *) > Head[Expand[a, x_ /; MemberQ[L, x]]] =!= Plus; > > Maybe, there is no better way, but I wonder, if > the Expand with Pattern is a good Idea here. > > Since in most Cases "a" _is_ in fact a Monomial > in simple power-product-form, and since this is > an often used Function, using "Expand" might be > nearly every time an Overkill. > > Maybe there is a quick "pretest", checking > for the "simple power-product-form" > a = a1^k1*...an^kn, a1,..an Symbols or Constants, > k1..kn non negative integers? > > Greetings, > Detlef After checking that a is a polynomial in the variables L, you can check that setting everything in L to 0 yields 0. MonomialQ[a_, L_List] := PolynomialQ[a, L] && (a /. (#1 -> 0 & ) /@ L) === 0 It does give the desired results for your examples (after changing bc to b*c in your last example). Rob Pratt Department of Operations Research The University of North Carolina at Chapel Hill rpratt at email.unc.edu http://www.unc.edu/~rpratt/