-
Notifications
You must be signed in to change notification settings - Fork 0
/
hole-binders-disjoint-symmetric.agda
2057 lines (1941 loc) · 88.5 KB
/
hole-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 hole-binders-disjoint-symmetric where
-- these lemmas build up to proving that the various
-- hole 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-hbd-lam : {e : ihexp} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
hole-binders-disjoint e (·λ x ·[ τ1 ] e1) →
hole-binders-disjoint e e1
lem-hbd-lam HBDUnit = HBDUnit
lem-hbd-lam HBDNum = HBDNum
lem-hbd-lam HBDVar = HBDVar
lem-hbd-lam (HBDLam bd) = HBDLam (lem-hbd-lam bd)
lem-hbd-lam (HBDAp bd1 bd2) =
HBDAp (lem-hbd-lam bd1) (lem-hbd-lam bd2)
lem-hbd-lam (HBDInl bd) = HBDInl (lem-hbd-lam bd)
lem-hbd-lam (HBDInr bd) = HBDInr (lem-hbd-lam bd)
lem-hbd-lam (HBDMatch bd (HBDZRules bdpre bdpost)) =
HBDMatch (lem-hbd-lam bd)
(HBDZRules (lem-hbd-rs-lam bdpre)
(lem-hbd-rs-lam bdpost))
lem-hbd-lam (HBDPair bd1 bd2) =
HBDPair (lem-hbd-lam bd1) (lem-hbd-lam bd2)
lem-hbd-lam (HBDFst bd) = HBDFst (lem-hbd-lam bd)
lem-hbd-lam (HBDSnd bd) = HBDSnd (lem-hbd-lam bd)
lem-hbd-lam (HBDEHole bdσ) = HBDEHole (lem-hbd-σ-lam bdσ)
lem-hbd-lam (HBDHole bdσ bd) =
HBDHole (lem-hbd-σ-lam bdσ) (lem-hbd-lam bd)
lem-hbd-σ-lam : {σ : subst-env} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
hole-binders-disjoint-σ σ (·λ x ·[ τ1 ] e1) →
hole-binders-disjoint-σ σ e1
lem-hbd-σ-lam HBDσId = HBDσId
lem-hbd-σ-lam (HBDσSubst bd bdσ) =
HBDσSubst (lem-hbd-lam bd) (lem-hbd-σ-lam bdσ)
lem-hbd-rs-lam : {rs : rules} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
hole-binders-disjoint-rs rs (·λ x ·[ τ1 ] e1) →
hole-binders-disjoint-rs rs e1
lem-hbd-rs-lam HBDNoRules = HBDNoRules
lem-hbd-rs-lam (HBDRules bdr bdrs) =
HBDRules (lem-hbd-r-lam bdr) (lem-hbd-rs-lam bdrs)
lem-hbd-r-lam : {r : rule} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
hole-binders-disjoint-r r (·λ x ·[ τ1 ] e1) →
hole-binders-disjoint-r r e1
lem-hbd-r-lam (HBDRule bdp bd) =
HBDRule (lem-hbd-p-lam bdp) (lem-hbd-lam bd)
lem-hbd-p-lam : {p : pattrn} {x : Nat} {τ1 : htyp} {e1 : ihexp} →
hole-binders-disjoint-p p (·λ x ·[ τ1 ] e1) →
hole-binders-disjoint-p p e1
lem-hbd-p-lam HBDPUnit = HBDPUnit
lem-hbd-p-lam HBDPNum = HBDPNum
lem-hbd-p-lam HBDPVar = HBDPVar
lem-hbd-p-lam (HBDPInl bd) = HBDPInl (lem-hbd-p-lam bd)
lem-hbd-p-lam (HBDPInr bd) = HBDPInr (lem-hbd-p-lam bd)
lem-hbd-p-lam (HBDPPair bd1 bd2) =
HBDPPair (lem-hbd-p-lam bd1) (lem-hbd-p-lam bd2)
lem-hbd-p-lam HBDPWild = HBDPWild
lem-hbd-p-lam (HBDPEHole (HUBLam ub)) = HBDPEHole ub
lem-hbd-p-lam (HBDPHole (HUBLam ub) bd) =
HBDPHole ub (lem-hbd-p-lam bd)
mutual
lem-hbd-ap : {e : ihexp} {e1 e2 : ihexp} →
hole-binders-disjoint e (e1 ∘ e2) →
hole-binders-disjoint e e1 ×
hole-binders-disjoint e e2
lem-hbd-ap HBDUnit = HBDUnit , HBDUnit
lem-hbd-ap HBDNum = HBDNum , HBDNum
lem-hbd-ap HBDVar = HBDVar , HBDVar
lem-hbd-ap (HBDLam bd)
with lem-hbd-ap bd
... | bd1 , bd2 = HBDLam bd1 , HBDLam bd2
lem-hbd-ap (HBDAp bd1 bd2)
with lem-hbd-ap bd1 | lem-hbd-ap bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
HBDAp bd1₁ bd2₁ , HBDAp bd1₂ bd2₂
lem-hbd-ap (HBDInl bd)
with lem-hbd-ap bd
... | bd1 , bd2 = HBDInl bd1 , HBDInl bd2
lem-hbd-ap (HBDInr bd)
with lem-hbd-ap bd
... | bd1 , bd2 = HBDInr bd1 , HBDInr bd2
lem-hbd-ap (HBDMatch bd (HBDZRules pret postt))
with lem-hbd-ap bd |
lem-hbd-rs-ap pret |
lem-hbd-rs-ap postt
... | bd1 , bd2
| bdpre1 , bdpre2
| bdpost1 , bdpost2 =
HBDMatch bd1 (HBDZRules bdpre1 bdpost1) ,
HBDMatch bd2 (HBDZRules bdpre2 bdpost2)
lem-hbd-ap (HBDPair bd1 bd2)
with lem-hbd-ap bd1 | lem-hbd-ap bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
HBDPair bd1₁ bd2₁ , HBDPair bd1₂ bd2₂
lem-hbd-ap (HBDFst bd)
with lem-hbd-ap bd
... | bd1 , bd2 = HBDFst bd1 , HBDFst bd2
lem-hbd-ap (HBDSnd bd)
with lem-hbd-ap bd
... | bd1 , bd2 = HBDSnd bd1 , HBDSnd bd2
lem-hbd-ap (HBDEHole bdσ)
with lem-hbd-σ-ap bdσ
... | bdσ1 , bdσ2 = HBDEHole bdσ1 , HBDEHole bdσ2
lem-hbd-ap (HBDHole bdσ bd)
with lem-hbd-σ-ap bdσ | lem-hbd-ap bd
... | bdσ1 , bdσ2 | bd1 , bd2 =
HBDHole bdσ1 bd1 , HBDHole bdσ2 bd2
lem-hbd-σ-ap : {σ : subst-env} {e1 e2 : ihexp} →
hole-binders-disjoint-σ σ (e1 ∘ e2) →
hole-binders-disjoint-σ σ e1 ×
hole-binders-disjoint-σ σ e2
lem-hbd-σ-ap HBDσId = HBDσId , HBDσId
lem-hbd-σ-ap (HBDσSubst bd bdσ)
with lem-hbd-ap bd | lem-hbd-σ-ap bdσ
... | bd1 , bd2 | bdσ1 , bdσ2 =
HBDσSubst bd1 bdσ1 , HBDσSubst bd2 bdσ2
lem-hbd-rs-ap : {rs : rules} {e1 e2 : ihexp} →
hole-binders-disjoint-rs rs (e1 ∘ e2) →
hole-binders-disjoint-rs rs e1 ×
hole-binders-disjoint-rs rs e2
lem-hbd-rs-ap HBDNoRules = HBDNoRules , HBDNoRules
lem-hbd-rs-ap (HBDRules bdr bdrs)
with lem-hbd-r-ap bdr | lem-hbd-rs-ap bdrs
... | bdr1 , bdr2 | bd1 , bd2 =
HBDRules bdr1 bd1 , HBDRules bdr2 bd2
lem-hbd-r-ap : {r : rule} {e1 e2 : ihexp} →
hole-binders-disjoint-r r (e1 ∘ e2) →
hole-binders-disjoint-r r e1 ×
hole-binders-disjoint-r r e2
lem-hbd-r-ap (HBDRule pt bd)
with lem-hbd-p-ap pt | lem-hbd-ap bd
... | pt1 , pt2 | bd1 , bd2 =
HBDRule pt1 bd1 , HBDRule pt2 bd2
lem-hbd-p-ap : {p : pattrn} {e1 e2 : ihexp} →
hole-binders-disjoint-p p (e1 ∘ e2) →
hole-binders-disjoint-p p e1 ×
hole-binders-disjoint-p p e2
lem-hbd-p-ap HBDPUnit = HBDPUnit , HBDPUnit
lem-hbd-p-ap HBDPNum = HBDPNum , HBDPNum
lem-hbd-p-ap HBDPVar = HBDPVar , HBDPVar
lem-hbd-p-ap (HBDPInl bd)
with lem-hbd-p-ap bd
... | bd1 , bd2 = HBDPInl bd1 , HBDPInl bd2
lem-hbd-p-ap (HBDPInr bd)
with lem-hbd-p-ap bd
... | bd1 , bd2 = HBDPInr bd1 , HBDPInr bd2
lem-hbd-p-ap (HBDPPair bd1 bd2)
with lem-hbd-p-ap bd1 | lem-hbd-p-ap bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
HBDPPair bd1₁ bd2₁ , HBDPPair bd1₂ bd2₂
lem-hbd-p-ap HBDPWild = HBDPWild , HBDPWild
lem-hbd-p-ap (HBDPEHole (HUBAp ub1 ub2)) =
HBDPEHole ub1 , HBDPEHole ub2
lem-hbd-p-ap (HBDPHole (HUBAp ub1 ub2) bd)
with lem-hbd-p-ap bd
... | bd1 , bd2 =
HBDPHole ub1 bd1 , HBDPHole ub2 bd2
mutual
lem-hbd-inl : {e : ihexp} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint e (inl τ e1) →
hole-binders-disjoint e e1
lem-hbd-inl HBDUnit = HBDUnit
lem-hbd-inl HBDNum = HBDNum
lem-hbd-inl HBDVar = HBDVar
lem-hbd-inl (HBDLam bd) = HBDLam (lem-hbd-inl bd)
lem-hbd-inl (HBDAp bd1 bd2) =
HBDAp (lem-hbd-inl bd1) (lem-hbd-inl bd2)
lem-hbd-inl (HBDInl bd) = HBDInl (lem-hbd-inl bd)
lem-hbd-inl (HBDInr bd) = HBDInr (lem-hbd-inl bd)
lem-hbd-inl (HBDMatch bd (HBDZRules bdpre bdpost)) =
HBDMatch (lem-hbd-inl bd)
(HBDZRules (lem-hbd-rs-inl bdpre)
(lem-hbd-rs-inl bdpost))
lem-hbd-inl (HBDPair bd1 bd2) =
HBDPair (lem-hbd-inl bd1) (lem-hbd-inl bd2)
lem-hbd-inl (HBDFst bd) = HBDFst (lem-hbd-inl bd)
lem-hbd-inl (HBDSnd bd) = HBDSnd (lem-hbd-inl bd)
lem-hbd-inl (HBDEHole bdσ) =
HBDEHole (lem-hbd-σ-inl bdσ)
lem-hbd-inl (HBDHole bdσ bd) =
HBDHole (lem-hbd-σ-inl bdσ) (lem-hbd-inl bd)
lem-hbd-σ-inl : {σ : subst-env} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint-σ σ (inl τ e1) →
hole-binders-disjoint-σ σ e1
lem-hbd-σ-inl HBDσId = HBDσId
lem-hbd-σ-inl (HBDσSubst bd bdσ) =
HBDσSubst (lem-hbd-inl bd) (lem-hbd-σ-inl bdσ)
lem-hbd-rs-inl : {rs : rules} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint-rs rs (inl τ e1) →
hole-binders-disjoint-rs rs e1
lem-hbd-rs-inl HBDNoRules = HBDNoRules
lem-hbd-rs-inl (HBDRules bdr bdrs) =
HBDRules (lem-hbd-r-inl bdr) (lem-hbd-rs-inl bdrs)
lem-hbd-r-inl : {r : rule} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint-r r (inl τ e1) →
hole-binders-disjoint-r r e1
lem-hbd-r-inl (HBDRule bdp bd) =
HBDRule (lem-hbd-p-inl bdp) (lem-hbd-inl bd)
lem-hbd-p-inl : {p : pattrn} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint-p p (inl τ e1) →
hole-binders-disjoint-p p e1
lem-hbd-p-inl HBDPUnit = HBDPUnit
lem-hbd-p-inl HBDPNum = HBDPNum
lem-hbd-p-inl HBDPVar = HBDPVar
lem-hbd-p-inl (HBDPInl bd) = HBDPInl (lem-hbd-p-inl bd)
lem-hbd-p-inl (HBDPInr bd) = HBDPInr (lem-hbd-p-inl bd)
lem-hbd-p-inl (HBDPPair bd1 bd2) =
HBDPPair (lem-hbd-p-inl bd1) (lem-hbd-p-inl bd2)
lem-hbd-p-inl HBDPWild = HBDPWild
lem-hbd-p-inl (HBDPEHole (HUBInl ub)) = HBDPEHole ub
lem-hbd-p-inl (HBDPHole (HUBInl ub) bd) =
HBDPHole ub (lem-hbd-p-inl bd)
mutual
lem-hbd-inr : {e : ihexp} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint e (inr τ e1) →
hole-binders-disjoint e e1
lem-hbd-inr HBDUnit = HBDUnit
lem-hbd-inr HBDNum = HBDNum
lem-hbd-inr HBDVar = HBDVar
lem-hbd-inr (HBDLam bd) = HBDLam (lem-hbd-inr bd)
lem-hbd-inr (HBDAp bd1 bd2) =
HBDAp (lem-hbd-inr bd1) (lem-hbd-inr bd2)
lem-hbd-inr (HBDInl bd) = HBDInl (lem-hbd-inr bd)
lem-hbd-inr (HBDInr bd) = HBDInr (lem-hbd-inr bd)
lem-hbd-inr (HBDMatch bd (HBDZRules bdpre bdpost)) =
HBDMatch (lem-hbd-inr bd)
(HBDZRules (lem-hbd-rs-inr bdpre)
(lem-hbd-rs-inr bdpost))
lem-hbd-inr (HBDPair bd1 bd2) =
HBDPair (lem-hbd-inr bd1) (lem-hbd-inr bd2)
lem-hbd-inr (HBDFst bd) = HBDFst (lem-hbd-inr bd)
lem-hbd-inr (HBDSnd bd) = HBDSnd (lem-hbd-inr bd)
lem-hbd-inr (HBDEHole bdσ) =
HBDEHole (lem-hbd-σ-inr bdσ)
lem-hbd-inr (HBDHole bdσ bd) =
HBDHole (lem-hbd-σ-inr bdσ) (lem-hbd-inr bd)
lem-hbd-σ-inr : {σ : subst-env} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint-σ σ (inr τ e1) →
hole-binders-disjoint-σ σ e1
lem-hbd-σ-inr HBDσId = HBDσId
lem-hbd-σ-inr (HBDσSubst bd bdσ) =
HBDσSubst (lem-hbd-inr bd) (lem-hbd-σ-inr bdσ)
lem-hbd-rs-inr : {rs : rules} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint-rs rs (inr τ e1) →
hole-binders-disjoint-rs rs e1
lem-hbd-rs-inr HBDNoRules = HBDNoRules
lem-hbd-rs-inr (HBDRules bdr bdrs) =
HBDRules (lem-hbd-r-inr bdr) (lem-hbd-rs-inr bdrs)
lem-hbd-r-inr : {r : rule} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint-r r (inr τ e1) →
hole-binders-disjoint-r r e1
lem-hbd-r-inr (HBDRule bdp bd) =
HBDRule (lem-hbd-p-inr bdp) (lem-hbd-inr bd)
lem-hbd-p-inr : {p : pattrn} {τ : htyp} {e1 : ihexp} →
hole-binders-disjoint-p p (inr τ e1) →
hole-binders-disjoint-p p e1
lem-hbd-p-inr HBDPUnit = HBDPUnit
lem-hbd-p-inr HBDPNum = HBDPNum
lem-hbd-p-inr HBDPVar = HBDPVar
lem-hbd-p-inr (HBDPInl bd) = HBDPInl (lem-hbd-p-inr bd)
lem-hbd-p-inr (HBDPInr bd) = HBDPInr (lem-hbd-p-inr bd)
lem-hbd-p-inr (HBDPPair bd1 bd2) =
HBDPPair (lem-hbd-p-inr bd1) (lem-hbd-p-inr bd2)
lem-hbd-p-inr HBDPWild = HBDPWild
lem-hbd-p-inr (HBDPEHole (HUBInr ub)) = HBDPEHole ub
lem-hbd-p-inr (HBDPHole (HUBInr ub) bd) =
HBDPHole ub (lem-hbd-p-inr bd)
mutual
lem-hbd-match : {e : ihexp} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r : rule} {rs-post : rules} →
hole-binders-disjoint e
(match e1 ·: τ of (rs-pre / r / rs-post)) →
hole-binders-disjoint e e1 ×
hole-binders-disjoint e rs-pre ×
hole-binders-disjoint e r ×
hole-binders-disjoint e rs-post
lem-hbd-match HBDUnit = HBDUnit , HBDUnit , HBDUnit , HBDUnit
lem-hbd-match HBDNum = HBDNum , HBDNum , HBDNum , HBDNum
lem-hbd-match HBDVar = HBDVar , HBDVar , HBDVar , HBDVar
lem-hbd-match (HBDLam bd)
with lem-hbd-match bd
... | bd' , bdpre , bdr , bdpost =
HBDLam bd' , HBDLam bdpre , HBDLam bdr , HBDLam bdpost
lem-hbd-match (HBDAp bd1 bd2)
with lem-hbd-match bd1 | lem-hbd-match bd2
... | bd1' , bdpre1 , bdr1 , bdpost1 |
bd2' , bdpre2 , bdr2 , bdpost2 =
HBDAp bd1' bd2' ,
HBDAp bdpre1 bdpre2 ,
HBDAp bdr1 bdr2 ,
HBDAp bdpost1 bdpost2
lem-hbd-match (HBDInl bd)
with lem-hbd-match bd
... | bd' , bdpre , bdr , bdpost =
HBDInl bd' , HBDInl bdpre , HBDInl bdr , HBDInl bdpost
lem-hbd-match (HBDInr bd)
with lem-hbd-match bd
... | bd' , bdpre , bdr , bdpost =
HBDInr bd' , HBDInr bdpre , HBDInr bdr , HBDInr bdpost
lem-hbd-match (HBDMatch bd (HBDZRules bdpre bdpost))
with lem-hbd-match bd |
lem-hbd-rs-match bdpre |
lem-hbd-rs-match bdpost
... | bd' , bdpre , bdr , bdpost
| bdpre' , bdprepre , bdprer , bdprepost
| bdpost' , bdpostpre , bdpostr , bdpostpost =
HBDMatch bd' (HBDZRules bdpre' bdpost') ,
HBDMatch bdpre (HBDZRules bdprepre bdpostpre) ,
HBDMatch bdr (HBDZRules bdprer bdpostr) ,
HBDMatch bdpost (HBDZRules bdprepost bdpostpost)
lem-hbd-match (HBDPair bd1 bd2)
with lem-hbd-match bd1 | lem-hbd-match bd2
... | bd1' , bdpre1 , bdr1 , bdpost1 |
bd2' , bdpre2 , bdr2 , bdpost2 =
HBDPair bd1' bd2' ,
HBDPair bdpre1 bdpre2 ,
HBDPair bdr1 bdr2 ,
HBDPair bdpost1 bdpost2
lem-hbd-match (HBDFst bd)
with lem-hbd-match bd
... | bd' , bdpre , bdr , bdpost =
HBDFst bd' , HBDFst bdpre , HBDFst bdr , HBDFst bdpost
lem-hbd-match (HBDSnd bd)
with lem-hbd-match bd
... | bd' , bdpre , bdr , bdpost =
HBDSnd bd' , HBDSnd bdpre , HBDSnd bdr , HBDSnd bdpost
lem-hbd-match (HBDEHole bdσ)
with lem-hbd-σ-match bdσ
... | bdσ' , bdσpre , bdσr , bdσpost =
HBDEHole bdσ' ,
HBDEHole bdσpre ,
HBDEHole bdσr ,
HBDEHole bdσpost
lem-hbd-match (HBDHole bdσ bd)
with lem-hbd-σ-match bdσ | lem-hbd-match bd
... | bdσ' , bdσpre , bdσr , bdσpost
| bd' , bdpre , bdr , bdpost =
HBDHole bdσ' bd' ,
HBDHole bdσpre bdpre ,
HBDHole bdσr bdr ,
HBDHole bdσpost bdpost
lem-hbd-σ-match : {σ : subst-env} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r : rule} {rs-post : rules} →
hole-binders-disjoint-σ σ
(match e1 ·: τ of (rs-pre / r / rs-post)) →
hole-binders-disjoint-σ σ e1 ×
hole-binders-disjoint-σ σ rs-pre ×
hole-binders-disjoint-σ σ r ×
hole-binders-disjoint-σ σ rs-post
lem-hbd-σ-match HBDσId = HBDσId , HBDσId , HBDσId , HBDσId
lem-hbd-σ-match (HBDσSubst bd bdσ)
with lem-hbd-match bd | lem-hbd-σ-match bdσ
... | bd' , bdpre , bdr , bdpost
| bdσ' , bdσpre , bdσr , bdσpost =
HBDσSubst bd' bdσ' ,
HBDσSubst bdpre bdσpre ,
HBDσSubst bdr bdσr ,
HBDσSubst bdpost bdσpost
lem-hbd-rs-match : {rs : rules} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r : rule} {rs-post : rules} →
hole-binders-disjoint-rs rs
(match e1 ·: τ of (rs-pre / r / rs-post)) →
hole-binders-disjoint-rs rs e1 ×
hole-binders-disjoint-rs rs rs-pre ×
hole-binders-disjoint-rs rs r ×
hole-binders-disjoint-rs rs rs-post
lem-hbd-rs-match HBDNoRules =
HBDNoRules , HBDNoRules , HBDNoRules , HBDNoRules
lem-hbd-rs-match (HBDRules bdr bdrs)
with lem-hbd-r-match bdr | lem-hbd-rs-match bdrs
... | bdr' , bdrpre , bdrr , bdrpost
| bdrs' , bdrspre , bdrsr , bdrspost =
HBDRules bdr' bdrs' ,
HBDRules bdrpre bdrspre ,
HBDRules bdrr bdrsr ,
HBDRules bdrpost bdrspost
lem-hbd-r-match : {r : rule} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r1 : rule} {rs-post : rules} →
hole-binders-disjoint-r r
(match e1 ·: τ of (rs-pre / r1 / rs-post)) →
hole-binders-disjoint-r r e1 ×
hole-binders-disjoint-r r rs-pre ×
hole-binders-disjoint-r r r1 ×
hole-binders-disjoint-r r rs-post
lem-hbd-r-match (HBDRule bdp bd)
with lem-hbd-p-match bdp | lem-hbd-match bd
... | bdp' , bdppre , bdpr , bdppost
| bd' , bdpre , bdr , bdpost =
HBDRule bdp' bd' ,
HBDRule bdppre bdpre ,
HBDRule bdpr bdr ,
HBDRule bdppost bdpost
lem-hbd-p-match : {p : pattrn} {e1 : ihexp} {τ : htyp}
{rs-pre : rules} {r1 : rule} {rs-post : rules} →
hole-binders-disjoint-p p
(match e1 ·: τ of (rs-pre / r1 / rs-post)) →
hole-binders-disjoint-p p e1 ×
hole-binders-disjoint-p p rs-pre ×
hole-binders-disjoint-p p r1 ×
hole-binders-disjoint-p p rs-post
lem-hbd-p-match HBDPUnit = HBDPUnit , HBDPUnit , HBDPUnit , HBDPUnit
lem-hbd-p-match HBDPNum = HBDPNum , HBDPNum , HBDPNum , HBDPNum
lem-hbd-p-match HBDPVar =
HBDPVar , HBDPVar , HBDPVar , HBDPVar
lem-hbd-p-match (HBDPInl bd)
with lem-hbd-p-match bd
... | bd' , bdpre , bdr , bdpost =
HBDPInl bd' , HBDPInl bdpre , HBDPInl bdr , HBDPInl bdpost
lem-hbd-p-match (HBDPInr bd)
with lem-hbd-p-match bd
... | bd' , bdpre , bdr , bdpost =
HBDPInr bd' , HBDPInr bdpre , HBDPInr bdr , HBDPInr bdpost
lem-hbd-p-match (HBDPPair bd1 bd2)
with lem-hbd-p-match bd1 | lem-hbd-p-match bd2
... | bd1' , bdpre1 , bdr1 , bdpost1
| bd2' , bdpre2 , bdr2 , bdpost2 =
HBDPPair bd1' bd2' ,
HBDPPair bdpre1 bdpre2 ,
HBDPPair bdr1 bdr2 ,
HBDPPair bdpost1 bdpost2
lem-hbd-p-match HBDPWild =
HBDPWild , HBDPWild , HBDPWild , HBDPWild
lem-hbd-p-match (HBDPEHole
(HUBMatch ub
(HUBZRules ubpre (HUBRules ubr ubpost)))) =
HBDPEHole ub , HBDPEHole ubpre , HBDPEHole ubr , HBDPEHole ubpost
lem-hbd-p-match (HBDPHole
(HUBMatch ub
(HUBZRules ubpre (HUBRules ubr ubpost))) bd)
with lem-hbd-p-match bd
... | bd' , bdpre , bdr , bdpost =
HBDPHole ub bd' , HBDPHole ubpre bdpre ,
HBDPHole ubr bdr , HBDPHole ubpost bdpost
mutual
lem-hbd-pair : {e : ihexp} {e1 e2 : ihexp} →
hole-binders-disjoint e ⟨ e1 , e2 ⟩ →
(hole-binders-disjoint e e1) ×
(hole-binders-disjoint e e2)
lem-hbd-pair HBDUnit = HBDUnit , HBDUnit
lem-hbd-pair HBDNum = HBDNum , HBDNum
lem-hbd-pair HBDVar = HBDVar , HBDVar
lem-hbd-pair (HBDLam bd)
with lem-hbd-pair bd
... | bd1 , bd2 = HBDLam bd1 , HBDLam bd2
lem-hbd-pair (HBDAp bd1 bd2)
with lem-hbd-pair bd1 | lem-hbd-pair bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
HBDAp bd1₁ bd2₁ , HBDAp bd1₂ bd2₂
lem-hbd-pair (HBDInl bd)
with lem-hbd-pair bd
... | bd1 , bd2 = HBDInl bd1 , HBDInl bd2
lem-hbd-pair (HBDInr bd)
with lem-hbd-pair bd
... | bd1 , bd2 = HBDInr bd1 , HBDInr bd2
lem-hbd-pair (HBDMatch bd (HBDZRules bdpre bdpost))
with lem-hbd-pair bd |
lem-hbd-rs-pair bdpre |
lem-hbd-rs-pair bdpost
... | bd1 , bd2
| bdpre1 , bdpre2
| bdpost1 , bdpost2 =
HBDMatch bd1 (HBDZRules bdpre1 bdpost1) ,
HBDMatch bd2 (HBDZRules bdpre2 bdpost2)
lem-hbd-pair (HBDPair bd1 bd2)
with lem-hbd-pair bd1 | lem-hbd-pair bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
HBDPair bd1₁ bd2₁ , HBDPair bd1₂ bd2₂
lem-hbd-pair (HBDFst bd)
with lem-hbd-pair bd
... | bd1 , bd2 = HBDFst bd1 , HBDFst bd2
lem-hbd-pair (HBDSnd bd)
with lem-hbd-pair bd
... | bd1 , bd2 = HBDSnd bd1 , HBDSnd bd2
lem-hbd-pair (HBDEHole bdσ)
with lem-hbd-σ-pair bdσ
... | bdσ1 , bdσ2 =
HBDEHole bdσ1 , HBDEHole bdσ2
lem-hbd-pair (HBDHole bdσ bd)
with lem-hbd-σ-pair bdσ | lem-hbd-pair bd
... | bdσ1 , bdσ2 | bd1 , bd2 =
HBDHole bdσ1 bd1 , HBDHole bdσ2 bd2
lem-hbd-σ-pair : {σ : subst-env} {e1 e2 : ihexp} →
hole-binders-disjoint-σ σ ⟨ e1 , e2 ⟩ →
hole-binders-disjoint-σ σ e1 ×
hole-binders-disjoint-σ σ e2
lem-hbd-σ-pair HBDσId =
HBDσId , HBDσId
lem-hbd-σ-pair (HBDσSubst bd bdσ)
with lem-hbd-σ-pair bdσ | lem-hbd-pair bd
... | bdσ1 , bdσ2 | bd1 , bd2 =
HBDσSubst bd1 bdσ1 , HBDσSubst bd2 bdσ2
lem-hbd-rs-pair : {rs : rules} {e1 e2 : ihexp} →
hole-binders-disjoint-rs rs ⟨ e1 , e2 ⟩ →
(hole-binders-disjoint-rs rs e1) ×
(hole-binders-disjoint-rs rs e2)
lem-hbd-rs-pair HBDNoRules = HBDNoRules , HBDNoRules
lem-hbd-rs-pair (HBDRules bdr bdrs)
with lem-hbd-r-pair bdr | lem-hbd-rs-pair bdrs
... | bdr1 , bdr2 | bdrs1 , bdrs2 =
HBDRules bdr1 bdrs1 , HBDRules bdr2 bdrs2
lem-hbd-r-pair : {r : rule} {e1 e2 : ihexp} →
hole-binders-disjoint-r r ⟨ e1 , e2 ⟩ →
(hole-binders-disjoint-r r e1) ×
(hole-binders-disjoint-r r e2)
lem-hbd-r-pair (HBDRule bdp bd)
with lem-hbd-p-pair bdp | lem-hbd-pair bd
... | bdp' , ubp | bd' , ub =
HBDRule bdp' bd' , HBDRule ubp ub
lem-hbd-p-pair : {p : pattrn} {e1 e2 : ihexp} →
hole-binders-disjoint-p p ⟨ e1 , e2 ⟩ →
(hole-binders-disjoint-p p e1) ×
(hole-binders-disjoint-p p e2)
lem-hbd-p-pair HBDPUnit = HBDPUnit , HBDPUnit
lem-hbd-p-pair HBDPNum = HBDPNum , HBDPNum
lem-hbd-p-pair HBDPVar = HBDPVar , HBDPVar
lem-hbd-p-pair (HBDPInl bd)
with lem-hbd-p-pair bd
... | bd1 , bd2 = HBDPInl bd1 , HBDPInl bd2
lem-hbd-p-pair (HBDPInr bd)
with lem-hbd-p-pair bd
... | bd1 , bd2 = HBDPInr bd1 , HBDPInr bd2
lem-hbd-p-pair (HBDPPair bd1 bd2)
with lem-hbd-p-pair bd1 | lem-hbd-p-pair bd2
... | bd1₁ , bd1₂ | bd2₁ , bd2₂ =
HBDPPair bd1₁ bd2₁ , HBDPPair bd1₂ bd2₂
lem-hbd-p-pair HBDPWild = HBDPWild , HBDPWild
lem-hbd-p-pair (HBDPEHole (HUBPair ub1 ub2))=
HBDPEHole ub1 , HBDPEHole ub2
lem-hbd-p-pair (HBDPHole (HUBPair ub1 ub2) bd)
with lem-hbd-p-pair bd
... | bd1 , bd2 = HBDPHole ub1 bd1 , HBDPHole ub2 bd2
mutual
lem-hbd-fst : {e : ihexp} {e1 : ihexp} →
hole-binders-disjoint e (fst e1) →
hole-binders-disjoint e e1
lem-hbd-fst HBDUnit = HBDUnit
lem-hbd-fst HBDNum = HBDNum
lem-hbd-fst HBDVar = HBDVar
lem-hbd-fst (HBDLam bd) = HBDLam (lem-hbd-fst bd)
lem-hbd-fst (HBDAp bd1 bd2) =
HBDAp (lem-hbd-fst bd1) (lem-hbd-fst bd2)
lem-hbd-fst (HBDInl bd) = HBDInl (lem-hbd-fst bd)
lem-hbd-fst (HBDInr bd) = HBDInr (lem-hbd-fst bd)
lem-hbd-fst (HBDMatch bd (HBDZRules bdpre bdpost)) =
HBDMatch (lem-hbd-fst bd)
(HBDZRules (lem-hbd-rs-fst bdpre)
(lem-hbd-rs-fst bdpost))
lem-hbd-fst (HBDPair bd1 bd2) =
HBDPair (lem-hbd-fst bd1) (lem-hbd-fst bd2)
lem-hbd-fst (HBDFst bd) = HBDFst (lem-hbd-fst bd)
lem-hbd-fst (HBDSnd bd) = HBDSnd (lem-hbd-fst bd)
lem-hbd-fst (HBDEHole bdσ) = HBDEHole (lem-hbd-σ-fst bdσ)
lem-hbd-fst (HBDHole bdσ bd) =
HBDHole (lem-hbd-σ-fst bdσ) (lem-hbd-fst bd)
lem-hbd-σ-fst : {σ : subst-env} {e1 : ihexp} →
hole-binders-disjoint-σ σ (fst e1) →
hole-binders-disjoint-σ σ e1
lem-hbd-σ-fst HBDσId = HBDσId
lem-hbd-σ-fst (HBDσSubst bd bdσ) =
HBDσSubst (lem-hbd-fst bd) (lem-hbd-σ-fst bdσ)
lem-hbd-rs-fst : {rs : rules} {e1 : ihexp} →
hole-binders-disjoint-rs rs (fst e1) →
hole-binders-disjoint-rs rs e1
lem-hbd-rs-fst HBDNoRules = HBDNoRules
lem-hbd-rs-fst (HBDRules bdr bdrs) =
HBDRules (lem-hbd-r-fst bdr) (lem-hbd-rs-fst bdrs)
lem-hbd-r-fst : {r : rule} {e1 : ihexp} →
hole-binders-disjoint-r r (fst e1) →
hole-binders-disjoint-r r e1
lem-hbd-r-fst (HBDRule bdp bd) =
HBDRule (lem-hbd-p-fst bdp) (lem-hbd-fst bd)
lem-hbd-p-fst : {p : pattrn} {e1 : ihexp} →
hole-binders-disjoint-p p (fst e1) →
hole-binders-disjoint-p p e1
lem-hbd-p-fst HBDPUnit = HBDPUnit
lem-hbd-p-fst HBDPNum = HBDPNum
lem-hbd-p-fst HBDPVar = HBDPVar
lem-hbd-p-fst (HBDPInl bd) = HBDPInl (lem-hbd-p-fst bd)
lem-hbd-p-fst (HBDPInr bd) = HBDPInr (lem-hbd-p-fst bd)
lem-hbd-p-fst (HBDPPair bd1 bd2) =
HBDPPair (lem-hbd-p-fst bd1) (lem-hbd-p-fst bd2)
lem-hbd-p-fst HBDPWild = HBDPWild
lem-hbd-p-fst (HBDPEHole (HUBFst ub)) = HBDPEHole ub
lem-hbd-p-fst (HBDPHole (HUBFst ub) bd) =
HBDPHole ub (lem-hbd-p-fst bd)
mutual
lem-hbd-snd : {e : ihexp} {e1 : ihexp} →
hole-binders-disjoint e (snd e1) →
hole-binders-disjoint e e1
lem-hbd-snd HBDUnit = HBDUnit
lem-hbd-snd HBDNum = HBDNum
lem-hbd-snd HBDVar = HBDVar
lem-hbd-snd (HBDLam bd) = HBDLam (lem-hbd-snd bd)
lem-hbd-snd (HBDAp bd1 bd2) =
HBDAp (lem-hbd-snd bd1) (lem-hbd-snd bd2)
lem-hbd-snd (HBDInl bd) = HBDInl (lem-hbd-snd bd)
lem-hbd-snd (HBDInr bd) = HBDInr (lem-hbd-snd bd)
lem-hbd-snd (HBDMatch bd (HBDZRules bdpre bdpost)) =
HBDMatch (lem-hbd-snd bd)
(HBDZRules (lem-hbd-rs-snd bdpre)
(lem-hbd-rs-snd bdpost))
lem-hbd-snd (HBDPair bd1 bd2) =
HBDPair (lem-hbd-snd bd1) (lem-hbd-snd bd2)
lem-hbd-snd (HBDFst bd) = HBDFst (lem-hbd-snd bd)
lem-hbd-snd (HBDSnd bd) = HBDSnd (lem-hbd-snd bd)
lem-hbd-snd (HBDEHole bdσ) = HBDEHole (lem-hbd-σ-snd bdσ)
lem-hbd-snd (HBDHole bdσ bd) =
HBDHole (lem-hbd-σ-snd bdσ) (lem-hbd-snd bd)
lem-hbd-σ-snd : {σ : subst-env} {e1 : ihexp} →
hole-binders-disjoint-σ σ (snd e1) →
hole-binders-disjoint-σ σ e1
lem-hbd-σ-snd HBDσId = HBDσId
lem-hbd-σ-snd (HBDσSubst bd bdσ) =
HBDσSubst (lem-hbd-snd bd) (lem-hbd-σ-snd bdσ)
lem-hbd-rs-snd : {rs : rules} {e1 : ihexp} →
hole-binders-disjoint-rs rs (snd e1) →
hole-binders-disjoint-rs rs e1
lem-hbd-rs-snd HBDNoRules = HBDNoRules
lem-hbd-rs-snd (HBDRules bdr bdrs) =
HBDRules (lem-hbd-r-snd bdr) (lem-hbd-rs-snd bdrs)
lem-hbd-r-snd : {r : rule} {e1 : ihexp} →
hole-binders-disjoint-r r (snd e1) →
hole-binders-disjoint-r r e1
lem-hbd-r-snd (HBDRule bdp bd) =
HBDRule (lem-hbd-p-snd bdp) (lem-hbd-snd bd)
lem-hbd-p-snd : {p : pattrn} {e1 : ihexp} →
hole-binders-disjoint-p p (snd e1) →
hole-binders-disjoint-p p e1
lem-hbd-p-snd HBDPUnit = HBDPUnit
lem-hbd-p-snd HBDPNum = HBDPNum
lem-hbd-p-snd HBDPVar = HBDPVar
lem-hbd-p-snd (HBDPInl bd) = HBDPInl (lem-hbd-p-snd bd)
lem-hbd-p-snd (HBDPInr bd) = HBDPInr (lem-hbd-p-snd bd)
lem-hbd-p-snd (HBDPPair bd1 bd2) =
HBDPPair (lem-hbd-p-snd bd1) (lem-hbd-p-snd bd2)
lem-hbd-p-snd HBDPWild = HBDPWild
lem-hbd-p-snd (HBDPEHole (HUBSnd ub)) = HBDPEHole ub
lem-hbd-p-snd (HBDPHole (HUBSnd ub) bd) =
HBDPHole ub (lem-hbd-p-snd bd)
mutual
lem-hbd-ehole : {e : ihexp} {u : Nat} {σ : subst-env} →
hole-binders-disjoint e ⦇-⦈⟨ u , σ ⟩ →
hole-binders-disjoint e σ
lem-hbd-ehole HBDUnit = HBDUnit
lem-hbd-ehole HBDNum = HBDNum
lem-hbd-ehole HBDVar = HBDVar
lem-hbd-ehole (HBDLam bd) =
HBDLam (lem-hbd-ehole bd)
lem-hbd-ehole (HBDAp bd1 bd2) =
HBDAp (lem-hbd-ehole bd1) (lem-hbd-ehole bd2)
lem-hbd-ehole (HBDInl bd) = HBDInl (lem-hbd-ehole bd)
lem-hbd-ehole (HBDInr bd) = HBDInr (lem-hbd-ehole bd)
lem-hbd-ehole (HBDMatch bd (HBDZRules bdpre bdpost)) =
HBDMatch (lem-hbd-ehole bd)
(HBDZRules (lem-hbd-rs-ehole bdpre)
(lem-hbd-rs-ehole bdpost))
lem-hbd-ehole (HBDPair bd1 bd2) =
HBDPair (lem-hbd-ehole bd1)
(lem-hbd-ehole bd2)
lem-hbd-ehole (HBDFst bd) = HBDFst (lem-hbd-ehole bd)
lem-hbd-ehole (HBDSnd bd) = HBDSnd (lem-hbd-ehole bd)
lem-hbd-ehole (HBDEHole bdσ) = HBDEHole (lem-hbd-σ-ehole bdσ)
lem-hbd-ehole (HBDHole bdσ bd) =
HBDHole (lem-hbd-σ-ehole bdσ)
(lem-hbd-ehole bd)
lem-hbd-σ-ehole : {σ : subst-env} {u : Nat} {σ1 : subst-env} →
hole-binders-disjoint-σ σ ⦇-⦈⟨ u , σ1 ⟩ →
hole-binders-disjoint-σ σ σ1
lem-hbd-σ-ehole HBDσId = HBDσId
lem-hbd-σ-ehole (HBDσSubst bd bdσ) =
HBDσSubst (lem-hbd-ehole bd) (lem-hbd-σ-ehole bdσ)
lem-hbd-rs-ehole : {rs : rules} {u : Nat} {σ : subst-env} →
hole-binders-disjoint-rs rs ⦇-⦈⟨ u , σ ⟩ →
hole-binders-disjoint-rs rs σ
lem-hbd-rs-ehole HBDNoRules = HBDNoRules
lem-hbd-rs-ehole (HBDRules bdr bdrs) =
HBDRules (lem-hbd-r-ehole bdr) (lem-hbd-rs-ehole bdrs)
lem-hbd-r-ehole : {r : rule} {u : Nat} {σ : subst-env} →
hole-binders-disjoint-r r ⦇-⦈⟨ u , σ ⟩ →
hole-binders-disjoint-r r σ
lem-hbd-r-ehole (HBDRule bdp bde) =
HBDRule (lem-hbd-p-ehole bdp) (lem-hbd-ehole bde)
lem-hbd-p-ehole : {p : pattrn} {u : Nat} {σ : subst-env} →
hole-binders-disjoint-p p ⦇-⦈⟨ u , σ ⟩ →
hole-binders-disjoint-p p σ
lem-hbd-p-ehole HBDPUnit = HBDPUnit
lem-hbd-p-ehole HBDPNum = HBDPNum
lem-hbd-p-ehole HBDPVar = HBDPVar
lem-hbd-p-ehole (HBDPInl bd) = HBDPInl (lem-hbd-p-ehole bd)
lem-hbd-p-ehole (HBDPInr bd) = HBDPInr (lem-hbd-p-ehole bd)
lem-hbd-p-ehole (HBDPPair bd1 bd2) =
HBDPPair (lem-hbd-p-ehole bd1) (lem-hbd-p-ehole bd2)
lem-hbd-p-ehole HBDPWild = HBDPWild
lem-hbd-p-ehole (HBDPEHole (HUBEHole ubσ)) =
HBDPEHole ubσ
lem-hbd-p-ehole (HBDPHole (HUBEHole ubσ) bd) =
HBDPHole ubσ (lem-hbd-p-ehole bd)
mutual
lem-hbd-hole : {e : ihexp} {e1 : ihexp} {u : Nat} {σ : subst-env} →
hole-binders-disjoint e ⦇⌜ e1 ⌟⦈⟨ u , σ ⟩ →
hole-binders-disjoint e σ ×
hole-binders-disjoint e e1
lem-hbd-hole HBDUnit = HBDUnit , HBDUnit
lem-hbd-hole HBDNum = HBDNum , HBDNum
lem-hbd-hole HBDVar = HBDVar , HBDVar
lem-hbd-hole (HBDLam bd)
with lem-hbd-hole bd
... | bdσ , bd' =
HBDLam bdσ , HBDLam bd'
lem-hbd-hole (HBDAp bd1 bd2)
with lem-hbd-hole bd1 | lem-hbd-hole bd2
... | bd1σ , bd1' | bd2σ , bd2' =
HBDAp bd1σ bd2σ , HBDAp bd1' bd2'
lem-hbd-hole (HBDInl bd)
with lem-hbd-hole bd
... | bdσ , bd' =
HBDInl bdσ , HBDInl bd'
lem-hbd-hole (HBDInr bd)
with lem-hbd-hole bd
... | bdσ , bd' =
HBDInr bdσ , HBDInr bd'
lem-hbd-hole (HBDMatch bd (HBDZRules bdpre bdpost))
with lem-hbd-hole bd |
lem-hbd-rs-hole bdpre |
lem-hbd-rs-hole bdpost
... | bdσ , bd'
| bdpreσ , bdpre'
| bdpostσ , bdpost' =
HBDMatch bdσ (HBDZRules bdpreσ bdpostσ) ,
HBDMatch bd' (HBDZRules bdpre' bdpost')
lem-hbd-hole (HBDPair bd1 bd2)
with lem-hbd-hole bd1 | lem-hbd-hole bd2
... | bdσ1 , bd1' | bdσ2 , bd2' =
HBDPair bdσ1 bdσ2 , HBDPair bd1' bd2'
lem-hbd-hole (HBDFst bd)
with lem-hbd-hole bd
... | bdσ , bd' = HBDFst bdσ , HBDFst bd'
lem-hbd-hole (HBDSnd bd)
with lem-hbd-hole bd
... | bdσ , bd' = HBDSnd bdσ , HBDSnd bd'
lem-hbd-hole (HBDEHole bdσ)
with lem-hbd-σ-hole bdσ
... | bdσσ , bdσ' =
HBDEHole bdσσ , HBDEHole bdσ'
lem-hbd-hole (HBDHole bdσ bde)
with lem-hbd-σ-hole bdσ | lem-hbd-hole bde
... | bdσσ , bdσ' | bdeσ , bde' =
HBDHole bdσσ bdeσ , HBDHole bdσ' bde'
lem-hbd-σ-hole : {σ : subst-env} {e1 : ihexp} {u : Nat} {σ1 : subst-env} →
hole-binders-disjoint-σ σ ⦇⌜ e1 ⌟⦈⟨ u , σ1 ⟩ →
hole-binders-disjoint-σ σ σ1 ×
hole-binders-disjoint-σ σ e1
lem-hbd-σ-hole HBDσId = HBDσId , HBDσId
lem-hbd-σ-hole (HBDσSubst bdd bdσ)
with lem-hbd-hole bdd | lem-hbd-σ-hole bdσ
... | bddσ , bdd' | bdσσ , bdσ' =
HBDσSubst bddσ bdσσ , HBDσSubst bdd' bdσ'
lem-hbd-rs-hole : {rs : rules} {e1 : ihexp} {u : Nat} {σ : subst-env} →
hole-binders-disjoint-rs rs ⦇⌜ e1 ⌟⦈⟨ u , σ ⟩ →
hole-binders-disjoint-rs rs σ ×
hole-binders-disjoint-rs rs e1
lem-hbd-rs-hole HBDNoRules = HBDNoRules , HBDNoRules
lem-hbd-rs-hole (HBDRules bdr bdrs)
with lem-hbd-r-hole bdr | lem-hbd-rs-hole bdrs
... | bdrσ , bdr' | bdrsσ , bdrs' =
HBDRules bdrσ bdrsσ , HBDRules bdr' bdrs'
lem-hbd-r-hole : {r : rule} {e1 : ihexp} {u : Nat} {σ : subst-env} →
hole-binders-disjoint-r r ⦇⌜ e1 ⌟⦈⟨ u , σ ⟩ →
hole-binders-disjoint-r r σ ×
hole-binders-disjoint-r r e1
lem-hbd-r-hole (HBDRule bdp bde)
with lem-hbd-p-hole bdp | lem-hbd-hole bde
... | bdpσ , bdp' | bdeσ , bde' =
HBDRule bdpσ bdeσ , HBDRule bdp' bde'
lem-hbd-p-hole : {p : pattrn} {e1 : ihexp} {u : Nat} {σ : subst-env} →
hole-binders-disjoint-p p ⦇⌜ e1 ⌟⦈⟨ u , σ ⟩ →
hole-binders-disjoint-p p σ ×
hole-binders-disjoint-p p e1
lem-hbd-p-hole HBDPUnit = HBDPUnit , HBDPUnit
lem-hbd-p-hole HBDPNum = HBDPNum , HBDPNum
lem-hbd-p-hole HBDPVar = HBDPVar , HBDPVar
lem-hbd-p-hole (HBDPInl bd)
with lem-hbd-p-hole bd
... | bdσ , bd' =
HBDPInl bdσ , HBDPInl bd'
lem-hbd-p-hole (HBDPInr bd)
with lem-hbd-p-hole bd
... | bdσ , bd' =
HBDPInr bdσ , HBDPInr bd'
lem-hbd-p-hole (HBDPPair bd1 bd2)
with lem-hbd-p-hole bd1 |
lem-hbd-p-hole bd2
... | bdσ1 , bd1' | bdσ2 , bd2' =
HBDPPair bdσ1 bdσ2 , HBDPPair bd1' bd2'
lem-hbd-p-hole HBDPWild = HBDPWild , HBDPWild
lem-hbd-p-hole (HBDPEHole (HUBHole ubσ ub)) =
HBDPEHole ubσ , HBDPEHole ub
lem-hbd-p-hole (HBDPHole (HUBHole ubσ ub) bd)
with lem-hbd-p-hole bd
... | bdσ , bd' =
HBDPHole ubσ bdσ , HBDPHole ub bd'
mutual
lem-σ-hbd-subst : {e : ihexp} {d : ihexp} {y : Nat} {σ : subst-env} →
hole-binders-disjoint e (Subst d y σ) →
hole-binders-disjoint e d ×
hole-binders-disjoint e σ
lem-σ-hbd-subst HBDUnit = HBDUnit , HBDUnit
lem-σ-hbd-subst HBDNum = HBDNum , HBDNum
lem-σ-hbd-subst HBDVar = HBDVar , HBDVar
lem-σ-hbd-subst (HBDLam bd)
with lem-σ-hbd-subst bd
... | bd' , bdσ =
HBDLam bd' , HBDLam bdσ
lem-σ-hbd-subst (HBDAp bd1 bd2)
with lem-σ-hbd-subst bd1 | lem-σ-hbd-subst bd2
... | bd1' , bdσ1 | bd2' , bdσ2 =
HBDAp bd1' bd2' , HBDAp bdσ1 bdσ2
lem-σ-hbd-subst (HBDInl bd)
with lem-σ-hbd-subst bd
... | bd' , bdσ =
HBDInl bd' , HBDInl bdσ
lem-σ-hbd-subst (HBDInr bd)
with lem-σ-hbd-subst bd
... | bd' , bdσ =
HBDInr bd' , HBDInr bdσ
lem-σ-hbd-subst (HBDMatch bd (HBDZRules bdpre bdpost))
with lem-σ-hbd-subst bd |
lem-σ-hbd-rs-subst bdpre |
lem-σ-hbd-rs-subst bdpost
... | bd' , bdσ
| bdpre' , bdpreσ
| bdpost' , bdpostσ =
HBDMatch bd' (HBDZRules bdpre' bdpost') ,
HBDMatch bdσ (HBDZRules bdpreσ bdpostσ)
lem-σ-hbd-subst (HBDPair bd1 bd2)
with lem-σ-hbd-subst bd1 | lem-σ-hbd-subst bd2
... | bd1' , bdσ1 | bd2' , bdσ2 =
HBDPair bd1' bd2' , HBDPair bdσ1 bdσ2
lem-σ-hbd-subst (HBDFst bd)
with lem-σ-hbd-subst bd
... | bd' , bdσ =
HBDFst bd' , HBDFst bdσ
lem-σ-hbd-subst (HBDSnd bd)
with lem-σ-hbd-subst bd
... | bd' , bdσ =
HBDSnd bd' , HBDSnd bdσ
lem-σ-hbd-subst (HBDEHole bdσ)
with lem-σ-hbd-σ-subst bdσ
... | bdσ' , bdσσ =
HBDEHole bdσ' , HBDEHole bdσσ
lem-σ-hbd-subst (HBDHole bdσ bde)
with lem-σ-hbd-σ-subst bdσ | lem-σ-hbd-subst bde
... | bdσ' , bdσσ | bde' , bdeσ =
HBDHole bdσ' bde' , HBDHole bdσσ bdeσ
lem-σ-hbd-σ-subst : {σ : subst-env} {d : ihexp} {y : Nat} {σ1 : subst-env} →
hole-binders-disjoint-σ σ (Subst d y σ1) →
hole-binders-disjoint-σ σ d ×
hole-binders-disjoint-σ σ σ1
lem-σ-hbd-σ-subst HBDσId = HBDσId , HBDσId
lem-σ-hbd-σ-subst (HBDσSubst bdd bdσ)
with lem-σ-hbd-subst bdd | lem-σ-hbd-σ-subst bdσ
... | bdd' , bddσ | bdσ' , bdσσ =
HBDσSubst bdd' bdσ' , HBDσSubst bddσ bdσσ
lem-σ-hbd-rs-subst : {rs : rules} {d : ihexp} {y : Nat} {σ : subst-env} →
hole-binders-disjoint-rs rs (Subst d y σ) →
hole-binders-disjoint-rs rs d ×
hole-binders-disjoint-rs rs σ
lem-σ-hbd-rs-subst HBDNoRules = HBDNoRules , HBDNoRules
lem-σ-hbd-rs-subst (HBDRules bdr bdrs)
with lem-σ-hbd-r-subst bdr | lem-σ-hbd-rs-subst bdrs
... | bdr' , bdrσ | bdrs' , bdrsσ =
HBDRules bdr' bdrs' , HBDRules bdrσ bdrsσ
lem-σ-hbd-r-subst : {r : rule} {d : ihexp} {y : Nat} {σ : subst-env} →
hole-binders-disjoint-r r (Subst d y σ) →
hole-binders-disjoint-r r d ×
hole-binders-disjoint-r r σ
lem-σ-hbd-r-subst (HBDRule bdp bd)
with lem-σ-hbd-p-subst bdp | lem-σ-hbd-subst bd
... | bdp' , bdpσ | bd' , bdσ =
HBDRule bdp' bd' , HBDRule bdpσ bdσ
lem-σ-hbd-p-subst : {p : pattrn} {d : ihexp} {y : Nat} {σ : subst-env} →
hole-binders-disjoint-p p (Subst d y σ) →
hole-binders-disjoint-p p d ×
hole-binders-disjoint-p p σ
lem-σ-hbd-p-subst HBDPUnit = HBDPUnit , HBDPUnit
lem-σ-hbd-p-subst HBDPNum = HBDPNum , HBDPNum
lem-σ-hbd-p-subst HBDPVar = HBDPVar , HBDPVar
lem-σ-hbd-p-subst (HBDPInl bd)
with lem-σ-hbd-p-subst bd
... | bd' , bdσ =
HBDPInl bd' , HBDPInl bdσ
lem-σ-hbd-p-subst (HBDPInr bd)
with lem-σ-hbd-p-subst bd
... | bd' , bdσ =
HBDPInr bd' , HBDPInr bdσ
lem-σ-hbd-p-subst (HBDPPair bd1 bd2)
with lem-σ-hbd-p-subst bd1 | lem-σ-hbd-p-subst bd2
... | bd1' , bdσ1 | bd2' , bdσ2 =
HBDPPair bd1' bd2' , HBDPPair bdσ1 bdσ2
lem-σ-hbd-p-subst HBDPWild = HBDPWild , HBDPWild
lem-σ-hbd-p-subst (HBDPEHole (HUBσSubst ubσ ub)) =
HBDPEHole ubσ , HBDPEHole ub
lem-σ-hbd-p-subst (HBDPHole (HUBσSubst ubσ ub) bd)
with lem-σ-hbd-p-subst bd
... | bd' , bdσ =
HBDPHole ubσ bd' , HBDPHole ub bdσ
mutual
lem-rs-hbd : {e : ihexp} {r : rule} {rs : rules} →
hole-binders-disjoint e (r / rs) →
hole-binders-disjoint e r ×
hole-binders-disjoint e rs
lem-rs-hbd HBDUnit = HBDUnit , HBDUnit
lem-rs-hbd HBDNum = HBDNum , HBDNum
lem-rs-hbd HBDVar = HBDVar , HBDVar
lem-rs-hbd (HBDLam bd)
with lem-rs-hbd bd
... | bdr , bdrs = HBDLam bdr , HBDLam bdrs
lem-rs-hbd (HBDAp bd1 bd2)
with lem-rs-hbd bd1 | lem-rs-hbd bd2
... | bdr1 , bdrs1 | bdr2 , bdrs2 =
HBDAp bdr1 bdr2 , HBDAp bdrs1 bdrs2
lem-rs-hbd (HBDInl bd)
with lem-rs-hbd bd
... | bdr , bdrs = HBDInl bdr , HBDInl bdrs
lem-rs-hbd (HBDInr bd)
with lem-rs-hbd bd
... | bdr , bdrs = HBDInr bdr , HBDInr bdrs
lem-rs-hbd (HBDMatch bd (HBDZRules bdpre bdpost))
with lem-rs-hbd bd |
lem-rs-hbd-rs bdpre |
lem-rs-hbd-rs bdpost