diff -r 6088fea1c8b1 -r 8a1c8dc72b5c LFex.thy --- a/LFex.thy Mon Dec 07 14:00:36 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,307 +0,0 @@ -theory LFex -imports Nominal QuotMain -begin - -atom_decl name ident - -nominal_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" - -function - fv_kind :: "kind \ name set" -and fv_ty :: "ty \ name set" -and fv_trm :: "trm \ name set" -where - "fv_kind (Type) = {}" -| "fv_kind (KPi A x K) = (fv_ty A) \ ((fv_kind K) - {x})" -| "fv_ty (TConst i) = {}" -| "fv_ty (TApp A M) = (fv_ty A) \ (fv_trm M)" -| "fv_ty (TPi A x B) = (fv_ty A) \ ((fv_ty B) - {x})" -| "fv_trm (Const i) = {}" -| "fv_trm (Var x) = {x}" -| "fv_trm (App M N) = (fv_trm M) \ (fv_trm N)" -| "fv_trm (Lam A x M) = (fv_ty A) \ ((fv_trm M) - {x})" -sorry - -termination fv_kind sorry - -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)" -| a21: "\A \ty A'; K \ki K'\ \ (KPi A x K) \ki (KPi A' x K')" -| a22: "\A \ty A'; K \ki ([(x,x')]\K'); x \ (fv_ty A'); x \ ((fv_kind K') - {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')" -| a51: "\A \ty A'; B \ty B'\ \ (TPi A x B) \ty (TPi A' x B')" -| a52: "\A \ty A'; B \ty ([(x,x')]\B'); x \ (fv_ty B'); x \ ((fv_ty B') - {x'})\ - \ (TPi A x B) \ty (TPi A' x' B')" -| a6: "i = j \ (Const i) \trm (Const j)" -| a7: "x = y \ (Var x) \trm (Var y)" -| a8: "\M \trm M'; N \tr N'\ \ (App M N) \tr (App M' N')" -| a91: "\A \ty A'; M \tr M'\ \ (Lam A x M) \tr (Lam A' x M')" -| a92: "\A \ty A'; M \tr ([(x,x')]\M'); x \ (fv_ty B'); x \ ((fv_trm M') - {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) - done - -lemma alpha_equivps: - shows "equivp akind" - and "equivp aty" - and "equivp atrm" -sorry - -quotient KIND = kind / akind - by (rule alpha_equivps) - -quotient TY = ty / aty - and TRM = trm / atrm - by (auto intro: alpha_equivps) - -print_quotients - -quotient_def - TYP :: "KIND" -where - "TYP \ Type" - -quotient_def - KPI :: "TY \ name \ KIND \ KIND" -where - "KPI \ KPi" - -quotient_def - TCONST :: "ident \ TY" -where - "TCONST \ TConst" - -quotient_def - TAPP :: "TY \ TRM \ TY" -where - "TAPP \ TApp" - -quotient_def - TPI :: "TY \ name \ TY \ TY" -where - "TPI \ TPi" - -(* FIXME: does not work with CONST *) -quotient_def - CONS :: "ident \ TRM" -where - "CONS \ Const" - -quotient_def - VAR :: "name \ TRM" -where - "VAR \ Var" - -quotient_def - APP :: "TRM \ TRM \ TRM" -where - "APP \ App" - -quotient_def - LAM :: "TY \ name \ TRM \ TRM" -where - "LAM \ Lam" - -thm TYP_def -thm KPI_def -thm TCONST_def -thm TAPP_def -thm TPI_def -thm VAR_def -thm CONS_def -thm APP_def -thm LAM_def - -(* FIXME: print out a warning if the type contains a liftet type, like kind \ name set *) -quotient_def - FV_kind :: "KIND \ name set" -where - "FV_kind \ fv_kind" - -quotient_def - FV_ty :: "TY \ name set" -where - "FV_ty \ fv_ty" - -quotient_def - FV_trm :: "TRM \ name set" -where - "FV_trm \ fv_trm" - -thm FV_kind_def -thm FV_ty_def -thm FV_trm_def - -(* FIXME: does not work yet *) -overloading - perm_kind \ "perm :: 'x prm \ KIND \ KIND" (unchecked) - perm_ty \ "perm :: 'x prm \ TY \ TY" (unchecked) - perm_trm \ "perm :: 'x prm \ TRM \ TRM" (unchecked) -begin - -quotient_def - perm_kind :: "'x prm \ KIND \ KIND" -where - "perm_kind \ (perm::'x prm \ kind \ kind)" - -quotient_def - perm_ty :: "'x prm \ TY \ TY" -where - "perm_ty \ (perm::'x prm \ ty \ ty)" - -quotient_def - perm_trm :: "'x prm \ TRM \ TRM" -where - "perm_trm \ (perm::'x prm \ trm \ trm)" - -(* TODO/FIXME: Think whether these RSP theorems are true. *) -lemma kpi_rsp[quotient_rsp]: - "(aty ===> op = ===> akind ===> akind) KPi KPi" sorry -lemma tconst_rsp[quotient_rsp]: - "(op = ===> aty) TConst TConst" sorry -lemma tapp_rsp[quotient_rsp]: - "(aty ===> atrm ===> aty) TApp TApp" sorry -lemma tpi_rsp[quotient_rsp]: - "(aty ===> op = ===> aty ===> aty) TPi TPi" sorry -lemma var_rsp[quotient_rsp]: - "(op = ===> atrm) Var Var" sorry -lemma app_rsp[quotient_rsp]: - "(atrm ===> atrm ===> atrm) App App" sorry -lemma const_rsp[quotient_rsp]: - "(op = ===> atrm) Const Const" sorry -lemma lam_rsp[quotient_rsp]: - "(aty ===> op = ===> atrm ===> atrm) Lam Lam" sorry - -lemma perm_kind_rsp[quotient_rsp]: - "(op = ===> akind ===> akind) op \ op \" sorry -lemma perm_ty_rsp[quotient_rsp]: - "(op = ===> aty ===> aty) op \ op \" sorry -lemma perm_trm_rsp[quotient_rsp]: - "(op = ===> atrm ===> atrm) op \ op \" sorry - -lemma fv_ty_rsp[quotient_rsp]: - "(aty ===> op =) fv_ty fv_ty" sorry -lemma fv_kind_rsp[quotient_rsp]: - "(akind ===> op =) fv_kind fv_kind" sorry -lemma fv_trm_rsp[quotient_rsp]: - "(atrm ===> op =) fv_trm fv_trm" sorry - - -thm akind_aty_atrm.induct -thm kind_ty_trm.induct - -ML {* - val quot = @{thms Quotient_KIND Quotient_TY Quotient_TRM} - val rel_refl = map (fn x => @{thm equivp_reflp} OF [x]) @{thms alpha_equivps} - val reps_same = map (fn x => @{thm Quotient_rel_rep} OF [x]) quot - val trans2 = map (fn x => @{thm equals_rsp} OF [x]) quot -*} - -lemma - assumes a0: - "P1 TYP TYP" - and a1: - "\A A' K K' x. \(A::TY) = A'; P2 A A'; (K::KIND) = K'; P1 K K'\ - \ P1 (KPI A x K) (KPI A' x K')" - and a2: - "\A A' K K' x x'. \(A ::TY) = A'; P2 A A'; (K :: KIND) = ([(x, x')] \ K'); P1 K ([(x, x')] \ K'); - x \ FV_ty A'; x \ FV_kind K' - {x'}\ \ P1 (KPI A x K) (KPI A' x' K')" - and a3: - "\i j. i = j \ P2 (TCONST i) (TCONST j)" - and a4: - "\A A' M M'. \(A ::TY) = A'; P2 A A'; (M :: TRM) = M'; P3 M M'\ \ P2 (TAPP A M) (TAPP A' M')" - and a5: - "\A A' B B' x. \(A ::TY) = A'; P2 A A'; (B ::TY) = B'; P2 B B'\ \ P2 (TPI A x B) (TPI A' x B')" - and a6: - "\A A' B x x' B'. \(A ::TY) = A'; P2 A A'; (B ::TY) = ([(x, x')] \ B'); P2 B ([(x, x')] \ B'); - x \ FV_ty B'; x \ FV_ty B' - {x'}\ \ P2 (TPI A x B) (TPI A' x' B')" - and a7: - "\i j m. i = j \ P3 (CONS i) (m (CONS j))" - and a8: - "\x y m. x = y \ P3 (VAR x) (m (VAR y))" - and a9: - "\M m M' N N'. \(M :: TRM) = m M'; P3 M (m M'); (N :: TRM) = N'; P3 N N'\ \ P3 (APP M N) (APP M' N')" - and a10: - "\A A' M M' x. \(A ::TY) = A'; P2 A A'; (M :: TRM) = M'; P3 M M'\ \ P3 (LAM A x M) (LAM A' x M')" - and a11: - "\A A' M x x' M' B'. \(A ::TY) = A'; P2 A A'; (M :: TRM) = ([(x, x')] \ M'); P3 M ([(x, x')] \ M'); - x \ FV_ty B'; x \ FV_trm M' - {x'}\ \ P3 (LAM A x M) (LAM A' x' M')" - shows "((x1 :: KIND) = x2 \ P1 x1 x2) \ - ((x3 ::TY) = x4 \ P2 x3 x4) \ - ((x5 :: TRM) = x6 \ P3 x5 x6)" -using a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 -apply - -apply(tactic {* procedure_tac @{context} @{thm akind_aty_atrm.induct} 1 *}) -apply(tactic {* regularize_tac @{context} 1 *}) -apply(tactic {* all_inj_repabs_tac @{context} rel_refl trans2 1 *}) -apply(fold perm_kind_def perm_ty_def perm_trm_def) -apply(tactic {* clean_tac @{context} 1 *}) -(* -Profiling: -ML_prf {* fun ith i = (#concl (fst (Subgoal.focus @{context} i (#goal (Isar.goal ()))))) *} -ML_prf {* profile 2 Seq.list_of ((clean_tac @{context} quot defs 1) (ith 3)) *} -ML_prf {* profile 2 Seq.list_of ((regularize_tac @{context} @{thms alpha_equivps} 1) (ith 1)) *} -ML_prf {* PolyML.profiling 1 *} -ML_prf {* profile 2 Seq.list_of ((all_inj_repabs_tac @{context} quot rel_refl trans2 1) (#goal (Isar.goal ()))) *} -*) -done - -(* Does not work: -lemma - assumes a0: "P1 TYP" - and a1: "\ty name kind. \P2 ty; P1 kind\ \ P1 (KPI ty name kind)" - and a2: "\id. P2 (TCONST id)" - and a3: "\ty trm. \P2 ty; P3 trm\ \ P2 (TAPP ty trm)" - and a4: "\ty1 name ty2. \P2 ty1; P2 ty2\ \ P2 (TPI ty1 name ty2)" - and a5: "\id. P3 (CONS id)" - and a6: "\name. P3 (VAR name)" - and a7: "\trm1 trm2. \P3 trm1; P3 trm2\ \ P3 (APP trm1 trm2)" - and a8: "\ty name trm. \P2 ty; P3 trm\ \ P3 (LAM ty name trm)" - shows "P1 mkind \ P2 mty \ P3 mtrm" -using a0 a1 a2 a3 a4 a5 a6 a7 a8 -*) - -lemma "\P TYP; - \ty name kind. \Q ty; P kind\ \ P (KPI ty name kind); - \id. Q (TCONST id); - \ty trm. \Q ty; R trm\ \ Q (TAPP ty trm); - \ty1 name ty2. \Q ty1; Q ty2\ \ Q (TPI ty1 name ty2); - \id. R (CONS id); \name. R (VAR name); - \trm1 trm2. \R trm1; R trm2\ \ R (APP trm1 trm2); - \ty name trm. \Q ty; R trm\ \ R (LAM ty name trm)\ - \ P mkind \ Q mty \ R mtrm" -apply(tactic {* lift_tac @{context} @{thm kind_ty_trm.induct} 1 *}) -done - -print_quotients - -end - - -