src/Doc/Isar_Ref/Spec.thy
author wenzelm
Sat, 07 Nov 2015 12:53:22 +0100
changeset 61597 53e32a9b66b8
parent 61566 c3d6e570ccef
child 61606 6d5213bd9709
permissions -rw-r--r--
added @{undefined} with somewhat undefined symbol;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     1
theory Spec
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
     2
imports Base Main "~~/src/Tools/Permanent_Interpretation"
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     3
begin
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     4
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
     5
chapter \<open>Specifications\<close>
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
     6
59781
wenzelm
parents: 59422
diff changeset
     7
text \<open>The Isabelle/Isar theory format integrates specifications and proofs,
wenzelm
parents: 59422
diff changeset
     8
  with support for interactive development by continuous document editing.
wenzelm
parents: 59422
diff changeset
     9
  There is a separate document preparation system (see
wenzelm
parents: 59422
diff changeset
    10
  \chref{ch:document-prep}), for typesetting formal developments together
wenzelm
parents: 59422
diff changeset
    11
  with informal text. The resulting hyper-linked PDF documents can be used
wenzelm
parents: 59422
diff changeset
    12
  both for WWW presentation and printed copies.
29745
fe221f1d8976 added introduction;
wenzelm
parents: 29706
diff changeset
    13
fe221f1d8976 added introduction;
wenzelm
parents: 29706
diff changeset
    14
  The Isar proof language (see \chref{ch:proofs}) is embedded into the
fe221f1d8976 added introduction;
wenzelm
parents: 29706
diff changeset
    15
  theory language as a proper sub-language.  Proof mode is entered by
fe221f1d8976 added introduction;
wenzelm
parents: 29706
diff changeset
    16
  stating some @{command theorem} or @{command lemma} at the theory
fe221f1d8976 added introduction;
wenzelm
parents: 29706
diff changeset
    17
  level, and left again with the final conclusion (e.g.\ via @{command
59781
wenzelm
parents: 59422
diff changeset
    18
  qed}).
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    19
\<close>
29745
fe221f1d8976 added introduction;
wenzelm
parents: 29706
diff changeset
    20
fe221f1d8976 added introduction;
wenzelm
parents: 29706
diff changeset
    21
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    22
section \<open>Defining theories \label{sec:begin-thy}\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    23
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    24
text \<open>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    25
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    26
    @{command_def "theory"} & : & \<open>toplevel \<rightarrow> theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    27
    @{command_def (global) "end"} & : & \<open>theory \<rightarrow> toplevel\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    28
    @{command_def "thy_deps"}\<open>\<^sup>*\<close> & : & \<open>theory \<rightarrow>\<close> \\
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    29
  \end{matharray}
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    30
59781
wenzelm
parents: 59422
diff changeset
    31
  Isabelle/Isar theories are defined via theory files, which consist of an
wenzelm
parents: 59422
diff changeset
    32
  outermost sequence of definition--statement--proof elements. Some
wenzelm
parents: 59422
diff changeset
    33
  definitions are self-sufficient (e.g.\ @{command fun} in Isabelle/HOL),
wenzelm
parents: 59422
diff changeset
    34
  with foundational proofs performed internally. Other definitions require
wenzelm
parents: 59422
diff changeset
    35
  an explicit proof as justification (e.g.\ @{command function} and
wenzelm
parents: 59422
diff changeset
    36
  @{command termination} in Isabelle/HOL). Plain statements like @{command
wenzelm
parents: 59422
diff changeset
    37
  theorem} or @{command lemma} are merely a special case of that, defining a
wenzelm
parents: 59422
diff changeset
    38
  theorem from a given proposition and its proof.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    39
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
    40
  The theory body may be sub-structured by means of \<^emph>\<open>local theory
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
    41
  targets\<close>, such as @{command "locale"} and @{command "class"}. It is also
59781
wenzelm
parents: 59422
diff changeset
    42
  possible to use @{command context}~@{keyword "begin"}~\dots~@{command end}
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
    43
  blocks to delimited a local theory context: a \<^emph>\<open>named context\<close> to
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
    44
  augment a locale or class specification, or an \<^emph>\<open>unnamed context\<close> to
59781
wenzelm
parents: 59422
diff changeset
    45
  refer to local parameters and assumptions that are discharged later. See
wenzelm
parents: 59422
diff changeset
    46
  \secref{sec:target} for more details.
28745
146d570e12b5 reworked "Defining Theories";
wenzelm
parents: 28728
diff changeset
    47
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
    48
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
    49
  A theory is commenced by the @{command "theory"} command, which
59781
wenzelm
parents: 59422
diff changeset
    50
  indicates imports of previous theories, according to an acyclic
wenzelm
parents: 59422
diff changeset
    51
  foundational order. Before the initial @{command "theory"} command, there
wenzelm
parents: 59422
diff changeset
    52
  may be optional document header material (like @{command section} or
wenzelm
parents: 59422
diff changeset
    53
  @{command text}, see \secref{sec:markup}). The document header is outside
wenzelm
parents: 59422
diff changeset
    54
  of the formal theory context, though.
wenzelm
parents: 59422
diff changeset
    55
wenzelm
parents: 59422
diff changeset
    56
  A theory is concluded by a final @{command (global) "end"} command, one
wenzelm
parents: 59422
diff changeset
    57
  that does not belong to a local theory target. No further commands may
wenzelm
parents: 59422
diff changeset
    58
  follow such a global @{command (global) "end"}.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    59
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    60
  @{rail \<open>
59781
wenzelm
parents: 59422
diff changeset
    61
    @@{command theory} @{syntax name} imports? keywords? \<newline> @'begin'
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    62
    ;
47114
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    63
    imports: @'imports' (@{syntax name} +)
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    64
    ;
50128
599c935aac82 alternative completion for outer syntax keywords;
wenzelm
parents: 49243
diff changeset
    65
    keywords: @'keywords' (keyword_decls + @'and')
599c935aac82 alternative completion for outer syntax keywords;
wenzelm
parents: 49243
diff changeset
    66
    ;
599c935aac82 alternative completion for outer syntax keywords;
wenzelm
parents: 49243
diff changeset
    67
    keyword_decls: (@{syntax string} +)
599c935aac82 alternative completion for outer syntax keywords;
wenzelm
parents: 49243
diff changeset
    68
      ('::' @{syntax name} @{syntax tags})? ('==' @{syntax name})?
60093
c48d536231fe clarified thy_deps;
wenzelm
parents: 60091
diff changeset
    69
    ;
c48d536231fe clarified thy_deps;
wenzelm
parents: 60091
diff changeset
    70
    @@{command thy_deps} (thy_bounds thy_bounds?)?
c48d536231fe clarified thy_deps;
wenzelm
parents: 60091
diff changeset
    71
    ;
c48d536231fe clarified thy_deps;
wenzelm
parents: 60091
diff changeset
    72
    thy_bounds: @{syntax name} | '(' (@{syntax name} + @'|') ')'
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    73
  \<close>}
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
    74
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    75
  \<^descr> @{command "theory"}~\<open>A \<IMPORTS> B\<^sub>1 \<dots> B\<^sub>n \<BEGIN>\<close>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    76
  starts a new theory \<open>A\<close> based on the merge of existing
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    77
  theories \<open>B\<^sub>1 \<dots> B\<^sub>n\<close>.  Due to the possibility to import more
47114
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    78
  than one ancestor, the resulting theory structure of an Isabelle
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    79
  session forms a directed acyclic graph (DAG).  Isabelle takes care
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    80
  that sources contributing to the development graph are always
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    81
  up-to-date: changed files are automatically rechecked whenever a
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    82
  theory header specification is processed.
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    83
59781
wenzelm
parents: 59422
diff changeset
    84
  Empty imports are only allowed in the bootstrap process of the special
wenzelm
parents: 59422
diff changeset
    85
  theory @{theory Pure}, which is the start of any other formal development
wenzelm
parents: 59422
diff changeset
    86
  based on Isabelle. Regular user theories usually refer to some more
wenzelm
parents: 59422
diff changeset
    87
  complex entry point, such as theory @{theory Main} in Isabelle/HOL.
wenzelm
parents: 59422
diff changeset
    88
47114
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    89
  The optional @{keyword_def "keywords"} specification declares outer
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    90
  syntax (\chref{ch:outer-syntax}) that is introduced in this theory
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    91
  later on (rare in end-user applications).  Both minor keywords and
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    92
  major keywords of the Isar command language need to be specified, in
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    93
  order to make parsing of proof documents work properly.  Command
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    94
  keywords need to be classified according to their structural role in
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    95
  the formal text.  Examples may be seen in Isabelle/HOL sources
61503
28e788ca2c5d more control symbols;
wenzelm
parents: 61494
diff changeset
    96
  itself, such as @{keyword "keywords"}~\<^verbatim>\<open>"typedef"\<close>
28e788ca2c5d more control symbols;
wenzelm
parents: 61494
diff changeset
    97
  \<open>:: thy_goal\<close> or @{keyword "keywords"}~\<^verbatim>\<open>"datatype"\<close> \<open>:: thy_decl\<close>
28e788ca2c5d more control symbols;
wenzelm
parents: 61494
diff changeset
    98
  for theory-level declarations
47114
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
    99
  with and without proof, respectively.  Additional @{syntax tags}
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
   100
  provide defaults for document preparation (\secref{sec:tags}).
50128
599c935aac82 alternative completion for outer syntax keywords;
wenzelm
parents: 49243
diff changeset
   101
61503
28e788ca2c5d more control symbols;
wenzelm
parents: 61494
diff changeset
   102
  It is possible to specify an alternative completion via \<^verbatim>\<open>==\<close>~\<open>text\<close>,
28e788ca2c5d more control symbols;
wenzelm
parents: 61494
diff changeset
   103
  while the default is the corresponding keyword name.
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   104
  
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   105
  \<^descr> @{command (global) "end"} concludes the current theory
47114
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
   106
  definition.  Note that some other commands, e.g.\ local theory
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
   107
  targets @{command locale} or @{command class} may involve a
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
   108
  @{keyword "begin"} that needs to be matched by @{command (local)
7c9e31ffcd9e updated theory header syntax and related details;
wenzelm
parents: 46999
diff changeset
   109
  "end"}, according to the usual rules for nested blocks.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   110
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   111
  \<^descr> @{command thy_deps} visualizes the theory hierarchy as a directed
60093
c48d536231fe clarified thy_deps;
wenzelm
parents: 60091
diff changeset
   112
  acyclic graph. By default, all imported theories are shown, taking the
c48d536231fe clarified thy_deps;
wenzelm
parents: 60091
diff changeset
   113
  base session as a starting point. Alternatively, it is possibly to
c48d536231fe clarified thy_deps;
wenzelm
parents: 60091
diff changeset
   114
  restrict the full theory graph by giving bounds, analogously to
c48d536231fe clarified thy_deps;
wenzelm
parents: 60091
diff changeset
   115
  @{command_ref class_deps}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   116
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   117
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   118
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   119
section \<open>Local theory targets \label{sec:target}\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   120
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   121
text \<open>
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   122
  \begin{matharray}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   123
    @{command_def "context"} & : & \<open>theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   124
    @{command_def (local) "end"} & : & \<open>local_theory \<rightarrow> theory\<close> \\
59926
003dbac78546 some explanation of 'private';
wenzelm
parents: 59917
diff changeset
   125
    @{keyword_def "private"} \\
59990
a81dc82ecba3 clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents: 59939
diff changeset
   126
    @{keyword_def "qualified"} \\
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   127
  \end{matharray}
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   128
59781
wenzelm
parents: 59422
diff changeset
   129
  A local theory target is a specification context that is managed
wenzelm
parents: 59422
diff changeset
   130
  separately within the enclosing theory. Contexts may introduce parameters
wenzelm
parents: 59422
diff changeset
   131
  (fixed variables) and assumptions (hypotheses). Definitions and theorems
47482
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   132
  depending on the context may be added incrementally later on.
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   133
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   134
  \<^emph>\<open>Named contexts\<close> refer to locales (cf.\ \secref{sec:locale}) or
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   135
  type classes (cf.\ \secref{sec:class}); the name ``\<open>-\<close>''
47482
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   136
  signifies the global theory context.
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   137
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   138
  \<^emph>\<open>Unnamed contexts\<close> may introduce additional parameters and
47482
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   139
  assumptions, and results produced in the context are generalized
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   140
  accordingly.  Such auxiliary contexts may be nested within other
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   141
  targets, like @{command "locale"}, @{command "class"}, @{command
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   142
  "instantiation"}, @{command "overloading"}.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   143
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   144
  @{rail \<open>
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   145
    @@{command context} @{syntax nameref} @'begin'
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   146
    ;
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   147
    @@{command context} @{syntax_ref "includes"}? (@{syntax context_elem} * ) @'begin'
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   148
    ;
46999
1c3c185bab4e more precise syntax;
wenzelm
parents: 45600
diff changeset
   149
    @{syntax_def target}: '(' @'in' @{syntax nameref} ')'
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   150
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   151
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   152
  \<^descr> @{command "context"}~\<open>c \<BEGIN>\<close> opens a named
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   153
  context, by recommencing an existing locale or class \<open>c\<close>.
47482
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   154
  Note that locale and class definitions allow to include the
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   155
  @{keyword "begin"} keyword as well, in order to continue the local
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   156
  theory immediately after the initial specification.
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   157
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   158
  \<^descr> @{command "context"}~\<open>bundles elements \<BEGIN>\<close> opens
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   159
  an unnamed context, by extending the enclosing global or local
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   160
  theory target by the given declaration bundles (\secref{sec:bundle})
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   161
  and context elements (\<open>\<FIXES>\<close>, \<open>\<ASSUMES>\<close>
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   162
  etc.).  This means any results stemming from definitions and proofs
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   163
  in the extended context will be exported into the enclosing target
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   164
  by lifting over extra parameters and premises.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   165
  
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   166
  \<^descr> @{command (local) "end"} concludes the current local theory,
47482
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   167
  according to the nesting of contexts.  Note that a global @{command
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   168
  (global) "end"} has a different meaning: it concludes the theory
a83b25e5bad3 some coverage of unnamed contexts, which can be nested within other targets;
wenzelm
parents: 47114
diff changeset
   169
  itself (\secref{sec:begin-thy}).
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   170
  
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   171
  \<^descr> @{keyword "private"} or @{keyword "qualified"} may be given as
59990
a81dc82ecba3 clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents: 59939
diff changeset
   172
  modifiers before any local theory command. This restricts name space
a81dc82ecba3 clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents: 59939
diff changeset
   173
  accesses to the local scope, as determined by the enclosing @{command
59939
7d46aa03696e support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents: 59926
diff changeset
   174
  "context"}~@{keyword "begin"}~\dots~@{command "end"} block. Outside its
7d46aa03696e support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents: 59926
diff changeset
   175
  scope, a @{keyword "private"} name is inaccessible, and a @{keyword
60297
wenzelm
parents: 60093
diff changeset
   176
  "qualified"} name is only accessible with some qualification.
59939
7d46aa03696e support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents: 59926
diff changeset
   177
7d46aa03696e support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents: 59926
diff changeset
   178
  Neither a global @{command theory} nor a @{command locale} target provides
7d46aa03696e support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents: 59926
diff changeset
   179
  a local scope by itself: an extra unnamed context is required to use
59990
a81dc82ecba3 clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents: 59939
diff changeset
   180
  @{keyword "private"} or @{keyword "qualified"} here.
59926
003dbac78546 some explanation of 'private';
wenzelm
parents: 59917
diff changeset
   181
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   182
  \<^descr> \<open>(\<close>@{keyword_def "in"}~\<open>c)\<close> given after any local
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   183
  theory command specifies an immediate target, e.g.\ ``@{command
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   184
  "definition"}~\<open>(\<IN> c)\<close>'' or ``@{command "theorem"}~\<open>(\<IN> c)\<close>''. This works both in a local or global theory context; the
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   185
  current target context will be suspended for this command only. Note that
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   186
  ``\<open>(\<IN> -)\<close>'' will always produce a global result independently
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   187
  of the current target context.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   188
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   189
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   190
  Any specification element that operates on \<open>local_theory\<close> according
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   191
  to this manual implicitly allows the above target syntax \<open>(\<close>@{keyword "in"}~\<open>c)\<close>, but individual syntax diagrams omit that
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   192
  aspect for clarity.
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   193
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   194
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   195
  The exact meaning of results produced within a local theory
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   196
  context depends on the underlying target infrastructure (locale, type
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   197
  class etc.). The general idea is as follows, considering a context named
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   198
  \<open>c\<close> with parameter \<open>x\<close> and assumption \<open>A[x]\<close>.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   199
  
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   200
  Definitions are exported by introducing a global version with
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   201
  additional arguments; a syntactic abbreviation links the long form
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   202
  with the abstract version of the target context.  For example,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   203
  \<open>a \<equiv> t[x]\<close> becomes \<open>c.a ?x \<equiv> t[?x]\<close> at the theory
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   204
  level (for arbitrary \<open>?x\<close>), together with a local
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   205
  abbreviation \<open>c \<equiv> c.a x\<close> in the target context (for the
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   206
  fixed parameter \<open>x\<close>).
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   207
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   208
  Theorems are exported by discharging the assumptions and
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   209
  generalizing the parameters of the context.  For example, \<open>a:
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   210
  B[x]\<close> becomes \<open>c.a: A[?x] \<Longrightarrow> B[?x]\<close>, again for arbitrary
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   211
  \<open>?x\<close>.
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   212
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   213
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   214
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   215
section \<open>Bundled declarations \label{sec:bundle}\<close>
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   216
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   217
text \<open>
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   218
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   219
    @{command_def "bundle"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
61494
63b18f758874 proper spaces around @{text};
wenzelm
parents: 61493
diff changeset
   220
    @{command_def "print_bundles"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   221
    @{command_def "include"} & : & \<open>proof(state) \<rightarrow> proof(state)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   222
    @{command_def "including"} & : & \<open>proof(prove) \<rightarrow> proof(prove)\<close> \\
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   223
    @{keyword_def "includes"} & : & syntax \\
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   224
  \end{matharray}
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   225
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   226
  The outer syntax of fact expressions (\secref{sec:syn-att}) involves
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   227
  theorems and attributes, which are evaluated in the context and
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   228
  applied to it.  Attributes may declare theorems to the context, as
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   229
  in \<open>this_rule [intro] that_rule [elim]\<close> for example.
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   230
  Configuration options (\secref{sec:config}) are special declaration
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   231
  attributes that operate on the context without a theorem, as in
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   232
  \<open>[[show_types = false]]\<close> for example.
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   233
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   234
  Expressions of this form may be defined as \<^emph>\<open>bundled
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   235
  declarations\<close> in the context, and included in other situations later
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   236
  on.  Including declaration bundles augments a local context casually
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   237
  without logical dependencies, which is in contrast to locales and
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   238
  locale interpretation (\secref{sec:locale}).
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   239
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   240
  @{rail \<open>
59785
4e6ab5831cc0 clarified syntax category "fixes";
wenzelm
parents: 59783
diff changeset
   241
    @@{command bundle} @{syntax name} '=' @{syntax thmrefs} @{syntax for_fixes}
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   242
    ;
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   243
    @@{command print_bundles} ('!'?)
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   244
    ;
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   245
    (@@{command include} | @@{command including}) (@{syntax nameref}+)
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   246
    ;
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   247
    @{syntax_def "includes"}: @'includes' (@{syntax nameref}+)
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   248
  \<close>}
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   249
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   250
  \<^descr> @{command bundle}~\<open>b = decls\<close> defines a bundle of
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   251
  declarations in the current context.  The RHS is similar to the one
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   252
  of the @{command declare} command.  Bundles defined in local theory
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   253
  targets are subject to transformations via morphisms, when moved
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   254
  into different application contexts; this works analogously to any
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   255
  other local theory specification.
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   256
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   257
  \<^descr> @{command print_bundles} prints the named bundles that are available
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   258
  in the current context; the ``\<open>!\<close>'' option indicates extra
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   259
  verbosity.
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   260
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   261
  \<^descr> @{command include}~\<open>b\<^sub>1 \<dots> b\<^sub>n\<close> includes the declarations
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   262
  from the given bundles into the current proof body context.  This is
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   263
  analogous to @{command "note"} (\secref{sec:proof-facts}) with the
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   264
  expanded bundles.
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   265
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   266
  \<^descr> @{command including} is similar to @{command include}, but
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   267
  works in proof refinement (backward mode).  This is analogous to
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   268
  @{command "using"} (\secref{sec:proof-facts}) with the expanded
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   269
  bundles.
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   270
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   271
  \<^descr> @{keyword "includes"}~\<open>b\<^sub>1 \<dots> b\<^sub>n\<close> is similar to
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   272
  @{command include}, but works in situations where a specification
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   273
  context is constructed, notably for @{command context} and long
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   274
  statements of @{command theorem} etc.
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   275
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   276
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   277
  Here is an artificial example of bundling various configuration
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   278
  options:
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   279
\<close>
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   280
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59901
diff changeset
   281
(*<*)experiment begin(*>*)
53536
69c943125fd3 do not expose internal flags to attribute name space;
wenzelm
parents: 53370
diff changeset
   282
bundle trace = [[simp_trace, linarith_trace, metis_trace, smt_trace]]
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   283
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   284
lemma "x = x"
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   285
  including trace by metis
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59901
diff changeset
   286
(*<*)end(*>*)
47484
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   287
e94cc23d434a some coverage of bundled declarations;
wenzelm
parents: 47483
diff changeset
   288
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   289
section \<open>Term definitions \label{sec:term-definitions}\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   290
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   291
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   292
  \begin{matharray}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   293
    @{command_def "definition"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   294
    @{attribute_def "defn"} & : & \<open>attribute\<close> \\
61494
63b18f758874 proper spaces around @{text};
wenzelm
parents: 61493
diff changeset
   295
    @{command_def "print_defn_rules"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   296
    @{command_def "abbreviation"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
61494
63b18f758874 proper spaces around @{text};
wenzelm
parents: 61493
diff changeset
   297
    @{command_def "print_abbrevs"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   298
  \end{matharray}
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   299
57487
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   300
  Term definitions may either happen within the logic (as equational axioms
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   301
  of a certain form, see also see \secref{sec:consts}), or outside of it as
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   302
  rewrite system on abstract syntax. The second form is called
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   303
  ``abbreviation''.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   304
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   305
  @{rail \<open>
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   306
    @@{command definition} (decl @'where')? @{syntax thmdecl}? @{syntax prop}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   307
    ;
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   308
    @@{command abbreviation} @{syntax mode}? \<newline>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   309
      (decl @'where')? @{syntax prop}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   310
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   311
    decl: @{syntax name} ('::' @{syntax type})? @{syntax mixfix}?
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   312
    ;
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   313
    @@{command print_abbrevs} ('!'?)
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   314
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   315
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   316
  \<^descr> @{command "definition"}~\<open>c \<WHERE> eq\<close> produces an
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   317
  internal definition \<open>c \<equiv> t\<close> according to the specification
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   318
  given as \<open>eq\<close>, which is then turned into a proven fact.  The
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   319
  given proposition may deviate from internal meta-level equality
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   320
  according to the rewrite rules declared as @{attribute defn} by the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   321
  object-logic.  This usually covers object-level equality \<open>x =
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   322
  y\<close> and equivalence \<open>A \<leftrightarrow> B\<close>.  End-users normally need not
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   323
  change the @{attribute defn} setup.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   324
  
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   325
  Definitions may be presented with explicit arguments on the LHS, as
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   326
  well as additional conditions, e.g.\ \<open>f x y = t\<close> instead of
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   327
  \<open>f \<equiv> \<lambda>x y. t\<close> and \<open>y \<noteq> 0 \<Longrightarrow> g x y = u\<close> instead of an
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   328
  unrestricted \<open>g \<equiv> \<lambda>x y. u\<close>.
51585
fcd5af4aac2b added 'print_defn_rules' command;
wenzelm
parents: 51565
diff changeset
   329
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   330
  \<^descr> @{command "print_defn_rules"} prints the definitional rewrite rules
51585
fcd5af4aac2b added 'print_defn_rules' command;
wenzelm
parents: 51565
diff changeset
   331
  declared via @{attribute defn} in the current context.
fcd5af4aac2b added 'print_defn_rules' command;
wenzelm
parents: 51565
diff changeset
   332
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   333
  \<^descr> @{command "abbreviation"}~\<open>c \<WHERE> eq\<close> introduces a
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
   334
  syntactic constant which is associated with a certain term according
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   335
  to the meta-level equality \<open>eq\<close>.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   336
  
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   337
  Abbreviations participate in the usual type-inference process, but
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   338
  are expanded before the logic ever sees them.  Pretty printing of
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   339
  terms involves higher-order rewriting with rules stemming from
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   340
  reverted abbreviations.  This needs some care to avoid overlapping
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   341
  or looping syntactic replacements!
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   342
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   343
  The optional \<open>mode\<close> specification restricts output to a
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   344
  particular print mode; using ``\<open>input\<close>'' here achieves the
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   345
  effect of one-way abbreviations.  The mode may also include an
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   346
  ``@{keyword "output"}'' qualifier that affects the concrete syntax
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   347
  declared for abbreviations, cf.\ @{command "syntax"} in
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   348
  \secref{sec:syn-trans}.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   349
  
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   350
  \<^descr> @{command "print_abbrevs"} prints all constant abbreviations of the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   351
  current context; the ``\<open>!\<close>'' option indicates extra verbosity.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   352
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   353
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   354
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   355
section \<open>Axiomatizations \label{sec:axiomatizations}\<close>
57487
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   356
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   357
text \<open>
57487
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   358
  \begin{matharray}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   359
    @{command_def "axiomatization"} & : & \<open>theory \<rightarrow> theory\<close> & (axiomatic!) \\
57487
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   360
  \end{matharray}
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   361
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   362
  @{rail \<open>
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   363
    @@{command axiomatization} @{syntax "fixes"}? (@'where' specs)?
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   364
    ;
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   365
    specs: (@{syntax thmdecl}? @{syntax props} + @'and')
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   366
  \<close>}
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   367
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   368
  \<^descr> @{command "axiomatization"}~\<open>c\<^sub>1 \<dots> c\<^sub>m \<WHERE> \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n\<close>
57487
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   369
  introduces several constants simultaneously and states axiomatic
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   370
  properties for these. The constants are marked as being specified once and
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   371
  for all, which prevents additional specifications for the same constants
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   372
  later on, but it is always possible do emit axiomatizations without
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   373
  referring to particular constants. Note that lack of precise dependency
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   374
  tracking of axiomatizations may disrupt the well-formedness of an
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   375
  otherwise definitional theory.
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   376
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   377
  Axiomatization is restricted to a global theory context: support for local
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   378
  theory targets \secref{sec:target} would introduce an extra dimension of
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   379
  uncertainty what the written specifications really are, and make it
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   380
  infeasible to argue why they are correct.
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   381
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   382
  Axiomatic specifications are required when declaring a new logical system
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   383
  within Isabelle/Pure, but in an application environment like Isabelle/HOL
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   384
  the user normally stays within definitional mechanisms provided by the
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   385
  logic and its libraries.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   386
\<close>
57487
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   387
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   388
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   389
section \<open>Generic declarations\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   390
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   391
text \<open>
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   392
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   393
    @{command_def "declaration"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   394
    @{command_def "syntax_declaration"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   395
    @{command_def "declare"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   396
  \end{matharray}
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   397
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   398
  Arbitrary operations on the background context may be wrapped-up as
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   399
  generic declaration elements.  Since the underlying concept of local
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   400
  theories may be subject to later re-interpretation, there is an
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   401
  additional dependency on a morphism that tells the difference of the
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   402
  original declaration context wrt.\ the application context
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   403
  encountered later on.  A fact declaration is an important special
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   404
  case: it consists of a theorem which is applied to the context by
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   405
  means of an attribute.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   406
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   407
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   408
    (@@{command declaration} | @@{command syntax_declaration})
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   409
      ('(' @'pervasive' ')')? \<newline> @{syntax text}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   410
    ;
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   411
    @@{command declare} (@{syntax thmrefs} + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   412
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   413
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   414
  \<^descr> @{command "declaration"}~\<open>d\<close> adds the declaration
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   415
  function \<open>d\<close> of ML type @{ML_type declaration}, to the current
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   416
  local theory under construction.  In later application contexts, the
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   417
  function is transformed according to the morphisms being involved in
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   418
  the interpretation hierarchy.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   419
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   420
  If the \<open>(pervasive)\<close> option is given, the corresponding
33516
0855a09bc5cf added "declaration (pervasive)";
wenzelm
parents: 31914
diff changeset
   421
  declaration is applied to all possible contexts involved, including
0855a09bc5cf added "declaration (pervasive)";
wenzelm
parents: 31914
diff changeset
   422
  the global background theory.
0855a09bc5cf added "declaration (pervasive)";
wenzelm
parents: 31914
diff changeset
   423
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   424
  \<^descr> @{command "syntax_declaration"} is similar to @{command
40784
177e8cea3e09 added 'syntax_declaration' command;
wenzelm
parents: 40256
diff changeset
   425
  "declaration"}, but is meant to affect only ``syntactic'' tools by
177e8cea3e09 added 'syntax_declaration' command;
wenzelm
parents: 40256
diff changeset
   426
  convention (such as notation and type-checking information).
177e8cea3e09 added 'syntax_declaration' command;
wenzelm
parents: 40256
diff changeset
   427
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   428
  \<^descr> @{command "declare"}~\<open>thms\<close> declares theorems to the
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   429
  current local theory context.  No theorem binding is involved here,
61337
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 60297
diff changeset
   430
  unlike @{command "lemmas"} (cf.\ \secref{sec:theorems}), so
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 60297
diff changeset
   431
  @{command "declare"} only has the effect of applying attributes as
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 60297
diff changeset
   432
  included in the theorem specification.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   433
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   434
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   435
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   436
section \<open>Locales \label{sec:locale}\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   437
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   438
text \<open>
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   439
  A locale is a functor that maps parameters (including implicit type
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   440
  parameters) and a specification to a list of declarations.  The
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   441
  syntax of locales is modeled after the Isar proof context commands
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   442
  (cf.\ \secref{sec:proof-context}).
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   443
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   444
  Locale hierarchies are supported by maintaining a graph of
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   445
  dependencies between locale instances in the global theory.
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   446
  Dependencies may be introduced through import (where a locale is
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   447
  defined as sublocale of the imported instances) or by proving that
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   448
  an existing locale is a sublocale of one or several locale
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   449
  instances.
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   450
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   451
  A locale may be opened with the purpose of appending to its list of
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   452
  declarations (cf.\ \secref{sec:target}).  When opening a locale
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   453
  declarations from all dependencies are collected and are presented
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   454
  as a local theory.  In this process, which is called \<^emph>\<open>roundup\<close>,
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   455
  redundant locale instances are omitted.  A locale instance is
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   456
  redundant if it is subsumed by an instance encountered earlier.  A
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   457
  more detailed description of this process is available elsewhere
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58316
diff changeset
   458
  @{cite Ballarin2014}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   459
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   460
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   461
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   462
subsection \<open>Locale expressions \label{sec:locale-expr}\<close>
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   463
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   464
text \<open>
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   465
  A \<^emph>\<open>locale expression\<close> denotes a context composed of instances
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   466
  of existing locales.  The context consists of the declaration
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   467
  elements from the locale instances.  Redundant locale instances are
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   468
  omitted according to roundup.
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   469
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   470
  @{rail \<open>
59785
4e6ab5831cc0 clarified syntax category "fixes";
wenzelm
parents: 59783
diff changeset
   471
    @{syntax_def locale_expr}: (instance + '+') @{syntax for_fixes}
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   472
    ;
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   473
    instance: (qualifier ':')? @{syntax nameref} (pos_insts | named_insts)
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   474
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   475
    qualifier: @{syntax name} ('?' | '!')?
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   476
    ;
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   477
    pos_insts: ('_' | @{syntax term})*
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   478
    ;
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   479
    named_insts: @'where' (@{syntax name} '=' @{syntax term} + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   480
  \<close>}
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   481
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   482
  A locale instance consists of a reference to a locale and either
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   483
  positional or named parameter instantiations.  Identical
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   484
  instantiations (that is, those that instantiate a parameter by itself)
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   485
  may be omitted.  The notation `\<open>_\<close>' enables to omit the
40256
eb5412b77ac4 eliminated obsolete \_ escape;
wenzelm
parents: 40255
diff changeset
   486
  instantiation for a parameter inside a positional instantiation.
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   487
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   488
  Terms in instantiations are from the context the locale expressions
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   489
  is declared in.  Local names may be added to this context with the
48824
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   490
  optional @{keyword "for"} clause.  This is useful for shadowing names
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   491
  bound in outer contexts, and for declaring syntax.  In addition,
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   492
  syntax declarations from one instance are effective when parsing
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   493
  subsequent instances of the same expression.
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   494
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   495
  Instances have an optional qualifier which applies to names in
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   496
  declarations.  Names include local definitions and theorem names.
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   497
  If present, the qualifier itself is either optional
61503
28e788ca2c5d more control symbols;
wenzelm
parents: 61494
diff changeset
   498
  (``\<^verbatim>\<open>?\<close>''), which means that it may be omitted on input of the
28e788ca2c5d more control symbols;
wenzelm
parents: 61494
diff changeset
   499
  qualified name, or mandatory (``\<^verbatim>\<open>!\<close>'').  If neither
61565
352c73a689da Qualifiers in locale expressions default to mandatory regardless of the command.
ballarin
parents: 61503
diff changeset
   500
  ``\<^verbatim>\<open>?\<close>'' nor ``\<^verbatim>\<open>!\<close>'' are present the default
352c73a689da Qualifiers in locale expressions default to mandatory regardless of the command.
ballarin
parents: 61503
diff changeset
   501
  is used, which is ``mandatory''.  Qualifiers play no role
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   502
  in determining whether one locale instance subsumes another.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   503
\<close>
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   504
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   505
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   506
subsection \<open>Locale declarations\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   507
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   508
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   509
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   510
    @{command_def "locale"} & : & \<open>theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   511
    @{command_def "experiment"} & : & \<open>theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   512
    @{command_def "print_locale"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   513
    @{command_def "print_locales"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   514
    @{command_def "locale_deps"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   515
    @{method_def intro_locales} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   516
    @{method_def unfold_locales} & : & \<open>method\<close> \\
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   517
  \end{matharray}
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   518
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   519
  \indexisarelem{fixes}\indexisarelem{constrains}\indexisarelem{assumes}
28787
8ea7403147c5 removed "includes" element (lost update?);
wenzelm
parents: 28768
diff changeset
   520
  \indexisarelem{defines}\indexisarelem{notes}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   521
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   522
    @@{command locale} @{syntax name} ('=' @{syntax locale})? @'begin'?
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   523
    ;
59901
840d03805755 added command 'experiment';
wenzelm
parents: 59785
diff changeset
   524
    @@{command experiment} (@{syntax context_elem}*) @'begin'
840d03805755 added command 'experiment';
wenzelm
parents: 59785
diff changeset
   525
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   526
    @@{command print_locale} '!'? @{syntax nameref}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   527
    ;
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   528
    @@{command print_locales} ('!'?)
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   529
    ;
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   530
    @{syntax_def locale}: @{syntax context_elem}+ |
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   531
      @{syntax locale_expr} ('+' (@{syntax context_elem}+))?
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   532
    ;
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   533
    @{syntax_def context_elem}:
59785
4e6ab5831cc0 clarified syntax category "fixes";
wenzelm
parents: 59783
diff changeset
   534
      @'fixes' @{syntax "fixes"} |
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   535
      @'constrains' (@{syntax name} '::' @{syntax type} + @'and') |
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   536
      @'assumes' (@{syntax props} + @'and') |
42705
528a2ba8fa74 tuned some syntax names;
wenzelm
parents: 42704
diff changeset
   537
      @'defines' (@{syntax thmdecl}? @{syntax prop} @{syntax prop_pat}? + @'and') |
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   538
      @'notes' (@{syntax thmdef}? @{syntax thmrefs} + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   539
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   540
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   541
  \<^descr> @{command "locale"}~\<open>loc = import + body\<close> defines a
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   542
  new locale \<open>loc\<close> as a context consisting of a certain view of
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   543
  existing locales (\<open>import\<close>) plus some additional elements
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   544
  (\<open>body\<close>).  Both \<open>import\<close> and \<open>body\<close> are optional;
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   545
  the degenerate form @{command "locale"}~\<open>loc\<close> defines an empty
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   546
  locale, which may still be useful to collect declarations of facts
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   547
  later on.  Type-inference on locale expressions automatically takes
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   548
  care of the most general typing that the combined context elements
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   549
  may acquire.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   550
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   551
  The \<open>import\<close> consists of a locale expression; see
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   552
  \secref{sec:proof-context} above.  Its @{keyword "for"} clause defines
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   553
  the parameters of \<open>import\<close>.  These are parameters of
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   554
  the defined locale.  Locale parameters whose instantiation is
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   555
  omitted automatically extend the (possibly empty) @{keyword "for"}
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   556
  clause: they are inserted at its beginning.  This means that these
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   557
  parameters may be referred to from within the expression and also in
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   558
  the subsequent context elements and provides a notational
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   559
  convenience for the inheritance of parameters in locale
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   560
  declarations.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   561
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   562
  The \<open>body\<close> consists of context elements.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   563
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   564
    \<^descr> @{element "fixes"}~\<open>x :: \<tau> (mx)\<close> declares a local
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   565
    parameter of type \<open>\<tau>\<close> and mixfix annotation \<open>mx\<close> (both
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   566
    are optional).  The special syntax declaration ``\<open>(\<close>@{keyword_ref "structure"}\<open>)\<close>'' means that \<open>x\<close> may
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   567
    be referenced implicitly in this context.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   568
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   569
    \<^descr> @{element "constrains"}~\<open>x :: \<tau>\<close> introduces a type
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   570
    constraint \<open>\<tau>\<close> on the local parameter \<open>x\<close>.  This
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   571
    element is deprecated.  The type constraint should be introduced in
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   572
    the @{keyword "for"} clause or the relevant @{element "fixes"} element.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   573
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   574
    \<^descr> @{element "assumes"}~\<open>a: \<phi>\<^sub>1 \<dots> \<phi>\<^sub>n\<close>
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   575
    introduces local premises, similar to @{command "assume"} within a
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   576
    proof (cf.\ \secref{sec:proof-context}).
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   577
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   578
    \<^descr> @{element "defines"}~\<open>a: x \<equiv> t\<close> defines a previously
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   579
    declared parameter.  This is similar to @{command "def"} within a
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   580
    proof (cf.\ \secref{sec:proof-context}), but @{element "defines"}
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   581
    takes an equational proposition instead of variable-term pair.  The
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   582
    left-hand side of the equation may have additional arguments, e.g.\
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   583
    ``@{element "defines"}~\<open>f x\<^sub>1 \<dots> x\<^sub>n \<equiv> t\<close>''.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   584
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   585
    \<^descr> @{element "notes"}~\<open>a = b\<^sub>1 \<dots> b\<^sub>n\<close>
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   586
    reconsiders facts within a local context.  Most notably, this may
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   587
    include arbitrary declarations in any attribute specifications
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   588
    included here, e.g.\ a local @{attribute simp} rule.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   589
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   590
  Both @{element "assumes"} and @{element "defines"} elements
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   591
  contribute to the locale specification.  When defining an operation
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   592
  derived from the parameters, @{command "definition"}
57487
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
   593
  (\secref{sec:term-definitions}) is usually more appropriate.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   594
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   595
  Note that ``\<open>(\<IS> p\<^sub>1 \<dots> p\<^sub>n)\<close>'' patterns given
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   596
  in the syntax of @{element "assumes"} and @{element "defines"} above
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   597
  are illegal in locale definitions.  In the long goal format of
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   598
  \secref{sec:goals}, term bindings may be included as expected,
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   599
  though.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   600
  
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   601
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   602
  Locale specifications are ``closed up'' by
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   603
  turning the given text into a predicate definition \<open>loc_axioms\<close> and deriving the original assumptions as local lemmas
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   604
  (modulo local definitions).  The predicate statement covers only the
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   605
  newly specified assumptions, omitting the content of included locale
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   606
  expressions.  The full cumulative view is only provided on export,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   607
  involving another predicate \<open>loc\<close> that refers to the complete
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   608
  specification text.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   609
  
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   610
  In any case, the predicate arguments are those locale parameters
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   611
  that actually occur in the respective piece of text.  Also these
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   612
  predicates operate at the meta-level in theory, but the locale
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   613
  packages attempts to internalize statements according to the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   614
  object-logic setup (e.g.\ replacing \<open>\<And>\<close> by \<open>\<forall>\<close>, and
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   615
  \<open>\<Longrightarrow>\<close> by \<open>\<longrightarrow>\<close> in HOL; see also
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   616
  \secref{sec:object-logic}).  Separate introduction rules \<open>loc_axioms.intro\<close> and \<open>loc.intro\<close> are provided as well.
59901
840d03805755 added command 'experiment';
wenzelm
parents: 59785
diff changeset
   617
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   618
  \<^descr> @{command experiment}~\<open>exprs\<close>~@{keyword "begin"} opens an
59901
840d03805755 added command 'experiment';
wenzelm
parents: 59785
diff changeset
   619
  anonymous locale context with private naming policy. Specifications in its
840d03805755 added command 'experiment';
wenzelm
parents: 59785
diff changeset
   620
  body are inaccessible from outside. This is useful to perform experiments,
840d03805755 added command 'experiment';
wenzelm
parents: 59785
diff changeset
   621
  without polluting the name space.
840d03805755 added command 'experiment';
wenzelm
parents: 59785
diff changeset
   622
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   623
  \<^descr> @{command "print_locale"}~\<open>locale\<close> prints the
33867
52643d0f856d Typos in documenation.
ballarin
parents: 33846
diff changeset
   624
  contents of the named locale.  The command omits @{element "notes"}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   625
  elements by default.  Use @{command "print_locale"}\<open>!\<close> to
33867
52643d0f856d Typos in documenation.
ballarin
parents: 33846
diff changeset
   626
  have them included.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   627
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   628
  \<^descr> @{command "print_locales"} prints the names of all locales of the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   629
  current theory; the ``\<open>!\<close>'' option indicates extra verbosity.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   630
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   631
  \<^descr> @{command "locale_deps"} visualizes all locales and their
50716
e04c44dc11fc document 'locale_deps';
wenzelm
parents: 50128
diff changeset
   632
  relations as a Hasse diagram. This includes locales defined as type
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   633
  classes (\secref{sec:class}).  See also @{command
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   634
  "print_dependencies"} below.
50716
e04c44dc11fc document 'locale_deps';
wenzelm
parents: 50128
diff changeset
   635
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   636
  \<^descr> @{method intro_locales} and @{method unfold_locales}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   637
  repeatedly expand all introduction rules of locale predicates of the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   638
  theory.  While @{method intro_locales} only applies the \<open>loc.intro\<close> introduction rules and therefore does not descend to
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   639
  assumptions, @{method unfold_locales} is more aggressive and applies
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   640
  \<open>loc_axioms.intro\<close> as well.  Both methods are aware of locale
28787
8ea7403147c5 removed "includes" element (lost update?);
wenzelm
parents: 28768
diff changeset
   641
  specifications entailed by the context, both from target statements,
8ea7403147c5 removed "includes" element (lost update?);
wenzelm
parents: 28768
diff changeset
   642
  and from interpretations (see below).  New goals that are entailed
8ea7403147c5 removed "includes" element (lost update?);
wenzelm
parents: 28768
diff changeset
   643
  by the current context are discharged automatically.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   644
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   645
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   646
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   647
subsection \<open>Locale interpretation\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   648
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   649
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   650
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   651
    @{command_def "interpretation"} & : & \<open>theory | local_theory \<rightarrow> proof(prove)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   652
    @{command_def "interpret"} & : & \<open>proof(state) | proof(chain) \<rightarrow> proof(prove)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   653
    @{command_def "sublocale"} & : & \<open>theory | local_theory \<rightarrow> proof(prove)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   654
    @{command_def "print_dependencies"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   655
    @{command_def "print_interps"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   656
  \end{matharray}
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   657
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   658
  Locales may be instantiated, and the resulting instantiated
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   659
  declarations added to the current context.  This requires proof (of
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   660
  the instantiated specification) and is called \<^emph>\<open>locale
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   661
  interpretation\<close>.  Interpretation is possible in locales (@{command
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   662
  "sublocale"}), global and local theories (@{command
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   663
  "interpretation"}) and also within proof bodies (@{command
48824
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   664
  "interpret"}).
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   665
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   666
  @{rail \<open>
53368
92b9965f479d Clarifies documentation of interpretation in local theories.
ballarin
parents: 53015
diff changeset
   667
    @@{command interpretation} @{syntax locale_expr} equations?
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   668
    ;
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   669
    @@{command interpret} @{syntax locale_expr} equations?
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   670
    ;
55029
61a6bf7d4b02 clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents: 54049
diff changeset
   671
    @@{command sublocale} (@{syntax nameref} ('<' | '\<subseteq>'))? @{syntax locale_expr} \<newline>
42704
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
   672
      equations?
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   673
    ;
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   674
    @@{command print_dependencies} '!'? @{syntax locale_expr}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   675
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   676
    @@{command print_interps} @{syntax nameref}
41434
710cdb9e0d17 Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents: 41249
diff changeset
   677
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   678
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61565
diff changeset
   679
    equations: @'rewrites' (@{syntax thmdecl}? @{syntax prop} + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   680
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   681
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61565
diff changeset
   682
  \<^descr> @{command "interpretation"}~\<open>expr\<close>~@{keyword "rewrites"}~\<open>eqns\<close>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   683
  interprets \<open>expr\<close> in a global or local theory.  The command
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   684
  generates proof obligations for the instantiated specifications.
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   685
  Once these are discharged by the user, instantiated declarations (in
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   686
  particular, facts) are added to the theory in a post-processing
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   687
  phase.
53368
92b9965f479d Clarifies documentation of interpretation in local theories.
ballarin
parents: 53015
diff changeset
   688
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   689
  The command is aware of interpretations that are already active.
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   690
  Post-processing is achieved through a variant of roundup that takes
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   691
  the interpretations of the current global or local theory into
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   692
  account.  In order to simplify the proof obligations according to
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   693
  existing interpretations use methods @{method intro_locales} or
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   694
  @{method unfold_locales}.
53368
92b9965f479d Clarifies documentation of interpretation in local theories.
ballarin
parents: 53015
diff changeset
   695
53369
b4bcac7d065b Clarifies that interpretation does not only apply to facts, but to declaratoins in general.
ballarin
parents: 53368
diff changeset
   696
  When adding declarations to locales, interpreted versions of these
b4bcac7d065b Clarifies that interpretation does not only apply to facts, but to declaratoins in general.
ballarin
parents: 53368
diff changeset
   697
  declarations are added to the global theory for all interpretations
b4bcac7d065b Clarifies that interpretation does not only apply to facts, but to declaratoins in general.
ballarin
parents: 53368
diff changeset
   698
  in the global theory as well. That is, interpretations in global
b4bcac7d065b Clarifies that interpretation does not only apply to facts, but to declaratoins in general.
ballarin
parents: 53368
diff changeset
   699
  theories dynamically participate in any declarations added to
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   700
  locales.
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   701
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   702
  In contrast, the lifetime of an interpretation in a local theory is
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   703
  limited to the current context block.  At the closing @{command end}
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   704
  of the block the interpretation and its declarations disappear.
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   705
  This enables establishing facts based on interpretations without
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   706
  creating permanent links to the interpreted locale instances, as
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   707
  would be the case with @{command sublocale}.
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   708
  While @{command "interpretation"}~\<open>(\<IN> c)
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   709
  \<dots>\<close> is technically possible, it is not useful since its result is
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   710
  discarded immediately.
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   711
48824
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   712
  Free variables in the interpreted expression are allowed.  They are
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   713
  turned into schematic variables in the generated declarations.  In
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   714
  order to use a free variable whose name is already bound in the
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   715
  context --- for example, because a constant of that name exists ---
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   716
  add it to the @{keyword "for"} clause.
48824
45d0e40b07af Clarification: free variables allowed in interpreted locale instances.
ballarin
parents: 47484
diff changeset
   717
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   718
  The equations \<open>eqns\<close> yield \<^emph>\<open>rewrite morphisms\<close>, which are
53370
7a41ec2cc522 Further clarifies sublocale and rewrite morphisms.
ballarin
parents: 53369
diff changeset
   719
  unfolded during post-processing and are useful for interpreting
7a41ec2cc522 Further clarifies sublocale and rewrite morphisms.
ballarin
parents: 53369
diff changeset
   720
  concepts introduced through definitions.  The equations must be
7a41ec2cc522 Further clarifies sublocale and rewrite morphisms.
ballarin
parents: 53369
diff changeset
   721
  proved.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   722
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61565
diff changeset
   723
  \<^descr> @{command "interpret"}~\<open>expr\<close>~@{keyword "rewrites"}~\<open>eqns\<close> interprets
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   724
  \<open>expr\<close> in the proof context and is otherwise similar to
53370
7a41ec2cc522 Further clarifies sublocale and rewrite morphisms.
ballarin
parents: 53369
diff changeset
   725
  interpretation in local theories.  Note that for @{command
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   726
  "interpret"} the \<open>eqns\<close> should be
41434
710cdb9e0d17 Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents: 41249
diff changeset
   727
  explicitly universally quantified.
710cdb9e0d17 Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents: 41249
diff changeset
   728
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61565
diff changeset
   729
  \<^descr> @{command "sublocale"}~\<open>name \<subseteq> expr\<close>~@{keyword "rewrites"}~\<open>eqns\<close>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   730
  interprets \<open>expr\<close> in the locale \<open>name\<close>.  A proof that
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   731
  the specification of \<open>name\<close> implies the specification of
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   732
  \<open>expr\<close> is required.  As in the localized version of the
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   733
  theorem command, the proof is in the context of \<open>name\<close>.  After
53370
7a41ec2cc522 Further clarifies sublocale and rewrite morphisms.
ballarin
parents: 53369
diff changeset
   734
  the proof obligation has been discharged, the locale hierarchy is
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   735
  changed as if \<open>name\<close> imported \<open>expr\<close> (hence the name
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   736
  @{command "sublocale"}).  When the context of \<open>name\<close> is
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   737
  subsequently entered, traversing the locale hierarchy will involve
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   738
  the locale instances of \<open>expr\<close>, and their declarations will be
53370
7a41ec2cc522 Further clarifies sublocale and rewrite morphisms.
ballarin
parents: 53369
diff changeset
   739
  added to the context.  This makes @{command "sublocale"}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   740
  dynamic: extensions of a locale that is instantiated in \<open>expr\<close>
53370
7a41ec2cc522 Further clarifies sublocale and rewrite morphisms.
ballarin
parents: 53369
diff changeset
   741
  may take place after the @{command "sublocale"} declaration and
7a41ec2cc522 Further clarifies sublocale and rewrite morphisms.
ballarin
parents: 53369
diff changeset
   742
  still become available in the context.  Circular @{command
7a41ec2cc522 Further clarifies sublocale and rewrite morphisms.
ballarin
parents: 53369
diff changeset
   743
  "sublocale"} declarations are allowed as long as they do not lead to
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   744
  infinite chains.
41434
710cdb9e0d17 Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents: 41249
diff changeset
   745
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   746
  If interpretations of \<open>name\<close> exist in the current global
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   747
  theory, the command adds interpretations for \<open>expr\<close> as well,
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   748
  with the same qualifier, although only for fragments of \<open>expr\<close>
53368
92b9965f479d Clarifies documentation of interpretation in local theories.
ballarin
parents: 53015
diff changeset
   749
  that are not interpreted in the theory already.
41434
710cdb9e0d17 Documentation for 'interpret' and 'sublocale' with mixins.
ballarin
parents: 41249
diff changeset
   750
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   751
  The equations \<open>eqns\<close> amend the morphism through
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   752
  which \<open>expr\<close> is interpreted.  This enables mapping definitions
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   753
  from the interpreted locales to entities of \<open>name\<close> and can
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   754
  help break infinite chains induced by circular @{command
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   755
  "sublocale"} declarations.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   756
53368
92b9965f479d Clarifies documentation of interpretation in local theories.
ballarin
parents: 53015
diff changeset
   757
  In a named context block the @{command sublocale} command may also
92b9965f479d Clarifies documentation of interpretation in local theories.
ballarin
parents: 53015
diff changeset
   758
  be used, but the locale argument must be omitted.  The command then
92b9965f479d Clarifies documentation of interpretation in local theories.
ballarin
parents: 53015
diff changeset
   759
  refers to the locale (or class) target of the context block.
51747
e4b5bebe5235 documentation and NEWS
haftmann
parents: 51657
diff changeset
   760
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   761
  \<^descr> @{command "print_dependencies"}~\<open>expr\<close> is useful for
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   762
  understanding the effect of an interpretation of \<open>expr\<close> in
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   763
  the current context.  It lists all locale instances for which
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   764
  interpretations would be added to the current context.  Variant
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   765
  @{command "print_dependencies"}\<open>!\<close> does not generalize
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   766
  parameters and assumes an empty context --- that is, it prints all
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   767
  locale instances that would be considered for interpretation.  The
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   768
  latter is useful for understanding the dependencies of a locale
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   769
  expression.
41435
12585dfb86fe Diagnostic command to show locale dependencies.
ballarin
parents: 41434
diff changeset
   770
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   771
  \<^descr> @{command "print_interps"}~\<open>locale\<close> lists all
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   772
  interpretations of \<open>locale\<close> in the current theory or proof
51565
5e9fdbdf88ce Improvements to the print_dependencies command.
ballarin
parents: 51313
diff changeset
   773
  context, including those due to a combination of an @{command
38110
2c1913d1b945 Documentation of 'interpret' updated.
ballarin
parents: 37768
diff changeset
   774
  "interpretation"} or @{command "interpret"} and one or several
2c1913d1b945 Documentation of 'interpret' updated.
ballarin
parents: 37768
diff changeset
   775
  @{command "sublocale"} declarations.
33867
52643d0f856d Typos in documenation.
ballarin
parents: 33846
diff changeset
   776
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   777
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   778
  \begin{warn}
54049
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   779
    If a global theory inherits declarations (body elements) for a
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   780
    locale from one parent and an interpretation of that locale from
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   781
    another parent, the interpretation will not be applied to the
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   782
    declarations.
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   783
  \end{warn}
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   784
566b769c3477 Streamlined locales reference material.
ballarin
parents: 53536
diff changeset
   785
  \begin{warn}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   786
    Since attributes are applied to interpreted theorems,
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   787
    interpretation may modify the context of common proof tools, e.g.\
33867
52643d0f856d Typos in documenation.
ballarin
parents: 33846
diff changeset
   788
    the Simplifier or Classical Reasoner.  As the behavior of such
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   789
    tools is \<^emph>\<open>not\<close> stable under interpretation morphisms, manual
33867
52643d0f856d Typos in documenation.
ballarin
parents: 33846
diff changeset
   790
    declarations might have to be added to the target context of the
52643d0f856d Typos in documenation.
ballarin
parents: 33846
diff changeset
   791
    interpretation to revert such declarations.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   792
  \end{warn}
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   793
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   794
  \begin{warn}
51747
e4b5bebe5235 documentation and NEWS
haftmann
parents: 51657
diff changeset
   795
    An interpretation in a local theory or proof context may subsume previous
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   796
    interpretations.  This happens if the same specification fragment
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   797
    is interpreted twice and the instantiation of the second
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   798
    interpretation is more general than the interpretation of the
33846
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   799
    first.  The locale package does not attempt to remove subsumed
cff41e82e3df Updated locale documentation.
ballarin
parents: 33516
diff changeset
   800
    interpretations.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   801
  \end{warn}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   802
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   803
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   804
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   805
subsubsection \<open>Permanent locale interpretation\<close>
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   806
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   807
text \<open>
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   808
  Permanent locale interpretation is a library extension on top
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   809
  of @{command "interpretation"} and @{command "sublocale"}.  It is
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   810
  available by importing theory @{file "~~/src/Tools/Permanent_Interpretation.thy"}
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   811
  and provides
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   812
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   813
  \<^enum> a unified view on arbitrary suitable local theories as interpretation target;
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   814
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   815
  \<^enum> rewrite morphisms by means of \<^emph>\<open>rewrite definitions\<close>.
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   816
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   817
  
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   818
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   819
    @{command_def "permanent_interpretation"} & : & \<open>local_theory \<rightarrow> proof(prove)\<close>
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   820
  \end{matharray}
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   821
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   822
  @{rail \<open>
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   823
    @@{command permanent_interpretation} @{syntax locale_expr} \<newline>
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   824
      definitions? equations?
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   825
    ;
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   826
    definitions: @'defining' (@{syntax thmdecl}? @{syntax name} \<newline>
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   827
      @{syntax mixfix}? @'=' @{syntax term} + @'and');
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61565
diff changeset
   828
    equations: @'rewrites' (@{syntax thmdecl}? @{syntax prop} + @'and')
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   829
  \<close>}
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   830
61566
c3d6e570ccef Keyword 'rewrites' identifies rewrite morphisms.
ballarin
parents: 61565
diff changeset
   831
  \<^descr> @{command "permanent_interpretation"}~\<open>expr \<DEFINING> defs\<close>~@{keyword "rewrites"}~\<open>eqns\<close>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   832
  interprets \<open>expr\<close> in the current local theory.  The command
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   833
  generates proof obligations for the instantiated specifications.
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   834
  Instantiated declarations (in particular, facts) are added to the
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   835
  local theory's underlying target in a post-processing phase.  When
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   836
  adding declarations to locales, interpreted versions of these
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   837
  declarations are added to any target for all interpretations
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   838
  in that target as well. That is, permanent interpretations
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   839
  dynamically participate in any declarations added to
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   840
  locales.
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   841
  
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   842
  The local theory's underlying target must explicitly support
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   843
  permanent interpretations.  Prominent examples are global theories
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   844
  (where @{command "permanent_interpretation"} is technically
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   845
  corresponding to @{command "interpretation"}) and locales
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   846
  (where @{command "permanent_interpretation"} is technically
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   847
  corresponding to @{command "sublocale"}).  Unnamed contexts
59320
a375de4dc07a avoid technical term "mixin" in user documentation text
haftmann
parents: 59028
diff changeset
   848
  (see \secref{sec:target}) are not admissible since they are
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   849
  non-permanent due to their very nature.  
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   850
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   851
  In additions to \<^emph>\<open>rewrite morphisms\<close> specified by \<open>eqns\<close>,
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   852
  also \<^emph>\<open>rewrite definitions\<close> may be specified.  Semantically, a
59320
a375de4dc07a avoid technical term "mixin" in user documentation text
haftmann
parents: 59028
diff changeset
   853
  rewrite definition
a375de4dc07a avoid technical term "mixin" in user documentation text
haftmann
parents: 59028
diff changeset
   854
  
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
   855
    \<^item> produces a corresponding definition in
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   856
    the local theory's underlying target \<^emph>\<open>and\<close>
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   857
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
   858
    \<^item> augments the rewrite morphism with the equation
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   859
    stemming from the symmetric of the corresponding definition.
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   860
  
59320
a375de4dc07a avoid technical term "mixin" in user documentation text
haftmann
parents: 59028
diff changeset
   861
  This is technically different to to a naive combination
a375de4dc07a avoid technical term "mixin" in user documentation text
haftmann
parents: 59028
diff changeset
   862
  of a conventional definition and an explicit rewrite equation:
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   863
  
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
   864
    \<^item> Definitions are parsed in the syntactic interpretation
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   865
    context, just like equations.
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
   866
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
   867
    \<^item> The proof needs not consider the equations stemming from
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   868
    definitions -- they are proved implicitly by construction.
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   869
  
59320
a375de4dc07a avoid technical term "mixin" in user documentation text
haftmann
parents: 59028
diff changeset
   870
  Rewrite definitions yield a pattern for introducing new explicit
59003
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   871
  operations for existing terms after interpretation.
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   872
\<close>
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   873
16d92d37a8a1 documentation stubs about permanent_interpretation
haftmann
parents: 58724
diff changeset
   874
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   875
section \<open>Classes \label{sec:class}\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   876
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   877
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   878
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   879
    @{command_def "class"} & : & \<open>theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   880
    @{command_def "instantiation"} & : & \<open>theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   881
    @{command_def "instance"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   882
    @{command "instance"} & : & \<open>theory \<rightarrow> proof(prove)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   883
    @{command_def "subclass"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   884
    @{command_def "print_classes"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   885
    @{command_def "class_deps"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   886
    @{method_def intro_classes} & : & \<open>method\<close> \\
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   887
  \end{matharray}
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   888
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   889
  A class is a particular locale with \<^emph>\<open>exactly one\<close> type variable
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   890
  \<open>\<alpha>\<close>.  Beyond the underlying locale, a corresponding type class
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   891
  is established which is interpreted logically as axiomatic type
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58316
diff changeset
   892
  class @{cite "Wenzel:1997:TPHOL"} whose logical content are the
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   893
  assumptions of the locale.  Thus, classes provide the full
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   894
  generality of locales combined with the commodity of type classes
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58316
diff changeset
   895
  (notably type-inference).  See @{cite "isabelle-classes"} for a short
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   896
  tutorial.
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
   897
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   898
  @{rail \<open>
42704
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
   899
    @@{command class} class_spec @'begin'?
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
   900
    ;
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
   901
    class_spec: @{syntax name} '='
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   902
      ((@{syntax nameref} '+' (@{syntax context_elem}+)) |
42704
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
   903
        @{syntax nameref} | (@{syntax context_elem}+))      
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   904
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
   905
    @@{command instantiation} (@{syntax nameref} + @'and') '::' @{syntax arity} @'begin'
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   906
    ;
42704
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
   907
    @@{command instance} (() | (@{syntax nameref} + @'and') '::' @{syntax arity} |
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
   908
      @{syntax nameref} ('<' | '\<subseteq>') @{syntax nameref} )
31681
127e8a8b8cde refined section concerning classes
haftmann
parents: 31047
diff changeset
   909
    ;
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
   910
    @@{command subclass} @{syntax nameref}
58202
be1d10595b7b restrictive options for class dependencies
haftmann
parents: 57947
diff changeset
   911
    ;
60091
9feddd64183e tuned signature;
wenzelm
parents: 60090
diff changeset
   912
    @@{command class_deps} (class_bounds class_bounds?)?
60090
75ec8fd5d2bf misc tuning and clarification;
wenzelm
parents: 59990
diff changeset
   913
    ;
60091
9feddd64183e tuned signature;
wenzelm
parents: 60090
diff changeset
   914
    class_bounds: @{syntax sort} | '(' (@{syntax sort} + @'|') ')'
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   915
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   916
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   917
  \<^descr> @{command "class"}~\<open>c = superclasses + body\<close> defines
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   918
  a new class \<open>c\<close>, inheriting from \<open>superclasses\<close>.  This
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   919
  introduces a locale \<open>c\<close> with import of all locales \<open>superclasses\<close>.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   920
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   921
  Any @{element "fixes"} in \<open>body\<close> are lifted to the global
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   922
  theory level (\<^emph>\<open>class operations\<close> \<open>f\<^sub>1, \<dots>,
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   923
  f\<^sub>n\<close> of class \<open>c\<close>), mapping the local type parameter
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   924
  \<open>\<alpha>\<close> to a schematic type variable \<open>?\<alpha> :: c\<close>.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   925
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   926
  Likewise, @{element "assumes"} in \<open>body\<close> are also lifted,
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   927
  mapping each local parameter \<open>f :: \<tau>[\<alpha>]\<close> to its
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   928
  corresponding global constant \<open>f :: \<tau>[?\<alpha> :: c]\<close>.  The
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   929
  corresponding introduction rule is provided as \<open>c_class_axioms.intro\<close>.  This rule should be rarely needed directly
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   930
  --- the @{method intro_classes} method takes care of the details of
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   931
  class membership proofs.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   932
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   933
  \<^descr> @{command "instantiation"}~\<open>t :: (s\<^sub>1, \<dots>, s\<^sub>n)s
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   934
  \<BEGIN>\<close> opens a target (cf.\ \secref{sec:target}) which
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   935
  allows to specify class operations \<open>f\<^sub>1, \<dots>, f\<^sub>n\<close> corresponding
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   936
  to sort \<open>s\<close> at the particular type instance \<open>(\<alpha>\<^sub>1 :: s\<^sub>1,
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   937
  \<dots>, \<alpha>\<^sub>n :: s\<^sub>n) t\<close>.  A plain @{command "instance"} command in the
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
   938
  target body poses a goal stating these type arities.  The target is
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
   939
  concluded by an @{command_ref (local) "end"} command.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   940
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   941
  Note that a list of simultaneous type constructors may be given;
31914
0bf275fbe93a instance arities can be simultaneous
haftmann
parents: 31681
diff changeset
   942
  this corresponds nicely to mutually recursive type definitions, e.g.\
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   943
  in Isabelle/HOL.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   944
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   945
  \<^descr> @{command "instance"} in an instantiation target body sets
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   946
  up a goal stating the type arities claimed at the opening @{command
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   947
  "instantiation"}.  The proof would usually proceed by @{method
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   948
  intro_classes}, and then establish the characteristic theorems of
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   949
  the type classes involved.  After finishing the proof, the
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   950
  background theory will be augmented by the proven type arities.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   951
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   952
  On the theory level, @{command "instance"}~\<open>t :: (s\<^sub>1, \<dots>,
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   953
  s\<^sub>n)s\<close> provides a convenient way to instantiate a type class with no
37112
67934c40a5f7 Typo fixed.
webertj
parents: 36454
diff changeset
   954
  need to specify operations: one can continue with the
31681
127e8a8b8cde refined section concerning classes
haftmann
parents: 31047
diff changeset
   955
  instantiation proof immediately.
127e8a8b8cde refined section concerning classes
haftmann
parents: 31047
diff changeset
   956
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   957
  \<^descr> @{command "subclass"}~\<open>c\<close> in a class context for class
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   958
  \<open>d\<close> sets up a goal stating that class \<open>c\<close> is logically
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   959
  contained in class \<open>d\<close>.  After finishing the proof, class
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   960
  \<open>d\<close> is proven to be subclass \<open>c\<close> and the locale \<open>c\<close> is interpreted into \<open>d\<close> simultaneously.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   961
56594
e3a06699a13f tuned spelling;
wenzelm
parents: 56451
diff changeset
   962
  A weakened form of this is available through a further variant of
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   963
  @{command instance}:  @{command instance}~\<open>c\<^sub>1 \<subseteq> c\<^sub>2\<close> opens
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   964
  a proof that class \<open>c\<^sub>2\<close> implies \<open>c\<^sub>1\<close> without reference
31681
127e8a8b8cde refined section concerning classes
haftmann
parents: 31047
diff changeset
   965
  to the underlying locales;  this is useful if the properties to prove
56594
e3a06699a13f tuned spelling;
wenzelm
parents: 56451
diff changeset
   966
  the logical connection are not sufficient on the locale level but on
31681
127e8a8b8cde refined section concerning classes
haftmann
parents: 31047
diff changeset
   967
  the theory level.
127e8a8b8cde refined section concerning classes
haftmann
parents: 31047
diff changeset
   968
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   969
  \<^descr> @{command "print_classes"} prints all classes in the current
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   970
  theory.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   971
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   972
  \<^descr> @{command "class_deps"} visualizes classes and their subclass
60090
75ec8fd5d2bf misc tuning and clarification;
wenzelm
parents: 59990
diff changeset
   973
  relations as a directed acyclic graph. By default, all classes from the
75ec8fd5d2bf misc tuning and clarification;
wenzelm
parents: 59990
diff changeset
   974
  current theory context are show. This may be restricted by optional bounds
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   975
  as follows: @{command "class_deps"}~\<open>upper\<close> or @{command
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   976
  "class_deps"}~\<open>upper lower\<close>. A class is visualized, iff it is a
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   977
  subclass of some sort from \<open>upper\<close> and a superclass of some sort
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   978
  from \<open>lower\<close>.
29706
10e6f2faa1e5 updated type class section
haftmann
parents: 29613
diff changeset
   979
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
   980
  \<^descr> @{method intro_classes} repeatedly expands all class
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   981
  introduction rules of this theory.  Note that this method usually
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   982
  needs not be named explicitly, as it is already included in the
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   983
  default proof step (e.g.\ of @{command "proof"}).  In particular,
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   984
  instantiation of trivial (syntactic) classes may be performed by a
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   985
  single ``@{command ".."}'' proof step.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   986
\<close>
26870
94bedbb34b92 misc reorganization;
wenzelm
parents: 26869
diff changeset
   987
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   988
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   989
subsection \<open>The class target\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   990
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   991
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   992
  %FIXME check
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   993
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   994
  A named context may refer to a locale (cf.\ \secref{sec:target}).
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   995
  If this locale is also a class \<open>c\<close>, apart from the common
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   996
  locale target behaviour the following happens.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
   997
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   998
  \<^item> Local constant declarations \<open>g[\<alpha>]\<close> referring to the
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   999
  local type parameter \<open>\<alpha>\<close> and local parameters \<open>f[\<alpha>]\<close>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1000
  are accompanied by theory-level constants \<open>g[?\<alpha> :: c]\<close>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1001
  referring to theory-level class operations \<open>f[?\<alpha> :: c]\<close>.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1002
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1003
  \<^item> Local theorem bindings are lifted as are assumptions.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1004
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1005
  \<^item> Local syntax refers to local operations \<open>g[\<alpha>]\<close> and
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1006
  global operations \<open>g[?\<alpha> :: c]\<close> uniformly.  Type inference
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1007
  resolves ambiguities.  In rare cases, manual type annotations are
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1008
  needed.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1009
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1010
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1011
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1012
subsection \<open>Co-regularity of type classes and arities\<close>
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1013
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1014
text \<open>The class relation together with the collection of
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1015
  type-constructor arities must obey the principle of
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1016
  \<^emph>\<open>co-regularity\<close> as defined below.
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1017
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1018
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1019
  For the subsequent formulation of co-regularity we assume
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1020
  that the class relation is closed by transitivity and reflexivity.
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1021
  Moreover the collection of arities \<open>t :: (\<^vec>s)c\<close> is
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1022
  completed such that \<open>t :: (\<^vec>s)c\<close> and \<open>c \<subseteq> c'\<close>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1023
  implies \<open>t :: (\<^vec>s)c'\<close> for all such declarations.
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1024
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1025
  Treating sorts as finite sets of classes (meaning the intersection),
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1026
  the class relation \<open>c\<^sub>1 \<subseteq> c\<^sub>2\<close> is extended to sorts as
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1027
  follows:
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1028
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1029
    \<open>s\<^sub>1 \<subseteq> s\<^sub>2 \<equiv> \<forall>c\<^sub>2 \<in> s\<^sub>2. \<exists>c\<^sub>1 \<in> s\<^sub>1. c\<^sub>1 \<subseteq> c\<^sub>2\<close>
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1030
  \]
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1031
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1032
  This relation on sorts is further extended to tuples of sorts (of
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1033
  the same length) in the component-wise way.
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1034
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1035
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1036
  Co-regularity of the class relation together with the
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1037
  arities relation means:
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1038
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1039
    \<open>t :: (\<^vec>s\<^sub>1)c\<^sub>1 \<Longrightarrow> t :: (\<^vec>s\<^sub>2)c\<^sub>2 \<Longrightarrow> c\<^sub>1 \<subseteq> c\<^sub>2 \<Longrightarrow> \<^vec>s\<^sub>1 \<subseteq> \<^vec>s\<^sub>2\<close>
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1040
  \]
61420
ee42cba50933 redundant due to \parindent 0pt;
wenzelm
parents: 61414
diff changeset
  1041
  for all such arities.  In other words, whenever the result
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1042
  classes of some type-constructor arities are related, then the
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1043
  argument sorts need to be related in the same way.
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1044
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1045
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1046
  Co-regularity is a very fundamental property of the
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1047
  order-sorted algebra of types.  For example, it entails principle
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58316
diff changeset
  1048
  types and most general unifiers, e.g.\ see @{cite "nipkow-prehofer"}.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1049
\<close>
37768
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1050
e86221f3bac7 moved co-regularity to class section; avoid duplicated class_deps
haftmann
parents: 37112
diff changeset
  1051
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1052
section \<open>Unrestricted overloading\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1053
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1054
text \<open>
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1055
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1056
    @{command_def "overloading"} & : & \<open>theory \<rightarrow> local_theory\<close> \\
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1057
  \end{matharray}
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1058
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1059
  Isabelle/Pure's definitional schemes support certain forms of
31047
c13b0406c039 tuned description of overloading
haftmann
parents: 30546
diff changeset
  1060
  overloading (see \secref{sec:consts}).  Overloading means that a
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1061
  constant being declared as \<open>c :: \<alpha> decl\<close> may be
31047
c13b0406c039 tuned description of overloading
haftmann
parents: 30546
diff changeset
  1062
  defined separately on type instances
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1063
  \<open>c :: (\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n) t decl\<close>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1064
  for each type constructor \<open>t\<close>.  At most occasions
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1065
  overloading will be used in a Haskell-like fashion together with
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1066
  type classes by means of @{command "instantiation"} (see
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1067
  \secref{sec:class}).  Sometimes low-level overloading is desirable.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1068
  The @{command "overloading"} target provides a convenient view for
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1069
  end-users.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1070
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1071
  @{rail \<open>
42704
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1072
    @@{command overloading} ( spec + ) @'begin'
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1073
    ;
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1074
    spec: @{syntax name} ( '==' | '\<equiv>' ) @{syntax term} ( '(' @'unchecked' ')' )?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1075
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1076
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1077
  \<^descr> @{command "overloading"}~\<open>x\<^sub>1 \<equiv> c\<^sub>1 :: \<tau>\<^sub>1 \<AND> \<dots> x\<^sub>n \<equiv> c\<^sub>n :: \<tau>\<^sub>n \<BEGIN>\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1078
  opens a theory target (cf.\ \secref{sec:target}) which allows to
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1079
  specify constants with overloaded definitions.  These are identified
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1080
  by an explicitly given mapping from variable names \<open>x\<^sub>i\<close> to
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1081
  constants \<open>c\<^sub>i\<close> at particular type instances.  The
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1082
  definitions themselves are established using common specification
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1083
  tools, using the names \<open>x\<^sub>i\<close> as reference to the
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1084
  corresponding constants.  The target is concluded by @{command
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1085
  (local) "end"}.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1086
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1087
  A \<open>(unchecked)\<close> option disables global dependency checks for
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1088
  the corresponding definition, which is occasionally useful for
31047
c13b0406c039 tuned description of overloading
haftmann
parents: 30546
diff changeset
  1089
  exotic overloading (see \secref{sec:consts} for a precise description).
c13b0406c039 tuned description of overloading
haftmann
parents: 30546
diff changeset
  1090
  It is at the discretion of the user to avoid
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1091
  malformed theory specifications!
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1092
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1093
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1094
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1095
section \<open>Incorporating ML code \label{sec:ML}\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1096
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1097
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1098
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1099
    @{command_def "SML_file"} & : & \<open>theory \<rightarrow> theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1100
    @{command_def "ML_file"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1101
    @{command_def "ML"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1102
    @{command_def "ML_prf"} & : & \<open>proof \<rightarrow> proof\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1103
    @{command_def "ML_val"} & : & \<open>any \<rightarrow>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1104
    @{command_def "ML_command"} & : & \<open>any \<rightarrow>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1105
    @{command_def "setup"} & : & \<open>theory \<rightarrow> theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1106
    @{command_def "local_setup"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1107
    @{command_def "attribute_setup"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1108
  \end{matharray}
57478
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1109
  \begin{tabular}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1110
    @{attribute_def ML_print_depth} & : & \<open>attribute\<close> & default 10 \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1111
    @{attribute_def ML_source_trace} & : & \<open>attribute\<close> & default \<open>false\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1112
    @{attribute_def ML_exception_trace} & : & \<open>attribute\<close> & default \<open>false\<close> \\
57478
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1113
  \end{tabular}
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1114
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1115
  @{rail \<open>
56275
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 55837
diff changeset
  1116
    (@@{command SML_file} | @@{command ML_file}) @{syntax name}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1117
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
  1118
    (@@{command ML} | @@{command ML_prf} | @@{command ML_val} |
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
  1119
      @@{command ML_command} | @@{command setup} | @@{command local_setup}) @{syntax text}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1120
    ;
59783
00b62aa9f430 tuned syntax diagrams -- no duplication of "target";
wenzelm
parents: 59781
diff changeset
  1121
    @@{command attribute_setup} @{syntax name} '=' @{syntax text} @{syntax text}?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1122
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1123
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1124
  \<^descr> @{command "SML_file"}~\<open>name\<close> reads and evaluates the
56275
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 55837
diff changeset
  1125
  given Standard ML file.  Top-level SML bindings are stored within
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 55837
diff changeset
  1126
  the theory context; the initial environment is restricted to the
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 55837
diff changeset
  1127
  Standard ML implementation of Poly/ML, without the many add-ons of
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 55837
diff changeset
  1128
  Isabelle/ML.  Multiple @{command "SML_file"} commands may be used to
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 55837
diff changeset
  1129
  build larger Standard ML projects, independently of the regular
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 55837
diff changeset
  1130
  Isabelle/ML environment.
600f432ab556 added command 'SML_file' for Standard ML without Isabelle/ML add-ons;
wenzelm
parents: 55837
diff changeset
  1131
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1132
  \<^descr> @{command "ML_file"}~\<open>name\<close> reads and evaluates the
48890
d72ca5742f80 'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents: 48824
diff changeset
  1133
  given ML file.  The current theory context is passed down to the ML
d72ca5742f80 'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents: 48824
diff changeset
  1134
  toplevel and may be modified, using @{ML "Context.>>"} or derived ML
d72ca5742f80 'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents: 48824
diff changeset
  1135
  commands.  Top-level ML bindings are stored within the (global or
d72ca5742f80 'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents: 48824
diff changeset
  1136
  local) theory context.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1137
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1138
  \<^descr> @{command "ML"}~\<open>text\<close> is similar to @{command
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1139
  "ML_file"}, but evaluates directly the given \<open>text\<close>.
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1140
  Top-level ML bindings are stored within the (global or local) theory
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1141
  context.
28281
132456af0731 added ML_prf;
wenzelm
parents: 28114
diff changeset
  1142
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1143
  \<^descr> @{command "ML_prf"} is analogous to @{command "ML"} but works
48890
d72ca5742f80 'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents: 48824
diff changeset
  1144
  within a proof context.  Top-level ML bindings are stored within the
d72ca5742f80 'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents: 48824
diff changeset
  1145
  proof context in a purely sequential fashion, disregarding the
d72ca5742f80 'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents: 48824
diff changeset
  1146
  nested proof structure.  ML bindings introduced by @{command
d72ca5742f80 'ML_file' evaluates ML text from a file directly within the theory, without predeclaration via 'uses';
wenzelm
parents: 48824
diff changeset
  1147
  "ML_prf"} are discarded at the end of the proof.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1148
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1149
  \<^descr> @{command "ML_val"} and @{command "ML_command"} are diagnostic
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1150
  versions of @{command "ML"}, which means that the context may not be
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1151
  updated.  @{command "ML_val"} echos the bindings produced at the ML
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1152
  toplevel, but @{command "ML_command"} is silent.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1153
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1154
  \<^descr> @{command "setup"}~\<open>text\<close> changes the current theory
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1155
  context by applying \<open>text\<close>, which refers to an ML expression
30461
00323c45ea83 added 'local_setup' command;
wenzelm
parents: 30242
diff changeset
  1156
  of type @{ML_type "theory -> theory"}.  This enables to initialize
00323c45ea83 added 'local_setup' command;
wenzelm
parents: 30242
diff changeset
  1157
  any object-logic specific tools and packages written in ML, for
00323c45ea83 added 'local_setup' command;
wenzelm
parents: 30242
diff changeset
  1158
  example.
00323c45ea83 added 'local_setup' command;
wenzelm
parents: 30242
diff changeset
  1159
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1160
  \<^descr> @{command "local_setup"} is similar to @{command "setup"} for
30461
00323c45ea83 added 'local_setup' command;
wenzelm
parents: 30242
diff changeset
  1161
  a local theory context, and an ML expression of type @{ML_type
00323c45ea83 added 'local_setup' command;
wenzelm
parents: 30242
diff changeset
  1162
  "local_theory -> local_theory"}.  This allows to
00323c45ea83 added 'local_setup' command;
wenzelm
parents: 30242
diff changeset
  1163
  invoke local theory specification packages without going through
00323c45ea83 added 'local_setup' command;
wenzelm
parents: 30242
diff changeset
  1164
  concrete outer syntax, for example.
28758
4ce896a30f88 added bind_thm, bind_thms;
wenzelm
parents: 28757
diff changeset
  1165
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1166
  \<^descr> @{command "attribute_setup"}~\<open>name = text description\<close>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1167
  defines an attribute in the current context.  The given \<open>text\<close> has to be an ML expression of type
30526
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1168
  @{ML_type "attribute context_parser"}, cf.\ basic parsers defined in
55837
154855d9a564 clarified names of antiquotations and markup;
wenzelm
parents: 55385
diff changeset
  1169
  structure @{ML_structure Args} and @{ML_structure Attrib}.
30526
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1170
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1171
  In principle, attributes can operate both on a given theorem and the
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1172
  implicit context, although in practice only one is modified and the
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1173
  other serves as parameter.  Here are examples for these two cases:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1174
\<close>
30526
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1175
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59901
diff changeset
  1176
(*<*)experiment begin(*>*)
58619
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1177
  attribute_setup my_rule =
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1178
    \<open>Attrib.thms >> (fn ths =>
42704
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1179
      Thm.rule_attribute
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1180
        (fn context: Context.generic => fn th: thm =>
30526
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1181
          let val th' = th OF ths
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1182
          in th' end))\<close>
30526
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1183
58619
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1184
  attribute_setup my_declaration =
4b41df5fef81 clarified whitespace;
wenzelm
parents: 58618
diff changeset
  1185
    \<open>Attrib.thms >> (fn ths =>
42704
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1186
      Thm.declaration_attribute
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1187
        (fn th: thm => fn context: Context.generic =>
30526
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1188
          let val context' = context
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1189
          in context' end))\<close>
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59901
diff changeset
  1190
(*<*)end(*>*)
30526
7f9a9ec1c94d added 'attribute_setup' command;
wenzelm
parents: 30461
diff changeset
  1191
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1192
text \<open>
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1193
  \<^descr> @{attribute ML_print_depth} controls the printing depth of the ML
57478
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1194
  toplevel pretty printer; the precise effect depends on the ML compiler and
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1195
  run-time system. Typically the limit should be less than 10. Bigger values
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1196
  such as 100--1000 are occasionally useful for debugging.
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1197
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1198
  \<^descr> @{attribute ML_source_trace} indicates whether the source text that
57478
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1199
  is given to the ML compiler should be output: it shows the raw Standard ML
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1200
  after expansion of Isabelle/ML antiquotations.
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1201
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1202
  \<^descr> @{attribute ML_exception_trace} indicates whether the ML run-time
57478
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1203
  system should print a detailed stack trace on exceptions. The result is
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1204
  dependent on the particular ML compiler version. Note that after Poly/ML
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1205
  5.3 some optimizations in the run-time systems may hinder exception
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1206
  traces.
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1207
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1208
  The boundary for the exception trace is the current Isar command
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1209
  transactions. It is occasionally better to insert the combinator @{ML
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58316
diff changeset
  1210
  Runtime.exn_trace} into ML code for debugging @{cite
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58316
diff changeset
  1211
  "isabelle-implementation"}, closer to the point where it actually
57478
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1212
  happens.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1213
\<close>
57478
fa14d60a8cca more on ML options;
wenzelm
parents: 56594
diff changeset
  1214
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1215
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1216
section \<open>Primitive specification elements\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1217
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1218
subsection \<open>Sorts\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1219
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1220
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1221
  \begin{matharray}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1222
    @{command_def "default_sort"} & : & \<open>local_theory \<rightarrow> local_theory\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1223
  \end{matharray}
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1224
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1225
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
  1226
    @@{command default_sort} @{syntax sort}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1227
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1228
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1229
  \<^descr> @{command "default_sort"}~\<open>s\<close> makes sort \<open>s\<close> the
28767
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1230
  new default sort for any type variable that is given explicitly in
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1231
  the text, but lacks a sort constraint (wrt.\ the current context).
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1232
  Type variables generated by type inference are not affected.
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1233
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1234
  Usually the default sort is only changed when defining a new
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1235
  object-logic.  For example, the default sort in Isabelle/HOL is
39831
350857040d09 prefer checked antiquotations;
wenzelm
parents: 39214
diff changeset
  1236
  @{class type}, the class of all HOL types.
28767
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1237
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1238
  When merging theories, the default sorts of the parents are
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1239
  logically intersected, i.e.\ the representations as lists of classes
f09ceb800d00 minor tuning (according to old ref manual);
wenzelm
parents: 28762
diff changeset
  1240
  are joined.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1241
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1242
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1243
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1244
subsection \<open>Types \label{sec:types-pure}\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1245
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1246
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1247
  \begin{matharray}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1248
    @{command_def "type_synonym"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1249
    @{command_def "typedecl"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1250
  \end{matharray}
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1251
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1252
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
  1253
    @@{command type_synonym} (@{syntax typespec} '=' @{syntax type} @{syntax mixfix}?)
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1254
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
  1255
    @@{command typedecl} @{syntax typespec} @{syntax mixfix}?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1256
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1257
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1258
  \<^descr> @{command "type_synonym"}~\<open>(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t = \<tau>\<close> introduces a
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1259
  \<^emph>\<open>type synonym\<close> \<open>(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t\<close> for the existing type \<open>\<tau>\<close>. Unlike the semantic type definitions in Isabelle/HOL, type synonyms
57487
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1260
  are merely syntactic abbreviations without any logical significance.
41249
26f12f98f50a Command 'type_synonym' (with single argument) supersedes 'types' (legacy feature);
wenzelm
parents: 40800
diff changeset
  1261
  Internally, type synonyms are fully expanded.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1262
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1263
  \<^descr> @{command "typedecl"}~\<open>(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t\<close> declares a new
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1264
  type constructor \<open>t\<close>.  If the object-logic defines a base sort
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1265
  \<open>s\<close>, then the constructor is declared to operate on that, via
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1266
  the axiomatic type-class instance \<open>t :: (s, \<dots>, s)s\<close>.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1267
57487
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1268
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1269
  \begin{warn}
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1270
  If you introduce a new type axiomatically, i.e.\ via @{command_ref
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1271
  typedecl} and @{command_ref axiomatization}
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1272
  (\secref{sec:axiomatizations}), the minimum requirement is that it has a
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1273
  non-empty model, to avoid immediate collapse of the logical environment.
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1274
  Moreover, one needs to demonstrate that the interpretation of such
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1275
  free-form axiomatizations can coexist with other axiomatization schemes
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1276
  for types, notably @{command_def typedef} in Isabelle/HOL
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1277
  (\secref{sec:hol-typedef}), or any other extension that people might have
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1278
  introduced elsewhere.
7806a74c54ac misc tuning and clarification;
wenzelm
parents: 57480
diff changeset
  1279
  \end{warn}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1280
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1281
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1282
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1283
subsection \<open>Constants and definitions \label{sec:consts}\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1284
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1285
text \<open>
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1286
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1287
    @{command_def "consts"} & : & \<open>theory \<rightarrow> theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1288
    @{command_def "defs"} & : & \<open>theory \<rightarrow> theory\<close> \\
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1289
  \end{matharray}
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1290
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1291
  Definitions essentially express abbreviations within the logic.  The
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1292
  simplest form of a definition is \<open>c :: \<sigma> \<equiv> t\<close>, where \<open>c\<close> is a newly declared constant.  Isabelle also allows derived forms
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1293
  where the arguments of \<open>c\<close> appear on the left, abbreviating a
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1294
  prefix of \<open>\<lambda>\<close>-abstractions, e.g.\ \<open>c \<equiv> \<lambda>x y. t\<close> may be
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1295
  written more conveniently as \<open>c x y \<equiv> t\<close>.  Moreover,
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1296
  definitions may be weakened by adding arbitrary pre-conditions:
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1297
  \<open>A \<Longrightarrow> c x y \<equiv> t\<close>.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1298
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1299
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1300
  The built-in well-formedness conditions for definitional
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1301
  specifications are:
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1302
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1303
  \<^item> Arguments (on the left-hand side) must be distinct variables.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1304
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1305
  \<^item> All variables on the right-hand side must also appear on the
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1306
  left-hand side.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1307
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1308
  \<^item> All type variables on the right-hand side must also appear on
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1309
  the left-hand side; this prohibits \<open>0 :: nat \<equiv> length ([] ::
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1310
  \<alpha> list)\<close> for example.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1311
61421
e0825405d398 more symbols;
wenzelm
parents: 61420
diff changeset
  1312
  \<^item> The definition must not be recursive.  Most object-logics
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1313
  provide definitional principles that can be used to express
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1314
  recursion safely.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1315
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1316
31047
c13b0406c039 tuned description of overloading
haftmann
parents: 30546
diff changeset
  1317
  The right-hand side of overloaded definitions may mention overloaded constants
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1318
  recursively at type instances corresponding to the immediate
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1319
  argument types \<open>\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n\<close>.  Incomplete
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1320
  specification patterns impose global constraints on all occurrences,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1321
  e.g.\ \<open>d :: \<alpha> \<times> \<alpha>\<close> on the left-hand side means that all
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1322
  corresponding occurrences on some right-hand side need to be an
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1323
  instance of this, general \<open>d :: \<alpha> \<times> \<beta>\<close> will be disallowed.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1324
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1325
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
  1326
    @@{command consts} ((@{syntax name} '::' @{syntax type} @{syntax mixfix}?) +)
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1327
    ;
42704
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1328
    @@{command defs} opt? (@{syntax axmdecl} @{syntax prop} +)
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1329
    ;
3f19e324ff59 tuned rail diagrams and layout;
wenzelm
parents: 42651
diff changeset
  1330
    opt: '(' @'unchecked'? @'overloaded'? ')'
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1331
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1332
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1333
  \<^descr> @{command "consts"}~\<open>c :: \<sigma>\<close> declares constant \<open>c\<close> to have any instance of type scheme \<open>\<sigma>\<close>.  The optional
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1334
  mixfix annotations may attach concrete syntax to the constants
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28758
diff changeset
  1335
  declared.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1336
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1337
  \<^descr> @{command "defs"}~\<open>name: eqn\<close> introduces \<open>eqn\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1338
  as a definitional axiom for some existing constant.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1339
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1340
  The \<open>(unchecked)\<close> option disables global dependency checks
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1341
  for this definition, which is occasionally useful for exotic
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1342
  overloading.  It is at the discretion of the user to avoid malformed
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1343
  theory specifications!
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1344
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1345
  The \<open>(overloaded)\<close> option declares definitions to be
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1346
  potentially overloaded.  Unless this option is given, a warning
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1347
  message would be issued for any definitional equation with a more
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1348
  special type than that of the corresponding constant declaration.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1349
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1350
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1351
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1352
section \<open>Naming existing theorems \label{sec:theorems}\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1353
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1354
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1355
  \begin{matharray}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1356
    @{command_def "lemmas"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1357
    @{command_def "named_theorems"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1358
  \end{matharray}
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1359
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1360
  @{rail \<open>
61337
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 60297
diff changeset
  1361
    @@{command lemmas} (@{syntax thmdef}? @{syntax thmrefs} + @'and')
59785
4e6ab5831cc0 clarified syntax category "fixes";
wenzelm
parents: 59783
diff changeset
  1362
      @{syntax for_fixes}
57946
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57941
diff changeset
  1363
    ;
59785
4e6ab5831cc0 clarified syntax category "fixes";
wenzelm
parents: 59783
diff changeset
  1364
    @@{command named_theorems} (@{syntax name} @{syntax text}? + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1365
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1366
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1367
  \<^descr> @{command "lemmas"}~\<open>a = b\<^sub>1 \<dots> b\<^sub>n\<close>~@{keyword_def
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1368
  "for"}~\<open>x\<^sub>1 \<dots> x\<^sub>m\<close> evaluates given facts (with attributes) in
45600
1bbbac9a0cb0 'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents: 42936
diff changeset
  1369
  the current context, which may be augmented by local variables.
1bbbac9a0cb0 'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents: 42936
diff changeset
  1370
  Results are standardized before being stored, i.e.\ schematic
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1371
  variables are renamed to enforce index \<open>0\<close> uniformly.
45600
1bbbac9a0cb0 'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
wenzelm
parents: 42936
diff changeset
  1372
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1373
  \<^descr> @{command "named_theorems"}~\<open>name description\<close> declares a
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1374
  dynamic fact within the context. The same \<open>name\<close> is used to define
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1375
  an attribute with the usual \<open>add\<close>/\<open>del\<close> syntax (e.g.\ see
57946
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57941
diff changeset
  1376
  \secref{sec:simp-rules}) to maintain the content incrementally, in
6a26aa5fa65e updated documentation concerning 'named_theorems';
wenzelm
parents: 57941
diff changeset
  1377
  canonical declaration order of the text structure.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1378
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1379
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1380
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1381
section \<open>Oracles\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1382
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1383
text \<open>
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1384
  \begin{matharray}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1385
    @{command_def "oracle"} & : & \<open>theory \<rightarrow> theory\<close> & (axiomatic!) \\
47483
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1386
  \end{matharray}
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1387
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1388
  Oracles allow Isabelle to take advantage of external reasoners such
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1389
  as arithmetic decision procedures, model checkers, fast tautology
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1390
  checkers or computer algebra systems.  Invoked as an oracle, an
3f704717a67f more uniform outline;
wenzelm
parents: 47482
diff changeset
  1391
  external reasoner can create arbitrary Isabelle theorems.
28756
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1392
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1393
  It is the responsibility of the user to ensure that the external
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1394
  reasoner is as trustworthy as the application requires.  Another
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1395
  typical source of errors is the linkup between Isabelle and the
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1396
  external tool, not just its concrete implementation, but also the
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1397
  required translation between two different logical environments.
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1398
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1399
  Isabelle merely guarantees well-formedness of the propositions being
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1400
  asserted, and records within the internal derivation object how
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1401
  presumed theorems depend on unproven suppositions.
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1402
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1403
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
  1404
    @@{command oracle} @{syntax name} '=' @{syntax text}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1405
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1406
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1407
  \<^descr> @{command "oracle"}~\<open>name = text\<close> turns the given ML
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1408
  expression \<open>text\<close> of type @{ML_text "'a -> cterm"} into an
28290
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28281
diff changeset
  1409
  ML function of type @{ML_text "'a -> thm"}, which is bound to the
28756
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1410
  global identifier @{ML_text name}.  This acts like an infinitary
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1411
  specification of axioms!  Invoking the oracle only works within the
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1412
  scope of the resulting theory.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1413
28756
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1414
40800
330eb65c9469 Parse.liberal_name for document antiquotations and attributes;
wenzelm
parents: 40784
diff changeset
  1415
  See @{file "~~/src/HOL/ex/Iff_Oracle.thy"} for a worked example of
28756
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1416
  defining a new primitive rule as oracle, and turning it into a proof
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1417
  method.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1418
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1419
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1420
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1421
section \<open>Name spaces\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1422
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1423
text \<open>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1424
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1425
    @{command_def "hide_class"} & : & \<open>theory \<rightarrow> theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1426
    @{command_def "hide_type"} & : & \<open>theory \<rightarrow> theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1427
    @{command_def "hide_const"} & : & \<open>theory \<rightarrow> theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1428
    @{command_def "hide_fact"} & : & \<open>theory \<rightarrow> theory\<close> \\
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1429
  \end{matharray}
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1430
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1431
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
  1432
    ( @{command hide_class} | @{command hide_type} |
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 41435
diff changeset
  1433
      @{command hide_const} | @{command hide_fact} ) ('(' @'open' ')')? (@{syntax nameref} + )
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1434
  \<close>}
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1435
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1436
  Isabelle organizes any kind of name declarations (of types,
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1437
  constants, theorems etc.) by separate hierarchically structured name
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1438
  spaces.  Normally the user does not have to control the behavior of
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1439
  name spaces by hand, yet the following commands provide some way to
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1440
  do so.
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1441
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1442
  \<^descr> @{command "hide_class"}~\<open>names\<close> fully removes class
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1443
  declarations from a given name space; with the \<open>(open)\<close>
60297
wenzelm
parents: 60093
diff changeset
  1444
  option, only the unqualified base name is hidden.
36177
8e0770d2e499 separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents: 35681
diff changeset
  1445
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1446
  Note that hiding name space accesses has no impact on logical
28756
529798e71924 tuned section "Oracles";
wenzelm
parents: 28745
diff changeset
  1447
  declarations --- they remain valid internally.  Entities that are no
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1448
  longer accessible to the user are printed with the special qualifier
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1449
  ``\<open>??\<close>'' prefixed to the full internal name.
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1450
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61421
diff changeset
  1451
  \<^descr> @{command "hide_type"}, @{command "hide_const"}, and @{command
36177
8e0770d2e499 separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents: 35681
diff changeset
  1452
  "hide_fact"} are similar to @{command "hide_class"}, but hide types,
8e0770d2e499 separate commands 'hide_class', 'hide_type', 'hide_const', 'hide_fact';
wenzelm
parents: 35681
diff changeset
  1453
  constants, and facts, respectively.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1454
\<close>
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26870
diff changeset
  1455
26869
3bc332135aa7 added chapters for "Specifications" and "Proofs";
wenzelm
parents:
diff changeset
  1456
end