10225
|
1 |
(*<*)theory Star = Main:(*>*)
|
|
2 |
|
10237
|
3 |
section{*The reflexive transitive closure*}
|
10225
|
4 |
|
|
5 |
text{*
|
10237
|
6 |
A perfect example of an inductive definition is the reflexive transitive
|
10225
|
7 |
closure of a relation. This concept was already introduced in
|
|
8 |
\S\ref{sec:rtrancl}, but it was not shown how it is defined. In fact,
|
|
9 |
the operator @{text"^*"} is not defined inductively but via a least
|
|
10 |
fixpoint because at that point in the theory hierarchy
|
|
11 |
inductive definitions are not yet available. But now they are:
|
|
12 |
*}
|
|
13 |
|
10237
|
14 |
consts rtc :: "('a \<times> 'a)set \<Rightarrow> ('a \<times> 'a)set" ("_*" [1000] 999)
|
10225
|
15 |
inductive "r*"
|
|
16 |
intros
|
10237
|
17 |
rtc_refl[intro!]: "(x,x) \<in> r*"
|
|
18 |
rtc_step: "\<lbrakk> (x,y) \<in> r*; (y,z) \<in> r \<rbrakk> \<Longrightarrow> (x,z) \<in> r*"
|
10225
|
19 |
|
|
20 |
lemma [intro]: "(x,y) : r \<Longrightarrow> (x,y) \<in> r*"
|
10237
|
21 |
by(blast intro: rtc_step);
|
10225
|
22 |
|
|
23 |
lemma step2[rule_format]:
|
|
24 |
"(y,z) \<in> r* \<Longrightarrow> (x,y) \<in> r \<longrightarrow> (x,z) \<in> r*"
|
10237
|
25 |
apply(erule rtc.induct)
|
10225
|
26 |
apply(blast);
|
10237
|
27 |
apply(blast intro: rtc_step);
|
10225
|
28 |
done
|
|
29 |
|
10237
|
30 |
lemma rtc_trans[rule_format]:
|
10225
|
31 |
"(x,y) \<in> r* \<Longrightarrow> \<forall>z. (y,z) \<in> r* \<longrightarrow> (x,z) \<in> r*"
|
10237
|
32 |
apply(erule rtc.induct)
|
10225
|
33 |
apply blast;
|
|
34 |
apply(blast intro: step2);
|
|
35 |
done
|
|
36 |
|
10237
|
37 |
consts rtc2 :: "('a \<times> 'a)set \<Rightarrow> ('a \<times> 'a)set"
|
|
38 |
inductive "rtc2 r"
|
10225
|
39 |
intros
|
10237
|
40 |
"(x,y) \<in> r \<Longrightarrow> (x,y) \<in> rtc2 r"
|
|
41 |
"(x,x) \<in> rtc2 r"
|
|
42 |
"\<lbrakk> (x,y) \<in> rtc2 r; (y,z) \<in> rtc2 r \<rbrakk> \<Longrightarrow> (x,z) \<in> rtc2 r"
|
10225
|
43 |
|
10237
|
44 |
text{*
|
|
45 |
The equivalence of the two definitions is easily shown by the obvious rule
|
|
46 |
inductions:
|
|
47 |
*}
|
10225
|
48 |
|
10237
|
49 |
lemma "(x,y) \<in> rtc2 r \<Longrightarrow> (x,y) \<in> r*"
|
|
50 |
apply(erule rtc2.induct);
|
10225
|
51 |
apply(blast);
|
10237
|
52 |
apply(blast);
|
|
53 |
apply(blast intro: rtc_trans);
|
|
54 |
done
|
|
55 |
|
|
56 |
lemma "(x,y) \<in> r* \<Longrightarrow> (x,y) \<in> rtc2 r"
|
|
57 |
apply(erule rtc.induct);
|
|
58 |
apply(blast intro: rtc2.intros);
|
|
59 |
apply(blast intro: rtc2.intros);
|
10225
|
60 |
done
|
|
61 |
|
|
62 |
(*<*)end(*>*)
|