author | wenzelm |
Thu, 30 May 2013 17:10:13 +0200 | |
changeset 52244 | cb15da7bd550 |
parent 50085 | 24ef81a22ee9 |
child 52406 | 1e57c3c4e05c |
permissions | -rw-r--r-- |
30184
37969710e61f
removed parts of the manual that are clearly obsolete, or covered by
wenzelm
parents:
11625
diff
changeset
|
1 |
|
104 | 2 |
\chapter{Theorems and Forward Proof} |
2040
6db93e6f1b11
Documented sort hypotheses and improved discussion of derivations
paulson
parents:
1876
diff
changeset
|
3 |
|
50085 | 4 |
\section{*Sort hypotheses} \label{sec:sort-hyps} |
50082
a025340c4abb
removed some historic material that is obsolete or rarely used;
wenzelm
parents:
50074
diff
changeset
|
5 |
|
2040
6db93e6f1b11
Documented sort hypotheses and improved discussion of derivations
paulson
parents:
1876
diff
changeset
|
6 |
\begin{ttbox} |
7644 | 7 |
strip_shyps : thm -> thm |
8 |
strip_shyps_warning : thm -> thm |
|
2040
6db93e6f1b11
Documented sort hypotheses and improved discussion of derivations
paulson
parents:
1876
diff
changeset
|
9 |
\end{ttbox} |
6db93e6f1b11
Documented sort hypotheses and improved discussion of derivations
paulson
parents:
1876
diff
changeset
|
10 |
|
2044
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
11 |
Isabelle's type variables are decorated with sorts, constraining them to |
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
12 |
certain ranges of types. This has little impact when sorts only serve for |
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
13 |
syntactic classification of types --- for example, FOL distinguishes between |
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
14 |
terms and other types. But when type classes are introduced through axioms, |
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
15 |
this may result in some sorts becoming {\em empty\/}: where one cannot exhibit |
4317 | 16 |
a type belonging to it because certain sets of axioms are unsatisfiable. |
2044
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
17 |
|
3108 | 18 |
If a theorem contains a type variable that is constrained by an empty |
3485
f27a30a18a17
Now there are TWO spaces after each full stop, so that the Emacs sentence
paulson
parents:
3135
diff
changeset
|
19 |
sort, then that theorem has no instances. It is basically an instance |
3108 | 20 |
of {\em ex falso quodlibet}. But what if it is used to prove another |
21 |
theorem that no longer involves that sort? The latter theorem holds |
|
22 |
only if under an additional non-emptiness assumption. |
|
2040
6db93e6f1b11
Documented sort hypotheses and improved discussion of derivations
paulson
parents:
1876
diff
changeset
|
23 |
|
3485
f27a30a18a17
Now there are TWO spaces after each full stop, so that the Emacs sentence
paulson
parents:
3135
diff
changeset
|
24 |
Therefore, Isabelle's theorems carry around sort hypotheses. The {\tt |
2044
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
25 |
shyps} field is a list of sorts occurring in type variables in the current |
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
26 |
{\tt prop} and {\tt hyps} fields. It may also includes sorts used in the |
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
27 |
theorem's proof that no longer appear in the {\tt prop} or {\tt hyps} |
3485
f27a30a18a17
Now there are TWO spaces after each full stop, so that the Emacs sentence
paulson
parents:
3135
diff
changeset
|
28 |
fields --- so-called {\em dangling\/} sort constraints. These are the |
2044
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
29 |
critical ones, asserting non-emptiness of the corresponding sorts. |
e8d52d05530a
Improved discussion of shyps thanks to Markus Wenzel
paulson
parents:
2040
diff
changeset
|
30 |
|
7644 | 31 |
Isabelle automatically removes extraneous sorts from the {\tt shyps} field at |
32 |
the end of a proof, provided that non-emptiness can be established by looking |
|
33 |
at the theorem's signature: from the {\tt classes} and {\tt arities} |
|
34 |
information. This operation is performed by \texttt{strip_shyps} and |
|
35 |
\texttt{strip_shyps_warning}. |
|
36 |
||
37 |
\begin{ttdescription} |
|
38 |
||
39 |
\item[\ttindexbold{strip_shyps} $thm$] removes any extraneous sort hypotheses |
|
40 |
that can be witnessed from the type signature. |
|
41 |
||
42 |
\item[\ttindexbold{strip_shyps_warning}] is like \texttt{strip_shyps}, but |
|
43 |
issues a warning message of any pending sort hypotheses that do not have a |
|
44 |
(syntactic) witness. |
|
45 |
||
46 |
\end{ttdescription} |
|
2040
6db93e6f1b11
Documented sort hypotheses and improved discussion of derivations
paulson
parents:
1876
diff
changeset
|
47 |
|
104 | 48 |
|
11622 | 49 |
\section{Proof terms}\label{sec:proofObjects} |
50 |
\index{proof terms|(} Isabelle can record the full meta-level proof of each |
|
51 |
theorem. The proof term contains all logical inferences in detail. |
|
52 |
%while |
|
53 |
%omitting bookkeeping steps that have no logical meaning to an outside |
|
54 |
%observer. Rewriting steps are recorded in similar detail as the output of |
|
55 |
%simplifier tracing. |
|
56 |
Resolution and rewriting steps are broken down to primitive rules of the |
|
57 |
meta-logic. The proof term can be inspected by a separate proof-checker, |
|
58 |
for example. |
|
1590 | 59 |
|
11622 | 60 |
According to the well-known {\em Curry-Howard isomorphism}, a proof can |
61 |
be viewed as a $\lambda$-term. Following this idea, proofs |
|
62 |
in Isabelle are internally represented by a datatype similar to the one for |
|
63 |
terms described in \S\ref{sec:terms}. |
|
64 |
\begin{ttbox} |
|
65 |
infix 8 % %%; |
|
66 |
||
67 |
datatype proof = |
|
68 |
PBound of int |
|
69 |
| Abst of string * typ option * proof |
|
70 |
| AbsP of string * term option * proof |
|
71 |
| op % of proof * term option |
|
72 |
| op %% of proof * proof |
|
73 |
| Hyp of term |
|
74 |
| PThm of (string * (string * string list) list) * |
|
75 |
proof * term * typ list option |
|
76 |
| PAxm of string * term * typ list option |
|
77 |
| Oracle of string * term * typ list option |
|
78 |
| MinProof of proof list; |
|
79 |
\end{ttbox} |
|
1590 | 80 |
|
11622 | 81 |
\begin{ttdescription} |
82 |
\item[\ttindexbold{Abst} ($a$, $\tau$, $prf$)] is the abstraction over |
|
83 |
a {\it term variable} of type $\tau$ in the body $prf$. Logically, this |
|
84 |
corresponds to $\bigwedge$ introduction. The name $a$ is used only for |
|
85 |
parsing and printing. |
|
86 |
\item[\ttindexbold{AbsP} ($a$, $\varphi$, $prf$)] is the abstraction |
|
87 |
over a {\it proof variable} standing for a proof of proposition $\varphi$ |
|
88 |
in the body $prf$. This corresponds to $\Longrightarrow$ introduction. |
|
89 |
\item[$prf$ \% $t$] \index{\%@{\tt\%}|bold} |
|
90 |
is the application of proof $prf$ to term $t$ |
|
91 |
which corresponds to $\bigwedge$ elimination. |
|
92 |
\item[$prf@1$ \%\% $prf@2$] \index{\%\%@{\tt\%\%}|bold} |
|
93 |
is the application of proof $prf@1$ to |
|
94 |
proof $prf@2$ which corresponds to $\Longrightarrow$ elimination. |
|
95 |
\item[\ttindexbold{PBound} $i$] is a {\em proof variable} with de Bruijn |
|
96 |
\cite{debruijn72} index $i$. |
|
97 |
\item[\ttindexbold{Hyp} $\varphi$] corresponds to the use of a meta level |
|
98 |
hypothesis $\varphi$. |
|
99 |
\item[\ttindexbold{PThm} (($name$, $tags$), $prf$, $\varphi$, $\overline{\tau}$)] |
|
100 |
stands for a pre-proved theorem, where $name$ is the name of the theorem, |
|
101 |
$prf$ is its actual proof, $\varphi$ is the proven proposition, |
|
102 |
and $\overline{\tau}$ is |
|
103 |
a type assignment for the type variables occurring in the proposition. |
|
104 |
\item[\ttindexbold{PAxm} ($name$, $\varphi$, $\overline{\tau}$)] |
|
105 |
corresponds to the use of an axiom with name $name$ and proposition |
|
106 |
$\varphi$, where $\overline{\tau}$ is a type assignment for the type |
|
107 |
variables occurring in the proposition. |
|
108 |
\item[\ttindexbold{Oracle} ($name$, $\varphi$, $\overline{\tau}$)] |
|
109 |
denotes the invocation of an oracle with name $name$ which produced |
|
110 |
a proposition $\varphi$, where $\overline{\tau}$ is a type assignment |
|
111 |
for the type variables occurring in the proposition. |
|
112 |
\item[\ttindexbold{MinProof} $prfs$] |
|
113 |
represents a {\em minimal proof} where $prfs$ is a list of theorems, |
|
114 |
axioms or oracles. |
|
115 |
\end{ttdescription} |
|
116 |
Note that there are no separate constructors |
|
117 |
for abstraction and application on the level of {\em types}, since |
|
118 |
instantiation of type variables is accomplished via the type assignments |
|
119 |
attached to {\tt Thm}, {\tt Axm} and {\tt Oracle}. |
|
1590 | 120 |
|
121 |
Each theorem's derivation is stored as the {\tt der} field of its internal |
|
122 |
record: |
|
123 |
\begin{ttbox} |
|
11622 | 124 |
#2 (#der (rep_thm conjI)); |
125 |
{\out PThm (("HOL.conjI", []),} |
|
126 |
{\out AbsP ("H", None, AbsP ("H", None, \dots)), \dots, None) %} |
|
127 |
{\out None % None : Proofterm.proof} |
|
1590 | 128 |
\end{ttbox} |
11622 | 129 |
This proof term identifies a labelled theorem, {\tt conjI} of theory |
130 |
\texttt{HOL}, whose underlying proof is |
|
131 |
{\tt AbsP ("H", None, AbsP ("H", None, $\dots$))}. |
|
132 |
The theorem is applied to two (implicit) term arguments, which correspond |
|
133 |
to the two variables occurring in its proposition. |
|
1590 | 134 |
|
11622 | 135 |
Isabelle's inference kernel can produce proof objects with different |
136 |
levels of detail. This is controlled via the global reference variable |
|
137 |
\ttindexbold{proofs}: |
|
138 |
\begin{ttdescription} |
|
139 |
\item[proofs := 0;] only record uses of oracles |
|
140 |
\item[proofs := 1;] record uses of oracles as well as dependencies |
|
141 |
on other theorems and axioms |
|
142 |
\item[proofs := 2;] record inferences in full detail |
|
1590 | 143 |
\end{ttdescription} |
11622 | 144 |
Reconstruction and checking of proofs as described in \S\ref{sec:reconstruct_proofs} |
145 |
will not work for proofs constructed with {\tt proofs} set to |
|
146 |
{\tt 0} or {\tt 1}. |
|
147 |
Theorems involving oracles will be printed with a |
|
148 |
suffixed \verb|[!]| to point out the different quality of confidence achieved. |
|
5371 | 149 |
|
7871 | 150 |
\medskip |
151 |
||
11622 | 152 |
The dependencies of theorems can be viewed using the function |
153 |
\ttindexbold{thm_deps}\index{theorems!dependencies}: |
|
7871 | 154 |
\begin{ttbox} |
155 |
thm_deps [\(thm@1\), \(\ldots\), \(thm@n\)]; |
|
156 |
\end{ttbox} |
|
157 |
generates the dependency graph of the theorems $thm@1$, $\ldots$, $thm@n$ and |
|
11622 | 158 |
displays it using Isabelle's graph browser. For this to work properly, |
159 |
the theorems in question have to be proved with {\tt proofs} set to a value |
|
160 |
greater than {\tt 0}. You can use |
|
161 |
\begin{ttbox} |
|
162 |
ThmDeps.enable : unit -> unit |
|
163 |
ThmDeps.disable : unit -> unit |
|
164 |
\end{ttbox} |
|
165 |
to set \texttt{proofs} appropriately. |
|
166 |
||
167 |
\subsection{Reconstructing and checking proof terms}\label{sec:reconstruct_proofs} |
|
168 |
\index{proof terms!reconstructing} |
|
169 |
\index{proof terms!checking} |
|
170 |
||
171 |
When looking at the above datatype of proofs more closely, one notices that |
|
172 |
some arguments of constructors are {\it optional}. The reason for this is that |
|
173 |
keeping a full proof term for each theorem would result in enormous memory |
|
174 |
requirements. Fortunately, typical proof terms usually contain quite a lot of |
|
175 |
redundant information that can be reconstructed from the context. Therefore, |
|
176 |
Isabelle's inference kernel creates only {\em partial} (or {\em implicit}) |
|
177 |
\index{proof terms!partial} proof terms, in which |
|
178 |
all typing information in terms, all term and type labels of abstractions |
|
179 |
{\tt AbsP} and {\tt Abst}, and (if possible) some argument terms of |
|
180 |
\verb!%! are omitted. The following functions are available for |
|
181 |
reconstructing and checking proof terms: |
|
182 |
\begin{ttbox} |
|
183 |
Reconstruct.reconstruct_proof : |
|
184 |
Sign.sg -> term -> Proofterm.proof -> Proofterm.proof |
|
185 |
Reconstruct.expand_proof : |
|
186 |
Sign.sg -> string list -> Proofterm.proof -> Proofterm.proof |
|
187 |
ProofChecker.thm_of_proof : theory -> Proofterm.proof -> thm |
|
188 |
\end{ttbox} |
|
189 |
||
190 |
\begin{ttdescription} |
|
191 |
\item[Reconstruct.reconstruct_proof $sg$ $t$ $prf$] |
|
192 |
turns the partial proof $prf$ into a full proof of the |
|
193 |
proposition denoted by $t$, with respect to signature $sg$. |
|
194 |
Reconstruction will fail with an error message if $prf$ |
|
195 |
is not a proof of $t$, is ill-formed, or does not contain |
|
196 |
sufficient information for reconstruction by |
|
197 |
{\em higher order pattern unification} |
|
198 |
\cite{nipkow-patterns, Berghofer-Nipkow:2000:TPHOL}. |
|
199 |
The latter may only happen for proofs |
|
200 |
built up ``by hand'' but not for those produced automatically |
|
201 |
by Isabelle's inference kernel. |
|
202 |
\item[Reconstruct.expand_proof $sg$ |
|
203 |
\ttlbrack$name@1$, $\ldots$, $name@n${\ttrbrack} $prf$] |
|
204 |
expands and reconstructs the proofs of all theorems with names |
|
205 |
$name@1$, $\ldots$, $name@n$ in the (full) proof $prf$. |
|
206 |
\item[ProofChecker.thm_of_proof $thy$ $prf$] turns the (full) proof |
|
207 |
$prf$ into a theorem with respect to theory $thy$ by replaying |
|
208 |
it using only primitive rules from Isabelle's inference kernel. |
|
209 |
\end{ttdescription} |
|
210 |
||
211 |
\subsection{Parsing and printing proof terms} |
|
212 |
\index{proof terms!parsing} |
|
213 |
\index{proof terms!printing} |
|
214 |
||
215 |
Isabelle offers several functions for parsing and printing |
|
216 |
proof terms. The concrete syntax for proof terms is described |
|
217 |
in Fig.\ts\ref{fig:proof_gram}. |
|
218 |
Implicit term arguments in partial proofs are indicated |
|
219 |
by ``{\tt _}''. |
|
220 |
Type arguments for theorems and axioms may be specified using |
|
221 |
\verb!%! or ``$\cdot$'' with an argument of the form {\tt TYPE($type$)} |
|
222 |
(see \S\ref{sec:basic_syntax}). |
|
223 |
They must appear before any other term argument of a theorem |
|
224 |
or axiom. In contrast to term arguments, type arguments may |
|
225 |
be completely omitted. |
|
7871 | 226 |
\begin{ttbox} |
11625
74cdf24724ea
Tuned section about parsing and printing proof terms.
berghofe
parents:
11622
diff
changeset
|
227 |
ProofSyntax.read_proof : theory -> bool -> string -> Proofterm.proof |
74cdf24724ea
Tuned section about parsing and printing proof terms.
berghofe
parents:
11622
diff
changeset
|
228 |
ProofSyntax.pretty_proof : Sign.sg -> Proofterm.proof -> Pretty.T |
74cdf24724ea
Tuned section about parsing and printing proof terms.
berghofe
parents:
11622
diff
changeset
|
229 |
ProofSyntax.pretty_proof_of : bool -> thm -> Pretty.T |
74cdf24724ea
Tuned section about parsing and printing proof terms.
berghofe
parents:
11622
diff
changeset
|
230 |
ProofSyntax.print_proof_of : bool -> thm -> unit |
7871 | 231 |
\end{ttbox} |
11622 | 232 |
\begin{figure} |
233 |
\begin{center} |
|
234 |
\begin{tabular}{rcl} |
|
235 |
$proof$ & $=$ & {\tt Lam} $params${\tt .} $proof$ ~~$|$~~ |
|
236 |
$\Lambda params${\tt .} $proof$ \\ |
|
237 |
& $|$ & $proof$ \verb!%! $any$ ~~$|$~~ |
|
238 |
$proof$ $\cdot$ $any$ \\ |
|
239 |
& $|$ & $proof$ \verb!%%! $proof$ ~~$|$~~ |
|
240 |
$proof$ {\boldmath$\cdot$} $proof$ \\ |
|
241 |
& $|$ & $id$ ~~$|$~~ $longid$ \\\\ |
|
242 |
$param$ & $=$ & $idt$ ~~$|$~~ $idt$ {\tt :} $prop$ ~~$|$~~ |
|
243 |
{\tt (} $param$ {\tt )} \\\\ |
|
244 |
$params$ & $=$ & $param$ ~~$|$~~ $param$ $params$ |
|
245 |
\end{tabular} |
|
246 |
\end{center} |
|
247 |
\caption{Proof term syntax}\label{fig:proof_gram} |
|
248 |
\end{figure} |
|
249 |
The function {\tt read_proof} reads in a proof term with |
|
250 |
respect to a given theory. The boolean flag indicates whether |
|
251 |
the proof term to be parsed contains explicit typing information |
|
252 |
to be taken into account. |
|
253 |
Usually, typing information is left implicit and |
|
254 |
is inferred during proof reconstruction. The pretty printing |
|
255 |
functions operating on theorems take a boolean flag as an |
|
256 |
argument which indicates whether the proof term should |
|
257 |
be reconstructed before printing. |
|
258 |
||
259 |
The following example (based on Isabelle/HOL) illustrates how |
|
260 |
to parse and check proof terms. We start by parsing a partial |
|
261 |
proof term |
|
262 |
\begin{ttbox} |
|
263 |
val prf = ProofSyntax.read_proof Main.thy false |
|
264 |
"impI % _ % _ %% (Lam H : _. conjE % _ % _ % _ %% H %% |
|
265 |
(Lam (H1 : _) H2 : _. conjI % _ % _ %% H2 %% H1))"; |
|
266 |
{\out val prf = PThm (("HOL.impI", []), \dots, \dots, None) % None % None %%} |
|
267 |
{\out AbsP ("H", None, PThm (("HOL.conjE", []), \dots, \dots, None) %} |
|
268 |
{\out None % None % None %% PBound 0 %%} |
|
269 |
{\out AbsP ("H1", None, AbsP ("H2", None, \dots))) : Proofterm.proof} |
|
270 |
\end{ttbox} |
|
271 |
The statement to be established by this proof is |
|
272 |
\begin{ttbox} |
|
273 |
val t = term_of |
|
274 |
(read_cterm (sign_of Main.thy) ("A & B --> B & A", propT)); |
|
275 |
{\out val t = Const ("Trueprop", "bool => prop") $} |
|
276 |
{\out (Const ("op -->", "[bool, bool] => bool") $} |
|
277 |
{\out \dots $ \dots : Term.term} |
|
278 |
\end{ttbox} |
|
279 |
Using {\tt t} we can reconstruct the full proof |
|
280 |
\begin{ttbox} |
|
281 |
val prf' = Reconstruct.reconstruct_proof (sign_of Main.thy) t prf; |
|
282 |
{\out val prf' = PThm (("HOL.impI", []), \dots, \dots, Some []) %} |
|
283 |
{\out Some (Const ("op &", \dots) $ Free ("A", \dots) $ Free ("B", \dots)) %} |
|
284 |
{\out Some (Const ("op &", \dots) $ Free ("B", \dots) $ Free ("A", \dots)) %%} |
|
285 |
{\out AbsP ("H", Some (Const ("Trueprop", \dots) $ \dots), \dots)} |
|
286 |
{\out : Proofterm.proof} |
|
287 |
\end{ttbox} |
|
288 |
This proof can finally be turned into a theorem |
|
289 |
\begin{ttbox} |
|
290 |
val thm = ProofChecker.thm_of_proof Main.thy prf'; |
|
291 |
{\out val thm = "A & B --> B & A" : Thm.thm} |
|
292 |
\end{ttbox} |
|
293 |
||
294 |
\index{proof terms|)} |
|
295 |
\index{theorems|)} |
|
7871 | 296 |
|
5371 | 297 |
|
298 |
%%% Local Variables: |
|
299 |
%%% mode: latex |
|
300 |
%%% TeX-master: "ref" |
|
301 |
%%% End: |