-
Notifications
You must be signed in to change notification settings - Fork 0
/
binders-disjoint-symmetric.agda
2083 lines (1966 loc) · 83.7 KB
/
binders-disjoint-symmetric.agda
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
open import List
open import Nat
open import Prelude
open import binders-disjointness
open import contexts
open import core
open import freshness
open import lemmas-contexts
open import patterns-core
module binders-disjoint-symmetric where
-- these lemmas build up to proving that the various
-- disjointness judgements are symmetric.
--
-- more specifically, the definitions of the disjointness
-- judgements deconstruct on the first argument, while
-- leaving the second argument generic. these lemmas
-- show that you can instead deconstruct on the second
-- arugment. all of these results are entirely mechanical,
-- but horribly tedious.
mutual
lem-bd-lam : {e : ihexp} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
binders-disjoint e (·λ x ·[ τ1 ] e1) →
unbound-in-e x e ×
binders-disjoint e e1
lem-bd-lam BDUnit = UBUnit , BDUnit
lem-bd-lam BDNum = UBNum , BDNum
lem-bd-lam BDVar = UBVar , BDVar
lem-bd-lam (BDLam (UBLam x≠y ub) bd)
with lem-bd-lam bd
... | ub' , bd' =
UBLam (flip x≠y) ub' , BDLam ub bd'
lem-bd-lam (BDAp bd1 bd2)
with lem-bd-lam bd1 | lem-bd-lam bd2
... | ub1 , bd1' | ub2 , bd2' =
UBAp ub1 ub2 , BDAp bd1' bd2'
lem-bd-lam (BDInl bd)
with lem-bd-lam bd
... | ub , bd' = UBInl ub , BDInl bd'
lem-bd-lam (BDInr bd)
with lem-bd-lam bd
... | ub , bd' = UBInr ub , BDInr bd'
lem-bd-lam (BDMatch bd (BDZRules bdpre bdpost))
with lem-bd-lam bd |
lem-bd-rs-lam bdpre |
lem-bd-rs-lam bdpost
... | ub , bd'
| ubpre , bdpre'
| ubpost , bdpost' =
UBMatch ub (UBZRules ubpre ubpost) ,
BDMatch bd' (BDZRules bdpre' bdpost')
lem-bd-lam (BDPair bd1 bd2)
with lem-bd-lam bd1 | lem-bd-lam bd2
... | ub1 , bd1' | ub2 , bd2' =
UBPair ub1 ub2 , BDPair bd1' bd2'
lem-bd-lam (BDFst bd)
with lem-bd-lam bd
... | ub , bd' = UBFst ub , BDFst bd'
lem-bd-lam (BDSnd bd)
with lem-bd-lam bd
... | ub , bd' = UBSnd ub , BDSnd bd'
lem-bd-lam (BDEHole bdσ)
with lem-bd-σ-lam bdσ
... | ubσ , bdσ' = UBEHole ubσ , BDEHole bdσ'
lem-bd-lam (BDHole bdσ bd)
with lem-bd-σ-lam bdσ | lem-bd-lam bd
... | ubσ , bdσ' | ub , bd' =
UBHole ubσ ub , BDHole bdσ' bd'
lem-bd-σ-lam : {σ : subst-env} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
binders-disjoint-σ σ (·λ x ·[ τ1 ] e1) →
unbound-in-σ x σ ×
binders-disjoint-σ σ e1
lem-bd-σ-lam BDσId = UBσId , BDσId
lem-bd-σ-lam (BDσSubst bd (UBLam y≠x ub) bdσ)
with lem-bd-lam bd | lem-bd-σ-lam bdσ
... | ub' , bd' | ubσ , bdσ' =
UBσSubst ub' (flip y≠x) ubσ , BDσSubst bd' ub bdσ'
lem-bd-rs-lam : {rs : rules} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
binders-disjoint-rs rs (·λ x ·[ τ1 ] e1) →
unbound-in-rs x rs ×
binders-disjoint-rs rs e1
lem-bd-rs-lam BDNoRules = UBNoRules , BDNoRules
lem-bd-rs-lam (BDRules bdr bdrs)
with lem-bd-r-lam bdr | lem-bd-rs-lam bdrs
... | ubr , bdr' | ubrs , bdrs' =
UBRules ubr ubrs , BDRules bdr' bdrs'
lem-bd-r-lam : {r : rule} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
binders-disjoint-r r (·λ x ·[ τ1 ] e1) →
unbound-in-r x r ×
binders-disjoint-r r e1
lem-bd-r-lam (BDRule bdp bd)
with lem-bd-p-lam bdp | lem-bd-lam bd
... | ubp , bdp' | ub , bd' =
UBRule ubp ub , BDRule bdp' bd'
lem-bd-p-lam : {p : pattrn} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
binders-disjoint-p p (·λ x ·[ τ1 ] e1) →
unbound-in-p x p ×
binders-disjoint-p p e1
lem-bd-p-lam BDPUnit = UBPUnit , BDPUnit
lem-bd-p-lam BDPNum = UBPNum , BDPNum
lem-bd-p-lam (BDPVar (UBLam x≠y ub)) =
UBPVar (flip x≠y) , BDPVar ub
lem-bd-p-lam (BDPInl bd)
with lem-bd-p-lam bd
... | ub , bd' = UBPInl ub , BDPInl bd'
lem-bd-p-lam (BDPInr bd)
with lem-bd-p-lam bd
... | ub , bd' = UBPInr ub , BDPInr bd'
lem-bd-p-lam (BDPPair bd1 bd2)
with lem-bd-p-lam bd1 | lem-bd-p-lam bd2
... | ub1 , bd1' | ub2 , bd2' =
UBPPair ub1 ub2 , BDPPair bd1' bd2'
lem-bd-p-lam BDPWild = UBPWild , BDPWild
lem-bd-p-lam BDPEHole = UBPEHole , BDPEHole
lem-bd-p-lam (BDPHole bd)
with lem-bd-p-lam bd
... | ub , bd' = UBPHole ub , BDPHole bd'
mutual
lem-bd-ap : {e : ihexp} {e1 e2 : ihexp} →
binders-disjoint e (e1 ∘ e2) →
binders-disjoint e e1 ×
binders-disjoint e e2
lem-bd-ap BDUnit = BDUnit , BDUnit
lem-bd-ap BDNum = BDNum , BDNum
lem-bd-ap BDVar = BDVar , BDVar
lem-bd-ap (BDLam (UBAp ub1 ub2) bd)
with lem-bd-ap bd
... | bd1 , bd2 = BDLam ub1 bd1 , BDLam ub2 bd2
lem-bd-ap (BDAp bd1 bd2)
with lem-bd-ap bd1 | lem-bd-ap bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
BDAp bd1₁ bd2₁ , BDAp bd1₂ bd2₂
lem-bd-ap (BDInl bd)
with lem-bd-ap bd
... | bd1 , bd2 = BDInl bd1 , BDInl bd2
lem-bd-ap (BDInr bd)
with lem-bd-ap bd
... | bd1 , bd2 = BDInr bd1 , BDInr bd2
lem-bd-ap (BDMatch bd (BDZRules pret postt))
with lem-bd-ap bd |
lem-bd-rs-ap pret |
lem-bd-rs-ap postt
... | bd1 , bd2
| bdpre1 , bdpre2
| bdpost1 , bdpost2 =
BDMatch bd1 (BDZRules bdpre1 bdpost1) ,
BDMatch bd2 (BDZRules bdpre2 bdpost2)
lem-bd-ap (BDPair bd1 bd2)
with lem-bd-ap bd1 | lem-bd-ap bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
BDPair bd1₁ bd2₁ , BDPair bd1₂ bd2₂
lem-bd-ap (BDFst bd)
with lem-bd-ap bd
... | bd1 , bd2 = BDFst bd1 , BDFst bd2
lem-bd-ap (BDSnd bd)
with lem-bd-ap bd
... | bd1 , bd2 = BDSnd bd1 , BDSnd bd2
lem-bd-ap (BDEHole bdσ)
with lem-bd-σ-ap bdσ
... | bdσ1 , bdσ2 =
BDEHole bdσ1 , BDEHole bdσ2
lem-bd-ap (BDHole bdσ bd)
with lem-bd-σ-ap bdσ | lem-bd-ap bd
... | bdσ1 , bdσ2 | bd1 , bd2 =
BDHole bdσ1 bd1 , BDHole bdσ2 bd2
lem-bd-σ-ap : {σ : subst-env} {e1 e2 : ihexp} →
binders-disjoint-σ σ (e1 ∘ e2) →
binders-disjoint-σ σ e1 ×
binders-disjoint-σ σ e2
lem-bd-σ-ap BDσId = BDσId , BDσId
lem-bd-σ-ap (BDσSubst bd (UBAp ub1 ub2) bdσ)
with lem-bd-ap bd | lem-bd-σ-ap bdσ
... | bd1 , bd2 | bdσ1 , bdσ2 =
BDσSubst bd1 ub1 bdσ1 , BDσSubst bd2 ub2 bdσ2
lem-bd-rs-ap : {rs : rules} {e1 e2 : ihexp} →
binders-disjoint-rs rs (e1 ∘ e2) →
binders-disjoint-rs rs e1 ×
binders-disjoint-rs rs e2
lem-bd-rs-ap BDNoRules = BDNoRules , BDNoRules
lem-bd-rs-ap (BDRules bdr bdrs)
with lem-bd-r-ap bdr | lem-bd-rs-ap bdrs
... | bdr1 , bdr2 | bd1 , bd2 =
BDRules bdr1 bd1 , BDRules bdr2 bd2
lem-bd-r-ap : {r : rule} {e1 e2 : ihexp} →
binders-disjoint-r r (e1 ∘ e2) →
binders-disjoint-r r e1 ×
binders-disjoint-r r e2
lem-bd-r-ap (BDRule pt bd)
with lem-bd-p-ap pt | lem-bd-ap bd
... | pt1 , pt2 | bd1 , bd2 =
BDRule pt1 bd1 , BDRule pt2 bd2
lem-bd-p-ap : {p : pattrn} {e1 e2 : ihexp} →
binders-disjoint-p p (e1 ∘ e2) →
binders-disjoint-p p e1 ×
binders-disjoint-p p e2
lem-bd-p-ap BDPUnit = BDPUnit , BDPUnit
lem-bd-p-ap BDPNum = BDPNum , BDPNum
lem-bd-p-ap (BDPVar (UBAp ub1 ub2)) =
BDPVar ub1 , BDPVar ub2
lem-bd-p-ap (BDPInl bd)
with lem-bd-p-ap bd
... | bd1 , bd2 = BDPInl bd1 , BDPInl bd2
lem-bd-p-ap (BDPInr bd)
with lem-bd-p-ap bd
... | bd1 , bd2 = BDPInr bd1 , BDPInr bd2
lem-bd-p-ap (BDPPair bd1 bd2)
with lem-bd-p-ap bd1 | lem-bd-p-ap bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
BDPPair bd1₁ bd2₁ , BDPPair bd1₂ bd2₂
lem-bd-p-ap BDPWild = BDPWild , BDPWild
lem-bd-p-ap BDPEHole = BDPEHole , BDPEHole
lem-bd-p-ap (BDPHole bd)
with lem-bd-p-ap bd
... | bd1 , bd2 = BDPHole bd1 , BDPHole bd2
mutual
lem-bd-inl : {e : ihexp} {τ : htyp} {e1 : ihexp} →
binders-disjoint e (inl τ e1) →
binders-disjoint e e1
lem-bd-inl BDUnit = BDUnit
lem-bd-inl BDNum = BDNum
lem-bd-inl BDVar = BDVar
lem-bd-inl (BDLam (UBInl ub) bd) =
BDLam ub (lem-bd-inl bd)
lem-bd-inl (BDAp bd1 bd2) =
BDAp (lem-bd-inl bd1) (lem-bd-inl bd2)
lem-bd-inl (BDInl bd) = BDInl (lem-bd-inl bd)
lem-bd-inl (BDInr bd) = BDInr (lem-bd-inl bd)
lem-bd-inl (BDMatch bd (BDZRules bdpre bdpost)) =
BDMatch (lem-bd-inl bd)
(BDZRules (lem-bd-rs-inl bdpre)
(lem-bd-rs-inl bdpost))
lem-bd-inl (BDPair bd1 bd2) =
BDPair (lem-bd-inl bd1) (lem-bd-inl bd2)
lem-bd-inl (BDFst bd) = BDFst (lem-bd-inl bd)
lem-bd-inl (BDSnd bd) = BDSnd (lem-bd-inl bd)
lem-bd-inl (BDEHole bdσ) = BDEHole (lem-bd-σ-inl bdσ)
lem-bd-inl (BDHole bdσ bd) =
BDHole (lem-bd-σ-inl bdσ)
(lem-bd-inl bd)
lem-bd-σ-inl : {σ : subst-env} {τ : htyp} {e1 : ihexp} →
binders-disjoint-σ σ (inl τ e1) →
binders-disjoint-σ σ e1
lem-bd-σ-inl BDσId = BDσId
lem-bd-σ-inl (BDσSubst bd (UBInl ub) bdσ) =
BDσSubst (lem-bd-inl bd) ub (lem-bd-σ-inl bdσ)
lem-bd-rs-inl : {rs : rules} {τ : htyp} {e1 : ihexp} →
binders-disjoint-rs rs (inl τ e1) →
binders-disjoint-rs rs e1
lem-bd-rs-inl BDNoRules = BDNoRules
lem-bd-rs-inl (BDRules bdr bdrs) =
BDRules (lem-bd-r-inl bdr) (lem-bd-rs-inl bdrs)
lem-bd-r-inl : {r : rule} {τ : htyp} {e1 : ihexp} →
binders-disjoint-r r (inl τ e1) →
binders-disjoint-r r e1
lem-bd-r-inl (BDRule bdp bd) =
BDRule (lem-bd-p-inl bdp) (lem-bd-inl bd)
lem-bd-p-inl : {p : pattrn} {τ : htyp} {e1 : ihexp} →
binders-disjoint-p p (inl τ e1) →
binders-disjoint-p p e1
lem-bd-p-inl BDPUnit = BDPUnit
lem-bd-p-inl BDPNum = BDPNum
lem-bd-p-inl (BDPVar (UBInl ub)) = BDPVar ub
lem-bd-p-inl (BDPInl bd) = BDPInl (lem-bd-p-inl bd)
lem-bd-p-inl (BDPInr bd) = BDPInr (lem-bd-p-inl bd)
lem-bd-p-inl (BDPPair bd1 bd2) =
BDPPair (lem-bd-p-inl bd1) (lem-bd-p-inl bd2)
lem-bd-p-inl BDPWild = BDPWild
lem-bd-p-inl BDPEHole = BDPEHole
lem-bd-p-inl (BDPHole bd) =
BDPHole (lem-bd-p-inl bd)
mutual
lem-bd-inr : {e : ihexp} {τ : htyp} {e1 : ihexp} →
binders-disjoint e (inr τ e1) →
binders-disjoint e e1
lem-bd-inr BDUnit = BDUnit
lem-bd-inr BDNum = BDNum
lem-bd-inr BDVar = BDVar
lem-bd-inr (BDLam (UBInr ub) bd) =
BDLam ub (lem-bd-inr bd)
lem-bd-inr (BDAp bd1 bd2) =
BDAp (lem-bd-inr bd1) (lem-bd-inr bd2)
lem-bd-inr (BDInl bd) = BDInl (lem-bd-inr bd)
lem-bd-inr (BDInr bd) = BDInr (lem-bd-inr bd)
lem-bd-inr (BDMatch bd (BDZRules bdpre bdpost)) =
BDMatch (lem-bd-inr bd)
(BDZRules (lem-bd-rs-inr bdpre)
(lem-bd-rs-inr bdpost))
lem-bd-inr (BDPair bd1 bd2) =
BDPair (lem-bd-inr bd1) (lem-bd-inr bd2)
lem-bd-inr (BDFst bd) = BDFst (lem-bd-inr bd)
lem-bd-inr (BDSnd bd) = BDSnd (lem-bd-inr bd)
lem-bd-inr (BDEHole bdσ) =
BDEHole (lem-bd-σ-inr bdσ)
lem-bd-inr (BDHole bdσ bd) =
BDHole (lem-bd-σ-inr bdσ) (lem-bd-inr bd)
lem-bd-σ-inr : {σ : subst-env} {τ : htyp} {e1 : ihexp} →
binders-disjoint-σ σ (inr τ e1) →
binders-disjoint-σ σ e1
lem-bd-σ-inr BDσId = BDσId
lem-bd-σ-inr (BDσSubst bd (UBInr ub) bdσ) =
BDσSubst (lem-bd-inr bd) ub (lem-bd-σ-inr bdσ)
lem-bd-rs-inr : {rs : rules} {τ : htyp} {e1 : ihexp} →
binders-disjoint-rs rs (inr τ e1) →
binders-disjoint-rs rs e1
lem-bd-rs-inr BDNoRules = BDNoRules
lem-bd-rs-inr (BDRules bdr bdrs) =
BDRules (lem-bd-r-inr bdr) (lem-bd-rs-inr bdrs)
lem-bd-r-inr : {r : rule} {τ : htyp} {e1 : ihexp} →
binders-disjoint-r r (inr τ e1) →
binders-disjoint-r r e1
lem-bd-r-inr (BDRule bdp bd) =
BDRule (lem-bd-p-inr bdp) (lem-bd-inr bd)
lem-bd-p-inr : {p : pattrn} {τ : htyp} {e1 : ihexp} →
binders-disjoint-p p (inr τ e1) →
binders-disjoint-p p e1
lem-bd-p-inr BDPUnit = BDPUnit
lem-bd-p-inr BDPNum = BDPNum
lem-bd-p-inr (BDPVar (UBInr ub)) = BDPVar ub
lem-bd-p-inr (BDPInl bd) = BDPInl (lem-bd-p-inr bd)
lem-bd-p-inr (BDPInr bd) = BDPInr (lem-bd-p-inr bd)
lem-bd-p-inr (BDPPair bd1 bd2) =
BDPPair (lem-bd-p-inr bd1) (lem-bd-p-inr bd2)
lem-bd-p-inr BDPWild = BDPWild
lem-bd-p-inr BDPEHole = BDPEHole
lem-bd-p-inr (BDPHole bd) =
BDPHole (lem-bd-p-inr bd)
mutual
lem-bd-match : {e : ihexp} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r : rule} {rs-post : rules} →
binders-disjoint e
(match e1 ·: τ of (rs-pre / r / rs-post)) →
binders-disjoint e e1 ×
binders-disjoint e rs-pre ×
binders-disjoint e r ×
binders-disjoint e rs-post
lem-bd-match BDUnit = BDUnit , BDUnit , BDUnit , BDUnit
lem-bd-match BDNum = BDNum , BDNum , BDNum , BDNum
lem-bd-match BDVar = BDVar , BDVar , BDVar , BDVar
lem-bd-match (BDLam (UBMatch ub
(UBZRules ubpre (UBRules ubr ubpost)))
bd)
with lem-bd-match bd
... | bd' , bdpre , bdr , bdpost =
BDLam ub bd' ,
BDLam ubpre bdpre ,
BDLam ubr bdr ,
BDLam ubpost bdpost
lem-bd-match (BDAp bd1 bd2)
with lem-bd-match bd1 | lem-bd-match bd2
... | bd1' , bdpre1 , bdr1 , bdpost1 |
bd2' , bdpre2 , bdr2 , bdpost2 =
BDAp bd1' bd2' ,
BDAp bdpre1 bdpre2 ,
BDAp bdr1 bdr2 ,
BDAp bdpost1 bdpost2
lem-bd-match (BDInl bd)
with lem-bd-match bd
... | bd' , bdpre , bdr , bdpost =
BDInl bd' , BDInl bdpre , BDInl bdr , BDInl bdpost
lem-bd-match (BDInr bd)
with lem-bd-match bd
... | bd' , bdpre , bdr , bdpost =
BDInr bd' , BDInr bdpre , BDInr bdr , BDInr bdpost
lem-bd-match (BDMatch bd (BDZRules bdpre bdpost))
with lem-bd-match bd |
lem-bd-rs-match bdpre |
lem-bd-rs-match bdpost
... | bd' , bdpre , bdr , bdpost
| bdpre' , bdprepre , bdprer , bdprepost
| bdpost' , bdpostpre , bdpostr , bdpostpost =
BDMatch bd' (BDZRules bdpre' bdpost') ,
BDMatch bdpre (BDZRules bdprepre bdpostpre) ,
BDMatch bdr (BDZRules bdprer bdpostr) ,
BDMatch bdpost (BDZRules bdprepost bdpostpost)
lem-bd-match (BDPair bd1 bd2)
with lem-bd-match bd1 | lem-bd-match bd2
... | bd1' , bdpre1 , bdr1 , bdpost1 |
bd2' , bdpre2 , bdr2 , bdpost2 =
BDPair bd1' bd2' ,
BDPair bdpre1 bdpre2 ,
BDPair bdr1 bdr2 ,
BDPair bdpost1 bdpost2
lem-bd-match (BDFst bd)
with lem-bd-match bd
... | bd' , bdpre , bdr , bdpost =
BDFst bd' , BDFst bdpre , BDFst bdr , BDFst bdpost
lem-bd-match (BDSnd bd)
with lem-bd-match bd
... | bd' , bdpre , bdr , bdpost =
BDSnd bd' , BDSnd bdpre , BDSnd bdr , BDSnd bdpost
lem-bd-match (BDEHole bdσ)
with lem-bd-σ-match bdσ
... | bdσ' , bdσpre , bdσr , bdσpost =
BDEHole bdσ' ,
BDEHole bdσpre ,
BDEHole bdσr ,
BDEHole bdσpost
lem-bd-match (BDHole bdσ bd)
with lem-bd-σ-match bdσ | lem-bd-match bd
... | bdσ' , bdσpre , bdσr , bdσpost
| bd' , bdpre , bdr , bdpost =
BDHole bdσ' bd' ,
BDHole bdσpre bdpre ,
BDHole bdσr bdr ,
BDHole bdσpost bdpost
lem-bd-σ-match : {σ : subst-env} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r : rule} {rs-post : rules} →
binders-disjoint-σ σ
(match e1 ·: τ of (rs-pre / r / rs-post)) →
binders-disjoint-σ σ e1 ×
binders-disjoint-σ σ rs-pre ×
binders-disjoint-σ σ r ×
binders-disjoint-σ σ rs-post
lem-bd-σ-match BDσId = BDσId , BDσId , BDσId , BDσId
lem-bd-σ-match (BDσSubst bd
(UBMatch ube
(UBZRules ubpre
(UBRules ubr
ubpost)))
bdσ)
with lem-bd-match bd | lem-bd-σ-match bdσ
... | bd' , bdpre , bdr , bdpost
| bdσ' , bdσpre , bdσr , bdσpost =
BDσSubst bd' ube bdσ' ,
BDσSubst bdpre ubpre bdσpre ,
BDσSubst bdr ubr bdσr ,
BDσSubst bdpost ubpost bdσpost
lem-bd-rs-match : {rs : rules} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r : rule} {rs-post : rules} →
binders-disjoint-rs rs
(match e1 ·: τ of (rs-pre / r / rs-post)) →
binders-disjoint-rs rs e1 ×
binders-disjoint-rs rs rs-pre ×
binders-disjoint-rs rs r ×
binders-disjoint-rs rs rs-post
lem-bd-rs-match BDNoRules =
BDNoRules , BDNoRules , BDNoRules , BDNoRules
lem-bd-rs-match (BDRules bdr bdrs)
with lem-bd-r-match bdr | lem-bd-rs-match bdrs
... | bdr' , bdrpre , bdrr , bdrpost
| bdrs' , bdrspre , bdrsr , bdrspost =
BDRules bdr' bdrs' ,
BDRules bdrpre bdrspre ,
BDRules bdrr bdrsr ,
BDRules bdrpost bdrspost
lem-bd-r-match : {r : rule} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r1 : rule} {rs-post : rules} →
binders-disjoint-r r
(match e1 ·: τ of (rs-pre / r1 / rs-post)) →
binders-disjoint-r r e1 ×
binders-disjoint-r r rs-pre ×
binders-disjoint-r r r1 ×
binders-disjoint-r r rs-post
lem-bd-r-match (BDRule bdp bd)
with lem-bd-p-match bdp | lem-bd-match bd
... | bdp' , bdppre , bdpr , bdppost
| bd' , bdpre , bdr , bdpost =
BDRule bdp' bd' ,
BDRule bdppre bdpre ,
BDRule bdpr bdr ,
BDRule bdppost bdpost
lem-bd-p-match : {p : pattrn} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r1 : rule} {rs-post : rules} →
binders-disjoint-p p
(match e1 ·: τ of (rs-pre / r1 / rs-post)) →
binders-disjoint-p p e1 ×
binders-disjoint-p p rs-pre ×
binders-disjoint-p p r1 ×
binders-disjoint-p p rs-post
lem-bd-p-match BDPUnit = BDPUnit , BDPUnit , BDPUnit , BDPUnit
lem-bd-p-match BDPNum = BDPNum , BDPNum , BDPNum , BDPNum
lem-bd-p-match (BDPVar (UBMatch ub
(UBZRules ubpre
(UBRules ubr ubpost)))) =
BDPVar ub , BDPVar ubpre , BDPVar ubr , BDPVar ubpost
lem-bd-p-match (BDPInl bd)
with lem-bd-p-match bd
... | bd' , bdpre , bdr , bdpost =
BDPInl bd' , BDPInl bdpre , BDPInl bdr , BDPInl bdpost
lem-bd-p-match (BDPInr bd)
with lem-bd-p-match bd
... | bd' , bdpre , bdr , bdpost =
BDPInr bd' , BDPInr bdpre , BDPInr bdr , BDPInr bdpost
lem-bd-p-match (BDPPair bd1 bd2)
with lem-bd-p-match bd1 | lem-bd-p-match bd2
... | bd1' , bdpre1 , bdr1 , bdpost1
| bd2' , bdpre2 , bdr2 , bdpost2 =
BDPPair bd1' bd2' ,
BDPPair bdpre1 bdpre2 ,
BDPPair bdr1 bdr2 ,
BDPPair bdpost1 bdpost2
lem-bd-p-match BDPWild =
BDPWild , BDPWild , BDPWild , BDPWild
lem-bd-p-match BDPEHole =
BDPEHole , BDPEHole , BDPEHole , BDPEHole
lem-bd-p-match (BDPHole bd)
with lem-bd-p-match bd
... | bd' , bdpre , bdr , bdpost =
BDPHole bd' , BDPHole bdpre , BDPHole bdr , BDPHole bdpost
mutual
lem-bd-pair : {e : ihexp} {e1 e2 : ihexp} →
binders-disjoint e ⟨ e1 , e2 ⟩ →
binders-disjoint e e1 ×
binders-disjoint e e2
lem-bd-pair BDUnit = BDUnit , BDUnit
lem-bd-pair BDNum = BDNum , BDNum
lem-bd-pair BDVar = BDVar , BDVar
lem-bd-pair (BDLam (UBPair ub1 ub2) bd)
with lem-bd-pair bd
... | bd1 , bd2 = BDLam ub1 bd1 , BDLam ub2 bd2
lem-bd-pair (BDAp bd1 bd2)
with lem-bd-pair bd1 | lem-bd-pair bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
BDAp bd1₁ bd2₁ , BDAp bd1₂ bd2₂
lem-bd-pair (BDInl bd)
with lem-bd-pair bd
... | bd1 , bd2 = BDInl bd1 , BDInl bd2
lem-bd-pair (BDInr bd)
with lem-bd-pair bd
... | bd1 , bd2 = BDInr bd1 , BDInr bd2
lem-bd-pair (BDMatch bd (BDZRules bdpre bdpost))
with lem-bd-pair bd |
lem-bd-rs-pair bdpre |
lem-bd-rs-pair bdpost
... | bd1 , bd2
| bdpre1 , bdpre2
| bdpost1 , bdpost2 =
BDMatch bd1 (BDZRules bdpre1 bdpost1) ,
BDMatch bd2 (BDZRules bdpre2 bdpost2)
lem-bd-pair (BDPair bd1 bd2)
with lem-bd-pair bd1 | lem-bd-pair bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
BDPair bd1₁ bd2₁ , BDPair bd1₂ bd2₂
lem-bd-pair (BDFst bd)
with lem-bd-pair bd
... | bd1 , bd2 = BDFst bd1 , BDFst bd2
lem-bd-pair (BDSnd bd)
with lem-bd-pair bd
... | bd1 , bd2 = BDSnd bd1 , BDSnd bd2
lem-bd-pair (BDEHole bdσ)
with lem-bd-σ-pair bdσ
... | bdσ1 , bdσ2 =
BDEHole bdσ1 , BDEHole bdσ2
lem-bd-pair (BDHole bdσ bd)
with lem-bd-σ-pair bdσ | lem-bd-pair bd
... | bdσ1 , bdσ2 | bd1 , bd2 =
BDHole bdσ1 bd1 , BDHole bdσ2 bd2
lem-bd-σ-pair : {σ : subst-env} {e1 e2 : ihexp} →
binders-disjoint-σ σ ⟨ e1 , e2 ⟩ →
binders-disjoint-σ σ e1 ×
binders-disjoint-σ σ e2
lem-bd-σ-pair BDσId =
BDσId , BDσId
lem-bd-σ-pair (BDσSubst bd (UBPair ub1 ub2) bdσ)
with lem-bd-σ-pair bdσ | lem-bd-pair bd
... | bdσ1 , bdσ2 | bd1 , bd2 =
BDσSubst bd1 ub1 bdσ1 , BDσSubst bd2 ub2 bdσ2
lem-bd-rs-pair : {rs : rules} {e1 e2 : ihexp} →
binders-disjoint-rs rs ⟨ e1 , e2 ⟩ →
binders-disjoint-rs rs e1 ×
binders-disjoint-rs rs e2
lem-bd-rs-pair BDNoRules = BDNoRules , BDNoRules
lem-bd-rs-pair (BDRules bdr bdrs)
with lem-bd-r-pair bdr | lem-bd-rs-pair bdrs
... | bdr' , ubr | bdrs' , ubrs =
BDRules bdr' bdrs' , BDRules ubr ubrs
lem-bd-r-pair : {r : rule} {e1 e2 : ihexp} →
binders-disjoint-r r ⟨ e1 , e2 ⟩ →
binders-disjoint-r r e1 ×
binders-disjoint-r r e2
lem-bd-r-pair (BDRule bdp bd)
with lem-bd-p-pair bdp | lem-bd-pair bd
... | bdp' , ubp | bd' , ub =
BDRule bdp' bd' , BDRule ubp ub
lem-bd-p-pair : {p : pattrn} {e1 e2 : ihexp} →
binders-disjoint-p p ⟨ e1 , e2 ⟩ →
binders-disjoint-p p e1 ×
binders-disjoint-p p e2
lem-bd-p-pair BDPUnit = BDPUnit , BDPUnit
lem-bd-p-pair BDPNum = BDPNum , BDPNum
lem-bd-p-pair (BDPVar (UBPair ub1 ub2)) =
BDPVar ub1 , BDPVar ub2
lem-bd-p-pair (BDPInl bd)
with lem-bd-p-pair bd
... | bd' , ub = BDPInl bd' , BDPInl ub
lem-bd-p-pair (BDPInr bd)
with lem-bd-p-pair bd
... | bd' , ub = BDPInr bd' , BDPInr ub
lem-bd-p-pair (BDPPair bd1 bd2)
with lem-bd-p-pair bd1 | lem-bd-p-pair bd2
... | bd1' , ub1 | bd2' , ub2 =
BDPPair bd1' bd2' , BDPPair ub1 ub2
lem-bd-p-pair BDPWild = BDPWild , BDPWild
lem-bd-p-pair BDPEHole = BDPEHole , BDPEHole
lem-bd-p-pair (BDPHole bd)
with lem-bd-p-pair bd
... | bd' , ub = BDPHole bd' , BDPHole ub
mutual
lem-bd-fst : {e : ihexp} {e1 : ihexp} →
binders-disjoint e (fst e1) →
binders-disjoint e e1
lem-bd-fst BDUnit = BDUnit
lem-bd-fst BDNum = BDNum
lem-bd-fst BDVar = BDVar
lem-bd-fst (BDLam (UBFst ub) bd) = BDLam ub (lem-bd-fst bd)
lem-bd-fst (BDAp bd1 bd2) =
BDAp (lem-bd-fst bd1) (lem-bd-fst bd2)
lem-bd-fst (BDInl bd) = BDInl (lem-bd-fst bd)
lem-bd-fst (BDInr bd) = BDInr (lem-bd-fst bd)
lem-bd-fst (BDMatch bd (BDZRules bdpre bdpost)) =
BDMatch (lem-bd-fst bd)
(BDZRules (lem-bd-rs-fst bdpre)
(lem-bd-rs-fst bdpost))
lem-bd-fst (BDPair bd1 bd2) =
BDPair (lem-bd-fst bd1) (lem-bd-fst bd2)
lem-bd-fst (BDFst bd) = BDFst (lem-bd-fst bd)
lem-bd-fst (BDSnd bd) = BDSnd (lem-bd-fst bd)
lem-bd-fst (BDEHole bdσ) = BDEHole (lem-bd-σ-fst bdσ)
lem-bd-fst (BDHole bdσ bd) =
BDHole (lem-bd-σ-fst bdσ) (lem-bd-fst bd)
lem-bd-σ-fst : {σ : subst-env} {e1 : ihexp} →
binders-disjoint-σ σ (fst e1) →
binders-disjoint-σ σ e1
lem-bd-σ-fst BDσId = BDσId
lem-bd-σ-fst (BDσSubst bd (UBFst ub) bdσ) =
BDσSubst (lem-bd-fst bd) ub (lem-bd-σ-fst bdσ)
lem-bd-rs-fst : {rs : rules} {e1 : ihexp} →
binders-disjoint-rs rs (fst e1) →
binders-disjoint-rs rs e1
lem-bd-rs-fst BDNoRules = BDNoRules
lem-bd-rs-fst (BDRules bdr bdrs) =
BDRules (lem-bd-r-fst bdr) (lem-bd-rs-fst bdrs)
lem-bd-r-fst : {r : rule} {e1 : ihexp} →
binders-disjoint-r r (fst e1) →
binders-disjoint-r r e1
lem-bd-r-fst (BDRule bdp bd) =
BDRule (lem-bd-p-fst bdp) (lem-bd-fst bd)
lem-bd-p-fst : {p : pattrn} {e1 : ihexp} →
binders-disjoint-p p (fst e1) →
binders-disjoint-p p e1
lem-bd-p-fst BDPUnit = BDPUnit
lem-bd-p-fst BDPNum = BDPNum
lem-bd-p-fst (BDPVar (UBFst ub)) = BDPVar ub
lem-bd-p-fst (BDPInl bd) = BDPInl (lem-bd-p-fst bd)
lem-bd-p-fst (BDPInr bd) = BDPInr (lem-bd-p-fst bd)
lem-bd-p-fst (BDPPair bd1 bd2) =
BDPPair (lem-bd-p-fst bd1) (lem-bd-p-fst bd2)
lem-bd-p-fst BDPWild = BDPWild
lem-bd-p-fst BDPEHole = BDPEHole
lem-bd-p-fst (BDPHole bd) =
BDPHole (lem-bd-p-fst bd)
mutual
lem-bd-snd : {e : ihexp} {e1 : ihexp} →
binders-disjoint e (snd e1) →
binders-disjoint e e1
lem-bd-snd BDUnit = BDUnit
lem-bd-snd BDNum = BDNum
lem-bd-snd BDVar = BDVar
lem-bd-snd (BDLam (UBSnd ub) bd) =
BDLam ub (lem-bd-snd bd)
lem-bd-snd (BDAp bd1 bd2) =
BDAp (lem-bd-snd bd1) (lem-bd-snd bd2)
lem-bd-snd (BDInl bd) = BDInl (lem-bd-snd bd)
lem-bd-snd (BDInr bd) = BDInr (lem-bd-snd bd)
lem-bd-snd (BDMatch bd (BDZRules bdpre bdpost)) =
BDMatch (lem-bd-snd bd)
(BDZRules (lem-bd-rs-snd bdpre)
(lem-bd-rs-snd bdpost))
lem-bd-snd (BDPair bd1 bd2) =
BDPair (lem-bd-snd bd1) (lem-bd-snd bd2)
lem-bd-snd (BDFst bd) = BDFst (lem-bd-snd bd)
lem-bd-snd (BDSnd bd) = BDSnd (lem-bd-snd bd)
lem-bd-snd (BDEHole bdσ) = BDEHole (lem-bd-σ-snd bdσ)
lem-bd-snd (BDHole bdσ bd) =
BDHole (lem-bd-σ-snd bdσ) (lem-bd-snd bd)
lem-bd-σ-snd : {σ : subst-env} {e1 : ihexp} →
binders-disjoint-σ σ (snd e1) →
binders-disjoint-σ σ e1
lem-bd-σ-snd BDσId = BDσId
lem-bd-σ-snd (BDσSubst bd (UBSnd ub) bdσ) =
BDσSubst (lem-bd-snd bd) ub (lem-bd-σ-snd bdσ)
lem-bd-rs-snd : {rs : rules} {e1 : ihexp} →
binders-disjoint-rs rs (snd e1) →
binders-disjoint-rs rs e1
lem-bd-rs-snd BDNoRules = BDNoRules
lem-bd-rs-snd (BDRules bdr bdrs) =
BDRules (lem-bd-r-snd bdr) (lem-bd-rs-snd bdrs)
lem-bd-r-snd : {r : rule} {e1 : ihexp} →
binders-disjoint-r r (snd e1) →
binders-disjoint-r r e1
lem-bd-r-snd (BDRule bdp bd) =
BDRule (lem-bd-p-snd bdp) (lem-bd-snd bd)
lem-bd-p-snd : {p : pattrn} {e1 : ihexp} →
binders-disjoint-p p (snd e1) →
binders-disjoint-p p e1
lem-bd-p-snd BDPUnit = BDPUnit
lem-bd-p-snd BDPNum = BDPNum
lem-bd-p-snd (BDPVar (UBSnd ub)) = BDPVar ub
lem-bd-p-snd (BDPInl bd) = BDPInl (lem-bd-p-snd bd)
lem-bd-p-snd (BDPInr bd) = BDPInr (lem-bd-p-snd bd)
lem-bd-p-snd (BDPPair bd1 bd2) =
BDPPair (lem-bd-p-snd bd1) (lem-bd-p-snd bd2)
lem-bd-p-snd BDPWild = BDPWild
lem-bd-p-snd BDPEHole = BDPEHole
lem-bd-p-snd (BDPHole bd) =
BDPHole (lem-bd-p-snd bd)
mutual
lem-bd-ehole : {e : ihexp} {u : Nat} {σ : subst-env} →
binders-disjoint e ⦇-⦈⟨ u , σ ⟩ →
binders-disjoint e σ
lem-bd-ehole BDUnit = BDUnit
lem-bd-ehole BDNum = BDNum
lem-bd-ehole BDVar = BDVar
lem-bd-ehole (BDLam (UBEHole ubσ) bd) =
BDLam ubσ (lem-bd-ehole bd)
lem-bd-ehole (BDAp bd1 bd2) =
BDAp (lem-bd-ehole bd1) (lem-bd-ehole bd2)
lem-bd-ehole (BDInl bd) = BDInl (lem-bd-ehole bd)
lem-bd-ehole (BDInr bd) = BDInr (lem-bd-ehole bd)
lem-bd-ehole (BDMatch bd (BDZRules bdpre bdpost)) =
BDMatch (lem-bd-ehole bd)
(BDZRules (lem-bd-rs-ehole bdpre)
(lem-bd-rs-ehole bdpost))
lem-bd-ehole (BDPair bd1 bd2) =
BDPair (lem-bd-ehole bd1)
(lem-bd-ehole bd2)
lem-bd-ehole (BDFst bd) = BDFst (lem-bd-ehole bd)
lem-bd-ehole (BDSnd bd) = BDSnd (lem-bd-ehole bd)
lem-bd-ehole (BDEHole bdσ) = BDEHole (lem-bd-σ-ehole bdσ)
lem-bd-ehole (BDHole bdσ bd) =
BDHole (lem-bd-σ-ehole bdσ)
(lem-bd-ehole bd)
lem-bd-σ-ehole : {σ : subst-env} {u : Nat} {σ1 : subst-env} →
binders-disjoint-σ σ ⦇-⦈⟨ u , σ1 ⟩ →
binders-disjoint-σ σ σ1
lem-bd-σ-ehole BDσId = BDσId
lem-bd-σ-ehole (BDσSubst bd (UBEHole ubσ) bdσ) =
BDσSubst (lem-bd-ehole bd) ubσ (lem-bd-σ-ehole bdσ)
lem-bd-rs-ehole : {rs : rules} {u : Nat} {σ : subst-env} →
binders-disjoint-rs rs ⦇-⦈⟨ u , σ ⟩ →
binders-disjoint-rs rs σ
lem-bd-rs-ehole BDNoRules = BDNoRules
lem-bd-rs-ehole (BDRules bdr bdrs) =
BDRules (lem-bd-r-ehole bdr) (lem-bd-rs-ehole bdrs)
lem-bd-r-ehole : {r : rule} {u : Nat} {σ : subst-env} →
binders-disjoint-r r ⦇-⦈⟨ u , σ ⟩ →
binders-disjoint-r r σ
lem-bd-r-ehole (BDRule bdp bde) =
BDRule (lem-bd-p-ehole bdp) (lem-bd-ehole bde)
lem-bd-p-ehole : {p : pattrn} {u : Nat} {σ : subst-env} →
binders-disjoint-p p ⦇-⦈⟨ u , σ ⟩ →
binders-disjoint-p p σ
lem-bd-p-ehole BDPUnit = BDPUnit
lem-bd-p-ehole BDPNum = BDPNum
lem-bd-p-ehole (BDPVar (UBEHole ubσ)) = BDPVar ubσ
lem-bd-p-ehole (BDPInl bd) = BDPInl (lem-bd-p-ehole bd)
lem-bd-p-ehole (BDPInr bd) = BDPInr (lem-bd-p-ehole bd)
lem-bd-p-ehole (BDPPair bd1 bd2) =
BDPPair (lem-bd-p-ehole bd1) (lem-bd-p-ehole bd2)
lem-bd-p-ehole BDPWild = BDPWild
lem-bd-p-ehole BDPEHole = BDPEHole
lem-bd-p-ehole (BDPHole bd) =
BDPHole (lem-bd-p-ehole bd)
mutual
lem-bd-hole : {e : ihexp} {e1 : ihexp} {u : Nat} {σ : subst-env} →
binders-disjoint e ⦇⌜ e1 ⌟⦈⟨ u , σ ⟩ →
binders-disjoint e σ ×
binders-disjoint e e1
lem-bd-hole BDUnit = BDUnit , BDUnit
lem-bd-hole BDNum = BDNum , BDNum
lem-bd-hole BDVar = BDVar , BDVar
lem-bd-hole (BDLam (UBHole ubσ ub) bd)
with lem-bd-hole bd
... | bdσ , bd' =
BDLam ubσ bdσ , BDLam ub bd'
lem-bd-hole (BDAp bd1 bd2)
with lem-bd-hole bd1 | lem-bd-hole bd2
... | bd1σ , bd1' | bd2σ , bd2' =
BDAp bd1σ bd2σ , BDAp bd1' bd2'
lem-bd-hole (BDInl bd)
with lem-bd-hole bd
... | bdσ , bd' =
BDInl bdσ , BDInl bd'
lem-bd-hole (BDInr bd)
with lem-bd-hole bd
... | bdσ , bd' =
BDInr bdσ , BDInr bd'
lem-bd-hole (BDMatch bd (BDZRules bdpre bdpost))
with lem-bd-hole bd |
lem-bd-rs-hole bdpre |
lem-bd-rs-hole bdpost
... | bdσ , bd'
| bdpreσ , bdpre'
| bdpostσ , bdpost' =
BDMatch bdσ (BDZRules bdpreσ bdpostσ) ,
BDMatch bd' (BDZRules bdpre' bdpost')
lem-bd-hole (BDPair bd1 bd2)
with lem-bd-hole bd1 | lem-bd-hole bd2
... | bdσ1 , bd1' | bdσ2 , bd2' =
BDPair bdσ1 bdσ2 , BDPair bd1' bd2'
lem-bd-hole (BDFst bd)
with lem-bd-hole bd
... | bdσ , bd' = BDFst bdσ , BDFst bd'
lem-bd-hole (BDSnd bd)
with lem-bd-hole bd
... | bdσ , bd' = BDSnd bdσ , BDSnd bd'
lem-bd-hole (BDEHole bdσ)
with lem-bd-σ-hole bdσ
... | bdσσ , bdσ' =
BDEHole bdσσ , BDEHole bdσ'
lem-bd-hole (BDHole bdσ bde)
with lem-bd-σ-hole bdσ | lem-bd-hole bde
... | bdσσ , bdσ' | bdeσ , bde' =
BDHole bdσσ bdeσ , BDHole bdσ' bde'
lem-bd-σ-hole : {σ : subst-env} {e1 : ihexp} {u : Nat} {σ1 : subst-env} →
binders-disjoint-σ σ ⦇⌜ e1 ⌟⦈⟨ u , σ1 ⟩ →
binders-disjoint-σ σ σ1 ×
binders-disjoint-σ σ e1
lem-bd-σ-hole BDσId = BDσId , BDσId
lem-bd-σ-hole (BDσSubst bdd (UBHole ubσ ub) bdσ)
with lem-bd-hole bdd | lem-bd-σ-hole bdσ
... | bddσ , bdd' | bdσσ , bdσ' =
BDσSubst bddσ ubσ bdσσ , BDσSubst bdd' ub bdσ'
lem-bd-rs-hole : {rs : rules} {e1 : ihexp} {u : Nat} {σ : subst-env} →
binders-disjoint-rs rs ⦇⌜ e1 ⌟⦈⟨ u , σ ⟩ →
binders-disjoint-rs rs σ ×
binders-disjoint-rs rs e1
lem-bd-rs-hole BDNoRules = BDNoRules , BDNoRules
lem-bd-rs-hole (BDRules bdr bdrs)
with lem-bd-r-hole bdr | lem-bd-rs-hole bdrs
... | bdrσ , bdr' | bdrsσ , bdrs' =
BDRules bdrσ bdrsσ , BDRules bdr' bdrs'
lem-bd-r-hole : {r : rule} {e1 : ihexp} {u : Nat} {σ : subst-env} →
binders-disjoint-r r ⦇⌜ e1 ⌟⦈⟨ u , σ ⟩ →
binders-disjoint-r r σ ×
binders-disjoint-r r e1
lem-bd-r-hole (BDRule bdp bde)
with lem-bd-p-hole bdp | lem-bd-hole bde
... | bdpσ , bdp' | bdeσ , bde' =
BDRule bdpσ bdeσ , BDRule bdp' bde'
lem-bd-p-hole : {p : pattrn} {e1 : ihexp} {u : Nat} {σ : subst-env} →
binders-disjoint-p p ⦇⌜ e1 ⌟⦈⟨ u , σ ⟩ →
binders-disjoint-p p σ ×
binders-disjoint-p p e1
lem-bd-p-hole BDPUnit = BDPUnit , BDPUnit
lem-bd-p-hole BDPNum = BDPNum , BDPNum
lem-bd-p-hole (BDPVar (UBHole ubσ ub)) =
BDPVar ubσ , BDPVar ub
lem-bd-p-hole (BDPInl bd)
with lem-bd-p-hole bd
... | bdσ , bd' =
BDPInl bdσ , BDPInl bd'
lem-bd-p-hole (BDPInr bd)
with lem-bd-p-hole bd
... | bdσ , bd' =
BDPInr bdσ , BDPInr bd'
lem-bd-p-hole (BDPPair bd1 bd2)
with lem-bd-p-hole bd1 |
lem-bd-p-hole bd2
... | bdσ1 , bd1' | bdσ2 , bd2' =
BDPPair bdσ1 bdσ2 , BDPPair bd1' bd2'
lem-bd-p-hole BDPWild = BDPWild , BDPWild
lem-bd-p-hole BDPEHole = BDPEHole , BDPEHole
lem-bd-p-hole (BDPHole bd)
with lem-bd-p-hole bd
... | bdσ , bd' =
BDPHole bdσ , BDPHole bd'
mutual
lem-σ-bd-subst : {e : ihexp} {d : ihexp} {y : Nat} {σ : subst-env} →
binders-disjoint e (Subst d y σ) →
binders-disjoint e d ×
unbound-in-e y e ×
binders-disjoint e σ
lem-σ-bd-subst BDUnit = BDUnit , UBUnit , BDUnit
lem-σ-bd-subst BDNum = BDNum , UBNum , BDNum
lem-σ-bd-subst BDVar = BDVar , UBVar , BDVar
lem-σ-bd-subst (BDLam (UBσSubst ub x≠y ubσ) bd)
with lem-σ-bd-subst bd
... | bd' , ub' , bdσ =
BDLam ub bd' , UBLam (flip x≠y) ub' , BDLam ubσ bdσ
lem-σ-bd-subst (BDAp bd1 bd2)
with lem-σ-bd-subst bd1 | lem-σ-bd-subst bd2
... | bd1' , ub1 , bdσ1 | bd2' , ub2 , bdσ2 =
BDAp bd1' bd2' , UBAp ub1 ub2 , BDAp bdσ1 bdσ2
lem-σ-bd-subst (BDInl bd)
with lem-σ-bd-subst bd
... | bd' , ub , bdσ =
BDInl bd' , UBInl ub , BDInl bdσ
lem-σ-bd-subst (BDInr bd)
with lem-σ-bd-subst bd
... | bd' , ub , bdσ =
BDInr bd' , UBInr ub , BDInr bdσ
lem-σ-bd-subst (BDMatch bd (BDZRules bdpre bdpost))
with lem-σ-bd-subst bd |
lem-σ-bd-rs-subst bdpre |
lem-σ-bd-rs-subst bdpost
... | bd' , ub , bdσ
| bdpre' , ubpre , bdpreσ
| bdpost' , ubpost , bdpostσ =
BDMatch bd' (BDZRules bdpre' bdpost') ,
UBMatch ub (UBZRules ubpre ubpost) ,
BDMatch bdσ (BDZRules bdpreσ bdpostσ)
lem-σ-bd-subst (BDPair bd1 bd2)
with lem-σ-bd-subst bd1 | lem-σ-bd-subst bd2
... | bd1' , ub1 , bdσ1 | bd2' , ub2 , bdσ2 =
BDPair bd1' bd2' , UBPair ub1 ub2 , BDPair bdσ1 bdσ2
lem-σ-bd-subst (BDFst bd)
with lem-σ-bd-subst bd
... | bd' , ub , bdσ =
BDFst bd' , UBFst ub , BDFst bdσ
lem-σ-bd-subst (BDSnd bd)
with lem-σ-bd-subst bd
... | bd' , ub , bdσ =
BDSnd bd' , UBSnd ub , BDSnd bdσ
lem-σ-bd-subst (BDEHole bdσ)
with lem-σ-bd-σ-subst bdσ
... | bdσ' , ubσ , bdσσ =
BDEHole bdσ' , UBEHole ubσ , BDEHole bdσσ
lem-σ-bd-subst (BDHole bdσ bde)
with lem-σ-bd-σ-subst bdσ | lem-σ-bd-subst bde
... | bdσ' , ubσ , bdσσ | bde' , ube , bdeσ =
BDHole bdσ' bde' , UBHole ubσ ube , BDHole bdσσ bdeσ
lem-σ-bd-σ-subst : {σ : subst-env} {d : ihexp} {y : Nat} {σ1 : subst-env} →
binders-disjoint-σ σ (Subst d y σ1) →
binders-disjoint-σ σ d ×
unbound-in-σ y σ ×
binders-disjoint-σ σ σ1
lem-σ-bd-σ-subst BDσId = BDσId , UBσId , BDσId
lem-σ-bd-σ-subst (BDσSubst bdd (UBσSubst ub x≠y ubσ) bdσ)
with lem-σ-bd-subst bdd | lem-σ-bd-σ-subst bdσ
... | bdd' , ubd , bddσ | bdσ' , ubσ' , bdσσ =
BDσSubst bdd' ub bdσ' ,
UBσSubst ubd (flip x≠y) ubσ' ,
BDσSubst bddσ ubσ bdσσ
lem-σ-bd-rs-subst : {rs : rules} {d : ihexp} {y : Nat} {σ : subst-env} →
binders-disjoint-rs rs (Subst d y σ) →
binders-disjoint-rs rs d ×
unbound-in-rs y rs ×
binders-disjoint-rs rs σ
lem-σ-bd-rs-subst BDNoRules = BDNoRules , UBNoRules , BDNoRules
lem-σ-bd-rs-subst (BDRules bdr bdrs)
with lem-σ-bd-r-subst bdr | lem-σ-bd-rs-subst bdrs
... | bdr' , ubr , bdrσ | bdrs' , ubrs , bdrsσ =
BDRules bdr' bdrs' , UBRules ubr ubrs , BDRules bdrσ bdrsσ
lem-σ-bd-r-subst : {r : rule} {d : ihexp} {y : Nat} {σ : subst-env} →
binders-disjoint-r r (Subst d y σ) →
binders-disjoint-r r d ×