author | blanchet |
Thu, 11 Sep 2014 18:54:36 +0200 | |
changeset 58305 | 57752a91eec4 |
parent 58202 | be1d10595b7b |
child 58316 | 18e6cb6a5297 |
permissions | -rw-r--r-- |
26869 | 1 |
theory Spec |
42651 | 2 |
imports Base Main |
26869 | 3 |
begin |
4 |
||
42936 | 5 |
chapter {* Specifications *} |
26869 | 6 |
|
29745 | 7 |
text {* |
8 |
The Isabelle/Isar theory format integrates specifications and |
|
9 |
proofs, supporting interactive development with unlimited undo |
|
10 |
operation. There is an integrated document preparation system (see |
|
11 |
\chref{ch:document-prep}), for typesetting formal developments |
|
12 |
together with informal text. The resulting hyper-linked PDF |
|
13 |
documents can be used both for WWW presentation and printed copies. |
|
14 |
||
15 |
The Isar proof language (see \chref{ch:proofs}) is embedded into the |
|
16 |
theory language as a proper sub-language. Proof mode is entered by |
|
17 |
stating some @{command theorem} or @{command lemma} at the theory |
|
18 |
level, and left again with the final conclusion (e.g.\ via @{command |
|
19 |
qed}). Some theory specification mechanisms also require a proof, |
|
20 |
such as @{command typedef} in HOL, which demands non-emptiness of |
|
21 |
the representing sets. |
|
22 |
*} |
|
23 |
||
24 |
||
26870 | 25 |
section {* Defining theories \label{sec:begin-thy} *} |
26 |
||
27 |
text {* |
|
28 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
29 |
@{command_def "theory"} & : & @{text "toplevel \<rightarrow> theory"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
30 |
@{command_def (global) "end"} & : & @{text "theory \<rightarrow> toplevel"} \\ |
26870 | 31 |
\end{matharray} |
32 |
||
28745 | 33 |
Isabelle/Isar theories are defined via theory files, which may |
34 |
contain both specifications and proofs; occasionally definitional |
|
35 |
mechanisms also require some explicit proof. The theory body may be |
|
36 |
sub-structured by means of \emph{local theory targets}, such as |
|
37 |
@{command "locale"} and @{command "class"}. |
|
26870 | 38 |
|
28745 | 39 |
The first proper command of a theory is @{command "theory"}, which |
40 |
indicates imports of previous theories and optional dependencies on |
|
41 |
other source files (usually in ML). Just preceding the initial |
|
42 |
@{command "theory"} command there may be an optional @{command |
|
43 |
"header"} declaration, which is only relevant to document |
|
44 |
preparation: see also the other section markup commands in |
|
45 |
\secref{sec:markup}. |
|
46 |
||
47 |
A theory is concluded by a final @{command (global) "end"} command, |
|
48 |
one that does not belong to a local theory target. No further |
|
49 |
commands may follow such a global @{command (global) "end"}, |
|
50 |
although some user-interfaces might pretend that trailing input is |
|
51 |
admissible. |
|
26870 | 52 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
53 |
@{rail \<open> |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54049
diff
changeset
|
54 |
@@{command theory} @{syntax name} imports keywords? \<newline> @'begin' |
26870 | 55 |
; |
47114
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
56 |
imports: @'imports' (@{syntax name} +) |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
57 |
; |
50128
599c935aac82
alternative completion for outer syntax keywords;
wenzelm
parents:
49243
diff
changeset
|
58 |
keywords: @'keywords' (keyword_decls + @'and') |
599c935aac82
alternative completion for outer syntax keywords;
wenzelm
parents:
49243
diff
changeset
|
59 |
; |
599c935aac82
alternative completion for outer syntax keywords;
wenzelm
parents:
49243
diff
changeset
|
60 |
keyword_decls: (@{syntax string} +) |
599c935aac82
alternative completion for outer syntax keywords;
wenzelm
parents:
49243
diff
changeset
|
61 |
('::' @{syntax name} @{syntax tags})? ('==' @{syntax name})? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
62 |
\<close>} |
26870 | 63 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
64 |
\begin{description} |
26870 | 65 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
66 |
\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
|
67 |
starts a new theory @{text A} based on the merge of existing |
47114
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
68 |
theories @{text "B\<^sub>1 \<dots> B\<^sub>n"}. Due to the possibility to import more |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
69 |
than one ancestor, the resulting theory structure of an Isabelle |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
70 |
session forms a directed acyclic graph (DAG). Isabelle takes care |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
71 |
that sources contributing to the development graph are always |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
72 |
up-to-date: changed files are automatically rechecked whenever a |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
73 |
theory header specification is processed. |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
74 |
|
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
75 |
The optional @{keyword_def "keywords"} specification declares outer |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
76 |
syntax (\chref{ch:outer-syntax}) that is introduced in this theory |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
77 |
later on (rare in end-user applications). Both minor keywords and |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
78 |
major keywords of the Isar command language need to be specified, in |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
79 |
order to make parsing of proof documents work properly. Command |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
80 |
keywords need to be classified according to their structural role in |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
81 |
the formal text. Examples may be seen in Isabelle/HOL sources |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
82 |
itself, such as @{keyword "keywords"}~@{verbatim "\"typedef\""} |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
83 |
@{text ":: thy_goal"} or @{keyword "keywords"}~@{verbatim |
58305
57752a91eec4
renamed 'datatype' to 'old_datatype'; 'datatype' is now alias for 'datatype_new'
blanchet
parents:
58202
diff
changeset
|
84 |
"\"old_datatype\""} @{text ":: thy_decl"} for theory-level declarations |
47114
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
85 |
with and without proof, respectively. Additional @{syntax tags} |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
86 |
provide defaults for document preparation (\secref{sec:tags}). |
50128
599c935aac82
alternative completion for outer syntax keywords;
wenzelm
parents:
49243
diff
changeset
|
87 |
|
599c935aac82
alternative completion for outer syntax keywords;
wenzelm
parents:
49243
diff
changeset
|
88 |
It is possible to specify an alternative completion via @{text "== |
599c935aac82
alternative completion for outer syntax keywords;
wenzelm
parents:
49243
diff
changeset
|
89 |
text"}, while the default is the corresponding keyword name. |
26870 | 90 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
91 |
\item @{command (global) "end"} concludes the current theory |
47114
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
92 |
definition. Note that some other commands, e.g.\ local theory |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
93 |
targets @{command locale} or @{command class} may involve a |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
94 |
@{keyword "begin"} that needs to be matched by @{command (local) |
7c9e31ffcd9e
updated theory header syntax and related details;
wenzelm
parents:
46999
diff
changeset
|
95 |
"end"}, according to the usual rules for nested blocks. |
27040 | 96 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
97 |
\end{description} |
27040 | 98 |
*} |
99 |
||
100 |
||
101 |
section {* Local theory targets \label{sec:target} *} |
|
102 |
||
47483 | 103 |
text {* |
104 |
\begin{matharray}{rcll} |
|
105 |
@{command_def "context"} & : & @{text "theory \<rightarrow> local_theory"} \\ |
|
106 |
@{command_def (local) "end"} & : & @{text "local_theory \<rightarrow> theory"} \\ |
|
107 |
\end{matharray} |
|
108 |
||
109 |
A local theory target is a context managed separately within the |
|
110 |
enclosing theory. Contexts may introduce parameters (fixed |
|
27040 | 111 |
variables) and assumptions (hypotheses). Definitions and theorems |
47482
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
112 |
depending on the context may be added incrementally later on. |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
113 |
|
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
114 |
\emph{Named contexts} refer to locales (cf.\ \secref{sec:locale}) or |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
115 |
type classes (cf.\ \secref{sec:class}); the name ``@{text "-"}'' |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
116 |
signifies the global theory context. |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
117 |
|
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
118 |
\emph{Unnamed contexts} may introduce additional parameters and |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
119 |
assumptions, and results produced in the context are generalized |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
120 |
accordingly. Such auxiliary contexts may be nested within other |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
121 |
targets, like @{command "locale"}, @{command "class"}, @{command |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
122 |
"instantiation"}, @{command "overloading"}. |
27040 | 123 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
124 |
@{rail \<open> |
47484 | 125 |
@@{command context} @{syntax nameref} @'begin' |
27040 | 126 |
; |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
127 |
@@{command context} @{syntax_ref "includes"}? (@{syntax context_elem} * ) @'begin' |
47484 | 128 |
; |
46999 | 129 |
@{syntax_def target}: '(' @'in' @{syntax nameref} ')' |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
130 |
\<close>} |
27040 | 131 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
132 |
\begin{description} |
27040 | 133 |
|
47482
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
134 |
\item @{command "context"}~@{text "c \<BEGIN>"} opens a named |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
135 |
context, by recommencing an existing locale or class @{text c}. |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
136 |
Note that locale and class definitions allow to include the |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
137 |
@{keyword "begin"} keyword as well, in order to continue the local |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
138 |
theory immediately after the initial specification. |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
139 |
|
47484 | 140 |
\item @{command "context"}~@{text "bundles elements \<BEGIN>"} opens |
141 |
an unnamed context, by extending the enclosing global or local |
|
142 |
theory target by the given declaration bundles (\secref{sec:bundle}) |
|
143 |
and context elements (@{text "\<FIXES>"}, @{text "\<ASSUMES>"} |
|
144 |
etc.). This means any results stemming from definitions and proofs |
|
145 |
in the extended context will be exported into the enclosing target |
|
146 |
by lifting over extra parameters and premises. |
|
27040 | 147 |
|
47482
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
148 |
\item @{command (local) "end"} concludes the current local theory, |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
149 |
according to the nesting of contexts. Note that a global @{command |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
150 |
(global) "end"} has a different meaning: it concludes the theory |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
151 |
itself (\secref{sec:begin-thy}). |
27040 | 152 |
|
29745 | 153 |
\item @{text "("}@{keyword_def "in"}~@{text "c)"} given after any |
154 |
local theory command specifies an immediate target, e.g.\ |
|
155 |
``@{command "definition"}~@{text "(\<IN> c) \<dots>"}'' or ``@{command |
|
27040 | 156 |
"theorem"}~@{text "(\<IN> c) \<dots>"}''. This works both in a local or |
157 |
global theory context; the current target context will be suspended |
|
158 |
for this command only. Note that ``@{text "(\<IN> -)"}'' will |
|
159 |
always produce a global result independently of the current target |
|
160 |
context. |
|
161 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
162 |
\end{description} |
27040 | 163 |
|
164 |
The exact meaning of results produced within a local theory context |
|
165 |
depends on the underlying target infrastructure (locale, type class |
|
166 |
etc.). The general idea is as follows, considering a context named |
|
167 |
@{text c} with parameter @{text x} and assumption @{text "A[x]"}. |
|
168 |
||
169 |
Definitions are exported by introducing a global version with |
|
170 |
additional arguments; a syntactic abbreviation links the long form |
|
171 |
with the abstract version of the target context. For example, |
|
172 |
@{text "a \<equiv> t[x]"} becomes @{text "c.a ?x \<equiv> t[?x]"} at the theory |
|
173 |
level (for arbitrary @{text "?x"}), together with a local |
|
174 |
abbreviation @{text "c \<equiv> c.a x"} in the target context (for the |
|
175 |
fixed parameter @{text x}). |
|
176 |
||
177 |
Theorems are exported by discharging the assumptions and |
|
178 |
generalizing the parameters of the context. For example, @{text "a: |
|
179 |
B[x]"} becomes @{text "c.a: A[?x] \<Longrightarrow> B[?x]"}, again for arbitrary |
|
180 |
@{text "?x"}. |
|
47482
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
181 |
|
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
182 |
\medskip The Isabelle/HOL library contains numerous applications of |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
183 |
locales and classes, e.g.\ see @{file "~~/src/HOL/Algebra"}. An |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
184 |
example for an unnamed auxiliary contexts is given in @{file |
a83b25e5bad3
some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents:
47114
diff
changeset
|
185 |
"~~/src/HOL/Isar_Examples/Group_Context.thy"}. *} |
27040 | 186 |
|
187 |
||
47484 | 188 |
section {* Bundled declarations \label{sec:bundle} *} |
189 |
||
190 |
text {* |
|
191 |
\begin{matharray}{rcl} |
|
192 |
@{command_def "bundle"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
193 |
@{command_def "print_bundles"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow> "} \\ |
|
194 |
@{command_def "include"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\ |
|
195 |
@{command_def "including"} & : & @{text "proof(prove) \<rightarrow> proof(prove)"} \\ |
|
196 |
@{keyword_def "includes"} & : & syntax \\ |
|
197 |
\end{matharray} |
|
198 |
||
199 |
The outer syntax of fact expressions (\secref{sec:syn-att}) involves |
|
200 |
theorems and attributes, which are evaluated in the context and |
|
201 |
applied to it. Attributes may declare theorems to the context, as |
|
202 |
in @{text "this_rule [intro] that_rule [elim]"} for example. |
|
203 |
Configuration options (\secref{sec:config}) are special declaration |
|
204 |
attributes that operate on the context without a theorem, as in |
|
205 |
@{text "[[show_types = false]]"} for example. |
|
206 |
||
207 |
Expressions of this form may be defined as \emph{bundled |
|
208 |
declarations} in the context, and included in other situations later |
|
209 |
on. Including declaration bundles augments a local context casually |
|
210 |
without logical dependencies, which is in contrast to locales and |
|
211 |
locale interpretation (\secref{sec:locale}). |
|
212 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
213 |
@{rail \<open> |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54049
diff
changeset
|
214 |
@@{command bundle} @{syntax target}? \<newline> |
47484 | 215 |
@{syntax name} '=' @{syntax thmrefs} (@'for' (@{syntax vars} + @'and'))? |
216 |
; |
|
217 |
(@@{command include} | @@{command including}) (@{syntax nameref}+) |
|
218 |
; |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
219 |
@{syntax_def "includes"}: @'includes' (@{syntax nameref}+) |
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
220 |
\<close>} |
47484 | 221 |
|
222 |
\begin{description} |
|
223 |
||
224 |
\item @{command bundle}~@{text "b = decls"} defines a bundle of |
|
225 |
declarations in the current context. The RHS is similar to the one |
|
226 |
of the @{command declare} command. Bundles defined in local theory |
|
227 |
targets are subject to transformations via morphisms, when moved |
|
228 |
into different application contexts; this works analogously to any |
|
229 |
other local theory specification. |
|
230 |
||
231 |
\item @{command print_bundles} prints the named bundles that are |
|
232 |
available in the current context. |
|
233 |
||
234 |
\item @{command include}~@{text "b\<^sub>1 \<dots> b\<^sub>n"} includes the declarations |
|
235 |
from the given bundles into the current proof body context. This is |
|
236 |
analogous to @{command "note"} (\secref{sec:proof-facts}) with the |
|
237 |
expanded bundles. |
|
238 |
||
239 |
\item @{command including} is similar to @{command include}, but |
|
240 |
works in proof refinement (backward mode). This is analogous to |
|
241 |
@{command "using"} (\secref{sec:proof-facts}) with the expanded |
|
242 |
bundles. |
|
243 |
||
244 |
\item @{keyword "includes"}~@{text "b\<^sub>1 \<dots> b\<^sub>n"} is similar to |
|
245 |
@{command include}, but works in situations where a specification |
|
246 |
context is constructed, notably for @{command context} and long |
|
247 |
statements of @{command theorem} etc. |
|
248 |
||
249 |
\end{description} |
|
250 |
||
251 |
Here is an artificial example of bundling various configuration |
|
252 |
options: *} |
|
253 |
||
53536
69c943125fd3
do not expose internal flags to attribute name space;
wenzelm
parents:
53370
diff
changeset
|
254 |
bundle trace = [[simp_trace, linarith_trace, metis_trace, smt_trace]] |
47484 | 255 |
|
256 |
lemma "x = x" |
|
257 |
including trace by metis |
|
258 |
||
259 |
||
57487 | 260 |
section {* Term definitions \label{sec:term-definitions} *} |
27040 | 261 |
|
262 |
text {* |
|
263 |
\begin{matharray}{rcll} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
264 |
@{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
|
265 |
@{attribute_def "defn"} & : & @{text attribute} \\ |
51585 | 266 |
@{command_def "print_defn_rules"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow> "} \\ |
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
267 |
@{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
|
268 |
@{command_def "print_abbrevs"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow> "} \\ |
27040 | 269 |
\end{matharray} |
270 |
||
57487 | 271 |
Term definitions may either happen within the logic (as equational axioms |
272 |
of a certain form, see also see \secref{sec:consts}), or outside of it as |
|
273 |
rewrite system on abstract syntax. The second form is called |
|
274 |
``abbreviation''. |
|
27040 | 275 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
276 |
@{rail \<open> |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54049
diff
changeset
|
277 |
@@{command definition} @{syntax target}? \<newline> |
42704 | 278 |
(decl @'where')? @{syntax thmdecl}? @{syntax prop} |
27040 | 279 |
; |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54049
diff
changeset
|
280 |
@@{command abbreviation} @{syntax target}? @{syntax mode}? \<newline> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
281 |
(decl @'where')? @{syntax prop} |
27040 | 282 |
; |
283 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
284 |
decl: @{syntax name} ('::' @{syntax type})? @{syntax mixfix}? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
285 |
\<close>} |
27040 | 286 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
287 |
\begin{description} |
27040 | 288 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
289 |
\item @{command "definition"}~@{text "c \<WHERE> eq"} produces an |
27040 | 290 |
internal definition @{text "c \<equiv> t"} according to the specification |
291 |
given as @{text eq}, which is then turned into a proven fact. The |
|
292 |
given proposition may deviate from internal meta-level equality |
|
293 |
according to the rewrite rules declared as @{attribute defn} by the |
|
294 |
object-logic. This usually covers object-level equality @{text "x = |
|
295 |
y"} and equivalence @{text "A \<leftrightarrow> B"}. End-users normally need not |
|
296 |
change the @{attribute defn} setup. |
|
297 |
||
298 |
Definitions may be presented with explicit arguments on the LHS, as |
|
299 |
well as additional conditions, e.g.\ @{text "f x y = t"} instead of |
|
300 |
@{text "f \<equiv> \<lambda>x y. t"} and @{text "y \<noteq> 0 \<Longrightarrow> g x y = u"} instead of an |
|
301 |
unrestricted @{text "g \<equiv> \<lambda>x y. u"}. |
|
51585 | 302 |
|
303 |
\item @{command "print_defn_rules"} prints the definitional rewrite rules |
|
304 |
declared via @{attribute defn} in the current context. |
|
305 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
306 |
\item @{command "abbreviation"}~@{text "c \<WHERE> eq"} introduces a |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
307 |
syntactic constant which is associated with a certain term according |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
308 |
to the meta-level equality @{text eq}. |
27040 | 309 |
|
310 |
Abbreviations participate in the usual type-inference process, but |
|
311 |
are expanded before the logic ever sees them. Pretty printing of |
|
312 |
terms involves higher-order rewriting with rules stemming from |
|
313 |
reverted abbreviations. This needs some care to avoid overlapping |
|
314 |
or looping syntactic replacements! |
|
315 |
||
316 |
The optional @{text mode} specification restricts output to a |
|
317 |
particular print mode; using ``@{text input}'' here achieves the |
|
318 |
effect of one-way abbreviations. The mode may also include an |
|
319 |
``@{keyword "output"}'' qualifier that affects the concrete syntax |
|
320 |
declared for abbreviations, cf.\ @{command "syntax"} in |
|
321 |
\secref{sec:syn-trans}. |
|
322 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
323 |
\item @{command "print_abbrevs"} prints all constant abbreviations |
27040 | 324 |
of the current context. |
325 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
326 |
\end{description} |
27040 | 327 |
*} |
328 |
||
329 |
||
57487 | 330 |
section {* Axiomatizations \label{sec:axiomatizations} *} |
331 |
||
332 |
text {* |
|
333 |
\begin{matharray}{rcll} |
|
334 |
@{command_def "axiomatization"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!) \\ |
|
335 |
\end{matharray} |
|
336 |
||
337 |
@{rail \<open> |
|
338 |
@@{command axiomatization} @{syntax "fixes"}? (@'where' specs)? |
|
339 |
; |
|
340 |
||
341 |
@{syntax_def "fixes"}: ((@{syntax name} ('::' @{syntax type})? |
|
342 |
@{syntax mixfix}? | @{syntax vars}) + @'and') |
|
343 |
; |
|
344 |
specs: (@{syntax thmdecl}? @{syntax props} + @'and') |
|
345 |
\<close>} |
|
346 |
||
347 |
\begin{description} |
|
348 |
||
349 |
\item @{command "axiomatization"}~@{text "c\<^sub>1 \<dots> c\<^sub>m \<WHERE> \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"} |
|
350 |
introduces several constants simultaneously and states axiomatic |
|
351 |
properties for these. The constants are marked as being specified once and |
|
352 |
for all, which prevents additional specifications for the same constants |
|
353 |
later on, but it is always possible do emit axiomatizations without |
|
354 |
referring to particular constants. Note that lack of precise dependency |
|
355 |
tracking of axiomatizations may disrupt the well-formedness of an |
|
356 |
otherwise definitional theory. |
|
357 |
||
358 |
Axiomatization is restricted to a global theory context: support for local |
|
359 |
theory targets \secref{sec:target} would introduce an extra dimension of |
|
360 |
uncertainty what the written specifications really are, and make it |
|
361 |
infeasible to argue why they are correct. |
|
362 |
||
363 |
Axiomatic specifications are required when declaring a new logical system |
|
364 |
within Isabelle/Pure, but in an application environment like Isabelle/HOL |
|
365 |
the user normally stays within definitional mechanisms provided by the |
|
366 |
logic and its libraries. |
|
367 |
||
368 |
\end{description} |
|
369 |
*} |
|
370 |
||
371 |
||
27040 | 372 |
section {* Generic declarations *} |
373 |
||
374 |
text {* |
|
47483 | 375 |
\begin{matharray}{rcl} |
376 |
@{command_def "declaration"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
377 |
@{command_def "syntax_declaration"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
378 |
@{command_def "declare"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
379 |
\end{matharray} |
|
380 |
||
27040 | 381 |
Arbitrary operations on the background context may be wrapped-up as |
382 |
generic declaration elements. Since the underlying concept of local |
|
383 |
theories may be subject to later re-interpretation, there is an |
|
384 |
additional dependency on a morphism that tells the difference of the |
|
385 |
original declaration context wrt.\ the application context |
|
386 |
encountered later on. A fact declaration is an important special |
|
387 |
case: it consists of a theorem which is applied to the context by |
|
388 |
means of an attribute. |
|
389 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
390 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
391 |
(@@{command declaration} | @@{command syntax_declaration}) |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54049
diff
changeset
|
392 |
('(' @'pervasive' ')')? \<newline> @{syntax target}? @{syntax text} |
27040 | 393 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
394 |
@@{command declare} @{syntax target}? (@{syntax thmrefs} + @'and') |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
395 |
\<close>} |
27040 | 396 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
397 |
\begin{description} |
27040 | 398 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
399 |
\item @{command "declaration"}~@{text d} adds the declaration |
27040 | 400 |
function @{text d} of ML type @{ML_type declaration}, to the current |
401 |
local theory under construction. In later application contexts, the |
|
402 |
function is transformed according to the morphisms being involved in |
|
403 |
the interpretation hierarchy. |
|
404 |
||
33516 | 405 |
If the @{text "(pervasive)"} option is given, the corresponding |
406 |
declaration is applied to all possible contexts involved, including |
|
407 |
the global background theory. |
|
408 |
||
40784 | 409 |
\item @{command "syntax_declaration"} is similar to @{command |
410 |
"declaration"}, but is meant to affect only ``syntactic'' tools by |
|
411 |
convention (such as notation and type-checking information). |
|
412 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
413 |
\item @{command "declare"}~@{text thms} declares theorems to the |
27040 | 414 |
current local theory context. No theorem binding is involved here, |
415 |
unlike @{command "theorems"} or @{command "lemmas"} (cf.\ |
|
51313 | 416 |
\secref{sec:theorems}), so @{command "declare"} only has the effect |
27040 | 417 |
of applying attributes as included in the theorem specification. |
418 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
419 |
\end{description} |
27040 | 420 |
*} |
421 |
||
422 |
||
423 |
section {* Locales \label{sec:locale} *} |
|
424 |
||
425 |
text {* |
|
54049 | 426 |
A locale is a functor that maps parameters (including implicit type |
427 |
parameters) and a specification to a list of declarations. The |
|
428 |
syntax of locales is modeled after the Isar proof context commands |
|
429 |
(cf.\ \secref{sec:proof-context}). |
|
430 |
||
431 |
Locale hierarchies are supported by maintaining a graph of |
|
432 |
dependencies between locale instances in the global theory. |
|
433 |
Dependencies may be introduced through import (where a locale is |
|
434 |
defined as sublocale of the imported instances) or by proving that |
|
435 |
an existing locale is a sublocale of one or several locale |
|
436 |
instances. |
|
437 |
||
438 |
A locale may be opened with the purpose of appending to its list of |
|
439 |
declarations (cf.\ \secref{sec:target}). When opening a locale |
|
440 |
declarations from all dependencies are collected and are presented |
|
441 |
as a local theory. In this process, which is called \emph{roundup}, |
|
442 |
redundant locale instances are omitted. A locale instance is |
|
443 |
redundant if it is subsumed by an instance encountered earlier. A |
|
444 |
more detailed description of this process is available elsewhere |
|
55117 | 445 |
\cite{Ballarin2014}. |
27040 | 446 |
*} |
447 |
||
448 |
||
33846 | 449 |
subsection {* Locale expressions \label{sec:locale-expr} *} |
450 |
||
451 |
text {* |
|
54049 | 452 |
A \emph{locale expression} denotes a context composed of instances |
453 |
of existing locales. The context consists of the declaration |
|
454 |
elements from the locale instances. Redundant locale instances are |
|
455 |
omitted according to roundup. |
|
33846 | 456 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
457 |
@{rail \<open> |
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
458 |
@{syntax_def locale_expr}: (instance + '+') (@'for' (@{syntax "fixes"} + @'and'))? |
33846 | 459 |
; |
42617 | 460 |
instance: (qualifier ':')? @{syntax nameref} (pos_insts | named_insts) |
33846 | 461 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
462 |
qualifier: @{syntax name} ('?' | '!')? |
33846 | 463 |
; |
42617 | 464 |
pos_insts: ('_' | @{syntax term})* |
33846 | 465 |
; |
42617 | 466 |
named_insts: @'where' (@{syntax name} '=' @{syntax term} + @'and') |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
467 |
\<close>} |
33846 | 468 |
|
469 |
A locale instance consists of a reference to a locale and either |
|
470 |
positional or named parameter instantiations. Identical |
|
54049 | 471 |
instantiations (that is, those that instantiate a parameter by itself) |
40256 | 472 |
may be omitted. The notation `@{text "_"}' enables to omit the |
473 |
instantiation for a parameter inside a positional instantiation. |
|
33846 | 474 |
|
475 |
Terms in instantiations are from the context the locale expressions |
|
476 |
is declared in. Local names may be added to this context with the |
|
48824
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
477 |
optional @{keyword "for"} clause. This is useful for shadowing names |
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
478 |
bound in outer contexts, and for declaring syntax. In addition, |
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
479 |
syntax declarations from one instance are effective when parsing |
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
480 |
subsequent instances of the same expression. |
33846 | 481 |
|
482 |
Instances have an optional qualifier which applies to names in |
|
483 |
declarations. Names include local definitions and theorem names. |
|
484 |
If present, the qualifier itself is either optional |
|
485 |
(``\texttt{?}''), which means that it may be omitted on input of the |
|
486 |
qualified name, or mandatory (``\texttt{!}''). If neither |
|
487 |
``\texttt{?}'' nor ``\texttt{!}'' are present, the command's default |
|
488 |
is used. For @{command "interpretation"} and @{command "interpret"} |
|
489 |
the default is ``mandatory'', for @{command "locale"} and @{command |
|
54049 | 490 |
"sublocale"} the default is ``optional''. Qualifiers play no role |
491 |
in determining whether one locale instance subsumes another. |
|
33846 | 492 |
*} |
493 |
||
494 |
||
495 |
subsection {* Locale declarations *} |
|
27040 | 496 |
|
497 |
text {* |
|
498 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
499 |
@{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
|
500 |
@{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
|
501 |
@{command_def "print_locales"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
50716 | 502 |
@{command_def "locale_deps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
503 |
@{method_def intro_locales} & : & @{text method} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
504 |
@{method_def unfold_locales} & : & @{text method} \\ |
27040 | 505 |
\end{matharray} |
506 |
||
507 |
\indexisarelem{fixes}\indexisarelem{constrains}\indexisarelem{assumes} |
|
28787 | 508 |
\indexisarelem{defines}\indexisarelem{notes} |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
509 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
510 |
@@{command locale} @{syntax name} ('=' @{syntax locale})? @'begin'? |
27040 | 511 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
512 |
@@{command print_locale} '!'? @{syntax nameref} |
27040 | 513 |
; |
42617 | 514 |
@{syntax_def locale}: @{syntax context_elem}+ | |
515 |
@{syntax locale_expr} ('+' (@{syntax context_elem}+))? |
|
27040 | 516 |
; |
42617 | 517 |
@{syntax_def context_elem}: |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
518 |
@'fixes' (@{syntax "fixes"} + @'and') | |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
519 |
@'constrains' (@{syntax name} '::' @{syntax type} + @'and') | |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
520 |
@'assumes' (@{syntax props} + @'and') | |
42705 | 521 |
@'defines' (@{syntax thmdecl}? @{syntax prop} @{syntax prop_pat}? + @'and') | |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
522 |
@'notes' (@{syntax thmdef}? @{syntax thmrefs} + @'and') |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
523 |
\<close>} |
27040 | 524 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
525 |
\begin{description} |
27040 | 526 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
527 |
\item @{command "locale"}~@{text "loc = import + body"} defines a |
27040 | 528 |
new locale @{text loc} as a context consisting of a certain view of |
529 |
existing locales (@{text import}) plus some additional elements |
|
530 |
(@{text body}). Both @{text import} and @{text body} are optional; |
|
531 |
the degenerate form @{command "locale"}~@{text loc} defines an empty |
|
532 |
locale, which may still be useful to collect declarations of facts |
|
533 |
later on. Type-inference on locale expressions automatically takes |
|
534 |
care of the most general typing that the combined context elements |
|
535 |
may acquire. |
|
536 |
||
54049 | 537 |
The @{text import} consists of a locale expression; see |
538 |
\secref{sec:proof-context} above. Its @{keyword "for"} clause defines |
|
539 |
the parameters of @{text import}. These are parameters of |
|
540 |
the defined locale. Locale parameters whose instantiation is |
|
541 |
omitted automatically extend the (possibly empty) @{keyword "for"} |
|
542 |
clause: they are inserted at its beginning. This means that these |
|
543 |
parameters may be referred to from within the expression and also in |
|
544 |
the subsequent context elements and provides a notational |
|
545 |
convenience for the inheritance of parameters in locale |
|
33846 | 546 |
declarations. |
27040 | 547 |
|
33846 | 548 |
The @{text body} consists of context elements. |
27040 | 549 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
550 |
\begin{description} |
27040 | 551 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
552 |
\item @{element "fixes"}~@{text "x :: \<tau> (mx)"} declares a local |
27040 | 553 |
parameter of type @{text \<tau>} and mixfix annotation @{text mx} (both |
554 |
are optional). The special syntax declaration ``@{text |
|
51657
3db1bbc82d8d
more accurate documentation of "(structure)" mixfix;
wenzelm
parents:
51585
diff
changeset
|
555 |
"("}@{keyword_ref "structure"}@{text ")"}'' means that @{text x} may |
3db1bbc82d8d
more accurate documentation of "(structure)" mixfix;
wenzelm
parents:
51585
diff
changeset
|
556 |
be referenced implicitly in this context. |
27040 | 557 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
558 |
\item @{element "constrains"}~@{text "x :: \<tau>"} introduces a type |
33846 | 559 |
constraint @{text \<tau>} on the local parameter @{text x}. This |
38110 | 560 |
element is deprecated. The type constraint should be introduced in |
54049 | 561 |
the @{keyword "for"} clause or the relevant @{element "fixes"} element. |
27040 | 562 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
563 |
\item @{element "assumes"}~@{text "a: \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"} |
27040 | 564 |
introduces local premises, similar to @{command "assume"} within a |
565 |
proof (cf.\ \secref{sec:proof-context}). |
|
566 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
567 |
\item @{element "defines"}~@{text "a: x \<equiv> t"} defines a previously |
27040 | 568 |
declared parameter. This is similar to @{command "def"} within a |
569 |
proof (cf.\ \secref{sec:proof-context}), but @{element "defines"} |
|
570 |
takes an equational proposition instead of variable-term pair. The |
|
571 |
left-hand side of the equation may have additional arguments, e.g.\ |
|
572 |
``@{element "defines"}~@{text "f x\<^sub>1 \<dots> x\<^sub>n \<equiv> t"}''. |
|
573 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
574 |
\item @{element "notes"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"} |
27040 | 575 |
reconsiders facts within a local context. Most notably, this may |
576 |
include arbitrary declarations in any attribute specifications |
|
577 |
included here, e.g.\ a local @{attribute simp} rule. |
|
578 |
||
54049 | 579 |
\end{description} |
27040 | 580 |
|
54049 | 581 |
Both @{element "assumes"} and @{element "defines"} elements |
582 |
contribute to the locale specification. When defining an operation |
|
583 |
derived from the parameters, @{command "definition"} |
|
57487 | 584 |
(\secref{sec:term-definitions}) is usually more appropriate. |
27040 | 585 |
|
586 |
Note that ``@{text "(\<IS> p\<^sub>1 \<dots> p\<^sub>n)"}'' patterns given |
|
587 |
in the syntax of @{element "assumes"} and @{element "defines"} above |
|
588 |
are illegal in locale definitions. In the long goal format of |
|
589 |
\secref{sec:goals}, term bindings may be included as expected, |
|
590 |
though. |
|
591 |
||
33846 | 592 |
\medskip Locale specifications are ``closed up'' by |
27040 | 593 |
turning the given text into a predicate definition @{text |
594 |
loc_axioms} and deriving the original assumptions as local lemmas |
|
595 |
(modulo local definitions). The predicate statement covers only the |
|
596 |
newly specified assumptions, omitting the content of included locale |
|
597 |
expressions. The full cumulative view is only provided on export, |
|
598 |
involving another predicate @{text loc} that refers to the complete |
|
599 |
specification text. |
|
600 |
||
601 |
In any case, the predicate arguments are those locale parameters |
|
54049 | 602 |
that actually occur in the respective piece of text. Also these |
603 |
predicates operate at the meta-level in theory, but the locale |
|
27040 | 604 |
packages attempts to internalize statements according to the |
605 |
object-logic setup (e.g.\ replacing @{text \<And>} by @{text \<forall>}, and |
|
606 |
@{text "\<Longrightarrow>"} by @{text "\<longrightarrow>"} in HOL; see also |
|
607 |
\secref{sec:object-logic}). Separate introduction rules @{text |
|
608 |
loc_axioms.intro} and @{text loc.intro} are provided as well. |
|
609 |
||
33867 | 610 |
\item @{command "print_locale"}~@{text "locale"} prints the |
611 |
contents of the named locale. The command omits @{element "notes"} |
|
612 |
elements by default. Use @{command "print_locale"}@{text "!"} to |
|
613 |
have them included. |
|
27040 | 614 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
615 |
\item @{command "print_locales"} prints the names of all locales |
27040 | 616 |
of the current theory. |
617 |
||
50716 | 618 |
\item @{command "locale_deps"} visualizes all locales and their |
619 |
relations as a Hasse diagram. This includes locales defined as type |
|
54049 | 620 |
classes (\secref{sec:class}). See also @{command |
621 |
"print_dependencies"} below. |
|
50716 | 622 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
623 |
\item @{method intro_locales} and @{method unfold_locales} |
27040 | 624 |
repeatedly expand all introduction rules of locale predicates of the |
625 |
theory. While @{method intro_locales} only applies the @{text |
|
54049 | 626 |
loc.intro} introduction rules and therefore does not descend to |
27040 | 627 |
assumptions, @{method unfold_locales} is more aggressive and applies |
628 |
@{text loc_axioms.intro} as well. Both methods are aware of locale |
|
28787 | 629 |
specifications entailed by the context, both from target statements, |
630 |
and from interpretations (see below). New goals that are entailed |
|
631 |
by the current context are discharged automatically. |
|
27040 | 632 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
633 |
\end{description} |
27040 | 634 |
*} |
635 |
||
636 |
||
48824
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
637 |
subsection {* Locale interpretation *} |
27040 | 638 |
|
639 |
text {* |
|
640 |
\begin{matharray}{rcl} |
|
53368
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
641 |
@{command_def "interpretation"} & : & @{text "theory | local_theory \<rightarrow> proof(prove)"} \\ |
33846 | 642 |
@{command_def "interpret"} & : & @{text "proof(state) | proof(chain) \<rightarrow> proof(prove)"} \\ |
53368
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
643 |
@{command_def "sublocale"} & : & @{text "theory | local_theory \<rightarrow> proof(prove)"} \\ |
41435 | 644 |
@{command_def "print_dependencies"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
33846 | 645 |
@{command_def "print_interps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
27040 | 646 |
\end{matharray} |
647 |
||
54049 | 648 |
Locales may be instantiated, and the resulting instantiated |
649 |
declarations added to the current context. This requires proof (of |
|
650 |
the instantiated specification) and is called \emph{locale |
|
651 |
interpretation}. Interpretation is possible in locales (@{command |
|
652 |
"sublocale"}), global and local theories (@{command |
|
653 |
"interpretation"}) and also within proof bodies (@{command |
|
48824
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
654 |
"interpret"}). |
47483 | 655 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
656 |
@{rail \<open> |
53368
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
657 |
@@{command interpretation} @{syntax locale_expr} equations? |
27040 | 658 |
; |
42617 | 659 |
@@{command interpret} @{syntax locale_expr} equations? |
27040 | 660 |
; |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54049
diff
changeset
|
661 |
@@{command sublocale} (@{syntax nameref} ('<' | '\<subseteq>'))? @{syntax locale_expr} \<newline> |
42704 | 662 |
equations? |
33846 | 663 |
; |
42617 | 664 |
@@{command print_dependencies} '!'? @{syntax locale_expr} |
27040 | 665 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
666 |
@@{command print_interps} @{syntax nameref} |
41434
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
667 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
668 |
|
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
669 |
equations: @'where' (@{syntax thmdecl}? @{syntax prop} + @'and') |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
670 |
\<close>} |
27040 | 671 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
672 |
\begin{description} |
27040 | 673 |
|
33867 | 674 |
\item @{command "interpretation"}~@{text "expr \<WHERE> eqns"} |
54049 | 675 |
interprets @{text expr} in a global or local theory. The command |
676 |
generates proof obligations for the instantiated specifications. |
|
677 |
Once these are discharged by the user, instantiated declarations (in |
|
678 |
particular, facts) are added to the theory in a post-processing |
|
679 |
phase. |
|
53368
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
680 |
|
54049 | 681 |
The command is aware of interpretations that are already active. |
682 |
Post-processing is achieved through a variant of roundup that takes |
|
683 |
the interpretations of the current global or local theory into |
|
684 |
account. In order to simplify the proof obligations according to |
|
685 |
existing interpretations use methods @{method intro_locales} or |
|
686 |
@{method unfold_locales}. |
|
53368
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
687 |
|
53369
b4bcac7d065b
Clarifies that interpretation does not only apply to facts, but to declaratoins in general.
ballarin
parents:
53368
diff
changeset
|
688 |
When adding declarations to locales, interpreted versions of these |
b4bcac7d065b
Clarifies that interpretation does not only apply to facts, but to declaratoins in general.
ballarin
parents:
53368
diff
changeset
|
689 |
declarations are added to the global theory for all interpretations |
b4bcac7d065b
Clarifies that interpretation does not only apply to facts, but to declaratoins in general.
ballarin
parents:
53368
diff
changeset
|
690 |
in the global theory as well. That is, interpretations in global |
b4bcac7d065b
Clarifies that interpretation does not only apply to facts, but to declaratoins in general.
ballarin
parents:
53368
diff
changeset
|
691 |
theories dynamically participate in any declarations added to |
54049 | 692 |
locales. |
693 |
||
694 |
In contrast, the lifetime of an interpretation in a local theory is |
|
695 |
limited to the current context block. At the closing @{command end} |
|
696 |
of the block the interpretation and its declarations disappear. |
|
697 |
This enables establishing facts based on interpretations without |
|
698 |
creating permanent links to the interpreted locale instances, as |
|
699 |
would be the case with @{command sublocale}. |
|
700 |
While @{command "interpretation"}~@{text "(\<IN> c) |
|
701 |
\<dots>"} is technically possible, it is not useful since its result is |
|
702 |
discarded immediately. |
|
33846 | 703 |
|
48824
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
704 |
Free variables in the interpreted expression are allowed. They are |
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
705 |
turned into schematic variables in the generated declarations. In |
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
706 |
order to use a free variable whose name is already bound in the |
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
707 |
context --- for example, because a constant of that name exists --- |
54049 | 708 |
add it to the @{keyword "for"} clause. |
48824
45d0e40b07af
Clarification: free variables allowed in interpreted locale instances.
ballarin
parents:
47484
diff
changeset
|
709 |
|
53370
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
710 |
The equations @{text eqns} yield \emph{rewrite morphisms}, which are |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
711 |
unfolded during post-processing and are useful for interpreting |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
712 |
concepts introduced through definitions. The equations must be |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
713 |
proved. |
27040 | 714 |
|
38110 | 715 |
\item @{command "interpret"}~@{text "expr \<WHERE> eqns"} interprets |
716 |
@{text expr} in the proof context and is otherwise similar to |
|
53370
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
717 |
interpretation in local theories. Note that for @{command |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
718 |
"interpret"} the @{text eqns} should be |
41434
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
719 |
explicitly universally quantified. |
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
720 |
|
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
721 |
\item @{command "sublocale"}~@{text "name \<subseteq> expr \<WHERE> |
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
722 |
eqns"} |
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
723 |
interprets @{text expr} in the locale @{text name}. A proof that |
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
724 |
the specification of @{text name} implies the specification of |
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
725 |
@{text expr} is required. As in the localized version of the |
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
726 |
theorem command, the proof is in the context of @{text name}. After |
53370
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
727 |
the proof obligation has been discharged, the locale hierarchy is |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
728 |
changed as if @{text name} imported @{text expr} (hence the name |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
729 |
@{command "sublocale"}). When the context of @{text name} is |
54049 | 730 |
subsequently entered, traversing the locale hierarchy will involve |
53370
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
731 |
the locale instances of @{text expr}, and their declarations will be |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
732 |
added to the context. This makes @{command "sublocale"} |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
733 |
dynamic: extensions of a locale that is instantiated in @{text expr} |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
734 |
may take place after the @{command "sublocale"} declaration and |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
735 |
still become available in the context. Circular @{command |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
736 |
"sublocale"} declarations are allowed as long as they do not lead to |
54049 | 737 |
infinite chains. |
41434
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
738 |
|
53368
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
739 |
If interpretations of @{text name} exist in the current global |
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
740 |
theory, the command adds interpretations for @{text expr} as well, |
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
741 |
with the same qualifier, although only for fragments of @{text expr} |
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
742 |
that are not interpreted in the theory already. |
41434
710cdb9e0d17
Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents:
41249
diff
changeset
|
743 |
|
53370
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
744 |
The equations @{text eqns} amend the morphism through |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
745 |
which @{text expr} is interpreted. This enables mapping definitions |
7a41ec2cc522
Further clarifies sublocale and rewrite morphisms.
ballarin
parents:
53369
diff
changeset
|
746 |
from the interpreted locales to entities of @{text name} and can |
54049 | 747 |
help break infinite chains induced by circular @{command |
748 |
"sublocale"} declarations. |
|
27040 | 749 |
|
53368
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
750 |
In a named context block the @{command sublocale} command may also |
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
751 |
be used, but the locale argument must be omitted. The command then |
92b9965f479d
Clarifies documentation of interpretation in local theories.
ballarin
parents:
53015
diff
changeset
|
752 |
refers to the locale (or class) target of the context block. |
51747 | 753 |
|
41435 | 754 |
\item @{command "print_dependencies"}~@{text "expr"} is useful for |
54049 | 755 |
understanding the effect of an interpretation of @{text "expr"} in |
756 |
the current context. It lists all locale instances for which |
|
757 |
interpretations would be added to the current context. Variant |
|
758 |
@{command "print_dependencies"}@{text "!"} does not generalize |
|
759 |
parameters and assumes an empty context --- that is, it prints all |
|
760 |
locale instances that would be considered for interpretation. The |
|
761 |
latter is useful for understanding the dependencies of a locale |
|
762 |
expression. |
|
41435 | 763 |
|
33867 | 764 |
\item @{command "print_interps"}~@{text "locale"} lists all |
38110 | 765 |
interpretations of @{text "locale"} in the current theory or proof |
51565 | 766 |
context, including those due to a combination of an @{command |
38110 | 767 |
"interpretation"} or @{command "interpret"} and one or several |
768 |
@{command "sublocale"} declarations. |
|
33867 | 769 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
770 |
\end{description} |
27040 | 771 |
|
772 |
\begin{warn} |
|
54049 | 773 |
If a global theory inherits declarations (body elements) for a |
774 |
locale from one parent and an interpretation of that locale from |
|
775 |
another parent, the interpretation will not be applied to the |
|
776 |
declarations. |
|
777 |
\end{warn} |
|
778 |
||
779 |
\begin{warn} |
|
27040 | 780 |
Since attributes are applied to interpreted theorems, |
781 |
interpretation may modify the context of common proof tools, e.g.\ |
|
33867 | 782 |
the Simplifier or Classical Reasoner. As the behavior of such |
783 |
tools is \emph{not} stable under interpretation morphisms, manual |
|
784 |
declarations might have to be added to the target context of the |
|
785 |
interpretation to revert such declarations. |
|
27040 | 786 |
\end{warn} |
787 |
||
788 |
\begin{warn} |
|
51747 | 789 |
An interpretation in a local theory or proof context may subsume previous |
27040 | 790 |
interpretations. This happens if the same specification fragment |
791 |
is interpreted twice and the instantiation of the second |
|
792 |
interpretation is more general than the interpretation of the |
|
33846 | 793 |
first. The locale package does not attempt to remove subsumed |
794 |
interpretations. |
|
27040 | 795 |
\end{warn} |
796 |
*} |
|
797 |
||
798 |
||
799 |
section {* Classes \label{sec:class} *} |
|
800 |
||
801 |
text {* |
|
802 |
\begin{matharray}{rcl} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
803 |
@{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
|
804 |
@{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
|
805 |
@{command_def "instance"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
42626 | 806 |
@{command "instance"} & : & @{text "theory \<rightarrow> proof(prove)"} \\ |
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
807 |
@{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
|
808 |
@{command_def "print_classes"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
29706 | 809 |
@{command_def "class_deps"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
810 |
@{method_def intro_classes} & : & @{text method} \\ |
27040 | 811 |
\end{matharray} |
812 |
||
47483 | 813 |
A class is a particular locale with \emph{exactly one} type variable |
814 |
@{text \<alpha>}. Beyond the underlying locale, a corresponding type class |
|
815 |
is established which is interpreted logically as axiomatic type |
|
816 |
class \cite{Wenzel:1997:TPHOL} whose logical content are the |
|
817 |
assumptions of the locale. Thus, classes provide the full |
|
818 |
generality of locales combined with the commodity of type classes |
|
819 |
(notably type-inference). See \cite{isabelle-classes} for a short |
|
820 |
tutorial. |
|
821 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
822 |
@{rail \<open> |
42704 | 823 |
@@{command class} class_spec @'begin'? |
824 |
; |
|
825 |
class_spec: @{syntax name} '=' |
|
42617 | 826 |
((@{syntax nameref} '+' (@{syntax context_elem}+)) | |
42704 | 827 |
@{syntax nameref} | (@{syntax context_elem}+)) |
27040 | 828 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
829 |
@@{command instantiation} (@{syntax nameref} + @'and') '::' @{syntax arity} @'begin' |
27040 | 830 |
; |
42704 | 831 |
@@{command instance} (() | (@{syntax nameref} + @'and') '::' @{syntax arity} | |
832 |
@{syntax nameref} ('<' | '\<subseteq>') @{syntax nameref} ) |
|
31681 | 833 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
834 |
@@{command subclass} @{syntax target}? @{syntax nameref} |
58202 | 835 |
; |
836 |
@@{command class_deps} @{syntax sort}? @{syntax sort}? |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
837 |
\<close>} |
27040 | 838 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
839 |
\begin{description} |
27040 | 840 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
841 |
\item @{command "class"}~@{text "c = superclasses + body"} defines |
27040 | 842 |
a new class @{text c}, inheriting from @{text superclasses}. This |
843 |
introduces a locale @{text c} with import of all locales @{text |
|
844 |
superclasses}. |
|
845 |
||
846 |
Any @{element "fixes"} in @{text body} are lifted to the global |
|
847 |
theory level (\emph{class operations} @{text "f\<^sub>1, \<dots>, |
|
848 |
f\<^sub>n"} of class @{text c}), mapping the local type parameter |
|
849 |
@{text \<alpha>} to a schematic type variable @{text "?\<alpha> :: c"}. |
|
850 |
||
851 |
Likewise, @{element "assumes"} in @{text body} are also lifted, |
|
852 |
mapping each local parameter @{text "f :: \<tau>[\<alpha>]"} to its |
|
853 |
corresponding global constant @{text "f :: \<tau>[?\<alpha> :: c]"}. The |
|
854 |
corresponding introduction rule is provided as @{text |
|
855 |
c_class_axioms.intro}. This rule should be rarely needed directly |
|
856 |
--- the @{method intro_classes} method takes care of the details of |
|
857 |
class membership proofs. |
|
858 |
||
28768
a056077b65a1
added section "Co-regularity of type classes and arities" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
859 |
\item @{command "instantiation"}~@{text "t :: (s\<^sub>1, \<dots>, s\<^sub>n)s |
51747 | 860 |
\<BEGIN>"} opens a target (cf.\ \secref{sec:target}) which |
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
861 |
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
|
862 |
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
|
863 |
\<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
|
864 |
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
|
865 |
concluded by an @{command_ref (local) "end"} command. |
27040 | 866 |
|
867 |
Note that a list of simultaneous type constructors may be given; |
|
31914 | 868 |
this corresponds nicely to mutually recursive type definitions, e.g.\ |
27040 | 869 |
in Isabelle/HOL. |
870 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
871 |
\item @{command "instance"} in an instantiation target body sets |
27040 | 872 |
up a goal stating the type arities claimed at the opening @{command |
873 |
"instantiation"}. The proof would usually proceed by @{method |
|
874 |
intro_classes}, and then establish the characteristic theorems of |
|
875 |
the type classes involved. After finishing the proof, the |
|
876 |
background theory will be augmented by the proven type arities. |
|
877 |
||
31681 | 878 |
On the theory level, @{command "instance"}~@{text "t :: (s\<^sub>1, \<dots>, |
879 |
s\<^sub>n)s"} provides a convenient way to instantiate a type class with no |
|
37112 | 880 |
need to specify operations: one can continue with the |
31681 | 881 |
instantiation proof immediately. |
882 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
883 |
\item @{command "subclass"}~@{text c} in a class context for class |
27040 | 884 |
@{text d} sets up a goal stating that class @{text c} is logically |
885 |
contained in class @{text d}. After finishing the proof, class |
|
886 |
@{text d} is proven to be subclass @{text c} and the locale @{text |
|
887 |
c} is interpreted into @{text d} simultaneously. |
|
888 |
||
56594 | 889 |
A weakened form of this is available through a further variant of |
31681 | 890 |
@{command instance}: @{command instance}~@{text "c\<^sub>1 \<subseteq> c\<^sub>2"} opens |
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
51747
diff
changeset
|
891 |
a proof that class @{text "c\<^sub>2"} implies @{text "c\<^sub>1"} without reference |
31681 | 892 |
to the underlying locales; this is useful if the properties to prove |
56594 | 893 |
the logical connection are not sufficient on the locale level but on |
31681 | 894 |
the theory level. |
895 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
896 |
\item @{command "print_classes"} prints all classes in the current |
27040 | 897 |
theory. |
898 |
||
29706 | 899 |
\item @{command "class_deps"} visualizes all classes and their |
58202 | 900 |
subclass relations as a Hasse diagram. An optional first sort argument |
901 |
constrains the set of classes to all subclasses of this sort, |
|
902 |
an optional second sort argument to all superclasses of this sort. |
|
29706 | 903 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
904 |
\item @{method intro_classes} repeatedly expands all class |
27040 | 905 |
introduction rules of this theory. Note that this method usually |
906 |
needs not be named explicitly, as it is already included in the |
|
907 |
default proof step (e.g.\ of @{command "proof"}). In particular, |
|
908 |
instantiation of trivial (syntactic) classes may be performed by a |
|
909 |
single ``@{command ".."}'' proof step. |
|
26870 | 910 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
911 |
\end{description} |
26870 | 912 |
*} |
913 |
||
27040 | 914 |
|
915 |
subsection {* The class target *} |
|
916 |
||
917 |
text {* |
|
918 |
%FIXME check |
|
919 |
||
920 |
A named context may refer to a locale (cf.\ \secref{sec:target}). |
|
921 |
If this locale is also a class @{text c}, apart from the common |
|
922 |
locale target behaviour the following happens. |
|
923 |
||
924 |
\begin{itemize} |
|
925 |
||
926 |
\item Local constant declarations @{text "g[\<alpha>]"} referring to the |
|
927 |
local type parameter @{text \<alpha>} and local parameters @{text "f[\<alpha>]"} |
|
928 |
are accompanied by theory-level constants @{text "g[?\<alpha> :: c]"} |
|
929 |
referring to theory-level class operations @{text "f[?\<alpha> :: c]"}. |
|
930 |
||
931 |
\item Local theorem bindings are lifted as are assumptions. |
|
932 |
||
933 |
\item Local syntax refers to local operations @{text "g[\<alpha>]"} and |
|
934 |
global operations @{text "g[?\<alpha> :: c]"} uniformly. Type inference |
|
935 |
resolves ambiguities. In rare cases, manual type annotations are |
|
936 |
needed. |
|
937 |
||
938 |
\end{itemize} |
|
939 |
*} |
|
940 |
||
941 |
||
37768
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
942 |
subsection {* Co-regularity of type classes and arities *} |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
943 |
|
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
944 |
text {* The class relation together with the collection of |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
945 |
type-constructor arities must obey the principle of |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
946 |
\emph{co-regularity} as defined below. |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
947 |
|
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
948 |
\medskip For the subsequent formulation of co-regularity we assume |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
949 |
that the class relation is closed by transitivity and reflexivity. |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
950 |
Moreover the collection of arities @{text "t :: (\<^vec>s)c"} is |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
951 |
completed such that @{text "t :: (\<^vec>s)c"} and @{text "c \<subseteq> c'"} |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
952 |
implies @{text "t :: (\<^vec>s)c'"} for all such declarations. |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
953 |
|
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
954 |
Treating sorts as finite sets of classes (meaning the intersection), |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
955 |
the class relation @{text "c\<^sub>1 \<subseteq> c\<^sub>2"} is extended to sorts as |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
956 |
follows: |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
957 |
\[ |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
958 |
@{text "s\<^sub>1 \<subseteq> s\<^sub>2 \<equiv> \<forall>c\<^sub>2 \<in> s\<^sub>2. \<exists>c\<^sub>1 \<in> s\<^sub>1. c\<^sub>1 \<subseteq> c\<^sub>2"} |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
959 |
\] |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
960 |
|
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
961 |
This relation on sorts is further extended to tuples of sorts (of |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
962 |
the same length) in the component-wise way. |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
963 |
|
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
964 |
\smallskip Co-regularity of the class relation together with the |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
965 |
arities relation means: |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
966 |
\[ |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
967 |
@{text "t :: (\<^vec>s\<^sub>1)c\<^sub>1 \<Longrightarrow> t :: (\<^vec>s\<^sub>2)c\<^sub>2 \<Longrightarrow> c\<^sub>1 \<subseteq> c\<^sub>2 \<Longrightarrow> \<^vec>s\<^sub>1 \<subseteq> \<^vec>s\<^sub>2"} |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
968 |
\] |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
969 |
\noindent for all such arities. In other words, whenever the result |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
970 |
classes of some type-constructor arities are related, then the |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
971 |
argument sorts need to be related in the same way. |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
972 |
|
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
973 |
\medskip Co-regularity is a very fundamental property of the |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
974 |
order-sorted algebra of types. For example, it entails principle |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
975 |
types and most general unifiers, e.g.\ see \cite{nipkow-prehofer}. |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
976 |
*} |
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
977 |
|
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
978 |
|
27040 | 979 |
section {* Unrestricted overloading *} |
980 |
||
981 |
text {* |
|
47483 | 982 |
\begin{matharray}{rcl} |
983 |
@{command_def "overloading"} & : & @{text "theory \<rightarrow> local_theory"} \\ |
|
984 |
\end{matharray} |
|
985 |
||
27040 | 986 |
Isabelle/Pure's definitional schemes support certain forms of |
31047 | 987 |
overloading (see \secref{sec:consts}). Overloading means that a |
988 |
constant being declared as @{text "c :: \<alpha> decl"} may be |
|
989 |
defined separately on type instances |
|
990 |
@{text "c :: (\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n) t decl"} |
|
56594 | 991 |
for each type constructor @{text t}. At most occasions |
27040 | 992 |
overloading will be used in a Haskell-like fashion together with |
993 |
type classes by means of @{command "instantiation"} (see |
|
994 |
\secref{sec:class}). Sometimes low-level overloading is desirable. |
|
995 |
The @{command "overloading"} target provides a convenient view for |
|
996 |
end-users. |
|
997 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
998 |
@{rail \<open> |
42704 | 999 |
@@{command overloading} ( spec + ) @'begin' |
1000 |
; |
|
1001 |
spec: @{syntax name} ( '==' | '\<equiv>' ) @{syntax term} ( '(' @'unchecked' ')' )? |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1002 |
\<close>} |
27040 | 1003 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1004 |
\begin{description} |
27040 | 1005 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1006 |
\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 | 1007 |
opens a theory target (cf.\ \secref{sec:target}) which allows to |
1008 |
specify constants with overloaded definitions. These are identified |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1009 |
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
|
1010 |
constants @{text "c\<^sub>i"} at particular type instances. The |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1011 |
definitions themselves are established using common specification |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1012 |
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
|
1013 |
corresponding constants. The target is concluded by @{command |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1014 |
(local) "end"}. |
27040 | 1015 |
|
1016 |
A @{text "(unchecked)"} option disables global dependency checks for |
|
1017 |
the corresponding definition, which is occasionally useful for |
|
31047 | 1018 |
exotic overloading (see \secref{sec:consts} for a precise description). |
1019 |
It is at the discretion of the user to avoid |
|
27040 | 1020 |
malformed theory specifications! |
1021 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1022 |
\end{description} |
27040 | 1023 |
*} |
1024 |
||
1025 |
||
1026 |
section {* Incorporating ML code \label{sec:ML} *} |
|
1027 |
||
1028 |
text {* |
|
1029 |
\begin{matharray}{rcl} |
|
56275
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1030 |
@{command_def "SML_file"} & : & @{text "theory \<rightarrow> theory"} \\ |
48890
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1031 |
@{command_def "ML_file"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1032 |
@{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
|
1033 |
@{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
|
1034 |
@{command_def "ML_val"} & : & @{text "any \<rightarrow>"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1035 |
@{command_def "ML_command"} & : & @{text "any \<rightarrow>"} \\ |
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1036 |
@{command_def "setup"} & : & @{text "theory \<rightarrow> theory"} \\ |
30461 | 1037 |
@{command_def "local_setup"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
57941
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
wenzelm
parents:
57487
diff
changeset
|
1038 |
@{command_def "attribute_setup"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1039 |
\end{matharray} |
57478 | 1040 |
\begin{tabular}{rcll} |
1041 |
@{attribute_def ML_print_depth} & : & @{text attribute} & default 10 \\ |
|
1042 |
@{attribute_def ML_source_trace} & : & @{text attribute} & default @{text false} \\ |
|
1043 |
@{attribute_def ML_exception_trace} & : & @{text attribute} & default @{text false} \\ |
|
1044 |
\end{tabular} |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1045 |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1046 |
@{rail \<open> |
56275
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1047 |
(@@{command SML_file} | @@{command ML_file}) @{syntax name} |
27040 | 1048 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1049 |
(@@{command ML} | @@{command ML_prf} | @@{command ML_val} | |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1050 |
@@{command ML_command} | @@{command setup} | @@{command local_setup}) @{syntax text} |
27040 | 1051 |
; |
57947 | 1052 |
@@{command attribute_setup} @{syntax target}? |
1053 |
@{syntax name} '=' @{syntax text} @{syntax text}? |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1054 |
\<close>} |
27040 | 1055 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1056 |
\begin{description} |
27040 | 1057 |
|
56275
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1058 |
\item @{command "SML_file"}~@{text "name"} reads and evaluates the |
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1059 |
given Standard ML file. Top-level SML bindings are stored within |
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1060 |
the theory context; the initial environment is restricted to the |
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1061 |
Standard ML implementation of Poly/ML, without the many add-ons of |
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1062 |
Isabelle/ML. Multiple @{command "SML_file"} commands may be used to |
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1063 |
build larger Standard ML projects, independently of the regular |
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1064 |
Isabelle/ML environment. |
600f432ab556
added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents:
55837
diff
changeset
|
1065 |
|
48890
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1066 |
\item @{command "ML_file"}~@{text "name"} reads and evaluates the |
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1067 |
given ML file. The current theory context is passed down to the ML |
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1068 |
toplevel and may be modified, using @{ML "Context.>>"} or derived ML |
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1069 |
commands. Top-level ML bindings are stored within the (global or |
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1070 |
local) theory context. |
27040 | 1071 |
|
48890
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1072 |
\item @{command "ML"}~@{text "text"} is similar to @{command |
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1073 |
"ML_file"}, but evaluates directly the given @{text "text"}. |
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1074 |
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
|
1075 |
context. |
28281 | 1076 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1077 |
\item @{command "ML_prf"} is analogous to @{command "ML"} but works |
48890
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1078 |
within a proof context. Top-level ML bindings are stored within the |
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1079 |
proof context in a purely sequential fashion, disregarding the |
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1080 |
nested proof structure. ML bindings introduced by @{command |
d72ca5742f80
'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents:
48824
diff
changeset
|
1081 |
"ML_prf"} are discarded at the end of the proof. |
27040 | 1082 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1083 |
\item @{command "ML_val"} and @{command "ML_command"} are diagnostic |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1084 |
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
|
1085 |
updated. @{command "ML_val"} echos the bindings produced at the ML |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1086 |
toplevel, but @{command "ML_command"} is silent. |
27040 | 1087 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1088 |
\item @{command "setup"}~@{text "text"} changes the current theory |
27040 | 1089 |
context by applying @{text "text"}, which refers to an ML expression |
30461 | 1090 |
of type @{ML_type "theory -> theory"}. This enables to initialize |
1091 |
any object-logic specific tools and packages written in ML, for |
|
1092 |
example. |
|
1093 |
||
1094 |
\item @{command "local_setup"} is similar to @{command "setup"} for |
|
1095 |
a local theory context, and an ML expression of type @{ML_type |
|
1096 |
"local_theory -> local_theory"}. This allows to |
|
1097 |
invoke local theory specification packages without going through |
|
1098 |
concrete outer syntax, for example. |
|
28758 | 1099 |
|
30526 | 1100 |
\item @{command "attribute_setup"}~@{text "name = text description"} |
57941
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
wenzelm
parents:
57487
diff
changeset
|
1101 |
defines an attribute in the current context. The given @{text |
30526 | 1102 |
"text"} has to be an ML expression of type |
1103 |
@{ML_type "attribute context_parser"}, cf.\ basic parsers defined in |
|
55837 | 1104 |
structure @{ML_structure Args} and @{ML_structure Attrib}. |
30526 | 1105 |
|
1106 |
In principle, attributes can operate both on a given theorem and the |
|
1107 |
implicit context, although in practice only one is modified and the |
|
1108 |
other serves as parameter. Here are examples for these two cases: |
|
1109 |
||
1110 |
\end{description} |
|
1111 |
*} |
|
1112 |
||
42704 | 1113 |
attribute_setup my_rule = {* |
1114 |
Attrib.thms >> (fn ths => |
|
1115 |
Thm.rule_attribute |
|
1116 |
(fn context: Context.generic => fn th: thm => |
|
30526 | 1117 |
let val th' = th OF ths |
42936 | 1118 |
in th' end)) *} |
30526 | 1119 |
|
42704 | 1120 |
attribute_setup my_declaration = {* |
1121 |
Attrib.thms >> (fn ths => |
|
1122 |
Thm.declaration_attribute |
|
1123 |
(fn th: thm => fn context: Context.generic => |
|
30526 | 1124 |
let val context' = context |
42936 | 1125 |
in context' end)) *} |
30526 | 1126 |
|
57478 | 1127 |
text {* |
1128 |
\begin{description} |
|
1129 |
||
1130 |
\item @{attribute ML_print_depth} controls the printing depth of the ML |
|
1131 |
toplevel pretty printer; the precise effect depends on the ML compiler and |
|
1132 |
run-time system. Typically the limit should be less than 10. Bigger values |
|
1133 |
such as 100--1000 are occasionally useful for debugging. |
|
1134 |
||
1135 |
\item @{attribute ML_source_trace} indicates whether the source text that |
|
1136 |
is given to the ML compiler should be output: it shows the raw Standard ML |
|
1137 |
after expansion of Isabelle/ML antiquotations. |
|
1138 |
||
1139 |
\item @{attribute ML_exception_trace} indicates whether the ML run-time |
|
1140 |
system should print a detailed stack trace on exceptions. The result is |
|
1141 |
dependent on the particular ML compiler version. Note that after Poly/ML |
|
1142 |
5.3 some optimizations in the run-time systems may hinder exception |
|
1143 |
traces. |
|
1144 |
||
1145 |
The boundary for the exception trace is the current Isar command |
|
1146 |
transactions. It is occasionally better to insert the combinator @{ML |
|
1147 |
Runtime.exn_trace} into ML code for debugging |
|
1148 |
\cite{isabelle-implementation}, closer to the point where it actually |
|
1149 |
happens. |
|
1150 |
||
1151 |
\end{description} |
|
1152 |
*} |
|
1153 |
||
27040 | 1154 |
|
1155 |
section {* Primitive specification elements *} |
|
1156 |
||
55385
169e12bbf9a3
discontinued axiomatic 'classes', 'classrel', 'arities';
wenzelm
parents:
55117
diff
changeset
|
1157 |
subsection {* Sorts *} |
27040 | 1158 |
|
1159 |
text {* |
|
1160 |
\begin{matharray}{rcll} |
|
37768
e86221f3bac7
moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents:
37112
diff
changeset
|
1161 |
@{command_def "default_sort"} & : & @{text "local_theory \<rightarrow> local_theory"} |
27040 | 1162 |
\end{matharray} |
1163 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1164 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1165 |
@@{command default_sort} @{syntax sort} |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1166 |
\<close>} |
27040 | 1167 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1168 |
\begin{description} |
27040 | 1169 |
|
36454
f2b5bcc61a8c
command 'defaultsort' is renamed to 'default_sort', it works within a local theory context;
wenzelm
parents:
36178
diff
changeset
|
1170 |
\item @{command "default_sort"}~@{text s} makes sort @{text s} the |
28767 | 1171 |
new default sort for any type variable that is given explicitly in |
1172 |
the text, but lacks a sort constraint (wrt.\ the current context). |
|
1173 |
Type variables generated by type inference are not affected. |
|
1174 |
||
1175 |
Usually the default sort is only changed when defining a new |
|
1176 |
object-logic. For example, the default sort in Isabelle/HOL is |
|
39831 | 1177 |
@{class type}, the class of all HOL types. |
28767 | 1178 |
|
1179 |
When merging theories, the default sorts of the parents are |
|
1180 |
logically intersected, i.e.\ the representations as lists of classes |
|
1181 |
are joined. |
|
27040 | 1182 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1183 |
\end{description} |
27040 | 1184 |
*} |
1185 |
||
1186 |
||
57487 | 1187 |
subsection {* Types \label{sec:types-pure} *} |
27040 | 1188 |
|
1189 |
text {* |
|
1190 |
\begin{matharray}{rcll} |
|
41249
26f12f98f50a
Command 'type_synonym' (with single argument) supersedes 'types' (legacy feature);
wenzelm
parents:
40800
diff
changeset
|
1191 |
@{command_def "type_synonym"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
35681 | 1192 |
@{command_def "typedecl"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
27040 | 1193 |
\end{matharray} |
1194 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1195 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1196 |
@@{command type_synonym} (@{syntax typespec} '=' @{syntax type} @{syntax mixfix}?) |
27040 | 1197 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1198 |
@@{command typedecl} @{syntax typespec} @{syntax mixfix}? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1199 |
\<close>} |
27040 | 1200 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1201 |
\begin{description} |
27040 | 1202 |
|
57487 | 1203 |
\item @{command "type_synonym"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t = \<tau>"} introduces a |
1204 |
\emph{type synonym} @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"} for the existing type @{text |
|
1205 |
"\<tau>"}. Unlike the semantic type definitions in Isabelle/HOL, type synonyms |
|
1206 |
are merely syntactic abbreviations without any logical significance. |
|
41249
26f12f98f50a
Command 'type_synonym' (with single argument) supersedes 'types' (legacy feature);
wenzelm
parents:
40800
diff
changeset
|
1207 |
Internally, type synonyms are fully expanded. |
27040 | 1208 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1209 |
\item @{command "typedecl"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"} declares a new |
28767 | 1210 |
type constructor @{text t}. If the object-logic defines a base sort |
1211 |
@{text s}, then the constructor is declared to operate on that, via |
|
55385
169e12bbf9a3
discontinued axiomatic 'classes', 'classrel', 'arities';
wenzelm
parents:
55117
diff
changeset
|
1212 |
the axiomatic type-class instance @{text "t :: (s, \<dots>, s)s"}. |
27040 | 1213 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1214 |
\end{description} |
57487 | 1215 |
|
1216 |
\begin{warn} |
|
1217 |
If you introduce a new type axiomatically, i.e.\ via @{command_ref |
|
1218 |
typedecl} and @{command_ref axiomatization} |
|
1219 |
(\secref{sec:axiomatizations}), the minimum requirement is that it has a |
|
1220 |
non-empty model, to avoid immediate collapse of the logical environment. |
|
1221 |
Moreover, one needs to demonstrate that the interpretation of such |
|
1222 |
free-form axiomatizations can coexist with other axiomatization schemes |
|
1223 |
for types, notably @{command_def typedef} in Isabelle/HOL |
|
1224 |
(\secref{sec:hol-typedef}), or any other extension that people might have |
|
1225 |
introduced elsewhere. |
|
1226 |
\end{warn} |
|
27040 | 1227 |
*} |
1228 |
||
1229 |
||
1230 |
subsection {* Constants and definitions \label{sec:consts} *} |
|
1231 |
||
1232 |
text {* |
|
47483 | 1233 |
\begin{matharray}{rcl} |
1234 |
@{command_def "consts"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1235 |
@{command_def "defs"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1236 |
\end{matharray} |
|
1237 |
||
27040 | 1238 |
Definitions essentially express abbreviations within the logic. The |
1239 |
simplest form of a definition is @{text "c :: \<sigma> \<equiv> t"}, where @{text |
|
1240 |
c} is a newly declared constant. Isabelle also allows derived forms |
|
1241 |
where the arguments of @{text c} appear on the left, abbreviating a |
|
1242 |
prefix of @{text \<lambda>}-abstractions, e.g.\ @{text "c \<equiv> \<lambda>x y. t"} may be |
|
1243 |
written more conveniently as @{text "c x y \<equiv> t"}. Moreover, |
|
1244 |
definitions may be weakened by adding arbitrary pre-conditions: |
|
1245 |
@{text "A \<Longrightarrow> c x y \<equiv> t"}. |
|
1246 |
||
1247 |
\medskip The built-in well-formedness conditions for definitional |
|
1248 |
specifications are: |
|
1249 |
||
1250 |
\begin{itemize} |
|
1251 |
||
1252 |
\item Arguments (on the left-hand side) must be distinct variables. |
|
1253 |
||
1254 |
\item All variables on the right-hand side must also appear on the |
|
1255 |
left-hand side. |
|
1256 |
||
1257 |
\item All type variables on the right-hand side must also appear on |
|
1258 |
the left-hand side; this prohibits @{text "0 :: nat \<equiv> length ([] :: |
|
1259 |
\<alpha> list)"} for example. |
|
1260 |
||
1261 |
\item The definition must not be recursive. Most object-logics |
|
1262 |
provide definitional principles that can be used to express |
|
1263 |
recursion safely. |
|
1264 |
||
1265 |
\end{itemize} |
|
1266 |
||
31047 | 1267 |
The right-hand side of overloaded definitions may mention overloaded constants |
27040 | 1268 |
recursively at type instances corresponding to the immediate |
1269 |
argument types @{text "\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n"}. Incomplete |
|
1270 |
specification patterns impose global constraints on all occurrences, |
|
1271 |
e.g.\ @{text "d :: \<alpha> \<times> \<alpha>"} on the left-hand side means that all |
|
1272 |
corresponding occurrences on some right-hand side need to be an |
|
1273 |
instance of this, general @{text "d :: \<alpha> \<times> \<beta>"} will be disallowed. |
|
1274 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1275 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1276 |
@@{command consts} ((@{syntax name} '::' @{syntax type} @{syntax mixfix}?) +) |
27040 | 1277 |
; |
42704 | 1278 |
@@{command defs} opt? (@{syntax axmdecl} @{syntax prop} +) |
1279 |
; |
|
1280 |
opt: '(' @'unchecked'? @'overloaded'? ')' |
|
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1281 |
\<close>} |
27040 | 1282 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1283 |
\begin{description} |
27040 | 1284 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1285 |
\item @{command "consts"}~@{text "c :: \<sigma>"} declares constant @{text |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1286 |
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
|
1287 |
mixfix annotations may attach concrete syntax to the constants |
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1288 |
declared. |
27040 | 1289 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1290 |
\item @{command "defs"}~@{text "name: eqn"} introduces @{text eqn} |
27040 | 1291 |
as a definitional axiom for some existing constant. |
1292 |
||
1293 |
The @{text "(unchecked)"} option disables global dependency checks |
|
1294 |
for this definition, which is occasionally useful for exotic |
|
1295 |
overloading. It is at the discretion of the user to avoid malformed |
|
1296 |
theory specifications! |
|
1297 |
||
1298 |
The @{text "(overloaded)"} option declares definitions to be |
|
1299 |
potentially overloaded. Unless this option is given, a warning |
|
1300 |
message would be issued for any definitional equation with a more |
|
1301 |
special type than that of the corresponding constant declaration. |
|
1302 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1303 |
\end{description} |
27040 | 1304 |
*} |
1305 |
||
1306 |
||
51313 | 1307 |
section {* Naming existing theorems \label{sec:theorems} *} |
27040 | 1308 |
|
1309 |
text {* |
|
1310 |
\begin{matharray}{rcll} |
|
28761
9ec4482c9201
updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents:
28760
diff
changeset
|
1311 |
@{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
|
1312 |
@{command_def "theorems"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
57946
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1313 |
@{command_def "named_theorems"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
27040 | 1314 |
\end{matharray} |
1315 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1316 |
@{rail \<open> |
55029
61a6bf7d4b02
clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents:
54049
diff
changeset
|
1317 |
(@@{command lemmas} | @@{command theorems}) @{syntax target}? \<newline> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1318 |
(@{syntax thmdef}? @{syntax thmrefs} + @'and') |
45600
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
42936
diff
changeset
|
1319 |
(@'for' (@{syntax vars} + @'and'))? |
57946
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1320 |
; |
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1321 |
@@{command named_theorems} @{syntax target}? |
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1322 |
@{syntax name} @{syntax text}? |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1323 |
\<close>} |
27040 | 1324 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1325 |
\begin{description} |
27040 | 1326 |
|
45600
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
42936
diff
changeset
|
1327 |
\item @{command "lemmas"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"}~@{keyword_def |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
42936
diff
changeset
|
1328 |
"for"}~@{text "x\<^sub>1 \<dots> x\<^sub>m"} evaluates given facts (with attributes) in |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
42936
diff
changeset
|
1329 |
the current context, which may be augmented by local variables. |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
42936
diff
changeset
|
1330 |
Results are standardized before being stored, i.e.\ schematic |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
42936
diff
changeset
|
1331 |
variables are renamed to enforce index @{text "0"} uniformly. |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
42936
diff
changeset
|
1332 |
|
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
42936
diff
changeset
|
1333 |
\item @{command "theorems"} is the same as @{command "lemmas"}, but |
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents:
42936
diff
changeset
|
1334 |
marks the result as a different kind of facts. |
27040 | 1335 |
|
57946
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1336 |
\item @{command "named_theorems"}~@{text "name description"} declares a |
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1337 |
dynamic fact within the context. The same @{text name} is used to define |
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1338 |
an attribute with the usual @{text add}/@{text del} syntax (e.g.\ see |
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1339 |
\secref{sec:simp-rules}) to maintain the content incrementally, in |
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1340 |
canonical declaration order of the text structure. |
6a26aa5fa65e
updated documentation concerning 'named_theorems';
wenzelm
parents:
57941
diff
changeset
|
1341 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1342 |
\end{description} |
27040 | 1343 |
*} |
1344 |
||
1345 |
||
1346 |
section {* Oracles *} |
|
1347 |
||
47483 | 1348 |
text {* |
1349 |
\begin{matharray}{rcll} |
|
1350 |
@{command_def "oracle"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!) \\ |
|
1351 |
\end{matharray} |
|
1352 |
||
1353 |
Oracles allow Isabelle to take advantage of external reasoners such |
|
1354 |
as arithmetic decision procedures, model checkers, fast tautology |
|
1355 |
checkers or computer algebra systems. Invoked as an oracle, an |
|
1356 |
external reasoner can create arbitrary Isabelle theorems. |
|
28756 | 1357 |
|
1358 |
It is the responsibility of the user to ensure that the external |
|
1359 |
reasoner is as trustworthy as the application requires. Another |
|
1360 |
typical source of errors is the linkup between Isabelle and the |
|
1361 |
external tool, not just its concrete implementation, but also the |
|
1362 |
required translation between two different logical environments. |
|
1363 |
||
1364 |
Isabelle merely guarantees well-formedness of the propositions being |
|
1365 |
asserted, and records within the internal derivation object how |
|
1366 |
presumed theorems depend on unproven suppositions. |
|
1367 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1368 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1369 |
@@{command oracle} @{syntax name} '=' @{syntax text} |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1370 |
\<close>} |
27040 | 1371 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1372 |
\begin{description} |
27040 | 1373 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1374 |
\item @{command "oracle"}~@{text "name = text"} turns the given ML |
28290 | 1375 |
expression @{text "text"} of type @{ML_text "'a -> cterm"} into an |
1376 |
ML function of type @{ML_text "'a -> thm"}, which is bound to the |
|
28756 | 1377 |
global identifier @{ML_text name}. This acts like an infinitary |
1378 |
specification of axioms! Invoking the oracle only works within the |
|
1379 |
scope of the resulting theory. |
|
27040 | 1380 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1381 |
\end{description} |
28756 | 1382 |
|
40800
330eb65c9469
Parse.liberal_name for document antiquotations and attributes;
wenzelm
parents:
40784
diff
changeset
|
1383 |
See @{file "~~/src/HOL/ex/Iff_Oracle.thy"} for a worked example of |
28756 | 1384 |
defining a new primitive rule as oracle, and turning it into a proof |
1385 |
method. |
|
27040 | 1386 |
*} |
1387 |
||
1388 |
||
1389 |
section {* Name spaces *} |
|
1390 |
||
1391 |
text {* |
|
1392 |
\begin{matharray}{rcl} |
|
36177
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1393 |
@{command_def "hide_class"} & : & @{text "theory \<rightarrow> theory"} \\ |
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1394 |
@{command_def "hide_type"} & : & @{text "theory \<rightarrow> theory"} \\ |
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1395 |
@{command_def "hide_const"} & : & @{text "theory \<rightarrow> theory"} \\ |
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1396 |
@{command_def "hide_fact"} & : & @{text "theory \<rightarrow> theory"} \\ |
27040 | 1397 |
\end{matharray} |
1398 |
||
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1399 |
@{rail \<open> |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1400 |
( @{command hide_class} | @{command hide_type} | |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
41435
diff
changeset
|
1401 |
@{command hide_const} | @{command hide_fact} ) ('(' @'open' ')')? (@{syntax nameref} + ) |
55112
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents:
55029
diff
changeset
|
1402 |
\<close>} |
27040 | 1403 |
|
1404 |
Isabelle organizes any kind of name declarations (of types, |
|
1405 |
constants, theorems etc.) by separate hierarchically structured name |
|
1406 |
spaces. Normally the user does not have to control the behavior of |
|
1407 |
name spaces by hand, yet the following commands provide some way to |
|
1408 |
do so. |
|
1409 |
||
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1410 |
\begin{description} |
27040 | 1411 |
|
36177
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1412 |
\item @{command "hide_class"}~@{text names} fully removes class |
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1413 |
declarations from a given name space; with the @{text "(open)"} |
39977
c9cbc16e93ce
do not mention unqualified names, now that 'global' and 'local' are gone
krauss
parents:
39214
diff
changeset
|
1414 |
option, only the base name is hidden. |
36177
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1415 |
|
27040 | 1416 |
Note that hiding name space accesses has no impact on logical |
28756 | 1417 |
declarations --- they remain valid internally. Entities that are no |
27040 | 1418 |
longer accessible to the user are printed with the special qualifier |
1419 |
``@{text "??"}'' prefixed to the full internal name. |
|
1420 |
||
36177
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1421 |
\item @{command "hide_type"}, @{command "hide_const"}, and @{command |
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1422 |
"hide_fact"} are similar to @{command "hide_class"}, but hide types, |
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1423 |
constants, and facts, respectively. |
8e0770d2e499
separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents:
35681
diff
changeset
|
1424 |
|
28760
cbc435f7b16b
unified use of declaration environment with IsarImplementation;
wenzelm
parents:
28758
diff
changeset
|
1425 |
\end{description} |
27040 | 1426 |
*} |
1427 |
||
26869 | 1428 |
end |