src/HOL/Lambda/Type.thy
changeset 23750 a1db5f819d00
parent 23464 bc2563c37b1a
child 25974 0cb35fa9c6fa
equal deleted inserted replaced
23749:ac6d3a8d22b5 23750:a1db5f819d00
    43 
    43 
    44 datatype type =
    44 datatype type =
    45     Atom nat
    45     Atom nat
    46   | Fun type type    (infixr "\<Rightarrow>" 200)
    46   | Fun type type    (infixr "\<Rightarrow>" 200)
    47 
    47 
    48 inductive2 typing :: "(nat \<Rightarrow> type) \<Rightarrow> dB \<Rightarrow> type \<Rightarrow> bool"  ("_ \<turnstile> _ : _" [50, 50, 50] 50)
    48 inductive typing :: "(nat \<Rightarrow> type) \<Rightarrow> dB \<Rightarrow> type \<Rightarrow> bool"  ("_ \<turnstile> _ : _" [50, 50, 50] 50)
    49   where
    49   where
    50     Var [intro!]: "env x = T \<Longrightarrow> env \<turnstile> Var x : T"
    50     Var [intro!]: "env x = T \<Longrightarrow> env \<turnstile> Var x : T"
    51   | Abs [intro!]: "env\<langle>0:T\<rangle> \<turnstile> t : U \<Longrightarrow> env \<turnstile> Abs t : (T \<Rightarrow> U)"
    51   | Abs [intro!]: "env\<langle>0:T\<rangle> \<turnstile> t : U \<Longrightarrow> env \<turnstile> Abs t : (T \<Rightarrow> U)"
    52   | App [intro!]: "env \<turnstile> s : T \<Rightarrow> U \<Longrightarrow> env \<turnstile> t : T \<Longrightarrow> env \<turnstile> (s \<degree> t) : U"
    52   | App [intro!]: "env \<turnstile> s : T \<Rightarrow> U \<Longrightarrow> env \<turnstile> t : T \<Longrightarrow> env \<turnstile> (s \<degree> t) : U"
    53 
    53 
    54 inductive_cases2 typing_elims [elim!]:
    54 inductive_cases typing_elims [elim!]:
    55   "e \<turnstile> Var i : T"
    55   "e \<turnstile> Var i : T"
    56   "e \<turnstile> t \<degree> u : T"
    56   "e \<turnstile> t \<degree> u : T"
    57   "e \<turnstile> Abs t : T"
    57   "e \<turnstile> Abs t : T"
    58 
    58 
    59 consts
    59 consts
   162   apply (erule_tac x = "t \<degree> a" in allE)
   162   apply (erule_tac x = "t \<degree> a" in allE)
   163   apply (erule_tac x = T in allE)
   163   apply (erule_tac x = T in allE)
   164   apply (erule impE)
   164   apply (erule impE)
   165    apply assumption
   165    apply assumption
   166   apply (elim exE conjE)
   166   apply (elim exE conjE)
   167   apply (ind_cases2 "e \<turnstile> t \<degree> u : T" for t u T)
   167   apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T)
   168   apply (rule_tac x = "Ta # Ts" in exI)
   168   apply (rule_tac x = "Ta # Ts" in exI)
   169   apply simp
   169   apply simp
   170   done
   170   done
   171 
   171 
   172 lemma list_app_typeE:
   172 lemma list_app_typeE:
   200 
   200 
   201 theorem var_app_type_eq:
   201 theorem var_app_type_eq:
   202   "e \<turnstile> Var i \<degree>\<degree> ts : T \<Longrightarrow> e \<turnstile> Var i \<degree>\<degree> ts : U \<Longrightarrow> T = U"
   202   "e \<turnstile> Var i \<degree>\<degree> ts : T \<Longrightarrow> e \<turnstile> Var i \<degree>\<degree> ts : U \<Longrightarrow> T = U"
   203   apply (induct ts arbitrary: T U rule: rev_induct)
   203   apply (induct ts arbitrary: T U rule: rev_induct)
   204   apply simp
   204   apply simp
   205   apply (ind_cases2 "e \<turnstile> Var i : T" for T)
   205   apply (ind_cases "e \<turnstile> Var i : T" for T)
   206   apply (ind_cases2 "e \<turnstile> Var i : T" for T)
   206   apply (ind_cases "e \<turnstile> Var i : T" for T)
   207   apply simp
   207   apply simp
   208   apply simp
   208   apply simp
   209   apply (ind_cases2 "e \<turnstile> t \<degree> u : T" for t u T)
   209   apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T)
   210   apply (ind_cases2 "e \<turnstile> t \<degree> u : T" for t u T)
   210   apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T)
   211   apply atomize
   211   apply atomize
   212   apply (erule_tac x="Ta \<Rightarrow> T" in allE)
   212   apply (erule_tac x="Ta \<Rightarrow> T" in allE)
   213   apply (erule_tac x="Tb \<Rightarrow> U" in allE)
   213   apply (erule_tac x="Tb \<Rightarrow> U" in allE)
   214   apply (erule impE)
   214   apply (erule impE)
   215   apply assumption
   215   apply assumption
   228   apply atomize
   228   apply atomize
   229   apply (case_tac U)
   229   apply (case_tac U)
   230   apply (rule FalseE)
   230   apply (rule FalseE)
   231   apply simp
   231   apply simp
   232   apply (erule list_app_typeE)
   232   apply (erule list_app_typeE)
   233   apply (ind_cases2 "e \<turnstile> t \<degree> u : T" for t u T)
   233   apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T)
   234   apply (drule_tac T="Atom nat" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq)
   234   apply (drule_tac T="Atom nat" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq)
   235   apply assumption
   235   apply assumption
   236   apply simp
   236   apply simp
   237   apply (erule_tac x="ts @ [a]" in allE)
   237   apply (erule_tac x="ts @ [a]" in allE)
   238   apply (erule_tac x="Ts @ [type1]" in allE)
   238   apply (erule_tac x="Ts @ [type1]" in allE)
   240   apply simp
   240   apply simp
   241   apply (erule impE)
   241   apply (erule impE)
   242   apply (rule types_snoc)
   242   apply (rule types_snoc)
   243   apply assumption
   243   apply assumption
   244   apply (erule list_app_typeE)
   244   apply (erule list_app_typeE)
   245   apply (ind_cases2 "e \<turnstile> t \<degree> u : T" for t u T)
   245   apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T)
   246   apply (drule_tac T="type1 \<Rightarrow> type2" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq)
   246   apply (drule_tac T="type1 \<Rightarrow> type2" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq)
   247   apply assumption
   247   apply assumption
   248   apply simp
   248   apply simp
   249   apply (erule impE)
   249   apply (erule impE)
   250   apply (rule typing.App)
   250   apply (rule typing.App)
   251   apply assumption
   251   apply assumption
   252   apply (erule list_app_typeE)
   252   apply (erule list_app_typeE)
   253   apply (ind_cases2 "e \<turnstile> t \<degree> u : T" for t u T)
   253   apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T)
   254   apply (frule_tac T="type1 \<Rightarrow> type2" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq)
   254   apply (frule_tac T="type1 \<Rightarrow> type2" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq)
   255   apply assumption
   255   apply assumption
   256   apply simp
   256   apply simp
   257   apply (erule exE)
   257   apply (erule exE)
   258   apply (rule_tac x="type1 # Us" in exI)
   258   apply (rule_tac x="type1 # Us" in exI)
   259   apply simp
   259   apply simp
   260   apply (erule list_app_typeE)
   260   apply (erule list_app_typeE)
   261   apply (ind_cases2 "e \<turnstile> t \<degree> u : T" for t u T)
   261   apply (ind_cases "e \<turnstile> t \<degree> u : T" for t u T)
   262   apply (frule_tac T="type1 \<Rightarrow> Us \<Rrightarrow> T" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq)
   262   apply (frule_tac T="type1 \<Rightarrow> Us \<Rrightarrow> T" and U="Ta \<Rightarrow> Tsa \<Rrightarrow> T" in var_app_type_eq)
   263   apply assumption
   263   apply assumption
   264   apply simp
   264   apply simp
   265   done
   265   done
   266 
   266 
   330 lemma subject_reduction: "e \<turnstile> t : T \<Longrightarrow> t \<rightarrow>\<^sub>\<beta> t' \<Longrightarrow> e \<turnstile> t' : T"
   330 lemma subject_reduction: "e \<turnstile> t : T \<Longrightarrow> t \<rightarrow>\<^sub>\<beta> t' \<Longrightarrow> e \<turnstile> t' : T"
   331   apply (induct arbitrary: t' set: typing)
   331   apply (induct arbitrary: t' set: typing)
   332     apply blast
   332     apply blast
   333    apply blast
   333    apply blast
   334   apply atomize
   334   apply atomize
   335   apply (ind_cases2 "s \<degree> t \<rightarrow>\<^sub>\<beta> t'" for s t t')
   335   apply (ind_cases "s \<degree> t \<rightarrow>\<^sub>\<beta> t'" for s t t')
   336     apply hypsubst
   336     apply hypsubst
   337     apply (ind_cases2 "env \<turnstile> Abs t : T \<Rightarrow> U" for env t T U)
   337     apply (ind_cases "env \<turnstile> Abs t : T \<Rightarrow> U" for env t T U)
   338     apply (rule subst_lemma)
   338     apply (rule subst_lemma)
   339       apply assumption
   339       apply assumption
   340      apply assumption
   340      apply assumption
   341     apply (rule ext)
   341     apply (rule ext)
   342     apply (case_tac x)
   342     apply (case_tac x)
   343      apply auto
   343      apply auto
   344   done
   344   done
   345 
   345 
   346 theorem subject_reduction': "t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> e \<turnstile> t : T \<Longrightarrow> e \<turnstile> t' : T"
   346 theorem subject_reduction': "t \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<Longrightarrow> e \<turnstile> t : T \<Longrightarrow> e \<turnstile> t' : T"
   347   by (induct set: rtrancl) (iprover intro: subject_reduction)+
   347   by (induct set: rtranclp) (iprover intro: subject_reduction)+
   348 
   348 
   349 
   349 
   350 subsection {* Alternative induction rule for types *}
   350 subsection {* Alternative induction rule for types *}
   351 
   351 
   352 lemma type_induct [induct type]:
   352 lemma type_induct [induct type]: