-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-smt-search-cfg.ss
113 lines (95 loc) · 4.66 KB
/
test-smt-search-cfg.ss
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!r6rs
;; Test slice sampling
(import (only (scheme-tools) pretty-print symbol-maker)
(scheme-tools srfi-compat :69)
(scheme-tools srfi-compat :1)
(scheme-tools math)
(scheme-tools bin)
(unweave smt-search)
(unweave external labeling)
(unweave type-inference)
(unweave invariant-inference))
;; Geometric
;; (define expr2
;; '(letrec ([sum-list (lambda (xs)
;; (if (null? xs) 0
;; (+ (car xs)
;; (sum-list (cdr xs)))))])
;; (sum-list (cons 1 (cons 2 (cons 3 '()))))))
'(define expr2
'(assert
(letrec ([geometric (lambda ()
(if (xrp 1 1 1 #t #f)
'()
(cons (+ (xrp 1 1 1 0 1)
(xrp 1 1 1 0 1))
(geometric))))])
(geometric))
(lambda (n) (equal? n (cons 1 (cons 1 (cons 1 (cons 1 '()))))))))
(define expr2
'(assert
(letrec ([geometric (lambda ()
(if (xrp 1 1 1 #t #f)
'()
(if (xrp 1 1 1 #t #f)
(cons 1 (geometric))
(cons 1 (cons 1 (geometric))))))])
(geometric))
(lambda (n) (equal? n (cons 1 (cons 1 (cons 1 (cons 1 '()))))))))
(define transformed-expr
(anf (label-transform expr2)))
(pretty-print transformed-expr)
(define inferred-types
(infer-types transformed-expr
`((+ . (-> Int (-> Int Int)))
(- . (-> Int (-> Int Int)))
(* . (-> Int (-> Int Int)))
(= . (-> Int (-> Int Bool)))
(equal? . (-> a (-> a Bool)))
(> . (-> Int (-> Int Bool)))
(< . (-> Int (-> Int Bool)))
(cons . (-> a (-> (Lst a) (Lst a))))
(() . (Lst a))
(car . (-> (Lst a) a))
(cdr . (-> (Lst a) (Lst a)))
(null? . (-> (Lst a) Bool))
(flip . (-> () Bool)))))
(pretty-print transformed-expr)
(pretty-print inferred-types)
(define inferred-invariants
(infer-invariants transformed-expr (cadr inferred-types)
'((unit . (: (rf (V unit) true) unit ()))
(flip . (-> () (: (rf (V Bool) (or (= true V) (= false V))) Bool ())))
(car . (-> (: (rf (V (Lst a)) true) (Lst a) xs) (: (rf (V a) (= V (car xs))) a ())))
(cdr . (-> (: (rf (V (Lst a)) true) (Lst a) xs) (: (rf (V (Lst a)) (= V (cdr xs))) (Lst a) ())))
(null? . (-> (: (rf (V (Lst a)) true) (Lst a) x)
(: (rf (V Bool) (= V (= nil x))) Bool ())))
(cons . (-> (: (rf (V a) true) a x)
(-> (: (rf (V (Lst a)) true) (Lst a) y)
(: (rf (V (Lst a)) (= V (cons x y))) (Lst a) ()))))
(equal? . (-> (: (rf (V a) true) a x)
(-> (: (rf (V a) true) a y)
(: (rf (V Bool) (= V (= x y))) Bool ()))))
(() . (: (rf (V (Lst a)) true) (Lst a) ()))
(+ . (-> (: (rf (V Int) true) Int x)
(-> (: (rf (V Int) true) Int y)
(: (rf (V Int) (= V (+ x y))) Int ()))))
(- . (-> (: (rf (V Int) true) Int x)
(-> (: (rf (V Int) true) Int y)
(: (rf (V Int) (= V (- x y))) Int ()))))
(* . (-> (: (rf (V Int) true) Int x)
(-> (: (rf (V Int) true) Int y)
(: (rf (V Int) (= V (* x y))) Int ()))))
(= . (-> (: (rf (V Int) true) Int x)
(-> (: (rf (V Int) true) Int y)
(: (rf (V Bool) (= V (= x y))) Bool ()))))
(> . (-> (: (rf (V Int) true) Int x)
(-> (: (rf (V Int) true) Int y)
(: (rf (V Bool) (= V (> x y))) Bool ()))))
(< . (-> (: (rf (V Int) true) Int x)
(-> (: (rf (V Int) true) Int y)
(: (rf (V Bool) (= V (< x y))) Bool ())))))))
(pretty-print inferred-invariants)
(define label->invariant-map (caddr inferred-invariants))
(define label->invariant-map '())
(pretty-print (smt-calc-prob 100 transformed-expr (cadr inferred-types) label->invariant-map))