@@ -42,15 +42,13 @@ proof goal_cases
4242qed ( auto simp : eqvt_def head_ctor_graph_aux_def )
4343nominal_termination ( eqvt ) by lexicographic_order
4444
45- nominal_function head_data :: "\<tau> \<Rightarrow> data_name option" where
45+ nominal_function head_data :: "\<tau> \<Rightarrow> ( data_name * \<tau> list) option" where
4646 "head_data (TyVar _) = None"
47- | "head_data (TyData T) = Some T "
47+ | "head_data (TyData T) = Some (T, []) "
4848| "head_data TyArrow = None"
49- | "head_data (TyApp (TyData T) _) = Some T"
50- | "head_data (TyApp (TyVar _) _) = None"
51- | "head_data (TyApp TyArrow _) = None"
52- | "head_data (TyApp (TyApp _ _) _) = None"
53- | "head_data (TyApp (TyForall _ _ _) _) = None"
49+ | "head_data (TyApp \<tau>1 \<tau>2) = (case head_data \<tau>1 of
50+ Some (T, xs) \<Rightarrow> Some (T, xs @ [\<tau>2])
51+ | None \<Rightarrow> None)"
5452| "head_data (TyForall _ _ _) = None"
5553proof goal_cases
5654 case ( 3 P x )
@@ -59,7 +57,7 @@ proof goal_cases
5957 case ( TyApp \<tau>1 \<tau>2 )
6058 then show ?thesis using 3 by ( cases \<tau>1 rule : \<tau>.exhaust ) auto
6159 qed
62- qed ( auto simp : eqvt_def head_data_graph_aux_def )
60+ qed ( auto simp : eqvt_def head_data_graph_aux_def split !: option.splits )
6361nominal_termination ( eqvt ) by lexicographic_order
6462
6563nominal_function set_alt_list :: "alt_list \<Rightarrow> alt set" where
@@ -76,23 +74,23 @@ nominal_function ctor_data_app :: "\<tau> \<Rightarrow> (data_name * tyvar list)
7674| "ctor_data_app (TyData T) = Some (T, [])"
7775| "ctor_data_app TyArrow = None"
7876| "ctor_data_app (TyApp \<tau>1 (TyVar a)) = (case ctor_data_app \<tau>1 of
79- Some (T, s ) \<Rightarrow> Some (T, a#s )
77+ Some (T, tys ) \<Rightarrow> Some (T, a#tys )
8078 | None \<Rightarrow> None)"
8179| "ctor_data_app (TyApp _ (TyData _)) = None"
8280| "ctor_data_app (TyApp _ TyArrow) = None"
8381| "ctor_data_app (TyApp _ (TyApp _ _)) = None"
8482| "ctor_data_app (TyApp _ (TyForall _ _ _)) = None"
8583| "ctor_data_app (TyForall _ _ _) = None"
8684proof goal_cases
87- case 1
85+ case 1
8886 then show ?case by ( auto simp : eqvt_def ctor_data_app_graph_aux_def split !: option.splits )
8987next
9088 case ( 3 P x )
9189 then show ?case
9290 proof ( cases x rule : \<tau>.exhaust )
9391 case ( TyApp \<tau>1 \<tau>2 )
9492 then show ?thesis using 3 by ( cases \<tau>2 rule : \<tau>.exhaust ) auto
95- qed ( auto simp : 3 )
93+ qed auto
9694qed auto
9795nominal_termination ( eqvt ) by lexicographic_order
9896
@@ -112,38 +110,38 @@ nominal_function ctor_type_app :: "\<tau> \<Rightarrow> (data_name * tyvar list)
112110| "ctor_type_app (TyForall _ _ _) = None"
113111proof goal_cases
114112 case ( 3 P x )
115- show ?case using 3 ( 1 - 3 , 13 )
113+ then show ?case
116114 proof ( cases x rule : \<tau>.exhaust )
117115 case outer : ( TyApp \<tau>1 \<tau>2 )
118- then show ?thesis using 3 ( 9 - 12 )
116+ then show ?thesis using 3
119117 proof ( cases \<tau>1 rule : \<tau>.exhaust )
120- case inner : ( TyApp \<tau>1' \<tau>2' )
121- then show ?thesis using outer 3 ( 4 - 8 ) by ( cases \<tau>1' rule : \<tau>.exhaust ) blast +
122- qed blast +
123- qed blast +
118+ case ( TyApp \<sigma>1 \<sigma>2 )
119+ then show ?thesis using outer 3 by ( cases \<sigma>1 rule : \<tau>.exhaust ) auto
120+ qed auto
121+ qed auto
124122next
125123 case ( 74 a k e \<tau>1 \<tau>2 a k e \<tau>1 \<tau>2 )
126- then show ?case by ( simp add : 74 )
124+ then show ?case by presburger
127125next
128126 case ( 92 a k e \<tau>2 a k e \<tau>2 )
129- then show ?case by ( simp add : 92 )
127+ then show ?case by presburger
130128qed ( auto simp : eqvt_def ctor_type_app_graph_aux_def )
131129nominal_termination ( eqvt ) by lexicographic_order
132130
133- nominal_function ctor_type_forall :: "\<tau> \<Rightarrow> (data_name * tyvar list) option" where
131+ nominal_function ctor_type_forall :: "\<tau> \<Rightarrow> (data_name * tyvar list * \<kappa> list ) option" where
134132 "ctor_type_forall (TyVar _) = None"
135- | "ctor_type_forall (TyData T) = Some (T, [])"
133+ | "ctor_type_forall (TyData T) = Some (T, [], [] )"
136134| "ctor_type_forall TyArrow = None"
137- | "ctor_type_forall (TyApp \<tau>1 \<tau>2) = ctor_type_app (TyApp \<tau>1 \<tau>2)"
138- | "ctor_type_forall (TyForall a _ e) = (case ctor_type_forall e of
139- Some (T, s ) \<Rightarrow> (if a \<in> set s then Some (T, filter (\<lambda>x. x \<noteq> a) s ) else None)
140- | None \<Rightarrow> None)"
135+ | "ctor_type_forall (TyApp \<tau>1 \<tau>2) = (case ctor_type_app (TyApp \<tau>1 \<tau>2) of Some (T, tys) \<Rightarrow> Some (T, tys, []) | None \<Rightarrow> None )"
136+ | "ctor_type_forall (TyForall a k e) = (case ctor_type_forall e of
137+ Some (T, xs, ks ) \<Rightarrow> (if a \<in> set xs then Some (T, filter (\<lambda>x. x \<noteq> a) xs, k#ks ) else None)
138+ | _ \<Rightarrow> None)"
141139proof goal_cases
142140 case 1
143141 then show ?case by ( auto simp : eqvt_def ctor_type_forall_graph_aux_def split !: option.splits list.splits )
144142next
145143 case ( 3 P x )
146- then show ?case by ( cases x rule : \<tau>.exhaust )
144+ then show ?case by ( cases x rule : \<tau>.exhaust ) auto
147145next
148146 case ( 18 a k e a' k' e' )
149147 obtain c :: tyvar where P : "atom c \<sharp> (a, e, a', e', ctor_type_forall_sumC e, ctor_type_forall_sumC e')" by ( rule obtain_fresh )
@@ -154,9 +152,10 @@ next
154152 then show ?case
155153 proof ( cases "ctor_type_forall_sumC e" )
156154 case ( Some t )
157- then obtain T s where P1 : "t = (T, s)" by fastforce
158- from Some obtain T' s' where P2 : "ctor_type_forall_sumC e' = Some (T', s')" using 3 by auto
159- have "T = T'" using "2" P1 P2 Some Some_eqvt option.inject perm_data_name_tyvar by auto
155+ then obtain T s ks where P1 : "t = (T, s, ks)" by ( metis prod.exhaust )
156+ from Some obtain T' s' ks' where P2 : "ctor_type_forall_sumC e' = Some (T', s', ks')" using 3 by auto
157+ then have pairs : "(a \<leftrightarrow> c) \<bullet> (T, s, ks) = (a' \<leftrightarrow> c) \<bullet> (T', s', ks')" using 2 P1 Some Some_eqvt option.inject by simp
158+ from pairs have "T = T'" "ks = ks'" by auto
160159 have same : "(a \<leftrightarrow> c) \<bullet> s = (a' \<leftrightarrow> c) \<bullet> s'" using "2" P1 P2 Some by auto
161160 have x : "a \<in> set s \<longleftrightarrow> a' \<in> set s'" by ( metis flip_at_simps ( 2 ) mem_permute_iff permute_flip_cancel same set_eqvt )
162161 have 4 : "atom c \<sharp> s" using c ( 5 ) Some P1 fresh_Some fresh_Pair by metis
@@ -167,19 +166,26 @@ next
167166 also have "... = filter (\<lambda>x. x \<noteq> c) ((a' \<leftrightarrow> c) \<bullet> s')" using same by argo
168167 also have "... = (a' \<leftrightarrow> c) \<bullet> filter (\<lambda>x. x \<noteq> a') s'" by simp
169168 also have "... = filter (\<lambda>x. x \<noteq> a') s'" using 6 flip_fresh_fresh by blast
170- finally have 9 : "Some (T, filter (\<lambda>x. x \<noteq> a) s) = Some (T', filter (\<lambda>x. x \<noteq> a') s')" using \<open>T = T'\<close> by blast
171- then show ?thesis using Some P1 P2 x by simp
169+ finally have 9 : "Some (T, filter (\<lambda>x. x \<noteq> a) s, ks) = Some (T', filter (\<lambda>x. x \<noteq> a') s', ks')" using \<open>T = T'\<close> \<open>ks = ks'\<close> by blast
170+ then show ?thesis
171+ proof ( cases "a \<in> set s" )
172+ case True
173+ then show ?thesis using Some P1 P2 x 18 ( 5 ) 9 by simp
174+ next
175+ case False
176+ then show ?thesis using P1 P2 Some x by force
177+ qed
172178 qed simp
173179qed auto
174180nominal_termination ( eqvt ) by lexicographic_order
175181
176182(* This function checks if a type has the form \<forall>[a:k]. [\<tau>] \<rightarrow> T [a] *)
177- nominal_function ctor_type :: "\<tau> \<Rightarrow> data_name option" where
183+ nominal_function ctor_type :: "\<tau> \<Rightarrow> ( data_name * \<kappa> list) option" where
178184 "ctor_type (TyVar a) = None"
179- | "ctor_type (TyData T) = Some T "
185+ | "ctor_type (TyData T) = Some (T, []) "
180186| "ctor_type TyArrow = None"
181- | "ctor_type (TyApp \<tau>1 \<tau>2) = (case ctor_type_app (TyApp \<tau>1 \<tau>2) of Some (T, []) \<Rightarrow> Some T | _ \<Rightarrow> None)"
182- | "ctor_type (TyForall a k e) = (case ctor_type_forall (TyForall a k e) of Some (T, []) \<Rightarrow> Some T | _ \<Rightarrow> None)"
187+ | "ctor_type (TyApp \<tau>1 \<tau>2) = (case ctor_type_app (TyApp \<tau>1 \<tau>2) of Some (T, []) \<Rightarrow> Some (T, []) | _ \<Rightarrow> None)"
188+ | "ctor_type (TyForall a k e) = (case ctor_type_forall (TyForall a k e) of Some (T, [], ks ) \<Rightarrow> Some (T, k#ks) | _ \<Rightarrow> None)"
183189proof goal_cases
184190 case 1
185191 then show ?case by ( auto simp : eqvt_def ctor_type_graph_aux_def split !: option.splits list.splits )
@@ -188,18 +194,34 @@ next
188194 then show ?case by ( cases x rule : \<tau>.exhaust )
189195next
190196 case ( 18 a k e a' k' e' )
191- then show ?case by ( simp add : 18 )
197+ have "(case ctor_type_forall (\<forall> a' : k' . e') of None \<Rightarrow> None | Some (d, [], ks) \<Rightarrow> Some (d, k # ks) | Some (d, t # x, ks) \<Rightarrow> Map.empty x) = (case ctor_type_forall (\<forall> a' : k' . e') of None \<Rightarrow> None | Some (d, [], ks) \<Rightarrow> Some (d, k' # ks) | Some (d, t # x, ks) \<Rightarrow> Map.empty x)"
198+ using "18" by fastforce
199+ then show ?case
200+ by ( simp add : "18" )
192201qed auto
193202nominal_termination ( eqvt ) by lexicographic_order
194203
195204abbreviation exhaustive :: "alt_list \<Rightarrow> \<Delta> \<Rightarrow> data_name \<Rightarrow> bool" where
196205 "exhaustive alts \<Delta> T \<equiv>
197206 (\<nexists>x e. MatchVar x e \<in> set_alt_list alts) \<longrightarrow>
198- (\<forall>D \<tau>.
199- (AxCtor D \<tau> \<in> set \<Delta> \<and> ctor_type \<tau> = Some T ) \<longrightarrow>
207+ (\<forall>D \<tau> ks .
208+ (AxCtor D \<tau> \<in> set \<Delta> \<and> ctor_type \<tau> = Some (T, ks) ) \<longrightarrow>
200209 (\<exists>tys vals e. MatchCtor D tys vals e \<in> set_alt_list alts)
201210 )"
202211
212+ nominal_function zip_with :: "('a::pt \<Rightarrow> 'b::pt \<Rightarrow> 'c::pt) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'c list" where
213+ "zip_with _ [] _ = []"
214+ | "zip_with _ _ [] = []"
215+ | "zip_with f (a#as) (b#bs) = f a b # zip_with f as bs"
216+ proof goal_cases
217+ case ( 3 P x )
218+ then show ?case sorry
219+ qed ( auto simp : eqvt_def zip_with_graph_aux_def )
220+ nominal_termination ( eqvt ) by lexicographic_order
221+
222+ lemma zip_with_length [ simp ]: "length (zip_with f as bs) = min (length as) (length bs)"
223+ by ( induction f as bs rule : zip_with.induct ) auto
224+
203225nominal_function is_value :: "term => bool" where
204226 "is_value (Var x) = False"
205227| "is_value (\<lambda> x : \<tau> . e) = True"
0 commit comments