src/HOL/Nominal/Examples/Fsub.thy
changeset 69597 ff784d5a5bfb
parent 67443 3abf6a722518
child 80142 34e0ddfc6dcc
equal deleted inserted replaced
69596:c8a2755bf220 69597:ff784d5a5bfb
    47   | TApp  "trm" "ty"  (infixl "\<cdot>\<^sub>\<tau>" 200)
    47   | TApp  "trm" "ty"  (infixl "\<cdot>\<^sub>\<tau>" 200)
    48 
    48 
    49 text \<open>To be polite to the eye, some more familiar notation is introduced. 
    49 text \<open>To be polite to the eye, some more familiar notation is introduced. 
    50   Because of the change in the order of arguments, one needs to use 
    50   Because of the change in the order of arguments, one needs to use 
    51   translation rules, instead of syntax annotations at the term-constructors
    51   translation rules, instead of syntax annotations at the term-constructors
    52   as given above for @{term "Arrow"}.\<close>
    52   as given above for \<^term>\<open>Arrow\<close>.\<close>
    53 
    53 
    54 abbreviation
    54 abbreviation
    55   Forall_syn :: "tyvrs \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty"  ("(3\<forall>_<:_./ _)" [0, 0, 10] 10) 
    55   Forall_syn :: "tyvrs \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty"  ("(3\<forall>_<:_./ _)" [0, 0, 10] 10) 
    56 where
    56 where
    57   "\<forall>X<:T\<^sub>1. T\<^sub>2 \<equiv> ty.Forall X T\<^sub>2 T\<^sub>1"
    57   "\<forall>X<:T\<^sub>1. T\<^sub>2 \<equiv> ty.Forall X T\<^sub>2 T\<^sub>1"
    64 abbreviation
    64 abbreviation
    65   TAbs_syn   :: "tyvrs \<Rightarrow> ty \<Rightarrow> trm \<Rightarrow> trm" ("(3\<lambda>_<:_./ _)" [0, 0, 10] 10) 
    65   TAbs_syn   :: "tyvrs \<Rightarrow> ty \<Rightarrow> trm \<Rightarrow> trm" ("(3\<lambda>_<:_./ _)" [0, 0, 10] 10) 
    66 where
    66 where
    67   "\<lambda>X<:T. t \<equiv> trm.TAbs X t T"
    67   "\<lambda>X<:T. t \<equiv> trm.TAbs X t T"
    68 
    68 
    69 text \<open>Again there are numerous facts that are proved automatically for @{typ "ty"} 
    69 text \<open>Again there are numerous facts that are proved automatically for \<^typ>\<open>ty\<close> 
    70   and @{typ "trm"}: for example that the set of free variables, i.e.~the \<open>support\<close>, 
    70   and \<^typ>\<open>trm\<close>: for example that the set of free variables, i.e.~the \<open>support\<close>, 
    71   is finite. However note that nominal-datatype declarations do \emph{not} define 
    71   is finite. However note that nominal-datatype declarations do \emph{not} define 
    72   ``classical" constructor-based datatypes, but rather define $\alpha$-equivalence 
    72   ``classical" constructor-based datatypes, but rather define $\alpha$-equivalence 
    73   classes---we can for example show that $\alpha$-equivalent @{typ "ty"}s 
    73   classes---we can for example show that $\alpha$-equivalent \<^typ>\<open>ty\<close>s 
    74   and @{typ "trm"}s are equal:\<close>
    74   and \<^typ>\<open>trm\<close>s are equal:\<close>
    75 
    75 
    76 lemma alpha_illustration:
    76 lemma alpha_illustration:
    77   shows "(\<forall>X<:T. Tvar X) = (\<forall>Y<:T. Tvar Y)"
    77   shows "(\<forall>X<:T. Tvar X) = (\<forall>Y<:T. Tvar Y)"
    78   and   "(\<lambda>x:T. Var x) = (\<lambda>y:T. Var y)"
    78   and   "(\<lambda>x:T. Var x) = (\<lambda>y:T. Var y)"
    79   by (simp_all add: ty.inject trm.inject alpha calc_atm fresh_atm)
    79   by (simp_all add: ty.inject trm.inject alpha calc_atm fresh_atm)
   216 apply(simp add: fresh_set_empty) 
   216 apply(simp add: fresh_set_empty) 
   217 apply(simp only: fresh_ty_dom_cons)
   217 apply(simp only: fresh_ty_dom_cons)
   218 apply(auto simp add: fresh_prod fresh_list_cons tyvrs_fresh) 
   218 apply(auto simp add: fresh_prod fresh_list_cons tyvrs_fresh) 
   219 done
   219 done
   220 
   220 
   221 text \<open>Not all lists of type @{typ "env"} are well-formed. One condition
   221 text \<open>Not all lists of type \<^typ>\<open>env\<close> are well-formed. One condition
   222   requires that in @{term "TVarB X S#\<Gamma>"} all free variables of @{term "S"} must be 
   222   requires that in \<^term>\<open>TVarB X S#\<Gamma>\<close> all free variables of \<^term>\<open>S\<close> must be 
   223   in the @{term "ty_dom"} of @{term "\<Gamma>"}, that is @{term "S"} must be \<open>closed\<close> 
   223   in the \<^term>\<open>ty_dom\<close> of \<^term>\<open>\<Gamma>\<close>, that is \<^term>\<open>S\<close> must be \<open>closed\<close> 
   224   in @{term "\<Gamma>"}. The set of free variables of @{term "S"} is the 
   224   in \<^term>\<open>\<Gamma>\<close>. The set of free variables of \<^term>\<open>S\<close> is the 
   225   \<open>support\<close> of @{term "S"}.\<close>
   225   \<open>support\<close> of \<^term>\<open>S\<close>.\<close>
   226 
   226 
   227 definition "closed_in" :: "ty \<Rightarrow> env \<Rightarrow> bool" ("_ closed'_in _" [100,100] 100) where
   227 definition "closed_in" :: "ty \<Rightarrow> env \<Rightarrow> bool" ("_ closed'_in _" [100,100] 100) where
   228   "S closed_in \<Gamma> \<equiv> (supp S)\<subseteq>(ty_dom \<Gamma>)"
   228   "S closed_in \<Gamma> \<equiv> (supp S)\<subseteq>(ty_dom \<Gamma>)"
   229 
   229 
   230 lemma closed_in_eqvt[eqvt]:
   230 lemma closed_in_eqvt[eqvt]:
   592 
   592 
   593 section \<open>Subtyping-Relation\<close>
   593 section \<open>Subtyping-Relation\<close>
   594 
   594 
   595 text \<open>The definition for the subtyping-relation follows quite closely what is written 
   595 text \<open>The definition for the subtyping-relation follows quite closely what is written 
   596   in the POPLmark-paper, except for the premises dealing with well-formed contexts and 
   596   in the POPLmark-paper, except for the premises dealing with well-formed contexts and 
   597   the freshness constraint @{term "X\<sharp>\<Gamma>"} in the \<open>S_Forall\<close>-rule. (The freshness
   597   the freshness constraint \<^term>\<open>X\<sharp>\<Gamma>\<close> in the \<open>S_Forall\<close>-rule. (The freshness
   598   constraint is specific to the \emph{nominal approach}. Note, however, that the constraint
   598   constraint is specific to the \emph{nominal approach}. Note, however, that the constraint
   599   does \emph{not} make the subtyping-relation ``partial"\ldots because we work over
   599   does \emph{not} make the subtyping-relation ``partial"\ldots because we work over
   600   $\alpha$-equivalence classes.)\<close>
   600   $\alpha$-equivalence classes.)\<close>
   601 
   601 
   602 inductive 
   602 inductive 
   844 The POPLmark-paper says the following:
   844 The POPLmark-paper says the following:
   845 
   845 
   846 \begin{quote}
   846 \begin{quote}
   847 \begin{lemma}[Transitivity and Narrowing] \
   847 \begin{lemma}[Transitivity and Narrowing] \
   848 \begin{enumerate}
   848 \begin{enumerate}
   849 \item If @{term "\<Gamma> \<turnstile> S<:Q"} and @{term "\<Gamma> \<turnstile> Q<:T"}, then @{term "\<Gamma> \<turnstile> S<:T"}.
   849 \item If \<^term>\<open>\<Gamma> \<turnstile> S<:Q\<close> and \<^term>\<open>\<Gamma> \<turnstile> Q<:T\<close>, then \<^term>\<open>\<Gamma> \<turnstile> S<:T\<close>.
   850 \item If \<open>\<Gamma>,X<:Q,\<Delta> \<turnstile> M<:N\<close> and @{term "\<Gamma> \<turnstile> P<:Q"} then \<open>\<Gamma>,X<:P,\<Delta> \<turnstile> M<:N\<close>.
   850 \item If \<open>\<Gamma>,X<:Q,\<Delta> \<turnstile> M<:N\<close> and \<^term>\<open>\<Gamma> \<turnstile> P<:Q\<close> then \<open>\<Gamma>,X<:P,\<Delta> \<turnstile> M<:N\<close>.
   851 \end{enumerate}
   851 \end{enumerate}
   852 \end{lemma}
   852 \end{lemma}
   853 
   853 
   854 The two parts are proved simultaneously, by induction on the size
   854 The two parts are proved simultaneously, by induction on the size
   855 of @{term "Q"}.  The argument for part (2) assumes that part (1) has 
   855 of \<^term>\<open>Q\<close>.  The argument for part (2) assumes that part (1) has 
   856 been established already for the @{term "Q"} in question; part (1) uses 
   856 been established already for the \<^term>\<open>Q\<close> in question; part (1) uses 
   857 part (2) only for strictly smaller @{term "Q"}.
   857 part (2) only for strictly smaller \<^term>\<open>Q\<close>.
   858 \end{quote}
   858 \end{quote}
   859 
   859 
   860 For the induction on the size of @{term "Q"}, we use the induction-rule 
   860 For the induction on the size of \<^term>\<open>Q\<close>, we use the induction-rule 
   861 \<open>measure_induct_rule\<close>:
   861 \<open>measure_induct_rule\<close>:
   862 
   862 
   863 \begin{center}
   863 \begin{center}
   864 @{thm measure_induct_rule[of "size_ty",no_vars]}
   864 @{thm measure_induct_rule[of "size_ty",no_vars]}
   865 \end{center}
   865 \end{center}
   866 
   866 
   867 That means in order to show a property @{term "P a"} for all @{term "a"}, 
   867 That means in order to show a property \<^term>\<open>P a\<close> for all \<^term>\<open>a\<close>, 
   868 the induct-rule requires to prove that for all @{term x} @{term "P x"} holds using the 
   868 the induct-rule requires to prove that for all \<^term>\<open>x\<close> \<^term>\<open>P x\<close> holds using the 
   869 assumption that for all @{term y} whose size is strictly smaller than 
   869 assumption that for all \<^term>\<open>y\<close> whose size is strictly smaller than 
   870 that of @{term x} the property @{term "P y"} holds.\<close>
   870 that of \<^term>\<open>x\<close> the property \<^term>\<open>P y\<close> holds.\<close>
   871 
   871 
   872 lemma 
   872 lemma 
   873   shows subtype_transitivity: "\<Gamma>\<turnstile>S<:Q \<Longrightarrow> \<Gamma>\<turnstile>Q<:T \<Longrightarrow> \<Gamma>\<turnstile>S<:T" 
   873   shows subtype_transitivity: "\<Gamma>\<turnstile>S<:Q \<Longrightarrow> \<Gamma>\<turnstile>Q<:T \<Longrightarrow> \<Gamma>\<turnstile>S<:T" 
   874   and subtype_narrow: "(\<Delta>@[(TVarB X Q)]@\<Gamma>)\<turnstile>M<:N \<Longrightarrow> \<Gamma>\<turnstile>P<:Q \<Longrightarrow> (\<Delta>@[(TVarB X P)]@\<Gamma>)\<turnstile>M<:N"
   874   and subtype_narrow: "(\<Delta>@[(TVarB X Q)]@\<Gamma>)\<turnstile>M<:N \<Longrightarrow> \<Gamma>\<turnstile>P<:Q \<Longrightarrow> (\<Delta>@[(TVarB X P)]@\<Gamma>)\<turnstile>M<:N"
   875 proof (induct Q arbitrary: \<Gamma> S T \<Delta> X P M N taking: "size_ty" rule: measure_induct_rule)
   875 proof (induct Q arbitrary: \<Gamma> S T \<Delta> X P M N taking: "size_ty" rule: measure_induct_rule)