-
Notifications
You must be signed in to change notification settings - Fork 8
/
tapl.scm
59 lines (52 loc) · 1.52 KB
/
tapl.scm
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
59
(define ∅L '(as emptyset (Set L)))
(define L
(lambda ()
(z/
`(declare-datatypes
((L 0))
(((tru) (fls) (zero) (succ (s1 L)) (pred (p1 L)) (iszero (z1 L))))))))
(define fresh/L
(lambda (t xs)
(if (null? xs) succeed (fresh () (z/ `(declare-const ,(car xs) ,t)) (freshL t (cdr xs))))))
(define map-seto
(lambda (fo s out)
(conde
((z/== s ∅L)
(z/== out ∅L))
((fresh (se sr oe or)
(fresh/L '(Set L) (list sr or))
(fresh/L 'L (list se oe))
(z/== s (set sr se))
(!ino se sr)
(z/== out (set or oe))
(!ino oe or)
(fo se oe)
(map-seto fo sr or))))))
(define S
(lambda (i s)
(conde
((z/== i 0) (z/== s ∅L))
((fresh (i-1 S-1 S-11 S-111 S-succ S-pred S-iszero s1 s2)
(freshL '(Set L) (list S-1 S-succ S-pred S-iszero s1 s2))
(z/== i `(+ 1 ,i-1))
(S i-1 S-1)
(map-seto (lambda (e o) (z/== o `(succ ,e))) S-1 S-succ)
(map-seto (lambda (e o) (z/== o `(pred ,e))) S-1 S-pred)
(map-seto (lambda (e o) (z/== o `(iszero ,e))) S-1 S-iszero)
(uniono (set ∅L 'tru 'fls 'zero) S-succ s1)
(uniono s1 S-pred s2)
(uniono s2 S-iszero s))))))
(test "S0"
(run* (q) (L) (freshL '(Set L) (list q))
(S 0 q))
`(,∅L))
(test "S1"
(run* (q) (L) (freshL '(Set L) (list q))
(S 1 q))
'((union
[union (singleton tru) (singleton fls)]
[singleton zero])))
(ignore "S2"
(run 1 (q) (L) (freshL '(Set L) (list q))
(S 2 q))
'works-but-not-pretty)