User Tools

Site Tools


Sidebar

projects

ntr0 (due 20210825)
pct1 (bonus; due 20210819)
wcp1 (due 20210818)
uom0 (due 20210901)
pct2 (due 20210825)
wcp2 (due 20210825)
pnf0 (due 20210901)
pct3 (bonus; due 20210901)
wcp3 (due 20210901)
pnf1 (due 20210908)
pct4 (due 20210908)
wcp4 (due 20210908)
pnf2 (due 20210915)
gfo0 (due 20210915)
pct5 (bonus; due 20210915)
wcp5 (due 20210915)
pnf3 (due 20210922)
pct6 (due 20210922)
wcp6 (due 20210922)
saf0 (due 20210929)
pct7 (bonus; due 20210929)
wcp7 (due 20210929)
saf1 (due 20211006)
pct8 (due 20211006)
wcp8 (due 20211006)
saf2 (due 20211020)
pct9 (bonus; due 20211020)
bwp1 (bonus; due 20211020)
wcp9 (due 20211020)
fom0 (due 20211027)
gfo1 (due 20211027)
pctA (due 20211027)
wcpA (due 20211027)
pctB (bonus; due 20211103)
wcpB (due 20211103)
mpg0 (due 20211110)
pctC (due 20211110)
wcpC (due 20211110)
gfo2 (due 20211117)
pctD (bonus; due 20211117)
pctE (bonus; due 20211201)
bwp2 (bonus; due 20211201)
EoCE (due 20211209)
haas:fall2021:discrete:projects:pnc2:faq

PNC2 FAQ

I don't get the square root trick in relation to the sieve

It works in much the same application: allowing us to avoid unnecessary (or more specifically to the sieve, redundant) work.

Take 16 for example.

To find all the primes up to 16 (square root is 4), we'd do the following:

  • 2 is a prime
    • mark off all multiples of 2 (4, 6, 8, 10, 12, 14, 16)
  • 3 is unmarked, it is a prime
    • mark off all multiples of 3 (6, 9, 12, 15)
  • 4 is marked, it isn't a prime. It is also the square root point. STOP.

So now, when we read through the array to find the unmarked values, we find:

  • 2
  • 3
  • 5 (never touched by the multiples of 2 or 3)
  • 7 (never touched by the multiples of 2 or 3)
  • 11 (never touched by the multiples of 2 or 3)
  • 13 (never touched by the multiples of 2 or 3)

But, won't it miss something?

This would actually cover us until we start getting into uncovered multiples of higher primes (for instance, because we never processed multiples of 5, we'd hit an issue with some composite multiple of 5 that 2 and 3 did not also cover):

  • 10 (covered by 2)
  • 15 (covered by 3)
  • 20 (covered by 2)
  • 25 (aha! NOT covered by 2 nor 3)

But, since we were ONLY checking up to 16, and 4 was its square root point, there is no need to worry about whether or not 25 is prime or composite, because it exceeds the range we were interested in.

Interestingly, 25 is also the square of 5, but that is less central to this than the property of the multiples, for if we were to continue:

  • 30 (covered by 2 and 3)
  • 35 (NOT covered by 2 nor 3)

So if we never covered multiples of 5, we'd start see these values ending in 5 start to fall through (55, 65 for instance).

Certainly not ALL values ending in 5 (5 is a prime, after all, and we have multiples of 3 that end in 5: 15, 45, 75). But we should see the pattern of what can slip through the cracks if it is never checked (so if it is needed to be checked, it absolutely needs to be checked).

The trick is in recognizing the value of the square root point in relation to the numbers involved. Because we're not going that high, we can utilize the square root point as a nice stopping point in our processing.

What about quantities, don't they screw with this scheme?

Yes, only because sieves need to know up front how much space to allocate (related to how many values to process). That is why we (somewhat grossly) overestimate (see the requisite section on the project page where we did a hack to allocate memory based on rough estimations of how many primes would be encountered).

In the end, though, it makes no difference: quantity or range, we have a means of knowing the (approximate with respect to quantity) amount of space needs and values to process. We'll admittedly take a bit of a performance hit because of eventual overestimations on quantities (as they get larger), unless you increased the resolution of estimation factors (beyond the x18, or the x6, x12, x18 example I showed on the project page).

But in the long run, performance on the sieve will be so staggering improved over primereg that even with a noted performance hit to accommodate quantity, it should still be drastically improved over the time-constrained algorithms.

haas/fall2021/discrete/projects/pnc2/faq.txt · Last modified: 2017/09/25 09:46 by 127.0.0.1