10762
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Mutual}%
|
17056
|
4 |
%
|
|
5 |
\isadelimtheory
|
|
6 |
%
|
|
7 |
\endisadelimtheory
|
|
8 |
%
|
|
9 |
\isatagtheory
|
|
10 |
%
|
|
11 |
\endisatagtheory
|
|
12 |
{\isafoldtheory}%
|
|
13 |
%
|
|
14 |
\isadelimtheory
|
|
15 |
%
|
|
16 |
\endisadelimtheory
|
10762
|
17 |
%
|
10878
|
18 |
\isamarkupsubsection{Mutually Inductive Definitions%
|
10762
|
19 |
}
|
11866
|
20 |
\isamarkuptrue%
|
10762
|
21 |
%
|
|
22 |
\begin{isamarkuptext}%
|
|
23 |
Just as there are datatypes defined by mutual recursion, there are sets defined
|
10790
|
24 |
by mutual induction. As a trivial example we consider the even and odd
|
|
25 |
natural numbers:%
|
10762
|
26 |
\end{isamarkuptext}%
|
17175
|
27 |
\isamarkuptrue%
|
23733
|
28 |
\isacommand{inductive{\isacharunderscore}set}\isamarkupfalse%
|
10762
|
29 |
\isanewline
|
25330
|
30 |
\ \ Even\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ set{\isachardoublequoteclose}\ \isakeyword{and}\isanewline
|
|
31 |
\ \ Odd\ \ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ set{\isachardoublequoteclose}\isanewline
|
23733
|
32 |
\isakeyword{where}\isanewline
|
|
33 |
\ \ zero{\isacharcolon}\ \ {\isachardoublequoteopen}{\isadigit{0}}\ {\isasymin}\ Even{\isachardoublequoteclose}\isanewline
|
|
34 |
{\isacharbar}\ EvenI{\isacharcolon}\ {\isachardoublequoteopen}n\ {\isasymin}\ Odd\ {\isasymLongrightarrow}\ Suc\ n\ {\isasymin}\ Even{\isachardoublequoteclose}\isanewline
|
|
35 |
{\isacharbar}\ OddI{\isacharcolon}\ \ {\isachardoublequoteopen}n\ {\isasymin}\ Even\ {\isasymLongrightarrow}\ Suc\ n\ {\isasymin}\ Odd{\isachardoublequoteclose}%
|
10762
|
36 |
\begin{isamarkuptext}%
|
|
37 |
\noindent
|
10790
|
38 |
The mutually inductive definition of multiple sets is no different from
|
|
39 |
that of a single set, except for induction: just as for mutually recursive
|
|
40 |
datatypes, induction needs to involve all the simultaneously defined sets. In
|
19389
|
41 |
the above case, the induction rule is called \isa{Even{\isacharunderscore}Odd{\isachardot}induct}
|
10790
|
42 |
(simply concatenate the names of the sets involved) and has the conclusion
|
10762
|
43 |
\begin{isabelle}%
|
19389
|
44 |
\ \ \ \ \ {\isacharparenleft}{\isacharquery}x\ {\isasymin}\ Even\ {\isasymlongrightarrow}\ {\isacharquery}P\ {\isacharquery}x{\isacharparenright}\ {\isasymand}\ {\isacharparenleft}{\isacharquery}y\ {\isasymin}\ Odd\ {\isasymlongrightarrow}\ {\isacharquery}Q\ {\isacharquery}y{\isacharparenright}%
|
10762
|
45 |
\end{isabelle}
|
|
46 |
|
11494
|
47 |
If we want to prove that all even numbers are divisible by two, we have to
|
10790
|
48 |
generalize the statement as follows:%
|
10762
|
49 |
\end{isamarkuptext}%
|
17175
|
50 |
\isamarkuptrue%
|
|
51 |
\isacommand{lemma}\isamarkupfalse%
|
19389
|
52 |
\ {\isachardoublequoteopen}{\isacharparenleft}m\ {\isasymin}\ Even\ {\isasymlongrightarrow}\ {\isadigit{2}}\ dvd\ m{\isacharparenright}\ {\isasymand}\ {\isacharparenleft}n\ {\isasymin}\ Odd\ {\isasymlongrightarrow}\ {\isadigit{2}}\ dvd\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}%
|
17056
|
53 |
\isadelimproof
|
|
54 |
%
|
|
55 |
\endisadelimproof
|
|
56 |
%
|
|
57 |
\isatagproof
|
16069
|
58 |
%
|
|
59 |
\begin{isamarkuptxt}%
|
|
60 |
\noindent
|
|
61 |
The proof is by rule induction. Because of the form of the induction theorem,
|
|
62 |
it is applied by \isa{rule} rather than \isa{erule} as for ordinary
|
|
63 |
inductive definitions:%
|
|
64 |
\end{isamarkuptxt}%
|
17175
|
65 |
\isamarkuptrue%
|
|
66 |
\isacommand{apply}\isamarkupfalse%
|
19389
|
67 |
{\isacharparenleft}rule\ Even{\isacharunderscore}Odd{\isachardot}induct{\isacharparenright}%
|
16069
|
68 |
\begin{isamarkuptxt}%
|
|
69 |
\begin{isabelle}%
|
|
70 |
\ {\isadigit{1}}{\isachardot}\ {\isadigit{2}}\ dvd\ {\isadigit{0}}\isanewline
|
19389
|
71 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ Odd{\isacharsemicolon}\ {\isadigit{2}}\ dvd\ Suc\ n{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isadigit{2}}\ dvd\ Suc\ n\isanewline
|
|
72 |
\ {\isadigit{3}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ Even{\isacharsemicolon}\ {\isadigit{2}}\ dvd\ n{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isadigit{2}}\ dvd\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}%
|
16069
|
73 |
\end{isabelle}
|
|
74 |
The first two subgoals are proved by simplification and the final one can be
|
|
75 |
proved in the same manner as in \S\ref{sec:rule-induction}
|
|
76 |
where the same subgoal was encountered before.
|
|
77 |
We do not show the proof script.%
|
|
78 |
\end{isamarkuptxt}%
|
17175
|
79 |
\isamarkuptrue%
|
17056
|
80 |
%
|
|
81 |
\endisatagproof
|
|
82 |
{\isafoldproof}%
|
|
83 |
%
|
|
84 |
\isadelimproof
|
|
85 |
%
|
|
86 |
\endisadelimproof
|
|
87 |
%
|
25330
|
88 |
\isamarkupsubsection{Inductively Defined Predicates\label{sec:ind-predicates}%
|
|
89 |
}
|
|
90 |
\isamarkuptrue%
|
|
91 |
%
|
|
92 |
\begin{isamarkuptext}%
|
|
93 |
\index{inductive predicates|(}
|
|
94 |
Instead of a set of even numbers one can also define a predicate on \isa{nat}:%
|
|
95 |
\end{isamarkuptext}%
|
|
96 |
\isamarkuptrue%
|
|
97 |
\isacommand{inductive}\isamarkupfalse%
|
|
98 |
\ evn\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
|
|
99 |
zero{\isacharcolon}\ {\isachardoublequoteopen}evn\ {\isadigit{0}}{\isachardoublequoteclose}\ {\isacharbar}\isanewline
|
|
100 |
step{\isacharcolon}\ {\isachardoublequoteopen}evn\ n\ {\isasymLongrightarrow}\ evn{\isacharparenleft}Suc{\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}%
|
|
101 |
\begin{isamarkuptext}%
|
|
102 |
\noindent Everything works as before, except that
|
|
103 |
you write \commdx{inductive} instead of \isacommand{inductive\_set} and
|
|
104 |
\isa{evn\ n} instead of \isa{n\ {\isasymin}\ even}. The notation is more
|
|
105 |
lightweight but the usual set-theoretic operations, e.g. \isa{Even\ {\isasymunion}\ Odd},
|
|
106 |
are not directly available on predicates.
|
|
107 |
|
|
108 |
When defining an n-ary relation as a predicate it is recommended to curry
|
|
109 |
the predicate: its type should be \isa{{\isasymtau}\isactrlisub {\isadigit{1}}\ {\isasymRightarrow}\ {\isasymdots}\ {\isasymRightarrow}\ {\isasymtau}\isactrlisub n\ {\isasymRightarrow}\ bool} rather than
|
|
110 |
\isa{{\isasymtau}\isactrlisub {\isadigit{1}}\ {\isasymtimes}\ {\isasymdots}\ {\isasymtimes}\ {\isasymtau}\isactrlisub n\ {\isasymRightarrow}\ bool}. The curried version facilitates inductions.
|
|
111 |
\index{inductive predicates|)}%
|
|
112 |
\end{isamarkuptext}%
|
|
113 |
\isamarkuptrue%
|
|
114 |
%
|
17056
|
115 |
\isadelimtheory
|
|
116 |
%
|
|
117 |
\endisadelimtheory
|
|
118 |
%
|
|
119 |
\isatagtheory
|
|
120 |
%
|
|
121 |
\endisatagtheory
|
|
122 |
{\isafoldtheory}%
|
|
123 |
%
|
|
124 |
\isadelimtheory
|
|
125 |
%
|
|
126 |
\endisadelimtheory
|
10762
|
127 |
\end{isabellebody}%
|
|
128 |
%%% Local Variables:
|
|
129 |
%%% mode: latex
|
|
130 |
%%% TeX-master: "root"
|
|
131 |
%%% End:
|