doc-src/IsarOverview/Isar/document/Induction.tex
author nipkow
Mon, 02 May 2005 18:29:29 +0200
changeset 15909 5f0c8a3f0226
parent 14617 a2bcb11ce445
child 16044 6887e6d12a94
permissions -rw-r--r--
fixed setsum problem
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     1
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     2
\begin{isabellebody}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     3
\def\isabellecontext{Induction}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     4
\isamarkupfalse%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     5
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     6
\isamarkupsection{Case distinction and induction \label{sec:Induct}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     7
}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     8
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     9
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    10
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    11
Computer science applications abound with inductively defined
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    12
structures, which is why we treat them in more detail. HOL already
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    13
comes with a datatype of lists with the two constructors \isa{Nil}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    14
and \isa{Cons}. \isa{Nil} is written \isa{{\isacharbrackleft}{\isacharbrackright}} and \isa{Cons\ x\ xs} is written \isa{x\ {\isacharhash}\ xs}.%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    15
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    16
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    17
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    18
\isamarkupsubsection{Case distinction\label{sec:CaseDistinction}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    19
}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    20
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    21
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    22
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    23
We have already met the \isa{cases} method for performing
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    24
binary case splits. Here is another example:%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    25
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    26
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    27
\isacommand{lemma}\ {\isachardoublequote}{\isasymnot}\ A\ {\isasymor}\ A{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    28
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    29
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    30
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    31
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    32
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    33
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    34
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    35
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    36
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    37
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    38
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    39
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    40
\noindent The two cases must come in this order because \isa{cases} merely abbreviates \isa{{\isacharparenleft}rule\ case{\isacharunderscore}split{\isacharunderscore}thm{\isacharparenright}} where
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    41
\isa{case{\isacharunderscore}split{\isacharunderscore}thm} is \isa{{\isasymlbrakk}{\isacharquery}P\ {\isasymLongrightarrow}\ {\isacharquery}Q{\isacharsemicolon}\ {\isasymnot}\ {\isacharquery}P\ {\isasymLongrightarrow}\ {\isacharquery}Q{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharquery}Q}. If we reverse
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    42
the order of the two cases in the proof, the first case would prove
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    43
\isa{{\isasymnot}\ A\ {\isasymLongrightarrow}\ {\isasymnot}\ A\ {\isasymor}\ A} which would solve the first premise of
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    44
\isa{case{\isacharunderscore}split{\isacharunderscore}thm}, instantiating \isa{{\isacharquery}P} with \isa{{\isasymnot}\ A}, thus making the second premise \isa{{\isasymnot}\ {\isasymnot}\ A\ {\isasymLongrightarrow}\ {\isasymnot}\ A\ {\isasymor}\ A}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    45
Therefore the order of subgoals is not always completely arbitrary.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    46
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    47
The above proof is appropriate if \isa{A} is textually small.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    48
However, if \isa{A} is large, we do not want to repeat it. This can
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    49
be avoided by the following idiom%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    50
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    51
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    52
\isacommand{lemma}\ {\isachardoublequote}{\isasymnot}\ A\ {\isasymor}\ A{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    53
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    54
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    55
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    56
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    57
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    58
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    59
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    60
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    61
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    62
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    63
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    64
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    65
\noindent which is like the previous proof but instantiates
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    66
\isa{{\isacharquery}P} right away with \isa{A}. Thus we could prove the two
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    67
cases in any order. The phrase `\isakeyword{case}~\isa{True}'
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    68
abbreviates `\isakeyword{assume}~\isa{True{\isacharcolon}\ A}' and analogously for
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    69
\isa{False} and \isa{{\isasymnot}\ A}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    70
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    71
The same game can be played with other datatypes, for example lists,
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    72
where \isa{tl} is the tail of a list, and \isa{length} returns a
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    73
natural number (remember: $0-1=0$):%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    74
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    75
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    76
\isamarkupfalse%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    77
\isacommand{lemma}\ {\isachardoublequote}length{\isacharparenleft}tl\ xs{\isacharparenright}\ {\isacharequal}\ length\ xs\ {\isacharminus}\ {\isadigit{1}}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    78
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    79
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    80
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    81
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    82
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    83
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    84
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    85
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    86
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
    87
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    88
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    89
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    90
\noindent Here `\isakeyword{case}~\isa{Nil}' abbreviates
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    91
`\isakeyword{assume}~\isa{Nil{\isacharcolon}}~\isa{xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}}' and
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    92
`\isakeyword{case}~\isa{Cons}'
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    93
abbreviates `\isakeyword{fix}~\isa{{\isacharquery}\ {\isacharquery}{\isacharquery}}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    94
\isakeyword{assume}~\isa{Cons{\isacharcolon}}~\isa{xs\ {\isacharequal}\ {\isacharquery}\ {\isacharhash}\ {\isacharquery}{\isacharquery}}'
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    95
where \isa{{\isacharquery}} and \isa{{\isacharquery}{\isacharquery}}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    96
stand for variable names that have been chosen by the system.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    97
Therefore we cannot refer to them.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    98
Luckily, this proof is simple enough we do not need to refer to them.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    99
However, sometimes one may have to. Hence Isar offers a simple scheme for
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   100
naming those variables: replace the anonymous \isa{Cons} by
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   101
\isa{{\isacharparenleft}Cons\ y\ ys{\isacharparenright}}, which abbreviates `\isakeyword{fix}~\isa{y\ ys}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   102
\isakeyword{assume}~\isa{Cons{\isacharcolon}}~\isa{xs\ {\isacharequal}\ y\ {\isacharhash}\ ys}'.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   103
In each \isakeyword{case} the assumption can be
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   104
referred to inside the proof by the name of the constructor. In
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   105
Section~\ref{sec:full-Ind} below we will come across an example
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   106
of this.%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   107
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   108
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   109
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   110
\isamarkupsubsection{Structural induction%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   111
}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   112
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   113
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   114
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   115
We start with an inductive proof where both cases are proved automatically:%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   116
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   117
\isamarkuptrue%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   118
\isacommand{lemma}\ {\isachardoublequote}{\isadigit{2}}\ {\isacharasterisk}\ {\isacharparenleft}{\isasymSum}i{\isacharcolon}{\isacharcolon}nat\ {\isacharequal}\ {\isadigit{0}}{\isachardot}{\isachardot}{\isacharless}n{\isacharplus}{\isadigit{1}}{\isachardot}\ i{\isacharparenright}\ {\isacharequal}\ n{\isacharasterisk}{\isacharparenleft}n{\isacharplus}{\isadigit{1}}{\isacharparenright}{\isachardoublequote}\isanewline
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   119
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   120
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   121
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   122
\begin{isamarkuptext}%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   123
\noindent The constraint \isa{{\isacharcolon}{\isacharcolon}nat} is needed because all of
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   124
the operations involved are overloaded.
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   125
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   126
If we want to expose more of the structure of the
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   127
proof, we can use pattern matching to avoid having to repeat the goal
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   128
statement:%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   129
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   130
\isamarkuptrue%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   131
\isacommand{lemma}\ {\isachardoublequote}{\isadigit{2}}\ {\isacharasterisk}\ {\isacharparenleft}{\isasymSum}i{\isacharcolon}{\isacharcolon}nat\ {\isacharequal}\ {\isadigit{0}}{\isachardot}{\isachardot}{\isacharless}n{\isacharplus}{\isadigit{1}}{\isachardot}\ i{\isacharparenright}\ {\isacharequal}\ n{\isacharasterisk}{\isacharparenleft}n{\isacharplus}{\isadigit{1}}{\isacharparenright}{\isachardoublequote}\ {\isacharparenleft}\isakeyword{is}\ {\isachardoublequote}{\isacharquery}P\ n{\isachardoublequote}{\isacharparenright}\isanewline
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   132
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   133
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   134
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   135
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   136
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   137
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   138
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   139
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   140
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   141
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   142
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   143
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   144
\noindent We could refine this further to show more of the equational
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   145
proof. Instead we explore the same avenue as for case distinctions:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   146
introducing context via the \isakeyword{case} command:%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   147
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   148
\isamarkuptrue%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   149
\isacommand{lemma}\ {\isachardoublequote}{\isadigit{2}}\ {\isacharasterisk}\ {\isacharparenleft}{\isasymSum}i{\isacharcolon}{\isacharcolon}nat\ {\isacharequal}\ {\isadigit{0}}{\isachardot}{\isachardot}{\isacharless}n{\isacharplus}{\isadigit{1}}{\isachardot}\ i{\isacharparenright}\ {\isacharequal}\ n{\isacharasterisk}{\isacharparenleft}n{\isacharplus}{\isadigit{1}}{\isacharparenright}{\isachardoublequote}\isanewline
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   150
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   151
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   152
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   153
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   154
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   155
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   156
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   157
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   158
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   159
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   160
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   161
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   162
\noindent The implicitly defined \isa{{\isacharquery}case} refers to the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   163
corresponding case to be proved, i.e.\ \isa{{\isacharquery}P\ {\isadigit{0}}} in the first case and
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   164
\isa{{\isacharquery}P{\isacharparenleft}Suc\ n{\isacharparenright}} in the second case. Context \isakeyword{case}~\isa{{\isadigit{0}}} is
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   165
empty whereas \isakeyword{case}~\isa{Suc} assumes \isa{{\isacharquery}P\ n}. Again we
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   166
have the same problem as with case distinctions: we cannot refer to an anonymous \isa{n}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   167
in the induction step because it has not been introduced via \isakeyword{fix}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   168
(in contrast to the previous proof). The solution is the one outlined for
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   169
\isa{Cons} above: replace \isa{Suc} by \isa{{\isacharparenleft}Suc\ i{\isacharparenright}}:%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   170
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   171
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   172
\isacommand{lemma}\ \isakeyword{fixes}\ n{\isacharcolon}{\isacharcolon}nat\ \isakeyword{shows}\ {\isachardoublequote}n\ {\isacharless}\ n{\isacharasterisk}n\ {\isacharplus}\ {\isadigit{1}}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   173
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   174
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   175
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   176
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   177
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   178
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   179
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   180
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   181
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   182
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   183
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   184
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   185
\noindent Of course we could again have written
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   186
\isakeyword{thus}~\isa{{\isacharquery}case} instead of giving the term explicitly
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   187
but we wanted to use \isa{i} somewhere.%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   188
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   189
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   190
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   191
\isamarkupsubsection{Induction formulae involving \isa{{\isasymAnd}} or \isa{{\isasymLongrightarrow}}\label{sec:full-Ind}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   192
}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   193
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   194
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   195
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   196
Let us now consider the situation where the goal to be proved contains
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   197
\isa{{\isasymAnd}} or \isa{{\isasymLongrightarrow}}, say \isa{{\isasymAnd}x{\isachardot}\ P\ x\ {\isasymLongrightarrow}\ Q\ x} --- motivation and a
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   198
real example follow shortly.  This means that in each case of the induction,
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   199
\isa{{\isacharquery}case} would be of the form \isa{{\isasymAnd}x{\isachardot}\ P{\isacharprime}\ x\ {\isasymLongrightarrow}\ Q{\isacharprime}\ x}.  Thus the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   200
first proof steps will be the canonical ones, fixing \isa{x} and assuming
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   201
\isa{P{\isacharprime}\ x}. To avoid this tedium, induction performs these steps
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   202
automatically: for example in case \isa{{\isacharparenleft}Suc\ n{\isacharparenright}}, \isa{{\isacharquery}case} is only
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   203
\isa{Q{\isacharprime}\ x} whereas the assumptions (named \isa{Suc}!) contain both the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   204
usual induction hypothesis \emph{and} \isa{P{\isacharprime}\ x}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   205
It should be clear how this generalises to more complex formulae.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   206
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   207
As an example we will now prove complete induction via
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   208
structural induction.%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   209
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   210
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   211
\isacommand{lemma}\ \isakeyword{assumes}\ A{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isasymAnd}n{\isachardot}\ {\isacharparenleft}{\isasymAnd}m{\isachardot}\ m\ {\isacharless}\ n\ {\isasymLongrightarrow}\ P\ m{\isacharparenright}\ {\isasymLongrightarrow}\ P\ n{\isacharparenright}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   212
\ \ \isakeyword{shows}\ {\isachardoublequote}P{\isacharparenleft}n{\isacharcolon}{\isacharcolon}nat{\isacharparenright}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   213
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   214
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   215
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   216
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   217
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   218
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   219
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   220
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   221
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   222
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   223
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   224
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   225
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   226
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   227
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   228
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   229
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   230
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   231
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   232
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   233
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   234
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   235
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   236
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   237
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   238
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   239
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   240
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   241
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   242
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   243
\noindent Given the explanations above and the comments in the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   244
proof text (only necessary for novices), the proof should be quite
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   245
readable.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   246
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   247
The statement of the lemma is interesting because it deviates from the style in
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   248
the Tutorial~\cite{LNCS2283}, which suggests to introduce \isa{{\isasymforall}} or
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   249
\isa{{\isasymlongrightarrow}} into a theorem to strengthen it for induction. In Isar
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   250
proofs we can use \isa{{\isasymAnd}} and \isa{{\isasymLongrightarrow}} instead. This simplifies the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   251
proof and means we do not have to convert between the two kinds of
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   252
connectives.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   253
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   254
Note that in a nested induction over the same data type, the inner
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   255
case labels hide the outer ones of the same name. If you want to refer
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   256
to the outer ones inside, you need to name them on the outside, e.g.\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   257
\isakeyword{note}~\isa{outer{\isacharunderscore}IH\ {\isacharequal}\ Suc}.%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   258
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   259
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   260
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   261
\isamarkupsubsection{Rule induction%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   262
}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   263
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   264
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   265
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   266
HOL also supports inductively defined sets. See \cite{LNCS2283}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   267
for details. As an example we define our own version of the reflexive
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   268
transitive closure of a relation --- HOL provides a predefined one as well.%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   269
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   270
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   271
\isacommand{consts}\ rtc\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}set\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}set{\isachardoublequote}\ \ \ {\isacharparenleft}{\isachardoublequote}{\isacharunderscore}{\isacharasterisk}{\isachardoublequote}\ {\isacharbrackleft}{\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharbrackright}\ {\isadigit{9}}{\isadigit{9}}{\isadigit{9}}{\isacharparenright}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   272
\isamarkupfalse%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   273
\isacommand{inductive}\ {\isachardoublequote}r{\isacharasterisk}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   274
\isakeyword{intros}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   275
refl{\isacharcolon}\ \ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}x{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   276
step{\isacharcolon}\ \ {\isachardoublequote}{\isasymlbrakk}\ {\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharsemicolon}\ {\isacharparenleft}y{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isamarkupfalse%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   277
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   278
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   279
\noindent
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   280
First the constant is declared as a function on binary
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   281
relations (with concrete syntax \isa{r{\isacharasterisk}} instead of \isa{rtc\ r}), then the defining clauses are given. We will now prove that
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   282
\isa{r{\isacharasterisk}} is indeed transitive:%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   283
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   284
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   285
\isacommand{lemma}\ \isakeyword{assumes}\ A{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\ \isakeyword{shows}\ {\isachardoublequote}{\isacharparenleft}y{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}\ {\isasymLongrightarrow}\ {\isacharparenleft}x{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   286
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   287
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   288
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   289
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   290
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   291
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   292
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   293
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   294
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   295
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   296
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   297
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   298
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   299
\noindent Rule induction is triggered by a fact $(x_1,\dots,x_n)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   300
\in R$ piped into the proof, here \isakeyword{using}~\isa{A}. The
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   301
proof itself follows the inductive definition very
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   302
closely: there is one case for each rule, and it has the same name as
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   303
the rule, analogous to structural induction.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   304
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   305
However, this proof is rather terse. Here is a more readable version:%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   306
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   307
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   308
\isacommand{lemma}\ \isakeyword{assumes}\ A{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}y{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\ \isakeyword{and}\ B{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}y{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   309
\ \ \isakeyword{shows}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}z{\isacharparenright}\ {\isasymin}\ r{\isacharasterisk}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   310
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   311
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   312
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   313
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   314
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   315
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   316
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   317
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   318
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   319
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   320
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   321
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   322
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   323
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   324
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   325
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   326
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   327
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   328
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   329
\noindent We start the proof with \isakeyword{from}~\isa{A\ B}. Only \isa{A} is ``consumed'' by the induction step.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   330
Since \isa{B} is left over we don't just prove \isa{{\isacharquery}thesis} but \isa{B\ {\isasymLongrightarrow}\ {\isacharquery}thesis}, just as in the previous proof. The
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   331
base case is trivial. In the assumptions for the induction step we can
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   332
see very clearly how things fit together and permit ourselves the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   333
obvious forward step \isa{IH{\isacharbrackleft}OF\ B{\isacharbrackright}}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   334
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   335
The notation `\isakeyword{case}~\isa{(}\emph{constructor} \emph{vars}\isa{)}'
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   336
is also supported for inductive definitions. The \emph{constructor} is (the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   337
name of) the rule and the \emph{vars} fix the free variables in the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   338
rule; the order of the \emph{vars} must correspond to the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   339
\emph{alphabetical order} of the variables as they appear in the rule.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   340
For example, we could start the above detailed proof of the induction
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   341
with \isakeyword{case}~\isa{(step x' x y)}. However, we can then only
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   342
refer to the assumptions named \isa{step} collectively and not
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   343
individually, as the above proof requires.%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   344
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   345
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   346
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   347
\isamarkupsubsection{More induction%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   348
}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   349
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   350
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   351
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   352
We close the section by demonstrating how arbitrary induction
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   353
rules are applied. As a simple example we have chosen recursion
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   354
induction, i.e.\ induction based on a recursive function
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   355
definition. However, most of what we show works for induction in
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   356
general.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   357
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   358
The example is an unusual definition of rotation:%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   359
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   360
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   361
\isacommand{consts}\ rot\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   362
\isamarkupfalse%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   363
\isacommand{recdef}\ rot\ {\isachardoublequote}measure\ length{\isachardoublequote}\ \ %
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   364
\isamarkupcmt{for the internal termination proof%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   365
}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   366
\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   367
{\isachardoublequote}rot\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   368
{\isachardoublequote}rot\ {\isacharbrackleft}x{\isacharbrackright}\ {\isacharequal}\ {\isacharbrackleft}x{\isacharbrackright}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   369
{\isachardoublequote}rot\ {\isacharparenleft}x{\isacharhash}y{\isacharhash}zs{\isacharparenright}\ {\isacharequal}\ y\ {\isacharhash}\ rot{\isacharparenleft}x{\isacharhash}zs{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   370
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   371
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   372
\noindent This yields, among other things, the induction rule
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   373
\isa{rot{\isachardot}induct}: \begin{isabelle}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   374
{\isasymlbrakk}P\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\ {\isasymAnd}x{\isachardot}\ P\ {\isacharbrackleft}x{\isacharbrackright}{\isacharsemicolon}\ {\isasymAnd}x\ y\ zs{\isachardot}\ P\ {\isacharparenleft}x\ {\isacharhash}\ zs{\isacharparenright}\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}x\ {\isacharhash}\ y\ {\isacharhash}\ zs{\isacharparenright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ x%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   375
\end{isabelle}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   376
In the following proof we rely on a default naming scheme for cases: they are
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   377
called 1, 2, etc, unless they have been named explicitly. The latter happens
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   378
only with datatypes and inductively defined sets, but not with recursive
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   379
functions.%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   380
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   381
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   382
\isacommand{lemma}\ {\isachardoublequote}xs\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymLongrightarrow}\ rot\ xs\ {\isacharequal}\ tl\ xs\ {\isacharat}\ {\isacharbrackleft}hd\ xs{\isacharbrackright}{\isachardoublequote}\isanewline
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   383
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   384
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   385
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   386
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   387
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   388
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   389
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   390
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   391
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   392
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   393
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   394
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   395
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   396
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   397
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   398
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   399
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   400
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   401
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   402
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   403
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   404
\isamarkupfalse%
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   405
\isamarkupfalse%
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   406
%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   407
\begin{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   408
\noindent
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   409
The third case is only shown in gory detail (see \cite{BauerW-TPHOLs01}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   410
for how to reason with chains of equations) to demonstrate that the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   411
`\isakeyword{case}~\isa{(}\emph{constructor} \emph{vars}\isa{)}' notation also
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   412
works for arbitrary induction theorems with numbered cases. The order
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   413
of the \emph{vars} corresponds to the order of the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   414
\isa{{\isasymAnd}}-quantified variables in each case of the induction
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   415
theorem. For induction theorems produced by \isakeyword{recdef} it is
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   416
the order in which the variables appear on the left-hand side of the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   417
equation.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   418
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   419
The proof is so simple that it can be condensed to%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   420
\end{isamarkuptext}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   421
\isamarkuptrue%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   422
\isamarkupfalse%
15909
5f0c8a3f0226 fixed setsum problem
nipkow
parents: 14617
diff changeset
   423
\isanewline
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   424
\isamarkupfalse%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   425
\isamarkupfalse%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   426
\end{isabellebody}%
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   427
%%% Local Variables:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   428
%%% mode: latex
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   429
%%% TeX-master: "root"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   430
%%% End: