10365
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Even}%
|
|
4 |
\isanewline
|
|
5 |
\isacommand{theory}\ Even\ {\isacharequal}\ Main{\isacharcolon}%
|
|
6 |
\begin{isamarkuptext}%
|
|
7 |
We begin with a simple example: the set of even numbers. Obviously this
|
|
8 |
concept can be expressed already using the divides relation (dvd). We shall
|
|
9 |
prove below that the two formulations coincide.
|
|
10 |
|
|
11 |
First, we declare the constant \isa{even} to be a set of natural numbers.
|
|
12 |
Then, an inductive declaration gives it the desired properties.%
|
|
13 |
\end{isamarkuptext}%
|
|
14 |
\isacommand{consts}\ even\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}nat\ set{\isachardoublequote}\isanewline
|
|
15 |
\isacommand{inductive}\ even\isanewline
|
|
16 |
\isakeyword{intros}\isanewline
|
|
17 |
zero{\isacharbrackleft}intro{\isacharbang}{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isadigit{0}}\ {\isasymin}\ even{\isachardoublequote}\isanewline
|
|
18 |
step{\isacharbrackleft}intro{\isacharbang}{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isasymin}\ even{\isachardoublequote}%
|
|
19 |
\begin{isamarkuptext}%
|
|
20 |
An inductive definition consists of introduction rules. The first one
|
|
21 |
above states that 0 is even; the second states that if $n$ is even, so is
|
|
22 |
$n+2$. Given this declaration, Isabelle generates a fixed point definition
|
|
23 |
for \isa{even} and proves many theorems about it. These theorems include the
|
|
24 |
introduction rules specified in the declaration, an elimination rule for case
|
|
25 |
analysis and an induction rule. We can refer to these theorems by
|
|
26 |
automatically-generated names:
|
|
27 |
|
|
28 |
\begin{isabelle}%
|
|
29 |
\ \ \ \ \ n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ even%
|
|
30 |
\end{isabelle}
|
|
31 |
\rulename{even.step}
|
|
32 |
|
|
33 |
\begin{isabelle}%
|
10645
|
34 |
\ \ \ \ \ {\isasymlbrakk}xa\ {\isasymin}\ even{\isacharsemicolon}\ P\ {\isadigit{0}}{\isacharsemicolon}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ even{\isacharsemicolon}\ P\ n{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ xa%
|
10365
|
35 |
\end{isabelle}
|
|
36 |
\rulename{even.induct}
|
|
37 |
|
|
38 |
Attributes can be given to the introduction rules. Here both rules are
|
|
39 |
specified as \isa{intro!}, which will cause them to be applied aggressively.
|
|
40 |
Obviously, regarding 0 as even is always safe. The second rule is also safe
|
|
41 |
because $n+2$ is even if and only if $n$ is even. We prove this equivalence
|
|
42 |
later.%
|
|
43 |
\end{isamarkuptext}%
|
|
44 |
%
|
|
45 |
\begin{isamarkuptext}%
|
|
46 |
Our first lemma states that numbers of the form $2\times k$ are even.
|
|
47 |
Introduction rules are used to show that given values belong to the inductive
|
|
48 |
set. Often, as here, the proof involves some other sort of induction.%
|
|
49 |
\end{isamarkuptext}%
|
|
50 |
\isacommand{lemma}\ two{\isacharunderscore}times{\isacharunderscore}even{\isacharbrackleft}intro{\isacharbang}{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isacharhash}{\isadigit{2}}{\isacharasterisk}k\ {\isasymin}\ even{\isachardoublequote}\isanewline
|
|
51 |
\isacommand{apply}\ {\isacharparenleft}induct\ {\isachardoublequote}k{\isachardoublequote}{\isacharparenright}\isanewline
|
|
52 |
\ \isacommand{apply}\ auto\isanewline
|
|
53 |
\isacommand{done}%
|
|
54 |
\begin{isamarkuptext}%
|
|
55 |
The first step is induction on the natural number \isa{k}, which leaves
|
|
56 |
two subgoals:
|
|
57 |
|
|
58 |
pr(latex xsymbols symbols);
|
|
59 |
proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{1}}\isanewline
|
|
60 |
\isanewline
|
|
61 |
goal\ {\isacharparenleft}lemma\ two{\isacharunderscore}times{\isacharunderscore}even{\isacharparenright}{\isacharcolon}\isanewline
|
|
62 |
{\isacharhash}{\isadigit{2}}\ {\isacharasterisk}\ k\ {\isasymin}\ even\isanewline
|
|
63 |
\ {\isadigit{1}}{\isachardot}\ {\isacharhash}{\isadigit{2}}\ {\isacharasterisk}\ {\isadigit{0}}\ {\isasymin}\ even\isanewline
|
|
64 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isacharhash}{\isadigit{2}}\ {\isacharasterisk}\ n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isacharhash}{\isadigit{2}}\ {\isacharasterisk}\ Suc\ n\ {\isasymin}\ even
|
|
65 |
|
|
66 |
Here \isa{auto} simplifies both subgoals so that they match the introduction
|
|
67 |
rules, which then are applied automatically.%
|
|
68 |
\end{isamarkuptext}%
|
|
69 |
%
|
|
70 |
\begin{isamarkuptext}%
|
|
71 |
Our goal is to prove the equivalence between the traditional definition
|
|
72 |
of even (using the divides relation) and our inductive definition. Half of
|
|
73 |
this equivalence is trivial using the lemma just proved, whose \isa{intro!}
|
|
74 |
attribute ensures it will be applied automatically.%
|
|
75 |
\end{isamarkuptext}%
|
|
76 |
\isacommand{lemma}\ dvd{\isacharunderscore}imp{\isacharunderscore}even{\isacharcolon}\ {\isachardoublequote}{\isacharhash}{\isadigit{2}}\ dvd\ n\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even{\isachardoublequote}\isanewline
|
|
77 |
\isacommand{apply}\ {\isacharparenleft}auto\ simp\ add{\isacharcolon}\ dvd{\isacharunderscore}def{\isacharparenright}\isanewline
|
|
78 |
\isacommand{done}%
|
|
79 |
\begin{isamarkuptext}%
|
|
80 |
our first rule induction!%
|
|
81 |
\end{isamarkuptext}%
|
|
82 |
\isacommand{lemma}\ even{\isacharunderscore}imp{\isacharunderscore}dvd{\isacharcolon}\ {\isachardoublequote}n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isacharhash}{\isadigit{2}}\ dvd\ n{\isachardoublequote}\isanewline
|
|
83 |
\isacommand{apply}\ {\isacharparenleft}erule\ even{\isachardot}induct{\isacharparenright}\isanewline
|
|
84 |
\ \isacommand{apply}\ simp\isanewline
|
|
85 |
\isacommand{apply}\ {\isacharparenleft}simp\ add{\isacharcolon}\ dvd{\isacharunderscore}def{\isacharparenright}\isanewline
|
|
86 |
\isacommand{apply}\ clarify\isanewline
|
|
87 |
\isacommand{apply}\ {\isacharparenleft}rule{\isacharunderscore}tac\ x\ {\isacharequal}\ {\isachardoublequote}Suc\ k{\isachardoublequote}\ \isakeyword{in}\ exI{\isacharparenright}\isanewline
|
|
88 |
\isacommand{apply}\ simp\isanewline
|
|
89 |
\isacommand{done}%
|
|
90 |
\begin{isamarkuptext}%
|
|
91 |
proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{1}}\isanewline
|
|
92 |
\isanewline
|
|
93 |
goal\ {\isacharparenleft}lemma\ even{\isacharunderscore}imp{\isacharunderscore}dvd{\isacharparenright}{\isacharcolon}\isanewline
|
|
94 |
n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isacharhash}{\isadigit{2}}\ dvd\ n\isanewline
|
|
95 |
\ {\isadigit{1}}{\isachardot}\ {\isacharhash}{\isadigit{2}}\ dvd\ {\isadigit{0}}\isanewline
|
|
96 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ even{\isacharsemicolon}\ {\isacharhash}{\isadigit{2}}\ dvd\ n{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharhash}{\isadigit{2}}\ dvd\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}
|
|
97 |
|
|
98 |
proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{3}}\isanewline
|
|
99 |
\isanewline
|
|
100 |
goal\ {\isacharparenleft}lemma\ even{\isacharunderscore}imp{\isacharunderscore}dvd{\isacharparenright}{\isacharcolon}\isanewline
|
|
101 |
n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isacharhash}{\isadigit{2}}\ dvd\ n\isanewline
|
|
102 |
\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ even{\isacharsemicolon}\ {\isasymexists}k{\isachardot}\ n\ {\isacharequal}\ {\isacharhash}{\isadigit{2}}\ {\isacharasterisk}\ k{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isasymexists}k{\isachardot}\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ {\isacharhash}{\isadigit{2}}\ {\isacharasterisk}\ k
|
|
103 |
|
|
104 |
proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{4}}\isanewline
|
|
105 |
\isanewline
|
|
106 |
goal\ {\isacharparenleft}lemma\ even{\isacharunderscore}imp{\isacharunderscore}dvd{\isacharparenright}{\isacharcolon}\isanewline
|
|
107 |
n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isacharhash}{\isadigit{2}}\ dvd\ n\isanewline
|
|
108 |
\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}n\ k{\isachardot}\ {\isacharhash}{\isadigit{2}}\ {\isacharasterisk}\ k\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isasymexists}ka{\isachardot}\ Suc\ {\isacharparenleft}Suc\ {\isacharparenleft}{\isacharhash}{\isadigit{2}}\ {\isacharasterisk}\ k{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharhash}{\isadigit{2}}\ {\isacharasterisk}\ ka%
|
|
109 |
\end{isamarkuptext}%
|
|
110 |
%
|
|
111 |
\begin{isamarkuptext}%
|
|
112 |
no iff-attribute because we don't always want to use it%
|
|
113 |
\end{isamarkuptext}%
|
|
114 |
\isacommand{theorem}\ even{\isacharunderscore}iff{\isacharunderscore}dvd{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}n\ {\isasymin}\ even{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}{\isacharhash}{\isadigit{2}}\ dvd\ n{\isacharparenright}{\isachardoublequote}\isanewline
|
|
115 |
\isacommand{apply}\ {\isacharparenleft}blast\ intro{\isacharcolon}\ dvd{\isacharunderscore}imp{\isacharunderscore}even\ even{\isacharunderscore}imp{\isacharunderscore}dvd{\isacharparenright}\isanewline
|
|
116 |
\isacommand{done}%
|
|
117 |
\begin{isamarkuptext}%
|
|
118 |
this result ISN'T inductive...%
|
|
119 |
\end{isamarkuptext}%
|
|
120 |
\isacommand{lemma}\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharcolon}\ {\isachardoublequote}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even{\isachardoublequote}\isanewline
|
|
121 |
\isacommand{apply}\ {\isacharparenleft}erule\ even{\isachardot}induct{\isacharparenright}\isanewline
|
|
122 |
\isacommand{oops}%
|
|
123 |
\begin{isamarkuptext}%
|
|
124 |
proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{1}}\isanewline
|
|
125 |
\isanewline
|
|
126 |
goal\ {\isacharparenleft}lemma\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharparenright}{\isacharcolon}\isanewline
|
|
127 |
Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even\isanewline
|
|
128 |
\ {\isadigit{1}}{\isachardot}\ n\ {\isasymin}\ even\isanewline
|
|
129 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}na{\isachardot}\ {\isasymlbrakk}na\ {\isasymin}\ even{\isacharsemicolon}\ n\ {\isasymin}\ even{\isasymrbrakk}\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even%
|
|
130 |
\end{isamarkuptext}%
|
|
131 |
%
|
|
132 |
\begin{isamarkuptext}%
|
|
133 |
...so we need an inductive lemma...%
|
|
134 |
\end{isamarkuptext}%
|
|
135 |
\isacommand{lemma}\ even{\isacharunderscore}imp{\isacharunderscore}even{\isacharunderscore}minus{\isacharunderscore}{\isadigit{2}}{\isacharcolon}\ {\isachardoublequote}n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n{\isacharminus}{\isacharhash}{\isadigit{2}}\ {\isasymin}\ even{\isachardoublequote}\isanewline
|
|
136 |
\isacommand{apply}\ {\isacharparenleft}erule\ even{\isachardot}induct{\isacharparenright}\isanewline
|
|
137 |
\isacommand{apply}\ auto\isanewline
|
|
138 |
\isacommand{done}%
|
|
139 |
\begin{isamarkuptext}%
|
|
140 |
proof\ {\isacharparenleft}prove{\isacharparenright}{\isacharcolon}\ step\ {\isadigit{1}}\isanewline
|
|
141 |
\isanewline
|
|
142 |
goal\ {\isacharparenleft}lemma\ even{\isacharunderscore}imp{\isacharunderscore}even{\isacharunderscore}minus{\isacharunderscore}{\isadigit{2}}{\isacharparenright}{\isacharcolon}\isanewline
|
|
143 |
n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isacharminus}\ {\isacharhash}{\isadigit{2}}\ {\isasymin}\ even\isanewline
|
|
144 |
\ {\isadigit{1}}{\isachardot}\ {\isadigit{0}}\ {\isacharminus}\ {\isacharhash}{\isadigit{2}}\ {\isasymin}\ even\isanewline
|
|
145 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ even{\isacharsemicolon}\ n\ {\isacharminus}\ {\isacharhash}{\isadigit{2}}\ {\isasymin}\ even{\isasymrbrakk}\ {\isasymLongrightarrow}\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharminus}\ {\isacharhash}{\isadigit{2}}\ {\isasymin}\ even%
|
|
146 |
\end{isamarkuptext}%
|
|
147 |
%
|
|
148 |
\begin{isamarkuptext}%
|
|
149 |
...and prove it in a separate step%
|
|
150 |
\end{isamarkuptext}%
|
|
151 |
\isacommand{lemma}\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharcolon}\ {\isachardoublequote}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even{\isachardoublequote}\isanewline
|
|
152 |
\isacommand{apply}\ {\isacharparenleft}drule\ even{\isacharunderscore}imp{\isacharunderscore}even{\isacharunderscore}minus{\isacharunderscore}{\isadigit{2}}{\isacharparenright}\isanewline
|
|
153 |
\isacommand{apply}\ simp\isanewline
|
|
154 |
\isacommand{done}\isanewline
|
|
155 |
\isanewline
|
|
156 |
\isacommand{lemma}\ {\isacharbrackleft}iff{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isasymin}\ even{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}n\ {\isasymin}\ even{\isacharparenright}{\isachardoublequote}\isanewline
|
|
157 |
\isacommand{apply}\ {\isacharparenleft}blast\ dest{\isacharcolon}\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharparenright}\isanewline
|
|
158 |
\isacommand{done}\isanewline
|
|
159 |
\isanewline
|
|
160 |
\isacommand{end}\isanewline
|
|
161 |
\isanewline
|
|
162 |
\end{isabellebody}%
|
|
163 |
%%% Local Variables:
|
|
164 |
%%% mode: latex
|
|
165 |
%%% TeX-master: "root"
|
|
166 |
%%% End:
|