summary |
shortlog |
changelog |
graph |
tags |
branches |
files |
changeset |
file |
revisions |
annotate |
diff |
raw

doc-src/TutorialI/Inductive/Star.thy

changeset 10520 | bb9dfcc87951 |

parent 10396 | 5ab08609e6c8 |

child 10898 | b086f4e1722f |

1.1 --- a/doc-src/TutorialI/Inductive/Star.thy Fri Nov 24 16:49:27 2000 +0100 1.2 +++ b/doc-src/TutorialI/Inductive/Star.thy Sun Nov 26 10:48:38 2000 +0100 1.3 @@ -3,14 +3,12 @@ 1.4 section{*The reflexive transitive closure*} 1.5 1.6 text{*\label{sec:rtc} 1.7 -{\bf Say something about inductive relations as opposed to sets? Or has that 1.8 -been said already? If not, explain induction!} 1.9 - 1.10 -A perfect example of an inductive definition is the reflexive transitive 1.11 -closure of a relation. This concept was already introduced in 1.12 -\S\ref{sec:Relations}, where the operator @{text"^*"} was 1.13 -defined as a least fixed point because 1.14 -inductive definitions were not yet available. But now they are: 1.15 +Many inductive definitions define proper relations rather than merely set 1.16 +like @{term even}. A perfect example is the 1.17 +reflexive transitive closure of a relation. This concept was already 1.18 +introduced in \S\ref{sec:Relations}, where the operator @{text"^*"} was 1.19 +defined as a least fixed point because inductive definitions were not yet 1.20 +available. But now they are: 1.21 *} 1.22 1.23 consts rtc :: "('a \<times> 'a)set \<Rightarrow> ('a \<times> 'a)set" ("_*" [1000] 999) 1.24 @@ -21,13 +19,13 @@ 1.25 1.26 text{*\noindent 1.27 The function @{term rtc} is annotated with concrete syntax: instead of 1.28 -@{text"rtc r"} we can read and write {term"r*"}. The actual definition 1.29 -consists of two rules. Reflexivity is obvious and is immediately declared an 1.30 -equivalence rule. Thus the automatic tools will apply it automatically. The 1.31 +@{text"rtc r"} we can read and write @{term"r*"}. The actual definition 1.32 +consists of two rules. Reflexivity is obvious and is immediately given the 1.33 +@{text iff} attribute to increase automation. The 1.34 second rule, @{thm[source]rtc_step}, says that we can always add one more 1.35 @{term r}-step to the left. Although we could make @{thm[source]rtc_step} an 1.36 -introduction rule, this is dangerous: the recursion slows down and may 1.37 -even kill the automatic tactics. 1.38 +introduction rule, this is dangerous: the recursion in the second premise 1.39 +slows down and may even kill the automatic tactics. 1.40 1.41 The above definition of the concept of reflexive transitive closure may 1.42 be sufficiently intuitive but it is certainly not the only possible one: 1.43 @@ -45,38 +43,44 @@ 1.44 danger of killing the automatic tactics because @{term"r*"} occurs only in 1.45 the conclusion and not in the premise. Thus some proofs that would otherwise 1.46 need @{thm[source]rtc_step} can now be found automatically. The proof also 1.47 -shows that @{term blast} is quite able to handle @{thm[source]rtc_step}. But 1.48 +shows that @{text blast} is quite able to handle @{thm[source]rtc_step}. But 1.49 some of the other automatic tactics are more sensitive, and even @{text 1.50 blast} can be lead astray in the presence of large numbers of rules. 1.51 1.52 -Let us now turn to transitivity. It should be a consequence of the definition. 1.53 +To prove transitivity, we need rule induction, i.e.\ theorem 1.54 +@{thm[source]rtc.induct}: 1.55 +@{thm[display]rtc.induct} 1.56 +It says that @{text"?P"} holds for an arbitrary pair @{text"(?xb,?xa) \<in> 1.57 +?r*"} if @{text"?P"} is preserved by all rules of the inductive definition, 1.58 +i.e.\ if @{text"?P"} holds for the conclusion provided it holds for the 1.59 +premises. In general, rule induction for an $n$-ary inductive relation $R$ 1.60 +expects a premise of the form $(x@1,\dots,x@n) \in R$. 1.61 + 1.62 +Now we turn to the inductive proof of transitivity: 1.63 *} 1.64 1.65 -lemma rtc_trans: 1.66 - "\<lbrakk> (x,y) \<in> r*; (y,z) \<in> r* \<rbrakk> \<Longrightarrow> (x,z) \<in> r*" 1.67 - 1.68 -txt{*\noindent 1.69 -The proof starts canonically by rule induction: 1.70 -*} 1.71 - 1.72 +lemma rtc_trans: "\<lbrakk> (x,y) \<in> r*; (y,z) \<in> r* \<rbrakk> \<Longrightarrow> (x,z) \<in> r*" 1.73 apply(erule rtc.induct) 1.74 1.75 txt{*\noindent 1.76 -However, even the resulting base case is a problem 1.77 +Unfortunately, even the resulting base case is a problem 1.78 @{subgoals[display,indent=0,goals_limit=1]} 1.79 and maybe not what you had expected. We have to abandon this proof attempt. 1.80 -To understand what is going on, 1.81 -let us look at the induction rule @{thm[source]rtc.induct}: 1.82 -\[ \frac{(x,y) \in r^* \qquad \bigwedge x.~P~x~x \quad \dots}{P~x~y} \] 1.83 -When applying this rule, $x$ becomes @{term x}, $y$ becomes 1.84 -@{term y} and $P~x~y$ becomes @{prop"(x,z) : r*"}, thus 1.85 +To understand what is going on, let us look again at @{thm[source]rtc.induct}. 1.86 +In the above application of @{text erule}, the first premise of 1.87 +@{thm[source]rtc.induct} is unified with the first suitable assumption, which 1.88 +is @{term"(x,y) \<in> r*"} rather than @{term"(y,z) \<in> r*"}. Although that 1.89 +is what we want, it is merely due to the order in which the assumptions occur 1.90 +in the subgoal, which it is not good practice to rely on. As a result, 1.91 +@{text"?xb"} becomes @{term x}, @{text"?xa"} becomes 1.92 +@{term y} and @{text"?P"} becomes @{term"%u v. (u,z) : r*"}, thus 1.93 yielding the above subgoal. So what went wrong? 1.94 1.95 -When looking at the instantiation of $P~x~y$ we see 1.96 -that $P$ does not depend on its second parameter at 1.97 -all. The reason is that in our original goal, of the pair @{term"(x,y)"} only 1.98 -@{term x} appears also in the conclusion, but not @{term y}. Thus our 1.99 -induction statement is too weak. Fortunately, it can easily be strengthened: 1.100 +When looking at the instantiation of @{text"?P"} we see that it does not 1.101 +depend on its second parameter at all. The reason is that in our original 1.102 +goal, of the pair @{term"(x,y)"} only @{term x} appears also in the 1.103 +conclusion, but not @{term y}. Thus our induction statement is too 1.104 +weak. Fortunately, it can easily be strengthened: 1.105 transfer the additional premise @{prop"(y,z):r*"} into the conclusion:*} 1.106 (*<*)oops(*>*) 1.107 lemma rtc_trans[rule_format]: 1.108 @@ -145,10 +149,15 @@ 1.109 certainly pick the simplest induction schema available for any concept. 1.110 Hence @{term rtc} is the definition of choice. 1.111 1.112 -\begin{exercise} 1.113 +\begin{exercise}\label{ex:converse-rtc-step} 1.114 Show that the converse of @{thm[source]rtc_step} also holds: 1.115 @{prop[display]"[| (x,y) : r*; (y,z) : r |] ==> (x,z) : r*"} 1.116 \end{exercise} 1.117 +\begin{exercise} 1.118 +Repeat the development of this section, but starting with a definition of 1.119 +@{term rtc} where @{thm[source]rtc_step} is replaced by its converse as shown 1.120 +in exercise~\ref{ex:converse-rtc-step}. 1.121 +\end{exercise} 1.122 *} 1.123 (*<*) 1.124 lemma rtc_step2[rule_format]: "(x,y) : r* \<Longrightarrow> (y,z) : r --> (x,z) : r*"