-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITypingInversions.v
698 lines (648 loc) · 20.4 KB
/
ITypingInversions.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
(* Inversion lemmata *)
From Coq Require Import Bool String List BinPos Compare_dec Lia Arith.
Require Import Equations.Prop.DepElim.
From Equations Require Import Equations.
From Translation
Require Import util Sorts SAst SLiftSubst Equality SCommon ITyping.
Section Inversions.
Context `{Sort_notion : Sorts.notion}.
Derive NoConfusion for sterm.
Open Scope i_scope.
Ltac destruct_pand :=
match goal with
| h : exists _, _ |- _ => destruct h
| h : _ /\ _ |- _ => destruct h
end.
Ltac destruct_pands :=
repeat destruct_pand.
Ltac mysplit :=
match goal with
| |- exists _, _ => eexists
| |- _ /\ _ => split
end.
Ltac mysplits :=
repeat mysplit.
Ltac invtac :=
intros ;
lazymatch goal with
| h : _ |- _ =>
dependent induction h ; [
repeat eexists ; eassumption
| destruct_pands ; mysplits ; try eassumption ;
match goal with
| h : nl ?A = _ |- _ =>
solve [ transitivity (nl A) ; eauto ]
end
]
end.
Lemma inversionRel :
forall {Σ Γ n T},
Σ ;;; Γ |-i sRel n : T ->
exists A,
nth_error Γ n = Some A /\
nl (lift0 (S n) A) = nl T.
Proof.
invtac.
Defined.
Lemma inversionSort :
forall {Σ Γ s T},
Σ ;;; Γ |-i sSort s : T ->
nl (sSort (Sorts.succ s)) = nl T.
Proof.
invtac.
Defined.
Lemma inversionProd :
forall {Σ Γ n A B T},
Σ ;;; Γ |-i sProd n A B : T ->
exists s1 s2,
(Σ ;;; Γ |-i A : sSort s1) /\
(Σ ;;; Γ ,, A |-i B : sSort s2) /\
(nl (sSort (Sorts.prod_sort s1 s2)) = nl T).
Proof.
invtac.
Defined.
Lemma inversionLambda :
forall {Σ Γ na A B t T},
Σ ;;; Γ |-i sLambda na A B t : T ->
exists s1 s2 na',
(Σ ;;; Γ |-i A : sSort s1) /\
(Σ ;;; Γ ,, A |-i B : sSort s2) /\
(Σ ;;; Γ ,, A |-i t : B) /\
(nl (sProd na' A B) = nl T).
Proof.
invtac.
Defined.
Lemma inversionApp :
forall {Σ Γ t A B u T},
Σ ;;; Γ |-i sApp t A B u : T ->
exists s1 s2 n,
(Σ ;;; Γ |-i A : sSort s1) /\
(Σ ;;; Γ ,, A |-i B : sSort s2) /\
(Σ ;;; Γ |-i t : sProd n A B) /\
(Σ ;;; Γ |-i u : A) /\
(nl (B{ 0 := u }) = nl T).
Proof.
invtac.
Defined.
Lemma inversionSum :
forall {Σ Γ n A B T},
Σ ;;; Γ |-i sSum n A B : T ->
exists s1 s2,
(Σ ;;; Γ |-i A : sSort s1) /\
(Σ ;;; Γ ,, A |-i B : sSort s2) /\
(nl (sSort (Sorts.sum_sort s1 s2)) = nl T).
Proof.
invtac.
Defined.
Lemma inversionPair :
forall {Σ Γ A B u v T},
Σ ;;; Γ |-i sPair A B u v : T ->
exists n s1 s2,
(Σ ;;; Γ |-i A : sSort s1) /\
(Σ ;;; Γ ,, A |-i B : sSort s2) /\
(Σ ;;; Γ |-i u : A) /\
(Σ ;;; Γ |-i v : B{ 0 := u }) /\
(nl (sSum n A B) = nl T).
Proof.
invtac.
Defined.
Lemma inversionPi1 :
forall {Σ Γ A B p T},
Σ ;;; Γ |-i sPi1 A B p : T ->
exists n s1 s2,
(Σ ;;; Γ |-i p : sSum n A B) /\
(Σ ;;; Γ |-i A : sSort s1) /\
(Σ ;;; Γ ,, A |-i B : sSort s2) /\
(nl A = nl T).
Proof.
invtac.
Defined.
Lemma inversionPi2 :
forall {Σ Γ A B p T},
Σ ;;; Γ |-i sPi2 A B p : T ->
exists n s1 s2,
(Σ ;;; Γ |-i p : sSum n A B) /\
(Σ ;;; Γ |-i A : sSort s1) /\
(Σ ;;; Γ ,, A |-i B : sSort s2) /\
(nl (B{ 0 := sPi1 A B p }) = nl T).
Proof.
invtac.
Defined.
Lemma inversionEq :
forall {Σ Γ A u v T},
Σ ;;; Γ |-i sEq A u v : T ->
exists s,
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i u : A) /\
(Σ ;;; Γ |-i v : A) /\
(nl (sSort (Sorts.eq_sort s)) = nl T).
Proof.
invtac.
Defined.
Lemma inversionRefl :
forall {Σ Γ A u T},
Σ ;;; Γ |-i sRefl A u : T ->
exists s,
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i u : A) /\
(nl (sEq A u u) = nl T).
Proof.
invtac.
Defined.
Lemma inversionJ :
forall {Σ Γ A u P w v p T},
Σ ;;; Γ |-i sJ A u P w v p : T ->
exists s1 s2,
(Σ ;;; Γ |-i A : sSort s1) /\
(Σ ;;; Γ |-i u : A) /\
(Σ ;;; Γ |-i v : A) /\
(Σ ;;; Γ ,, A ,, (sEq (lift0 1 A) (lift0 1 u) (sRel 0)) |-i P : sSort s2) /\
(Σ ;;; Γ |-i p : sEq A u v) /\
(Σ ;;; Γ |-i w : (P {1 := u}){0 := sRefl A u}) /\
(nl (P{1 := v}{0 := p}) = nl T).
Proof.
invtac.
Defined.
Lemma inversionTransport :
forall {Σ Γ A B p t T},
Σ ;;; Γ |-i sTransport A B p t : T ->
exists s,
(Σ ;;; Γ |-i p : sEq (sSort s) A B) /\
(Σ ;;; Γ |-i t : A) /\
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i B : sSort s) /\
(nl B = nl T).
Proof.
invtac.
Defined.
Lemma inversionBeta :
forall {Σ Γ t u T},
Σ ;;; Γ |-i sBeta t u : T ->
exists s n A B,
(Σ ;;; Γ,, A |-i t : B) /\
(Σ ;;; Γ |-i u : A) /\
(Σ ;;; Γ |-i A : sSort s) /\
(nl (sEq (B {0 := u}) (sApp (sLambda n A B t) A B u) (t {0 := u}))
= nl T).
Proof.
invtac.
Defined.
Lemma inversionHeq :
forall {Σ Γ A B a b T},
Σ ;;; Γ |-i sHeq A a B b : T ->
exists s,
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i B : sSort s) /\
(Σ ;;; Γ |-i a : A) /\
(Σ ;;; Γ |-i b : B) /\
(nl (sSort (heq_sort s)) = nl T).
Proof.
invtac.
Defined.
Lemma inversionPack :
forall {Σ Γ A1 A2 T},
Σ ;;; Γ |-i sPack A1 A2 : T ->
exists s,
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(nl (sSort (pack_sort s)) = nl T).
Proof.
invtac.
Defined.
Lemma inversionHeqToEq :
forall {Σ Γ p T},
Σ ;;; Γ |-i sHeqToEq p : T ->
exists A u v s,
(Σ ;;; Γ |-i p : sHeq A u A v) /\
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i u : A) /\
(Σ ;;; Γ |-i v : A) /\
(nl (sEq A u v) = nl T).
Proof.
invtac.
Defined.
Lemma inversionHeqRefl :
forall {Σ Γ A a T},
Σ ;;; Γ |-i sHeqRefl A a : T ->
exists s,
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i a : A) /\
(nl (sHeq A a A a) = nl T).
Proof.
invtac.
Defined.
Lemma inversionHeqSym :
forall {Σ Γ p T},
Σ ;;; Γ |-i sHeqSym p : T ->
exists A a B b s,
(Σ ;;; Γ |-i p : sHeq A a B b) /\
(Σ ;;; Γ |-i a : A) /\
(Σ ;;; Γ |-i b : B) /\
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i B : sSort s) /\
(nl (sHeq B b A a) = nl T).
Proof.
invtac.
Defined.
Lemma inversionHeqTrans :
forall {Σ Γ p q T},
Σ ;;; Γ |-i sHeqTrans p q : T ->
exists A a B b C c s,
(Σ ;;; Γ |-i p : sHeq A a B b) /\
(Σ ;;; Γ |-i q : sHeq B b C c) /\
(Σ ;;; Γ |-i a : A) /\
(Σ ;;; Γ |-i b : B) /\
(Σ ;;; Γ |-i c : C) /\
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i B : sSort s) /\
(Σ ;;; Γ |-i C : sSort s) /\
(nl (sHeq A a C c) = nl T).
Proof.
invtac.
Defined.
Lemma inversionHeqTransport :
forall {Σ Γ p t T},
Σ ;;; Γ |-i sHeqTransport p t : T ->
exists A B s,
(Σ ;;; Γ |-i p : sEq (sSort s) A B) /\
(Σ ;;; Γ |-i t : A) /\
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i B : sSort s) /\
(nl (sHeq A t B (sTransport A B p t)) = nl T).
Proof.
invtac.
Defined.
Lemma inversionCongProd :
forall {Σ Γ B1 B2 pA pB T},
Σ ;;; Γ |-i sCongProd B1 B2 pA pB : T ->
exists s z nx ny A1 A2,
(Σ ;;; Γ |-i pA : sHeq (sSort s) A1 (sSort s) A2) /\
(Σ ;;; Γ ,, (sPack A1 A2)
|-i pB : sHeq (sSort z) ((lift 1 1 B1){ 0 := sProjT1 (sRel 0) })
(sSort z) ((lift 1 1 B2){ 0 := sProjT2 (sRel 0) })) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(Σ ;;; Γ ,, A1 |-i B1 : sSort z) /\
(Σ ;;; Γ ,, A2 |-i B2 : sSort z) /\
(nl (sHeq (sSort (Sorts.prod_sort s z)) (sProd nx A1 B1)
(sSort (Sorts.prod_sort s z)) (sProd ny A2 B2))
= nl T).
Proof.
invtac. Unshelve. all: constructor.
Defined.
Lemma inversionCongLambda :
forall {Σ Γ B1 B2 t1 t2 pA pB pt T},
Σ ;;; Γ |-i sCongLambda B1 B2 t1 t2 pA pB pt : T ->
exists s z nx ny A1 A2,
(Σ ;;; Γ |-i pA : sHeq (sSort s) A1 (sSort s) A2) /\
(Σ ;;; Γ ,, (sPack A1 A2)
|-i pB : sHeq (sSort z) ((lift 1 1 B1){ 0 := sProjT1 (sRel 0) })
(sSort z) ((lift 1 1 B2){ 0 := sProjT2 (sRel 0) })) /\
(Σ ;;; Γ ,, (sPack A1 A2)
|-i pt : sHeq ((lift 1 1 B1){ 0 := sProjT1 (sRel 0) })
((lift 1 1 t1){ 0 := sProjT1 (sRel 0) })
((lift 1 1 B2){ 0 := sProjT2 (sRel 0) })
((lift 1 1 t2){ 0 := sProjT2 (sRel 0) })) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(Σ ;;; Γ ,, A1 |-i B1 : sSort z) /\
(Σ ;;; Γ ,, A2 |-i B2 : sSort z) /\
(Σ ;;; Γ ,, A1 |-i t1 : B1) /\
(Σ ;;; Γ ,, A2 |-i t2 : B2) /\
(nl (sHeq (sProd nx A1 B1) (sLambda nx A1 B1 t1)
(sProd ny A2 B2) (sLambda ny A2 B2 t2))
= nl T).
Proof.
invtac. Unshelve. all: constructor.
Defined.
Lemma inversionCongApp :
forall {Σ Γ B1 B2 pu pA pB pv T},
Σ ;;; Γ |-i sCongApp B1 B2 pu pA pB pv : T ->
exists s z nx ny A1 A2 u1 u2 v1 v2,
(Σ ;;; Γ |-i pA : sHeq (sSort s) A1 (sSort s) A2) /\
(Σ ;;; Γ ,, (sPack A1 A2)
|-i pB : sHeq (sSort z) ((lift 1 1 B1){ 0 := sProjT1 (sRel 0) })
(sSort z) ((lift 1 1 B2){ 0 := sProjT2 (sRel 0) })) /\
(Σ ;;; Γ |-i pu : sHeq (sProd nx A1 B1) u1 (sProd ny A2 B2) u2) /\
(Σ ;;; Γ |-i pv : sHeq A1 v1 A2 v2) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(Σ ;;; Γ ,, A1 |-i B1 : sSort z) /\
(Σ ;;; Γ ,, A2 |-i B2 : sSort z) /\
(Σ ;;; Γ |-i u1 : sProd nx A1 B1) /\
(Σ ;;; Γ |-i u2 : sProd ny A2 B2) /\
(Σ ;;; Γ |-i v1 : A1) /\
(Σ ;;; Γ |-i v2 : A2) /\
(nl (sHeq (B1{0 := v1}) (sApp u1 A1 B1 v1)
(B2{0 := v2}) (sApp u2 A2 B2 v2))
= nl T).
Proof.
invtac.
Defined.
Lemma inversionCongSum :
forall {Σ Γ B1 B2 pA pB T},
Σ ;;; Γ |-i sCongSum B1 B2 pA pB : T ->
exists s z nx ny A1 A2,
(Σ ;;; Γ |-i pA : sHeq (sSort s) A1 (sSort s) A2) /\
(Σ ;;; Γ ,, (sPack A1 A2)
|-i pB : sHeq (sSort z) ((lift 1 1 B1){ 0 := sProjT1 (sRel 0) })
(sSort z) ((lift 1 1 B2){ 0 := sProjT2 (sRel 0) })) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(Σ ;;; Γ ,, A1 |-i B1 : sSort z) /\
(Σ ;;; Γ ,, A2 |-i B2 : sSort z) /\
(nl (sHeq (sSort (Sorts.sum_sort s z)) (sSum nx A1 B1)
(sSort (Sorts.sum_sort s z)) (sSum ny A2 B2))
= nl T).
Proof.
invtac. Unshelve. all: constructor.
Defined.
Lemma inversionCongPair :
forall {Σ Γ B1 B2 pA pB pu pv T},
Σ ;;; Γ |-i sCongPair B1 B2 pA pB pu pv : T ->
exists s z nx ny A1 A2 u1 u2 v1 v2,
(Σ ;;; Γ |-i pA : sHeq (sSort s) A1 (sSort s) A2) /\
(Σ ;;; Γ ,, (sPack A1 A2)
|-i pB : sHeq (sSort z) ((lift 1 1 B1){ 0 := sProjT1 (sRel 0) })
(sSort z) ((lift 1 1 B2){ 0 := sProjT2 (sRel 0) })) /\
(Σ ;;; Γ |-i pu : sHeq A1 u1 A2 u2) /\
(Σ ;;; Γ |-i pv : sHeq (B1{ 0 := u1 }) v1 (B2{ 0 := u2 }) v2) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(Σ ;;; Γ ,, A1 |-i B1 : sSort z) /\
(Σ ;;; Γ ,, A2 |-i B2 : sSort z) /\
(Σ ;;; Γ |-i u1 : A1) /\
(Σ ;;; Γ |-i u2 : A2) /\
(Σ ;;; Γ |-i v1 : B1{ 0 := u1 }) /\
(Σ ;;; Γ |-i v2 : B2{ 0 := u2 }) /\
(nl (sHeq (sSum nx A1 B1) (sPair A1 B1 u1 v1)
(sSum ny A2 B2) (sPair A2 B2 u2 v2))
= nl T).
Proof.
invtac. Unshelve. all: constructor.
Defined.
Lemma inversionCongPi1 :
forall {Σ Γ B1 B2 pA pB pp T},
Σ ;;; Γ |-i sCongPi1 B1 B2 pA pB pp : T ->
exists s z nx ny A1 A2 p1 p2,
(Σ ;;; Γ |-i pA : sHeq (sSort s) A1 (sSort s) A2) /\
(Σ ;;; Γ ,, (sPack A1 A2)
|-i pB : sHeq (sSort z) ((lift 1 1 B1){ 0 := sProjT1 (sRel 0) })
(sSort z) ((lift 1 1 B2){ 0 := sProjT2 (sRel 0) })) /\
(Σ ;;; Γ |-i pp : sHeq (sSum nx A1 B1) p1 (sSum ny A2 B2) p2) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(Σ ;;; Γ ,, A1 |-i B1 : sSort z) /\
(Σ ;;; Γ ,, A2 |-i B2 : sSort z) /\
(Σ ;;; Γ |-i p1 : sSum nx A1 B1) /\
(Σ ;;; Γ |-i p2 : sSum ny A2 B2) /\
(nl (sHeq A1 (sPi1 A1 B1 p1) A2 (sPi1 A2 B2 p2)) = nl T).
Proof.
invtac.
Defined.
Lemma inversionCongPi2 :
forall {Σ Γ B1 B2 pA pB pp T},
Σ ;;; Γ |-i sCongPi2 B1 B2 pA pB pp : T ->
exists s z nx ny A1 A2 p1 p2,
(Σ ;;; Γ |-i pA : sHeq (sSort s) A1 (sSort s) A2) /\
(Σ ;;; Γ ,, (sPack A1 A2)
|-i pB : sHeq (sSort z) ((lift 1 1 B1){ 0 := sProjT1 (sRel 0) })
(sSort z) ((lift 1 1 B2){ 0 := sProjT2 (sRel 0) })) /\
(Σ ;;; Γ |-i pp : sHeq (sSum nx A1 B1) p1 (sSum ny A2 B2) p2) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(Σ ;;; Γ ,, A1 |-i B1 : sSort z) /\
(Σ ;;; Γ ,, A2 |-i B2 : sSort z) /\
(Σ ;;; Γ |-i p1 : sSum nx A1 B1) /\
(Σ ;;; Γ |-i p2 : sSum ny A2 B2) /\
(nl (sHeq (B1{ 0 := sPi1 A1 B1 p1}) (sPi2 A1 B1 p1)
(B2{ 0 := sPi1 A2 B2 p2}) (sPi2 A2 B2 p2))
= nl T).
Proof.
invtac.
Defined.
Lemma inversionCongEq :
forall {Σ Γ pA pu pv T},
Σ ;;; Γ |-i sCongEq pA pu pv : T ->
exists s A1 A2 u1 u2 v1 v2,
(Σ ;;; Γ |-i pA : sHeq (sSort s) A1 (sSort s) A2) /\
(Σ ;;; Γ |-i pu : sHeq A1 u1 A2 u2) /\
(Σ ;;; Γ |-i pv : sHeq A1 v1 A2 v2) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(Σ ;;; Γ |-i u1 : A1) /\
(Σ ;;; Γ |-i u2 : A2) /\
(Σ ;;; Γ |-i v1 : A1) /\
(Σ ;;; Γ |-i v2 : A2) /\
(nl (sHeq (sSort (Sorts.eq_sort s)) (sEq A1 u1 v1)
(sSort (Sorts.eq_sort s)) (sEq A2 u2 v2))
= nl T).
Proof.
invtac.
Defined.
Lemma inversionCongRefl :
forall {Σ Γ pA pu T},
Σ ;;; Γ |-i sCongRefl pA pu : T ->
exists s A1 A2 u1 u2,
(Σ ;;; Γ |-i pA : sHeq (sSort s) A1 (sSort s) A2) /\
(Σ ;;; Γ |-i pu : sHeq A1 u1 A2 u2) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(Σ ;;; Γ |-i u1 : A1) /\
(Σ ;;; Γ |-i u2 : A2) /\
(nl (sHeq (sEq A1 u1 u1) (sRefl A1 u1)
(sEq A2 u2 u2) (sRefl A2 u2))
= nl T).
Proof.
invtac.
Defined.
Lemma inversionEqToHeq :
forall {Σ Γ p T},
Σ ;;; Γ |-i sEqToHeq p : T ->
exists A u v s,
(Σ ;;; Γ |-i p : sEq A u v) /\
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i u : A) /\
(Σ ;;; Γ |-i v : A) /\
(nl (sHeq A u A v) = nl T).
Proof.
invtac.
Defined.
Lemma inversionHeqTypeEq :
forall {Σ Γ A B p T},
Σ ;;; Γ |-i sHeqTypeEq A B p : T ->
exists u v s,
(Σ ;;; Γ |-i p : sHeq A u B v) /\
(Σ ;;; Γ |-i A : sSort s) /\
(Σ ;;; Γ |-i B : sSort s) /\
(Σ ;;; Γ |-i u : A) /\
(Σ ;;; Γ |-i v : B) /\
(nl (sEq (sSort s) A B) = nl T).
Proof.
invtac.
Defined.
Lemma inversionProjT1 :
forall {Σ Γ p T},
Σ ;;; Γ |-i sProjT1 p : T ->
exists s A1 A2,
(Σ ;;; Γ |-i p : sPack A1 A2) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(nl A1 = nl T).
Proof.
invtac.
Defined.
Lemma inversionProjT2 :
forall {Σ Γ p T},
Σ ;;; Γ |-i sProjT2 p : T ->
exists s A1 A2,
(Σ ;;; Γ |-i p : sPack A1 A2) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(nl A2 = nl T).
Proof.
invtac.
Defined.
Lemma inversionProjTe :
forall {Σ Γ p T},
Σ ;;; Γ |-i sProjTe p : T ->
exists s A1 A2,
(Σ ;;; Γ |-i p : sPack A1 A2) /\
(Σ ;;; Γ |-i A1 : sSort s) /\
(Σ ;;; Γ |-i A2 : sSort s) /\
(nl (sHeq A1 (sProjT1 p) A2 (sProjT2 p)) = nl T).
Proof.
invtac.
Defined.
Lemma inversionAx :
forall {Σ Γ id T},
Σ ;;; Γ |-i sAx id : T ->
exists ty,
(lookup_glob Σ id = Some ty) /\
(nl ty = nl T).
Proof.
invtac.
Defined.
End Inversions.
(* Tactic to apply inversion automatically *)
Open Scope i_scope.
Ltac ttinv h :=
let s := fresh "s" in
let s1 := fresh "s1" in
let s2 := fresh "s2" in
let z := fresh "z" in
let his := fresh "is" in
let nx := fresh "nx" in
let ny := fresh "ny" in
let np := fresh "np" in
let ne := fresh "ne" in
let na := fresh "na" in
let A := fresh "A" in
let B := fresh "B" in
let C := fresh "C" in
let A1 := fresh "A1" in
let A2 := fresh "A2" in
let B1 := fresh "B1" in
let B2 := fresh "B2" in
let u := fresh "u" in
let v := fresh "v" in
let u1 := fresh "u1" in
let u2 := fresh "u2" in
let v1 := fresh "v1" in
let v2 := fresh "v2" in
let p1 := fresh "p1" in
let p2 := fresh "p2" in
let a := fresh "a" in
let b := fresh "b" in
let c := fresh "c" in
let t := fresh "t" in
let ty := fresh "ty" in
let univs := fresh "univs" in
let decl := fresh "decl" in
let isdecl := fresh "isdecl" in
let hh := fresh "h" in
lazymatch type of h with
| _ ;;; _ |-i ?term : _ =>
lazymatch term with
| sRel _ => destruct (inversionRel h) as [his [? ?]]
| sSort _ => pose proof (inversionSort h) as hh
| sProd _ _ _ => destruct (inversionProd h) as (s1 & s2 & hh) ; splits_one hh
| sLambda _ _ _ _ => destruct (inversionLambda h) as (s1 & s2 & na & hh) ;
splits_one hh
| sApp _ _ _ _ => destruct (inversionApp h) as (s1 & s2 & na & hh) ;
splits_one hh
| sSum _ _ _ => destruct (inversionSum h) as (s1 & s2 & hh) ; splits_one hh
| sPair _ _ _ _ =>
destruct (inversionPair h) as (nx & s1 & s2 & hh) ; splits_one hh
| sPi1 _ _ _ =>
destruct (inversionPi1 h) as (nx & s1 & s2 & hh) ; splits_one hh
| sPi2 _ _ _ =>
destruct (inversionPi2 h) as (nx & s1 & s2 & hh) ; splits_one hh
| sEq _ _ _ => destruct (inversionEq h) as (s & hh) ; splits_one hh
| sRefl _ _ => destruct (inversionRefl h) as (s & hh) ; splits_one hh
| sJ _ _ _ _ _ _ => destruct (inversionJ h) as (s1 & s2 & hh) ;
splits_one hh
| sTransport _ _ _ _ => destruct (inversionTransport h) as (s & hh) ;
splits_one hh
| sBeta _ _ =>
destruct (inversionBeta h) as (s & nx & A & B & hh) ; splits_one hh
| sHeq _ _ _ _ => destruct (inversionHeq h) as (s & hh) ; splits_one hh
| sHeqToEq _ => destruct (inversionHeqToEq h) as (A & u & v & s & hh) ;
splits_one hh
| sHeqRefl _ _ => destruct (inversionHeqRefl h) as (s & hh) ; splits_one hh
| sHeqSym _ => destruct (inversionHeqSym h) as (A & a & B & b & s & hh) ;
splits_one hh
| sHeqTrans _ _ =>
destruct (inversionHeqTrans h) as (A & a & B & b & C & c & s & hh) ;
splits_one hh
| sHeqTransport _ _ =>
destruct (inversionHeqTransport h) as (A & B & s & hh) ;
splits_one hh
| sCongProd _ _ _ _ =>
destruct (inversionCongProd h) as (s & z & nx & ny & A1 & A2 & hh) ;
splits_one hh
| sCongLambda _ _ _ _ _ _ _ =>
destruct (inversionCongLambda h)
as (s & z & nx & ny & A1 & A2 & hh) ;
splits_one hh
| sCongApp _ _ _ _ _ _ =>
destruct (inversionCongApp h)
as (s & z & nx & ny & A1 & A2 & u1 & u2 & v1 & v2 & hh) ;
splits_one hh
| sCongSum _ _ _ _ =>
destruct (inversionCongSum h) as (s & z & nx & ny & A1 & A2 & hh) ;
splits_one hh
| sCongPair _ _ _ _ _ _ =>
destruct (inversionCongPair h)
as (s & z & nx & ny & A1 & A2 & u1 & u2 & v1 & v2 & hh) ;
splits_one hh
| sCongPi1 _ _ _ _ _ =>
destruct (inversionCongPi1 h)
as (s & z & nx & ny & A1 & A2 & p1 & p2 & hh) ;
splits_one hh
| sCongPi2 _ _ _ _ _ =>
destruct (inversionCongPi2 h)
as (s & z & nx & ny & A1 & A2 & p1 & p2 & hh) ;
splits_one hh
| sCongEq _ _ _ =>
destruct (inversionCongEq h) as (s & A1 & A2 & u1 & u2 & v1 & v2 & hh) ;
splits_one hh
| sCongRefl _ _ =>
destruct (inversionCongRefl h) as (s & A1 & A2 & u1 & u2 & hh) ;
splits_one hh
| sEqToHeq _ =>
destruct (inversionEqToHeq h) as (A & u & v & s & hh) ;
splits_one hh
| sHeqTypeEq _ _ _ =>
destruct (inversionHeqTypeEq h) as (u & v & s & hh) ;
splits_one hh
| sPack _ _ => destruct (inversionPack h) as (s & hh) ; splits_one hh
| sProjT1 _ =>
destruct (inversionProjT1 h) as (s & A1 & A2 & hh) ; splits_one hh
| sProjT2 _ =>
destruct (inversionProjT2 h) as (s & A1 & A2 & hh) ; splits_one hh
| sProjTe _ =>
destruct (inversionProjTe h) as (s & A1 & A2 & hh) ; splits_one hh
| sAx _ => destruct (inversionAx h) as [ty hh] ; splits_one hh
end
end.