author | wenzelm |
Thu, 19 Jun 2014 12:01:26 +0200 | |
changeset 57341 | d6393137b161 |
parent 56895 | f058120aaad4 |
child 57343 | e0f573aca42f |
permissions | -rw-r--r-- |
57341 | 1 |
(*:wrap=hard:maxLineLen=78:*) |
2 |
||
29755 | 3 |
theory Integration |
4 |
imports Base |
|
5 |
begin |
|
18537 | 6 |
|
7 |
chapter {* System integration *} |
|
8 |
||
20447 | 9 |
section {* Isar toplevel \label{sec:isar-toplevel} *} |
18537 | 10 |
|
48974 | 11 |
text {* The Isar toplevel may be considered the central hub of the |
18537 | 12 |
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
|
13 |
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
|
14 |
which also incorporates the underlying ML compiler. |
18537 | 15 |
|
20451 | 16 |
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
|
17 |
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
|
18 |
conducting proofs. Instead, ML now only serves as the |
18537 | 19 |
implementation language for the system (and user extensions), while |
20451 | 20 |
the specific Isar toplevel supports the concepts of theory and proof |
21 |
development natively. This includes the graph structure of theories |
|
22 |
and the block structure of proofs, support for unlimited undo, |
|
23 |
facilities for tracing, debugging, timing, profiling etc. |
|
18537 | 24 |
|
25 |
\medskip The toplevel maintains an implicit state, which is |
|
26 |
transformed by a sequence of transitions -- either interactively or |
|
52788 | 27 |
in batch-mode. |
18537 | 28 |
|
29 |
The toplevel state is a disjoint sum of empty @{text toplevel}, or |
|
30 |
@{text theory}, or @{text proof}. On entering the main Isar loop we |
|
31 |
start with an empty toplevel. A theory is commenced by giving a |
|
32 |
@{text \<THEORY>} header; within a theory we may issue theory |
|
20025 | 33 |
commands such as @{text \<DEFINITION>}, or state a @{text |
34 |
\<THEOREM>} to be proven. Now we are within a proof state, with a |
|
35 |
rich collection of Isar proof commands for structured proof |
|
18537 | 36 |
composition, or unstructured proof scripts. When the proof is |
37 |
concluded we get back to the theory, which is then updated by |
|
38 |
storing the resulting fact. Further theory declarations or theorem |
|
39 |
statements with proofs may follow, until we eventually conclude the |
|
40 |
theory development by issuing @{text \<END>}. The resulting theory |
|
41 |
is then stored within the theory database and we are back to the |
|
42 |
empty toplevel. |
|
43 |
||
44 |
In addition to these proper state transformations, there are also |
|
45 |
some diagnostic commands for peeking at the toplevel state without |
|
46 |
modifying it (e.g.\ \isakeyword{thm}, \isakeyword{term}, |
|
47 |
\isakeyword{print-cases}). |
|
48 |
*} |
|
49 |
||
50 |
text %mlref {* |
|
51 |
\begin{mldecls} |
|
52 |
@{index_ML_type Toplevel.state} \\ |
|
55838 | 53 |
@{index_ML_exception Toplevel.UNDEF} \\ |
18537 | 54 |
@{index_ML Toplevel.is_toplevel: "Toplevel.state -> bool"} \\ |
55 |
@{index_ML Toplevel.theory_of: "Toplevel.state -> theory"} \\ |
|
56 |
@{index_ML Toplevel.proof_of: "Toplevel.state -> Proof.state"} \\ |
|
32833 | 57 |
@{index_ML Toplevel.timing: "bool Unsynchronized.ref"} \\ |
58 |
@{index_ML Toplevel.profiling: "int Unsynchronized.ref"} \\ |
|
18537 | 59 |
\end{mldecls} |
60 |
||
61 |
\begin{description} |
|
62 |
||
39864 | 63 |
\item Type @{ML_type Toplevel.state} represents Isar toplevel |
64 |
states, which are normally manipulated through the concept of |
|
65 |
toplevel transitions only (\secref{sec:toplevel-transition}). Also |
|
66 |
note that a raw toplevel state is subject to the same linearity |
|
67 |
restrictions as a theory context (cf.~\secref{sec:context-theory}). |
|
18537 | 68 |
|
69 |
\item @{ML Toplevel.UNDEF} is raised for undefined toplevel |
|
20451 | 70 |
operations. Many operations work only partially for certain cases, |
71 |
since @{ML_type Toplevel.state} is a sum type. |
|
18537 | 72 |
|
20451 | 73 |
\item @{ML Toplevel.is_toplevel}~@{text "state"} checks for an empty |
74 |
toplevel state. |
|
18537 | 75 |
|
34931 | 76 |
\item @{ML Toplevel.theory_of}~@{text "state"} selects the |
77 |
background theory of @{text "state"}, raises @{ML Toplevel.UNDEF} |
|
78 |
for an empty toplevel state. |
|
18537 | 79 |
|
20451 | 80 |
\item @{ML Toplevel.proof_of}~@{text "state"} selects the Isar proof |
81 |
state if available, otherwise raises @{ML Toplevel.UNDEF}. |
|
18537 | 82 |
|
32833 | 83 |
\item @{ML "Toplevel.timing := true"} makes the toplevel print timing |
18537 | 84 |
information for each Isar command being executed. |
85 |
||
40149
4c35be108990
proper markup of uninterpreted ML text as @{ML_text}, not @{verbatim};
wenzelm
parents:
39882
diff
changeset
|
86 |
\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
|
87 |
low-level profiling of the underlying ML runtime system. For |
20451 | 88 |
Poly/ML, @{text "n = 1"} means time and @{text "n = 2"} space |
89 |
profiling. |
|
18537 | 90 |
|
91 |
\end{description} |
|
92 |
*} |
|
93 |
||
39882 | 94 |
text %mlantiq {* |
95 |
\begin{matharray}{rcl} |
|
96 |
@{ML_antiquotation_def "Isar.state"} & : & @{text ML_antiquotation} \\ |
|
97 |
\end{matharray} |
|
98 |
||
99 |
\begin{description} |
|
100 |
||
101 |
\item @{text "@{Isar.state}"} refers to Isar toplevel state at that |
|
102 |
point --- as abstract value. |
|
103 |
||
104 |
This only works for diagnostic ML commands, such as @{command |
|
105 |
ML_val} or @{command ML_command}. |
|
106 |
||
107 |
\end{description} |
|
108 |
*} |
|
109 |
||
18537 | 110 |
|
20451 | 111 |
subsection {* Toplevel transitions \label{sec:toplevel-transition} *} |
18537 | 112 |
|
20451 | 113 |
text {* |
114 |
An Isar toplevel transition consists of a partial function on the |
|
115 |
toplevel state, with additional information for diagnostics and |
|
116 |
error reporting: there are fields for command name, source position, |
|
117 |
optional source text, as well as flags for interactive-only commands |
|
118 |
(which issue a warning in batch-mode), printing of result state, |
|
119 |
etc. |
|
18537 | 120 |
|
20451 | 121 |
The operational part is represented as the sequential union of a |
122 |
list of partial functions, which are tried in turn until the first |
|
20475 | 123 |
one succeeds. This acts like an outer case-expression for various |
34931 | 124 |
alternative state transitions. For example, \isakeyword{qed} works |
20475 | 125 |
differently for a local proofs vs.\ the global ending of the main |
126 |
proof. |
|
18537 | 127 |
|
128 |
Toplevel transitions are composed via transition transformers. |
|
129 |
Internally, Isar commands are put together from an empty transition |
|
34931 | 130 |
extended by name and source position. It is then left to the |
131 |
individual command parser to turn the given concrete syntax into a |
|
132 |
suitable transition transformer that adjoins actual operations on a |
|
133 |
theory or proof state etc. |
|
18537 | 134 |
*} |
135 |
||
136 |
text %mlref {* |
|
137 |
\begin{mldecls} |
|
138 |
@{index_ML Toplevel.keep: "(Toplevel.state -> unit) -> |
|
139 |
Toplevel.transition -> Toplevel.transition"} \\ |
|
140 |
@{index_ML Toplevel.theory: "(theory -> theory) -> |
|
141 |
Toplevel.transition -> Toplevel.transition"} \\ |
|
142 |
@{index_ML Toplevel.theory_to_proof: "(theory -> Proof.state) -> |
|
143 |
Toplevel.transition -> Toplevel.transition"} \\ |
|
144 |
@{index_ML Toplevel.proof: "(Proof.state -> Proof.state) -> |
|
145 |
Toplevel.transition -> Toplevel.transition"} \\ |
|
49864 | 146 |
@{index_ML Toplevel.proofs: "(Proof.state -> Proof.state Seq.result Seq.seq) -> |
18537 | 147 |
Toplevel.transition -> Toplevel.transition"} \\ |
21168
0f869edd6cc1
replaced Toplevel.proof_to_theory by Toplevel.end_proof;
wenzelm
parents:
20491
diff
changeset
|
148 |
@{index_ML Toplevel.end_proof: "(bool -> Proof.state -> Proof.context) -> |
18537 | 149 |
Toplevel.transition -> Toplevel.transition"} \\ |
150 |
\end{mldecls} |
|
151 |
||
152 |
\begin{description} |
|
153 |
||
20451 | 154 |
\item @{ML Toplevel.keep}~@{text "tr"} adjoins a diagnostic |
155 |
function. |
|
18537 | 156 |
|
20451 | 157 |
\item @{ML Toplevel.theory}~@{text "tr"} adjoins a theory |
158 |
transformer. |
|
18537 | 159 |
|
20451 | 160 |
\item @{ML Toplevel.theory_to_proof}~@{text "tr"} adjoins a global |
161 |
goal function, which turns a theory into a proof state. The theory |
|
162 |
may be changed before entering the proof; the generic Isar goal |
|
163 |
setup includes an argument that specifies how to apply the proven |
|
164 |
result to the theory, when the proof is finished. |
|
18558 | 165 |
|
20451 | 166 |
\item @{ML Toplevel.proof}~@{text "tr"} adjoins a deterministic |
167 |
proof command, with a singleton result. |
|
18537 | 168 |
|
20451 | 169 |
\item @{ML Toplevel.proofs}~@{text "tr"} adjoins a general proof |
170 |
command, with zero or more result states (represented as a lazy |
|
171 |
list). |
|
18537 | 172 |
|
21168
0f869edd6cc1
replaced Toplevel.proof_to_theory by Toplevel.end_proof;
wenzelm
parents:
20491
diff
changeset
|
173 |
\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
|
174 |
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
|
175 |
resulting facts in the context etc. |
18537 | 176 |
|
177 |
\end{description} |
|
178 |
*} |
|
179 |
||
180 |
||
57341 | 181 |
section {* Theory loader database *} |
18537 | 182 |
|
20451 | 183 |
text {* |
57341 | 184 |
In batch mode and within dumped logic images, the theory database maintains |
185 |
a collection of theories as a directed acyclic graph. A theory may refer to |
|
186 |
other theories as @{keyword "imports"}, or to auxiliary files via special |
|
187 |
\emph{load commands} (e.g.\ @{command ML_file}). For each theory, the base |
|
188 |
directory of its own theory file is called \emph{master directory}: this is |
|
189 |
used as the relative location to refer to other files from that theory. |
|
18537 | 190 |
*} |
191 |
||
192 |
text %mlref {* |
|
193 |
\begin{mldecls} |
|
194 |
@{index_ML use_thy: "string -> unit"} \\ |
|
24173
4ba00a972eb8
theory loader: added use_thys, removed obsolete update_thy;
wenzelm
parents:
22095
diff
changeset
|
195 |
@{index_ML use_thys: "string list -> unit"} \\ |
37864 | 196 |
@{index_ML Thy_Info.get_theory: "string -> theory"} \\ |
57341 | 197 |
@{index_ML Thy_Info.remove_thy: "string -> unit"} \\ |
198 |
@{index_ML Thy_Info.register_thy: "theory -> unit"} \\ |
|
18537 | 199 |
\end{mldecls} |
200 |
||
201 |
\begin{description} |
|
202 |
||
24173
4ba00a972eb8
theory loader: added use_thys, removed obsolete update_thy;
wenzelm
parents:
22095
diff
changeset
|
203 |
\item @{ML use_thy}~@{text A} ensures that theory @{text A} is fully |
57341 | 204 |
up-to-date wrt.\ the external file store, reloading outdated ancestors as |
205 |
required. |
|
18537 | 206 |
|
57341 | 207 |
\item @{ML use_thys} is similar to @{ML use_thy}, but handles several |
208 |
theories simultaneously. Thus it acts like processing the import header of a |
|
209 |
theory, without performing the merge of the result. By loading a whole |
|
210 |
sub-graph of theories, the intrinsic parallelism can be exploited by the |
|
211 |
system to speedup loading. |
|
18537 | 212 |
|
37864 | 213 |
\item @{ML Thy_Info.get_theory}~@{text A} retrieves the theory value |
57341 | 214 |
presently associated with name @{text A}. Note that the result might be |
215 |
outdated wrt.\ the file-system content. |
|
37864 | 216 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
34931
diff
changeset
|
217 |
\item @{ML Thy_Info.remove_thy}~@{text A} deletes theory @{text A} and all |
18537 | 218 |
descendants from the theory database. |
219 |
||
57341 | 220 |
\item @{ML Thy_Info.register_thy}~@{text "text thy"} registers an existing |
221 |
theory value with the theory loader database and updates source version |
|
222 |
information according to the current file-system state. |
|
18537 | 223 |
|
224 |
\end{description} |
|
225 |
*} |
|
30272 | 226 |
|
18537 | 227 |
end |