doc-src/IsarImplementation/Thy/Prelim.thy
author wenzelm
Mon, 18 Oct 2010 16:23:55 +0100
changeset 39865 a724b90f951e
parent 39864 f3b4fde34cd1
child 39866 5ec01d5acd0c
permissions -rw-r--r--
more on "Configuration options";
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29755
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 29581
diff changeset
     1
theory Prelim
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 29581
diff changeset
     2
imports Base
d66b34e46bdf observe usual theory naming conventions;
wenzelm
parents: 29581
diff changeset
     3
begin
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     4
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     5
chapter {* Preliminaries *}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     6
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
     7
section {* Contexts \label{sec:context} *}
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
     8
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
     9
text {*
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    10
  A logical context represents the background that is required for
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    11
  formulating statements and composing proofs.  It acts as a medium to
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    12
  produce formal content, depending on earlier material (declarations,
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    13
  results etc.).
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    14
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    15
  For example, derivations within the Isabelle/Pure logic can be
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    16
  described as a judgment @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"}, which means that a
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    17
  proposition @{text "\<phi>"} is derivable from hypotheses @{text "\<Gamma>"}
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    18
  within the theory @{text "\<Theta>"}.  There are logical reasons for
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    19
  keeping @{text "\<Theta>"} and @{text "\<Gamma>"} separate: theories can be
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    20
  liberal about supporting type constructors and schematic
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    21
  polymorphism of constants and axioms, while the inner calculus of
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    22
  @{text "\<Gamma> \<turnstile> \<phi>"} is strictly limited to Simple Type Theory (with
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    23
  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
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    31
  transferred into a \emph{larger} context, i.e.\ @{text "\<Gamma> \<turnstile>\<^sub>\<Theta>
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    32
  \<phi>"} implies @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta>\<^sub>' \<phi>"} for contexts @{text "\<Theta>'
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    33
  \<supseteq> \<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
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    36
  into a \emph{smaller} context, i.e.\ @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta> \<phi>"}
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    37
  implies @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<Delta> \<Longrightarrow> \<phi>"} where @{text "\<Gamma>' \<supseteq> \<Gamma>"} and
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    38
  @{text "\<Delta> = \<Gamma>' - \<Gamma>"}.  Note that @{text "\<Theta>"} remains unchanged here,
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    39
  only the @{text "\<Gamma>"} part is affected.
20429
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
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    43
  \medskip By modeling the main characteristics of the primitive
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    44
  @{text "\<Theta>"} and @{text "\<Gamma>"} above, and abstracting over any
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    45
  particular logical content, we arrive at the fundamental notions of
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    46
  \emph{theory context} and \emph{proof context} in Isabelle/Isar.
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    47
  These implement a certain policy to manage arbitrary \emph{context
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    48
  data}.  There is a strongly-typed mechanism to declare new kinds of
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    49
  data at compile time.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    50
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    51
  The internal bootstrap process of Isabelle/Pure eventually reaches a
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    52
  stage where certain data slots provide the logical content of @{text
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    53
  "\<Theta>"} and @{text "\<Gamma>"} sketched above, but this does not stop there!
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    54
  Various additional data slots support all kinds of mechanisms that
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    55
  are not necessarily part of the core logic.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    56
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    57
  For example, there would be data for canonical introduction and
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    58
  elimination rules for arbitrary operators (depending on the
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    59
  object-logic and application), which enables users to perform
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    60
  standard proof steps implicitly (cf.\ the @{text "rule"} method
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    61
  \cite{isabelle-isar-ref}).
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    62
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    63
  \medskip Thus Isabelle/Isar is able to bring forth more and more
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    64
  concepts successively.  In particular, an object-logic like
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    65
  Isabelle/HOL continues the Isabelle/Pure setup by adding specific
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    66
  components for automated reasoning (classical reasoner, tableau
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    67
  prover, structured induction etc.) and derived specification
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    68
  mechanisms (inductive predicates, recursive functions etc.).  All of
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    69
  this is ultimately based on the generic data management by theory
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    70
  and proof contexts introduced here.
18537
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
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    74
subsection {* Theory context \label{sec:context-theory} *}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    75
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    76
text {* A \emph{theory} is a data container with explicit name and
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    77
  unique identifier.  Theories are related by a (nominal) sub-theory
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    78
  relation, which corresponds to the dependency graph of the original
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
    79
  construction; each theory is derived from a certain sub-graph of
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    80
  ancestor theories.  To this end, the system maintains a set of
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    81
  symbolic ``identification stamps'' within each theory.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
    82
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    83
  In order to avoid the full-scale overhead of explicit sub-theory
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    84
  identification of arbitrary intermediate stages, a theory is
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    85
  switched into @{text "draft"} mode under certain circumstances.  A
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    86
  draft theory acts like a linear type, where updates invalidate
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    87
  earlier versions.  An invalidated draft is called \emph{stale}.
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
    88
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    89
  The @{text "checkpoint"} operation produces a safe stepping stone
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    90
  that will survive the next update without becoming stale: both the
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    91
  old and the new theory remain valid and are related by the
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    92
  sub-theory relation.  Checkpointing essentially recovers purely
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    93
  functional theory values, at the expense of some extra internal
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
    94
  bookkeeping.
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
    95
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
    96
  The @{text "copy"} operation produces an auxiliary version that has
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
    97
  the same data content, but is unrelated to the original: updates of
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
    98
  the copy do not affect the original, neither does the sub-theory
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
    99
  relation hold.
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   100
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   101
  The @{text "merge"} operation produces the least upper bound of two
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   102
  theories, which actually degenerates into absorption of one theory
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   103
  into the other (according to the nominal sub-theory relation).
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   104
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   105
  The @{text "begin"} operation starts a new theory by importing
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   106
  several parent theories and entering a special mode of nameless
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   107
  incremental updates, until the final @{text "end"} operation is
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   108
  performed.
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   109
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   110
  \medskip The example in \figref{fig:ex-theory} below shows a theory
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   111
  graph derived from @{text "Pure"}, with theory @{text "Length"}
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   112
  importing @{text "Nat"} and @{text "List"}.  The body of @{text
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   113
  "Length"} consists of a sequence of updates, working mostly on
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   114
  drafts internally, while transaction boundaries of Isar top-level
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   115
  commands (\secref{sec:isar-toplevel}) are guaranteed to be safe
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   116
  checkpoints.
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   117
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   118
  \begin{figure}[htb]
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   119
  \begin{center}
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   120
  \begin{tabular}{rcccl}
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   121
        &            & @{text "Pure"} \\
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   122
        &            & @{text "\<down>"} \\
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   123
        &            & @{text "FOL"} \\
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   124
        & $\swarrow$ &              & $\searrow$ & \\
21852
wenzelm
parents: 20547
diff changeset
   125
  @{text "Nat"} &    &              &            & @{text "List"} \\
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   126
        & $\searrow$ &              & $\swarrow$ \\
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   127
        &            & @{text "Length"} \\
26864
1417e704d724 replaced macros by antiquotations;
wenzelm
parents: 24137
diff changeset
   128
        &            & \multicolumn{3}{l}{~~@{keyword "imports"}} \\
1417e704d724 replaced macros by antiquotations;
wenzelm
parents: 24137
diff changeset
   129
        &            & \multicolumn{3}{l}{~~@{keyword "begin"}} \\
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   130
        &            & $\vdots$~~ \\
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   131
        &            & @{text "\<bullet>"}~~ \\
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   132
        &            & $\vdots$~~ \\
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   133
        &            & @{text "\<bullet>"}~~ \\
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   134
        &            & $\vdots$~~ \\
26864
1417e704d724 replaced macros by antiquotations;
wenzelm
parents: 24137
diff changeset
   135
        &            & \multicolumn{3}{l}{~~@{command "end"}} \\
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   136
  \end{tabular}
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   137
  \caption{A theory definition depending on ancestors}\label{fig:ex-theory}
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   138
  \end{center}
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   139
  \end{figure}
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   140
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   141
  \medskip There is a separate notion of \emph{theory reference} for
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   142
  maintaining a live link to an evolving theory context: updates on
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   143
  drafts are propagated automatically.  Dynamic updating stops when
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   144
  the next @{text "checkpoint"} is reached.
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   145
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   146
  Derived entities may store a theory reference in order to indicate
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   147
  the formal context from which they are derived.  This implicitly
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   148
  assumes monotonic reasoning, because the referenced context may
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   149
  become larger without further notice.
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   150
*}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   151
20430
wenzelm
parents: 20429
diff changeset
   152
text %mlref {*
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   153
  \begin{mldecls}
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   154
  @{index_ML_type theory} \\
39837
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   155
  @{index_ML Theory.eq_thy: "theory * theory -> bool"} \\
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   156
  @{index_ML Theory.subthy: "theory * theory -> bool"} \\
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   157
  @{index_ML Theory.checkpoint: "theory -> theory"} \\
20547
wenzelm
parents: 20530
diff changeset
   158
  @{index_ML Theory.copy: "theory -> theory"} \\
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   159
  @{index_ML Theory.merge: "theory * theory -> theory"} \\
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   160
  @{index_ML Theory.begin_theory: "string -> theory list -> theory"} \\
39837
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   161
  @{index_ML Theory.parents_of: "theory -> theory list"} \\
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   162
  @{index_ML Theory.ancestors_of: "theory -> theory list"} \\
20547
wenzelm
parents: 20530
diff changeset
   163
  \end{mldecls}
wenzelm
parents: 20530
diff changeset
   164
  \begin{mldecls}
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   165
  @{index_ML_type theory_ref} \\
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   166
  @{index_ML Theory.deref: "theory_ref -> theory"} \\
24137
8d7896398147 replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents: 22869
diff changeset
   167
  @{index_ML Theory.check_thy: "theory -> theory_ref"} \\
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   168
  \end{mldecls}
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   169
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   170
  \begin{description}
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   171
39864
wenzelm
parents: 39863
diff changeset
   172
  \item Type @{ML_type theory} represents theory contexts.  This is
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   173
  essentially a linear type, with explicit runtime checking.
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   174
  Primitive theory operations destroy the original version, which then
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   175
  becomes ``stale''.  This can be prevented by explicit checkpointing,
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   176
  which the system does at least at the boundary of toplevel command
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   177
  transactions \secref{sec:isar-toplevel}.
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   178
39837
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   179
  \item @{ML "Theory.eq_thy"}~@{text "(thy\<^sub>1, thy\<^sub>2)"} check strict
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   180
  identity of two theories.
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   181
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   182
  \item @{ML "Theory.subthy"}~@{text "(thy\<^sub>1, thy\<^sub>2)"} compares theories
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   183
  according to the intrinsic graph structure of the construction.
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   184
  This sub-theory relation is a nominal approximation of inclusion
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   185
  (@{text "\<subseteq>"}) of the corresponding content (according to the
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   186
  semantics of the ML modules that implement the data).
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   187
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   188
  \item @{ML "Theory.checkpoint"}~@{text "thy"} produces a safe
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   189
  stepping stone in the linear development of @{text "thy"}.  This
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   190
  changes the old theory, but the next update will result in two
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   191
  related, valid theories.
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   192
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   193
  \item @{ML "Theory.copy"}~@{text "thy"} produces a variant of @{text
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   194
  "thy"} with the same data.  The copy is not related to the original,
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   195
  but the original is unchanged.
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   196
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   197
  \item @{ML "Theory.merge"}~@{text "(thy\<^sub>1, thy\<^sub>2)"} absorbs one theory
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   198
  into the other, without changing @{text "thy\<^sub>1"} or @{text "thy\<^sub>2"}.
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   199
  This version of ad-hoc theory merge fails for unrelated theories!
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   200
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   201
  \item @{ML "Theory.begin_theory"}~@{text "name parents"} constructs
39825
f9066b94bf07 eliminated fancy \ML logo for the sake of simpler source text (less dependence on LaTeX);
wenzelm
parents: 39821
diff changeset
   202
  a new theory based on the given parents.  This ML function is
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   203
  normally not invoked directly.
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   204
39837
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   205
  \item @{ML "Theory.parents_of"}~@{text "thy"} returns the direct
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   206
  ancestors of @{text thy}.
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   207
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   208
  \item @{ML "Theory.ancestors_of"}~@{text "thy"} returns all
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   209
  ancestors of @{text thy} (not including @{text thy} itself).
eacb7825025d cover some more theory operations;
wenzelm
parents: 39833
diff changeset
   210
39864
wenzelm
parents: 39863
diff changeset
   211
  \item Type @{ML_type theory_ref} represents a sliding reference to
wenzelm
parents: 39863
diff changeset
   212
  an always valid theory; updates on the original are propagated
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   213
  automatically.
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   214
24137
8d7896398147 replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents: 22869
diff changeset
   215
  \item @{ML "Theory.deref"}~@{text "thy_ref"} turns a @{ML_type
8d7896398147 replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents: 22869
diff changeset
   216
  "theory_ref"} into an @{ML_type "theory"} value.  As the referenced
8d7896398147 replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents: 22869
diff changeset
   217
  theory evolves monotonically over time, later invocations of @{ML
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   218
  "Theory.deref"} may refer to a larger context.
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   219
24137
8d7896398147 replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents: 22869
diff changeset
   220
  \item @{ML "Theory.check_thy"}~@{text "thy"} produces a @{ML_type
8d7896398147 replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents: 22869
diff changeset
   221
  "theory_ref"} from a valid @{ML_type "theory"} value.
8d7896398147 replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents: 22869
diff changeset
   222
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   223
  \end{description}
20430
wenzelm
parents: 20429
diff changeset
   224
*}
wenzelm
parents: 20429
diff changeset
   225
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   226
text %mlantiq {*
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   227
  \begin{matharray}{rcl}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   228
  @{ML_antiquotation_def "theory"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   229
  @{ML_antiquotation_def "theory_ref"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   230
  \end{matharray}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   231
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   232
  \begin{rail}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   233
  ('theory' | 'theory\_ref') nameref?
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   234
  ;
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   235
  \end{rail}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   236
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   237
  \begin{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   238
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   239
  \item @{text "@{theory}"} refers to the background theory of the
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   240
  current context --- as abstract value.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   241
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   242
  \item @{text "@{theory A}"} refers to an explicitly named ancestor
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   243
  theory @{text "A"} of the background theory of the current context
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   244
  --- as abstract value.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   245
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   246
  \item @{text "@{theory_ref}"} is similar to @{text "@{theory}"}, but
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   247
  produces a @{ML_type theory_ref} via @{ML "Theory.check_thy"} as
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   248
  explained above.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   249
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   250
  \end{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   251
*}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   252
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   253
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   254
subsection {* Proof context \label{sec:context-proof} *}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   255
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   256
text {* A proof context is a container for pure data with a
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   257
  back-reference to the theory from which it is derived.  The @{text
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   258
  "init"} operation creates a proof context from a given theory.
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   259
  Modifications to draft theories are propagated to the proof context
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   260
  as usual, but there is also an explicit @{text "transfer"} operation
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   261
  to force resynchronization with more substantial updates to the
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   262
  underlying theory.
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   263
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   264
  Entities derived in a proof context need to record logical
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   265
  requirements explicitly, since there is no separate context
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   266
  identification or symbolic inclusion as for theories.  For example,
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   267
  hypotheses used in primitive derivations (cf.\ \secref{sec:thms})
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   268
  are recorded separately within the sequent @{text "\<Gamma> \<turnstile> \<phi>"}, just to
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   269
  make double sure.  Results could still leak into an alien proof
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   270
  context due to programming errors, but Isabelle/Isar includes some
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   271
  extra validity checks in critical positions, notably at the end of a
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   272
  sub-proof.
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   273
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   274
  Proof contexts may be manipulated arbitrarily, although the common
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   275
  discipline is to follow block structure as a mental model: a given
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   276
  context is extended consecutively, and results are exported back
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   277
  into the original context.  Note that an Isar proof state models
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   278
  block-structured reasoning explicitly, using a stack of proof
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   279
  contexts internally.  For various technical reasons, the background
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   280
  theory of an Isar proof state must not be changed while the proof is
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   281
  still under construction!
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   282
*}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   283
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   284
text %mlref {*
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   285
  \begin{mldecls}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   286
  @{index_ML_type Proof.context} \\
36611
b0c047d03208 ProofContext.init_global;
wenzelm
parents: 35408
diff changeset
   287
  @{index_ML ProofContext.init_global: "theory -> Proof.context"} \\
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   288
  @{index_ML ProofContext.theory_of: "Proof.context -> theory"} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   289
  @{index_ML ProofContext.transfer: "theory -> Proof.context -> Proof.context"} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   290
  \end{mldecls}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   291
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   292
  \begin{description}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   293
39864
wenzelm
parents: 39863
diff changeset
   294
  \item Type @{ML_type Proof.context} represents proof contexts.
wenzelm
parents: 39863
diff changeset
   295
  Elements of this type are essentially pure values, with a sliding
wenzelm
parents: 39863
diff changeset
   296
  reference to the background theory.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   297
36611
b0c047d03208 ProofContext.init_global;
wenzelm
parents: 35408
diff changeset
   298
  \item @{ML ProofContext.init_global}~@{text "thy"} produces a proof context
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   299
  derived from @{text "thy"}, initializing all data.
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   300
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   301
  \item @{ML ProofContext.theory_of}~@{text "ctxt"} selects the
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   302
  background theory from @{text "ctxt"}, dereferencing its internal
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   303
  @{ML_type theory_ref}.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   304
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   305
  \item @{ML ProofContext.transfer}~@{text "thy ctxt"} promotes the
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   306
  background theory of @{text "ctxt"} to the super theory @{text
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   307
  "thy"}.
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   308
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   309
  \end{description}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   310
*}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   311
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   312
text %mlantiq {*
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   313
  \begin{matharray}{rcl}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   314
  @{ML_antiquotation_def "context"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   315
  \end{matharray}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   316
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   317
  \begin{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   318
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   319
  \item @{text "@{context}"} refers to \emph{the} context at
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   320
  compile-time --- as abstract value.  Independently of (local) theory
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   321
  or proof mode, this always produces a meaningful result.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   322
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   323
  This is probably the most common antiquotation in interactive
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   324
  experimentation with ML inside Isar.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   325
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   326
  \end{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   327
*}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
   328
20430
wenzelm
parents: 20429
diff changeset
   329
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   330
subsection {* Generic contexts \label{sec:generic-context} *}
20429
116255c9209b more on contexts;
wenzelm
parents: 20214
diff changeset
   331
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   332
text {*
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   333
  A generic context is the disjoint sum of either a theory or proof
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   334
  context.  Occasionally, this enables uniform treatment of generic
20450
wenzelm
parents: 20449
diff changeset
   335
  context data, typically extra-logical information.  Operations on
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   336
  generic contexts include the usual injections, partial selections,
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   337
  and combinators for lifting operations on either component of the
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   338
  disjoint sum.
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   339
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   340
  Moreover, there are total operations @{text "theory_of"} and @{text
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   341
  "proof_of"} to convert a generic context into either kind: a theory
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   342
  can always be selected from the sum, while a proof context might
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   343
  have to be constructed by an ad-hoc @{text "init"} operation, which
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   344
  incurs a small runtime overhead.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   345
*}
20430
wenzelm
parents: 20429
diff changeset
   346
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   347
text %mlref {*
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   348
  \begin{mldecls}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   349
  @{index_ML_type Context.generic} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   350
  @{index_ML Context.theory_of: "Context.generic -> theory"} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   351
  @{index_ML Context.proof_of: "Context.generic -> Proof.context"} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   352
  \end{mldecls}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   353
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   354
  \begin{description}
20430
wenzelm
parents: 20429
diff changeset
   355
39864
wenzelm
parents: 39863
diff changeset
   356
  \item Type @{ML_type Context.generic} is the direct sum of @{ML_type
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   357
  "theory"} and @{ML_type "Proof.context"}, with the datatype
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   358
  constructors @{ML "Context.Theory"} and @{ML "Context.Proof"}.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   359
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   360
  \item @{ML Context.theory_of}~@{text "context"} always produces a
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   361
  theory from the generic @{text "context"}, using @{ML
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   362
  "ProofContext.theory_of"} as required.
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   363
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   364
  \item @{ML Context.proof_of}~@{text "context"} always produces a
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   365
  proof context from the generic @{text "context"}, using @{ML
36611
b0c047d03208 ProofContext.init_global;
wenzelm
parents: 35408
diff changeset
   366
  "ProofContext.init_global"} as required (note that this re-initializes the
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   367
  context data with each invocation).
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   368
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   369
  \end{description}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   370
*}
20437
wenzelm
parents: 20430
diff changeset
   371
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   372
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   373
subsection {* Context data \label{sec:context-data} *}
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   374
33524
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   375
text {* The main purpose of theory and proof contexts is to manage
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   376
  arbitrary (pure) data.  New data types can be declared incrementally
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   377
  at compile time.  There are separate declaration mechanisms for any
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   378
  of the three kinds of contexts: theory, proof, generic.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   379
33524
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   380
  \paragraph{Theory data} declarations need to implement the following
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   381
  SML signature:
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   382
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   383
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   384
  \begin{tabular}{ll}
22869
9f915d44a666 simplified context data;
wenzelm
parents: 22438
diff changeset
   385
  @{text "\<type> T"} & representing type \\
9f915d44a666 simplified context data;
wenzelm
parents: 22438
diff changeset
   386
  @{text "\<val> empty: T"} & empty default value \\
9f915d44a666 simplified context data;
wenzelm
parents: 22438
diff changeset
   387
  @{text "\<val> extend: T \<rightarrow> T"} & re-initialize on import \\
9f915d44a666 simplified context data;
wenzelm
parents: 22438
diff changeset
   388
  @{text "\<val> merge: T \<times> T \<rightarrow> T"} & join on import \\
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   389
  \end{tabular}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   390
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   391
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   392
  The @{text "empty"} value acts as initial default for \emph{any}
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   393
  theory that does not declare actual data content; @{text "extend"}
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   394
  is acts like a unitary version of @{text "merge"}.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   395
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   396
  Implementing @{text "merge"} can be tricky.  The general idea is
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   397
  that @{text "merge (data\<^sub>1, data\<^sub>2)"} inserts those parts of @{text
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   398
  "data\<^sub>2"} into @{text "data\<^sub>1"} that are not yet present, while
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   399
  keeping the general order of things.  The @{ML Library.merge}
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   400
  function on plain lists may serve as canonical template.
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   401
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   402
  Particularly note that shared parts of the data must not be
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   403
  duplicated by naive concatenation, or a theory graph that is like a
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   404
  chain of diamonds would cause an exponential blowup!
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   405
33524
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   406
  \paragraph{Proof context data} declarations need to implement the
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   407
  following SML signature:
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   408
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   409
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   410
  \begin{tabular}{ll}
22869
9f915d44a666 simplified context data;
wenzelm
parents: 22438
diff changeset
   411
  @{text "\<type> T"} & representing type \\
9f915d44a666 simplified context data;
wenzelm
parents: 22438
diff changeset
   412
  @{text "\<val> init: theory \<rightarrow> T"} & produce initial value \\
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   413
  \end{tabular}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   414
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   415
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   416
  The @{text "init"} operation is supposed to produce a pure value
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   417
  from the given background theory and should be somehow
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   418
  ``immediate''.  Whenever a proof context is initialized, which
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   419
  happens frequently, the the system invokes the @{text "init"}
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   420
  operation of \emph{all} theory data slots ever declared.  This also
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   421
  means that one needs to be economic about the total number of proof
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   422
  data declarations in the system, i.e.\ each ML module should declare
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   423
  at most one, sometimes two data slots for its internal use.
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   424
  Repeated data declarations to simulate a record type should be
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   425
  avoided!
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   426
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   427
  \paragraph{Generic data} provides a hybrid interface for both theory
33524
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   428
  and proof data.  The @{text "init"} operation for proof contexts is
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   429
  predefined to select the current data value from the background
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   430
  theory.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   431
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   432
  \bigskip Any of the above data declarations over type @{text "T"}
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   433
  result in an ML structure with the following signature:
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   434
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   435
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   436
  \begin{tabular}{ll}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   437
  @{text "get: context \<rightarrow> T"} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   438
  @{text "put: T \<rightarrow> context \<rightarrow> context"} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   439
  @{text "map: (T \<rightarrow> T) \<rightarrow> context \<rightarrow> context"} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   440
  \end{tabular}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   441
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   442
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   443
  These other operations provide exclusive access for the particular
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   444
  kind of context (theory, proof, or generic context).  This interface
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   445
  observes the ML discipline for types and scopes: there is no other
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   446
  way to access the corresponding data slot of a context.  By keeping
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   447
  these operations private, an Isabelle/ML module may maintain
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   448
  abstract values authentically.  *}
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   449
20450
wenzelm
parents: 20449
diff changeset
   450
text %mlref {*
wenzelm
parents: 20449
diff changeset
   451
  \begin{mldecls}
33524
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   452
  @{index_ML_functor Theory_Data} \\
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   453
  @{index_ML_functor Proof_Data} \\
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   454
  @{index_ML_functor Generic_Data} \\
20450
wenzelm
parents: 20449
diff changeset
   455
  \end{mldecls}
wenzelm
parents: 20449
diff changeset
   456
wenzelm
parents: 20449
diff changeset
   457
  \begin{description}
wenzelm
parents: 20449
diff changeset
   458
33524
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   459
  \item @{ML_functor Theory_Data}@{text "(spec)"} declares data for
20450
wenzelm
parents: 20449
diff changeset
   460
  type @{ML_type theory} according to the specification provided as
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   461
  argument structure.  The resulting structure provides data init and
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   462
  access operations as described above.
20450
wenzelm
parents: 20449
diff changeset
   463
33524
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   464
  \item @{ML_functor Proof_Data}@{text "(spec)"} is analogous to
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   465
  @{ML_functor Theory_Data} for type @{ML_type Proof.context}.
20450
wenzelm
parents: 20449
diff changeset
   466
33524
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   467
  \item @{ML_functor Generic_Data}@{text "(spec)"} is analogous to
a08e6c1cbc04 updated functor Theory_Data, Proof_Data, Generic_Data;
wenzelm
parents: 33174
diff changeset
   468
  @{ML_functor Theory_Data} for type @{ML_type Context.generic}.
20450
wenzelm
parents: 20449
diff changeset
   469
wenzelm
parents: 20449
diff changeset
   470
  \end{description}
wenzelm
parents: 20449
diff changeset
   471
*}
wenzelm
parents: 20449
diff changeset
   472
34928
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   473
text %mlex {*
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   474
  The following artificial example demonstrates theory
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   475
  data: we maintain a set of terms that are supposed to be wellformed
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   476
  wrt.\ the enclosing theory.  The public interface is as follows:
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   477
*}
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   478
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   479
ML {*
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   480
  signature WELLFORMED_TERMS =
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   481
  sig
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   482
    val get: theory -> term list
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   483
    val add: term -> theory -> theory
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   484
  end;
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   485
*}
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   486
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   487
text {* The implementation uses private theory data internally, and
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   488
  only exposes an operation that involves explicit argument checking
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   489
  wrt.\ the given theory. *}
34928
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   490
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   491
ML {*
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   492
  structure Wellformed_Terms: WELLFORMED_TERMS =
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   493
  struct
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   494
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   495
  structure Terms = Theory_Data
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   496
  (
39687
4e9b6ada3a21 modernized structure Ord_List;
wenzelm
parents: 37533
diff changeset
   497
    type T = term Ord_List.T;
34928
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   498
    val empty = [];
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   499
    val extend = I;
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   500
    fun merge (ts1, ts2) =
39687
4e9b6ada3a21 modernized structure Ord_List;
wenzelm
parents: 37533
diff changeset
   501
      Ord_List.union Term_Ord.fast_term_ord ts1 ts2;
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   502
  );
34928
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   503
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   504
  val get = Terms.get;
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   505
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   506
  fun add raw_t thy =
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   507
    let
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   508
      val t = Sign.cert_term thy raw_t;
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   509
    in
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   510
      Terms.map (Ord_List.insert Term_Ord.fast_term_ord t) thy
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   511
    end;
34928
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   512
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   513
  end;
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   514
*}
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   515
39864
wenzelm
parents: 39863
diff changeset
   516
text {* Type @{ML_type "term Ord_List.T"} is used for reasonably
wenzelm
parents: 39863
diff changeset
   517
  efficient representation of a set of terms: all operations are
wenzelm
parents: 39863
diff changeset
   518
  linear in the number of stored elements.  Here we assume that users
wenzelm
parents: 39863
diff changeset
   519
  of this module do not care about the declaration order, since that
wenzelm
parents: 39863
diff changeset
   520
  data structure forces its own arrangement of elements.
34928
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   521
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   522
  Observe how the @{verbatim merge} operation joins the data slots of
39687
4e9b6ada3a21 modernized structure Ord_List;
wenzelm
parents: 37533
diff changeset
   523
  the two constituents: @{ML Ord_List.union} prevents duplication of
34928
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   524
  common data from different branches, thus avoiding the danger of
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   525
  exponential blowup.  Plain list append etc.\ must never be used for
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   526
  theory data merges!
34928
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   527
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   528
  \medskip Our intended invariant is achieved as follows:
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   529
  \begin{enumerate}
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   530
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   531
  \item @{ML Wellformed_Terms.add} only admits terms that have passed
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   532
  the @{ML Sign.cert_term} check of the given theory at that point.
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   533
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   534
  \item Wellformedness in the sense of @{ML Sign.cert_term} is
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   535
  monotonic wrt.\ the sub-theory relation.  So our data can move
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   536
  upwards in the hierarchy (via extension or merges), and maintain
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   537
  wellformedness without further checks.
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   538
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   539
  \end{enumerate}
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   540
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   541
  Note that all basic operations of the inference kernel (which
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   542
  includes @{ML Sign.cert_term}) observe this monotonicity principle,
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   543
  but other user-space tools don't.  For example, fully-featured
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   544
  type-inference via @{ML Syntax.check_term} (cf.\
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   545
  \secref{sec:term-check}) is not necessarily monotonic wrt.\ the
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   546
  background theory, since constraints of term constants can be
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   547
  modified by later declarations, for example.
34928
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   548
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   549
  In most cases, user-space context data does not have to take such
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   550
  invariants too seriously.  The situation is different in the
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   551
  implementation of the inference kernel itself, which uses the very
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   552
  same data mechanisms for types, constants, axioms etc.
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   553
*}
c4cd36411983 moved examples to proper place;
wenzelm
parents: 34927
diff changeset
   554
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20437
diff changeset
   555
39865
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   556
subsection {* Configuration options \label{sec:config-options} *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   557
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   558
text {* A \emph{configuration option} is a named optional value of
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   559
  some basic type (Boolean, integer, string) that is stored in the
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   560
  context.  It is a simple application of general context data
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   561
  (\secref{sec:context-data}) that is sufficiently common to justify
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   562
  customized setup, which includes some concrete declarations for
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   563
  end-users using existing notation for attributes (cf.\
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   564
  \secref{sec:attributes}).
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   565
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   566
  For example, the predefined configuration option @{attribute
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   567
  show_types} controls output of explicit type constraints for
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   568
  variables in printed terms (cf.\ \secref{sec:parse-print}).  Its
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   569
  value can be modified within Isar text like this:
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   570
*}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   571
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   572
declare [[show_types = false]]
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   573
  -- {* declaration within (local) theory context *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   574
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   575
example_proof
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   576
  note [[show_types = true]]
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   577
    -- {* declaration within proof (forward mode) *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   578
  term x
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   579
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   580
  have "x = x"
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   581
    using [[show_types = false]]
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   582
      -- {* declaration within proof (backward mode) *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   583
    ..
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   584
qed
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   585
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   586
text {* Configuration options that are not set explicitly hold a
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   587
  default value that can depend on the application context.  This
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   588
  allows to retrieve the value from another slot within the context,
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   589
  or fall back on a global preference mechanism, for example.
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   590
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   591
  The operations to declare configuration options and get/map their
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   592
  values are modeled as direct replacements for historic global
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   593
  references, only that the context is made explicit.  This allows
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   594
  easy configuration of tools, without relying on the execution order
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   595
  as required for old-style mutable references.  *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   596
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   597
text %mlref {*
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   598
  \begin{mldecls}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   599
  @{index_ML Config.get: "Proof.context -> 'a Config.T -> 'a"} \\
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   600
  @{index_ML Config.map: "'a Config.T -> ('a -> 'a) -> Proof.context -> Proof.context"} \\
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   601
  @{index_ML Attrib.config_bool: "string -> (Context.generic -> bool) ->
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   602
  bool Config.T * (theory -> theory)"} \\
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   603
  @{index_ML Attrib.config_int: "string -> (Context.generic -> int) ->
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   604
  int Config.T * (theory -> theory)"} \\
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   605
  @{index_ML Attrib.config_string: "string -> (Context.generic -> string) ->
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   606
  string Config.T * (theory -> theory)"} \\
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   607
  \end{mldecls}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   608
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   609
  \begin{description}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   610
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   611
  \item @{ML Config.get}~@{text "ctxt config"} gets the value of
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   612
  @{text "config"} in the given context.
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   613
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   614
  \item @{ML Config.map}~@{text "config f ctxt"} updates the context
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   615
  by updating the value of @{text "config"}.
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   616
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   617
  \item @{text "(config, setup) ="}~@{ML Attrib.config_bool}~@{text
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   618
  "name default"} creates a named configuration option of type
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   619
  @{ML_type bool}, with the given @{text "default"} depending on the
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   620
  application context.  The resulting @{text "config"} can be used to
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   621
  get/map its value in a given context.  The @{text "setup"} function
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   622
  needs to be applied to the theory initially, in order to make
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   623
  concrete declaration syntax available to the user.
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   624
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   625
  \item @{ML Attrib.config_int} and @{ML Attrib.config_string} work
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   626
  like @{ML Attrib.config_bool}, but for types @{ML_type int} and
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   627
  @{ML_type string}, respectively.
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   628
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   629
  \end{description}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   630
*}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   631
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   632
text %mlex {* The following example shows how to declare and use a
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   633
  Boolean configuration option called @{text "my_flag"} with constant
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   634
  default value @{ML false}.  *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   635
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   636
ML {*
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   637
  val (my_flag, my_flag_setup) =
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   638
    Attrib.config_bool "my_flag" (K false)
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   639
*}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   640
setup my_flag_setup
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   641
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   642
text {* Now the user can refer to @{attribute my_flag} in
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   643
  declarations, while we can retrieve the current value from the
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   644
  context via @{ML Config.get}.  *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   645
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   646
ML_val {* Config.get @{context} my_flag *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   647
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   648
declare [[my_flag = true]]
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   649
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   650
ML_val {* Config.get @{context} my_flag *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   651
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   652
example_proof
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   653
  note [[my_flag = false]]
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   654
  ML_val {* Config.get @{context} my_flag *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   655
qed
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   656
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   657
ML_val {* Config.get @{context} my_flag *}
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   658
a724b90f951e more on "Configuration options";
wenzelm
parents: 39864
diff changeset
   659
26872
336dfd860744 fixed some labels;
wenzelm
parents: 26864
diff changeset
   660
section {* Names \label{sec:names} *}
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   661
34925
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   662
text {* In principle, a name is just a string, but there are various
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   663
  conventions for representing additional structure.  For example,
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   664
  ``@{text "Foo.bar.baz"}'' is considered as a long name consisting of
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   665
  qualifier @{text "Foo.bar"} and base name @{text "baz"}.  The
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   666
  individual constituents of a name may have further substructure,
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   667
  e.g.\ the string ``\verb,\,\verb,<alpha>,'' encodes as a single
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   668
  symbol.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   669
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   670
  \medskip Subsequently, we shall introduce specific categories of
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   671
  names.  Roughly speaking these correspond to logical entities as
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   672
  follows:
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   673
  \begin{itemize}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   674
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   675
  \item Basic names (\secref{sec:basic-name}): free and bound
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   676
  variables.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   677
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   678
  \item Indexed names (\secref{sec:indexname}): schematic variables.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   679
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   680
  \item Long names (\secref{sec:long-name}): constants of any kind
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   681
  (type constructors, term constants, other concepts defined in user
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   682
  space).  Such entities are typically managed via name spaces
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   683
  (\secref{sec:name-space}).
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   684
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   685
  \end{itemize}
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   686
*}
20437
wenzelm
parents: 20430
diff changeset
   687
wenzelm
parents: 20430
diff changeset
   688
39863
c0de5386017e more on "Basic data types";
wenzelm
parents: 39861
diff changeset
   689
subsection {* Strings of symbols \label{sec:symbols} *}
20437
wenzelm
parents: 20430
diff changeset
   690
34925
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   691
text {* A \emph{symbol} constitutes the smallest textual unit in
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   692
  Isabelle --- raw ML characters are normally not encountered at all!
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   693
  Isabelle strings consist of a sequence of symbols, represented as a
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   694
  packed string or an exploded list of strings.  Each symbol is in
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   695
  itself a small string, which has either one of the following forms:
20437
wenzelm
parents: 20430
diff changeset
   696
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   697
  \begin{enumerate}
20437
wenzelm
parents: 20430
diff changeset
   698
37533
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   699
  \item a single ASCII character ``@{text "c"}'', for example
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   700
  ``\verb,a,'',
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   701
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   702
  \item a codepoint according to UTF8 (non-ASCII byte sequence),
20437
wenzelm
parents: 20430
diff changeset
   703
20488
wenzelm
parents: 20479
diff changeset
   704
  \item a regular symbol ``\verb,\,\verb,<,@{text "ident"}\verb,>,'',
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   705
  for example ``\verb,\,\verb,<alpha>,'',
20437
wenzelm
parents: 20430
diff changeset
   706
20488
wenzelm
parents: 20479
diff changeset
   707
  \item a control symbol ``\verb,\,\verb,<^,@{text "ident"}\verb,>,'',
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   708
  for example ``\verb,\,\verb,<^bold>,'',
20437
wenzelm
parents: 20430
diff changeset
   709
20488
wenzelm
parents: 20479
diff changeset
   710
  \item a raw symbol ``\verb,\,\verb,<^raw:,@{text text}\verb,>,''
34925
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   711
  where @{text text} consists of printable characters excluding
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   712
  ``\verb,.,'' and ``\verb,>,'', for example
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   713
  ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
20437
wenzelm
parents: 20430
diff changeset
   714
20488
wenzelm
parents: 20479
diff changeset
   715
  \item a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   716
  n}\verb,>, where @{text n} consists of digits, for example
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   717
  ``\verb,\,\verb,<^raw42>,''.
20437
wenzelm
parents: 20430
diff changeset
   718
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   719
  \end{enumerate}
20437
wenzelm
parents: 20430
diff changeset
   720
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   721
  The @{text "ident"} syntax for symbol names is @{text "letter
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   722
  (letter | digit)\<^sup>*"}, where @{text "letter = A..Za..z"} and @{text
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   723
  "digit = 0..9"}.  There are infinitely many regular symbols and
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   724
  control symbols, but a fixed collection of standard symbols is
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   725
  treated specifically.  For example, ``\verb,\,\verb,<alpha>,'' is
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   726
  classified as a letter, which means it may occur within regular
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   727
  Isabelle identifiers.
20437
wenzelm
parents: 20430
diff changeset
   728
37533
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   729
  The character set underlying Isabelle symbols is 7-bit ASCII, but
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   730
  8-bit character sequences are passed-through unchanged.  Unicode/UCS
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   731
  data in UTF-8 encoding is processed in a non-strict fashion, such
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   732
  that well-formed code sequences are recognized
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   733
  accordingly.\footnote{Note that ISO-Latin-1 differs from UTF-8 only
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   734
  in some special punctuation characters that even have replacements
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   735
  within the standard collection of Isabelle symbols.  Text consisting
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   736
  of ASCII plus accented letters can be processed in either encoding.}
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   737
  Unicode provides its own collection of mathematical symbols, but
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   738
  within the core Isabelle/ML world there is no link to the standard
d775bd70f571 explicit treatment of UTF8 character sequences as Isabelle symbols;
wenzelm
parents: 36611
diff changeset
   739
  collection of Isabelle regular symbols.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   740
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   741
  \medskip Output of Isabelle symbols depends on the print mode
29758
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
   742
  (\secref{print-mode}).  For example, the standard {\LaTeX} setup of
7a3b5bbed313 removed rudiments of glossary;
wenzelm
parents: 29755
diff changeset
   743
  the Isabelle document preparation system would present
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   744
  ``\verb,\,\verb,<alpha>,'' as @{text "\<alpha>"}, and
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   745
  ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text
34925
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   746
  "\<^bold>\<alpha>"}.  On-screen rendering usually works by mapping a finite
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   747
  subset of Isabelle symbols to suitable Unicode characters.
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   748
*}
20437
wenzelm
parents: 20430
diff changeset
   749
wenzelm
parents: 20430
diff changeset
   750
text %mlref {*
wenzelm
parents: 20430
diff changeset
   751
  \begin{mldecls}
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   752
  @{index_ML_type "Symbol.symbol": string} \\
20437
wenzelm
parents: 20430
diff changeset
   753
  @{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\
wenzelm
parents: 20430
diff changeset
   754
  @{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\
wenzelm
parents: 20430
diff changeset
   755
  @{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\
wenzelm
parents: 20430
diff changeset
   756
  @{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\
20547
wenzelm
parents: 20530
diff changeset
   757
  @{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\
wenzelm
parents: 20530
diff changeset
   758
  \end{mldecls}
wenzelm
parents: 20530
diff changeset
   759
  \begin{mldecls}
20437
wenzelm
parents: 20430
diff changeset
   760
  @{index_ML_type "Symbol.sym"} \\
wenzelm
parents: 20430
diff changeset
   761
  @{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\
wenzelm
parents: 20430
diff changeset
   762
  \end{mldecls}
wenzelm
parents: 20430
diff changeset
   763
wenzelm
parents: 20430
diff changeset
   764
  \begin{description}
wenzelm
parents: 20430
diff changeset
   765
39864
wenzelm
parents: 39863
diff changeset
   766
  \item Type @{ML_type "Symbol.symbol"} represents individual Isabelle
34921
008126f730a0 formal markup of type aliases;
wenzelm
parents: 33524
diff changeset
   767
  symbols.
20437
wenzelm
parents: 20430
diff changeset
   768
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   769
  \item @{ML "Symbol.explode"}~@{text "str"} produces a symbol list
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   770
  from the packed form.  This function supersedes @{ML
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   771
  "String.explode"} for virtually all purposes of manipulating text in
34925
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   772
  Isabelle!\footnote{The runtime overhead for exploded strings is
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   773
  mainly that of the list structure: individual symbols that happen to
39821
bf164c153d10 minor tuning and updating;
wenzelm
parents: 39687
diff changeset
   774
  be a singleton string do not require extra memory in Poly/ML.}
20437
wenzelm
parents: 20430
diff changeset
   775
wenzelm
parents: 20430
diff changeset
   776
  \item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   777
  "Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify standard
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   778
  symbols according to fixed syntactic conventions of Isabelle, cf.\
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   779
  \cite{isabelle-isar-ref}.
20437
wenzelm
parents: 20430
diff changeset
   780
39864
wenzelm
parents: 39863
diff changeset
   781
  \item Type @{ML_type "Symbol.sym"} is a concrete datatype that
wenzelm
parents: 39863
diff changeset
   782
  represents the different kinds of symbols explicitly, with
wenzelm
parents: 39863
diff changeset
   783
  constructors @{ML "Symbol.Char"}, @{ML "Symbol.Sym"}, @{ML
wenzelm
parents: 39863
diff changeset
   784
  "Symbol.UTF8"}, @{ML "Symbol.Ctrl"}, @{ML "Symbol.Raw"}.
20437
wenzelm
parents: 20430
diff changeset
   785
wenzelm
parents: 20430
diff changeset
   786
  \item @{ML "Symbol.decode"} converts the string representation of a
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   787
  symbol into the datatype version.
20437
wenzelm
parents: 20430
diff changeset
   788
wenzelm
parents: 20430
diff changeset
   789
  \end{description}
34925
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   790
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   791
  \paragraph{Historical note.} In the original SML90 standard the
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   792
  primitive ML type @{ML_type char} did not exists, and the basic @{ML
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   793
  "explode: string -> string list"} operation would produce a list of
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   794
  singleton strings as in Isabelle/ML today.  When SML97 came out,
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   795
  Isabelle did not adopt its slightly anachronistic 8-bit characters,
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   796
  but the idea of exploding a string into a list of small strings was
34925
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   797
  extended to ``symbols'' as explained above.  Thus Isabelle sources
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   798
  can refer to an infinite store of user-defined symbols, without
38a44d813a3c more details on Isabelle symbols;
wenzelm
parents: 34924
diff changeset
   799
  having to worry about the multitude of Unicode encodings.
20437
wenzelm
parents: 20430
diff changeset
   800
*}
wenzelm
parents: 20430
diff changeset
   801
wenzelm
parents: 20430
diff changeset
   802
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   803
subsection {* Basic names \label{sec:basic-name} *}
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   804
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   805
text {*
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   806
  A \emph{basic name} essentially consists of a single Isabelle
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   807
  identifier.  There are conventions to mark separate classes of basic
29761
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
   808
  names, by attaching a suffix of underscores: one underscore means
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
   809
  \emph{internal name}, two underscores means \emph{Skolem name},
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
   810
  three underscores means \emph{internal Skolem name}.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   811
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   812
  For example, the basic name @{text "foo"} has the internal version
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   813
  @{text "foo_"}, with Skolem versions @{text "foo__"} and @{text
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   814
  "foo___"}, respectively.
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   815
20488
wenzelm
parents: 20479
diff changeset
   816
  These special versions provide copies of the basic name space, apart
wenzelm
parents: 20479
diff changeset
   817
  from anything that normally appears in the user text.  For example,
wenzelm
parents: 20479
diff changeset
   818
  system generated variables in Isar proof contexts are usually marked
34926
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   819
  as internal, which prevents mysterious names like @{text "xaa"} to
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   820
  appear in human-readable text.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   821
20488
wenzelm
parents: 20479
diff changeset
   822
  \medskip Manipulating binding scopes often requires on-the-fly
wenzelm
parents: 20479
diff changeset
   823
  renamings.  A \emph{name context} contains a collection of already
wenzelm
parents: 20479
diff changeset
   824
  used names.  The @{text "declare"} operation adds names to the
wenzelm
parents: 20479
diff changeset
   825
  context.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   826
20488
wenzelm
parents: 20479
diff changeset
   827
  The @{text "invents"} operation derives a number of fresh names from
wenzelm
parents: 20479
diff changeset
   828
  a given starting point.  For example, the first three names derived
wenzelm
parents: 20479
diff changeset
   829
  from @{text "a"} are @{text "a"}, @{text "b"}, @{text "c"}.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   830
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   831
  The @{text "variants"} operation produces fresh names by
20488
wenzelm
parents: 20479
diff changeset
   832
  incrementing tentative names as base-26 numbers (with digits @{text
wenzelm
parents: 20479
diff changeset
   833
  "a..z"}) until all clashes are resolved.  For example, name @{text
wenzelm
parents: 20479
diff changeset
   834
  "foo"} results in variants @{text "fooa"}, @{text "foob"}, @{text
wenzelm
parents: 20479
diff changeset
   835
  "fooc"}, \dots, @{text "fooaa"}, @{text "fooab"} etc.; each renaming
wenzelm
parents: 20479
diff changeset
   836
  step picks the next unused variant from this sequence.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   837
*}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   838
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   839
text %mlref {*
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   840
  \begin{mldecls}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   841
  @{index_ML Name.internal: "string -> string"} \\
20547
wenzelm
parents: 20530
diff changeset
   842
  @{index_ML Name.skolem: "string -> string"} \\
wenzelm
parents: 20530
diff changeset
   843
  \end{mldecls}
wenzelm
parents: 20530
diff changeset
   844
  \begin{mldecls}
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   845
  @{index_ML_type Name.context} \\
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   846
  @{index_ML Name.context: Name.context} \\
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   847
  @{index_ML Name.declare: "string -> Name.context -> Name.context"} \\
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   848
  @{index_ML Name.invents: "Name.context -> string -> int -> string list"} \\
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   849
  @{index_ML Name.variants: "string list -> Name.context -> string list * Name.context"} \\
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   850
  \end{mldecls}
34926
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   851
  \begin{mldecls}
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   852
  @{index_ML Variable.names_of: "Proof.context -> Name.context"} \\
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   853
  \end{mldecls}
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   854
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   855
  \begin{description}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   856
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   857
  \item @{ML Name.internal}~@{text "name"} produces an internal name
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   858
  by adding one underscore.
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   859
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   860
  \item @{ML Name.skolem}~@{text "name"} produces a Skolem name by
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   861
  adding two underscores.
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   862
39864
wenzelm
parents: 39863
diff changeset
   863
  \item Type @{ML_type Name.context} represents the context of already
wenzelm
parents: 39863
diff changeset
   864
  used names; the initial value is @{ML "Name.context"}.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   865
20488
wenzelm
parents: 20479
diff changeset
   866
  \item @{ML Name.declare}~@{text "name"} enters a used name into the
wenzelm
parents: 20479
diff changeset
   867
  context.
20437
wenzelm
parents: 20430
diff changeset
   868
20488
wenzelm
parents: 20479
diff changeset
   869
  \item @{ML Name.invents}~@{text "context name n"} produces @{text
wenzelm
parents: 20479
diff changeset
   870
  "n"} fresh names derived from @{text "name"}.
wenzelm
parents: 20479
diff changeset
   871
wenzelm
parents: 20479
diff changeset
   872
  \item @{ML Name.variants}~@{text "names context"} produces fresh
29761
2b658e50683a minor tuning and typographic fixes;
wenzelm
parents: 29758
diff changeset
   873
  variants of @{text "names"}; the result is entered into the context.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   874
34926
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   875
  \item @{ML Variable.names_of}~@{text "ctxt"} retrieves the context
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   876
  of declared type and term variable names.  Projecting a proof
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   877
  context down to a primitive name context is occasionally useful when
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   878
  invoking lower-level operations.  Regular management of ``fresh
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   879
  variables'' is done by suitable operations of structure @{ML_struct
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   880
  Variable}, which is also able to provide an official status of
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   881
  ``locally fixed variable'' within the logical environment (cf.\
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   882
  \secref{sec:variables}).
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   883
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   884
  \end{description}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   885
*}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   886
39857
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   887
text %mlex {* The following simple examples demonstrate how to produce
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   888
  fresh names from the initial @{ML Name.context}. *}
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   889
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   890
ML {*
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   891
  Name.invents Name.context "a" 5;
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   892
  #1 (Name.variants ["x", "x", "a", "a", "'a", "'a"] Name.context);
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   893
*}
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   894
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   895
text {* \medskip The same works reletively to the formal context as
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   896
  follows. *}
39857
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   897
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   898
locale ex = fixes a b c :: 'a
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   899
begin
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   900
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   901
ML {*
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   902
  val names = Variable.names_of @{context};
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   903
  Name.invents names "a" 5;
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   904
  #1 (Name.variants ["x", "x", "a", "a", "'a", "'a"] names);
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   905
*}
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   906
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   907
end
ea93e088398d more examples;
wenzelm
parents: 39846
diff changeset
   908
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   909
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   910
subsection {* Indexed names \label{sec:indexname} *}
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   911
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   912
text {*
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   913
  An \emph{indexed name} (or @{text "indexname"}) is a pair of a basic
20488
wenzelm
parents: 20479
diff changeset
   914
  name and a natural number.  This representation allows efficient
wenzelm
parents: 20479
diff changeset
   915
  renaming by incrementing the second component only.  The canonical
wenzelm
parents: 20479
diff changeset
   916
  way to rename two collections of indexnames apart from each other is
wenzelm
parents: 20479
diff changeset
   917
  this: determine the maximum index @{text "maxidx"} of the first
wenzelm
parents: 20479
diff changeset
   918
  collection, then increment all indexes of the second collection by
wenzelm
parents: 20479
diff changeset
   919
  @{text "maxidx + 1"}; the maximum index of an empty collection is
wenzelm
parents: 20479
diff changeset
   920
  @{text "-1"}.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   921
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   922
  Occasionally, basic names are injected into the same pair type of
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   923
  indexed names: then @{text "(x, -1)"} is used to encode the basic
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   924
  name @{text "x"}.
20488
wenzelm
parents: 20479
diff changeset
   925
wenzelm
parents: 20479
diff changeset
   926
  \medskip Isabelle syntax observes the following rules for
wenzelm
parents: 20479
diff changeset
   927
  representing an indexname @{text "(x, i)"} as a packed string:
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   928
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   929
  \begin{itemize}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   930
20479
wenzelm
parents: 20476
diff changeset
   931
  \item @{text "?x"} if @{text "x"} does not end with a digit and @{text "i = 0"},
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   932
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   933
  \item @{text "?xi"} if @{text "x"} does not end with a digit,
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   934
20488
wenzelm
parents: 20479
diff changeset
   935
  \item @{text "?x.i"} otherwise.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   936
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   937
  \end{itemize}
20470
c839b38a1f32 more on variables;
wenzelm
parents: 20452
diff changeset
   938
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   939
  Indexnames may acquire large index numbers after several maxidx
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   940
  shifts have been applied.  Results are usually normalized towards
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   941
  @{text "0"} at certain checkpoints, notably at the end of a proof.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   942
  This works by producing variants of the corresponding basic name
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   943
  components.  For example, the collection @{text "?x1, ?x7, ?x42"}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   944
  becomes @{text "?x, ?xa, ?xb"}.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   945
*}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   946
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   947
text %mlref {*
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   948
  \begin{mldecls}
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
   949
  @{index_ML_type indexname: "string * int"} \\
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   950
  \end{mldecls}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   951
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   952
  \begin{description}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   953
39864
wenzelm
parents: 39863
diff changeset
   954
  \item Type @{ML_type indexname} represents indexed names.  This is
wenzelm
parents: 39863
diff changeset
   955
  an abbreviation for @{ML_type "string * int"}.  The second component
wenzelm
parents: 39863
diff changeset
   956
  is usually non-negative, except for situations where @{text "(x,
wenzelm
parents: 39863
diff changeset
   957
  -1)"} is used to inject basic names into this type.  Other negative
34926
19294b07e445 Variable.names_of;
wenzelm
parents: 34925
diff changeset
   958
  indexes should not be used.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   959
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   960
  \end{description}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   961
*}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   962
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   963
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   964
subsection {* Long names \label{sec:long-name} *}
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   965
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   966
text {* A \emph{long name} consists of a sequence of non-empty name
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   967
  components.  The packed representation uses a dot as separator, as
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   968
  in ``@{text "A.b.c"}''.  The last component is called \emph{base
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   969
  name}, the remaining prefix is called \emph{qualifier} (which may be
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   970
  empty).  The qualifier can be understood as the access path to the
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   971
  named entity while passing through some nested block-structure,
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   972
  although our free-form long names do not really enforce any strict
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   973
  discipline.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   974
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   975
  For example, an item named ``@{text "A.b.c"}'' may be understood as
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   976
  a local entity @{text "c"}, within a local structure @{text "b"},
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   977
  within a global structure @{text "A"}.  In practice, long names
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   978
  usually represent 1--3 levels of qualification.  User ML code should
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   979
  not make any assumptions about the particular structure of long
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   980
  names!
20437
wenzelm
parents: 20430
diff changeset
   981
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   982
  The empty name is commonly used as an indication of unnamed
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   983
  entities, or entities that are not entered into the corresponding
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   984
  name space, whenever this makes any sense.  The basic operations on
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   985
  long names map empty names again to empty names.
20437
wenzelm
parents: 20430
diff changeset
   986
*}
wenzelm
parents: 20430
diff changeset
   987
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   988
text %mlref {*
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
   989
  \begin{mldecls}
30365
790129514c2d adapted to structure Long_Name;
wenzelm
parents: 30281
diff changeset
   990
  @{index_ML Long_Name.base_name: "string -> string"} \\
790129514c2d adapted to structure Long_Name;
wenzelm
parents: 30281
diff changeset
   991
  @{index_ML Long_Name.qualifier: "string -> string"} \\
790129514c2d adapted to structure Long_Name;
wenzelm
parents: 30281
diff changeset
   992
  @{index_ML Long_Name.append: "string -> string -> string"} \\
790129514c2d adapted to structure Long_Name;
wenzelm
parents: 30281
diff changeset
   993
  @{index_ML Long_Name.implode: "string list -> string"} \\
790129514c2d adapted to structure Long_Name;
wenzelm
parents: 30281
diff changeset
   994
  @{index_ML Long_Name.explode: "string -> string list"} \\
20547
wenzelm
parents: 20530
diff changeset
   995
  \end{mldecls}
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   996
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   997
  \begin{description}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   998
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
   999
  \item @{ML Long_Name.base_name}~@{text "name"} returns the base name
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1000
  of a long name.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1001
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1002
  \item @{ML Long_Name.qualifier}~@{text "name"} returns the qualifier
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1003
  of a long name.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1004
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1005
  \item @{ML Long_Name.append}~@{text "name\<^isub>1 name\<^isub>2"} appends two long
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1006
  names.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1007
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1008
  \item @{ML Long_Name.implode}~@{text "names"} and @{ML
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1009
  Long_Name.explode}~@{text "name"} convert between the packed string
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1010
  representation and the explicit list form of long names.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1011
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1012
  \end{description}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1013
*}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1014
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1015
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1016
subsection {* Name spaces \label{sec:name-space} *}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1017
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1018
text {* A @{text "name space"} manages a collection of long names,
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1019
  together with a mapping between partially qualified external names
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1020
  and fully qualified internal names (in both directions).  Note that
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1021
  the corresponding @{text "intern"} and @{text "extern"} operations
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1022
  are mostly used for parsing and printing only!  The @{text
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1023
  "declare"} operation augments a name space according to the accesses
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1024
  determined by a given binding, and a naming policy from the context.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1025
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1026
  \medskip A @{text "binding"} specifies details about the prospective
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1027
  long name of a newly introduced formal entity.  It consists of a
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1028
  base name, prefixes for qualification (separate ones for system
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1029
  infrastructure and user-space mechanisms), a slot for the original
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1030
  source position, and some additional flags.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1031
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1032
  \medskip A @{text "naming"} provides some additional details for
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1033
  producing a long name from a binding.  Normally, the naming is
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1034
  implicit in the theory or proof context.  The @{text "full"}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1035
  operation (and its variants for different context types) produces a
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1036
  fully qualified internal name to be entered into a name space.  The
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1037
  main equation of this ``chemical reaction'' when binding new
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1038
  entities in a context is as follows:
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1039
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
  1040
  \medskip
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1041
  \begin{tabular}{l}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1042
  @{text "binding + naming \<longrightarrow> long name + name space accesses"}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1043
  \end{tabular}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1044
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
  1045
  \bigskip As a general principle, there is a separate name space for
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1046
  each kind of formal entity, e.g.\ fact, logical constant, type
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1047
  constructor, type class.  It is usually clear from the occurrence in
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1048
  concrete syntax (or from the scope) which kind of entity a name
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1049
  refers to.  For example, the very same name @{text "c"} may be used
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1050
  uniformly for a constant, type constructor, and type class.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1051
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1052
  There are common schemes to name derived entities systematically
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1053
  according to the name of the main logical entity involved, e.g.\
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1054
  fact @{text "c.intro"} for a canonical introduction rule related to
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1055
  constant @{text "c"}.  This technique of mapping names from one
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1056
  space into another requires some care in order to avoid conflicts.
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1057
  In particular, theorem names derived from a type constructor or type
39839
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1058
  class should get an additional suffix in addition to the usual
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1059
  qualification.  This leads to the following conventions for derived
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1060
  names:
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1061
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1062
  \medskip
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1063
  \begin{tabular}{ll}
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1064
  logical entity & fact name \\\hline
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1065
  constant @{text "c"} & @{text "c.intro"} \\
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1066
  type @{text "c"} & @{text "c_type.intro"} \\
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1067
  class @{text "c"} & @{text "c_class.intro"} \\
08f59175e541 misc tuning;
wenzelm
parents: 39837
diff changeset
  1068
  \end{tabular}
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1069
*}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1070
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1071
text %mlref {*
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1072
  \begin{mldecls}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1073
  @{index_ML_type binding} \\
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1074
  @{index_ML Binding.empty: binding} \\
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1075
  @{index_ML Binding.name: "string -> binding"} \\
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1076
  @{index_ML Binding.qualify: "bool -> string -> binding -> binding"} \\
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1077
  @{index_ML Binding.prefix: "bool -> string -> binding -> binding"} \\
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1078
  @{index_ML Binding.conceal: "binding -> binding"} \\
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1079
  @{index_ML Binding.str_of: "binding -> string"} \\
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1080
  \end{mldecls}
20547
wenzelm
parents: 20530
diff changeset
  1081
  \begin{mldecls}
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1082
  @{index_ML_type Name_Space.naming} \\
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1083
  @{index_ML Name_Space.default_naming: Name_Space.naming} \\
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1084
  @{index_ML Name_Space.add_path: "string -> Name_Space.naming -> Name_Space.naming"} \\
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1085
  @{index_ML Name_Space.full_name: "Name_Space.naming -> binding -> string"} \\
20547
wenzelm
parents: 20530
diff changeset
  1086
  \end{mldecls}
wenzelm
parents: 20530
diff changeset
  1087
  \begin{mldecls}
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1088
  @{index_ML_type Name_Space.T} \\
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1089
  @{index_ML Name_Space.empty: "string -> Name_Space.T"} \\
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1090
  @{index_ML Name_Space.merge: "Name_Space.T * Name_Space.T -> Name_Space.T"} \\
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1091
  @{index_ML Name_Space.declare: "bool -> Name_Space.naming -> binding -> Name_Space.T ->
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1092
  string * Name_Space.T"} \\
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1093
  @{index_ML Name_Space.intern: "Name_Space.T -> string -> string"} \\
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1094
  @{index_ML Name_Space.extern: "Name_Space.T -> string -> string"} \\
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1095
  @{index_ML Name_Space.is_concealed: "Name_Space.T -> string -> bool"}
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1096
  \end{mldecls}
20437
wenzelm
parents: 20430
diff changeset
  1097
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1098
  \begin{description}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1099
39864
wenzelm
parents: 39863
diff changeset
  1100
  \item Type @{ML_type binding} represents the abstract concept of
wenzelm
parents: 39863
diff changeset
  1101
  name bindings.
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1102
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1103
  \item @{ML Binding.empty} is the empty binding.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1104
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1105
  \item @{ML Binding.name}~@{text "name"} produces a binding with base
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1106
  name @{text "name"}.  Note that this lacks proper source position
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1107
  information; see also the ML antiquotation @{ML_antiquotation
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1108
  binding}.
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1109
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1110
  \item @{ML Binding.qualify}~@{text "mandatory name binding"}
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1111
  prefixes qualifier @{text "name"} to @{text "binding"}.  The @{text
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1112
  "mandatory"} flag tells if this name component always needs to be
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1113
  given in name space accesses --- this is mostly @{text "false"} in
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1114
  practice.  Note that this part of qualification is typically used in
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1115
  derived specification mechanisms.
20437
wenzelm
parents: 20430
diff changeset
  1116
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1117
  \item @{ML Binding.prefix} is similar to @{ML Binding.qualify}, but
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1118
  affects the system prefix.  This part of extra qualification is
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1119
  typically used in the infrastructure for modular specifications,
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1120
  notably ``local theory targets'' (see also \chref{ch:local-theory}).
20437
wenzelm
parents: 20430
diff changeset
  1121
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1122
  \item @{ML Binding.conceal}~@{text "binding"} indicates that the
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1123
  binding shall refer to an entity that serves foundational purposes
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1124
  only.  This flag helps to mark implementation details of
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1125
  specification mechanism etc.  Other tools should not depend on the
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1126
  particulars of concealed entities (cf.\ @{ML
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1127
  Name_Space.is_concealed}).
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1128
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1129
  \item @{ML Binding.str_of}~@{text "binding"} produces a string
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1130
  representation for human-readable output, together with some formal
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1131
  markup that might get used in GUI front-ends, for example.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1132
39864
wenzelm
parents: 39863
diff changeset
  1133
  \item Type @{ML_type Name_Space.naming} represents the abstract
wenzelm
parents: 39863
diff changeset
  1134
  concept of a naming policy.
20437
wenzelm
parents: 20430
diff changeset
  1135
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1136
  \item @{ML Name_Space.default_naming} is the default naming policy.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1137
  In a theory context, this is usually augmented by a path prefix
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1138
  consisting of the theory name.
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1139
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1140
  \item @{ML Name_Space.add_path}~@{text "path naming"} augments the
20488
wenzelm
parents: 20479
diff changeset
  1141
  naming policy by extending its path component.
20437
wenzelm
parents: 20430
diff changeset
  1142
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1143
  \item @{ML Name_Space.full_name}~@{text "naming binding"} turns a
30281
9ad15d8ed311 renamed NameSpace.base to NameSpace.base_name (in accordance with "full_name");
wenzelm
parents: 30272
diff changeset
  1144
  name binding (usually a basic name) into the fully qualified
29008
d863c103ded0 adapted to changes in binding module
haftmann
parents: 26872
diff changeset
  1145
  internal name, according to the given naming policy.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1146
39864
wenzelm
parents: 39863
diff changeset
  1147
  \item Type @{ML_type Name_Space.T} represents name spaces.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1148
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1149
  \item @{ML Name_Space.empty}~@{text "kind"} and @{ML Name_Space.merge}~@{text
20488
wenzelm
parents: 20479
diff changeset
  1150
  "(space\<^isub>1, space\<^isub>2)"} are the canonical operations for
wenzelm
parents: 20479
diff changeset
  1151
  maintaining name spaces according to theory data management
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1152
  (\secref{sec:context-data}); @{text "kind"} is a formal comment
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1153
  to characterize the purpose of a name space.
20437
wenzelm
parents: 20430
diff changeset
  1154
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1155
  \item @{ML Name_Space.declare}~@{text "strict naming bindings
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1156
  space"} enters a name binding as fully qualified internal name into
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1157
  the name space, with external accesses determined by the naming
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1158
  policy.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1159
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1160
  \item @{ML Name_Space.intern}~@{text "space name"} internalizes a
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1161
  (partially qualified) external name.
20437
wenzelm
parents: 20430
diff changeset
  1162
20488
wenzelm
parents: 20479
diff changeset
  1163
  This operation is mostly for parsing!  Note that fully qualified
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1164
  names stemming from declarations are produced via @{ML
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1165
  "Name_Space.full_name"} and @{ML "Name_Space.declare"}
29008
d863c103ded0 adapted to changes in binding module
haftmann
parents: 26872
diff changeset
  1166
  (or their derivatives for @{ML_type theory} and
20488
wenzelm
parents: 20479
diff changeset
  1167
  @{ML_type Proof.context}).
20437
wenzelm
parents: 20430
diff changeset
  1168
33174
1f2051f41335 adjusted to changes in corresponding ML code
haftmann
parents: 30365
diff changeset
  1169
  \item @{ML Name_Space.extern}~@{text "space name"} externalizes a
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1170
  (fully qualified) internal name.
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1171
30281
9ad15d8ed311 renamed NameSpace.base to NameSpace.base_name (in accordance with "full_name");
wenzelm
parents: 30272
diff changeset
  1172
  This operation is mostly for printing!  User code should not rely on
9ad15d8ed311 renamed NameSpace.base to NameSpace.base_name (in accordance with "full_name");
wenzelm
parents: 30272
diff changeset
  1173
  the precise result too much.
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1174
34927
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1175
  \item @{ML Name_Space.is_concealed}~@{text "space name"} indicates
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1176
  whether @{text "name"} refers to a strictly private entity that
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1177
  other tools are supposed to ignore!
c4c02ac736a6 more details on long names, binding/naming, name space;
wenzelm
parents: 34926
diff changeset
  1178
20476
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1179
  \end{description}
6d3f144cc1bd more on names;
wenzelm
parents: 20475
diff changeset
  1180
*}
30272
2d612824e642 regenerated document;
wenzelm
parents: 30270
diff changeset
  1181
39832
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1182
text %mlantiq {*
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1183
  \begin{matharray}{rcl}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1184
  @{ML_antiquotation_def "binding"} & : & @{text ML_antiquotation} \\
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1185
  \end{matharray}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1186
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1187
  \begin{rail}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1188
  'binding' name
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1189
  ;
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1190
  \end{rail}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1191
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1192
  \begin{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1193
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1194
  \item @{text "@{binding name}"} produces a binding with base name
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1195
  @{text "name"} and the source position taken from the concrete
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1196
  syntax of this antiquotation.  In many situations this is more
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1197
  appropriate than the more basic @{ML Binding.name} function.
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1198
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1199
  \end{description}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1200
*}
1080dee73a53 various concrete ML antiquotations;
wenzelm
parents: 39825
diff changeset
  1201
39833
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1202
text %mlex {* The following example yields the source position of some
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1203
  concrete binding inlined into the text.
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1204
*}
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1205
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1206
ML {* Binding.pos_of @{binding here} *}
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1207
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
  1208
text {* \medskip That position can be also printed in a message as
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
  1209
  follows. *}
39833
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1210
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1211
ML_command {*
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1212
  writeln
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1213
    ("Look here" ^ Position.str_of (Binding.pos_of @{binding here}))
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1214
*}
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1215
39861
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
  1216
text {* This illustrates a key virtue of formalized bindings as
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
  1217
  opposed to raw specifications of base names: the system can use this
b8d89db3e238 use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents: 39857
diff changeset
  1218
  additional information for advanced feedback given to the user. *}
39833
6d54a48c859d more examples;
wenzelm
parents: 39832
diff changeset
  1219
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
  1220
end