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