diff -r cdbef6152dcc -r 6704045112a8 src/HOL/Nominal/Examples/Contexts.thy --- a/src/HOL/Nominal/Examples/Contexts.thy Sun Jan 06 19:18:01 2008 +0100 +++ b/src/HOL/Nominal/Examples/Contexts.thy Mon Jan 07 02:24:24 2008 +0100 @@ -9,7 +9,8 @@ We show here that the Plotkin-style of defining reduction relations (based on congruence rules) is equivalent to the Felleisen-Hieb-style representation - (based on contexts). + (based on contexts), and show cbv-evaluation via a + list-machine described by Roshan James. The interesting point is that contexts do not contain any binders. On the other hand the operation of filling @@ -27,10 +28,10 @@ text {* Contexts - the lambda case in contexts does not bind a name - even if we introduce the nomtation [_]._ fro CLam. + even if we introduce the nomtation [_]._ for CLam. *} nominal_datatype ctx = - Hole + Hole ("\" 1000) | CAppL "ctx" "lam" | CAppR "lam" "ctx" | CLam "name" "ctx" ("CLam [_]._" [100,100] 100) @@ -49,52 +50,26 @@ apply(fresh_guess)+ done -lemma subst_eqvt[eqvt]: - fixes pi::"name prm" - shows "pi\t1[x::=t2] = (pi\t1)[(pi\x)::=(pi\t2)]" -by (nominal_induct t1 avoiding: x t2 rule: lam.induct) - (auto simp add: perm_bij fresh_atm fresh_bij) - -lemma subst_fresh: - fixes x y::"name" - and t t'::"lam" - shows "y\([x].t,t') \ y\t[x::=t']" -by (nominal_induct t avoiding: x y t' rule: lam.inducts) - (auto simp add: abs_fresh fresh_prod fresh_atm) - -text {* - Filling is the operation that fills a term into a hole. While - contexts themselves are not alpha-equivalence classes, the - filling operation produces an alpha-equivalent lambda-term. -*} +text {* Filling is the operation that fills a term into a hole. *} consts filling :: "ctx \ lam \ lam" ("_<_>" [100,100] 100) nominal_primrec - "Hole = t" + "\ = t" "(CAppL E t') = App (E) t'" "(CAppR t' E) = App t' (E)" "(CLam [x].E) = Lam [x].(E)" by (rule TrueI)+ +text {* + While contexts themselves are not alpha-equivalence classes, the + filling operation produces an alpha-equivalent lambda-term. +*} lemma alpha_test: - shows "(CLam [x].Hole) = (CLam [y].Hole)" -by (auto simp add: alpha lam.inject calc_atm fresh_atm) - -lemma replace_eqvt[eqvt]: - fixes pi:: "name prm" - shows "pi\(E) = (pi\E)<(pi\e)>" -by (nominal_induct E rule: ctx.inducts) (auto) - -lemma replace_fresh: - fixes x::"name" - and E::"ctx" - and t::"lam" - shows "x\(E,t) \ x\E" -by (induct E rule: ctx.weak_induct) - (auto simp add: fresh_prod abs_fresh) - + shows "x\y \ (CLam [x].\) \ (CLam [y].\)" + and "(CLam [x].\) = (CLam [y].\)" +by (auto simp add: alpha ctx.inject lam.inject calc_atm fresh_atm) text {* The composition of two contexts *} @@ -102,7 +77,7 @@ ctx_replace :: "ctx \ ctx \ ctx" ("_ \ _" [100,100] 100) nominal_primrec - "Hole \ E' = E'" + "\ \ E' = E'" "(CAppL E t') \ E' = CAppL (E \ E') t'" "(CAppR t' E) \ E' = CAppR t' (E \ E')" "(CLam [x].E) \ E' = CLam [x].(E \ E')" @@ -112,75 +87,110 @@ shows "E1> = (E1 \ E2)" by (induct E1 rule: ctx.weak_induct) (auto) -lemma ctx_compose_fresh: - fixes x::"name" - and E1 E2::"ctx" - shows "x\(E1,E2) \ x\(E1\E2)" -by (induct E1 rule: ctx.weak_induct) - (auto simp add: fresh_prod) - text {* Beta-reduction via contexts in the Felleisen-Hieb style. *} inductive ctx_red :: "lam\lam\bool" ("_ \x _" [80,80] 80) where - xbeta[intro]: "x\(E,t') \ E \x E" - -equivariance ctx_red - -nominal_inductive ctx_red - by (simp_all add: replace_fresh subst_fresh abs_fresh) + xbeta[intro]: "E \x E" text {* Beta-reduction via congruence rules in the Plotkin style. *} inductive cong_red :: "lam\lam\bool" ("_ \o _" [80,80] 80) where - obeta[intro]: "x\t' \ App (Lam [x].t) t' \o t[x::=t']" + obeta[intro]: "App (Lam [x].t) t' \o t[x::=t']" | oapp1[intro]: "t \o t' \ App t t2 \o App t' t2" | oapp2[intro]: "t \o t' \ App t2 t \o App t2 t'" | olam[intro]: "t \o t' \ Lam [x].t \o Lam [x].t'" -equivariance cong_red - -nominal_inductive cong_red - by (simp_all add: subst_fresh abs_fresh) - text {* The proof that shows both relations are equal. *} -lemma cong_red_ctx: +lemma cong_red_in_ctx: assumes a: "t \o t'" shows "E \o E" using a by (induct E rule: ctx.weak_induct) (auto) -lemma ctx_red_ctx: +lemma ctx_red_in_ctx: assumes a: "t \x t'" shows "E \x E" using a -by (nominal_induct t t' avoiding: E rule: ctx_red.strong_induct) - (auto simp add: ctx_compose ctx_compose_fresh) +by (induct) (auto simp add: ctx_compose) -lemma ctx_red_hole: - assumes a: "Hole \x Hole" - shows "t \x t'" -using a by simp - -theorem ctx_red_cong_red: +theorem ctx_red_implies_cong_red: assumes a: "t \x t'" shows "t \o t'" using a -by (induct) (auto intro!: cong_red_ctx) +by (induct) (auto intro!: cong_red_in_ctx) -theorem cong_red_ctx_red: +theorem cong_red_implies_ctx_red: assumes a: "t \o t'" shows "t \x t'" -using a -apply(induct) -apply(rule ctx_red_hole) -apply(rule xbeta) -apply(simp) -apply(metis ctx_red_ctx filling.simps)+ (* found by SledgeHammer *) -done +using a +proof (induct) + case (obeta x t' t) + have "\ \x \" by (rule xbeta) + then show "App (Lam [x].t) t' \x t[x::=t']" by simp +qed (metis ctx_red_in_ctx filling.simps)+ (* found by SledgeHammer *) + +section {* We now use context in a cbv list machine *} + +text {* First the function that composes a list of contexts *} +consts + ctx_composes :: "ctx list \ ctx" ("_\" [80] 80) + +primrec + "[]\ = \" + "(E#Es)\ = (Es\) \ E" + +text {* Values *} +inductive + val :: "lam\bool" +where + v_Lam[intro]: "val (Lam [x].e)" + | v_Var[intro]: "val (Var x)" + + +text {* CBV reduction using contexts *} +inductive + cbv :: "lam\lam\bool" ("_ \cbv _" [80,80] 80) +where + cbv_beta[intro]: "val v \ E \cbv E" + +text {* reflexive, transitive closure of CBV reduction *} +inductive + "cbv_star" :: "lam\lam\bool" (" _ \cbv* _" [80,80] 80) +where + cbvs1[intro]: "e \cbv* e" +| cbvs2[intro]: "e \cbv e' \ e \cbv* e'" +| cbvs3[intro,trans]: "\e1\cbv* e2; e2 \cbv* e3\ \ e1 \cbv* e3" + +text {* A list machine which builds up a list of contexts *} +inductive + machine :: "lam\ctx list\lam\ctx list\bool" ("<_,_> \ <_,_>" [60,60,60,60] 60) +where + m1[intro]: " \ e2)#Es>" +| m2[intro]: "val v \ e2)#Es> \ )#Es>" +| m3[intro]: "val v \ )#Es> \ " + +inductive + "machine_star" :: "lam\ctx list\lam\ctx list\bool" ("<_,_> \* <_,_>" [60,60,60,60] 60) +where + ms1[intro]: " \* " +| ms2[intro]: " \ \ \* " +| ms3[intro,trans]: "\ \* ; \* \ \ \* " + +lemma machine_red_implies_cbv_reds_aux: + assumes a: " \ " + shows "(Es\) \cbv* (Es'\)" +using a +by (induct) (auto simp add: ctx_compose[symmetric]) + +lemma machine_execution_implies_cbv_reds: + assumes a: " \ " + shows "e \cbv* e'" +using a +by (auto dest: machine_red_implies_cbv_reds_aux) end