doc-src/IsarOverview/Isar/Logic.thy
author boehmes
Tue, 07 Dec 2010 15:44:38 +0100
changeset 41064 0c447a17770a
parent 32834 a4e0b8d88f28
permissions -rw-r--r--
updated SMT certificates
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17914
99ead7a7eb42 fix headers;
wenzelm
parents: 14617
diff changeset
     1
(*<*)theory Logic imports Main begin(*>*)
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     2
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     3
section{*Logic \label{sec:Logic}*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     4
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     5
subsection{*Propositional logic*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     6
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     7
subsubsection{*Introduction rules*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     8
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
     9
text{* We start with a really trivial toy proof to introduce the basic
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    10
features of structured proofs. *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    11
lemma "A \<longrightarrow> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    12
proof (rule impI)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    13
  assume a: "A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    14
  show "A" by(rule a)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    15
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    16
text{*\noindent
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    17
The operational reading: the \isakeyword{assume}-\isakeyword{show}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    18
block proves @{prop"A \<Longrightarrow> A"} (@{term a} is a degenerate rule (no
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    19
assumptions) that proves @{term A} outright), which rule
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    20
@{thm[source]impI} (@{thm impI}) turns into the desired @{prop"A \<longrightarrow>
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    21
A"}.  However, this text is much too detailed for comfort. Therefore
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    22
Isar implements the following principle: \begin{quote}\em Command
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    23
\isakeyword{proof} automatically tries to select an introduction rule
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    24
based on the goal and a predefined list of rules.  \end{quote} Here
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    25
@{thm[source]impI} is applied automatically: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    26
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    27
lemma "A \<longrightarrow> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    28
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    29
  assume a: A
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    30
  show A by(rule a)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    31
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    32
30649
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 29298
diff changeset
    33
text{*\noindent As you see above, single-identifier formulae such as @{term A}
57753e0ec1d4 1. New cancellation simprocs for common factors in inequations
nipkow
parents: 29298
diff changeset
    34
need not be enclosed in double quotes. However, we will continue to do so for
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    35
uniformity.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    36
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    37
Instead of applying fact @{text a} via the @{text rule} method, we can
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    38
also push it directly onto our goal.  The proof is then immediate,
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    39
which is formally written as ``.'' in Isar: *}
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    40
lemma "A \<longrightarrow> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    41
proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    42
  assume a: "A"
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    43
  from a show "A" .
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    44
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    45
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    46
text{* We can also push several facts towards a goal, and put another
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    47
rule in between to establish some result that is one step further
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    48
removed.  We illustrate this by introducing a trivial conjunction: *}
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    49
lemma "A \<longrightarrow> A \<and> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    50
proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    51
  assume a: "A"
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    52
  from a and a show "A \<and> A" by(rule conjI)
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    53
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    54
text{*\noindent Rule @{thm[source]conjI} is of course @{thm conjI}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    55
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    56
Proofs of the form \isakeyword{by}@{text"(rule"}~\emph{name}@{text")"}
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    57
can be abbreviated to ``..'' if \emph{name} refers to one of the
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    58
predefined introduction rules (or elimination rules, see below): *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    59
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    60
lemma "A \<longrightarrow> A \<and> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    61
proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    62
  assume a: "A"
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    63
  from a and a show "A \<and> A" ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    64
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    65
text{*\noindent
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    66
This is what happens: first the matching introduction rule @{thm[source]conjI}
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    67
is applied (first ``.''), the remaining problem is solved immediately (second ``.''). *}
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    68
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    69
subsubsection{*Elimination rules*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    70
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    71
text{*A typical elimination rule is @{thm[source]conjE}, $\land$-elimination:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    72
@{thm[display,indent=5]conjE}  In the following proof it is applied
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    73
by hand, after its first (\emph{major}) premise has been eliminated via
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    74
@{text"[OF ab]"}: *}
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    75
lemma "A \<and> B \<longrightarrow> B \<and> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    76
proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    77
  assume ab: "A \<and> B"
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    78
  show "B \<and> A"
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    79
  proof (rule conjE[OF ab])  -- {*@{text"conjE[OF ab]"}: @{thm conjE[OF ab]} *}
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    80
    assume a: "A" and b: "B"
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
    81
    from b and a show ?thesis ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    82
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    83
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    84
text{*\noindent Note that the term @{text"?thesis"} always stands for the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    85
``current goal'', i.e.\ the enclosing \isakeyword{show} (or
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    86
\isakeyword{have}) statement.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    87
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    88
This is too much proof text. Elimination rules should be selected
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    89
automatically based on their major premise, the formula or rather connective
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    90
to be eliminated. In Isar they are triggered by facts being fed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    91
\emph{into} a proof. Syntax:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    92
\begin{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    93
\isakeyword{from} \emph{fact} \isakeyword{show} \emph{proposition} \emph{proof}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    94
\end{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    95
where \emph{fact} stands for the name of a previously proved
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    96
proposition, e.g.\ an assumption, an intermediate result or some global
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    97
theorem, which may also be modified with @{text OF} etc.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    98
The \emph{fact} is ``piped'' into the \emph{proof}, which can deal with it
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
    99
how it chooses. If the \emph{proof} starts with a plain \isakeyword{proof},
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   100
an elimination rule (from a predefined list) is applied
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   101
whose first premise is solved by the \emph{fact}. Thus the proof above
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   102
is equivalent to the following one: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   103
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   104
lemma "A \<and> B \<longrightarrow> B \<and> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   105
proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   106
  assume ab: "A \<and> B"
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   107
  from ab show "B \<and> A"
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   108
  proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   109
    assume a: "A" and b: "B"
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   110
    from b and a show ?thesis ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   111
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   112
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   113
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   114
text{* Now we come to a second important principle:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   115
\begin{quote}\em
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   116
Try to arrange the sequence of propositions in a UNIX-like pipe,
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   117
such that the proof of each proposition builds on the previous proposition.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   118
\end{quote}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   119
The previous proposition can be referred to via the fact @{text this}.
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   120
This greatly reduces the need for explicit naming of propositions.  We also
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   121
rearrange the additional inner assumptions into proper order for immediate use:
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   122
*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   123
lemma "A \<and> B \<longrightarrow> B \<and> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   124
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   125
  assume "A \<and> B"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   126
  from this show "B \<and> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   127
  proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   128
    assume "B" "A"
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   129
    from this show ?thesis ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   130
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   131
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   132
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   133
text{*\noindent Because of the frequency of \isakeyword{from}~@{text
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   134
this}, Isar provides two abbreviations:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   135
\begin{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   136
\begin{tabular}{r@ {\quad=\quad}l}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   137
\isakeyword{then} & \isakeyword{from} @{text this} \\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   138
\isakeyword{thus} & \isakeyword{then} \isakeyword{show}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   139
\end{tabular}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   140
\end{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   141
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   142
Here is an alternative proof that operates purely by forward reasoning: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   143
lemma "A \<and> B \<longrightarrow> B \<and> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   144
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   145
  assume ab: "A \<and> B"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   146
  from ab have a: "A" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   147
  from ab have b: "B" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   148
  from b a show "B \<and> A" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   149
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   150
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   151
text{*\noindent It is worth examining this text in detail because it
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   152
exhibits a number of new concepts.  For a start, it is the first time
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   153
we have proved intermediate propositions (\isakeyword{have}) on the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   154
way to the final \isakeyword{show}. This is the norm in nontrivial
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   155
proofs where one cannot bridge the gap between the assumptions and the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   156
conclusion in one step. To understand how the proof works we need to
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   157
explain more Isar details:
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   158
\begin{itemize}
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   159
\item
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   160
Method @{text rule} can be given a list of rules, in which case
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   161
@{text"(rule"}~\textit{rules}@{text")"} applies the first matching
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   162
rule in the list \textit{rules}.
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   163
\item Command \isakeyword{from} can be
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   164
followed by any number of facts.  Given \isakeyword{from}~@{text
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   165
f}$_1$~\dots~@{text f}$_n$, the proof step
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   166
@{text"(rule"}~\textit{rules}@{text")"} following a \isakeyword{have}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   167
or \isakeyword{show} searches \textit{rules} for a rule whose first
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   168
$n$ premises can be proved by @{text f}$_1$~\dots~@{text f}$_n$ in the
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   169
given order.
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   170
\item ``..'' is short for
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   171
@{text"by(rule"}~\textit{elim-rules intro-rules}@{text")"}\footnote{or
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   172
merely @{text"(rule"}~\textit{intro-rules}@{text")"} if there are no facts
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   173
fed into the proof}, where \textit{elim-rules} and \textit{intro-rules}
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   174
are the predefined elimination and introduction rule. Thus
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   175
elimination rules are tried first (if there are incoming facts).
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   176
\end{itemize}
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   177
Hence in the above proof both \isakeyword{have}s are proved via
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   178
@{thm[source]conjE} triggered by \isakeyword{from}~@{text ab} whereas
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   179
in the \isakeyword{show} step no elimination rule is applicable and
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   180
the proof succeeds with @{thm[source]conjI}. The latter would fail had
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   181
we written \isakeyword{from}~@{text"a b"} instead of
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   182
\isakeyword{from}~@{text"b a"}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   183
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   184
A plain \isakeyword{proof} with no argument is short for
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   185
\isakeyword{proof}~@{text"(rule"}~\textit{elim-rules intro-rules}@{text")"}\footnotemark[1].
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   186
This means that the matching rule is selected by the incoming facts and the goal exactly as just explained.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   187
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   188
Although we have only seen a few introduction and elimination rules so
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   189
far, Isar's predefined rules include all the usual natural deduction
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   190
rules. We conclude our exposition of propositional logic with an extended
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   191
example --- which rules are used implicitly where? *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   192
lemma "\<not> (A \<and> B) \<longrightarrow> \<not> A \<or> \<not> B"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   193
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   194
  assume n: "\<not> (A \<and> B)"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   195
  show "\<not> A \<or> \<not> B"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   196
  proof (rule ccontr)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   197
    assume nn: "\<not> (\<not> A \<or> \<not> B)"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   198
    have "\<not> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   199
    proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   200
      assume a: "A"
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   201
      have "\<not> B"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   202
      proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   203
        assume b: "B"
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   204
        from a and b have "A \<and> B" ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   205
        with n show False ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   206
      qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   207
      hence "\<not> A \<or> \<not> B" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   208
      with nn show False ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   209
    qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   210
    hence "\<not> A \<or> \<not> B" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   211
    with nn show False ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   212
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   213
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   214
text{*\noindent
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   215
Rule @{thm[source]ccontr} (``classical contradiction'') is
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   216
@{thm ccontr[no_vars]}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   217
Apart from demonstrating the strangeness of classical
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   218
arguments by contradiction, this example also introduces two new
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   219
abbreviations:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   220
\begin{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   221
\begin{tabular}{l@ {\quad=\quad}l}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   222
\isakeyword{hence} & \isakeyword{then} \isakeyword{have} \\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   223
\isakeyword{with}~\emph{facts} &
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   224
\isakeyword{from}~\emph{facts} @{text this}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   225
\end{tabular}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   226
\end{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   227
*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   228
19840
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   229
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   230
subsection{*Avoiding duplication*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   231
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   232
text{* So far our examples have been a bit unnatural: normally we want to
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   233
prove rules expressed with @{text"\<Longrightarrow>"}, not @{text"\<longrightarrow>"}. Here is an example:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   234
*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   235
lemma "A \<and> B \<Longrightarrow> B \<and> A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   236
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   237
  assume "A \<and> B" thus "B" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   238
next
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   239
  assume "A \<and> B" thus "A" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   240
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   241
text{*\noindent The \isakeyword{proof} always works on the conclusion,
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   242
@{prop"B \<and> A"} in our case, thus selecting $\land$-introduction. Hence
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   243
we must show @{prop B} and @{prop A}; both are proved by
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   244
$\land$-elimination and the proofs are separated by \isakeyword{next}:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   245
\begin{description}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   246
\item[\isakeyword{next}] deals with multiple subgoals. For example,
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   247
when showing @{term"A \<and> B"} we need to show both @{term A} and @{term
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   248
B}.  Each subgoal is proved separately, in \emph{any} order. The
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   249
individual proofs are separated by \isakeyword{next}.  \footnote{Each
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   250
\isakeyword{show} must prove one of the pending subgoals.  If a
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   251
\isakeyword{show} matches multiple subgoals, e.g.\ if the subgoals
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   252
contain ?-variables, the first one is proved. Thus the order in which
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   253
the subgoals are proved can matter --- see
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   254
\S\ref{sec:CaseDistinction} for an example.}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   255
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   256
Strictly speaking \isakeyword{next} is only required if the subgoals
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   257
are proved in different assumption contexts which need to be
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   258
separated, which is not the case above. For clarity we
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   259
have employed \isakeyword{next} anyway and will continue to do so.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   260
\end{description}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   261
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   262
This is all very well as long as formulae are small. Let us now look at some
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   263
devices to avoid repeating (possibly large) formulae. A very general method
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   264
is pattern matching: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   265
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   266
lemma "large_A \<and> large_B \<Longrightarrow> large_B \<and> large_A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   267
      (is "?AB \<Longrightarrow> ?B \<and> ?A")
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   268
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   269
  assume "?AB" thus "?B" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   270
next
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   271
  assume "?AB" thus "?A" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   272
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   273
text{*\noindent Any formula may be followed by
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   274
@{text"("}\isakeyword{is}~\emph{pattern}@{text")"} which causes the pattern
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   275
to be matched against the formula, instantiating the @{text"?"}-variables in
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   276
the pattern. Subsequent uses of these variables in other terms causes
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   277
them to be replaced by the terms they stand for.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   278
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   279
We can simplify things even more by stating the theorem by means of the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   280
\isakeyword{assumes} and \isakeyword{shows} elements which allow direct
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   281
naming of assumptions: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   282
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   283
lemma assumes ab: "large_A \<and> large_B"
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   284
  shows "large_B \<and> large_A" (is "?B \<and> ?A")
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   285
proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   286
  from ab show "?B" ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   287
next
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   288
  from ab show "?A" ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   289
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   290
text{*\noindent Note the difference between @{text ?AB}, a term, and
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   291
@{text ab}, a fact.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   292
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   293
Finally we want to start the proof with $\land$-elimination so we
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   294
don't have to perform it twice, as above. Here is a slick way to
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   295
achieve this: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   296
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   297
lemma assumes ab: "large_A \<and> large_B"
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   298
  shows "large_B \<and> large_A" (is "?B \<and> ?A")
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   299
using ab
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   300
proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   301
  assume "?B" "?A" thus ?thesis ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   302
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   303
text{*\noindent Command \isakeyword{using} can appear before a proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   304
and adds further facts to those piped into the proof. Here @{text ab}
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   305
is the only such fact and it triggers $\land$-elimination. Another
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   306
frequent idiom is as follows:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   307
\begin{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   308
\isakeyword{from} \emph{major-facts}~
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   309
\isakeyword{show} \emph{proposition}~
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   310
\isakeyword{using} \emph{minor-facts}~
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   311
\emph{proof}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   312
\end{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   313
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   314
Sometimes it is necessary to suppress the implicit application of rules in a
27171
nipkow
parents: 25427
diff changeset
   315
\isakeyword{proof}. For example \isakeyword{show(s)}~@{prop[source]"P \<or> Q"}
nipkow
parents: 25427
diff changeset
   316
would trigger $\lor$-introduction, requiring us to prove @{prop P}, which may
nipkow
parents: 25427
diff changeset
   317
not be what we had in mind.
nipkow
parents: 25427
diff changeset
   318
A simple ``@{text"-"}'' prevents this \emph{faux pas}: *}
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   319
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   320
lemma assumes ab: "A \<or> B" shows "B \<or> A"
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   321
proof -
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   322
  from ab show ?thesis
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   323
  proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   324
    assume A thus ?thesis ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   325
  next
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   326
    assume B thus ?thesis ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   327
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   328
qed
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   329
text{*\noindent Alternatively one can feed @{prop"A \<or> B"} directly
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   330
into the proof, thus triggering the elimination rule: *}
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   331
lemma assumes ab: "A \<or> B" shows "B \<or> A"
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   332
using ab
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   333
proof
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   334
  assume A thus ?thesis ..
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   335
next
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   336
  assume B thus ?thesis ..
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   337
qed
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   338
text{* \noindent Remember that eliminations have priority over
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   339
introductions.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   340
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   341
\subsection{Avoiding names}
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   342
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   343
Too many names can easily clutter a proof.  We already learned
19840
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   344
about @{text this} as a means of avoiding explicit names. Another
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   345
handy device is to refer to a fact not by name but by contents: for
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   346
example, writing @{text "`A \<or> B`"} (enclosing the formula in back quotes)
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   347
refers to the fact @{text"A \<or> B"}
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   348
without the need to name it. Here is a simple example, a revised version
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   349
of the previous proof *}
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   350
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   351
lemma assumes "A \<or> B" shows "B \<or> A"
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   352
using `A \<or> B`
19840
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   353
(*<*)oops(*>*)
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   354
text{*\noindent which continues as before.
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   355
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   356
Clearly, this device of quoting facts by contents is only advisable
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   357
for small formulae. In such cases it is superior to naming because the
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   358
reader immediately sees what the fact is without needing to search for
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   359
it in the preceding proof text.
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   360
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   361
The assumptions of a lemma can also be referred to via their
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   362
predefined name @{text assms}. Hence the @{text"`A \<or> B`"} in the
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   363
previous proof can also be replaced by @{text assms}. Note that @{text
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   364
assms} refers to the list of \emph{all} assumptions. To pick out a
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   365
specific one, say the second, write @{text"assms(2)"}.
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   366
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   367
This indexing notation $name(.)$ works for any $name$ that stands for
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   368
a list of facts, for example $f$@{text".simps"}, the equations of the
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   369
recursively defined function $f$. You may also select sublists by writing
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   370
$name(2-3)$.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   371
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   372
Above we recommended the UNIX-pipe model (i.e. @{text this}) to avoid
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   373
the need to name propositions. But frequently we needed to feed more
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   374
than one previously derived fact into a proof step. Then the UNIX-pipe
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   375
model appears to break down and we need to name the different facts to
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   376
refer to them. But this can be avoided: *}
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   377
lemma assumes "A \<and> B" shows "B \<and> A"
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   378
proof -
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   379
  from `A \<and> B` have "B" ..
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   380
  moreover
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   381
  from `A \<and> B` have "A" ..
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   382
  ultimately show "B \<and> A" ..
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   383
qed
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   384
text{*\noindent You can combine any number of facts @{term A1} \dots\ @{term
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   385
An} into a sequence by separating their proofs with
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   386
\isakeyword{moreover}. After the final fact, \isakeyword{ultimately} stands
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   387
for \isakeyword{from}~@{term A1}~\dots~@{term An}.  This avoids having to
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   388
introduce names for all of the sequence elements.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   389
25412
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   390
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   391
\subsection{Predicate calculus}
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   392
6f56f0350f6c updates
nipkow
parents: 19840
diff changeset
   393
Command \isakeyword{fix} introduces new local variables into a
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   394
proof. The pair \isakeyword{fix}-\isakeyword{show} corresponds to @{text"\<And>"}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   395
(the universal quantifier at the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   396
meta-level) just like \isakeyword{assume}-\isakeyword{show} corresponds to
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   397
@{text"\<Longrightarrow>"}. Here is a sample proof, annotated with the rules that are
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   398
applied implicitly: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   399
lemma assumes P: "\<forall>x. P x" shows "\<forall>x. P(f x)"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   400
proof                       --"@{thm[source]allI}: @{thm allI}"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   401
  fix a
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   402
  from P show "P(f a)" ..  --"@{thm[source]allE}: @{thm allE}"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   403
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   404
text{*\noindent Note that in the proof we have chosen to call the bound
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   405
variable @{term a} instead of @{term x} merely to show that the choice of
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   406
local names is irrelevant.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   407
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   408
Next we look at @{text"\<exists>"} which is a bit more tricky.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   409
*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   410
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   411
lemma assumes Pf: "\<exists>x. P(f x)" shows "\<exists>y. P y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   412
proof -
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   413
  from Pf show ?thesis
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   414
  proof              -- "@{thm[source]exE}: @{thm exE}"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   415
    fix x
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   416
    assume "P(f x)"
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   417
    thus ?thesis ..  -- "@{thm[source]exI}: @{thm exI}"
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   418
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   419
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   420
text{*\noindent Explicit $\exists$-elimination as seen above can become
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   421
cumbersome in practice.  The derived Isar language element
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   422
\isakeyword{obtain} provides a more appealing form of generalised
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   423
existence reasoning: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   424
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   425
lemma assumes Pf: "\<exists>x. P(f x)" shows "\<exists>y. P y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   426
proof -
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   427
  from Pf obtain x where "P(f x)" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   428
  thus "\<exists>y. P y" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   429
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   430
text{*\noindent Note how the proof text follows the usual mathematical style
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   431
of concluding $P(x)$ from $\exists x. P(x)$, while carefully introducing $x$
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   432
as a new local variable.  Technically, \isakeyword{obtain} is similar to
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   433
\isakeyword{fix} and \isakeyword{assume} together with a soundness proof of
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   434
the elimination involved.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   435
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   436
Here is a proof of a well known tautology.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   437
Which rule is used where?  *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   438
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   439
lemma assumes ex: "\<exists>x. \<forall>y. P x y" shows "\<forall>y. \<exists>x. P x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   440
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   441
  fix y
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   442
  from ex obtain x where "\<forall>y. P x y" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   443
  hence "P x y" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   444
  thus "\<exists>x. P x y" ..
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   445
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   446
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   447
subsection{*Making bigger steps*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   448
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   449
text{* So far we have confined ourselves to single step proofs. Of course
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   450
powerful automatic methods can be used just as well. Here is an example,
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   451
Cantor's theorem that there is no surjective function from a set to its
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   452
powerset: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   453
theorem "\<exists>S. S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   454
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   455
  let ?S = "{x. x \<notin> f x}"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   456
  show "?S \<notin> range f"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   457
  proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   458
    assume "?S \<in> range f"
19840
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   459
    then obtain y where "?S = f y" ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   460
    show False
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   461
    proof cases
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   462
      assume "y \<in> ?S"
19840
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   463
      with `?S = f y` show False by blast
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   464
    next
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   465
      assume "y \<notin> ?S"
19840
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   466
      with `?S = f y` show False by blast
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   467
    qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   468
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   469
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   470
text{*\noindent
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   471
For a start, the example demonstrates two new constructs:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   472
\begin{itemize}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   473
\item \isakeyword{let} introduces an abbreviation for a term, in our case
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   474
the witness for the claim.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   475
\item Proof by @{text"cases"} starts a proof by cases. Note that it remains
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   476
implicit what the two cases are: it is merely expected that the two subproofs
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   477
prove @{text"P \<Longrightarrow> ?thesis"} and @{text"\<not>P \<Longrightarrow> ?thesis"} (in that order)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   478
for some @{term P}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   479
\end{itemize}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   480
If you wonder how to \isakeyword{obtain} @{term y}:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   481
via the predefined elimination rule @{thm rangeE[no_vars]}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   482
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   483
Method @{text blast} is used because the contradiction does not follow easily
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   484
by just a single rule. If you find the proof too cryptic for human
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   485
consumption, here is a more detailed version; the beginning up to
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   486
\isakeyword{obtain} stays unchanged. *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   487
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   488
theorem "\<exists>S. S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   489
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   490
  let ?S = "{x. x \<notin> f x}"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   491
  show "?S \<notin> range f"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   492
  proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   493
    assume "?S \<in> range f"
19840
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   494
    then obtain y where "?S = f y" ..
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   495
    show False
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   496
    proof cases
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   497
      assume "y \<in> ?S"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   498
      hence "y \<notin> f y"   by simp
19840
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   499
      hence "y \<notin> ?S"    by(simp add: `?S = f y`)
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   500
      with `y \<in> ?S` show False by contradiction
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   501
    next
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   502
      assume "y \<notin> ?S"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   503
      hence "y \<in> f y"   by simp
19840
600c35fd1b5e added quoting via back quotes
nipkow
parents: 17914
diff changeset
   504
      hence "y \<in> ?S"    by(simp add: `?S = f y`)
29298
ddee49421280 eliminated implicit use of prems;
wenzelm
parents: 27171
diff changeset
   505
      with `y \<notin> ?S` show False by contradiction
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   506
    qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   507
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   508
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   509
text{*\noindent Method @{text contradiction} succeeds if both $P$ and
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   510
$\neg P$ are among the assumptions and the facts fed into that step, in any order.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   511
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   512
As it happens, Cantor's theorem can be proved automatically by best-first
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   513
search. Depth-first search would diverge, but best-first search successfully
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   514
navigates through the large search space:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   515
*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   516
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   517
theorem "\<exists>S. S \<notin> range (f :: 'a \<Rightarrow> 'a set)"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   518
by best
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   519
(* Of course this only works in the context of HOL's carefully
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   520
constructed introduction and elimination rules for set theory.*)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   521
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   522
subsection{*Raw proof blocks*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   523
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   524
text{* Although we have shown how to employ powerful automatic methods like
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   525
@{text blast} to achieve bigger proof steps, there may still be the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   526
tendency to use the default introduction and elimination rules to
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   527
decompose goals and facts. This can lead to very tedious proofs:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   528
*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   529
lemma "\<forall>x y. A x y \<and> B x y \<longrightarrow> C x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   530
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   531
  fix x show "\<forall>y. A x y \<and> B x y \<longrightarrow> C x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   532
  proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   533
    fix y show "A x y \<and> B x y \<longrightarrow> C x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   534
    proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   535
      assume "A x y \<and> B x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   536
      show "C x y" sorry
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   537
    qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   538
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   539
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   540
text{*\noindent Since we are only interested in the decomposition and not the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   541
actual proof, the latter has been replaced by
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   542
\isakeyword{sorry}. Command \isakeyword{sorry} proves anything but is
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   543
only allowed in quick and dirty mode, the default interactive mode. It
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   544
is very convenient for top down proof development.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   545
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   546
Luckily we can avoid this step by step decomposition very easily: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   547
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   548
lemma "\<forall>x y. A x y \<and> B x y \<longrightarrow> C x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   549
proof -
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   550
  have "\<And>x y. \<lbrakk> A x y; B x y \<rbrakk> \<Longrightarrow> C x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   551
  proof -
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   552
    fix x y assume "A x y" "B x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   553
    show "C x y" sorry
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   554
  qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   555
  thus ?thesis by blast
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   556
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   557
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   558
text{*\noindent
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   559
This can be simplified further by \emph{raw proof blocks}, i.e.\
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   560
proofs enclosed in braces: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   561
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   562
lemma "\<forall>x y. A x y \<and> B x y \<longrightarrow> C x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   563
proof -
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   564
  { fix x y assume "A x y" "B x y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   565
    have "C x y" sorry }
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   566
  thus ?thesis by blast
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   567
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   568
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   569
text{*\noindent The result of the raw proof block is the same theorem
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   570
as above, namely @{prop"\<And>x y. \<lbrakk> A x y; B x y \<rbrakk> \<Longrightarrow> C x y"}.  Raw
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   571
proof blocks are like ordinary proofs except that they do not prove
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   572
some explicitly stated property but that the property emerges directly
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   573
out of the \isakeyword{fixe}s, \isakeyword{assume}s and
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   574
\isakeyword{have} in the block. Thus they again serve to avoid
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   575
duplication. Note that the conclusion of a raw proof block is stated with
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   576
\isakeyword{have} rather than \isakeyword{show} because it is not the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   577
conclusion of some pending goal but some independent claim.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   578
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   579
The general idea demonstrated in this subsection is very
25427
8ba39d2d9d0b updated
nipkow
parents: 25412
diff changeset
   580
important in Isar and distinguishes it from \isa{apply}-style proofs:
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   581
\begin{quote}\em
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   582
Do not manipulate the proof state into a particular form by applying
25427
8ba39d2d9d0b updated
nipkow
parents: 25412
diff changeset
   583
proof methods but state the desired form explicitly and let the proof
8ba39d2d9d0b updated
nipkow
parents: 25412
diff changeset
   584
methods verify that from this form the original goal follows.
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   585
\end{quote}
14617
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   586
This yields more readable and also more robust proofs.
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   587
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   588
\subsubsection{General case distinctions}
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   589
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   590
As an important application of raw proof blocks we show how to deal
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   591
with general case distinctions --- more specific kinds are treated in
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   592
\S\ref{sec:CaseDistinction}. Imagine that you would like to prove some
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   593
goal by distinguishing $n$ cases $P_1$, \dots, $P_n$. You show that
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   594
the $n$ cases are exhaustive (i.e.\ $P_1 \lor \dots \lor P_n$) and
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   595
that each case $P_i$ implies the goal. Taken together, this proves the
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   596
goal. The corresponding Isar proof pattern (for $n = 3$) is very handy:
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   597
*}
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   598
text_raw{*\renewcommand{\isamarkupcmt}[1]{#1}*}
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   599
(*<*)lemma "XXX"(*>*)
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   600
proof -
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   601
  have "P\<^isub>1 \<or> P\<^isub>2 \<or> P\<^isub>3" (*<*)sorry(*>*) -- {*\dots*}
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   602
  moreover
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   603
  { assume P\<^isub>1
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   604
    -- {*\dots*}
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   605
    have ?thesis (*<*)sorry(*>*) -- {*\dots*} }
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   606
  moreover
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   607
  { assume P\<^isub>2
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   608
    -- {*\dots*}
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   609
    have ?thesis (*<*)sorry(*>*) -- {*\dots*} }
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   610
  moreover
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   611
  { assume P\<^isub>3
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   612
    -- {*\dots*}
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   613
    have ?thesis (*<*)sorry(*>*) -- {*\dots*} }
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   614
  ultimately show ?thesis by blast
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   615
qed
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   616
text_raw{*\renewcommand{\isamarkupcmt}[1]{{\isastylecmt--- #1}}*}
a2bcb11ce445 Added case distinction proof pattern.
nipkow
parents: 13999
diff changeset
   617
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   618
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   619
subsection{*Further refinements*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   620
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   621
text{* This subsection discusses some further tricks that can make
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   622
life easier although they are not essential. *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   623
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   624
subsubsection{*\isakeyword{and}*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   625
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   626
text{* Propositions (following \isakeyword{assume} etc) may but need not be
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   627
separated by \isakeyword{and}. This is not just for readability
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   628
(\isakeyword{from} \isa{A} \isakeyword{and} \isa{B} looks nicer than
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   629
\isakeyword{from} \isa{A} \isa{B}) but for structuring lists of propositions
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   630
into possibly named blocks. In
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   631
\begin{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   632
\isakeyword{assume} \isa{A:} $A_1$ $A_2$ \isakeyword{and} \isa{B:} $A_3$
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   633
\isakeyword{and} $A_4$
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   634
\end{center}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   635
label \isa{A} refers to the list of propositions $A_1$ $A_2$ and
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   636
label \isa{B} to $A_3$. *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   637
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   638
subsubsection{*\isakeyword{note}*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   639
text{* If you want to remember intermediate fact(s) that cannot be
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   640
named directly, use \isakeyword{note}. For example the result of raw
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   641
proof block can be named by following it with
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   642
\isakeyword{note}~@{text"some_name = this"}.  As a side effect,
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   643
@{text this} is set to the list of facts on the right-hand side. You
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   644
can also say @{text"note some_fact"}, which simply sets @{text this},
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   645
i.e.\ recalls @{text"some_fact"}, e.g.\ in a \isakeyword{moreover} sequence. *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   646
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   647
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   648
subsubsection{*\isakeyword{fixes}*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   649
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   650
text{* Sometimes it is necessary to decorate a proposition with type
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   651
constraints, as in Cantor's theorem above. These type constraints tend
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   652
to make the theorem less readable. The situation can be improved a
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   653
little by combining the type constraint with an outer @{text"\<And>"}: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   654
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   655
theorem "\<And>f :: 'a \<Rightarrow> 'a set. \<exists>S. S \<notin> range f"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   656
(*<*)oops(*>*)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   657
text{*\noindent However, now @{term f} is bound and we need a
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   658
\isakeyword{fix}~\isa{f} in the proof before we can refer to @{term f}.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   659
This is avoided by \isakeyword{fixes}: *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   660
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   661
theorem fixes f :: "'a \<Rightarrow> 'a set" shows "\<exists>S. S \<notin> range f"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   662
(*<*)oops(*>*)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   663
text{* \noindent
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   664
Even better, \isakeyword{fixes} allows to introduce concrete syntax locally:*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   665
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   666
lemma comm_mono:
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   667
  fixes r :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix ">" 60) and
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   668
       f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"   (infixl "++" 70)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   669
  assumes comm: "\<And>x y::'a. x ++ y = y ++ x" and
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   670
          mono: "\<And>x y z::'a. x > y \<Longrightarrow> x ++ z > y ++ z"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   671
  shows "x > y \<Longrightarrow> z ++ x > z ++ y"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   672
by(simp add: comm mono)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   673
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   674
text{*\noindent The concrete syntax is dropped at the end of the proof and the
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   675
theorem becomes @{thm[display,margin=60]comm_mono}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   676
\tweakskip *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   677
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   678
subsubsection{*\isakeyword{obtain}*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   679
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   680
text{* The \isakeyword{obtain} construct can introduce multiple
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   681
witnesses and propositions as in the following proof fragment:*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   682
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   683
lemma assumes A: "\<exists>x y. P x y \<and> Q x y" shows "R"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   684
proof -
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   685
  from A obtain x y where P: "P x y" and Q: "Q x y"  by blast
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   686
(*<*)oops(*>*)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   687
text{* Remember also that one does not even need to start with a formula
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   688
containing @{text"\<exists>"} as we saw in the proof of Cantor's theorem.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   689
*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   690
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   691
subsubsection{*Combining proof styles*}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   692
25427
8ba39d2d9d0b updated
nipkow
parents: 25412
diff changeset
   693
text{* Finally, whole \isa{apply}-scripts may appear in the leaves of the
8ba39d2d9d0b updated
nipkow
parents: 25412
diff changeset
   694
proof tree, although this is best avoided.  Here is a contrived example: *}
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   695
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   696
lemma "A \<longrightarrow> (A \<longrightarrow> B) \<longrightarrow> B"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   697
proof
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   698
  assume a: "A"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   699
  show "(A \<longrightarrow>B) \<longrightarrow> B"
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   700
    apply(rule impI)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   701
    apply(erule impE)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   702
    apply(rule a)
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   703
    apply assumption
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   704
    done
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   705
qed
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   706
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   707
text{*\noindent You may need to resort to this technique if an
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   708
automatic step fails to prove the desired proposition.
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   709
25427
8ba39d2d9d0b updated
nipkow
parents: 25412
diff changeset
   710
When converting a proof from \isa{apply}-style into Isar you can proceed
13999
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   711
in a top-down manner: parts of the proof can be left in script form
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   712
while the outer structure is already expressed in Isar. *}
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   713
454a2ad0c381 IsarOverview moved one level up
kleing
parents:
diff changeset
   714
(*<*)end(*>*)