|
13267
|
1 |
(*<*)theory Logic = Main:(*>*)
|
|
|
2 |
|
|
|
3 |
text{*
|
|
|
4 |
We begin by looking at a simplified grammar for Isar proofs:
|
|
|
5 |
\begin{center}
|
|
|
6 |
\begin{tabular}{lrl}
|
|
|
7 |
\emph{proof} & ::= & \isacommand{proof} \emph{method}$^?$
|
|
|
8 |
\emph{statement}*
|
|
|
9 |
\isacommand{qed} \\
|
|
|
10 |
&$\mid$& \isacommand{by} \emph{method}\\[1ex]
|
|
|
11 |
\emph{statement} &::= & \isacommand{fix} \emph{variables} \\
|
|
|
12 |
&$\mid$& \isacommand{assume} proposition* \\
|
|
13294
|
13 |
&$\mid$& (\isacommand{from} \emph{label}$^*$ $\mid$
|
|
|
14 |
\isacommand{then})$^?$ \\
|
|
|
15 |
&& (\isacommand{show} $\mid$ \isacommand{have})
|
|
13267
|
16 |
\emph{proposition} \emph{proof} \\[1ex]
|
|
|
17 |
\emph{proposition} &::=& (\emph{label}{\bf:})$^?$ \emph{string}
|
|
|
18 |
\end{tabular}
|
|
|
19 |
\end{center}
|
|
|
20 |
where paranthesis are used for grouping and $^?$ indicates an optional item.
|
|
|
21 |
|
|
|
22 |
This is a typical proof skeleton:
|
|
|
23 |
|
|
|
24 |
\begin{center}
|
|
|
25 |
\begin{tabular}{@ {}ll}
|
|
|
26 |
\isacommand{proof}\\
|
|
13294
|
27 |
\hspace*{3ex}\isacommand{assume} "\emph{the-assm}"\\
|
|
13267
|
28 |
\hspace*{3ex}\isacommand{have} "\dots" & -- "intermediate result"\\
|
|
|
29 |
\hspace*{3ex}\vdots\\
|
|
|
30 |
\hspace*{3ex}\isacommand{have} "\dots" & -- "intermediate result"\\
|
|
13294
|
31 |
\hspace*{3ex}\isacommand{show} "\emph{the-concl}"\\
|
|
13267
|
32 |
\isacommand{qed}
|
|
|
33 |
\end{tabular}
|
|
|
34 |
\end{center}
|
|
13294
|
35 |
It proves \emph{the-assm}~@{text"\<Longrightarrow>"}~\emph{the-concl}.
|
|
13267
|
36 |
*}
|
|
|
37 |
|
|
|
38 |
section{*Logic*}
|
|
|
39 |
|
|
|
40 |
subsection{*Propositional logic*}
|
|
|
41 |
|
|
13294
|
42 |
subsubsection{*Introduction rules*}
|
|
|
43 |
|
|
13267
|
44 |
lemma "A \<longrightarrow> A"
|
|
|
45 |
proof (rule impI)
|
|
|
46 |
assume A: "A"
|
|
|
47 |
show "A" by(rule A)
|
|
|
48 |
qed
|
|
|
49 |
|
|
|
50 |
text{*\noindent
|
|
|
51 |
The operational reading: the assume-show block proves @{prop"A \<Longrightarrow> A"},
|
|
|
52 |
which rule @{thm[source]impI} turns into the desired @{prop"A \<longrightarrow> A"}.
|
|
|
53 |
However, this text is much too detailled for comfort. Therefore Isar
|
|
|
54 |
implements the following principle:
|
|
|
55 |
\begin{quote}\em
|
|
13294
|
56 |
Command \isacommand{proof} automatically tries select an introduction rule
|
|
|
57 |
based on the goal and a predefined list of rules.
|
|
13267
|
58 |
\end{quote}
|
|
|
59 |
Here @{thm[source]impI} is applied automatically:
|
|
|
60 |
*}
|
|
|
61 |
|
|
|
62 |
lemma "A \<longrightarrow> A"
|
|
|
63 |
proof
|
|
|
64 |
assume A: "A"
|
|
|
65 |
show "A" by(rule A)
|
|
|
66 |
qed
|
|
|
67 |
|
|
13294
|
68 |
text{* Trivial proofs, in particular those by assumption, should be trivial
|
|
|
69 |
to perform. Method "." does just that (and a bit more --- see later). Thus
|
|
|
70 |
naming of assumptions is often superfluous: *}
|
|
13267
|
71 |
|
|
|
72 |
lemma "A \<longrightarrow> A"
|
|
|
73 |
proof
|
|
|
74 |
assume "A"
|
|
|
75 |
have "A" .
|
|
|
76 |
qed
|
|
|
77 |
|
|
13294
|
78 |
text{* To hide proofs by assumption further, \isacommand{by}@{text"(method)"}
|
|
|
79 |
first applies @{text method} and then tries to solve all remaining subgoals
|
|
|
80 |
by assumption: *}
|
|
13267
|
81 |
|
|
|
82 |
lemma "A \<longrightarrow> A & A"
|
|
|
83 |
proof
|
|
|
84 |
assume A
|
|
|
85 |
show "A & A" by(rule conjI)
|
|
|
86 |
qed
|
|
|
87 |
|
|
13294
|
88 |
text{*\noindent A drawback of these implicit proofs by assumption is that it
|
|
|
89 |
is no longer obvious where an assumption is used.
|
|
13267
|
90 |
|
|
13294
|
91 |
Proofs of the form \isacommand{by}@{text"(rule <name>)"} can be abbreviated
|
|
|
92 |
to ".." if @{text"<name>"} is one of the predefined introduction rules. Thus
|
|
|
93 |
*}
|
|
|
94 |
|
|
|
95 |
lemma "A \<longrightarrow> A \<and> A"
|
|
13267
|
96 |
proof
|
|
|
97 |
assume A
|
|
13294
|
98 |
show "A \<and> A" ..
|
|
13267
|
99 |
qed
|
|
|
100 |
|
|
13294
|
101 |
text{*\noindent
|
|
|
102 |
What happens: first the matching introduction rule @{thm[source]conjI}
|
|
|
103 |
is applied (first "."), then the two subgoals are solved by assumption
|
|
|
104 |
(second "."). *}
|
|
13267
|
105 |
|
|
13294
|
106 |
subsubsection{*Elimination rules*}
|
|
13267
|
107 |
|
|
13294
|
108 |
text{*A typical elimination rule is @{thm[source]conjE}, $\land$-elimination:
|
|
|
109 |
@{thm[display,indent=5]conjE[no_vars]} In the following proof it is applied
|
|
|
110 |
by hand, after its first (``\emph{major}'') premise has been eliminated via
|
|
|
111 |
@{text"[OF AB]"}: *}
|
|
|
112 |
|
|
|
113 |
lemma "A \<and> B \<longrightarrow> B \<and> A"
|
|
13267
|
114 |
proof
|
|
13294
|
115 |
assume AB: "A \<and> B"
|
|
|
116 |
show "B \<and> A"
|
|
13267
|
117 |
proof (rule conjE[OF AB])
|
|
|
118 |
assume A and B
|
|
13294
|
119 |
show ?thesis ..
|
|
13267
|
120 |
qed
|
|
|
121 |
qed
|
|
|
122 |
|
|
13294
|
123 |
text{*\noindent Note that the term @{text"?thesis"} always stands for the
|
|
|
124 |
``current goal'', i.e.\ the enclosing \isacommand{show} (or
|
|
|
125 |
\isacommand{have}).
|
|
13267
|
126 |
|
|
13294
|
127 |
This is too much proof text. Elimination rules should be selected
|
|
|
128 |
automatically based on their major premise, the formula or rather connective
|
|
|
129 |
to be eliminated. In Isar they are triggered by propositions being fed
|
|
|
130 |
\emph{into} a proof block. Syntax:
|
|
|
131 |
\begin{center}
|
|
|
132 |
\isacommand{from} \emph{fact} \isacommand{show} \emph{proposition}
|
|
|
133 |
\end{center}
|
|
|
134 |
where \emph{fact} stands for the name of a previously proved proved
|
|
|
135 |
proposition, e.g.\ an assumption, an intermediate result or some global
|
|
|
136 |
theorem. The fact may also be modified with @{text of}, @{text OF} etc.
|
|
|
137 |
This command applies a elimination rule (from a predefined list)
|
|
|
138 |
whose first premise is solved by the fact. Thus: *}
|
|
13267
|
139 |
|
|
13294
|
140 |
lemma "A \<and> B \<longrightarrow> B \<and> A"
|
|
13267
|
141 |
proof
|
|
13294
|
142 |
assume AB: "A \<and> B"
|
|
|
143 |
from AB show "B \<and> A"
|
|
13267
|
144 |
proof
|
|
|
145 |
assume A and B
|
|
|
146 |
show ?thesis ..
|
|
|
147 |
qed
|
|
|
148 |
qed
|
|
|
149 |
|
|
13294
|
150 |
text{* Now we come a second important principle:
|
|
|
151 |
\begin{quote}\em
|
|
|
152 |
Try to arrange the sequence of propositions in a UNIX-like pipe,
|
|
|
153 |
such that the proof of each proposition builds on the previous proposition.
|
|
|
154 |
\end{quote}
|
|
|
155 |
The previous proposition can be referred to via the fact @{text this}.
|
|
|
156 |
This greatly reduces the need for explicit naming of propositions:
|
|
|
157 |
*}
|
|
|
158 |
|
|
|
159 |
lemma "A \<and> B \<longrightarrow> B \<and> A"
|
|
13267
|
160 |
proof
|
|
13294
|
161 |
assume "A \<and> B"
|
|
|
162 |
from this show "B \<and> A"
|
|
13267
|
163 |
proof
|
|
|
164 |
assume A and B
|
|
|
165 |
show ?thesis ..
|
|
|
166 |
qed
|
|
|
167 |
qed
|
|
|
168 |
|
|
13294
|
169 |
text{*\noindent
|
|
|
170 |
A final simplification: \isacommand{from}~@{text this} can be
|
|
|
171 |
abbreviated to \isacommand{thus}.
|
|
|
172 |
\bigskip
|
|
13267
|
173 |
|
|
13294
|
174 |
Here is an alternative proof that operates purely by forward reasoning: *}
|
|
|
175 |
|
|
|
176 |
lemma "A \<and> B \<longrightarrow> B \<and> A"
|
|
13267
|
177 |
proof
|
|
13294
|
178 |
assume ab: "A \<and> B"
|
|
13267
|
179 |
from ab have a: A ..
|
|
|
180 |
from ab have b: B ..
|
|
13294
|
181 |
from b a show "B \<and> A" ..
|
|
13267
|
182 |
qed
|
|
|
183 |
|
|
13294
|
184 |
text{*\noindent
|
|
|
185 |
It is worth examining this text in detail because it exhibits a number of new features.
|
|
13267
|
186 |
|
|
13294
|
187 |
For a start, this is the first time we have proved intermediate propositions
|
|
|
188 |
(\isacommand{have}) on the way to the final \isacommand{show}. This is the
|
|
|
189 |
norm in any nontrival proof where one cannot bridge the gap between the
|
|
|
190 |
assumptions and the conclusion in one step. Both \isacommand{have}s above are
|
|
|
191 |
proved automatically via @{thm[source]conjE} triggered by
|
|
|
192 |
\isacommand{from}~@{text ab}.
|
|
13267
|
193 |
|
|
13294
|
194 |
The \isacommand{show} command illustrates two things:
|
|
|
195 |
\begin{itemize}
|
|
|
196 |
\item \isacommand{from} can be followed by any number of facts.
|
|
|
197 |
Given \isacommand{from}~@{text f}$_1$~\dots~@{text f}$_n$, \isacommand{show}
|
|
|
198 |
tries to find an elimination rule whose first $n$ premises can be proved
|
|
|
199 |
by the given facts in the given order.
|
|
|
200 |
\item If there is no matching elimination rule, introduction rules are tried,
|
|
|
201 |
again using the facts to prove the premises.
|
|
|
202 |
\end{itemize}
|
|
|
203 |
In this case, the proof succeeds with @{thm[source]conjI}. Note that the proof would fail if we had written \isacommand{from}~@{text"a b"}
|
|
|
204 |
instead of \isacommand{from}~@{text"b a"}.
|
|
|
205 |
|
|
|
206 |
This treatment of facts fed into a proof is not restricted to implicit
|
|
|
207 |
application of introduction and elimination rules but applies to explicit
|
|
|
208 |
application of rules as well. Thus you could replace the final ``..'' above
|
|
|
209 |
with \isacommand{by}@{text"(rule conjI)"}.
|
|
|
210 |
|
|
|
211 |
Note Isar's predefined introduction and elimination rules include all the
|
|
|
212 |
usual natural deduction rules for propositional logic. We conclude this
|
|
|
213 |
section with an extended example --- which rules are used implicitly where?
|
|
|
214 |
Rule @{thm[source]ccontr} is @{thm ccontr[no_vars]}.
|
|
|
215 |
*}
|
|
|
216 |
|
|
|
217 |
lemma "\<not>(A \<and> B) \<longrightarrow> \<not>A \<or> \<not>B"
|
|
13267
|
218 |
proof
|
|
13294
|
219 |
assume n: "\<not>(A \<and> B)"
|
|
|
220 |
show "\<not>A \<or> \<not>B"
|
|
13267
|
221 |
proof (rule ccontr)
|
|
13294
|
222 |
assume nn: "\<not>(\<not> A \<or> \<not>B)"
|
|
13267
|
223 |
from n show False
|
|
|
224 |
proof
|
|
13294
|
225 |
show "A \<and> B"
|
|
13267
|
226 |
proof
|
|
|
227 |
show A
|
|
|
228 |
proof (rule ccontr)
|
|
13294
|
229 |
assume "\<not>A"
|
|
13267
|
230 |
have "\<not> A \<or> \<not> B" ..
|
|
|
231 |
from nn this show False ..
|
|
|
232 |
qed
|
|
|
233 |
next
|
|
|
234 |
show B
|
|
|
235 |
proof (rule ccontr)
|
|
13294
|
236 |
assume "\<not>B"
|
|
13267
|
237 |
have "\<not> A \<or> \<not> B" ..
|
|
|
238 |
from nn this show False ..
|
|
|
239 |
qed
|
|
|
240 |
qed
|
|
|
241 |
qed
|
|
|
242 |
qed
|
|
|
243 |
qed;
|
|
|
244 |
|
|
13294
|
245 |
text{*\noindent Apart from demonstrating the strangeness of classical
|
|
|
246 |
arguments by contradiction, this example also introduces a new language
|
|
|
247 |
feature to deal with multiple subgoals: \isacommand{next}. When showing
|
|
|
248 |
@{term"A \<and> B"} we need to show both @{term A} and @{term B}. Each subgoal
|
|
|
249 |
is proved separately, in \emph{any} order. The individual proofs are
|
|
|
250 |
separated by \isacommand{next}. *}
|
|
13267
|
251 |
|
|
|
252 |
subsection{*Becoming more concise*}
|
|
|
253 |
|
|
13294
|
254 |
text{* So far our examples have been a bit unnatural: normally we want to
|
|
|
255 |
prove rules expressed with @{text"\<Longrightarrow>"}, not @{text"\<longrightarrow>"}. Here is an example:
|
|
|
256 |
*}
|
|
13267
|
257 |
|
|
|
258 |
lemma "\<lbrakk> A \<Longrightarrow> False \<rbrakk> \<Longrightarrow> \<not> A"
|
|
|
259 |
proof
|
|
13294
|
260 |
assume "A \<Longrightarrow> False" "A"
|
|
13267
|
261 |
thus False .
|
|
|
262 |
qed
|
|
|
263 |
|
|
13294
|
264 |
text{*\noindent The \isacommand{proof} always works on the conclusion,
|
|
|
265 |
@{prop"\<not>A"} in our case, thus selecting $\neg$-introduction. Hence we can
|
|
|
266 |
additionally assume @{prop"A"}.
|
|
13267
|
267 |
|
|
13294
|
268 |
This is all very well as long as formulae are small. Let us now look at some
|
|
|
269 |
devices to avoid repeating (possibly large) formulae. A very general method
|
|
|
270 |
is pattern matching: *}
|
|
13267
|
271 |
|
|
13294
|
272 |
lemma "(large_formula \<Longrightarrow> False) \<Longrightarrow> \<not> large_formula"
|
|
13267
|
273 |
(is "(?P \<Longrightarrow> _) \<Longrightarrow> _")
|
|
|
274 |
proof
|
|
|
275 |
assume "?P \<Longrightarrow> False" ?P
|
|
|
276 |
thus False .
|
|
|
277 |
qed
|
|
|
278 |
|
|
13294
|
279 |
text{*\noindent Any formula may be followed by
|
|
|
280 |
@{text"("}\isacommand{is}~\emph{pattern}@{text")"} which causes the pattern
|
|
|
281 |
to be matched against the formula, instantiating the ?-variables in the
|
|
|
282 |
pattern. Subsequent uses of these variables in other terms simply causes them
|
|
|
283 |
to be replaced by the terms they stand for.
|
|
|
284 |
|
|
|
285 |
We can simplify things even more by stating the theorem by means of the
|
|
|
286 |
\isacommand{assumes} and \isacommand{shows} primitives which allow direct
|
|
|
287 |
naming of assumptions: *}
|
|
13267
|
288 |
|
|
|
289 |
lemma assumes A: "large_formula \<Longrightarrow> False"
|
|
13294
|
290 |
shows "\<not> large_formula" (is "\<not> ?P")
|
|
13267
|
291 |
proof
|
|
|
292 |
assume ?P
|
|
13294
|
293 |
with A show False .
|
|
13267
|
294 |
qed
|
|
|
295 |
|
|
13294
|
296 |
text{*\noindent Here we have used the abbreviation
|
|
|
297 |
\begin{center}
|
|
|
298 |
\isacommand{with}~\emph{facts} \quad = \quad
|
|
|
299 |
\isacommand{from}~\emph{facts} \isacommand{and} @{text this}
|
|
|
300 |
\end{center}
|
|
|
301 |
|
|
|
302 |
Sometimes it is necessary to supress the implicit application of rules in a
|
|
|
303 |
\isacommand{proof}. For example \isacommand{show}~@{prop"A \<or> B"} would
|
|
|
304 |
trigger $\lor$-introduction, requiring us to prove @{prop A}. A simple
|
|
|
305 |
``@{text"-"}'' prevents this \emph{faut pas}: *}
|
|
|
306 |
|
|
|
307 |
lemma assumes AB: "A \<or> B" shows "B \<or> A"
|
|
13267
|
308 |
proof -
|
|
13294
|
309 |
from AB show ?thesis
|
|
|
310 |
proof
|
|
|
311 |
assume A show ?thesis ..
|
|
|
312 |
next
|
|
|
313 |
assume B show ?thesis ..
|
|
13267
|
314 |
qed
|
|
|
315 |
qed
|
|
|
316 |
|
|
13294
|
317 |
subsection{*Predicate calculus*}
|
|
|
318 |
|
|
|
319 |
text{* Command \isacommand{fix} introduces new local variables into a
|
|
|
320 |
proof. It corresponds to @{text"\<And>"} (the universal quantifier at the
|
|
|
321 |
meta-level) just like \isacommand{assume}-\isacommand{show} corresponds to
|
|
|
322 |
@{text"\<Longrightarrow>"}. Here is a sample proof, annotated with the rules that are
|
|
|
323 |
applied implictly: *}
|
|
|
324 |
|
|
|
325 |
lemma assumes P: "\<forall>x. P x" shows "\<forall>x. P(f x)"
|
|
|
326 |
proof -- "@{thm[source]allI}: @{thm allI[no_vars]}"
|
|
|
327 |
fix a
|
|
|
328 |
from P show "P(f a)" .. --"@{thm[source]allE}: @{thm allE[no_vars]}"
|
|
|
329 |
qed
|
|
|
330 |
|
|
|
331 |
text{*\noindent Note that in the proof we have chosen to call the bound
|
|
|
332 |
variable @{term a} instead of @{term x} merely to show that the choice of
|
|
|
333 |
names is irrelevant.
|
|
|
334 |
|
|
|
335 |
Next we look at @{text"\<exists>"} which is a bit more tricky.
|
|
13267
|
336 |
*}
|
|
|
337 |
|
|
13294
|
338 |
lemma assumes Pf: "\<exists>x. P(f x)" shows "\<exists>y. P y"
|
|
13267
|
339 |
proof -
|
|
13294
|
340 |
from Pf show ?thesis
|
|
|
341 |
proof -- "@{thm[source]exE}: @{thm exE[no_vars]}"
|
|
|
342 |
fix a
|
|
|
343 |
assume "P(f a)"
|
|
|
344 |
show ?thesis .. --"@{thm[source]exI}: @{thm exI[no_vars]}"
|
|
|
345 |
qed
|
|
13267
|
346 |
qed
|
|
|
347 |
|
|
13294
|
348 |
text {*\noindent
|
|
|
349 |
Explicit $\exists$-elimination as seen above can become
|
|
|
350 |
cumbersome in practice. The derived Isar language element
|
|
|
351 |
``\isakeyword{obtain}'' provides a more handsome way to perform
|
|
|
352 |
generalized existence reasoning:
|
|
13267
|
353 |
*}
|
|
|
354 |
|
|
13294
|
355 |
lemma assumes Pf: "\<exists>x. P(f x)" shows "\<exists>y. P y"
|
|
|
356 |
proof -
|
|
|
357 |
from Pf obtain x where "P(f x)" ..
|
|
|
358 |
thus "\<exists>y. P y" ..
|
|
13267
|
359 |
qed
|
|
|
360 |
|
|
13294
|
361 |
text {*\noindent Note how the proof text follows the usual mathematical style
|
|
|
362 |
of concluding $P x$ from $\exists x. P(x)$, while carefully introducing $x$
|
|
|
363 |
as a new local variable.
|
|
|
364 |
Technically, \isakeyword{obtain} is similar to \isakeyword{fix} and
|
|
|
365 |
\isakeyword{assume} together with a soundness proof of the
|
|
|
366 |
elimination involved. Thus it behaves similar to any other forward
|
|
|
367 |
proof element.
|
|
13267
|
368 |
|
|
13294
|
369 |
Here is a proof of a well known tautology which employs another useful
|
|
|
370 |
abbreviation: \isakeyword{hence} abbreviates \isakeyword{from}~@{text
|
|
|
371 |
this}~\isakeyword{have}. Figure out which rule is used where! *}
|
|
|
372 |
|
|
|
373 |
lemma assumes ex: "\<exists>x. \<forall>y. P x y" shows "\<forall>y. \<exists>x. P x y"
|
|
13267
|
374 |
proof
|
|
13294
|
375 |
fix y
|
|
|
376 |
from ex obtain x where "\<forall>y. P x y" ..
|
|
|
377 |
hence "P x y" ..
|
|
|
378 |
thus "\<exists>x. P x y" ..
|
|
|
379 |
qed
|
|
|
380 |
|
|
|
381 |
text{* So far we have confined ourselves to single step proofs. Of course
|
|
|
382 |
powerful automatic methods can be used just as well. Here is an example,
|
|
|
383 |
Cantor's theorem that there is no surjective function from a set to its
|
|
|
384 |
powerset: *}
|
|
|
385 |
|
|
|
386 |
theorem "\<exists>S. S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
|
|
|
387 |
proof
|
|
|
388 |
let ?S = "{x. x \<notin> f x}"
|
|
|
389 |
show "?S \<notin> range f"
|
|
13267
|
390 |
proof
|
|
13294
|
391 |
assume "?S \<in> range f"
|
|
13267
|
392 |
then obtain y where fy: "?S = f y" ..
|
|
|
393 |
show False
|
|
|
394 |
proof (cases)
|
|
13294
|
395 |
assume "y \<in> ?S"
|
|
13267
|
396 |
with fy show False by blast
|
|
|
397 |
next
|
|
13294
|
398 |
assume "y \<notin> ?S"
|
|
13267
|
399 |
with fy show False by blast
|
|
|
400 |
qed
|
|
|
401 |
qed
|
|
|
402 |
qed
|
|
|
403 |
|
|
13294
|
404 |
text{*\noindent
|
|
|
405 |
For a start, the example demonstrates two new language elements:
|
|
|
406 |
\begin{itemize}
|
|
|
407 |
\item \isakeyword{let} introduces an abbreviation for a term, in our case
|
|
|
408 |
the witness for the claim, because the term occurs multiple times in the proof.
|
|
|
409 |
\item Proof by @{text"(cases)"} starts a proof by cases. Note that it remains
|
|
|
410 |
implicit what the two cases are: it is merely expected that the two subproofs
|
|
|
411 |
prove @{prop"P \<Longrightarrow> Q"} and @{prop"\<not>P \<Longrightarrow> Q"} for suitable @{term P} and
|
|
|
412 |
@{term Q}.
|
|
|
413 |
\end{itemize}
|
|
|
414 |
If you wonder how to \isakeyword{obtain} @{term y}:
|
|
|
415 |
via the predefined elimination rule @{thm rangeE[no_vars]}.
|
|
|
416 |
|
|
|
417 |
Method @{text blast} is used because the contradiction does not follow easily
|
|
|
418 |
by just a single rule. If you find the proof too cryptic for human
|
|
|
419 |
consumption, here is a more detailed version; the beginning up to
|
|
|
420 |
\isakeyword{obtain} stays unchanged. *}
|
|
|
421 |
|
|
|
422 |
theorem "\<exists>S. S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
|
|
13267
|
423 |
proof
|
|
13294
|
424 |
let ?S = "{x. x \<notin> f x}"
|
|
|
425 |
show "?S \<notin> range f"
|
|
13267
|
426 |
proof
|
|
13294
|
427 |
assume "?S \<in> range f"
|
|
|
428 |
then obtain y where fy: "?S = f y" ..
|
|
13267
|
429 |
show False
|
|
|
430 |
proof (cases)
|
|
13294
|
431 |
assume A: "y \<in> ?S"
|
|
|
432 |
hence isin: "y \<in> f y" by(simp add:fy)
|
|
|
433 |
from A have "y \<notin> f y" by simp
|
|
13267
|
434 |
with isin show False by contradiction
|
|
|
435 |
next
|
|
13294
|
436 |
assume A: "y \<notin> ?S"
|
|
|
437 |
hence notin: "y \<notin> f y" by(simp add:fy)
|
|
|
438 |
from A have "y \<in> f y" by simp
|
|
13267
|
439 |
with notin show False by contradiction
|
|
|
440 |
qed
|
|
|
441 |
qed
|
|
|
442 |
qed
|
|
|
443 |
|
|
13294
|
444 |
text {*\noindent Method @{text contradiction} succeeds if both $P$ and
|
|
|
445 |
$\neg P$ are among the assumptions and the facts fed into that step.
|
|
|
446 |
|
|
|
447 |
As it happens, Cantor's theorem can be proved automatically by best-first
|
|
|
448 |
search. Depth-first search would diverge, but best-first search successfully
|
|
|
449 |
navigates through the large search space:
|
|
13267
|
450 |
*}
|
|
|
451 |
|
|
13294
|
452 |
theorem "\<exists>S. S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
|
|
|
453 |
by best
|
|
13267
|
454 |
|
|
13294
|
455 |
text{*\noindent Of course this only works in the context of HOL's carefully
|
|
|
456 |
constructed introduction and elimination rules for set theory.
|
|
|
457 |
|
|
|
458 |
Finally, whole scripts may appear in the leaves of the proof tree, although
|
|
|
459 |
this is best avoided. Here is a contrived example: *}
|
|
13267
|
460 |
|
|
|
461 |
lemma "A \<longrightarrow> (A \<longrightarrow>B) \<longrightarrow> B"
|
|
|
462 |
proof
|
|
13294
|
463 |
assume a: A
|
|
13267
|
464 |
show "(A \<longrightarrow>B) \<longrightarrow> B"
|
|
|
465 |
apply(rule impI)
|
|
|
466 |
apply(erule impE)
|
|
13294
|
467 |
apply(rule a)
|
|
13267
|
468 |
apply assumption
|
|
|
469 |
done
|
|
|
470 |
qed
|
|
|
471 |
|
|
13294
|
472 |
text{*\noindent You may need to resort to this technique if an automatic step
|
|
|
473 |
fails to prove the desired proposition. *}
|
|
|
474 |
(*<*)end(*>*)
|