-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathbool.ott
203 lines (143 loc) · 3.92 KB
/
bool.ott
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
% Language additions for booleans
grammar
tm, a , b , A , B :: '' ::= {{ com terms and types }}
| Bool :: :: TyBool {{ com boolean type }}
| True :: :: LitTrue {{ com boolean value true }}
| False :: :: LitFalse {{ com boolean value false }}
| if a then b1 else b2 :: :: If {{ com conditional }}
| if a then b1 else b2 [ x . B ] :: :: IfM {{ com conditional }}
v :: 'v_' ::=
| Bool :: :: TyBool
| True :: :: LitTrue
| False :: :: LitFalse
neutral , ne :: 'n_' ::=
| if ne then a else b :: :: If
nf :: 'nf_' ::=
| Bool :: :: TyBool
| True :: :: LitTrue
| False :: :: LitFalse
| if ne then a else b :: :: If
defns
Jwhnf :: '' ::=
defn
whnf G |- a ~> nf :: :: whnf :: 'whnf_'
by
whnf G |- a ~> True
whnf G |- b1 ~> nf
--------------------------- :: if_true
whnf G |- if a then b1 else b2 ~> nf
whnf G |- a ~> False
whnf G |- b2 ~> nf
------------------------------- :: if_false
whnf G |- if a then b1 else b2 ~> nf
----------------- :: bool
whnf G |- Bool ~> Bool
---------------- :: true
whnf G |- True ~> True
------------------- :: false
whnf G |- False ~> False
whnf G |- a ~> ne
---------------------------------------------------- :: if_cong
whnf G |- if a then b1 else b2 ~> if ne then b1 else b2
defns
JOp :: '' ::=
defn
a ~> b :: :: step :: 's_'
{{ com single-step operational semantics, i. e. head reduction }}
by
---------------------------------- :: if_true
if True then b1 else b2 ~> b1
---------------------------------- :: if_false
if False then b1 else b2 ~> b1
a ~> a'
--------------------------------- :: if
if a then b1 else b2 ~> if a' then b1 else b2
defns
JEq :: '' ::=
defn
G |- A = B :: :: eq :: 'e_'
{{ com Definitional equality }}
by
----------------------------- :: if_true
G |- if True then a else b = a
------------------------------- :: if_false
G |- if False then a else b = b
G |- a = a'
G |- b1 = b1'
G |- b2 = b2'
--------------------------------------------------- :: if
G |- if a then b1 else b2 = if a' then b1' else b2'
-------------------------------- :: if_eta
G |- if a then b else b = b
defns
JTyping :: '' ::=
defn
G |- a : A :: :: typing :: 't_'
{{ com Typing }}
by
---------------- :: bool
G |- Bool : Type
---------------- :: true
G |- True : Bool
---------------- :: false
G |- False : Bool
G |- a : Bool
G |- b1 : A
G |- b2 : A
---------------------------- :: if_simple
G |- if a then b1 else b2 : A
G |- a : Bool
G |- b1 : A [ True / x ]
G |- b2 : A [ False / x ]
G, x:Bool |- A : Type
-------------------------------- :: if_full
G |- if a then b1 else b2 : A[a/x]
G |- x : Bool
G |- b1 : A [ True / x ]
G |- b2 : A [ False / x ]
G |- A : Type
---------------------------- :: if
G |- if x then b1 else b2 : A
defns
JBidirectional :: '' ::=
defn
G |- a => A :: :: inferType :: 'i_'
{{ com type synthesis (algorithmic) }}
by
---------------- :: bool
G |- Bool => Type
---------------- :: true
G |- True => Bool
---------------- :: false
G |- False => Bool
G |- a <= Bool
G |- b1 => A1
G |- b2 => A2
G |- A1 <=> A2
---------------------------- :: if_simple
G |- if a then b1 else b2 => A1
G |- a <= Bool
G |- b1 <= A [ True / x ]
G |- b2 <= A [ False / x ]
G, x:Bool |- A <= Type
-------------------------------- :: if_motive
G |- if a then b1 else b2 [x.A] => A[a/x]
G |- a <= Bool
G |- b1 => B1
G |- b2 => B2
----------------------------------------------- :: if_alt
G |- if a then b1 else b2 => if a then B1 else B2
defn
G |- a <= B :: :: checkType :: 'c_'
{{ com type checking (algorithmic) }}
by
G |- a <= Bool
G |- b1 <= A
G |- b2 <= A
---------------------------- :: if_simple
G |- if a then b1 else b2 <= A
G |- x <= Bool
G |- b1 <= A [ True / x ]
G |- b2 <= A [ False / x ]
------------------------------ :: if
G |- if x then b1 else b2 <= A