doc-src/TutorialI/Inductive/Even.tex
author paulson
Thu, 26 Oct 2000 11:27:48 +0200
changeset 10341 6eb91805a012
parent 10325 76f318befccb
child 10419 1bfdd19c1d47
permissions -rw-r--r--
added the $Id:$ line
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10341
6eb91805a012 added the $Id:$ line
paulson
parents: 10325
diff changeset
     1
% ID:         $Id$
10325
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
     2
\section{The set of even numbers}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
     3
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
     4
The set of even numbers can be inductively defined as the least set
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
     5
containing 0 and closed under the operation ${\cdots}+2$.  Obviously,
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
     6
\emph{even} can also be expressed using the divides relation (\isa{dvd}). 
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
     7
We shall prove below that the two formulations coincide.  On the way we
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
     8
shall examine the primary means of reasoning about inductively defined
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
     9
sets: rule induction.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    10
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    11
\subsection{Making an inductive definition}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    12
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    13
Using \isacommand{consts}, we declare the constant \isa{even} to be a set
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    14
of natural numbers. The \isacommand{inductive} declaration gives it the
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    15
desired properties.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    16
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    17
\isacommand{consts}\ even\ ::\ "nat\ set"\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    18
\isacommand{inductive}\ even\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    19
\isakeyword{intros}\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    20
zero[intro!]:\ "0\ \isasymin \ even"\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    21
step[intro!]:\ "n\ \isasymin \ even\ \isasymLongrightarrow \ (Suc\ (Suc\
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    22
n))\ \isasymin \ even"
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    23
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    24
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    25
An inductive definition consists of introduction rules.  The first one
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    26
above states that 0 is even; the second states that if $n$ is even, then so
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    27
is
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    28
$n+2$.  Given this declaration, Isabelle generates a fixed point definition
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    29
for \isa{even} and proves theorems about it.  These theorems include the
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    30
introduction rules specified in the declaration, an elimination rule for case
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    31
analysis and an induction rule.  We can refer to these theorems by
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    32
automatically-generated names.  Here are two examples:
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    33
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    34
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    35
n\ \isasymin \ even\ \isasymLongrightarrow \ Suc\ (Suc\ n)\ \isasymin \
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    36
even%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    37
\rulename{even.step}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    38
\par\medskip
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    39
\isasymlbrakk xa\ \isasymin \ even;\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    40
\ P\ 0;\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    41
\ \isasymAnd n.\ \isasymlbrakk n\ \isasymin \ even;\ P\ n\isasymrbrakk \
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    42
\isasymLongrightarrow \ P\ (Suc\ (Suc\ n))\isasymrbrakk\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    43
\ \isasymLongrightarrow \ P\ xa%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    44
\rulename{even.induct}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    45
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    46
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    47
The introduction rules can be given attributes.  Here both rules are
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    48
specified as \isa{intro!}, directing the classical reasoner to 
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    49
apply them aggressively. Obviously, regarding 0 as even is safe.  The
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    50
\isa{step} rule is also safe because $n+2$ is even if and only if $n$ is
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    51
even.  We prove this equivalence later.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    52
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    53
\subsection{Using introduction rules}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    54
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    55
Our first lemma states that numbers of the form $2\times k$ are even.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    56
Introduction rules are used to show that specific values belong to the
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    57
inductive set.  Such proofs typically involve 
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    58
induction, perhaps over some other inductive set.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    59
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    60
\isacommand{lemma}\ two_times_even[intro!]:\ "\#2*k\ \isasymin \ even"
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    61
\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    62
\isacommand{apply}\ (induct\ "k")\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    63
\ \isacommand{apply}\ auto\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    64
\isacommand{done}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    65
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    66
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    67
The first step is induction on the natural number \isa{k}, which leaves
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    68
two subgoals:
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    69
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    70
\ 1.\ \#2\ *\ 0\ \isasymin \ even\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    71
\ 2.\ \isasymAnd n.\ \#2\ *\ n\ \isasymin \ even\ \isasymLongrightarrow \ \#2\ *\ Suc\ n\ \isasymin \ even
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    72
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    73
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    74
Here \isa{auto} simplifies both subgoals so that they match the introduction
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    75
rules, which are then applied automatically.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    76
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    77
Our ultimate goal is to prove the equivalence between the traditional
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    78
definition of \isa{even} (using the divides relation) and our inductive
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    79
definition.  One direction of this equivalence is immediate by the lemma
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    80
just proved, whose \isa{intro!} attribute ensures it will be used.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    81
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    82
\isacommand{lemma}\ dvd_imp_even:\ "\#2\ dvd\ n\ \isasymLongrightarrow \ n\ \isasymin \ even"\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    83
\isacommand{apply}\ (auto\ simp\ add:\ dvd_def)\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    84
\isacommand{done}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    85
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    86
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    87
\subsection{Rule induction}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    88
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    89
The other direction of this equivalence is proved by induction over the set
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    90
\isa{even}.   This type of inductive argument is called \textbf{rule induction}. 
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    91
It is the usual way of proving a property of the elements of an inductively
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    92
defined set.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    93
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    94
\isacommand{lemma}\ even_imp_dvd:\ "n\ \isasymin \ even\ \isasymLongrightarrow \ \#2\ dvd\ n"\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    95
\isacommand{apply}\ (erule\ even.induct)\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    96
\ \isacommand{apply}\ simp\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    97
\isacommand{apply}\ (simp\ add:\ dvd_def)\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    98
\isacommand{apply}\ clarify\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
    99
\isacommand{apply}\ (rule_tac\ x\ =\ "Suc\ k"\ \isakeyword{in}\ exI)\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   100
\isacommand{apply}\ simp\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   101
\isacommand{done}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   102
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   103
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   104
We begin by applying induction.  Note that \isa{even.induct} has the form
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   105
of an elimination rule, so we use the method \isa{erule}.  We get two
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   106
subgoals:
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   107
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   108
\ 1.\ \#2\ dvd\ 0\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   109
\ 2.\ \isasymAnd n.\ \isasymlbrakk n\ \isasymin \ even;\ \#2\ dvd\ n\isasymrbrakk \ \isasymLongrightarrow \ \#2\ dvd\ Suc\ (Suc\ n)
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   110
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   111
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   112
The first subgoal is trivial (by \isa{simp}).  For the second
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   113
subgoal, we unfold the definition of \isa{dvd}:
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   114
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   115
\ 1.\ \isasymAnd n.\ \isasymlbrakk n\ \isasymin \ even;\ \isasymexists k.\
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   116
n\ =\ \#2\ *\ k\isasymrbrakk \ \isasymLongrightarrow \ \isasymexists k.\
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   117
Suc\ (Suc\ n)\ =\ \#2\ *\ k
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   118
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   119
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   120
Then we use
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   121
\isa{clarify} to eliminate the existential quantifier from the assumption
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   122
and replace \isa{n} by \isa{\#2\ *\ k}.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   123
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   124
\ 1.\ \isasymAnd n\ k.\ \#2\ *\ k\ \isasymin \ even\ \isasymLongrightarrow \ \isasymexists ka.\ Suc\ (Suc\ (\#2\ *\ k))\ =\ \#2\ *\ ka%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   125
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   126
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   127
The \isa{rule_tac\ldots exI} tells Isabelle that the desired
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   128
\isa{ka} is
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   129
\isa{Suc\ k}.  With this hint, the subgoal becomes trivial, and \isa{simp}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   130
concludes the proof.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   131
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   132
\medskip
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   133
Combining the previous two results yields our objective, the
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   134
equivalence relating \isa{even} and \isa{dvd}. 
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   135
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   136
%we don't want [iff]: discuss?
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   137
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   138
\isacommand{theorem}\ even_iff_dvd:\ "(n\ \isasymin \ even)\ =\ (\#2\ dvd\ n)"\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   139
\isacommand{apply}\ (blast\ intro:\ dvd_imp_even\ even_imp_dvd)\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   140
\isacommand{done}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   141
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   142
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   143
\subsection{Generalization and rule induction}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   144
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   145
Everybody knows that when before applying induction we often must generalize
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   146
the induction formula.  This step is just as important with rule induction,
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   147
and the required generalizations can be complicated.  In this 
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   148
example, the obvious statement of the result is not inductive:
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   149
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   150
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   151
\isacommand{lemma}\ "Suc\ (Suc\ n)\ \isasymin \ even\
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   152
\isasymLongrightarrow \ n\ \isasymin \ even"\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   153
\isacommand{apply}\ (erule\ even.induct)\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   154
\isacommand{oops}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   155
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   156
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   157
Rule induction finds no occurrences of \isa{Suc\ (Suc\ n)} in the
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   158
conclusion, which it therefore leaves unchanged.  (Look at
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   159
\isa{even.induct} to see why this happens.)  We get these subgoals:
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   160
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   161
\ 1.\ n\ \isasymin \ even\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   162
\ 2.\ \isasymAnd na.\ \isasymlbrakk na\ \isasymin \ even;\ n\ \isasymin \ even\isasymrbrakk \ \isasymLongrightarrow \ n\ \isasymin \ even%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   163
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   164
The first one is hopeless.  In general, rule inductions involving
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   165
non-trivial terms will probably go wrong.  The solution is easy provided
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   166
we have the necessary inverses, here subtraction:
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   167
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   168
\isacommand{lemma}\ even_imp_even_minus_2:\ "n\ \isasymin \ even\ \isasymLongrightarrow \ n-\#2\ \isasymin \ even"\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   169
\isacommand{apply}\ (erule\ even.induct)\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   170
\ \isacommand{apply}\ auto\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   171
\isacommand{done}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   172
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   173
%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   174
This lemma is trivially inductive.  Here are the subgoals:
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   175
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   176
\ 1.\ 0\ -\ \#2\ \isasymin \ even\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   177
\ 2.\ \isasymAnd n.\ \isasymlbrakk n\ \isasymin \ even;\ n\ -\ \#2\ \isasymin \ even\isasymrbrakk \ \isasymLongrightarrow \ Suc\ (Suc\ n)\ -\ \#2\ \isasymin \ even%
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   178
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   179
The first is trivial because \isa{0\ -\ \#2} simplifies to \isa{0}, which is
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   180
even.  The second is trivial too: \isa{Suc\ (Suc\ n)\ -\ \#2} simplifies to
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   181
\isa{n}, matching the assumption.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   182
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   183
\medskip
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   184
Using our lemma, we can easily prove the result we originally wanted:
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   185
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   186
\isacommand{lemma}\ Suc_Suc_even_imp_even:\ "Suc\ (Suc\ n)\ \isasymin \ even\ \isasymLongrightarrow \ n\ \isasymin \ even"\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   187
\isacommand{apply}\ (drule\ even_imp_even_minus_2)\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   188
\isacommand{apply}\ simp\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   189
\isacommand{done}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   190
\end{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   191
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   192
We have just proved the converse of the introduction rule \isa{even.step}. 
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   193
This suggests proving the following equivalence.  We give it the \isa{iff}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   194
attribute because of its obvious value for simplification.
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   195
\begin{isabelle}
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   196
\isacommand{lemma}\ [iff]:\ "((Suc\ (Suc\ n))\ \isasymin \ even)\ =\ (n\
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   197
\isasymin \ even)"\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   198
\isacommand{apply}\ (blast\ dest:\ Suc_Suc_even_imp_even)\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   199
\isacommand{done}\isanewline
76f318befccb Even numbers section of Inductive chapter
paulson
parents:
diff changeset
   200
\end{isabelle}