Skip to content

Commit 42c5162

Browse files
committed
Evaluate under type lambdas to match Haskell
1 parent c054a26 commit 42c5162

File tree

3 files changed

+90
-38
lines changed

3 files changed

+90
-38
lines changed

Defs.thy

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,39 @@ proof goal_cases
2727
qed (auto simp: eqvt_def isin_graph_aux_def)
2828
nominal_termination (eqvt) by lexicographic_order
2929

30-
nominal_function head_ctor :: "term \<Rightarrow> bool"
31-
and is_value :: "term => bool" where
30+
nominal_function head_ctor :: "term \<Rightarrow> bool" where
3231
"head_ctor (Var _) = False"
3332
| "head_ctor (Lam _ _ _) = False"
3433
| "head_ctor (TyLam _ _ _) = False"
35-
| "head_ctor (App e1 e2) = (head_ctor e1 \<and> is_value e2)"
34+
| "head_ctor (App e1 e2) = head_ctor e1"
3635
| "head_ctor (TApp e _) = head_ctor e"
3736
| "head_ctor (Ctor _) = True"
3837
| "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
3943

40-
| "is_value (Var x) = False"
44+
nominal_function is_value :: "term => bool" where
45+
"is_value (Var x) = False"
4146
| "is_value (\<lambda> x : \<tau> . e) = True"
42-
| "is_value (\<Lambda> a : k . e) = True"
43-
| "is_value (App e1 e2) = (head_ctor e1 \<and> is_value e2)"
47+
| "is_value (\<Lambda> a : k . e) = is_value e"
48+
| "is_value (App e1 e2) = head_ctor e1"
4449
| "is_value (TApp e \<tau>) = head_ctor e"
4550
| "is_value (Ctor _) = True"
4651
| "is_value (Let x \<tau> e1 e2) = False"
4752
proof goal_cases
4853
case (3 P x)
49-
then show ?case
50-
proof (cases x)
51-
case (Inl a)
52-
then show ?thesis using 3(1-7) by (cases a rule: term.exhaust) auto
53-
next
54-
case (Inr b)
55-
then show ?thesis using 3(8-14) by (cases b rule: term.exhaust) auto
56-
qed
57-
qed (auto simp: eqvt_def head_ctor_is_value_graph_aux_def)
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)
5863
nominal_termination (eqvt) by lexicographic_order
5964

6065
nominal_function subst_term :: "term => term \<Rightarrow> var => term" where

Semantics.thy

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ no_notation HOL.implies (infixr "\<longrightarrow>" 25)
66

77
inductive Step :: "term \<Rightarrow> term \<Rightarrow> bool" ("_ \<longrightarrow> _" 25) where
88

9-
ST_BetaI: "App (\<lambda> x : \<tau> . e) e2 \<longrightarrow> e[e2/x]"
9+
ST_Beta: "App (\<lambda> x : \<tau> . e) e2 \<longrightarrow> e[e2/x]"
1010

11-
| ST_AppI: "e1 \<longrightarrow> e2 \<Longrightarrow> App e1 e \<longrightarrow> App e2 e"
11+
| ST_TBeta: "is_value e \<Longrightarrow> TApp (\<Lambda> a : k . e) \<tau> \<longrightarrow> e[\<tau>/a]"
1212

13-
| ST_SubstI: "Let x \<tau> e1 e2 \<longrightarrow> e2[e1/x]"
13+
| ST_TAbs: "e \<longrightarrow> e' \<Longrightarrow> (\<Lambda> a:k. e) \<longrightarrow> (\<Lambda> a:k. e')"
1414

15-
| ST_BetaTI: "TApp (\<Lambda> a : k . e) \<tau> \<longrightarrow> e[\<tau>/a]"
15+
| ST_App: "e1 \<longrightarrow> e1' \<Longrightarrow> App e1 e2 \<longrightarrow> App e1' e2"
16+
17+
| ST_TApp: "e \<longrightarrow> e' \<Longrightarrow> TApp e \<tau> \<longrightarrow> TApp e' \<tau>"
18+
19+
| ST_Let: "Let x \<tau> e1 e2 \<longrightarrow> e2[e1/x]"
1620

17-
| ST_AppTI: "e1 \<longrightarrow> e2 \<Longrightarrow> TApp e1 \<tau> \<longrightarrow> TApp e2 \<tau>"
1821
equivariance Step
1922
nominal_inductive Step .
2023

@@ -53,47 +56,88 @@ next
5356
then show ?case using Step.cases beta_nf_def by fastforce
5457
next
5558
case (TyLam a k e)
56-
then show ?case using Step.cases beta_nf_def by fastforce
59+
show ?case
60+
proof (rule ccontr)
61+
assume "\<not>beta_nf (\<Lambda> a:k. e)"
62+
then obtain e' where "(\<Lambda> a:k. e) \<longrightarrow> e'" using beta_nf_def by blast
63+
then show "False"
64+
proof cases
65+
case (ST_TAbs e2 e2' b)
66+
obtain c::tyvar where c:"atom c \<sharp> (a, e, b, e2)" by (rule obtain_fresh)
67+
then obtain e3 where 1: "[[atom b]]lst. e2 = [[atom c]]lst. e3" by (metis Abs_lst_rename fresh_PairD(2))
68+
then have 2: "e = (c \<leftrightarrow> a) \<bullet> e3" using ST_TAbs(1) c by (metis Abs_rename_body)
69+
from 1 have "e3 = (b \<leftrightarrow> c) \<bullet> e2" using Abs_rename_body by blast
70+
then have "e3 \<longrightarrow> (b \<leftrightarrow> c) \<bullet> e2'" using ST_TAbs(3) Step.eqvt by blast
71+
then have "e \<longrightarrow> (c \<leftrightarrow> a) \<bullet> (b \<leftrightarrow> c) \<bullet> e2'" using 2 Step.eqvt by blast
72+
then show ?thesis using TyLam beta_nf_def by auto
73+
qed
74+
qed
5775
qed auto
5876

5977
lemma Step_deterministic: "\<lbrakk> e \<longrightarrow> e1 ; e \<longrightarrow> e2 \<rbrakk> \<Longrightarrow> e1 = e2"
6078
proof (induction e e1 arbitrary: e2 rule: Step.induct)
61-
case (ST_BetaI v x \<tau> e)
79+
case (ST_Beta v x \<tau> e)
6280
then show ?case
6381
proof cases
64-
case (ST_BetaI y e')
82+
case (ST_Beta y e')
6583
then show ?thesis using subst_term_same by blast
6684
next
67-
case (ST_AppI e')
85+
case (ST_App e')
6886
then show ?thesis using Step.cases by fastforce
6987
qed
7088
next
71-
case (ST_AppI e1 e2 e)
72-
from ST_AppI(3) show ?case
73-
apply cases
74-
using ST_AppI Step.cases value_beta_nf beta_nf_def by fastforce+
89+
case outer: (ST_TAbs e e' a k)
90+
from outer(3) show ?case
91+
proof cases
92+
case (ST_TAbs e3 e3' b)
93+
obtain c::tyvar where "atom c \<sharp> (a, e, b, e3, e', e3')" by (rule obtain_fresh)
94+
then have c: "atom c \<sharp> (a, e, b, e3)" "atom c \<sharp> e'" "atom c \<sharp> e3'" by auto
95+
then obtain e4 where 1: "[[atom b]]lst. e3 = [[atom c]]lst. e4" by (metis Abs_lst_rename fresh_PairD(2))
96+
then have 2: "e = (c \<leftrightarrow> a) \<bullet> e4" using ST_TAbs(1) c by (metis Abs_rename_body)
97+
from 1 have 3: "e4 = (b \<leftrightarrow> c) \<bullet> e3" using c by (metis Abs_rename_body)
98+
99+
have x1: "(\<Lambda> a : k . e') = (\<Lambda> c : k . (a \<leftrightarrow> c) \<bullet> e')" using c(2) Abs_lst_rename by fastforce
100+
have x2: "(\<Lambda> b : k . e3') = (\<Lambda> c : k. (b \<leftrightarrow> c) \<bullet> e3')" using c(3) Abs_lst_rename by fastforce
101+
102+
let ?e4' = "(c \<leftrightarrow> a) \<bullet> (b \<leftrightarrow> c) \<bullet> e3'"
103+
from 3 have "e4 \<longrightarrow> (b \<leftrightarrow> c) \<bullet> e3'" using Step.eqvt ST_TAbs(3) by blast
104+
then have "e \<longrightarrow> ?e4'" using Step.eqvt 2 by blast
105+
then have "e' = ?e4'" using outer(2) by blast
106+
then have "(a \<leftrightarrow> c) \<bullet> e' = (b \<leftrightarrow> c) \<bullet> e3'" by (simp add: flip_commute)
107+
then show ?thesis using x1 x2 ST_TAbs(2) by argo
108+
qed
109+
next
110+
case (ST_App e1 e2 e)
111+
from ST_App(3) show ?case
112+
proof cases
113+
case (ST_Beta x \<tau> e)
114+
then show ?thesis using ST_App.hyps beta_nf_def is_value.simps(2) value_beta_nf by blast
115+
next
116+
case (ST_App e2)
117+
then show ?thesis by (simp add: ST_App.IH)
118+
qed
75119
next
76-
case (ST_SubstI v x e)
120+
case (ST_Let v x e)
77121
then show ?case
78122
proof cases
79-
case (ST_SubstI x e)
123+
case (ST_Let x e)
80124
then show ?thesis using subst_term_same by blast
81125
qed
82126
next
83-
case (ST_BetaTI a e \<tau>)
84-
then show ?case
127+
case (ST_TBeta a e \<tau>)
128+
from ST_TBeta(2) show ?case
85129
proof cases
86-
case (ST_BetaTI b e')
130+
case (ST_TBeta b e')
87131
then show ?thesis using subst_term_type_same by blast
88132
next
89-
case (ST_AppTI e2)
90-
then show ?thesis using is_value.simps(3) value_beta_nf beta_nf_def by blast
133+
case (ST_TApp e2)
134+
then show ?thesis using is_value.simps(3) value_beta_nf beta_nf_def ST_TBeta(1) by blast
91135
qed
92136
next
93-
case (ST_AppTI e1 e2 \<tau>)
94-
from ST_AppTI(3) show ?case
137+
case (ST_TApp e1 e2 \<tau>)
138+
from ST_TApp(3) show ?case
95139
apply cases
96-
using ST_AppTI value_beta_nf beta_nf_def by auto
140+
using ST_TApp value_beta_nf beta_nf_def by auto
97141
qed
98142

99143
end

Typing_Lemmas.thy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ begin
44

55
no_notation Set.member ("(_/ : _)" [51, 51] 50)
66

7+
lemma fun_ty_val: "\<lbrakk> \<Gamma> , \<Delta> \<turnstile> e : \<tau>1 \<rightarrow> \<tau>2 ; is_value e \<rbrakk> \<Longrightarrow> (\<exists>x e'. e = (\<lambda>x:\<tau>1. e')) \<or> head_ctor e"
8+
by (induction \<Gamma> \<Delta> e "\<tau>1 \<rightarrow> \<tau>2" rule: Tm.induct) auto
9+
710
lemma context_cons_valid[elim]: "(\<Delta>::\<Delta>) \<turnstile> bndr # \<Gamma> \<Longrightarrow> (\<Delta> \<turnstile> \<Gamma> \<Longrightarrow> P) \<Longrightarrow> P"
811
by (cases rule: Ctx.cases) (auto simp: context_valid(1))
912

0 commit comments

Comments
 (0)