author | haftmann |
Wed, 06 Oct 2010 13:48:12 +0200 | |
changeset 39929 | a62e01e9b22c |
parent 35001 | 31f8d9eaceff |
child 39885 | 6a3f7941c3a0 |
permissions | -rw-r--r-- |
30296 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Proof}% |
|
4 |
% |
|
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
\isacommand{theory}\isamarkupfalse% |
|
11 |
\ Proof\isanewline |
|
12 |
\isakeyword{imports}\ Base\isanewline |
|
13 |
\isakeyword{begin}% |
|
14 |
\endisatagtheory |
|
15 |
{\isafoldtheory}% |
|
16 |
% |
|
17 |
\isadelimtheory |
|
18 |
% |
|
19 |
\endisadelimtheory |
|
20 |
% |
|
21 |
\isamarkupchapter{Structured proofs% |
|
22 |
} |
|
23 |
\isamarkuptrue% |
|
24 |
% |
|
25 |
\isamarkupsection{Variables \label{sec:variables}% |
|
26 |
} |
|
27 |
\isamarkuptrue% |
|
28 |
% |
|
29 |
\begin{isamarkuptext}% |
|
30 |
Any variable that is not explicitly bound by \isa{{\isasymlambda}}-abstraction |
|
31 |
is considered as ``free''. Logically, free variables act like |
|
32 |
outermost universal quantification at the sequent level: \isa{A\isactrlisub {\isadigit{1}}{\isacharparenleft}x{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ A\isactrlisub n{\isacharparenleft}x{\isacharparenright}\ {\isasymturnstile}\ B{\isacharparenleft}x{\isacharparenright}} means that the result |
|
33 |
holds \emph{for all} values of \isa{x}. Free variables for |
|
34 |
terms (not types) can be fully internalized into the logic: \isa{{\isasymturnstile}\ B{\isacharparenleft}x{\isacharparenright}} and \isa{{\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ B{\isacharparenleft}x{\isacharparenright}} are interchangeable, provided |
|
35 |
that \isa{x} does not occur elsewhere in the context. |
|
36 |
Inspecting \isa{{\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ B{\isacharparenleft}x{\isacharparenright}} more closely, we see that inside the |
|
37 |
quantifier, \isa{x} is essentially ``arbitrary, but fixed'', |
|
38 |
while from outside it appears as a place-holder for instantiation |
|
39 |
(thanks to \isa{{\isasymAnd}} elimination). |
|
40 |
||
41 |
The Pure logic represents the idea of variables being either inside |
|
42 |
or outside the current scope by providing separate syntactic |
|
43 |
categories for \emph{fixed variables} (e.g.\ \isa{x}) vs.\ |
|
44 |
\emph{schematic variables} (e.g.\ \isa{{\isacharquery}x}). Incidently, a |
|
35001 | 45 |
universal result \isa{{\isasymturnstile}\ {\isasymAnd}x{\isachardot}\ B{\isacharparenleft}x{\isacharparenright}} has the HHF normal form \isa{{\isasymturnstile}\ B{\isacharparenleft}{\isacharquery}x{\isacharparenright}}, which represents its generality without requiring an |
46 |
explicit quantifier. The same principle works for type variables: |
|
47 |
\isa{{\isasymturnstile}\ B{\isacharparenleft}{\isacharquery}{\isasymalpha}{\isacharparenright}} represents the idea of ``\isa{{\isasymturnstile}\ {\isasymforall}{\isasymalpha}{\isachardot}\ B{\isacharparenleft}{\isasymalpha}{\isacharparenright}}'' |
|
48 |
without demanding a truly polymorphic framework. |
|
30296 | 49 |
|
50 |
\medskip Additional care is required to treat type variables in a |
|
51 |
way that facilitates type-inference. In principle, term variables |
|
52 |
depend on type variables, which means that type variables would have |
|
53 |
to be declared first. For example, a raw type-theoretic framework |
|
54 |
would demand the context to be constructed in stages as follows: |
|
55 |
\isa{{\isasymGamma}\ {\isacharequal}\ {\isasymalpha}{\isacharcolon}\ type{\isacharcomma}\ x{\isacharcolon}\ {\isasymalpha}{\isacharcomma}\ a{\isacharcolon}\ A{\isacharparenleft}x\isactrlisub {\isasymalpha}{\isacharparenright}}. |
|
56 |
||
57 |
We allow a slightly less formalistic mode of operation: term |
|
58 |
variables \isa{x} are fixed without specifying a type yet |
|
59 |
(essentially \emph{all} potential occurrences of some instance |
|
60 |
\isa{x\isactrlisub {\isasymtau}} are fixed); the first occurrence of \isa{x} |
|
61 |
within a specific term assigns its most general type, which is then |
|
62 |
maintained consistently in the context. The above example becomes |
|
63 |
\isa{{\isasymGamma}\ {\isacharequal}\ x{\isacharcolon}\ term{\isacharcomma}\ {\isasymalpha}{\isacharcolon}\ type{\isacharcomma}\ A{\isacharparenleft}x\isactrlisub {\isasymalpha}{\isacharparenright}}, where type \isa{{\isasymalpha}} is fixed \emph{after} term \isa{x}, and the constraint |
|
64 |
\isa{x\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}} is an implicit consequence of the occurrence of |
|
65 |
\isa{x\isactrlisub {\isasymalpha}} in the subsequent proposition. |
|
66 |
||
67 |
This twist of dependencies is also accommodated by the reverse |
|
68 |
operation of exporting results from a context: a type variable |
|
69 |
\isa{{\isasymalpha}} is considered fixed as long as it occurs in some fixed |
|
70 |
term variable of the context. For example, exporting \isa{x{\isacharcolon}\ term{\isacharcomma}\ {\isasymalpha}{\isacharcolon}\ type\ {\isasymturnstile}\ x\isactrlisub {\isasymalpha}\ {\isacharequal}\ x\isactrlisub {\isasymalpha}} produces in the first step |
|
71 |
\isa{x{\isacharcolon}\ term\ {\isasymturnstile}\ x\isactrlisub {\isasymalpha}\ {\isacharequal}\ x\isactrlisub {\isasymalpha}} for fixed \isa{{\isasymalpha}}, |
|
72 |
and only in the second step \isa{{\isasymturnstile}\ {\isacharquery}x\isactrlisub {\isacharquery}\isactrlisub {\isasymalpha}\ {\isacharequal}\ {\isacharquery}x\isactrlisub {\isacharquery}\isactrlisub {\isasymalpha}} for schematic \isa{{\isacharquery}x} and \isa{{\isacharquery}{\isasymalpha}}. |
|
73 |
||
74 |
\medskip The Isabelle/Isar proof context manages the gory details of |
|
75 |
term vs.\ type variables, with high-level principles for moving the |
|
76 |
frontier between fixed and schematic variables. |
|
77 |
||
78 |
The \isa{add{\isacharunderscore}fixes} operation explictly declares fixed |
|
79 |
variables; the \isa{declare{\isacharunderscore}term} operation absorbs a term into |
|
80 |
a context by fixing new type variables and adding syntactic |
|
81 |
constraints. |
|
82 |
||
83 |
The \isa{export} operation is able to perform the main work of |
|
84 |
generalizing term and type variables as sketched above, assuming |
|
85 |
that fixing variables and terms have been declared properly. |
|
86 |
||
87 |
There \isa{import} operation makes a generalized fact a genuine |
|
88 |
part of the context, by inventing fixed variables for the schematic |
|
89 |
ones. The effect can be reversed by using \isa{export} later, |
|
90 |
potentially with an extended context; the result is equivalent to |
|
91 |
the original modulo renaming of schematic variables. |
|
92 |
||
93 |
The \isa{focus} operation provides a variant of \isa{import} |
|
94 |
for nested propositions (with explicit quantification): \isa{{\isasymAnd}x\isactrlisub {\isadigit{1}}\ {\isasymdots}\ x\isactrlisub n{\isachardot}\ B{\isacharparenleft}x\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlisub n{\isacharparenright}} is |
|
95 |
decomposed by inventing fixed variables \isa{x\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ x\isactrlisub n} for the body.% |
|
96 |
\end{isamarkuptext}% |
|
97 |
\isamarkuptrue% |
|
98 |
% |
|
99 |
\isadelimmlref |
|
100 |
% |
|
101 |
\endisadelimmlref |
|
102 |
% |
|
103 |
\isatagmlref |
|
104 |
% |
|
105 |
\begin{isamarkuptext}% |
|
106 |
\begin{mldecls} |
|
107 |
\indexdef{}{ML}{Variable.add\_fixes}\verb|Variable.add_fixes: |\isasep\isanewline% |
|
108 |
\verb| string list -> Proof.context -> string list * Proof.context| \\ |
|
109 |
\indexdef{}{ML}{Variable.variant\_fixes}\verb|Variable.variant_fixes: |\isasep\isanewline% |
|
110 |
\verb| string list -> Proof.context -> string list * Proof.context| \\ |
|
111 |
\indexdef{}{ML}{Variable.declare\_term}\verb|Variable.declare_term: term -> Proof.context -> Proof.context| \\ |
|
112 |
\indexdef{}{ML}{Variable.declare\_constraints}\verb|Variable.declare_constraints: term -> Proof.context -> Proof.context| \\ |
|
113 |
\indexdef{}{ML}{Variable.export}\verb|Variable.export: Proof.context -> Proof.context -> thm list -> thm list| \\ |
|
114 |
\indexdef{}{ML}{Variable.polymorphic}\verb|Variable.polymorphic: Proof.context -> term list -> term list| \\ |
|
31794
71af1fd6a5e4
renamed Variable.import_thms to Variable.import (back again cf. ed7aa5a350ef -- Alice is no longer supported);
wenzelm
parents:
30296
diff
changeset
|
115 |
\indexdef{}{ML}{Variable.import}\verb|Variable.import: bool -> thm list -> Proof.context ->|\isasep\isanewline% |
32302 | 116 |
\verb| (((ctyp * ctyp) list * (cterm * cterm) list) * thm list) * Proof.context| \\ |
35001 | 117 |
\indexdef{}{ML}{Variable.focus}\verb|Variable.focus: cterm -> Proof.context ->|\isasep\isanewline% |
118 |
\verb| ((string * cterm) list * cterm) * Proof.context| \\ |
|
30296 | 119 |
\end{mldecls} |
120 |
||
121 |
\begin{description} |
|
122 |
||
123 |
\item \verb|Variable.add_fixes|~\isa{xs\ ctxt} fixes term |
|
124 |
variables \isa{xs}, returning the resulting internal names. By |
|
125 |
default, the internal representation coincides with the external |
|
126 |
one, which also means that the given variables must not be fixed |
|
127 |
already. There is a different policy within a local proof body: the |
|
128 |
given names are just hints for newly invented Skolem variables. |
|
129 |
||
130 |
\item \verb|Variable.variant_fixes| is similar to \verb|Variable.add_fixes|, but always produces fresh variants of the given |
|
131 |
names. |
|
132 |
||
133 |
\item \verb|Variable.declare_term|~\isa{t\ ctxt} declares term |
|
134 |
\isa{t} to belong to the context. This automatically fixes new |
|
135 |
type variables, but not term variables. Syntactic constraints for |
|
136 |
type and term variables are declared uniformly, though. |
|
137 |
||
138 |
\item \verb|Variable.declare_constraints|~\isa{t\ ctxt} declares |
|
139 |
syntactic constraints from term \isa{t}, without making it part |
|
140 |
of the context yet. |
|
141 |
||
142 |
\item \verb|Variable.export|~\isa{inner\ outer\ thms} generalizes |
|
143 |
fixed type and term variables in \isa{thms} according to the |
|
144 |
difference of the \isa{inner} and \isa{outer} context, |
|
145 |
following the principles sketched above. |
|
146 |
||
147 |
\item \verb|Variable.polymorphic|~\isa{ctxt\ ts} generalizes type |
|
148 |
variables in \isa{ts} as far as possible, even those occurring |
|
149 |
in fixed term variables. The default policy of type-inference is to |
|
150 |
fix newly introduced type variables, which is essentially reversed |
|
151 |
with \verb|Variable.polymorphic|: here the given terms are detached |
|
152 |
from the context as far as possible. |
|
153 |
||
31794
71af1fd6a5e4
renamed Variable.import_thms to Variable.import (back again cf. ed7aa5a350ef -- Alice is no longer supported);
wenzelm
parents:
30296
diff
changeset
|
154 |
\item \verb|Variable.import|~\isa{open\ thms\ ctxt} invents fixed |
30296 | 155 |
type and term variables for the schematic ones occurring in \isa{thms}. The \isa{open} flag indicates whether the fixed names |
156 |
should be accessible to the user, otherwise newly introduced names |
|
157 |
are marked as ``internal'' (\secref{sec:names}). |
|
158 |
||
159 |
\item \verb|Variable.focus|~\isa{B} decomposes the outermost \isa{{\isasymAnd}} prefix of proposition \isa{B}. |
|
160 |
||
161 |
\end{description}% |
|
162 |
\end{isamarkuptext}% |
|
163 |
\isamarkuptrue% |
|
164 |
% |
|
165 |
\endisatagmlref |
|
166 |
{\isafoldmlref}% |
|
167 |
% |
|
168 |
\isadelimmlref |
|
169 |
% |
|
170 |
\endisadelimmlref |
|
171 |
% |
|
35001 | 172 |
\isadelimmlex |
173 |
% |
|
174 |
\endisadelimmlex |
|
175 |
% |
|
176 |
\isatagmlex |
|
177 |
% |
|
178 |
\begin{isamarkuptext}% |
|
179 |
The following example (in theory \hyperlink{theory.Pure}{\mbox{\isa{Pure}}}) shows |
|
180 |
how to work with fixed term and type parameters work with |
|
181 |
type-inference.% |
|
182 |
\end{isamarkuptext}% |
|
183 |
\isamarkuptrue% |
|
184 |
% |
|
185 |
\endisatagmlex |
|
186 |
{\isafoldmlex}% |
|
187 |
% |
|
188 |
\isadelimmlex |
|
189 |
% |
|
190 |
\endisadelimmlex |
|
191 |
\isacommand{typedecl}\isamarkupfalse% |
|
192 |
\ foo\ \ % |
|
193 |
\isamarkupcmt{some basic type for testing purposes% |
|
194 |
} |
|
195 |
\isanewline |
|
196 |
% |
|
197 |
\isadelimML |
|
198 |
\isanewline |
|
199 |
% |
|
200 |
\endisadelimML |
|
201 |
% |
|
202 |
\isatagML |
|
203 |
\isacommand{ML}\isamarkupfalse% |
|
204 |
\ {\isacharverbatimopen}\isanewline |
|
205 |
\ \ {\isacharparenleft}{\isacharasterisk}static\ compile{\isacharminus}time\ context\ {\isacharminus}{\isacharminus}\ for\ testing\ only{\isacharasterisk}{\isacharparenright}\isanewline |
|
206 |
\ \ val\ ctxt{\isadigit{0}}\ {\isacharequal}\ % |
|
207 |
\isaantiq |
|
208 |
context% |
|
209 |
\endisaantiq |
|
210 |
{\isacharsemicolon}\isanewline |
|
211 |
\isanewline |
|
212 |
\ \ {\isacharparenleft}{\isacharasterisk}locally\ fixed\ parameters\ {\isacharminus}{\isacharminus}\ no\ type\ assignment\ yet{\isacharasterisk}{\isacharparenright}\isanewline |
|
213 |
\ \ val\ {\isacharparenleft}{\isacharbrackleft}x{\isacharcomma}\ y{\isacharbrackright}{\isacharcomma}\ ctxt{\isadigit{1}}{\isacharparenright}\ {\isacharequal}\ ctxt{\isadigit{0}}\ {\isacharbar}{\isachargreater}\ Variable{\isachardot}add{\isacharunderscore}fixes\ {\isacharbrackleft}{\isachardoublequote}x{\isachardoublequote}{\isacharcomma}\ {\isachardoublequote}y{\isachardoublequote}{\isacharbrackright}{\isacharsemicolon}\isanewline |
|
214 |
\isanewline |
|
215 |
\ \ {\isacharparenleft}{\isacharasterisk}t{\isadigit{1}}{\isacharcolon}\ most\ general\ fixed\ type{\isacharsemicolon}\ t{\isadigit{1}}{\isacharprime}{\isacharcolon}\ most\ general\ arbitrary\ type{\isacharasterisk}{\isacharparenright}\isanewline |
|
216 |
\ \ val\ t{\isadigit{1}}\ {\isacharequal}\ Syntax{\isachardot}read{\isacharunderscore}term\ ctxt{\isadigit{1}}\ {\isachardoublequote}x{\isachardoublequote}{\isacharsemicolon}\isanewline |
|
217 |
\ \ val\ t{\isadigit{1}}{\isacharprime}\ {\isacharequal}\ singleton\ {\isacharparenleft}Variable{\isachardot}polymorphic\ ctxt{\isadigit{1}}{\isacharparenright}\ t{\isadigit{1}}{\isacharsemicolon}\isanewline |
|
218 |
\isanewline |
|
219 |
\ \ {\isacharparenleft}{\isacharasterisk}term\ u\ enforces\ specific\ type\ assignment{\isacharasterisk}{\isacharparenright}\isanewline |
|
220 |
\ \ val\ u\ {\isacharequal}\ Syntax{\isachardot}read{\isacharunderscore}term\ ctxt{\isadigit{1}}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcolon}{\isacharcolon}foo{\isacharparenright}\ {\isasymequiv}\ y{\isachardoublequote}{\isacharsemicolon}\isanewline |
|
221 |
\isanewline |
|
222 |
\ \ {\isacharparenleft}{\isacharasterisk}official\ declaration\ of\ u\ {\isacharminus}{\isacharminus}\ propagates\ constraints\ etc{\isachardot}{\isacharasterisk}{\isacharparenright}\isanewline |
|
223 |
\ \ val\ ctxt{\isadigit{2}}\ {\isacharequal}\ ctxt{\isadigit{1}}\ {\isacharbar}{\isachargreater}\ Variable{\isachardot}declare{\isacharunderscore}term\ u{\isacharsemicolon}\isanewline |
|
224 |
\ \ val\ t{\isadigit{2}}\ {\isacharequal}\ Syntax{\isachardot}read{\isacharunderscore}term\ ctxt{\isadigit{2}}\ {\isachardoublequote}x{\isachardoublequote}{\isacharsemicolon}\ \ {\isacharparenleft}{\isacharasterisk}x{\isacharcolon}{\isacharcolon}foo\ is\ enforced{\isacharasterisk}{\isacharparenright}\isanewline |
|
225 |
{\isacharverbatimclose}% |
|
226 |
\endisatagML |
|
227 |
{\isafoldML}% |
|
228 |
% |
|
229 |
\isadelimML |
|
230 |
% |
|
231 |
\endisadelimML |
|
232 |
% |
|
233 |
\begin{isamarkuptext}% |
|
234 |
In the above example, the starting context had been derived |
|
235 |
from the toplevel theory, which means that fixed variables are |
|
236 |
internalized literally: \verb|x| is mapped again to |
|
237 |
\verb|x|, and attempting to fix it again in the subsequent |
|
238 |
context is an error. Alternatively, fixed parameters can be renamed |
|
239 |
explicitly as follows:% |
|
240 |
\end{isamarkuptext}% |
|
241 |
\isamarkuptrue% |
|
242 |
% |
|
243 |
\isadelimML |
|
244 |
% |
|
245 |
\endisadelimML |
|
246 |
% |
|
247 |
\isatagML |
|
248 |
\isacommand{ML}\isamarkupfalse% |
|
249 |
\ {\isacharverbatimopen}\isanewline |
|
250 |
\ \ val\ ctxt{\isadigit{0}}\ {\isacharequal}\ % |
|
251 |
\isaantiq |
|
252 |
context% |
|
253 |
\endisaantiq |
|
254 |
{\isacharsemicolon}\isanewline |
|
255 |
\ \ val\ {\isacharparenleft}{\isacharbrackleft}x{\isadigit{1}}{\isacharcomma}\ x{\isadigit{2}}{\isacharcomma}\ x{\isadigit{3}}{\isacharbrackright}{\isacharcomma}\ ctxt{\isadigit{1}}{\isacharparenright}\ {\isacharequal}\isanewline |
|
256 |
\ \ \ \ ctxt{\isadigit{0}}\ {\isacharbar}{\isachargreater}\ Variable{\isachardot}variant{\isacharunderscore}fixes\ {\isacharbrackleft}{\isachardoublequote}x{\isachardoublequote}{\isacharcomma}\ {\isachardoublequote}x{\isachardoublequote}{\isacharcomma}\ {\isachardoublequote}x{\isachardoublequote}{\isacharbrackright}{\isacharsemicolon}\isanewline |
|
257 |
{\isacharverbatimclose}% |
|
258 |
\endisatagML |
|
259 |
{\isafoldML}% |
|
260 |
% |
|
261 |
\isadelimML |
|
262 |
% |
|
263 |
\endisadelimML |
|
264 |
% |
|
265 |
\begin{isamarkuptext}% |
|
266 |
\noindent Subsequent ML code can now work with the invented |
|
267 |
names of \verb|x1|, \verb|x2|, \verb|x3|, without |
|
268 |
depending on the details on the system policy for introducing these |
|
269 |
variants. Recall that within a proof body the system always invents |
|
270 |
fresh ``skolem constants'', e.g.\ as follows:% |
|
271 |
\end{isamarkuptext}% |
|
272 |
\isamarkuptrue% |
|
273 |
\isacommand{lemma}\isamarkupfalse% |
|
274 |
\ {\isachardoublequoteopen}PROP\ XXX{\isachardoublequoteclose}\isanewline |
|
275 |
% |
|
276 |
\isadelimproof |
|
277 |
% |
|
278 |
\endisadelimproof |
|
279 |
% |
|
280 |
\isatagproof |
|
281 |
\isacommand{proof}\isamarkupfalse% |
|
282 |
\ {\isacharminus}% |
|
283 |
\endisatagproof |
|
284 |
{\isafoldproof}% |
|
285 |
% |
|
286 |
\isadelimproof |
|
287 |
\isanewline |
|
288 |
% |
|
289 |
\endisadelimproof |
|
290 |
% |
|
291 |
\isadelimML |
|
292 |
\ \ % |
|
293 |
\endisadelimML |
|
294 |
% |
|
295 |
\isatagML |
|
296 |
\isacommand{ML{\isacharunderscore}prf}\isamarkupfalse% |
|
297 |
\ {\isacharverbatimopen}\isanewline |
|
298 |
\ \ \ \ val\ ctxt{\isadigit{0}}\ {\isacharequal}\ % |
|
299 |
\isaantiq |
|
300 |
context% |
|
301 |
\endisaantiq |
|
302 |
{\isacharsemicolon}\isanewline |
|
303 |
\isanewline |
|
304 |
\ \ \ \ val\ {\isacharparenleft}{\isacharbrackleft}x{\isadigit{1}}{\isacharbrackright}{\isacharcomma}\ ctxt{\isadigit{1}}{\isacharparenright}\ {\isacharequal}\ ctxt{\isadigit{0}}\ {\isacharbar}{\isachargreater}\ Variable{\isachardot}add{\isacharunderscore}fixes\ {\isacharbrackleft}{\isachardoublequote}x{\isachardoublequote}{\isacharbrackright}{\isacharsemicolon}\isanewline |
|
305 |
\ \ \ \ val\ {\isacharparenleft}{\isacharbrackleft}x{\isadigit{2}}{\isacharbrackright}{\isacharcomma}\ ctxt{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ ctxt{\isadigit{1}}\ {\isacharbar}{\isachargreater}\ Variable{\isachardot}add{\isacharunderscore}fixes\ {\isacharbrackleft}{\isachardoublequote}x{\isachardoublequote}{\isacharbrackright}{\isacharsemicolon}\isanewline |
|
306 |
\ \ \ \ val\ {\isacharparenleft}{\isacharbrackleft}x{\isadigit{3}}{\isacharbrackright}{\isacharcomma}\ ctxt{\isadigit{3}}{\isacharparenright}\ {\isacharequal}\ ctxt{\isadigit{2}}\ {\isacharbar}{\isachargreater}\ Variable{\isachardot}add{\isacharunderscore}fixes\ {\isacharbrackleft}{\isachardoublequote}x{\isachardoublequote}{\isacharbrackright}{\isacharsemicolon}\isanewline |
|
307 |
\isanewline |
|
308 |
\ \ \ \ val\ {\isacharparenleft}{\isacharbrackleft}y{\isadigit{1}}{\isacharcomma}\ y{\isadigit{2}}{\isacharbrackright}{\isacharcomma}\ ctxt{\isadigit{4}}{\isacharparenright}\ {\isacharequal}\isanewline |
|
309 |
\ \ \ \ \ \ ctxt{\isadigit{3}}\ {\isacharbar}{\isachargreater}\ Variable{\isachardot}variant{\isacharunderscore}fixes\ {\isacharbrackleft}{\isachardoublequote}y{\isachardoublequote}{\isacharcomma}\ {\isachardoublequote}y{\isachardoublequote}{\isacharbrackright}{\isacharsemicolon}\isanewline |
|
310 |
\ \ {\isacharverbatimclose}\isanewline |
|
311 |
\ \ \isacommand{oops}\isamarkupfalse% |
|
312 |
% |
|
313 |
\endisatagML |
|
314 |
{\isafoldML}% |
|
315 |
% |
|
316 |
\isadelimML |
|
317 |
% |
|
318 |
\endisadelimML |
|
319 |
% |
|
320 |
\begin{isamarkuptext}% |
|
321 |
\noindent In this situation \verb|Variable.add_fixes| and \verb|Variable.variant_fixes| are very similar, but identical name |
|
322 |
proposals given in a row are only accepted by the second version.% |
|
323 |
\end{isamarkuptext}% |
|
324 |
\isamarkuptrue% |
|
325 |
% |
|
30296 | 326 |
\isamarkupsection{Assumptions \label{sec:assumptions}% |
327 |
} |
|
328 |
\isamarkuptrue% |
|
329 |
% |
|
330 |
\begin{isamarkuptext}% |
|
331 |
An \emph{assumption} is a proposition that it is postulated in the |
|
332 |
current context. Local conclusions may use assumptions as |
|
333 |
additional facts, but this imposes implicit hypotheses that weaken |
|
334 |
the overall statement. |
|
335 |
||
336 |
Assumptions are restricted to fixed non-schematic statements, i.e.\ |
|
337 |
all generality needs to be expressed by explicit quantifiers. |
|
338 |
Nevertheless, the result will be in HHF normal form with outermost |
|
339 |
quantifiers stripped. For example, by assuming \isa{{\isasymAnd}x\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}{\isachardot}\ P\ x} we get \isa{{\isasymAnd}x\ {\isacharcolon}{\isacharcolon}\ {\isasymalpha}{\isachardot}\ P\ x\ {\isasymturnstile}\ P\ {\isacharquery}x} for schematic \isa{{\isacharquery}x} |
|
340 |
of fixed type \isa{{\isasymalpha}}. Local derivations accumulate more and |
|
341 |
more explicit references to hypotheses: \isa{A\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ A\isactrlisub n\ {\isasymturnstile}\ B} where \isa{A\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ A\isactrlisub n} needs to |
|
342 |
be covered by the assumptions of the current context. |
|
343 |
||
344 |
\medskip The \isa{add{\isacharunderscore}assms} operation augments the context by |
|
345 |
local assumptions, which are parameterized by an arbitrary \isa{export} rule (see below). |
|
346 |
||
347 |
The \isa{export} operation moves facts from a (larger) inner |
|
348 |
context into a (smaller) outer context, by discharging the |
|
349 |
difference of the assumptions as specified by the associated export |
|
350 |
rules. Note that the discharged portion is determined by the |
|
35001 | 351 |
difference of contexts, not the facts being exported! There is a |
30296 | 352 |
separate flag to indicate a goal context, where the result is meant |
353 |
to refine an enclosing sub-goal of a structured proof state. |
|
354 |
||
355 |
\medskip The most basic export rule discharges assumptions directly |
|
356 |
by means of the \isa{{\isasymLongrightarrow}} introduction rule: |
|
357 |
\[ |
|
35001 | 358 |
\infer[(\isa{{\isasymLongrightarrow}{\isasymdash}intro})]{\isa{{\isasymGamma}\ {\isacharminus}\ A\ {\isasymturnstile}\ A\ {\isasymLongrightarrow}\ B}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B}} |
30296 | 359 |
\] |
360 |
||
361 |
The variant for goal refinements marks the newly introduced |
|
362 |
premises, which causes the canonical Isar goal refinement scheme to |
|
363 |
enforce unification with local premises within the goal: |
|
364 |
\[ |
|
35001 | 365 |
\infer[(\isa{{\isacharhash}{\isasymLongrightarrow}{\isasymdash}intro})]{\isa{{\isasymGamma}\ {\isacharminus}\ A\ {\isasymturnstile}\ {\isacharhash}A\ {\isasymLongrightarrow}\ B}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B}} |
30296 | 366 |
\] |
367 |
||
368 |
\medskip Alternative versions of assumptions may perform arbitrary |
|
369 |
transformations on export, as long as the corresponding portion of |
|
370 |
hypotheses is removed from the given facts. For example, a local |
|
371 |
definition works by fixing \isa{x} and assuming \isa{x\ {\isasymequiv}\ t}, |
|
372 |
with the following export rule to reverse the effect: |
|
373 |
\[ |
|
35001 | 374 |
\infer[(\isa{{\isasymequiv}{\isasymdash}expand})]{\isa{{\isasymGamma}\ {\isacharminus}\ {\isacharparenleft}x\ {\isasymequiv}\ t{\isacharparenright}\ {\isasymturnstile}\ B\ t}}{\isa{{\isasymGamma}\ {\isasymturnstile}\ B\ x}} |
30296 | 375 |
\] |
376 |
This works, because the assumption \isa{x\ {\isasymequiv}\ t} was introduced in |
|
377 |
a context with \isa{x} being fresh, so \isa{x} does not |
|
378 |
occur in \isa{{\isasymGamma}} here.% |
|
379 |
\end{isamarkuptext}% |
|
380 |
\isamarkuptrue% |
|
381 |
% |
|
382 |
\isadelimmlref |
|
383 |
% |
|
384 |
\endisadelimmlref |
|
385 |
% |
|
386 |
\isatagmlref |
|
387 |
% |
|
388 |
\begin{isamarkuptext}% |
|
389 |
\begin{mldecls} |
|
390 |
\indexdef{}{ML type}{Assumption.export}\verb|type Assumption.export| \\ |
|
391 |
\indexdef{}{ML}{Assumption.assume}\verb|Assumption.assume: cterm -> thm| \\ |
|
392 |
\indexdef{}{ML}{Assumption.add\_assms}\verb|Assumption.add_assms: Assumption.export ->|\isasep\isanewline% |
|
393 |
\verb| cterm list -> Proof.context -> thm list * Proof.context| \\ |
|
394 |
\indexdef{}{ML}{Assumption.add\_assumes}\verb|Assumption.add_assumes: |\isasep\isanewline% |
|
395 |
\verb| cterm list -> Proof.context -> thm list * Proof.context| \\ |
|
396 |
\indexdef{}{ML}{Assumption.export}\verb|Assumption.export: bool -> Proof.context -> Proof.context -> thm -> thm| \\ |
|
397 |
\end{mldecls} |
|
398 |
||
399 |
\begin{description} |
|
400 |
||
401 |
\item \verb|Assumption.export| represents arbitrary export |
|
402 |
rules, which is any function of type \verb|bool -> cterm list -> thm -> thm|, |
|
403 |
where the \verb|bool| indicates goal mode, and the \verb|cterm list| the collection of assumptions to be discharged |
|
404 |
simultaneously. |
|
405 |
||
35001 | 406 |
\item \verb|Assumption.assume|~\isa{A} turns proposition \isa{A} into a primitive assumption \isa{A\ {\isasymturnstile}\ A{\isacharprime}}, where the |
407 |
conclusion \isa{A{\isacharprime}} is in HHF normal form. |
|
30296 | 408 |
|
409 |
\item \verb|Assumption.add_assms|~\isa{r\ As} augments the context |
|
410 |
by assumptions \isa{As} with export rule \isa{r}. The |
|
411 |
resulting facts are hypothetical theorems as produced by the raw |
|
412 |
\verb|Assumption.assume|. |
|
413 |
||
414 |
\item \verb|Assumption.add_assumes|~\isa{As} is a special case of |
|
35001 | 415 |
\verb|Assumption.add_assms| where the export rule performs \isa{{\isasymLongrightarrow}{\isasymdash}intro} or \isa{{\isacharhash}{\isasymLongrightarrow}{\isasymdash}intro}, depending on goal |
416 |
mode. |
|
30296 | 417 |
|
418 |
\item \verb|Assumption.export|~\isa{is{\isacharunderscore}goal\ inner\ outer\ thm} |
|
419 |
exports result \isa{thm} from the the \isa{inner} context |
|
420 |
back into the \isa{outer} one; \isa{is{\isacharunderscore}goal\ {\isacharequal}\ true} means |
|
421 |
this is a goal context. The result is in HHF normal form. Note |
|
422 |
that \verb|ProofContext.export| combines \verb|Variable.export| |
|
423 |
and \verb|Assumption.export| in the canonical way. |
|
424 |
||
425 |
\end{description}% |
|
426 |
\end{isamarkuptext}% |
|
427 |
\isamarkuptrue% |
|
428 |
% |
|
429 |
\endisatagmlref |
|
430 |
{\isafoldmlref}% |
|
431 |
% |
|
432 |
\isadelimmlref |
|
433 |
% |
|
434 |
\endisadelimmlref |
|
435 |
% |
|
35001 | 436 |
\isadelimmlex |
437 |
% |
|
438 |
\endisadelimmlex |
|
439 |
% |
|
440 |
\isatagmlex |
|
441 |
% |
|
442 |
\begin{isamarkuptext}% |
|
443 |
The following example demonstrates how rules can be |
|
444 |
derived by building up a context of assumptions first, and exporting |
|
445 |
some local fact afterwards. We refer to \hyperlink{theory.Pure}{\mbox{\isa{Pure}}} equality |
|
446 |
here for testing purposes.% |
|
447 |
\end{isamarkuptext}% |
|
448 |
\isamarkuptrue% |
|
449 |
% |
|
450 |
\endisatagmlex |
|
451 |
{\isafoldmlex}% |
|
452 |
% |
|
453 |
\isadelimmlex |
|
454 |
% |
|
455 |
\endisadelimmlex |
|
456 |
% |
|
457 |
\isadelimML |
|
458 |
% |
|
459 |
\endisadelimML |
|
460 |
% |
|
461 |
\isatagML |
|
462 |
\isacommand{ML}\isamarkupfalse% |
|
463 |
\ {\isacharverbatimopen}\isanewline |
|
464 |
\ \ {\isacharparenleft}{\isacharasterisk}static\ compile{\isacharminus}time\ context\ {\isacharminus}{\isacharminus}\ for\ testing\ only{\isacharasterisk}{\isacharparenright}\isanewline |
|
465 |
\ \ val\ ctxt{\isadigit{0}}\ {\isacharequal}\ % |
|
466 |
\isaantiq |
|
467 |
context% |
|
468 |
\endisaantiq |
|
469 |
{\isacharsemicolon}\isanewline |
|
470 |
\isanewline |
|
471 |
\ \ val\ {\isacharparenleft}{\isacharbrackleft}eq{\isacharbrackright}{\isacharcomma}\ ctxt{\isadigit{1}}{\isacharparenright}\ {\isacharequal}\isanewline |
|
472 |
\ \ \ \ ctxt{\isadigit{0}}\ {\isacharbar}{\isachargreater}\ Assumption{\isachardot}add{\isacharunderscore}assumes\ {\isacharbrackleft}% |
|
473 |
\isaantiq |
|
474 |
cprop\ {\isachardoublequote}x\ {\isasymequiv}\ y{\isachardoublequote}% |
|
475 |
\endisaantiq |
|
476 |
{\isacharbrackright}{\isacharsemicolon}\isanewline |
|
477 |
\ \ val\ eq{\isacharprime}\ {\isacharequal}\ Thm{\isachardot}symmetric\ eq{\isacharsemicolon}\isanewline |
|
478 |
\isanewline |
|
479 |
\ \ {\isacharparenleft}{\isacharasterisk}back\ to\ original\ context\ {\isacharminus}{\isacharminus}\ discharges\ assumption{\isacharasterisk}{\isacharparenright}\isanewline |
|
480 |
\ \ val\ r\ {\isacharequal}\ Assumption{\isachardot}export\ false\ ctxt{\isadigit{1}}\ ctxt{\isadigit{0}}\ eq{\isacharprime}{\isacharsemicolon}\isanewline |
|
481 |
{\isacharverbatimclose}% |
|
482 |
\endisatagML |
|
483 |
{\isafoldML}% |
|
484 |
% |
|
485 |
\isadelimML |
|
486 |
% |
|
487 |
\endisadelimML |
|
488 |
% |
|
489 |
\begin{isamarkuptext}% |
|
490 |
\noindent Note that the variables of the resulting rule are |
|
491 |
not generalized. This would have required to fix them properly in |
|
492 |
the context beforehand, and export wrt.\ variables afterwards (cf.\ |
|
493 |
\verb|Variable.export| or the combined \verb|ProofContext.export|).% |
|
494 |
\end{isamarkuptext}% |
|
495 |
\isamarkuptrue% |
|
496 |
% |
|
497 |
\isamarkupsection{Structured goals and results \label{sec:struct-goals}% |
|
30296 | 498 |
} |
499 |
\isamarkuptrue% |
|
500 |
% |
|
501 |
\begin{isamarkuptext}% |
|
502 |
Local results are established by monotonic reasoning from facts |
|
503 |
within a context. This allows common combinations of theorems, |
|
504 |
e.g.\ via \isa{{\isasymAnd}{\isacharslash}{\isasymLongrightarrow}} elimination, resolution rules, or equational |
|
505 |
reasoning, see \secref{sec:thms}. Unaccounted context manipulations |
|
506 |
should be avoided, notably raw \isa{{\isasymAnd}{\isacharslash}{\isasymLongrightarrow}} introduction or ad-hoc |
|
507 |
references to free variables or assumptions not present in the proof |
|
508 |
context. |
|
509 |
||
510 |
\medskip The \isa{SUBPROOF} combinator allows to structure a |
|
511 |
tactical proof recursively by decomposing a selected sub-goal: |
|
512 |
\isa{{\isacharparenleft}{\isasymAnd}x{\isachardot}\ A{\isacharparenleft}x{\isacharparenright}\ {\isasymLongrightarrow}\ B{\isacharparenleft}x{\isacharparenright}{\isacharparenright}\ {\isasymLongrightarrow}\ {\isasymdots}} is turned into \isa{B{\isacharparenleft}x{\isacharparenright}\ {\isasymLongrightarrow}\ {\isasymdots}} |
|
513 |
after fixing \isa{x} and assuming \isa{A{\isacharparenleft}x{\isacharparenright}}. This means |
|
514 |
the tactic needs to solve the conclusion, but may use the premise as |
|
515 |
a local fact, for locally fixed variables. |
|
516 |
||
35001 | 517 |
The family of \isa{FOCUS} combinators is similar to \isa{SUBPROOF}, but allows to retain schematic variables and pending |
518 |
subgoals in the resulting goal state. |
|
519 |
||
30296 | 520 |
The \isa{prove} operation provides an interface for structured |
521 |
backwards reasoning under program control, with some explicit sanity |
|
522 |
checks of the result. The goal context can be augmented by |
|
523 |
additional fixed variables (cf.\ \secref{sec:variables}) and |
|
524 |
assumptions (cf.\ \secref{sec:assumptions}), which will be available |
|
525 |
as local facts during the proof and discharged into implications in |
|
526 |
the result. Type and term variables are generalized as usual, |
|
527 |
according to the context. |
|
528 |
||
529 |
The \isa{obtain} operation produces results by eliminating |
|
530 |
existing facts by means of a given tactic. This acts like a dual |
|
531 |
conclusion: the proof demonstrates that the context may be augmented |
|
35001 | 532 |
by parameters and assumptions, without affecting any conclusions |
533 |
that do not mention these parameters. See also |
|
30296 | 534 |
\cite{isabelle-isar-ref} for the user-level \isa{{\isasymOBTAIN}} and |
535 |
\isa{{\isasymGUESS}} elements. Final results, which may not refer to |
|
536 |
the parameters in the conclusion, need to exported explicitly into |
|
537 |
the original context.% |
|
538 |
\end{isamarkuptext}% |
|
539 |
\isamarkuptrue% |
|
540 |
% |
|
541 |
\isadelimmlref |
|
542 |
% |
|
543 |
\endisadelimmlref |
|
544 |
% |
|
545 |
\isatagmlref |
|
546 |
% |
|
547 |
\begin{isamarkuptext}% |
|
548 |
\begin{mldecls} |
|
32201
3689b647356d
updated Variable.focus, SUBPROOF, Obtain.result, Goal.finish;
wenzelm
parents:
31794
diff
changeset
|
549 |
\indexdef{}{ML}{SUBPROOF}\verb|SUBPROOF: (Subgoal.focus -> tactic) -> Proof.context -> int -> tactic| \\ |
35001 | 550 |
\indexdef{}{ML}{Subgoal.FOCUS}\verb|Subgoal.FOCUS: (Subgoal.focus -> tactic) -> Proof.context -> int -> tactic| \\ |
551 |
\indexdef{}{ML}{Subgoal.FOCUS\_PREMS}\verb|Subgoal.FOCUS_PREMS: (Subgoal.focus -> tactic) -> Proof.context -> int -> tactic| \\ |
|
552 |
\indexdef{}{ML}{Subgoal.FOCUS\_PARAMS}\verb|Subgoal.FOCUS_PARAMS: (Subgoal.focus -> tactic) -> Proof.context -> int -> tactic| \\ |
|
30296 | 553 |
\end{mldecls} |
35001 | 554 |
|
30296 | 555 |
\begin{mldecls} |
556 |
\indexdef{}{ML}{Goal.prove}\verb|Goal.prove: Proof.context -> string list -> term list -> term ->|\isasep\isanewline% |
|
557 |
\verb| ({prems: thm list, context: Proof.context} -> tactic) -> thm| \\ |
|
558 |
\indexdef{}{ML}{Goal.prove\_multi}\verb|Goal.prove_multi: Proof.context -> string list -> term list -> term list ->|\isasep\isanewline% |
|
559 |
\verb| ({prems: thm list, context: Proof.context} -> tactic) -> thm list| \\ |
|
560 |
\end{mldecls} |
|
561 |
\begin{mldecls} |
|
562 |
\indexdef{}{ML}{Obtain.result}\verb|Obtain.result: (Proof.context -> tactic) ->|\isasep\isanewline% |
|
32201
3689b647356d
updated Variable.focus, SUBPROOF, Obtain.result, Goal.finish;
wenzelm
parents:
31794
diff
changeset
|
563 |
\verb| thm list -> Proof.context -> ((string * cterm) list * thm list) * Proof.context| \\ |
30296 | 564 |
\end{mldecls} |
565 |
||
566 |
\begin{description} |
|
567 |
||
568 |
\item \verb|SUBPROOF|~\isa{tac\ ctxt\ i} decomposes the structure |
|
569 |
of the specified sub-goal, producing an extended context and a |
|
570 |
reduced goal, which needs to be solved by the given tactic. All |
|
571 |
schematic parameters of the goal are imported into the context as |
|
572 |
fixed ones, which may not be instantiated in the sub-proof. |
|
573 |
||
35001 | 574 |
\item \verb|Subgoal.FOCUS|, \verb|Subgoal.FOCUS_PREMS|, and \verb|Subgoal.FOCUS_PARAMS| are similar to \verb|SUBPROOF|, but are |
575 |
slightly more flexible: only the specified parts of the subgoal are |
|
576 |
imported into the context, and the body tactic may introduce new |
|
577 |
subgoals and schematic variables. |
|
578 |
||
30296 | 579 |
\item \verb|Goal.prove|~\isa{ctxt\ xs\ As\ C\ tac} states goal \isa{C} in the context augmented by fixed variables \isa{xs} and |
580 |
assumptions \isa{As}, and applies tactic \isa{tac} to solve |
|
581 |
it. The latter may depend on the local assumptions being presented |
|
582 |
as facts. The result is in HHF normal form. |
|
583 |
||
584 |
\item \verb|Goal.prove_multi| is simular to \verb|Goal.prove|, but |
|
585 |
states several conclusions simultaneously. The goal is encoded by |
|
586 |
means of Pure conjunction; \verb|Goal.conjunction_tac| will turn this |
|
587 |
into a collection of individual subgoals. |
|
588 |
||
589 |
\item \verb|Obtain.result|~\isa{tac\ thms\ ctxt} eliminates the |
|
590 |
given facts using a tactic, which results in additional fixed |
|
591 |
variables and assumptions in the context. Final results need to be |
|
592 |
exported explicitly. |
|
593 |
||
594 |
\end{description}% |
|
595 |
\end{isamarkuptext}% |
|
596 |
\isamarkuptrue% |
|
597 |
% |
|
598 |
\endisatagmlref |
|
599 |
{\isafoldmlref}% |
|
600 |
% |
|
601 |
\isadelimmlref |
|
602 |
% |
|
603 |
\endisadelimmlref |
|
604 |
% |
|
605 |
\isadelimtheory |
|
606 |
% |
|
607 |
\endisadelimtheory |
|
608 |
% |
|
609 |
\isatagtheory |
|
610 |
\isacommand{end}\isamarkupfalse% |
|
611 |
% |
|
612 |
\endisatagtheory |
|
613 |
{\isafoldtheory}% |
|
614 |
% |
|
615 |
\isadelimtheory |
|
616 |
% |
|
617 |
\endisadelimtheory |
|
618 |
\isanewline |
|
619 |
\end{isabellebody}% |
|
620 |
%%% Local Variables: |
|
621 |
%%% mode: latex |
|
622 |
%%% TeX-master: "root" |
|
623 |
%%% End: |