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