doc-src/IsarImplementation/Thy/prelim.thy
author wenzelm
Thu Aug 31 22:55:49 2006 +0200 (2006-08-31)
changeset 20451 27ea2ba48fa3
parent 20450 725a91601ed1
child 20452 6d8b29c7a960
permissions -rw-r--r--
misc cleanup;
wenzelm@18537
     1
wenzelm@18537
     2
(* $Id$ *)
wenzelm@18537
     3
wenzelm@18537
     4
theory prelim imports base begin
wenzelm@18537
     5
wenzelm@18537
     6
chapter {* Preliminaries *}
wenzelm@18537
     7
wenzelm@20429
     8
section {* Contexts \label{sec:context} *}
wenzelm@18537
     9
wenzelm@20429
    10
text {*
wenzelm@20451
    11
  A logical context represents the background that is required for
wenzelm@20451
    12
  formulating statements and composing proofs.  It acts as a medium to
wenzelm@20451
    13
  produce formal content, depending on earlier material (declarations,
wenzelm@20451
    14
  results etc.).
wenzelm@18537
    15
wenzelm@20451
    16
  For example, derivations within the Isabelle/Pure logic can be
wenzelm@20451
    17
  described as a judgment @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"}, which means that a
wenzelm@20429
    18
  proposition @{text "\<phi>"} is derivable from hypotheses @{text "\<Gamma>"}
wenzelm@20429
    19
  within the theory @{text "\<Theta>"}.  There are logical reasons for
wenzelm@20451
    20
  keeping @{text "\<Theta>"} and @{text "\<Gamma>"} separate: theories can be
wenzelm@20451
    21
  liberal about supporting type constructors and schematic
wenzelm@20451
    22
  polymorphism of constants and axioms, while the inner calculus of
wenzelm@20451
    23
  @{text "\<Gamma> \<turnstile> \<phi>"} is strictly limited to Simple Type Theory (with
wenzelm@20451
    24
  fixed type variables in the assumptions).
wenzelm@18537
    25
wenzelm@20429
    26
  \medskip Contexts and derivations are linked by the following key
wenzelm@20429
    27
  principles:
wenzelm@20429
    28
wenzelm@20429
    29
  \begin{itemize}
wenzelm@20429
    30
wenzelm@20429
    31
  \item Transfer: monotonicity of derivations admits results to be
wenzelm@20451
    32
  transferred into a \emph{larger} context, i.e.\ @{text "\<Gamma> \<turnstile>\<^sub>\<Theta>
wenzelm@20451
    33
  \<phi>"} implies @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta>\<^sub>' \<phi>"} for contexts @{text "\<Theta>'
wenzelm@20451
    34
  \<supseteq> \<Theta>"} and @{text "\<Gamma>' \<supseteq> \<Gamma>"}.
wenzelm@18537
    35
wenzelm@20429
    36
  \item Export: discharge of hypotheses admits results to be exported
wenzelm@20451
    37
  into a \emph{smaller} context, i.e.\ @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta> \<phi>"}
wenzelm@20451
    38
  implies @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<Delta> \<Longrightarrow> \<phi>"} where @{text "\<Gamma>' \<supseteq> \<Gamma>"} and
wenzelm@20451
    39
  @{text "\<Delta> = \<Gamma>' - \<Gamma>"}.  Note that @{text "\<Theta>"} remains unchanged here,
wenzelm@20451
    40
  only the @{text "\<Gamma>"} part is affected.
wenzelm@20429
    41
wenzelm@20429
    42
  \end{itemize}
wenzelm@18537
    43
wenzelm@20451
    44
  \medskip By modeling the main characteristics of the primitive
wenzelm@20451
    45
  @{text "\<Theta>"} and @{text "\<Gamma>"} above, and abstracting over any
wenzelm@20451
    46
  particular logical content, we arrive at the fundamental notions of
wenzelm@20451
    47
  \emph{theory context} and \emph{proof context} in Isabelle/Isar.
wenzelm@20451
    48
  These implement a certain policy to manage arbitrary \emph{context
wenzelm@20451
    49
  data}.  There is a strongly-typed mechanism to declare new kinds of
wenzelm@20429
    50
  data at compile time.
wenzelm@18537
    51
wenzelm@20451
    52
  The internal bootstrap process of Isabelle/Pure eventually reaches a
wenzelm@20451
    53
  stage where certain data slots provide the logical content of @{text
wenzelm@20451
    54
  "\<Theta>"} and @{text "\<Gamma>"} sketched above, but this does not stop there!
wenzelm@20451
    55
  Various additional data slots support all kinds of mechanisms that
wenzelm@20451
    56
  are not necessarily part of the core logic.
wenzelm@18537
    57
wenzelm@20429
    58
  For example, there would be data for canonical introduction and
wenzelm@20429
    59
  elimination rules for arbitrary operators (depending on the
wenzelm@20429
    60
  object-logic and application), which enables users to perform
wenzelm@20451
    61
  standard proof steps implicitly (cf.\ the @{text "rule"} method
wenzelm@20451
    62
  \cite{isabelle-isar-ref}).
wenzelm@18537
    63
wenzelm@20451
    64
  \medskip Thus Isabelle/Isar is able to bring forth more and more
wenzelm@20451
    65
  concepts successively.  In particular, an object-logic like
wenzelm@20451
    66
  Isabelle/HOL continues the Isabelle/Pure setup by adding specific
wenzelm@20451
    67
  components for automated reasoning (classical reasoner, tableau
wenzelm@20451
    68
  prover, structured induction etc.) and derived specification
wenzelm@20451
    69
  mechanisms (inductive predicates, recursive functions etc.).  All of
wenzelm@20451
    70
  this is ultimately based on the generic data management by theory
wenzelm@20451
    71
  and proof contexts introduced here.
wenzelm@18537
    72
*}
wenzelm@18537
    73
wenzelm@18537
    74
wenzelm@18537
    75
subsection {* Theory context \label{sec:context-theory} *}
wenzelm@18537
    76
wenzelm@20429
    77
text {*
wenzelm@20447
    78
  \glossary{Theory}{FIXME}
wenzelm@20447
    79
wenzelm@20451
    80
  A \emph{theory} is a data container with explicit named and unique
wenzelm@20451
    81
  identifier.  Theories are related by a (nominal) sub-theory
wenzelm@20451
    82
  relation, which corresponds to the dependency graph of the original
wenzelm@20451
    83
  construction; each theory is derived from a certain sub-graph of
wenzelm@20451
    84
  ancestor theories.
wenzelm@20451
    85
wenzelm@20451
    86
  The @{text "merge"} operation produces the least upper bound of two
wenzelm@20451
    87
  theories, which actually degenerates into absorption of one theory
wenzelm@20451
    88
  into the other (due to the nominal sub-theory relation).
wenzelm@18537
    89
wenzelm@20429
    90
  The @{text "begin"} operation starts a new theory by importing
wenzelm@20429
    91
  several parent theories and entering a special @{text "draft"} mode,
wenzelm@20429
    92
  which is sustained until the final @{text "end"} operation.  A draft
wenzelm@20451
    93
  theory acts like a linear type, where updates invalidate earlier
wenzelm@20451
    94
  versions.  An invalidated draft is called ``stale''.
wenzelm@20429
    95
wenzelm@20447
    96
  The @{text "checkpoint"} operation produces an intermediate stepping
wenzelm@20451
    97
  stone that will survive the next update: both the original and the
wenzelm@20451
    98
  changed theory remain valid and are related by the sub-theory
wenzelm@20451
    99
  relation.  Checkpointing essentially recovers purely functional
wenzelm@20451
   100
  theory values, at the expense of some extra internal bookkeeping.
wenzelm@20447
   101
wenzelm@20447
   102
  The @{text "copy"} operation produces an auxiliary version that has
wenzelm@20447
   103
  the same data content, but is unrelated to the original: updates of
wenzelm@20447
   104
  the copy do not affect the original, neither does the sub-theory
wenzelm@20447
   105
  relation hold.
wenzelm@20429
   106
wenzelm@20447
   107
  \medskip The example in \figref{fig:ex-theory} below shows a theory
wenzelm@20451
   108
  graph derived from @{text "Pure"}, with theory @{text "Length"}
wenzelm@20451
   109
  importing @{text "Nat"} and @{text "List"}.  The body of @{text
wenzelm@20451
   110
  "Length"} consists of a sequence of updates, working mostly on
wenzelm@20451
   111
  drafts.  Intermediate checkpoints may occur as well, due to the
wenzelm@20451
   112
  history mechanism provided by the Isar top-level, cf.\
wenzelm@20451
   113
  \secref{sec:isar-toplevel}.
wenzelm@20447
   114
wenzelm@20447
   115
  \begin{figure}[htb]
wenzelm@20447
   116
  \begin{center}
wenzelm@20429
   117
  \begin{tabular}{rcccl}
wenzelm@20447
   118
        &            & @{text "Pure"} \\
wenzelm@20447
   119
        &            & @{text "\<down>"} \\
wenzelm@20447
   120
        &            & @{text "FOL"} \\
wenzelm@18537
   121
        & $\swarrow$ &              & $\searrow$ & \\
wenzelm@20447
   122
  $Nat$ &            &              &            & @{text "List"} \\
wenzelm@18537
   123
        & $\searrow$ &              & $\swarrow$ \\
wenzelm@20447
   124
        &            & @{text "Length"} \\
wenzelm@18537
   125
        &            & \multicolumn{3}{l}{~~$\isarkeyword{imports}$} \\
wenzelm@18537
   126
        &            & \multicolumn{3}{l}{~~$\isarkeyword{begin}$} \\
wenzelm@18537
   127
        &            & $\vdots$~~ \\
wenzelm@20447
   128
        &            & @{text "\<bullet>"}~~ \\
wenzelm@20447
   129
        &            & $\vdots$~~ \\
wenzelm@20447
   130
        &            & @{text "\<bullet>"}~~ \\
wenzelm@20447
   131
        &            & $\vdots$~~ \\
wenzelm@18537
   132
        &            & \multicolumn{3}{l}{~~$\isarkeyword{end}$} \\
wenzelm@20429
   133
  \end{tabular}
wenzelm@20451
   134
  \caption{A theory definition depending on ancestors}\label{fig:ex-theory}
wenzelm@20447
   135
  \end{center}
wenzelm@20447
   136
  \end{figure}
wenzelm@20451
   137
wenzelm@20451
   138
  \medskip There is a separate notion of \emph{theory reference} for
wenzelm@20451
   139
  maintaining a live link to an evolving theory context: updates on
wenzelm@20451
   140
  drafts are propagated automatically.  The dynamic stops after an
wenzelm@20451
   141
  explicit @{text "end"} only.
wenzelm@20451
   142
wenzelm@20451
   143
  Derived entities may store a theory reference in order to indicate
wenzelm@20451
   144
  the context they belong to.  This implicitly assumes monotonic
wenzelm@20451
   145
  reasoning, because the referenced context may become larger without
wenzelm@20451
   146
  further notice.
wenzelm@18537
   147
*}
wenzelm@18537
   148
wenzelm@20430
   149
text %mlref {*
wenzelm@20447
   150
  \begin{mldecls}
wenzelm@20447
   151
  @{index_ML_type theory} \\
wenzelm@20447
   152
  @{index_ML Theory.subthy: "theory * theory -> bool"} \\
wenzelm@20447
   153
  @{index_ML Theory.merge: "theory * theory -> theory"} \\
wenzelm@20447
   154
  @{index_ML Theory.checkpoint: "theory -> theory"} \\
wenzelm@20447
   155
  @{index_ML Theory.copy: "theory -> theory"} \\[1ex]
wenzelm@20447
   156
  @{index_ML_type theory_ref} \\
wenzelm@20447
   157
  @{index_ML Theory.self_ref: "theory -> theory_ref"} \\
wenzelm@20447
   158
  @{index_ML Theory.deref: "theory_ref -> theory"} \\
wenzelm@20447
   159
  \end{mldecls}
wenzelm@20447
   160
wenzelm@20447
   161
  \begin{description}
wenzelm@20447
   162
wenzelm@20451
   163
  \item @{ML_type theory} represents theory contexts.  This is
wenzelm@20451
   164
  essentially a linear type!  Most operations destroy the original
wenzelm@20451
   165
  version, which then becomes ``stale''.
wenzelm@20447
   166
wenzelm@20447
   167
  \item @{ML "Theory.subthy"}~@{text "(thy\<^sub>1, thy\<^sub>2)"}
wenzelm@20447
   168
  compares theories according to the inherent graph structure of the
wenzelm@20447
   169
  construction.  This sub-theory relation is a nominal approximation
wenzelm@20447
   170
  of inclusion (@{text "\<subseteq>"}) of the corresponding content.
wenzelm@20447
   171
wenzelm@20447
   172
  \item @{ML "Theory.merge"}~@{text "(thy\<^sub>1, thy\<^sub>2)"}
wenzelm@20447
   173
  absorbs one theory into the other.  This fails for unrelated
wenzelm@20447
   174
  theories!
wenzelm@20447
   175
wenzelm@20447
   176
  \item @{ML "Theory.checkpoint"}~@{text "thy"} produces a safe
wenzelm@20447
   177
  stepping stone in the linear development of @{text "thy"}.  The next
wenzelm@20447
   178
  update will result in two related, valid theories.
wenzelm@20447
   179
wenzelm@20447
   180
  \item @{ML "Theory.copy"}~@{text "thy"} produces a variant of @{text
wenzelm@20451
   181
  "thy"} that holds a copy of the same data.  The result is not
wenzelm@20451
   182
  related to the original; the original is unchanched.
wenzelm@20447
   183
wenzelm@20451
   184
  \item @{ML_type theory_ref} represents a sliding reference to an
wenzelm@20451
   185
  always valid theory; updates on the original are propagated
wenzelm@20447
   186
  automatically.
wenzelm@20447
   187
wenzelm@20449
   188
  \item @{ML "Theory.self_ref"}~@{text "thy"} and @{ML
wenzelm@20449
   189
  "Theory.deref"}~@{text "thy_ref"} convert between @{ML_type
wenzelm@20449
   190
  "theory"} and @{ML_type "theory_ref"}.  As the referenced theory
wenzelm@20449
   191
  evolves monotonically over time, later invocations of @{ML
wenzelm@20451
   192
  "Theory.deref"} may refer to a larger context.
wenzelm@20447
   193
wenzelm@20447
   194
  \end{description}
wenzelm@20430
   195
*}
wenzelm@20430
   196
wenzelm@18537
   197
wenzelm@18537
   198
subsection {* Proof context \label{sec:context-proof} *}
wenzelm@18537
   199
wenzelm@18537
   200
text {*
wenzelm@20447
   201
  \glossary{Proof context}{The static context of a structured proof,
wenzelm@20447
   202
  acts like a local ``theory'' of the current portion of Isar proof
wenzelm@20447
   203
  text, generalizes the idea of local hypotheses @{text "\<Gamma>"} in
wenzelm@20447
   204
  judgments @{text "\<Gamma> \<turnstile> \<phi>"} of natural deduction calculi.  There is a
wenzelm@20447
   205
  generic notion of introducing and discharging hypotheses.
wenzelm@20447
   206
  Arbritrary auxiliary context data may be adjoined.}
wenzelm@20429
   207
wenzelm@20447
   208
  A proof context is a container for pure data with a back-reference
wenzelm@20449
   209
  to the theory it belongs to.  The @{text "init"} operation creates a
wenzelm@20451
   210
  proof context from a given theory.  Modifications to draft theories
wenzelm@20451
   211
  are propagated to the proof context as usual, but there is also an
wenzelm@20451
   212
  explicit @{text "transfer"} operation to force resynchronization
wenzelm@20451
   213
  with more substantial updates to the underlying theory.  The actual
wenzelm@20451
   214
  context data does not require any special bookkeeping, thanks to the
wenzelm@20451
   215
  lack of destructive features.
wenzelm@20429
   216
wenzelm@20447
   217
  Entities derived in a proof context need to record inherent logical
wenzelm@20447
   218
  requirements explicitly, since there is no separate context
wenzelm@20447
   219
  identification as for theories.  For example, hypotheses used in
wenzelm@20451
   220
  primitive derivations (cf.\ \secref{sec:thms}) are recorded
wenzelm@20447
   221
  separately within the sequent @{text "\<Gamma> \<turnstile> \<phi>"}, just to make double
wenzelm@20447
   222
  sure.  Results could still leak into an alien proof context do to
wenzelm@20447
   223
  programming errors, but Isabelle/Isar includes some extra validity
wenzelm@20447
   224
  checks in critical positions, notably at the end of sub-proof.
wenzelm@20429
   225
wenzelm@20451
   226
  Proof contexts may be manipulated arbitrarily, although the common
wenzelm@20451
   227
  discipline is to follow block structure as a mental model: a given
wenzelm@20451
   228
  context is extended consecutively, and results are exported back
wenzelm@20451
   229
  into the original context.  Note that the Isar proof states model
wenzelm@20451
   230
  block-structured reasoning explicitly, using a stack of proof
wenzelm@20451
   231
  contexts internally, cf.\ \secref{sec:isar-proof-state}.
wenzelm@18537
   232
*}
wenzelm@18537
   233
wenzelm@20449
   234
text %mlref {*
wenzelm@20449
   235
  \begin{mldecls}
wenzelm@20449
   236
  @{index_ML_type Proof.context} \\
wenzelm@20449
   237
  @{index_ML ProofContext.init: "theory -> Proof.context"} \\
wenzelm@20449
   238
  @{index_ML ProofContext.theory_of: "Proof.context -> theory"} \\
wenzelm@20449
   239
  @{index_ML ProofContext.transfer: "theory -> Proof.context -> Proof.context"} \\
wenzelm@20449
   240
  \end{mldecls}
wenzelm@20449
   241
wenzelm@20449
   242
  \begin{description}
wenzelm@20449
   243
wenzelm@20449
   244
  \item @{ML_type Proof.context} represents proof contexts.  Elements
wenzelm@20449
   245
  of this type are essentially pure values, with a sliding reference
wenzelm@20449
   246
  to the background theory.
wenzelm@20449
   247
wenzelm@20449
   248
  \item @{ML ProofContext.init}~@{text "thy"} produces a proof context
wenzelm@20449
   249
  derived from @{text "thy"}, initializing all data.
wenzelm@20449
   250
wenzelm@20449
   251
  \item @{ML ProofContext.theory_of}~@{text "ctxt"} selects the
wenzelm@20451
   252
  background theory from @{text "ctxt"}, dereferencing its internal
wenzelm@20451
   253
  @{ML_type theory_ref}.
wenzelm@20449
   254
wenzelm@20449
   255
  \item @{ML ProofContext.transfer}~@{text "thy ctxt"} promotes the
wenzelm@20449
   256
  background theory of @{text "ctxt"} to the super theory @{text
wenzelm@20449
   257
  "thy"}.
wenzelm@20449
   258
wenzelm@20449
   259
  \end{description}
wenzelm@20449
   260
*}
wenzelm@20449
   261
wenzelm@20430
   262
wenzelm@20451
   263
subsection {* Generic contexts \label{sec:generic-context} *}
wenzelm@20429
   264
wenzelm@20449
   265
text {*
wenzelm@20449
   266
  A generic context is the disjoint sum of either a theory or proof
wenzelm@20451
   267
  context.  Occasionally, this enables uniform treatment of generic
wenzelm@20450
   268
  context data, typically extra-logical information.  Operations on
wenzelm@20449
   269
  generic contexts include the usual injections, partial selections,
wenzelm@20449
   270
  and combinators for lifting operations on either component of the
wenzelm@20449
   271
  disjoint sum.
wenzelm@20449
   272
wenzelm@20449
   273
  Moreover, there are total operations @{text "theory_of"} and @{text
wenzelm@20449
   274
  "proof_of"} to convert a generic context into either kind: a theory
wenzelm@20451
   275
  can always be selected from the sum, while a proof context might
wenzelm@20451
   276
  have to be constructed by an ad-hoc @{text "init"} operation.
wenzelm@20449
   277
*}
wenzelm@20430
   278
wenzelm@20449
   279
text %mlref {*
wenzelm@20449
   280
  \begin{mldecls}
wenzelm@20449
   281
  @{index_ML_type Context.generic} \\
wenzelm@20449
   282
  @{index_ML Context.theory_of: "Context.generic -> theory"} \\
wenzelm@20449
   283
  @{index_ML Context.proof_of: "Context.generic -> Proof.context"} \\
wenzelm@20449
   284
  \end{mldecls}
wenzelm@20449
   285
wenzelm@20449
   286
  \begin{description}
wenzelm@20430
   287
wenzelm@20449
   288
  \item @{ML_type Context.generic} is the direct sum of @{ML_type
wenzelm@20451
   289
  "theory"} and @{ML_type "Proof.context"}, with the datatype
wenzelm@20451
   290
  constructors @{ML "Context.Theory"} and @{ML "Context.Proof"}.
wenzelm@20449
   291
wenzelm@20449
   292
  \item @{ML Context.theory_of}~@{text "context"} always produces a
wenzelm@20449
   293
  theory from the generic @{text "context"}, using @{ML
wenzelm@20449
   294
  "ProofContext.theory_of"} as required.
wenzelm@20449
   295
wenzelm@20449
   296
  \item @{ML Context.proof_of}~@{text "context"} always produces a
wenzelm@20449
   297
  proof context from the generic @{text "context"}, using @{ML
wenzelm@20451
   298
  "ProofContext.init"} as required (note that this re-initializes the
wenzelm@20451
   299
  context data with each invocation).
wenzelm@20449
   300
wenzelm@20449
   301
  \end{description}
wenzelm@20449
   302
*}
wenzelm@20437
   303
wenzelm@20447
   304
subsection {* Context data *}
wenzelm@20447
   305
wenzelm@20447
   306
text {*
wenzelm@20451
   307
  The main purpose of theory and proof contexts is to manage arbitrary
wenzelm@20451
   308
  data.  New data types can be declared incrementally at compile time.
wenzelm@20451
   309
  There are separate declaration mechanisms for any of the three kinds
wenzelm@20451
   310
  of contexts: theory, proof, generic.
wenzelm@20449
   311
wenzelm@20449
   312
  \paragraph{Theory data} may refer to destructive entities, which are
wenzelm@20451
   313
  maintained in direct correspondence to the linear evolution of
wenzelm@20451
   314
  theory values, including explicit copies.\footnote{Most existing
wenzelm@20451
   315
  instances of destructive theory data are merely historical relics
wenzelm@20451
   316
  (e.g.\ the destructive theorem storage, and destructive hints for
wenzelm@20451
   317
  the Simplifier and Classical rules).}  A theory data declaration
wenzelm@20451
   318
  needs to implement the following specification (depending on type
wenzelm@20451
   319
  @{text "T"}):
wenzelm@20449
   320
wenzelm@20449
   321
  \medskip
wenzelm@20449
   322
  \begin{tabular}{ll}
wenzelm@20449
   323
  @{text "name: string"} \\
wenzelm@20449
   324
  @{text "empty: T"} & initial value \\
wenzelm@20449
   325
  @{text "copy: T \<rightarrow> T"} & refresh impure data \\
wenzelm@20449
   326
  @{text "extend: T \<rightarrow> T"} & re-initialize on import \\
wenzelm@20449
   327
  @{text "merge: T \<times> T \<rightarrow> T"} & join on import \\
wenzelm@20449
   328
  @{text "print: T \<rightarrow> unit"} & diagnostic output \\
wenzelm@20449
   329
  \end{tabular}
wenzelm@20449
   330
  \medskip
wenzelm@20449
   331
wenzelm@20449
   332
  \noindent The @{text "name"} acts as a comment for diagnostic
wenzelm@20449
   333
  messages; @{text "copy"} is just the identity for pure data; @{text
wenzelm@20449
   334
  "extend"} is acts like a unitary version of @{text "merge"}, both
wenzelm@20449
   335
  should also include the functionality of @{text "copy"} for impure
wenzelm@20449
   336
  data.
wenzelm@20449
   337
wenzelm@20451
   338
  \paragraph{Proof context data} is purely functional.  A declaration
wenzelm@20451
   339
  needs to implement the following specification:
wenzelm@20449
   340
wenzelm@20449
   341
  \medskip
wenzelm@20449
   342
  \begin{tabular}{ll}
wenzelm@20449
   343
  @{text "name: string"} \\
wenzelm@20449
   344
  @{text "init: theory \<rightarrow> T"} & produce initial value \\
wenzelm@20449
   345
  @{text "print: T \<rightarrow> unit"} & diagnostic output \\
wenzelm@20449
   346
  \end{tabular}
wenzelm@20449
   347
  \medskip
wenzelm@20449
   348
wenzelm@20449
   349
  \noindent The @{text "init"} operation is supposed to produce a pure
wenzelm@20451
   350
  value from the given background theory.  The remainder is analogous
wenzelm@20451
   351
  to theory data.
wenzelm@20449
   352
wenzelm@20451
   353
  \paragraph{Generic data} provides a hybrid interface for both theory
wenzelm@20451
   354
  and proof data.  The declaration is essentially the same as for
wenzelm@20451
   355
  (pure) theory data, without @{text "copy"}, though.  The @{text
wenzelm@20451
   356
  "init"} operation for proof contexts merely selects the current data
wenzelm@20451
   357
  value from the background theory.
wenzelm@20449
   358
wenzelm@20449
   359
  \bigskip In any case, a data declaration of type @{text "T"} results
wenzelm@20449
   360
  in the following interface:
wenzelm@20449
   361
wenzelm@20449
   362
  \medskip
wenzelm@20449
   363
  \begin{tabular}{ll}
wenzelm@20449
   364
  @{text "init: theory \<rightarrow> theory"} \\
wenzelm@20449
   365
  @{text "get: context \<rightarrow> T"} \\
wenzelm@20449
   366
  @{text "put: T \<rightarrow> context \<rightarrow> context"} \\
wenzelm@20449
   367
  @{text "map: (T \<rightarrow> T) \<rightarrow> context \<rightarrow> context"} \\
wenzelm@20449
   368
  @{text "print: context \<rightarrow> unit"}
wenzelm@20449
   369
  \end{tabular}
wenzelm@20449
   370
  \medskip
wenzelm@20449
   371
wenzelm@20449
   372
  \noindent Here @{text "init"} needs to be applied to the current
wenzelm@20449
   373
  theory context once, in order to register the initial setup.  The
wenzelm@20449
   374
  other operations provide access for the particular kind of context
wenzelm@20449
   375
  (theory, proof, or generic context).  Note that this is a safe
wenzelm@20449
   376
  interface: there is no other way to access the corresponding data
wenzelm@20451
   377
  slot of a context.  By keeping these operations private, a component
wenzelm@20451
   378
  may maintain abstract values authentically, without other components
wenzelm@20451
   379
  interfering.
wenzelm@20447
   380
*}
wenzelm@20447
   381
wenzelm@20450
   382
text %mlref {*
wenzelm@20450
   383
  \begin{mldecls}
wenzelm@20450
   384
  @{index_ML_functor TheoryDataFun} \\
wenzelm@20450
   385
  @{index_ML_functor ProofDataFun} \\
wenzelm@20450
   386
  @{index_ML_functor GenericDataFun} \\
wenzelm@20450
   387
  \end{mldecls}
wenzelm@20450
   388
wenzelm@20450
   389
  \begin{description}
wenzelm@20450
   390
wenzelm@20450
   391
  \item @{ML_functor TheoryDataFun}@{text "(spec)"} declares data for
wenzelm@20450
   392
  type @{ML_type theory} according to the specification provided as
wenzelm@20451
   393
  argument structure.  The resulting structure provides data init and
wenzelm@20451
   394
  access operations as described above.
wenzelm@20450
   395
wenzelm@20450
   396
  \item @{ML_functor ProofDataFun}@{text "(spec)"} is analogous for
wenzelm@20450
   397
  type @{ML_type Proof.context}.
wenzelm@20450
   398
wenzelm@20450
   399
  \item @{ML_functor GenericDataFun}@{text "(spec)"} is analogous for
wenzelm@20450
   400
  type @{ML_type Context.generic}.
wenzelm@20450
   401
wenzelm@20450
   402
  \end{description}
wenzelm@20450
   403
*}
wenzelm@20450
   404
wenzelm@20447
   405
wenzelm@20437
   406
section {* Named entities *}
wenzelm@20437
   407
wenzelm@20451
   408
text {*
wenzelm@20451
   409
  By general convention, each kind of formal entities (logical
wenzelm@20451
   410
  constant, type, type class, theorem, method etc.) lives in a
wenzelm@20451
   411
  separate name space.  It is usually clear from the syntactic context
wenzelm@20451
   412
  of a name, which kind of entity it refers to.  For example, proof
wenzelm@20451
   413
  method @{text "foo"} vs.\ theorem @{text "foo"} vs.\ logical
wenzelm@20451
   414
  constant @{text "foo"} are easily distinguished thanks to the design
wenzelm@20451
   415
  of the concrete outer syntax.  A notable exception are logical
wenzelm@20451
   416
  identifiers within a term (\secref{sec:terms}): constants, fixed
wenzelm@20451
   417
  variables, and bound variables all share the same identifier syntax,
wenzelm@20451
   418
  but are distinguished by their scope.
wenzelm@20451
   419
wenzelm@20451
   420
  Name spaces are organized uniformly, as a collection of qualified
wenzelm@20451
   421
  names consisting of a sequence of basic name components separated by
wenzelm@20451
   422
  dots: @{text "Bar.bar.foo"}, @{text "Bar.foo"}, and @{text "foo"}
wenzelm@20451
   423
  are examples for qualified names.
wenzelm@20437
   424
wenzelm@20451
   425
  Despite the independence of names of different kinds, certain naming
wenzelm@20451
   426
  conventions may relate them to each other.  For example, a constant
wenzelm@20451
   427
  @{text "foo"} could be accompanied with theorems @{text
wenzelm@20451
   428
  "foo.intro"}, @{text "foo.elim"}, @{text "foo.simps"} etc.  The same
wenzelm@20451
   429
  could happen for a type @{text "foo"}, but this is apt to cause
wenzelm@20451
   430
  clashes in the theorem name space!  To avoid this, there is an
wenzelm@20451
   431
  additional convention to add a suffix that determines the original
wenzelm@20451
   432
  kind.  For example, constant @{text "foo"} could associated with
wenzelm@20451
   433
  theorem @{text "foo.intro"}, type @{text "foo"} with theorem @{text
wenzelm@20451
   434
  "foo_type.intro"}, and type class @{text "foo"} with @{text
wenzelm@20451
   435
  "foo_class.intro"}.
wenzelm@20451
   436
wenzelm@20451
   437
  \medskip Name components are subdivided into \emph{symbols}, which
wenzelm@20451
   438
  constitute the smallest textual unit in Isabelle --- raw characters
wenzelm@20451
   439
  are normally not encountered.
wenzelm@20451
   440
*}
wenzelm@20437
   441
wenzelm@20437
   442
wenzelm@20437
   443
subsection {* Strings of symbols *}
wenzelm@20437
   444
wenzelm@20451
   445
text {*
wenzelm@20451
   446
  Isabelle strings consist of a sequence of
wenzelm@20451
   447
  symbols\glossary{Symbol}{The smallest unit of text in Isabelle,
wenzelm@20451
   448
  subsumes plain ASCII characters as well as an infinite collection of
wenzelm@20451
   449
  named symbols (for greek, math etc.).}, which are either packed as
wenzelm@20451
   450
  an actual @{text "string"}, or represented as a list.  Each symbol
wenzelm@20451
   451
  is in itself a small string of the following form:
wenzelm@20437
   452
wenzelm@20451
   453
  \begin{enumerate}
wenzelm@20437
   454
wenzelm@20451
   455
  \item either a singleton ASCII character ``@{text "c"}'' (with
wenzelm@20451
   456
  character code 0--127), for example ``\verb,a,'',
wenzelm@20437
   457
wenzelm@20451
   458
  \item or a regular symbol ``\verb,\,\verb,<,@{text
wenzelm@20451
   459
  "ident"}\verb,>,'', for example ``\verb,\,\verb,<alpha>,'',
wenzelm@20437
   460
wenzelm@20451
   461
  \item or a control symbol ``\verb,\,\verb,<^,@{text
wenzelm@20451
   462
  "ident"}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'',
wenzelm@20437
   463
wenzelm@20451
   464
  \item or a raw control symbol ``\verb,\,\verb,<^raw:,@{text
wenzelm@20451
   465
  "\<dots>"}\verb,>,'' where ``@{text "\<dots>"}'' refers to any printable ASCII
wenzelm@20451
   466
  character (excluding ``\verb,.,'' and ``\verb,>,'') or non-ASCII
wenzelm@20451
   467
  character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
wenzelm@20437
   468
wenzelm@20451
   469
  \item or a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text
wenzelm@20451
   470
  "nnn"}\verb,>, where @{text "nnn"} are digits, for example
wenzelm@20451
   471
  ``\verb,\,\verb,<^raw42>,''.
wenzelm@20437
   472
wenzelm@20451
   473
  \end{enumerate}
wenzelm@20437
   474
wenzelm@20451
   475
  The @{text "ident"} syntax for symbol names is @{text "letter
wenzelm@20451
   476
  (letter | digit)\<^sup>*"}, where @{text "letter = A..Za..z"} and
wenzelm@20451
   477
  @{text "digit = 0..9"}.  There are infinitely many regular symbols
wenzelm@20451
   478
  and control symbols available, but a certain collection of standard
wenzelm@20451
   479
  symbols is treated specifically.  For example,
wenzelm@20451
   480
  ``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter,
wenzelm@20451
   481
  which means it may occur within regular Isabelle identifier syntax.
wenzelm@20437
   482
wenzelm@20451
   483
  Output of symbols depends on the print mode
wenzelm@20451
   484
  (\secref{sec:print-mode}).  For example, the standard {\LaTeX} setup
wenzelm@20451
   485
  of the Isabelle document preparation system would present
wenzelm@20451
   486
  ``\verb,\,\verb,<alpha>,'' as @{text "\<alpha>"}, and
wenzelm@20451
   487
  ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text
wenzelm@20451
   488
  "\<^bold>\<alpha>"}.
wenzelm@20437
   489
wenzelm@20451
   490
  \medskip It is important to note that the character set underlying
wenzelm@20451
   491
  Isabelle symbols is plain 7-bit ASCII.  Since 8-bit characters are
wenzelm@20451
   492
  passed through transparently, Isabelle may easily process
wenzelm@20451
   493
  Unicode/UCS data as well (using UTF-8 encoding).  Unicode provides
wenzelm@20451
   494
  its own collection of mathematical symbols, but there is no built-in
wenzelm@20451
   495
  link to the ones of Isabelle.
wenzelm@20451
   496
*}
wenzelm@20437
   497
wenzelm@20437
   498
text %mlref {*
wenzelm@20437
   499
  \begin{mldecls}
wenzelm@20437
   500
  @{index_ML_type "Symbol.symbol"} \\
wenzelm@20437
   501
  @{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\
wenzelm@20437
   502
  @{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\
wenzelm@20437
   503
  @{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\
wenzelm@20437
   504
  @{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\
wenzelm@20451
   505
  @{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\[1ex]
wenzelm@20437
   506
  @{index_ML_type "Symbol.sym"} \\
wenzelm@20437
   507
  @{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\
wenzelm@20437
   508
  \end{mldecls}
wenzelm@20437
   509
wenzelm@20437
   510
  \begin{description}
wenzelm@20437
   511
wenzelm@20451
   512
  \item @{ML_type "Symbol.symbol"} represents Isabelle symbols.  This
wenzelm@20451
   513
  type is an alias for @{ML_type "string"}, but emphasizes the
wenzelm@20437
   514
  specific format encountered here.
wenzelm@20437
   515
wenzelm@20447
   516
  \item @{ML "Symbol.explode"}~@{text "s"} produces a symbol list from
wenzelm@20451
   517
  the packed form that is encountered in most practical situations.
wenzelm@20451
   518
  This function supercedes @{ML "String.explode"} for virtually all
wenzelm@20451
   519
  purposes of manipulating text in Isabelle!  Plain @{ML "implode"}
wenzelm@20451
   520
  may still be used for the reverse operation.
wenzelm@20437
   521
wenzelm@20437
   522
  \item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML
wenzelm@20437
   523
  "Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify certain symbols
wenzelm@20437
   524
  (both ASCII and several named ones) according to fixed syntactic
wenzelm@20451
   525
  conventions of Isabelle, cf.\ \cite{isabelle-isar-ref}.
wenzelm@20437
   526
wenzelm@20437
   527
  \item @{ML_type "Symbol.sym"} is a concrete datatype that represents
wenzelm@20451
   528
  the different kinds of symbols explicitly with constructors @{ML
wenzelm@20451
   529
  "Symbol.Char"}, @{ML "Symbol.Sym"}, @{ML "Symbol.Ctrl"}, or @{ML
wenzelm@20451
   530
  "Symbol.Raw"}.
wenzelm@20437
   531
wenzelm@20437
   532
  \item @{ML "Symbol.decode"} converts the string representation of a
wenzelm@20451
   533
  symbol into the datatype version.
wenzelm@20437
   534
wenzelm@20437
   535
  \end{description}
wenzelm@20437
   536
*}
wenzelm@20437
   537
wenzelm@20437
   538
wenzelm@20437
   539
subsection {* Qualified names and name spaces *}
wenzelm@20437
   540
wenzelm@20450
   541
text {*
wenzelm@20451
   542
  A \emph{qualified name} essentially consists of a non-empty list of
wenzelm@20451
   543
  basic name components.  The packad notation uses a dot as separator,
wenzelm@20451
   544
  as in @{text "A.b"}, for example.  The very last component is called
wenzelm@20451
   545
  \emph{base} name, the remaining prefix \emph{qualifier} (which may
wenzelm@20451
   546
  be empty).
wenzelm@20437
   547
wenzelm@20451
   548
  A @{text "naming"} policy tells how to produce fully qualified names
wenzelm@20451
   549
  from a given specification.  The @{text "full"} operation applies
wenzelm@20451
   550
  performs naming of a name; the policy is usually taken from the
wenzelm@20451
   551
  context.  For example, a common policy is to attach an implicit
wenzelm@20451
   552
  prefix.
wenzelm@20437
   553
wenzelm@20451
   554
  A @{text "name space"} manages declarations of fully qualified
wenzelm@20451
   555
  names.  There are separate operations to @{text "declare"}, @{text
wenzelm@20451
   556
  "intern"}, and @{text "extern"} names.
wenzelm@20451
   557
wenzelm@20451
   558
  FIXME
wenzelm@20437
   559
*}
wenzelm@20437
   560
wenzelm@20451
   561
text %mlref FIXME
wenzelm@20451
   562
wenzelm@20437
   563
wenzelm@20437
   564
section {* Structured output *}
wenzelm@20437
   565
wenzelm@20437
   566
subsection {* Pretty printing *}
wenzelm@20437
   567
wenzelm@20437
   568
text FIXME
wenzelm@20437
   569
wenzelm@20437
   570
subsection {* Output channels *}
wenzelm@20437
   571
wenzelm@20437
   572
text FIXME
wenzelm@20437
   573
wenzelm@20451
   574
subsection {* Print modes \label{sec:print-mode} *}
wenzelm@20437
   575
wenzelm@20437
   576
text FIXME
wenzelm@20437
   577
wenzelm@20437
   578
wenzelm@18537
   579
end