31 on the way towards the \isacom{show} statement that proves the actual |
31 on the way towards the \isacom{show} statement that proves the actual |
32 goal. In more detail, this is the Isar core syntax: |
32 goal. In more detail, this is the Isar core syntax: |
33 \medskip |
33 \medskip |
34 |
34 |
35 \begin{tabular}{@ {}lcl@ {}} |
35 \begin{tabular}{@ {}lcl@ {}} |
36 \textit{proof} &=& \isacom{by} \textit{method}\\ |
36 \textit{proof} &=& \indexed{\isacom{by}}{by} \textit{method}\\ |
37 &$\mid$& \isacom{proof} [\textit{method}] \ \textit{step}$^*$ \ \isacom{qed} |
37 &$\mid$& \indexed{\isacom{proof}}{proof} [\textit{method}] \ \textit{step}$^*$ \ \indexed{\isacom{qed}}{qed} |
38 \end{tabular} |
38 \end{tabular} |
39 \medskip |
39 \medskip |
40 |
40 |
41 \begin{tabular}{@ {}lcl@ {}} |
41 \begin{tabular}{@ {}lcl@ {}} |
42 \textit{step} &=& \isacom{fix} \textit{variables} \\ |
42 \textit{step} &=& \indexed{\isacom{fix}}{fix} \textit{variables} \\ |
43 &$\mid$& \isacom{assume} \textit{proposition} \\ |
43 &$\mid$& \indexed{\isacom{assume}}{assume} \textit{proposition} \\ |
44 &$\mid$& [\isacom{from} \textit{fact}$^+$] (\isacom{have} $\mid$ \isacom{show}) \ \textit{proposition} \ \textit{proof} |
44 &$\mid$& [\indexed{\isacom{from}}{from} \textit{fact}$^+$] (\indexed{\isacom{have}}{have} $\mid$ \indexed{\isacom{show}}{show}) \ \textit{proposition} \ \textit{proof} |
45 \end{tabular} |
45 \end{tabular} |
46 \medskip |
46 \medskip |
47 |
47 |
48 \begin{tabular}{@ {}lcl@ {}} |
48 \begin{tabular}{@ {}lcl@ {}} |
49 \textit{proposition} &=& [\textit{name}:] @{text"\""}\textit{formula}@{text"\""} |
49 \textit{proposition} &=& [\textit{name}:] @{text"\""}\textit{formula}@{text"\""} |
114 not necessary. Both \isacom{have} steps are obvious. The second one introduces |
114 not necessary. Both \isacom{have} steps are obvious. The second one introduces |
115 the diagonal set @{term"{x. x \<notin> f x}"}, the key idea in the proof. |
115 the diagonal set @{term"{x. x \<notin> f x}"}, the key idea in the proof. |
116 If you wonder why @{text 2} directly implies @{text False}: from @{text 2} |
116 If you wonder why @{text 2} directly implies @{text False}: from @{text 2} |
117 it follows that @{prop"a \<notin> f a \<longleftrightarrow> a \<in> f a"}. |
117 it follows that @{prop"a \<notin> f a \<longleftrightarrow> a \<in> f a"}. |
118 |
118 |
119 \subsection{@{text this}, \isacom{then}, \isacom{hence} and \isacom{thus}} |
119 \subsection{\indexed{@{text this}}{this}, \indexed{\isacom{then}}{then}, \indexed{\isacom{hence}}{hence} and \indexed{\isacom{thus}}{thus}} |
120 |
120 |
121 Labels should be avoided. They interrupt the flow of the reader who has to |
121 Labels should be avoided. They interrupt the flow of the reader who has to |
122 scan the context for the point where the label was introduced. Ideally, the |
122 scan the context for the point where the label was introduced. Ideally, the |
123 proof is a linear flow, where the output of one step becomes the input of the |
123 proof is a linear flow, where the output of one step becomes the input of the |
124 next step, piping the previously proved fact into the next proof, just like |
124 next step, piping the previously proved fact into the next proof, just like |
163 |
163 |
164 There are two further linguistic variations: |
164 There are two further linguistic variations: |
165 \medskip |
165 \medskip |
166 |
166 |
167 \begin{tabular}{r@ {\quad=\quad}l} |
167 \begin{tabular}{r@ {\quad=\quad}l} |
168 (\isacom{have}$\mid$\isacom{show}) \ \textit{prop} \ \isacom{using} \ \textit{facts} |
168 (\isacom{have}$\mid$\isacom{show}) \ \textit{prop} \ \indexed{\isacom{using}}{using} \ \textit{facts} |
169 & |
169 & |
170 \isacom{from} \ \textit{facts} \ (\isacom{have}$\mid$\isacom{show}) \ \textit{prop}\\ |
170 \isacom{from} \ \textit{facts} \ (\isacom{have}$\mid$\isacom{show}) \ \textit{prop}\\ |
171 \isacom{with} \ \textit{facts} & \isacom{from} \ \textit{facts} \isa{this} |
171 \indexed{\isacom{with}}{with} \ \textit{facts} & \isacom{from} \ \textit{facts} \isa{this} |
172 \end{tabular} |
172 \end{tabular} |
173 \medskip |
173 \medskip |
174 |
174 |
175 \noindent The \isacom{using} idiom de-emphasizes the used facts by moving them |
175 \noindent The \isacom{using} idiom de-emphasizes the used facts by moving them |
176 behind the proposition. |
176 behind the proposition. |
177 |
177 |
178 \subsection{Structured Lemma Statements: \isacom{fixes}, \isacom{assumes}, \isacom{shows}} |
178 \subsection{Structured Lemma Statements: \indexed{\isacom{fixes}}{fixes}, \indexed{\isacom{assumes}}{assumes}, \indexed{\isacom{shows}}{shows}} |
179 |
179 \index{lemma@\isacom{lemma}} |
180 Lemmas can also be stated in a more structured fashion. To demonstrate this |
180 Lemmas can also be stated in a more structured fashion. To demonstrate this |
181 feature with Cantor's theorem, we rephrase @{prop"\<not> surj f"} |
181 feature with Cantor's theorem, we rephrase @{prop"\<not> surj f"} |
182 a little: |
182 a little: |
183 *} |
183 *} |
184 |
184 |
215 False}---but there is no suitable introduction rule and \isacom{proof} |
215 False}---but there is no suitable introduction rule and \isacom{proof} |
216 would fail. |
216 would fail. |
217 \end{warn} |
217 \end{warn} |
218 |
218 |
219 Stating a lemma with \isacom{assumes}-\isacom{shows} implicitly introduces the |
219 Stating a lemma with \isacom{assumes}-\isacom{shows} implicitly introduces the |
220 name @{text assms} that stands for the list of all assumptions. You can refer |
220 name \indexed{@{text assms}}{assms} that stands for the list of all assumptions. You can refer |
221 to individual assumptions by @{text"assms(1)"}, @{text"assms(2)"} etc, |
221 to individual assumptions by @{text"assms(1)"}, @{text"assms(2)"} etc, |
222 thus obviating the need to name them individually. |
222 thus obviating the need to name them individually. |
223 |
223 |
224 \section{Proof Patterns} |
224 \section{Proof Patterns} |
225 |
225 |
434 |
434 |
435 In the proof patterns shown above, formulas are often duplicated. |
435 In the proof patterns shown above, formulas are often duplicated. |
436 This can make the text harder to read, write and maintain. Pattern matching |
436 This can make the text harder to read, write and maintain. Pattern matching |
437 is an abbreviation mechanism to avoid such duplication. Writing |
437 is an abbreviation mechanism to avoid such duplication. Writing |
438 \begin{quote} |
438 \begin{quote} |
439 \isacom{show} \ \textit{formula} @{text"("}\isacom{is} \textit{pattern}@{text")"} |
439 \isacom{show} \ \textit{formula} @{text"("}\indexed{\isacom{is}}{is} \textit{pattern}@{text")"} |
440 \end{quote} |
440 \end{quote} |
441 matches the pattern against the formula, thus instantiating the unknowns in |
441 matches the pattern against the formula, thus instantiating the unknowns in |
442 the pattern for later use. As an example, consider the proof pattern for |
442 the pattern for later use. As an example, consider the proof pattern for |
443 @{text"\<longleftrightarrow>"}: |
443 @{text"\<longleftrightarrow>"}: |
444 \end{isamarkuptext}% |
444 \end{isamarkuptext}% |
458 text{* Instead of duplicating @{text"formula\<^sub>i"} in the text, we introduce |
458 text{* Instead of duplicating @{text"formula\<^sub>i"} in the text, we introduce |
459 the two abbreviations @{text"?L"} and @{text"?R"} by pattern matching. |
459 the two abbreviations @{text"?L"} and @{text"?R"} by pattern matching. |
460 Pattern matching works wherever a formula is stated, in particular |
460 Pattern matching works wherever a formula is stated, in particular |
461 with \isacom{have} and \isacom{lemma}. |
461 with \isacom{have} and \isacom{lemma}. |
462 |
462 |
463 The unknown @{text"?thesis"} is implicitly matched against any goal stated by |
463 The unknown \indexed{@{text"?thesis"}}{thesis} is implicitly matched against any goal stated by |
464 \isacom{lemma} or \isacom{show}. Here is a typical example: *} |
464 \isacom{lemma} or \isacom{show}. Here is a typical example: *} |
465 |
465 |
466 lemma "formula" |
466 lemma "formula" |
467 proof - |
467 proof - |
468 txt_raw{*\\\mbox{}\quad$\vdots$\\\mbox{}\hspace{-1.4ex}*} |
468 txt_raw{*\\\mbox{}\quad$\vdots$\\\mbox{}\hspace{-1.4ex}*} |
469 show ?thesis (*<*)sorry(*>*) txt_raw{*\ $\dots$\\*} |
469 show ?thesis (*<*)sorry(*>*) txt_raw{*\ $\dots$\\*} |
470 qed |
470 qed |
471 |
471 |
472 text{* |
472 text{* |
473 Unknowns can also be instantiated with \isacom{let} commands |
473 Unknowns can also be instantiated with \indexed{\isacom{let}}{let} commands |
474 \begin{quote} |
474 \begin{quote} |
475 \isacom{let} @{text"?t"} = @{text"\""}\textit{some-big-term}@{text"\""} |
475 \isacom{let} @{text"?t"} = @{text"\""}\textit{some-big-term}@{text"\""} |
476 \end{quote} |
476 \end{quote} |
477 Later proof steps can refer to @{text"?t"}: |
477 Later proof steps can refer to @{text"?t"}: |
478 \begin{quote} |
478 \begin{quote} |
495 The name is longer than the fact it stands for! Short facts do not need names, |
495 The name is longer than the fact it stands for! Short facts do not need names, |
496 one can refer to them easily by quoting them: |
496 one can refer to them easily by quoting them: |
497 \begin{quote} |
497 \begin{quote} |
498 \isacom{have} \ @{text"\"x > 0\""}\\ |
498 \isacom{have} \ @{text"\"x > 0\""}\\ |
499 $\vdots$\\ |
499 $\vdots$\\ |
500 \isacom{from} @{text "`x>0`"} \dots |
500 \isacom{from} @{text "`x>0`"} \dots\index{$IMP053@@{text"`...`"}} |
501 \end{quote} |
501 \end{quote} |
502 Note that the quotes around @{text"x>0"} are \conceptnoidx{back quotes}. |
502 Note that the quotes around @{text"x>0"} are \conceptnoidx{back quotes}. |
503 They refer to the fact not by name but by value. |
503 They refer to the fact not by name but by value. |
504 |
504 |
505 \subsection{\isacom{moreover}} |
505 \subsection{\indexed{\isacom{moreover}}{moreover}} |
|
506 \index{ultimately@\isacom{ultimately}} |
506 |
507 |
507 Sometimes one needs a number of facts to enable some deduction. Of course |
508 Sometimes one needs a number of facts to enable some deduction. Of course |
508 one can name these facts individually, as shown on the right, |
509 one can name these facts individually, as shown on the right, |
509 but one can also combine them with \isacom{moreover}, as shown on the left: |
510 but one can also combine them with \isacom{moreover}, as shown on the left: |
510 *}text_raw{* |
511 *}text_raw{* |
548 |
549 |
549 Sometimes one would like to prove some lemma locally within a proof. |
550 Sometimes one would like to prove some lemma locally within a proof. |
550 A lemma that shares the current context of assumptions but that |
551 A lemma that shares the current context of assumptions but that |
551 has its own assumptions and is generalized over its locally fixed |
552 has its own assumptions and is generalized over its locally fixed |
552 variables at the end. This is what a \concept{raw proof block} does: |
553 variables at the end. This is what a \concept{raw proof block} does: |
553 \begin{quote} |
554 \begin{quote}\index{$IMP053@@{text"{ ... }"} (proof block)} |
554 @{text"{"} \isacom{fix} @{text"x\<^sub>1 \<dots> x\<^sub>n"}\\ |
555 @{text"{"} \isacom{fix} @{text"x\<^sub>1 \<dots> x\<^sub>n"}\\ |
555 \mbox{}\ \ \ \isacom{assume} @{text"A\<^sub>1 \<dots> A\<^sub>m"}\\ |
556 \mbox{}\ \ \ \isacom{assume} @{text"A\<^sub>1 \<dots> A\<^sub>m"}\\ |
556 \mbox{}\ \ \ $\vdots$\\ |
557 \mbox{}\ \ \ $\vdots$\\ |
557 \mbox{}\ \ \ \isacom{have} @{text"B"}\\ |
558 \mbox{}\ \ \ \isacom{have} @{text"B"}\\ |
558 @{text"}"} |
559 @{text"}"} |
582 text{* Note that the result of a raw proof block has no name. In this example |
583 text{* Note that the result of a raw proof block has no name. In this example |
583 it was directly piped (via \isacom{then}) into the final proof, but it can |
584 it was directly piped (via \isacom{then}) into the final proof, but it can |
584 also be named for later reference: you simply follow the block directly by a |
585 also be named for later reference: you simply follow the block directly by a |
585 \isacom{note} command: |
586 \isacom{note} command: |
586 \begin{quote} |
587 \begin{quote} |
587 \isacom{note} \ @{text"name = this"} |
588 \indexed{\isacom{note}}{note} \ @{text"name = this"} |
588 \end{quote} |
589 \end{quote} |
589 This introduces a new name @{text name} that refers to @{text this}, |
590 This introduces a new name @{text name} that refers to @{text this}, |
590 the fact just proved, in this case the preceding block. In general, |
591 the fact just proved, in this case the preceding block. In general, |
591 \isacom{note} introduces a new name for one or more facts. |
592 \isacom{note} introduces a new name for one or more facts. |
592 |
593 |
616 the relevant @{const take} and @{const drop} lemmas for you. |
617 the relevant @{const take} and @{const drop} lemmas for you. |
617 \endexercise |
618 \endexercise |
618 |
619 |
619 |
620 |
620 \section{Case Analysis and Induction} |
621 \section{Case Analysis and Induction} |
621 |
622 \index{case analysis}\index{induction} |
622 \subsection{Datatype Case Analysis} |
623 \subsection{Datatype Case Analysis} |
623 |
624 |
624 We have seen case analysis on formulas. Now we want to distinguish |
625 We have seen case analysis on formulas. Now we want to distinguish |
625 which form some term takes: is it @{text 0} or of the form @{term"Suc n"}, |
626 which form some term takes: is it @{text 0} or of the form @{term"Suc n"}, |
626 is it @{term"[]"} or of the form @{term"x#xs"}, etc. Here is a typical example |
627 is it @{term"[]"} or of the form @{term"x#xs"}, etc. Here is a typical example |