MathGroup Archive 2010

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

Search the Archive

Re: Positions of Polynomials in expr?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109340] Re: Positions of Polynomials in expr?
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Thu, 22 Apr 2010 06:43:17 -0400 (EDT)
  • References: <hqotst$9bt$1@smc.vnet.net>

Am 22.04.2010 09:29, schrieb Jack L Goldberg 1:
> Hi Folks,
> 
> "Select" and "Cases" are commands that do essentially the same thing,  
> namely, pick out elements of a list which, in the first case matches a  
> criterion, in the second case, matches a pattern.  I call these  
> parallel commands.  Is there a command parallel to "Position" which  
> uses criterion rather than pattern matching?
> 
> If no such parallel function exists, can one easily construct one?
> 
> I actually have a special case in mind.  I want to find the position  
> of all parts of expr which fail the test PolynomialQ[f_,x].  Naively,  
> I thought one might Map
> Polynomial[#,x]& to all levels of expr and then find the positions of "False".
> I haven't tried it because I'm betting someone knows how to do this  
> neatly and I do not like to re-invent the wheel.  When I do so, the  
> wheel tends to be more like an oval than a circle.

Since you can use a criterion in a pattern with the PatternTest (?) it
is not really necessary to have an own function:

Position[expr,_?(PolynomialQ[#,x]&)]

would do what a "parallel" function to Position would. In your case
something like

Position[expr,_Plus?(PolynomialQ[#,x]&)]

will probably closer to what you want, since PolynomialQ gives True for
constants, an usually there are plenty in every expression...

Of course it would be easy to write your own
function if the above is too cryptic:

positiontest[expr_,test_]:=Position[expr,_?test]


hth,

albert


  • Prev by Date: Re: Unevaluated functions
  • Next by Date: Re: Dynamic evaluation of layered networks
  • Previous by thread: Positions of Polynomials in expr?
  • Next by thread: Re: Positions of Polynomials in expr?