author | wenzelm |
Sat, 15 Jun 2013 21:01:07 +0200 | |
changeset 52408 | fa2dc6c6c94f |
parent 52407 | e4662afb3483 |
child 52409 | 47c62377be78 |
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 |
|
11622 | 4 |
\section{Proof terms}\label{sec:proofObjects} |
5 |
||
6 |
Note that there are no separate constructors |
|
7 |
for abstraction and application on the level of {\em types}, since |
|
8 |
instantiation of type variables is accomplished via the type assignments |
|
9 |
attached to {\tt Thm}, {\tt Axm} and {\tt Oracle}. |
|
1590 | 10 |
|
11 |
Each theorem's derivation is stored as the {\tt der} field of its internal |
|
12 |
record: |
|
13 |
\begin{ttbox} |
|
11622 | 14 |
#2 (#der (rep_thm conjI)); |
15 |
{\out PThm (("HOL.conjI", []),} |
|
16 |
{\out AbsP ("H", None, AbsP ("H", None, \dots)), \dots, None) %} |
|
17 |
{\out None % None : Proofterm.proof} |
|
1590 | 18 |
\end{ttbox} |
11622 | 19 |
This proof term identifies a labelled theorem, {\tt conjI} of theory |
20 |
\texttt{HOL}, whose underlying proof is |
|
21 |
{\tt AbsP ("H", None, AbsP ("H", None, $\dots$))}. |
|
22 |
The theorem is applied to two (implicit) term arguments, which correspond |
|
23 |
to the two variables occurring in its proposition. |
|
1590 | 24 |
|
11622 | 25 |
Reconstruction and checking of proofs as described in \S\ref{sec:reconstruct_proofs} |
26 |
will not work for proofs constructed with {\tt proofs} set to |
|
27 |
{\tt 0} or {\tt 1}. |
|
28 |
Theorems involving oracles will be printed with a |
|
29 |
suffixed \verb|[!]| to point out the different quality of confidence achieved. |
|
5371 | 30 |
|
7871 | 31 |
\medskip |
32 |
||
11622 | 33 |
The dependencies of theorems can be viewed using the function |
34 |
\ttindexbold{thm_deps}\index{theorems!dependencies}: |
|
7871 | 35 |
\begin{ttbox} |
36 |
thm_deps [\(thm@1\), \(\ldots\), \(thm@n\)]; |
|
37 |
\end{ttbox} |
|
38 |
generates the dependency graph of the theorems $thm@1$, $\ldots$, $thm@n$ and |
|
11622 | 39 |
displays it using Isabelle's graph browser. For this to work properly, |
40 |
the theorems in question have to be proved with {\tt proofs} set to a value |
|
41 |
greater than {\tt 0}. You can use |
|
42 |
\begin{ttbox} |
|
43 |
ThmDeps.enable : unit -> unit |
|
44 |
ThmDeps.disable : unit -> unit |
|
45 |
\end{ttbox} |
|
46 |
to set \texttt{proofs} appropriately. |
|
47 |
||
48 |
\subsection{Reconstructing and checking proof terms}\label{sec:reconstruct_proofs} |
|
49 |
\index{proof terms!reconstructing} |
|
50 |
\index{proof terms!checking} |
|
51 |
||
52 |
When looking at the above datatype of proofs more closely, one notices that |
|
53 |
some arguments of constructors are {\it optional}. The reason for this is that |
|
54 |
keeping a full proof term for each theorem would result in enormous memory |
|
55 |
requirements. Fortunately, typical proof terms usually contain quite a lot of |
|
56 |
redundant information that can be reconstructed from the context. Therefore, |
|
57 |
Isabelle's inference kernel creates only {\em partial} (or {\em implicit}) |
|
58 |
\index{proof terms!partial} proof terms, in which |
|
59 |
all typing information in terms, all term and type labels of abstractions |
|
60 |
{\tt AbsP} and {\tt Abst}, and (if possible) some argument terms of |
|
61 |
\verb!%! are omitted. The following functions are available for |
|
62 |
reconstructing and checking proof terms: |
|
63 |
\begin{ttbox} |
|
64 |
Reconstruct.reconstruct_proof : |
|
65 |
Sign.sg -> term -> Proofterm.proof -> Proofterm.proof |
|
66 |
Reconstruct.expand_proof : |
|
67 |
Sign.sg -> string list -> Proofterm.proof -> Proofterm.proof |
|
68 |
ProofChecker.thm_of_proof : theory -> Proofterm.proof -> thm |
|
69 |
\end{ttbox} |
|
70 |
||
71 |
\begin{ttdescription} |
|
72 |
\item[Reconstruct.reconstruct_proof $sg$ $t$ $prf$] |
|
73 |
turns the partial proof $prf$ into a full proof of the |
|
74 |
proposition denoted by $t$, with respect to signature $sg$. |
|
75 |
Reconstruction will fail with an error message if $prf$ |
|
76 |
is not a proof of $t$, is ill-formed, or does not contain |
|
77 |
sufficient information for reconstruction by |
|
78 |
{\em higher order pattern unification} |
|
79 |
\cite{nipkow-patterns, Berghofer-Nipkow:2000:TPHOL}. |
|
80 |
The latter may only happen for proofs |
|
81 |
built up ``by hand'' but not for those produced automatically |
|
82 |
by Isabelle's inference kernel. |
|
83 |
\item[Reconstruct.expand_proof $sg$ |
|
84 |
\ttlbrack$name@1$, $\ldots$, $name@n${\ttrbrack} $prf$] |
|
85 |
expands and reconstructs the proofs of all theorems with names |
|
86 |
$name@1$, $\ldots$, $name@n$ in the (full) proof $prf$. |
|
87 |
\item[ProofChecker.thm_of_proof $thy$ $prf$] turns the (full) proof |
|
88 |
$prf$ into a theorem with respect to theory $thy$ by replaying |
|
89 |
it using only primitive rules from Isabelle's inference kernel. |
|
90 |
\end{ttdescription} |
|
91 |
||
92 |
\subsection{Parsing and printing proof terms} |
|
93 |
\index{proof terms!parsing} |
|
94 |
\index{proof terms!printing} |
|
95 |
||
96 |
Isabelle offers several functions for parsing and printing |
|
97 |
proof terms. The concrete syntax for proof terms is described |
|
98 |
in Fig.\ts\ref{fig:proof_gram}. |
|
99 |
Implicit term arguments in partial proofs are indicated |
|
100 |
by ``{\tt _}''. |
|
101 |
Type arguments for theorems and axioms may be specified using |
|
102 |
\verb!%! or ``$\cdot$'' with an argument of the form {\tt TYPE($type$)} |
|
103 |
(see \S\ref{sec:basic_syntax}). |
|
104 |
They must appear before any other term argument of a theorem |
|
105 |
or axiom. In contrast to term arguments, type arguments may |
|
106 |
be completely omitted. |
|
7871 | 107 |
\begin{ttbox} |
11625
74cdf24724ea
Tuned section about parsing and printing proof terms.
berghofe
parents:
11622
diff
changeset
|
108 |
ProofSyntax.read_proof : theory -> bool -> string -> Proofterm.proof |
74cdf24724ea
Tuned section about parsing and printing proof terms.
berghofe
parents:
11622
diff
changeset
|
109 |
ProofSyntax.pretty_proof : Sign.sg -> Proofterm.proof -> Pretty.T |
74cdf24724ea
Tuned section about parsing and printing proof terms.
berghofe
parents:
11622
diff
changeset
|
110 |
ProofSyntax.pretty_proof_of : bool -> thm -> Pretty.T |
74cdf24724ea
Tuned section about parsing and printing proof terms.
berghofe
parents:
11622
diff
changeset
|
111 |
ProofSyntax.print_proof_of : bool -> thm -> unit |
7871 | 112 |
\end{ttbox} |
11622 | 113 |
\begin{figure} |
114 |
\begin{center} |
|
115 |
\begin{tabular}{rcl} |
|
116 |
$proof$ & $=$ & {\tt Lam} $params${\tt .} $proof$ ~~$|$~~ |
|
117 |
$\Lambda params${\tt .} $proof$ \\ |
|
118 |
& $|$ & $proof$ \verb!%! $any$ ~~$|$~~ |
|
119 |
$proof$ $\cdot$ $any$ \\ |
|
120 |
& $|$ & $proof$ \verb!%%! $proof$ ~~$|$~~ |
|
121 |
$proof$ {\boldmath$\cdot$} $proof$ \\ |
|
122 |
& $|$ & $id$ ~~$|$~~ $longid$ \\\\ |
|
123 |
$param$ & $=$ & $idt$ ~~$|$~~ $idt$ {\tt :} $prop$ ~~$|$~~ |
|
124 |
{\tt (} $param$ {\tt )} \\\\ |
|
125 |
$params$ & $=$ & $param$ ~~$|$~~ $param$ $params$ |
|
126 |
\end{tabular} |
|
127 |
\end{center} |
|
128 |
\caption{Proof term syntax}\label{fig:proof_gram} |
|
129 |
\end{figure} |
|
130 |
The function {\tt read_proof} reads in a proof term with |
|
131 |
respect to a given theory. The boolean flag indicates whether |
|
132 |
the proof term to be parsed contains explicit typing information |
|
133 |
to be taken into account. |
|
134 |
Usually, typing information is left implicit and |
|
135 |
is inferred during proof reconstruction. The pretty printing |
|
136 |
functions operating on theorems take a boolean flag as an |
|
137 |
argument which indicates whether the proof term should |
|
138 |
be reconstructed before printing. |
|
139 |
||
140 |
The following example (based on Isabelle/HOL) illustrates how |
|
141 |
to parse and check proof terms. We start by parsing a partial |
|
142 |
proof term |
|
143 |
\begin{ttbox} |
|
144 |
val prf = ProofSyntax.read_proof Main.thy false |
|
145 |
"impI % _ % _ %% (Lam H : _. conjE % _ % _ % _ %% H %% |
|
146 |
(Lam (H1 : _) H2 : _. conjI % _ % _ %% H2 %% H1))"; |
|
147 |
{\out val prf = PThm (("HOL.impI", []), \dots, \dots, None) % None % None %%} |
|
148 |
{\out AbsP ("H", None, PThm (("HOL.conjE", []), \dots, \dots, None) %} |
|
149 |
{\out None % None % None %% PBound 0 %%} |
|
150 |
{\out AbsP ("H1", None, AbsP ("H2", None, \dots))) : Proofterm.proof} |
|
151 |
\end{ttbox} |
|
152 |
The statement to be established by this proof is |
|
153 |
\begin{ttbox} |
|
154 |
val t = term_of |
|
155 |
(read_cterm (sign_of Main.thy) ("A & B --> B & A", propT)); |
|
156 |
{\out val t = Const ("Trueprop", "bool => prop") $} |
|
157 |
{\out (Const ("op -->", "[bool, bool] => bool") $} |
|
158 |
{\out \dots $ \dots : Term.term} |
|
159 |
\end{ttbox} |
|
160 |
Using {\tt t} we can reconstruct the full proof |
|
161 |
\begin{ttbox} |
|
162 |
val prf' = Reconstruct.reconstruct_proof (sign_of Main.thy) t prf; |
|
163 |
{\out val prf' = PThm (("HOL.impI", []), \dots, \dots, Some []) %} |
|
164 |
{\out Some (Const ("op &", \dots) $ Free ("A", \dots) $ Free ("B", \dots)) %} |
|
165 |
{\out Some (Const ("op &", \dots) $ Free ("B", \dots) $ Free ("A", \dots)) %%} |
|
166 |
{\out AbsP ("H", Some (Const ("Trueprop", \dots) $ \dots), \dots)} |
|
167 |
{\out : Proofterm.proof} |
|
168 |
\end{ttbox} |
|
169 |
This proof can finally be turned into a theorem |
|
170 |
\begin{ttbox} |
|
171 |
val thm = ProofChecker.thm_of_proof Main.thy prf'; |
|
172 |
{\out val thm = "A & B --> B & A" : Thm.thm} |
|
173 |
\end{ttbox} |
|
174 |
||
175 |
\index{proof terms|)} |
|
176 |
\index{theorems|)} |
|
7871 | 177 |
|
5371 | 178 |
|
179 |
%%% Local Variables: |
|
180 |
%%% mode: latex |
|
181 |
%%% TeX-master: "ref" |
|
182 |
%%% End: |