-
Notifications
You must be signed in to change notification settings - Fork 1
/
075-is_multiply_prime.dfy
43 lines (42 loc) · 1.56 KB
/
075-is_multiply_prime.dfy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
predicate Prime(p: nat)
{
p > 1 &&
forall k :: 1 < k < p ==> p % k != 0
}
method is_multiply_prime(x: nat) returns (ans : bool)
// pre-conditions-start
requires x > 1
// pre-conditions-end
// post-conditions-start
ensures ans <==> exists a: nat, b: nat, c: nat :: Prime(a) && Prime(b) && Prime(c) && x == a * b * c
// post-conditions-end
{
// impl-start
for a := 2 to x
// invariants-start
invariant forall i: nat, j: nat, k: nat :: (Prime(i) && Prime(j) && Prime(k) && i < a) ==> x != i * j * k
// invariants-end
{
if Prime(a) {
for b := 2 to x
// invariants-start
invariant forall j: nat, k: nat :: (Prime(j) && Prime(k) && j < b) ==> x != a * j * k
// invariants-end
{
if Prime(b) {
for c := 2 to x
// invariants-start
invariant forall k: nat :: (Prime(k) && k < c) ==> x != a * b * k
// invariants-end
{
if Prime(c) && x == a * b * c {
return true;
}
}
}
}
}
}
return false;
// impl-end
}