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