for var i:nat=2; i ≤ rootOfp; i=i+1 do
invariant 2 ≤ i ∧ i ≤ rootOfp+2;
- invariant ∀j:nat with j < i. (ret[j] = true) ⇔ (isPrime(j) ∧
- (∀l:nat with j < l. (divides(j,l) ⇒ ¬isPrime(l))));
+ // Prime elements in range 2..rootOfp
+ invariant ∀j:nat with j < i. (ret[j] = true) ⇔ isPrime(j);
invariant ∀j:nat with j < i. (ret[j] = false) ⇔ ¬isPrime(j);
+ // Prime divisors that have already been processed
+ invariant ∀j:nat with 2 < i ∧ i < j ∧ j < MAX. ( divides(i-1,j) ⇒ ret[j] = false);
decreases rootOfp+2-i;
{
if ret[i] = true then
invariant 1 ≤ k ∧ k ≤ MAX/i;
invariant ∀p:nat with p ≤ i. (ret[p] = true ⇒
// p+r*i < MAX is implied by range of k
+ // partial processed array
(∀r:nat with 1 ≤ r ∧ r < k. ret[(r+1)*p] = false));
decreases MAX/i - k;
{
return ret;
}
+