src/ZF/Epsilon.thy
author paulson
Tue Jul 02 13:28:08 2002 +0200 (2002-07-02)
changeset 13269 3ba9be497c33
parent 13217 bc5dc2392578
child 13328 703de709a64b
permissions -rw-r--r--
Tidying and introduction of various new theorems
     1 (*  Title:      ZF/epsilon.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1993  University of Cambridge
     5 
     6 Epsilon induction and recursion
     7 *)
     8 
     9 theory Epsilon = Nat + mono:
    10 
    11 constdefs
    12   eclose    :: "i=>i"
    13     "eclose(A) == UN n:nat. nat_rec(n, A, %m r. Union(r))"
    14 
    15   transrec  :: "[i, [i,i]=>i] =>i"
    16     "transrec(a,H) == wfrec(Memrel(eclose({a})), a, H)"
    17  
    18   rank      :: "i=>i"
    19     "rank(a) == transrec(a, %x f. UN y:x. succ(f`y))"
    20 
    21   transrec2 :: "[i, i, [i,i]=>i] =>i"
    22     "transrec2(k, a, b) ==                     
    23        transrec(k, 
    24                 %i r. if(i=0, a, 
    25                         if(EX j. i=succ(j),        
    26                            b(THE j. i=succ(j), r`(THE j. i=succ(j))),   
    27                            UN j<i. r`j)))"
    28 
    29   recursor  :: "[i, [i,i]=>i, i]=>i"
    30     "recursor(a,b,k) ==  transrec(k, %n f. nat_case(a, %m. b(m, f`m), n))"
    31 
    32   rec  :: "[i, i, [i,i]=>i]=>i"
    33     "rec(k,a,b) == recursor(a,b,k)"
    34 
    35 
    36 (*** Basic closure properties ***)
    37 
    38 lemma arg_subset_eclose: "A <= eclose(A)"
    39 apply (unfold eclose_def)
    40 apply (rule nat_rec_0 [THEN equalityD2, THEN subset_trans])
    41 apply (rule nat_0I [THEN UN_upper])
    42 done
    43 
    44 lemmas arg_into_eclose = arg_subset_eclose [THEN subsetD, standard]
    45 
    46 lemma Transset_eclose: "Transset(eclose(A))"
    47 apply (unfold eclose_def Transset_def)
    48 apply (rule subsetI [THEN ballI])
    49 apply (erule UN_E)
    50 apply (rule nat_succI [THEN UN_I], assumption)
    51 apply (erule nat_rec_succ [THEN ssubst])
    52 apply (erule UnionI, assumption)
    53 done
    54 
    55 (* x : eclose(A) ==> x <= eclose(A) *)
    56 lemmas eclose_subset =  
    57        Transset_eclose [unfolded Transset_def, THEN bspec, standard]
    58 
    59 (* [| A : eclose(B); c : A |] ==> c : eclose(B) *)
    60 lemmas ecloseD = eclose_subset [THEN subsetD, standard]
    61 
    62 lemmas arg_in_eclose_sing = arg_subset_eclose [THEN singleton_subsetD]
    63 lemmas arg_into_eclose_sing = arg_in_eclose_sing [THEN ecloseD, standard]
    64 
    65 (* This is epsilon-induction for eclose(A); see also eclose_induct_down...
    66    [| a: eclose(A);  !!x. [| x: eclose(A); ALL y:x. P(y) |] ==> P(x) 
    67    |] ==> P(a) 
    68 *)
    69 lemmas eclose_induct =
    70      Transset_induct [OF _ Transset_eclose, induct set: eclose]
    71 
    72 
    73 (*Epsilon induction*)
    74 lemma eps_induct:
    75     "[| !!x. ALL y:x. P(y) ==> P(x) |]  ==>  P(a)"
    76 by (rule arg_in_eclose_sing [THEN eclose_induct], blast) 
    77 
    78 
    79 (*** Leastness of eclose ***)
    80 
    81 (** eclose(A) is the least transitive set including A as a subset. **)
    82 
    83 lemma eclose_least_lemma: 
    84     "[| Transset(X);  A<=X;  n: nat |] ==> nat_rec(n, A, %m r. Union(r)) <= X"
    85 apply (unfold Transset_def)
    86 apply (erule nat_induct) 
    87 apply (simp add: nat_rec_0)
    88 apply (simp add: nat_rec_succ, blast)
    89 done
    90 
    91 lemma eclose_least: 
    92      "[| Transset(X);  A<=X |] ==> eclose(A) <= X"
    93 apply (unfold eclose_def)
    94 apply (rule eclose_least_lemma [THEN UN_least], assumption+)
    95 done
    96 
    97 (*COMPLETELY DIFFERENT induction principle from eclose_induct!!*)
    98 lemma eclose_induct_down: 
    99     "[| a: eclose(b);                                            
   100         !!y.   [| y: b |] ==> P(y);                              
   101         !!y z. [| y: eclose(b);  P(y);  z: y |] ==> P(z)         
   102      |] ==> P(a)"
   103 apply (rule eclose_least [THEN subsetD, THEN CollectD2, of "eclose(b)"])
   104   prefer 3 apply assumption
   105  apply (unfold Transset_def) 
   106  apply (blast intro: ecloseD)
   107 apply (blast intro: arg_subset_eclose [THEN subsetD])
   108 done
   109 
   110 (*fixed up for induct method*)
   111 lemmas eclose_induct_down = eclose_induct_down [consumes 1]
   112 
   113 lemma Transset_eclose_eq_arg: "Transset(X) ==> eclose(X) = X"
   114 apply (erule equalityI [OF eclose_least arg_subset_eclose])
   115 apply (rule subset_refl)
   116 done
   117 
   118 
   119 (*** Epsilon recursion ***)
   120 
   121 (*Unused...*)
   122 lemma mem_eclose_trans: "[| A: eclose(B);  B: eclose(C) |] ==> A: eclose(C)"
   123 by (rule eclose_least [OF Transset_eclose eclose_subset, THEN subsetD], 
   124     assumption+)
   125 
   126 (*Variant of the previous lemma in a useable form for the sequel*)
   127 lemma mem_eclose_sing_trans:
   128      "[| A: eclose({B});  B: eclose({C}) |] ==> A: eclose({C})"
   129 by (rule eclose_least [OF Transset_eclose singleton_subsetI, THEN subsetD], 
   130     assumption+)
   131 
   132 lemma under_Memrel: "[| Transset(i);  j:i |] ==> Memrel(i)-``{j} = j"
   133 by (unfold Transset_def, blast)
   134 
   135 lemma lt_Memrel: "j < i ==> Memrel(i) -`` {j} = j"
   136 by (simp add: lt_def Ord_def under_Memrel) 
   137 
   138 (* j : eclose(A) ==> Memrel(eclose(A)) -`` j = j *)
   139 lemmas under_Memrel_eclose = Transset_eclose [THEN under_Memrel, standard]
   140 
   141 lemmas wfrec_ssubst = wf_Memrel [THEN wfrec, THEN ssubst]
   142 
   143 lemma wfrec_eclose_eq:
   144     "[| k:eclose({j});  j:eclose({i}) |] ==>  
   145      wfrec(Memrel(eclose({i})), k, H) = wfrec(Memrel(eclose({j})), k, H)"
   146 apply (erule eclose_induct)
   147 apply (rule wfrec_ssubst)
   148 apply (rule wfrec_ssubst)
   149 apply (simp add: under_Memrel_eclose mem_eclose_sing_trans [of _ j i])
   150 done
   151 
   152 lemma wfrec_eclose_eq2: 
   153     "k: i ==> wfrec(Memrel(eclose({i})),k,H) = wfrec(Memrel(eclose({k})),k,H)"
   154 apply (rule arg_in_eclose_sing [THEN wfrec_eclose_eq])
   155 apply (erule arg_into_eclose_sing)
   156 done
   157 
   158 lemma transrec: "transrec(a,H) = H(a, lam x:a. transrec(x,H))"
   159 apply (unfold transrec_def)
   160 apply (rule wfrec_ssubst)
   161 apply (simp add: wfrec_eclose_eq2 arg_in_eclose_sing under_Memrel_eclose)
   162 done
   163 
   164 (*Avoids explosions in proofs; resolve it with a meta-level definition.*)
   165 lemma def_transrec:
   166     "[| !!x. f(x)==transrec(x,H) |] ==> f(a) = H(a, lam x:a. f(x))"
   167 apply simp
   168 apply (rule transrec)
   169 done
   170 
   171 lemma transrec_type:
   172     "[| !!x u. [| x:eclose({a});  u: Pi(x,B) |] ==> H(x,u) : B(x) |]
   173      ==> transrec(a,H) : B(a)"
   174 apply (rule_tac i = "a" in arg_in_eclose_sing [THEN eclose_induct])
   175 apply (subst transrec)
   176 apply (simp add: lam_type) 
   177 done
   178 
   179 lemma eclose_sing_Ord: "Ord(i) ==> eclose({i}) <= succ(i)"
   180 apply (erule Ord_is_Transset [THEN Transset_succ, THEN eclose_least])
   181 apply (rule succI1 [THEN singleton_subsetI])
   182 done
   183 
   184 lemma succ_subset_eclose_sing: "succ(i) <= eclose({i})"
   185 apply (insert arg_subset_eclose [of "{i}"], simp) 
   186 apply (frule eclose_subset, blast) 
   187 done
   188 
   189 lemma eclose_sing_Ord_eq: "Ord(i) ==> eclose({i}) = succ(i)"
   190 apply (rule equalityI)
   191 apply (erule eclose_sing_Ord)  
   192 apply (rule succ_subset_eclose_sing) 
   193 done
   194 
   195 lemma Ord_transrec_type:
   196   assumes jini: "j: i"
   197       and ordi: "Ord(i)"
   198       and minor: " !!x u. [| x: i;  u: Pi(x,B) |] ==> H(x,u) : B(x)"
   199   shows "transrec(j,H) : B(j)"
   200 apply (rule transrec_type)
   201 apply (insert jini ordi)
   202 apply (blast intro!: minor
   203              intro: Ord_trans 
   204              dest: Ord_in_Ord [THEN eclose_sing_Ord, THEN subsetD])
   205 done
   206 
   207 (*** Rank ***)
   208 
   209 (*NOT SUITABLE FOR REWRITING -- RECURSIVE!*)
   210 lemma rank: "rank(a) = (UN y:a. succ(rank(y)))"
   211 by (subst rank_def [THEN def_transrec], simp)
   212 
   213 lemma Ord_rank [simp]: "Ord(rank(a))"
   214 apply (rule_tac a="a" in eps_induct) 
   215 apply (subst rank)
   216 apply (rule Ord_succ [THEN Ord_UN])
   217 apply (erule bspec, assumption)
   218 done
   219 
   220 lemma rank_of_Ord: "Ord(i) ==> rank(i) = i"
   221 apply (erule trans_induct)
   222 apply (subst rank)
   223 apply (simp add: Ord_equality)
   224 done
   225 
   226 lemma rank_lt: "a:b ==> rank(a) < rank(b)"
   227 apply (rule_tac a1 = "b" in rank [THEN ssubst])
   228 apply (erule UN_I [THEN ltI])
   229 apply (rule_tac [2] Ord_UN, auto)
   230 done
   231 
   232 lemma eclose_rank_lt: "a: eclose(b) ==> rank(a) < rank(b)"
   233 apply (erule eclose_induct_down)
   234 apply (erule rank_lt)
   235 apply (erule rank_lt [THEN lt_trans], assumption)
   236 done
   237 
   238 lemma rank_mono: "a<=b ==> rank(a) le rank(b)"
   239 apply (rule subset_imp_le)
   240 apply (subst rank)
   241 apply (subst rank, auto)
   242 done
   243 
   244 lemma rank_Pow: "rank(Pow(a)) = succ(rank(a))"
   245 apply (rule rank [THEN trans])
   246 apply (rule le_anti_sym)
   247 apply (rule_tac [2] UN_upper_le)
   248 apply (rule UN_least_le)
   249 apply (auto intro: rank_mono simp add: Ord_UN)
   250 done
   251 
   252 lemma rank_0 [simp]: "rank(0) = 0"
   253 by (rule rank [THEN trans], blast)
   254 
   255 lemma rank_succ [simp]: "rank(succ(x)) = succ(rank(x))"
   256 apply (rule rank [THEN trans])
   257 apply (rule equalityI [OF UN_least succI1 [THEN UN_upper]])
   258 apply (erule succE, blast)
   259 apply (erule rank_lt [THEN leI, THEN succ_leI, THEN le_imp_subset])
   260 done
   261 
   262 lemma rank_Union: "rank(Union(A)) = (UN x:A. rank(x))"
   263 apply (rule equalityI)
   264 apply (rule_tac [2] rank_mono [THEN le_imp_subset, THEN UN_least])
   265 apply (erule_tac [2] Union_upper)
   266 apply (subst rank)
   267 apply (rule UN_least)
   268 apply (erule UnionE)
   269 apply (rule subset_trans)
   270 apply (erule_tac [2] RepFunI [THEN Union_upper])
   271 apply (erule rank_lt [THEN succ_leI, THEN le_imp_subset])
   272 done
   273 
   274 lemma rank_eclose: "rank(eclose(a)) = rank(a)"
   275 apply (rule le_anti_sym)
   276 apply (rule_tac [2] arg_subset_eclose [THEN rank_mono])
   277 apply (rule_tac a1 = "eclose (a) " in rank [THEN ssubst])
   278 apply (rule Ord_rank [THEN UN_least_le])
   279 apply (erule eclose_rank_lt [THEN succ_leI])
   280 done
   281 
   282 lemma rank_pair1: "rank(a) < rank(<a,b>)"
   283 apply (unfold Pair_def)
   284 apply (rule consI1 [THEN rank_lt, THEN lt_trans])
   285 apply (rule consI1 [THEN consI2, THEN rank_lt])
   286 done
   287 
   288 lemma rank_pair2: "rank(b) < rank(<a,b>)"
   289 apply (unfold Pair_def)
   290 apply (rule consI1 [THEN consI2, THEN rank_lt, THEN lt_trans])
   291 apply (rule consI1 [THEN consI2, THEN rank_lt])
   292 done
   293 
   294 (*Not clear how to remove the P(a) condition, since the "then" part
   295   must refer to "a"*)
   296 lemma the_equality_if:
   297      "P(a) ==> (THE x. P(x)) = (if (EX!x. P(x)) then a else 0)"
   298 by (simp add: the_0 the_equality2)
   299 
   300 (*The first premise not only fixs i but ensures f~=0.
   301   The second premise is now essential.  Consider otherwise the relation 
   302   r = {<0,0>,<0,1>,<0,2>,...}.  Then f`0 = Union(f``{0}) = Union(nat) = nat,
   303   whose rank equals that of r.*)
   304 lemma rank_apply: "[|i : domain(f); function(f)|] ==> rank(f`i) < rank(f)"
   305 apply clarify  
   306 apply (simp add: function_apply_equality) 
   307 apply (blast intro: lt_trans rank_lt rank_pair2)
   308 done
   309 
   310 
   311 (*** Corollaries of leastness ***)
   312 
   313 lemma mem_eclose_subset: "A:B ==> eclose(A)<=eclose(B)"
   314 apply (rule Transset_eclose [THEN eclose_least])
   315 apply (erule arg_into_eclose [THEN eclose_subset])
   316 done
   317 
   318 lemma eclose_mono: "A<=B ==> eclose(A) <= eclose(B)"
   319 apply (rule Transset_eclose [THEN eclose_least])
   320 apply (erule subset_trans)
   321 apply (rule arg_subset_eclose)
   322 done
   323 
   324 (** Idempotence of eclose **)
   325 
   326 lemma eclose_idem: "eclose(eclose(A)) = eclose(A)"
   327 apply (rule equalityI)
   328 apply (rule eclose_least [OF Transset_eclose subset_refl])
   329 apply (rule arg_subset_eclose)
   330 done
   331 
   332 (** Transfinite recursion for definitions based on the 
   333     three cases of ordinals **)
   334 
   335 lemma transrec2_0 [simp]: "transrec2(0,a,b) = a"
   336 by (rule transrec2_def [THEN def_transrec, THEN trans], simp)
   337 
   338 lemma transrec2_succ [simp]: "transrec2(succ(i),a,b) = b(i, transrec2(i,a,b))"
   339 apply (rule transrec2_def [THEN def_transrec, THEN trans])
   340 apply (simp add: the_equality if_P)
   341 done
   342 
   343 lemma transrec2_Limit:
   344      "Limit(i) ==> transrec2(i,a,b) = (UN j<i. transrec2(j,a,b))"
   345 apply (rule transrec2_def [THEN def_transrec, THEN trans])
   346 apply (auto simp add: OUnion_def) 
   347 done
   348 
   349 lemma def_transrec2:
   350      "(!!x. f(x)==transrec2(x,a,b))
   351       ==> f(0) = a & 
   352           f(succ(i)) = b(i, f(i)) & 
   353           (Limit(K) --> f(K) = (UN j<K. f(j)))"
   354 by (simp add: transrec2_Limit)
   355 
   356 
   357 (** recursor -- better than nat_rec; the succ case has no type requirement! **)
   358 
   359 (*NOT suitable for rewriting*)
   360 lemmas recursor_lemma = recursor_def [THEN def_transrec, THEN trans]
   361 
   362 lemma recursor_0: "recursor(a,b,0) = a"
   363 by (rule nat_case_0 [THEN recursor_lemma])
   364 
   365 lemma recursor_succ: "recursor(a,b,succ(m)) = b(m, recursor(a,b,m))"
   366 by (rule recursor_lemma, simp)
   367 
   368 
   369 (** rec: old version for compatibility **)
   370 
   371 lemma rec_0 [simp]: "rec(0,a,b) = a"
   372 apply (unfold rec_def)
   373 apply (rule recursor_0)
   374 done
   375 
   376 lemma rec_succ [simp]: "rec(succ(m),a,b) = b(m, rec(m,a,b))"
   377 apply (unfold rec_def)
   378 apply (rule recursor_succ)
   379 done
   380 
   381 lemma rec_type:
   382     "[| n: nat;   
   383         a: C(0);   
   384         !!m z. [| m: nat;  z: C(m) |] ==> b(m,z): C(succ(m)) |]
   385      ==> rec(n,a,b) : C(n)"
   386 by (erule nat_induct, auto)
   387 
   388 ML
   389 {*
   390 val arg_subset_eclose = thm "arg_subset_eclose";
   391 val arg_into_eclose = thm "arg_into_eclose";
   392 val Transset_eclose = thm "Transset_eclose";
   393 val eclose_subset = thm "eclose_subset";
   394 val ecloseD = thm "ecloseD";
   395 val arg_in_eclose_sing = thm "arg_in_eclose_sing";
   396 val arg_into_eclose_sing = thm "arg_into_eclose_sing";
   397 val eclose_induct = thm "eclose_induct";
   398 val eps_induct = thm "eps_induct";
   399 val eclose_least = thm "eclose_least";
   400 val eclose_induct_down = thm "eclose_induct_down";
   401 val Transset_eclose_eq_arg = thm "Transset_eclose_eq_arg";
   402 val mem_eclose_trans = thm "mem_eclose_trans";
   403 val mem_eclose_sing_trans = thm "mem_eclose_sing_trans";
   404 val under_Memrel = thm "under_Memrel";
   405 val under_Memrel_eclose = thm "under_Memrel_eclose";
   406 val wfrec_ssubst = thm "wfrec_ssubst";
   407 val wfrec_eclose_eq = thm "wfrec_eclose_eq";
   408 val wfrec_eclose_eq2 = thm "wfrec_eclose_eq2";
   409 val transrec = thm "transrec";
   410 val def_transrec = thm "def_transrec";
   411 val transrec_type = thm "transrec_type";
   412 val eclose_sing_Ord = thm "eclose_sing_Ord";
   413 val Ord_transrec_type = thm "Ord_transrec_type";
   414 val rank = thm "rank";
   415 val Ord_rank = thm "Ord_rank";
   416 val rank_of_Ord = thm "rank_of_Ord";
   417 val rank_lt = thm "rank_lt";
   418 val eclose_rank_lt = thm "eclose_rank_lt";
   419 val rank_mono = thm "rank_mono";
   420 val rank_Pow = thm "rank_Pow";
   421 val rank_0 = thm "rank_0";
   422 val rank_succ = thm "rank_succ";
   423 val rank_Union = thm "rank_Union";
   424 val rank_eclose = thm "rank_eclose";
   425 val rank_pair1 = thm "rank_pair1";
   426 val rank_pair2 = thm "rank_pair2";
   427 val the_equality_if = thm "the_equality_if";
   428 val rank_apply = thm "rank_apply";
   429 val mem_eclose_subset = thm "mem_eclose_subset";
   430 val eclose_mono = thm "eclose_mono";
   431 val eclose_idem = thm "eclose_idem";
   432 val transrec2_0 = thm "transrec2_0";
   433 val transrec2_succ = thm "transrec2_succ";
   434 val transrec2_Limit = thm "transrec2_Limit";
   435 val recursor_0 = thm "recursor_0";
   436 val recursor_succ = thm "recursor_succ";
   437 val rec_0 = thm "rec_0";
   438 val rec_succ = thm "rec_succ";
   439 val rec_type = thm "rec_type";
   440 *}
   441 
   442 end