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