| author | blanchet |
| Fri, 13 Sep 2013 16:30:16 +0200 | |
| changeset 53618 | 4161d2b96b8c |
| parent 52788 | da1fdbfebd39 |
| child 53709 | 84522727f9d3 |
| permissions | -rw-r--r-- |
| 29755 | 1 |
theory Integration |
2 |
imports Base |
|
3 |
begin |
|
| 18537 | 4 |
|
5 |
chapter {* System integration *}
|
|
6 |
||
| 20447 | 7 |
section {* Isar toplevel \label{sec:isar-toplevel} *}
|
| 18537 | 8 |
|
| 48974 | 9 |
text {* The Isar toplevel may be considered the central hub of the
|
| 18537 | 10 |
Isabelle/Isar system, where all key components and sub-systems are |
|
39825
f9066b94bf07
eliminated fancy \ML logo for the sake of simpler source text (less dependence on LaTeX);
wenzelm
parents:
37982
diff
changeset
|
11 |
integrated into a single read-eval-print loop of Isar commands, |
|
f9066b94bf07
eliminated fancy \ML logo for the sake of simpler source text (less dependence on LaTeX);
wenzelm
parents:
37982
diff
changeset
|
12 |
which also incorporates the underlying ML compiler. |
| 18537 | 13 |
|
| 20451 | 14 |
Isabelle/Isar departs from the original ``LCF system architecture'' |
|
39825
f9066b94bf07
eliminated fancy \ML logo for the sake of simpler source text (less dependence on LaTeX);
wenzelm
parents:
37982
diff
changeset
|
15 |
where ML was really The Meta Language for defining theories and |
|
f9066b94bf07
eliminated fancy \ML logo for the sake of simpler source text (less dependence on LaTeX);
wenzelm
parents:
37982
diff
changeset
|
16 |
conducting proofs. Instead, ML now only serves as the |
| 18537 | 17 |
implementation language for the system (and user extensions), while |
| 20451 | 18 |
the specific Isar toplevel supports the concepts of theory and proof |
19 |
development natively. This includes the graph structure of theories |
|
20 |
and the block structure of proofs, support for unlimited undo, |
|
21 |
facilities for tracing, debugging, timing, profiling etc. |
|
| 18537 | 22 |
|
23 |
\medskip The toplevel maintains an implicit state, which is |
|
24 |
transformed by a sequence of transitions -- either interactively or |
|
| 52788 | 25 |
in batch-mode. |
| 18537 | 26 |
|
27 |
The toplevel state is a disjoint sum of empty @{text toplevel}, or
|
|
28 |
@{text theory}, or @{text proof}. On entering the main Isar loop we
|
|
29 |
start with an empty toplevel. A theory is commenced by giving a |
|
30 |
@{text \<THEORY>} header; within a theory we may issue theory
|
|
| 20025 | 31 |
commands such as @{text \<DEFINITION>}, or state a @{text
|
32 |
\<THEOREM>} to be proven. Now we are within a proof state, with a |
|
33 |
rich collection of Isar proof commands for structured proof |
|
| 18537 | 34 |
composition, or unstructured proof scripts. When the proof is |
35 |
concluded we get back to the theory, which is then updated by |
|
36 |
storing the resulting fact. Further theory declarations or theorem |
|
37 |
statements with proofs may follow, until we eventually conclude the |
|
38 |
theory development by issuing @{text \<END>}. The resulting theory
|
|
39 |
is then stored within the theory database and we are back to the |
|
40 |
empty toplevel. |
|
41 |
||
42 |
In addition to these proper state transformations, there are also |
|
43 |
some diagnostic commands for peeking at the toplevel state without |
|
44 |
modifying it (e.g.\ \isakeyword{thm}, \isakeyword{term},
|
|
45 |
\isakeyword{print-cases}).
|
|
46 |
*} |
|
47 |
||
48 |
text %mlref {*
|
|
49 |
\begin{mldecls}
|
|
50 |
@{index_ML_type Toplevel.state} \\
|
|
51 |
@{index_ML Toplevel.UNDEF: "exn"} \\
|
|
52 |
@{index_ML Toplevel.is_toplevel: "Toplevel.state -> bool"} \\
|
|
53 |
@{index_ML Toplevel.theory_of: "Toplevel.state -> theory"} \\
|
|
54 |
@{index_ML Toplevel.proof_of: "Toplevel.state -> Proof.state"} \\
|
|
| 32833 | 55 |
@{index_ML Toplevel.debug: "bool Unsynchronized.ref"} \\
|
56 |
@{index_ML Toplevel.timing: "bool Unsynchronized.ref"} \\
|
|
57 |
@{index_ML Toplevel.profiling: "int Unsynchronized.ref"} \\
|
|
| 18537 | 58 |
\end{mldecls}
|
59 |
||
60 |
\begin{description}
|
|
61 |
||
| 39864 | 62 |
\item Type @{ML_type Toplevel.state} represents Isar toplevel
|
63 |
states, which are normally manipulated through the concept of |
|
64 |
toplevel transitions only (\secref{sec:toplevel-transition}). Also
|
|
65 |
note that a raw toplevel state is subject to the same linearity |
|
66 |
restrictions as a theory context (cf.~\secref{sec:context-theory}).
|
|
| 18537 | 67 |
|
68 |
\item @{ML Toplevel.UNDEF} is raised for undefined toplevel
|
|
| 20451 | 69 |
operations. Many operations work only partially for certain cases, |
70 |
since @{ML_type Toplevel.state} is a sum type.
|
|
| 18537 | 71 |
|
| 20451 | 72 |
\item @{ML Toplevel.is_toplevel}~@{text "state"} checks for an empty
|
73 |
toplevel state. |
|
| 18537 | 74 |
|
| 34931 | 75 |
\item @{ML Toplevel.theory_of}~@{text "state"} selects the
|
76 |
background theory of @{text "state"}, raises @{ML Toplevel.UNDEF}
|
|
77 |
for an empty toplevel state. |
|
| 18537 | 78 |
|
| 20451 | 79 |
\item @{ML Toplevel.proof_of}~@{text "state"} selects the Isar proof
|
80 |
state if available, otherwise raises @{ML Toplevel.UNDEF}.
|
|
| 18537 | 81 |
|
| 51659 | 82 |
\item @{ML "Toplevel.debug := true"} enables low-level exception
|
83 |
trace of the ML runtime system. Note that the result might appear |
|
84 |
on some raw output window only, outside the formal context of the |
|
85 |
source text. |
|
| 18537 | 86 |
|
| 32833 | 87 |
\item @{ML "Toplevel.timing := true"} makes the toplevel print timing
|
| 18537 | 88 |
information for each Isar command being executed. |
89 |
||
|
40149
4c35be108990
proper markup of uninterpreted ML text as @{ML_text}, not @{verbatim};
wenzelm
parents:
39882
diff
changeset
|
90 |
\item @{ML Toplevel.profiling}~@{ML_text ":="}~@{text "n"} controls
|
|
39825
f9066b94bf07
eliminated fancy \ML logo for the sake of simpler source text (less dependence on LaTeX);
wenzelm
parents:
37982
diff
changeset
|
91 |
low-level profiling of the underlying ML runtime system. For |
| 20451 | 92 |
Poly/ML, @{text "n = 1"} means time and @{text "n = 2"} space
|
93 |
profiling. |
|
| 18537 | 94 |
|
95 |
\end{description}
|
|
96 |
*} |
|
97 |
||
| 39882 | 98 |
text %mlantiq {*
|
99 |
\begin{matharray}{rcl}
|
|
100 |
@{ML_antiquotation_def "Isar.state"} & : & @{text ML_antiquotation} \\
|
|
101 |
\end{matharray}
|
|
102 |
||
103 |
\begin{description}
|
|
104 |
||
105 |
\item @{text "@{Isar.state}"} refers to Isar toplevel state at that
|
|
106 |
point --- as abstract value. |
|
107 |
||
108 |
This only works for diagnostic ML commands, such as @{command
|
|
109 |
ML_val} or @{command ML_command}.
|
|
110 |
||
111 |
\end{description}
|
|
112 |
*} |
|
113 |
||
| 18537 | 114 |
|
| 20451 | 115 |
subsection {* Toplevel transitions \label{sec:toplevel-transition} *}
|
| 18537 | 116 |
|
| 20451 | 117 |
text {*
|
118 |
An Isar toplevel transition consists of a partial function on the |
|
119 |
toplevel state, with additional information for diagnostics and |
|
120 |
error reporting: there are fields for command name, source position, |
|
121 |
optional source text, as well as flags for interactive-only commands |
|
122 |
(which issue a warning in batch-mode), printing of result state, |
|
123 |
etc. |
|
| 18537 | 124 |
|
| 20451 | 125 |
The operational part is represented as the sequential union of a |
126 |
list of partial functions, which are tried in turn until the first |
|
| 20475 | 127 |
one succeeds. This acts like an outer case-expression for various |
| 34931 | 128 |
alternative state transitions. For example, \isakeyword{qed} works
|
| 20475 | 129 |
differently for a local proofs vs.\ the global ending of the main |
130 |
proof. |
|
| 18537 | 131 |
|
132 |
Toplevel transitions are composed via transition transformers. |
|
133 |
Internally, Isar commands are put together from an empty transition |
|
| 34931 | 134 |
extended by name and source position. It is then left to the |
135 |
individual command parser to turn the given concrete syntax into a |
|
136 |
suitable transition transformer that adjoins actual operations on a |
|
137 |
theory or proof state etc. |
|
| 18537 | 138 |
*} |
139 |
||
140 |
text %mlref {*
|
|
141 |
\begin{mldecls}
|
|
142 |
@{index_ML Toplevel.print: "Toplevel.transition -> Toplevel.transition"} \\
|
|
143 |
@{index_ML Toplevel.keep: "(Toplevel.state -> unit) ->
|
|
144 |
Toplevel.transition -> Toplevel.transition"} \\ |
|
145 |
@{index_ML Toplevel.theory: "(theory -> theory) ->
|
|
146 |
Toplevel.transition -> Toplevel.transition"} \\ |
|
147 |
@{index_ML Toplevel.theory_to_proof: "(theory -> Proof.state) ->
|
|
148 |
Toplevel.transition -> Toplevel.transition"} \\ |
|
149 |
@{index_ML Toplevel.proof: "(Proof.state -> Proof.state) ->
|
|
150 |
Toplevel.transition -> Toplevel.transition"} \\ |
|
| 49864 | 151 |
@{index_ML Toplevel.proofs: "(Proof.state -> Proof.state Seq.result Seq.seq) ->
|
| 18537 | 152 |
Toplevel.transition -> Toplevel.transition"} \\ |
|
21168
0f869edd6cc1
replaced Toplevel.proof_to_theory by Toplevel.end_proof;
wenzelm
parents:
20491
diff
changeset
|
153 |
@{index_ML Toplevel.end_proof: "(bool -> Proof.state -> Proof.context) ->
|
| 18537 | 154 |
Toplevel.transition -> Toplevel.transition"} \\ |
155 |
\end{mldecls}
|
|
156 |
||
157 |
\begin{description}
|
|
158 |
||
| 20451 | 159 |
\item @{ML Toplevel.print}~@{text "tr"} sets the print flag, which
|
160 |
causes the toplevel loop to echo the result state (in interactive |
|
161 |
mode). |
|
| 18537 | 162 |
|
| 20451 | 163 |
\item @{ML Toplevel.keep}~@{text "tr"} adjoins a diagnostic
|
164 |
function. |
|
| 18537 | 165 |
|
| 20451 | 166 |
\item @{ML Toplevel.theory}~@{text "tr"} adjoins a theory
|
167 |
transformer. |
|
| 18537 | 168 |
|
| 20451 | 169 |
\item @{ML Toplevel.theory_to_proof}~@{text "tr"} adjoins a global
|
170 |
goal function, which turns a theory into a proof state. The theory |
|
171 |
may be changed before entering the proof; the generic Isar goal |
|
172 |
setup includes an argument that specifies how to apply the proven |
|
173 |
result to the theory, when the proof is finished. |
|
| 18558 | 174 |
|
| 20451 | 175 |
\item @{ML Toplevel.proof}~@{text "tr"} adjoins a deterministic
|
176 |
proof command, with a singleton result. |
|
| 18537 | 177 |
|
| 20451 | 178 |
\item @{ML Toplevel.proofs}~@{text "tr"} adjoins a general proof
|
179 |
command, with zero or more result states (represented as a lazy |
|
180 |
list). |
|
| 18537 | 181 |
|
|
21168
0f869edd6cc1
replaced Toplevel.proof_to_theory by Toplevel.end_proof;
wenzelm
parents:
20491
diff
changeset
|
182 |
\item @{ML Toplevel.end_proof}~@{text "tr"} adjoins a concluding
|
|
0f869edd6cc1
replaced Toplevel.proof_to_theory by Toplevel.end_proof;
wenzelm
parents:
20491
diff
changeset
|
183 |
proof command, that returns the resulting theory, after storing the |
|
0f869edd6cc1
replaced Toplevel.proof_to_theory by Toplevel.end_proof;
wenzelm
parents:
20491
diff
changeset
|
184 |
resulting facts in the context etc. |
| 18537 | 185 |
|
186 |
\end{description}
|
|
187 |
*} |
|
188 |
||
189 |
||
| 20451 | 190 |
section {* Theory database \label{sec:theory-database} *}
|
| 18537 | 191 |
|
| 20451 | 192 |
text {*
|
193 |
The theory database maintains a collection of theories, together |
|
194 |
with some administrative information about their original sources, |
|
195 |
which are held in an external store (i.e.\ some directory within the |
|
196 |
regular file system). |
|
| 18537 | 197 |
|
| 20451 | 198 |
The theory database is organized as a directed acyclic graph; |
199 |
entries are referenced by theory name. Although some additional |
|
200 |
interfaces allow to include a directory specification as well, this |
|
201 |
is only a hint to the underlying theory loader. The internal theory |
|
202 |
name space is flat! |
|
| 18537 | 203 |
|
204 |
Theory @{text A} is associated with the main theory file @{text
|
|
205 |
A}\verb,.thy,, which needs to be accessible through the theory |
|
|
39825
f9066b94bf07
eliminated fancy \ML logo for the sake of simpler source text (less dependence on LaTeX);
wenzelm
parents:
37982
diff
changeset
|
206 |
loader path. Any number of additional ML source files may be |
| 18537 | 207 |
associated with each theory, by declaring these dependencies in the |
208 |
theory header as @{text \<USES>}, and loading them consecutively
|
|
|
39825
f9066b94bf07
eliminated fancy \ML logo for the sake of simpler source text (less dependence on LaTeX);
wenzelm
parents:
37982
diff
changeset
|
209 |
within the theory context. The system keeps track of incoming ML |
| 34931 | 210 |
sources and associates them with the current theory. |
| 18537 | 211 |
|
212 |
The basic internal actions of the theory database are @{text
|
|
| 37982 | 213 |
"update"} and @{text "remove"}:
|
| 18537 | 214 |
|
215 |
\begin{itemize}
|
|
216 |
||
217 |
\item @{text "update A"} introduces a link of @{text "A"} with a
|
|
218 |
@{text "theory"} value of the same name; it asserts that the theory
|
|
| 20451 | 219 |
sources are now consistent with that value; |
| 18537 | 220 |
|
| 20451 | 221 |
\item @{text "remove A"} deletes entry @{text "A"} from the theory
|
| 18537 | 222 |
database. |
223 |
||
224 |
\end{itemize}
|
|
225 |
||
226 |
These actions are propagated to sub- or super-graphs of a theory |
|
| 20451 | 227 |
entry as expected, in order to preserve global consistency of the |
228 |
state of all loaded theories with the sources of the external store. |
|
229 |
This implies certain causalities between actions: @{text "update"}
|
|
| 37982 | 230 |
or @{text "remove"} of an entry will @{text "remove"} all
|
231 |
descendants. |
|
| 18537 | 232 |
|
233 |
\medskip There are separate user-level interfaces to operate on the |
|
234 |
theory database directly or indirectly. The primitive actions then |
|
235 |
just happen automatically while working with the system. In |
|
236 |
particular, processing a theory header @{text "\<THEORY> A
|
|
| 20451 | 237 |
\<IMPORTS> B\<^sub>1 \<dots> B\<^sub>n \<BEGIN>"} ensures that the |
| 18537 | 238 |
sub-graph of the collective imports @{text "B\<^sub>1 \<dots> B\<^sub>n"}
|
| 20451 | 239 |
is up-to-date, too. Earlier theories are reloaded as required, with |
| 18537 | 240 |
@{text update} actions proceeding in topological order according to
|
241 |
theory dependencies. There may be also a wave of implied @{text
|
|
| 37982 | 242 |
remove} actions for derived theory nodes until a stable situation |
| 18537 | 243 |
is achieved eventually. |
244 |
*} |
|
245 |
||
246 |
text %mlref {*
|
|
247 |
\begin{mldecls}
|
|
248 |
@{index_ML use_thy: "string -> unit"} \\
|
|
|
24173
4ba00a972eb8
theory loader: added use_thys, removed obsolete update_thy;
wenzelm
parents:
22095
diff
changeset
|
249 |
@{index_ML use_thys: "string list -> unit"} \\
|
| 37864 | 250 |
@{index_ML Thy_Info.get_theory: "string -> theory"} \\
|
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
34931
diff
changeset
|
251 |
@{index_ML Thy_Info.remove_thy: "string -> unit"} \\[1ex]
|
| 37982 | 252 |
@{index_ML Thy_Info.register_thy: "theory -> unit"} \\[1ex]
|
|
40149
4c35be108990
proper markup of uninterpreted ML text as @{ML_text}, not @{verbatim};
wenzelm
parents:
39882
diff
changeset
|
253 |
@{ML_text "datatype action = Update | Remove"} \\
|
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
34931
diff
changeset
|
254 |
@{index_ML Thy_Info.add_hook: "(Thy_Info.action -> string -> unit) -> unit"} \\
|
| 18537 | 255 |
\end{mldecls}
|
256 |
||
257 |
\begin{description}
|
|
258 |
||
|
24173
4ba00a972eb8
theory loader: added use_thys, removed obsolete update_thy;
wenzelm
parents:
22095
diff
changeset
|
259 |
\item @{ML use_thy}~@{text A} ensures that theory @{text A} is fully
|
|
4ba00a972eb8
theory loader: added use_thys, removed obsolete update_thy;
wenzelm
parents:
22095
diff
changeset
|
260 |
up-to-date wrt.\ the external file store, reloading outdated |
| 34931 | 261 |
ancestors as required. In batch mode, the simultaneous @{ML
|
262 |
use_thys} should be used exclusively. |
|
| 18537 | 263 |
|
|
24173
4ba00a972eb8
theory loader: added use_thys, removed obsolete update_thy;
wenzelm
parents:
22095
diff
changeset
|
264 |
\item @{ML use_thys} is similar to @{ML use_thy}, but handles
|
|
4ba00a972eb8
theory loader: added use_thys, removed obsolete update_thy;
wenzelm
parents:
22095
diff
changeset
|
265 |
several theories simultaneously. Thus it acts like processing the |
|
4ba00a972eb8
theory loader: added use_thys, removed obsolete update_thy;
wenzelm
parents:
22095
diff
changeset
|
266 |
import header of a theory, without performing the merge of the |
| 34931 | 267 |
result. By loading a whole sub-graph of theories like that, the |
268 |
intrinsic parallelism can be exploited by the system, to speedup |
|
269 |
loading. |
|
| 18537 | 270 |
|
| 37864 | 271 |
\item @{ML Thy_Info.get_theory}~@{text A} retrieves the theory value
|
272 |
presently associated with name @{text A}. Note that the result
|
|
273 |
might be outdated. |
|
274 |
||
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
34931
diff
changeset
|
275 |
\item @{ML Thy_Info.remove_thy}~@{text A} deletes theory @{text A} and all
|
| 18537 | 276 |
descendants from the theory database. |
277 |
||
| 37982 | 278 |
\item @{ML Thy_Info.register_thy}~@{text "text thy"} registers an
|
279 |
existing theory value with the theory loader database and updates |
|
280 |
source version information according to the current file-system |
|
281 |
state. |
|
| 18537 | 282 |
|
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
34931
diff
changeset
|
283 |
\item @{ML "Thy_Info.add_hook"}~@{text f} registers function @{text
|
| 18537 | 284 |
f} as a hook for theory database actions. The function will be |
285 |
invoked with the action and theory name being involved; thus derived |
|
286 |
actions may be performed in associated system components, e.g.\ |
|
| 20451 | 287 |
maintaining the state of an editor for the theory sources. |
| 18537 | 288 |
|
289 |
The kind and order of actions occurring in practice depends both on |
|
290 |
user interactions and the internal process of resolving theory |
|
291 |
imports. Hooks should not rely on a particular policy here! Any |
|
| 20451 | 292 |
exceptions raised by the hook are ignored. |
| 18537 | 293 |
|
294 |
\end{description}
|
|
295 |
*} |
|
| 30272 | 296 |
|
| 18537 | 297 |
end |