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