| 10762 |      1 | (*<*)theory Mutual = Main:(*>*)
 | 
|  |      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 | 
 | 
|  |     11 | consts even :: "nat set"
 | 
|  |     12 |        odd  :: "nat set"
 | 
|  |     13 | 
 | 
|  |     14 | inductive even odd
 | 
|  |     15 | intros
 | 
|  |     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"
 | 
|  |     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
 | 
|  |     24 | the above case, the induction rule is called @{thm[source]even_odd.induct}
 | 
|  |     25 | (simply concatenate the names of the sets involved) and has the conclusion
 | 
| 10762 |     26 | @{text[display]"(?x \<in> even \<longrightarrow> ?P ?x) \<and> (?y \<in> odd \<longrightarrow> ?Q ?y)"}
 | 
|  |     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 | 
 | 
|  |     32 | lemma "(m \<in> even \<longrightarrow> 2 dvd m) \<and> (n \<in> odd \<longrightarrow> 2 dvd (Suc n))"
 | 
|  |     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 | 
 | 
|  |     40 | apply(rule even_odd.induct)
 | 
|  |     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(*>*)
 |