7 text {* |
7 text {* |
8 The user will just give a specification of inductive predicate(s) and |
8 The user will just give a specification of inductive predicate(s) and |
9 expects from the package to produce a convenient reasoning |
9 expects from the package to produce a convenient reasoning |
10 infrastructure. This infrastructure needs to be derived from the definition |
10 infrastructure. This infrastructure needs to be derived from the definition |
11 that correspond to the specified predicate(s). Before we start with |
11 that correspond to the specified predicate(s). Before we start with |
12 explaining all parts of the package, let us first give some examples |
12 explaining all parts of the package, let us first give some examples showing |
13 showing how to define inductive predicates and then also how |
13 how to define inductive predicates and then also how to generate a reasoning |
14 to generate a reasoning infrastructure for them. From the examples |
14 infrastructure for them. From the examples we will figure out a general |
15 we will figure out a general method for |
15 method for defining inductive predicates. This is usually the first step in |
16 defining inductive predicates. The aim in this section is \emph{not} to |
16 writing a package for Isabelle. The aim in this section is \emph{not} to |
17 write proofs that are as beautiful as possible, but as close as possible to |
17 write proofs that are as beautiful as possible, but as close as possible to |
18 the ML-implementation we will develop in later sections. |
18 the ML-implementation we will develop in later sections. |
|
19 |
19 |
20 |
20 We first consider the transitive closure of a relation @{text R}. The |
21 We first consider the transitive closure of a relation @{text R}. The |
21 ``pencil-and-paper'' specification for the transitive closure is: |
22 ``pencil-and-paper'' specification for the transitive closure is: |
22 |
23 |
23 \begin{center}\small |
24 \begin{center}\small |
24 @{prop[mode=Axiom] "trcl R x x"} \hspace{5mm} |
25 @{prop[mode=Axiom] "trcl R x x"} \hspace{5mm} |
25 @{prop[mode=Rule] "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z"} |
26 @{prop[mode=Rule] "R x y \<Longrightarrow> trcl R y z \<Longrightarrow> trcl R x z"} |
26 \end{center} |
27 \end{center} |
27 |
28 |
28 The package has to make an appropriate definition for @{term "trcl"}. |
29 As mentioned before, the package has to make an appropriate definition for |
29 Since an inductively |
30 @{term "trcl"}. Since an inductively defined predicate is the least |
30 defined predicate is the least predicate closed under a collection of |
31 predicate closed under a collection of introduction rules, the predicate |
31 introduction rules, the predicate @{text "trcl R x y"} can be defined so |
32 @{text "trcl R x y"} can be defined so that it holds if and only if @{text |
32 that it holds if and only if @{text "P x y"} holds for every predicate |
33 "P x y"} holds for every predicate @{text P} closed under the rules |
33 @{text P} closed under the rules above. This gives rise to the definition |
34 above. This gives rise to the definition |
34 *} |
35 *} |
35 |
36 |
36 definition "trcl \<equiv> |
37 definition "trcl \<equiv> |
37 \<lambda>R x y. \<forall>P. (\<forall>x. P x x) |
38 \<lambda>R x y. \<forall>P. (\<forall>x. P x x) |
38 \<longrightarrow> (\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z) \<longrightarrow> P x y" |
39 \<longrightarrow> (\<forall>x y z. R x y \<longrightarrow> P y z \<longrightarrow> P x z) \<longrightarrow> P x y" |
39 |
40 |
40 text {* |
41 text {* |
41 We have to use the object implication @{text "\<longrightarrow>"} and object quantification |
42 Note we have to use the object implication @{text "\<longrightarrow>"} and object |
42 @{text "\<forall>"} for stating this definition (there is no other way for |
43 quantification @{text "\<forall>"} for stating this definition (there is no other |
43 definitions in HOL). However, the introduction rules and induction |
44 way for definitions in HOL). However, the introduction rules and induction |
44 principles associated with the transitive closure should use the meta-connectives, |
45 principles associated with the transitive closure should use the |
45 since they simplify the reasoning for the user. |
46 meta-connectives, since they simplify the reasoning for the user. |
46 |
47 |
47 |
48 |
48 With this definition, the proof of the induction principle for @{term trcl} |
49 With this definition, the proof of the induction principle for @{term trcl} |
49 is almost immediate. It suffices to convert all the meta-level |
50 is almost immediate. It suffices to convert all the meta-level |
50 connectives in the lemma to object-level connectives using the |
51 connectives in the lemma to object-level connectives using the |
174 @{text blast}, @{text auto} and the like in automated proofs. The reason is |
175 @{text blast}, @{text auto} and the like in automated proofs. The reason is |
175 that you do not have precise control over them (the user can, for example, |
176 that you do not have precise control over them (the user can, for example, |
176 declare new intro- or simplification rules that can throw automatic tactics |
177 declare new intro- or simplification rules that can throw automatic tactics |
177 off course) and also it is very hard to debug proofs involving automatic |
178 off course) and also it is very hard to debug proofs involving automatic |
178 tactics whenever something goes wrong. Therefore if possible, automatic |
179 tactics whenever something goes wrong. Therefore if possible, automatic |
179 tactics should be avoided or be constrained sufficiently. |
180 tactics in packages should be avoided or be constrained sufficiently. |
180 |
181 |
181 The method of defining inductive predicates by impredicative quantification |
182 The method of defining inductive predicates by impredicative quantification |
182 also generalises to mutually inductive predicates. The next example defines |
183 also generalises to mutually inductive predicates. The next example defines |
183 the predicates @{text even} and @{text odd} given by |
184 the predicates @{text even} and @{text odd} given by |
184 |
185 |
243 THEN mp, THEN mp, THEN mp, OF r1, OF r2, OF r3]) |
244 THEN mp, THEN mp, THEN mp, OF r1, OF r2, OF r3]) |
244 done |
245 done |
245 qed |
246 qed |
246 |
247 |
247 text {* |
248 text {* |
248 The interesting lines are 7 to 15. The assumptions fall into two categories: |
249 The interesting lines are 7 to 15. Again, the assumptions fall into two categories: |
249 @{text p1} corresponds to the premise of the introduction rule; @{text "r1"} |
250 @{text p1} corresponds to the premise of the introduction rule; @{text "r1"} |
250 to @{text "r3"} come from the definition of @{text "even"}. |
251 to @{text "r3"} come from the definition of @{text "even"}. |
251 In Line 13, we apply the assumption @{text "r2"} (since we prove the second |
252 In Line 13, we apply the assumption @{text "r2"} (since we prove the second |
252 introduction rule). In Lines 14 and 15 we apply assumption @{text "p1"} (if |
253 introduction rule). In Lines 14 and 15 we apply assumption @{text "p1"} (if |
253 the second introduction rule had more premises we have to do that for all |
254 the second introduction rule had more premises we have to do that for all |