doc-src/IsarImplementation/Thy/prelim.thy
author wenzelm
Wed, 30 Aug 2006 12:28:32 +0200
changeset 20437 0eb5e30fd620
parent 20430 fd646e926983
child 20447 5b75f1c4d7d6
permissions -rw-r--r--
tuned;
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 {*
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    76
  Each theory is explicitly named and holds a unique identifier.
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    77
  There is a separate \emph{theory reference} for pointing backwards
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    78
  to the enclosing theory context of derived entities.  Theories are
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    79
  related by a (nominal) sub-theory relation, which corresponds to the
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    80
  canonical dependency graph: each theory is derived from a certain
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    81
  sub-graph of ancestor theories.  The @{text "merge"} of two theories
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    82
  refers to the least upper bound, which actually degenerates into
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    83
  absorption of one theory into the other, due to the nominal
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    84
  sub-theory relation this.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    85
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    86
  The @{text "begin"} operation starts a new theory by importing
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    87
  several parent theories and entering a special @{text "draft"} mode,
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    88
  which is sustained until the final @{text "end"} operation.  A draft
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    89
  mode theory acts like a linear type, where updates invalidate
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    90
  earlier drafts, but theory reference values will be propagated
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    91
  automatically.  Thus derived entities that ``belong'' to a draft
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    92
  might be transferred spontaneously to a larger context.  An
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    93
  invalidated draft is called ``stale''.  The @{text "copy"} operation
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    94
  produces an auxiliary version with the same data content, but is
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    95
  unrelated to the original: updates of the copy do not affect the
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    96
  original, neither does the sub-theory relation hold.
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    97
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    98
  The example below shows a theory graph derived from @{text "Pure"}.
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    99
  Theory @{text "Length"} imports @{text "Nat"} and @{text "List"}.
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   100
  The linear draft mode is enabled during the ``@{text "\<dots>"}'' stage of
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   101
  the theory body.
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   102
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   103
  \bigskip
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   104
  \begin{tabular}{rcccl}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   105
        &            & $Pure$ \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   106
        &            & $\downarrow$ \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   107
        &            & $FOL$ \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   108
        & $\swarrow$ &              & $\searrow$ & \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   109
  $Nat$ &            &              &            & $List$ \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   110
        & $\searrow$ &              & $\swarrow$ \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   111
        &            & $Length$ \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   112
        &            & \multicolumn{3}{l}{~~$\isarkeyword{imports}$} \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   113
        &            & \multicolumn{3}{l}{~~$\isarkeyword{begin}$} \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   114
        &            & $\vdots$~~ \\
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   115
        &            & \multicolumn{3}{l}{~~$\isarkeyword{end}$} \\
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   116
  \end{tabular}
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   117
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   118
  \medskip In practice, derived theory operations mostly operate
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   119
  drafts, namely the body of the current portion of theory that the
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   120
  user happens to be composing.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   121
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   122
 \medskip There is also a builtin theory history mechanism that amends for
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   123
  the destructive behaviour of theory drafts.  The @{text
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   124
  "checkpoint"} operation produces an intermediate stepping stone that
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   125
  survives the next update unscathed: both the original and the
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   126
  changed theory remain valid and are related by the sub-theory
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   127
  relation.  This recovering of pure theory values comes at the cost
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   128
  of extra internal bookeeping.  The cumulative effect of
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   129
  checkpointing is purged by the @{text "finish"} operation.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   130
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   131
  History operations are usually managed by the system, e.g.\ notably
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   132
  in the Isar transaction loop.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   133
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   134
  \medskip
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   135
  FIXME theory data
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   136
*}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   137
20430
wenzelm
parents: 20429
diff changeset
   138
text %mlref {*
wenzelm
parents: 20429
diff changeset
   139
*}
wenzelm
parents: 20429
diff changeset
   140
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   141
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   142
subsection {* Proof context \label{sec:context-proof} *}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   143
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   144
text {*
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   145
  A proof context is an arbitrary container that is initialized from a
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   146
  given theory.  The result contains a back-reference to the theory it
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   147
  belongs to, together with pure data.  No further bookkeeping is
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   148
  required here, thanks to the lack of destructive features.
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   149
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   150
  There is no restriction on producing proof contexts, although the
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   151
  usual discipline is to follow block structure as a mental model: a
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   152
  given context is extended consecutively, results are exported back
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   153
  into the original context.  In particular, the concept of Isar proof
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   154
  state models block-structured reasoning explicitly, using a stack of
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   155
  proof contexts.
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   156
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   157
  Due to the lack of identification and back-referencing, entities
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   158
  derived in a proof context need to record inherent logical
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   159
  requirements explicitly.  For example, hypotheses used in a
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   160
  derivation will be recorded separately within the sequent @{text "\<Gamma>
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   161
  \<turnstile> \<phi>"}, just to make double sure.  Results could leak into an alien
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   162
  proof context do to programming errors, but Isabelle/Isar
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   163
  occasionally includes extra validity checks at the end of a
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   164
  sub-proof.
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   165
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   166
  \medskip
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   167
  FIXME proof data
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   168
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   169
\glossary{Proof context}{The static context of a structured proof,
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   170
acts like a local ``theory'' of the current portion of Isar proof
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   171
text, generalizes the idea of local hypotheses @{text "\<Gamma>"} in
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   172
judgments @{text "\<Gamma> \<turnstile> \<phi>"} of natural deduction calculi.  There is a
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   173
generic notion of introducing and discharging hypotheses.  Arbritrary
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   174
auxiliary context data may be adjoined.}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   175
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   176
*}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   177
20430
wenzelm
parents: 20429
diff changeset
   178
text %mlref {* FIXME *}
wenzelm
parents: 20429
diff changeset
   179
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   180
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   181
subsection {* Generic contexts *}
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   182
20430
wenzelm
parents: 20429
diff changeset
   183
text FIXME
wenzelm
parents: 20429
diff changeset
   184
wenzelm
parents: 20429
diff changeset
   185
text %mlref {* FIXME *}
wenzelm
parents: 20429
diff changeset
   186
20437
wenzelm
parents: 20430
diff changeset
   187
wenzelm
parents: 20430
diff changeset
   188
section {* Named entities *}
wenzelm
parents: 20430
diff changeset
   189
wenzelm
parents: 20430
diff changeset
   190
text {* Named entities of different kinds (logical constant, type,
wenzelm
parents: 20430
diff changeset
   191
type class, theorem, method etc.) live in separate name spaces.  It is
wenzelm
parents: 20430
diff changeset
   192
usually clear from the occurrence of a name which kind of entity it
wenzelm
parents: 20430
diff changeset
   193
refers to.  For example, proof method @{text "foo"} vs.\ theorem
wenzelm
parents: 20430
diff changeset
   194
@{text "foo"} vs.\ logical constant @{text "foo"} are easily
wenzelm
parents: 20430
diff changeset
   195
distinguished by means of the syntactic context.  A notable exception
wenzelm
parents: 20430
diff changeset
   196
are logical identifiers within a term (\secref{sec:terms}): constants,
wenzelm
parents: 20430
diff changeset
   197
fixed variables, and bound variables all share the same identifier
wenzelm
parents: 20430
diff changeset
   198
syntax, but are distinguished by their scope.
wenzelm
parents: 20430
diff changeset
   199
wenzelm
parents: 20430
diff changeset
   200
Each name space is organized as a collection of \emph{qualified
wenzelm
parents: 20430
diff changeset
   201
names}, which consist of a sequence of basic name components separated
wenzelm
parents: 20430
diff changeset
   202
by dots: @{text "Bar.bar.foo"}, @{text "Bar.foo"}, and @{text "foo"}
wenzelm
parents: 20430
diff changeset
   203
are examples for valid qualified names.  Name components are
wenzelm
parents: 20430
diff changeset
   204
subdivided into \emph{symbols}, which constitute the smallest textual
wenzelm
parents: 20430
diff changeset
   205
unit in Isabelle --- raw characters are normally not encountered
wenzelm
parents: 20430
diff changeset
   206
directly. *}
wenzelm
parents: 20430
diff changeset
   207
wenzelm
parents: 20430
diff changeset
   208
wenzelm
parents: 20430
diff changeset
   209
subsection {* Strings of symbols *}
wenzelm
parents: 20430
diff changeset
   210
wenzelm
parents: 20430
diff changeset
   211
text {* Isabelle strings consist of a sequence of
wenzelm
parents: 20430
diff changeset
   212
symbols\glossary{Symbol}{The smalles unit of text in Isabelle,
wenzelm
parents: 20430
diff changeset
   213
subsumes plain ASCII characters as well as an infinite collection of
wenzelm
parents: 20430
diff changeset
   214
named symbols (for greek, math etc.).}, which are either packed as an
wenzelm
parents: 20430
diff changeset
   215
actual @{text "string"}, or represented as a list.  Each symbol is in
wenzelm
parents: 20430
diff changeset
   216
itself a small string of the following form:
wenzelm
parents: 20430
diff changeset
   217
wenzelm
parents: 20430
diff changeset
   218
\begin{enumerate}
wenzelm
parents: 20430
diff changeset
   219
wenzelm
parents: 20430
diff changeset
   220
\item either a singleton ASCII character ``@{text "c"}'' (with
wenzelm
parents: 20430
diff changeset
   221
character code 0--127), for example ``\verb,a,'',
wenzelm
parents: 20430
diff changeset
   222
wenzelm
parents: 20430
diff changeset
   223
\item or a regular symbol ``\verb,\,\verb,<,@{text "ident"}\verb,>,'',
wenzelm
parents: 20430
diff changeset
   224
for example ``\verb,\,\verb,<alpha>,'',
wenzelm
parents: 20430
diff changeset
   225
wenzelm
parents: 20430
diff changeset
   226
\item or a control symbol ``\verb,\,\verb,<^,@{text
wenzelm
parents: 20430
diff changeset
   227
"ident"}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'',
wenzelm
parents: 20430
diff changeset
   228
wenzelm
parents: 20430
diff changeset
   229
\item or a raw control symbol ``\verb,\,\verb,<^raw:,@{text
wenzelm
parents: 20430
diff changeset
   230
"\<dots>"}\verb,>,'' where ``@{text "\<dots>"}'' refers to any
wenzelm
parents: 20430
diff changeset
   231
printable ASCII character (excluding ``\verb,.,'' and ``\verb,>,'') or
wenzelm
parents: 20430
diff changeset
   232
non-ASCII character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
wenzelm
parents: 20430
diff changeset
   233
wenzelm
parents: 20430
diff changeset
   234
\item or a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text
wenzelm
parents: 20430
diff changeset
   235
"nnn"}\verb,>, where @{text "nnn"} are digits, for example
wenzelm
parents: 20430
diff changeset
   236
``\verb,\,\verb,<^raw42>,''.
wenzelm
parents: 20430
diff changeset
   237
wenzelm
parents: 20430
diff changeset
   238
\end{enumerate}
wenzelm
parents: 20430
diff changeset
   239
wenzelm
parents: 20430
diff changeset
   240
The @{text "ident"} syntax for symbol names is @{text "letter (letter
wenzelm
parents: 20430
diff changeset
   241
| digit)\<^sup>*"}, where @{text "letter = A..Za..Z"} and @{text
wenzelm
parents: 20430
diff changeset
   242
"digit = 0..9"}.  There are infinitely many regular symbols and
wenzelm
parents: 20430
diff changeset
   243
control symbols available, but a certain collection of standard
wenzelm
parents: 20430
diff changeset
   244
symbols is treated specifically.  For example,
wenzelm
parents: 20430
diff changeset
   245
``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter,
wenzelm
parents: 20430
diff changeset
   246
which means it may occur within regular Isabelle identifier syntax.
wenzelm
parents: 20430
diff changeset
   247
wenzelm
parents: 20430
diff changeset
   248
Output of symbols depends on the print mode (\secref{sec:print-mode}).
wenzelm
parents: 20430
diff changeset
   249
For example, the standard {\LaTeX} setup of the Isabelle document
wenzelm
parents: 20430
diff changeset
   250
preparation system would present ``\verb,\,\verb,<alpha>,'' as @{text
wenzelm
parents: 20430
diff changeset
   251
"\<alpha>"}, and ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text
wenzelm
parents: 20430
diff changeset
   252
"\<^bold>\<alpha>"}.
wenzelm
parents: 20430
diff changeset
   253
wenzelm
parents: 20430
diff changeset
   254
\medskip It is important to note that the character set underlying
wenzelm
parents: 20430
diff changeset
   255
Isabelle symbols is plain 7-bit ASCII.  Since 8-bit characters are
wenzelm
parents: 20430
diff changeset
   256
passed through transparently, Isabelle may easily process actual
wenzelm
parents: 20430
diff changeset
   257
Unicode/UCS data (using the well-known UTF-8 encoding, for example).
wenzelm
parents: 20430
diff changeset
   258
Unicode provides its own collection of mathematical symbols, but there
wenzelm
parents: 20430
diff changeset
   259
is presently no link to Isabelle's named ones; both kinds of symbols
wenzelm
parents: 20430
diff changeset
   260
coexist independently. *}
wenzelm
parents: 20430
diff changeset
   261
wenzelm
parents: 20430
diff changeset
   262
text %mlref {*
wenzelm
parents: 20430
diff changeset
   263
  \begin{mldecls}
wenzelm
parents: 20430
diff changeset
   264
  @{index_ML_type "Symbol.symbol"} \\
wenzelm
parents: 20430
diff changeset
   265
  @{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\
wenzelm
parents: 20430
diff changeset
   266
  @{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\
wenzelm
parents: 20430
diff changeset
   267
  @{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\
wenzelm
parents: 20430
diff changeset
   268
  @{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\
wenzelm
parents: 20430
diff changeset
   269
  @{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\
wenzelm
parents: 20430
diff changeset
   270
  @{index_ML_type "Symbol.sym"} \\
wenzelm
parents: 20430
diff changeset
   271
  @{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\
wenzelm
parents: 20430
diff changeset
   272
  \end{mldecls}
wenzelm
parents: 20430
diff changeset
   273
wenzelm
parents: 20430
diff changeset
   274
  \begin{description}
wenzelm
parents: 20430
diff changeset
   275
wenzelm
parents: 20430
diff changeset
   276
  \item @{ML_type "Symbol.symbol"} represents Isabelle symbols; this type
wenzelm
parents: 20430
diff changeset
   277
  is merely an alias for @{ML_type "string"}, but emphasizes the
wenzelm
parents: 20430
diff changeset
   278
  specific format encountered here.
wenzelm
parents: 20430
diff changeset
   279
wenzelm
parents: 20430
diff changeset
   280
  \item @{ML "Symbol.explode"}~@{text "s"} produces an actual symbol
wenzelm
parents: 20430
diff changeset
   281
  list from the packed form usually encountered as user input.  This
wenzelm
parents: 20430
diff changeset
   282
  function replaces @{ML "String.explode"} for virtually all purposes
wenzelm
parents: 20430
diff changeset
   283
  of manipulating text in Isabelle!  Plain @{text "implode"} may be
wenzelm
parents: 20430
diff changeset
   284
  used for the reverse operation.
wenzelm
parents: 20430
diff changeset
   285
wenzelm
parents: 20430
diff changeset
   286
  \item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML
wenzelm
parents: 20430
diff changeset
   287
  "Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify certain symbols
wenzelm
parents: 20430
diff changeset
   288
  (both ASCII and several named ones) according to fixed syntactic
wenzelm
parents: 20430
diff changeset
   289
  convections of Isabelle, e.g.\ see \cite{isabelle-isar-ref}.
wenzelm
parents: 20430
diff changeset
   290
wenzelm
parents: 20430
diff changeset
   291
  \item @{ML_type "Symbol.sym"} is a concrete datatype that represents
wenzelm
parents: 20430
diff changeset
   292
  the different kinds of symbols explicitly as @{ML "Symbol.Char"},
wenzelm
parents: 20430
diff changeset
   293
  @{ML "Symbol.Sym"}, @{ML "Symbol.Ctrl"}, or @{ML "Symbol.Raw"}.
wenzelm
parents: 20430
diff changeset
   294
wenzelm
parents: 20430
diff changeset
   295
  \item @{ML "Symbol.decode"} converts the string representation of a
wenzelm
parents: 20430
diff changeset
   296
  symbol into the explicit datatype version.
wenzelm
parents: 20430
diff changeset
   297
wenzelm
parents: 20430
diff changeset
   298
  \end{description}
wenzelm
parents: 20430
diff changeset
   299
*}
wenzelm
parents: 20430
diff changeset
   300
wenzelm
parents: 20430
diff changeset
   301
wenzelm
parents: 20430
diff changeset
   302
subsection {* Qualified names and name spaces *}
wenzelm
parents: 20430
diff changeset
   303
wenzelm
parents: 20430
diff changeset
   304
text %FIXME {* Qualified names are constructed according to implicit naming
wenzelm
parents: 20430
diff changeset
   305
principles of the present context.
wenzelm
parents: 20430
diff changeset
   306
wenzelm
parents: 20430
diff changeset
   307
wenzelm
parents: 20430
diff changeset
   308
The last component is called \emph{base name}; the remaining prefix of
wenzelm
parents: 20430
diff changeset
   309
qualification may be empty.
wenzelm
parents: 20430
diff changeset
   310
wenzelm
parents: 20430
diff changeset
   311
Some practical conventions help to organize named entities more
wenzelm
parents: 20430
diff changeset
   312
systematically:
wenzelm
parents: 20430
diff changeset
   313
wenzelm
parents: 20430
diff changeset
   314
\begin{itemize}
wenzelm
parents: 20430
diff changeset
   315
wenzelm
parents: 20430
diff changeset
   316
\item Names are qualified first by the theory name, second by an
wenzelm
parents: 20430
diff changeset
   317
optional ``structure''.  For example, a constant @{text "c"} declared
wenzelm
parents: 20430
diff changeset
   318
as part of a certain structure @{text "b"} (say a type definition) in
wenzelm
parents: 20430
diff changeset
   319
theory @{text "A"} will be named @{text "A.b.c"} internally.
wenzelm
parents: 20430
diff changeset
   320
wenzelm
parents: 20430
diff changeset
   321
\item
wenzelm
parents: 20430
diff changeset
   322
wenzelm
parents: 20430
diff changeset
   323
\item
wenzelm
parents: 20430
diff changeset
   324
wenzelm
parents: 20430
diff changeset
   325
\item
wenzelm
parents: 20430
diff changeset
   326
wenzelm
parents: 20430
diff changeset
   327
\item
wenzelm
parents: 20430
diff changeset
   328
wenzelm
parents: 20430
diff changeset
   329
\end{itemize}
wenzelm
parents: 20430
diff changeset
   330
wenzelm
parents: 20430
diff changeset
   331
Names of different kinds of entities are basically independent, but
wenzelm
parents: 20430
diff changeset
   332
some practical naming conventions relate them to each other.  For
wenzelm
parents: 20430
diff changeset
   333
example, a constant @{text "foo"} may be accompanied with theorems
wenzelm
parents: 20430
diff changeset
   334
@{text "foo.intro"}, @{text "foo.elim"}, @{text "foo.simps"} etc.  The
wenzelm
parents: 20430
diff changeset
   335
same may happen for a type @{text "foo"}, which is then apt to cause
wenzelm
parents: 20430
diff changeset
   336
clashes in the theorem name space!  To avoid this, we occasionally
wenzelm
parents: 20430
diff changeset
   337
follow an additional convention of suffixes that determine the
wenzelm
parents: 20430
diff changeset
   338
original kind of entity that a name has been derived.  For example,
wenzelm
parents: 20430
diff changeset
   339
constant @{text "foo"} is associated with theorem @{text "foo.intro"},
wenzelm
parents: 20430
diff changeset
   340
type @{text "foo"} with theorem @{text "foo_type.intro"}, and type
wenzelm
parents: 20430
diff changeset
   341
class @{text "foo"} with @{text "foo_class.intro"}.
wenzelm
parents: 20430
diff changeset
   342
wenzelm
parents: 20430
diff changeset
   343
*}
wenzelm
parents: 20430
diff changeset
   344
wenzelm
parents: 20430
diff changeset
   345
wenzelm
parents: 20430
diff changeset
   346
section {* Structured output *}
wenzelm
parents: 20430
diff changeset
   347
wenzelm
parents: 20430
diff changeset
   348
subsection {* Pretty printing *}
wenzelm
parents: 20430
diff changeset
   349
wenzelm
parents: 20430
diff changeset
   350
text FIXME
wenzelm
parents: 20430
diff changeset
   351
wenzelm
parents: 20430
diff changeset
   352
subsection {* Output channels *}
wenzelm
parents: 20430
diff changeset
   353
wenzelm
parents: 20430
diff changeset
   354
text FIXME
wenzelm
parents: 20430
diff changeset
   355
wenzelm
parents: 20430
diff changeset
   356
subsection {* Print modes *}
wenzelm
parents: 20430
diff changeset
   357
wenzelm
parents: 20430
diff changeset
   358
text FIXME
wenzelm
parents: 20430
diff changeset
   359
wenzelm
parents: 20430
diff changeset
   360
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   361
end