0

1 
(* Title: ZF/trancl.ML


2 
ID: $Id$


3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory


4 
Copyright 1992 University of Cambridge


5 


6 
For trancl.thy. Transitive closure of a relation


7 
*)


8 


9 
open Trancl;


10 


11 
val major::prems = goalw Trancl.thy [trans_def]


12 
"[ trans(r); <a,b>:r; <b,c>:r ] ==> <a,c>:r";


13 
by (rtac (major RS spec RS spec RS spec RS mp RS mp) 1);


14 
by (REPEAT (resolve_tac prems 1));


15 
val transD = result();


16 


17 
goal Trancl.thy "bnd_mono(field(r)*field(r), %s. id(field(r)) Un (r O s))";


18 
by (rtac bnd_monoI 1);


19 
by (REPEAT (ares_tac [subset_refl, Un_mono, comp_mono] 2));


20 
by (fast_tac comp_cs 1);


21 
val rtrancl_bnd_mono = result();


22 


23 
val [prem] = goalw Trancl.thy [rtrancl_def] "r<=s ==> r^* <= s^*";


24 
by (rtac lfp_mono 1);


25 
by (REPEAT (resolve_tac [rtrancl_bnd_mono, prem, subset_refl, id_mono,


26 
comp_mono, Un_mono, field_mono, Sigma_mono] 1));


27 
val rtrancl_mono = result();


28 


29 
(* r^* = id(field(r)) Un ( r O r^* ) *)


30 
val rtrancl_unfold = rtrancl_bnd_mono RS (rtrancl_def RS def_lfp_Tarski);


31 


32 
(** The relation rtrancl **)


33 


34 
val rtrancl_type = standard (rtrancl_def RS def_lfp_subset);


35 


36 
(*Reflexivity of rtrancl*)


37 
val [prem] = goal Trancl.thy "[ a: field(r) ] ==> <a,a> : r^*";


38 
by (resolve_tac [rtrancl_unfold RS ssubst] 1);


39 
by (rtac (prem RS idI RS UnI1) 1);


40 
val rtrancl_refl = result();


41 


42 
(*Closure under composition with r *)


43 
val prems = goal Trancl.thy


44 
"[ <a,b> : r^*; <b,c> : r ] ==> <a,c> : r^*";


45 
by (resolve_tac [rtrancl_unfold RS ssubst] 1);


46 
by (rtac (compI RS UnI2) 1);


47 
by (resolve_tac prems 1);


48 
by (resolve_tac prems 1);


49 
val rtrancl_into_rtrancl = result();


50 


51 
(*rtrancl of r contains all pairs in r *)


52 
val prems = goal Trancl.thy "<a,b> : r ==> <a,b> : r^*";


53 
by (resolve_tac [rtrancl_refl RS rtrancl_into_rtrancl] 1);


54 
by (REPEAT (resolve_tac (prems@[fieldI1]) 1));


55 
val r_into_rtrancl = result();


56 


57 
(*The premise ensures that r consists entirely of pairs*)


58 
val prems = goal Trancl.thy "r <= Sigma(A,B) ==> r <= r^*";


59 
by (cut_facts_tac prems 1);


60 
by (fast_tac (ZF_cs addIs [r_into_rtrancl]) 1);


61 
val r_subset_rtrancl = result();


62 


63 
goal Trancl.thy "field(r^*) = field(r)";


64 
by (fast_tac (eq_cs addIs [r_into_rtrancl]


65 
addSDs [rtrancl_type RS subsetD]) 1);


66 
val rtrancl_field = result();


67 


68 


69 
(** standard induction rule **)


70 


71 
val major::prems = goal Trancl.thy


72 
"[ <a,b> : r^*; \


73 
\ !!x. x: field(r) ==> P(<x,x>); \


74 
\ !!x y z.[ P(<x,y>); <x,y>: r^*; <y,z>: r ] ==> P(<x,z>) ] \


75 
\ ==> P(<a,b>)";


76 
by (rtac ([rtrancl_def, rtrancl_bnd_mono, major] MRS def_induct) 1);


77 
by (fast_tac (ZF_cs addIs prems addSEs [idE,compE]) 1);


78 
val rtrancl_full_induct = result();


79 


80 
(*nice induction rule.


81 
Tried adding the typing hypotheses y,z:field(r), but these


82 
caused expensive case splits!*)


83 
val major::prems = goal Trancl.thy


84 
"[ <a,b> : r^*; \


85 
\ P(a); \


86 
\ !!y z.[ <a,y> : r^*; <y,z> : r; P(y) ] ==> P(z) \


87 
\ ] ==> P(b)";


88 
(*by induction on this formula*)


89 
by (subgoal_tac "ALL y. <a,b> = <a,y> > P(y)" 1);


90 
(*now solve first subgoal: this formula is sufficient*)


91 
by (EVERY1 [etac (spec RS mp), rtac refl]);


92 
(*now do the induction*)


93 
by (resolve_tac [major RS rtrancl_full_induct] 1);


94 
by (ALLGOALS (fast_tac (ZF_cs addIs prems)));


95 
val rtrancl_induct = result();


96 


97 
(*transitivity of transitive closure!!  by induction.*)


98 
goalw Trancl.thy [trans_def] "trans(r^*)";


99 
by (REPEAT (resolve_tac [allI,impI] 1));


100 
by (eres_inst_tac [("b","z")] rtrancl_induct 1);


101 
by (DEPTH_SOLVE (eresolve_tac [asm_rl, rtrancl_into_rtrancl] 1));


102 
val trans_rtrancl = result();


103 


104 
(*elimination of rtrancl  by induction on a special formula*)


105 
val major::prems = goal Trancl.thy


106 
"[ <a,b> : r^*; (a=b) ==> P; \


107 
\ !!y.[ <a,y> : r^*; <y,b> : r ] ==> P ] \


108 
\ ==> P";


109 
by (subgoal_tac "a = b  (EX y. <a,y> : r^* & <y,b> : r)" 1);


110 
(*see HOL/trancl*)


111 
by (rtac (major RS rtrancl_induct) 2);


112 
by (ALLGOALS (fast_tac (ZF_cs addSEs prems)));


113 
val rtranclE = result();


114 


115 


116 
(**** The relation trancl ****)


117 


118 
(*Transitivity of r^+ is proved by transitivity of r^* *)


119 
goalw Trancl.thy [trans_def,trancl_def] "trans(r^+)";


120 
by (safe_tac comp_cs);


121 
by (rtac (rtrancl_into_rtrancl RS (trans_rtrancl RS transD RS compI)) 1);


122 
by (REPEAT (assume_tac 1));


123 
val trans_trancl = result();


124 


125 
(** Conversions between trancl and rtrancl **)


126 


127 
val [major] = goalw Trancl.thy [trancl_def] "<a,b> : r^+ ==> <a,b> : r^*";


128 
by (resolve_tac [major RS compEpair] 1);


129 
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));


130 
val trancl_into_rtrancl = result();


131 


132 
(*r^+ contains all pairs in r *)


133 
val [prem] = goalw Trancl.thy [trancl_def] "<a,b> : r ==> <a,b> : r^+";


134 
by (REPEAT (ares_tac [prem,compI,rtrancl_refl,fieldI1] 1));


135 
val r_into_trancl = result();


136 


137 
(*The premise ensures that r consists entirely of pairs*)


138 
val prems = goal Trancl.thy "r <= Sigma(A,B) ==> r <= r^+";


139 
by (cut_facts_tac prems 1);


140 
by (fast_tac (ZF_cs addIs [r_into_trancl]) 1);


141 
val r_subset_trancl = result();


142 


143 
(*intro rule by definition: from r^* and r *)


144 
val prems = goalw Trancl.thy [trancl_def]


145 
"[ <a,b> : r^*; <b,c> : r ] ==> <a,c> : r^+";


146 
by (REPEAT (resolve_tac ([compI]@prems) 1));


147 
val rtrancl_into_trancl1 = result();


148 


149 
(*intro rule from r and r^* *)


150 
val prems = goal Trancl.thy


151 
"[ <a,b> : r; <b,c> : r^* ] ==> <a,c> : r^+";


152 
by (resolve_tac (prems RL [rtrancl_induct]) 1);


153 
by (resolve_tac (prems RL [r_into_trancl]) 1);


154 
by (etac (trans_trancl RS transD) 1);


155 
by (etac r_into_trancl 1);


156 
val rtrancl_into_trancl2 = result();


157 


158 
(*Nice induction rule for trancl*)


159 
val major::prems = goal Trancl.thy


160 
"[ <a,b> : r^+; \


161 
\ !!y. [ <a,y> : r ] ==> P(y); \


162 
\ !!y z.[ <a,y> : r^+; <y,z> : r; P(y) ] ==> P(z) \


163 
\ ] ==> P(b)";


164 
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);


165 
(*by induction on this formula*)


166 
by (subgoal_tac "ALL z. <y,z> : r > P(z)" 1);


167 
(*now solve first subgoal: this formula is sufficient*)


168 
by (fast_tac ZF_cs 1);


169 
by (etac rtrancl_induct 1);


170 
by (ALLGOALS (fast_tac (ZF_cs addIs (rtrancl_into_trancl1::prems))));


171 
val trancl_induct = result();


172 


173 
(*elimination of r^+  NOT an induction rule*)


174 
val major::prems = goal Trancl.thy


175 
"[ <a,b> : r^+; \


176 
\ <a,b> : r ==> P; \


177 
\ !!y.[ <a,y> : r^+; <y,b> : r ] ==> P \


178 
\ ] ==> P";


179 
by (subgoal_tac "<a,b> : r  (EX y. <a,y> : r^+ & <y,b> : r)" 1);


180 
by (fast_tac (ZF_cs addIs prems) 1);


181 
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);


182 
by (etac rtranclE 1);


183 
by (ALLGOALS (fast_tac (ZF_cs addIs [rtrancl_into_trancl1])));


184 
val tranclE = result();


185 


186 
goalw Trancl.thy [trancl_def] "r^+ <= field(r)*field(r)";


187 
by (fast_tac (ZF_cs addEs [compE, rtrancl_type RS subsetD RS SigmaE2]) 1);


188 
val trancl_type = result();


189 


190 
val [prem] = goalw Trancl.thy [trancl_def] "r<=s ==> r^+ <= s^+";


191 
by (REPEAT (resolve_tac [prem, comp_mono, rtrancl_mono] 1));


192 
val trancl_mono = result();


193 
