143 "\<And>"} prefix of proposition @{text "B"}. |
143 "\<And>"} prefix of proposition @{text "B"}. |
144 |
144 |
145 \end{description} |
145 \end{description} |
146 *} |
146 *} |
147 |
147 |
|
148 text %mlex {* The following example (in theory @{theory Pure}) shows |
|
149 how to work with fixed term and type parameters work with |
|
150 type-inference. |
|
151 *} |
|
152 |
|
153 typedecl foo -- {* some basic type for testing purposes *} |
|
154 |
|
155 ML {* |
|
156 (*static compile-time context -- for testing only*) |
|
157 val ctxt0 = @{context}; |
|
158 |
|
159 (*locally fixed parameters -- no type assignment yet*) |
|
160 val ([x, y], ctxt1) = ctxt0 |> Variable.add_fixes ["x", "y"]; |
|
161 |
|
162 (*t1: most general fixed type; t1': most general arbitrary type*) |
|
163 val t1 = Syntax.read_term ctxt1 "x"; |
|
164 val t1' = singleton (Variable.polymorphic ctxt1) t1; |
|
165 |
|
166 (*term u enforces specific type assignment*) |
|
167 val u = Syntax.read_term ctxt1 "(x::foo) \<equiv> y"; |
|
168 |
|
169 (*official declaration of u -- propagates constraints etc.*) |
|
170 val ctxt2 = ctxt1 |> Variable.declare_term u; |
|
171 val t2 = Syntax.read_term ctxt2 "x"; (*x::foo is enforced*) |
|
172 *} |
|
173 |
|
174 text {* In the above example, the starting context had been derived |
|
175 from the toplevel theory, which means that fixed variables are |
|
176 internalized literally: @{verbatim "x"} is mapped again to |
|
177 @{verbatim "x"}, and attempting to fix it again in the subsequent |
|
178 context is an error. Alternatively, fixed parameters can be renamed |
|
179 explicitly as follows: |
|
180 *} |
|
181 |
|
182 ML {* |
|
183 val ctxt0 = @{context}; |
|
184 val ([x1, x2, x3], ctxt1) = |
|
185 ctxt0 |> Variable.variant_fixes ["x", "x", "x"]; |
|
186 *} |
|
187 |
|
188 text {* \noindent Subsequent ML code can now work with the invented |
|
189 names of @{verbatim x1}, @{verbatim x2}, @{verbatim x3}, without |
|
190 depending on the details on the system policy for introducing these |
|
191 variants. Recall that within a proof body the system always invents |
|
192 fresh ``skolem constants'', e.g.\ as follows: |
|
193 *} |
|
194 |
|
195 lemma "PROP XXX" |
|
196 proof - |
|
197 ML_prf %"ML" {* |
|
198 val ctxt0 = @{context}; |
|
199 |
|
200 val ([x1], ctxt1) = ctxt0 |> Variable.add_fixes ["x"]; |
|
201 val ([x2], ctxt2) = ctxt1 |> Variable.add_fixes ["x"]; |
|
202 val ([x3], ctxt3) = ctxt2 |> Variable.add_fixes ["x"]; |
|
203 |
|
204 val ([y1, y2], ctxt4) = |
|
205 ctxt3 |> Variable.variant_fixes ["y", "y"]; |
|
206 *} |
|
207 oops |
|
208 |
|
209 text {* \noindent In this situation @{ML Variable.add_fixes} and @{ML |
|
210 Variable.variant_fixes} are very similar, but identical name |
|
211 proposals given in a row are only accepted by the second version. |
|
212 *} |
|
213 |
148 |
214 |
149 section {* Assumptions \label{sec:assumptions} *} |
215 section {* Assumptions \label{sec:assumptions} *} |
150 |
216 |
151 text {* |
217 text {* |
152 An \emph{assumption} is a proposition that it is postulated in the |
218 An \emph{assumption} is a proposition that it is postulated in the |
244 and @{ML "Assumption.export"} in the canonical way. |
310 and @{ML "Assumption.export"} in the canonical way. |
245 |
311 |
246 \end{description} |
312 \end{description} |
247 *} |
313 *} |
248 |
314 |
|
315 text %mlex {* The following example demonstrates how rules can be |
|
316 derived by building up a context of assumptions first, and exporting |
|
317 some local fact afterwards. We refer to @{theory Pure} equality |
|
318 here for testing purposes. |
|
319 *} |
|
320 |
|
321 ML {* |
|
322 (*static compile-time context -- for testing only*) |
|
323 val ctxt0 = @{context}; |
|
324 |
|
325 val ([eq], ctxt1) = |
|
326 ctxt0 |> Assumption.add_assumes [@{cprop "x \<equiv> y"}]; |
|
327 val eq' = Thm.symmetric eq; |
|
328 |
|
329 (*back to original context -- discharges assumption*) |
|
330 val r = Assumption.export false ctxt1 ctxt0 eq'; |
|
331 *} |
|
332 |
|
333 text {* \noindent Note that the variables of the resulting rule are |
|
334 not generalized. This would have required to fix them properly in |
|
335 the context beforehand, and export wrt.\ variables afterwards (cf.\ |
|
336 @{ML Variable.export} or the combined @{ML "ProofContext.export"}). |
|
337 *} |
|
338 |
249 |
339 |
250 section {* Structured goals and results \label{sec:struct-goals} *} |
340 section {* Structured goals and results \label{sec:struct-goals} *} |
251 |
341 |
252 text {* |
342 text {* |
253 Local results are established by monotonic reasoning from facts |
343 Local results are established by monotonic reasoning from facts |