1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti, C.Sacerdoti Coen, *)
8 (* ||A|| E.Tassi, S.Zacchiroli *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 include "PTS/subst.ma".
17 (*************************** substl *****************************)
19 nlet rec substl (G:list T) (N:T) : list T ≝
22 | cons A D ⇒ ((subst A (length T D) N)::(substl D N))
26 nlemma substl_cons: ∀A,N.∀G.
27 substl (A::G) N = (subst_aux A (length T G) N)::(substl G N).
32 nlemma length_cons: ∀A.∀G. length T (A::G) = length T G + 1.
35 (****************************************************************)
37 naxiom A: nat → nat → Prop.
38 naxiom R: nat → nat → nat → Prop.
39 naxiom conv: T → T → Prop.
41 ninductive TJ: list T → T → T → Prop ≝
42 | ax : ∀i,j. A i j → TJ (nil T) (Sort i) (Sort j)
43 | start: ∀G.∀A.∀i.TJ G A (Sort i) → TJ (A::G) (Rel 0) (lift A 0 1)
45 TJ G A B → TJ G C (Sort i) → TJ (C::G) (lift A 0 1) (lift B 0 1)
46 | prod: ∀G.∀A,B.∀i,j,k. R i j k →
47 TJ G A (Sort i) → TJ (A::G) B (Sort j) → TJ G (Prod A B) (Sort k)
49 TJ G F (Prod A B) → TJ G a A → TJ G (App F a) (subst B 0 a)
51 TJ (A::G) b B → TJ G (Prod A B) (Sort i) → TJ G (Lambda A b) (Prod A B)
52 | conv: ∀G.∀A,B,C.∀i. conv B C →
53 TJ G A B → TJ G B (Sort i) → TJ G A C.
55 notation "hvbox(G break ⊢ A : B)" non associative with precedence 55 for @{'TJ $G $A $B}.
56 interpretation "type judgement" 'TJ G A B = (TJ G A B).
58 (* ninverter TJ_inv2 for TJ (%?%) : Prop. *)
60 (**** definitions ****)
62 ninductive Glegal (G: list T) : Prop ≝
63 glegalk : ∀A,B. G ⊢ A : B → Glegal G.
65 ninductive Gterm (G: list T) (A:T) : Prop ≝
66 | is_term: ∀B.G ⊢ A:B → Gterm G A
67 | is_type: ∀B.G ⊢ B:A → Gterm G A.
69 ninductive Gtype (G: list T) (A:T) : Prop ≝
70 gtypek: ∀i.G ⊢ A : Sort i → Gtype G A.
72 ninductive Gelement (G:list T) (A:T) : Prop ≝
73 gelementk: ∀B.G ⊢ A:B → Gtype G B → Gelement G A.
75 ninductive Tlegal (A:T) : Prop ≝
76 tlegalk: ∀G. Gterm G A → Tlegal A.
79 ndefinition Glegal ≝ λG: list T.∃A,B:T.TJ G A B .
81 ndefinition Gterm ≝ λG: list T.λA.∃B.TJ G A B ∨ TJ G B A.
83 ndefinition Gtype ≝ λG: list T.λA.∃i.TJ G A (Sort i).
85 ndefinition Gelement ≝ λG: list T.λA.∃B.TJ G A B ∨ Gtype G B.
87 ndefinition Tlegal ≝ λA:T.∃G: list T.Gterm G A.
91 ntheorem free_var1: ∀G.∀A,B,C. TJ G A B →
93 #G; #i; #j; #axij; #Gleg; ncases Gleg;
94 #A; #B; #tjAB; nelim tjAB; /2/; (* bello *) nqed.
97 ntheorem start_lemma1: ∀G.∀i,j.
98 A i j → Glegal G → G ⊢ Sort i: Sort j.
99 #G; #i; #j; #axij; #Gleg; ncases Gleg;
100 #A; #B; #tjAB; nelim tjAB; /2/;
103 ntheorem start_rel: ∀G.∀A.∀C.∀n,i,q.
104 G ⊢ C: Sort q → G ⊢ Rel n: lift A 0 i → (C::G) ⊢ Rel (S n): lift A 0 (S i).
105 #G; #A; #C; #n; #i; #p; #tjC; #tjn;
106 napplyS (weak G (Rel n));//. (* bello *)
108 nrewrite > (plus_n_O i);
109 nrewrite > (plus_n_Sm i O);
110 nrewrite < (lift_lift A 1 i);
111 nrewrite > (plus_n_O n); nrewrite > (plus_n_Sm n O);
112 applyS (weak G (Rel n) (lift A i) C p tjn tjC). *)
115 ntheorem start_lemma2: ∀G.
116 Glegal G → ∀n. n < |G| → G ⊢ Rel n: lift (nth n T G (Rel O)) 0 (S n).
117 #G; #Gleg; ncases Gleg; #A; #B; #tjAB; nelim tjAB; /2/;
118 ##[#i; #j; #axij; #p; nnormalize; #abs; napply False_ind;
119 napply (absurd … abs); //;
120 ##|#G; #A; #i; #tjA; #Hind; #m; ncases m; /2/;
121 #p; #Hle; napply start_rel; //; napply Hind;
122 napply le_S_S_to_le; napply Hle;
123 ##|#G; #A; #B; #C; #i; #tjAB; #tjC; #Hind1; #_; #m; ncases m;
124 /2/; #p; #Hle; napply start_rel; //;
125 napply Hind1; napply le_S_S_to_le; napply Hle;
130 nlet rec TJm G D on D : Prop ≝
133 | cons A D1 ⇒ TJ G (Rel 0) A ∧ TJm G D1
136 nlemma tjm1: ∀G,D.∀A. TJm G (A::D) → TJ G (Rel 0) A.
137 #G; #D; #A; *; //; nqed.
139 ntheorem transitivity_tj: ∀D.∀A,B. TJ D A B →
140 ∀G. Glegal G → TJm G D → TJ G A B.
141 #D; #A; #B; #tjAB; nelim tjAB;
144 ##|#E; #T; #T0; #T1; #n; #tjT; #tjT1; #H; #H1; #G; #HlegG;
149 ntheorem substitution_tj:
150 ∀G.∀A,B,N,M.TJ (A::G) M B → TJ G N A →
151 TJ G (subst N M) (subst N B).
153 napply (TJ_inv2 (A::G) M B);
155 ##|#G; #A; #N; #tjA; #Hind; #Heq;
157 ##|#G; #A; #B; #C; #n; #tjA; #tjC; #Hind1; #Hind2; #Heq;
159 ##|nnormalize; #E; #A; #B; #i; #j; #k;
160 #Ax; #tjA; #tjB; #Hind1; #_;
161 #Heq; #HeqB; #tjN; napply (prod ?????? Ax);
163 ##|nnormalize; napplyS weak;
167 ntheorem substitution_tj:
168 ∀E.∀A,B,M. E ⊢M:B → ∀G,D.∀N. E = D@A::G → G ⊢ N:A →
169 ((substl D N)@G) ⊢ M[|D| ← N]: B[|D| ← N].
170 #E; #A; #B; #M; #tjMB; nelim tjMB;
171 ##[nnormalize; #i; #j; #k; #G; #D; #N; ncases D;
172 ##[nnormalize; #isnil; ndestruct;
173 ##|#P; #L; nnormalize; #isnil; ndestruct;
175 ##|#G; #A1; #i; #tjA; #Hind; #G1; #D; ncases D;
177 nrewrite > (delift (lift N O O) A1 O O O ??); //;
178 nnormalize in Heq; ndestruct;/2/;
179 ##|#H; #L; #N1; #Heq; nnormalize in Heq;
180 #tjN1; nnormalize; ndestruct;
183 ##|#G; #P; #Q; #R; #i; #tjP; #tjR; #Hind1; #Hind2;
184 #G1; #D; #N; ncases D; nnormalize;
185 ##[#Heq; ndestruct; #tjN; //;
188 (* napplyS weak non va *)
189 ncut (S (length T L) = (length T L)+0+1); ##[//##] #Heq;
192 ##|#G; #P; #Q; #i; #j; #k; #Ax; #tjP; #tjQ; #Hind1; #Hind2;
193 #G1; #D; #N; #Heq; #tjN; nnormalize;
196 ##|ncut (S (length T D) = (length T D)+1); ##[//##] #Heq1;
198 napply (Hind2 ? (P::D));nnormalize;//;
200 ##|#G; #P; #Q; #R; #S; #tjP; #tjS; #Hind1; #Hind2;
201 #G1; #D; #N; #Heq; #tjN; nnormalize in Hind1 ⊢ %;
202 nrewrite > (plus_n_O (length ? D)) in ⊢ (? ? ? (? ? % ?));
203 nrewrite > (subst_lemma R S N ? 0);
205 ##|#G; #P; #Q; #R; #i; #tjR; #tjProd; #Hind1; #Hind2;
206 #G1; #D; #N; #Heq; #tjN; nnormalize;
208 ##[nnormalize in Hind2; /2/;
209 ##|(* napplyS (Hind1 G1 (P::D) N ? tjN); sistemare *)
210 ngeneralize in match (Hind1 G1 (P::D) N ? tjN);
211 ##[#H; nnormalize in H; napplyS H;##|nnormalize; //##]