forked from MetaCoq/metacoq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCUICInversion.v
288 lines (261 loc) · 8.1 KB
/
PCUICInversion.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
(* Distributed under the terms of the MIT license. *)
From Equations Require Import Equations.
From Coq Require Import Bool String List Program BinPos Compare_dec Omega.
From MetaCoq.Template Require Import config utils.
From MetaCoq.PCUIC Require Import PCUICAst PCUICAstUtils PCUICInduction
PCUICLiftSubst PCUICUnivSubst PCUICTyping PCUICWeakeningEnv PCUICWeakening
PCUICSubstitution PCUICClosed PCUICCumulativity PCUICConversion PCUICGeneration.
Require Import ssreflect ssrbool.
Require Import String.
From MetaCoq Require Import LibHypsNaming.
Local Open Scope string_scope.
Set Asymmetric Patterns.
From Equations Require Import Equations.
Require Import Equations.Prop.DepElim.
Set Equations With UIP.
Section Inversion.
Context `{checker_flags}.
Context (Σ : global_env_ext).
Context (wfΣ : wf Σ).
Ltac insum :=
match goal with
| |- ∑ x : _, _ =>
eexists
end.
Ltac intimes :=
match goal with
| |- _ × _ =>
split
end.
Ltac outsum :=
match goal with
| ih : ∑ x : _, _ |- _ =>
destruct ih as [? ?]
end.
Ltac outtimes :=
match goal with
| ih : _ × _ |- _ =>
destruct ih as [? ?]
end.
Ltac invtac h :=
dependent induction h ; [
repeat insum ;
repeat intimes ;
[ first [ eassumption | reflexivity ] .. | eapply cumul_refl' ]
| repeat outsum ;
repeat outtimes ;
repeat insum ;
repeat intimes ;
[ first [ eassumption | reflexivity ] ..
| eapply cumul_trans ; eassumption ]
].
Derive Signature for typing.
Lemma inversion_Rel :
forall {Γ n T},
Σ ;;; Γ |- tRel n : T ->
∑ decl,
wf_local Σ Γ ×
(nth_error Γ n = Some decl) ×
Σ ;;; Γ |- lift0 (S n) (decl_type decl) <= T.
Proof.
intros Γ n T h. invtac h.
Qed.
Lemma inversion_Var :
forall {Γ i T},
Σ ;;; Γ |- tVar i : T -> False.
Proof.
intros Γ i T h. dependent induction h. assumption.
Qed.
Lemma inversion_Evar :
forall {Γ n l T},
Σ ;;; Γ |- tEvar n l : T -> False.
Proof.
intros Γ n l T h. dependent induction h. assumption.
Qed.
Lemma inversion_Sort :
forall {Γ s T},
Σ ;;; Γ |- tSort s : T ->
∑ l,
wf_local Σ Γ ×
LevelSet.In l (global_ext_levels Σ) ×
(s = Universe.make l) ×
Σ ;;; Γ |- tSort (Universe.super l) <= T.
Proof.
intros Γ s T h. invtac h.
Qed.
Lemma inversion_Prod :
forall {Γ na A B T},
Σ ;;; Γ |- tProd na A B : T ->
∑ s1 s2,
Σ ;;; Γ |- A : tSort s1 ×
Σ ;;; Γ ,, vass na A |- B : tSort s2 ×
Σ ;;; Γ |- tSort (Universe.sort_of_product s1 s2) <= T.
Proof.
intros Γ na A B T h. invtac h.
Qed.
Lemma inversion_Lambda :
forall {Γ na A t T},
Σ ;;; Γ |- tLambda na A t : T ->
∑ s B,
Σ ;;; Γ |- A : tSort s ×
Σ ;;; Γ ,, vass na A |- t : B ×
Σ ;;; Γ |- tProd na A B <= T.
Proof.
intros Γ na A t T h. invtac h.
Qed.
Lemma inversion_LetIn :
forall {Γ na b B t T},
Σ ;;; Γ |- tLetIn na b B t : T ->
∑ s1 A,
Σ ;;; Γ |- B : tSort s1 ×
Σ ;;; Γ |- b : B ×
Σ ;;; Γ ,, vdef na b B |- t : A ×
Σ ;;; Γ |- tLetIn na b B A <= T.
Proof.
intros Γ na b B t T h. invtac h.
Qed.
Lemma inversion_App :
forall {Γ u v T},
Σ ;;; Γ |- tApp u v : T ->
∑ na A B,
Σ ;;; Γ |- u : tProd na A B ×
Σ ;;; Γ |- v : A ×
Σ ;;; Γ |- B{ 0 := v } <= T.
Proof.
intros Γ u v T h. invtac h.
Qed.
Lemma inversion_Const :
forall {Γ c u T},
Σ ;;; Γ |- tConst c u : T ->
∑ decl,
wf_local Σ Γ ×
declared_constant Σ c decl ×
(consistent_instance_ext Σ decl.(cst_universes) u) ×
Σ ;;; Γ |- subst_instance_constr u (cst_type decl) <= T.
Proof.
intros Γ c u T h. invtac h.
Qed.
Lemma inversion_Ind :
forall {Γ ind u T},
Σ ;;; Γ |- tInd ind u : T ->
∑ mdecl idecl,
wf_local Σ Γ ×
declared_inductive Σ mdecl ind idecl ×
consistent_instance_ext Σ (ind_universes mdecl) u ×
Σ ;;; Γ |- subst_instance_constr u idecl.(ind_type) <= T.
Proof.
intros Γ ind u T h. invtac h.
Qed.
Lemma inversion_Construct :
forall {Γ ind i u T},
Σ ;;; Γ |- tConstruct ind i u : T ->
∑ mdecl idecl cdecl,
wf_local Σ Γ ×
declared_constructor (fst Σ) mdecl idecl (ind, i) cdecl ×
consistent_instance_ext Σ (ind_universes mdecl) u ×
Σ;;; Γ |- type_of_constructor mdecl cdecl (ind, i) u <= T.
Proof.
intros Γ ind i u T h. invtac h.
Qed.
Lemma inversion_Case :
forall {Γ ind npar p c brs T},
Σ ;;; Γ |- tCase (ind, npar) p c brs : T ->
∑ u args mdecl idecl pty indctx pctx ps btys,
declared_inductive Σ mdecl ind idecl ×
ind_npars mdecl = npar ×
let pars := firstn npar args in
Σ ;;; Γ |- p : pty ×
types_of_case ind mdecl idecl pars u p pty =
Some (indctx, pctx, ps, btys) ×
check_correct_arity (global_ext_constraints Σ)
idecl ind u indctx pars pctx ×
existsb (leb_sort_family (universe_family ps)) (ind_kelim idecl) ×
Σ ;;; Γ |- c : mkApps (tInd ind u) args ×
All2 (fun x y =>
(fst x = fst y) *
(Σ ;;; Γ |- snd x : snd y) *
(Σ ;;; Γ |- snd y : tSort ps)
) brs btys ×
Σ ;;; Γ |- mkApps p (skipn npar args ++ [c]) <= T.
Proof.
intros Γ ind npar p c brs T h. invtac h.
Qed.
Lemma inversion_Proj :
forall {Γ p c T},
Σ ;;; Γ |- tProj p c : T ->
∑ u mdecl idecl pdecl args,
declared_projection Σ mdecl idecl p pdecl ×
Σ ;;; Γ |- c : mkApps (tInd (fst (fst p)) u) args ×
#|args| = ind_npars mdecl ×
let ty := snd pdecl in
Σ ;;; Γ |- (subst0 (c :: List.rev args)) (subst_instance_constr u ty)
<= T.
Proof.
intros Γ p c T h. invtac h.
Qed.
Lemma inversion_Fix :
forall {Γ mfix n T},
Σ ;;; Γ |- tFix mfix n : T ->
∑ decl,
let types := fix_context mfix in
fix_guard mfix ×
nth_error mfix n = Some decl ×
wf_local Σ (Γ ,,, types) ×
All (fun d =>
Σ ;;; Γ ,,, types |- dbody d : (lift0 #|types|) (dtype d) ×
isLambda (dbody d) = true
) mfix ×
Σ ;;; Γ |- dtype decl <= T.
Proof.
intros Γ mfix n T h. invtac h.
Qed.
Lemma inversion_CoFix :
forall {Γ mfix idx T},
Σ ;;; Γ |- tCoFix mfix idx : T ->
∑ decl,
allow_cofix ×
let types := fix_context mfix in
nth_error mfix idx = Some decl ×
wf_local Σ (Γ ,,, types) ×
All (fun d =>
Σ ;;; Γ ,,, types |- d.(dbody) : lift0 #|types| d.(dtype)
) mfix ×
Σ ;;; Γ |- decl.(dtype) <= T.
Proof.
intros Γ mfix idx T h. invtac h.
Qed.
Lemma inversion_it_mkLambda_or_LetIn :
forall {Γ Δ t T},
Σ ;;; Γ |- it_mkLambda_or_LetIn Δ t : T ->
∑ A,
Σ ;;; Γ ,,, Δ |- t : A ×
Σ ;;; Γ |- it_mkProd_or_LetIn Δ A <= T.
Proof.
intros Γ Δ t T h.
induction Δ as [| [na [b|] A] Δ ih ] in Γ, t, h |- *.
- eexists. split ; eauto.
- simpl. apply ih in h. cbn in h.
destruct h as [B [h c]].
apply inversion_LetIn in h as hh.
destruct hh as [s1 [A' [? [? [? ?]]]]].
exists A'. split ; eauto.
cbn. eapply cumul_trans ; try eassumption.
eapply cumul_it_mkProd_or_LetIn.
assumption.
- simpl. apply ih in h. cbn in h.
destruct h as [B [h c]].
apply inversion_Lambda in h as hh.
pose proof hh as [s1 [B' [? [? ?]]]].
exists B'. split ; eauto.
cbn. eapply cumul_trans ; try eassumption.
eapply cumul_it_mkProd_or_LetIn.
assumption.
Qed.
End Inversion.
Lemma destArity_it_mkProd_or_LetIn ctx ctx' t :
destArity ctx (it_mkProd_or_LetIn ctx' t) =
destArity (ctx ,,, ctx') t.
Proof.
induction ctx' in ctx, t |- *; simpl; auto.
rewrite IHctx'. destruct a as [na [b|] ty]; reflexivity.
Qed.