Skip to content

Commit 9343569

Browse files
committed
Prove soundness
1 parent 57ed5e3 commit 9343569

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

Lemmas.thy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ lemma subst_context_var_name: "atom c \<sharp> \<Gamma> \<Longrightarrow> subst_
6161
proof (induction \<Gamma> \<tau> a rule: subst_context.induct)
6262
case (3 b k \<Gamma> \<tau>' a)
6363
then have 1: "\<Gamma>[\<tau>'/a] = ((a \<leftrightarrow> c) \<bullet> \<Gamma>)[\<tau>'/c]" by (auto simp: fresh_Cons)
64-
have 2: "b \<noteq> c" using 3 binder.fresh(2) fresh_Cons fresh_at_base(2) by blast
64+
have 2: "b \<noteq> c" using 3 binder.fresh(2) fresh_Cons fresh_at_base(2) by blast
6565
then show ?case
6666
proof (cases "a = b")
6767
case True

Soundness.thy

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ proof (nominal_induct e avoiding: \<tau> a \<sigma> \<Gamma>' \<Gamma> rule: ter
257257
then show ?case using Tm_Var[OF 1] Var isin_subst_var by auto
258258
next
259259
case (App e1 e2)
260-
obtain \<tau>1 where P: "\<Gamma>' @ BTyVar a k # \<Gamma> \<turnstile> e1 : \<tau>1 \<rightarrow> \<tau>" "\<Gamma>' @ BTyVar a k # \<Gamma> \<turnstile> e2 : \<tau>1" by (cases rule: Tm.cases[OF App(3)]) auto
260+
obtain \<tau>1 where P: "\<Gamma>' @ BTyVar a k # \<Gamma> \<turnstile> e1 : \<tau>1 \<rightarrow> \<tau>" "\<Gamma>' @ BTyVar a k # \<Gamma> \<turnstile> e2 : \<tau>1" by (cases rule: Tm.cases[OF App(3)]) auto
261261
have 1: "\<Gamma>'[\<sigma>/a] @ \<Gamma> \<turnstile> e1[\<sigma>/a] : \<tau>1[\<sigma>/a] \<rightarrow> \<tau>[\<sigma>/a]" using App(1)[OF P(1) App(4)] by simp
262262
have 2: "\<Gamma>'[\<sigma>/a] @ \<Gamma> \<turnstile> e2[\<sigma>/a] : \<tau>1[\<sigma>/a]" by (rule App(2)[OF P(2) App(4)])
263263
show ?case using Tm_App[OF 1 2] by simp
@@ -286,7 +286,7 @@ next
286286
case (TyLam b k2 \<sigma>2)
287287
have 1: "atom b \<sharp> \<Gamma>' @ BTyVar a k # \<Gamma>" using fresh_Cons fresh_append TyLam(2,4,5) by force
288288
obtain \<sigma>'::\<tau> where P: "BTyVar b k2 # \<Gamma>' @ BTyVar a k # \<Gamma> \<turnstile> \<sigma>2 : \<sigma>'" "\<tau> = (\<forall> b : k2 . \<sigma>')" by (rule T_AbsT_Inv[OF TyLam.prems(1) 1 TyLam(1)])
289-
then have 2: "BTyVar b k2 # \<Gamma>'[\<sigma>/a] @ \<Gamma> \<turnstile> \<sigma>2[\<sigma>/a] : \<sigma>'[\<sigma>/a]" using TyLam(6)[of "BTyVar b k2 # \<Gamma>'"] TyLam(2,8) by force
289+
then have 2: "BTyVar b k2 # \<Gamma>'[\<sigma>/a] @ \<Gamma> \<turnstile> \<sigma>2[\<sigma>/a] : \<sigma>'[\<sigma>/a]" using TyLam(6)[of "BTyVar b k2 # \<Gamma>'"] TyLam(2,8) by force
290290
show ?case using Tm_TAbs[OF 2] TyLam(2,3) P(2) by simp
291291
next
292292
case (Let x \<tau>1 e1 e2)
@@ -352,4 +352,60 @@ next
352352
show ?case using Tm_Let[OF 2 3] Let(3,5) by simp
353353
qed
354354

355+
theorem preservation:
356+
fixes e e'::"term"
357+
assumes "[] \<turnstile> e : \<tau>" "e \<longrightarrow> e'"
358+
shows "[] \<turnstile> e' : \<tau>"
359+
using assms beta_nf_def value_beta_nf proof (nominal_induct "[]::\<Gamma>" e \<tau> arbitrary: e' rule: Tm_strong_induct)
360+
case (App e1 e2 \<tau>1 \<tau>2)
361+
from App(5) show ?case
362+
proof cases
363+
case (ST_BetaI x \<tau> e)
364+
then show ?thesis by (metis App.hyps(1) App.hyps(3) T_Abs_Inv \<tau>.eq_iff(3) append_Nil fresh_Nil substitution)
365+
next
366+
case (ST_AppI e2')
367+
then show ?thesis using App.hyps(2,3,6) Tm_App value_beta_nf by blast
368+
qed
369+
next
370+
case (TApp a k e \<sigma> \<tau>)
371+
from TApp(4) show ?case
372+
proof cases
373+
case (ST_BetaTI b k2 e2)
374+
obtain c::tyvar where "atom c \<sharp> (a, b, e2, \<sigma>)" using obtain_fresh by blast
375+
then have c: "atom c \<sharp> a" "atom c \<sharp> b" "atom c \<sharp> e2" "atom c \<sharp> \<sigma>" by auto
376+
obtain \<sigma>2 where c1: "(\<forall> a:k. \<sigma>) = (\<forall> c:k. \<sigma>2)" using Abs_lst_rename[OF c(4)] by auto
377+
have same: "k = k2" using TApp(1) forall_ty_lam ST_BetaTI(1) by fastforce
378+
obtain e2' where c2: "(\<Lambda> b:k2. e2) = (\<Lambda> c:k. e2')" using Abs_lst_rename[OF c(3)] same by auto
379+
have 1: "[] \<turnstile> (\<Lambda> c:k. e2') : \<forall> c:k. \<sigma>2" using TApp(1) ST_BetaTI(1) c2 c1 by simp
380+
have 2: "[BTyVar c k] \<turnstile> e2' : \<sigma>2"
381+
proof (cases rule: Tm.cases[OF 1])
382+
case (4 d _ _ e \<sigma>)
383+
have x1: "(d \<leftrightarrow> c) \<bullet> e = e2'" using Abs_rename_body[of d e c e2'] 4(2) by simp
384+
have x2: "(d \<leftrightarrow> c) \<bullet> \<sigma> = \<sigma>2" using Abs_rename_body[of d \<sigma> c \<sigma>2] 4(3) by simp
385+
show ?thesis
386+
by (metis "1" Abs1_eq_iff(3) T_AbsT_Inv \<tau>.eq_iff(5) fresh_Nil fresh_in_context_ty typing_regularity)
387+
qed auto
388+
then show ?thesis
389+
by (metis TApp.hyps(3) \<tau>.eq_iff(5) append_Nil c1 c2 local.ST_BetaTI(2) subst_context.simps(1) subst_term_type_same subst_type_same term.eq_iff(6) type_substitution(3))
390+
next
391+
case (ST_AppTI e2)
392+
then show ?thesis using TApp(2,3) Tm_TApp beta_nf_def value_beta_nf by blast
393+
qed
394+
next
395+
case (Let e1 e2 \<tau>1 \<tau>2 x)
396+
from Let(4) show ?case
397+
proof cases
398+
case (ST_SubstI x e2)
399+
then show ?thesis
400+
by (metis Let.hyps(1,3,4) Step.ST_SubstI Step_deterministic append.left_neutral substitution)
401+
qed
402+
qed auto
403+
404+
lemma multi_preservation: "\<lbrakk> e \<longrightarrow>* e' ; [] \<turnstile> e : \<tau> \<rbrakk> \<Longrightarrow> [] \<turnstile> e' : \<tau>"
405+
by (induction e e' rule: Steps.induct) (auto simp: preservation)
406+
407+
corollary soundness: "\<lbrakk> [] \<turnstile> e : \<tau> ; e \<longrightarrow>* e' \<rbrakk> \<Longrightarrow> \<not>(stuck e')"
408+
unfolding stuck_def beta_nf_def
409+
using progress multi_preservation by blast
410+
355411
end

Typing_Lemmas.thy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ proof (cases rule: Tm.cases[OF a])
2828
then have 1: "atom x \<sharp> BVar x' \<tau>1' # \<Gamma>'" using b by (simp add: 2 fresh_Cons)
2929
have 3: "((x' \<leftrightarrow> x) \<bullet> (BVar x' \<tau>1 # \<Gamma>)) \<turnstile> (x' \<leftrightarrow> x) \<bullet> e' : \<tau>2" by (metis "2"(1) "2"(2) "2"(4) Tm.eqvt flip_fresh_fresh no_vars_in_ty term.eq_iff(5))
3030
have "((x' \<leftrightarrow> x) \<bullet> (BVar x' \<tau>1) # ((x' \<leftrightarrow> x) \<bullet> \<Gamma>)) = BVar x \<tau>1#\<Gamma>"
31-
by (metis "1" "2"(1) "2"(4) CtxE(2) binder.perm_simps(1) context_valid_tm flip_at_simps(1) flip_fresh_fresh fresh_Cons no_vars_in_ty)
31+
by (metis "1" "2"(1) "2"(4) CtxE(2) binder.perm_simps(1) context_valid_tm flip_at_simps(1) flip_fresh_fresh fresh_Cons no_vars_in_ty)
3232
then show ?thesis using 1 2 3 swap that by auto
3333
qed
3434
qed simp_all
@@ -97,7 +97,7 @@ proof (cases rule: Ty.cases[OF a])
9797
then obtain c::tyvar where "atom c \<sharp> (a, \<sigma>, a2, \<sigma>2, \<Gamma>)" using obtain_fresh by blast
9898
then have c: "atom c \<sharp> a" "atom c \<sharp> \<sigma>" "atom c \<sharp> a2" "atom c \<sharp> \<sigma>2" "atom c \<sharp> \<Gamma>" by auto
9999
obtain \<sigma>' where P: "(a2 \<leftrightarrow> c) \<bullet> (\<forall> a2:k. \<sigma>2) = (\<forall> c:k. \<sigma>')" using flip_fresh_fresh by force
100-
then have 1: "(a2 \<leftrightarrow> c) \<bullet> \<sigma>2 = \<sigma>'" by (simp add: Abs1_eq_iff(3))
100+
then have 1: "(a2 \<leftrightarrow> c) \<bullet> \<sigma>2 = \<sigma>'" by (simp add: Abs1_eq_iff(3))
101101
have 2: "(a2 \<leftrightarrow> c) \<bullet> \<Gamma> = \<Gamma>" by (metis "5"(1) "5"(4) CtxE(1) c(5) context_valid_ty flip_def swap_fresh_fresh)
102102
have 3: "((a2 \<leftrightarrow> c) \<bullet> BTyVar a2 k) = BTyVar c k" using P by auto
103103
have "(a2 \<leftrightarrow> c) \<bullet> (BTyVar a2 k # \<Gamma> \<turnstile>\<^sub>t\<^sub>y \<sigma>2 : \<star>)" using 5 by auto
@@ -164,7 +164,7 @@ proof (induction \<Gamma>')
164164
then show ?case
165165
proof (cases rule: Ctx.cases[OF Cons(3)])
166166
case (2 \<Gamma>2 c k3)
167-
then have "BTyVar a k = bndr \<or> BTyVar a k \<in> (\<Gamma>' @ BTyVar b k2 # \<Gamma>)" by (metis Cons.prems(1) Cons_eq_append_conv isin.simps(5) list.inject)
167+
then have "BTyVar a k = bndr \<or> BTyVar a k \<in> (\<Gamma>' @ BTyVar b k2 # \<Gamma>)" by (metis Cons.prems(1) Cons_eq_append_conv isin.simps(5) list.inject)
168168
then show ?thesis
169169
proof
170170
assume a: "BTyVar a k = bndr"

0 commit comments

Comments
 (0)