-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExample.sin
More file actions
32 lines (24 loc) · 852 Bytes
/
Copy pathExample.sin
File metadata and controls
32 lines (24 loc) · 852 Bytes
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
let rec
merge = lambda a. lambda b.
{assume a and b infinite and disjoint}
let a1=hd a, b1=hd b
in if a1 < b1 then a1::(merge (tl a) b)
else {a1 > b1} b1::(merge a (tl b)),
mult = lambda a. lambda b. (a * hd b)::(mult a tl b),
remove = lambda a. lambda b.
{ a-b, treat lists as sets. PRE: a & b ascending }
if hd a < hd b then (hd a)::(remove tl a b)
else if hd a > hd b then remove a tl b
else remove tl a tl b,
from = lambda n. n::(from (n+1)),
{ n::(n+1)::(n+2):: ... }
products = lambda l. { PRE: l ascending }
let rec p = (hd l * hd l) :: { & elts coprime }
(merge (mult hd l (merge tl l p))
(products tl l))
in p
in let rec
composites = products primes,
primes = 2 :: (remove (from 3) composites) { ! }
in primes
{\fB Composites and Primes. \fP}