-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.rkt
65 lines (54 loc) · 1.39 KB
/
util.rkt
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
#lang s-exp rosette/safe
(require rosette/lib/meta/meta
rosette/lib/tools/render)
(provide domain
mapthunk
choose*
decide*
number*
hole*)
; -----------------------
; Random utility function
; -----------------------
(define (mapthunk f n)
(letrec ([rec (lambda (i) (if (= i 0)
null
(cons (f)
(rec (- i 1)))))])
(rec n)))
(define (repeat x n)
(letrec ([rec (lambda (i) (if (= i 0)
null
(cons x
(rec (- i 1)))))])
(rec n)))
; -------------------------
; Enhanced solver interface
; -------------------------
; Choose an expression dynamically
(define (choose* . xs)
(define-symbolic* i number?)
(assert (>= i 0))
(assert (< i (length xs)))
(list-ref xs i))
; Dynamically create a decision/boolean
(define (decide*)
(define-symbolic* b boolean?)
b)
; Dynamically create a number
(define (number* a b)
(define-symbolic* n number?)
(assert (>= n a))
(assert (< n b))
n)
; Dynamically create a constant hole
(define (hole*)
(define-symbolic* h number?)
h)
; Return the "domain" of the solver
(define domain
(thunk
(let ([n (expt 2 (- (current-bitwidth) 1))])
(list
(- n)
(- n 1)))))