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