Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
added verification of prime count, sum and product
Source Link
DarthGizka
  • 2.8k
  • 1
  • 13
  • 30

Note: the primes up to 64K are only the lowest level a three-level operation for sieving up to 2^64, the factors of the factors as it were. And each level gets considerably more complicated to code and verify (even 'just' a reference implementation). I've already discussed a few issues regarding the verification of prime sieves over on Stack Overflow last year:

Preempting an objection that hasn't been raised yet - the class could and should compare prime count, sum and product against expected values just like the file vetting script linked above does.

assert_equal("count", 6542, Primes.Length);
var sum = Primes.Select((p) => (int)p).Sum();
assert_equal("sum", 202288087, sum);
var primorial_64bit = Primes.Select((p) => (ulong)p).Aggregate((product, prime) => product * prime);
assert_equal("product", 8987519195527561682UL, primorial_64bit);

Note: the primes up to 64K are only the lowest level a three-level operation for sieving up to 2^64, the factors of the factors as it were. And each level gets considerably more complicated to code and verify (even 'just' a reference implementation). I've already discussed a few issues regarding the verification of prime sieves over on Stack Overflow last year:

Preempting an objection that hasn't been raised yet - the class could and should compare prime count, sum and product against expected values just like the file vetting script linked above does.

assert_equal("count", 6542, Primes.Length);
var sum = Primes.Select((p) => (int)p).Sum();
assert_equal("sum", 202288087, sum);
var primorial_64bit = Primes.Select((p) => (ulong)p).Aggregate((product, prime) => product * prime);
assert_equal("product", 8987519195527561682UL, primorial_64bit);
added para about reference implementations
Source Link
DarthGizka
  • 2.8k
  • 1
  • 13
  • 30

Another consideration: a reference implementation remains verified only as long as the verified binary remains unmodified - that is, until someone hits the 'build' button again, at which point there's new binary that requires verification. Add to that the fact that I've uncovered (and reported) several compiler bugs in each of the compilers I used extensively, starting with MS VC++, Borland C++ and Delphi, and a whole slew of them in FoxPro. And there are plenty more ways how things can go wrong, even without compiler bugs (starting with stale object files/libraries). In that light a local, write-protected file is a whole lot simpler and inspires a whole lot more trust.

Another consideration: a reference implementation remains verified only as long as the verified binary remains unmodified - that is, until someone hits the 'build' button again, at which point there's new binary that requires verification. Add to that the fact that I've uncovered (and reported) several compiler bugs in each of the compilers I used extensively, starting with MS VC++, Borland C++ and Delphi, and a whole slew of them in FoxPro. And there are plenty more ways how things can go wrong, even without compiler bugs (starting with stale object files/libraries). In that light a local, write-protected file is a whole lot simpler and inspires a whole lot more trust.

fixed awkward expression
Source Link
DarthGizka
  • 2.8k
  • 1
  • 13
  • 30
Loading
Source Link
DarthGizka
  • 2.8k
  • 1
  • 13
  • 30
Loading
lang-cs

AltStyle によって変換されたページ (->オリジナル) /