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