MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Improving PolynomialQ

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16700] Re: [mg16626] Improving PolynomialQ
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Mon, 22 Mar 1999 22:33:33 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Actually it is quite easy to wite such a function in Mathematica, though
maybe easier for a mathematician than a programmer! (I do not mean any
disrespect to programmers, but it seems to me that the programming style
below is very natural for mathematicians but probably less so for people
acustomed to programming in other languages than Mathematica.) Here is
the definition of PolyQ (equivalent of your NewPolynomialQ):

In[1]:=
PolyQ[x_?NumericQ]:=True;
PolyQ[x_Symbol/;AtomQ [x]&& Not[MemberQ[Attributes[x],Protected]]]:=True;
PolyQ[x_+y_]/;PolyQ[x]&&PolyQ[y]:=True;
PolyQ[x_*y_]/;PolyQ[x]&&PolyQ[y]:=True;
PolyQ[x_^y_]/;PolyQ[x]&&IntegerQ[y]&&Positive[y]:=True;

Now

In[2]:=
PolyQ[3x^3*a^2-3x*y+7]
Out[2]=
True

In[3]:=
Map[PolyQ,{x,  x+(-1)^y, x+Cos[Pi x], 2^x}]
Out[3]=
                 y                                    x
{True, PolyQ[(-1)  + x], PolyQ[x + Cos[Pi x]], PolyQ[2 ]}

I think this is the behaviour you wanted. It may still produce
undesirable results in some cases I have not forseen, but I am confident
that if it does so, it could be easily fixed.

Andrzej

Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp/
http://eri2.tuins.ac.jp/


On Fri, Mar 19, 1999, Jack Goldberg <jackgold at math.lsa.umich.edu> wrote:

>Hi Group,
>
>Here is a programming challange:  Design a predicate
>
>	NewPolynomialQ[ expr ]
>
>which takes an expression  "expr"  as an SINGLE argument 
>and returns True if expr is a polynomial and False if it 
>is not.  The argument  "expr"  may contain any number of 
>variables and the variables may have any names.  
>
>(This makes the problem much more difficult than those 
>handled by  PolynomialQ  which requires the names of the 
>variables.)  From some experimentation I did, here are a 
>small group of test expr's which are not handled well by
>PolynomailQ  
>
>	x,  x+(-1)^y, x+Cos[Pi x], 2^x
>
>If this challange is too difficult (I have a sneaking 
>suspicion that it just might well be insoluble) how 
>about a "semi" predicate
>
>	NewPolynomial[ expr ]
>
>which returns True only when it is manifestly clear that 
>expr is a polynomial in all its variables and returns 
>NewPolynomial[ expr]  otherwise -  much like  Positive[ expr ]?
>
>While trying out various possibilities, I ran into some unexpected
>outputs from  Variables[ expr ].  Compare, for instance, 
>
>	Variables[x+(-1)^y]
>with
>	Variables[x+Cos[y]]
>
>Since Variables[expr]  is designed to work only with polynomials, one
>might argue that Mathematica is not responsible for its misuse as above. 
>However,
>if the argument to variables is not a polynomial, shouldn't Variables
>be designed to return  Variables[expr]  instead of a misleading answer?
>So, one should reprogram  Variables[expr] to detect whether  expr  is 
>a polynomial... ah ha! so that's the motivation behind the challange.
>
>Jack  
>





  • Prev by Date: Re: combinations
  • Next by Date: Re: ReadList Problems
  • Previous by thread: Re: Improving PolynomialQ
  • Next by thread: Re: Improving PolynomialQ