11theory Defs
2- imports Syntax Nominal2_Lemmas
2+ imports Syntax Nominal2_Lemmas "HOL-Library.Adhoc_Overloading"
33begin
44
55nominal_function isin :: "binder \<Rightarrow> \<Gamma> \<Rightarrow> bool" ( infixr "\<in>" 80 ) where
@@ -27,28 +27,49 @@ proof goal_cases
2727qed ( auto simp : eqvt_def isin_graph_aux_def )
2828nominal_termination ( eqvt ) by lexicographic_order
2929
30- nominal_function
31- is_value :: "term => bool"
32- where
33- "is_value (Var x) = False"
30+ nominal_function head_ctor :: "term \<Rightarrow> bool" where
31+ "head_ctor (Var _) = False"
32+ | "head_ctor (Lam _ _ _) = False"
33+ | "head_ctor (TyLam _ _ _) = False"
34+ | "head_ctor (App e1 e2) = head_ctor e1"
35+ | "head_ctor (TApp e _) = head_ctor e"
36+ | "head_ctor (Ctor _) = True"
37+ | "head_ctor (Let _ _ _ _) = False"
38+ proof goal_cases
39+ case ( 3 P x )
40+ then show ?case by ( cases x rule : term . exhaust )
41+ qed ( auto simp : eqvt_def head_ctor_graph_aux_def )
42+ nominal_termination ( eqvt ) by lexicographic_order
43+
44+ nominal_function is_value :: "term => bool" where
45+ "is_value (Var x) = False"
3446| "is_value (\<lambda> x : \<tau> . e) = True"
35- | "is_value (\<Lambda> a : k . e) = True "
36- | "is_value (App e1 e2) = False "
37- | "is_value (TyApp e \<tau>) = False "
38- | "is_value Unit = True"
47+ | "is_value (\<Lambda> a : k . e) = is_value e "
48+ | "is_value (App e1 e2) = head_ctor e1 "
49+ | "is_value (TApp e \<tau>) = head_ctor e "
50+ | "is_value (Ctor _) = True"
3951| "is_value (Let x \<tau> e1 e2) = False"
40- apply ( auto simp : eqvt_def is_value_graph_aux_def )
41- using term . exhaust by blast
52+ proof goal_cases
53+ case ( 3 P x )
54+ then show ?case by ( cases x rule : term . exhaust )
55+ next
56+ case ( 17 a k e a' k' e' )
57+ obtain c :: tyvar where c : "atom c \<sharp> (a, e, a', e')" by ( rule obtain_fresh )
58+ have 1 : "is_value_sumC e' = (a' \<leftrightarrow> c) \<bullet> is_value_sumC e'" using permute_boolE permute_boolI by blast
59+ have 2 : "is_value_sumC e = (a \<leftrightarrow> c) \<bullet> is_value_sumC e" using permute_boolE permute_boolI by blast
60+ from c have "(a \<leftrightarrow> c) \<bullet> e = (a' \<leftrightarrow> c) \<bullet> e'" using 17 ( 5 ) by simp
61+ then show ?case using 1 2 17 ( 1 , 2 ) eqvt_at_def by metis
62+ qed ( auto simp : eqvt_def is_value_graph_aux_def )
4263nominal_termination ( eqvt ) by lexicographic_order
4364
44- nominal_function subst_term :: "term => term \<Rightarrow> var => term" ( "_[_'/_]" [ 1000 , 0 , 0 ] 1000 ) where
45- "(Var y)[e/x] = (if x = y then e else Var y)"
46- | "(App e1 e2)[e/x] = App e1[e/x] e2[e/x] "
47- | "(TyApp e1 \<tau>)[e/x] = TyApp e1[e/x] \<tau>"
48- | "Unit[_/_] = Unit "
49- | "atom y \<sharp> (e, x) \<Longrightarrow> (\<lambda> y:\<tau>. e2)[e/x] = (\<lambda> y:\<tau>. e2[e/x] )"
50- | "atom y \<sharp> (e, x) \<Longrightarrow> (\<Lambda> y:k. e2)[e/x] = (\<Lambda> y:k. e2[e/x] )"
51- | "atom y \<sharp> (e, x) \<Longrightarrow> (Let y \<tau> e1 e2)[e/x] = ( Let y \<tau> e1[e/x] e2[e/x] )"
65+ nominal_function subst_term :: "term => term \<Rightarrow> var => term" where
66+ "subst_term (Var y) e x = (if x = y then e else Var y)"
67+ | "subst_term (App e1 e2) e x = App (subst_term e1 e x) (subst_term e2 e x) "
68+ | "subst_term (TApp e1 \<tau>) e x = TApp (subst_term e1 e x) \<tau>"
69+ | "subst_term (Ctor D) _ _ = Ctor D "
70+ | "atom y \<sharp> (e, x) \<Longrightarrow> subst_term (\<lambda> y:\<tau>. e2) e x = (\<lambda> y:\<tau>. subst_term e2 e x )"
71+ | "atom y \<sharp> (e, x) \<Longrightarrow> subst_term (\<Lambda> y:k. e2) e x = (\<Lambda> y:k. subst_term e2 e x )"
72+ | "atom y \<sharp> (e, x) \<Longrightarrow> subst_term (Let y \<tau> e1 e2) e x = Let y \<tau> (subst_term e1 e x) (subst_term e2 e x )"
5273proof ( goal_cases )
5374 case ( 3 P x )
5475 then obtain t e y where P : "x = (t, e, y)" by ( metis prod.exhaust )
6889qed ( auto simp : eqvt_def subst_term_graph_aux_def )
6990nominal_termination ( eqvt ) by lexicographic_order
7091
71- nominal_function subst_type :: "\<tau> \<Rightarrow> \<tau> \<Rightarrow> tyvar \<Rightarrow> \<tau>" ( "_[_'/_]" [ 1000 , 0 , 0 ] 1000 ) where
72- "TyUnit[_/_] = TyUnit "
73- | "(TyVar b)[ \<tau>/a] = (if a=b then \<tau> else TyVar b)"
74- | "(\<tau>1 \<rightarrow> \<tau>2)[\<tau>/a] = (\<tau>1[\<tau>/a] \<rightarrow> \<tau>2[\<tau>/a]) "
75- | "(TyConApp \<tau>1 \<tau>2)[ \<tau>/a] = TyConApp \<tau>1[ \<tau>/a] \<tau>2[ \<tau>/a] "
76- | "atom b \<sharp> (\<tau>, a) \<Longrightarrow> (\<forall> b:k. \<sigma>)[ \<tau>/a] = (\<forall>b:k. \<sigma>[ \<tau>/a] )"
92+ nominal_function subst_type :: "\<tau> \<Rightarrow> \<tau> \<Rightarrow> tyvar \<Rightarrow> \<tau>" where
93+ "subst_type (TyData T) _ _ = TyData T "
94+ | "subst_type (TyVar b) \<tau> a = (if a=b then \<tau> else TyVar b)"
95+ | "subst_type TyArrow _ _ = TyArrow "
96+ | "subst_type (TyApp \<tau>1 \<tau>2) \<tau> a = TyApp (subst_type \<tau>1 \<tau> a) (subst_type \<tau>2 \<tau> a) "
97+ | "atom b \<sharp> (\<tau>, a) \<Longrightarrow> subst_type (\<forall> b:k. \<sigma>) \<tau> a = (\<forall>b:k. subst_type \<sigma> \<tau> a )"
7798proof goal_cases
7899 case ( 3 P x )
79100 then obtain t \<tau> a where P : "x = (t, \<tau>, a)" by ( metis prod.exhaust )
@@ -87,14 +108,14 @@ next
87108qed ( auto simp : eqvt_def subst_type_graph_aux_def )
88109nominal_termination ( eqvt ) by lexicographic_order
89110
90- nominal_function subst_term_type :: "term \<Rightarrow> \<tau> \<Rightarrow> tyvar \<Rightarrow> term" ( "_[_'/_]" [ 1000 , 0 , 0 ] 1000 ) where
111+ nominal_function subst_term_type :: "term \<Rightarrow> \<tau> \<Rightarrow> tyvar \<Rightarrow> term" where
91112 "subst_term_type (Var x) _ _ = Var x"
92- | "subst_term_type Unit _ _ = Unit "
93- | "subst_term_type (App e1 e2) \<tau> a = App e1[ \<tau>/a] e2[ \<tau>/a] "
94- | "subst_term_type (TyApp e \<tau>2) \<tau> a = TyApp e[ \<tau>/a] \<tau>2[ \<tau>/a] "
95- | "atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (\<lambda> y:\<tau>'. e2) \<tau> a = (\<lambda> y:\<tau>'[ \<tau>/a]. e2[ \<tau>/a] )"
96- | "atom b \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (\<Lambda> b:k. e2) \<tau> a = (\<Lambda> b:k. e2[ \<tau>/a] )"
97- | "atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (Let y \<tau>' e1 e2) \<tau> a = Let y \<tau>'[ \<tau>/a] e1[ \<tau>/a] e2[ \<tau>/a] "
113+ | "subst_term_type (Ctor D) _ _ = Ctor D "
114+ | "subst_term_type (App e1 e2) \<tau> a = App (subst_term_type e1 \<tau> a) (subst_term_type e2 \<tau> a) "
115+ | "subst_term_type (TApp e \<tau>2) \<tau> a = TApp (subst_term_type e \<tau> a) (subst_type \<tau>2 \<tau> a) "
116+ | "atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (\<lambda> y:\<tau>'. e2) \<tau> a = (\<lambda> y:(subst_type \<tau>' \<tau> a). subst_term_type e2 \<tau> a )"
117+ | "atom b \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (\<Lambda> b:k. e2) \<tau> a = (\<Lambda> b:k. subst_term_type e2 \<tau> a )"
118+ | "atom y \<sharp> (\<tau>, a) \<Longrightarrow> subst_term_type (Let y \<tau>' e1 e2) \<tau> a = Let y (subst_type \<tau>' \<tau> a) (subst_term_type e1 \<tau> a) (subst_term_type e2 \<tau> a) "
98119proof goal_cases
99120 case ( 3 P x )
100121 then obtain t \<tau> a where P : "x = (t, \<tau>, a)" by ( metis prod.exhaust )
114135qed ( auto simp : eqvt_def subst_term_type_graph_aux_def )
115136nominal_termination ( eqvt ) by lexicographic_order
116137
117- nominal_function subst_context :: "\<Gamma> \<Rightarrow> \<tau> \<Rightarrow> tyvar \<Rightarrow> \<Gamma>" ( "_[_'/_]" [ 1000 , 0 , 0 ] 1000 ) where
138+ nominal_function subst_context :: "\<Gamma> \<Rightarrow> \<tau> \<Rightarrow> tyvar \<Rightarrow> \<Gamma>" where
118139 "subst_context [] _ _ = []"
119- | "subst_context (BVar x \<tau> # \<Gamma>) \<tau>' a = BVar x \<tau>[ \<tau>'/a] # subst_context \<Gamma> \<tau>' a"
140+ | "subst_context (BVar x \<tau> # \<Gamma>) \<tau>' a = BVar x (subst_type \<tau> \<tau>' a) # subst_context \<Gamma> \<tau>' a"
120141| "subst_context (BTyVar b k # \<Gamma>) \<tau>' a = (if a = b then subst_context \<Gamma> \<tau>' a else BTyVar b k # subst_context \<Gamma> \<tau>' a)"
121142proof goal_cases
122143 case ( 3 P x )
@@ -129,4 +150,10 @@ proof goal_cases
129150qed ( auto simp : eqvt_def subst_context_graph_aux_def )
130151nominal_termination ( eqvt ) by lexicographic_order
131152
153+ no_notation inverse_divide ( infixl "'/" 70 )
154+ consts subst :: "'a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'a" ( "_[_'/_]" [ 1000 , 0 , 0 ] 1000 )
155+
156+ adhoc_overloading
157+ subst subst_term subst_type subst_term_type subst_context
158+
132159end
0 commit comments