doc-src/TutorialI/Inductive/document/Mutual.tex
author wenzelm
Mon, 16 Mar 2009 17:51:24 +0100
changeset 30548 2eef5e71edd6
parent 25330 15bf0f47a87d
child 35103 d74fe18f01e9
permissions -rw-r--r--
updated generated file;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
     1
%
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
     2
\begin{isabellebody}%
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
     3
\def\isabellecontext{Mutual}%
17056
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
     4
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
     5
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
     6
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
     7
\endisadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
     8
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
     9
\isatagtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    10
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    11
\endisatagtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    12
{\isafoldtheory}%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    13
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    14
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    15
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    16
\endisadelimtheory
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    17
%
10878
b254d5ad6dd4 auto update
paulson
parents: 10790
diff changeset
    18
\isamarkupsubsection{Mutually Inductive Definitions%
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    19
}
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    20
\isamarkuptrue%
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    21
%
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    22
\begin{isamarkuptext}%
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    23
Just as there are datatypes defined by mutual recursion, there are sets defined
10790
520dd8696927 *** empty log message ***
nipkow
parents: 10762
diff changeset
    24
by mutual induction. As a trivial example we consider the even and odd
520dd8696927 *** empty log message ***
nipkow
parents: 10762
diff changeset
    25
natural numbers:%
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    26
\end{isamarkuptext}%
17175
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    27
\isamarkuptrue%
23733
3f8ad7418e55 Adapted to new inductive definition package.
berghofe
parents: 19389
diff changeset
    28
\isacommand{inductive{\isacharunderscore}set}\isamarkupfalse%
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    29
\isanewline
25330
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    30
\ \ Even\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ set{\isachardoublequoteclose}\ \isakeyword{and}\isanewline
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    31
\ \ Odd\ \ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ set{\isachardoublequoteclose}\isanewline
23733
3f8ad7418e55 Adapted to new inductive definition package.
berghofe
parents: 19389
diff changeset
    32
\isakeyword{where}\isanewline
3f8ad7418e55 Adapted to new inductive definition package.
berghofe
parents: 19389
diff changeset
    33
\ \ zero{\isacharcolon}\ \ {\isachardoublequoteopen}{\isadigit{0}}\ {\isasymin}\ Even{\isachardoublequoteclose}\isanewline
3f8ad7418e55 Adapted to new inductive definition package.
berghofe
parents: 19389
diff changeset
    34
{\isacharbar}\ EvenI{\isacharcolon}\ {\isachardoublequoteopen}n\ {\isasymin}\ Odd\ {\isasymLongrightarrow}\ Suc\ n\ {\isasymin}\ Even{\isachardoublequoteclose}\isanewline
3f8ad7418e55 Adapted to new inductive definition package.
berghofe
parents: 19389
diff changeset
    35
{\isacharbar}\ OddI{\isacharcolon}\ \ {\isachardoublequoteopen}n\ {\isasymin}\ Even\ {\isasymLongrightarrow}\ Suc\ n\ {\isasymin}\ Odd{\isachardoublequoteclose}%
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    36
\begin{isamarkuptext}%
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    37
\noindent
10790
520dd8696927 *** empty log message ***
nipkow
parents: 10762
diff changeset
    38
The mutually inductive definition of multiple sets is no different from
520dd8696927 *** empty log message ***
nipkow
parents: 10762
diff changeset
    39
that of a single set, except for induction: just as for mutually recursive
520dd8696927 *** empty log message ***
nipkow
parents: 10762
diff changeset
    40
datatypes, induction needs to involve all the simultaneously defined sets. In
19389
0d57259fea82 Even/Odd: avoid clash with even/odd of Main HOL;
wenzelm
parents: 17187
diff changeset
    41
the above case, the induction rule is called \isa{Even{\isacharunderscore}Odd{\isachardot}induct}
10790
520dd8696927 *** empty log message ***
nipkow
parents: 10762
diff changeset
    42
(simply concatenate the names of the sets involved) and has the conclusion
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    43
\begin{isabelle}%
19389
0d57259fea82 Even/Odd: avoid clash with even/odd of Main HOL;
wenzelm
parents: 17187
diff changeset
    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
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    45
\end{isabelle}
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    46
11494
23a118849801 revisions and indexing
paulson
parents: 10878
diff changeset
    47
If we want to prove that all even numbers are divisible by two, we have to
10790
520dd8696927 *** empty log message ***
nipkow
parents: 10762
diff changeset
    48
generalize the statement as follows:%
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
    49
\end{isamarkuptext}%
17175
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    50
\isamarkuptrue%
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    51
\isacommand{lemma}\isamarkupfalse%
19389
0d57259fea82 Even/Odd: avoid clash with even/odd of Main HOL;
wenzelm
parents: 17187
diff changeset
    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
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    53
\isadelimproof
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    54
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    55
\endisadelimproof
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    56
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    57
\isatagproof
16069
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    58
%
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    59
\begin{isamarkuptxt}%
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    60
\noindent
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    61
The proof is by rule induction. Because of the form of the induction theorem,
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    62
it is applied by \isa{rule} rather than \isa{erule} as for ordinary
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    63
inductive definitions:%
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    64
\end{isamarkuptxt}%
17175
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    65
\isamarkuptrue%
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    66
\isacommand{apply}\isamarkupfalse%
19389
0d57259fea82 Even/Odd: avoid clash with even/odd of Main HOL;
wenzelm
parents: 17187
diff changeset
    67
{\isacharparenleft}rule\ Even{\isacharunderscore}Odd{\isachardot}induct{\isacharparenright}%
16069
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    68
\begin{isamarkuptxt}%
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    69
\begin{isabelle}%
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    70
\ {\isadigit{1}}{\isachardot}\ {\isadigit{2}}\ dvd\ {\isadigit{0}}\isanewline
19389
0d57259fea82 Even/Odd: avoid clash with even/odd of Main HOL;
wenzelm
parents: 17187
diff changeset
    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
0d57259fea82 Even/Odd: avoid clash with even/odd of Main HOL;
wenzelm
parents: 17187
diff changeset
    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
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    73
\end{isabelle}
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    74
The first two subgoals are proved by simplification and the final one can be
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    75
proved in the same manner as in \S\ref{sec:rule-induction}
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    76
where the same subgoal was encountered before.
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    77
We do not show the proof script.%
3f2a9f400168 *** empty log message ***
nipkow
parents: 15614
diff changeset
    78
\end{isamarkuptxt}%
17175
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
    79
\isamarkuptrue%
17056
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    80
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    81
\endisatagproof
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    82
{\isafoldproof}%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    83
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    84
\isadelimproof
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    85
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    86
\endisadelimproof
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
    87
%
25330
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    88
\isamarkupsubsection{Inductively Defined Predicates\label{sec:ind-predicates}%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    89
}
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    90
\isamarkuptrue%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    91
%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    92
\begin{isamarkuptext}%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    93
\index{inductive predicates|(}
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    94
Instead of a set of even numbers one can also define a predicate on \isa{nat}:%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    95
\end{isamarkuptext}%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    96
\isamarkuptrue%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    97
\isacommand{inductive}\isamarkupfalse%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    98
\ evn\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
    99
zero{\isacharcolon}\ {\isachardoublequoteopen}evn\ {\isadigit{0}}{\isachardoublequoteclose}\ {\isacharbar}\isanewline
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   100
step{\isacharcolon}\ {\isachardoublequoteopen}evn\ n\ {\isasymLongrightarrow}\ evn{\isacharparenleft}Suc{\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   101
\begin{isamarkuptext}%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   102
\noindent Everything works as before, except that
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   103
you write \commdx{inductive} instead of \isacommand{inductive\_set} and
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   104
\isa{evn\ n} instead of \isa{n\ {\isasymin}\ even}. The notation is more
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   105
lightweight but the usual set-theoretic operations, e.g. \isa{Even\ {\isasymunion}\ Odd},
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   106
are not directly available on predicates.
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   107
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   108
When defining an n-ary relation as a predicate it is recommended to curry
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   109
the predicate: its type should be \isa{{\isasymtau}\isactrlisub {\isadigit{1}}\ {\isasymRightarrow}\ {\isasymdots}\ {\isasymRightarrow}\ {\isasymtau}\isactrlisub n\ {\isasymRightarrow}\ bool} rather than
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   110
\isa{{\isasymtau}\isactrlisub {\isadigit{1}}\ {\isasymtimes}\ {\isasymdots}\ {\isasymtimes}\ {\isasymtau}\isactrlisub n\ {\isasymRightarrow}\ bool}. The curried version facilitates inductions.
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   111
\index{inductive predicates|)}%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   112
\end{isamarkuptext}%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   113
\isamarkuptrue%
15bf0f47a87d added inductive
nipkow
parents: 23733
diff changeset
   114
%
17056
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   115
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   116
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   117
\endisadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   118
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   119
\isatagtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   120
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   121
\endisatagtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   122
{\isafoldtheory}%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   123
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   124
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   125
%
05fc32a23b8b updated;
wenzelm
parents: 16069
diff changeset
   126
\endisadelimtheory
10762
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
   127
\end{isabellebody}%
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
   128
%%% Local Variables:
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
   129
%%% mode: latex
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
   130
%%% TeX-master: "root"
cd1a2bee5549 *** empty log message ***
nipkow
parents:
diff changeset
   131
%%% End: