src/HOL/WF.ML
changeset 1475 7f5a4cd08209
parent 1465 5d7a7e439cec
child 1485 240cc98b94a7
     1.1 --- a/src/HOL/WF.ML	Mon Feb 05 14:44:09 1996 +0100
     1.2 +++ b/src/HOL/WF.ML	Mon Feb 05 21:27:16 1996 +0100
     1.3 @@ -1,9 +1,9 @@
     1.4 -(*  Title:      HOL/WF.ML
     1.5 +(*  Title:      HOL/wf.ML
     1.6      ID:         $Id$
     1.7 -    Author:     Tobias Nipkow
     1.8 -    Copyright   1992  University of Cambridge
     1.9 +    Author:     Tobias Nipkow, with minor changes by Konrad Slind
    1.10 +    Copyright   1992  University of Cambridge/1995 TU Munich
    1.11  
    1.12 -For WF.thy.  Well-founded Recursion
    1.13 +For WF.thy.  Wellfoundedness, induction, and  recursion
    1.14  *)
    1.15  
    1.16  open WF;
    1.17 @@ -48,7 +48,7 @@
    1.18  by (REPEAT (resolve_tac prems 1));
    1.19  qed "wf_anti_refl";
    1.20  
    1.21 -(*transitive closure of a WF relation is WF!*)
    1.22 +(*transitive closure of a wf relation is wf! *)
    1.23  val [prem] = goal WF.thy "wf(r) ==> wf(r^+)";
    1.24  by (rewtac wf_def);
    1.25  by (strip_tac 1);
    1.26 @@ -69,41 +69,32 @@
    1.27    H_cong to expose the equality*)
    1.28  goalw WF.thy [cut_def]
    1.29      "(cut f r x = cut g r x) = (!y. (y,x):r --> f(y)=g(y))";
    1.30 -by(simp_tac (!simpset addsimps [expand_fun_eq]
    1.31 -                        setloop (split_tac [expand_if])) 1);
    1.32 -qed "cut_cut_eq";
    1.33 +by(simp_tac (HOL_ss addsimps [expand_fun_eq]
    1.34 +                    setloop (split_tac [expand_if])) 1);
    1.35 +qed "cuts_eq";
    1.36  
    1.37  goalw WF.thy [cut_def] "!!x. (x,a):r ==> (cut f r a)(x) = f(x)";
    1.38 -by(Asm_simp_tac 1);
    1.39 +by(asm_simp_tac HOL_ss 1);
    1.40  qed "cut_apply";
    1.41  
    1.42 -
    1.43  (*** is_recfun ***)
    1.44  
    1.45  goalw WF.thy [is_recfun_def,cut_def]
    1.46 -    "!!f. [| is_recfun r a H f;  ~(b,a):r |] ==> f(b) = (@z.True)";
    1.47 +    "!!f. [| is_recfun r H a f;  ~(b,a):r |] ==> f(b) = (@z.True)";
    1.48  by (etac ssubst 1);
    1.49 -by(Asm_simp_tac 1);
    1.50 +by(asm_simp_tac HOL_ss 1);
    1.51  qed "is_recfun_undef";
    1.52  
    1.53 -(*eresolve_tac transD solves (a,b):r using transitivity AT MOST ONCE
    1.54 -  mp amd allE  instantiate induction hypotheses*)
    1.55 -fun indhyp_tac hyps =
    1.56 -    ares_tac (TrueI::hyps) ORELSE' 
    1.57 -    (cut_facts_tac hyps THEN'
    1.58 -       DEPTH_SOLVE_1 o (ares_tac [TrueI] ORELSE'
    1.59 -                        eresolve_tac [transD, mp, allE]));
    1.60 -
    1.61  (*** NOTE! some simplifications need a different finish_tac!! ***)
    1.62  fun indhyp_tac hyps =
    1.63      resolve_tac (TrueI::refl::hyps) ORELSE' 
    1.64      (cut_facts_tac hyps THEN'
    1.65         DEPTH_SOLVE_1 o (ares_tac [TrueI] ORELSE'
    1.66                          eresolve_tac [transD, mp, allE]));
    1.67 -val wf_super_ss = !simpset setsolver indhyp_tac;
    1.68 +val wf_super_ss = HOL_ss setsolver indhyp_tac;
    1.69  
    1.70  val prems = goalw WF.thy [is_recfun_def,cut_def]
    1.71 -    "[| wf(r);  trans(r);  is_recfun r a H f;  is_recfun r b H g |] ==> \
    1.72 +    "[| wf(r);  trans(r);  is_recfun r H a f;  is_recfun r H b g |] ==> \
    1.73      \ (x,a):r --> (x,b):r --> f(x)=g(x)";
    1.74  by (cut_facts_tac prems 1);
    1.75  by (etac wf_induct 1);
    1.76 @@ -115,7 +106,7 @@
    1.77  
    1.78  val prems as [wfr,transr,recfa,recgb,_] = goalw WF.thy [cut_def]
    1.79      "[| wf(r);  trans(r); \
    1.80 -\       is_recfun r a H f;  is_recfun r b H g;  (b,a):r |] ==> \
    1.81 +\       is_recfun r H a f;  is_recfun r H b g;  (b,a):r |] ==> \
    1.82  \    cut f r b = g";
    1.83  val gundef = recgb RS is_recfun_undef
    1.84  and fisg   = recgb RS (recfa RS (transr RS (wfr RS is_recfun_equal)));
    1.85 @@ -128,70 +119,112 @@
    1.86  (*** Main Existence Lemma -- Basic Properties of the_recfun ***)
    1.87  
    1.88  val prems = goalw WF.thy [the_recfun_def]
    1.89 -    "is_recfun r a H f ==> is_recfun r a H (the_recfun r a H)";
    1.90 -by (res_inst_tac [("P", "is_recfun r a H")] selectI 1);
    1.91 +    "is_recfun r H a f ==> is_recfun r H a (the_recfun r H a)";
    1.92 +by (res_inst_tac [("P", "is_recfun r H a")] selectI 1);
    1.93  by (resolve_tac prems 1);
    1.94  qed "is_the_recfun";
    1.95  
    1.96  val prems = goal WF.thy
    1.97 -    "[| wf(r);  trans(r) |] ==> is_recfun r a H (the_recfun r a H)";
    1.98 -by (cut_facts_tac prems 1);
    1.99 -by (wf_ind_tac "a" prems 1);
   1.100 -by (res_inst_tac [("f", "cut (%y. wftrec r y H) r a1")] is_the_recfun 1);
   1.101 -by (rewrite_goals_tac [is_recfun_def, wftrec_def]);
   1.102 -by (rtac (cut_cut_eq RS ssubst) 1);
   1.103 -(*Applying the substitution: must keep the quantified assumption!!*)
   1.104 -by (EVERY1 [strip_tac, rtac H_cong1, rtac allE, atac,
   1.105 -            etac (mp RS ssubst), atac]);
   1.106 -by (fold_tac [is_recfun_def]);
   1.107 -by (asm_simp_tac (wf_super_ss addsimps[cut_apply,is_recfun_cut,cut_cut_eq]) 1);
   1.108 + "[| wf(r);  trans(r) |] ==> is_recfun r H a (the_recfun r H a)";
   1.109 +  by (cut_facts_tac prems 1);
   1.110 +  by (wf_ind_tac "a" prems 1);
   1.111 +  by (res_inst_tac [("f","cut (%y. H (the_recfun r H y) y) r a1")]
   1.112 +                   is_the_recfun 1);
   1.113 +  by (rewrite_goals_tac [is_recfun_def]);
   1.114 +  by (rtac (cuts_eq RS ssubst) 1);
   1.115 +  by (rtac allI 1);
   1.116 +  by (rtac impI 1);
   1.117 +  by (res_inst_tac [("f1","H"),("x","y")](arg_cong RS fun_cong) 1);
   1.118 +  by (subgoal_tac
   1.119 +         "the_recfun r H y = cut(%x. H(cut(the_recfun r H y) r x) x) r y" 1);
   1.120 +  by (etac allE 2);
   1.121 +  by (dtac impE 2);
   1.122 +  by (atac 2);
   1.123 +  by (atac 3);
   1.124 +  by (atac 2);
   1.125 +  by (etac ssubst 1);
   1.126 +  by (simp_tac (HOL_ss addsimps [cuts_eq]) 1);
   1.127 +  by (rtac allI 1);
   1.128 +  by (rtac impI 1);
   1.129 +  by (asm_simp_tac (wf_super_ss addsimps[cut_apply,is_recfun_cut,cuts_eq]) 1);
   1.130 +  by (res_inst_tac [("f1","H"),("x","ya")](arg_cong RS fun_cong) 1);
   1.131 +  by (fold_tac [is_recfun_def]);
   1.132 +  by (asm_simp_tac (wf_super_ss addsimps[cut_apply,is_recfun_cut,cuts_eq]) 1);
   1.133  qed "unfold_the_recfun";
   1.134  
   1.135 -
   1.136 -(*Beware incompleteness of unification!*)
   1.137 -val prems = goal WF.thy
   1.138 -    "[| wf(r);  trans(r);  (c,a):r;  (c,b):r |] \
   1.139 -\    ==> the_recfun r a H c = the_recfun r b H c";
   1.140 -by (DEPTH_SOLVE (ares_tac (prems@[is_recfun_equal,unfold_the_recfun]) 1));
   1.141 -qed "the_recfun_equal";
   1.142 -
   1.143 -val prems = goal WF.thy
   1.144 -    "[| wf(r); trans(r); (b,a):r |] \
   1.145 -\    ==> cut (the_recfun r a H) r b = the_recfun r b H";
   1.146 -by (REPEAT (ares_tac (prems@[is_recfun_cut,unfold_the_recfun]) 1));
   1.147 -qed "the_recfun_cut";
   1.148 -
   1.149 -(*** Unfolding wftrec ***)
   1.150 +val unwind1_the_recfun = rewrite_rule[is_recfun_def] unfold_the_recfun;
   1.151  
   1.152 -goalw WF.thy [wftrec_def]
   1.153 -    "!!r. [| wf(r);  trans(r) |] ==> \
   1.154 -\    wftrec r a H = H a (cut (%x.wftrec r x H) r a)";
   1.155 -by (EVERY1 [stac (rewrite_rule [is_recfun_def] unfold_the_recfun),
   1.156 -            REPEAT o atac, rtac H_cong1]);
   1.157 -by (asm_simp_tac (!simpset addsimps [cut_cut_eq,the_recfun_cut]) 1);
   1.158 -qed "wftrec";
   1.159 -
   1.160 -(*Unused but perhaps interesting*)
   1.161 +(*--------------Old proof-----------------------------------------------------
   1.162  val prems = goal WF.thy
   1.163 -    "[| wf(r);  trans(r);  !!f x. H x (cut f r x) = H x f |] ==> \
   1.164 -\               wftrec r a H = H a (%x.wftrec r x H)";
   1.165 -by (rtac (wftrec RS trans) 1);
   1.166 -by (REPEAT (resolve_tac prems 1));
   1.167 -qed "wftrec2";
   1.168 +    "[| wf(r);  trans(r) |] ==> is_recfun r H a (the_recfun r H a)";
   1.169 +by (cut_facts_tac prems 1);
   1.170 +by (wf_ind_tac "a" prems 1);
   1.171 +by (res_inst_tac [("f", "cut (%y. wftrec r H y) r a1")] is_the_recfun 1); 
   1.172 +by (rewrite_goals_tac [is_recfun_def, wftrec_def]);
   1.173 +by (rtac (cuts_eq RS ssubst) 1);
   1.174 +(*Applying the substitution: must keep the quantified assumption!!*)
   1.175 +by (EVERY1 [strip_tac, rtac H_cong1, rtac allE, atac,
   1.176 +            etac (mp RS ssubst), atac]); 
   1.177 +by (fold_tac [is_recfun_def]);
   1.178 +by (asm_simp_tac (wf_super_ss addsimps[cut_apply,is_recfun_cut,cuts_eq]) 1);
   1.179 +qed "unfold_the_recfun";
   1.180 +---------------------------------------------------------------------------*)
   1.181  
   1.182  (** Removal of the premise trans(r) **)
   1.183 +val th = rewrite_rule[is_recfun_def]
   1.184 +                     (trans_trancl RSN (2,(wf_trancl RS unfold_the_recfun)));
   1.185  
   1.186  goalw WF.thy [wfrec_def]
   1.187 -    "!!r. wf(r) ==> wfrec r a H = H a (cut (%x.wfrec r x H) r a)";
   1.188 +    "!!r. wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a";
   1.189 +by (rtac H_cong 1);
   1.190 +by (rtac refl 2);
   1.191 +by (simp_tac (HOL_ss addsimps [cuts_eq]) 1);
   1.192 +by (rtac allI 1);
   1.193 +by (rtac impI 1);
   1.194 +by (simp_tac(HOL_ss addsimps [wfrec_def]) 1);
   1.195 +by (res_inst_tac [("a1","a")] (th RS ssubst) 1);
   1.196 +by (atac 1);
   1.197 +by (forward_tac[wf_trancl] 1);
   1.198 +by (forward_tac[r_into_trancl] 1);
   1.199 +by (asm_simp_tac (HOL_ss addsimps [cut_apply]) 1);
   1.200 +by (rtac H_cong 1);    (*expose the equality of cuts*)
   1.201 +by (rtac refl 2);
   1.202 +by (simp_tac (HOL_ss addsimps [cuts_eq, cut_apply, r_into_trancl]) 1);
   1.203 +by (strip_tac 1);
   1.204 +by (res_inst_tac [("r2","r^+")] (is_recfun_equal_lemma RS mp RS mp) 1);
   1.205 +by (atac 1);
   1.206 +by (rtac trans_trancl 1);
   1.207 +by (rtac unfold_the_recfun 1);
   1.208 +by (atac 1);
   1.209 +by (rtac trans_trancl 1);
   1.210 +by (rtac unfold_the_recfun 1);
   1.211 +by (atac 1);
   1.212 +by (rtac trans_trancl 1);
   1.213 +by (rtac transD 1);
   1.214 +by (rtac trans_trancl 1);
   1.215 +by (forw_inst_tac [("a","ya")] r_into_trancl 1);
   1.216 +by (atac 1);
   1.217 +by (atac 1);
   1.218 +by (forw_inst_tac [("a","ya")] r_into_trancl 1);
   1.219 +by (atac 1);
   1.220 +qed "wfrec";
   1.221 +
   1.222 +(*--------------Old proof-----------------------------------------------------
   1.223 +goalw WF.thy [wfrec_def]
   1.224 +    "!!r. wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a";
   1.225  by (etac (wf_trancl RS wftrec RS ssubst) 1);
   1.226  by (rtac trans_trancl 1);
   1.227  by (rtac (refl RS H_cong) 1);    (*expose the equality of cuts*)
   1.228 -by (simp_tac (!simpset addsimps [cut_cut_eq, cut_apply, r_into_trancl]) 1);
   1.229 +by (simp_tac (HOL_ss addsimps [cuts_eq, cut_apply, r_into_trancl]) 1);
   1.230  qed "wfrec";
   1.231 +---------------------------------------------------------------------------*)
   1.232  
   1.233 -(*This form avoids giant explosions in proofs.  NOTE USE OF == *)
   1.234 +(*---------------------------------------------------------------------------
   1.235 + * This form avoids giant explosions in proofs.  NOTE USE OF == 
   1.236 + *---------------------------------------------------------------------------*)
   1.237  val rew::prems = goal WF.thy
   1.238 -    "[| !!x. f(x)==wfrec r x H;  wf(r) |] ==> f(a) = H a (cut (%x.f(x)) r a)";
   1.239 +    "[| f==wfrec r H;  wf(r) |] ==> f(a) = H (cut f r a) a";
   1.240  by (rewtac rew);
   1.241  by (REPEAT (resolve_tac (prems@[wfrec]) 1));
   1.242  qed "def_wfrec";
   1.243 +