author | haftmann |
Thu, 19 Jun 2025 17:15:40 +0200 | |
changeset 82734 | 89347c0cc6a3 |
parent 80914 | d97fdabd9e2b |
permissions | -rw-r--r-- |
21107 | 1 |
theory Lam_Funs |
66453
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents:
63167
diff
changeset
|
2 |
imports "HOL-Nominal.Nominal" |
21107 | 3 |
begin |
4 |
||
63167 | 5 |
text \<open> |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
6 |
Provides useful definitions for reasoning |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
7 |
with lambda-terms. |
63167 | 8 |
\<close> |
25751 | 9 |
|
21107 | 10 |
atom_decl name |
11 |
||
22829
f1db55c7534d
tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents:
22540
diff
changeset
|
12 |
nominal_datatype lam = |
f1db55c7534d
tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents:
22540
diff
changeset
|
13 |
Var "name" |
f1db55c7534d
tuned some proofs and changed variable names in some definitions of Nominal.thy
urbanc
parents:
22540
diff
changeset
|
14 |
| App "lam" "lam" |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80149
diff
changeset
|
15 |
| Lam "\<guillemotleft>name\<guillemotright>lam" (\<open>Lam [_]._\<close> [100,100] 100) |
21107 | 16 |
|
63167 | 17 |
text \<open>The depth of a lambda-term.\<close> |
21557
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
18 |
|
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
19 |
nominal_primrec |
21555 | 20 |
depth :: "lam \<Rightarrow> nat" |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
21 |
where |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
22 |
"depth (Var x) = 1" |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
23 |
| "depth (App t1 t2) = (max (depth t1) (depth t2)) + 1" |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
24 |
| "depth (Lam [a].t) = (depth t) + 1" |
80149 | 25 |
by(finite_guess | simp | fresh_guess)+ |
21107 | 26 |
|
63167 | 27 |
text \<open> |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
28 |
The free variables of a lambda-term. A complication in this |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
29 |
function arises from the fact that it returns a name set, which |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
30 |
is not a finitely supported type. Therefore we have to prove |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
31 |
the invariant that frees always returns a finite set of names. |
63167 | 32 |
\<close> |
21557
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
33 |
|
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
34 |
nominal_primrec (invariant: "\<lambda>s::name set. finite s") |
21557
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
35 |
frees :: "lam \<Rightarrow> name set" |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
36 |
where |
21557
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
37 |
"frees (Var a) = {a}" |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
38 |
| "frees (App t1 t2) = (frees t1) \<union> (frees t2)" |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
39 |
| "frees (Lam [a].t) = (frees t) - {a}" |
80149 | 40 |
apply(finite_guess | simp add: fresh_def | fresh_guess)+ |
41 |
apply (simp add: at_fin_set_supp at_name_inst) |
|
22418
49e2d9744ae1
major update of the nominal package; there is now an infrastructure
urbanc
parents:
21557
diff
changeset
|
42 |
apply(fresh_guess)+ |
21557
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
43 |
done |
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
44 |
|
63167 | 45 |
text \<open> |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
46 |
We can avoid the definition of frees by |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
47 |
using the build in notion of support. |
63167 | 48 |
\<close> |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
49 |
|
21557
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
50 |
lemma frees_equals_support: |
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
51 |
shows "frees t = supp t" |
26966
071f40487734
made the naming of the induction principles consistent: weak_induct is
urbanc
parents:
26764
diff
changeset
|
52 |
by (nominal_induct t rule: lam.strong_induct) |
21557
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
53 |
(simp_all add: lam.supp supp_atm abs_supp) |
3c8e29a6e4f0
added the function for free variables of a lambda-term, which is a
urbanc
parents:
21555
diff
changeset
|
54 |
|
63167 | 55 |
text \<open>Parallel and single capture-avoiding substitution.\<close> |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
56 |
|
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
57 |
fun |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
58 |
lookup :: "(name\<times>lam) list \<Rightarrow> name \<Rightarrow> lam" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
59 |
where |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
60 |
"lookup [] x = Var x" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
61 |
| "lookup ((y,e)#\<theta>) x = (if x=y then e else lookup \<theta> x)" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
62 |
|
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
63 |
lemma lookup_eqvt[eqvt]: |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
64 |
fixes pi::"name prm" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
65 |
and \<theta>::"(name\<times>lam) list" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
66 |
and X::"name" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
67 |
shows "pi\<bullet>(lookup \<theta> X) = lookup (pi\<bullet>\<theta>) (pi\<bullet>X)" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
68 |
by (induct \<theta>) (auto simp add: eqvts) |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
69 |
|
21555 | 70 |
nominal_primrec |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80149
diff
changeset
|
71 |
psubst :: "(name\<times>lam) list \<Rightarrow> lam \<Rightarrow> lam" (\<open>_<_>\<close> [95,95] 105) |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
72 |
where |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
73 |
"\<theta><(Var x)> = (lookup \<theta> x)" |
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
29097
diff
changeset
|
74 |
| "\<theta><(App e\<^sub>1 e\<^sub>2)> = App (\<theta><e\<^sub>1>) (\<theta><e\<^sub>2>)" |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
75 |
| "x\<sharp>\<theta> \<Longrightarrow> \<theta><(Lam [x].e)> = Lam [x].(\<theta><e>)" |
80149 | 76 |
by (finite_guess | simp add: abs_fresh | fresh_guess)+ |
21107 | 77 |
|
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
78 |
lemma psubst_eqvt[eqvt]: |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
79 |
fixes pi::"name prm" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
80 |
and t::"lam" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
81 |
shows "pi\<bullet>(\<theta><t>) = (pi\<bullet>\<theta>)<(pi\<bullet>t)>" |
26966
071f40487734
made the naming of the induction principles consistent: weak_induct is
urbanc
parents:
26764
diff
changeset
|
82 |
by (nominal_induct t avoiding: \<theta> rule: lam.strong_induct) |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
83 |
(simp_all add: eqvts fresh_bij) |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
84 |
|
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
85 |
abbreviation |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80149
diff
changeset
|
86 |
subst :: "lam \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam" (\<open>_[_::=_]\<close> [100,100,100] 100) |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
87 |
where |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
88 |
"t[x::=t'] \<equiv> ([(x,t')])<t>" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
89 |
|
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
90 |
lemma subst[simp]: |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
91 |
shows "(Var x)[y::=t'] = (if x=y then t' else (Var x))" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
92 |
and "(App t1 t2)[y::=t'] = App (t1[y::=t']) (t2[y::=t'])" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
93 |
and "x\<sharp>(y,t') \<Longrightarrow> (Lam [x].t)[y::=t'] = Lam [x].(t[y::=t'])" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
94 |
by (simp_all add: fresh_list_cons fresh_list_nil) |
21107 | 95 |
|
96 |
lemma subst_supp: |
|
97 |
shows "supp(t1[a::=t2]) \<subseteq> (((supp(t1)-{a})\<union>supp(t2))::name set)" |
|
80149 | 98 |
proof (nominal_induct t1 avoiding: a t2 rule: lam.strong_induct) |
99 |
case (Var name) |
|
100 |
then show ?case |
|
101 |
by (simp add: lam.supp(1) supp_atm) |
|
102 |
next |
|
103 |
case (App lam1 lam2) |
|
104 |
then show ?case |
|
105 |
using lam.supp(2) by fastforce |
|
106 |
next |
|
107 |
case (Lam name lam) |
|
108 |
then show ?case |
|
109 |
using frees.simps(3) frees_equals_support by auto |
|
110 |
qed |
|
21107 | 111 |
|
63167 | 112 |
text \<open> |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
113 |
Contexts - lambda-terms with a single hole. |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
114 |
Note that the lambda case in contexts does not bind a |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
115 |
name, even if we introduce the notation [_]._ for CLam. |
63167 | 116 |
\<close> |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
117 |
nominal_datatype clam = |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80149
diff
changeset
|
118 |
Hole (\<open>\<box>\<close> 1000) |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
119 |
| CAppL "clam" "lam" |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
120 |
| CAppR "lam" "clam" |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80149
diff
changeset
|
121 |
| CLam "name" "clam" (\<open>CLam [_]._\<close> [100,100] 100) |
21107 | 122 |
|
63167 | 123 |
text \<open>Filling a lambda-term into a context.\<close> |
21107 | 124 |
|
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
125 |
nominal_primrec |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80149
diff
changeset
|
126 |
filling :: "clam \<Rightarrow> lam \<Rightarrow> lam" (\<open>_\<lbrakk>_\<rbrakk>\<close> [100,100] 100) |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
127 |
where |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
128 |
"\<box>\<lbrakk>t\<rbrakk> = t" |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
129 |
| "(CAppL E t')\<lbrakk>t\<rbrakk> = App (E\<lbrakk>t\<rbrakk>) t'" |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
130 |
| "(CAppR t' E)\<lbrakk>t\<rbrakk> = App t' (E\<lbrakk>t\<rbrakk>)" |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
131 |
| "(CLam [x].E)\<lbrakk>t\<rbrakk> = Lam [x].(E\<lbrakk>t\<rbrakk>)" |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
132 |
by (rule TrueI)+ |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
133 |
|
63167 | 134 |
text \<open>Composition od two contexts\<close> |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
135 |
|
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
136 |
nominal_primrec |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
80149
diff
changeset
|
137 |
clam_compose :: "clam \<Rightarrow> clam \<Rightarrow> clam" (\<open>_ \<circ> _\<close> [100,100] 100) |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
138 |
where |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
139 |
"\<box> \<circ> E' = E'" |
29097
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
140 |
| "(CAppL E t') \<circ> E' = CAppL (E \<circ> E') t'" |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
141 |
| "(CAppR t' E) \<circ> E' = CAppR t' (E \<circ> E')" |
68245155eb58
Modified nominal_primrec to make it work with local theories, unified syntax
berghofe
parents:
26966
diff
changeset
|
142 |
| "(CLam [x].E) \<circ> E' = CLam [x].(E \<circ> E')" |
26764
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
143 |
by (rule TrueI)+ |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
144 |
|
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
145 |
lemma clam_compose: |
805eece49928
extended to be a library of general facts about the lambda calculus
urbanc
parents:
25751
diff
changeset
|
146 |
shows "(E1 \<circ> E2)\<lbrakk>t\<rbrakk> = E1\<lbrakk>E2\<lbrakk>t\<rbrakk>\<rbrakk>" |
26966
071f40487734
made the naming of the induction principles consistent: weak_induct is
urbanc
parents:
26764
diff
changeset
|
147 |
by (induct E1 rule: clam.induct) (auto) |
21107 | 148 |
|
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21107
diff
changeset
|
149 |
end |