src/ZF/Epsilon.thy
changeset 13164 dfc399c684e4
parent 6070 032babd0120b
child 13175 81082cfa5618
     1.1 --- a/src/ZF/Epsilon.thy	Sat May 18 20:08:17 2002 +0200
     1.2 +++ b/src/ZF/Epsilon.thy	Sat May 18 22:22:23 2002 +0200
     1.3 @@ -6,18 +6,19 @@
     1.4  Epsilon induction and recursion
     1.5  *)
     1.6  
     1.7 -Epsilon = Nat + mono +
     1.8 +theory Epsilon = Nat + mono:
     1.9 +
    1.10  constdefs
    1.11 -  eclose    :: i=>i
    1.12 +  eclose    :: "i=>i"
    1.13      "eclose(A) == UN n:nat. nat_rec(n, A, %m r. Union(r))"
    1.14  
    1.15 -  transrec  :: [i, [i,i]=>i] =>i
    1.16 +  transrec  :: "[i, [i,i]=>i] =>i"
    1.17      "transrec(a,H) == wfrec(Memrel(eclose({a})), a, H)"
    1.18   
    1.19 -  rank      :: i=>i
    1.20 +  rank      :: "i=>i"
    1.21      "rank(a) == transrec(a, %x f. UN y:x. succ(f`y))"
    1.22  
    1.23 -  transrec2 :: [i, i, [i,i]=>i] =>i
    1.24 +  transrec2 :: "[i, i, [i,i]=>i] =>i"
    1.25      "transrec2(k, a, b) ==                     
    1.26         transrec(k, 
    1.27                  %i r. if(i=0, a, 
    1.28 @@ -25,10 +26,394 @@
    1.29                             b(THE j. i=succ(j), r`(THE j. i=succ(j))),   
    1.30                             UN j<i. r`j)))"
    1.31  
    1.32 -    recursor  :: [i, [i,i]=>i, i]=>i
    1.33 -     "recursor(a,b,k) ==  transrec(k, %n f. nat_case(a, %m. b(m, f`m), n))"
    1.34 +  recursor  :: "[i, [i,i]=>i, i]=>i"
    1.35 +    "recursor(a,b,k) ==  transrec(k, %n f. nat_case(a, %m. b(m, f`m), n))"
    1.36 +
    1.37 +  rec  :: "[i, i, [i,i]=>i]=>i"
    1.38 +    "rec(k,a,b) == recursor(a,b,k)"
    1.39 +
    1.40 +
    1.41 +(*** Basic closure properties ***)
    1.42 +
    1.43 +lemma arg_subset_eclose: "A <= eclose(A)"
    1.44 +apply (unfold eclose_def)
    1.45 +apply (rule nat_rec_0 [THEN equalityD2, THEN subset_trans])
    1.46 +apply (rule nat_0I [THEN UN_upper])
    1.47 +done
    1.48 +
    1.49 +lemmas arg_into_eclose = arg_subset_eclose [THEN subsetD, standard]
    1.50 +
    1.51 +lemma Transset_eclose: "Transset(eclose(A))"
    1.52 +apply (unfold eclose_def Transset_def)
    1.53 +apply (rule subsetI [THEN ballI])
    1.54 +apply (erule UN_E)
    1.55 +apply (rule nat_succI [THEN UN_I], assumption)
    1.56 +apply (erule nat_rec_succ [THEN ssubst])
    1.57 +apply (erule UnionI, assumption)
    1.58 +done
    1.59 +
    1.60 +(* x : eclose(A) ==> x <= eclose(A) *)
    1.61 +lemmas eclose_subset =  
    1.62 +       Transset_eclose [unfolded Transset_def, THEN bspec, standard]
    1.63 +
    1.64 +(* [| A : eclose(B); c : A |] ==> c : eclose(B) *)
    1.65 +lemmas ecloseD = eclose_subset [THEN subsetD, standard]
    1.66 +
    1.67 +lemmas arg_in_eclose_sing = arg_subset_eclose [THEN singleton_subsetD]
    1.68 +lemmas arg_into_eclose_sing = arg_in_eclose_sing [THEN ecloseD, standard]
    1.69 +
    1.70 +(* This is epsilon-induction for eclose(A); see also eclose_induct_down...
    1.71 +   [| a: eclose(A);  !!x. [| x: eclose(A); ALL y:x. P(y) |] ==> P(x) 
    1.72 +   |] ==> P(a) 
    1.73 +*)
    1.74 +lemmas eclose_induct = Transset_induct [OF _ Transset_eclose]
    1.75 +
    1.76 +(*Epsilon induction*)
    1.77 +lemma eps_induct:
    1.78 +    "[| !!x. ALL y:x. P(y) ==> P(x) |]  ==>  P(a)"
    1.79 +by (rule arg_in_eclose_sing [THEN eclose_induct], blast) 
    1.80 +
    1.81 +
    1.82 +(*** Leastness of eclose ***)
    1.83 +
    1.84 +(** eclose(A) is the least transitive set including A as a subset. **)
    1.85 +
    1.86 +lemma eclose_least_lemma: 
    1.87 +    "[| Transset(X);  A<=X;  n: nat |] ==> nat_rec(n, A, %m r. Union(r)) <= X"
    1.88 +apply (unfold Transset_def)
    1.89 +apply (erule nat_induct) 
    1.90 +apply (simp add: nat_rec_0)
    1.91 +apply (simp add: nat_rec_succ, blast)
    1.92 +done
    1.93 +
    1.94 +lemma eclose_least: 
    1.95 +     "[| Transset(X);  A<=X |] ==> eclose(A) <= X"
    1.96 +apply (unfold eclose_def)
    1.97 +apply (rule eclose_least_lemma [THEN UN_least], assumption+)
    1.98 +done
    1.99 +
   1.100 +(*COMPLETELY DIFFERENT induction principle from eclose_induct!!*)
   1.101 +lemma eclose_induct_down: 
   1.102 +    "[| a: eclose(b);                                            
   1.103 +        !!y.   [| y: b |] ==> P(y);                              
   1.104 +        !!y z. [| y: eclose(b);  P(y);  z: y |] ==> P(z)         
   1.105 +     |] ==> P(a)"
   1.106 +apply (rule eclose_least [THEN subsetD, THEN CollectD2, of "eclose(b)"])
   1.107 +  prefer 3 apply assumption
   1.108 + apply (unfold Transset_def) 
   1.109 + apply (blast intro: ecloseD)
   1.110 +apply (blast intro: arg_subset_eclose [THEN subsetD])
   1.111 +done
   1.112 +
   1.113 +lemma Transset_eclose_eq_arg: "Transset(X) ==> eclose(X) = X"
   1.114 +apply (erule equalityI [OF eclose_least arg_subset_eclose])
   1.115 +apply (rule subset_refl)
   1.116 +done
   1.117 +
   1.118 +
   1.119 +(*** Epsilon recursion ***)
   1.120 +
   1.121 +(*Unused...*)
   1.122 +lemma mem_eclose_trans: "[| A: eclose(B);  B: eclose(C) |] ==> A: eclose(C)"
   1.123 +by (rule eclose_least [OF Transset_eclose eclose_subset, THEN subsetD], 
   1.124 +    assumption+)
   1.125 +
   1.126 +(*Variant of the previous lemma in a useable form for the sequel*)
   1.127 +lemma mem_eclose_sing_trans:
   1.128 +     "[| A: eclose({B});  B: eclose({C}) |] ==> A: eclose({C})"
   1.129 +by (rule eclose_least [OF Transset_eclose singleton_subsetI, THEN subsetD], 
   1.130 +    assumption+)
   1.131 +
   1.132 +lemma under_Memrel: "[| Transset(i);  j:i |] ==> Memrel(i)-``{j} = j"
   1.133 +by (unfold Transset_def, blast)
   1.134 +
   1.135 +(* j : eclose(A) ==> Memrel(eclose(A)) -`` j = j *)
   1.136 +lemmas under_Memrel_eclose = Transset_eclose [THEN under_Memrel, standard]
   1.137 +
   1.138 +lemmas wfrec_ssubst = wf_Memrel [THEN wfrec, THEN ssubst]
   1.139 +
   1.140 +lemma wfrec_eclose_eq:
   1.141 +    "[| k:eclose({j});  j:eclose({i}) |] ==>  
   1.142 +     wfrec(Memrel(eclose({i})), k, H) = wfrec(Memrel(eclose({j})), k, H)"
   1.143 +apply (erule eclose_induct)
   1.144 +apply (rule wfrec_ssubst)
   1.145 +apply (rule wfrec_ssubst)
   1.146 +apply (simp add: under_Memrel_eclose mem_eclose_sing_trans [of _ j i])
   1.147 +done
   1.148 +
   1.149 +lemma wfrec_eclose_eq2: 
   1.150 +    "k: i ==> wfrec(Memrel(eclose({i})),k,H) = wfrec(Memrel(eclose({k})),k,H)"
   1.151 +apply (rule arg_in_eclose_sing [THEN wfrec_eclose_eq])
   1.152 +apply (erule arg_into_eclose_sing)
   1.153 +done
   1.154 +
   1.155 +lemma transrec: "transrec(a,H) = H(a, lam x:a. transrec(x,H))"
   1.156 +apply (unfold transrec_def)
   1.157 +apply (rule wfrec_ssubst)
   1.158 +apply (simp add: wfrec_eclose_eq2 arg_in_eclose_sing under_Memrel_eclose)
   1.159 +done
   1.160 +
   1.161 +(*Avoids explosions in proofs; resolve it with a meta-level definition.*)
   1.162 +lemma def_transrec:
   1.163 +    "[| !!x. f(x)==transrec(x,H) |] ==> f(a) = H(a, lam x:a. f(x))"
   1.164 +apply simp
   1.165 +apply (rule transrec)
   1.166 +done
   1.167 +
   1.168 +lemma transrec_type:
   1.169 +    "[| !!x u. [| x:eclose({a});  u: Pi(x,B) |] ==> H(x,u) : B(x) |]
   1.170 +     ==> transrec(a,H) : B(a)"
   1.171 +apply (rule_tac i = "a" in arg_in_eclose_sing [THEN eclose_induct])
   1.172 +apply (subst transrec)
   1.173 +apply (simp add: lam_type) 
   1.174 +done
   1.175 +
   1.176 +lemma eclose_sing_Ord: "Ord(i) ==> eclose({i}) <= succ(i)"
   1.177 +apply (erule Ord_is_Transset [THEN Transset_succ, THEN eclose_least])
   1.178 +apply (rule succI1 [THEN singleton_subsetI])
   1.179 +done
   1.180 +
   1.181 +lemma Ord_transrec_type:
   1.182 +  assumes jini: "j: i"
   1.183 +      and ordi: "Ord(i)"
   1.184 +      and minor: " !!x u. [| x: i;  u: Pi(x,B) |] ==> H(x,u) : B(x)"
   1.185 +  shows "transrec(j,H) : B(j)"
   1.186 +apply (rule transrec_type)
   1.187 +apply (insert jini ordi)
   1.188 +apply (blast intro!: minor
   1.189 +             intro: Ord_trans 
   1.190 +             dest: Ord_in_Ord [THEN eclose_sing_Ord, THEN subsetD])
   1.191 +done
   1.192 +
   1.193 +(*** Rank ***)
   1.194 +
   1.195 +(*NOT SUITABLE FOR REWRITING -- RECURSIVE!*)
   1.196 +lemma rank: "rank(a) = (UN y:a. succ(rank(y)))"
   1.197 +by (subst rank_def [THEN def_transrec], simp)
   1.198 +
   1.199 +lemma Ord_rank [simp]: "Ord(rank(a))"
   1.200 +apply (rule_tac a="a" in eps_induct) 
   1.201 +apply (subst rank)
   1.202 +apply (rule Ord_succ [THEN Ord_UN])
   1.203 +apply (erule bspec, assumption)
   1.204 +done
   1.205 +
   1.206 +lemma rank_of_Ord: "Ord(i) ==> rank(i) = i"
   1.207 +apply (erule trans_induct)
   1.208 +apply (subst rank)
   1.209 +apply (simp add: Ord_equality)
   1.210 +done
   1.211 +
   1.212 +lemma rank_lt: "a:b ==> rank(a) < rank(b)"
   1.213 +apply (rule_tac a1 = "b" in rank [THEN ssubst])
   1.214 +apply (erule UN_I [THEN ltI])
   1.215 +apply (rule_tac [2] Ord_UN, auto)
   1.216 +done
   1.217 +
   1.218 +lemma eclose_rank_lt: "a: eclose(b) ==> rank(a) < rank(b)"
   1.219 +apply (erule eclose_induct_down)
   1.220 +apply (erule rank_lt)
   1.221 +apply (erule rank_lt [THEN lt_trans], assumption)
   1.222 +done
   1.223  
   1.224 -    rec  :: [i, i, [i,i]=>i]=>i
   1.225 -     "rec(k,a,b) ==  recursor(a,b,k)"
   1.226 +lemma rank_mono: "a<=b ==> rank(a) le rank(b)"
   1.227 +apply (rule subset_imp_le)
   1.228 +apply (subst rank)
   1.229 +apply (subst rank, auto)
   1.230 +done
   1.231 +
   1.232 +lemma rank_Pow: "rank(Pow(a)) = succ(rank(a))"
   1.233 +apply (rule rank [THEN trans])
   1.234 +apply (rule le_anti_sym)
   1.235 +apply (rule_tac [2] UN_upper_le)
   1.236 +apply (rule UN_least_le)
   1.237 +apply (auto intro: rank_mono simp add: Ord_UN)
   1.238 +done
   1.239 +
   1.240 +lemma rank_0 [simp]: "rank(0) = 0"
   1.241 +by (rule rank [THEN trans], blast)
   1.242 +
   1.243 +lemma rank_succ [simp]: "rank(succ(x)) = succ(rank(x))"
   1.244 +apply (rule rank [THEN trans])
   1.245 +apply (rule equalityI [OF UN_least succI1 [THEN UN_upper]])
   1.246 +apply (erule succE, blast)
   1.247 +apply (erule rank_lt [THEN leI, THEN succ_leI, THEN le_imp_subset])
   1.248 +done
   1.249 +
   1.250 +lemma rank_Union: "rank(Union(A)) = (UN x:A. rank(x))"
   1.251 +apply (rule equalityI)
   1.252 +apply (rule_tac [2] rank_mono [THEN le_imp_subset, THEN UN_least])
   1.253 +apply (erule_tac [2] Union_upper)
   1.254 +apply (subst rank)
   1.255 +apply (rule UN_least)
   1.256 +apply (erule UnionE)
   1.257 +apply (rule subset_trans)
   1.258 +apply (erule_tac [2] RepFunI [THEN Union_upper])
   1.259 +apply (erule rank_lt [THEN succ_leI, THEN le_imp_subset])
   1.260 +done
   1.261 +
   1.262 +lemma rank_eclose: "rank(eclose(a)) = rank(a)"
   1.263 +apply (rule le_anti_sym)
   1.264 +apply (rule_tac [2] arg_subset_eclose [THEN rank_mono])
   1.265 +apply (rule_tac a1 = "eclose (a) " in rank [THEN ssubst])
   1.266 +apply (rule Ord_rank [THEN UN_least_le])
   1.267 +apply (erule eclose_rank_lt [THEN succ_leI])
   1.268 +done
   1.269 +
   1.270 +lemma rank_pair1: "rank(a) < rank(<a,b>)"
   1.271 +apply (unfold Pair_def)
   1.272 +apply (rule consI1 [THEN rank_lt, THEN lt_trans])
   1.273 +apply (rule consI1 [THEN consI2, THEN rank_lt])
   1.274 +done
   1.275 +
   1.276 +lemma rank_pair2: "rank(b) < rank(<a,b>)"
   1.277 +apply (unfold Pair_def)
   1.278 +apply (rule consI1 [THEN consI2, THEN rank_lt, THEN lt_trans])
   1.279 +apply (rule consI1 [THEN consI2, THEN rank_lt])
   1.280 +done
   1.281 +
   1.282 +(*Not clear how to remove the P(a) condition, since the "then" part
   1.283 +  must refer to "a"*)
   1.284 +lemma the_equality_if:
   1.285 +     "P(a) ==> (THE x. P(x)) = (if (EX!x. P(x)) then a else 0)"
   1.286 +by (simp add: the_0 the_equality2)
   1.287 +
   1.288 +(*The premise is needed not just to fix i but to ensure f~=0*)
   1.289 +lemma rank_apply: "i : domain(f) ==> rank(f`i) < rank(f)"
   1.290 +apply (unfold apply_def, clarify)
   1.291 +apply (subgoal_tac "rank (y) < rank (f) ")
   1.292 +prefer 2 apply (blast intro: lt_trans rank_lt rank_pair2)
   1.293 +apply (subgoal_tac "0 < rank (f) ")
   1.294 +apply (erule_tac [2] Ord_rank [THEN Ord_0_le, THEN lt_trans1])
   1.295 +apply (simp add: the_equality_if)
   1.296 +done
   1.297 +
   1.298 +
   1.299 +(*** Corollaries of leastness ***)
   1.300 +
   1.301 +lemma mem_eclose_subset: "A:B ==> eclose(A)<=eclose(B)"
   1.302 +apply (rule Transset_eclose [THEN eclose_least])
   1.303 +apply (erule arg_into_eclose [THEN eclose_subset])
   1.304 +done
   1.305 +
   1.306 +lemma eclose_mono: "A<=B ==> eclose(A) <= eclose(B)"
   1.307 +apply (rule Transset_eclose [THEN eclose_least])
   1.308 +apply (erule subset_trans)
   1.309 +apply (rule arg_subset_eclose)
   1.310 +done
   1.311 +
   1.312 +(** Idempotence of eclose **)
   1.313 +
   1.314 +lemma eclose_idem: "eclose(eclose(A)) = eclose(A)"
   1.315 +apply (rule equalityI)
   1.316 +apply (rule eclose_least [OF Transset_eclose subset_refl])
   1.317 +apply (rule arg_subset_eclose)
   1.318 +done
   1.319 +
   1.320 +(** Transfinite recursion for definitions based on the 
   1.321 +    three cases of ordinals **)
   1.322 +
   1.323 +lemma transrec2_0 [simp]: "transrec2(0,a,b) = a"
   1.324 +by (rule transrec2_def [THEN def_transrec, THEN trans], simp)
   1.325 +
   1.326 +lemma transrec2_succ [simp]: "transrec2(succ(i),a,b) = b(i, transrec2(i,a,b))"
   1.327 +apply (rule transrec2_def [THEN def_transrec, THEN trans])
   1.328 +apply (simp add: the_equality if_P)
   1.329 +done
   1.330 +
   1.331 +lemma transrec2_Limit:
   1.332 +     "Limit(i) ==> transrec2(i,a,b) = (UN j<i. transrec2(j,a,b))"
   1.333 +apply (rule transrec2_def [THEN def_transrec, THEN trans], simp)
   1.334 +apply (blast dest!: Limit_has_0 elim!: succ_LimitE)
   1.335 +done
   1.336 +
   1.337 +
   1.338 +(** recursor -- better than nat_rec; the succ case has no type requirement! **)
   1.339 +
   1.340 +(*NOT suitable for rewriting*)
   1.341 +lemmas recursor_lemma = recursor_def [THEN def_transrec, THEN trans]
   1.342 +
   1.343 +lemma recursor_0: "recursor(a,b,0) = a"
   1.344 +by (rule nat_case_0 [THEN recursor_lemma])
   1.345 +
   1.346 +lemma recursor_succ: "recursor(a,b,succ(m)) = b(m, recursor(a,b,m))"
   1.347 +by (rule recursor_lemma, simp)
   1.348 +
   1.349 +
   1.350 +(** rec: old version for compatibility **)
   1.351 +
   1.352 +lemma rec_0 [simp]: "rec(0,a,b) = a"
   1.353 +apply (unfold rec_def)
   1.354 +apply (rule recursor_0)
   1.355 +done
   1.356 +
   1.357 +lemma rec_succ [simp]: "rec(succ(m),a,b) = b(m, rec(m,a,b))"
   1.358 +apply (unfold rec_def)
   1.359 +apply (rule recursor_succ)
   1.360 +done
   1.361 +
   1.362 +lemma rec_type:
   1.363 +    "[| n: nat;   
   1.364 +        a: C(0);   
   1.365 +        !!m z. [| m: nat;  z: C(m) |] ==> b(m,z): C(succ(m)) |]
   1.366 +     ==> rec(n,a,b) : C(n)"
   1.367 +apply (erule nat_induct, auto)
   1.368 +done
   1.369 +
   1.370 +ML
   1.371 +{*
   1.372 +val arg_subset_eclose = thm "arg_subset_eclose";
   1.373 +val arg_into_eclose = thm "arg_into_eclose";
   1.374 +val Transset_eclose = thm "Transset_eclose";
   1.375 +val eclose_subset = thm "eclose_subset";
   1.376 +val ecloseD = thm "ecloseD";
   1.377 +val arg_in_eclose_sing = thm "arg_in_eclose_sing";
   1.378 +val arg_into_eclose_sing = thm "arg_into_eclose_sing";
   1.379 +val eclose_induct = thm "eclose_induct";
   1.380 +val eps_induct = thm "eps_induct";
   1.381 +val eclose_least_lemma = thm "eclose_least_lemma";
   1.382 +val eclose_least = thm "eclose_least";
   1.383 +val eclose_induct_down = thm "eclose_induct_down";
   1.384 +val Transset_eclose_eq_arg = thm "Transset_eclose_eq_arg";
   1.385 +val mem_eclose_trans = thm "mem_eclose_trans";
   1.386 +val mem_eclose_sing_trans = thm "mem_eclose_sing_trans";
   1.387 +val under_Memrel = thm "under_Memrel";
   1.388 +val under_Memrel_eclose = thm "under_Memrel_eclose";
   1.389 +val wfrec_ssubst = thm "wfrec_ssubst";
   1.390 +val wfrec_eclose_eq = thm "wfrec_eclose_eq";
   1.391 +val wfrec_eclose_eq2 = thm "wfrec_eclose_eq2";
   1.392 +val transrec = thm "transrec";
   1.393 +val def_transrec = thm "def_transrec";
   1.394 +val transrec_type = thm "transrec_type";
   1.395 +val eclose_sing_Ord = thm "eclose_sing_Ord";
   1.396 +val Ord_transrec_type = thm "Ord_transrec_type";
   1.397 +val rank = thm "rank";
   1.398 +val Ord_rank = thm "Ord_rank";
   1.399 +val rank_of_Ord = thm "rank_of_Ord";
   1.400 +val rank_lt = thm "rank_lt";
   1.401 +val eclose_rank_lt = thm "eclose_rank_lt";
   1.402 +val rank_mono = thm "rank_mono";
   1.403 +val rank_Pow = thm "rank_Pow";
   1.404 +val rank_0 = thm "rank_0";
   1.405 +val rank_succ = thm "rank_succ";
   1.406 +val rank_Union = thm "rank_Union";
   1.407 +val rank_eclose = thm "rank_eclose";
   1.408 +val rank_pair1 = thm "rank_pair1";
   1.409 +val rank_pair2 = thm "rank_pair2";
   1.410 +val the_equality_if = thm "the_equality_if";
   1.411 +val rank_apply = thm "rank_apply";
   1.412 +val mem_eclose_subset = thm "mem_eclose_subset";
   1.413 +val eclose_mono = thm "eclose_mono";
   1.414 +val eclose_idem = thm "eclose_idem";
   1.415 +val transrec2_0 = thm "transrec2_0";
   1.416 +val transrec2_succ = thm "transrec2_succ";
   1.417 +val transrec2_Limit = thm "transrec2_Limit";
   1.418 +val recursor_lemma = thm "recursor_lemma";
   1.419 +val recursor_0 = thm "recursor_0";
   1.420 +val recursor_succ = thm "recursor_succ";
   1.421 +val rec_0 = thm "rec_0";
   1.422 +val rec_succ = thm "rec_succ";
   1.423 +val rec_type = thm "rec_type";
   1.424 +*}
   1.425  
   1.426  end