-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprime-stms.c
58 lines (46 loc) · 900 Bytes
/
prime-stms.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// TYPE(VARS): expression of type TYPE over variables VARS
bool divides (int q, int p) {
return BOOL(p,q);
}
//
bool prime (int p) {
if (BOOL(p)) return BOOL(p);
else {
int q = INT(p,q);
while (BOOL(p,q))
if (BOOL(p,q)) return BOOL(p,q);
else ANY(p,q);
}
return BOOL(p);
}
int main () {
if (BOOL()) ANY(); else ANY();
}
/*
BOOL(p,q): (p / q) * q == p
BOOL(p): p == 1 || divides(2,p)
BOOL(p): true
INT(p,q): 3
BOOL(p,q): q * q <= p
BOOL(p,q): divides(q,p)
BOOL(p,q): false
ANY(p,q): q = q + 2
BOOL(p): false
BOOL(): prime(641)
ANY(): printInt(641)
ANY(): printInt(0)
*/
/*
BOOL(): prime(641)
BOOL(p): p == 1 || divides(2,p)
true
false
BOOL(p,q): (p / q) * q == p
q * q <= p
divides(q,p)
false
INT(p,q): 3
ANY(): printInt(641)
printInt(0)
ANY(p,q): q = q + 2
*/