-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathFStar.Monotonic.Witnessed.fst
338 lines (269 loc) · 13.7 KB
/
FStar.Monotonic.Witnessed.fst
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
(*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Monotonic.Witnessed
open FStar.Preorder
(* NOT EXPOSED BY THE INTERFACE [start] *)
(*
A hybrid modal extension to F*'s classical reasoning logic:
- extends F*'s logic with two hybrid modal operators (get, set)
- extends F*'s logic with corresponding logical axioms, based
on the Kripke semantics of these two hybrid modal operators:
w |= get p iff w |= p w
w |= set p w' iff w' |= p
We do not expose these modal operators to the users directly.
Instead we use them below to define the 'witnessed' modality
which is the basis of reasoning about monotonic state in F*,
as discussed in Ahman et al.'s POPL 2018 paper "Recalling a
Witness: Foundations and Applications of Monotonic State".
*)
(* Hybrid modal operators *)
assume private type get : #world:Type -> (world -> Type0) -> Type0
assume private type set : #world:Type -> Type0 -> world -> Type0
(* Weakening for the get operator *)
assume val get_weakening :#world:Type
-> p:(world -> Type0)
-> q:(world -> Type0)
-> Lemma (requires (forall w. p w ==> q w))
(ensures (get p ==> get q))
[SMTPat (get p); SMTPat (get q)]
(* Interaction axioms between the get and set operators *)
assume val get_set_axiom :#world:Type
-> p:Type0
-> Lemma (get (set #world p) <==> p)
[SMTPat (get (set #world p))]
assume val set_get_axiom :#world:Type
-> w:world
-> p:(world -> Type0)
-> Lemma (set (get p) w <==> set (p w) w)
[SMTPat (set (get p) w)]
assume val set_set_axiom :#world:Type
-> w:world
-> w':world
-> p:Type0
-> Lemma (set (set p w') w <==> set p w')
[SMTPat (set (set p w') w)]
(* Useful derivable get lemma *)
private val get_constant_lemma :world:Type
-> p:Type0
-> Lemma (get #world (fun _ -> p) <==> p)
let get_constant_lemma world p = get_set_axiom #world p
(* Get and set commute with (non-modal) logical connectives *)
private val get_true :world:Type
-> Lemma (get #world (fun _ -> True))
let get_true world = get_constant_lemma world True
assume private val set_true :#world:Type
-> w:world
-> Lemma (set True w)
private val get_false :world:Type
-> Lemma (requires (get #world (fun _ -> False)))
(ensures (False))
let get_false world = get_constant_lemma world False
assume val set_false :#world:Type
-> w:world
-> Lemma (requires (set False w))
(ensures (False))
private val get_and_1 :#world:Type
-> p:(world -> Type0)
-> q:(world -> Type0)
-> Lemma (requires (get (fun w -> p w /\ q w)))
(ensures (get p /\ get q))
let get_and_1 #world p q = ()
assume private val set_and_1 :#world:Type
-> w:world
-> p:Type0
-> q:Type0
-> Lemma (requires (set (p /\ q) w))
(ensures (set p w /\ set q w))
assume private val get_and_2 :#world:Type
-> p:(world -> Type0)
-> q:(world -> Type0)
-> Lemma (requires (get p /\ get q))
(ensures (get (fun w -> p w /\ q w)))
assume private val set_and_2 :#world:Type
-> w:world
-> p:Type0
-> q:Type0
-> Lemma (requires (set p w /\ set q w))
(ensures (set (p /\ q) w))
private val get_or_1 :#world:Type
-> p:(world -> Type0)
-> q:(world -> Type0)
-> Lemma (requires (get p \/ get q))
(ensures (get (fun w -> p w \/ q w)))
let get_or_1 #world p q = ()
assume private val set_or_1 :#world:Type
-> w:world
-> p:Type0
-> q:Type0
-> Lemma (requires (set p w \/ set q w))
(ensures (set (p \/ q) w))
assume private val get_or_2 :#world:Type
-> p:(world -> Type0)
-> q:(world -> Type0)
-> Lemma (requires (get (fun w -> p w \/ q w)))
(ensures (get p \/ get q))
assume private val set_or_2 :#world:Type
-> w:world
-> p:Type0
-> q:Type0
-> Lemma (requires (set (p \/ q) w))
(ensures (set p w \/ set q w))
private val get_impl_1 :#world:Type
-> p:(world -> Type0)
-> q:(world -> Type0)
-> Lemma (requires (get (fun w -> p w ==> q w) /\ get p))
(ensures (get q))
let get_impl_1 #world p q =
get_and_2 (fun w -> p w ==> q w) p;
get_weakening (fun w -> (p w ==> q w) /\ p w) q
assume private val set_impl_1 :#world:Type
-> w:world
-> p:Type0
-> q:Type0
-> Lemma (requires (set (p ==> q) w /\ set p w))
(ensures (set q w))
assume private val get_impl_2 :#world:Type
-> p:(world -> Type0)
-> q:(world -> Type0)
-> Lemma (requires (get p ==> get q))
(ensures (get (fun w -> p w ==> q w)))
assume private val set_impl_2 :#world:Type
-> w:world
-> p:Type0
-> q:Type0
-> Lemma (requires (set p w ==> set q w))
(ensures (set (p ==> q) w))
private val get_forall_1_aux :#world:Type
-> #t:Type
-> p:(t -> world -> Type0)
-> x:t
-> Lemma (requires (get (fun w -> forall x. p x w)))
(ensures (get (fun w -> p x w)))
let get_forall_1_aux #world #t p x =
get_weakening (fun w -> forall x. p x w) (fun w -> p x w)
private val get_forall_1 :#world:Type
-> #t:Type
-> p:(t -> world -> Type0)
-> Lemma (requires (get (fun w -> forall x. p x w)))
(ensures (forall x. get (fun w -> p x w)))
let get_forall_1 #world #t p = ()
assume private val set_forall_1 :#world:Type
-> #t:Type
-> w:world
-> p:(t -> Type0)
-> Lemma (requires (set (forall x. p x) w))
(ensures (forall x. set (p x) w))
assume private val get_forall_2 :#world:Type
-> #t:Type
-> p:(t -> world -> Type0)
-> Lemma (requires (forall x. get (fun w -> p x w)))
(ensures (get (fun w -> forall x. p x w)))
assume private val set_forall_2 :#world:Type
-> #t:Type
-> w:world
-> p:(t -> Type0)
-> Lemma (requires (forall x. set (p x) w))
(ensures (set (forall x. p x) w))
private val get_exists_1_aux :#world:Type
-> #t:Type
-> p:(t -> world -> Type0)
-> x:t
-> Lemma (requires (get (fun w -> p x w)))
(ensures (get (fun w -> exists x. p x w)))
let get_exists_1_aux #world #t p x =
get_weakening (fun w -> p x w) (fun w -> exists x . p x w)
private val get_exists_1 :#world:Type
-> #t:Type
-> p:(t -> world -> Type0)
-> Lemma (requires (exists x. get (fun w -> p x w)))
(ensures (get (fun w -> exists x. p x w)))
let get_exists_1 #world #t p = ()
assume private val set_exists_1 :#world:Type
-> #t:Type
-> w:world
-> p:(t -> Type0)
-> Lemma (requires (exists x. set (p x) w))
(ensures (set (exists x. p x) w))
assume private val get_exists_2 :#world:Type
-> #t:Type
-> p:(t -> world -> Type0)
-> Lemma (requires (get (fun w -> exists x. p x w)))
(ensures (exists x. get (fun w -> p x w)))
assume private val set_exists_2 :#world:Type
-> #t:Type
-> w:world
-> p:(t -> Type0)
-> Lemma (requires (set (exists x. p x) w))
(ensures (exists x. set (p x) w))
private val get_eq :#world:Type
-> #t:Type
-> v:t
-> v':t
-> Lemma (get #world (fun _ -> v == v') <==> v == v')
let get_eq #world #t v v' =
get_constant_lemma world (v == v')
assume private val set_eq :#world:Type
-> #t:Type
-> w:world
-> v:t
-> v':t
-> Lemma (set (v == v') w <==> v == v')
(* NOT EXPOSED BY THE INTERFACE [end] *)
(* EXPOSED BY THE INTERFACE [start] *)
(* Witnessed modality *)
let witnessed #state rel p = get (fun s -> forall s'. rel s s' ==> p s')
(* Weakening for the witnessed modality *)
let lemma_witnessed_weakening #state rel p q = ()
(* Some logical properties of the witnessed modality *)
let lemma_witnessed_constant #state rel p = get_constant_lemma state p
let lemma_witnessed_nested #state rel p = ()
let lemma_witnessed_and #state rel p q =
let aux () :Lemma (requires (witnessed rel p /\ witnessed rel q))
(ensures (witnessed rel (fun s -> p s /\ q s)))
= get_and_2 (fun s -> forall s'. rel s s' ==> p s') (fun s -> forall s'. rel s s' ==> q s')
in
FStar.Classical.move_requires aux ()
let lemma_witnessed_or #state rel p q = ()
let lemma_witnessed_impl #state rel p q =
let aux () :Lemma (requires ((witnessed rel (fun s -> p s ==> q s) /\ witnessed rel p)))
(ensures (witnessed rel q))
= get_and_2 (fun s -> forall s'. rel s s' ==> p s' ==> q s') (fun s -> forall s'. rel s s' ==> p s')
in
FStar.Classical.move_requires aux ()
let lemma_witnessed_forall #state #t rel p =
let aux () :Lemma (requires (forall x. witnessed rel (fun s -> p x s)))
(ensures (witnessed rel (fun s -> forall x. p x s)))
= get_forall_2 #state #t (fun x s -> forall s'. rel s s' ==> p x s')
in
FStar.Classical.move_requires aux ()
let lemma_witnessed_exists #state #t rel p = ()
(* EXPOSED BY THE INTERFACE [end] *)
(* NOT EXPOSED BY THE INTERFACE [start] *)
(* An equivalent past-view of the witnessed modality *)
let witnessed_past (#state:Type) (rel:preorder state) (p:(state -> Type0)) =
get (fun s -> exists s'. rel s' s /\ (forall s''. rel s' s'' ==> p s''))
val witnessed_defs_equiv_1 :#state:Type
-> rel:preorder state
-> p:(state -> Type0)
-> Lemma (requires (witnessed #state rel p))
(ensures (witnessed #state rel p))
let witnessed_defs_equiv_1 #state rel p = ()
val witnessed_defs_equiv_2 :#state:Type
-> rel:preorder state
-> p:(state -> Type0)
-> Lemma (requires (witnessed #state rel p))
(ensures (witnessed #state rel p))
let witnessed_defs_equiv_2 #state rel p =
get_weakening #state (fun s -> exists s'. rel s' s /\ (forall s''. rel s' s'' ==> p s''))
(fun s -> forall s'. rel s s' ==> p s')
(* NOT EXPOSED BY THE INTERFACE [end] *)