Joerg Arndt on Mon, 17 Sep 2012 19:29:06 +0200

 Re: forprime

```* Bill Allombert <Bill.Allombert@math.u-bordeaux1.fr> [Sep 17. 2012 19:21]:
> On Sun, Sep 16, 2012 at 09:12:14AM +0200, Karim Belabas wrote:
> > > On Sat, Sep 15, 2012 at 3:36 AM,  <michel.marcus@free.fr> wrote:
> > > > forprime loops over prime numbers.
> > > >
> > > > is there a  function that would loop over composite numbers ?
> > * Charles Greathouse [2012-09-15 09:41]:
> > > I typically write
> > >
> > > p=3; forprime(q=5, lim, for(n=p+1, q-1, /* your code here */); p=q)
> >
> > It's not easy to do this properly in GP and the result is not that readable
> > [ N.B. the above loops through composites only up to precprime(lim) ]
> >
> > I just committed a function forcomposite() to 'master', following the (new)
> > forprime() model:
> >
> > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> > (09:05) gp > ??forcomposite
> > forcomposite(n = a,{b},seq):
> >
> >    Evaluates seq, where the formal variable n ranges over the composite numbers
> > between  the  non-negative  real numbers a to b,  including a and b if they are
> > composite. Nothing is done if a > b.
>
> What is the usecase for such function ? I never needed it myself.
>
> At worse you can do
> for(a=1,1000,if(!isprime(a),print(a)))
>
> I feel concerned because I will have to write dedicated code for GP2C to handle
> it...
>
> Cheers,
> Bill.

Agreed, and the snippet posted before can handle this nicely enough.

cheers,  jj

```

• References:
• forprime
• From: michel.marcus@free.fr
• Re: forprime
• From: Charles Greathouse <charles.greathouse@case.edu>
• Re: forprime
• From: Karim Belabas <Karim.Belabas@math.u-bordeaux1.fr>
• Re: forprime
• From: Bill Allombert <Bill.Allombert@math.u-bordeaux1.fr>