+ All Categories
Home > Documents > nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal...

nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal...

Date post: 09-Jul-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
111
Nominal Techniques or, “The Real Thing” Christian Urban (TU Munich) A Formalisation of a CK Machine: CK _ _ Eugene, 26. July 2008 – p. 1/49
Transcript
Page 1: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Nominal Techniquesor, “The Real Thing”

Christian Urban (TU Munich)http://isabelle.in.tum.de/nominal/

A Formalisation of a CK Machine:

_�!cbv _

CK_ + _

Eugene, 26. July 2008 – p. 1/49

Page 2: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Nominal Techniquesor, “The Real Thing”

Christian Urban (TU Munich)http://isabelle.in.tum.de/nominal/

A Formalisation of a CK Machine:

_�!cbv _

CK_ + _

Eugene, 26. July 2008 – p. 1/49

Page 3: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Nominal Techniquesor, “The Real Thing”

Christian Urban (TU Munich)http://isabelle.in.tum.de/nominal/

A Formalisation of a CK Machine:

_�!cbv _

CK_ + _

Eugene, 26. July 2008 – p. 1/49

Page 4: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Lambda-TermsWe build on the theory Nominal (which in turnbuilds on HOL). Nominal provides an infra-structure to reason with binders.

atom_decl name

nominal_datatype lam =Var "name"j App "lam" "lam"j Lam "«name»lam" ("Lam [_]._")

We allow more than one kind of atoms.At the moment we only support single, but nestedbinders (future: arbitrary binding structures).

Eugene, 26. July 2008 – p. 2/49

Page 5: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Lambda-TermsWe build on the theory Nominal (which in turnbuilds on HOL). Nominal provides an infra-structure to reason with binders.

atom_decl name

nominal_datatype lam =Var "name"j App "lam" "lam"j Lam "«name»lam" ("Lam [_]._")

We allow more than one kind of atoms.At the moment we only support single, but nestedbinders (future: arbitrary binding structures).

Eugene, 26. July 2008 – p. 2/49

Page 6: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Contexts

Eugene, 26. July 2008 – p. 3/49

datatype ctx =Hole ("�")j CAppL "ctx" "lam"j CAppR "lam" "ctx"j CLam "name" "ctx" ("CLam [_]._")

funfilling :: "ctx) lam) lam" ("_[[_]]")

where"�[[t]] = t"j "(CAppL E t’)[[t]] = App (E[[t]]) t’"j "(CAppR t’ E)[[t]] = App t’ (E[[t]])"j "(CLam [x].E)[[t]] = Lam [x].(E[[t]])"

lemma alpha_test:shows "x6=y =) (CLam [x].�) 6= (CLam [y].�)"and "(CLam [x].�)[[Var x]] = (CLam [y].�)[[Var y]]"

by (simp_all add: ctx.inject lam.inject alpha swap_simps fresh_atm)

Page 7: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Backtrack One StepFor our CK machines we actually do not needcontexts for lambdas.

datatype ctx =Hole ("�")j CAppL "ctx" "lam"j CAppR "lam" "ctx"

funfilling :: "ctx) lam) lam" ("_[[_]]")

where"�[[t]] = t"j "(CAppL E t’)[[t]] = App (E[[t]]) t’"j "(CAppR t’ E)[[t]] = App t’ (E[[t]])"

Eugene, 26. July 2008 – p. 4/49

Page 8: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Context Compositionfun ctx_compose :: "ctx) ctx) ctx" ("_ � _")where"� � E’ = E’"j "(CAppL E t’) � E’ = CAppL (E � E’) t’"j "(CAppR t’ E) � E’ = CAppR t’ (E � E’)"

lemma ctx_compose:shows "(E1 � E2)[[t]] = E1[[E2[[t]]]]"

by (induct E1 rule: ctx.induct) (simp_all)

types ctxs = "ctx list"

fun ctx_composes :: "ctxs) ctx" ("_#")where

"[]# = �"j "(E#Es)# = (Es#) � E"

Eugene, 26. July 2008 – p. 5/49

Page 9: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Context Compositionfun ctx_compose :: "ctx) ctx) ctx" ("_ � _")where"� � E’ = E’"j "(CAppL E t’) � E’ = CAppL (E � E’) t’"j "(CAppR t’ E) � E’ = CAppR t’ (E � E’)"

lemma ctx_compose:shows "(E1 � E2)[[t]] = E1[[E2[[t]]]]"

by (induct E1 rule: ctx.induct) (simp_all)

types ctxs = "ctx list"

fun ctx_composes :: "ctxs) ctx" ("_#")where

"[]# = �"j "(E#Es)# = (Es#) � E"

Eugene, 26. July 2008 – p. 5/49

Subgoals1. � � E2[[t]] = �[[E2[[t]]]]2.Vctx lam. ctx � E2[[t]] = ctx[[E2[[t]]]] =) CAppL ctx lam � E2[[t]] = CAppL ctx

lam[[E2[[t]]]]3.Vlam ctx. ctx � E2[[t]] = ctx[[E2[[t]]]] =) CAppR lam ctx � E2[[t]] = CAppR lam

ctx[[E2[[t]]]]

Page 10: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Context Compositionfun ctx_compose :: "ctx) ctx) ctx" ("_ � _")where"� � E’ = E’"j "(CAppL E t’) � E’ = CAppL (E � E’) t’"j "(CAppR t’ E) � E’ = CAppR t’ (E � E’)"

lemma ctx_compose:shows "(E1 � E2)[[t]] = E1[[E2[[t]]]]"

by (induct E1 rule: ctx.induct) (simp_all)

types ctxs = "ctx list"

fun ctx_composes :: "ctxs) ctx" ("_#")where

"[]# = �"j "(E#Es)# = (Es#) � E"

Eugene, 26. July 2008 – p. 5/49

Page 11: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Definition of Typesnominal_datatype ty =tVar "string"j tArr "ty" "ty" ("_! _")

types ty_ctx = "(name�ty) list"

abbreviation"sub_ty_ctx" :: "ty_ctx) ty_ctx) bool" ("_� _")

where"� 1 � � 2 � 8 x. x 2 set � 1 �! x 2 set � 2"

Eugene, 26. July 2008 – p. 6/49

Page 12: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Definition of Typesnominal_datatype ty =tVar "string"j tArr "ty" "ty" ("_! _")

types ty_ctx = "(name�ty) list"

abbreviation"sub_ty_ctx" :: "ty_ctx) ty_ctx) bool" ("_� _")

where"� 1 � � 2 � 8 x. x 2 set � 1 �! x 2 set � 2"

We can overload�, but this might mean we haveto give explicit type-annotations so that Isabellecan figure out what is meant.

Eugene, 26. July 2008 – p. 6/49

Page 13: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgementsinductivevalid :: "ty_ctx) bool"

wherev1: "valid []"j v2: "[[valid � ; x#� ]]=) valid ((x,T)#� )"

inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

Eugene, 26. July 2008 – p. 7/49

Page 14: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgementsinductivevalid :: "ty_ctx) bool"

wherev1: "valid []"j v2: "[[valid � ; x#� ]]=) valid ((x,T)#� )"

inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

Eugene, 26. July 2008 – p. 7/49

valid � (x, T) 2 set �� ` Var x : T

� ` t1 : T1 ! T2 � ` t2 : T1

� ` App t1 t2 : T2

x # � (x, T1)::� ` t : T2

� ` Lam [x].t : T1 ! T2

Page 15: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgementsinductivevalid :: "ty_ctx) bool"

wherev1: "valid []"j v2: "[[valid � ; x#� ]]=) valid ((x,T)#� )"

inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

declare typing.intros[intro] valid.intros[intro]

Eugene, 26. July 2008 – p. 7/49

Page 16: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgementsinductivevalid :: "ty_ctx) bool"

wherev1: "valid []"j v2: "[[valid � ; x#� ]]=) valid ((x,T)#� )"

inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

declare typing.intros[intro] valid.intros[intro]

Eugene, 26. July 2008 – p. 7/49

We want to have the strong inductionprinciple for the typing judgement.1.) The relation needs to be equivariant.

Page 17: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgementsinductivevalid :: "ty_ctx) bool"

wherev1: "valid []"j v2: "[[valid � ; x#� ]]=) valid ((x,T)#� )"

inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

declare typing.intros[intro] valid.intros[intro]

equivariance validequivariance typing

Eugene, 26. July 2008 – p. 7/49

Page 18: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgementsinductivevalid :: "ty_ctx) bool"

wherev1: "valid []"j v2: "[[valid � ; x#� ]]=) valid ((x,T)#� )"

inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

declare typing.intros[intro] valid.intros[intro]

equivariance validequivariance typing

Eugene, 26. July 2008 – p. 7/49

This proves for us:valid � =) valid (� � � )� ` t : T =) � � � ` � � t : � � T

Page 19: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgements (2)inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

lemma ty_fresh:fixes x::"name"and T::"ty"shows "x#T"

by (induct T rule: ty.induct)(simp_all add: fresh_string)

nominal_inductive typing

by (simp_all add: abs_fresh ty_fresh)

Eugene, 26. July 2008 – p. 8/49

Page 20: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgements (2)inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

lemma ty_fresh:fixes x::"name"and T::"ty"shows "x#T"

by (induct T rule: ty.induct)(simp_all add: fresh_string)

nominal_inductive typing

by (simp_all add: abs_fresh ty_fresh)

Eugene, 26. July 2008 – p. 8/49

Subgoals1.Vx � T1 t T2. [[x # � ; (x, T1)::� ` t : T2]] =) x # �

2.Vx � T1 t T2. [[x # � ; (x, T1)::� ` t : T2]] =) x # Lam [x].t

3.Vx � T1 t T2. [[x # � ; (x, T1)::� ` t : T2]] =) x # T1 ! T2

Page 21: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgements (2)inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

lemma ty_fresh:fixes x::"name"and T::"ty"shows "x#T"

by (induct T rule: ty.induct)(simp_all add: fresh_string)

nominal_inductive typing

by (simp_all add: abs_fresh ty_fresh)

Eugene, 26. July 2008 – p. 8/49

Page 22: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Typing Judgements (2)inductivetyping :: "ty_ctx) lam) ty) bool" ("_ ` _ : _")

wheret_Var: "[[valid � ; (x,T) 2 set � ]] =) � ` Var x : T"j t_App: "[[� ` t1 : T1!T2; � ` t2 : T1]] =) � ` App t1 t2 : T2"j t_Lam: "[[x#� ; (x,T1)#� ` t : T2]] =) � ` Lam [x].t : T1 ! T2"

lemma ty_fresh:fixes x::"name"and T::"ty"shows "x#T"

by (induct T rule: ty.induct)(simp_all add: fresh_string)

nominal_inductive typingby (simp_all add: abs_fresh ty_fresh)

Eugene, 26. July 2008 – p. 8/49

Page 23: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Weakeninglemma weakening:fixes � 1 � 2::"ty_ctx"assumes a: "� 1 ` t : T"and b: "valid � 2"and c: "� 1 � � 2"shows "� 2 ` t : T"

using a b cby (nominal_induct � 1 t T avoiding: � 2 rule: typing.strong_induct)

(auto simp add: atomize_all atomize_imp)

This proof is can be found automatically, but thattells us not much. . .

Eugene, 26. July 2008 – p. 9/49

Page 24: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Weakeninglemma weakening:fixes � 1 � 2::"ty_ctx"assumes a: "� 1 ` t : T"and b: "valid � 2"and c: "� 1 � � 2"shows "� 2 ` t : T"

using a b cby (nominal_induct � 1 t T avoiding: � 2 rule: typing.strong_induct)

(auto simp add: atomize_all atomize_imp)

This proof is can be found automatically, but thattells us not much. . .

Eugene, 26. July 2008 – p. 9/49

Page 25: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Lemma / Theorem / Corollary

Lemmas / Theorems / Corollary are of the form:theorem theorem_name:fixes x::"type". . .assumes "assm1"and "assm2". . .shows "statement". . .

Grey parts are optional.Assumptions and the (goal)statement must be oftype bool.

Eugene, 26. July 2008 – p. 10/49

Page 26: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Lemma / Theorem / Corollary

Lemmas / Theorems / Corollary are of the form:theorem theorem_name:fixes x::"type". . .assumes "assm1"and "assm2". . .shows "statement". . .

Grey parts are optional.Assumptions and the (goal)statement must be oftype bool.

Eugene, 26. July 2008 – p. 10/49

lemma weakening:fixes � 1 � 2::"ty_ctx"assumes a: "� 1 ` t : T"and b: "valid � 2"and c: "� 1 � � 2"shows "� 2 ` t : T"

Page 27: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Struct. of an Ind. Prooflemma weakening:fixes � 1 � 2::"ty_ctx"assumes a: "� 1 ` t : T"and b: "valid � 2"and c: "� 1 � � 2"shows "� 2 ` t : T"

using a b cproof(nominal_induct � 1 t T avoiding: � 2 rule: typing.strong_induct)case (t_Var � 1 x T). . .show "� 2 ` Var x : T". . .

nextcase (t_App � 1 t1 T1 T2 t2). . .show "� 2 ` App t1 t2 : T2". . .

nextcase (t_Lam x � 1 T1 t T2). . .show "� 2 ` Lam [x].t : T1 ! T2". . .

qed Eugene, 26. July 2008 – p. 11/49

Page 28: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CasesEach case is of the form:

case (Name x. . . )have n1: "statment1" by justificationhave n2: "statment2" by justification. . .show "statment" by justification

Grey parts are optional.Justifications can also be: using . . . by . . .

Eugene, 26. July 2008 – p. 12/49

Page 29: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CasesEach case is of the form:

case (Name x. . . )have n1: "statment1" by justificationhave n2: "statment2" by justification. . .show "statment" by justification

Grey parts are optional.Justifications can also be: using . . . by . . .

using ih by . . .using n1 n2 n3 by . . .using lemma_name. . .by . . .

Eugene, 26. July 2008 – p. 12/49

Page 30: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CasesEach case is of the form:

case (Name x. . . )have n1: "statment1" by justificationhave n2: "statment2" by justification. . .show "statment" by justification

Grey parts are optional.Justifications can also be: using . . . by . . .

using ih by . . .using n1 n2 n3 by . . .using lemma_name. . .by . . .

Eugene, 26. July 2008 – p. 12/49

Page 31: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

JustificationsOmitting proofssorryAssumptionsby factAutomated proofsby simp simplification (equations, definitions)by auto simplification & proof search

(many goals)by force simplification & proof search

(first goal)by blast proof search. . .

Eugene, 26. July 2008 – p. 13/49

Page 32: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

valid � (x, T) 2 set �� ` Var x : T

lemma weakening:fixes � 1 � 2::"ty_ctx"assumes a: "� 1 ` t : T"and b: "valid � 2"and c: "� 1 � � 2"shows "� 2 ` t : T"

using a b cproof(nominal_induct � 1 t T avoiding: � 2 rule: typing.strong_induct)case (t_Var � 1 x T)have a1: "valid � 2" by facthave a2: "� 1 � � 2" by facthave a3: "(x,T) 2 (set � 1)" by facthave a4: "(x,T) 2 (set � 2)" using a2 a3 by simpshow "� 2 ` Var x : T" using a1 a4 by auto

next : : :Eugene, 26. July 2008 – p. 14/49

Page 33: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

x # � (x, T1)::� ` t : T2

� ` Lam [x].t : T1 ! T2

nextcase (t_Lam x � 1 T1 t T2)have vc: "x#� 2" by facthave ih: "[[valid ((x,T1)#� 2); (x,T1)#� 1 � (x,T1)#� 2]]

=) (x,T1)#� 2 ` t:T2" by facthave a1: "� 1 � � 2" by facthave a2: "(x,T1)#� 1 � (x,T1)#� 2" using a1 by simphave b1: "valid � 2" by facthave b2: "valid ((x,T1)#� 2)" using vc b1 by autohave b3: "(x,T1)#� 2 ` t : T2" using ih b2 a2 by simpshow "� 2 ` Lam [x].t : T1!T2" using b3 vc by auto

next : : :

Eugene, 26. July 2008 – p. 15/49

Page 34: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

x # � (x, T1)::� ` t : T2

� ` Lam [x].t : T1 ! T2

nextcase (t_Lam x � 1 T1 t T2)have vc: "x#� 2" by facthave ih: "[[valid ((x,T1)#� 2); (x,T1)#� 1 � (x,T1)#� 2]]

=) (x,T1)#� 2 ` t:T2" by facthave "� 1 � � 2" by factthen have a2: "(x,T1)#� 1 � (x,T1)#� 2" by simphave "valid � 2" by factthen have b2: "valid ((x,T1)#� 2)" using vc by autohave "(x,T1)#� 2 ` t : T2" using ih b2 a2 by simpthen show "� 2 ` Lam [x].t : T1!T2" using vc by auto

next : : :

Eugene, 26. July 2008 – p. 16/49

Page 35: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

A Sequence of Facts

have n1: “. . . ”have n2: “. . . ”

. . .

have nn: “. . . ”have “. . . ” using n1 n2. . . nn

have “. . . ”moreover have “. . . ”

. . .

moreover have “. . . ”ultimately have “. . . ”

Eugene, 26. July 2008 – p. 17/49

Page 36: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

x # � (x, T1)::� ` t : T2

� ` Lam [x].t : T1 ! T2

nextcase (t_Lam x � 1 T1 t T2)have vc: "x#� 2" by facthave ih: "[[valid ((x,T1)#� 2); (x,T1)#� 1 � (x,T1)#� 2]]

=) (x,T1)#� 2 ` t:T2" by facthave "� 1 � � 2" by factthen have "(x,T1)#� 1 � (x,T1)#� 2" by simpmoreoverhave "valid � 2" by factthen have "valid ((x,T1)#� 2)" using vc by autoultimately have "(x,T1)#� 2 ` t : T2" using ih by simpthen show "� 2 ` Lam [x].t : T1!T2" using vc by auto

next : : :

Eugene, 26. July 2008 – p. 18/49

Page 37: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

x # � (x, T1)::� ` t : T2

� ` Lam [x].t : T1 ! T2

nextcase (t_Lam x � 1 T1 t T2)have vc: "x#� 2" by facthave ih: "[[valid ((x,T1)#� 2); (x,T1)#� 1 � (x,T1)#� 2]]

=) (x,T1)#� 2 ` t:T2" by facthave "� 1 � � 2" by factthen have "(x,T1)#� 1 � (x,T1)#� 2" by simpmoreoverhave "valid � 2" by factthen have "valid ((x,T1)#� 2)" using vc by autoultimately have "(x,T1)#� 2 ` t : T2" using ih by simpthen show "� 2 ` Lam [x].t : T1!T2" using vc by auto

qed (auto)

Eugene, 26. July 2008 – p. 19/49

Page 38: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Capture-Avoiding Subst.We next want to introduce an evaluation relationand a CK machine.For this we need the notion of capture-avoidingsubstitution.

constssubst :: "lam) name) lam) lam" ("_[_::=_]")

nominal_primrec"(Var x)[y::=s] = (if x=y then s else (Var x))""(App t1 t2)[y::=s] = App (t1[y::=s]) (t2[y::=s])""x#(y,s) =) (Lam [x].t)[y::=s] = Lam [x].(t[y::=s])"

Despite its looks, this is a total function!

Eugene, 26. July 2008 – p. 20/49

Page 39: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Capture-Avoiding Subst.We next want to introduce an evaluation relationand a CK machine.For this we need the notion of capture-avoidingsubstitution.

constssubst :: "lam) name) lam) lam" ("_[_::=_]")

nominal_primrec"(Var x)[y::=s] = (if x=y then s else (Var x))""(App t1 t2)[y::=s] = App (t1[y::=s]) (t2[y::=s])""x#(y,s) =) (Lam [x].t)[y::=s] = Lam [x].(t[y::=s])"

Despite its looks, this is a total function!Eugene, 26. July 2008 – p. 20/49

Page 40: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Bound Names FunctionHowever there is a problem with the bound namesfunction:

constsbnds :: "lam) name set"

nominal_primrec"bnds (Var x) = {}""bnds (App t1 t2) = bnds (t1) [ bnds (t2)""bnds (Lam [x].t) = bnds (t) [ {x}"

lemmashows "bnds (Lam [x].Var x) = {x}"and "bnds (Lam [y].Var y) = {y}"

by (simp_all)

Eugene, 26. July 2008 – p. 21/49

Page 41: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Bound Names FunctionHowever there is a problem with the bound namesfunction:

constsbnds :: "lam) name set"

nominal_primrec"bnds (Var x) = {}""bnds (App t1 t2) = bnds (t1) [ bnds (t2)""bnds (Lam [x].t) = bnds (t) [ {x}"

lemmashows "bnds (Lam [x].Var x) = {x}"and "bnds (Lam [y].Var y) = {y}"

by (simp_all)

Eugene, 26. July 2008 – p. 21/49

Assume x 6= y.

Lam [x].Var x = Lam [y].Var y

bnds (Lam [x].Var x) = bnds (Lam [y].Var y)

{x} = {y}

Page 42: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Bound Names FunctionHowever there is a problem with the bound namesfunction:

constsbnds :: "lam) name set"

nominal_primrec"bnds (Var x) = {}""bnds (App t1 t2) = bnds (t1) [ bnds (t2)""bnds (Lam [x].t) = bnds (t) [ {x}"

lemmashows "bnds (Lam [x].Var x) = {x}"and "bnds (Lam [y].Var y) = {y}"

by (simp_all)

Eugene, 26. July 2008 – p. 21/49

Assume x 6= y.

Lam [x].Var x = Lam [y].Var y

bnds (Lam [x].Var x) = bnds (Lam [y].Var y)

{x} = {y}

Page 43: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Bound Names FunctionHowever there is a problem with the bound namesfunction:

constsbnds :: "lam) name set"

nominal_primrec"bnds (Var x) = {}""bnds (App t1 t2) = bnds (t1) [ bnds (t2)""bnds (Lam [x].t) = bnds (t) [ {x}"

lemmashows "bnds (Lam [x].Var x) = {x}"and "bnds (Lam [y].Var y) = {y}"

by (simp_all)

Eugene, 26. July 2008 – p. 21/49

Assume x 6= y.

Lam [x].Var x = Lam [y].Var y

bnds (Lam [x].Var x) = bnds (Lam [y].Var y)

{x} = {y}

Page 44: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Bound Names FunctionHowever there is a problem with the bound namesfunction:

constsbnds :: "lam) name set"

nominal_primrec"bnds (Var x) = {}""bnds (App t1 t2) = bnds (t1) [ bnds (t2)""bnds (Lam [x].t) = bnds (t) [ {x}"

lemmashows "bnds (Lam [x].Var x) = {x}"and "bnds (Lam [y].Var y) = {y}"

by (simp_all)

Eugene, 26. July 2008 – p. 21/49

Assume x 6= y.

Lam [x].Var x = Lam [y].Var y

bnds (Lam [x].Var x) = bnds (Lam [y].Var y)

{x} = {y}

Page 45: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Bound Names FunctionHowever there is a problem with the bound namesfunction:

constsbnds :: "lam) name set"

nominal_primrec"bnds (Var x) = {}""bnds (App t1 t2) = bnds (t1) [ bnds (t2)""bnds (Lam [x].t) = bnds (t) [ {x}"

lemmashows "bnds (Lam [x].Var x) = {x}"and "bnds (Lam [y].Var y) = {y}"

by (simp_all)

Eugene, 26. July 2008 – p. 21/49

Page 46: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Capture-Avoiding Subst.constssubst :: "lam) name) lam) lam" ("_[_::=_]")

nominal_primrec"(Var x)[y::=s] = (if x=y then s else (Var x))""(App t1 t2)[y::=s] = App (t1[y::=s]) (t2[y::=s])""x#(y,s) =) (Lam [x].t)[y::=s] = Lam [x].(t[y::=s])"

Eugene, 26. July 2008 – p. 22/49

Page 47: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Capture-Avoiding Subst.constssubst :: "lam) name) lam) lam" ("_[_::=_]")

nominal_primrec"(Var x)[y::=s] = (if x=y then s else (Var x))""(App t1 t2)[y::=s] = App (t1[y::=s]) (t2[y::=s])""x#(y,s) =) (Lam [x].t)[y::=s] = Lam [x].(t[y::=s])"

Eugene, 26. July 2008 – p. 22/49

Freshness Condition for Binders (FCB)8a ts: a # f ) a # f a ts

Vx1 y1. ::: ::: =) x1 # Lam [x1].y1

Page 48: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Capture-Avoiding Subst.constssubst :: "lam) name) lam) lam" ("_[_::=_]")

nominal_primrec"(Var x)[y::=s] = (if x=y then s else (Var x))""(App t1 t2)[y::=s] = App (t1[y::=s]) (t2[y::=s])""x#(y,s) =) (Lam [x].t)[y::=s] = Lam [x].(t[y::=s])"

Eugene, 26. July 2008 – p. 22/49

Freshness Condition for Binders (FCB)8a ts: a # f ) a # f a tsV

x1 y1. ::: ::: =) x1 # Lam [x1].y1

Page 49: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Capture-Avoiding Subst.constssubst :: "lam) name) lam) lam" ("_[_::=_]")

nominal_primrec"(Var x)[y::=s] = (if x=y then s else (Var x))""(App t1 t2)[y::=s] = App (t1[y::=s]) (t2[y::=s])""x#(y,s) =) (Lam [x].t)[y::=s] = Lam [x].(t[y::=s])"

apply(finite_guess)+apply(rule TrueI)+apply(simp add: abs_fresh)+apply(fresh_guess)+done

Eugene, 26. July 2008 – p. 22/49

Freshness Condition for Binders (FCB)8a ts: a # f ) a # f a tsV

x1 y1. ::: ::: =) x1 # Lam [x1].y1

Page 50: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Capture-Avoiding Subst.constssubst :: "lam) name) lam) lam" ("_[_::=_]")

nominal_primrec"(Var x)[y::=s] = (if x=y then s else (Var x))""(App t1 t2)[y::=s] = App (t1[y::=s]) (t2[y::=s])""x#(y,s) =) (Lam [x].t)[y::=s] = Lam [x].(t[y::=s])"

apply(finite_guess)+apply(rule TrueI)+apply(simp add: abs_fresh)+apply(fresh_guess)+done

Eugene, 26. July 2008 – p. 22/49

FCB for Bound Variable Function:Vx1 y1. ::: ::: =) x1 # (y1 [ {x1})

Freshness Condition for Binders (FCB)8a ts: a # f ) a # f a tsV

x1 y1. ::: ::: =) x1 # Lam [x1].y1

Page 51: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Evaluation Relationinductiveeval :: "lam) lam) bool" ("_ + _")

wheree_Lam: "Lam [x].t + Lam [x].t"j e_App: "[[t1+ Lam [x].t; t2+ v’; t[x::=v’]+ v]] =) App t1 t2 + v"

declare eval.intros[intro]

Eugene, 26. July 2008 – p. 23/49

Page 52: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Evaluation Relationinductiveeval :: "lam) lam) bool" ("_ + _")

wheree_Lam: "Lam [x].t + Lam [x].t"j e_App: "[[t1+ Lam [x].t; t2+ v’; t[x::=v’]+ v]] =) App t1 t2 + v"

declare eval.intros[intro]

Eugene, 26. July 2008 – p. 23/49

Lam [x].t + Lam [x].t

t1 + Lam [x].t t2 + v’ t[x::=v’] + vApp t1 t2 + v

Page 53: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Valuesinductiveval :: "lam) bool"

wherev_Lam[intro]: "val (Lam [x].e)"

lemma eval_to_val:assumes a: "t + t’"shows "val t’"

using a by (induct) (auto)

If our language contained natural numbers,booleans, etc., we would expand on this definition.

Eugene, 26. July 2008 – p. 24/49

Page 54: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Valuesinductiveval :: "lam) bool"

wherev_Lam[intro]: "val (Lam [x].e)"

lemma eval_to_val:assumes a: "t + t’"shows "val t’"

using a by (induct) (auto)

If our language contained natural numbers,booleans, etc., we would expand on this definition.

Eugene, 26. July 2008 – p. 24/49

Page 55: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CK MachineA CK machine works on configurations h_,_iconsisting of a lambda-term and a list of contexts.

inductivemachine :: "lam)ctxs)lam)ctxs)bool" ("h_,_i 7! h_,_i")

wherem1: "hApp e1 e2,Esi 7! he1,(CAppL � e2)#Esi"j m2: "val v =) hv,(CAppL � e2)#Esi 7! he2,(CAppR v �)#Esi"j m3: "val v =) hv,(CAppR (Lam [x].e) �)#Esi 7! he[x::=v],Esi"

inductive"machines" :: "lam)ctxs)lam)ctxs)bool" ("h_,_i 7!* h_,_i")

wherems1: "he,Esi 7!* he,Esi"j ms2: "[[he1,Es1i 7! he2,Es2i; he2,Es2i 7!* he3,Es3i]]

=) he1,Es1i 7!* he3,Es3i"

Eugene, 26. July 2008 – p. 25/49

Page 56: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CK MachineA CK machine works on configurations h_,_iconsisting of a lambda-term and a list of contexts.

inductivemachine :: "lam)ctxs)lam)ctxs)bool" ("h_,_i 7! h_,_i")

wherem1: "hApp e1 e2,Esi 7! he1,(CAppL � e2)#Esi"j m2: "val v =) hv,(CAppL � e2)#Esi 7! he2,(CAppR v �)#Esi"j m3: "val v =) hv,(CAppR (Lam [x].e) �)#Esi 7! he[x::=v],Esi"

inductive"machines" :: "lam)ctxs)lam)ctxs)bool" ("h_,_i 7!* h_,_i")

wherems1: "he,Esi 7!* he,Esi"j ms2: "[[he1,Es1i 7! he2,Es2i; he2,Es2i 7!* he3,Es3i]]

=) he1,Es1i 7!* he3,Es3i"

Eugene, 26. July 2008 – p. 25/49

Initial state ofthe CK machine:

ht,[]i

Page 57: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CK MachineA CK machine works on configurations h_,_iconsisting of a lambda-term and a list of contexts.

inductivemachine :: "lam)ctxs)lam)ctxs)bool" ("h_,_i 7! h_,_i")

wherem1: "hApp e1 e2,Esi 7! he1,(CAppL � e2)#Esi"j m2: "val v =) hv,(CAppL � e2)#Esi 7! he2,(CAppR v �)#Esi"j m3: "val v =) hv,(CAppR (Lam [x].e) �)#Esi 7! he[x::=v],Esi"

inductive"machines" :: "lam)ctxs)lam)ctxs)bool" ("h_,_i 7!* h_,_i")

wherems1: "he,Esi 7!* he,Esi"j ms2: "[[he1,Es1i 7! he2,Es2i; he2,Es2i 7!* he3,Es3i]]

=) he1,Es1i 7!* he3,Es3i"Eugene, 26. July 2008 – p. 25/49

Page 58: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Our GoalOur goal is to show that the result the machinecalculates corresponds to the value the evaluationrelation generates and vice versa. That means:

t + v() ht,[]i 7!* hv,[]i

with v being a value.

Eugene, 26. July 2008 – p. 26/49

Page 59: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Left-to-Right Direction

lemma ms3:assumes a: "he1,Es1i 7!* he2,Es2i" "he2,Es2i 7!* he3,Es3i"shows "he1,Es1i 7!* he3,Es3i"

using a by (induct) (auto)

theorem eval_implies_machines_ctx:assumes a: "t + t’"shows "ht,Esi 7!* ht’,Esi"

using aby (induct arbitrary: Es)

(metis eval_to_val machine.intros ms1 ms2 ms3 v_Lam)+

corollary eval_implies_machines:assumes a: "t + t’"shows "ht,[]i 7!* ht’,[]i"

using a using eval_implies_machines_ctx by simpEugene, 26. July 2008 – p. 27/49

Page 60: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Left-to-Right Directionlemma ms3:assumes a: "he1,Es1i 7!* he2,Es2i" "he2,Es2i 7!* he3,Es3i"shows "he1,Es1i 7!* he3,Es3i"

using a by (induct) (auto)

theorem eval_implies_machines_ctx:assumes a: "t + t’"shows "ht,Esi 7!* ht’,Esi"

using aby (induct arbitrary: Es)

(metis eval_to_val machine.intros ms1 ms2 ms3 v_Lam)+

corollary eval_implies_machines:assumes a: "t + t’"shows "ht,[]i 7!* ht’,[]i"

using a using eval_implies_machines_ctx by simpEugene, 26. July 2008 – p. 27/49

Page 61: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Left-to-Right Directionlemma ms3:assumes a: "he1,Es1i 7!* he2,Es2i" "he2,Es2i 7!* he3,Es3i"shows "he1,Es1i 7!* he3,Es3i"

using a by (induct) (auto)

theorem eval_implies_machines_ctx:assumes a: "t + t’"shows "ht,Esi 7!* ht’,Esi"

using aby (induct arbitrary: Es)

(metis eval_to_val machine.intros ms1 ms2 ms3 v_Lam)+

corollary eval_implies_machines:assumes a: "t + t’"shows "ht,[]i 7!* ht’,[]i"

using a using eval_implies_machines_ctx by simpEugene, 26. July 2008 – p. 27/49

Page 62: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Left-to-Right Directionlemma ms3:assumes a: "he1,Es1i 7!* he2,Es2i" "he2,Es2i 7!* he3,Es3i"shows "he1,Es1i 7!* he3,Es3i"

using a by (induct) (auto)

theorem eval_implies_machines_ctx:assumes a: "t + t’"shows "ht,Esi 7!* ht’,Esi"

using aby (induct arbitrary: Es)

(metis eval_to_val machine.intros ms1 ms2 ms3 v_Lam)+

corollary eval_implies_machines:assumes a: "t + t’"shows "ht,[]i 7!* ht’,[]i"

using a using eval_implies_machines_ctx by simpEugene, 26. July 2008 – p. 27/49

Sledgehammer:Can be used at any point in the development.

Isabelle

externalprover

problem

hints

Page 63: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Left-to-Right Directionlemma ms3:assumes a: "he1,Es1i 7!* he2,Es2i" "he2,Es2i 7!* he3,Es3i"shows "he1,Es1i 7!* he3,Es3i"

using a by (induct) (auto)

theorem eval_implies_machines_ctx:assumes a: "t + t’"shows "ht,Esi 7!* ht’,Esi"

using aby (induct arbitrary: Es)

(metis eval_to_val machine.intros ms1 ms2 ms3 v_Lam)+

corollary eval_implies_machines:assumes a: "t + t’"shows "ht,[]i 7!* ht’,[]i"

using a using eval_implies_machines_ctx by simpEugene, 26. July 2008 – p. 27/49

Sledgehammer:Can be used at any point in the development.

Isabelle externalprover

problem

hints

Page 64: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Left-to-Right Directionlemma ms3:assumes a: "he1,Es1i 7!* he2,Es2i" "he2,Es2i 7!* he3,Es3i"shows "he1,Es1i 7!* he3,Es3i"

using a by (induct) (auto)

theorem eval_implies_machines_ctx:assumes a: "t + t’"shows "ht,Esi 7!* ht’,Esi"

using aby (induct arbitrary: Es)

(metis eval_to_val machine.intros ms1 ms2 ms3 v_Lam)+

corollary eval_implies_machines:assumes a: "t + t’"shows "ht,[]i 7!* ht’,[]i"

using a using eval_implies_machines_ctx by simpEugene, 26. July 2008 – p. 27/49

Sledgehammer:Can be used at any point in the development.

Isabelle externalprover

problem

hints

Page 65: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Left-to-Right Directionlemma ms3:assumes a: "he1,Es1i 7!* he2,Es2i" "he2,Es2i 7!* he3,Es3i"shows "he1,Es1i 7!* he3,Es3i"

using a by (induct) (auto)

theorem eval_implies_machines_ctx:assumes a: "t + t’"shows "ht,Esi 7!* ht’,Esi"

using aby (induct arbitrary: Es)

(metis eval_to_val machine.intros ms1 ms2 ms3 v_Lam)+

corollary eval_implies_machines:assumes a: "t + t’"shows "ht,[]i 7!* ht’,[]i"

using a using eval_implies_machines_ctx by simpEugene, 26. July 2008 – p. 27/49

Page 66: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Right-to-Left DirectionThe statement for the other direction is asfollows:

lemma machines_implies_eval:assumes a: "ht,[]i 7!* hv,[]i"and b: "val v"shows "t + v"

We can prove this direction by introducing asmall-step reduction relation.

Eugene, 26. July 2008 – p. 28/49

Page 67: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Right-to-Left DirectionThe statement for the other direction is asfollows:

lemma machines_implies_eval:assumes a: "ht,[]i 7!* hv,[]i"and b: "val v"shows "t + v"oops

We can prove this direction by introducing asmall-step reduction relation.

Eugene, 26. July 2008 – p. 28/49

Page 68: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Right-to-Left DirectionThe statement for the other direction is asfollows:

lemma machines_implies_eval:assumes a: "ht,[]i 7!* hv,[]i"and b: "val v"shows "t + v"oops

We can prove this direction by introducing asmall-step reduction relation.

Eugene, 26. July 2008 – p. 28/49

Page 69: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CBV Reductioninductivecbv :: "lam)lam)bool" ("_�!cbv _")

wherecbv1: "val v =) App (Lam [x].t) v�!cbv t[x::=v]"j cbv2: "t�!cbv t’ =) App t t2 �!cbv App t’ t2"j cbv3: "t�!cbv t’ =) App t2 t�!cbv App t2 t’"

Later on we like to use the strong inductionprinciple for this relation.

Eugene, 26. July 2008 – p. 29/49

Page 70: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CBV Reductioninductivecbv :: "lam)lam)bool" ("_�!cbv _")

wherecbv1: "val v =) App (Lam [x].t) v�!cbv t[x::=v]"j cbv2: "t�!cbv t’ =) App t t2 �!cbv App t’ t2"j cbv3: "t�!cbv t’ =) App t2 t�!cbv App t2 t’"

Later on we like to use the strong inductionprinciple for this relation.

Eugene, 26. July 2008 – p. 29/49

Conditions:1.Vv x t. val v =) x # App Lam [x].t v

2.Vv x t. val v =) x # t[x::=v]

Page 71: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CBV Reductioninductivecbv :: "lam)lam)bool" ("_�!cbv _")

wherecbv1: "[[val v; x#v]] =) App (Lam [x].t) v�!cbv t[x::=v]"j cbv2[intro]: "t�!cbv t’ =) App t t2 �!cbv App t’ t2"j cbv3[intro]: "t�!cbv t’ =) App t2 t�!cbv App t2 t’"

The conditions that give us automatically thestrong induction principle require us to add theassumption x # v. This makes this rule lessuseful.

Eugene, 26. July 2008 – p. 30/49

Page 72: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Strong Induction Principlelemma subst_eqvt[eqvt]:fixes �::"name prm"shows "��(t1[x::=t2]) = (��t1)[(��x)::=(��t2)]"

by (nominal_induct t1 avoiding: x t2 rule: lam.strong_induct)(auto simp add: perm_bij fresh_atm fresh_bij)

lemma fresh_fact:fixes z::"name"shows "[[z#s; (z=y _ z#t)]] =) z#t[y::=s]"

by (nominal_induct t avoiding: z y s rule: lam.strong_induct)(auto simp add: abs_fresh fresh_prod fresh_atm)

equivariance valequivariance cbvnominal_inductive cbvby (simp_all add: abs_fresh fresh_fact)

Eugene, 26. July 2008 – p. 31/49

Page 73: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

lemma subst_rename:assumes a: "y#t"shows "t[x::=s] = ([(y,x)]�t)[y::=s]"

using aby (nominal_induct t avoiding: x y s rule: lam.strong_induct)

(auto simp add: calc_atm fresh_atm abs_fresh)

lemma better_cbv1[intro]:assumes a: "val v"shows "App (Lam [x].t) v�!cbv t[x::=v]"

proof -obtain y::"name" where fs: "y#(x,t,v)"

by (rule exists_fresh) (auto simp add: fs_name1)have "App (Lam [x].t) v = App (Lam [y].([(y,x)]�t)) v" using fs

by (auto simp add: lam.inject alpha’ fresh_prod fresh_atm)also have ":::�!cbv ([(y,x)]�t)[y::=v]" using fs a

by (auto simp add: cbv1 fresh_prod)also have "::: = t[x::=v]" using fs

by (simp add: subst_rename[symmetric] fresh_prod)finally show "App (Lam [x].t) v�!cbv t[x::=v]" by simp

qedEugene, 26. July 2008 – p. 32/49

Page 74: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CBV Reduction?inductive"cbvs" :: "lam) lam) bool" (" _�!cbv* _")

wherecbvs1[intro]: "e�!cbv* e"j cbvs2[intro]: "[[e1�!cbv e2; e2 �!cbv* e3]] =) e1 �!cbv* e3"

lemma cbvs3[intro]:assumes a: "e1 �!cbv* e2" "e2 �!cbv* e3"shows "e1 �!cbv* e3"

using a by (induct) (auto)

lemma cbv_in_ctx:assumes a: "t�!cbv t’"shows "E[[t]] �!cbv E[[t’]]"

using a by (induct E) (auto)

Eugene, 26. July 2008 – p. 33/49

Page 75: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CBV Reduction?inductive"cbvs" :: "lam) lam) bool" (" _�!cbv* _")

wherecbvs1[intro]: "e�!cbv* e"j cbvs2[intro]: "[[e1�!cbv e2; e2 �!cbv* e3]] =) e1 �!cbv* e3"

lemma cbvs3[intro]:assumes a: "e1 �!cbv* e2" "e2 �!cbv* e3"shows "e1 �!cbv* e3"

using a by (induct) (auto)

lemma cbv_in_ctx:assumes a: "t�!cbv t’"shows "E[[t]] �!cbv E[[t’]]"

using a by (induct E) (auto)

Eugene, 26. July 2008 – p. 33/49

Page 76: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CK Machine Implies CBV?

lemma machine_implies_cbvs_ctx:assumes a: "he,Esi 7! he’,Es’i"shows "(Es#)[[e]] �!cbv* (Es’#)[[e’]]"

using a by (induct) (auto simp add: ctx_compose intro: cbv_in_ctx)

lemma machines_implies_cbvs_ctx:assumes a: "he,Esi 7!* he’,Es’i"shows "(Es#)[[e]] �!cbv* (Es’#)[[e’]]"

using aby (induct) (auto dest: machine_implies_cbvs_ctx)

lemma machines_implies_cbvs:assumes a: "he,[]i 7!* he’,[]i"shows "e�!cbv* e’"

using a by (auto dest: machines_implies_cbvs_ctx)

Eugene, 26. July 2008 – p. 34/49

Page 77: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CK Machine Implies CBV?

lemma machine_implies_cbvs_ctx:assumes a: "he,Esi 7! he’,Es’i"shows "(Es#)[[e]] �!cbv* (Es’#)[[e’]]"

using a by (induct) (auto simp add: ctx_compose intro: cbv_in_ctx)

lemma machines_implies_cbvs_ctx:assumes a: "he,Esi 7!* he’,Es’i"shows "(Es#)[[e]] �!cbv* (Es’#)[[e’]]"

using aby (induct) (auto dest: machine_implies_cbvs_ctx)

lemma machines_implies_cbvs:assumes a: "he,[]i 7!* he’,[]i"shows "e�!cbv* e’"

using a by (auto dest: machines_implies_cbvs_ctx)

Eugene, 26. July 2008 – p. 34/49

Page 78: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CK Machine Implies CBV?

lemma machine_implies_cbvs_ctx:assumes a: "he,Esi 7! he’,Es’i"shows "(Es#)[[e]] �!cbv* (Es’#)[[e’]]"

using a by (induct) (auto simp add: ctx_compose intro: cbv_in_ctx)

lemma machines_implies_cbvs_ctx:assumes a: "he,Esi 7!* he’,Es’i"shows "(Es#)[[e]] �!cbv* (Es’#)[[e’]]"

using aby (induct) (auto dest: machine_implies_cbvs_ctx)

lemma machines_implies_cbvs:assumes a: "he,[]i 7!* he’,[]i"shows "e�!cbv* e’"

using a by (auto dest: machines_implies_cbvs_ctx)

Eugene, 26. July 2008 – p. 34/49

If we had not derived the bettercbv-rule, then we would have to do anexplicit renaming here.

Page 79: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CK Machine Implies CBV?

lemma machine_implies_cbvs_ctx:assumes a: "he,Esi 7! he’,Es’i"shows "(Es#)[[e]] �!cbv* (Es’#)[[e’]]"

using a by (induct) (auto simp add: ctx_compose intro: cbv_in_ctx)

lemma machines_implies_cbvs_ctx:assumes a: "he,Esi 7!* he’,Es’i"shows "(Es#)[[e]] �!cbv* (Es’#)[[e’]]"

using aby (induct) (auto dest: machine_implies_cbvs_ctx)

lemma machines_implies_cbvs:assumes a: "he,[]i 7!* he’,[]i"shows "e�!cbv* e’"

using a by (auto dest: machines_implies_cbvs_ctx)

Eugene, 26. July 2008 – p. 34/49

Page 80: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

CBV? Implies EvaluationWe need the following scaffolding lemmas inorder to show that cbv-reduction impliesevaluation.

lemma eval_val:assumes a: "val t"shows "t + t"

using a by (induct) (auto)

lemma e_App_elim:assumes a: "App t1 t2 + v"shows "9 x t v’. t1 + Lam [x].t ^ t2 + v’ ^ t[x::=v’] + v"

using a by (cases) (auto simp add: lam.inject)

Eugene, 26. July 2008 – p. 35/49

Page 81: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

lemma cbv_eval:assumes a: "t1 �!cbv t2" "t2 + t3"shows "t1 + t3"

using aby (induct arbitrary: t3)

(auto intro: eval_val dest!: e_App_elim)

lemma cbvs_eval:assumes a: "t1 �!cbv* t2" "t2 + t3"shows "t1 + t3"

using a by (induct) (auto simp add: cbv_eval)

lemma cbvs_implies_eval:assumes a: "t�!cbv* v" "val v"shows "t + v"

using aby (induct)

(auto simp add: eval_val cbvs_eval dest: cbvs2)Eugene, 26. July 2008 – p. 36/49

Page 82: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Right-to-Left DirectionVia the the cbv-reduction relation we can finallyshow that the CK machine implies the evaluationrelation.

theorem machines_implies_eval:assumes a: "ht1,[]i 7!* ht2,[]i"and b: "val t2"shows "t1 + t2"

proof -from a have "t1 �!cbv* t2" by (simp add: machines_implies_cbvs)then show "t1 + t2" using b by (simp add: cbvs_implies_eval)

qed

Eugene, 26. July 2008 – p. 37/49

Page 83: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Preservation and ProgressNext we like to prove a type preservation and anprogress lemma for the cbv-reduction relation.

theorem cbv_type_preservation:assumes a: "t�!cbv t’"and b: "� ` t : T"shows "� ` t’ : T"

theorem progress:assumes a: "[] ` t : T"shows "(9 t’. t�!cbv t’) _ (val t)"

We need the property of type-substitutivity.

Eugene, 26. July 2008 – p. 38/49

Page 84: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Preservation and ProgressNext we like to prove a type preservation and anprogress lemma for the cbv-reduction relation.

theorem cbv_type_preservation:assumes a: "t�!cbv t’"and b: "� ` t : T"shows "� ` t’ : T"

theorem progress:assumes a: "[] ` t : T"shows "(9 t’. t�!cbv t’) _ (val t)"

We need the property of type-substitutivity.

Eugene, 26. July 2008 – p. 38/49

Page 85: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Some Side-Lemmaslemma valid_elim:assumes a: "valid ((x,T)#� )"shows "x#� ^ valid � "

using a by (cases) (auto)

lemma valid_insert:assumes a: "valid (�@[(x,T)]@� )"shows "valid (�@� )"

using aby (induct �)

(auto simp add: fresh_list_append fresh_list_cons dest!: valid_elim)

lemma fresh_list:shows "y#xs = (8 x 2 set xs. y#x)"

by (induct xs) (simp_all add: fresh_list_nil fresh_list_cons)

lemma context_unique:assumes a1: "valid � "and a2: "(x,T) 2 set � "and a3: "(x,U) 2 set � "

shows "T = U"using a1 a2 a3by (induct) (auto simp add: fresh_list fresh_prod fresh_atm) Eugene, 26. July 2008 – p. 39/49

Page 86: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

lemma type_substitution_aux:assumes a: "�@[(x,T’)]@� ` e : T"and b: "� ` e’ : T’"shows "�@� ` e[x::=e’] : T"

using a bproof (nominal_induct � ’�"�@[(x,T’)]@� " e T

avoiding: x e’ � rule: typing.strong_induct)case (t_Var � ’ y T x e’ �)then have a1: "valid (�@[(x,T’)]@� )"

and a2: "(y,T) 2 set (�@[(x,T’)]@� )"and a3: "� ` e’ : T’" by simp_all

from a1 have a4: "valid (�@� )" by (rule valid_insert){ assume eq: "x=y"from a1 a2 have "T=T’" using eq by (auto intro: context_unique)with a3 have "�@� ` Var y[x::=e’] : T" using eq a4 by (auto intro: weakening) }

moreover{ assume ineq: "x6=y"from a2 have "(y,T) 2 set (�@� )" using ineq by simpthen have "�@� ` Var y[x::=e’] : T" using ineq a4 by auto }

ultimately show "�@� ` Var y[x::=e’] : T" by blastqed (force simp add: fresh_list_append fresh_list_cons)+

Eugene, 26. July 2008 – p. 40/49

corollary type_substitution:assumes a: "(x,T’)#� ` e : T"and b: "� ` e’ : T’"shows "� ` e[x::=e’] : T"

Page 87: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

lemma type_substitution_aux:assumes a: "�@[(x,T’)]@� ` e : T"and b: "� ` e’ : T’"shows "�@� ` e[x::=e’] : T"

using a bproof (nominal_induct � ’�"�@[(x,T’)]@� " e T

avoiding: x e’ � rule: typing.strong_induct)case (t_Var � ’ y T x e’ �)then have a1: "valid (�@[(x,T’)]@� )"

and a2: "(y,T) 2 set (�@[(x,T’)]@� )"and a3: "� ` e’ : T’" by simp_all

from a1 have a4: "valid (�@� )" by (rule valid_insert){ assume eq: "x=y"from a1 a2 have "T=T’" using eq by (auto intro: context_unique)with a3 have "�@� ` Var y[x::=e’] : T" using eq a4 by (auto intro: weakening) }

moreover{ assume ineq: "x6=y"from a2 have "(y,T) 2 set (�@� )" using ineq by simpthen have "�@� ` Var y[x::=e’] : T" using ineq a4 by auto }

ultimately show "�@� ` Var y[x::=e’] : T" by blastqed (force simp add: fresh_list_append fresh_list_cons)+

Eugene, 26. July 2008 – p. 40/49

Page 88: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

lemma type_substitution_aux:assumes a: "�@[(x,T’)]@� ` e : T"and b: "� ` e’ : T’"shows "�@� ` e[x::=e’] : T"

using a bproof (nominal_induct � ’�"�@[(x,T’)]@� " e T

avoiding: x e’ � rule: typing.strong_induct)case (t_Var � ’ y T x e’ �)then have a1: "valid (�@[(x,T’)]@� )"

and a2: "(y,T) 2 set (�@[(x,T’)]@� )"and a3: "� ` e’ : T’" by simp_all

from a1 have a4: "valid (�@� )" by (rule valid_insert){ assume eq: "x=y"from a1 a2 have "T=T’" using eq by (auto intro: context_unique)with a3 have "�@� ` Var y[x::=e’] : T" using eq a4 by (auto intro: weakening) }

moreover{ assume ineq: "x6=y"from a2 have "(y,T) 2 set (�@� )" using ineq by simpthen have "�@� ` Var y[x::=e’] : T" using ineq a4 by auto }

ultimately show "�@� ` Var y[x::=e’] : T" by blastqed (force simp add: fresh_list_append fresh_list_cons)+

Eugene, 26. July 2008 – p. 40/49

valid � (x, T) 2 set �� ` Var x : T

Page 89: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Type Substitutivitylemma type_substitution_aux:assumes a: "�@[(x,T’)]@� ` e : T"and b: "� ` e’ : T’"shows "�@� ` e[x::=e’] : T"

corollary type_substitution:assumes a: "(x,T’)#� ` e : T"and b: "� ` e’ : T’"shows "� ` e[x::=e’] : T"

using a b type_substitution_aux[where �="[]"]by (auto)

Eugene, 26. July 2008 – p. 41/49

Page 90: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Inversion Lemmaslemma t_App_elim:assumes a: "� ` App t1 t2 : T"shows "9 T’. � ` t1 : T’! T ^ � ` t2 : T’"

using a by (cases) (auto simp add: lam.inject)

lemma t_Lam_elim:assumes ty: "� ` Lam [x].t : T"and fc: "x#� "shows "9 T1 T2. T = T1 ! T2 ^ (x,T1)#� ` t : T2"

using ty fcby (cases rule: typing.strong_cases)

(auto simp add: alpha lam.inject abs_fresh ty_fresh)

Eugene, 26. July 2008 – p. 42/49

� ` t1 : T1 ! T2 � ` t2 : T1

� ` App t1 t2 : T2

x # � (x, T1)::� ` t : T2

� ` Lam [x].t : T1 ! T2

Page 91: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Type Preservation

Eugene, 26. July 2008 – p. 43/49

theorem cbv_type_preservation:assumes a: "t�!cbv t’"and b: "� ` t : T"shows "� ` t’ : T"

using a bby (nominal_induct avoiding: � T rule: cbv.strong_induct)

(auto dest!: t_Lam_elim t_App_elimsimp add: type_substitution ty.inject)

corollary cbvs_type_preservation:assumes a: "t�!cbv* t’"and b: "� ` t : T"shows "� ` t’ : T"

using a bby (induct) (auto intro: cbv_type_preservation)

Page 92: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Progress LemmaFinally we can establish the progress lemma:

lemma canonical_tArr:assumes a: "[] ` t : T1! T2"and b: "val t"shows "9 x t’. t = Lam [x].t’"

using b a by (induct) (auto)

This lemma is stated with extensions in mind.

theorem progress:assumes a: "[] ` t : T"shows "(9 t’. t�!cbv t’) _ (val t)"

using aby (induct ��"[]::ty_ctx" t T)

(auto intro!: cbv.intros dest: canonical_tArr)Eugene, 26. July 2008 – p. 44/49

Page 93: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Progress LemmaFinally we can establish the progress lemma:

lemma canonical_tArr:assumes a: "[] ` t : T1! T2"and b: "val t"shows "9 x t’. t = Lam [x].t’"

using b a by (induct) (auto)

This lemma is stated with extensions in mind.theorem progress:assumes a: "[] ` t : T"shows "(9 t’. t�!cbv t’) _ (val t)"

using aby (induct ��"[]::ty_ctx" t T)

(auto intro!: cbv.intros dest: canonical_tArr)Eugene, 26. July 2008 – p. 44/49

Page 94: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

ExtensionsWith only minimal modifications the proofs can beextended to the language given by:

nominal_datatype lam =Var "name"j App "lam" "lam"j Lam "«name»lam" ("Lam [_]._")j Num "nat"j Minus "lam" "lam" ("_ -- _")j Plus "lam" "lam" ("_ ++ _")j TRUEj FALSEj IF "lam" "lam" "lam"j Fix "«name»lam" ("Fix [_]._")j Zet "lam"j Eqi "lam" "lam"

Eugene, 26. July 2008 – p. 45/49

Page 95: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Formalisation of LF(joint work with Cheney and Berghofer)

1. Solution Proofdef= Alg.

1st Solution Proofdef=

+ex Alg.

2nd Solution Proofdef= Alg.-ex

3rd Solution Proofdef= Alg.

Eugene, 26. July 2008 – p. 46/49

2h

Page 96: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Formalisation of LF(joint work with Cheney and Berghofer)

1. Solution Proofdef= Alg.

1st Solution Proofdef=

+ex Alg.

2nd Solution Proofdef= Alg.-ex

3rd Solution Proofdef= Alg.

Eugene, 26. July 2008 – p. 46/49

2h

Page 97: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Formalisation of LF(joint work with Cheney and Berghofer)

1. Solution Proofdef= Alg.

1st Solution Proofdef=

+ex Alg.

2nd Solution Proofdef= Alg.-ex

3rd Solution Proofdef= Alg.

Eugene, 26. July 2008 – p. 46/49(each time one needs to check�31pp of informal paper proofs)

2h

Page 98: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Formalisation of LF(joint work with Cheney and Berghofer)

1. Solution Proofdef= Alg.

1st Solution Proofdef=

+ex Alg.

2nd Solution Proofdef= Alg.-ex

3rd Solution Proofdef= Alg.

Eugene, 26. July 2008 – p. 46/49(each time one needs to check�31pp of informal paper proofs)

2h

Page 99: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Formalisation of LF(joint work with Cheney and Berghofer)

1. Solution Proofdef= Alg.

1st Solution Proofdef=

+ex Alg.

2nd Solution Proofdef= Alg.-ex

3rd Solution Proofdef= Alg.

Eugene, 26. July 2008 – p. 46/49(each time one needs to check�31pp of informal paper proofs)

2h

Page 100: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Two Health Warnings ;o)Theorem provers should come with two healthwarnings:

Theorem provers are addictive!(Xavier Leroy: “Building [proof] scripts is surprisinglyaddictive, in a videogame kind of way...”)

Theorem provers cause you to lose faith in yourproofs done by hand!(Michael Norrish, Mike Gordon, me, very possibly others)

Eugene, 26. July 2008 – p. 47/49

Page 101: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Two Health Warnings ;o)Theorem provers should come with two healthwarnings:

Theorem provers are addictive!(Xavier Leroy: “Building [proof] scripts is surprisinglyaddictive, in a videogame kind of way...”)

Theorem provers cause you to lose faith in yourproofs done by hand!(Michael Norrish, Mike Gordon, me, very possibly others)

Eugene, 26. July 2008 – p. 47/49

Page 102: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Two Health Warnings ;o)Theorem provers should come with two healthwarnings:

Theorem provers are addictive!(Xavier Leroy: “Building [proof] scripts is surprisinglyaddictive, in a videogame kind of way...”)

Theorem provers cause you to lose faith in yourproofs done by hand!(Michael Norrish, Mike Gordon, me, very possibly others)

Eugene, 26. July 2008 – p. 47/49

Page 103: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Answers to ExercisesGiven a finite set of atoms. What is the supportof this set?

If S is finite, then supp(S) = S.

What is the support of the set of all atoms?Let A = fa0; a1 : : :g, then supp(A) = ?.

From the set of all atoms take one atom out.What is the support of the resulting set?supp(A� fag) = fag.

Are there any sets of atoms that have infinitesupport? If both S and A� S are infinite thensupp(S) = A.

Eugene, 26. July 2008 – p. 48/49

Page 104: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Answers to ExercisesGiven a finite set of atoms. What is the supportof this set? If S is finite, then supp(S) = S.

What is the support of the set of all atoms?Let A = fa0; a1 : : :g, then supp(A) = ?.

From the set of all atoms take one atom out.What is the support of the resulting set?supp(A� fag) = fag.

Are there any sets of atoms that have infinitesupport? If both S and A� S are infinite thensupp(S) = A.

Eugene, 26. July 2008 – p. 48/49

Page 105: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Answers to ExercisesGiven a finite set of atoms. What is the supportof this set? If S is finite, then supp(S) = S.

What is the support of the set of all atoms?

Let A = fa0; a1 : : :g, then supp(A) = ?.

From the set of all atoms take one atom out.What is the support of the resulting set?supp(A� fag) = fag.

Are there any sets of atoms that have infinitesupport? If both S and A� S are infinite thensupp(S) = A.

Eugene, 26. July 2008 – p. 48/49

Page 106: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Answers to ExercisesGiven a finite set of atoms. What is the supportof this set? If S is finite, then supp(S) = S.

What is the support of the set of all atoms?Let A = fa0; a1 : : :g, then supp(A) = ?.

From the set of all atoms take one atom out.What is the support of the resulting set?supp(A� fag) = fag.

Are there any sets of atoms that have infinitesupport? If both S and A� S are infinite thensupp(S) = A.

Eugene, 26. July 2008 – p. 48/49

Page 107: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Answers to ExercisesGiven a finite set of atoms. What is the supportof this set? If S is finite, then supp(S) = S.

What is the support of the set of all atoms?Let A = fa0; a1 : : :g, then supp(A) = ?.

From the set of all atoms take one atom out.What is the support of the resulting set?

supp(A� fag) = fag.

Are there any sets of atoms that have infinitesupport? If both S and A� S are infinite thensupp(S) = A.

Eugene, 26. July 2008 – p. 48/49

Page 108: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Answers to ExercisesGiven a finite set of atoms. What is the supportof this set? If S is finite, then supp(S) = S.

What is the support of the set of all atoms?Let A = fa0; a1 : : :g, then supp(A) = ?.

From the set of all atoms take one atom out.What is the support of the resulting set?supp(A� fag) = fag.

Are there any sets of atoms that have infinitesupport? If both S and A� S are infinite thensupp(S) = A.

Eugene, 26. July 2008 – p. 48/49

Page 109: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Answers to ExercisesGiven a finite set of atoms. What is the supportof this set? If S is finite, then supp(S) = S.

What is the support of the set of all atoms?Let A = fa0; a1 : : :g, then supp(A) = ?.

From the set of all atoms take one atom out.What is the support of the resulting set?supp(A� fag) = fag.

Are there any sets of atoms that have infinitesupport?

If both S and A� S are infinite thensupp(S) = A.

Eugene, 26. July 2008 – p. 48/49

Page 110: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Answers to ExercisesGiven a finite set of atoms. What is the supportof this set? If S is finite, then supp(S) = S.

What is the support of the set of all atoms?Let A = fa0; a1 : : :g, then supp(A) = ?.

From the set of all atoms take one atom out.What is the support of the resulting set?supp(A� fag) = fag.

Are there any sets of atoms that have infinitesupport? If both S and A� S are infinite thensupp(S) = A.

Eugene, 26. July 2008 – p. 48/49

Page 111: nms.kcl.ac.uk · Lambda-Terms We build on the theory Nominal (which in turn builds on HOL). Nominal provides an infra-structure to reason with binders. atom_decl name nominal_datatype

Thank you very much!

Eugene, 26. July 2008 – p. 49/49


Recommended