aboutsummaryrefslogtreecommitdiff
path: root/src/racket_specs
diff options
context:
space:
mode:
authorAria Shrimpton <me@aria.rip>2024-01-25 13:44:49 +0000
committerAria Shrimpton <me@aria.rip>2024-01-25 13:44:49 +0000
commit2944298c10918da40a3b4ccbf850029a317375a0 (patch)
treed564dcb7d52b757cc65ac4603ba51dde9125519b /src/racket_specs
parenteac6d0a8dea55bc1f190218b8f1a6a9f10059037 (diff)
support constraint checking on mappings
Diffstat (limited to 'src/racket_specs')
-rw-r--r--src/racket_specs/combinators.rkt9
-rw-r--r--src/racket_specs/mapping-setup.rkt47
2 files changed, 55 insertions, 1 deletions
diff --git a/src/racket_specs/combinators.rkt b/src/racket_specs/combinators.rkt
index a74296b..016a44f 100644
--- a/src/racket_specs/combinators.rkt
+++ b/src/racket_specs/combinators.rkt
@@ -74,5 +74,12 @@
[(< (length l) 2) null]
[else (append (list (take l 2)) (consecutive-pairs (drop l 1)))]))
+; Mapping helpers
+
+; (is-map? lst) -> boolean?
+(define (is-map? l)
+ (and (list? l)
+ (andmap pair? l)))
+
; Export procedures
-(provide for-all-unique-pairs for-all-consecutive-pairs for-all-elems elem-and not-equal? leq? geq? unique-count?) \ No newline at end of file
+(provide for-all-unique-pairs for-all-consecutive-pairs for-all-elems elem-and not-equal? leq? geq? unique-count? is-map?)
diff --git a/src/racket_specs/mapping-setup.rkt b/src/racket_specs/mapping-setup.rkt
new file mode 100644
index 0000000..6b6fc48
--- /dev/null
+++ b/src/racket_specs/mapping-setup.rkt
@@ -0,0 +1,47 @@
+#lang rosette
+
+(define (check-spec-len prop pre spec xs)
+ (assume (and (prop xs) (pre xs)))
+ (assert (prop (car (spec xs)))))
+
+(define (check-spec-is-empty prop pre spec xs)
+ (assume (and (prop xs) (pre xs)))
+ (assert (prop (car (spec xs)))))
+
+(define (check-spec-contains prop pre spec xs x)
+ (assume (and (prop xs) (pre xs)))
+ (assert (prop (car (spec xs x)))))
+
+(define (check-spec-insert prop pre spec xs x)
+ (assume (and (prop xs) (pre xs)))
+ (assert (prop (spec xs x))))
+
+(define (check-spec-remove prop pre spec xs x)
+ (assume (and (prop xs) (pre xs)))
+ (assert (prop (car (spec xs x)))))
+
+(define (check-spec-clear prop pre spec xs)
+ (assume (and (prop xs) (pre xs)))
+ (assert (prop (spec xs))))
+
+(define (check-not-contradict prop pre xs)
+ (assert (and (prop xs) (pre xs) (> (length xs) 1))))
+
+(define (check prop pres specs xs k v)
+ (cond
+ [(or (unsat? (solve (check-not-contradict prop (first pres) xs)))
+ (unsat? (solve (check-not-contradict prop (second pres) xs)))
+ (unsat? (solve (check-not-contradict prop (third pres) xs)))
+ (unsat? (solve (check-not-contradict prop (fourth pres) xs)))
+ (unsat? (solve (check-not-contradict prop (fifth pres) xs)))
+ (unsat? (solve (check-not-contradict prop (sixth pres) xs)))
+ ) #f]
+ [else (and (unsat? (verify (check-spec-clear prop (first pres) (first specs) xs)))
+ (unsat? (verify (check-spec-contains prop (second pres) (second specs) xs k)))
+ (unsat? (verify (check-spec-insert prop (third pres) (third specs) xs k v)))
+ (unsat? (verify (check-spec-is-empty prop (fourth pres) (fourth specs) xs)))
+ (unsat? (verify (check-spec-len prop (fifth pres) (fifth specs) xs)))
+ (unsat? (verify (check-spec-remove prop (sixth pres) (sixth specs) xs k)))
+ )]))
+
+(provide check)