Project

General

Profile

Feature #1155

Create a new "prime source" iterator

Added by John Abbott about 6 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
New Function
Target version:
Start date:
11 Feb 2018
Due date:
% Done:

100%

Estimated time:
22.20 h
Spent time:

Description

In CoCoA-4 the old factorizer code had an "iterator" for generating primes in succession.

Add such an object to CoCoALib


Related issues

Related to CoCoALib - Feature #1154: SmallFpImpl: new ctor arg to say do-not-check-that-arg-is-primeClosed2018-02-11

History

#1 Updated by John Abbott about 6 years ago

Add a new class to CoCoALib for generating primes in succession -- for use inside CRT loops.

Currently a CRT loop looks like this:

  long p;
  while (true)
  {
    p = NextPrime(p);
    SmallFpImpl ModP(p);
    // computation modulo p
  }

NextPrime simply increments its arg (in a "clever" way) and then calls IsPrime (or IsSmallPrime), and keeps going until IsPrime produces true.

However it is known that Eratothenes's Sieve is a quick way of generating a table of primes over a given range, so it may be a good idea to have a PrimeSource object which generates an internal table, then uses that.

So the loop could look like this:

  PrimeSource PS(1000000);  // arg is start value
  while (true)
  {
     long p = NextPrime(PS);
     SmallFpImpl ModP(p, NoCheck);
     // do computation mod p
  }

#2 Updated by John Abbott about 6 years ago

  • Related to Feature #1154: SmallFpImpl: new ctor arg to say do-not-check-that-arg-is-prime added

#3 Updated by John Abbott about 6 years ago

  • Status changed from New to Resolved
  • Assignee set to John Abbott
  • % Done changed from 0 to 70

I have added 4 "iterators: PrimeSeq, PrimeSeqForCRT, FastMostlyPrimeSeq, NoSmallFactorsSeq.

First trials have been promising.

#4 Updated by John Abbott almost 6 years ago

  • Status changed from Resolved to Feedback
  • % Done changed from 70 to 90

Time to move to feedback.

Only remaining doubt: the function NextPrime needs to be reconsidered (what happens when the iterator reaches the end?)

#5 Updated by John Abbott over 5 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100
  • Estimated time set to 22.20 h

SUMMARY

Created 5 new iterators for generating primes (or "almost primes")
Created new type SmallPrime

All seems to work well (except for semantic doubt about NextPrime when it reaches the end)
Closing

Also available in: Atom PDF