13202
|
1 |
|
|
2 |
(*<*)
|
|
3 |
theory Tutorial = Main:
|
|
4 |
(*>*)
|
|
5 |
|
|
6 |
chapter {* Introduction *}
|
|
7 |
|
13227
|
8 |
chapter {* Technical issues *}
|
|
9 |
|
|
10 |
section {* Source texts *}
|
|
11 |
|
|
12 |
section {* Interaction and debugging *}
|
|
13 |
|
13205
|
14 |
section {* Step-by-step examples *}
|
|
15 |
|
|
16 |
subsection {* Summing natural numbers *}
|
|
17 |
|
|
18 |
theorem "2 * (\<Sum>i < n + 1. i) = n * (n + 1)" (is "?P n")
|
|
19 |
proof (induct n)
|
|
20 |
case 0
|
|
21 |
then show "?P 0" by simp
|
|
22 |
next
|
|
23 |
case (Suc n)
|
|
24 |
let "?S n = _" = "?P n"
|
|
25 |
have "?S (n + 1) = ?S n + 2 * (n + 1)" by simp
|
|
26 |
also have "?S n = n * (n + 1)" .
|
|
27 |
also have "\<dots> + 2 * (n + 1) = (n + 1) * (n + 2)" by simp
|
|
28 |
finally show "?P (Suc n)" by simp
|
|
29 |
qed
|
|
30 |
|
|
31 |
theorem "2 * (\<Sum>i < n + 1. i) = n * (n + 1)"
|
|
32 |
proof (induct n)
|
|
33 |
case 0
|
|
34 |
then show ?case by simp
|
|
35 |
next
|
|
36 |
case Suc
|
|
37 |
then show ?case by simp
|
|
38 |
qed
|
|
39 |
|
|
40 |
theorem "2 * (\<Sum>i < n + 1. i) = n * (n + 1)"
|
|
41 |
by (induct n) simp_all
|
|
42 |
|
|
43 |
theorem "2 * (\<Sum>i < n + 1. i) = n * (n + 1)"
|
|
44 |
apply (induct n)
|
|
45 |
apply simp_all
|
|
46 |
done
|
|
47 |
|
|
48 |
|
|
49 |
|
13202
|
50 |
chapter {* Interaction and debugging *}
|
|
51 |
|
|
52 |
chapter {* Calculational reasoning *}
|
|
53 |
|
|
54 |
chapter {* Proof by cases and induction *}
|
|
55 |
|
|
56 |
chapter {* General natural deduction *}
|
|
57 |
|
|
58 |
chapter {* Example: FIXME *}
|
|
59 |
|
|
60 |
|
|
61 |
chapter FIXME
|
|
62 |
|
|
63 |
|
|
64 |
section {* Formal document preparation *}
|
|
65 |
|
|
66 |
subsection {* Example *}
|
|
67 |
|
|
68 |
text {*
|
|
69 |
See this very document itself.
|
|
70 |
*}
|
|
71 |
|
|
72 |
subsection {* Getting started *}
|
|
73 |
|
|
74 |
text {*
|
|
75 |
\verb"isatool mkdir Test && isatool make"
|
|
76 |
*}
|
|
77 |
|
|
78 |
section {* Human-readable proof composition in Isar *}
|
|
79 |
|
|
80 |
subsection {* Getting started *}
|
|
81 |
|
|
82 |
text {* Claim a trivial goal in order to enter proof mode @{text \<dots>} *}
|
|
83 |
|
|
84 |
lemma True
|
|
85 |
proof
|
|
86 |
|
|
87 |
txt {* After the canonical initial refinement step we are left
|
|
88 |
within an \emph{proof body}. *}
|
|
89 |
|
|
90 |
txt {* Here we may augment the present local {proof context} as we
|
|
91 |
please. *}
|
|
92 |
|
|
93 |
fix something
|
|
94 |
assume a: "anything something"
|
|
95 |
|
|
96 |
txt {* Note that the present configuration may be inspected by
|
|
97 |
several \emph{diagnostic commands}. *}
|
|
98 |
|
|
99 |
term something -- "@{term [show_types] something}"
|
|
100 |
term anything -- "@{term [show_types] anything}"
|
|
101 |
thm a -- {* @{thm a} *}
|
|
102 |
|
|
103 |
txt {* We may state local (auxiliary) results as well. *}
|
|
104 |
|
|
105 |
have True proof qed
|
|
106 |
|
|
107 |
txt {* We are now satisfied. *}
|
|
108 |
qed
|
|
109 |
|
|
110 |
|
|
111 |
subsection {* Calculational Reasoning *}
|
|
112 |
|
|
113 |
text {*
|
|
114 |
Isar is mainly about Natural Deduction, but Calculational Reasoning
|
|
115 |
turns out as a simplified instance of that, so we demonstrate it
|
|
116 |
first.
|
|
117 |
*}
|
|
118 |
|
|
119 |
subsubsection {* Transitive chains *}
|
|
120 |
|
|
121 |
text {*
|
|
122 |
Technique: establish a chain of local facts, separated by \cmd{also}
|
|
123 |
and terminated by \cmd{finally}; another goal has to follow to point
|
|
124 |
out the final result.
|
|
125 |
*}
|
|
126 |
|
|
127 |
lemma "x1 = x4"
|
|
128 |
proof - -- "do nothing yet"
|
|
129 |
have "x1 = x2" sorry
|
|
130 |
also
|
|
131 |
have "x2 = x3" sorry
|
|
132 |
also
|
|
133 |
have "x3 = x4" sorry
|
|
134 |
finally
|
|
135 |
show "x1 = x4" .
|
|
136 |
qed
|
|
137 |
|
|
138 |
text {*
|
|
139 |
This may be written more succinctly, using the special term binds
|
|
140 |
``@{text \<dots>}'' (for the right-hand side of the last statement) and
|
|
141 |
``@{text ?thesis}'' (for the original claim at the head of the
|
|
142 |
proof).
|
|
143 |
*}
|
|
144 |
|
|
145 |
lemma "x1 = x4"
|
|
146 |
proof -
|
|
147 |
have "x1 = x2" sorry
|
|
148 |
also have "\<dots> = x3" sorry
|
|
149 |
also have "\<dots> = x4" sorry
|
|
150 |
finally show ?thesis .
|
|
151 |
qed
|
|
152 |
|
|
153 |
text {*
|
|
154 |
The (implicit) forward-chaining steps involved in \cmd{also} and
|
|
155 |
\cmd{finally} are declared in the current context. The main library
|
|
156 |
of Isabelle/HOL already knows about (mixed) transitivities of @{text
|
|
157 |
"="}, @{text "<"}, @{text "\<le>"} etc.
|
|
158 |
*}
|
|
159 |
|
|
160 |
lemma "(x1::nat) < x6"
|
|
161 |
-- {* restriction to type @{typ nat} ensures that @{text "<"} is really transitive *}
|
|
162 |
proof -
|
|
163 |
have "x1 < x2" sorry
|
|
164 |
also have "\<dots> \<le> x3" sorry
|
|
165 |
also have "\<dots> = x4" sorry
|
|
166 |
also have "\<dots> < x5" sorry
|
|
167 |
also have "\<dots> = x6" sorry
|
|
168 |
finally show ?thesis .
|
|
169 |
qed
|
|
170 |
|
|
171 |
text {*
|
|
172 |
We may also calculate on propositions.
|
|
173 |
*}
|
|
174 |
|
|
175 |
lemma True
|
|
176 |
proof
|
|
177 |
have "A \<longrightarrow> B \<longrightarrow> C" sorry
|
|
178 |
also have A sorry
|
|
179 |
also have B sorry
|
|
180 |
finally have C .
|
|
181 |
qed
|
|
182 |
|
|
183 |
text {*
|
|
184 |
This is getting pretty close to Dijkstra's preferred proof style.
|
|
185 |
*}
|
|
186 |
|
|
187 |
lemma True
|
|
188 |
proof
|
|
189 |
have [trans]: "\<And>X Y Z. X \<longrightarrow> Y \<Longrightarrow> Y \<longrightarrow> Z \<Longrightarrow> X \<longrightarrow> Z" by rules
|
|
190 |
have "A \<longrightarrow> B" sorry
|
|
191 |
also have "\<dots> \<longrightarrow> C" sorry
|
|
192 |
also have "\<dots> \<longrightarrow> D" sorry
|
|
193 |
finally have "A \<longrightarrow> D" .
|
|
194 |
qed
|
|
195 |
|
|
196 |
|
|
197 |
subsubsection {* Degenerate calculations and bigstep reasoning *}
|
|
198 |
|
|
199 |
text {*
|
|
200 |
Instead of \cmd{also}/\cmd{finally} we may use degenerative steps
|
|
201 |
\cmd{moreover}/\cmd{ultimately} to accumulate facts, without
|
|
202 |
applying any forward rules yet.
|
|
203 |
*}
|
|
204 |
|
|
205 |
lemma True
|
|
206 |
proof
|
|
207 |
have A sorry
|
|
208 |
moreover have B sorry
|
|
209 |
moreover have C sorry
|
|
210 |
ultimately have A and B and C . -- "Pretty obvious, right?"
|
|
211 |
qed
|
|
212 |
|
|
213 |
text {*
|
|
214 |
Both kinds of calculational elements may be used together.
|
|
215 |
*}
|
|
216 |
|
|
217 |
lemma True
|
|
218 |
proof
|
|
219 |
assume reasoning_pattern [trans]: "A \<Longrightarrow> B \<Longrightarrow> C \<Longrightarrow> D"
|
|
220 |
have A sorry
|
|
221 |
moreover have B sorry
|
|
222 |
moreover have C sorry
|
|
223 |
finally have D .
|
|
224 |
qed
|
|
225 |
|
|
226 |
|
|
227 |
subsection {* Natural deduction *}
|
|
228 |
|
|
229 |
subsubsection {* Primitive patterns *}
|
|
230 |
|
|
231 |
text {*
|
|
232 |
The default theory context admits to perform canonical single-step
|
|
233 |
reasoning (similar to Gentzen) without further ado.
|
|
234 |
*}
|
|
235 |
|
|
236 |
lemma True
|
|
237 |
proof
|
|
238 |
|
|
239 |
have True ..
|
|
240 |
|
|
241 |
{ assume False
|
|
242 |
then have C .. }
|
|
243 |
|
|
244 |
have "\<not> A"
|
|
245 |
proof
|
|
246 |
assume A
|
|
247 |
show False sorry
|
|
248 |
qed
|
|
249 |
|
|
250 |
{ assume "\<not> A" and A
|
|
251 |
then have C .. }
|
|
252 |
|
|
253 |
have "A \<longrightarrow> B"
|
|
254 |
proof
|
|
255 |
assume A
|
|
256 |
show B sorry
|
|
257 |
qed
|
|
258 |
|
|
259 |
{ assume "A \<longrightarrow> B" and A
|
|
260 |
then have B .. }
|
|
261 |
|
|
262 |
have "A \<and> B"
|
|
263 |
proof
|
|
264 |
show A sorry
|
|
265 |
show B sorry
|
|
266 |
qed
|
|
267 |
|
|
268 |
{ assume "A \<and> B"
|
|
269 |
then have A .. }
|
|
270 |
|
|
271 |
{ assume "A \<and> B"
|
|
272 |
then have B .. }
|
|
273 |
|
|
274 |
{ assume A
|
|
275 |
then have "A \<or> B" .. }
|
|
276 |
|
|
277 |
{ assume B
|
|
278 |
then have "A \<or> B" .. }
|
|
279 |
|
|
280 |
{ assume "A \<or> B"
|
|
281 |
then have C
|
|
282 |
proof
|
|
283 |
assume A
|
|
284 |
then show ?thesis sorry
|
|
285 |
next
|
|
286 |
assume B
|
|
287 |
then show ?thesis sorry
|
|
288 |
qed }
|
|
289 |
|
|
290 |
have "\<forall>x. P x"
|
|
291 |
proof
|
|
292 |
fix x
|
|
293 |
show "P x" sorry
|
|
294 |
qed
|
|
295 |
|
|
296 |
{ assume "\<forall>x. P x"
|
|
297 |
then have "P t" .. }
|
|
298 |
|
|
299 |
have "\<exists>x. P x"
|
|
300 |
proof
|
|
301 |
show "P t" sorry
|
|
302 |
qed
|
|
303 |
|
|
304 |
{ assume "\<exists>x. P x"
|
|
305 |
then obtain x where "P x" ..
|
|
306 |
note nothing -- "relax" }
|
|
307 |
qed
|
|
308 |
|
|
309 |
text {*
|
|
310 |
Certainly, this works with derived rules for defined concepts in the
|
|
311 |
same manner. E.g.\ use the simple-typed set-theory of Isabelle/HOL. *}
|
|
312 |
|
|
313 |
lemma True
|
|
314 |
proof
|
|
315 |
have "y \<in> (\<Inter>x \<in> A. B x)"
|
|
316 |
proof
|
|
317 |
fix x
|
|
318 |
assume "x \<in> A"
|
|
319 |
show "y \<in> B x" sorry
|
|
320 |
qed
|
|
321 |
|
|
322 |
have "y \<in> (\<Union>x \<in> A. B x)"
|
|
323 |
proof
|
|
324 |
show "a \<in> A" sorry
|
|
325 |
show "y \<in> B a" sorry
|
|
326 |
qed
|
|
327 |
qed
|
|
328 |
|
|
329 |
|
|
330 |
subsubsection {* Variations in structure *}
|
|
331 |
|
|
332 |
text {*
|
|
333 |
The design of the Isar language takes the user seriously
|
|
334 |
*}
|
|
335 |
|
|
336 |
subsubsection {* Generalized elimination *}
|
|
337 |
|
|
338 |
subsubsection {* Scalable cases and induction *}
|
|
339 |
|
|
340 |
section {* Assimilating the old tactical style *}
|
|
341 |
|
|
342 |
text {*
|
|
343 |
Improper commands:
|
|
344 |
Observation: every Isar subproof may start with a ``script'' of
|
|
345 |
*}
|
|
346 |
|
|
347 |
(*<*)
|
|
348 |
end
|
|
349 |
(*>*)
|