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