1797
fddb470720f1
renamed ExLam to Lambda and completed the proof of the strong ind principle; tuned paper
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1
theory Lambda
2454
+ − 2
imports "../Nominal2"
1594
+ − 3
begin
+ − 4
2784
+ − 5
2885
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 6
1594
+ − 7
atom_decl name
+ − 8
2436
+ − 9
nominal_datatype lam =
1800
78fdc6b36a1c
changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 10
Var "name"
2436
+ − 11
| App "lam" "lam"
2683
+ − 12
| Lam x::"name" l::"lam" bind x in l ("Lam [_]. _" [100, 100] 100)
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 13
2885
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 14
ML {* Method.SIMPLE_METHOD' *}
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 15
ML {* Sign.intern_const *}
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 16
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 17
ML {*
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 18
val test:((Proof.context -> Method.method) context_parser) =
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 19
Scan.succeed (fn ctxt =>
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 20
let
2891
304dfe6cc83a
the simplifier can simplify "sort (atom a)" if a is a concrete atom type declared with atom_decl
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 21
val _ = Inductive.the_inductive ctxt "local.frees_lst_graph"
2885
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 22
in
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 23
Method.SIMPLE_METHOD' (K all_tac)
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 24
end)
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 25
*}
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 26
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 27
method_setup test = {* test *} {* test *}
2868
+ − 28
+ − 29
section {* free name function *}
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 30
2860
+ − 31
text {* first returns an atom list *}
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 32
2885
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 33
ML Thm.implies_intr
1264f2a21ea9
some rudimentary infrastructure for storing data about nominal datatypes
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 34
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 35
nominal_primrec
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 36
frees_lst :: "lam \<Rightarrow> atom list"
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 37
where
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 38
"frees_lst (Var x) = [atom x]"
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 39
| "frees_lst (App t1 t2) = frees_lst t1 @ frees_lst t2"
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 40
| "frees_lst (Lam [x]. t) = removeAll (atom x) (frees_lst t)"
2868
+ − 41
unfolding eqvt_def
+ − 42
unfolding frees_lst_graph_def
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 43
apply (rule, perm_simp, rule)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 44
apply(rule TrueI)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 45
apply(rule_tac y="x" in lam.exhaust)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 46
apply(auto)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 47
apply (erule Abs_lst1_fcb)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 48
apply(simp add: supp_removeAll fresh_def)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 49
apply(drule supp_eqvt_at)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 50
apply(simp add: finite_supp)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 51
apply(auto simp add: fresh_def supp_removeAll eqvts eqvt_at_def)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 52
done
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 53
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 54
termination
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 55
by lexicographic_order
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 56
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 57
text {* a small test lemma *}
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 58
lemma shows "supp t = set (frees_lst t)"
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 59
by (induct t rule: frees_lst.induct) (simp_all add: lam.supp supp_at_base)
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 60
2860
+ − 61
text {* second returns an atom set - therefore needs an invariant *}
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 62
2821
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 63
nominal_primrec (invariant "\<lambda>x (y::atom set). finite y")
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 64
frees_set :: "lam \<Rightarrow> atom set"
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 65
where
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 66
"frees_set (Var x) = {atom x}"
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 67
| "frees_set (App t1 t2) = frees_set t1 \<union> frees_set t2"
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 68
| "frees_set (Lam [x]. t) = (frees_set t) - {atom x}"
2845
+ − 69
apply(simp add: eqvt_def frees_set_graph_def)
+ − 70
apply(rule, perm_simp, rule)
+ − 71
apply(erule frees_set_graph.induct)
+ − 72
apply(auto)[9]
+ − 73
apply(rule_tac y="x" in lam.exhaust)
+ − 74
apply(auto)[3]
+ − 75
apply(simp)
+ − 76
apply(erule Abs_lst1_fcb)
+ − 77
apply(simp_all add: fresh_minus_atom_set)
+ − 78
apply(erule fresh_eqvt_at)
+ − 79
apply(simp_all add: finite_supp eqvt_at_def eqvts)
+ − 80
done
2821
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 81
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 82
termination
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 83
by lexicographic_order
2821
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 84
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 85
lemma "frees_set t = supp t"
2845
+ − 86
by (induct rule: frees_set.induct) (simp_all add: lam.supp supp_at_base)
2821
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 87
2809
+ − 88
lemma fresh_fun_eqvt_app3:
+ − 89
assumes a: "eqvt f"
+ − 90
and b: "a \<sharp> x" "a \<sharp> y" "a \<sharp> z"
+ − 91
shows "a \<sharp> f x y z"
+ − 92
using fresh_fun_eqvt_app[OF a b(1)] a b
+ − 93
by (metis fresh_fun_app)
+ − 94
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 95
2868
+ − 96
section {* A test with a locale and an interpretation. *}
+ − 97
+ − 98
text {* conclusion: it is no necessary *}
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 99
2814
+ − 100
locale test =
+ − 101
fixes f1::"name \<Rightarrow> ('a::pt)"
+ − 102
and f2::"lam \<Rightarrow> lam \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> ('a::pt)"
+ − 103
and f3::"name \<Rightarrow> lam \<Rightarrow> 'a \<Rightarrow> ('a::pt)"
+ − 104
assumes fs: "finite (supp (f1, f2, f3))"
+ − 105
and eq: "eqvt f1" "eqvt f2" "eqvt f3"
+ − 106
and fcb: "\<forall>x t r. atom x \<sharp> f3 x t r"
+ − 107
begin
+ − 108
2845
+ − 109
nominal_primrec
2814
+ − 110
f :: "lam \<Rightarrow> ('a::pt)"
2807
13af2c8d7329
a test with a recursion combinator defined on top of nominal_primrec
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 111
where
2814
+ − 112
"f (Var x) = f1 x"
+ − 113
| "f (App t1 t2) = f2 t1 t2 (f t1) (f t2)"
2816
+ − 114
| "f (Lam [x].t) = f3 x t (f t)"
2809
+ − 115
apply (simp add: eqvt_def f_graph_def)
2814
+ − 116
apply (perm_simp)
+ − 117
apply(simp add: eq[simplified eqvt_def])
2821
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 118
apply(rule TrueI)
2816
+ − 119
apply(rule_tac y="x" in lam.exhaust)
2809
+ − 120
apply(auto simp add: fresh_star_def)
2843
+ − 121
apply(erule Abs_lst1_fcb)
2809
+ − 122
apply simp_all
2814
+ − 123
apply(simp add: fcb)
2816
+ − 124
apply (rule fresh_fun_eqvt_app3[OF eq(3)])
+ − 125
apply (simp add: fresh_at_base)
+ − 126
apply assumption
+ − 127
apply (erule fresh_eqvt_at)
+ − 128
apply (simp add: finite_supp)
+ − 129
apply assumption
2814
+ − 130
apply (subgoal_tac "\<And>p y r. p \<bullet> (f3 x y r) = f3 (p \<bullet> x) (p \<bullet> y) (p \<bullet> r)")
2816
+ − 131
apply (simp add: eqvt_at_def)
+ − 132
apply (simp add: permute_fun_app_eq eq[unfolded eqvt_def])
+ − 133
done
2807
13af2c8d7329
a test with a recursion combinator defined on top of nominal_primrec
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 134
2816
+ − 135
termination
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 136
by lexicographic_order
2821
c7d4bd9e89e0
fixed problem with earlier commit about nominal_function_common; added facility for specifying an invariant - added a definition of frees_set which need a finiteness invariant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 137
2814
+ − 138
end
2807
13af2c8d7329
a test with a recursion combinator defined on top of nominal_primrec
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 139
2816
+ − 140
interpretation hei: test
+ − 141
"%n. (1 :: nat)"
+ − 142
"%t1 t2 r1 r2. (r1 + r2)"
+ − 143
"%n t r. r + 1"
+ − 144
apply default
+ − 145
apply (auto simp add: pure_fresh supp_Pair)
+ − 146
apply (simp_all add: fresh_def supp_def permute_fun_def permute_pure)[3]
+ − 147
apply (simp_all add: eqvt_def permute_fun_def permute_pure)
+ − 148
done
+ − 149
2868
+ − 150
section {* height function *}
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 151
2666
+ − 152
nominal_primrec
2678
+ − 153
height :: "lam \<Rightarrow> int"
2666
+ − 154
where
2678
+ − 155
"height (Var x) = 1"
2683
+ − 156
| "height (App t1 t2) = max (height t1) (height t2) + 1"
+ − 157
| "height (Lam [x].t) = height t + 1"
2791
+ − 158
unfolding eqvt_def height_graph_def
+ − 159
apply (rule, perm_simp, rule)
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 160
apply(rule TrueI)
2666
+ − 161
apply(rule_tac y="x" in lam.exhaust)
2683
+ − 162
apply(auto simp add: lam.distinct lam.eq_iff)
2843
+ − 163
apply (erule Abs_lst1_fcb)
2767
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 164
apply(simp_all add: fresh_def pure_supp eqvt_at_def)
2666
+ − 165
done
+ − 166
+ − 167
termination
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 168
by lexicographic_order
2666
+ − 169
2707
+ − 170
thm height.simps
+ − 171
2683
+ − 172
2868
+ − 173
section {* capture-avoiding substitution *}
2683
+ − 174
2675
+ − 175
nominal_primrec
2683
+ − 176
subst :: "lam \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam" ("_ [_ ::= _]" [90, 90, 90] 90)
2675
+ − 177
where
2683
+ − 178
"(Var x)[y ::= s] = (if x = y then s else (Var x))"
+ − 179
| "(App t1 t2)[y ::= s] = App (t1[y ::= s]) (t2[y ::= s])"
+ − 180
| "atom x \<sharp> (y, s) \<Longrightarrow> (Lam [x]. t)[y ::= s] = Lam [x].(t[y ::= s])"
2791
+ − 181
unfolding eqvt_def subst_graph_def
+ − 182
apply (rule, perm_simp, rule)
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 183
apply(rule TrueI)
2683
+ − 184
apply(auto simp add: lam.distinct lam.eq_iff)
+ − 185
apply(rule_tac y="a" and c="(aa, b)" in lam.strong_exhaust)
+ − 186
apply(blast)+
2767
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 187
apply(simp_all add: fresh_star_def fresh_Pair_elim)
2843
+ − 188
apply (erule Abs_lst1_fcb)
2767
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 189
apply(simp_all add: Abs_fresh_iff)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 190
apply(drule_tac a="atom (xa)" in fresh_eqvt_at)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 191
apply(simp_all add: finite_supp fresh_Pair)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 192
apply(subgoal_tac "(atom x \<rightleftharpoons> atom xa) \<bullet> sa = sa")
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 193
apply(subgoal_tac "(atom x \<rightleftharpoons> atom xa) \<bullet> ya = ya")
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 194
apply(simp add: eqvt_at_def)
2840
+ − 195
apply(simp_all add: swap_fresh_fresh)
2675
+ − 196
done
+ − 197
2678
+ − 198
termination
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 199
by lexicographic_order
2683
+ − 200
+ − 201
lemma subst_eqvt[eqvt]:
+ − 202
shows "(p \<bullet> t[x ::= s]) = (p \<bullet> t)[(p \<bullet> x) ::= (p \<bullet> s)]"
+ − 203
by (induct t x s rule: subst.induct) (simp_all)
+ − 204
+ − 205
lemma forget:
+ − 206
shows "atom x \<sharp> t \<Longrightarrow> t[x ::= s] = t"
2845
+ − 207
by (nominal_induct t avoiding: x s rule: lam.strong_induct)
+ − 208
(auto simp add: lam.fresh fresh_at_base)
2683
+ − 209
+ − 210
text {* same lemma but with subst.induction *}
+ − 211
lemma forget2:
+ − 212
shows "atom x \<sharp> t \<Longrightarrow> t[x ::= s] = t"
2845
+ − 213
by (induct t x s rule: subst.induct)
+ − 214
(auto simp add: lam.fresh fresh_at_base fresh_Pair)
2683
+ − 215
+ − 216
lemma fresh_fact:
+ − 217
fixes z::"name"
+ − 218
assumes a: "atom z \<sharp> s"
2845
+ − 219
and b: "z = y \<or> atom z \<sharp> t"
2683
+ − 220
shows "atom z \<sharp> t[y ::= s]"
2845
+ − 221
using a b
+ − 222
by (nominal_induct t avoiding: z y s rule: lam.strong_induct)
+ − 223
(auto simp add: lam.fresh fresh_at_base)
2683
+ − 224
+ − 225
lemma substitution_lemma:
+ − 226
assumes a: "x \<noteq> y" "atom x \<sharp> u"
+ − 227
shows "t[x ::= s][y ::= u] = t[y ::= u][x ::= s[y ::= u]]"
+ − 228
using a
+ − 229
by (nominal_induct t avoiding: x y s u rule: lam.strong_induct)
+ − 230
(auto simp add: fresh_fact forget)
+ − 231
+ − 232
lemma subst_rename:
+ − 233
assumes a: "atom y \<sharp> t"
+ − 234
shows "t[x ::= s] = ((y \<leftrightarrow> x) \<bullet>t)[y ::= s]"
+ − 235
using a
+ − 236
apply (nominal_induct t avoiding: x y s rule: lam.strong_induct)
+ − 237
apply (auto simp add: lam.fresh fresh_at_base)
+ − 238
done
+ − 239
2767
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 240
lemma height_ge_one:
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 241
shows "1 \<le> (height e)"
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 242
by (induct e rule: lam.induct) (simp_all)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 243
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 244
theorem height_subst:
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 245
shows "height (e[x::=e']) \<le> ((height e) - 1) + (height e')"
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 246
proof (nominal_induct e avoiding: x e' rule: lam.strong_induct)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 247
case (Var y)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 248
have "1 \<le> height e'" by (rule height_ge_one)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 249
then show "height (Var y[x::=e']) \<le> height (Var y) - 1 + height e'" by simp
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 250
next
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 251
case (Lam y e1)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 252
hence ih: "height (e1[x::=e']) \<le> ((height e1) - 1) + (height e')" by simp
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 253
moreover
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 254
have vc: "atom y\<sharp>x" "atom y\<sharp>e'" by fact+ (* usual variable convention *)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 255
ultimately show "height ((Lam [y]. e1)[x::=e']) \<le> height (Lam [y]. e1) - 1 + height e'" by simp
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 256
next
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 257
case (App e1 e2)
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 258
hence ih1: "height (e1[x::=e']) \<le> ((height e1) - 1) + (height e')"
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 259
and ih2: "height (e2[x::=e']) \<le> ((height e2) - 1) + (height e')" by simp_all
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 260
then show "height ((App e1 e2)[x::=e']) \<le> height (App e1 e2) - 1 + height e'" by simp
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 261
qed
2683
+ − 262
+ − 263
subsection {* single-step beta-reduction *}
+ − 264
+ − 265
inductive
+ − 266
beta :: "lam \<Rightarrow> lam \<Rightarrow> bool" (" _ \<longrightarrow>b _" [80,80] 80)
+ − 267
where
+ − 268
b1[intro]: "t1 \<longrightarrow>b t2 \<Longrightarrow> App t1 s \<longrightarrow>b App t2 s"
+ − 269
| b2[intro]: "s1 \<longrightarrow>b s2 \<Longrightarrow> App t s1 \<longrightarrow>b App t s2"
+ − 270
| b3[intro]: "t1 \<longrightarrow>b t2 \<Longrightarrow> Lam [x]. t1 \<longrightarrow>b Lam [x]. t2"
+ − 271
| b4[intro]: "atom x \<sharp> s \<Longrightarrow> App (Lam [x]. t) s \<longrightarrow>b t[x ::= s]"
+ − 272
+ − 273
equivariance beta
+ − 274
+ − 275
nominal_inductive beta
+ − 276
avoids b4: "x"
+ − 277
by (simp_all add: fresh_star_def fresh_Pair lam.fresh fresh_fact)
+ − 278
+ − 279
text {* One-Reduction *}
+ − 280
+ − 281
inductive
+ − 282
One :: "lam \<Rightarrow> lam \<Rightarrow> bool" (" _ \<longrightarrow>1 _" [80,80] 80)
+ − 283
where
+ − 284
o1[intro]: "Var x \<longrightarrow>1 Var x"
+ − 285
| o2[intro]: "\<lbrakk>t1 \<longrightarrow>1 t2; s1 \<longrightarrow>1 s2\<rbrakk> \<Longrightarrow> App t1 s1 \<longrightarrow>1 App t2 s2"
+ − 286
| o3[intro]: "t1 \<longrightarrow>1 t2 \<Longrightarrow> Lam [x].t1 \<longrightarrow>1 Lam [x].t2"
+ − 287
| o4[intro]: "\<lbrakk>atom x \<sharp> (s1, s2); t1 \<longrightarrow>1 t2; s1 \<longrightarrow>1 s2\<rbrakk> \<Longrightarrow> App (Lam [x].t1) s1 \<longrightarrow>1 t2[x ::= s2]"
+ − 288
+ − 289
equivariance One
+ − 290
+ − 291
nominal_inductive One
+ − 292
avoids o3: "x"
+ − 293
| o4: "x"
+ − 294
by (simp_all add: fresh_star_def fresh_Pair lam.fresh fresh_fact)
+ − 295
+ − 296
lemma One_refl:
+ − 297
shows "t \<longrightarrow>1 t"
+ − 298
by (nominal_induct t rule: lam.strong_induct) (auto)
+ − 299
+ − 300
lemma One_subst:
+ − 301
assumes a: "t1 \<longrightarrow>1 t2" "s1 \<longrightarrow>1 s2"
+ − 302
shows "t1[x ::= s1] \<longrightarrow>1 t2[x ::= s2]"
+ − 303
using a
+ − 304
apply(nominal_induct t1 t2 avoiding: s1 s2 x rule: One.strong_induct)
+ − 305
apply(auto simp add: substitution_lemma fresh_at_base fresh_fact fresh_Pair)
+ − 306
done
+ − 307
+ − 308
lemma better_o4_intro:
+ − 309
assumes a: "t1 \<longrightarrow>1 t2" "s1 \<longrightarrow>1 s2"
+ − 310
shows "App (Lam [x]. t1) s1 \<longrightarrow>1 t2[ x ::= s2]"
+ − 311
proof -
2685
+ − 312
obtain y::"name" where fs: "atom y \<sharp> (x, t1, s1, t2, s2)" by (rule obtain_fresh)
2683
+ − 313
have "App (Lam [x]. t1) s1 = App (Lam [y]. ((y \<leftrightarrow> x) \<bullet> t1)) s1" using fs
+ − 314
by (auto simp add: lam.eq_iff Abs1_eq_iff' flip_def fresh_Pair fresh_at_base)
+ − 315
also have "\<dots> \<longrightarrow>1 ((y \<leftrightarrow> x) \<bullet> t2)[y ::= s2]" using fs a by (auto simp add: One.eqvt)
+ − 316
also have "\<dots> = t2[x ::= s2]" using fs by (simp add: subst_rename[symmetric])
+ − 317
finally show "App (Lam [x].t1) s1 \<longrightarrow>1 t2[x ::= s2]" by simp
+ − 318
qed
+ − 319
+ − 320
section {* Locally Nameless Terms *}
2678
+ − 321
2669
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 322
nominal_datatype ln =
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 323
LNBnd nat
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 324
| LNVar name
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 325
| LNApp ln ln
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 326
| LNLam ln
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 327
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 328
fun
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 329
lookup :: "name list \<Rightarrow> nat \<Rightarrow> name \<Rightarrow> ln"
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 330
where
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 331
"lookup [] n x = LNVar x"
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 332
| "lookup (y # ys) n x = (if x = y then LNBnd n else (lookup ys (n + 1) x))"
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 333
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 334
lemma supp_lookup:
2824
+ − 335
shows "supp (lookup xs n x) \<subseteq> {atom x}"
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 336
apply(induct arbitrary: n rule: lookup.induct)
2824
+ − 337
apply(simp add: ln.supp supp_at_base)
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 338
apply(simp add: ln.supp pure_supp)
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 339
done
2824
+ − 340
+ − 341
lemma supp_lookup_in:
+ − 342
shows "x \<in> set xs \<Longrightarrow> supp (lookup xs n x) = {}"
+ − 343
by (induct arbitrary: n rule: lookup.induct)(auto simp add: ln.supp pure_supp)
+ − 344
+ − 345
lemma supp_lookup_notin:
+ − 346
shows "x \<notin> set xs \<Longrightarrow> supp (lookup xs n x) = {atom x}"
+ − 347
by (induct arbitrary: n rule: lookup.induct) (auto simp add: ln.supp pure_supp supp_at_base)
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 348
2829
+ − 349
lemma supp_lookup_fresh:
+ − 350
shows "atom ` set xs \<sharp>* lookup xs n x"
+ − 351
by (case_tac "x \<in> set xs") (auto simp add: fresh_star_def fresh_def supp_lookup_in supp_lookup_notin)
+ − 352
+ − 353
lemma lookup_eqvt[eqvt]:
2669
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 354
shows "(p \<bullet> lookup xs n x) = lookup (p \<bullet> xs) (p \<bullet> n) (p \<bullet> x)"
2767
94f6f70e3067
New way of forward elimination of Abs1_eq and simplifications of the function obligation proofs.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 355
by (induct xs arbitrary: n) (simp_all add: permute_pure)
2669
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 356
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 357
text {* Function that translates lambda-terms into locally nameless terms *}
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 358
2826
+ − 359
nominal_primrec (invariant "\<lambda>(_, xs) y. atom ` set xs \<sharp>* y")
2669
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 360
trans :: "lam \<Rightarrow> name list \<Rightarrow> ln"
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 361
where
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 362
"trans (Var x) xs = lookup xs 0 x"
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 363
| "trans (App t1 t2) xs = LNApp (trans t1 xs) (trans t2 xs)"
2685
+ − 364
| "atom x \<sharp> xs \<Longrightarrow> trans (Lam [x]. t) xs = LNLam (trans t (x # xs))"
2829
+ − 365
apply (simp add: eqvt_def trans_graph_def)
+ − 366
apply (rule, perm_simp, rule)
2824
+ − 367
apply (erule trans_graph.induct)
2829
+ − 368
apply (auto simp add: ln.fresh)
+ − 369
apply (simp add: supp_lookup_fresh)
2824
+ − 370
apply (simp add: fresh_star_def ln.fresh)
+ − 371
apply (simp add: ln.fresh fresh_star_def)
2829
+ − 372
apply (rule_tac y="a" and c="b" in lam.strong_exhaust)
+ − 373
apply (auto simp add: fresh_star_def)[3]
2843
+ − 374
apply (erule Abs_lst1_fcb)
2829
+ − 375
apply (simp_all add: fresh_star_def)
+ − 376
apply (drule supp_eqvt_at)
+ − 377
apply (rule finite_supp)
+ − 378
apply (auto simp add: supp_Pair fresh_def supp_Cons supp_at_base)[1]
+ − 379
apply (simp add: eqvt_at_def swap_fresh_fresh)
+ − 380
done
2669
1d1772a89026
the function translating lambda terms to locally nameless lambda terms; still needs a stronger abs_eq_iff lemma...at the moment only proved for restrictions
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 381
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 382
termination
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 383
by lexicographic_order
2827
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 384
2860
+ − 385
text {* count the bound-variable occurences in a lambda-term *}
2827
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 386
2828
+ − 387
nominal_primrec
2827
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 388
cbvs :: "lam \<Rightarrow> name list \<Rightarrow> nat"
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 389
where
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 390
"cbvs (Var x) xs = (if x \<in> set xs then 1 else 0)"
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 391
| "cbvs (App t1 t2) xs = (cbvs t1 xs) + (cbvs t2 xs)"
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 392
| "atom x \<sharp> xs \<Longrightarrow> cbvs (Lam [x]. t) xs = cbvs t (x # xs)"
2828
+ − 393
apply(simp add: eqvt_def cbvs_graph_def)
+ − 394
apply(rule, perm_simp, rule)
+ − 395
apply(simp_all)
+ − 396
apply(case_tac x)
+ − 397
apply(rule_tac y="a" and c="b" in lam.strong_exhaust)
+ − 398
apply(auto simp add: fresh_star_def)
2843
+ − 399
apply(erule Abs_lst1_fcb)
2828
+ − 400
apply(simp_all add: pure_fresh)
+ − 401
apply (simp add: eqvt_at_def swap_fresh_fresh)
+ − 402
done
2827
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 403
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 404
termination
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 405
by lexicographic_order
2827
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 406
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 407
section {* De Bruijn Terms *}
2827
394664816e24
defined the "count-bound-variables-occurences" function which has an accumulator like trans
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 408
2667
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 409
nominal_datatype db =
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 410
DBVar nat
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 411
| DBApp db db
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 412
| DBLam db
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 413
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 414
fun dbapp_in where
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 415
"dbapp_in None _ = None"
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 416
| "dbapp_in (Some _ ) None = None"
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 417
| "dbapp_in (Some x) (Some y) = Some (DBApp x y)"
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 418
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 419
fun dblam_in where
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 420
"dblam_in None = None"
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 421
| "dblam_in (Some x) = Some (DBLam x)"
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 422
2798
+ − 423
lemma db_in_eqvt[eqvt]:
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 424
"p \<bullet> (dbapp_in x y) = dbapp_in (p \<bullet> x) (p \<bullet> y)"
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 425
"p \<bullet> (dblam_in x) = dblam_in (p \<bullet> x)"
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 426
apply (case_tac [!] x)
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 427
apply (simp_all add: eqvts)
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 428
apply (case_tac y)
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 429
apply (simp_all add: eqvts)
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 430
done
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 431
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 432
instance db :: pure
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 433
apply default
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 434
apply (induct_tac x rule: db.induct)
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 435
apply (simp_all add: permute_pure)
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 436
done
2795
+ − 437
+ − 438
lemma fresh_at_list: "atom x \<sharp> xs \<longleftrightarrow> x \<notin> set xs"
+ − 439
unfolding fresh_def supp_set[symmetric]
2845
+ − 440
by (induct xs) (auto simp add: supp_of_finite_insert supp_at_base supp_set_empty)
2795
+ − 441
2800
+ − 442
fun
+ − 443
vindex :: "name list \<Rightarrow> name \<Rightarrow> nat \<Rightarrow> db option"
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 444
where
2800
+ − 445
"vindex [] v n = None"
+ − 446
| "vindex (h # t) v n = (if v = h then (Some (DBVar n)) else (vindex t v (Suc n)))"
+ − 447
+ − 448
lemma vindex_eqvt[eqvt]:
+ − 449
"(p \<bullet> vindex l v n) = vindex (p \<bullet> l) (p \<bullet> v) (p \<bullet> n)"
+ − 450
by (induct l arbitrary: n) (simp_all add: permute_pure)
+ − 451
+ − 452
nominal_primrec
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 453
transdb :: "lam \<Rightarrow> name list \<Rightarrow> db option"
2800
+ − 454
where
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 455
"transdb (Var x) l = vindex l x 0"
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 456
| "transdb (App t1 t2) xs = dbapp_in (transdb t1 xs) (transdb t2 xs)"
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 457
| "x \<notin> set xs \<Longrightarrow> transdb (Lam [x].t) xs = dblam_in (transdb t (x # xs))"
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 458
unfolding eqvt_def transdb_graph_def
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 459
apply (rule, perm_simp, rule)
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 460
apply(rule TrueI)
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 461
apply (case_tac x)
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 462
apply (rule_tac y="a" and c="b" in lam.strong_exhaust)
2795
+ − 463
apply (auto simp add: fresh_star_def fresh_at_list)
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 464
apply (rule_tac f="dblam_in" in arg_cong)
2843
+ − 465
apply (erule Abs_lst1_fcb)
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 466
apply (simp_all add: pure_fresh)
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 467
apply (subgoal_tac "(atom x \<rightleftharpoons> atom xa) \<bullet> xsa = xsa")
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 468
apply (simp add: eqvt_at_def)
2795
+ − 469
apply (metis atom_name_def swap_fresh_fresh fresh_at_list)
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 470
done
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 471
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 472
termination
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 473
by lexicographic_order
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 474
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 475
lemma transdb_eqvt[eqvt]:
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 476
"p \<bullet> transdb t l = transdb (p \<bullet>t) (p \<bullet>l)"
2800
+ − 477
apply (nominal_induct t avoiding: l p rule: lam.strong_induct)
+ − 478
apply (simp add: vindex_eqvt)
+ − 479
apply (simp_all add: permute_pure)
2797
+ − 480
apply (simp add: fresh_at_list)
2822
23befefc6e73
cleaned ups a bit the examples with the invariant framework; exported nominal_function_config datatype into separate structure and file
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 481
apply (subst transdb.simps)
2797
+ − 482
apply (simp add: fresh_at_list[symmetric])
2800
+ − 483
apply (drule_tac x="name # l" in meta_spec)
+ − 484
apply auto
2797
+ − 485
done
+ − 486
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 487
lemma db_trans_test:
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 488
assumes a: "y \<noteq> x"
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 489
shows "transdb (Lam [x]. Lam [y]. App (Var x) (Var y)) [] =
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 490
Some (DBLam (DBLam (DBApp (DBVar 1) (DBVar 0))))"
2795
+ − 491
using a by simp
2792
c4ed08a7454a
Defined translation from nominal to de-Bruijn; with a freshness condition for the lambda case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 492
2667
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 493
abbreviation
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 494
mbind :: "'a option => ('a => 'b option) => 'b option" ("_ \<guillemotright>= _" [65,65] 65)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 495
where
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 496
"c \<guillemotright>= f \<equiv> case c of None => None | (Some v) => f v"
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 497
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 498
lemma mbind_eqvt:
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 499
fixes c::"'a::pt option"
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 500
shows "(p \<bullet> (c \<guillemotright>= f)) = ((p \<bullet> c) \<guillemotright>= (p \<bullet> f))"
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 501
apply(cases c)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 502
apply(simp_all)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 503
apply(perm_simp)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 504
apply(rule refl)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 505
done
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 506
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 507
lemma mbind_eqvt_raw[eqvt_raw]:
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 508
shows "(p \<bullet> option_case) \<equiv> option_case"
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 509
apply(rule eq_reflection)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 510
apply(rule ext)+
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 511
apply(case_tac xb)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 512
apply(simp_all)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 513
apply(rule_tac p="-p" in permute_boolE)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 514
apply(perm_simp add: permute_minus_cancel)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 515
apply(simp)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 516
apply(rule_tac p="-p" in permute_boolE)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 517
apply(perm_simp add: permute_minus_cancel)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 518
apply(simp)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 519
done
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 520
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 521
fun
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 522
index :: "atom list \<Rightarrow> nat \<Rightarrow> atom \<Rightarrow> nat option"
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 523
where
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 524
"index [] n x = None"
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 525
| "index (y # ys) n x = (if x = y then (Some n) else (index ys (n + 1) x))"
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 526
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 527
lemma [eqvt]:
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 528
shows "(p \<bullet> index xs n x) = index (p \<bullet> xs) (p \<bullet> n) (p \<bullet> x)"
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 529
apply(induct xs arbitrary: n)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 530
apply(simp_all add: permute_pure)
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 531
done
e3f8673085b1
added a translation function from lambda-terms to deBruijn terms (equivariance fails at the moment)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 532
2841
+ − 533
lemma supp_subst:
+ − 534
"supp (t[x ::= s]) \<subseteq> supp t \<union> supp s"
+ − 535
by (induct t x s rule: subst.induct) (auto simp add: lam.supp)
+ − 536
+ − 537
lemma var_fresh_subst:
+ − 538
"atom x \<sharp> s \<Longrightarrow> atom x \<sharp> (t[x ::= s])"
+ − 539
by (induct t x s rule: subst.induct) (auto simp add: lam.supp lam.fresh fresh_at_base)
+ − 540
2834
+ − 541
(* function that evaluates a lambda term *)
+ − 542
nominal_primrec
+ − 543
eval :: "lam \<Rightarrow> lam" and
2860
+ − 544
apply_subst :: "lam \<Rightarrow> lam \<Rightarrow> lam"
2834
+ − 545
where
+ − 546
"eval (Var x) = Var x"
+ − 547
| "eval (Lam [x].t) = Lam [x].(eval t)"
2860
+ − 548
| "eval (App t1 t2) = apply_subst (eval t1) (eval t2)"
+ − 549
| "apply_subst (Var x) t2 = App (Var x) t2"
+ − 550
| "apply_subst (App t0 t1) t2 = App (App t0 t1) t2"
+ − 551
| "atom x \<sharp> t2 \<Longrightarrow> apply_subst (Lam [x].t1) t2 = eval (t1[x::= t2])"
+ − 552
apply(simp add: eval_apply_subst_graph_def eqvt_def)
2841
+ − 553
apply(rule, perm_simp, rule)
2834
+ − 554
apply(rule TrueI)
2841
+ − 555
apply (case_tac x)
+ − 556
apply (case_tac a rule: lam.exhaust)
+ − 557
apply simp_all[3]
+ − 558
apply blast
+ − 559
apply (case_tac b)
+ − 560
apply (rule_tac y="a" and c="ba" in lam.strong_exhaust)
+ − 561
apply simp_all[3]
+ − 562
apply blast
+ − 563
apply blast
+ − 564
apply (simp add: Abs1_eq_iff fresh_star_def)
2834
+ − 565
apply(simp_all)
2843
+ − 566
apply(erule Abs_lst1_fcb)
2841
+ − 567
apply (simp add: Abs_fresh_iff)
+ − 568
apply (simp add: Abs_fresh_iff)
+ − 569
apply (erule fresh_eqvt_at)
+ − 570
apply (simp add: finite_supp)
+ − 571
apply (simp add: fresh_Inl)
+ − 572
apply (simp add: eqvt_at_def)
+ − 573
apply simp
+ − 574
apply clarify
2843
+ − 575
apply(erule Abs_lst1_fcb)
2841
+ − 576
apply (erule fresh_eqvt_at)
+ − 577
apply (simp add: finite_supp)
+ − 578
apply (simp add: fresh_Inl var_fresh_subst)
+ − 579
apply (erule fresh_eqvt_at)
+ − 580
apply (simp add: finite_supp)
+ − 581
apply (simp add: fresh_Inl)
+ − 582
apply (simp add: fresh_def)
+ − 583
using supp_subst apply blast
+ − 584
apply (simp add: eqvt_at_def subst_eqvt)
2843
+ − 585
apply (subst (2) swap_fresh_fresh)
2841
+ − 586
apply assumption+
+ − 587
apply rule
+ − 588
apply simp
2860
+ − 589
done
+ − 590
+ − 591
+ − 592
(* a small test
+ − 593
termination sorry
2845
+ − 594
2860
+ − 595
lemma
+ − 596
assumes "x \<noteq> y"
+ − 597
shows "eval (App (Lam [x].App (Var x) (Var x)) (Var y)) = App (Var y) (Var y)"
+ − 598
using assms
+ − 599
apply(simp add: lam.supp fresh_def supp_at_base)
+ − 600
done
+ − 601
*)
+ − 602
2852
+ − 603
+ − 604
text {* TODO: eqvt_at for the other side *}
+ − 605
nominal_primrec q where
+ − 606
"atom c \<sharp> (x, M) \<Longrightarrow> q (Lam [x]. M) (N :: lam) = Lam [x]. (Lam [c]. (App M (q (Var c) N)))"
+ − 607
| "q (Var x) N = Var x"
+ − 608
| "q (App l r) N = App l r"
+ − 609
unfolding eqvt_def q_graph_def
+ − 610
apply (rule, perm_simp, rule)
+ − 611
apply (rule TrueI)
+ − 612
apply (case_tac x)
+ − 613
apply (rule_tac y="a" in lam.exhaust)
+ − 614
apply simp_all
+ − 615
apply blast
+ − 616
apply blast
+ − 617
apply (rule_tac x="(name, lam)" and ?'a="name" in obtain_fresh)
+ − 618
apply blast
+ − 619
apply clarify
+ − 620
apply (rule_tac x="(x, xa, M, Ma, c, ca, Na)" and ?'a="name" in obtain_fresh)
+ − 621
apply (subgoal_tac "eqvt_at q_sumC (Var ca, Na)") --"Could come from nominal_function?"
+ − 622
apply (subgoal_tac "Lam [c]. App M (q_sumC (Var c, Na)) = Lam [a]. App M (q_sumC (Var a, Na))")
+ − 623
apply (subgoal_tac "Lam [ca]. App Ma (q_sumC (Var ca, Na)) = Lam [a]. App Ma (q_sumC (Var a, Na))")
+ − 624
apply (simp only:)
+ − 625
apply (erule Abs_lst1_fcb)
+ − 626
oops
+ − 627
2846
+ − 628
text {* Working Examples *}
+ − 629
+ − 630
nominal_primrec
+ − 631
map_term :: "(lam \<Rightarrow> lam) \<Rightarrow> lam \<Rightarrow> lam"
+ − 632
where
+ − 633
"eqvt f \<Longrightarrow> map_term f (Var x) = f (Var x)"
+ − 634
| "eqvt f \<Longrightarrow> map_term f (App t1 t2) = App (f t1) (f t2)"
+ − 635
| "eqvt f \<Longrightarrow> map_term f (Lam [x].t) = Lam [x].(f t)"
+ − 636
| "\<not>eqvt f \<Longrightarrow> map_term f t = t"
+ − 637
apply (simp add: eqvt_def map_term_graph_def)
+ − 638
apply (rule, perm_simp, rule)
+ − 639
apply(rule TrueI)
+ − 640
apply (case_tac x, case_tac "eqvt a", case_tac b rule: lam.exhaust)
+ − 641
apply auto
+ − 642
apply (erule Abs_lst1_fcb)
+ − 643
apply (simp_all add: Abs_fresh_iff fresh_fun_eqvt_app)
+ − 644
apply (simp add: eqvt_def permute_fun_app_eq)
+ − 645
done
+ − 646
+ − 647
termination
2858
de6b601c8d3d
added size-lemmas to simplifier; as a result termination can be proved by the standard lexicographic_order method
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 648
by lexicographic_order
2846
+ − 649
+ − 650
nominal_primrec
+ − 651
trans2 :: "lam \<Rightarrow> atom list \<Rightarrow> db option"
+ − 652
where
+ − 653
"trans2 (Var x) xs = (index xs 0 (atom x) \<guillemotright>= (\<lambda>n. Some (DBVar n)))"
+ − 654
| "trans2 (App t1 t2) xs = ((trans2 t1 xs) \<guillemotright>= (\<lambda>db1. (trans2 t2 xs) \<guillemotright>= (\<lambda>db2. Some (DBApp db1 db2))))"
+ − 655
| "trans2 (Lam [x].t) xs = (trans2 t (atom x # xs) \<guillemotright>= (\<lambda>db. Some (DBLam db)))"
+ − 656
oops
+ − 657
+ − 658
nominal_primrec
+ − 659
CPS :: "lam \<Rightarrow> (lam \<Rightarrow> lam) \<Rightarrow> lam"
+ − 660
where
+ − 661
"CPS (Var x) k = Var x"
+ − 662
| "CPS (App M N) k = CPS M (\<lambda>m. CPS N (\<lambda>n. n))"
+ − 663
oops
+ − 664
+ − 665
consts b :: name
+ − 666
nominal_primrec
+ − 667
Z :: "lam \<Rightarrow> (lam \<Rightarrow> lam) \<Rightarrow> lam"
+ − 668
where
+ − 669
"Z (App M N) k = Z M (%m. (Z N (%n.(App m n))))"
+ − 670
| "Z (App M N) k = Z M (%m. (Z N (%n.(App (App m n) (Abs b (k (Var b)))))))"
+ − 671
unfolding eqvt_def Z_graph_def
+ − 672
apply (rule, perm_simp, rule)
+ − 673
oops
2789
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 674
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 675
text {* tests of functions containing if and case *}
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 676
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 677
consts P :: "lam \<Rightarrow> bool"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 678
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 679
nominal_primrec
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 680
A :: "lam => lam"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 681
where
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 682
"A (App M N) = (if (True \<or> P M) then (A M) else (A N))"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 683
| "A (Var x) = (Var x)"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 684
| "A (App M N) = (if True then M else A N)"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 685
oops
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 686
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 687
nominal_primrec
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 688
C :: "lam => lam"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 689
where
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 690
"C (App M N) = (case (True \<or> P M) of True \<Rightarrow> (A M) | False \<Rightarrow> (A N))"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 691
| "C (Var x) = (Var x)"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 692
| "C (App M N) = (if True then M else C N)"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 693
oops
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 694
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 695
nominal_primrec
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 696
A :: "lam => lam"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 697
where
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 698
"A (Lam [x].M) = (Lam [x].M)"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 699
| "A (Var x) = (Var x)"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 700
| "A (App M N) = (if True then M else A N)"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 701
oops
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 702
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 703
nominal_primrec
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 704
B :: "lam => lam"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 705
where
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 706
"B (Lam [x].M) = (Lam [x].M)"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 707
| "B (Var x) = (Var x)"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 708
| "B (App M N) = (if True then M else (B N))"
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 709
unfolding eqvt_def
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 710
unfolding B_graph_def
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 711
apply(perm_simp)
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 712
apply(rule allI)
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 713
apply(rule refl)
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 714
oops
32979078bfe9
functions involving if and case do not throw exceptions anymore; but eqvt_at assumption has now a precondition
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 715
1594
+ − 716
end
+ − 717
+ − 718
+ − 719