diff -r 8e2dd0b29466 -r ef8a2b0b237a Quot/Nominal/LFex.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Quot/Nominal/LFex.thy Thu Jan 28 19:23:55 2010 +0100 @@ -0,0 +1,328 @@ +theory LFex +imports "Nominal2_Atoms" "Nominal2_Eqvt" "Nominal2_Supp" "../QuotMain" +begin + +atom_decl name +atom_decl ident + +datatype kind = + Type + | KPi "ty" "name" "kind" +and ty = + TConst "ident" + | TApp "ty" "trm" + | TPi "ty" "name" "ty" +and trm = + Const "ident" + | Var "name" + | App "trm" "trm" + | Lam "ty" "name" "trm" + +fun + rfv_kind :: "kind \ atom set" +and rfv_ty :: "ty \ atom set" +and rfv_trm :: "trm \ atom set" +where + "rfv_kind (Type) = {}" +| "rfv_kind (KPi A x K) = (rfv_ty A) \ ((rfv_kind K) - {atom x})" +| "rfv_ty (TConst i) = {}" +| "rfv_ty (TApp A M) = (rfv_ty A) \ (rfv_trm M)" +| "rfv_ty (TPi A x B) = (rfv_ty A) \ ((rfv_ty B) - {atom x})" +| "rfv_trm (Const i) = {}" +| "rfv_trm (Var x) = {atom x}" +| "rfv_trm (App M N) = (rfv_trm M) \ (rfv_trm N)" +| "rfv_trm (Lam A x M) = (rfv_ty A) \ ((rfv_trm M) - {atom x})" + +instantiation kind and ty and trm :: pt +begin + +primrec + permute_kind +and permute_ty +and permute_trm +where + "permute_kind pi Type = Type" +| "permute_kind pi (KPi t n k) = KPi (permute_ty pi t) (pi \ n) (permute_kind pi k)" +| "permute_ty pi (TConst i) = TConst (pi \ i)" +| "permute_ty pi (TApp A M) = TApp (permute_ty pi A) (permute_trm pi M)" +| "permute_ty pi (TPi A x B) = TPi (permute_ty pi A) (pi \ x) (permute_ty pi B)" +| "permute_trm pi (Const i) = Const (pi \ i)" +| "permute_trm pi (Var x) = Var (pi \ x)" +| "permute_trm pi (App M N) = App (permute_trm pi M) (permute_trm pi N)" +| "permute_trm pi (Lam A x M) = Lam (permute_ty pi A) (pi \ x) (permute_trm pi M)" + +lemma rperm_zero_ok: "0 \ (x :: kind) = x \ 0 \ (y :: ty) = y \ 0 \ (z :: trm) = z" +apply(induct_tac rule: kind_ty_trm.induct) +apply(simp_all) +done +instance +apply default +apply (simp_all only:rperm_zero_ok) +apply(induct_tac [!] x) +apply(simp_all) +apply(induct_tac ty) +apply(simp_all) +apply(induct_tac trm) +apply(simp_all) +apply(induct_tac trm) +apply(simp_all) +done + +end + +inductive + akind :: "kind \ kind \ bool" ("_ \ki _" [100, 100] 100) +and aty :: "ty \ ty \ bool" ("_ \ty _" [100, 100] 100) +and atrm :: "trm \ trm \ bool" ("_ \tr _" [100, 100] 100) +where + a1: "(Type) \ki (Type)" +| a2: "\A \ty A'; \pi. (rfv_kind K - {atom x} = rfv_kind K' - {atom x'} \ (rfv_kind K - {atom x})\* pi \ (pi \ K) \ki K' \ (pi \ x) = x')\ \ (KPi A x K) \ki (KPi A' x' K')" +| a3: "i = j \ (TConst i) \ty (TConst j)" +| a4: "\A \ty A'; M \tr M'\ \ (TApp A M) \ty (TApp A' M')" +| a5: "\A \ty A'; \pi. (rfv_ty B - {atom x} = rfv_ty B' - {atom x'} \ (rfv_ty B - {atom x})\* pi \ (pi \ B) \ty B' \ (pi \ x) = x')\ \ (TPi A x B) \ty (TPi A' x' B')" +| a6: "i = j \ (Const i) \tr (Const j)" +| a7: "x = y \ (Var x) \tr (Var y)" +| a8: "\M \tr M'; N \tr N'\ \ (App M N) \tr (App M' N')" +| a9: "\A \ty A'; \pi. (rfv_trm M - {atom x} = rfv_trm M' - {atom x'} \ (rfv_trm M - {atom x})\* pi \ (pi \ M) \tr M' \ (pi \ x) = x')\ \ (Lam A x M) \tr (Lam A' x' M')" + +lemma al_refl: + fixes K::"kind" + and A::"ty" + and M::"trm" + shows "K \ki K" + and "A \ty A" + and "M \tr M" + apply(induct K and A and M rule: kind_ty_trm.inducts) + apply(auto intro: akind_aty_atrm.intros) + apply (rule a2) + apply auto + apply(rule_tac x="0" in exI) + apply(simp_all add: fresh_star_def fresh_zero_perm) + apply (rule a5) + apply auto + apply(rule_tac x="0" in exI) + apply(simp_all add: fresh_star_def fresh_zero_perm) + apply (rule a9) + apply auto + apply(rule_tac x="0" in exI) + apply(simp_all add: fresh_star_def fresh_zero_perm) + done + +lemma alpha_equivps: + shows "equivp akind" + and "equivp aty" + and "equivp atrm" +sorry + +quotient_type KIND = kind / akind + by (rule alpha_equivps) + +quotient_type + TY = ty / aty and + TRM = trm / atrm + by (auto intro: alpha_equivps) + +quotient_definition + "TYP :: KIND" +as + "Type" + +quotient_definition + "KPI :: TY \ name \ KIND \ KIND" +as + "KPi" + +quotient_definition + "TCONST :: ident \ TY" +as + "TConst" + +quotient_definition + "TAPP :: TY \ TRM \ TY" +as + "TApp" + +quotient_definition + "TPI :: TY \ name \ TY \ TY" +as + "TPi" + +(* FIXME: does not work with CONST *) +quotient_definition + "CONS :: ident \ TRM" +as + "Const" + +quotient_definition + "VAR :: name \ TRM" +as + "Var" + +quotient_definition + "APP :: TRM \ TRM \ TRM" +as + "App" + +quotient_definition + "LAM :: TY \ name \ TRM \ TRM" +as + "Lam" + +(* FIXME: print out a warning if the type contains a liftet type, like kind \ name set *) +quotient_definition + "fv_kind :: KIND \ atom set" +as + "rfv_kind" + +quotient_definition + "fv_ty :: TY \ atom set" +as + "rfv_ty" + +quotient_definition + "fv_trm :: TRM \ atom set" +as + "rfv_trm" + +thm akind_aty_atrm.induct +lemma alpha_rfv: + shows "(t \ki s \ rfv_kind t = rfv_kind s) \ + (t1 \ty s1 \ rfv_ty t1 = rfv_ty s1) \ + (t2 \tr s2 \ rfv_trm t2 = rfv_trm s2)" + apply(rule akind_aty_atrm.induct) + apply(simp_all) + done + +lemma perm_rsp[quot_respect]: + "(op = ===> akind ===> akind) permute permute" + "(op = ===> aty ===> aty) permute permute" + "(op = ===> atrm ===> atrm) permute permute" +apply simp_all +sorry (* by eqvt *) + +lemma kpi_rsp[quot_respect]: + "(aty ===> op = ===> akind ===> akind) KPi KPi" + apply (auto intro: a1 a2 a3 a4 a5 a6 a7 a8 a9) sorry +lemma tconst_rsp[quot_respect]: + "(op = ===> aty) TConst TConst" + apply (auto intro: a1 a2 a3 a4 a5 a6 a7 a8 a9) done +lemma tapp_rsp[quot_respect]: + "(aty ===> atrm ===> aty) TApp TApp" + apply (auto intro: a1 a2 a3 a4 a5 a6 a7 a8 a9) done +lemma tpi_rsp[quot_respect]: + "(aty ===> op = ===> aty ===> aty) TPi TPi" + apply (auto intro: a1 a2 a3 a4 a5 a6 a7 a8 a9) sorry +lemma var_rsp[quot_respect]: + "(op = ===> atrm) Var Var" + apply (auto intro: a1 a2 a3 a4 a5 a6 a7 a8 a9) done +lemma app_rsp[quot_respect]: + "(atrm ===> atrm ===> atrm) App App" + apply (auto intro: a1 a2 a3 a4 a5 a6 a7 a8 a9) done +lemma const_rsp[quot_respect]: + "(op = ===> atrm) Const Const" + apply (auto intro: a1 a2 a3 a4 a5 a6 a7 a8 a9) done +lemma lam_rsp[quot_respect]: + "(aty ===> op = ===> atrm ===> atrm) Lam Lam" + apply (auto intro: a1 a2 a3 a4 a5 a6 a7 a8 a9) sorry +lemma rfv_ty_rsp[quot_respect]: + "(aty ===> op =) rfv_ty rfv_ty" + by (simp add: alpha_rfv) +lemma rfv_kind_rsp[quot_respect]: + "(akind ===> op =) rfv_kind rfv_kind" + by (simp add: alpha_rfv) +lemma rfv_trm_rsp[quot_respect]: + "(atrm ===> op =) rfv_trm rfv_trm" + by (simp add: alpha_rfv) + +thm akind_aty_atrm.induct +thm kind_ty_trm.induct + +lemma KIND_TY_TRM_induct: "\P10 TYP; \ty name kind. \P20 ty; P10 kind\ \ P10 (KPI ty name kind); \ident. P20 (TCONST ident); + \ty trm. \P20 ty; P30 trm\ \ P20 (TAPP ty trm); + \ty1 name ty2. \P20 ty1; P20 ty2\ \ P20 (TPI ty1 name ty2); \ident. P30 (CONS ident); + \name. P30 (VAR name); \trm1 trm2. \P30 trm1; P30 trm2\ \ P30 (APP trm1 trm2); + \ty name trm. \P20 ty; P30 trm\ \ P30 (LAM ty name trm)\ +\ P10 kind \ P20 ty \ P30 trm" +by (lifting kind_ty_trm.induct) + +instantiation KIND and TY and TRM :: pt +begin + +quotient_definition + "permute_KIND :: perm \ KIND \ KIND" +as + "permute :: perm \ kind \ kind" + +quotient_definition + "permute_TY :: perm \ TY \ TY" +as + "permute :: perm \ ty \ ty" + +quotient_definition + "permute_TRM :: perm \ TRM \ TRM" +as + "permute :: perm \ trm \ trm" + +term "permute_TRM" +thm permute_kind_permute_ty_permute_trm.simps +lemma [simp]: +shows "pi \ TYP = TYP" +and "pi \ (KPI t n k) = KPI (pi \ t) (pi \ n) (pi \ k)" +and "pi \ (TCONST i) = TCONST (pi \ i)" +and "pi \ (TAPP A M) = TAPP (pi \ A) (pi \ M)" +and "pi \ (TPI A x B) = TPI (pi \ A) (pi \ x) (pi \ B)" +and "pi \ (CONS i) = CONS (pi \ i)" +and "pi \ (VAR x) = VAR (pi \ x)" +and "pi \ (APP M N) = APP (pi \ M) (pi \ N)" +and "pi \ (LAM A x M) = LAM (pi \ A) (pi \ x) (pi \ M)" +apply (lifting permute_kind_permute_ty_permute_trm.simps) +done + +lemma perm_zero_ok: "0 \ (x :: KIND) = x \ 0 \ (y :: TY) = y \ 0 \ (z :: TRM) = z" +apply (induct rule: KIND_TY_TRM_induct) +apply simp_all +done + +lemma perm_add_ok: "((p1 + q1) \ (x1 :: KIND) = (p1 \ q1 \ (x1 :: KIND))) \ ((p2 + q2) \ (x2 :: TY) = p2 \ q2 \ x2) \ ((p3 + q3) \ (x3 :: TRM) = p3 \ q3 \ x3)" +apply(induct_tac [!] rule: KIND_TY_TRM_induct) +apply (simp_all) +(* Sth went wrong... *) +sorry + +instance +apply default +apply (simp_all add: perm_zero_ok perm_add_ok) +done + +end + +lemma "\P10 TYP TYP; + \A A' K x K' x'. + \(A :: TY) = A'; P20 A A'; + \pi. fv_kind K - {atom x} = fv_kind K' - {atom x'} \ + (fv_kind K - {atom x}) \* pi \ ((pi \ K) = K' \ P10 (pi \ K) K') \ pi \ x = x'\ + \ P10 (KPI A x K) (KPI A' x' K'); + \i j. i = j \ P20 (TCONST i) (TCONST j); + \A A' M M'. \A = A'; P20 A A'; M = M'; P30 M M'\ \ P20 (TAPP A M) (TAPP A' M'); + \A A' B x B' x'. + \A = A'; P20 A A'; + \pi. fv_ty B - {atom x} = fv_ty B' - {atom x'} \ + (fv_ty B - {atom x}) \* pi \ ((pi \ B) = B' \ P20 (pi \ B) B') \ pi \ x = x'\ + \ P20 (TPI A x B) (TPI A' x' B'); + \i j. i = j \ P30 (CONS i) (CONS j); \x y. x = y \ P30 (VAR x) (VAR y); + \M M' N N'. \M = M'; P30 M M'; N = N'; P30 N N'\ \ P30 (APP M N) (APP M' N'); + \A A' M x M' x'. + \A = A'; P20 A A'; + \pi. fv_trm M - {atom x} = fv_trm M' - {atom x'} \ + (fv_trm M - {atom x}) \* pi \ ((pi \ M) = M' \ P30 (pi \ M) M') \ pi \ x = x'\ + \ P30 (LAM A x M) (LAM A' x' M')\ +\ (x10 = x20 \ P10 x10 x20) \ + (x30 = x40 \ P20 x30 x40) \ (x50 = x60 \ P30 x50 x60)" +apply (lifting akind_aty_atrm.induct) +done + +end + + + +