User Tools

Site Tools


Sidebar

projects

pct0 (bonus; due 20190821)
mtf0 (bonus; due 20190821)
dsi0 (due 20190821)
wcp1 (due 20190821)
pct1 (due 20190828)
wcp2 (due 20190828)
bdt0 (due 20190904)
pct2 (due 20190904)
wcp3 (due 20190904)
dcf0 (due 20190911)
pct3 (due 20190911)
wcp4 (due 20190911)
nbm0 (due 20190918)
pct4 (due 20190918)
wcp5 (due 20190918)
bdt1 (due 20190925)
pct5 (due 20190925)
wcp6 (due 20190925)
mtf1 (due 20191002)
pct6 (due 20191002)
wcp7 (due 20191002)
dcf1 (due 20191009)
pct7 (due 20191009)
wcp8 (due 20191009)
yol0 (due 20191023)
pct8 (bonus; due 20191023)
pct9 (due 20191023)
wcp9 (due 20191023)
ewn0 (due 20191030)
pctA (due 20191030)
wcpA (due 20191030)
dcf2 (due 20191106)
pctB (due 20191106)
wcpB (due 20191106)
cnv0 (due 20191113)
pctC (due 20191113)
wcpC (due 20191113)
EoCE (due 20191211)
haas:fall2019: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/fall2019/discrete/projects/pnc2/faq.txt · Last modified: 2017/09/25 09:46 by 127.0.0.1