-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathba.rkt
52 lines (46 loc) · 1.4 KB
/
ba.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
#lang racket
(require redex)
(require redex/tut-subst)
(define-language BA
(t ::= v
true
false
(if t t t)
(succ t)
(pred t)
(zero? t))
(p ::= t)
(b ::= true false)
(v ::= b n)
(n ::= number)
(err ::= mismatch underflow)
(o ::= p err)
;; Evaluation Context
(E ::= hole (if E p p) (succ E) (pred E) (zero? E)))
;; Define the metafunction to lift Substitution into Redex
(define x? (redex-match BA x)) ;; Verifies that the given 'x' belongs to the Grammar of PCF
(define-metafunction BA
subst : x v e -> e
[(subst x v e)
,(subst/proc x? (list (term x)) (list (term v)) (term e))])
(define red
(reduction-relation
BA
#:domain o
(--> (in-hole E (if true p_1 p_2)) (in-hole E p_1) "ift")
(--> (in-hole E (if false p_1 p_2)) (in-hole E p_2) "iff")
(--> (in-hole E (if p_1 p_2 p_3)) mismatch
(side-condition (not
(cond
[(equal? (term p) true) "mismatch"]
[(equal? (term p) false) "mismatch"])))
"mismatch")
(--> (in-hole E (pred 0)) underflow "underflow")
(--> (in-hole E (pred n))
,(- (term n) 1)
(side-condition (not (equal? (term n) 0)))
"predecessor")
(--> (in-hole E (succ n)) ,(+ (term n) 1) "successor")
(--> (in-hole E (zero? n)) ,(if (equal? (term n) 0) (term true) (term false)))))
(define -->red
(compatible-closure red BA o))