-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFCC.v
459 lines (414 loc) · 12.7 KB
/
FCC.v
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
(** * Formula Choice Calculus (FCC) *)
Require Import Bool.
Require Import Relations.Relation_Definitions.
Require Import Classes.Morphisms.
Require Import Setoids.Setoid.
Load Formula.
Import Formula.
Module FCC.
(** ** Syntax *)
(** Syntax of choice calculus expressions with global dimensions and formula
choices. The object language is binary trees. *)
(** Object language syntax. *)
Inductive obj : Type :=
| empty : obj
| tree : unit -> obj -> obj -> obj.
(** Expression syntax. *)
Inductive cc : Type :=
| empty' : cc
| tree' : unit -> cc -> cc -> cc
| chc : formula -> cc -> cc -> cc.
(* TODO: write notation for choice. *)
(** ** Semantics *)
(** The semantics of a choice calculus expression is a function from
configurations to terms in the object language, i.e., binary trees. *)
(** Expression semantics. *)
Fixpoint semE (e : cc) (c : config) : obj :=
match e with
| empty' => empty
| tree' x l r => tree x (semE l c) (semE r c)
| chc f l r => if semF f c then semE l c else semE r c
end.
(** ** Semantic Equivalence Rules *)
(** Statement and proof of syntactic rules for expression equivalence from my
thesis. Multiple proofs are given when it is instructive. *)
(** Semantic equivalence for expressions. *)
Definition equivE : relation cc :=
fun e e' => forall c, (semE e c) = (semE e' c).
Infix "=e=" := equivE (at level 70) : type_scope.
(** Expression equivalence is reflexive. *)
Remark equivE_refl : Reflexive equivE.
Proof.
intros x c.
reflexivity.
Qed.
(** Expression equivalence is symmetric. *)
Remark equivE_sym : Symmetric equivE.
Proof.
intros x y H c.
symmetry.
apply H.
Qed.
(** Expression equivalence is transitive. *)
Remark equivE_trans : Transitive equivE.
Proof.
intros x y z H1 H2 c.
transitivity (semE y c).
apply H1.
apply H2.
Qed.
(** Expression equivalence is an equivalence relation. *)
Instance eqE : Equivalence equivE.
Proof.
split.
apply equivE_refl.
apply equivE_sym.
apply equivE_trans.
Qed.
(* TODO: make choice congruence rules instance of [Proper] typeclass. *)
(** Choice transposition rule. *)
Theorem chc_trans : forall (f : formula) (l r : cc),
chc f l r =e= chc (~ f) r l.
Proof.
(* Proof by unfolding [equivE]. *)
intros f l r c.
simpl.
destruct (semF f c);
reflexivity.
Qed.
(** AST-L-Congruence rule. *)
Remark ast_l_cong : forall l l' r : cc,
l =e= l' ->
tree' tt l r =e= tree' tt l' r.
Proof.
intros l l' r H c.
simpl.
rewrite -> H.
reflexivity.
Qed.
(** AST-R-Congruence rule. *)
Remark ast_r_cong : forall l r r' : cc,
r =e= r' ->
tree' tt l r =e= tree' tt l r'.
Proof.
intros l r r' H c.
simpl.
rewrite -> H.
reflexivity.
Qed.
(** Choice congruence rule for labels. *)
Remark chc_cong_f : forall (f f' : formula) (l r : cc),
f =f= f' ->
chc f l r =e= chc f' l r.
Proof.
(* Proof by unfolding [equivE]. *)
intros f f' l r H c.
simpl.
rewrite -> H.
reflexivity.
Qed.
(** Choice congruence rule for left alternatives. *)
Remark chc_cong_l : forall (f : formula) (l l' r : cc),
l =e= l' ->
chc f l r =e= chc f l' r.
Proof.
(* Proof by unfolding [equivE]. *)
intros f l l' r H c.
simpl.
rewrite -> H.
reflexivity.
Qed.
(** Choice congruence rule for right alternatives. *)
Remark chc_cong_r : forall (f : formula) (l r r' : cc),
r =e= r' ->
chc f l r =e= chc f l r'.
Proof.
(* Proof by unfolding [equivE]. *)
intros f l r r' H c.
simpl.
rewrite -> H.
reflexivity.
Restart.
(* Proof by deriving from [chc_cong_l]. *)
intros f l r r' H.
rewrite -> chc_trans.
rewrite -> chc_cong_l by apply H.
rewrite <- chc_trans.
reflexivity.
Qed.
(** Choice idempotence rule. *)
Theorem chc_idemp : forall (f : formula) (e : cc),
chc f e e =e= e.
Proof.
(* Proof by unfolding [equivE]. *)
intros f e c.
simpl.
destruct (semF f c);
reflexivity.
Qed.
(** Choice simplification rule for left label. *)
Theorem chc_f_l : forall (l r : cc),
chc (litT L) l r =e= l.
Proof.
(* Proof by unfolding [equivE]. *)
intros l r c.
reflexivity.
Qed.
(** Choice simplification rule for right label. *)
Theorem chc_f_r : forall (l r : cc),
chc (litT R) l r =e= r.
Proof.
(* Proof by unfolding [equivE]. *)
intros l r c.
reflexivity.
Restart.
(* Proof by deriving from [chc_f_l]. *)
intros l r.
rewrite -> chc_trans.
rewrite -> chc_cong_f by apply comp_r_l.
apply chc_f_l.
Qed.
(** Choice label join rule. *)
Theorem chc_f_join : forall (f1 f2 : formula) (l r : cc),
chc f1 l (chc f2 l r) =e= chc (f1 \/ f2) l r.
Proof.
(* Proof by unfolding [equivE]. *)
intros f1 f2 l r c.
simpl.
destruct (semF f1 c);
reflexivity.
Qed.
(** Choice label meet rule. *)
Theorem chc_f_meet : forall (f1 f2 : formula) (l r : cc),
chc f1 (chc f2 l r) r =e= chc (f1 /\ f2) l r.
Proof.
(* Proof by unfolding [equivE]. *)
intros f1 f2 l r c.
simpl.
destruct (semF f1 c);
reflexivity.
Restart.
(* Proof by deriving from [chc_f_join]. *)
intros f1 f2 l r.
rewrite -> chc_cong_l with (l' := chc (~ f2) r l) by apply chc_trans.
rewrite -> chc_trans.
rewrite -> chc_f_join.
rewrite -> chc_cong_f with (f' := ~ (f1 /\ f2)).
rewrite <- chc_trans.
reflexivity.
symmetry.
apply comp_meet.
Qed.
(** Choice label join complement rule. *)
Theorem chc_f_join_comp : forall (f1 f2 : formula) (l r : cc),
chc f1 l (chc f2 r l) =e= chc (f1 \/ ~ f2) l r.
Proof.
(* Proof by unfolding [equivE]. *)
intros f1 f2 l r c.
simpl.
destruct (semF f1 c);
simpl;
try rewrite -> negb_if;
reflexivity.
Restart.
(* Proof by deriving from [chc_f_join]. *)
intros f1 f2 l r.
rewrite -> chc_cong_r with (r' := chc (~ f2) l r) by apply chc_trans.
rewrite -> chc_f_join.
reflexivity.
Qed.
(** Choice label meet complement rule. *)
Theorem chc_f_meet_comp : forall (f1 f2 : formula) (l r : cc),
chc f1 (chc f2 r l) r =e= chc (f1 /\ ~ f2) l r.
Proof.
(* Proof by unfolding [equivE]. *)
intros f1 f2 l r c.
simpl.
destruct (semF f1 c);
simpl;
try rewrite -> negb_if;
reflexivity.
Restart.
(* Proof by deriving from [chc_f_meet]. *)
intros f1 f2 l r.
rewrite -> chc_cong_l with (l' := chc (~ f2) l r) by apply chc_trans.
rewrite -> chc_f_meet.
reflexivity.
Qed.
(* TODO: choice domination rule? *)
(** C-C-Merge rule. *)
Theorem cc_merge : forall (f : formula) (l r e e' : cc),
chc f (chc f l e) (chc f e' r) =e= chc f l r.
Proof.
(* Proof by unfolding [equivE]. *)
intros f l r e e' c.
simpl.
destruct (semF f c);
reflexivity.
Qed.
(** C-C-Merge rule for the case where the nested choice appears in the left
alternative. *)
Theorem cc_merge_l : forall (f : formula) (l r e : cc),
chc f (chc f l e) r =e= chc f l r.
Proof.
(* Proof by unfolding [equivE]. *)
intros f l r e c.
simpl.
destruct (semF f c);
reflexivity.
Restart.
(* Proof by deriving from [cc_merge]. *)
intros f l r e.
rewrite <- chc_cong_r with (r := chc f r r) by apply chc_idemp.
rewrite -> cc_merge.
reflexivity.
Qed.
(** C-C-Merge rule for the case where the nested choice appears in the right
alternative. *)
Theorem cc_merge_r : forall (f : formula) (l r e : cc),
chc f l (chc f e r) =e= chc f l r.
Proof.
(* Proof by deriving from [cc_merge_l]. *)
intros f l r e.
rewrite -> chc_cong_r with (r' := chc (~ f) r e) by apply chc_trans.
rewrite -> chc_trans.
rewrite -> cc_merge_l.
rewrite <- chc_trans.
reflexivity.
Qed.
(** AST-Factoring rule. *)
Theorem ast_factor : forall (f : formula) (l l' r r' : cc),
chc f (tree' tt l r) (tree' tt l' r') =e=
tree' tt (chc f l l') (chc f r r').
Proof.
intros f l l' r r' c.
simpl.
destruct (semF f c);
reflexivity.
Qed.
(** C-C-Swap rule. *)
Theorem cc_swap : forall (f1 f2 : formula) (e1 e2 e3 e4 : cc),
chc f1 (chc f2 e1 e2) (chc f2 e3 e4) =e=
chc f2 (chc f1 e1 e3) (chc f1 e2 e4).
Proof.
(* Proof by unfolding [equivE]. *)
intros f1 f2 e1 e2 e3 e4 c.
simpl.
destruct (semF f1 c);
reflexivity.
Qed.
(** C-C-Swap rule for the case where the nested choice appears in the left
alternative of the simpler form. *)
Theorem cc_swap_l : forall (f f' : formula) (l r r' : cc),
chc f' (chc f l r') (chc f r r') =e=
chc f (chc f' l r) r'.
Proof.
(* Proof by unfolding [equivE]. *)
intros f f' l r r' c.
simpl.
destruct (semF f' c);
reflexivity.
Restart.
(* Proof by deriving from [cc_swap]. *)
intros f f' l r r'.
rewrite -> cc_swap.
rewrite -> chc_cong_r by apply chc_idemp.
reflexivity.
Qed.
(** C-C-Swap rule for the case where the nested choice appears in the right
alternative of the simpler form. *)
Theorem cc_swap_r : forall (f f' : formula) (l l' r : cc),
chc f' (chc f l l') (chc f l r) =e=
chc f l (chc f' l' r).
Proof.
(* Proof by deriving from [cc_swap_l]. *)
intros f f' l l' r.
rewrite -> chc_cong_l with (l' := chc (~ f) l' l) by apply chc_trans.
rewrite -> chc_cong_r with (r' := chc (~ f) r l) by apply chc_trans.
rewrite -> cc_swap_l.
rewrite <- chc_trans.
reflexivity.
Qed.
(** ** Examples *)
(** Examples of some additional properties and derivations by semantic
equivalence rules. *)
Module Examples.
(** Flip operation. *)
Fixpoint flip (e : cc) : cc :=
match e with
| chc f l r => chc (~ f) (flip r) (flip l)
| _ => e
end.
(** The flip operation is an involution. *)
Example flip_invo : forall e : cc,
flip (flip e) =e= e.
Proof.
induction e as [n | n l IHl r IHr | f l IHl r IHr].
(* Case: [e = leaf' n]. *)
reflexivity.
(* Case: [e = node' n l r]. *)
reflexivity.
(* Case: [e = chc f l r]. *)
simpl.
rewrite -> chc_cong_f by apply comp_invo.
rewrite -> chc_cong_l by apply IHl.
rewrite -> chc_cong_r by apply IHr.
reflexivity.
Qed.
End Examples.
(** A subset of syntactic rules for expression equivalence. *)
Inductive equivE' : cc -> cc -> Prop :=
(* equivalence rules *)
| equivE_refl' : forall x : cc,
equivE' x x
| equivE_sym' : forall x y : cc,
equivE' x y ->
equivE' y x
| equivE_trans' : forall x y z : cc,
equivE' x y -> equivE' y z ->
equivE' x z
(* congruence rules *)
| ast_cong : forall l l' r r' : cc,
equivE' l l' -> equivE' r r' ->
equivE' (tree' tt l r) (tree' tt l' r')
| chc_cong : forall (f f' : formula) (l l' r r' : cc),
f =f= f' -> equivE' l l' -> equivE' r r' ->
equivE' (chc f l r) (chc f' l' r')
(* choice transposition rule *)
| chc_trans' : forall (f : formula) (l r : cc),
equivE' (chc f l r) (chc (~ f) r l)
(* choice simplification rules *)
| chc_idemp' : forall (f : formula) (e : cc),
equivE' (chc f e e) e
| chc_f_l' : forall (l r : cc),
equivE' (chc (litT L) l r) l
(* formula choice rule *)
| chc_f_join' : forall (f1 f2 : formula) (l r : cc),
equivE' (chc f1 l (chc f2 l r))
(chc (f1 \/ f2) l r)
(* choice merge rule *)
| cc_merge' : forall (f : formula) (l r e e' : cc),
equivE' (chc f (chc f l e) (chc f e' r))
(chc f l r)
(* object and choice commutation rules *)
| ast_factor' : forall (f : formula) (l l' r r' : cc),
equivE' (chc f (tree' tt l r) (tree' tt l' r'))
(tree' tt (chc f l l') (chc f r r'))
| cc_swap' : forall (f1 f2 : formula) (e1 e2 e3 e4 : cc),
equivE' (chc f1 (chc f2 e1 e2) (chc f2 e3 e4))
(chc f2 (chc f1 e1 e3) (chc f1 e2 e4)).
(** The subset of syntactic rules is complete. *)
Theorem equivE_complete : forall e e' : cc,
e =e= e' -> equivE' e e'.
Proof.
intros e e' H.
destruct e as [| tt l r | f l r]; destruct e' as [| tt' l' r' | f' l' r'].
(* Case: [e = empty'] and [e' = empty']. *)
apply equivE_refl'.
(* Case: [e = empty'] and [e' = tree' tt' l' r']. *)
(* Case: [e = empty'] and [e' = chc f' l' r']. *)
(* Case: [e = tree' tt l r] and [e' = tree' tt' l' r']. *)
(* Case: [e = tree' tt l r] and [e' = chc f' l' r']. *)
(* Case: [e = chc f l r] and [e' = chc f' l' r']. *)
Admitted. (* TODO: prove completeness for subset of rules. *)
End FCC.