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