-
Notifications
You must be signed in to change notification settings - Fork 0
/
bounds.v
1659 lines (1431 loc) · 64.7 KB
/
bounds.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
From SFS Require Import cps cps_util set_util identifiers ctx Ensembles_util
List_util functions tactics map_util.
From SFS Require Import heap heap_defs
cc_log_rel compat closure_conversion closure_conversion_util GC.
From Coq Require Import ZArith.Znumtheory Arith Arith.Wf_nat Relations.Relations
Lists.List MSets.MSets MSets.MSetRBT Numbers.BinNums
NArith.BinNat PArith.BinPos Sets.Ensembles Omega Permutation.
Require Import SFS.Maps.
Import ListNotations.
Open Scope ctx_scope.
Open Scope fun_scope.
Close Scope Z_scope.
Module Size (H : Heap).
Module Util := CCUtil H.
Import H Util.C.LR.Sem Util.C.LR.Sem.GC Util.C.LR.Sem.GC.Equiv
Util.C.LR.Sem.GC.Equiv.Defs Util.C.LR.Sem.GC
Util.C.LR Util.C Util.
(** * Size of CPS terms and heaps, needed to express the upper bound on the execution cost of certain transformations *)
(** The extra cost incurred by closure conversion when evaluating *)
Fixpoint cost_space_exp (e : exp) : nat :=
match e with
| Econstr x _ ys e => 1 + length ys + cost_space_exp e
| Ecase x l =>
(fix sizeOf_l l :=
match l with
| [] => 0
| (t, e) :: l => max (cost_space_exp e) (sizeOf_l l)
end) l
| Eproj x _ _ y e => cost_space_exp e
| Efun B e => max
(1 + PS.cardinal (fundefs_fv B) + (* env *)
3 * (numOf_fundefs B) + (* closures *)
cost_space_exp e)
(1 + PS.cardinal (fundefs_fv B) + cost_space_funs B)
| Eapp x _ ys => 0
| Eprim x _ ys e => cost_space_exp e
| Ehalt x => 0
end
with cost_space_funs (f : fundefs) : nat :=
match f with
| Fcons _ _ _ e B =>
max (cost_space_exp e) (cost_space_funs B)
| Fnil => 0
end.
Definition cost_value (c : fundefs -> nat) (v : value) : nat :=
match v with
| Loc _ => 0
| FunPtr B _ => c B
end.
Definition cost_block (c : fundefs -> nat) (b : block) : nat :=
match b with
| Constr _ vs => 0
| Clos v1 rho => cost_value c v1
| Env rho => 0
end.
(** The maximum cost of evaluating any function in the heap *)
Definition cost_heap (c : fundefs -> nat) (H : heap block) :=
max_with_measure (cost_block c) H.
Definition cost_env_app_exp_out (e : exp) : nat :=
match e with
| Econstr x _ ys e => 3 * length ys
| Ecase x l => 3
| Eproj x _ _ y e => 3
| Efun B e => 1 + 4 * PS.cardinal (fundefs_fv B)
| Eapp x _ ys => 3 + 3 * length ys
| Eprim x _ ys e => 3 * length ys
| Ehalt x => 3
end.
Definition cost_space_heap H1 := cost_heap (fun B => cost_space_funs B + (1 + PS.cardinal (fundefs_fv B))) H1.
(** * PostCondition *)
Definition Ktime := 7.
(** Enforces that the resource consumption of the target is within certain bounds *)
Definition Post
(k : nat) (* This varies locally in the proof *)
(A : nat) (* Size at entry *)
(δ : nat) (* local delta *)
(* (Funs : Ensemble var) *)
(* `{ToMSet Funs} *)
(p1 p2 : heap block * env * exp * nat * nat) :=
match p1, p2 with
| (H1, rho1, e1, c1, m1), (H2, rho2, e2, c2, m2) =>
(* time bound *)
c1 <= c2 + k <= Ktime * c1 /\
(* memory bound *)
m2 <= max (A + cost_space_exp e1 + δ) (m1 + max (cost_space_exp e1) (cost_space_heap H1))
end.
Definition Post_weak (* essentially, Post <--> Post_weak for our semantics *)
(k : nat) (* This varies locally in the proof *)
(A : nat) (* Size at entry *)
(δ : nat) (* local delta *)
(* (Funs : Ensemble var) *)
(* `{ToMSet Funs} *)
(p1 p2 : heap block * env * exp * nat * nat) :=
match p1, p2 with
| (H1, rho1, e1, c1, m1), (H2, rho2, e2, c2, m2) =>
(* time bound *)
(cost e1 <= c1 -> c1 <= c2 + k <= Ktime * c1) /\
(* memory bound *)
m2 <= max (A + cost_space_exp e1 + δ) (m1 + max (cost_space_exp e1) (cost_space_heap H1))
end.
Definition PostG
(size_heap size_env : nat)
(p1 p2 : heap block * env * exp * nat * nat) :=
match p1, p2 with
| (H1, rho1, e1, c1, m1), (H2, rho2, e2, c2, m2) =>
Post 0 size_heap size_env p1 p2
end.
(** * Precondition *)
(** Enforces that the initial heaps have related sizes *)
Definition Pre
(Funs : Ensemble var)
`{ToMSet Funs} A δ
(p1 p2 : heap block * env * exp) :=
let funs := 3 * PS.cardinal (@mset Funs _) in
match p1, p2 with
| (H1, rho1, e1), (H2, rho2, e2) =>
(* Sizes of the initial heaps *)
size_heap H2 + funs (* not yet projected funs *)
<= A + δ (* initial delta of heaps *)
end.
Definition PreG
(Funs : Ensemble var)
`{ToMSet Funs} (size_heap size_env : nat)
(p1 p2 : heap block * env * exp) :=
let funs := 3 * PS.cardinal (@mset Funs _) in
match p1, p2 with
| (H1, rho1, e1), (H2, rho2, e2) =>
Pre Funs size_heap size_env p1 p2
end.
Lemma cost_heap_block_get H1 c l b :
get l H1 = Some b ->
cost_block c b <= cost_heap c H1.
Proof.
eapply HL.max_with_measure_get.
Qed.
Lemma cost_heap_alloc H1 H1' c l b :
alloc b H1 = (l, H1') ->
cost_heap c H1' = max (cost_block c b) (cost_heap c H1).
Proof.
intros Hal. unfold cost_heap.
erewrite (HL.max_with_measure_alloc _ _ _ _ H1'); eauto.
rewrite Max.max_comm. eapply Nat.max_compat; omega.
Qed.
Lemma cost_space_heap_alloc H1 H1' l b :
alloc b H1 = (l, H1') ->
cost_space_heap H1' = max (cost_block (fun B => cost_space_funs B + (1 + PS.cardinal (fundefs_fv B))) b)
(cost_space_heap H1).
Proof.
intros. eapply cost_heap_alloc. eassumption.
Qed.
Lemma cost_heap_def_closures H1 H1' rho1 rho1' c B B0 rho :
def_closures B B0 rho1 H1 rho = (H1', rho1') ->
cost_heap c H1' = match B with
| Fnil => cost_heap c H1
| _ => max (c B0) (cost_heap c H1)
end.
Proof.
revert H1' rho1'. induction B; intros H1' rho1' Hclo.
- simpl in Hclo.
destruct (def_closures B B0 rho1 H1 rho) as [H2 rho2] eqn:Hclo'.
destruct (alloc (Clos (FunPtr B0 v) rho) H2) as [l' rho3] eqn:Hal. inv Hclo.
erewrite cost_heap_alloc; [| eassumption ].
simpl. destruct B.
+ erewrite (IHB H2); [| reflexivity ].
rewrite Max.max_assoc, Max.max_idempotent. reflexivity.
+ erewrite (IHB H2); reflexivity.
- inv Hclo; eauto.
Qed.
Lemma cost_space_heap_def_closures H1 H1' rho1 rho1' B B0 rho :
def_closures B B0 rho1 H1 rho = (H1', rho1') ->
cost_space_heap H1' = match B with
| Fnil => cost_space_heap H1
| _ => max (cost_space_funs B0 + (1 + PS.cardinal (fundefs_fv B0))) (cost_space_heap H1)
end.
Proof.
eapply cost_heap_def_closures.
Qed.
Lemma cost_space_heap_def_closures_cons H1 H1' rho1 rho1' B B0 rho :
B <> Fnil ->
def_closures B B0 rho1 H1 rho = (H1', rho1') ->
cost_space_heap H1' = max (cost_space_funs B0 + (1 + PS.cardinal (fundefs_fv B0))) (cost_space_heap H1).
Proof.
intros. erewrite cost_space_heap_def_closures; [| eassumption ].
destruct B. reflexivity.
congruence.
Qed.
Lemma cardinal_name_in_fundefs B :
unique_functions B ->
PS.cardinal (@mset (name_in_fundefs B) _) = numOf_fundefs B.
Proof.
intros Hun. induction B.
- inv Hun.
simpl.
rewrite Proper_carinal. Focus 2.
eapply Same_set_From_set.
rewrite <- (@mset_eq (v |: name_in_fundefs B)) at 1.
rewrite FromSet_union. eapply Same_set_Union_compat.
eapply ToMSet_Singleton.
eapply ToMSet_name_in_fundefs.
rewrite <- PS_cardinal_union. erewrite PS_cardinal_singleton.
now rewrite <- IHB; eauto.
rewrite <- mset_eq. reflexivity.
eapply FromSet_disjoint. rewrite <- !mset_eq...
eapply Disjoint_Singleton_l. eassumption.
- simpl.
rewrite PS.cardinal_spec. erewrite Same_set_FromList_length' with (l2 := []).
reflexivity. eapply NoDupA_NoDup. eapply PS.elements_spec2w.
now constructor.
rewrite <- FromSet_elements. rewrite <- mset_eq, FromList_nil. reflexivity.
Qed.
Lemma cost_env_app_exp_out_le_cost e :
cost_env_app_exp_out e <= 4 * (cost e).
Proof.
induction e; simpl; omega.
Qed.
Lemma fun_in_fundefs_cost_space_fundefs Funs {Hf : ToMSet Funs} B f tau xs e:
fun_in_fundefs B (f, tau, xs, e) ->
cost_space_exp e <= cost_space_funs B.
Proof.
induction B; intros Hin; inv Hin.
- simpl. inv H.
eapply Nat.le_max_l.
- eapply le_trans. eapply IHB. eassumption.
simpl. eapply Nat.le_max_r.
Qed.
(** * Compat lemmas *)
Lemma PostBase e1 e2 k
(Funs : Ensemble var) { _ : ToMSet Funs} A δ δ' :
k <= cost_env_app_exp_out e1 ->
δ' <= δ + cost_space_exp e1 ->
InvCostBase (Post k A δ) (Pre Funs A δ') e1 e2.
Proof.
unfold InvCostBase, Post, Pre.
intros Hleq Hleq' H1' H2' rho1' rho2' c Hs Hc.
unfold Ktime. split.
+ split. omega.
eapply plus_le_compat. omega.
eapply le_trans. eassumption.
eapply le_trans. eapply cost_env_app_exp_out_le_cost.
omega.
+ eapply le_trans. eapply le_plus_l.
eapply le_trans. eassumption.
eapply le_trans; [| now eapply Nat.le_max_l]. omega.
Qed.
Lemma PostBase_weak e1 e2 k
(Funs : Ensemble var) { _ : ToMSet Funs} A δ δ' :
k <= cost_env_app_exp_out e1 ->
δ' <= δ + cost_space_exp e1 ->
InvCostBase (Post_weak k A δ) (Pre Funs A δ') e1 e2.
Proof.
unfold InvCostBase, Post_weak, Pre.
intros Hleq Hleq' H1' H2' rho1' rho2' c Hs Hc.
unfold Ktime. split.
+ intros Hw. split. omega.
eapply plus_le_compat. omega.
eapply le_trans. eassumption.
eapply le_trans. eapply cost_env_app_exp_out_le_cost.
omega.
+ eapply le_trans. eapply le_plus_l.
eapply le_trans. eassumption.
eapply le_trans; [| now eapply Nat.le_max_l]. omega.
Qed.
Lemma PostTimeOut_weak e1 e2 k
(Funs : Ensemble var) { _ : ToMSet Funs} A δ δ' :
k <= cost_env_app_exp_out e1 ->
δ' <= δ + cost_space_exp e1 ->
InvCostTimeOut (Post_weak k A δ) (Pre Funs A δ') e1 e2.
Proof.
unfold InvCostBase, Post_weak, Pre.
intros Hleq Hleq' H1' H2' rho1' rho2' c Hs Hc.
unfold Ktime. split.
+ intros Hyp. omega.
+ eapply le_trans. eapply le_plus_l.
eapply le_trans. eassumption.
eapply le_trans; [| now eapply Nat.le_max_l]. omega.
Qed.
Lemma PostTimeOut e1 e2
(Funs : Ensemble var) { _ : ToMSet Funs} A δ δ' :
δ' <= δ + cost_space_exp e1 ->
InvCostTimeOut (Post 0 A δ) (Pre Funs A δ') e1 e2.
Proof.
unfold InvCostBase, Post, Pre.
intros Hleq H1' H2' rho1' rho2' c Hs Hc.
unfold Ktime. split.
+ omega.
+ eapply le_trans. eapply le_plus_l.
eapply le_trans. eassumption.
eapply le_trans; [| now eapply Nat.le_max_l]. omega.
Qed.
Lemma PostTimeOut' e1 e2 l
(Funs : Ensemble var) { _ : ToMSet Funs} A δ :
l <= 3 * PS.cardinal mset ->
InvCostTimeOut' (Post 0 A δ) (Pre Funs A δ) l e1 e2.
Proof.
unfold InvCostTimeOut', Post, Pre.
intros Hleq H1' H2' rho1' rho2' c m Hs Hc Hleq'.
unfold Ktime. split.
+ omega.
+ eapply le_trans. eassumption.
eapply le_trans. eapply plus_le_compat_l. eassumption.
eapply le_trans. eassumption.
eapply le_trans; [| now eapply Nat.le_max_l]. omega.
Qed.
Lemma PostTimeOut'_weak e1 e2 l k
(Funs : Ensemble var) { _ : ToMSet Funs} A δ :
l <= cost_space_exp e1 ->
k <= cost_env_app_exp_out e1 ->
InvCostTimeOut' (Post_weak k A δ) (Pre Funs A δ) l e1 e2.
Proof.
unfold InvCostTimeOut', Post_weak, Pre.
intros Hleq Hleq2 H1' H2' rho1' rho2' c m Hs Hc Hleq'.
unfold Ktime. split.
+ omega.
+ eapply le_trans. eassumption.
eapply le_trans. eapply plus_le_compat_l. eassumption.
eapply le_trans with (m := A + δ + cost_space_exp e1). omega.
eapply le_trans; [| now eapply Nat.le_max_l]. omega.
Qed.
Lemma PostBaseFuns e1 e2 k
(Funs : Ensemble var) { _ : ToMSet Funs} A δ δ' B1 B2:
S (PS.cardinal (fundefs_fv B1)) <= k <= cost_env_app_exp_out (Efun B1 e1) ->
δ' <= δ + cost_space_exp (Efun B1 e1) ->
InvCostTimeOut_Funs (Post_weak k A δ) (Pre Funs A δ') B1 e1 B2 e2.
Proof.
unfold InvCostTimeOut_Funs, Post_weak, Pre.
intros [Hleq1 Hleq2] Hleq' H1' H2' rho1' rho2' c Hs.
unfold Ktime. split.
+ intros Hyp. simpl in *. omega.
+ eapply le_trans. eapply le_plus_l.
eapply le_trans. eassumption.
eapply le_trans; [| now eapply Nat.le_max_l]. omega.
Qed.
Lemma PostAppCompat i j IP P Funs {Hf : ToMSet Funs}
b H1 H2 rho1 rho2 f1 t xs1 f2 xs2 f2' Γ k A δ :
Forall2 (fun y1 y2 => cc_approx_var_env i j IP P b H1 rho1 H2 rho2 y1 y2) (f1 :: xs1) (f2 :: xs2) ->
k <= (cost_env_app_exp_out (Eapp f1 t xs1)) ->
~ Γ \in FromList xs2 ->
~ f2' \in FromList xs2 ->
IInvAppCompat Util.clo_tag PostG
(Post k A δ) (Pre Funs A δ)
H1 H2 rho1 rho2 f1 t xs1 f2 xs2 f2' Γ.
Proof.
unfold IInvAppCompat, Pre, Post, PostG.
intros Hall Hk Hnin1 Hnin2 _ H1' H1'' H2' Hgc2 env_loc
rhoc1 rhoc2 rhoc3 rho1' rho2' rho2''
b1 b2 B1 f1' ct1 xs1' e1 l1 vs1 B
f3 c ct2 xs2' e2 l2 env_loc2 vs2 c1 c2 m1 m2 d3
Heq1 Hinj1 Heq2 Hinj2
[[Hc1 Hc2] Hm1] Hh1
Hgetf1 Hgetl1 Hgetecl Hfind1 Hgetxs1 Hclo Hset1
Hgetf2 Hgetxs2 Hset2 Hgetl2 Hfind2 Gc2.
assert (Hlen := Forall2_length _ _ _ Hall). inversion Hlen as [Hlen'].
{ rewrite <- !plus_n_O in *. split.
- split.
+ simpl. omega.
+ unfold Ktime in *. eapply le_trans.
rewrite <- !plus_assoc. eapply plus_le_compat_r. eassumption.
simpl in *. omega.
- eapply Max.max_lub.
+ simpl. eapply le_trans. eassumption.
eapply le_trans; [| eapply Max.le_max_r ].
eapply Max.max_lub.
* eapply le_trans. eapply plus_le_compat_r.
eapply plus_le_compat_r. eassumption.
rewrite <- plus_assoc. eapply plus_le_compat.
now eapply Max.le_max_r.
eapply le_trans; [| eapply HL.max_with_measure_get; now apply Hgetl1 ].
simpl. eapply plus_le_compat_r.
eapply fun_in_fundefs_cost_space_fundefs; eauto.
eapply find_def_correct. eassumption.
* eapply plus_le_compat.
now eapply Max.le_max_r.
eapply Max.max_lub.
eapply le_trans; [| eapply HL.max_with_measure_get; now apply Hgetl1 ].
simpl.
eapply le_trans. eapply fun_in_fundefs_cost_space_fundefs; eauto.
eapply find_def_correct. eassumption.
omega.
erewrite (cost_space_heap_def_closures_cons H1' H1''); [| | eassumption ].
eapply Max.max_lub.
eapply le_trans; [| eapply HL.max_with_measure_get; now apply Hgetl1 ].
reflexivity. reflexivity.
intros Hc; inv Hc. now inv Hfind1.
+ eapply le_trans. eapply le_trans; [| eapply Hh1 ]. omega.
eapply Max.le_max_l. }
Qed.
Lemma PostConstrCompat i j IP P k
b H1 H2 rho1 rho2 x c ys1 ys2 e1 e2 A δ :
k <= cost_env_app_exp_out (Econstr x c ys1 e1) ->
Forall2 (cc_approx_var_env i j IP P b H1 rho1 H2 rho2) ys1 ys2 ->
InvCtxCompat (Post_weak k A δ)
(Post 0 A (δ + (1 + length ys1)))
(Econstr_c x c ys1 Hole_c) (Econstr_c x c ys2 Hole_c) e1 e2.
Proof with (now eauto with Ensembles_DB).
unfold InvCtxCompat, Post.
intros Hleqk Hall H1' H2' H1'' H2'' rho1' rho2' rho1'' rho2'' c1 c2 c1' c2'
m1 m2 [[Hc1 Hc2] Hm] Hleq Hctx1 Hctx2.
assert (Hlen := Forall2_length _ _ _ Hall).
inv Hctx1. inv Hctx2. inv H13. inv H16.
rewrite !plus_O_n in *. simpl cost_ctx in *.
rewrite !Hlen in *.
split.
- intros Hleq1. split.
+ rewrite !(plus_comm _ (S (length _))). rewrite <- !plus_assoc.
assert (Hleq' : c1 <= c2) by omega.
simpl. omega.
+ simpl in *. omega.
- rewrite <- !plus_n_O in *. eapply le_trans. eassumption.
erewrite cost_space_heap_alloc; [| eassumption ].
eapply Nat.max_le_compat. simpl. omega.
simpl cost_block. eapply plus_le_compat.
now eapply Max.le_max_r.
rewrite Nat_as_OT.max_0_l.
eapply Nat.max_le_compat_r. simpl. omega.
Qed.
Lemma PreConstrCompat i j A δ IP P
(Funs Funs' : Ensemble var) {Hf : ToMSet Funs} {Hf' : ToMSet Funs'}
b H1 H2 rho1 rho2 x c ys1 ys2 e1 e2 :
Forall2 (fun y1 y2 => cc_approx_var_env i j IP P b H1 rho1 H2 rho2 y1 y2) ys1 ys2 ->
Funs' \subset Funs ->
IInvCtxCompat (Pre Funs A δ) (Pre Funs' A (δ + (1 + length ys1)))
(Econstr_c x c ys1 Hole_c) (Econstr_c x c ys2 Hole_c) e1 e2.
Proof with (now eauto with Ensembles_DB).
unfold IInvCtxCompat, Pre.
intros Hall Hsub H1' H2' H1'' H2'' rho1' rho2' rho1'' rho2'' c1' c2'
Hm Hctx1 Hctx2.
inv Hctx1. inv Hctx2. inv H13. inv H16.
unfold size_heap in *.
erewrite HL.size_with_measure_alloc; [| reflexivity | eassumption ].
unfold reach_size, size_reachable in *.
assert (Hsubleq : 3 * PS.cardinal (@mset Funs' _) <= 3 * PS.cardinal (@mset Funs _)).
{ eapply mult_le_compat_l. eapply PS_elements_subset. eassumption. }
rewrite <- plus_assoc. rewrite (plus_comm (size_val _)). rewrite plus_assoc.
eapply le_trans. eapply plus_le_compat_r.
eapply le_trans; [| now apply Hm]. omega. simpl.
eapply Forall2_length in Hall.
eapply (@getlist_length_eq value) in H11; try eassumption.
eapply (@getlist_length_eq value) in H14; try eassumption.
replace (@length var ys1) with (@length M.elt ys1) in *.
rewrite <- H14, Hall. rewrite !plus_assoc. reflexivity. reflexivity.
Qed.
Lemma PostProjCompat k x c y1 y2 e1 e2 n A δ :
k <= (cost_env_app_exp_out (Eproj x c n y1 e1)) ->
InvCtxCompat (Post_weak k A δ)
(Post 0 A δ)
(Eproj_c x c n y1 Hole_c) (Eproj_c x c n y2 Hole_c) e1 e2.
Proof with (now eauto with Ensembles_DB).
unfold InvCtxCompat, Post.
intros Hleqk H1' H2' H1'' H2'' rho1' rho2' rho1'' rho2'' c1 c2 c1' c2'
m1 m2 [[Hc1 Hc2] Hm] Hleq Hctx1 Hctx2.
inv Hctx1. inv Hctx2. inv H17. inv H13.
split; rewrite <- !plus_n_O in *.
- intros Hleq'; simpl in *; omega.
- eapply le_trans. eassumption.
eapply Nat.max_le_compat. simpl. omega.
simpl cost_block. eapply plus_le_compat.
now eapply Max.le_max_r.
eapply Nat.max_le_compat_r. simpl. omega.
Qed.
Lemma PreProjCompat x1 x2 c n y1 y2 e1 e2 A δ
(Funs : Ensemble var) {Hf : ToMSet Funs} (Funs' : Ensemble var) {Hf' : ToMSet Funs'} :
Funs' \subset Funs ->
IInvCtxCompat (Pre Funs A δ) (Pre Funs' A δ)
(Eproj_c x1 c n y1 Hole_c) (Eproj_c x2 c n y2 Hole_c) e1 e2.
Proof with (now eauto with Ensembles_DB).
unfold IInvCtxCompat, Pre.
intros Hsub H1' H2' H1'' H2'' rho1' rho2' rho1'' rho2'' c1' c2'
Hm1 Hctx1 Hctx2.
inv Hctx1. inv Hctx2. inv H13. inv H17.
eapply le_trans; [| now apply Hm1 ]. eapply plus_le_compat_l.
eapply mult_le_compat_l. eapply PS_elements_subset. eassumption.
Qed.
Lemma cost_space_exp_case_In x1 c1 e1 P1 :
List.In (c1, e1) P1 ->
cost_space_exp e1 <= cost_space_exp (Ecase x1 P1).
Proof.
induction P1; intros Hin.
- now inv Hin.
- inv Hin.
+ simpl. eapply Nat.le_max_l.
+ eapply le_trans. eapply IHP1. eassumption.
destruct a. simpl. eapply Max.le_max_r.
Qed.
Lemma PostCaseCompat k x1 x2 P1 P2 A δ :
k <= (cost_env_app_exp_out (Ecase x1 P1)) ->
InvCaseCompat (Post_weak k A δ)
(fun e1 e2 => Post 0 A δ) x1 x2 P1 P2.
Proof with (now eauto with Ensembles_DB).
unfold InvCaseCompat, Post.
intros Hleqk H1' H2' rho1' rho2' m1 m2
c1 c2 c e1 tc1 e2 tc2 Hin1 Hin2 Hleq1 [[Hc1 Hc2] Hm].
split; rewrite <- !plus_n_O in *.
- simpl in *; omega.
- eapply le_trans. eassumption.
eapply Nat.max_le_compat.
eapply plus_le_compat_r. eapply plus_le_compat_l.
eapply cost_space_exp_case_In. eassumption.
eapply plus_le_compat.
now eapply Max.le_max_r.
eapply Nat.max_le_compat_r.
eapply cost_space_exp_case_In. eassumption.
Qed.
Lemma PreCaseCompat A δ x1 x2 P1 P2
(Funs : Ensemble var) {Hf : ToMSet Funs} (Funs' : exp -> Ensemble var)
{HFe : forall e, ToMSet (Funs' e)} :
(forall c e, List.In (c, e) P1 -> Funs' e \subset Funs) ->
IInvCaseCompat (Pre Funs A δ) (fun e1 e2 => Pre (Funs' e1) A δ) x1 x2 P1 P2.
Proof with (now eauto with Ensembles_DB).
unfold IInvCtxCompat, Pre.
intros Hsub H1' rho1' H2' rho2 c1 c2 e1 e2 Hin1 Hin2 hleq.
eapply le_trans; [| eassumption ]. eapply plus_le_compat_l.
eapply mult_le_compat_l.
eapply PS_elements_subset. eapply Hsub. eassumption.
Qed.
Lemma PostFunsCompat B1 B2 e1 e2 k m A δ δ' :
1 + PS.cardinal (fundefs_fv B1) + m <= k ->
k <= cost_env_app_exp_out (Efun B1 e1) + m ->
δ' <= (1 + (PS.cardinal (@mset (occurs_free_fundefs B1) _)) + 3 * numOf_fundefs B1) + δ ->
InvCtxCompat (Post_weak k A δ)
(Post m A δ') (Efun1_c B1 Hole_c) (Efun1_c B2 Hole_c) e1 e2.
Proof with (now eauto with Ensembles_DB).
unfold InvCtxCompat, Post, Post_weak.
intros Hleq0 Hleq Hleq' H1' H2' H1'' H2'' rho1' rho2' rho1'' rho2'' c1 c2 c1' c2'
m1 m2 [[Hc1 Hc2] Hm] Hleq1 Hctx1 Hctx2.
inv Hctx1. inv Hctx2. inv H4. inv H9. inv H10.
rewrite !plus_O_n. simpl cost_ctx.
split.
- simpl in *. omega.
- eapply le_trans. eassumption.
simpl cost_space_exp; simpl reach_size.
eapply Nat.max_le_compat.
+ rewrite <- !plus_assoc.
eapply plus_le_compat_l.
eapply le_trans. eapply plus_le_compat_l. eassumption.
rewrite !plus_assoc. eapply plus_le_compat_r.
eapply le_trans; [| eapply Peano.le_n_S; eapply Max.le_max_l ].
assert (Heq : PS.cardinal (fundefs_fv B1) =
(PS.cardinal (@mset (occurs_free_fundefs B1) _))).
{ rewrite !PS.cardinal_spec. eapply Same_set_FromList_length'.
eapply NoDupA_NoDup. eapply PS.elements_spec2w.
eapply NoDupA_NoDup. eapply PS.elements_spec2w. rewrite <- !FromSet_elements.
rewrite <- !mset_eq at 1.
rewrite <- fundefs_fv_correct. reflexivity. }
rewrite Heq. omega.
+ eapply plus_le_compat.
now eapply Max.le_max_r.
erewrite (cost_space_heap_def_closures H' H1''); [| eassumption ].
erewrite (cost_space_heap_alloc H1' H'); [| eassumption ].
destruct B1.
* rewrite !Nat.max_assoc. eapply Nat.max_le_compat_r.
eapply Max.max_lub. eapply Max.max_lub.
eapply le_trans; [| eapply Peano.le_n_S; eapply Max.le_max_l ].
omega.
eapply le_trans; [| eapply Peano.le_n_S; eapply Max.le_max_r ].
omega.
simpl. omega.
* rewrite !Nat.max_assoc. eapply Nat.max_le_compat_r.
eapply Max.max_lub.
eapply le_trans; [| eapply Peano.le_n_S; eapply Max.le_max_l ].
omega.
simpl. omega.
Qed.
Lemma PreSubsetCompat (Funs : Ensemble var) {Hf : ToMSet Funs}
(Funs' : Ensemble var) {Hf' : ToMSet Funs'}
A d H1 rho1 e1 H2 rho2 e2 :
Pre Funs A d (H1, rho1, e1) (H2, rho2, e2) ->
Funs' \subset Funs ->
Pre Funs' A d (H1, rho1, e1) (H2, rho2, e2).
Proof.
unfold Pre. intros Hpre Hleq.
assert (Hsubleq : 3 * PS.cardinal (@mset Funs' _) <= 3 * PS.cardinal (@mset Funs _)).
{ eapply mult_le_compat_l. eapply PS_elements_subset. eassumption. }
omega.
Qed.
Lemma PreFunsCompat
(Scope : Ensemble var) {Hs : ToMSet Scope}
(* (Scope' : Ensemble var) {Hs' : ToMSet Scope'} *)
(Funs : Ensemble var) {Hf : ToMSet Funs}
(* (Funs' : Ensemble var) {Hf' : ToMSet Funs'} *)
(S : Ensemble var) {Hst : ToMSet S}
(S' : Ensemble var) {Hst' : ToMSet S'}
B1 B2 e1 e2 A δ:
Funs :&: S' \subset Funs :&: S ->
Disjoint _ (name_in_fundefs B1) (Scope :|: Funs) ->
unique_functions B1 ->
IInvCtxCompat_Funs (Pre (Funs :&: S \\ Scope) A δ)
(Pre ((name_in_fundefs B1 :|: Funs) :&: S' \\ (Scope \\ name_in_fundefs B1)) A
(δ + 3 * numOf_fundefs B1)) B1 B2 e1 e2.
Proof with (now eauto with Ensembles_DB).
unfold IInvCtxCompat.
intros Hsub Hdis Hun H1' H2' H1'' H2'' rho1' rho2' rho1'' rho2'' c1' c2'
Hm Hbin Hctx1 Hctx2.
eapply PreSubsetCompat with (Funs := name_in_fundefs B1 :|: (Funs :&: S \\ Scope)); eauto with Ensembles_DB.
inv Hctx1. inv Hctx2. inv H9. inv H10.
unfold Pre in *.
rewrite Proper_carinal. Focus 2.
eapply Same_set_From_set.
rewrite <- (@mset_eq (name_in_fundefs B1 :|: (Funs :&: S \\ Scope))) at 1.
rewrite FromSet_union. eapply Same_set_Union_compat.
eapply ToMSet_name_in_fundefs.
rewrite <- (@mset_eq (Funs :&: S \\ Scope)) at 1.
reflexivity. tci.
rewrite <- PS_cardinal_union, Nat_as_OT.mul_add_distr_l.
rewrite (plus_comm (3 * _)), plus_assoc. eapply le_trans.
eapply plus_le_compat_r. eassumption.
assert (Heq' : 3 * PS.cardinal (@mset (name_in_fundefs B1) (ToMSet_name_in_fundefs B1)) =
3 * numOf_fundefs B1).
{ f_equal. eapply cardinal_name_in_fundefs. eassumption. }
omega.
eapply FromSet_disjoint. rewrite <- !mset_eq.
eapply Disjoint_Included_r; [| eassumption ].
eapply Included_trans. eapply Setminus_Included.
eapply Included_trans. eapply Ensembles_util.Included_Intersection_l.
now eauto with Ensembles_DB.
eapply Included_trans.
eapply Included_Setminus_compat.
rewrite Intersection_Union_distr. eapply Included_Union_compat.
eapply Included_Intersection_l. reflexivity.
reflexivity.
rewrite Setminus_Union_distr...
Qed.
Lemma project_var_ToMSet Scope1 Scope2 `{ToMSet Scope1} Funs1 Funs2
fenv c Γ FVs y C1 :
project_var Util.clo_tag Scope1 Funs1 fenv c Γ FVs y C1 Scope2 Funs2 ->
ToMSet Scope2.
Proof.
intros Hvar.
assert (Hd1 := H). eapply Decidable_ToMSet in Hd1.
destruct Hd1 as [Hdec1].
destruct (Hdec1 y).
- assert (Scope1 <--> Scope2).
{ inv Hvar; eauto; try reflexivity.
now exfalso; eauto. now exfalso; eauto. }
eapply ToMSet_Same_set; eassumption.
- assert (y |: Scope1 <--> Scope2).
{ inv Hvar; try reflexivity.
exfalso; eauto. }
eapply ToMSet_Same_set; try eassumption.
eauto with typeclass_instances.
Qed.
Lemma project_var_ToMSet_Funs Scope1 `{ToMSet Scope1} Scope2 Funs1 Funs2 `{ToMSet Funs1}
fenv c Γ FVs y C1 :
project_var Util.clo_tag Scope1 Funs1 fenv c Γ FVs y C1 Scope2 Funs2 ->
ToMSet Funs2.
Proof.
intros Hvar.
assert (Hd1 := H). eapply Decidable_ToMSet in Hd1.
destruct Hd1 as [Hdec1].
destruct (Hdec1 y).
- assert (Funs1 <--> Funs2).
{ inv Hvar; eauto; try reflexivity.
now exfalso; eauto. }
tci.
- destruct (@Dec _ Funs1 _ y).
+ assert (Funs1 \\ [set y] <--> Funs2).
{ inv Hvar; try reflexivity.
exfalso; eauto. exfalso; eauto. }
eapply ToMSet_Same_set; try eassumption.
tci.
+ assert (Funs1 <--> Funs2).
{ inv Hvar; try reflexivity.
exfalso; eauto. }
eapply ToMSet_Same_set; try eassumption.
Qed.
Lemma project_var_cost_alloc_eq Scope Scope'
Funs `{ToMSet Funs}
Funs' `{ToMSet Funs'}
fenv c Γ FVs x C1 :
project_var Util.clo_tag Scope Funs fenv c Γ FVs x C1 Scope' Funs' ->
cost_alloc_ctx_CC C1 = 3 * PS.cardinal (@mset (Funs \\ Funs') _).
Proof.
intros Hvar; inv Hvar; eauto.
- rewrite (Proper_carinal _ PS.empty).
reflexivity.
eapply Same_set_From_set.
rewrite <- mset_eq, Setminus_Same_set_Empty_set.
rewrite FromSet_empty. reflexivity.
- simpl cost_ctx_full. erewrite PS_cardinal_singleton.
reflexivity.
rewrite <- mset_eq.
split. eapply Included_trans.
eapply Setminus_Setminus_Included. tci.
rewrite Setminus_Same_set_Empty_set, Union_Empty_set_neut_l...
reflexivity...
eapply Singleton_Included. constructor; eauto.
intros Hc. inv Hc. eauto.
- rewrite PS_cardinal_empty_l. reflexivity.
rewrite <- mset_eq. rewrite Setminus_Same_set_Empty_set. reflexivity.
Qed.
Lemma project_vars_cost_alloc_eq Scope `{ToMSet Scope} Scope'
Funs `{ToMSet Funs}
Funs' `{ToMSet Funs'}
fenv c Γ FVs xs C1 :
project_vars Util.clo_tag Scope Funs fenv c Γ FVs xs C1 Scope' Funs' ->
cost_alloc_ctx_CC C1 = 3 * PS.cardinal (@mset (Funs \\ Funs') _).
Proof with (now eauto with Ensembles_DB).
intros Hvar; induction Hvar; eauto.
- rewrite PS_cardinal_empty_l. reflexivity.
rewrite <- mset_eq, Setminus_Same_set_Empty_set.
reflexivity.
- assert (Hvar' := H2); assert (Hvar'' := H2).
eapply (project_var_ToMSet_Funs Scope1 Scope2 Funs1 Funs2) in Hvar''; eauto.
rewrite cost_alloc_ctx_CC_comp_ctx_f.
eapply (@project_var_cost_alloc_eq Scope1 Scope2 Funs1 _ Funs2 _) in H2.
rewrite H2. erewrite IHHvar; eauto.
rewrite <- Nat.mul_add_distr_l.
eapply Nat_as_OT.mul_cancel_l. omega.
rewrite PS_cardinal_union.
eapply Proper_carinal.
eapply Same_set_From_set. setoid_rewrite <- mset_eq.
rewrite FromSet_union.
do 2 setoid_rewrite <- mset_eq at 1.
rewrite Union_commut. erewrite Setminus_compose; tci.
reflexivity. eapply project_vars_Funs_l. eassumption.
eapply project_var_Funs_l. eassumption.
eapply FromSet_disjoint.
do 2 setoid_rewrite <- mset_eq at 1.
eapply Disjoint_Setminus_l... tci.
eapply project_var_ToMSet in Hvar'; tci.
Qed.
Lemma project_var_cost_eq'
Scope Scope' Funs Funs' fenv
c Γ FVs x C1 :
project_var Util.clo_tag Scope Funs fenv c Γ FVs x C1 Scope' Funs' ->
cost_ctx_full_cc C1 <= 3.
Proof with (now eauto with Ensembles_DB).
intros Hvar; inv Hvar; eauto.
Qed.
Lemma project_vars_cost_eq'
Scope Scope' Funs Funs' fenv
c Γ FVs xs C1 :
project_vars Util.clo_tag Scope Funs fenv c Γ FVs xs C1 Scope' Funs' ->
cost_ctx_full_cc C1 <= 3 * length xs.
Proof with (now eauto with Ensembles_DB).
intros Hvar; induction Hvar; eauto.
rewrite cost_ctx_full_cc_ctx_comp_ctx_f. simpl.
eapply le_trans. eapply plus_le_compat.
eapply project_var_cost_eq'. eassumption. eassumption.
omega.
Qed.
Lemma project_var_cost_eq
Scope {_ : ToMSet Scope} Scope' {_ : ToMSet Scope'} Funs `{ToMSet Funs}
Funs' `{ToMSet Funs'} fenv
c Γ FVs x C1 :
project_var Util.clo_tag Scope Funs fenv c Γ FVs x C1 Scope' Funs' ->
cost_ctx_full C1 = 3 * PS.cardinal (@mset (Funs \\ Funs') _) +
PS.cardinal (@mset ((FromList FVs \\ Funs) :&: (Scope' \\ Scope)) _).
Proof with (now eauto with Ensembles_DB).
intros Hvar; inv Hvar; eauto.
- rewrite !PS_cardinal_empty_l.
reflexivity.
rewrite <- mset_eq, Setminus_Same_set_Empty_set, Intersection_Empty_set_abs_r.
reflexivity.
rewrite <- mset_eq, Setminus_Same_set_Empty_set.
reflexivity.
- simpl cost_ctx_full.
erewrite PS_cardinal_singleton.
erewrite PS_cardinal_empty_l. omega.
rewrite <- mset_eq.
rewrite Setminus_Union_distr, (Setminus_Disjoint [set x]).
rewrite Setminus_Same_set_Empty_set, Union_Empty_set_neut_r.
rewrite Intersection_Disjoint.
reflexivity.
eapply Disjoint_Singleton_r. intros Hc; inv Hc; eauto.
eapply Disjoint_Singleton_l. eassumption.
rewrite <- mset_eq.
split. eapply Included_trans. eapply Setminus_Setminus_Included; tci...
now eauto with Ensembles_DB.
eapply Singleton_Included. constructor; eauto.
intros Hc. inv Hc; eauto.
- rewrite PS_cardinal_empty_l.
erewrite PS_cardinal_singleton.
simpl. reflexivity.
+ rewrite <- mset_eq.
rewrite Setminus_Union_distr, (Setminus_Disjoint [set x]).
rewrite Setminus_Same_set_Empty_set, Union_Empty_set_neut_r.
rewrite Intersection_commut, Intersection_Same_set.
reflexivity.
eapply Singleton_Included.
constructor. eapply nthN_In. eassumption.
eassumption.
eapply Disjoint_Singleton_l. eassumption.
+ rewrite <- mset_eq.
rewrite Setminus_Same_set_Empty_set. reflexivity.
Qed.
Lemma project_vars_cost_eq
Scope `{ToMSet Scope} Scope' `{ToMSet Scope'} Funs `{ToMSet Funs}
Funs' `{ToMSet Funs'}
fenv c Γ FVs xs C1 :
project_vars Util.clo_tag Scope Funs fenv c Γ FVs xs C1 Scope' Funs' ->
cost_ctx_full C1 = 3 * PS.cardinal (@mset (Funs \\ Funs') _) +
PS.cardinal (@mset ((FromList FVs \\ Funs) :&: (Scope' \\ Scope)) _).
Proof with (now eauto with Ensembles_DB).
intros Hvar; induction Hvar; eauto.
- rewrite !PS_cardinal_empty_l.
reflexivity.
rewrite <- mset_eq, Setminus_Same_set_Empty_set, Intersection_Empty_set_abs_r.
reflexivity.
rewrite <- mset_eq, Setminus_Same_set_Empty_set.
reflexivity.
- assert (Hvar' := H3). assert (Hvar'' := H3).
assert (Hvar''' := H3).
eapply project_var_ToMSet_Funs in Hvar''; eauto.
eapply project_var_ToMSet in Hvar'; eauto.
rewrite cost_ctx_full_ctx_comp_ctx_f.
eapply (@project_var_cost_eq Scope1 H Scope2 Hvar' Funs1 _ Funs2) in H3.
rewrite H3. erewrite IHHvar; eauto.
rewrite <- !plus_assoc, (plus_assoc _ (3 * _)), (plus_comm _ (3 * _)).
rewrite !plus_assoc.
rewrite <- Nat.mul_add_distr_l.
rewrite <- plus_assoc. eapply f_equal2_plus.
+ eapply Nat_as_OT.mul_cancel_l. omega.
rewrite PS_cardinal_union.
eapply Proper_carinal.
eapply Same_set_From_set. setoid_rewrite <- mset_eq.
rewrite FromSet_union.
do 2 setoid_rewrite <- mset_eq at 1.
rewrite Union_commut, Setminus_compose. now eauto with typeclass_instances.
tci. eapply project_vars_Funs_l. eassumption.
eapply project_var_Funs_l. eassumption.
eapply FromSet_disjoint.
do 2 setoid_rewrite <- mset_eq at 1.
eapply Disjoint_Setminus_l...
+ rewrite PS_cardinal_union.
eapply Proper_carinal.
eapply Same_set_From_set. setoid_rewrite <- mset_eq.
rewrite FromSet_union.
do 2 setoid_rewrite <- mset_eq at 1.
rewrite !(Intersection_commut _ (FromList FVs \\ _)).
assert (Hvar1 := Hvar'''). eapply project_var_Scope_Funs_eq in Hvar'''.
rewrite Hvar'''.
assert (Hseq : (Scope3 \\ Scope2) :&: (FromList FVs \\ (Funs1 \\ (Scope2 \\ Scope1))) <-->
(Scope3 \\ Scope2) :&: (FromList FVs \\ Funs1)).
{ rewrite Intersection_commut. rewrite Intersection_Setmius_Setminus_Disjoint.
rewrite Intersection_commut. reflexivity.
now eauto with Ensembles_DB. }
rewrite Hseq.
rewrite <- Intersection_Union_distr.
eapply Same_set_Intersection_compat; [| reflexivity ].
eapply Setminus_compose. now eauto with typeclass_instances.
eapply project_var_Scope_l. eassumption.
eapply project_vars_Scope_l. eassumption.
eapply FromSet_disjoint.
do 2 setoid_rewrite <- mset_eq at 1.
eapply Disjoint_Included_l. eapply Included_Intersection_compat.
eapply Included_Setminus_compat. reflexivity. eapply project_var_Funs_l. eassumption.
reflexivity. eapply Disjoint_Intersection_r.
eapply Disjoint_Setminus_r...
Grab Existential Variables. tci.
Qed.
Lemma project_var_Scope_Funs_subset Scope Scope' Funs Funs'
fenv c Γ FVs xs C1 :
project_var Util.clo_tag Scope Funs fenv c Γ FVs xs C1 Scope' Funs' ->
Funs \\ Funs' \subset Scope' \\ Scope.
Proof.
intros Hvar. inv Hvar.
now eauto with Ensembles_DB.
rewrite Setminus_Union_distr.
eapply Included_Union_preserv_l.
rewrite (Setminus_Disjoint [set xs]).
eapply Setminus_Included_Included_Union.
rewrite Union_Setminus_Included.
now eauto with Ensembles_DB. tci. reflexivity.
eapply Disjoint_Singleton_l. eassumption.
now eauto with Ensembles_DB.
Qed.
Lemma project_vars_Scope_Funs_subset
Scope Scope' {_ : ToMSet Scope}
Funs {_ : ToMSet Funs} Funs'
fenv c Γ FVs xs C1 :
project_vars Util.clo_tag Scope Funs fenv c Γ FVs xs C1 Scope' Funs' ->
Funs \\ Funs' \subset Scope' \\ Scope.
Proof.
intros Hvar. induction Hvar.
now eauto with Ensembles_DB.
rewrite <- Setminus_compose; [| | eapply project_vars_Funs_l; eassumption
| eapply project_var_Funs_l; eassumption ]; tci.
rewrite <- Setminus_compose with (s3 := Scope3);
[| | eapply project_var_Scope_l; eassumption
| eapply project_vars_Scope_l; eassumption ]; tci.