| author | Andreas Lochbihler | 
| Tue, 01 Dec 2015 12:35:11 +0100 | |
| changeset 61766 | 507b39df1a57 | 
| parent 61681 | ca53150406c9 | 
| child 61799 | 4cf66f21b764 | 
| permissions | -rw-r--r-- | 
| 10213 | 1 | (* Title: HOL/Transitive_Closure.thy | 
| 2 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | |
| 3 | Copyright 1992 University of Cambridge | |
| 4 | *) | |
| 5 | ||
| 60758 | 6 | section \<open>Reflexive and Transitive closure of a relation\<close> | 
| 12691 | 7 | |
| 15131 | 8 | theory Transitive_Closure | 
| 46664 
1f6c140f9c72
moved predicate relations and conversion rules between set and predicate relations from Predicate.thy to Relation.thy; moved Predicate.thy upwards in theory hierarchy
 haftmann parents: 
46638diff
changeset | 9 | imports Relation | 
| 15131 | 10 | begin | 
| 12691 | 11 | |
| 48891 | 12 | ML_file "~~/src/Provers/trancl.ML" | 
| 13 | ||
| 60758 | 14 | text \<open> | 
| 12691 | 15 |   @{text rtrancl} is reflexive/transitive closure,
 | 
| 16 |   @{text trancl} is transitive closure,
 | |
| 17 |   @{text reflcl} is reflexive closure.
 | |
| 18 | ||
| 19 |   These postfix operators have \emph{maximum priority}, forcing their
 | |
| 20 | operands to be atomic. | |
| 60758 | 21 | \<close> | 
| 10213 | 22 | |
| 61681 
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
 wenzelm parents: 
61424diff
changeset | 23 | context | 
| 
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
 wenzelm parents: 
61424diff
changeset | 24 | notes [[inductive_defs]] | 
| 
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
 wenzelm parents: 
61424diff
changeset | 25 | begin | 
| 
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
 wenzelm parents: 
61424diff
changeset | 26 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 27 | inductive_set | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 28 |   rtrancl :: "('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set"   ("(_^*)" [1000] 999)
 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 29 |   for r :: "('a \<times> 'a) set"
 | 
| 22262 | 30 | where | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 31 | rtrancl_refl [intro!, Pure.intro!, simp]: "(a, a) : r^*" | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 32 | | rtrancl_into_rtrancl [Pure.intro]: "(a, b) : r^* ==> (b, c) : r ==> (a, c) : r^*" | 
| 11327 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 berghofe parents: 
11115diff
changeset | 33 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 34 | inductive_set | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 35 |   trancl :: "('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set"  ("(_^+)" [1000] 999)
 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 36 |   for r :: "('a \<times> 'a) set"
 | 
| 22262 | 37 | where | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 38 | r_into_trancl [intro, Pure.intro]: "(a, b) : r ==> (a, b) : r^+" | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 39 | | trancl_into_trancl [Pure.intro]: "(a, b) : r^+ ==> (b, c) : r ==> (a, c) : r^+" | 
| 13704 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 40 | |
| 41792 
ff3cb0c418b7
renamed "nitpick\_def" to "nitpick_unfold" to reflect its new semantics
 blanchet parents: 
39302diff
changeset | 41 | declare rtrancl_def [nitpick_unfold del] | 
| 
ff3cb0c418b7
renamed "nitpick\_def" to "nitpick_unfold" to reflect its new semantics
 blanchet parents: 
39302diff
changeset | 42 | rtranclp_def [nitpick_unfold del] | 
| 
ff3cb0c418b7
renamed "nitpick\_def" to "nitpick_unfold" to reflect its new semantics
 blanchet parents: 
39302diff
changeset | 43 | trancl_def [nitpick_unfold del] | 
| 
ff3cb0c418b7
renamed "nitpick\_def" to "nitpick_unfold" to reflect its new semantics
 blanchet parents: 
39302diff
changeset | 44 | tranclp_def [nitpick_unfold del] | 
| 33878 
85102f57b4a8
removed "nitpick_def" attributes from (r)trancl(p), since "Nitpick.thy" overrides these
 blanchet parents: 
33656diff
changeset | 45 | |
| 61681 
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
 wenzelm parents: 
61424diff
changeset | 46 | end | 
| 
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
 wenzelm parents: 
61424diff
changeset | 47 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 48 | notation | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 49 |   rtranclp  ("(_^**)" [1000] 1000) and
 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 50 |   tranclp  ("(_^++)" [1000] 1000)
 | 
| 10213 | 51 | |
| 19656 
09be06943252
tuned concrete syntax -- abbreviation/const_syntax;
 wenzelm parents: 
19623diff
changeset | 52 | abbreviation | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 53 |   reflclp :: "('a => 'a => bool) => 'a => 'a => bool"  ("(_^==)" [1000] 1000) where
 | 
| 45137 | 54 | "r^== \<equiv> sup r op =" | 
| 22262 | 55 | |
| 56 | abbreviation | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 57 |   reflcl :: "('a \<times> 'a) set => ('a \<times> 'a) set"  ("(_^=)" [1000] 999) where
 | 
| 45137 | 58 | "r^= \<equiv> r \<union> Id" | 
| 10213 | 59 | |
| 21210 | 60 | notation (xsymbols) | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 61 |   rtranclp  ("(_\<^sup>*\<^sup>*)" [1000] 1000) and
 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 62 |   tranclp  ("(_\<^sup>+\<^sup>+)" [1000] 1000) and
 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 63 |   reflclp  ("(_\<^sup>=\<^sup>=)" [1000] 1000) and
 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 64 |   rtrancl  ("(_\<^sup>*)" [1000] 999) and
 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 65 |   trancl  ("(_\<^sup>+)" [1000] 999) and
 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 66 |   reflcl  ("(_\<^sup>=)" [1000] 999)
 | 
| 12691 | 67 | |
| 68 | ||
| 60758 | 69 | subsection \<open>Reflexive closure\<close> | 
| 26271 | 70 | |
| 30198 | 71 | lemma refl_reflcl[simp]: "refl(r^=)" | 
| 72 | by(simp add:refl_on_def) | |
| 26271 | 73 | |
| 74 | lemma antisym_reflcl[simp]: "antisym(r^=) = antisym r" | |
| 75 | by(simp add:antisym_def) | |
| 76 | ||
| 77 | lemma trans_reflclI[simp]: "trans r \<Longrightarrow> trans(r^=)" | |
| 78 | unfolding trans_def by blast | |
| 79 | ||
| 50616 | 80 | lemma reflclp_idemp [simp]: "(P^==)^== = P^==" | 
| 81 | by blast | |
| 26271 | 82 | |
| 60758 | 83 | subsection \<open>Reflexive-transitive closure\<close> | 
| 12691 | 84 | |
| 32883 
7cbd93dacef3
inf/sup1/2_iff are mere duplicates of underlying definitions: dropped
 haftmann parents: 
32601diff
changeset | 85 | lemma reflcl_set_eq [pred_set_conv]: "(sup (\<lambda>x y. (x, y) \<in> r) op =) = (\<lambda>x y. (x, y) \<in> r \<union> Id)" | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 86 | by (auto simp add: fun_eq_iff) | 
| 22262 | 87 | |
| 57284 
886ff14f20cc
r_into_(r)trancl should not be [simp]: helps little and comlicates some AFP proofs
 nipkow parents: 
57283diff
changeset | 88 | lemma r_into_rtrancl [intro]: "!!p. p \<in> r ==> p \<in> r^*" | 
| 60758 | 89 |   -- \<open>@{text rtrancl} of @{text r} contains @{text r}\<close>
 | 
| 12691 | 90 | apply (simp only: split_tupled_all) | 
| 91 | apply (erule rtrancl_refl [THEN rtrancl_into_rtrancl]) | |
| 92 | done | |
| 93 | ||
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 94 | lemma r_into_rtranclp [intro]: "r x y ==> r^** x y" | 
| 60758 | 95 |   -- \<open>@{text rtrancl} of @{text r} contains @{text r}\<close>
 | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 96 | by (erule rtranclp.rtrancl_refl [THEN rtranclp.rtrancl_into_rtrancl]) | 
| 22262 | 97 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 98 | lemma rtranclp_mono: "r \<le> s ==> r^** \<le> s^**" | 
| 60758 | 99 |   -- \<open>monotonicity of @{text rtrancl}\<close>
 | 
| 22262 | 100 | apply (rule predicate2I) | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 101 | apply (erule rtranclp.induct) | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 102 | apply (rule_tac [2] rtranclp.rtrancl_into_rtrancl, blast+) | 
| 12691 | 103 | done | 
| 104 | ||
| 60681 | 105 | lemma mono_rtranclp[mono]: | 
| 106 | "(\<And>a b. x a b \<longrightarrow> y a b) \<Longrightarrow> x^** a b \<longrightarrow> y^** a b" | |
| 107 | using rtranclp_mono[of x y] by auto | |
| 108 | ||
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 109 | lemmas rtrancl_mono = rtranclp_mono [to_set] | 
| 22262 | 110 | |
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 111 | theorem rtranclp_induct [consumes 1, case_names base step, induct set: rtranclp]: | 
| 22262 | 112 | assumes a: "r^** a b" | 
| 113 | and cases: "P a" "!!y z. [| r^** a y; r y z; P y |] ==> P z" | |
| 34909 
a799687944af
Tuned some proofs; nicer case names for some of the induction / cases rules.
 berghofe parents: 
33878diff
changeset | 114 | shows "P b" using a | 
| 
a799687944af
Tuned some proofs; nicer case names for some of the induction / cases rules.
 berghofe parents: 
33878diff
changeset | 115 | by (induct x\<equiv>a b) (rule cases)+ | 
| 12691 | 116 | |
| 25425 
9191942c4ead
Removed some case_names and consumes attributes that are now no longer
 berghofe parents: 
25295diff
changeset | 117 | lemmas rtrancl_induct [induct set: rtrancl] = rtranclp_induct [to_set] | 
| 22262 | 118 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 119 | lemmas rtranclp_induct2 = | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 120 | rtranclp_induct[of _ "(ax,ay)" "(bx,by)", split_rule, | 
| 22262 | 121 | consumes 1, case_names refl step] | 
| 122 | ||
| 14404 
4952c5a92e04
Transitive_Closure: added consumes and case_names attributes
 nipkow parents: 
14398diff
changeset | 123 | lemmas rtrancl_induct2 = | 
| 
4952c5a92e04
Transitive_Closure: added consumes and case_names attributes
 nipkow parents: 
14398diff
changeset | 124 | rtrancl_induct[of "(ax,ay)" "(bx,by)", split_format (complete), | 
| 
4952c5a92e04
Transitive_Closure: added consumes and case_names attributes
 nipkow parents: 
14398diff
changeset | 125 | consumes 1, case_names refl step] | 
| 18372 | 126 | |
| 30198 | 127 | lemma refl_rtrancl: "refl (r^*)" | 
| 128 | by (unfold refl_on_def) fast | |
| 19228 | 129 | |
| 60758 | 130 | text \<open>Transitivity of transitive closure.\<close> | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 131 | lemma trans_rtrancl: "trans (r^*)" | 
| 12823 | 132 | proof (rule transI) | 
| 133 | fix x y z | |
| 134 | assume "(x, y) \<in> r\<^sup>*" | |
| 135 | assume "(y, z) \<in> r\<^sup>*" | |
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 136 | then show "(x, z) \<in> r\<^sup>*" | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 137 | proof induct | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 138 | case base | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 139 | show "(x, y) \<in> r\<^sup>*" by fact | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 140 | next | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 141 | case (step u v) | 
| 60758 | 142 | from \<open>(x, u) \<in> r\<^sup>*\<close> and \<open>(u, v) \<in> r\<close> | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 143 | show "(x, v) \<in> r\<^sup>*" .. | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 144 | qed | 
| 12823 | 145 | qed | 
| 12691 | 146 | |
| 45607 | 147 | lemmas rtrancl_trans = trans_rtrancl [THEN transD] | 
| 12691 | 148 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 149 | lemma rtranclp_trans: | 
| 22262 | 150 | assumes xy: "r^** x y" | 
| 151 | and yz: "r^** y z" | |
| 152 | shows "r^** x z" using yz xy | |
| 153 | by induct iprover+ | |
| 154 | ||
| 26174 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 155 | lemma rtranclE [cases set: rtrancl]: | 
| 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 156 | assumes major: "(a::'a, b) : r^*" | 
| 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 157 | obtains | 
| 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 158 | (base) "a = b" | 
| 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 159 | | (step) y where "(a, y) : r^*" and "(y, b) : r" | 
| 60758 | 160 |   -- \<open>elimination of @{text rtrancl} -- by induction on a special formula\<close>
 | 
| 18372 | 161 | apply (subgoal_tac "(a::'a) = b | (EX y. (a,y) : r^* & (y,b) : r)") | 
| 162 | apply (rule_tac [2] major [THEN rtrancl_induct]) | |
| 163 | prefer 2 apply blast | |
| 164 | prefer 2 apply blast | |
| 26174 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 165 | apply (erule asm_rl exE disjE conjE base step)+ | 
| 18372 | 166 | done | 
| 12691 | 167 | |
| 32235 
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
 krauss parents: 
32215diff
changeset | 168 | lemma rtrancl_Int_subset: "[| Id \<subseteq> s; (r^* \<inter> s) O r \<subseteq> s|] ==> r^* \<subseteq> s" | 
| 22080 
7bf8868ab3e4
induction rules for trancl/rtrancl expressed using subsets
 paulson parents: 
21589diff
changeset | 169 | apply (rule subsetI) | 
| 61032 
b57df8eecad6
standardized some occurences of ancient "split" alias
 haftmann parents: 
60758diff
changeset | 170 | apply auto | 
| 
b57df8eecad6
standardized some occurences of ancient "split" alias
 haftmann parents: 
60758diff
changeset | 171 | apply (erule rtrancl_induct) | 
| 
b57df8eecad6
standardized some occurences of ancient "split" alias
 haftmann parents: 
60758diff
changeset | 172 | apply auto | 
| 22080 
7bf8868ab3e4
induction rules for trancl/rtrancl expressed using subsets
 paulson parents: 
21589diff
changeset | 173 | done | 
| 
7bf8868ab3e4
induction rules for trancl/rtrancl expressed using subsets
 paulson parents: 
21589diff
changeset | 174 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 175 | lemma converse_rtranclp_into_rtranclp: | 
| 22262 | 176 | "r a b \<Longrightarrow> r\<^sup>*\<^sup>* b c \<Longrightarrow> r\<^sup>*\<^sup>* a c" | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 177 | by (rule rtranclp_trans) iprover+ | 
| 22262 | 178 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 179 | lemmas converse_rtrancl_into_rtrancl = converse_rtranclp_into_rtranclp [to_set] | 
| 12691 | 180 | |
| 60758 | 181 | text \<open> | 
| 12691 | 182 |   \medskip More @{term "r^*"} equations and inclusions.
 | 
| 60758 | 183 | \<close> | 
| 12691 | 184 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 185 | lemma rtranclp_idemp [simp]: "(r^**)^** = r^**" | 
| 22262 | 186 | apply (auto intro!: order_antisym) | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 187 | apply (erule rtranclp_induct) | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 188 | apply (rule rtranclp.rtrancl_refl) | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 189 | apply (blast intro: rtranclp_trans) | 
| 12691 | 190 | done | 
| 191 | ||
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 192 | lemmas rtrancl_idemp [simp] = rtranclp_idemp [to_set] | 
| 22262 | 193 | |
| 12691 | 194 | lemma rtrancl_idemp_self_comp [simp]: "R^* O R^* = R^*" | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 195 | apply (rule set_eqI) | 
| 12691 | 196 | apply (simp only: split_tupled_all) | 
| 197 | apply (blast intro: rtrancl_trans) | |
| 198 | done | |
| 199 | ||
| 200 | lemma rtrancl_subset_rtrancl: "r \<subseteq> s^* ==> r^* \<subseteq> s^*" | |
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 201 | apply (drule rtrancl_mono) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 202 | apply simp | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 203 | done | 
| 12691 | 204 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 205 | lemma rtranclp_subset: "R \<le> S ==> S \<le> R^** ==> S^** = R^**" | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 206 | apply (drule rtranclp_mono) | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 207 | apply (drule rtranclp_mono) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 208 | apply simp | 
| 12691 | 209 | done | 
| 210 | ||
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 211 | lemmas rtrancl_subset = rtranclp_subset [to_set] | 
| 22262 | 212 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 213 | lemma rtranclp_sup_rtranclp: "(sup (R^**) (S^**))^** = (sup R S)^**" | 
| 50616 | 214 | by (blast intro!: rtranclp_subset intro: rtranclp_mono [THEN predicate2D]) | 
| 12691 | 215 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 216 | lemmas rtrancl_Un_rtrancl = rtranclp_sup_rtranclp [to_set] | 
| 22262 | 217 | |
| 50616 | 218 | lemma rtranclp_reflclp [simp]: "(R^==)^** = R^**" | 
| 219 | by (blast intro!: rtranclp_subset) | |
| 22262 | 220 | |
| 50616 | 221 | lemmas rtrancl_reflcl [simp] = rtranclp_reflclp [to_set] | 
| 12691 | 222 | |
| 223 | lemma rtrancl_r_diff_Id: "(r - Id)^* = r^*" | |
| 224 | apply (rule sym) | |
| 14208 | 225 | apply (rule rtrancl_subset, blast, clarify) | 
| 12691 | 226 | apply (rename_tac a b) | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 227 | apply (case_tac "a = b") | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 228 | apply blast | 
| 44921 | 229 | apply blast | 
| 12691 | 230 | done | 
| 231 | ||
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 232 | lemma rtranclp_r_diff_Id: "(inf r op ~=)^** = r^**" | 
| 22262 | 233 | apply (rule sym) | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 234 | apply (rule rtranclp_subset) | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 235 | apply blast+ | 
| 22262 | 236 | done | 
| 237 | ||
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 238 | theorem rtranclp_converseD: | 
| 22262 | 239 | assumes r: "(r^--1)^** x y" | 
| 240 | shows "r^** y x" | |
| 12823 | 241 | proof - | 
| 242 | from r show ?thesis | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 243 | by induct (iprover intro: rtranclp_trans dest!: conversepD)+ | 
| 12823 | 244 | qed | 
| 12691 | 245 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 246 | lemmas rtrancl_converseD = rtranclp_converseD [to_set] | 
| 22262 | 247 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 248 | theorem rtranclp_converseI: | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 249 | assumes "r^** y x" | 
| 22262 | 250 | shows "(r^--1)^** x y" | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 251 | using assms | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 252 | by induct (iprover intro: rtranclp_trans conversepI)+ | 
| 12691 | 253 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 254 | lemmas rtrancl_converseI = rtranclp_converseI [to_set] | 
| 22262 | 255 | |
| 12691 | 256 | lemma rtrancl_converse: "(r^-1)^* = (r^*)^-1" | 
| 257 | by (fast dest!: rtrancl_converseD intro!: rtrancl_converseI) | |
| 258 | ||
| 19228 | 259 | lemma sym_rtrancl: "sym r ==> sym (r^*)" | 
| 260 | by (simp only: sym_conv_converse_eq rtrancl_converse [symmetric]) | |
| 261 | ||
| 34909 
a799687944af
Tuned some proofs; nicer case names for some of the induction / cases rules.
 berghofe parents: 
33878diff
changeset | 262 | theorem converse_rtranclp_induct [consumes 1, case_names base step]: | 
| 22262 | 263 | assumes major: "r^** a b" | 
| 264 | and cases: "P b" "!!y z. [| r y z; r^** z b; P z |] ==> P y" | |
| 12937 
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
 wenzelm parents: 
12823diff
changeset | 265 | shows "P a" | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 266 | using rtranclp_converseI [OF major] | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 267 | by induct (iprover intro: cases dest!: conversepD rtranclp_converseD)+ | 
| 12691 | 268 | |
| 25425 
9191942c4ead
Removed some case_names and consumes attributes that are now no longer
 berghofe parents: 
25295diff
changeset | 269 | lemmas converse_rtrancl_induct = converse_rtranclp_induct [to_set] | 
| 22262 | 270 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 271 | lemmas converse_rtranclp_induct2 = | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 272 | converse_rtranclp_induct [of _ "(ax,ay)" "(bx,by)", split_rule, | 
| 22262 | 273 | consumes 1, case_names refl step] | 
| 274 | ||
| 14404 
4952c5a92e04
Transitive_Closure: added consumes and case_names attributes
 nipkow parents: 
14398diff
changeset | 275 | lemmas converse_rtrancl_induct2 = | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 276 | converse_rtrancl_induct [of "(ax,ay)" "(bx,by)", split_format (complete), | 
| 14404 
4952c5a92e04
Transitive_Closure: added consumes and case_names attributes
 nipkow parents: 
14398diff
changeset | 277 | consumes 1, case_names refl step] | 
| 12691 | 278 | |
| 34909 
a799687944af
Tuned some proofs; nicer case names for some of the induction / cases rules.
 berghofe parents: 
33878diff
changeset | 279 | lemma converse_rtranclpE [consumes 1, case_names base step]: | 
| 22262 | 280 | assumes major: "r^** x z" | 
| 18372 | 281 | and cases: "x=z ==> P" | 
| 22262 | 282 | "!!y. [| r x y; r^** y z |] ==> P" | 
| 18372 | 283 | shows P | 
| 22262 | 284 | apply (subgoal_tac "x = z | (EX y. r x y & r^** y z)") | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 285 | apply (rule_tac [2] major [THEN converse_rtranclp_induct]) | 
| 18372 | 286 | prefer 2 apply iprover | 
| 287 | prefer 2 apply iprover | |
| 288 | apply (erule asm_rl exE disjE conjE cases)+ | |
| 289 | done | |
| 12691 | 290 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 291 | lemmas converse_rtranclE = converse_rtranclpE [to_set] | 
| 22262 | 292 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 293 | lemmas converse_rtranclpE2 = converse_rtranclpE [of _ "(xa,xb)" "(za,zb)", split_rule] | 
| 22262 | 294 | |
| 295 | lemmas converse_rtranclE2 = converse_rtranclE [of "(xa,xb)" "(za,zb)", split_rule] | |
| 12691 | 296 | |
| 297 | lemma r_comp_rtrancl_eq: "r O r^* = r^* O r" | |
| 298 | by (blast elim: rtranclE converse_rtranclE | |
| 299 | intro: rtrancl_into_rtrancl converse_rtrancl_into_rtrancl) | |
| 300 | ||
| 32235 
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
 krauss parents: 
32215diff
changeset | 301 | lemma rtrancl_unfold: "r^* = Id Un r^* O r" | 
| 15551 | 302 | by (auto intro: rtrancl_into_rtrancl elim: rtranclE) | 
| 303 | ||
| 31690 | 304 | lemma rtrancl_Un_separatorE: | 
| 305 | "(a,b) : (P \<union> Q)^* \<Longrightarrow> \<forall>x y. (a,x) : P^* \<longrightarrow> (x,y) : Q \<longrightarrow> x=y \<Longrightarrow> (a,b) : P^*" | |
| 306 | apply (induct rule:rtrancl.induct) | |
| 307 | apply blast | |
| 308 | apply (blast intro:rtrancl_trans) | |
| 309 | done | |
| 310 | ||
| 311 | lemma rtrancl_Un_separator_converseE: | |
| 312 | "(a,b) : (P \<union> Q)^* \<Longrightarrow> \<forall>x y. (x,b) : P^* \<longrightarrow> (y,x) : Q \<longrightarrow> y=x \<Longrightarrow> (a,b) : P^*" | |
| 313 | apply (induct rule:converse_rtrancl_induct) | |
| 314 | apply blast | |
| 315 | apply (blast intro:rtrancl_trans) | |
| 316 | done | |
| 317 | ||
| 34970 | 318 | lemma Image_closed_trancl: | 
| 319 | assumes "r `` X \<subseteq> X" shows "r\<^sup>* `` X = X" | |
| 320 | proof - | |
| 321 |   from assms have **: "{y. \<exists>x\<in>X. (x, y) \<in> r} \<subseteq> X" by auto
 | |
| 322 | have "\<And>x y. (y, x) \<in> r\<^sup>* \<Longrightarrow> y \<in> X \<Longrightarrow> x \<in> X" | |
| 323 | proof - | |
| 324 | fix x y | |
| 325 | assume *: "y \<in> X" | |
| 326 | assume "(y, x) \<in> r\<^sup>*" | |
| 327 | then show "x \<in> X" | |
| 328 | proof induct | |
| 329 | case base show ?case by (fact *) | |
| 330 | next | |
| 331 | case step with ** show ?case by auto | |
| 332 | qed | |
| 333 | qed | |
| 334 | then show ?thesis by auto | |
| 335 | qed | |
| 336 | ||
| 12691 | 337 | |
| 60758 | 338 | subsection \<open>Transitive closure\<close> | 
| 10331 | 339 | |
| 13704 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 340 | lemma trancl_mono: "!!p. p \<in> r^+ ==> r \<subseteq> s ==> p \<in> s^+" | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 341 | apply (simp add: split_tupled_all) | 
| 13704 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 342 | apply (erule trancl.induct) | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 343 | apply (iprover dest: subsetD)+ | 
| 12691 | 344 | done | 
| 345 | ||
| 57284 
886ff14f20cc
r_into_(r)trancl should not be [simp]: helps little and comlicates some AFP proofs
 nipkow parents: 
57283diff
changeset | 346 | lemma r_into_trancl': "!!p. p : r ==> p : r^+" | 
| 13704 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 347 | by (simp only: split_tupled_all) (erule r_into_trancl) | 
| 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 348 | |
| 60758 | 349 | text \<open> | 
| 12691 | 350 |   \medskip Conversions between @{text trancl} and @{text rtrancl}.
 | 
| 60758 | 351 | \<close> | 
| 12691 | 352 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 353 | lemma tranclp_into_rtranclp: "r^++ a b ==> r^** a b" | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 354 | by (erule tranclp.induct) iprover+ | 
| 12691 | 355 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 356 | lemmas trancl_into_rtrancl = tranclp_into_rtranclp [to_set] | 
| 22262 | 357 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 358 | lemma rtranclp_into_tranclp1: assumes r: "r^** a b" | 
| 22262 | 359 | shows "!!c. r b c ==> r^++ a c" using r | 
| 17589 | 360 | by induct iprover+ | 
| 12691 | 361 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 362 | lemmas rtrancl_into_trancl1 = rtranclp_into_tranclp1 [to_set] | 
| 22262 | 363 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 364 | lemma rtranclp_into_tranclp2: "[| r a b; r^** b c |] ==> r^++ a c" | 
| 60758 | 365 |   -- \<open>intro rule from @{text r} and @{text rtrancl}\<close>
 | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 366 | apply (erule rtranclp.cases) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 367 | apply iprover | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 368 | apply (rule rtranclp_trans [THEN rtranclp_into_tranclp1]) | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 369 | apply (simp | rule r_into_rtranclp)+ | 
| 12691 | 370 | done | 
| 371 | ||
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 372 | lemmas rtrancl_into_trancl2 = rtranclp_into_tranclp2 [to_set] | 
| 22262 | 373 | |
| 60758 | 374 | text \<open>Nice induction rule for @{text trancl}\<close>
 | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 375 | lemma tranclp_induct [consumes 1, case_names base step, induct pred: tranclp]: | 
| 34909 
a799687944af
Tuned some proofs; nicer case names for some of the induction / cases rules.
 berghofe parents: 
33878diff
changeset | 376 | assumes a: "r^++ a b" | 
| 22262 | 377 | and cases: "!!y. r a y ==> P y" | 
| 378 | "!!y z. r^++ a y ==> r y z ==> P y ==> P z" | |
| 34909 
a799687944af
Tuned some proofs; nicer case names for some of the induction / cases rules.
 berghofe parents: 
33878diff
changeset | 379 | shows "P b" using a | 
| 
a799687944af
Tuned some proofs; nicer case names for some of the induction / cases rules.
 berghofe parents: 
33878diff
changeset | 380 | by (induct x\<equiv>a b) (iprover intro: cases)+ | 
| 12691 | 381 | |
| 25425 
9191942c4ead
Removed some case_names and consumes attributes that are now no longer
 berghofe parents: 
25295diff
changeset | 382 | lemmas trancl_induct [induct set: trancl] = tranclp_induct [to_set] | 
| 22262 | 383 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 384 | lemmas tranclp_induct2 = | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 385 | tranclp_induct [of _ "(ax,ay)" "(bx,by)", split_rule, | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 386 | consumes 1, case_names base step] | 
| 22262 | 387 | |
| 22172 | 388 | lemmas trancl_induct2 = | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 389 | trancl_induct [of "(ax,ay)" "(bx,by)", split_format (complete), | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 390 | consumes 1, case_names base step] | 
| 22172 | 391 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 392 | lemma tranclp_trans_induct: | 
| 22262 | 393 | assumes major: "r^++ x y" | 
| 394 | and cases: "!!x y. r x y ==> P x y" | |
| 395 | "!!x y z. [| r^++ x y; P x y; r^++ y z; P y z |] ==> P x z" | |
| 18372 | 396 | shows "P x y" | 
| 60758 | 397 | -- \<open>Another induction rule for trancl, incorporating transitivity\<close> | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 398 | by (iprover intro: major [THEN tranclp_induct] cases) | 
| 12691 | 399 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 400 | lemmas trancl_trans_induct = tranclp_trans_induct [to_set] | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 401 | |
| 26174 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 402 | lemma tranclE [cases set: trancl]: | 
| 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 403 | assumes "(a, b) : r^+" | 
| 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 404 | obtains | 
| 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 405 | (base) "(a, b) : r" | 
| 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 406 | | (step) c where "(a, c) : r^+" and "(c, b) : r" | 
| 
9efd4c04eaa4
rtranclE, tranclE: tuned statement, added case_names;
 wenzelm parents: 
25425diff
changeset | 407 | using assms by cases simp_all | 
| 10980 | 408 | |
| 32235 
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
 krauss parents: 
32215diff
changeset | 409 | lemma trancl_Int_subset: "[| r \<subseteq> s; (r^+ \<inter> s) O r \<subseteq> s|] ==> r^+ \<subseteq> s" | 
| 22080 
7bf8868ab3e4
induction rules for trancl/rtrancl expressed using subsets
 paulson parents: 
21589diff
changeset | 410 | apply (rule subsetI) | 
| 61032 
b57df8eecad6
standardized some occurences of ancient "split" alias
 haftmann parents: 
60758diff
changeset | 411 | apply auto | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 412 | apply (erule trancl_induct) | 
| 61032 
b57df8eecad6
standardized some occurences of ancient "split" alias
 haftmann parents: 
60758diff
changeset | 413 | apply auto | 
| 22080 
7bf8868ab3e4
induction rules for trancl/rtrancl expressed using subsets
 paulson parents: 
21589diff
changeset | 414 | done | 
| 
7bf8868ab3e4
induction rules for trancl/rtrancl expressed using subsets
 paulson parents: 
21589diff
changeset | 415 | |
| 32235 
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
 krauss parents: 
32215diff
changeset | 416 | lemma trancl_unfold: "r^+ = r Un r^+ O r" | 
| 15551 | 417 | by (auto intro: trancl_into_trancl elim: tranclE) | 
| 418 | ||
| 60758 | 419 | text \<open>Transitivity of @{term "r^+"}\<close>
 | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 420 | lemma trans_trancl [simp]: "trans (r^+)" | 
| 13704 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 421 | proof (rule transI) | 
| 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 422 | fix x y z | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 423 | assume "(x, y) \<in> r^+" | 
| 13704 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 424 | assume "(y, z) \<in> r^+" | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 425 | then show "(x, z) \<in> r^+" | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 426 | proof induct | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 427 | case (base u) | 
| 60758 | 428 | from \<open>(x, y) \<in> r^+\<close> and \<open>(y, u) \<in> r\<close> | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 429 | show "(x, u) \<in> r^+" .. | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 430 | next | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 431 | case (step u v) | 
| 60758 | 432 | from \<open>(x, u) \<in> r^+\<close> and \<open>(u, v) \<in> r\<close> | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 433 | show "(x, v) \<in> r^+" .. | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 434 | qed | 
| 13704 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 435 | qed | 
| 12691 | 436 | |
| 45607 | 437 | lemmas trancl_trans = trans_trancl [THEN transD] | 
| 12691 | 438 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 439 | lemma tranclp_trans: | 
| 22262 | 440 | assumes xy: "r^++ x y" | 
| 441 | and yz: "r^++ y z" | |
| 442 | shows "r^++ x z" using yz xy | |
| 443 | by induct iprover+ | |
| 444 | ||
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 445 | lemma trancl_id [simp]: "trans r \<Longrightarrow> r^+ = r" | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 446 | apply auto | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 447 | apply (erule trancl_induct) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 448 | apply assumption | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 449 | apply (unfold trans_def) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 450 | apply blast | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 451 | done | 
| 19623 | 452 | |
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 453 | lemma rtranclp_tranclp_tranclp: | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 454 | assumes "r^** x y" | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 455 | shows "!!z. r^++ y z ==> r^++ x z" using assms | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 456 | by induct (iprover intro: tranclp_trans)+ | 
| 12691 | 457 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 458 | lemmas rtrancl_trancl_trancl = rtranclp_tranclp_tranclp [to_set] | 
| 22262 | 459 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 460 | lemma tranclp_into_tranclp2: "r a b ==> r^++ b c ==> r^++ a c" | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 461 | by (erule tranclp_trans [OF tranclp.r_into_trancl]) | 
| 22262 | 462 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 463 | lemmas trancl_into_trancl2 = tranclp_into_tranclp2 [to_set] | 
| 12691 | 464 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 465 | lemma tranclp_converseI: "(r^++)^--1 x y ==> (r^--1)^++ x y" | 
| 22262 | 466 | apply (drule conversepD) | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 467 | apply (erule tranclp_induct) | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 468 | apply (iprover intro: conversepI tranclp_trans)+ | 
| 12691 | 469 | done | 
| 470 | ||
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 471 | lemmas trancl_converseI = tranclp_converseI [to_set] | 
| 22262 | 472 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 473 | lemma tranclp_converseD: "(r^--1)^++ x y ==> (r^++)^--1 x y" | 
| 22262 | 474 | apply (rule conversepI) | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 475 | apply (erule tranclp_induct) | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 476 | apply (iprover dest: conversepD intro: tranclp_trans)+ | 
| 13704 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 477 | done | 
| 12691 | 478 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 479 | lemmas trancl_converseD = tranclp_converseD [to_set] | 
| 22262 | 480 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 481 | lemma tranclp_converse: "(r^--1)^++ = (r^++)^--1" | 
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
43596diff
changeset | 482 | by (fastforce simp add: fun_eq_iff | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 483 | intro!: tranclp_converseI dest!: tranclp_converseD) | 
| 22262 | 484 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 485 | lemmas trancl_converse = tranclp_converse [to_set] | 
| 12691 | 486 | |
| 19228 | 487 | lemma sym_trancl: "sym r ==> sym (r^+)" | 
| 488 | by (simp only: sym_conv_converse_eq trancl_converse [symmetric]) | |
| 489 | ||
| 34909 
a799687944af
Tuned some proofs; nicer case names for some of the induction / cases rules.
 berghofe parents: 
33878diff
changeset | 490 | lemma converse_tranclp_induct [consumes 1, case_names base step]: | 
| 22262 | 491 | assumes major: "r^++ a b" | 
| 492 | and cases: "!!y. r y b ==> P(y)" | |
| 493 | "!!y z.[| r y z; r^++ z b; P(z) |] ==> P(y)" | |
| 18372 | 494 | shows "P a" | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 495 | apply (rule tranclp_induct [OF tranclp_converseI, OF conversepI, OF major]) | 
| 18372 | 496 | apply (rule cases) | 
| 22262 | 497 | apply (erule conversepD) | 
| 35216 | 498 | apply (blast intro: assms dest!: tranclp_converseD) | 
| 18372 | 499 | done | 
| 12691 | 500 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 501 | lemmas converse_trancl_induct = converse_tranclp_induct [to_set] | 
| 22262 | 502 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 503 | lemma tranclpD: "R^++ x y ==> EX z. R x z \<and> R^** z y" | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 504 | apply (erule converse_tranclp_induct) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 505 | apply auto | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 506 | apply (blast intro: rtranclp_trans) | 
| 12691 | 507 | done | 
| 508 | ||
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 509 | lemmas tranclD = tranclpD [to_set] | 
| 22262 | 510 | |
| 31577 | 511 | lemma converse_tranclpE: | 
| 512 | assumes major: "tranclp r x z" | |
| 513 | assumes base: "r x z ==> P" | |
| 514 | assumes step: "\<And> y. [| r x y; tranclp r y z |] ==> P" | |
| 515 | shows P | |
| 516 | proof - | |
| 517 | from tranclpD[OF major] | |
| 518 | obtain y where "r x y" and "rtranclp r y z" by iprover | |
| 519 | from this(2) show P | |
| 520 | proof (cases rule: rtranclp.cases) | |
| 521 | case rtrancl_refl | |
| 60758 | 522 | with \<open>r x y\<close> base show P by iprover | 
| 31577 | 523 | next | 
| 524 | case rtrancl_into_rtrancl | |
| 525 | from this have "tranclp r y z" | |
| 526 | by (iprover intro: rtranclp_into_tranclp1) | |
| 60758 | 527 | with \<open>r x y\<close> step show P by iprover | 
| 31577 | 528 | qed | 
| 529 | qed | |
| 530 | ||
| 531 | lemmas converse_tranclE = converse_tranclpE [to_set] | |
| 532 | ||
| 25295 
12985023be5e
tranclD2 (tranclD at the other end) + trancl_power
 kleing parents: 
23743diff
changeset | 533 | lemma tranclD2: | 
| 
12985023be5e
tranclD2 (tranclD at the other end) + trancl_power
 kleing parents: 
23743diff
changeset | 534 | "(x, y) \<in> R\<^sup>+ \<Longrightarrow> \<exists>z. (x, z) \<in> R\<^sup>* \<and> (z, y) \<in> R" | 
| 
12985023be5e
tranclD2 (tranclD at the other end) + trancl_power
 kleing parents: 
23743diff
changeset | 535 | by (blast elim: tranclE intro: trancl_into_rtrancl) | 
| 
12985023be5e
tranclD2 (tranclD at the other end) + trancl_power
 kleing parents: 
23743diff
changeset | 536 | |
| 13867 | 537 | lemma irrefl_tranclI: "r^-1 \<inter> r^* = {} ==> (x, x) \<notin> r^+"
 | 
| 18372 | 538 | by (blast elim: tranclE dest: trancl_into_rtrancl) | 
| 12691 | 539 | |
| 540 | lemma irrefl_trancl_rD: "!!X. ALL x. (x, x) \<notin> r^+ ==> (x, y) \<in> r ==> x \<noteq> y" | |
| 541 | by (blast dest: r_into_trancl) | |
| 542 | ||
| 543 | lemma trancl_subset_Sigma_aux: | |
| 544 | "(a, b) \<in> r^* ==> r \<subseteq> A \<times> A ==> a = b \<or> a \<in> A" | |
| 18372 | 545 | by (induct rule: rtrancl_induct) auto | 
| 12691 | 546 | |
| 547 | lemma trancl_subset_Sigma: "r \<subseteq> A \<times> A ==> r^+ \<subseteq> A \<times> A" | |
| 13704 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 548 | apply (rule subsetI) | 
| 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 549 | apply (simp only: split_tupled_all) | 
| 
854501b1e957
Transitive closure is now defined inductively as well.
 berghofe parents: 
12937diff
changeset | 550 | apply (erule tranclE) | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 551 | apply (blast dest!: trancl_into_rtrancl trancl_subset_Sigma_aux)+ | 
| 12691 | 552 | done | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 553 | |
| 50616 | 554 | lemma reflclp_tranclp [simp]: "(r^++)^== = r^**" | 
| 22262 | 555 | apply (safe intro!: order_antisym) | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 556 | apply (erule tranclp_into_rtranclp) | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 557 | apply (blast elim: rtranclp.cases dest: rtranclp_into_tranclp1) | 
| 11084 | 558 | done | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 559 | |
| 50616 | 560 | lemmas reflcl_trancl [simp] = reflclp_tranclp [to_set] | 
| 22262 | 561 | |
| 11090 | 562 | lemma trancl_reflcl [simp]: "(r^=)^+ = r^*" | 
| 11084 | 563 | apply safe | 
| 14208 | 564 | apply (drule trancl_into_rtrancl, simp) | 
| 565 | apply (erule rtranclE, safe) | |
| 566 | apply (rule r_into_trancl, simp) | |
| 11084 | 567 | apply (rule rtrancl_into_trancl1) | 
| 14208 | 568 | apply (erule rtrancl_reflcl [THEN equalityD2, THEN subsetD], fast) | 
| 11084 | 569 | done | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 570 | |
| 45140 | 571 | lemma rtrancl_trancl_reflcl [code]: "r^* = (r^+)^=" | 
| 572 | by simp | |
| 573 | ||
| 11090 | 574 | lemma trancl_empty [simp]: "{}^+ = {}"
 | 
| 11084 | 575 | by (auto elim: trancl_induct) | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 576 | |
| 11090 | 577 | lemma rtrancl_empty [simp]: "{}^* = Id"
 | 
| 11084 | 578 | by (rule subst [OF reflcl_trancl]) simp | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 579 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 580 | lemma rtranclpD: "R^** a b ==> a = b \<or> a \<noteq> b \<and> R^++ a b" | 
| 50616 | 581 | by (force simp add: reflclp_tranclp [symmetric] simp del: reflclp_tranclp) | 
| 22262 | 582 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 583 | lemmas rtranclD = rtranclpD [to_set] | 
| 11084 | 584 | |
| 16514 | 585 | lemma rtrancl_eq_or_trancl: | 
| 586 | "(x,y) \<in> R\<^sup>* = (x=y \<or> x\<noteq>y \<and> (x,y) \<in> R\<^sup>+)" | |
| 587 | by (fast elim: trancl_into_rtrancl dest: rtranclD) | |
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 588 | |
| 33656 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 589 | lemma trancl_unfold_right: "r^+ = r^* O r" | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 590 | by (auto dest: tranclD2 intro: rtrancl_into_trancl1) | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 591 | |
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 592 | lemma trancl_unfold_left: "r^+ = r O r^*" | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 593 | by (auto dest: tranclD intro: rtrancl_into_trancl2) | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 594 | |
| 57178 | 595 | lemma trancl_insert: | 
| 596 |   "(insert (y, x) r)^+ = r^+ \<union> {(a, b). (a, y) \<in> r^* \<and> (x, b) \<in> r^*}"
 | |
| 60758 | 597 |   -- \<open>primitive recursion for @{text trancl} over finite relations\<close>
 | 
| 57178 | 598 | apply (rule equalityI) | 
| 599 | apply (rule subsetI) | |
| 600 | apply (simp only: split_tupled_all) | |
| 601 | apply (erule trancl_induct, blast) | |
| 602 | apply (blast intro: rtrancl_into_trancl1 trancl_into_rtrancl trancl_trans) | |
| 603 | apply (rule subsetI) | |
| 604 | apply (blast intro: trancl_mono rtrancl_mono | |
| 605 | [THEN [2] rev_subsetD] rtrancl_trancl_trancl rtrancl_into_trancl2) | |
| 606 | done | |
| 607 | ||
| 608 | lemma trancl_insert2: | |
| 609 |   "(insert (a,b) r)^+ = r^+ \<union> {(x,y). ((x,a) : r^+ \<or> x=a) \<and> ((b,y) \<in> r^+ \<or> y=b)}"
 | |
| 610 | by(auto simp add: trancl_insert rtrancl_eq_or_trancl) | |
| 611 | ||
| 612 | lemma rtrancl_insert: | |
| 613 |   "(insert (a,b) r)^* = r^* \<union> {(x,y). (x,a) : r^* \<and> (b,y) \<in> r^*}"
 | |
| 614 | using trancl_insert[of a b r] | |
| 615 | by(simp add: rtrancl_trancl_reflcl del: reflcl_trancl) blast | |
| 616 | ||
| 33656 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 617 | |
| 60758 | 618 | text \<open>Simplifying nested closures\<close> | 
| 33656 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 619 | |
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 620 | lemma rtrancl_trancl_absorb[simp]: "(R^*)^+ = R^*" | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 621 | by (simp add: trans_rtrancl) | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 622 | |
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 623 | lemma trancl_rtrancl_absorb[simp]: "(R^+)^* = R^*" | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 624 | by (subst reflcl_trancl[symmetric]) simp | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 625 | |
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 626 | lemma rtrancl_reflcl_absorb[simp]: "(R^*)^= = R^*" | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 627 | by auto | 
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 628 | |
| 
fc1af6753233
a few lemmas for point-free reasoning about transitive closure
 krauss parents: 
32901diff
changeset | 629 | |
| 60758 | 630 | text \<open>@{text Domain} and @{text Range}\<close>
 | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 631 | |
| 11090 | 632 | lemma Domain_rtrancl [simp]: "Domain (R^*) = UNIV" | 
| 11084 | 633 | by blast | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 634 | |
| 11090 | 635 | lemma Range_rtrancl [simp]: "Range (R^*) = UNIV" | 
| 11084 | 636 | by blast | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 637 | |
| 11090 | 638 | lemma rtrancl_Un_subset: "(R^* \<union> S^*) \<subseteq> (R Un S)^*" | 
| 11084 | 639 | by (rule rtrancl_Un_rtrancl [THEN subst]) fast | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 640 | |
| 11090 | 641 | lemma in_rtrancl_UnI: "x \<in> R^* \<or> x \<in> S^* ==> x \<in> (R \<union> S)^*" | 
| 11084 | 642 | by (blast intro: subsetD [OF rtrancl_Un_subset]) | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 643 | |
| 11090 | 644 | lemma trancl_domain [simp]: "Domain (r^+) = Domain r" | 
| 46752 
e9e7209eb375
more fundamental pred-to-set conversions, particularly by means of inductive_set; associated consolidation of some theorem names (c.f. NEWS)
 haftmann parents: 
46664diff
changeset | 645 | by (unfold Domain_unfold) (blast dest: tranclD) | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 646 | |
| 11090 | 647 | lemma trancl_range [simp]: "Range (r^+) = Range r" | 
| 46752 
e9e7209eb375
more fundamental pred-to-set conversions, particularly by means of inductive_set; associated consolidation of some theorem names (c.f. NEWS)
 haftmann parents: 
46664diff
changeset | 648 | unfolding Domain_converse [symmetric] by (simp add: trancl_converse [symmetric]) | 
| 10996 
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
 nipkow parents: 
10980diff
changeset | 649 | |
| 11115 | 650 | lemma Not_Domain_rtrancl: | 
| 12691 | 651 | "x ~: Domain R ==> ((x, y) : R^*) = (x = y)" | 
| 652 | apply auto | |
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 653 | apply (erule rev_mp) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 654 | apply (erule rtrancl_induct) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 655 | apply auto | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 656 | done | 
| 11327 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 berghofe parents: 
11115diff
changeset | 657 | |
| 29609 | 658 | lemma trancl_subset_Field2: "r^+ <= Field r \<times> Field r" | 
| 659 | apply clarify | |
| 660 | apply (erule trancl_induct) | |
| 661 | apply (auto simp add: Field_def) | |
| 662 | done | |
| 663 | ||
| 41987 | 664 | lemma finite_trancl[simp]: "finite (r^+) = finite r" | 
| 29609 | 665 | apply auto | 
| 666 | prefer 2 | |
| 667 | apply (rule trancl_subset_Field2 [THEN finite_subset]) | |
| 668 | apply (rule finite_SigmaI) | |
| 669 | prefer 3 | |
| 670 | apply (blast intro: r_into_trancl' finite_subset) | |
| 671 | apply (auto simp add: finite_Field) | |
| 672 | done | |
| 673 | ||
| 60758 | 674 | text \<open>More about converse @{text rtrancl} and @{text trancl}, should
 | 
| 675 | be merged with main body.\<close> | |
| 12428 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 676 | |
| 14337 
e13731554e50
undid split_comp_eq[simp] because it leads to nontermination together with split_def!
 nipkow parents: 
14208diff
changeset | 677 | lemma single_valued_confluent: | 
| 
e13731554e50
undid split_comp_eq[simp] because it leads to nontermination together with split_def!
 nipkow parents: 
14208diff
changeset | 678 | "\<lbrakk> single_valued r; (x,y) \<in> r^*; (x,z) \<in> r^* \<rbrakk> | 
| 
e13731554e50
undid split_comp_eq[simp] because it leads to nontermination together with split_def!
 nipkow parents: 
14208diff
changeset | 679 | \<Longrightarrow> (y,z) \<in> r^* \<or> (z,y) \<in> r^*" | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 680 | apply (erule rtrancl_induct) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 681 | apply simp | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 682 | apply (erule disjE) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 683 | apply (blast elim:converse_rtranclE dest:single_valuedD) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 684 | apply(blast intro:rtrancl_trans) | 
| 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 685 | done | 
| 14337 
e13731554e50
undid split_comp_eq[simp] because it leads to nontermination together with split_def!
 nipkow parents: 
14208diff
changeset | 686 | |
| 12691 | 687 | lemma r_r_into_trancl: "(a, b) \<in> R ==> (b, c) \<in> R ==> (a, c) \<in> R^+" | 
| 12428 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 688 | by (fast intro: trancl_trans) | 
| 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 689 | |
| 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 690 | lemma trancl_into_trancl [rule_format]: | 
| 12691 | 691 | "(a, b) \<in> r\<^sup>+ ==> (b, c) \<in> r --> (a,c) \<in> r\<^sup>+" | 
| 692 | apply (erule trancl_induct) | |
| 12428 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 693 | apply (fast intro: r_r_into_trancl) | 
| 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 694 | apply (fast intro: r_r_into_trancl trancl_trans) | 
| 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 695 | done | 
| 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 696 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 697 | lemma tranclp_rtranclp_tranclp: | 
| 22262 | 698 | "r\<^sup>+\<^sup>+ a b ==> r\<^sup>*\<^sup>* b c ==> r\<^sup>+\<^sup>+ a c" | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 699 | apply (drule tranclpD) | 
| 26179 
bc5d582d6cfe
rtranclp_induct, tranclp_induct: added case_names;
 wenzelm parents: 
26174diff
changeset | 700 | apply (elim exE conjE) | 
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 701 | apply (drule rtranclp_trans, assumption) | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 702 | apply (drule rtranclp_into_tranclp2, assumption, assumption) | 
| 12428 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 703 | done | 
| 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 704 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 705 | lemmas trancl_rtrancl_trancl = tranclp_rtranclp_tranclp [to_set] | 
| 22262 | 706 | |
| 12691 | 707 | lemmas transitive_closure_trans [trans] = | 
| 708 | r_r_into_trancl trancl_trans rtrancl_trans | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 709 | trancl.trancl_into_trancl trancl_into_trancl2 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 710 | rtrancl.rtrancl_into_rtrancl converse_rtrancl_into_rtrancl | 
| 12691 | 711 | rtrancl_trancl_trancl trancl_rtrancl_trancl | 
| 12428 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 712 | |
| 23743 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 713 | lemmas transitive_closurep_trans' [trans] = | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 714 | tranclp_trans rtranclp_trans | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 715 | tranclp.trancl_into_trancl tranclp_into_tranclp2 | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 716 | rtranclp.rtrancl_into_rtrancl converse_rtranclp_into_rtranclp | 
| 
52fbc991039f
rtrancl and trancl are now defined using inductive_set.
 berghofe parents: 
22422diff
changeset | 717 | rtranclp_tranclp_tranclp tranclp_rtranclp_tranclp | 
| 22262 | 718 | |
| 12428 
f3033eed309a
setup [trans] rules for calculational Isar reasoning
 kleing parents: 
11327diff
changeset | 719 | declare trancl_into_rtrancl [elim] | 
| 11327 
cd2c27a23df1
Transitive closure is now defined via "inductive".
 berghofe parents: 
11115diff
changeset | 720 | |
| 60758 | 721 | subsection \<open>The power operation on relations\<close> | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 722 | |
| 60758 | 723 | text \<open>@{text "R ^^ n = R O ... O R"}, the n-fold composition of @{text R}\<close>
 | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 724 | |
| 30971 | 725 | overloading | 
| 726 |   relpow == "compow :: nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set"
 | |
| 47202 | 727 |   relpowp == "compow :: nat \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool)"
 | 
| 30971 | 728 | begin | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 729 | |
| 55575 
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
 blanchet parents: 
55534diff
changeset | 730 | primrec relpow :: "nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set" where
 | 
| 30971 | 731 | "relpow 0 R = Id" | 
| 32235 
8f9b8d14fc9f
"more standard" argument order of relation composition (op O)
 krauss parents: 
32215diff
changeset | 732 | | "relpow (Suc n) R = (R ^^ n) O R" | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 733 | |
| 55575 
a5e33e18fb5c
moved 'primrec' up (for real this time) and removed temporary 'old_primrec'
 blanchet parents: 
55534diff
changeset | 734 | primrec relpowp :: "nat \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool)" where
 | 
| 47202 | 735 | "relpowp 0 R = HOL.eq" | 
| 736 | | "relpowp (Suc n) R = (R ^^ n) OO R" | |
| 737 | ||
| 30971 | 738 | end | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 739 | |
| 47202 | 740 | lemma relpowp_relpow_eq [pred_set_conv]: | 
| 741 | fixes R :: "'a rel" | |
| 742 | shows "(\<lambda>x y. (x, y) \<in> R) ^^ n = (\<lambda>x y. (x, y) \<in> R ^^ n)" | |
| 47433 
07f4bf913230
renamed "rel_comp" to "relcomp" (to be consistent with, e.g., "relpow")
 griff parents: 
47202diff
changeset | 743 | by (induct n) (simp_all add: relcompp_relcomp_eq) | 
| 47202 | 744 | |
| 60758 | 745 | text \<open>for code generation\<close> | 
| 46360 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 746 | |
| 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 747 | definition relpow :: "nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set" where
 | 
| 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 748 | relpow_code_def [code_abbrev]: "relpow = compow" | 
| 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 749 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 750 | definition relpowp :: "nat \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool)" where
 | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 751 | relpowp_code_def [code_abbrev]: "relpowp = compow" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 752 | |
| 46360 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 753 | lemma [code]: | 
| 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 754 | "relpow (Suc n) R = (relpow n R) O R" | 
| 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 755 | "relpow 0 R = Id" | 
| 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 756 | by (simp_all add: relpow_code_def) | 
| 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 757 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 758 | lemma [code]: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 759 | "relpowp (Suc n) R = (R ^^ n) OO R" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 760 | "relpowp 0 R = HOL.eq" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 761 | by (simp_all add: relpowp_code_def) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 762 | |
| 46360 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 763 | hide_const (open) relpow | 
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 764 | hide_const (open) relpowp | 
| 46360 
5cb81e3fa799
adding code generation for relpow by copying the ideas for code generation of funpow
 bulwahn parents: 
46347diff
changeset | 765 | |
| 46362 | 766 | lemma relpow_1 [simp]: | 
| 30971 | 767 |   fixes R :: "('a \<times> 'a) set"
 | 
| 768 | shows "R ^^ 1 = R" | |
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 769 | by simp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 770 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 771 | lemma relpowp_1 [simp]: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 772 | fixes P :: "'a \<Rightarrow> 'a \<Rightarrow> bool" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 773 | shows "P ^^ 1 = P" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 774 | by (fact relpow_1 [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 775 | |
| 46362 | 776 | lemma relpow_0_I: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 777 | "(x, x) \<in> R ^^ 0" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 778 | by simp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 779 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 780 | lemma relpowp_0_I: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 781 | "(P ^^ 0) x x" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 782 | by (fact relpow_0_I [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 783 | |
| 46362 | 784 | lemma relpow_Suc_I: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 785 | "(x, y) \<in> R ^^ n \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> (x, z) \<in> R ^^ Suc n" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 786 | by auto | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 787 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 788 | lemma relpowp_Suc_I: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 789 | "(P ^^ n) x y \<Longrightarrow> P y z \<Longrightarrow> (P ^^ Suc n) x z" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 790 | by (fact relpow_Suc_I [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 791 | |
| 46362 | 792 | lemma relpow_Suc_I2: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 793 | "(x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ n \<Longrightarrow> (x, z) \<in> R ^^ Suc n" | 
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
43596diff
changeset | 794 | by (induct n arbitrary: z) (simp, fastforce) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 795 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 796 | lemma relpowp_Suc_I2: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 797 | "P x y \<Longrightarrow> (P ^^ n) y z \<Longrightarrow> (P ^^ Suc n) x z" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 798 | by (fact relpow_Suc_I2 [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 799 | |
| 46362 | 800 | lemma relpow_0_E: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 801 | "(x, y) \<in> R ^^ 0 \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> P" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 802 | by simp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 803 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 804 | lemma relpowp_0_E: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 805 | "(P ^^ 0) x y \<Longrightarrow> (x = y \<Longrightarrow> Q) \<Longrightarrow> Q" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 806 | by (fact relpow_0_E [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 807 | |
| 46362 | 808 | lemma relpow_Suc_E: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 809 | "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<And>y. (x, y) \<in> R ^^ n \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> P) \<Longrightarrow> P" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 810 | by auto | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 811 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 812 | lemma relpowp_Suc_E: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 813 | "(P ^^ Suc n) x z \<Longrightarrow> (\<And>y. (P ^^ n) x y \<Longrightarrow> P y z \<Longrightarrow> Q) \<Longrightarrow> Q" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 814 | by (fact relpow_Suc_E [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 815 | |
| 46362 | 816 | lemma relpow_E: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 817 | "(x, z) \<in> R ^^ n \<Longrightarrow> (n = 0 \<Longrightarrow> x = z \<Longrightarrow> P) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 818 | \<Longrightarrow> (\<And>y m. n = Suc m \<Longrightarrow> (x, y) \<in> R ^^ m \<Longrightarrow> (y, z) \<in> R \<Longrightarrow> P) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 819 | \<Longrightarrow> P" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 820 | by (cases n) auto | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 821 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 822 | lemma relpowp_E: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 823 | "(P ^^ n) x z \<Longrightarrow> (n = 0 \<Longrightarrow> x = z \<Longrightarrow> Q) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 824 | \<Longrightarrow> (\<And>y m. n = Suc m \<Longrightarrow> (P ^^ m) x y \<Longrightarrow> P y z \<Longrightarrow> Q) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 825 | \<Longrightarrow> Q" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 826 | by (fact relpow_E [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 827 | |
| 46362 | 828 | lemma relpow_Suc_D2: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 829 | "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<exists>y. (x, y) \<in> R \<and> (y, z) \<in> R ^^ n)" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 830 | apply (induct n arbitrary: x z) | 
| 46362 | 831 | apply (blast intro: relpow_0_I elim: relpow_0_E relpow_Suc_E) | 
| 832 | apply (blast intro: relpow_Suc_I elim: relpow_0_E relpow_Suc_E) | |
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 833 | done | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 834 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 835 | lemma relpowp_Suc_D2: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 836 | "(P ^^ Suc n) x z \<Longrightarrow> \<exists>y. P x y \<and> (P ^^ n) y z" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 837 | by (fact relpow_Suc_D2 [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 838 | |
| 46362 | 839 | lemma relpow_Suc_E2: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 840 | "(x, z) \<in> R ^^ Suc n \<Longrightarrow> (\<And>y. (x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ n \<Longrightarrow> P) \<Longrightarrow> P" | 
| 46362 | 841 | by (blast dest: relpow_Suc_D2) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 842 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 843 | lemma relpowp_Suc_E2: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 844 | "(P ^^ Suc n) x z \<Longrightarrow> (\<And>y. P x y \<Longrightarrow> (P ^^ n) y z \<Longrightarrow> Q) \<Longrightarrow> Q" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 845 | by (fact relpow_Suc_E2 [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 846 | |
| 46362 | 847 | lemma relpow_Suc_D2': | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 848 | "\<forall>x y z. (x, y) \<in> R ^^ n \<and> (y, z) \<in> R \<longrightarrow> (\<exists>w. (x, w) \<in> R \<and> (w, z) \<in> R ^^ n)" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 849 | by (induct n) (simp_all, blast) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 850 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 851 | lemma relpowp_Suc_D2': | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 852 | "\<forall>x y z. (P ^^ n) x y \<and> P y z \<longrightarrow> (\<exists>w. P x w \<and> (P ^^ n) w z)" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 853 | by (fact relpow_Suc_D2' [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 854 | |
| 46362 | 855 | lemma relpow_E2: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 856 | "(x, z) \<in> R ^^ n \<Longrightarrow> (n = 0 \<Longrightarrow> x = z \<Longrightarrow> P) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 857 | \<Longrightarrow> (\<And>y m. n = Suc m \<Longrightarrow> (x, y) \<in> R \<Longrightarrow> (y, z) \<in> R ^^ m \<Longrightarrow> P) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 858 | \<Longrightarrow> P" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 859 | apply (cases n, simp) | 
| 55417 
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
 blanchet parents: 
54412diff
changeset | 860 | apply (rename_tac nat) | 
| 46362 | 861 | apply (cut_tac n=nat and R=R in relpow_Suc_D2', simp, blast) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 862 | done | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 863 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 864 | lemma relpowp_E2: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 865 | "(P ^^ n) x z \<Longrightarrow> (n = 0 \<Longrightarrow> x = z \<Longrightarrow> Q) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 866 | \<Longrightarrow> (\<And>y m. n = Suc m \<Longrightarrow> P x y \<Longrightarrow> (P ^^ m) y z \<Longrightarrow> Q) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 867 | \<Longrightarrow> Q" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 868 | by (fact relpow_E2 [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 869 | |
| 46362 | 870 | lemma relpow_add: "R ^^ (m+n) = R^^m O R^^n" | 
| 45976 | 871 | by (induct n) auto | 
| 31351 | 872 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 873 | lemma relpowp_add: "P ^^ (m + n) = P ^^ m OO P ^^ n" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 874 | by (fact relpow_add [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 875 | |
| 46362 | 876 | lemma relpow_commute: "R O R ^^ n = R ^^ n O R" | 
| 45976 | 877 | by (induct n) (simp, simp add: O_assoc [symmetric]) | 
| 31970 
ccaadfcf6941
move rel_pow_commute: "R O R ^^ n = R ^^ n O R" to Transitive_Closure
 krauss parents: 
31690diff
changeset | 878 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 879 | lemma relpowp_commute: "P OO P ^^ n = P ^^ n OO P" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 880 | by (fact relpow_commute [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 881 | |
| 46362 | 882 | lemma relpow_empty: | 
| 45153 | 883 |   "0 < n \<Longrightarrow> ({} :: ('a \<times> 'a) set) ^^ n = {}"
 | 
| 884 | by (cases n) auto | |
| 45116 
f947eeef6b6f
adding lemma about rel_pow in Transitive_Closure for executable equation of the (refl) transitive closure
 bulwahn parents: 
44921diff
changeset | 885 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 886 | lemma relpowp_bot: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 887 | "0 < n \<Longrightarrow> (\<bottom> :: 'a \<Rightarrow> 'a \<Rightarrow> bool) ^^ n = \<bottom>" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 888 | by (fact relpow_empty [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 889 | |
| 46362 | 890 | lemma rtrancl_imp_UN_relpow: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 891 | assumes "p \<in> R^*" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 892 | shows "p \<in> (\<Union>n. R ^^ n)" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 893 | proof (cases p) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 894 | case (Pair x y) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 895 | with assms have "(x, y) \<in> R^*" by simp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 896 | then have "(x, y) \<in> (\<Union>n. R ^^ n)" proof induct | 
| 46362 | 897 | case base show ?case by (blast intro: relpow_0_I) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 898 | next | 
| 46362 | 899 | case step then show ?case by (blast intro: relpow_Suc_I) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 900 | qed | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 901 | with Pair show ?thesis by simp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 902 | qed | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 903 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 904 | lemma rtranclp_imp_Sup_relpowp: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 905 | assumes "(P^**) x y" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 906 | shows "(\<Squnion>n. P ^^ n) x y" | 
| 61424 
c3658c18b7bc
prod_case as canonical name for product type eliminator
 haftmann parents: 
61378diff
changeset | 907 | using assms and rtrancl_imp_UN_relpow [of "(x, y)", to_pred] by simp | 
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 908 | |
| 46362 | 909 | lemma relpow_imp_rtrancl: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 910 | assumes "p \<in> R ^^ n" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 911 | shows "p \<in> R^*" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 912 | proof (cases p) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 913 | case (Pair x y) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 914 | with assms have "(x, y) \<in> R ^^ n" by simp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 915 | then have "(x, y) \<in> R^*" proof (induct n arbitrary: x y) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 916 | case 0 then show ?case by simp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 917 | next | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 918 | case Suc then show ?case | 
| 46362 | 919 | by (blast elim: relpow_Suc_E intro: rtrancl_into_rtrancl) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 920 | qed | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 921 | with Pair show ?thesis by simp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 922 | qed | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 923 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 924 | lemma relpowp_imp_rtranclp: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 925 | assumes "(P ^^ n) x y" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 926 | shows "(P^**) x y" | 
| 61424 
c3658c18b7bc
prod_case as canonical name for product type eliminator
 haftmann parents: 
61378diff
changeset | 927 | using assms and relpow_imp_rtrancl [of "(x, y)", to_pred] by simp | 
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 928 | |
| 46362 | 929 | lemma rtrancl_is_UN_relpow: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 930 | "R^* = (\<Union>n. R ^^ n)" | 
| 46362 | 931 | by (blast intro: rtrancl_imp_UN_relpow relpow_imp_rtrancl) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 932 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 933 | lemma rtranclp_is_Sup_relpowp: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 934 | "P^** = (\<Squnion>n. P ^^ n)" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 935 | using rtrancl_is_UN_relpow [to_pred, of P] by auto | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 936 | |
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 937 | lemma rtrancl_power: | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 938 | "p \<in> R^* \<longleftrightarrow> (\<exists>n. p \<in> R ^^ n)" | 
| 46362 | 939 | by (simp add: rtrancl_is_UN_relpow) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 940 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 941 | lemma rtranclp_power: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 942 | "(P^**) x y \<longleftrightarrow> (\<exists>n. (P ^^ n) x y)" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 943 | by (simp add: rtranclp_is_Sup_relpowp) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 944 | |
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 945 | lemma trancl_power: | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 946 | "p \<in> R^+ \<longleftrightarrow> (\<exists>n > 0. p \<in> R ^^ n)" | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 947 | apply (cases p) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 948 | apply simp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 949 | apply (rule iffI) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 950 | apply (drule tranclD2) | 
| 46362 | 951 | apply (clarsimp simp: rtrancl_is_UN_relpow) | 
| 30971 | 952 | apply (rule_tac x="Suc n" in exI) | 
| 47433 
07f4bf913230
renamed "rel_comp" to "relcomp" (to be consistent with, e.g., "relpow")
 griff parents: 
47202diff
changeset | 953 | apply (clarsimp simp: relcomp_unfold) | 
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
43596diff
changeset | 954 | apply fastforce | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 955 | apply clarsimp | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 956 | apply (case_tac n, simp) | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 957 | apply clarsimp | 
| 46362 | 958 | apply (drule relpow_imp_rtrancl) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 959 | apply (drule rtrancl_into_trancl1) apply auto | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 960 | done | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 961 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 962 | lemma tranclp_power: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 963 | "(P^++) x y \<longleftrightarrow> (\<exists>n > 0. (P ^^ n) x y)" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 964 | using trancl_power [to_pred, of P "(x, y)"] by simp | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 965 | |
| 46362 | 966 | lemma rtrancl_imp_relpow: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 967 | "p \<in> R^* \<Longrightarrow> \<exists>n. p \<in> R ^^ n" | 
| 46362 | 968 | by (auto dest: rtrancl_imp_UN_relpow) | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 969 | |
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 970 | lemma rtranclp_imp_relpowp: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 971 | "(P^**) x y \<Longrightarrow> \<exists>n. (P ^^ n) x y" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 972 | by (auto dest: rtranclp_imp_Sup_relpowp) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 973 | |
| 60758 | 974 | text\<open>By Sternagel/Thiemann:\<close> | 
| 46362 | 975 | lemma relpow_fun_conv: | 
| 41987 | 976 | "((a,b) \<in> R ^^ n) = (\<exists>f. f 0 = a \<and> f n = b \<and> (\<forall>i<n. (f i, f(Suc i)) \<in> R))" | 
| 977 | proof (induct n arbitrary: b) | |
| 978 | case 0 show ?case by auto | |
| 979 | next | |
| 980 | case (Suc n) | |
| 981 | show ?case | |
| 47433 
07f4bf913230
renamed "rel_comp" to "relcomp" (to be consistent with, e.g., "relpow")
 griff parents: 
47202diff
changeset | 982 | proof (simp add: relcomp_unfold Suc) | 
| 41987 | 983 | show "(\<exists>y. (\<exists>f. f 0 = a \<and> f n = y \<and> (\<forall>i<n. (f i,f(Suc i)) \<in> R)) \<and> (y,b) \<in> R) | 
| 984 | = (\<exists>f. f 0 = a \<and> f(Suc n) = b \<and> (\<forall>i<Suc n. (f i, f (Suc i)) \<in> R))" | |
| 985 | (is "?l = ?r") | |
| 986 | proof | |
| 987 | assume ?l | |
| 988 | then obtain c f where 1: "f 0 = a" "f n = c" "\<And>i. i < n \<Longrightarrow> (f i, f (Suc i)) \<in> R" "(c,b) \<in> R" by auto | |
| 989 | let ?g = "\<lambda> m. if m = Suc n then b else f m" | |
| 990 | show ?r by (rule exI[of _ ?g], simp add: 1) | |
| 991 | next | |
| 992 | assume ?r | |
| 993 | then obtain f where 1: "f 0 = a" "b = f (Suc n)" "\<And>i. i < Suc n \<Longrightarrow> (f i, f (Suc i)) \<in> R" by auto | |
| 994 | show ?l by (rule exI[of _ "f n"], rule conjI, rule exI[of _ f], insert 1, auto) | |
| 995 | qed | |
| 996 | qed | |
| 997 | qed | |
| 998 | ||
| 47492 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 999 | lemma relpowp_fun_conv: | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 1000 | "(P ^^ n) x y \<longleftrightarrow> (\<exists>f. f 0 = x \<and> f n = y \<and> (\<forall>i<n. P (f i) (f (Suc i))))" | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 1001 | by (fact relpow_fun_conv [to_pred]) | 
| 
2631a12fb2d1
duplicate "relpow" facts for "relpowp" (to emphasize that both worlds exist and obtain better search results with "find_theorems")
 Christian Sternagel parents: 
47433diff
changeset | 1002 | |
| 46362 | 1003 | lemma relpow_finite_bounded1: | 
| 41987 | 1004 | assumes "finite(R :: ('a*'a)set)" and "k>0"
 | 
| 1005 | shows "R^^k \<subseteq> (UN n:{n. 0<n & n <= card R}. R^^n)" (is "_ \<subseteq> ?r")
 | |
| 1006 | proof- | |
| 1007 |   { fix a b k
 | |
| 1008 | have "(a,b) : R^^(Suc k) \<Longrightarrow> EX n. 0<n & n <= card R & (a,b) : R^^n" | |
| 1009 | proof(induct k arbitrary: b) | |
| 1010 | case 0 | |
| 1011 |       hence "R \<noteq> {}" by auto
 | |
| 60758 | 1012 | with card_0_eq[OF \<open>finite R\<close>] have "card R >= Suc 0" by auto | 
| 41987 | 1013 | thus ?case using 0 by force | 
| 1014 | next | |
| 1015 | case (Suc k) | |
| 1016 | then obtain a' where "(a,a') : R^^(Suc k)" and "(a',b) : R" by auto | |
| 60758 | 1017 | from Suc(1)[OF \<open>(a,a') : R^^(Suc k)\<close>] | 
| 41987 | 1018 | obtain n where "n \<le> card R" and "(a,a') \<in> R ^^ n" by auto | 
| 60758 | 1019 | have "(a,b) : R^^(Suc n)" using \<open>(a,a') \<in> R^^n\<close> and \<open>(a',b)\<in> R\<close> by auto | 
| 41987 | 1020 |       { assume "n < card R"
 | 
| 60758 | 1021 | hence ?case using \<open>(a,b): R^^(Suc n)\<close> Suc_leI[OF \<open>n < card R\<close>] by blast | 
| 41987 | 1022 | } moreover | 
| 1023 |       { assume "n = card R"
 | |
| 60758 | 1024 | from \<open>(a,b) \<in> R ^^ (Suc n)\<close>[unfolded relpow_fun_conv] | 
| 41987 | 1025 | obtain f where "f 0 = a" and "f(Suc n) = b" | 
| 1026 | and steps: "\<And>i. i <= n \<Longrightarrow> (f i, f (Suc i)) \<in> R" by auto | |
| 1027 | let ?p = "%i. (f i, f(Suc i))" | |
| 1028 |         let ?N = "{i. i \<le> n}"
 | |
| 1029 | have "?p ` ?N <= R" using steps by auto | |
| 1030 | from card_mono[OF assms(1) this] | |
| 1031 | have "card(?p ` ?N) <= card R" . | |
| 60758 | 1032 | also have "\<dots> < card ?N" using \<open>n = card R\<close> by simp | 
| 41987 | 1033 | finally have "~ inj_on ?p ?N" by(rule pigeonhole) | 
| 1034 | then obtain i j where i: "i <= n" and j: "j <= n" and ij: "i \<noteq> j" and | |
| 1035 | pij: "?p i = ?p j" by(auto simp: inj_on_def) | |
| 1036 | let ?i = "min i j" let ?j = "max i j" | |
| 1037 | have i: "?i <= n" and j: "?j <= n" and pij: "?p ?i = ?p ?j" | |
| 1038 | and ij: "?i < ?j" | |
| 1039 | using i j ij pij unfolding min_def max_def by auto | |
| 1040 | from i j pij ij obtain i j where i: "i<=n" and j: "j<=n" and ij: "i<j" | |
| 1041 | and pij: "?p i = ?p j" by blast | |
| 1042 | let ?g = "\<lambda> l. if l \<le> i then f l else f (l + (j - i))" | |
| 1043 | let ?n = "Suc(n - (j - i))" | |
| 46362 | 1044 | have abl: "(a,b) \<in> R ^^ ?n" unfolding relpow_fun_conv | 
| 41987 | 1045 | proof (rule exI[of _ ?g], intro conjI impI allI) | 
| 60758 | 1046 | show "?g ?n = b" using \<open>f(Suc n) = b\<close> j ij by auto | 
| 41987 | 1047 | next | 
| 1048 | fix k assume "k < ?n" | |
| 1049 | show "(?g k, ?g (Suc k)) \<in> R" | |
| 1050 | proof (cases "k < i") | |
| 1051 | case True | |
| 1052 | with i have "k <= n" by auto | |
| 1053 | from steps[OF this] show ?thesis using True by simp | |
| 1054 | next | |
| 1055 | case False | |
| 1056 | hence "i \<le> k" by auto | |
| 1057 | show ?thesis | |
| 1058 | proof (cases "k = i") | |
| 1059 | case True | |
| 1060 | thus ?thesis using ij pij steps[OF i] by simp | |
| 1061 | next | |
| 1062 | case False | |
| 60758 | 1063 | with \<open>i \<le> k\<close> have "i < k" by auto | 
| 1064 | hence small: "k + (j - i) <= n" using \<open>k<?n\<close> by arith | |
| 1065 | show ?thesis using steps[OF small] \<open>i<k\<close> by auto | |
| 41987 | 1066 | qed | 
| 1067 | qed | |
| 60758 | 1068 | qed (simp add: \<open>f 0 = a\<close>) | 
| 41987 | 1069 | moreover have "?n <= n" using i j ij by arith | 
| 60758 | 1070 | ultimately have ?case using \<open>n = card R\<close> by blast | 
| 41987 | 1071 | } | 
| 60758 | 1072 | ultimately show ?case using \<open>n \<le> card R\<close> by force | 
| 41987 | 1073 | qed | 
| 1074 | } | |
| 60758 | 1075 | thus ?thesis using gr0_implies_Suc[OF \<open>k>0\<close>] by auto | 
| 41987 | 1076 | qed | 
| 1077 | ||
| 46362 | 1078 | lemma relpow_finite_bounded: | 
| 41987 | 1079 | assumes "finite(R :: ('a*'a)set)"
 | 
| 1080 | shows "R^^k \<subseteq> (UN n:{n. n <= card R}. R^^n)"
 | |
| 1081 | apply(cases k) | |
| 1082 | apply force | |
| 46362 | 1083 | using relpow_finite_bounded1[OF assms, of k] by auto | 
| 41987 | 1084 | |
| 46362 | 1085 | lemma rtrancl_finite_eq_relpow: | 
| 41987 | 1086 |   "finite R \<Longrightarrow> R^* = (UN n : {n. n <= card R}. R^^n)"
 | 
| 46362 | 1087 | by(fastforce simp: rtrancl_power dest: relpow_finite_bounded) | 
| 41987 | 1088 | |
| 46362 | 1089 | lemma trancl_finite_eq_relpow: | 
| 41987 | 1090 |   "finite R \<Longrightarrow> R^+ = (UN n : {n. 0 < n & n <= card R}. R^^n)"
 | 
| 1091 | apply(auto simp add: trancl_power) | |
| 46362 | 1092 | apply(auto dest: relpow_finite_bounded1) | 
| 41987 | 1093 | done | 
| 1094 | ||
| 47433 
07f4bf913230
renamed "rel_comp" to "relcomp" (to be consistent with, e.g., "relpow")
 griff parents: 
47202diff
changeset | 1095 | lemma finite_relcomp[simp,intro]: | 
| 41987 | 1096 | assumes "finite R" and "finite S" | 
| 1097 | shows "finite(R O S)" | |
| 1098 | proof- | |
| 1099 |   have "R O S = (UN (x,y) : R. \<Union>((%(u,v). if u=y then {(x,v)} else {}) ` S))"
 | |
| 1100 | by(force simp add: split_def) | |
| 1101 | thus ?thesis using assms by(clarsimp) | |
| 1102 | qed | |
| 1103 | ||
| 1104 | lemma finite_relpow[simp,intro]: | |
| 1105 |   assumes "finite(R :: ('a*'a)set)" shows "n>0 \<Longrightarrow> finite(R^^n)"
 | |
| 1106 | apply(induct n) | |
| 1107 | apply simp | |
| 1108 | apply(case_tac n) | |
| 1109 | apply(simp_all add: assms) | |
| 1110 | done | |
| 1111 | ||
| 46362 | 1112 | lemma single_valued_relpow: | 
| 30954 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 1113 |   fixes R :: "('a * 'a) set"
 | 
| 
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
 haftmann parents: 
30549diff
changeset | 1114 | shows "single_valued R \<Longrightarrow> single_valued (R ^^ n)" | 
| 41987 | 1115 | apply (induct n arbitrary: R) | 
| 1116 | apply simp_all | |
| 1117 | apply (rule single_valuedI) | |
| 46362 | 1118 | apply (fast dest: single_valuedD elim: relpow_Suc_E) | 
| 41987 | 1119 | done | 
| 15551 | 1120 | |
| 45140 | 1121 | |
| 60758 | 1122 | subsection \<open>Bounded transitive closure\<close> | 
| 45140 | 1123 | |
| 1124 | definition ntrancl :: "nat \<Rightarrow> ('a \<times> 'a) set \<Rightarrow> ('a \<times> 'a) set"
 | |
| 1125 | where | |
| 1126 |   "ntrancl n R = (\<Union>i\<in>{i. 0 < i \<and> i \<le> Suc n}. R ^^ i)"
 | |
| 1127 | ||
| 1128 | lemma ntrancl_Zero [simp, code]: | |
| 1129 | "ntrancl 0 R = R" | |
| 1130 | proof | |
| 1131 | show "R \<subseteq> ntrancl 0 R" | |
| 1132 | unfolding ntrancl_def by fastforce | |
| 1133 | next | |
| 1134 |   { 
 | |
| 1135 | fix i have "0 < i \<and> i \<le> Suc 0 \<longleftrightarrow> i = 1" by auto | |
| 1136 | } | |
| 1137 | from this show "ntrancl 0 R \<le> R" | |
| 1138 | unfolding ntrancl_def by auto | |
| 1139 | qed | |
| 1140 | ||
| 46347 
54870ad19af4
new code equation for ntrancl that allows computation of the transitive closure of sets on infinite types as well
 bulwahn parents: 
46127diff
changeset | 1141 | lemma ntrancl_Suc [simp]: | 
| 45140 | 1142 | "ntrancl (Suc n) R = ntrancl n R O (Id \<union> R)" | 
| 1143 | proof | |
| 1144 |   {
 | |
| 1145 | fix a b | |
| 1146 | assume "(a, b) \<in> ntrancl (Suc n) R" | |
| 1147 | from this obtain i where "0 < i" "i \<le> Suc (Suc n)" "(a, b) \<in> R ^^ i" | |
| 1148 | unfolding ntrancl_def by auto | |
| 1149 | have "(a, b) \<in> ntrancl n R O (Id \<union> R)" | |
| 1150 | proof (cases "i = 1") | |
| 1151 | case True | |
| 60758 | 1152 | from this \<open>(a, b) \<in> R ^^ i\<close> show ?thesis | 
| 45140 | 1153 | unfolding ntrancl_def by auto | 
| 1154 | next | |
| 1155 | case False | |
| 60758 | 1156 | from this \<open>0 < i\<close> obtain j where j: "i = Suc j" "0 < j" | 
| 45140 | 1157 | by (cases i) auto | 
| 60758 | 1158 | from this \<open>(a, b) \<in> R ^^ i\<close> obtain c where c1: "(a, c) \<in> R ^^ j" and c2:"(c, b) \<in> R" | 
| 45140 | 1159 | by auto | 
| 60758 | 1160 | from c1 j \<open>i \<le> Suc (Suc n)\<close> have "(a, c) \<in> ntrancl n R" | 
| 45140 | 1161 | unfolding ntrancl_def by fastforce | 
| 1162 | from this c2 show ?thesis by fastforce | |
| 1163 | qed | |
| 1164 | } | |
| 1165 | from this show "ntrancl (Suc n) R \<subseteq> ntrancl n R O (Id \<union> R)" | |
| 1166 | by auto | |
| 1167 | next | |
| 1168 | show "ntrancl n R O (Id \<union> R) \<subseteq> ntrancl (Suc n) R" | |
| 1169 | unfolding ntrancl_def by fastforce | |
| 1170 | qed | |
| 1171 | ||
| 46347 
54870ad19af4
new code equation for ntrancl that allows computation of the transitive closure of sets on infinite types as well
 bulwahn parents: 
46127diff
changeset | 1172 | lemma [code]: | 
| 
54870ad19af4
new code equation for ntrancl that allows computation of the transitive closure of sets on infinite types as well
 bulwahn parents: 
46127diff
changeset | 1173 | "ntrancl (Suc n) r = (let r' = ntrancl n r in r' Un r' O r)" | 
| 
54870ad19af4
new code equation for ntrancl that allows computation of the transitive closure of sets on infinite types as well
 bulwahn parents: 
46127diff
changeset | 1174 | unfolding Let_def by auto | 
| 
54870ad19af4
new code equation for ntrancl that allows computation of the transitive closure of sets on infinite types as well
 bulwahn parents: 
46127diff
changeset | 1175 | |
| 45141 
b2eb87bd541b
avoid very specific code equation for card; corrected spelling
 haftmann parents: 
45140diff
changeset | 1176 | lemma finite_trancl_ntranl: | 
| 45140 | 1177 | "finite R \<Longrightarrow> trancl R = ntrancl (card R - 1) R" | 
| 46362 | 1178 | by (cases "card R") (auto simp add: trancl_finite_eq_relpow relpow_empty ntrancl_def) | 
| 45140 | 1179 | |
| 1180 | ||
| 60758 | 1181 | subsection \<open>Acyclic relations\<close> | 
| 45139 | 1182 | |
| 1183 | definition acyclic :: "('a * 'a) set => bool" where
 | |
| 1184 | "acyclic r \<longleftrightarrow> (!x. (x,x) ~: r^+)" | |
| 1185 | ||
| 1186 | abbreviation acyclicP :: "('a => 'a => bool) => bool" where
 | |
| 1187 |   "acyclicP r \<equiv> acyclic {(x, y). r x y}"
 | |
| 1188 | ||
| 46127 | 1189 | lemma acyclic_irrefl [code]: | 
| 45139 | 1190 | "acyclic r \<longleftrightarrow> irrefl (r^+)" | 
| 1191 | by (simp add: acyclic_def irrefl_def) | |
| 1192 | ||
| 1193 | lemma acyclicI: "ALL x. (x, x) ~: r^+ ==> acyclic r" | |
| 1194 | by (simp add: acyclic_def) | |
| 1195 | ||
| 54412 | 1196 | lemma (in order) acyclicI_order: | 
| 1197 | assumes *: "\<And>a b. (a, b) \<in> r \<Longrightarrow> f b < f a" | |
| 1198 | shows "acyclic r" | |
| 1199 | proof - | |
| 1200 |   { fix a b assume "(a, b) \<in> r\<^sup>+"
 | |
| 1201 | then have "f b < f a" | |
| 1202 | by induct (auto intro: * less_trans) } | |
| 1203 | then show ?thesis | |
| 1204 | by (auto intro!: acyclicI) | |
| 1205 | qed | |
| 1206 | ||
| 45139 | 1207 | lemma acyclic_insert [iff]: | 
| 1208 | "acyclic(insert (y,x) r) = (acyclic r & (x,y) ~: r^*)" | |
| 1209 | apply (simp add: acyclic_def trancl_insert) | |
| 1210 | apply (blast intro: rtrancl_trans) | |
| 1211 | done | |
| 1212 | ||
| 1213 | lemma acyclic_converse [iff]: "acyclic(r^-1) = acyclic r" | |
| 1214 | by (simp add: acyclic_def trancl_converse) | |
| 1215 | ||
| 1216 | lemmas acyclicP_converse [iff] = acyclic_converse [to_pred] | |
| 1217 | ||
| 1218 | lemma acyclic_impl_antisym_rtrancl: "acyclic r ==> antisym(r^*)" | |
| 1219 | apply (simp add: acyclic_def antisym_def) | |
| 1220 | apply (blast elim: rtranclE intro: rtrancl_into_trancl1 rtrancl_trancl_trancl) | |
| 1221 | done | |
| 1222 | ||
| 1223 | (* Other direction: | |
| 1224 | acyclic = no loops | |
| 1225 | antisym = only self loops | |
| 1226 | Goalw [acyclic_def,antisym_def] "antisym( r^* ) ==> acyclic(r - Id) | |
| 1227 | ==> antisym( r^* ) = acyclic(r - Id)"; | |
| 1228 | *) | |
| 1229 | ||
| 1230 | lemma acyclic_subset: "[| acyclic s; r <= s |] ==> acyclic r" | |
| 1231 | apply (simp add: acyclic_def) | |
| 1232 | apply (blast intro: trancl_mono) | |
| 1233 | done | |
| 1234 | ||
| 1235 | ||
| 60758 | 1236 | subsection \<open>Setup of transitivity reasoner\<close> | 
| 15076 
4b3d280ef06a
New prover for transitive and reflexive-transitive closure of relations.
 ballarin parents: 
14565diff
changeset | 1237 | |
| 60758 | 1238 | ML \<open> | 
| 15076 
4b3d280ef06a
New prover for transitive and reflexive-transitive closure of relations.
 ballarin parents: 
14565diff
changeset | 1239 | |
| 32215 | 1240 | structure Trancl_Tac = Trancl_Tac | 
| 1241 | ( | |
| 1242 |   val r_into_trancl = @{thm trancl.r_into_trancl};
 | |
| 1243 |   val trancl_trans  = @{thm trancl_trans};
 | |
| 1244 |   val rtrancl_refl = @{thm rtrancl.rtrancl_refl};
 | |
| 1245 |   val r_into_rtrancl = @{thm r_into_rtrancl};
 | |
| 1246 |   val trancl_into_rtrancl = @{thm trancl_into_rtrancl};
 | |
| 1247 |   val rtrancl_trancl_trancl = @{thm rtrancl_trancl_trancl};
 | |
| 1248 |   val trancl_rtrancl_trancl = @{thm trancl_rtrancl_trancl};
 | |
| 1249 |   val rtrancl_trans = @{thm rtrancl_trans};
 | |
| 15096 | 1250 | |
| 30107 
f3b3b0e3d184
Fixed nonexhaustive match problem in decomp, to make it fail more gracefully
 berghofe parents: 
29609diff
changeset | 1251 |   fun decomp (@{const Trueprop} $ t) =
 | 
| 37677 | 1252 |     let fun dec (Const (@{const_name Set.member}, _) $ (Const (@{const_name Pair}, _) $ a $ b) $ rel ) =
 | 
| 56257 | 1253 |         let fun decr (Const (@{const_name rtrancl}, _ ) $ r) = (r,"r*")
 | 
| 1254 |               | decr (Const (@{const_name trancl}, _ ) $ r)  = (r,"r+")
 | |
| 18372 | 1255 | | decr r = (r,"r"); | 
| 26801 
244184661a09
- Function dec in Trancl_Tac must eta-contract relation before calling
 berghofe parents: 
26340diff
changeset | 1256 | val (rel,r) = decr (Envir.beta_eta_contract rel); | 
| 18372 | 1257 | in SOME (a,b,rel,r) end | 
| 1258 | | dec _ = NONE | |
| 30107 
f3b3b0e3d184
Fixed nonexhaustive match problem in decomp, to make it fail more gracefully
 berghofe parents: 
29609diff
changeset | 1259 | in dec t end | 
| 
f3b3b0e3d184
Fixed nonexhaustive match problem in decomp, to make it fail more gracefully
 berghofe parents: 
29609diff
changeset | 1260 | | decomp _ = NONE; | 
| 32215 | 1261 | ); | 
| 15076 
4b3d280ef06a
New prover for transitive and reflexive-transitive closure of relations.
 ballarin parents: 
14565diff
changeset | 1262 | |
| 32215 | 1263 | structure Tranclp_Tac = Trancl_Tac | 
| 1264 | ( | |
| 1265 |   val r_into_trancl = @{thm tranclp.r_into_trancl};
 | |
| 1266 |   val trancl_trans  = @{thm tranclp_trans};
 | |
| 1267 |   val rtrancl_refl = @{thm rtranclp.rtrancl_refl};
 | |
| 1268 |   val r_into_rtrancl = @{thm r_into_rtranclp};
 | |
| 1269 |   val trancl_into_rtrancl = @{thm tranclp_into_rtranclp};
 | |
| 1270 |   val rtrancl_trancl_trancl = @{thm rtranclp_tranclp_tranclp};
 | |
| 1271 |   val trancl_rtrancl_trancl = @{thm tranclp_rtranclp_tranclp};
 | |
| 1272 |   val rtrancl_trans = @{thm rtranclp_trans};
 | |
| 22262 | 1273 | |
| 30107 
f3b3b0e3d184
Fixed nonexhaustive match problem in decomp, to make it fail more gracefully
 berghofe parents: 
29609diff
changeset | 1274 |   fun decomp (@{const Trueprop} $ t) =
 | 
| 22262 | 1275 | let fun dec (rel $ a $ b) = | 
| 56257 | 1276 |         let fun decr (Const (@{const_name rtranclp}, _ ) $ r) = (r,"r*")
 | 
| 1277 |               | decr (Const (@{const_name tranclp}, _ ) $ r)  = (r,"r+")
 | |
| 22262 | 1278 | | decr r = (r,"r"); | 
| 1279 | val (rel,r) = decr rel; | |
| 26801 
244184661a09
- Function dec in Trancl_Tac must eta-contract relation before calling
 berghofe parents: 
26340diff
changeset | 1280 | in SOME (a, b, rel, r) end | 
| 22262 | 1281 | | dec _ = NONE | 
| 30107 
f3b3b0e3d184
Fixed nonexhaustive match problem in decomp, to make it fail more gracefully
 berghofe parents: 
29609diff
changeset | 1282 | in dec t end | 
| 
f3b3b0e3d184
Fixed nonexhaustive match problem in decomp, to make it fail more gracefully
 berghofe parents: 
29609diff
changeset | 1283 | | decomp _ = NONE; | 
| 32215 | 1284 | ); | 
| 60758 | 1285 | \<close> | 
| 22262 | 1286 | |
| 60758 | 1287 | setup \<open> | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50616diff
changeset | 1288 | map_theory_simpset (fn ctxt => ctxt | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50616diff
changeset | 1289 | addSolver (mk_solver "Trancl" Trancl_Tac.trancl_tac) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50616diff
changeset | 1290 | addSolver (mk_solver "Rtrancl" Trancl_Tac.rtrancl_tac) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50616diff
changeset | 1291 | addSolver (mk_solver "Tranclp" Tranclp_Tac.trancl_tac) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
50616diff
changeset | 1292 | addSolver (mk_solver "Rtranclp" Tranclp_Tac.rtrancl_tac)) | 
| 60758 | 1293 | \<close> | 
| 15076 
4b3d280ef06a
New prover for transitive and reflexive-transitive closure of relations.
 ballarin parents: 
14565diff
changeset | 1294 | |
| 32215 | 1295 | |
| 60758 | 1296 | text \<open>Optional methods.\<close> | 
| 15076 
4b3d280ef06a
New prover for transitive and reflexive-transitive closure of relations.
 ballarin parents: 
14565diff
changeset | 1297 | |
| 
4b3d280ef06a
New prover for transitive and reflexive-transitive closure of relations.
 ballarin parents: 
14565diff
changeset | 1298 | method_setup trancl = | 
| 60758 | 1299 | \<open>Scan.succeed (SIMPLE_METHOD' o Trancl_Tac.trancl_tac)\<close> | 
| 1300 | \<open>simple transitivity reasoner\<close> | |
| 15076 
4b3d280ef06a
New prover for transitive and reflexive-transitive closure of relations.
 ballarin parents: 
14565diff
changeset | 1301 | method_setup rtrancl = | 
| 60758 | 1302 | \<open>Scan.succeed (SIMPLE_METHOD' o Trancl_Tac.rtrancl_tac)\<close> | 
| 1303 | \<open>simple transitivity reasoner\<close> | |
| 22262 | 1304 | method_setup tranclp = | 
| 60758 | 1305 | \<open>Scan.succeed (SIMPLE_METHOD' o Tranclp_Tac.trancl_tac)\<close> | 
| 1306 | \<open>simple transitivity reasoner (predicate version)\<close> | |
| 22262 | 1307 | method_setup rtranclp = | 
| 60758 | 1308 | \<open>Scan.succeed (SIMPLE_METHOD' o Tranclp_Tac.rtrancl_tac)\<close> | 
| 1309 | \<open>simple transitivity reasoner (predicate version)\<close> | |
| 15076 
4b3d280ef06a
New prover for transitive and reflexive-transitive closure of relations.
 ballarin parents: 
14565diff
changeset | 1310 | |
| 10213 | 1311 | end |