author | Christian Urban <urbanc@in.tum.de> |
Fri, 13 Feb 2009 01:05:31 +0000 | |
changeset 113 | 9b6c9d172378 |
parent 102 | 5e309df58557 |
child 114 | 13fd0a83d3c3 |
permissions | -rw-r--r-- |
32 | 1 |
theory Ind_Examples |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
2 |
imports Main LaTeXsugar |
32 | 3 |
begin |
4 |
||
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
5 |
section{* Examples of Inductive Definitions \label{sec:ind-examples} *} |
32 | 6 |
|
7 |
text {* |
|
113 | 8 |
Let us first give three examples showing how to define inductive predicates |
9 |
by hand and prove characteristic properties such as introduction rules and |
|
10 |
an induction rule. From these examples, we will then figure out a general |
|
11 |
method for defining inductive predicates. The aim in this section is not to |
|
12 |
write proofs that are as beautiful as possible, but as close as possible to |
|
13 |
the ML-code producing the proofs that we will develop later. |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
14 |
|
113 | 15 |
As a first example, we consider the transitive closure of a relation @{text |
16 |
R}. It is an inductive predicate characterized by the two introduction rules |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
17 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
18 |
\begin{center} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
19 |
@{term[mode=Axiom] "trcl R x x"} \hspace{5mm} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
20 |
@{term[mode=Rule] "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z"} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
21 |
\end{center} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
22 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
23 |
(FIXME first rule should be an ``axiom'') |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
24 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
25 |
Note that the @{text trcl} predicate has two different kinds of parameters: the |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
26 |
first parameter @{text R} stays \emph{fixed} throughout the definition, whereas |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
27 |
the second and third parameter changes in the ``recursive call''. |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
28 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
29 |
Since an inductively defined predicate is the least predicate closed under |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
30 |
a collection of introduction rules, we define the predicate @{text "trcl R x y"} in |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
31 |
such a way that it holds if and only if @{text "P x y"} holds for every predicate |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
32 |
@{text P} closed under the rules above. This gives rise to the definition |
32 | 33 |
*} |
34 |
||
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
35 |
definition "trcl R x y \<equiv> |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
36 |
\<forall>P. (\<forall>x. P x x) \<longrightarrow> (\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z) \<longrightarrow> P x y" |
32 | 37 |
|
38 |
text {* |
|
113 | 39 |
where we quantify over the predicate @{text P}. Note that we have to use the |
40 |
object implication @{text "\<longrightarrow>"} and object quantification @{text "\<forall>"} for stating |
|
41 |
this definition. |
|
32 | 42 |
|
113 | 43 |
With this definition of the transitive closure, the proof of the induction |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
44 |
theorem is almost immediate. It suffices to convert all the meta-level connectives |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
45 |
in the induction rule to object-level connectives using the @{text atomize} proof |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
46 |
method, expand the definition of @{text trcl}, eliminate the universal quantifier |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
47 |
contained in it, and then solve the goal by assumption. |
113 | 48 |
|
49 |
(FIXME: add linenumbers to the proof below and the text above) |
|
32 | 50 |
*} |
51 |
||
52 |
lemma trcl_induct: |
|
113 | 53 |
assumes asm: "trcl R x y" |
32 | 54 |
shows "(\<And>x. P x x) \<Longrightarrow> (\<And>x y z. R x y \<Longrightarrow> P y z \<Longrightarrow> P x z) \<Longrightarrow> P x y" |
113 | 55 |
apply(atomize (full)) |
56 |
apply(cut_tac asm) |
|
57 |
apply(unfold trcl_def) |
|
58 |
apply(drule spec[where x=P]) |
|
59 |
apply(assumption) |
|
60 |
done |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
61 |
|
113 | 62 |
text {* |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
63 |
We now turn to the proofs of the introduction rules, which are slightly more complicated. |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
64 |
In order to prove the first introduction rule, we again unfold the definition and |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
65 |
then apply the introdution rules for @{text "\<forall>"} and @{text "\<longrightarrow>"} as often as possible. |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
66 |
We then end up in a proof state of the following form: |
113 | 67 |
|
68 |
*} |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
69 |
|
113 | 70 |
(*<*)lemma "trcl R x x" |
71 |
apply (unfold trcl_def) |
|
72 |
apply (rule allI impI)+(*>*) |
|
73 |
txt {* @{subgoals [display]} *} |
|
32 | 74 |
(*<*)oops(*>*) |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
75 |
|
113 | 76 |
text {* |
77 |
The two assumptions correspond to the introduction rules, where @{text "trcl |
|
78 |
R"} has been replaced by P. Thus, all we have to do is to eliminate the |
|
79 |
universal quantifier in front of the first assumption, and then solve the |
|
80 |
goal by assumption: |
|
81 |
*} |
|
82 |
||
83 |
||
32 | 84 |
lemma trcl_base: "trcl R x x" |
113 | 85 |
apply(unfold trcl_def) |
86 |
apply(rule allI impI)+ |
|
87 |
apply(drule spec) |
|
88 |
apply(assumption) |
|
89 |
done |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
90 |
|
113 | 91 |
text {* |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
92 |
Since the second introduction rule has premises, its proof is not as easy as the previous |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
93 |
one. After unfolding the definitions and applying the introduction rules for @{text "\<forall>"} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
94 |
and @{text "\<longrightarrow>"}, we get the proof state |
113 | 95 |
*} |
96 |
||
97 |
||
98 |
(*<*)lemma "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z" |
|
99 |
apply (unfold trcl_def) |
|
100 |
apply (rule allI impI)+(*>*) |
|
101 |
txt {*@{subgoals [display]} *} |
|
102 |
(*<*)oops(*>*) |
|
103 |
||
104 |
text {* |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
105 |
The third and fourth assumption corresponds to the first and second introduction rule, |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
106 |
respectively, whereas the first and second assumption corresponds to the premises of |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
107 |
the introduction rule. Since we want to prove the second introduction rule, we apply |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
108 |
the fourth assumption to the goal @{term "P x z"}. In order for the assumption to |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
109 |
be applicable, we have to eliminate the universal quantifiers and turn the object-level |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
110 |
implications into meta-level ones. This can be accomplished using the @{text rule_format} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
111 |
attribute. Applying the assumption produces two new subgoals, which can be solved using |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
112 |
the first and second assumption. The second assumption again involves a quantifier and |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
113 |
implications that have to be eliminated before it can be applied. To avoid problems |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
114 |
with higher order unification, it is advisable to provide an instantiation for the |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
115 |
universally quantified predicate variable in the assumption. |
32 | 116 |
*} |
113 | 117 |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
118 |
|
32 | 119 |
lemma trcl_step: "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z" |
120 |
apply (unfold trcl_def) |
|
121 |
apply (rule allI impI)+ |
|
122 |
proof - |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
88
diff
changeset
|
123 |
case (goal1 P) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
88
diff
changeset
|
124 |
have g1: "R x y" by fact |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
88
diff
changeset
|
125 |
have g2: "\<forall>P. (\<forall>x. P x x) \<longrightarrow> (\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z) \<longrightarrow> P y z" by fact |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
88
diff
changeset
|
126 |
have g3: "\<forall>x. P x x" by fact |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
88
diff
changeset
|
127 |
have g4: "\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z" by fact |
32 | 128 |
show ?case |
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
88
diff
changeset
|
129 |
apply (rule g4 [rule_format]) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
88
diff
changeset
|
130 |
apply (rule g1) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
88
diff
changeset
|
131 |
apply (rule g2 [THEN spec [where x=P], THEN mp, THEN mp, OF g3, OF g4]) |
32 | 132 |
done |
133 |
qed |
|
134 |
||
135 |
text {* |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
136 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
137 |
This method of defining inductive predicates easily generalizes to mutually inductive |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
138 |
predicates, like the predicates @{text even} and @{text odd} characterized by the |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
139 |
following introduction rules: |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
140 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
141 |
\begin{center} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
142 |
@{term[mode=Axiom] "even (0::nat)"} \hspace{5mm} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
143 |
@{term[mode=Rule] "odd m \<Longrightarrow> even (Suc m)"} \hspace{5mm} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
144 |
@{term[mode=Rule] "even m \<Longrightarrow> odd (Suc m)"} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
145 |
\end{center} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
146 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
147 |
Since the predicates are mutually inductive, each of the definitions contain two |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
148 |
quantifiers over the predicates @{text P} and @{text Q}. |
32 | 149 |
*} |
150 |
||
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
151 |
definition "even n \<equiv> |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
152 |
\<forall>P Q. P 0 \<longrightarrow> (\<forall>m. Q m \<longrightarrow> P (Suc m)) |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
153 |
\<longrightarrow> (\<forall>m. P m \<longrightarrow> Q (Suc m)) \<longrightarrow> P n" |
32 | 154 |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
155 |
definition "odd n \<equiv> |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
156 |
\<forall>P Q. P 0 \<longrightarrow> (\<forall>m. Q m \<longrightarrow> P (Suc m)) |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
157 |
\<longrightarrow> (\<forall>m. P m \<longrightarrow> Q (Suc m)) \<longrightarrow> Q n" |
32 | 158 |
|
159 |
text {* |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
160 |
For proving the induction rule, we use exactly the same technique as in the transitive |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
161 |
closure example: |
32 | 162 |
*} |
163 |
||
164 |
lemma even_induct: |
|
165 |
assumes even: "even n" |
|
38
e21b2f888fa2
added a preliminary section about parsing
Christian Urban <urbanc@in.tum.de>
parents:
32
diff
changeset
|
166 |
shows "P 0 \<Longrightarrow> |
e21b2f888fa2
added a preliminary section about parsing
Christian Urban <urbanc@in.tum.de>
parents:
32
diff
changeset
|
167 |
(\<And>m. Q m \<Longrightarrow> P (Suc m)) \<Longrightarrow> (\<And>m. P m \<Longrightarrow> Q (Suc m)) \<Longrightarrow> P n" |
32 | 168 |
apply (atomize (full)) |
169 |
apply (cut_tac even) |
|
170 |
apply (unfold even_def) |
|
171 |
apply (drule spec [where x=P]) |
|
172 |
apply (drule spec [where x=Q]) |
|
173 |
apply assumption |
|
174 |
done |
|
175 |
||
176 |
text {* |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
177 |
A similar induction rule having @{term "Q n"} as a conclusion can be proved for |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
178 |
the @{text odd} predicate. |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
179 |
The proofs of the introduction rules are also very similar to the ones in the |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
180 |
previous example. We only show the proof of the second introduction rule, |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
181 |
since it is almost the same as the one for the third introduction rule, |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
182 |
and the proof of the first rule is trivial. |
32 | 183 |
*} |
184 |
||
185 |
lemma evenS: "odd m \<Longrightarrow> even (Suc m)" |
|
186 |
apply (unfold odd_def even_def) |
|
187 |
apply (rule allI impI)+ |
|
188 |
proof - |
|
189 |
case goal1 |
|
190 |
show ?case |
|
191 |
apply (rule goal1(3) [rule_format]) |
|
192 |
apply (rule goal1(1) [THEN spec [where x=P], THEN spec [where x=Q], |
|
193 |
THEN mp, THEN mp, THEN mp, OF goal1(2-4)]) |
|
194 |
done |
|
195 |
qed |
|
196 |
(*<*) |
|
197 |
lemma even0: "even 0" |
|
198 |
apply (unfold even_def) |
|
199 |
apply (rule allI impI)+ |
|
200 |
apply assumption |
|
201 |
done |
|
202 |
||
203 |
lemma oddS: "even m \<Longrightarrow> odd (Suc m)" |
|
204 |
apply (unfold odd_def even_def) |
|
205 |
apply (rule allI impI)+ |
|
206 |
proof - |
|
207 |
case goal1 |
|
208 |
show ?case |
|
209 |
apply (rule goal1(4) [rule_format]) |
|
210 |
apply (rule goal1(1) [THEN spec [where x=P], THEN spec [where x=Q], |
|
211 |
THEN mp, THEN mp, THEN mp, OF goal1(2-4)]) |
|
212 |
done |
|
213 |
qed |
|
214 |
(*>*) |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
215 |
|
32 | 216 |
text {* |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
217 |
As a final example, we will consider the definition of the accessible |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
218 |
part of a relation @{text R} characterized by the introduction rule |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
219 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
220 |
\begin{center} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
221 |
@{term[mode=Rule] "(\<forall>y. R y x \<longrightarrow> accpart R y) \<Longrightarrow> accpart R x"} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
222 |
\end{center} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
223 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
224 |
whose premise involves a universal quantifier and an implication. The |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
225 |
definition of @{text accpart} is as follows: |
32 | 226 |
*} |
227 |
||
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
228 |
definition "accpart R x \<equiv> \<forall>P. (\<forall>x. (\<forall>y. R y x \<longrightarrow> P y) \<longrightarrow> P x) \<longrightarrow> P x" |
32 | 229 |
|
230 |
text {* |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
231 |
The proof of the induction theorem is again straightforward: |
32 | 232 |
*} |
233 |
||
234 |
lemma accpart_induct: |
|
235 |
assumes acc: "accpart R x" |
|
236 |
shows "(\<And>x. (\<And>y. R y x \<Longrightarrow> P y) \<Longrightarrow> P x) \<Longrightarrow> P x" |
|
237 |
apply (atomize (full)) |
|
238 |
apply (cut_tac acc) |
|
239 |
apply (unfold accpart_def) |
|
240 |
apply (drule spec [where x=P]) |
|
241 |
apply assumption |
|
242 |
done |
|
243 |
(*<*) |
|
244 |
lemma accpartI: "(\<And>y. R y x \<Longrightarrow> accpart R y) \<Longrightarrow> accpart R x" |
|
245 |
apply (unfold accpart_def) |
|
246 |
apply (rule allI impI)+ |
|
247 |
(*>*) |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
248 |
|
32 | 249 |
txt {* |
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
250 |
|
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
251 |
Proving the introduction rule is a little more complicated, due to the quantifier |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
252 |
and the implication in the premise. We first convert the meta-level universal quantifier |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
253 |
and implication to their object-level counterparts. Unfolding the definition of |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
254 |
@{text accpart} and applying the introduction rules for @{text "\<forall>"} and @{text "\<longrightarrow>"} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
255 |
yields the following proof state: |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
256 |
@{subgoals [display]} |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
257 |
Applying the second assumption produces a proof state with the new local assumption |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
258 |
@{term "R y x"}, which will then be used to solve the goal @{term "P y"} using the |
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
259 |
first assumption. |
32 | 260 |
*} |
261 |
(*<*)oops(*>*) |
|
88
ebbd0dd008c8
adaptation of the package chapter to fit the rest
Christian Urban <urbanc@in.tum.de>
parents:
38
diff
changeset
|
262 |
|
32 | 263 |
lemma accpartI: "(\<And>y. R y x \<Longrightarrow> accpart R y) \<Longrightarrow> accpart R x" |
264 |
apply (unfold accpart_def) |
|
265 |
apply (rule allI impI)+ |
|
266 |
proof - |
|
267 |
case goal1 |
|
268 |
note goal1' = this |
|
269 |
show ?case |
|
270 |
apply (rule goal1'(2) [rule_format]) |
|
271 |
proof - |
|
272 |
case goal1 |
|
273 |
show ?case |
|
274 |
apply (rule goal1'(1) [OF goal1, THEN spec [where x=P], |
|
275 |
THEN mp, OF goal1'(2)]) |
|
276 |
done |
|
277 |
qed |
|
278 |
qed |
|
279 |
||
280 |
end |