src/ZF/WF.thy
changeset 13634 99a593b49b04
parent 13534 ca6debb89d77
child 13780 af7b79271364
equal deleted inserted replaced
13633:b03a36b8d528 13634:99a593b49b04
    45     "wfrec[A](r,a,H) == wfrec(r Int A*A, a, H)"
    45     "wfrec[A](r,a,H) == wfrec(r Int A*A, a, H)"
    46 
    46 
    47 
    47 
    48 subsection{*Well-Founded Relations*}
    48 subsection{*Well-Founded Relations*}
    49 
    49 
    50 (** Equivalences between wf and wf_on **)
    50 subsubsection{*Equivalences between @{term wf} and @{term wf_on}*}
    51 
    51 
    52 lemma wf_imp_wf_on: "wf(r) ==> wf[A](r)"
    52 lemma wf_imp_wf_on: "wf(r) ==> wf[A](r)"
    53 apply (unfold wf_def wf_on_def, clarify) (*needed for blast's efficiency*)
    53 apply (unfold wf_def wf_on_def, clarify) (*needed for blast's efficiency*)
    54 apply blast
    54 apply blast
    55 done
    55 done
    70 by (unfold wf_on_def wf_def, fast)
    70 by (unfold wf_on_def wf_def, fast)
    71 
    71 
    72 lemma wf_subset: "[|wf(s); r<=s|] ==> wf(r)"
    72 lemma wf_subset: "[|wf(s); r<=s|] ==> wf(r)"
    73 by (simp add: wf_def, fast)
    73 by (simp add: wf_def, fast)
    74 
    74 
    75 (** Introduction rules for wf_on **)
    75 subsubsection{*Introduction Rules for @{term wf_on}*}
    76 
    76 
       
    77 text{*If every non-empty subset of @{term A} has an @{term r}-minimal element
       
    78    then we have @{term "wf[A](r)"}.*}
    77 lemma wf_onI:
    79 lemma wf_onI:
    78 (*If every non-empty subset of A has an r-minimal element then wf[A](r).*)
       
    79  assumes prem: "!!Z u. [| Z<=A;  u:Z;  ALL x:Z. EX y:Z. <y,x>:r |] ==> False"
    80  assumes prem: "!!Z u. [| Z<=A;  u:Z;  ALL x:Z. EX y:Z. <y,x>:r |] ==> False"
    80  shows         "wf[A](r)"
    81  shows         "wf[A](r)"
    81 apply (unfold wf_on_def wf_def)
    82 apply (unfold wf_on_def wf_def)
    82 apply (rule equals0I [THEN disjCI, THEN allI])
    83 apply (rule equals0I [THEN disjCI, THEN allI])
    83 apply (rule_tac Z = "Z" in prem, blast+)
    84 apply (rule_tac Z = "Z" in prem, blast+)
    84 done
    85 done
    85 
    86 
    86 (*If r allows well-founded induction over A then wf[A](r)
    87 text{*If @{term r} allows well-founded induction over @{term A}
    87   Premise is equivalent to
    88    then we have @{term "wf[A](r)"}.   Premise is equivalent to
    88   !!B. ALL x:A. (ALL y. <y,x>: r --> y:B) --> x:B ==> A<=B  *)
    89   @{term "!!B. ALL x:A. (ALL y. <y,x>: r --> y:B) --> x:B ==> A<=B"} *}
    89 lemma wf_onI2:
    90 lemma wf_onI2:
    90  assumes prem: "!!y B. [| ALL x:A. (ALL y:A. <y,x>:r --> y:B) --> x:B;   y:A |]
    91  assumes prem: "!!y B. [| ALL x:A. (ALL y:A. <y,x>:r --> y:B) --> x:B;   y:A |]
    91                        ==> y:B"
    92                        ==> y:B"
    92  shows         "wf[A](r)"
    93  shows         "wf[A](r)"
    93 apply (rule wf_onI)
    94 apply (rule wf_onI)
    95   prefer 3 apply blast 
    96   prefer 3 apply blast 
    96  apply fast+
    97  apply fast+
    97 done
    98 done
    98 
    99 
    99 
   100 
   100 (** Well-founded Induction **)
   101 subsubsection{*Well-founded Induction*}
   101 
   102 
   102 (*Consider the least z in domain(r) such that P(z) does not hold...*)
   103 text{*Consider the least @{term z} in @{term "domain(r)"} such that
       
   104   @{term "P(z)"} does not hold...*}
   103 lemma wf_induct [induct set: wf]:
   105 lemma wf_induct [induct set: wf]:
   104     "[| wf(r);
   106     "[| wf(r);
   105         !!x.[| ALL y. <y,x>: r --> P(y) |] ==> P(x)
   107         !!x.[| ALL y. <y,x>: r --> P(y) |] ==> P(x) |]  
   106      |]  ==>  P(a)"
   108      ==> P(a)"
   107 apply (unfold wf_def) 
   109 apply (unfold wf_def) 
   108 apply (erule_tac x = "{z : domain(r). ~ P(z)}" in allE)
   110 apply (erule_tac x = "{z : domain(r). ~ P(z)}" in allE)
   109 apply blast 
   111 apply blast 
   110 done
   112 done
   111 
   113 
   112 lemmas wf_induct_rule = wf_induct [rule_format, induct set: wf]
   114 lemmas wf_induct_rule = wf_induct [rule_format, induct set: wf]
   113 
   115 
   114 (*The form of this rule is designed to match wfI*)
   116 text{*The form of this rule is designed to match @{text wfI}*}
   115 lemma wf_induct2:
   117 lemma wf_induct2:
   116     "[| wf(r);  a:A;  field(r)<=A;
   118     "[| wf(r);  a:A;  field(r)<=A;
   117         !!x.[| x: A;  ALL y. <y,x>: r --> P(y) |] ==> P(x) |]
   119         !!x.[| x: A;  ALL y. <y,x>: r --> P(y) |] ==> P(x) |]
   118      ==>  P(a)"
   120      ==>  P(a)"
   119 apply (erule_tac P="a:A" in rev_mp)
   121 apply (erule_tac P="a:A" in rev_mp)
   134 
   136 
   135 lemmas wf_on_induct_rule =
   137 lemmas wf_on_induct_rule =
   136   wf_on_induct [rule_format, consumes 2, induct set: wf_on]
   138   wf_on_induct [rule_format, consumes 2, induct set: wf_on]
   137 
   139 
   138 
   140 
   139 (*If r allows well-founded induction then wf(r)*)
   141 text{*If @{term r} allows well-founded induction 
       
   142    then we have @{term "wf(r)"}.*}
   140 lemma wfI:
   143 lemma wfI:
   141     "[| field(r)<=A;
   144     "[| field(r)<=A;
   142         !!y B. [| ALL x:A. (ALL y:A. <y,x>:r --> y:B) --> x:B;  y:A|]
   145         !!y B. [| ALL x:A. (ALL y:A. <y,x>:r --> y:B) --> x:B;  y:A|]
   143                ==> y:B |]
   146                ==> y:B |]
   144      ==>  wf(r)"
   147      ==>  wf(r)"
   183 apply (erule_tac a=a in wf_on_induct, assumption, blast)
   186 apply (erule_tac a=a in wf_on_induct, assumption, blast)
   184 done
   187 done
   185 
   188 
   186 
   189 
   187 
   190 
   188 
   191 text{*transitive closure of a WF relation is WF provided 
   189 (*transitive closure of a WF relation is WF provided A is downwards closed*)
   192   @{term A} is downward closed*}
   190 lemma wf_on_trancl:
   193 lemma wf_on_trancl:
   191     "[| wf[A](r);  r-``A <= A |] ==> wf[A](r^+)"
   194     "[| wf[A](r);  r-``A <= A |] ==> wf[A](r^+)"
   192 apply (rule wf_onI2)
   195 apply (rule wf_onI2)
   193 apply (frule bspec [THEN mp], assumption+)
   196 apply (frule bspec [THEN mp], assumption+)
   194 apply (erule_tac a = "y" in wf_on_induct, assumption)
   197 apply (erule_tac a = "y" in wf_on_induct, assumption)
   202  apply blast 
   205  apply blast 
   203 apply (rule trancl_type [THEN field_rel_subset])
   206 apply (rule trancl_type [THEN field_rel_subset])
   204 done
   207 done
   205 
   208 
   206 
   209 
   207 
   210 text{*@{term "r-``{a}"} is the set of everything under @{term a} in @{term r}*}
   208 (** r-``{a} is the set of everything under a in r **)
       
   209 
   211 
   210 lemmas underI = vimage_singleton_iff [THEN iffD2, standard]
   212 lemmas underI = vimage_singleton_iff [THEN iffD2, standard]
   211 lemmas underD = vimage_singleton_iff [THEN iffD1, standard]
   213 lemmas underD = vimage_singleton_iff [THEN iffD1, standard]
   212 
   214 
   213 (** is_recfun **)
   215 
       
   216 subsection{*The Predicate @{term is_recfun}*}
   214 
   217 
   215 lemma is_recfun_type: "is_recfun(r,a,H,f) ==> f: r-``{a} -> range(f)"
   218 lemma is_recfun_type: "is_recfun(r,a,H,f) ==> f: r-``{a} -> range(f)"
   216 apply (unfold is_recfun_def)
   219 apply (unfold is_recfun_def)
   217 apply (erule ssubst)
   220 apply (erule ssubst)
   218 apply (rule lamI [THEN rangeI, THEN lam_type], assumption)
   221 apply (rule lamI [THEN rangeI, THEN lam_type], assumption)
   279 apply (rule_tac a=a in wf_induct, assumption)
   282 apply (rule_tac a=a in wf_induct, assumption)
   280 apply (rename_tac a1) 
   283 apply (rename_tac a1) 
   281 apply (rule_tac f = "lam y: r-``{a1}. wftrec (r,y,H)" in is_the_recfun)
   284 apply (rule_tac f = "lam y: r-``{a1}. wftrec (r,y,H)" in is_the_recfun)
   282   apply typecheck
   285   apply typecheck
   283 apply (unfold is_recfun_def wftrec_def)
   286 apply (unfold is_recfun_def wftrec_def)
   284 (*Applying the substitution: must keep the quantified assumption!!*)
   287   --{*Applying the substitution: must keep the quantified assumption!*}
   285 apply (rule lam_cong [OF refl]) 
   288 apply (rule lam_cong [OF refl]) 
   286 apply (drule underD) 
   289 apply (drule underD) 
   287 apply (fold is_recfun_def)
   290 apply (fold is_recfun_def)
   288 apply (rule_tac t = "%z. H(?x,z)" in subst_context)
   291 apply (rule_tac t = "%z. H(?x,z)" in subst_context)
   289 apply (rule fun_extension)
   292 apply (rule fun_extension)
   314 apply (unfold wftrec_def)
   317 apply (unfold wftrec_def)
   315 apply (subst unfold_the_recfun [unfolded is_recfun_def])
   318 apply (subst unfold_the_recfun [unfolded is_recfun_def])
   316 apply (simp_all add: vimage_singleton_iff [THEN iff_sym] the_recfun_cut)
   319 apply (simp_all add: vimage_singleton_iff [THEN iff_sym] the_recfun_cut)
   317 done
   320 done
   318 
   321 
   319 (** Removal of the premise trans(r) **)
   322 
       
   323 subsubsection{*Removal of the Premise @{term "trans(r)"}*}
   320 
   324 
   321 (*NOT SUITABLE FOR REWRITING: it is recursive!*)
   325 (*NOT SUITABLE FOR REWRITING: it is recursive!*)
   322 lemma wfrec:
   326 lemma wfrec:
   323     "wf(r) ==> wfrec(r,a,H) = H(a, lam x:r-``{a}. wfrec(r,x,H))"
   327     "wf(r) ==> wfrec(r,a,H) = H(a, lam x:r-``{a}. wfrec(r,x,H))"
   324 apply (unfold wfrec_def) 
   328 apply (unfold wfrec_def) 
   353 apply (unfold wf_on_def wfrec_on_def)
   357 apply (unfold wf_on_def wfrec_on_def)
   354 apply (erule wfrec [THEN trans])
   358 apply (erule wfrec [THEN trans])
   355 apply (simp add: vimage_Int_square cons_subset_iff)
   359 apply (simp add: vimage_Int_square cons_subset_iff)
   356 done
   360 done
   357 
   361 
   358 (*Minimal-element characterization of well-foundedness*)
   362 text{*Minimal-element characterization of well-foundedness*}
   359 lemma wf_eq_minimal:
   363 lemma wf_eq_minimal:
   360      "wf(r) <-> (ALL Q x. x:Q --> (EX z:Q. ALL y. <y,z>:r --> y~:Q))"
   364      "wf(r) <-> (ALL Q x. x:Q --> (EX z:Q. ALL y. <y,z>:r --> y~:Q))"
   361 apply (unfold wf_def, blast)
   365 by (unfold wf_def, blast)
   362 done
   366 
   363 
   367 
   364 ML
   368 ML
   365 {*
   369 {*
   366 val wf_def = thm "wf_def";
   370 val wf_def = thm "wf_def";
   367 val wf_on_def = thm "wf_on_def";
   371 val wf_on_def = thm "wf_on_def";