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