author | paulson |
Mon, 26 Aug 2024 22:14:19 +0100 | |
changeset 80778 | 94bc8f62c835 |
parent 80761 | bc936d3d8b45 |
child 80914 | d97fdabd9e2b |
permissions | -rw-r--r-- |
17456 | 1 |
(* Title: CCL/Type.thy |
0 | 2 |
Author: Martin Coen |
3 |
Copyright 1993 University of Cambridge |
|
4 |
*) |
|
5 |
||
60770 | 6 |
section \<open>Types in CCL are defined as sets of terms\<close> |
17456 | 7 |
|
8 |
theory Type |
|
9 |
imports Term |
|
10 |
begin |
|
0 | 11 |
|
62143 | 12 |
definition Subtype :: "['a set, 'a \<Rightarrow> o] \<Rightarrow> 'a set" |
13 |
where "Subtype(A, P) == {x. x:A \<and> P(x)}" |
|
0 | 14 |
|
14765 | 15 |
syntax |
62143 | 16 |
"_Subtype" :: "[idt, 'a set, o] \<Rightarrow> 'a set" ("(1{_: _ ./ _})") |
80761 | 17 |
syntax_consts |
18 |
"_Subtype" == Subtype |
|
62143 | 19 |
translations |
20 |
"{x: A. B}" == "CONST Subtype(A, \<lambda>x. B)" |
|
999
9bf3816298d0
Gave tighter priorities to SUM and PROD to reduce ambiguities.
lcp
parents:
22
diff
changeset
|
21 |
|
62143 | 22 |
definition Unit :: "i set" |
23 |
where "Unit == {x. x=one}" |
|
24 |
||
25 |
definition Bool :: "i set" |
|
26 |
where "Bool == {x. x=true | x=false}" |
|
27 |
||
28 |
definition Plus :: "[i set, i set] \<Rightarrow> i set" (infixr "+" 55) |
|
29 |
where "A+B == {x. (EX a:A. x=inl(a)) | (EX b:B. x=inr(b))}" |
|
17456 | 30 |
|
62143 | 31 |
definition Pi :: "[i set, i \<Rightarrow> i set] \<Rightarrow> i set" |
32 |
where "Pi(A,B) == {x. EX b. x=lam x. b(x) \<and> (ALL x:A. b(x):B(x))}" |
|
33 |
||
34 |
definition Sigma :: "[i set, i \<Rightarrow> i set] \<Rightarrow> i set" |
|
35 |
where "Sigma(A,B) == {x. EX a:A. EX b:B(a).x=<a,b>}" |
|
0 | 36 |
|
62143 | 37 |
syntax |
38 |
"_Pi" :: "[idt, i set, i set] \<Rightarrow> i set" ("(3PROD _:_./ _)" [0,0,60] 60) |
|
39 |
"_Sigma" :: "[idt, i set, i set] \<Rightarrow> i set" ("(3SUM _:_./ _)" [0,0,60] 60) |
|
40 |
"_arrow" :: "[i set, i set] \<Rightarrow> i set" ("(_ ->/ _)" [54, 53] 53) |
|
41 |
"_star" :: "[i set, i set] \<Rightarrow> i set" ("(_ */ _)" [56, 55] 55) |
|
80761 | 42 |
syntax_consts |
43 |
"_Pi" "_arrow" \<rightleftharpoons> Pi and |
|
44 |
"_Sigma" "_star" \<rightleftharpoons> Sigma |
|
0 | 45 |
translations |
62143 | 46 |
"PROD x:A. B" \<rightharpoonup> "CONST Pi(A, \<lambda>x. B)" |
47 |
"A -> B" \<rightharpoonup> "CONST Pi(A, \<lambda>_. B)" |
|
48 |
"SUM x:A. B" \<rightharpoonup> "CONST Sigma(A, \<lambda>x. B)" |
|
49 |
"A * B" \<rightharpoonup> "CONST Sigma(A, \<lambda>_. B)" |
|
60770 | 50 |
print_translation \<open> |
69593 | 51 |
[(\<^const_syntax>\<open>Pi\<close>, |
52 |
fn _ => Syntax_Trans.dependent_tr' (\<^syntax_const>\<open>_Pi\<close>, \<^syntax_const>\<open>_arrow\<close>)), |
|
53 |
(\<^const_syntax>\<open>Sigma\<close>, |
|
54 |
fn _ => Syntax_Trans.dependent_tr' (\<^syntax_const>\<open>_Sigma\<close>, \<^syntax_const>\<open>_star\<close>))] |
|
60770 | 55 |
\<close> |
0 | 56 |
|
62143 | 57 |
definition Nat :: "i set" |
58 |
where "Nat == lfp(\<lambda>X. Unit + X)" |
|
59 |
||
60 |
definition List :: "i set \<Rightarrow> i set" |
|
61 |
where "List(A) == lfp(\<lambda>X. Unit + A*X)" |
|
62 |
||
63 |
definition Lists :: "i set \<Rightarrow> i set" |
|
64 |
where "Lists(A) == gfp(\<lambda>X. Unit + A*X)" |
|
65 |
||
66 |
definition ILists :: "i set \<Rightarrow> i set" |
|
67 |
where "ILists(A) == gfp(\<lambda>X.{} + A*X)" |
|
0 | 68 |
|
62143 | 69 |
|
70 |
definition TAll :: "(i set \<Rightarrow> i set) \<Rightarrow> i set" (binder "TALL " 55) |
|
71 |
where "TALL X. B(X) == Inter({X. EX Y. X=B(Y)})" |
|
0 | 72 |
|
62143 | 73 |
definition TEx :: "(i set \<Rightarrow> i set) \<Rightarrow> i set" (binder "TEX " 55) |
74 |
where "TEX X. B(X) == Union({X. EX Y. X=B(Y)})" |
|
0 | 75 |
|
62143 | 76 |
definition Lift :: "i set \<Rightarrow> i set" ("(3[_])") |
77 |
where "[A] == A Un {bot}" |
|
78 |
||
79 |
definition SPLIT :: "[i, [i, i] \<Rightarrow> i set] \<Rightarrow> i set" |
|
80 |
where "SPLIT(p,B) == Union({A. EX x y. p=<x,y> \<and> A=B(x,y)})" |
|
17456 | 81 |
|
20140 | 82 |
|
83 |
lemmas simp_type_defs = |
|
62143 | 84 |
Subtype_def Unit_def Bool_def Plus_def Sigma_def Pi_def Lift_def TAll_def TEx_def |
20140 | 85 |
and ind_type_defs = Nat_def List_def |
86 |
and simp_data_defs = one_def inl_def inr_def |
|
87 |
and ind_data_defs = zero_def succ_def nil_def cons_def |
|
88 |
||
58977 | 89 |
lemma subsetXH: "A <= B \<longleftrightarrow> (ALL x. x:A \<longrightarrow> x:B)" |
20140 | 90 |
by blast |
91 |
||
92 |
||
60770 | 93 |
subsection \<open>Exhaustion Rules\<close> |
20140 | 94 |
|
58977 | 95 |
lemma EmptyXH: "\<And>a. a : {} \<longleftrightarrow> False" |
96 |
and SubtypeXH: "\<And>a A P. a : {x:A. P(x)} \<longleftrightarrow> (a:A \<and> P(a))" |
|
97 |
and UnitXH: "\<And>a. a : Unit \<longleftrightarrow> a=one" |
|
98 |
and BoolXH: "\<And>a. a : Bool \<longleftrightarrow> a=true | a=false" |
|
99 |
and PlusXH: "\<And>a A B. a : A+B \<longleftrightarrow> (EX x:A. a=inl(x)) | (EX x:B. a=inr(x))" |
|
100 |
and PiXH: "\<And>a A B. a : PROD x:A. B(x) \<longleftrightarrow> (EX b. a=lam x. b(x) \<and> (ALL x:A. b(x):B(x)))" |
|
101 |
and SgXH: "\<And>a A B. a : SUM x:A. B(x) \<longleftrightarrow> (EX x:A. EX y:B(x).a=<x,y>)" |
|
20140 | 102 |
unfolding simp_type_defs by blast+ |
103 |
||
104 |
lemmas XHs = EmptyXH SubtypeXH UnitXH BoolXH PlusXH PiXH SgXH |
|
105 |
||
58977 | 106 |
lemma LiftXH: "a : [A] \<longleftrightarrow> (a=bot | a:A)" |
107 |
and TallXH: "a : TALL X. B(X) \<longleftrightarrow> (ALL X. a:B(X))" |
|
108 |
and TexXH: "a : TEX X. B(X) \<longleftrightarrow> (EX X. a:B(X))" |
|
20140 | 109 |
unfolding simp_type_defs by blast+ |
110 |
||
60770 | 111 |
ML \<open>ML_Thms.bind_thms ("case_rls", XH_to_Es @{thms XHs})\<close> |
20140 | 112 |
|
113 |
||
60770 | 114 |
subsection \<open>Canonical Type Rules\<close> |
20140 | 115 |
|
116 |
lemma oneT: "one : Unit" |
|
117 |
and trueT: "true : Bool" |
|
118 |
and falseT: "false : Bool" |
|
58977 | 119 |
and lamT: "\<And>b B. (\<And>x. x:A \<Longrightarrow> b(x):B(x)) \<Longrightarrow> lam x. b(x) : Pi(A,B)" |
120 |
and pairT: "\<And>b B. \<lbrakk>a:A; b:B(a)\<rbrakk> \<Longrightarrow> <a,b>:Sigma(A,B)" |
|
121 |
and inlT: "a:A \<Longrightarrow> inl(a) : A+B" |
|
122 |
and inrT: "b:B \<Longrightarrow> inr(b) : A+B" |
|
20140 | 123 |
by (blast intro: XHs [THEN iffD2])+ |
124 |
||
125 |
lemmas canTs = oneT trueT falseT pairT lamT inlT inrT |
|
126 |
||
127 |
||
60770 | 128 |
subsection \<open>Non-Canonical Type Rules\<close> |
20140 | 129 |
|
58977 | 130 |
lemma lem: "\<lbrakk>a:B(u); u = v\<rbrakk> \<Longrightarrow> a : B(v)" |
20140 | 131 |
by blast |
132 |
||
133 |
||
60770 | 134 |
ML \<open> |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
135 |
fun mk_ncanT_tac top_crls crls = |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
136 |
SUBPROOF (fn {context = ctxt, prems = major :: prems, ...} => |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58977
diff
changeset
|
137 |
resolve_tac ctxt ([major] RL top_crls) 1 THEN |
59499 | 138 |
REPEAT_SOME (eresolve_tac ctxt (crls @ @{thms exE bexE conjE disjE})) THEN |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
42814
diff
changeset
|
139 |
ALLGOALS (asm_simp_tac ctxt) THEN |
59499 | 140 |
ALLGOALS (assume_tac ctxt ORELSE' resolve_tac ctxt (prems RL [@{thm lem}]) |
141 |
ORELSE' eresolve_tac ctxt @{thms bspec}) THEN |
|
42793 | 142 |
safe_tac (ctxt addSIs prems)) |
60770 | 143 |
\<close> |
20140 | 144 |
|
60770 | 145 |
method_setup ncanT = \<open> |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
146 |
Scan.succeed (SIMPLE_METHOD' o mk_ncanT_tac @{thms case_rls} @{thms case_rls}) |
60770 | 147 |
\<close> |
20140 | 148 |
|
58977 | 149 |
lemma ifT: "\<lbrakk>b:Bool; b=true \<Longrightarrow> t:A(true); b=false \<Longrightarrow> u:A(false)\<rbrakk> \<Longrightarrow> if b then t else u : A(b)" |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
150 |
by ncanT |
20140 | 151 |
|
58977 | 152 |
lemma applyT: "\<lbrakk>f : Pi(A,B); a:A\<rbrakk> \<Longrightarrow> f ` a : B(a)" |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
153 |
by ncanT |
20140 | 154 |
|
58977 | 155 |
lemma splitT: "\<lbrakk>p:Sigma(A,B); \<And>x y. \<lbrakk>x:A; y:B(x); p=<x,y>\<rbrakk> \<Longrightarrow> c(x,y):C(<x,y>)\<rbrakk> \<Longrightarrow> split(p,c):C(p)" |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
156 |
by ncanT |
20140 | 157 |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
158 |
lemma whenT: |
58977 | 159 |
"\<lbrakk>p:A+B; |
160 |
\<And>x. \<lbrakk>x:A; p=inl(x)\<rbrakk> \<Longrightarrow> a(x):C(inl(x)); |
|
161 |
\<And>y. \<lbrakk>y:B; p=inr(y)\<rbrakk> \<Longrightarrow> b(y):C(inr(y))\<rbrakk> \<Longrightarrow> when(p,a,b) : C(p)" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
162 |
by ncanT |
20140 | 163 |
|
164 |
lemmas ncanTs = ifT applyT splitT whenT |
|
165 |
||
166 |
||
60770 | 167 |
subsection \<open>Subtypes\<close> |
20140 | 168 |
|
58977 | 169 |
lemma SubtypeD1: "a : Subtype(A, P) \<Longrightarrow> a : A" |
170 |
and SubtypeD2: "a : Subtype(A, P) \<Longrightarrow> P(a)" |
|
20140 | 171 |
by (simp_all add: SubtypeXH) |
172 |
||
58977 | 173 |
lemma SubtypeI: "\<lbrakk>a:A; P(a)\<rbrakk> \<Longrightarrow> a : {x:A. P(x)}" |
20140 | 174 |
by (simp add: SubtypeXH) |
175 |
||
58977 | 176 |
lemma SubtypeE: "\<lbrakk>a : {x:A. P(x)}; \<lbrakk>a:A; P(a)\<rbrakk> \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q" |
20140 | 177 |
by (simp add: SubtypeXH) |
178 |
||
179 |
||
60770 | 180 |
subsection \<open>Monotonicity\<close> |
20140 | 181 |
|
58977 | 182 |
lemma idM: "mono (\<lambda>X. X)" |
20140 | 183 |
apply (rule monoI) |
184 |
apply assumption |
|
185 |
done |
|
186 |
||
58977 | 187 |
lemma constM: "mono(\<lambda>X. A)" |
20140 | 188 |
apply (rule monoI) |
189 |
apply (rule subset_refl) |
|
190 |
done |
|
191 |
||
58977 | 192 |
lemma "mono(\<lambda>X. A(X)) \<Longrightarrow> mono(\<lambda>X.[A(X)])" |
20140 | 193 |
apply (rule subsetI [THEN monoI]) |
194 |
apply (drule LiftXH [THEN iffD1]) |
|
195 |
apply (erule disjE) |
|
196 |
apply (erule disjI1 [THEN LiftXH [THEN iffD2]]) |
|
197 |
apply (rule disjI2 [THEN LiftXH [THEN iffD2]]) |
|
198 |
apply (drule (1) monoD) |
|
199 |
apply blast |
|
200 |
done |
|
201 |
||
202 |
lemma SgM: |
|
58977 | 203 |
"\<lbrakk>mono(\<lambda>X. A(X)); \<And>x X. x:A(X) \<Longrightarrow> mono(\<lambda>X. B(X,x))\<rbrakk> \<Longrightarrow> |
204 |
mono(\<lambda>X. Sigma(A(X),B(X)))" |
|
20140 | 205 |
by (blast intro!: subsetI [THEN monoI] canTs elim!: case_rls |
206 |
dest!: monoD [THEN subsetD]) |
|
207 |
||
58977 | 208 |
lemma PiM: "(\<And>x. x:A \<Longrightarrow> mono(\<lambda>X. B(X,x))) \<Longrightarrow> mono(\<lambda>X. Pi(A,B(X)))" |
20140 | 209 |
by (blast intro!: subsetI [THEN monoI] canTs elim!: case_rls |
210 |
dest!: monoD [THEN subsetD]) |
|
211 |
||
58977 | 212 |
lemma PlusM: "\<lbrakk>mono(\<lambda>X. A(X)); mono(\<lambda>X. B(X))\<rbrakk> \<Longrightarrow> mono(\<lambda>X. A(X)+B(X))" |
20140 | 213 |
by (blast intro!: subsetI [THEN monoI] canTs elim!: case_rls |
214 |
dest!: monoD [THEN subsetD]) |
|
215 |
||
216 |
||
60770 | 217 |
subsection \<open>Recursive types\<close> |
20140 | 218 |
|
60770 | 219 |
subsubsection \<open>Conversion Rules for Fixed Points via monotonicity and Tarski\<close> |
20140 | 220 |
|
58977 | 221 |
lemma NatM: "mono(\<lambda>X. Unit+X)" |
20140 | 222 |
apply (rule PlusM constM idM)+ |
223 |
done |
|
224 |
||
225 |
lemma def_NatB: "Nat = Unit + Nat" |
|
226 |
apply (rule def_lfp_Tarski [OF Nat_def]) |
|
227 |
apply (rule NatM) |
|
228 |
done |
|
229 |
||
58977 | 230 |
lemma ListM: "mono(\<lambda>X.(Unit+Sigma(A,\<lambda>y. X)))" |
20140 | 231 |
apply (rule PlusM SgM constM idM)+ |
232 |
done |
|
233 |
||
234 |
lemma def_ListB: "List(A) = Unit + A * List(A)" |
|
235 |
apply (rule def_lfp_Tarski [OF List_def]) |
|
236 |
apply (rule ListM) |
|
237 |
done |
|
238 |
||
239 |
lemma def_ListsB: "Lists(A) = Unit + A * Lists(A)" |
|
240 |
apply (rule def_gfp_Tarski [OF Lists_def]) |
|
241 |
apply (rule ListM) |
|
242 |
done |
|
243 |
||
58977 | 244 |
lemma IListsM: "mono(\<lambda>X.({} + Sigma(A,\<lambda>y. X)))" |
20140 | 245 |
apply (rule PlusM SgM constM idM)+ |
246 |
done |
|
247 |
||
248 |
lemma def_IListsB: "ILists(A) = {} + A * ILists(A)" |
|
249 |
apply (rule def_gfp_Tarski [OF ILists_def]) |
|
250 |
apply (rule IListsM) |
|
251 |
done |
|
252 |
||
253 |
lemmas ind_type_eqs = def_NatB def_ListB def_ListsB def_IListsB |
|
254 |
||
255 |
||
60770 | 256 |
subsection \<open>Exhaustion Rules\<close> |
20140 | 257 |
|
58977 | 258 |
lemma NatXH: "a : Nat \<longleftrightarrow> (a=zero | (EX x:Nat. a=succ(x)))" |
259 |
and ListXH: "a : List(A) \<longleftrightarrow> (a=[] | (EX x:A. EX xs:List(A).a=x$xs))" |
|
260 |
and ListsXH: "a : Lists(A) \<longleftrightarrow> (a=[] | (EX x:A. EX xs:Lists(A).a=x$xs))" |
|
261 |
and IListsXH: "a : ILists(A) \<longleftrightarrow> (EX x:A. EX xs:ILists(A).a=x$xs)" |
|
20140 | 262 |
unfolding ind_data_defs |
263 |
by (rule ind_type_eqs [THEN XHlemma1], blast intro!: canTs elim!: case_rls)+ |
|
264 |
||
265 |
lemmas iXHs = NatXH ListXH |
|
266 |
||
60770 | 267 |
ML \<open>ML_Thms.bind_thms ("icase_rls", XH_to_Es @{thms iXHs})\<close> |
20140 | 268 |
|
269 |
||
60770 | 270 |
subsection \<open>Type Rules\<close> |
20140 | 271 |
|
272 |
lemma zeroT: "zero : Nat" |
|
58977 | 273 |
and succT: "n:Nat \<Longrightarrow> succ(n) : Nat" |
20140 | 274 |
and nilT: "[] : List(A)" |
58977 | 275 |
and consT: "\<lbrakk>h:A; t:List(A)\<rbrakk> \<Longrightarrow> h$t : List(A)" |
20140 | 276 |
by (blast intro: iXHs [THEN iffD2])+ |
277 |
||
278 |
lemmas icanTs = zeroT succT nilT consT |
|
279 |
||
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
280 |
|
60770 | 281 |
method_setup incanT = \<open> |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
282 |
Scan.succeed (SIMPLE_METHOD' o mk_ncanT_tac @{thms icase_rls} @{thms case_rls}) |
60770 | 283 |
\<close> |
20140 | 284 |
|
58977 | 285 |
lemma ncaseT: "\<lbrakk>n:Nat; n=zero \<Longrightarrow> b:C(zero); \<And>x. \<lbrakk>x:Nat; n=succ(x)\<rbrakk> \<Longrightarrow> c(x):C(succ(x))\<rbrakk> |
286 |
\<Longrightarrow> ncase(n,b,c) : C(n)" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
287 |
by incanT |
20140 | 288 |
|
58977 | 289 |
lemma lcaseT: "\<lbrakk>l:List(A); l = [] \<Longrightarrow> b:C([]); \<And>h t. \<lbrakk>h:A; t:List(A); l=h$t\<rbrakk> \<Longrightarrow> c(h,t):C(h$t)\<rbrakk> |
290 |
\<Longrightarrow> lcase(l,b,c) : C(l)" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
291 |
by incanT |
20140 | 292 |
|
293 |
lemmas incanTs = ncaseT lcaseT |
|
294 |
||
295 |
||
60770 | 296 |
subsection \<open>Induction Rules\<close> |
20140 | 297 |
|
298 |
lemmas ind_Ms = NatM ListM |
|
299 |
||
58977 | 300 |
lemma Nat_ind: "\<lbrakk>n:Nat; P(zero); \<And>x. \<lbrakk>x:Nat; P(x)\<rbrakk> \<Longrightarrow> P(succ(x))\<rbrakk> \<Longrightarrow> P(n)" |
20140 | 301 |
apply (unfold ind_data_defs) |
302 |
apply (erule def_induct [OF Nat_def _ NatM]) |
|
303 |
apply (blast intro: canTs elim!: case_rls) |
|
304 |
done |
|
305 |
||
58977 | 306 |
lemma List_ind: "\<lbrakk>l:List(A); P([]); \<And>x xs. \<lbrakk>x:A; xs:List(A); P(xs)\<rbrakk> \<Longrightarrow> P(x$xs)\<rbrakk> \<Longrightarrow> P(l)" |
20140 | 307 |
apply (unfold ind_data_defs) |
308 |
apply (erule def_induct [OF List_def _ ListM]) |
|
309 |
apply (blast intro: canTs elim!: case_rls) |
|
310 |
done |
|
311 |
||
312 |
lemmas inds = Nat_ind List_ind |
|
313 |
||
314 |
||
60770 | 315 |
subsection \<open>Primitive Recursive Rules\<close> |
20140 | 316 |
|
58977 | 317 |
lemma nrecT: "\<lbrakk>n:Nat; b:C(zero); \<And>x g. \<lbrakk>x:Nat; g:C(x)\<rbrakk> \<Longrightarrow> c(x,g):C(succ(x))\<rbrakk> |
318 |
\<Longrightarrow> nrec(n,b,c) : C(n)" |
|
20140 | 319 |
by (erule Nat_ind) auto |
320 |
||
58977 | 321 |
lemma lrecT: "\<lbrakk>l:List(A); b:C([]); \<And>x xs g. \<lbrakk>x:A; xs:List(A); g:C(xs)\<rbrakk> \<Longrightarrow> c(x,xs,g):C(x$xs) \<rbrakk> |
322 |
\<Longrightarrow> lrec(l,b,c) : C(l)" |
|
20140 | 323 |
by (erule List_ind) auto |
324 |
||
325 |
lemmas precTs = nrecT lrecT |
|
326 |
||
327 |
||
60770 | 328 |
subsection \<open>Theorem proving\<close> |
20140 | 329 |
|
58977 | 330 |
lemma SgE2: "\<lbrakk><a,b> : Sigma(A,B); \<lbrakk>a:A; b:B(a)\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" |
20140 | 331 |
unfolding SgXH by blast |
332 |
||
333 |
(* General theorem proving ignores non-canonical term-formers, *) |
|
334 |
(* - intro rules are type rules for canonical terms *) |
|
335 |
(* - elim rules are case rules (no non-canonical terms appear) *) |
|
336 |
||
60770 | 337 |
ML \<open>ML_Thms.bind_thms ("XHEs", XH_to_Es @{thms XHs})\<close> |
20140 | 338 |
|
339 |
lemmas [intro!] = SubtypeI canTs icanTs |
|
340 |
and [elim!] = SubtypeE XHEs |
|
341 |
||
342 |
||
60770 | 343 |
subsection \<open>Infinite Data Types\<close> |
20140 | 344 |
|
58977 | 345 |
lemma lfp_subset_gfp: "mono(f) \<Longrightarrow> lfp(f) <= gfp(f)" |
20140 | 346 |
apply (rule lfp_lowerbound [THEN subset_trans]) |
347 |
apply (erule gfp_lemma3) |
|
348 |
apply (rule subset_refl) |
|
349 |
done |
|
350 |
||
351 |
lemma gfpI: |
|
352 |
assumes "a:A" |
|
58977 | 353 |
and "\<And>x X. \<lbrakk>x:A; ALL y:A. t(y):X\<rbrakk> \<Longrightarrow> t(x) : B(X)" |
20140 | 354 |
shows "t(a) : gfp(B)" |
355 |
apply (rule coinduct) |
|
58977 | 356 |
apply (rule_tac P = "\<lambda>x. EX y:A. x=t (y)" in CollectI) |
41526 | 357 |
apply (blast intro!: assms)+ |
20140 | 358 |
done |
359 |
||
58977 | 360 |
lemma def_gfpI: "\<lbrakk>C == gfp(B); a:A; \<And>x X. \<lbrakk>x:A; ALL y:A. t(y):X\<rbrakk> \<Longrightarrow> t(x) : B(X)\<rbrakk> \<Longrightarrow> t(a) : C" |
20140 | 361 |
apply unfold |
362 |
apply (erule gfpI) |
|
363 |
apply blast |
|
364 |
done |
|
365 |
||
366 |
(* EG *) |
|
367 |
lemma "letrec g x be zero$g(x) in g(bot) : Lists(Nat)" |
|
368 |
apply (rule refl [THEN UnitXH [THEN iffD2], THEN Lists_def [THEN def_gfpI]]) |
|
369 |
apply (subst letrecB) |
|
370 |
apply (unfold cons_def) |
|
371 |
apply blast |
|
372 |
done |
|
373 |
||
374 |
||
62020 | 375 |
subsection \<open>Lemmas and tactics for using the rule \<open>coinduct3\<close> on \<open>[=\<close> and \<open>=\<close>\<close> |
20140 | 376 |
|
58977 | 377 |
lemma lfpI: "\<lbrakk>mono(f); a : f(lfp(f))\<rbrakk> \<Longrightarrow> a : lfp(f)" |
20140 | 378 |
apply (erule lfp_Tarski [THEN ssubst]) |
379 |
apply assumption |
|
380 |
done |
|
381 |
||
58977 | 382 |
lemma ssubst_single: "\<lbrakk>a = a'; a' : A\<rbrakk> \<Longrightarrow> a : A" |
20140 | 383 |
by simp |
384 |
||
58977 | 385 |
lemma ssubst_pair: "\<lbrakk>a = a'; b = b'; <a',b'> : A\<rbrakk> \<Longrightarrow> <a,b> : A" |
20140 | 386 |
by simp |
387 |
||
388 |
||
60770 | 389 |
ML \<open> |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
390 |
val coinduct3_tac = SUBPROOF (fn {context = ctxt, prems = mono :: prems, ...} => |
42793 | 391 |
fast_tac (ctxt addIs (mono RS @{thm coinduct3_mono_lemma} RS @{thm lfpI}) :: prems) 1); |
60770 | 392 |
\<close> |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
393 |
|
60770 | 394 |
method_setup coinduct3 = \<open>Scan.succeed (SIMPLE_METHOD' o coinduct3_tac)\<close> |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
395 |
|
58977 | 396 |
lemma ci3_RI: "\<lbrakk>mono(Agen); a : R\<rbrakk> \<Longrightarrow> a : lfp(\<lambda>x. Agen(x) Un R Un A)" |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
397 |
by coinduct3 |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
398 |
|
58977 | 399 |
lemma ci3_AgenI: "\<lbrakk>mono(Agen); a : Agen(lfp(\<lambda>x. Agen(x) Un R Un A))\<rbrakk> \<Longrightarrow> |
400 |
a : lfp(\<lambda>x. Agen(x) Un R Un A)" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
401 |
by coinduct3 |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
402 |
|
58977 | 403 |
lemma ci3_AI: "\<lbrakk>mono(Agen); a : A\<rbrakk> \<Longrightarrow> a : lfp(\<lambda>x. Agen(x) Un R Un A)" |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
404 |
by coinduct3 |
20140 | 405 |
|
60770 | 406 |
ML \<open> |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
407 |
fun genIs_tac ctxt genXH gen_mono = |
60754 | 408 |
resolve_tac ctxt [genXH RS @{thm iffD2}] THEN' |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
42814
diff
changeset
|
409 |
simp_tac ctxt THEN' |
42793 | 410 |
TRY o fast_tac |
411 |
(ctxt addIs [genXH RS @{thm iffD2}, gen_mono RS @{thm coinduct3_mono_lemma} RS @{thm lfpI}]) |
|
60770 | 412 |
\<close> |
20140 | 413 |
|
60770 | 414 |
method_setup genIs = \<open> |
42814 | 415 |
Attrib.thm -- Attrib.thm >> |
416 |
(fn (genXH, gen_mono) => fn ctxt => SIMPLE_METHOD' (genIs_tac ctxt genXH gen_mono)) |
|
60770 | 417 |
\<close> |
20140 | 418 |
|
419 |
||
60770 | 420 |
subsection \<open>POgen\<close> |
20140 | 421 |
|
422 |
lemma PO_refl: "<a,a> : PO" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
423 |
by (rule po_refl [THEN PO_iff [THEN iffD1]]) |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
424 |
|
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
425 |
lemma POgenIs: |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
426 |
"<true,true> : POgen(R)" |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
427 |
"<false,false> : POgen(R)" |
58977 | 428 |
"\<lbrakk><a,a'> : R; <b,b'> : R\<rbrakk> \<Longrightarrow> <<a,b>,<a',b'>> : POgen(R)" |
429 |
"\<And>b b'. (\<And>x. <b(x),b'(x)> : R) \<Longrightarrow> <lam x. b(x),lam x. b'(x)> : POgen(R)" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
430 |
"<one,one> : POgen(R)" |
58977 | 431 |
"<a,a'> : lfp(\<lambda>x. POgen(x) Un R Un PO) \<Longrightarrow> |
432 |
<inl(a),inl(a')> : POgen(lfp(\<lambda>x. POgen(x) Un R Un PO))" |
|
433 |
"<b,b'> : lfp(\<lambda>x. POgen(x) Un R Un PO) \<Longrightarrow> |
|
434 |
<inr(b),inr(b')> : POgen(lfp(\<lambda>x. POgen(x) Un R Un PO))" |
|
435 |
"<zero,zero> : POgen(lfp(\<lambda>x. POgen(x) Un R Un PO))" |
|
436 |
"<n,n'> : lfp(\<lambda>x. POgen(x) Un R Un PO) \<Longrightarrow> |
|
437 |
<succ(n),succ(n')> : POgen(lfp(\<lambda>x. POgen(x) Un R Un PO))" |
|
438 |
"<[],[]> : POgen(lfp(\<lambda>x. POgen(x) Un R Un PO))" |
|
439 |
"\<lbrakk><h,h'> : lfp(\<lambda>x. POgen(x) Un R Un PO); <t,t'> : lfp(\<lambda>x. POgen(x) Un R Un PO)\<rbrakk> |
|
440 |
\<Longrightarrow> <h$t,h'$t'> : POgen(lfp(\<lambda>x. POgen(x) Un R Un PO))" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
441 |
unfolding data_defs by (genIs POgenXH POgen_mono)+ |
20140 | 442 |
|
60770 | 443 |
ML \<open> |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
444 |
fun POgen_tac ctxt (rla, rlb) i = |
42793 | 445 |
SELECT_GOAL (safe_tac ctxt) i THEN |
60754 | 446 |
resolve_tac ctxt [rlb RS (rla RS @{thm ssubst_pair})] i THEN |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58977
diff
changeset
|
447 |
(REPEAT (resolve_tac ctxt |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
448 |
(@{thms POgenIs} @ [@{thm PO_refl} RS (@{thm POgen_mono} RS @{thm ci3_AI})] @ |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
449 |
(@{thms POgenIs} RL [@{thm POgen_mono} RS @{thm ci3_AgenI}]) @ |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
450 |
[@{thm POgen_mono} RS @{thm ci3_RI}]) i)) |
60770 | 451 |
\<close> |
20140 | 452 |
|
453 |
||
60770 | 454 |
subsection \<open>EQgen\<close> |
20140 | 455 |
|
456 |
lemma EQ_refl: "<a,a> : EQ" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
457 |
by (rule refl [THEN EQ_iff [THEN iffD1]]) |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
458 |
|
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
459 |
lemma EQgenIs: |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
460 |
"<true,true> : EQgen(R)" |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
461 |
"<false,false> : EQgen(R)" |
58977 | 462 |
"\<lbrakk><a,a'> : R; <b,b'> : R\<rbrakk> \<Longrightarrow> <<a,b>,<a',b'>> : EQgen(R)" |
463 |
"\<And>b b'. (\<And>x. <b(x),b'(x)> : R) \<Longrightarrow> <lam x. b(x),lam x. b'(x)> : EQgen(R)" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
464 |
"<one,one> : EQgen(R)" |
58977 | 465 |
"<a,a'> : lfp(\<lambda>x. EQgen(x) Un R Un EQ) \<Longrightarrow> |
466 |
<inl(a),inl(a')> : EQgen(lfp(\<lambda>x. EQgen(x) Un R Un EQ))" |
|
467 |
"<b,b'> : lfp(\<lambda>x. EQgen(x) Un R Un EQ) \<Longrightarrow> |
|
468 |
<inr(b),inr(b')> : EQgen(lfp(\<lambda>x. EQgen(x) Un R Un EQ))" |
|
469 |
"<zero,zero> : EQgen(lfp(\<lambda>x. EQgen(x) Un R Un EQ))" |
|
470 |
"<n,n'> : lfp(\<lambda>x. EQgen(x) Un R Un EQ) \<Longrightarrow> |
|
471 |
<succ(n),succ(n')> : EQgen(lfp(\<lambda>x. EQgen(x) Un R Un EQ))" |
|
472 |
"<[],[]> : EQgen(lfp(\<lambda>x. EQgen(x) Un R Un EQ))" |
|
473 |
"\<lbrakk><h,h'> : lfp(\<lambda>x. EQgen(x) Un R Un EQ); <t,t'> : lfp(\<lambda>x. EQgen(x) Un R Un EQ)\<rbrakk> |
|
474 |
\<Longrightarrow> <h$t,h'$t'> : EQgen(lfp(\<lambda>x. EQgen(x) Un R Un EQ))" |
|
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
475 |
unfolding data_defs by (genIs EQgenXH EQgen_mono)+ |
20140 | 476 |
|
60770 | 477 |
ML \<open> |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58977
diff
changeset
|
478 |
fun EQgen_raw_tac ctxt i = |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58977
diff
changeset
|
479 |
(REPEAT (resolve_tac ctxt (@{thms EQgenIs} @ |
32153
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
480 |
[@{thm EQ_refl} RS (@{thm EQgen_mono} RS @{thm ci3_AI})] @ |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
481 |
(@{thms EQgenIs} RL [@{thm EQgen_mono} RS @{thm ci3_AgenI}]) @ |
a0e57fb1b930
misc modernization: proper method setup instead of adhoc ML proofs;
wenzelm
parents:
32149
diff
changeset
|
482 |
[@{thm EQgen_mono} RS @{thm ci3_RI}]) i)) |
20140 | 483 |
|
484 |
(* Goals of the form R <= EQgen(R) - rewrite elements <a,b> : EQgen(R) using rews and *) |
|
485 |
(* then reduce this to a goal <a',b'> : R (hopefully?) *) |
|
486 |
(* rews are rewrite rules that would cause looping in the simpifier *) |
|
487 |
||
23894
1a4167d761ac
tactics: avoid dynamic reference to accidental theory context (via ML_Context.the_context etc.);
wenzelm
parents:
20140
diff
changeset
|
488 |
fun EQgen_tac ctxt rews i = |
20140 | 489 |
SELECT_GOAL |
42793 | 490 |
(TRY (safe_tac ctxt) THEN |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58977
diff
changeset
|
491 |
resolve_tac ctxt ((rews @ [@{thm refl}]) RL ((rews @ [@{thm refl}]) RL [@{thm ssubst_pair}])) i THEN |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
42814
diff
changeset
|
492 |
ALLGOALS (simp_tac ctxt) THEN |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58977
diff
changeset
|
493 |
ALLGOALS (EQgen_raw_tac ctxt)) i |
60770 | 494 |
\<close> |
0 | 495 |
|
60770 | 496 |
method_setup EQgen = \<open> |
58971 | 497 |
Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD' (EQgen_tac ctxt ths)) |
60770 | 498 |
\<close> |
58971 | 499 |
|
0 | 500 |
end |