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