Skip to content

Commit f2ecf8e

Browse files
committed
WIP
1 parent 25dad8e commit f2ecf8e

File tree

5 files changed

+89
-43
lines changed

5 files changed

+89
-43
lines changed

Defs.thy

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ proof goal_cases
4242
qed (auto simp: eqvt_def head_ctor_graph_aux_def)
4343
nominal_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"
5553
proof 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)
6361
nominal_termination (eqvt) by lexicographic_order
6462

6563
nominal_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"
8684
proof 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)
8987
next
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
9694
qed auto
9795
nominal_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"
113111
proof 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
124122
next
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
127125
next
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
130128
qed (auto simp: eqvt_def ctor_type_app_graph_aux_def)
131129
nominal_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)"
141139
proof 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)
144142
next
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
147145
next
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
173179
qed auto
174180
nominal_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)"
183189
proof 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)
189195
next
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")
192201
qed auto
193202
nominal_termination (eqvt) by lexicographic_order
194203

195204
abbreviation 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+
203225
nominal_function is_value :: "term => bool" where
204226
"is_value (Var x) = False"
205227
| "is_value (\<lambda> x : \<tau> . e) = True"

Nominal2_Lemmas.thy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,7 @@ lemma fresh_filter: "a = b \<or> atom a \<sharp> xs \<Longrightarrow> atom a \<s
9999
lemma Projl_permute: "\<exists>y. f = Inl y \<Longrightarrow> p \<bullet> projl f = projl (p \<bullet> f)" by auto
100100
lemma Projr_permute: "\<exists>y. f = Inr y \<Longrightarrow> p \<bullet> projr f = projr (p \<bullet> f)" by auto
101101

102+
lemma pair3_eqvt[simp]: "(a \<leftrightarrow> b) \<bullet> (x, y, z) = ((a \<leftrightarrow> b) \<bullet> x, (a \<leftrightarrow> b) \<bullet> y, (a \<leftrightarrow> b) \<bullet> z)"
103+
by (simp split: prod.splits)
104+
102105
end

Semantics.thy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ inductive Step :: "term \<Rightarrow> term \<Rightarrow> bool" ("_ \<longrightar
1818

1919
| ST_Let: "Let x \<tau> e1 e2 \<longrightarrow> e2[e1/x]"
2020

21+
| ST_Case_Cong: "e \<longrightarrow> e' \<Longrightarrow> Case e alts \<longrightarrow> Case e' alts"
22+
2123
equivariance Step
2224
nominal_inductive Step .
2325

Syntax.thy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ lemma perm_ctor_name_var[simp]: "((a::var) \<leftrightarrow> b) \<bullet> (D ::
9191
using flip_fresh_fresh pure_fresh by blast
9292
lemma perm_ctor_name_tyvar[simp]: "((a::tyvar) \<leftrightarrow> b) \<bullet> (D :: ctor_name) = D"
9393
using flip_fresh_fresh pure_fresh by blast
94-
94+
lemma perm_kind_var[simp]: "((a::var) \<leftrightarrow> b) \<bullet> (k::\<kappa>) = k"
95+
using supp_empty_kinds flip_fresh_fresh fresh_def by blast
96+
lemma perm_kind_tyvar[simp]: "((a::tyvar) \<leftrightarrow> b) \<bullet> (k::\<kappa>) = k"
97+
using supp_empty_kinds flip_fresh_fresh fresh_def by blast
98+
lemma perm_kind_list_var[simp]: "((a::var) \<leftrightarrow> b) \<bullet> (ks::\<kappa> list) = ks"
99+
by (induction ks) auto
100+
lemma perm_kind_list_tyvar[simp]: "((a::tyvar) \<leftrightarrow> b) \<bullet> (ks::\<kappa> list) = ks"
101+
by (induction ks) auto
95102

96103
end

Typing.thy

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ inductive Ax :: "\<Delta> \<Rightarrow> bool" ("\<turnstile> _")
1212

1313
| Ax_Data: "\<lbrakk> \<turnstile> \<Delta> ; \<nexists>k. AxData T k \<in> set \<Delta> \<rbrakk> \<Longrightarrow> \<turnstile> AxData T \<kappa> # \<Delta>"
1414

15+
<<<<<<< HEAD
1516
| Ax_Ctor: "\<lbrakk> [] , \<Delta> \<turnstile>\<^sub>t\<^sub>y \<tau> : \<star> ; ctor_type \<tau> = Some T ; \<nexists>t. AxCtor D t \<in> set \<Delta> \<rbrakk> \<Longrightarrow> \<turnstile> AxCtor D \<tau> # \<Delta>"
17+
=======
18+
| Ax_Ctor: "\<lbrakk> [] , \<Delta> \<turnstile>\<^sub>t\<^sub>y \<tau> : \<star> ; ctor_type \<tau> = Some (T, ks, tys) ; atom D \<sharp> \<Delta> \<rbrakk> \<Longrightarrow> \<turnstile> AxCtor D \<tau> # \<Delta>"
19+
>>>>>>> 9b53bd3 (WIP)
1620

1721
(* ------------------------------ *)
1822

@@ -36,7 +40,8 @@ inductive Ax :: "\<Delta> \<Rightarrow> bool" ("\<turnstile> _")
3640

3741
equivariance Ax
3842

39-
inductive Tm :: "\<Gamma> \<Rightarrow> \<Delta> \<Rightarrow> term \<Rightarrow> \<tau> \<Rightarrow> bool" ("_ , _ \<turnstile> _ : _" 50) where
43+
inductive Tm :: "\<Gamma> \<Rightarrow> \<Delta> \<Rightarrow> term \<Rightarrow> \<tau> \<Rightarrow> bool" ("_ , _ \<turnstile> _ : _" 50) and
44+
Alts :: "\<Gamma> \<Rightarrow> \<Delta> \<Rightarrow> data_name \<Rightarrow> \<tau> list \<Rightarrow> \<tau> \<Rightarrow> alt_list \<Rightarrow> \<tau> \<Rightarrow> bool" where
4045
Tm_Var: "\<lbrakk> \<Delta> \<turnstile> \<Gamma> ; BVar x \<tau> \<in> \<Gamma> \<rbrakk> \<Longrightarrow> \<Gamma> , \<Delta> \<turnstile> (Var x) : \<tau>"
4146

4247
| Tm_Abs: "BVar x \<tau>1 # \<Gamma> , \<Delta> \<turnstile> e : \<tau>2 \<Longrightarrow> \<Gamma> , \<Delta> \<turnstile> (\<lambda> x : \<tau>1 . e) : (\<tau>1 \<rightarrow> \<tau>2)"
@@ -51,9 +56,16 @@ inductive Tm :: "\<Gamma> \<Rightarrow> \<Delta> \<Rightarrow> term \<Rightarrow
5156

5257
| Tm_Let: "\<lbrakk> \<Gamma> , \<Delta> \<turnstile> e1 : \<tau>1 ; BVar x \<tau>1 # \<Gamma> , \<Delta> \<turnstile> e2 : \<tau>2 \<rbrakk> \<Longrightarrow> \<Gamma> , \<Delta> \<turnstile> Let x \<tau>1 e1 e2 : \<tau>2"
5358

54-
| Tm_Case: "\<lbrakk> \<Gamma> , \<Delta> \<turnstile> e : \<tau>1 ; head_data \<tau>1 = Some T ; \<Gamma> , \<Delta> \<turnstile>\<^sub>t\<^sub>y \<tau> : \<star> ; exhaustive alts \<Delta> T ;
55-
\<forall>m\<in>set_alt_list alts. True
56-
\<rbrakk> \<Longrightarrow> \<Gamma> , \<Delta> \<turnstile> Case e alts : \<tau>"
59+
| Tm_Case: "\<lbrakk> \<Gamma> , \<Delta> \<turnstile> e : \<tau>1 ; head_data \<tau>1 = Some (T, \<sigma>s) ; \<Gamma> , \<Delta> \<turnstile>\<^sub>t\<^sub>y \<tau> : \<star> ;
60+
exhaustive alts \<Delta> T ; Alts \<Gamma> \<Delta> T \<sigma>s \<tau>1 alts \<tau> \<rbrakk> \<Longrightarrow> \<Gamma> , \<Delta> \<turnstile> Case e alts : \<tau>"
61+
62+
| Alts_Nil: "Alts _ _ _ _ _ ANil _"
63+
64+
| Alts_Var: "\<lbrakk> BVar x \<tau>1#\<Gamma>, \<Delta> \<turnstile> e : \<tau> ; Alts \<Gamma> \<Delta> T \<sigma>s \<tau>1 alts \<tau> \<rbrakk> \<Longrightarrow> Alts \<Gamma> \<Delta> T \<sigma>s \<tau>1 (ACons (MatchVar x e) alts) \<tau>"
65+
66+
| Alts_Ctor: "\<lbrakk> AxCtor K cty \<in> set \<Delta> ; ctor_type cty = Some (T, ks, args) ; length ks = length tys ;
67+
length args = length vals ; (zip_with BVar vals args) @ (zip_with BTyVar tys ks) @ \<Gamma>, \<Delta> \<turnstile> e : \<tau> ; Alts \<Gamma> \<Delta> T \<sigma>s \<tau>1 alts \<tau>
68+
\<rbrakk> \<Longrightarrow> Alts \<Gamma> \<Delta> T \<sigma>s \<tau>1 (ACons (MatchCtor K tys vals e) alts) \<tau>"
5769

5870
equivariance Tm
5971

0 commit comments

Comments
 (0)