-
Notifications
You must be signed in to change notification settings - Fork 2
/
Metatheory_SP.v
1309 lines (1128 loc) · 32.1 KB
/
Metatheory_SP.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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(***************************************************************************
* Extra lemmas and tactics concerning lists, sets, and metatheory *
* Jacques Garrigue, june 2009, Coq 8.2 *
***************************************************************************)
Set Implicit Arguments.
Require Import List Arith Lib_Tactic Lib_FinSet.
Require Omega.
Require Import Metatheory_Var.
Require Import Metatheory_Fresh.
Require Import Metatheory_Env.
Import Env.
Open Scope set_scope.
Open Scope env_scope.
(** Rewriting programs *)
Ltac case_rewrite H t :=
case_eq t; introv H; rewrite H in *; try discriminate.
(** Results on lists *)
Hint Resolve in_or_app : core.
Lemma in_app_mid : forall (A:Set) (x a:A) l1 l2,
In x (l1 ++ a :: l2) -> a = x \/ In x (l1 ++ l2).
Proof.
intros.
destruct* (in_app_or _ _ _ H).
simpl in H0; destruct* H0.
Qed.
Lemma InA_In : forall v L, SetoidList.InA E.eq v L -> In v L.
induction 1; auto.
Qed.
Lemma cons_append : forall (A:Set) (a:A) l, a :: l = (a :: nil) ++ l.
Proof. auto.
Qed.
Section Nth.
Variables (A : Set) (d : A).
Lemma exists_nth : forall x Xs,
In x Xs -> exists n, n < length Xs /\ x = nth n Xs d.
Proof.
induction Xs; intros. elim H.
simpl in H; destruct* H.
exists 0; rewrite H; simpl; split2*. apply lt_O_Sn.
destruct* IHXs as [n [Hlen EQ]].
exists (S n). simpl; split2*.
apply* lt_n_S.
Qed.
End Nth.
Section Index.
Variable A : Set.
Hypothesis eq_dec : forall x y : A, {x = y}+{x <> y}.
Fixpoint index (i:nat) (x:A) (l : list A) {struct l} : option nat :=
match l with
| nil => None
| y::l' => if eq_dec x y then Some i else index (S i) x l'
end.
Lemma index_none_notin : forall x l n,
index n x l = None -> ~In x l.
Proof.
induction l; simpl; intros. auto.
destruct* (eq_dec x a). discriminate.
Qed.
Import Omega.
Lemma index_ok : forall def a l n,
index 0 a l = Some n ->
n < length l /\ nth n l def = a.
Proof.
intros.
replace n with (n-0) by omega.
apply (proj2 (A:= 0 <= n)).
gen n; generalize 0.
induction l; simpl; intros. discriminate.
destruct (eq_dec a a0).
subst.
inversions H.
split2*.
replace (n0 - n0) with 0 by omega.
auto with arith.
destruct (IHl _ _ H).
split. omega.
case_eq (n0 - n); intros.
elimtype False; omega.
replace n2 with (n0 - S n) by omega.
destruct H1.
auto with arith.
Qed.
End Index.
Section Combine.
Variables A B : Set.
Definition list_fst := List.map (@fst A B).
Definition list_snd := List.map (@snd A B).
Lemma combine_fst_snd : forall l,
combine (list_fst l) (list_snd l) = l.
Proof.
induction l; simpl. auto.
destruct a; simpl; rewrite* IHl.
Qed.
Lemma length_fst_snd : forall l,
length (list_fst l) = length (list_snd l).
Proof.
intros; unfold list_fst, list_snd.
do 2 rewrite map_length. auto.
Qed.
Lemma split_combine : forall (l:list (A*B)) l1 l2,
split l = (l1, l2) -> combine l1 l2 = l.
Proof.
intros. puts (split_combine l). rewrite H in H0. auto.
Qed.
Lemma split_length : forall l (l1:list A) (l2:list B),
split l = (l1, l2) -> length l1 = length l2.
Proof.
intros.
use (split_length_l l).
rewrite <- (split_length_r l) in H0.
rewrite H in H0; apply H0.
Qed.
Lemma combine_app : forall (l1 l2:list A) (l1' l2':list B),
length l1 = length l1' ->
combine (l1 ++ l2) (l1' ++ l2') = combine l1 l1' ++ combine l2 l2'.
Proof.
induction l1; destruct l1'; simpl; intros; try discriminate. auto.
rewrite* IHl1.
Qed.
Definition map_snd (f:B->B) :=
List.map (fun p:A*B => (fst p, f (snd p))).
Lemma map_snd_inv : forall f x y (l:list(A*B)),
In (x, y) (map_snd f l) ->
exists z, f z = y /\ In (x,z) l.
Proof.
intros.
destruct (proj1 (in_map_iff _ _ _) H) as [[x' T'] [Heq Hin]].
simpl in Heq. inversions Heq.
exists* T'.
Qed.
Lemma in_map_snd : forall f x y (l:list(A*B)),
In (x,y) l -> In (x, f y) (map_snd f l).
Proof.
introv.
refine (in_map _ _ _).
Qed.
Lemma list_fst_map_snd : forall f l,
list_fst (map_snd f l) = list_fst l.
Proof.
induction l; simpl; intros. auto. congruence.
Qed.
Lemma list_snd_map_snd : forall f l,
list_snd (map_snd f l) = List.map f (list_snd l).
Proof.
induction l; simpl; intros. auto. congruence.
Qed.
Variable eq_dec : forall x y:A, {x=y}+{x<>y}.
Fixpoint assoc x (l:list (A*B)) {struct l} : option B :=
match l with
| nil => None
| (y,z)::r => if eq_dec x y then Some z else assoc x r
end.
Lemma assoc_sound : forall x y l,
assoc x l = Some y -> In (x,y) l.
Proof.
induction l; simpl; intros. discriminate.
destruct a. destruct* (eq_dec x a). inversions* H.
Qed.
Lemma assoc_complete : forall x y l,
assoc x l = None -> ~In (x,y) l.
Proof.
induction l; simpl; intros; intro. tauto.
destruct a.
destruct (eq_dec x a). discriminate.
destruct H0. inversions* H0.
elim (IHl H H0).
Qed.
Lemma assoc_map : forall f x y l,
assoc x l = y -> assoc x (map_snd f l) = option_map f y.
Proof.
induction l; simpl; intros. subst*.
destruct a.
simpl.
destruct* (eq_dec x a).
inversions* H.
Qed.
End Combine.
Hint Resolve split_length in_map_snd : core.
Section Map.
Variables A B : Set.
Lemma list_map_comp : forall (f g:A->A) l,
List.map f (List.map g l) = List.map (fun x:A => f (g x)) l.
Proof.
induction l; simpl*. rewrite* IHl.
Qed.
Lemma list_map_ext : forall (l:list A) (f1 f2:A->B),
(forall x, In x l -> f1 x = f2 x) ->
List.map f1 l = List.map f2 l.
Proof.
intros. induction l. auto.
simpl. rewrite* H. rewrite* IHl.
Qed.
End Map.
Section Forall.
Variables (A:Set) (P:A->Prop).
Definition map_prop (f : forall c, P c) l : list_forall P l.
induction l; auto.
Defined.
Lemma list_forall_in : forall l,
(forall x, In x l -> P x) -> list_forall P l.
Proof.
induction l; simpl*.
Qed.
Lemma list_forall_out : forall l,
list_forall P l -> forall x, In x l -> P x.
Proof.
induction 1; simpl*; intros.
destruct* H1. subst*.
Qed.
Lemma list_forall_app : forall l1 l2,
list_forall P l1 -> list_forall P l2 -> list_forall P (l1 ++ l2).
Proof.
induction 1; intros; simpl; auto.
Qed.
Lemma list_forall_app_inv : forall l1 l2,
list_forall P (l1 ++ l2) -> list_forall P l2.
Proof.
induction l1; simpl; intros. auto.
inversion* H.
Qed.
Lemma list_forall_apply : forall (Q:A->Prop) l,
list_forall (fun x => P x -> Q x) l ->
list_forall P l -> list_forall Q l.
Proof.
intros; induction* H.
inversion* H0.
Qed.
Lemma list_forall_imp : forall (Q:A->Prop) l,
(forall x, P x -> Q x) -> list_forall P l -> list_forall Q l.
Proof.
induction l; intros; auto.
inversions H0.
constructor; auto.
Qed.
Lemma list_forall_rev : forall l,
list_forall P l -> list_forall P (rev l).
Proof.
induction l; simpl; intros; auto.
inversions H.
apply* list_forall_concat.
Qed.
Variable (B:Set) (Q:B -> Prop).
Lemma list_forall_map : forall f l,
(forall x, In x l -> P x -> Q (f x)) ->
list_forall P l ->
list_forall Q (List.map f l).
Proof.
intros; induction l.
simpl*.
inversion H0.
simpl; constructor; auto.
Qed.
Lemma list_for_n_map : forall f n l,
(forall x, In x l -> P x -> Q (f x)) ->
list_for_n P n l ->
list_for_n Q n (List.map f l).
Proof.
intros.
destruct H0; split. rewrite* map_length.
apply* list_forall_map.
Qed.
End Forall.
Hint Resolve list_forall_apply : core.
Ltac list_forall_find P l :=
match goal with
| H: list_forall P ?l1 |- _ =>
match l1 with context[l] => apply* (list_forall_out H) end
end.
Ltac list_forall_solve :=
match goal with
| |- list_forall ?P ?l =>
apply list_forall_in; intros; list_forall_find P l
| |- list_forall ?P (?l1++?l2) =>
let a := fresh "a" in let H := fresh "Hin" in
apply list_forall_in; intros a H;
destruct (in_app_or _ _ _ H);
[list_forall_find P l1 | list_forall_find P l2]
| |- list_forall ?P (?a :: ?l) =>
let x := fresh "x" in let H := fresh "Hin" in
apply list_forall_in; intros x H; simpl in H;
destruct H; [subst x; list_forall_find P a | list_forall_find P l]
end.
Hint Extern 1 (list_forall _ _) => solve [list_forall_solve] : core.
Section Forall2.
Inductive list_forall2 (A B:Set) (P:A->B->Prop) : list A -> list B -> Prop :=
| list_forall2_nil : list_forall2 P nil nil
| list_forall2_cons : forall a b la lb,
P a b ->
list_forall2 P la lb ->
list_forall2 P (a::la) (b::lb).
Hint Constructors list_forall2 : core.
Variables A B : Set.
Variable P : A -> B -> Prop.
Lemma list_forall2_app : forall l1 l2 l3 l4,
list_forall2 P l1 l3 -> list_forall2 P l2 l4 ->
list_forall2 P (l1 ++ l2) (l3 ++ l4).
Proof.
intros until 1.
revert l2 l4.
induction H; simpl*.
Qed.
Lemma list_forall2_app_inv : forall l2 l4 l1 l3,
list_forall2 P (l1 ++ l2) (l3 ++ l4) ->
length l1 = length l3 ->
list_forall2 P l1 l3 /\ list_forall2 P l2 l4.
Proof.
induction l1; intros; destruct l3; try discriminate; simpl in *.
auto.
inversions H.
destruct* (IHl1 l3).
Qed.
Lemma list_forall2_length : forall l1 l2,
list_forall2 P l1 l2 -> length l1 = length l2.
Proof.
induction 1; simpl*.
Qed.
Lemma list_forall2_In: forall x l1 l2,
In x l1 -> list_forall2 P l1 l2 -> exists y:B, In y l2 /\ P x y.
Proof.
induction 2. elim H.
simpl in H; destruct H.
subst*.
destruct* IHlist_forall2.
Qed.
Lemma list_forall2_get : forall Xs Ys Zs x y z,
list_forall2 P Ys Zs ->
binds x y (combine Xs Ys) ->
binds x z (combine Xs Zs) ->
P y z.
Proof.
intros.
gen Xs; induction H; intros; destruct Xs; try discriminate.
simpl in *.
env_fix.
binds_cases H1; binds_cases H2;
try solve [elim Fr; apply S.singleton_2; reflexivity].
apply* IHlist_forall2.
subst*.
Qed.
Lemma list_forall2_nth : forall d1 d2 n l1 l2,
list_forall2 P l1 l2 -> n < length l1 ->
P (nth n l1 d1) (nth n l2 d2).
Proof.
induction n; intros; inversions H; try elim (lt_n_O _ H0).
auto.
simpl. apply* IHn. simpl in H0; auto with arith.
Qed.
Lemma list_forall2_rev : forall l1 l2,
list_forall2 P l1 l2 -> list_forall2 P (rev l1) (rev l2).
Proof.
induction 1; simpl. auto.
apply* list_forall2_app.
Qed.
Variables C D : Set.
Variable P' : A -> B -> Prop.
Lemma list_forall2_map: forall (P1:C->D->Prop) f g l1 l2,
list_forall2 P l1 l2 ->
(forall x y, P x y -> P1 (f x) (g y)) ->
list_forall2 P1 (List.map f l1) (List.map g l2).
Proof.
clear P'.
induction 1; simpls; auto*.
Qed.
Lemma list_forall2_imp : forall l1 l2,
list_forall2 P l1 l2 ->
(forall x y, P x y -> P' x y) ->
list_forall2 P' l1 l2.
Proof.
induction 1; simpls; auto*.
Qed.
Lemma For_all2_map_iff1 : forall (f:C->A) l1 l2,
list_forall2 P (List.map f l1) l2 <-> list_forall2 (fun x => P (f x)) l1 l2.
Proof.
induction l1; destruct l2; simpl; split; intros; inversions H; auto;
destruct* (IHl1 l2).
Qed.
Lemma list_forall2_refl : forall (P:A->A->Prop),
(forall x, P x x) ->
forall l, list_forall2 P l l.
Proof.
induction l; simpl*.
Qed.
End Forall2.
Hint Constructors list_forall2 : core.
Hint Resolve list_forall2_app list_forall2_length
list_forall2_map list_forall2_imp list_forall2_refl : core.
Section Cut.
Variable A:Set.
Fixpoint cut (n:nat) (l:list A) {struct n} : list A * list A :=
match n with
| 0 => (nil, l)
| S n =>
match l with
| nil => (nil, nil)
| a :: l => let (l1, l2) := cut n l in (a :: l1, l2)
end
end.
Lemma cut_ok : forall n l l1 l2,
n <= length l -> cut n l = (l1, l2) ->
length l1 = n /\ l = l1 ++ l2.
Proof.
Import Omega.
induction n; simpl; intros.
inversions* H0.
destruct l; simpl in *.
elimtype False; omega.
assert (n <= length l) by omega.
case_rewrite R (cut n l).
inversions* H0.
destruct* (IHn l l0 l2).
subst*.
Qed.
End Cut.
(** Properties of mkset *)
Fixpoint mkset (l:list var) {struct l} : vars :=
match l with
| nil => {}
| h :: t => {{h}} \u mkset t
end.
Lemma in_mkset : forall x Xs,
In x Xs -> x \in mkset Xs.
Proof.
induction Xs; intros. elim H.
simpl.
simpl in H; destruct H.
apply S.union_2. auto with sets.
apply* S.union_3.
Qed.
(** Disjointness *)
Definition disjoint s1 s2 :=
forall x, x \in s1 -> x \notin s2.
Lemma disjoint_comm : forall A B,
disjoint A B -> disjoint B A.
Proof.
intros. intros x Hx Hx'. elim (H _ Hx' Hx).
Qed.
(********************************************************************)
(* A clever tactic to handle finite sets *)
(* First, some properties of sets *)
Lemma mem_3 : forall v L, S.mem v L = false -> v \notin L.
Proof.
intros. intro.
rewrite (S.mem_1 H0) in H.
discriminate.
Qed.
Hint Resolve mem_3 : core.
Lemma in_vars_dec : forall v S, {v \in S}+{v \notin S}.
Proof.
intros.
case_eq (S.mem v S); intros; auto with sets.
Qed.
Lemma remove_4 : forall y x L, y \in S.remove x L -> ~E.eq x y.
Proof.
intros; intro.
elim (S.remove_1 H0 H).
Qed.
Ltac sets_simpl_hyps x :=
match goal with
| H: _ \in {} |- _ => elim (in_empty H)
| H: x \in {{?y}} |- _ =>
puts (proj1 (in_singleton _ _) H); clear H;
subst y; try sets_simpl_hyps x
| H: x \in S.diff _ _ |- _ =>
let H1 := fresh "Hin" in let H2 := fresh "Hn" in
poses H1 (S.diff_1 H); poses H2 (S.diff_2 H); clear H;
try sets_simpl_hyps x
| H: x \in S.inter _ _ |- _ =>
let H1 := fresh "Hin" in let H2 := fresh "Hin" in
poses H1 (S.inter_1 H); poses H2 (S.inter_2 H); clear H;
try sets_simpl_hyps x
| H: S.mem x _ = false |- _ =>
let H1 := fresh "Hn" in
poses H1 (mem_3 H); clear H; try sets_simpl_hyps x
| H: x \in S.remove _ _ |- _ =>
let H1 := fresh "Hin" in let H2 := fresh "Hn" in
poses H1 (S.remove_3 H); poses H2 (remove_4 H); clear H;
try sets_simpl_hyps x
end.
Ltac sets_simpl :=
match goal with |- ?x \in _ => try sets_simpl_hyps x end.
Ltac find_in_goal L :=
match goal with |- ?x \in ?E =>
match E with context[L] =>
match goal with
| |- x \in L => assumption
| |- _ \in ?L1 \u ?L2 =>
try (apply S.union_2; find_in_goal L);
apply S.union_3; find_in_goal L
| |- _ \in S.diff ?L1 ?L2 =>
apply S.diff_3; [find_in_goal L | notin_solve]
| |- _ \in S.remove ?y ?L1 =>
let HE := fresh "HE" in
apply S.remove_2;
[try assumption; intro HE; rewrite HE in *; solve [auto]
| find_in_goal L]
end
end
end.
Ltac find_in_solve x :=
match goal with
| |- ?y \in _ => puts (S.singleton_2 (S.E.eq_refl y)); find_in_goal {{y}}
| H: x \in ?L |- _ => find_in_goal L
end.
Ltac union_solve x :=
try sets_simpl_hyps x;
try match goal with
| H: ~E.eq ?y ?y |- _ => elim H; reflexivity
| H: ?y <> ?y |- _ => elim H; reflexivity
| H: x \in _ \u _ |- _ =>
destruct (S.union_1 H); clear H; union_solve x
| H: x \notin ?L1 |- _ =>
match L1 with context[{{x}}] =>
elim H; find_in_solve x
end ||
match goal with
| H': x \in L1 |- _ => elim (H H')
| H': x \in ?L2 |- _ =>
match L1 with context[L2] =>
elim H; find_in_solve x
end
end
| H: ?L1 << ?L2 |- _ =>
match goal with
| H': x \in L1 |- _ =>
let H1 := fresh "Hin" in poses H1 (H _ H'); clear H; union_solve x
| H': x \in ?L3 |- _ =>
match L1 with context[L3] =>
let H1 := fresh "Hin" in
assert (H1: x \in L2) by (apply H; find_in_solve x);
clear H; union_solve x
end
end
| H: disjoint ?L1 ?L2 |- _ =>
match goal with
| H': x \in L1 |- _ =>
let H1 := fresh "Hin" in poses H1 (H _ H'); clear H; union_solve x
| H': x \in L2 |- _ =>
let H1 := fresh "Hin" in
poses H1 (disjoint_comm H H'); clear H; union_solve x
| H': x \in ?L3 |- _ =>
match L1 with context[L3] =>
let H1 := fresh "Hin" in
assert (H1: x \notin L2) by (apply H; find_in_solve x);
clear H; union_solve x
end ||
match L2 with context[L3] =>
let H1 := fresh "Hin" in
assert (H1: x \notin L1) by (apply (disjoint_comm H); find_in_solve x);
clear H; union_solve x
end
end
end.
Ltac sets_solve :=
match goal with
| |- ?x \in _ => try union_solve x; try find_in_solve x
| |- _ << _ =>
let y := fresh "y" in let Hy := fresh "Hy" in
intros y Hy; sets_solve
| |- ?x \notin _ =>
let H := fresh "Hin" in intro H; try union_solve x
| |- disjoint _ _ =>
let y := fresh "y" in let Hy := fresh "Hy" in let Hy' := fresh "Hy'" in
intros y Hy Hy'; try union_solve y
end.
Lemma test_self : forall x, x \in {{x}}.
intros; sets_solve.
Qed.
Lemma test_remove : forall x L1 L2,
S.remove x (L1 \u L2) << S.remove x (L2 \u L1).
Proof.
intros; sets_solve.
Qed.
Lemma test_subset : forall L1 L2 L3,
L2 << L1 -> L1 \u L2 << L3 -> L2 << L3.
Proof.
intros; sets_solve.
Qed.
Local Hint Extern 1 (_ \in _) => solve [sets_solve] : core.
Local Hint Extern 1 (_ << _) => solve [sets_solve] : core.
Local Hint Extern 1 (_ \notin _) => solve [sets_solve] : core.
Local Hint Extern 1 (disjoint _ _) => solve [sets_solve] : core.
(** More results on disjointness *)
Lemma disjoint_union : forall A B C,
disjoint A B -> disjoint A C -> disjoint A (B \u C).
Proof.
intros. auto.
Qed.
Lemma disjoint_empty : forall A, disjoint A {}.
auto*.
Qed.
Lemma disjoint_empty_l : forall A, disjoint {} A.
auto*.
Qed.
Lemma notin_disjoint : forall x A, x \notin A -> disjoint A {{x}}.
auto*.
Qed.
Lemma notin_disjoint_l : forall x L, x \notin L -> disjoint {{x}} L.
auto*.
Qed.
Lemma ok_disjoint : forall (A:Set) (E F:Env.env A),
ok (E & F) -> disjoint (dom E) (dom F).
Proof.
induction F; simpls; intros. auto.
destruct a; simpl.
inversions H.
rewrite dom_concat in H4.
use (IHF H2).
Qed.
Hint Resolve ok_disjoint : core.
Lemma fresh_disjoint : forall n Xs L,
fresh L n Xs -> disjoint (mkset Xs) L.
Proof.
induction n; destruct Xs; simpl; intros; auto*.
destruct H.
sets_solve.
apply* (IHn _ _ H0).
Qed.
Hint Immediate fresh_disjoint : core.
Lemma neq_disjoint : forall x y, x <> y -> disjoint {{x}} {{y}}.
auto*.
Qed.
Lemma disjoint_notin : forall s v, disjoint s {{v}} -> v \notin s.
auto*.
Qed.
Lemma diff_disjoint : forall L1 L2, disjoint (S.diff L1 L2) L2.
auto*.
Qed.
Lemma fresh_notin_mkset : forall n x Xs,
fresh {{x}} n Xs -> x \notin mkset Xs.
Proof.
intros.
apply* disjoint_notin.
Qed.
(** Results on environments *)
Section Env.
Variable A : Set.
Definition in_concat_or (E F:env A) p (H:In p (E & F)) :=
in_app_or F E p H.
Definition in_or_concat (E F:env A) p H : In p (E & F) :=
in_or_app F E p H.
Hint Resolve in_or_concat : core.
Lemma ok_cons : forall (E:env A) x (a:A),
ok E -> x # E -> ok ((x,a) :: E).
Proof (@ok_push A).
Lemma ok_single : forall x (a:A), ok (x ~ a).
intros. unfold single; apply ok_cons. apply (@ok_empty A).
simpl*.
Qed.
Lemma disjoint_ok : forall E F:env A,
ok E -> ok F -> disjoint (dom E) (dom F) -> ok (E & F).
Proof.
induction F; simpl; intros. auto.
destruct a; unfold concat.
apply ok_cons.
apply* IHF. inversion* H0.
fold (E&F).
rewrite dom_concat.
inversions* H0.
Qed.
Lemma binds_in : forall x (a:A) E,
binds x a E -> In (x, a) E.
Proof.
unfold binds; induction E; intros. elim (binds_empty H).
destruct a0; simpl in *.
destruct* (x == v). inversions* H.
Qed.
Lemma in_dom : forall x (a:A) E,
In (x,a) E -> x \in dom E.
Proof.
induction E; simpl; intros. elim H.
destruct H.
subst. auto.
destruct a0.
use (IHE H).
Qed.
Lemma binds_dom : forall x (a:A) E,
binds x a E -> x \in dom E.
Proof.
intros; apply* in_dom; apply* binds_in.
Qed.
Lemma in_ok_binds : forall x (a:A) E,
In (x,a) E -> ok E -> binds x a E.
Proof.
intros.
unfold binds.
induction H0. elim H.
simpl.
simpl in H; destruct H.
inversions H.
destruct* (x == x).
destruct* (x == x0).
subst.
elim (binds_fresh (IHok H) H1).
Qed.
Lemma dom_binds : forall x E,
x \in dom E -> exists y:A, binds x y E.
Proof.
induction E; simpl; intros. elim (in_empty H).
destruct a.
destruct (x == v); subst.
exists a. apply (binds_head v a E).
destruct* (S.union_1 H).
elim n; rewrite* (proj1 (in_singleton x v) H0).
destruct* IHE.
exists x0.
apply* (@binds_tail A x v x0 a E).
Qed.
Lemma binds_combine : forall x (c:A) Ys Ks,
binds x c (combine Ys Ks) -> In c Ks.
Proof.
induction Ys; destruct Ks; simpl; intros; try (elim (binds_empty H)).
unfold binds in H. simpl in H.
destruct* (eq_var_dec x a). inversion* H.
Qed.
Lemma in_dom_combine : forall v Xs (Us:list A),
v \in dom (combine Xs Us) -> In v Xs.
Proof.
induction Xs; destruct Us; simpl; auto; intros.
elim (in_empty H).
destruct (proj1 (in_union _ _ _) H).
rewrite* (proj1 (in_singleton _ _) H0).
auto*.
Qed.
(** More properties of get *)
Lemma get_notin_dom : forall x (S :env A),
x # S -> get x S = None.
Proof.
induction S; intros. auto.
destruct a; simpl in *.
destruct (eq_var_dec x v).
rewrite e in H. elim H. auto with sets.
auto with sets.
Qed.
Lemma dom_combine : forall Xs (As:list A),
length Xs = length As -> dom (combine Xs As) = mkset Xs.
Proof.
induction Xs; destruct As; simpl; intros; try discriminate. auto.
rewrite* IHXs.
Qed.
Lemma get_none_notin : forall x (S : env A),
get x S = None -> x # S.
Proof.
induction S; intro; simpl; auto*.
destruct* a.
simpl in H. destruct* (eq_var_dec x v).
discriminate.
intro. destruct* (proj1 (in_union _ _ _) H0).
elim n; apply (proj1 (in_singleton _ _) H1).
Qed.
Lemma get_none_notin_list : forall x (a:A) E,
get x E = None -> ~In (x,a) E.
Proof.
induction E; simpl; intros. auto.
destruct a0. destruct (x == v). discriminate.
intro. destruct H0. inversions H0. elim n; auto.
intuition.
Qed.
Section Map.
Variable f : A -> A.
Lemma ok_map0 : forall E,
ok E -> ok (map f E).
Proof.
intros.
rewrite (app_nil_end (map f E)).
fold (nil & map f E).
apply ok_map.
unfold concat; rewrite* <- (app_nil_end E).
Qed.
Lemma map_snd_env_map : forall l,
map_snd f l = Env.map f l.
Proof.
induction l; simpl*.
destruct a. rewrite* IHl.
Qed.
Lemma map_get_none : forall x E,
get x E = None -> get x (map f E) = None.
Proof.
induction E; simpl; intros; auto*.
destruct a. simpl. destruct* (eq_var_dec x v).
discriminate.
Qed.
Lemma in_map_inv : forall x a E,
In (x,a) (map f E) -> exists b, f b = a /\ In (x,b) E.
Proof.
induction E; simpl; intros. elim H.
destruct a0.
simpl in H; destruct H.
inversions H.
exists* a0.
destruct (IHE H).
exists* x0.
Qed.
Lemma binds_map_inv : forall S x y,
binds x y (map f S) -> exists z, f z = y /\ binds x z S.
Proof.
unfold binds.
induction S; simpl; intros. discriminate.
destruct a.
simpl in H.
destruct (x == v).
inversions H.
exists* a.
apply* IHS.
Qed.
End Map.
Section Env_prop.
Variable P : A -> Prop.
Lemma env_prop_single : forall x a, P a -> env_prop P (x ~ a).
Proof.
intros; intro; intros.
destruct* H0.
inversions* H0.
elim H0.
Qed.
Lemma env_prop_concat : forall l1 l2,
env_prop P l1 -> env_prop P l2 -> env_prop P (l1 & l2).
Proof.
intros; intro; intros.
destruct* (in_app_or _ _ _ H1).
Qed.
Lemma env_prop_concat_inv : forall l1 l2,
env_prop P (l1 & l2) -> env_prop P l1 /\ env_prop P l2.
Proof.
intros; split; intro; intros; apply* (H x).
Qed.
Lemma env_prop_single_inv : forall x a,
env_prop P (x ~ a) -> P a.
Proof.
intros; apply* H.
Qed.
Lemma env_prop_map : forall (f:A->A) E,
env_prop P (map f E) -> env_prop (fun x => P (f x)) E.
Proof.
intros; intro; intros.
apply (H x).
rewrite <- map_snd_env_map.
apply* in_map_snd.
Qed.
Lemma env_prop_list_forall : forall Xs Vs,
env_prop P (combine Xs Vs) ->
ok (combine Xs Vs) -> length Xs = length Vs -> list_forall P Vs.
Proof.
induction Xs; destruct Vs; simpl; intros; try discriminate; auto.
inversion H1; inversions H0.
constructor.
apply* (IHXs Vs).
intro; intros. apply* (H x).
apply* (H a).
Qed.
Lemma list_forall_env_prop : forall Xs Vs,
list_forall P Vs -> env_prop P (combine Xs Vs).
Proof.
intros; gen Xs.
induction H; destruct Xs; intro; simpl; intros; try contradiction.
destruct H1.
inversions* H1.
apply (IHlist_forall _ _ _ H1).
Qed.
End Env_prop.