10365
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Even}%
|
17056
|
4 |
%
|
|
5 |
\isadelimtheory
|
10365
|
6 |
\isanewline
|
17056
|
7 |
%
|
|
8 |
\endisadelimtheory
|
|
9 |
%
|
|
10 |
\isatagtheory
|
17175
|
11 |
\isacommand{theory}\isamarkupfalse%
|
|
12 |
\ Even\ \isakeyword{imports}\ Main\ \isakeyword{begin}%
|
17056
|
13 |
\endisatagtheory
|
|
14 |
{\isafoldtheory}%
|
|
15 |
%
|
|
16 |
\isadelimtheory
|
|
17 |
\isanewline
|
|
18 |
%
|
|
19 |
\endisadelimtheory
|
10878
|
20 |
\isanewline
|
|
21 |
\isanewline
|
23733
|
22 |
\isacommand{inductive{\isacharunderscore}set}\isamarkupfalse%
|
17175
|
23 |
\ even\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ set{\isachardoublequoteclose}\isanewline
|
23733
|
24 |
\isakeyword{where}\isanewline
|
|
25 |
\ \ zero{\isacharbrackleft}intro{\isacharbang}{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}{\isadigit{0}}\ {\isasymin}\ even{\isachardoublequoteclose}\isanewline
|
|
26 |
{\isacharbar}\ step{\isacharbrackleft}intro{\isacharbang}{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isasymin}\ even{\isachardoublequoteclose}%
|
10365
|
27 |
\begin{isamarkuptext}%
|
10878
|
28 |
An inductive definition consists of introduction rules.
|
10365
|
29 |
|
|
30 |
\begin{isabelle}%
|
21261
|
31 |
\ \ \ \ \ n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ even%
|
10365
|
32 |
\end{isabelle}
|
|
33 |
\rulename{even.step}
|
|
34 |
|
|
35 |
\begin{isabelle}%
|
23733
|
36 |
\ \ \ \ \ {\isasymlbrakk}x\ {\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\ x%
|
10365
|
37 |
\end{isabelle}
|
|
38 |
\rulename{even.induct}
|
|
39 |
|
|
40 |
Attributes can be given to the introduction rules. Here both rules are
|
10878
|
41 |
specified as \isa{intro!}
|
|
42 |
|
|
43 |
Our first lemma states that numbers of the form $2\times k$ are even.%
|
10365
|
44 |
\end{isamarkuptext}%
|
17175
|
45 |
\isamarkuptrue%
|
|
46 |
\isacommand{lemma}\isamarkupfalse%
|
|
47 |
\ two{\isacharunderscore}times{\isacharunderscore}even{\isacharbrackleft}intro{\isacharbang}{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}{\isadigit{2}}{\isacharasterisk}k\ {\isasymin}\ even{\isachardoublequoteclose}\isanewline
|
17056
|
48 |
%
|
|
49 |
\isadelimproof
|
|
50 |
%
|
|
51 |
\endisadelimproof
|
|
52 |
%
|
|
53 |
\isatagproof
|
17175
|
54 |
\isacommand{apply}\isamarkupfalse%
|
|
55 |
\ {\isacharparenleft}induct{\isacharunderscore}tac\ k{\isacharparenright}%
|
16069
|
56 |
\begin{isamarkuptxt}%
|
|
57 |
The first step is induction on the natural number \isa{k}, which leaves
|
|
58 |
two subgoals:
|
|
59 |
\begin{isabelle}%
|
21261
|
60 |
\ {\isadigit{1}}{\isachardot}\ {\isadigit{2}}\ {\isacharasterisk}\ {\isadigit{0}}\ {\isasymin}\ even\isanewline
|
|
61 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isadigit{2}}\ {\isacharasterisk}\ n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isadigit{2}}\ {\isacharasterisk}\ Suc\ n\ {\isasymin}\ even%
|
16069
|
62 |
\end{isabelle}
|
|
63 |
Here \isa{auto} simplifies both subgoals so that they match the introduction
|
|
64 |
rules, which then are applied automatically.%
|
|
65 |
\end{isamarkuptxt}%
|
17175
|
66 |
\isamarkuptrue%
|
|
67 |
\ \isacommand{apply}\isamarkupfalse%
|
|
68 |
\ auto\isanewline
|
|
69 |
\isacommand{done}\isamarkupfalse%
|
|
70 |
%
|
17056
|
71 |
\endisatagproof
|
|
72 |
{\isafoldproof}%
|
|
73 |
%
|
|
74 |
\isadelimproof
|
|
75 |
%
|
|
76 |
\endisadelimproof
|
11866
|
77 |
%
|
10365
|
78 |
\begin{isamarkuptext}%
|
|
79 |
Our goal is to prove the equivalence between the traditional definition
|
|
80 |
of even (using the divides relation) and our inductive definition. Half of
|
|
81 |
this equivalence is trivial using the lemma just proved, whose \isa{intro!}
|
|
82 |
attribute ensures it will be applied automatically.%
|
|
83 |
\end{isamarkuptext}%
|
17175
|
84 |
\isamarkuptrue%
|
|
85 |
\isacommand{lemma}\isamarkupfalse%
|
|
86 |
\ dvd{\isacharunderscore}imp{\isacharunderscore}even{\isacharcolon}\ {\isachardoublequoteopen}{\isadigit{2}}\ dvd\ n\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even{\isachardoublequoteclose}\isanewline
|
17056
|
87 |
%
|
|
88 |
\isadelimproof
|
|
89 |
%
|
|
90 |
\endisadelimproof
|
|
91 |
%
|
|
92 |
\isatagproof
|
17175
|
93 |
\isacommand{by}\isamarkupfalse%
|
|
94 |
\ {\isacharparenleft}auto\ simp\ add{\isacharcolon}\ dvd{\isacharunderscore}def{\isacharparenright}%
|
17056
|
95 |
\endisatagproof
|
|
96 |
{\isafoldproof}%
|
|
97 |
%
|
|
98 |
\isadelimproof
|
|
99 |
%
|
|
100 |
\endisadelimproof
|
11866
|
101 |
%
|
10365
|
102 |
\begin{isamarkuptext}%
|
|
103 |
our first rule induction!%
|
|
104 |
\end{isamarkuptext}%
|
17175
|
105 |
\isamarkuptrue%
|
|
106 |
\isacommand{lemma}\isamarkupfalse%
|
|
107 |
\ even{\isacharunderscore}imp{\isacharunderscore}dvd{\isacharcolon}\ {\isachardoublequoteopen}n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isadigit{2}}\ dvd\ n{\isachardoublequoteclose}\isanewline
|
17056
|
108 |
%
|
|
109 |
\isadelimproof
|
|
110 |
%
|
|
111 |
\endisadelimproof
|
|
112 |
%
|
|
113 |
\isatagproof
|
17175
|
114 |
\isacommand{apply}\isamarkupfalse%
|
|
115 |
\ {\isacharparenleft}erule\ even{\isachardot}induct{\isacharparenright}%
|
16069
|
116 |
\begin{isamarkuptxt}%
|
|
117 |
\begin{isabelle}%
|
|
118 |
\ {\isadigit{1}}{\isachardot}\ {\isadigit{2}}\ dvd\ {\isadigit{0}}\isanewline
|
21261
|
119 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ even{\isacharsemicolon}\ {\isadigit{2}}\ dvd\ n{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isadigit{2}}\ dvd\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}%
|
16069
|
120 |
\end{isabelle}%
|
|
121 |
\end{isamarkuptxt}%
|
17175
|
122 |
\isamarkuptrue%
|
|
123 |
\isacommand{apply}\isamarkupfalse%
|
|
124 |
\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ dvd{\isacharunderscore}def{\isacharparenright}%
|
16069
|
125 |
\begin{isamarkuptxt}%
|
|
126 |
\begin{isabelle}%
|
21261
|
127 |
\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ even{\isacharsemicolon}\ {\isasymexists}k{\isachardot}\ n\ {\isacharequal}\ {\isadigit{2}}\ {\isacharasterisk}\ k{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isasymexists}k{\isachardot}\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ {\isadigit{2}}\ {\isacharasterisk}\ k%
|
16069
|
128 |
\end{isabelle}%
|
|
129 |
\end{isamarkuptxt}%
|
17175
|
130 |
\isamarkuptrue%
|
|
131 |
\isacommand{apply}\isamarkupfalse%
|
|
132 |
\ clarify%
|
16069
|
133 |
\begin{isamarkuptxt}%
|
|
134 |
\begin{isabelle}%
|
21261
|
135 |
\ {\isadigit{1}}{\isachardot}\ {\isasymAnd}n\ k{\isachardot}\ {\isadigit{2}}\ {\isacharasterisk}\ k\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isasymexists}ka{\isachardot}\ Suc\ {\isacharparenleft}Suc\ {\isacharparenleft}{\isadigit{2}}\ {\isacharasterisk}\ k{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isadigit{2}}\ {\isacharasterisk}\ ka%
|
16069
|
136 |
\end{isabelle}%
|
|
137 |
\end{isamarkuptxt}%
|
17175
|
138 |
\isamarkuptrue%
|
|
139 |
\isacommand{apply}\isamarkupfalse%
|
|
140 |
\ {\isacharparenleft}rule{\isacharunderscore}tac\ x\ {\isacharequal}\ {\isachardoublequoteopen}Suc\ k{\isachardoublequoteclose}\ \isakeyword{in}\ exI{\isacharcomma}\ simp{\isacharparenright}\isanewline
|
|
141 |
\isacommand{done}\isamarkupfalse%
|
|
142 |
%
|
17056
|
143 |
\endisatagproof
|
|
144 |
{\isafoldproof}%
|
|
145 |
%
|
|
146 |
\isadelimproof
|
|
147 |
%
|
|
148 |
\endisadelimproof
|
11866
|
149 |
%
|
10365
|
150 |
\begin{isamarkuptext}%
|
|
151 |
no iff-attribute because we don't always want to use it%
|
|
152 |
\end{isamarkuptext}%
|
17056
|
153 |
\isamarkuptrue%
|
17175
|
154 |
\isacommand{theorem}\isamarkupfalse%
|
|
155 |
\ even{\isacharunderscore}iff{\isacharunderscore}dvd{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}n\ {\isasymin}\ even{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}{\isadigit{2}}\ dvd\ n{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
17056
|
156 |
%
|
|
157 |
\isadelimproof
|
|
158 |
%
|
|
159 |
\endisadelimproof
|
|
160 |
%
|
|
161 |
\isatagproof
|
17175
|
162 |
\isacommand{by}\isamarkupfalse%
|
|
163 |
\ {\isacharparenleft}blast\ intro{\isacharcolon}\ dvd{\isacharunderscore}imp{\isacharunderscore}even\ even{\isacharunderscore}imp{\isacharunderscore}dvd{\isacharparenright}%
|
17056
|
164 |
\endisatagproof
|
|
165 |
{\isafoldproof}%
|
|
166 |
%
|
|
167 |
\isadelimproof
|
|
168 |
%
|
|
169 |
\endisadelimproof
|
11866
|
170 |
%
|
10365
|
171 |
\begin{isamarkuptext}%
|
17175
|
172 |
this result ISN'T inductive...%
|
10365
|
173 |
\end{isamarkuptext}%
|
17175
|
174 |
\isamarkuptrue%
|
|
175 |
\isacommand{lemma}\isamarkupfalse%
|
|
176 |
\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharcolon}\ {\isachardoublequoteopen}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even{\isachardoublequoteclose}\isanewline
|
17056
|
177 |
%
|
|
178 |
\isadelimproof
|
|
179 |
%
|
|
180 |
\endisadelimproof
|
|
181 |
%
|
|
182 |
\isatagproof
|
17175
|
183 |
\isacommand{apply}\isamarkupfalse%
|
|
184 |
\ {\isacharparenleft}erule\ even{\isachardot}induct{\isacharparenright}%
|
|
185 |
\begin{isamarkuptxt}%
|
|
186 |
\begin{isabelle}%
|
21261
|
187 |
\ {\isadigit{1}}{\isachardot}\ n\ {\isasymin}\ even\isanewline
|
|
188 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}na{\isachardot}\ {\isasymlbrakk}na\ {\isasymin}\ even{\isacharsemicolon}\ n\ {\isasymin}\ even{\isasymrbrakk}\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even%
|
17175
|
189 |
\end{isabelle}%
|
|
190 |
\end{isamarkuptxt}%
|
|
191 |
\isamarkuptrue%
|
|
192 |
\isacommand{oops}\isamarkupfalse%
|
|
193 |
%
|
|
194 |
\endisatagproof
|
|
195 |
{\isafoldproof}%
|
|
196 |
%
|
|
197 |
\isadelimproof
|
16069
|
198 |
%
|
17175
|
199 |
\endisadelimproof
|
|
200 |
%
|
|
201 |
\begin{isamarkuptext}%
|
|
202 |
...so we need an inductive lemma...%
|
|
203 |
\end{isamarkuptext}%
|
|
204 |
\isamarkuptrue%
|
|
205 |
\isacommand{lemma}\isamarkupfalse%
|
|
206 |
\ even{\isacharunderscore}imp{\isacharunderscore}even{\isacharunderscore}minus{\isacharunderscore}{\isadigit{2}}{\isacharcolon}\ {\isachardoublequoteopen}n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isacharminus}\ {\isadigit{2}}\ {\isasymin}\ even{\isachardoublequoteclose}\isanewline
|
|
207 |
%
|
|
208 |
\isadelimproof
|
|
209 |
%
|
|
210 |
\endisadelimproof
|
|
211 |
%
|
|
212 |
\isatagproof
|
|
213 |
\isacommand{apply}\isamarkupfalse%
|
|
214 |
\ {\isacharparenleft}erule\ even{\isachardot}induct{\isacharparenright}%
|
16069
|
215 |
\begin{isamarkuptxt}%
|
|
216 |
\begin{isabelle}%
|
21261
|
217 |
\ {\isadigit{1}}{\isachardot}\ {\isadigit{0}}\ {\isacharminus}\ {\isadigit{2}}\ {\isasymin}\ even\isanewline
|
|
218 |
\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ even{\isacharsemicolon}\ n\ {\isacharminus}\ {\isadigit{2}}\ {\isasymin}\ even{\isasymrbrakk}\ {\isasymLongrightarrow}\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharminus}\ {\isadigit{2}}\ {\isasymin}\ even%
|
16069
|
219 |
\end{isabelle}%
|
|
220 |
\end{isamarkuptxt}%
|
17175
|
221 |
\isamarkuptrue%
|
|
222 |
\isacommand{apply}\isamarkupfalse%
|
|
223 |
\ auto\isanewline
|
|
224 |
\isacommand{done}\isamarkupfalse%
|
|
225 |
%
|
17056
|
226 |
\endisatagproof
|
|
227 |
{\isafoldproof}%
|
|
228 |
%
|
|
229 |
\isadelimproof
|
|
230 |
%
|
|
231 |
\endisadelimproof
|
11866
|
232 |
%
|
10365
|
233 |
\begin{isamarkuptext}%
|
|
234 |
...and prove it in a separate step%
|
|
235 |
\end{isamarkuptext}%
|
17175
|
236 |
\isamarkuptrue%
|
|
237 |
\isacommand{lemma}\isamarkupfalse%
|
|
238 |
\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharcolon}\ {\isachardoublequoteopen}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even{\isachardoublequoteclose}\isanewline
|
17056
|
239 |
%
|
|
240 |
\isadelimproof
|
|
241 |
%
|
|
242 |
\endisadelimproof
|
|
243 |
%
|
|
244 |
\isatagproof
|
17175
|
245 |
\isacommand{by}\isamarkupfalse%
|
|
246 |
\ {\isacharparenleft}drule\ even{\isacharunderscore}imp{\isacharunderscore}even{\isacharunderscore}minus{\isacharunderscore}{\isadigit{2}}{\isacharcomma}\ simp{\isacharparenright}%
|
17056
|
247 |
\endisatagproof
|
|
248 |
{\isafoldproof}%
|
|
249 |
%
|
|
250 |
\isadelimproof
|
|
251 |
\isanewline
|
|
252 |
%
|
|
253 |
\endisadelimproof
|
15481
|
254 |
\isanewline
|
10878
|
255 |
\isanewline
|
17175
|
256 |
\isacommand{lemma}\isamarkupfalse%
|
|
257 |
\ {\isacharbrackleft}iff{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isasymin}\ even{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}n\ {\isasymin}\ even{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
17056
|
258 |
%
|
|
259 |
\isadelimproof
|
|
260 |
%
|
|
261 |
\endisadelimproof
|
|
262 |
%
|
|
263 |
\isatagproof
|
17175
|
264 |
\isacommand{by}\isamarkupfalse%
|
|
265 |
\ {\isacharparenleft}blast\ dest{\isacharcolon}\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharparenright}%
|
17056
|
266 |
\endisatagproof
|
|
267 |
{\isafoldproof}%
|
|
268 |
%
|
|
269 |
\isadelimproof
|
|
270 |
\isanewline
|
|
271 |
%
|
|
272 |
\endisadelimproof
|
|
273 |
%
|
|
274 |
\isadelimtheory
|
10365
|
275 |
\isanewline
|
17056
|
276 |
%
|
|
277 |
\endisadelimtheory
|
|
278 |
%
|
|
279 |
\isatagtheory
|
17175
|
280 |
\isacommand{end}\isamarkupfalse%
|
|
281 |
%
|
17056
|
282 |
\endisatagtheory
|
|
283 |
{\isafoldtheory}%
|
|
284 |
%
|
|
285 |
\isadelimtheory
|
|
286 |
\isanewline
|
|
287 |
%
|
|
288 |
\endisadelimtheory
|
|
289 |
\isanewline
|
10365
|
290 |
\end{isabellebody}%
|
|
291 |
%%% Local Variables:
|
|
292 |
%%% mode: latex
|
|
293 |
%%% TeX-master: "root"
|
|
294 |
%%% End:
|