17914
|
1 |
(*<*)theory Mutual imports Main begin(*>*)
|
10762
|
2 |
|
10884
|
3 |
subsection{*Mutually Inductive Definitions*}
|
10762
|
4 |
|
|
5 |
text{*
|
|
6 |
Just as there are datatypes defined by mutual recursion, there are sets defined
|
10790
|
7 |
by mutual induction. As a trivial example we consider the even and odd
|
|
8 |
natural numbers:
|
10762
|
9 |
*}
|
|
10 |
|
19389
|
11 |
consts Even :: "nat set"
|
|
12 |
Odd :: "nat set"
|
10762
|
13 |
|
19389
|
14 |
inductive Even Odd
|
10762
|
15 |
intros
|
19389
|
16 |
zero: "0 \<in> Even"
|
|
17 |
EvenI: "n \<in> Odd \<Longrightarrow> Suc n \<in> Even"
|
|
18 |
OddI: "n \<in> Even \<Longrightarrow> Suc n \<in> Odd"
|
10762
|
19 |
|
|
20 |
text{*\noindent
|
10790
|
21 |
The mutually inductive definition of multiple sets is no different from
|
|
22 |
that of a single set, except for induction: just as for mutually recursive
|
|
23 |
datatypes, induction needs to involve all the simultaneously defined sets. In
|
19389
|
24 |
the above case, the induction rule is called @{thm[source]Even_Odd.induct}
|
10790
|
25 |
(simply concatenate the names of the sets involved) and has the conclusion
|
19389
|
26 |
@{text[display]"(?x \<in> Even \<longrightarrow> ?P ?x) \<and> (?y \<in> Odd \<longrightarrow> ?Q ?y)"}
|
10762
|
27 |
|
11494
|
28 |
If we want to prove that all even numbers are divisible by two, we have to
|
10790
|
29 |
generalize the statement as follows:
|
10762
|
30 |
*}
|
|
31 |
|
19389
|
32 |
lemma "(m \<in> Even \<longrightarrow> 2 dvd m) \<and> (n \<in> Odd \<longrightarrow> 2 dvd (Suc n))"
|
10762
|
33 |
|
|
34 |
txt{*\noindent
|
10790
|
35 |
The proof is by rule induction. Because of the form of the induction theorem,
|
|
36 |
it is applied by @{text rule} rather than @{text erule} as for ordinary
|
|
37 |
inductive definitions:
|
10762
|
38 |
*}
|
|
39 |
|
19389
|
40 |
apply(rule Even_Odd.induct)
|
10762
|
41 |
|
|
42 |
txt{*
|
|
43 |
@{subgoals[display,indent=0]}
|
|
44 |
The first two subgoals are proved by simplification and the final one can be
|
|
45 |
proved in the same manner as in \S\ref{sec:rule-induction}
|
|
46 |
where the same subgoal was encountered before.
|
|
47 |
We do not show the proof script.
|
|
48 |
*}
|
|
49 |
(*<*)
|
|
50 |
apply simp
|
|
51 |
apply simp
|
12815
|
52 |
apply(simp add: dvd_def)
|
10762
|
53 |
apply(clarify)
|
|
54 |
apply(rule_tac x = "Suc k" in exI)
|
|
55 |
apply simp
|
|
56 |
done
|
|
57 |
(*>*)
|
|
58 |
(*
|
|
59 |
Exercise: 1 : odd
|
|
60 |
*)
|
10790
|
61 |
(*<*)end(*>*)
|