author | wenzelm |
Thu, 13 Nov 2008 21:45:40 +0100 | |
changeset 28761 | 9ec4482c9201 |
parent 28760 | cbc435f7b16b |
child 28762 | f5d79aeffd81 |
permissions | -rw-r--r-- |
26869 | 1 |
(* $Id$ *) |
2 |
||
3 |
theory Spec |
|
4 |
imports Main |
|
5 |
begin |
|
6 |
||
27046 | 7 |
chapter {* Theory specifications *} |
26869 | 8 |
|
26870 | 9 |
section {* Defining theories \label{sec:begin-thy} *} |
10 |
||
11 |
text {* |
|
12 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
13 |
@{command_def "theory"} & : & @{text "toplevel \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
14 |
@{command_def (global) "end"} & : & @{text "theory \<rightarrow> toplevel"} \\ |
26870 | 15 |
\end{matharray} |
16 |
||
28745 | 17 |
Isabelle/Isar theories are defined via theory files, which may |
18 |
contain both specifications and proofs; occasionally definitional |
|
19 |
mechanisms also require some explicit proof. The theory body may be |
|
20 |
sub-structured by means of \emph{local theory targets}, such as |
|
21 |
@{command "locale"} and @{command "class"}. |
|
26870 | 22 |
|
28745 | 23 |
The first proper command of a theory is @{command "theory"}, which |
24 |
indicates imports of previous theories and optional dependencies on |
|
25 |
other source files (usually in ML). Just preceding the initial |
|
26 |
@{command "theory"} command there may be an optional @{command |
|
27 |
"header"} declaration, which is only relevant to document |
|
28 |
preparation: see also the other section markup commands in |
|
29 |
\secref{sec:markup}. |
|
30 |
||
31 |
A theory is concluded by a final @{command (global) "end"} command, |
|
32 |
one that does not belong to a local theory target. No further |
|
33 |
commands may follow such a global @{command (global) "end"}, |
|
34 |
although some user-interfaces might pretend that trailing input is |
|
35 |
admissible. |
|
26870 | 36 |
|
37 |
\begin{rail} |
|
38 |
'theory' name 'imports' (name +) uses? 'begin' |
|
39 |
; |
|
40 |
||
41 |
uses: 'uses' ((name | parname) +); |
|
42 |
\end{rail} |
|
43 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
44 |
\begin{description} |
26870 | 45 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
46 |
\item @{command "theory"}~@{text "A \<IMPORTS> B\<^sub>1 \<dots> B\<^sub>n \<BEGIN>"} |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
47 |
starts a new theory @{text A} based on the merge of existing |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
48 |
theories @{text "B\<^sub>1 \<dots> B\<^sub>n"}. |
26870 | 49 |
|
28745 | 50 |
Due to the possibility to import more than one ancestor, the |
51 |
resulting theory structure of an Isabelle session forms a directed |
|
52 |
acyclic graph (DAG). Isabelle's theory loader ensures that the |
|
53 |
sources contributing to the development graph are always up-to-date: |
|
54 |
changed files are automatically reloaded whenever a theory header |
|
55 |
specification is processed. |
|
26870 | 56 |
|
57 |
The optional @{keyword_def "uses"} specification declares additional |
|
58 |
dependencies on extra files (usually ML sources). Files will be |
|
28745 | 59 |
loaded immediately (as ML), unless the name is parenthesized. The |
60 |
latter case records a dependency that needs to be resolved later in |
|
61 |
the text, usually via explicit @{command_ref "use"} for ML files; |
|
62 |
other file formats require specific load commands defined by the |
|
63 |
corresponding tools or packages. |
|
26870 | 64 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
65 |
\item @{command (global) "end"} concludes the current theory |
28745 | 66 |
definition. Note that local theory targets involve a local |
67 |
@{command (local) "end"}, which is clear from the nesting. |
|
27040 | 68 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
69 |
\end{description} |
27040 | 70 |
*} |
71 |
||
72 |
||
73 |
section {* Local theory targets \label{sec:target} *} |
|
74 |
||
75 |
text {* |
|
76 |
A local theory target is a context managed separately within the |
|
77 |
enclosing theory. Contexts may introduce parameters (fixed |
|
78 |
variables) and assumptions (hypotheses). Definitions and theorems |
|
79 |
depending on the context may be added incrementally later on. Named |
|
80 |
contexts refer to locales (cf.\ \secref{sec:locale}) or type classes |
|
81 |
(cf.\ \secref{sec:class}); the name ``@{text "-"}'' signifies the |
|
82 |
global theory context. |
|
83 |
||
84 |
\begin{matharray}{rcll} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
85 |
@{command_def "context"} & : & @{text "theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
86 |
@{command_def (local) "end"} & : & @{text "local_theory \<rightarrow> theory"} \\ |
27040 | 87 |
\end{matharray} |
88 |
||
89 |
\indexouternonterm{target} |
|
90 |
\begin{rail} |
|
91 |
'context' name 'begin' |
|
92 |
; |
|
93 |
||
94 |
target: '(' 'in' name ')' |
|
95 |
; |
|
96 |
\end{rail} |
|
97 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
98 |
\begin{description} |
27040 | 99 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
100 |
\item @{command "context"}~@{text "c \<BEGIN>"} recommences an |
27040 | 101 |
existing locale or class context @{text c}. Note that locale and |
27051 | 102 |
class definitions allow to include the @{keyword "begin"} keyword as |
103 |
well, in order to continue the local theory immediately after the |
|
104 |
initial specification. |
|
27040 | 105 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
106 |
\item @{command (local) "end"} concludes the current local theory |
27040 | 107 |
and continues the enclosing global theory. Note that a global |
108 |
@{command (global) "end"} has a different meaning: it concludes the |
|
109 |
theory itself (\secref{sec:begin-thy}). |
|
110 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
111 |
\item @{text "(\<IN> c)"} given after any local theory command |
27040 | 112 |
specifies an immediate target, e.g.\ ``@{command |
113 |
"definition"}~@{text "(\<IN> c) \<dots>"}'' or ``@{command |
|
114 |
"theorem"}~@{text "(\<IN> c) \<dots>"}''. This works both in a local or |
|
115 |
global theory context; the current target context will be suspended |
|
116 |
for this command only. Note that ``@{text "(\<IN> -)"}'' will |
|
117 |
always produce a global result independently of the current target |
|
118 |
context. |
|
119 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
120 |
\end{description} |
27040 | 121 |
|
122 |
The exact meaning of results produced within a local theory context |
|
123 |
depends on the underlying target infrastructure (locale, type class |
|
124 |
etc.). The general idea is as follows, considering a context named |
|
125 |
@{text c} with parameter @{text x} and assumption @{text "A[x]"}. |
|
126 |
||
127 |
Definitions are exported by introducing a global version with |
|
128 |
additional arguments; a syntactic abbreviation links the long form |
|
129 |
with the abstract version of the target context. For example, |
|
130 |
@{text "a \<equiv> t[x]"} becomes @{text "c.a ?x \<equiv> t[?x]"} at the theory |
|
131 |
level (for arbitrary @{text "?x"}), together with a local |
|
132 |
abbreviation @{text "c \<equiv> c.a x"} in the target context (for the |
|
133 |
fixed parameter @{text x}). |
|
134 |
||
135 |
Theorems are exported by discharging the assumptions and |
|
136 |
generalizing the parameters of the context. For example, @{text "a: |
|
137 |
B[x]"} becomes @{text "c.a: A[?x] \<Longrightarrow> B[?x]"}, again for arbitrary |
|
138 |
@{text "?x"}. |
|
139 |
*} |
|
140 |
||
141 |
||
142 |
section {* Basic specification elements *} |
|
143 |
||
144 |
text {* |
|
145 |
\begin{matharray}{rcll} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
146 |
@{command_def "axiomatization"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!)\\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
147 |
@{command_def "definition"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
148 |
@{attribute_def "defn"} & : & @{text attribute} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
149 |
@{command_def "abbreviation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
150 |
@{command_def "print_abbrevs"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow> "} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
151 |
@{command_def "notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
152 |
@{command_def "no_notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
27040 | 153 |
\end{matharray} |
154 |
||
155 |
These specification mechanisms provide a slightly more abstract view |
|
156 |
than the underlying primitives of @{command "consts"}, @{command |
|
157 |
"defs"} (see \secref{sec:consts}), and @{command "axioms"} (see |
|
158 |
\secref{sec:axms-thms}). In particular, type-inference is commonly |
|
159 |
available, and result names need not be given. |
|
160 |
||
161 |
\begin{rail} |
|
162 |
'axiomatization' target? fixes? ('where' specs)? |
|
163 |
; |
|
164 |
'definition' target? (decl 'where')? thmdecl? prop |
|
165 |
; |
|
166 |
'abbreviation' target? mode? (decl 'where')? prop |
|
167 |
; |
|
168 |
('notation' | 'no\_notation') target? mode? (nameref structmixfix + 'and') |
|
169 |
; |
|
170 |
||
171 |
fixes: ((name ('::' type)? mixfix? | vars) + 'and') |
|
172 |
; |
|
173 |
specs: (thmdecl? props + 'and') |
|
174 |
; |
|
175 |
decl: name ('::' type)? mixfix? |
|
176 |
; |
|
177 |
\end{rail} |
|
178 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
179 |
\begin{description} |
27040 | 180 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
181 |
\item @{command "axiomatization"}~@{text "c\<^sub>1 \<dots> c\<^sub>m \<WHERE> \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"} |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
182 |
introduces several constants simultaneously and states axiomatic |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
183 |
properties for these. The constants are marked as being specified |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
184 |
once and for all, which prevents additional specifications being |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
185 |
issued later on. |
27040 | 186 |
|
187 |
Note that axiomatic specifications are only appropriate when |
|
28114 | 188 |
declaring a new logical system; axiomatic specifications are |
189 |
restricted to global theory contexts. Normal applications should |
|
190 |
only use definitional mechanisms! |
|
27040 | 191 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
192 |
\item @{command "definition"}~@{text "c \<WHERE> eq"} produces an |
27040 | 193 |
internal definition @{text "c \<equiv> t"} according to the specification |
194 |
given as @{text eq}, which is then turned into a proven fact. The |
|
195 |
given proposition may deviate from internal meta-level equality |
|
196 |
according to the rewrite rules declared as @{attribute defn} by the |
|
197 |
object-logic. This usually covers object-level equality @{text "x = |
|
198 |
y"} and equivalence @{text "A \<leftrightarrow> B"}. End-users normally need not |
|
199 |
change the @{attribute defn} setup. |
|
200 |
||
201 |
Definitions may be presented with explicit arguments on the LHS, as |
|
202 |
well as additional conditions, e.g.\ @{text "f x y = t"} instead of |
|
203 |
@{text "f \<equiv> \<lambda>x y. t"} and @{text "y \<noteq> 0 \<Longrightarrow> g x y = u"} instead of an |
|
204 |
unrestricted @{text "g \<equiv> \<lambda>x y. u"}. |
|
205 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
206 |
\item @{command "abbreviation"}~@{text "c \<WHERE> eq"} introduces a |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
207 |
syntactic constant which is associated with a certain term according |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
208 |
to the meta-level equality @{text eq}. |
27040 | 209 |
|
210 |
Abbreviations participate in the usual type-inference process, but |
|
211 |
are expanded before the logic ever sees them. Pretty printing of |
|
212 |
terms involves higher-order rewriting with rules stemming from |
|
213 |
reverted abbreviations. This needs some care to avoid overlapping |
|
214 |
or looping syntactic replacements! |
|
215 |
||
216 |
The optional @{text mode} specification restricts output to a |
|
217 |
particular print mode; using ``@{text input}'' here achieves the |
|
218 |
effect of one-way abbreviations. The mode may also include an |
|
219 |
``@{keyword "output"}'' qualifier that affects the concrete syntax |
|
220 |
declared for abbreviations, cf.\ @{command "syntax"} in |
|
221 |
\secref{sec:syn-trans}. |
|
222 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
223 |
\item @{command "print_abbrevs"} prints all constant abbreviations |
27040 | 224 |
of the current context. |
225 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
226 |
\item @{command "notation"}~@{text "c (mx)"} associates mixfix |
27040 | 227 |
syntax with an existing constant or fixed variable. This is a |
228 |
robust interface to the underlying @{command "syntax"} primitive |
|
229 |
(\secref{sec:syn-trans}). Type declaration and internal syntactic |
|
230 |
representation of the given entity is retrieved from the context. |
|
231 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
232 |
\item @{command "no_notation"} is similar to @{command "notation"}, |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
233 |
but removes the specified syntax annotation from the present |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
234 |
context. |
27040 | 235 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
236 |
\end{description} |
27040 | 237 |
|
238 |
All of these specifications support local theory targets (cf.\ |
|
239 |
\secref{sec:target}). |
|
240 |
*} |
|
241 |
||
242 |
||
243 |
section {* Generic declarations *} |
|
244 |
||
245 |
text {* |
|
246 |
Arbitrary operations on the background context may be wrapped-up as |
|
247 |
generic declaration elements. Since the underlying concept of local |
|
248 |
theories may be subject to later re-interpretation, there is an |
|
249 |
additional dependency on a morphism that tells the difference of the |
|
250 |
original declaration context wrt.\ the application context |
|
251 |
encountered later on. A fact declaration is an important special |
|
252 |
case: it consists of a theorem which is applied to the context by |
|
253 |
means of an attribute. |
|
254 |
||
255 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
256 |
@{command_def "declaration"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
257 |
@{command_def "declare"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
27040 | 258 |
\end{matharray} |
259 |
||
260 |
\begin{rail} |
|
261 |
'declaration' target? text |
|
262 |
; |
|
263 |
'declare' target? (thmrefs + 'and') |
|
264 |
; |
|
265 |
\end{rail} |
|
266 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
267 |
\begin{description} |
27040 | 268 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
269 |
\item @{command "declaration"}~@{text d} adds the declaration |
27040 | 270 |
function @{text d} of ML type @{ML_type declaration}, to the current |
271 |
local theory under construction. In later application contexts, the |
|
272 |
function is transformed according to the morphisms being involved in |
|
273 |
the interpretation hierarchy. |
|
274 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
275 |
\item @{command "declare"}~@{text thms} declares theorems to the |
27040 | 276 |
current local theory context. No theorem binding is involved here, |
277 |
unlike @{command "theorems"} or @{command "lemmas"} (cf.\ |
|
278 |
\secref{sec:axms-thms}), so @{command "declare"} only has the effect |
|
279 |
of applying attributes as included in the theorem specification. |
|
280 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
281 |
\end{description} |
27040 | 282 |
*} |
283 |
||
284 |
||
285 |
section {* Locales \label{sec:locale} *} |
|
286 |
||
287 |
text {* |
|
288 |
Locales are named local contexts, consisting of a list of |
|
289 |
declaration elements that are modeled after the Isar proof context |
|
290 |
commands (cf.\ \secref{sec:proof-context}). |
|
291 |
*} |
|
292 |
||
293 |
||
294 |
subsection {* Locale specifications *} |
|
295 |
||
296 |
text {* |
|
297 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
298 |
@{command_def "locale"} & : & @{text "theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
299 |
@{command_def "print_locale"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
300 |
@{command_def "print_locales"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
301 |
@{method_def intro_locales} & : & @{text method} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
302 |
@{method_def unfold_locales} & : & @{text method} \\ |
27040 | 303 |
\end{matharray} |
304 |
||
305 |
\indexouternonterm{contextexpr}\indexouternonterm{contextelem} |
|
306 |
\indexisarelem{fixes}\indexisarelem{constrains}\indexisarelem{assumes} |
|
307 |
\indexisarelem{defines}\indexisarelem{notes}\indexisarelem{includes} |
|
308 |
\begin{rail} |
|
27681 | 309 |
'locale' name ('=' localeexpr)? 'begin'? |
27040 | 310 |
; |
311 |
'print\_locale' '!'? localeexpr |
|
312 |
; |
|
313 |
localeexpr: ((contextexpr '+' (contextelem+)) | contextexpr | (contextelem+)) |
|
314 |
; |
|
315 |
||
316 |
contextexpr: nameref | '(' contextexpr ')' | |
|
317 |
(contextexpr (name mixfix? +)) | (contextexpr + '+') |
|
318 |
; |
|
319 |
contextelem: fixes | constrains | assumes | defines | notes |
|
320 |
; |
|
321 |
fixes: 'fixes' ((name ('::' type)? structmixfix? | vars) + 'and') |
|
322 |
; |
|
323 |
constrains: 'constrains' (name '::' type + 'and') |
|
324 |
; |
|
325 |
assumes: 'assumes' (thmdecl? props + 'and') |
|
326 |
; |
|
327 |
defines: 'defines' (thmdecl? prop proppat? + 'and') |
|
328 |
; |
|
329 |
notes: 'notes' (thmdef? thmrefs + 'and') |
|
330 |
; |
|
331 |
includes: 'includes' contextexpr |
|
332 |
; |
|
333 |
\end{rail} |
|
334 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
335 |
\begin{description} |
27040 | 336 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
337 |
\item @{command "locale"}~@{text "loc = import + body"} defines a |
27040 | 338 |
new locale @{text loc} as a context consisting of a certain view of |
339 |
existing locales (@{text import}) plus some additional elements |
|
340 |
(@{text body}). Both @{text import} and @{text body} are optional; |
|
341 |
the degenerate form @{command "locale"}~@{text loc} defines an empty |
|
342 |
locale, which may still be useful to collect declarations of facts |
|
343 |
later on. Type-inference on locale expressions automatically takes |
|
344 |
care of the most general typing that the combined context elements |
|
345 |
may acquire. |
|
346 |
||
347 |
The @{text import} consists of a structured context expression, |
|
348 |
consisting of references to existing locales, renamed contexts, or |
|
349 |
merged contexts. Renaming uses positional notation: @{text "c |
|
350 |
x\<^sub>1 \<dots> x\<^sub>n"} means that (a prefix of) the fixed |
|
351 |
parameters of context @{text c} are named @{text "x\<^sub>1, \<dots>, |
|
352 |
x\<^sub>n"}; a ``@{text _}'' (underscore) means to skip that |
|
353 |
position. Renaming by default deletes concrete syntax, but new |
|
354 |
syntax may by specified with a mixfix annotation. An exeption of |
|
355 |
this rule is the special syntax declared with ``@{text |
|
356 |
"(\<STRUCTURE>)"}'' (see below), which is neither deleted nor can it |
|
357 |
be changed. Merging proceeds from left-to-right, suppressing any |
|
358 |
duplicates stemming from different paths through the import |
|
359 |
hierarchy. |
|
360 |
||
361 |
The @{text body} consists of basic context elements, further context |
|
362 |
expressions may be included as well. |
|
363 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
364 |
\begin{description} |
27040 | 365 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
366 |
\item @{element "fixes"}~@{text "x :: \<tau> (mx)"} declares a local |
27040 | 367 |
parameter of type @{text \<tau>} and mixfix annotation @{text mx} (both |
368 |
are optional). The special syntax declaration ``@{text |
|
369 |
"(\<STRUCTURE>)"}'' means that @{text x} may be referenced |
|
370 |
implicitly in this context. |
|
371 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
372 |
\item @{element "constrains"}~@{text "x :: \<tau>"} introduces a type |
27040 | 373 |
constraint @{text \<tau>} on the local parameter @{text x}. |
374 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
375 |
\item @{element "assumes"}~@{text "a: \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"} |
27040 | 376 |
introduces local premises, similar to @{command "assume"} within a |
377 |
proof (cf.\ \secref{sec:proof-context}). |
|
378 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
379 |
\item @{element "defines"}~@{text "a: x \<equiv> t"} defines a previously |
27040 | 380 |
declared parameter. This is similar to @{command "def"} within a |
381 |
proof (cf.\ \secref{sec:proof-context}), but @{element "defines"} |
|
382 |
takes an equational proposition instead of variable-term pair. The |
|
383 |
left-hand side of the equation may have additional arguments, e.g.\ |
|
384 |
``@{element "defines"}~@{text "f x\<^sub>1 \<dots> x\<^sub>n \<equiv> t"}''. |
|
385 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
386 |
\item @{element "notes"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"} |
27040 | 387 |
reconsiders facts within a local context. Most notably, this may |
388 |
include arbitrary declarations in any attribute specifications |
|
389 |
included here, e.g.\ a local @{attribute simp} rule. |
|
390 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
391 |
\item @{element "includes"}~@{text c} copies the specified context |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
392 |
in a statically scoped manner. Only available in the long goal |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
393 |
format of \secref{sec:goals}. |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
394 |
|
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
395 |
In contrast, the initial @{text import} specification of a locale |
27040 | 396 |
expression maintains a dynamic relation to the locales being |
397 |
referenced (benefiting from any later fact declarations in the |
|
398 |
obvious manner). |
|
399 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
400 |
\end{description} |
27040 | 401 |
|
402 |
Note that ``@{text "(\<IS> p\<^sub>1 \<dots> p\<^sub>n)"}'' patterns given |
|
403 |
in the syntax of @{element "assumes"} and @{element "defines"} above |
|
404 |
are illegal in locale definitions. In the long goal format of |
|
405 |
\secref{sec:goals}, term bindings may be included as expected, |
|
406 |
though. |
|
407 |
||
408 |
\medskip By default, locale specifications are ``closed up'' by |
|
409 |
turning the given text into a predicate definition @{text |
|
410 |
loc_axioms} and deriving the original assumptions as local lemmas |
|
411 |
(modulo local definitions). The predicate statement covers only the |
|
412 |
newly specified assumptions, omitting the content of included locale |
|
413 |
expressions. The full cumulative view is only provided on export, |
|
414 |
involving another predicate @{text loc} that refers to the complete |
|
415 |
specification text. |
|
416 |
||
417 |
In any case, the predicate arguments are those locale parameters |
|
418 |
that actually occur in the respective piece of text. Also note that |
|
419 |
these predicates operate at the meta-level in theory, but the locale |
|
420 |
packages attempts to internalize statements according to the |
|
421 |
object-logic setup (e.g.\ replacing @{text \<And>} by @{text \<forall>}, and |
|
422 |
@{text "\<Longrightarrow>"} by @{text "\<longrightarrow>"} in HOL; see also |
|
423 |
\secref{sec:object-logic}). Separate introduction rules @{text |
|
424 |
loc_axioms.intro} and @{text loc.intro} are provided as well. |
|
425 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
426 |
\item @{command "print_locale"}~@{text "import + body"} prints the |
27040 | 427 |
specified locale expression in a flattened form. The notable |
428 |
special case @{command "print_locale"}~@{text loc} just prints the |
|
429 |
contents of the named locale, but keep in mind that type-inference |
|
430 |
will normalize type variables according to the usual alphabetical |
|
431 |
order. The command omits @{element "notes"} elements by default. |
|
432 |
Use @{command "print_locale"}@{text "!"} to get them included. |
|
433 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
434 |
\item @{command "print_locales"} prints the names of all locales |
27040 | 435 |
of the current theory. |
436 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
437 |
\item @{method intro_locales} and @{method unfold_locales} |
27040 | 438 |
repeatedly expand all introduction rules of locale predicates of the |
439 |
theory. While @{method intro_locales} only applies the @{text |
|
440 |
loc.intro} introduction rules and therefore does not decend to |
|
441 |
assumptions, @{method unfold_locales} is more aggressive and applies |
|
442 |
@{text loc_axioms.intro} as well. Both methods are aware of locale |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
443 |
specifications entailed by the context, both from target and |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
444 |
@{element "includes"} statements, and from interpretations (see |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
445 |
below). New goals that are entailed by the current context are |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
446 |
discharged automatically. |
27040 | 447 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
448 |
\end{description} |
27040 | 449 |
*} |
450 |
||
451 |
||
452 |
subsection {* Interpretation of locales *} |
|
453 |
||
454 |
text {* |
|
455 |
Locale expressions (more precisely, \emph{context expressions}) may |
|
456 |
be instantiated, and the instantiated facts added to the current |
|
457 |
context. This requires a proof of the instantiated specification |
|
458 |
and is called \emph{locale interpretation}. Interpretation is |
|
459 |
possible in theories and locales (command @{command |
|
460 |
"interpretation"}) and also within a proof body (command @{command |
|
461 |
"interpret"}). |
|
462 |
||
463 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
464 |
@{command_def "interpretation"} & : & @{text "theory \<rightarrow> proof(prove)"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
465 |
@{command_def "interpret"} & : & @{text "proof(state) | proof(chain \<rightarrow> proof(prove)"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
466 |
@{command_def "print_interps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
27040 | 467 |
\end{matharray} |
468 |
||
469 |
\indexouternonterm{interp} |
|
470 |
\begin{rail} |
|
471 |
'interpretation' (interp | name ('<' | subseteq) contextexpr) |
|
472 |
; |
|
473 |
'interpret' interp |
|
474 |
; |
|
475 |
'print\_interps' '!'? name |
|
476 |
; |
|
477 |
instantiation: ('[' (inst+) ']')? |
|
478 |
; |
|
28085
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
479 |
interp: (name ':')? \\ (contextexpr instantiation | |
27040 | 480 |
name instantiation 'where' (thmdecl? prop + 'and')) |
481 |
; |
|
482 |
\end{rail} |
|
483 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
484 |
\begin{description} |
27040 | 485 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
486 |
\item @{command "interpretation"}~@{text "expr insts \<WHERE> eqns"} |
27040 | 487 |
|
488 |
The first form of @{command "interpretation"} interprets @{text |
|
489 |
expr} in the theory. The instantiation is given as a list of terms |
|
490 |
@{text insts} and is positional. All parameters must receive an |
|
491 |
instantiation term --- with the exception of defined parameters. |
|
492 |
These are, if omitted, derived from the defining equation and other |
|
493 |
instantiations. Use ``@{text _}'' to omit an instantiation term. |
|
494 |
||
495 |
The command generates proof obligations for the instantiated |
|
496 |
specifications (assumes and defines elements). Once these are |
|
497 |
discharged by the user, instantiated facts are added to the theory |
|
498 |
in a post-processing phase. |
|
499 |
||
500 |
Additional equations, which are unfolded in facts during |
|
501 |
post-processing, may be given after the keyword @{keyword "where"}. |
|
502 |
This is useful for interpreting concepts introduced through |
|
503 |
definition specification elements. The equations must be proved. |
|
504 |
Note that if equations are present, the context expression is |
|
505 |
restricted to a locale name. |
|
506 |
||
507 |
The command is aware of interpretations already active in the |
|
28085
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
508 |
theory, but does not simplify the goal automatically. In order to |
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
509 |
simplify the proof obligations use methods @{method intro_locales} |
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
510 |
or @{method unfold_locales}. Post-processing is not applied to |
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
511 |
facts of interpretations that are already active. This avoids |
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
512 |
duplication of interpreted facts, in particular. Note that, in the |
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
513 |
case of a locale with import, parts of the interpretation may |
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
514 |
already be active. The command will only process facts for new |
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
515 |
parts. |
27040 | 516 |
|
28085
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
517 |
The context expression may be preceded by a name, which takes effect |
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
518 |
in the post-processing of facts. It is used to prefix fact names, |
914183e229e9
Interpretation commands no longer accept interpretation attributes.
ballarin
parents:
27681
diff
changeset
|
519 |
for example to avoid accidental hiding of other facts. |
27040 | 520 |
|
521 |
Adding facts to locales has the effect of adding interpreted facts |
|
522 |
to the theory for all active interpretations also. That is, |
|
523 |
interpretations dynamically participate in any facts added to |
|
524 |
locales. |
|
525 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
526 |
\item @{command "interpretation"}~@{text "name \<subseteq> expr"} |
27040 | 527 |
|
528 |
This form of the command interprets @{text expr} in the locale |
|
529 |
@{text name}. It requires a proof that the specification of @{text |
|
530 |
name} implies the specification of @{text expr}. As in the |
|
531 |
localized version of the theorem command, the proof is in the |
|
532 |
context of @{text name}. After the proof obligation has been |
|
533 |
dischared, the facts of @{text expr} become part of locale @{text |
|
534 |
name} as \emph{derived} context elements and are available when the |
|
535 |
context @{text name} is subsequently entered. Note that, like |
|
536 |
import, this is dynamic: facts added to a locale part of @{text |
|
537 |
expr} after interpretation become also available in @{text name}. |
|
538 |
Like facts of renamed context elements, facts obtained by |
|
539 |
interpretation may be accessed by prefixing with the parameter |
|
540 |
renaming (where the parameters are separated by ``@{text _}''). |
|
541 |
||
542 |
Unlike interpretation in theories, instantiation is confined to the |
|
543 |
renaming of parameters, which may be specified as part of the |
|
544 |
context expression @{text expr}. Using defined parameters in @{text |
|
545 |
name} one may achieve an effect similar to instantiation, though. |
|
546 |
||
547 |
Only specification fragments of @{text expr} that are not already |
|
548 |
part of @{text name} (be it imported, derived or a derived fragment |
|
549 |
of the import) are considered by interpretation. This enables |
|
550 |
circular interpretations. |
|
551 |
||
552 |
If interpretations of @{text name} exist in the current theory, the |
|
553 |
command adds interpretations for @{text expr} as well, with the same |
|
554 |
prefix and attributes, although only for fragments of @{text expr} |
|
555 |
that are not interpreted in the theory already. |
|
556 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
557 |
\item @{command "interpret"}~@{text "expr insts \<WHERE> eqns"} |
27040 | 558 |
interprets @{text expr} in the proof context and is otherwise |
559 |
similar to interpretation in theories. |
|
560 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
561 |
\item @{command "print_interps"}~@{text loc} prints the |
27040 | 562 |
interpretations of a particular locale @{text loc} that are active |
563 |
in the current context, either theory or proof context. The |
|
564 |
exclamation point argument triggers printing of \emph{witness} |
|
565 |
theorems justifying interpretations. These are normally omitted |
|
566 |
from the output. |
|
567 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
568 |
\end{description} |
27040 | 569 |
|
570 |
\begin{warn} |
|
571 |
Since attributes are applied to interpreted theorems, |
|
572 |
interpretation may modify the context of common proof tools, e.g.\ |
|
573 |
the Simplifier or Classical Reasoner. Since the behavior of such |
|
574 |
automated reasoning tools is \emph{not} stable under |
|
575 |
interpretation morphisms, manual declarations might have to be |
|
576 |
issued. |
|
577 |
\end{warn} |
|
578 |
||
579 |
\begin{warn} |
|
580 |
An interpretation in a theory may subsume previous |
|
581 |
interpretations. This happens if the same specification fragment |
|
582 |
is interpreted twice and the instantiation of the second |
|
583 |
interpretation is more general than the interpretation of the |
|
584 |
first. A warning is issued, since it is likely that these could |
|
585 |
have been generalized in the first place. The locale package does |
|
586 |
not attempt to remove subsumed interpretations. |
|
587 |
\end{warn} |
|
588 |
*} |
|
589 |
||
590 |
||
591 |
section {* Classes \label{sec:class} *} |
|
592 |
||
593 |
text {* |
|
594 |
A class is a particular locale with \emph{exactly one} type variable |
|
595 |
@{text \<alpha>}. Beyond the underlying locale, a corresponding type class |
|
596 |
is established which is interpreted logically as axiomatic type |
|
597 |
class \cite{Wenzel:1997:TPHOL} whose logical content are the |
|
598 |
assumptions of the locale. Thus, classes provide the full |
|
599 |
generality of locales combined with the commodity of type classes |
|
600 |
(notably type-inference). See \cite{isabelle-classes} for a short |
|
601 |
tutorial. |
|
602 |
||
603 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
604 |
@{command_def "class"} & : & @{text "theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
605 |
@{command_def "instantiation"} & : & @{text "theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
606 |
@{command_def "instance"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
607 |
@{command_def "subclass"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
608 |
@{command_def "print_classes"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
609 |
@{method_def intro_classes} & : & @{text method} \\ |
27040 | 610 |
\end{matharray} |
611 |
||
612 |
\begin{rail} |
|
613 |
'class' name '=' ((superclassexpr '+' (contextelem+)) | superclassexpr | (contextelem+)) \\ |
|
614 |
'begin'? |
|
615 |
; |
|
616 |
'instantiation' (nameref + 'and') '::' arity 'begin' |
|
617 |
; |
|
618 |
'instance' |
|
619 |
; |
|
620 |
'subclass' target? nameref |
|
621 |
; |
|
622 |
'print\_classes' |
|
623 |
; |
|
624 |
||
625 |
superclassexpr: nameref | (nameref '+' superclassexpr) |
|
626 |
; |
|
627 |
\end{rail} |
|
628 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
629 |
\begin{description} |
27040 | 630 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
631 |
\item @{command "class"}~@{text "c = superclasses + body"} defines |
27040 | 632 |
a new class @{text c}, inheriting from @{text superclasses}. This |
633 |
introduces a locale @{text c} with import of all locales @{text |
|
634 |
superclasses}. |
|
635 |
||
636 |
Any @{element "fixes"} in @{text body} are lifted to the global |
|
637 |
theory level (\emph{class operations} @{text "f\<^sub>1, \<dots>, |
|
638 |
f\<^sub>n"} of class @{text c}), mapping the local type parameter |
|
639 |
@{text \<alpha>} to a schematic type variable @{text "?\<alpha> :: c"}. |
|
640 |
||
641 |
Likewise, @{element "assumes"} in @{text body} are also lifted, |
|
642 |
mapping each local parameter @{text "f :: \<tau>[\<alpha>]"} to its |
|
643 |
corresponding global constant @{text "f :: \<tau>[?\<alpha> :: c]"}. The |
|
644 |
corresponding introduction rule is provided as @{text |
|
645 |
c_class_axioms.intro}. This rule should be rarely needed directly |
|
646 |
--- the @{method intro_classes} method takes care of the details of |
|
647 |
class membership proofs. |
|
648 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
649 |
\item @{command "instantiation"}~@{text "t :: (s\<^sub>1, \<dots>, s\<^sub>n) s |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
650 |
\<BEGIN>"} opens a theory target (cf.\ \secref{sec:target}) which |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
651 |
allows to specify class operations @{text "f\<^sub>1, \<dots>, f\<^sub>n"} corresponding |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
652 |
to sort @{text s} at the particular type instance @{text "(\<alpha>\<^sub>1 :: s\<^sub>1, |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
653 |
\<dots>, \<alpha>\<^sub>n :: s\<^sub>n) t"}. A plain @{command "instance"} command in the |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
654 |
target body poses a goal stating these type arities. The target is |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
655 |
concluded by an @{command_ref (local) "end"} command. |
27040 | 656 |
|
657 |
Note that a list of simultaneous type constructors may be given; |
|
658 |
this corresponds nicely to mutual recursive type definitions, e.g.\ |
|
659 |
in Isabelle/HOL. |
|
660 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
661 |
\item @{command "instance"} in an instantiation target body sets |
27040 | 662 |
up a goal stating the type arities claimed at the opening @{command |
663 |
"instantiation"}. The proof would usually proceed by @{method |
|
664 |
intro_classes}, and then establish the characteristic theorems of |
|
665 |
the type classes involved. After finishing the proof, the |
|
666 |
background theory will be augmented by the proven type arities. |
|
667 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
668 |
\item @{command "subclass"}~@{text c} in a class context for class |
27040 | 669 |
@{text d} sets up a goal stating that class @{text c} is logically |
670 |
contained in class @{text d}. After finishing the proof, class |
|
671 |
@{text d} is proven to be subclass @{text c} and the locale @{text |
|
672 |
c} is interpreted into @{text d} simultaneously. |
|
673 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
674 |
\item @{command "print_classes"} prints all classes in the current |
27040 | 675 |
theory. |
676 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
677 |
\item @{method intro_classes} repeatedly expands all class |
27040 | 678 |
introduction rules of this theory. Note that this method usually |
679 |
needs not be named explicitly, as it is already included in the |
|
680 |
default proof step (e.g.\ of @{command "proof"}). In particular, |
|
681 |
instantiation of trivial (syntactic) classes may be performed by a |
|
682 |
single ``@{command ".."}'' proof step. |
|
26870 | 683 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
684 |
\end{description} |
26870 | 685 |
*} |
686 |
||
27040 | 687 |
|
688 |
subsection {* The class target *} |
|
689 |
||
690 |
text {* |
|
691 |
%FIXME check |
|
692 |
||
693 |
A named context may refer to a locale (cf.\ \secref{sec:target}). |
|
694 |
If this locale is also a class @{text c}, apart from the common |
|
695 |
locale target behaviour the following happens. |
|
696 |
||
697 |
\begin{itemize} |
|
698 |
||
699 |
\item Local constant declarations @{text "g[\<alpha>]"} referring to the |
|
700 |
local type parameter @{text \<alpha>} and local parameters @{text "f[\<alpha>]"} |
|
701 |
are accompanied by theory-level constants @{text "g[?\<alpha> :: c]"} |
|
702 |
referring to theory-level class operations @{text "f[?\<alpha> :: c]"}. |
|
703 |
||
704 |
\item Local theorem bindings are lifted as are assumptions. |
|
705 |
||
706 |
\item Local syntax refers to local operations @{text "g[\<alpha>]"} and |
|
707 |
global operations @{text "g[?\<alpha> :: c]"} uniformly. Type inference |
|
708 |
resolves ambiguities. In rare cases, manual type annotations are |
|
709 |
needed. |
|
710 |
||
711 |
\end{itemize} |
|
712 |
*} |
|
713 |
||
714 |
||
27053 | 715 |
subsection {* Old-style axiomatic type classes \label{sec:axclass} *} |
27040 | 716 |
|
717 |
text {* |
|
718 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
719 |
@{command_def "axclass"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
720 |
@{command_def "instance"} & : & @{text "theory \<rightarrow> proof(prove)"} \\ |
27040 | 721 |
\end{matharray} |
722 |
||
723 |
Axiomatic type classes are Isabelle/Pure's primitive |
|
724 |
\emph{definitional} interface to type classes. For practical |
|
725 |
applications, you should consider using classes |
|
726 |
(cf.~\secref{sec:classes}) which provide high level interface. |
|
727 |
||
728 |
\begin{rail} |
|
729 |
'axclass' classdecl (axmdecl prop +) |
|
730 |
; |
|
731 |
'instance' (nameref ('<' | subseteq) nameref | nameref '::' arity) |
|
732 |
; |
|
733 |
\end{rail} |
|
734 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
735 |
\begin{description} |
27040 | 736 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
737 |
\item @{command "axclass"}~@{text "c \<subseteq> c\<^sub>1, \<dots>, c\<^sub>n axms"} defines an |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
738 |
axiomatic type class as the intersection of existing classes, with |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
739 |
additional axioms holding. Class axioms may not contain more than |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
740 |
one type variable. The class axioms (with implicit sort constraints |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
741 |
added) are bound to the given names. Furthermore a class |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
742 |
introduction rule is generated (being bound as @{text |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
743 |
c_class.intro}); this rule is employed by method @{method |
27040 | 744 |
intro_classes} to support instantiation proofs of this class. |
745 |
||
746 |
The ``class axioms'' are stored as theorems according to the given |
|
747 |
name specifications, adding @{text "c_class"} as name space prefix; |
|
748 |
the same facts are also stored collectively as @{text |
|
749 |
c_class.axioms}. |
|
750 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
751 |
\item @{command "instance"}~@{text "c\<^sub>1 \<subseteq> c\<^sub>2"} and @{command |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
752 |
"instance"}~@{text "t :: (s\<^sub>1, \<dots>, s\<^sub>n) s"} setup a goal stating a |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
753 |
class relation or type arity. The proof would usually proceed by |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
754 |
@{method intro_classes}, and then establish the characteristic |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
755 |
theorems of the type classes involved. After finishing the proof, |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
756 |
the theory will be augmented by a type signature declaration |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
757 |
corresponding to the resulting theorem. |
27040 | 758 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
759 |
\end{description} |
27040 | 760 |
*} |
761 |
||
762 |
||
763 |
section {* Unrestricted overloading *} |
|
764 |
||
765 |
text {* |
|
766 |
Isabelle/Pure's definitional schemes support certain forms of |
|
767 |
overloading (see \secref{sec:consts}). At most occassions |
|
768 |
overloading will be used in a Haskell-like fashion together with |
|
769 |
type classes by means of @{command "instantiation"} (see |
|
770 |
\secref{sec:class}). Sometimes low-level overloading is desirable. |
|
771 |
The @{command "overloading"} target provides a convenient view for |
|
772 |
end-users. |
|
773 |
||
774 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
775 |
@{command_def "overloading"} & : & @{text "theory \<rightarrow> local_theory"} \\ |
27040 | 776 |
\end{matharray} |
777 |
||
778 |
\begin{rail} |
|
779 |
'overloading' \\ |
|
780 |
( string ( '==' | equiv ) term ( '(' 'unchecked' ')' )? + ) 'begin' |
|
781 |
\end{rail} |
|
782 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
783 |
\begin{description} |
27040 | 784 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
785 |
\item @{command "overloading"}~@{text "x\<^sub>1 \<equiv> c\<^sub>1 :: \<tau>\<^sub>1 \<AND> \<dots> x\<^sub>n \<equiv> c\<^sub>n :: \<tau>\<^sub>n \<BEGIN>"} |
27040 | 786 |
opens a theory target (cf.\ \secref{sec:target}) which allows to |
787 |
specify constants with overloaded definitions. These are identified |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
788 |
by an explicitly given mapping from variable names @{text "x\<^sub>i"} to |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
789 |
constants @{text "c\<^sub>i"} at particular type instances. The |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
790 |
definitions themselves are established using common specification |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
791 |
tools, using the names @{text "x\<^sub>i"} as reference to the |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
792 |
corresponding constants. The target is concluded by @{command |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
793 |
(local) "end"}. |
27040 | 794 |
|
795 |
A @{text "(unchecked)"} option disables global dependency checks for |
|
796 |
the corresponding definition, which is occasionally useful for |
|
797 |
exotic overloading. It is at the discretion of the user to avoid |
|
798 |
malformed theory specifications! |
|
799 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
800 |
\end{description} |
27040 | 801 |
*} |
802 |
||
803 |
||
804 |
section {* Incorporating ML code \label{sec:ML} *} |
|
805 |
||
806 |
text {* |
|
807 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
808 |
@{command_def "use"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
809 |
@{command_def "ML"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
810 |
@{command_def "ML_prf"} & : & @{text "proof \<rightarrow> proof"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
811 |
@{command_def "ML_val"} & : & @{text "any \<rightarrow>"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
812 |
@{command_def "ML_command"} & : & @{text "any \<rightarrow>"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
813 |
@{command_def "setup"} & : & @{text "theory \<rightarrow> theory"} \\ |
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
814 |
\end{matharray} |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
815 |
|
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
816 |
\begin{mldecls} |
28758 | 817 |
@{index_ML bind_thms: "string * thm list -> unit"} \\ |
818 |
@{index_ML bind_thm: "string * thm -> unit"} \\ |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
819 |
\end{mldecls} |
27040 | 820 |
|
821 |
\begin{rail} |
|
822 |
'use' name |
|
823 |
; |
|
28757 | 824 |
('ML' | 'ML\_prf' | 'ML\_val' | 'ML\_command' | 'setup') text |
27040 | 825 |
; |
826 |
\end{rail} |
|
827 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
828 |
\begin{description} |
27040 | 829 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
830 |
\item @{command "use"}~@{text "file"} reads and executes ML |
27040 | 831 |
commands from @{text "file"}. The current theory context is passed |
28757 | 832 |
down to the ML toplevel and may be modified, using @{ML [source=false] |
27040 | 833 |
"Context.>>"} or derived ML commands. The file name is checked with |
834 |
the @{keyword_ref "uses"} dependency declaration given in the theory |
|
835 |
header (see also \secref{sec:begin-thy}). |
|
28281 | 836 |
|
837 |
Top-level ML bindings are stored within the (global or local) theory |
|
838 |
context. |
|
27040 | 839 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
840 |
\item @{command "ML"}~@{text "text"} is similar to @{command "use"}, |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
841 |
but executes ML commands directly from the given @{text "text"}. |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
842 |
Top-level ML bindings are stored within the (global or local) theory |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
843 |
context. |
28281 | 844 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
845 |
\item @{command "ML_prf"} is analogous to @{command "ML"} but works |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
846 |
within a proof context. |
28281 | 847 |
|
848 |
Top-level ML bindings are stored within the proof context in a |
|
849 |
purely sequential fashion, disregarding the nested proof structure. |
|
850 |
ML bindings introduced by @{command "ML_prf"} are discarded at the |
|
851 |
end of the proof. |
|
27040 | 852 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
853 |
\item @{command "ML_val"} and @{command "ML_command"} are diagnostic |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
854 |
versions of @{command "ML"}, which means that the context may not be |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
855 |
updated. @{command "ML_val"} echos the bindings produced at the ML |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
856 |
toplevel, but @{command "ML_command"} is silent. |
27040 | 857 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
858 |
\item @{command "setup"}~@{text "text"} changes the current theory |
27040 | 859 |
context by applying @{text "text"}, which refers to an ML expression |
28757 | 860 |
of type @{ML_type [source=false] "theory -> theory"}. This enables |
861 |
to initialize any object-logic specific tools and packages written |
|
862 |
in ML, for example. |
|
28758 | 863 |
|
864 |
\item @{ML bind_thms}~@{text "(name, thms)"} stores a list of |
|
865 |
theorems produced in ML both in the theory context and the ML |
|
866 |
toplevel, associating it with the provided name. Theorems are put |
|
867 |
into a global ``standard'' format before being stored. |
|
868 |
||
869 |
\item @{ML bind_thm} is similar to @{ML bind_thms} but refers to a |
|
870 |
singleton theorem. |
|
27040 | 871 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
872 |
\end{description} |
27040 | 873 |
*} |
874 |
||
875 |
||
876 |
section {* Primitive specification elements *} |
|
877 |
||
878 |
subsection {* Type classes and sorts \label{sec:classes} *} |
|
879 |
||
880 |
text {* |
|
881 |
\begin{matharray}{rcll} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
882 |
@{command_def "classes"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
883 |
@{command_def "classrel"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!) \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
884 |
@{command_def "defaultsort"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
885 |
@{command_def "class_deps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
27040 | 886 |
\end{matharray} |
887 |
||
888 |
\begin{rail} |
|
889 |
'classes' (classdecl +) |
|
890 |
; |
|
891 |
'classrel' (nameref ('<' | subseteq) nameref + 'and') |
|
892 |
; |
|
893 |
'defaultsort' sort |
|
894 |
; |
|
895 |
\end{rail} |
|
896 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
897 |
\begin{description} |
27040 | 898 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
899 |
\item @{command "classes"}~@{text "c \<subseteq> c\<^sub>1, \<dots>, c\<^sub>n"} declares class |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
900 |
@{text c} to be a subclass of existing classes @{text "c\<^sub>1, \<dots>, c\<^sub>n"}. |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
901 |
Cyclic class structures are not permitted. |
27040 | 902 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
903 |
\item @{command "classrel"}~@{text "c\<^sub>1 \<subseteq> c\<^sub>2"} states subclass |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
904 |
relations between existing classes @{text "c\<^sub>1"} and @{text "c\<^sub>2"}. |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
905 |
This is done axiomatically! The @{command_ref "instance"} command |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
906 |
(see \secref{sec:axclass}) provides a way to introduce proven class |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
907 |
relations. |
27040 | 908 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
909 |
\item @{command "defaultsort"}~@{text s} makes sort @{text s} the |
27040 | 910 |
new default sort for any type variables given without sort |
911 |
constraints. Usually, the default sort would be only changed when |
|
912 |
defining a new object-logic. |
|
913 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
914 |
\item @{command "class_deps"} visualizes the subclass relation, |
27040 | 915 |
using Isabelle's graph browser tool (see also \cite{isabelle-sys}). |
916 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
917 |
\end{description} |
27040 | 918 |
*} |
919 |
||
920 |
||
921 |
subsection {* Types and type abbreviations \label{sec:types-pure} *} |
|
922 |
||
923 |
text {* |
|
924 |
\begin{matharray}{rcll} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
925 |
@{command_def "types"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
926 |
@{command_def "typedecl"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
927 |
@{command_def "nonterminals"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
928 |
@{command_def "arities"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!) \\ |
27040 | 929 |
\end{matharray} |
930 |
||
931 |
\begin{rail} |
|
932 |
'types' (typespec '=' type infix? +) |
|
933 |
; |
|
934 |
'typedecl' typespec infix? |
|
935 |
; |
|
936 |
'nonterminals' (name +) |
|
937 |
; |
|
938 |
'arities' (nameref '::' arity +) |
|
939 |
; |
|
940 |
\end{rail} |
|
941 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
942 |
\begin{description} |
27040 | 943 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
944 |
\item @{command "types"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t = \<tau>"} introduces |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
945 |
\emph{type synonym} @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"} for existing type @{text |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
946 |
"\<tau>"}. Unlike actual type definitions, as are available in |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
947 |
Isabelle/HOL for example, type synonyms are just purely syntactic |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
948 |
abbreviations without any logical significance. Internally, type |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
949 |
synonyms are fully expanded. |
27040 | 950 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
951 |
\item @{command "typedecl"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"} declares a new |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
952 |
type constructor @{text t}, intended as an actual logical type (of |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
953 |
the object-logic, if available). |
27040 | 954 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
955 |
\item @{command "nonterminals"}~@{text c} declares type constructors |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
956 |
@{text c} (without arguments) to act as purely syntactic types, |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
957 |
i.e.\ nonterminal symbols of Isabelle's inner syntax of terms or |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
958 |
types. |
27040 | 959 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
960 |
\item @{command "arities"}~@{text "t :: (s\<^sub>1, \<dots>, s\<^sub>n) s"} augments |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
961 |
Isabelle's order-sorted signature of types by new type constructor |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
962 |
arities. This is done axiomatically! The @{command_ref "instance"} |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
963 |
command (see \S\ref{sec:axclass}) provides a way to introduce proven |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
964 |
type arities. |
27040 | 965 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
966 |
\end{description} |
27040 | 967 |
*} |
968 |
||
969 |
||
970 |
subsection {* Constants and definitions \label{sec:consts} *} |
|
971 |
||
972 |
text {* |
|
973 |
Definitions essentially express abbreviations within the logic. The |
|
974 |
simplest form of a definition is @{text "c :: \<sigma> \<equiv> t"}, where @{text |
|
975 |
c} is a newly declared constant. Isabelle also allows derived forms |
|
976 |
where the arguments of @{text c} appear on the left, abbreviating a |
|
977 |
prefix of @{text \<lambda>}-abstractions, e.g.\ @{text "c \<equiv> \<lambda>x y. t"} may be |
|
978 |
written more conveniently as @{text "c x y \<equiv> t"}. Moreover, |
|
979 |
definitions may be weakened by adding arbitrary pre-conditions: |
|
980 |
@{text "A \<Longrightarrow> c x y \<equiv> t"}. |
|
981 |
||
982 |
\medskip The built-in well-formedness conditions for definitional |
|
983 |
specifications are: |
|
984 |
||
985 |
\begin{itemize} |
|
986 |
||
987 |
\item Arguments (on the left-hand side) must be distinct variables. |
|
988 |
||
989 |
\item All variables on the right-hand side must also appear on the |
|
990 |
left-hand side. |
|
991 |
||
992 |
\item All type variables on the right-hand side must also appear on |
|
993 |
the left-hand side; this prohibits @{text "0 :: nat \<equiv> length ([] :: |
|
994 |
\<alpha> list)"} for example. |
|
995 |
||
996 |
\item The definition must not be recursive. Most object-logics |
|
997 |
provide definitional principles that can be used to express |
|
998 |
recursion safely. |
|
999 |
||
1000 |
\end{itemize} |
|
1001 |
||
1002 |
Overloading means that a constant being declared as @{text "c :: \<alpha> |
|
1003 |
decl"} may be defined separately on type instances @{text "c :: |
|
1004 |
(\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n) t decl"} for each type constructor @{text |
|
1005 |
t}. The right-hand side may mention overloaded constants |
|
1006 |
recursively at type instances corresponding to the immediate |
|
1007 |
argument types @{text "\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n"}. Incomplete |
|
1008 |
specification patterns impose global constraints on all occurrences, |
|
1009 |
e.g.\ @{text "d :: \<alpha> \<times> \<alpha>"} on the left-hand side means that all |
|
1010 |
corresponding occurrences on some right-hand side need to be an |
|
1011 |
instance of this, general @{text "d :: \<alpha> \<times> \<beta>"} will be disallowed. |
|
1012 |
||
1013 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1014 |
@{command_def "consts"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1015 |
@{command_def "defs"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1016 |
@{command_def "constdefs"} & : & @{text "theory \<rightarrow> theory"} \\ |
27040 | 1017 |
\end{matharray} |
1018 |
||
1019 |
\begin{rail} |
|
1020 |
'consts' ((name '::' type mixfix?) +) |
|
1021 |
; |
|
1022 |
'defs' ('(' 'unchecked'? 'overloaded'? ')')? \\ (axmdecl prop +) |
|
1023 |
; |
|
1024 |
\end{rail} |
|
1025 |
||
1026 |
\begin{rail} |
|
1027 |
'constdefs' structs? (constdecl? constdef +) |
|
1028 |
; |
|
1029 |
||
1030 |
structs: '(' 'structure' (vars + 'and') ')' |
|
1031 |
; |
|
1032 |
constdecl: ((name '::' type mixfix | name '::' type | name mixfix) 'where'?) | name 'where' |
|
1033 |
; |
|
1034 |
constdef: thmdecl? prop |
|
1035 |
; |
|
1036 |
\end{rail} |
|
1037 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1038 |
\begin{description} |
27040 | 1039 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1040 |
\item @{command "consts"}~@{text "c :: \<sigma>"} declares constant @{text |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1041 |
c} to have any instance of type scheme @{text \<sigma>}. The optional |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1042 |
mixfix annotations may attach concrete syntax to the constants |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1043 |
declared. |
27040 | 1044 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1045 |
\item @{command "defs"}~@{text "name: eqn"} introduces @{text eqn} |
27040 | 1046 |
as a definitional axiom for some existing constant. |
1047 |
||
1048 |
The @{text "(unchecked)"} option disables global dependency checks |
|
1049 |
for this definition, which is occasionally useful for exotic |
|
1050 |
overloading. It is at the discretion of the user to avoid malformed |
|
1051 |
theory specifications! |
|
1052 |
||
1053 |
The @{text "(overloaded)"} option declares definitions to be |
|
1054 |
potentially overloaded. Unless this option is given, a warning |
|
1055 |
message would be issued for any definitional equation with a more |
|
1056 |
special type than that of the corresponding constant declaration. |
|
1057 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1058 |
\item @{command "constdefs"} provides a streamlined combination of |
27040 | 1059 |
constants declarations and definitions: type-inference takes care of |
1060 |
the most general typing of the given specification (the optional |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1061 |
type constraint may refer to type-inference dummies ``@{text _}'' as |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1062 |
usual). The resulting type declaration needs to agree with that of |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1063 |
the specification; overloading is \emph{not} supported here! |
27040 | 1064 |
|
1065 |
The constant name may be omitted altogether, if neither type nor |
|
1066 |
syntax declarations are given. The canonical name of the |
|
1067 |
definitional axiom for constant @{text c} will be @{text c_def}, |
|
1068 |
unless specified otherwise. Also note that the given list of |
|
1069 |
specifications is processed in a strictly sequential manner, with |
|
1070 |
type-checking being performed independently. |
|
1071 |
||
1072 |
An optional initial context of @{text "(structure)"} declarations |
|
1073 |
admits use of indexed syntax, using the special symbol @{verbatim |
|
1074 |
"\<index>"} (printed as ``@{text "\<index>"}''). The latter concept is |
|
1075 |
particularly useful with locales (see also \S\ref{sec:locale}). |
|
1076 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1077 |
\end{description} |
27040 | 1078 |
*} |
1079 |
||
1080 |
||
1081 |
section {* Axioms and theorems \label{sec:axms-thms} *} |
|
1082 |
||
1083 |
text {* |
|
1084 |
\begin{matharray}{rcll} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1085 |
@{command_def "axioms"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!) \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1086 |
@{command_def "lemmas"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1087 |
@{command_def "theorems"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
27040 | 1088 |
\end{matharray} |
1089 |
||
1090 |
\begin{rail} |
|
1091 |
'axioms' (axmdecl prop +) |
|
1092 |
; |
|
1093 |
('lemmas' | 'theorems') target? (thmdef? thmrefs + 'and') |
|
1094 |
; |
|
1095 |
\end{rail} |
|
1096 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1097 |
\begin{description} |
27040 | 1098 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1099 |
\item @{command "axioms"}~@{text "a: \<phi>"} introduces arbitrary |
27040 | 1100 |
statements as axioms of the meta-logic. In fact, axioms are |
1101 |
``axiomatic theorems'', and may be referred later just as any other |
|
1102 |
theorem. |
|
1103 |
||
1104 |
Axioms are usually only introduced when declaring new logical |
|
1105 |
systems. Everyday work is typically done the hard way, with proper |
|
1106 |
definitions and proven theorems. |
|
1107 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1108 |
\item @{command "lemmas"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"} retrieves and stores |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1109 |
existing facts in the theory context, or the specified target |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1110 |
context (see also \secref{sec:target}). Typical applications would |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1111 |
also involve attributes, to declare Simplifier rules, for example. |
27040 | 1112 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1113 |
\item @{command "theorems"} is essentially the same as @{command |
27040 | 1114 |
"lemmas"}, but marks the result as a different kind of facts. |
1115 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1116 |
\end{description} |
27040 | 1117 |
*} |
1118 |
||
1119 |
||
1120 |
section {* Oracles *} |
|
1121 |
||
28756 | 1122 |
text {* Oracles allow Isabelle to take advantage of external reasoners |
1123 |
such as arithmetic decision procedures, model checkers, fast |
|
1124 |
tautology checkers or computer algebra systems. Invoked as an |
|
1125 |
oracle, an external reasoner can create arbitrary Isabelle theorems. |
|
1126 |
||
1127 |
It is the responsibility of the user to ensure that the external |
|
1128 |
reasoner is as trustworthy as the application requires. Another |
|
1129 |
typical source of errors is the linkup between Isabelle and the |
|
1130 |
external tool, not just its concrete implementation, but also the |
|
1131 |
required translation between two different logical environments. |
|
1132 |
||
1133 |
Isabelle merely guarantees well-formedness of the propositions being |
|
1134 |
asserted, and records within the internal derivation object how |
|
1135 |
presumed theorems depend on unproven suppositions. |
|
1136 |
||
27040 | 1137 |
\begin{matharray}{rcl} |
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1138 |
@{command_def "oracle"} & : & @{text "theory \<rightarrow> theory"} \\ |
27040 | 1139 |
\end{matharray} |
1140 |
||
1141 |
\begin{rail} |
|
28290 | 1142 |
'oracle' name '=' text |
27040 | 1143 |
; |
1144 |
\end{rail} |
|
1145 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1146 |
\begin{description} |
27040 | 1147 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1148 |
\item @{command "oracle"}~@{text "name = text"} turns the given ML |
28290 | 1149 |
expression @{text "text"} of type @{ML_text "'a -> cterm"} into an |
1150 |
ML function of type @{ML_text "'a -> thm"}, which is bound to the |
|
28756 | 1151 |
global identifier @{ML_text name}. This acts like an infinitary |
1152 |
specification of axioms! Invoking the oracle only works within the |
|
1153 |
scope of the resulting theory. |
|
27040 | 1154 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1155 |
\end{description} |
28756 | 1156 |
|
1157 |
See @{"file" "~~/src/FOL/ex/IffOracle.thy"} for a worked example of |
|
1158 |
defining a new primitive rule as oracle, and turning it into a proof |
|
1159 |
method. |
|
27040 | 1160 |
*} |
1161 |
||
1162 |
||
1163 |
section {* Name spaces *} |
|
1164 |
||
1165 |
text {* |
|
1166 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1167 |
@{command_def "global"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1168 |
@{command_def "local"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1169 |
@{command_def "hide"} & : & @{text "theory \<rightarrow> theory"} \\ |
27040 | 1170 |
\end{matharray} |
1171 |
||
1172 |
\begin{rail} |
|
1173 |
'hide' ('(open)')? name (nameref + ) |
|
1174 |
; |
|
1175 |
\end{rail} |
|
1176 |
||
1177 |
Isabelle organizes any kind of name declarations (of types, |
|
1178 |
constants, theorems etc.) by separate hierarchically structured name |
|
1179 |
spaces. Normally the user does not have to control the behavior of |
|
1180 |
name spaces by hand, yet the following commands provide some way to |
|
1181 |
do so. |
|
1182 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1183 |
\begin{description} |
27040 | 1184 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1185 |
\item @{command "global"} and @{command "local"} change the current |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1186 |
name declaration mode. Initially, theories start in @{command |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1187 |
"local"} mode, causing all names to be automatically qualified by |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1188 |
the theory name. Changing this to @{command "global"} causes all |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1189 |
names to be declared without the theory prefix, until @{command |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1190 |
"local"} is declared again. |
27040 | 1191 |
|
1192 |
Note that global names are prone to get hidden accidently later, |
|
1193 |
when qualified names of the same base name are introduced. |
|
1194 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1195 |
\item @{command "hide"}~@{text "space names"} fully removes |
27040 | 1196 |
declarations from a given name space (which may be @{text "class"}, |
1197 |
@{text "type"}, @{text "const"}, or @{text "fact"}); with the @{text |
|
1198 |
"(open)"} option, only the base name is hidden. Global |
|
1199 |
(unqualified) names may never be hidden. |
|
1200 |
||
1201 |
Note that hiding name space accesses has no impact on logical |
|
28756 | 1202 |
declarations --- they remain valid internally. Entities that are no |
27040 | 1203 |
longer accessible to the user are printed with the special qualifier |
1204 |
``@{text "??"}'' prefixed to the full internal name. |
|
1205 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1206 |
\end{description} |
27040 | 1207 |
*} |
1208 |
||
1209 |
||
1210 |
section {* Syntax and translations \label{sec:syn-trans} *} |
|
1211 |
||
1212 |
text {* |
|
1213 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1214 |
@{command_def "syntax"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1215 |
@{command_def "no_syntax"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1216 |
@{command_def "translations"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1217 |
@{command_def "no_translations"} & : & @{text "theory \<rightarrow> theory"} \\ |
27040 | 1218 |
\end{matharray} |
1219 |
||
1220 |
\begin{rail} |
|
1221 |
('syntax' | 'no\_syntax') mode? (constdecl +) |
|
1222 |
; |
|
1223 |
('translations' | 'no\_translations') (transpat ('==' | '=>' | '<=' | rightleftharpoons | rightharpoonup | leftharpoondown) transpat +) |
|
1224 |
; |
|
1225 |
||
1226 |
mode: ('(' ( name | 'output' | name 'output' ) ')') |
|
1227 |
; |
|
1228 |
transpat: ('(' nameref ')')? string |
|
1229 |
; |
|
1230 |
\end{rail} |
|
1231 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1232 |
\begin{description} |
27040 | 1233 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1234 |
\item @{command "syntax"}~@{text "(mode) decls"} is similar to |
27040 | 1235 |
@{command "consts"}~@{text decls}, except that the actual logical |
1236 |
signature extension is omitted. Thus the context free grammar of |
|
1237 |
Isabelle's inner syntax may be augmented in arbitrary ways, |
|
1238 |
independently of the logic. The @{text mode} argument refers to the |
|
1239 |
print mode that the grammar rules belong; unless the @{keyword_ref |
|
1240 |
"output"} indicator is given, all productions are added both to the |
|
1241 |
input and output grammar. |
|
1242 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1243 |
\item @{command "no_syntax"}~@{text "(mode) decls"} removes grammar |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1244 |
declarations (and translations) resulting from @{text decls}, which |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1245 |
are interpreted in the same manner as for @{command "syntax"} above. |
27040 | 1246 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1247 |
\item @{command "translations"}~@{text rules} specifies syntactic |
27040 | 1248 |
translation rules (i.e.\ macros): parse~/ print rules (@{text "\<rightleftharpoons>"}), |
1249 |
parse rules (@{text "\<rightharpoonup>"}), or print rules (@{text "\<leftharpoondown>"}). |
|
1250 |
Translation patterns may be prefixed by the syntactic category to be |
|
1251 |
used for parsing; the default is @{text logic}. |
|
1252 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1253 |
\item @{command "no_translations"}~@{text rules} removes syntactic |
27040 | 1254 |
translation rules, which are interpreted in the same manner as for |
1255 |
@{command "translations"} above. |
|
1256 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1257 |
\end{description} |
27040 | 1258 |
*} |
1259 |
||
1260 |
||
1261 |
section {* Syntax translation functions *} |
|
1262 |
||
1263 |
text {* |
|
1264 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1265 |
@{command_def "parse_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1266 |
@{command_def "parse_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1267 |
@{command_def "print_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1268 |
@{command_def "typed_print_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1269 |
@{command_def "print_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
27040 | 1270 |
\end{matharray} |
1271 |
||
1272 |
\begin{rail} |
|
1273 |
( 'parse\_ast\_translation' | 'parse\_translation' | 'print\_translation' | |
|
1274 |
'typed\_print\_translation' | 'print\_ast\_translation' ) ('(advanced)')? text |
|
1275 |
; |
|
1276 |
\end{rail} |
|
1277 |
||
1278 |
Syntax translation functions written in ML admit almost arbitrary |
|
1279 |
manipulations of Isabelle's inner syntax. Any of the above commands |
|
1280 |
have a single \railqtok{text} argument that refers to an ML |
|
1281 |
expression of appropriate type, which are as follows by default: |
|
1282 |
||
1283 |
%FIXME proper antiquotations |
|
1284 |
\begin{ttbox} |
|
1285 |
val parse_ast_translation : (string * (ast list -> ast)) list |
|
1286 |
val parse_translation : (string * (term list -> term)) list |
|
1287 |
val print_translation : (string * (term list -> term)) list |
|
1288 |
val typed_print_translation : |
|
1289 |
(string * (bool -> typ -> term list -> term)) list |
|
1290 |
val print_ast_translation : (string * (ast list -> ast)) list |
|
1291 |
\end{ttbox} |
|
1292 |
||
1293 |
If the @{text "(advanced)"} option is given, the corresponding |
|
1294 |
translation functions may depend on the current theory or proof |
|
1295 |
context. This allows to implement advanced syntax mechanisms, as |
|
1296 |
translations functions may refer to specific theory declarations or |
|
1297 |
auxiliary proof data. |
|
1298 |
||
1299 |
See also \cite[\S8]{isabelle-ref} for more information on the |
|
1300 |
general concept of syntax transformations in Isabelle. |
|
1301 |
||
1302 |
%FIXME proper antiquotations |
|
1303 |
\begin{ttbox} |
|
1304 |
val parse_ast_translation: |
|
27046 | 1305 |
(string * (Proof.context -> ast list -> ast)) list |
27040 | 1306 |
val parse_translation: |
27046 | 1307 |
(string * (Proof.context -> term list -> term)) list |
27040 | 1308 |
val print_translation: |
27046 | 1309 |
(string * (Proof.context -> term list -> term)) list |
27040 | 1310 |
val typed_print_translation: |
27046 | 1311 |
(string * (Proof.context -> bool -> typ -> term list -> term)) list |
27040 | 1312 |
val print_ast_translation: |
27046 | 1313 |
(string * (Proof.context -> ast list -> ast)) list |
27040 | 1314 |
\end{ttbox} |
1315 |
*} |
|
1316 |
||
26869 | 1317 |
end |