doc-src/IsarRef/Thy/pure.thy
author wenzelm
Wed, 14 May 2008 20:31:17 +0200
changeset 26894 1120f6cc10b0
parent 26870 94bedbb34b92
child 26957 e3f04fdd994d
permissions -rw-r--r--
proper checking of various Isar elements;
wenzelm@26767
     1
(* $Id$ *)
wenzelm@26767
     2
wenzelm@26767
     3
theory pure
wenzelm@26767
     4
imports CPure
wenzelm@26767
     5
begin
wenzelm@26767
     6
wenzelm@26767
     7
chapter {* Basic language elements \label{ch:pure-syntax} *}
wenzelm@26767
     8
wenzelm@26767
     9
text {*
wenzelm@26767
    10
  Subsequently, we introduce the main part of Pure theory and proof
wenzelm@26767
    11
  commands, together with fundamental proof methods and attributes.
wenzelm@26767
    12
  \Chref{ch:gen-tools} describes further Isar elements provided by
wenzelm@26767
    13
  generic tools and packages (such as the Simplifier) that are either
wenzelm@26767
    14
  part of Pure Isabelle or pre-installed in most object logics.
wenzelm@26852
    15
  Specific language elements introduced by the major object-logics are
wenzelm@26852
    16
  described in \chref{ch:hol} (Isabelle/HOL), \chref{ch:holcf}
wenzelm@26852
    17
  (Isabelle/HOLCF), and \chref{ch:zf} (Isabelle/ZF).  Nevertheless,
wenzelm@26852
    18
  examples given in the generic parts will usually refer to
wenzelm@26852
    19
  Isabelle/HOL as well.
wenzelm@26767
    20
wenzelm@26767
    21
  \medskip Isar commands may be either \emph{proper} document
wenzelm@26767
    22
  constructors, or \emph{improper commands}.  Some proof methods and
wenzelm@26767
    23
  attributes introduced later are classified as improper as well.
wenzelm@26767
    24
  Improper Isar language elements, which are subsequently marked by
wenzelm@26767
    25
  ``@{text "\<^sup>*"}'', are often helpful when developing proof
wenzelm@26767
    26
  documents, while their use is discouraged for the final
wenzelm@26767
    27
  human-readable outcome.  Typical examples are diagnostic commands
wenzelm@26767
    28
  that print terms or theorems according to the current context; other
wenzelm@26767
    29
  commands emulate old-style tactical theorem proving.
wenzelm@26767
    30
*}
wenzelm@26767
    31
wenzelm@26767
    32
wenzelm@26767
    33
section {* Theory commands *}
wenzelm@26767
    34
wenzelm@26767
    35
subsection {* Markup commands \label{sec:markup-thy} *}
wenzelm@26767
    36
wenzelm@26767
    37
text {*
wenzelm@26767
    38
  \begin{matharray}{rcl}
wenzelm@26767
    39
    @{command_def "chapter"} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26767
    40
    @{command_def "section"} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26767
    41
    @{command_def "subsection"} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26767
    42
    @{command_def "subsubsection"} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26767
    43
    @{command_def "text"} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26767
    44
    @{command_def "text_raw"} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26767
    45
  \end{matharray}
wenzelm@26767
    46
wenzelm@26767
    47
  Apart from formal comments (see \secref{sec:comments}), markup
wenzelm@26767
    48
  commands provide a structured way to insert text into the document
wenzelm@26767
    49
  generated from a theory (see \cite{isabelle-sys} for more
wenzelm@26767
    50
  information on Isabelle's document preparation tools).
wenzelm@26767
    51
wenzelm@26767
    52
  \begin{rail}
wenzelm@26767
    53
    ('chapter' | 'section' | 'subsection' | 'subsubsection' | 'text') target? text
wenzelm@26767
    54
    ;
wenzelm@26767
    55
    'text\_raw' text
wenzelm@26767
    56
    ;
wenzelm@26767
    57
  \end{rail}
wenzelm@26767
    58
wenzelm@26767
    59
  \begin{descr}
wenzelm@26767
    60
wenzelm@26767
    61
  \item [@{command "chapter"}, @{command "section"}, @{command
wenzelm@26767
    62
  "subsection"}, and @{command "subsubsection"}] mark chapter and
wenzelm@26767
    63
  section headings.
wenzelm@26767
    64
wenzelm@26767
    65
  \item [@{command "text"}] specifies paragraphs of plain text.
wenzelm@26767
    66
wenzelm@26767
    67
  \item [@{command "text_raw"}] inserts {\LaTeX} source into the
wenzelm@26767
    68
  output, without additional markup.  Thus the full range of document
wenzelm@26767
    69
  manipulations becomes available.
wenzelm@26767
    70
wenzelm@26767
    71
  \end{descr}
wenzelm@26767
    72
wenzelm@26767
    73
  The @{text "text"} argument of these markup commands (except for
wenzelm@26767
    74
  @{command "text_raw"}) may contain references to formal entities
wenzelm@26767
    75
  (``antiquotations'', see also \secref{sec:antiq}).  These are
wenzelm@26767
    76
  interpreted in the present theory context, or the named @{text
wenzelm@26767
    77
  "target"}.
wenzelm@26767
    78
wenzelm@26767
    79
  Any of these markup elements corresponds to a {\LaTeX} command with
wenzelm@26767
    80
  the name prefixed by @{verbatim "\\isamarkup"}.  For the sectioning
wenzelm@26767
    81
  commands this is a plain macro with a single argument, e.g.\
wenzelm@26767
    82
  @{verbatim "\\isamarkupchapter{"}@{text "\<dots>"}@{verbatim "}"} for
wenzelm@26767
    83
  @{command "chapter"}.  The @{command "text"} markup results in a
wenzelm@26777
    84
  {\LaTeX} environment @{verbatim "\\begin{isamarkuptext}"} @{text
wenzelm@26777
    85
  "\<dots>"} @{verbatim "\\end{isamarkuptext}"}, while @{command "text_raw"}
wenzelm@26767
    86
  causes the text to be inserted directly into the {\LaTeX} source.
wenzelm@26767
    87
wenzelm@26767
    88
  \medskip Additional markup commands are available for proofs (see
wenzelm@26767
    89
  \secref{sec:markup-prf}).  Also note that the @{command_ref
wenzelm@26767
    90
  "header"} declaration (see \secref{sec:begin-thy}) admits to insert
wenzelm@26767
    91
  section markup just preceding the actual theory definition.
wenzelm@26767
    92
*}
wenzelm@26767
    93
wenzelm@26767
    94
wenzelm@26767
    95
subsection {* Type classes and sorts \label{sec:classes} *}
wenzelm@26767
    96
wenzelm@26767
    97
text {*
wenzelm@26767
    98
  \begin{matharray}{rcll}
wenzelm@26767
    99
    @{command_def "classes"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   100
    @{command_def "classrel"} & : & \isartrans{theory}{theory} & (axiomatic!) \\
wenzelm@26767
   101
    @{command_def "defaultsort"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   102
    @{command_def "class_deps"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26767
   103
  \end{matharray}
wenzelm@26767
   104
wenzelm@26767
   105
  \begin{rail}
wenzelm@26767
   106
    'classes' (classdecl +)
wenzelm@26767
   107
    ;
wenzelm@26767
   108
    'classrel' (nameref ('<' | subseteq) nameref + 'and')
wenzelm@26767
   109
    ;
wenzelm@26767
   110
    'defaultsort' sort
wenzelm@26767
   111
    ;
wenzelm@26767
   112
  \end{rail}
wenzelm@26767
   113
wenzelm@26767
   114
  \begin{descr}
wenzelm@26767
   115
wenzelm@26767
   116
  \item [@{command "classes"}~@{text "c \<subseteq> c\<^sub>1, \<dots>, c\<^sub>n"}]
wenzelm@26767
   117
  declares class @{text c} to be a subclass of existing classes @{text
wenzelm@26767
   118
  "c\<^sub>1, \<dots>, c\<^sub>n"}.  Cyclic class structures are not permitted.
wenzelm@26767
   119
wenzelm@26767
   120
  \item [@{command "classrel"}~@{text "c\<^sub>1 \<subseteq> c\<^sub>2"}] states
wenzelm@26767
   121
  subclass relations between existing classes @{text "c\<^sub>1"} and
wenzelm@26767
   122
  @{text "c\<^sub>2"}.  This is done axiomatically!  The @{command_ref
wenzelm@26767
   123
  "instance"} command (see \secref{sec:axclass}) provides a way to
wenzelm@26767
   124
  introduce proven class relations.
wenzelm@26767
   125
wenzelm@26767
   126
  \item [@{command "defaultsort"}~@{text s}] makes sort @{text s} the
wenzelm@26767
   127
  new default sort for any type variables given without sort
wenzelm@26767
   128
  constraints.  Usually, the default sort would be only changed when
wenzelm@26767
   129
  defining a new object-logic.
wenzelm@26767
   130
wenzelm@26767
   131
  \item [@{command "class_deps"}] visualizes the subclass relation,
wenzelm@26767
   132
  using Isabelle's graph browser tool (see also \cite{isabelle-sys}).
wenzelm@26767
   133
wenzelm@26767
   134
  \end{descr}
wenzelm@26767
   135
*}
wenzelm@26767
   136
wenzelm@26767
   137
wenzelm@26767
   138
subsection {* Primitive types and type abbreviations \label{sec:types-pure} *}
wenzelm@26767
   139
wenzelm@26767
   140
text {*
wenzelm@26767
   141
  \begin{matharray}{rcll}
wenzelm@26767
   142
    @{command_def "types"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   143
    @{command_def "typedecl"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   144
    @{command_def "nonterminals"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   145
    @{command_def "arities"} & : & \isartrans{theory}{theory} & (axiomatic!) \\
wenzelm@26767
   146
  \end{matharray}
wenzelm@26767
   147
wenzelm@26767
   148
  \begin{rail}
wenzelm@26767
   149
    'types' (typespec '=' type infix? +)
wenzelm@26767
   150
    ;
wenzelm@26767
   151
    'typedecl' typespec infix?
wenzelm@26767
   152
    ;
wenzelm@26767
   153
    'nonterminals' (name +)
wenzelm@26767
   154
    ;
wenzelm@26767
   155
    'arities' (nameref '::' arity +)
wenzelm@26767
   156
    ;
wenzelm@26767
   157
  \end{rail}
wenzelm@26767
   158
wenzelm@26767
   159
  \begin{descr}
wenzelm@26767
   160
wenzelm@26767
   161
  \item [@{command "types"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t = \<tau>"}]
wenzelm@26767
   162
  introduces \emph{type synonym} @{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"}
wenzelm@26767
   163
  for existing type @{text "\<tau>"}.  Unlike actual type definitions, as
wenzelm@26767
   164
  are available in Isabelle/HOL for example, type synonyms are just
wenzelm@26767
   165
  purely syntactic abbreviations without any logical significance.
wenzelm@26767
   166
  Internally, type synonyms are fully expanded.
wenzelm@26767
   167
  
wenzelm@26767
   168
  \item [@{command "typedecl"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"}]
wenzelm@26767
   169
  declares a new type constructor @{text t}, intended as an actual
wenzelm@26767
   170
  logical type (of the object-logic, if available).
wenzelm@26767
   171
wenzelm@26767
   172
  \item [@{command "nonterminals"}~@{text c}] declares type
wenzelm@26767
   173
  constructors @{text c} (without arguments) to act as purely
wenzelm@26767
   174
  syntactic types, i.e.\ nonterminal symbols of Isabelle's inner
wenzelm@26767
   175
  syntax of terms or types.
wenzelm@26767
   176
wenzelm@26767
   177
  \item [@{command "arities"}~@{text "t :: (s\<^sub>1, \<dots>, s\<^sub>n)
wenzelm@26767
   178
  s"}] augments Isabelle's order-sorted signature of types by new type
wenzelm@26767
   179
  constructor arities.  This is done axiomatically!  The @{command_ref
wenzelm@26767
   180
  "instance"} command (see \S\ref{sec:axclass}) provides a way to
wenzelm@26767
   181
  introduce proven type arities.
wenzelm@26767
   182
wenzelm@26767
   183
  \end{descr}
wenzelm@26767
   184
*}
wenzelm@26767
   185
wenzelm@26767
   186
wenzelm@26767
   187
subsection {* Primitive constants and definitions \label{sec:consts} *}
wenzelm@26767
   188
wenzelm@26767
   189
text {*
wenzelm@26767
   190
  Definitions essentially express abbreviations within the logic.  The
wenzelm@26767
   191
  simplest form of a definition is @{text "c :: \<sigma> \<equiv> t"}, where @{text
wenzelm@26767
   192
  c} is a newly declared constant.  Isabelle also allows derived forms
wenzelm@26767
   193
  where the arguments of @{text c} appear on the left, abbreviating a
wenzelm@26767
   194
  prefix of @{text \<lambda>}-abstractions, e.g.\ @{text "c \<equiv> \<lambda>x y. t"} may be
wenzelm@26767
   195
  written more conveniently as @{text "c x y \<equiv> t"}.  Moreover,
wenzelm@26767
   196
  definitions may be weakened by adding arbitrary pre-conditions:
wenzelm@26767
   197
  @{text "A \<Longrightarrow> c x y \<equiv> t"}.
wenzelm@26767
   198
wenzelm@26767
   199
  \medskip The built-in well-formedness conditions for definitional
wenzelm@26767
   200
  specifications are:
wenzelm@26767
   201
wenzelm@26767
   202
  \begin{itemize}
wenzelm@26767
   203
wenzelm@26767
   204
  \item Arguments (on the left-hand side) must be distinct variables.
wenzelm@26767
   205
wenzelm@26767
   206
  \item All variables on the right-hand side must also appear on the
wenzelm@26767
   207
  left-hand side.
wenzelm@26767
   208
wenzelm@26767
   209
  \item All type variables on the right-hand side must also appear on
wenzelm@26767
   210
  the left-hand side; this prohibits @{text "0 :: nat \<equiv> length ([] ::
wenzelm@26767
   211
  \<alpha> list)"} for example.
wenzelm@26767
   212
wenzelm@26767
   213
  \item The definition must not be recursive.  Most object-logics
wenzelm@26767
   214
  provide definitional principles that can be used to express
wenzelm@26767
   215
  recursion safely.
wenzelm@26767
   216
wenzelm@26767
   217
  \end{itemize}
wenzelm@26767
   218
wenzelm@26767
   219
  Overloading means that a constant being declared as @{text "c :: \<alpha>
wenzelm@26767
   220
  decl"} may be defined separately on type instances @{text "c ::
wenzelm@26767
   221
  (\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n) t decl"} for each type constructor @{text
wenzelm@26767
   222
  t}.  The right-hand side may mention overloaded constants
wenzelm@26767
   223
  recursively at type instances corresponding to the immediate
wenzelm@26767
   224
  argument types @{text "\<beta>\<^sub>1, \<dots>, \<beta>\<^sub>n"}.  Incomplete
wenzelm@26767
   225
  specification patterns impose global constraints on all occurrences,
wenzelm@26767
   226
  e.g.\ @{text "d :: \<alpha> \<times> \<alpha>"} on the left-hand side means that all
wenzelm@26767
   227
  corresponding occurrences on some right-hand side need to be an
wenzelm@26767
   228
  instance of this, general @{text "d :: \<alpha> \<times> \<beta>"} will be disallowed.
wenzelm@26767
   229
wenzelm@26767
   230
  \begin{matharray}{rcl}
wenzelm@26767
   231
    @{command_def "consts"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   232
    @{command_def "defs"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   233
    @{command_def "constdefs"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   234
  \end{matharray}
wenzelm@26767
   235
wenzelm@26767
   236
  \begin{rail}
wenzelm@26767
   237
    'consts' ((name '::' type mixfix?) +)
wenzelm@26767
   238
    ;
wenzelm@26767
   239
    'defs' ('(' 'unchecked'? 'overloaded'? ')')? \\ (axmdecl prop +)
wenzelm@26767
   240
    ;
wenzelm@26767
   241
  \end{rail}
wenzelm@26767
   242
wenzelm@26767
   243
  \begin{rail}
wenzelm@26767
   244
    'constdefs' structs? (constdecl? constdef +)
wenzelm@26767
   245
    ;
wenzelm@26767
   246
wenzelm@26767
   247
    structs: '(' 'structure' (vars + 'and') ')'
wenzelm@26767
   248
    ;
wenzelm@26767
   249
    constdecl:  ((name '::' type mixfix | name '::' type | name mixfix) 'where'?) | name 'where'
wenzelm@26767
   250
    ;
wenzelm@26767
   251
    constdef: thmdecl? prop
wenzelm@26767
   252
    ;
wenzelm@26767
   253
  \end{rail}
wenzelm@26767
   254
wenzelm@26767
   255
  \begin{descr}
wenzelm@26767
   256
wenzelm@26767
   257
  \item [@{command "consts"}~@{text "c :: \<sigma>"}] declares constant
wenzelm@26767
   258
  @{text c} to have any instance of type scheme @{text \<sigma>}.  The
wenzelm@26767
   259
  optional mixfix annotations may attach concrete syntax to the
wenzelm@26767
   260
  constants declared.
wenzelm@26767
   261
  
wenzelm@26767
   262
  \item [@{command "defs"}~@{text "name: eqn"}] introduces @{text eqn}
wenzelm@26767
   263
  as a definitional axiom for some existing constant.
wenzelm@26767
   264
  
wenzelm@26767
   265
  The @{text "(unchecked)"} option disables global dependency checks
wenzelm@26767
   266
  for this definition, which is occasionally useful for exotic
wenzelm@26767
   267
  overloading.  It is at the discretion of the user to avoid malformed
wenzelm@26767
   268
  theory specifications!
wenzelm@26767
   269
  
wenzelm@26767
   270
  The @{text "(overloaded)"} option declares definitions to be
wenzelm@26767
   271
  potentially overloaded.  Unless this option is given, a warning
wenzelm@26767
   272
  message would be issued for any definitional equation with a more
wenzelm@26767
   273
  special type than that of the corresponding constant declaration.
wenzelm@26767
   274
  
wenzelm@26767
   275
  \item [@{command "constdefs"}] provides a streamlined combination of
wenzelm@26767
   276
  constants declarations and definitions: type-inference takes care of
wenzelm@26767
   277
  the most general typing of the given specification (the optional
wenzelm@26777
   278
  type constraint may refer to type-inference dummies ``@{text
wenzelm@26767
   279
  _}'' as usual).  The resulting type declaration needs to agree with
wenzelm@26767
   280
  that of the specification; overloading is \emph{not} supported here!
wenzelm@26767
   281
  
wenzelm@26767
   282
  The constant name may be omitted altogether, if neither type nor
wenzelm@26767
   283
  syntax declarations are given.  The canonical name of the
wenzelm@26767
   284
  definitional axiom for constant @{text c} will be @{text c_def},
wenzelm@26767
   285
  unless specified otherwise.  Also note that the given list of
wenzelm@26767
   286
  specifications is processed in a strictly sequential manner, with
wenzelm@26767
   287
  type-checking being performed independently.
wenzelm@26767
   288
  
wenzelm@26767
   289
  An optional initial context of @{text "(structure)"} declarations
wenzelm@26767
   290
  admits use of indexed syntax, using the special symbol @{verbatim
wenzelm@26767
   291
  "\<index>"} (printed as ``@{text "\<index>"}'').  The latter concept is
wenzelm@26767
   292
  particularly useful with locales (see also \S\ref{sec:locale}).
wenzelm@26767
   293
wenzelm@26767
   294
  \end{descr}
wenzelm@26767
   295
*}
wenzelm@26767
   296
wenzelm@26767
   297
wenzelm@26767
   298
subsection {* Syntax and translations \label{sec:syn-trans} *}
wenzelm@26767
   299
wenzelm@26767
   300
text {*
wenzelm@26767
   301
  \begin{matharray}{rcl}
wenzelm@26767
   302
    @{command_def "syntax"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   303
    @{command_def "no_syntax"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   304
    @{command_def "translations"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   305
    @{command_def "no_translations"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   306
  \end{matharray}
wenzelm@26767
   307
wenzelm@26767
   308
  \begin{rail}
wenzelm@26767
   309
    ('syntax' | 'no\_syntax') mode? (constdecl +)
wenzelm@26767
   310
    ;
wenzelm@26767
   311
    ('translations' | 'no\_translations') (transpat ('==' | '=>' | '<=' | rightleftharpoons | rightharpoonup | leftharpoondown) transpat +)
wenzelm@26767
   312
    ;
wenzelm@26767
   313
wenzelm@26767
   314
    mode: ('(' ( name | 'output' | name 'output' ) ')')
wenzelm@26767
   315
    ;
wenzelm@26767
   316
    transpat: ('(' nameref ')')? string
wenzelm@26767
   317
    ;
wenzelm@26767
   318
  \end{rail}
wenzelm@26767
   319
wenzelm@26767
   320
  \begin{descr}
wenzelm@26767
   321
  
wenzelm@26767
   322
  \item [@{command "syntax"}~@{text "(mode) decls"}] is similar to
wenzelm@26767
   323
  @{command "consts"}~@{text decls}, except that the actual logical
wenzelm@26767
   324
  signature extension is omitted.  Thus the context free grammar of
wenzelm@26767
   325
  Isabelle's inner syntax may be augmented in arbitrary ways,
wenzelm@26767
   326
  independently of the logic.  The @{text mode} argument refers to the
wenzelm@26767
   327
  print mode that the grammar rules belong; unless the @{keyword_ref
wenzelm@26767
   328
  "output"} indicator is given, all productions are added both to the
wenzelm@26767
   329
  input and output grammar.
wenzelm@26767
   330
  
wenzelm@26767
   331
  \item [@{command "no_syntax"}~@{text "(mode) decls"}] removes
wenzelm@26767
   332
  grammar declarations (and translations) resulting from @{text
wenzelm@26767
   333
  decls}, which are interpreted in the same manner as for @{command
wenzelm@26767
   334
  "syntax"} above.
wenzelm@26767
   335
  
wenzelm@26767
   336
  \item [@{command "translations"}~@{text rules}] specifies syntactic
wenzelm@26767
   337
  translation rules (i.e.\ macros): parse~/ print rules (@{text "\<rightleftharpoons>"}),
wenzelm@26767
   338
  parse rules (@{text "\<rightharpoonup>"}), or print rules (@{text "\<leftharpoondown>"}).
wenzelm@26767
   339
  Translation patterns may be prefixed by the syntactic category to be
wenzelm@26767
   340
  used for parsing; the default is @{text logic}.
wenzelm@26767
   341
  
wenzelm@26767
   342
  \item [@{command "no_translations"}~@{text rules}] removes syntactic
wenzelm@26767
   343
  translation rules, which are interpreted in the same manner as for
wenzelm@26767
   344
  @{command "translations"} above.
wenzelm@26767
   345
wenzelm@26767
   346
  \end{descr}
wenzelm@26767
   347
*}
wenzelm@26767
   348
wenzelm@26767
   349
wenzelm@26767
   350
subsection {* Axioms and theorems \label{sec:axms-thms} *}
wenzelm@26767
   351
wenzelm@26767
   352
text {*
wenzelm@26767
   353
  \begin{matharray}{rcll}
wenzelm@26767
   354
    @{command_def "axioms"} & : & \isartrans{theory}{theory} & (axiomatic!) \\
wenzelm@26767
   355
    @{command_def "lemmas"} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26767
   356
    @{command_def "theorems"} & : & isarkeep{local{\dsh}theory} \\
wenzelm@26767
   357
  \end{matharray}
wenzelm@26767
   358
wenzelm@26767
   359
  \begin{rail}
wenzelm@26767
   360
    'axioms' (axmdecl prop +)
wenzelm@26767
   361
    ;
wenzelm@26767
   362
    ('lemmas' | 'theorems') target? (thmdef? thmrefs + 'and')
wenzelm@26767
   363
    ;
wenzelm@26767
   364
  \end{rail}
wenzelm@26767
   365
wenzelm@26767
   366
  \begin{descr}
wenzelm@26767
   367
  
wenzelm@26767
   368
  \item [@{command "axioms"}~@{text "a: \<phi>"}] introduces arbitrary
wenzelm@26767
   369
  statements as axioms of the meta-logic.  In fact, axioms are
wenzelm@26767
   370
  ``axiomatic theorems'', and may be referred later just as any other
wenzelm@26767
   371
  theorem.
wenzelm@26767
   372
  
wenzelm@26767
   373
  Axioms are usually only introduced when declaring new logical
wenzelm@26767
   374
  systems.  Everyday work is typically done the hard way, with proper
wenzelm@26767
   375
  definitions and proven theorems.
wenzelm@26767
   376
  
wenzelm@26767
   377
  \item [@{command "lemmas"}~@{text "a = b\<^sub>1 \<dots> b\<^sub>n"}]
wenzelm@26767
   378
  retrieves and stores existing facts in the theory context, or the
wenzelm@26767
   379
  specified target context (see also \secref{sec:target}).  Typical
wenzelm@26767
   380
  applications would also involve attributes, to declare Simplifier
wenzelm@26767
   381
  rules, for example.
wenzelm@26767
   382
  
wenzelm@26767
   383
  \item [@{command "theorems"}] is essentially the same as @{command
wenzelm@26767
   384
  "lemmas"}, but marks the result as a different kind of facts.
wenzelm@26767
   385
wenzelm@26767
   386
  \end{descr}
wenzelm@26767
   387
*}
wenzelm@26767
   388
wenzelm@26767
   389
wenzelm@26767
   390
subsection {* Name spaces *}
wenzelm@26767
   391
wenzelm@26767
   392
text {*
wenzelm@26767
   393
  \begin{matharray}{rcl}
wenzelm@26767
   394
    @{command_def "global"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   395
    @{command_def "local"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   396
    @{command_def "hide"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   397
  \end{matharray}
wenzelm@26767
   398
wenzelm@26767
   399
  \begin{rail}
wenzelm@26767
   400
    'hide' ('(open)')? name (nameref + )
wenzelm@26767
   401
    ;
wenzelm@26767
   402
  \end{rail}
wenzelm@26767
   403
wenzelm@26767
   404
  Isabelle organizes any kind of name declarations (of types,
wenzelm@26767
   405
  constants, theorems etc.) by separate hierarchically structured name
wenzelm@26767
   406
  spaces.  Normally the user does not have to control the behavior of
wenzelm@26767
   407
  name spaces by hand, yet the following commands provide some way to
wenzelm@26767
   408
  do so.
wenzelm@26767
   409
wenzelm@26767
   410
  \begin{descr}
wenzelm@26767
   411
wenzelm@26767
   412
  \item [@{command "global"} and @{command "local"}] change the
wenzelm@26767
   413
  current name declaration mode.  Initially, theories start in
wenzelm@26767
   414
  @{command "local"} mode, causing all names to be automatically
wenzelm@26767
   415
  qualified by the theory name.  Changing this to @{command "global"}
wenzelm@26767
   416
  causes all names to be declared without the theory prefix, until
wenzelm@26767
   417
  @{command "local"} is declared again.
wenzelm@26767
   418
  
wenzelm@26767
   419
  Note that global names are prone to get hidden accidently later,
wenzelm@26767
   420
  when qualified names of the same base name are introduced.
wenzelm@26767
   421
  
wenzelm@26767
   422
  \item [@{command "hide"}~@{text "space names"}] fully removes
wenzelm@26767
   423
  declarations from a given name space (which may be @{text "class"},
wenzelm@26767
   424
  @{text "type"}, @{text "const"}, or @{text "fact"}); with the @{text
wenzelm@26767
   425
  "(open)"} option, only the base name is hidden.  Global
wenzelm@26767
   426
  (unqualified) names may never be hidden.
wenzelm@26767
   427
  
wenzelm@26767
   428
  Note that hiding name space accesses has no impact on logical
wenzelm@26767
   429
  declarations -- they remain valid internally.  Entities that are no
wenzelm@26767
   430
  longer accessible to the user are printed with the special qualifier
wenzelm@26767
   431
  ``@{text "??"}'' prefixed to the full internal name.
wenzelm@26767
   432
wenzelm@26767
   433
  \end{descr}
wenzelm@26767
   434
*}
wenzelm@26767
   435
wenzelm@26767
   436
wenzelm@26767
   437
subsection {* Incorporating ML code \label{sec:ML} *}
wenzelm@26767
   438
wenzelm@26767
   439
text {*
wenzelm@26767
   440
  \begin{matharray}{rcl}
wenzelm@26767
   441
    @{command_def "use"} & : & \isarkeep{theory~|~local{\dsh}theory} \\
wenzelm@26767
   442
    @{command_def "ML"} & : & \isarkeep{theory~|~local{\dsh}theory} \\
wenzelm@26767
   443
    @{command_def "ML_val"} & : & \isartrans{\cdot}{\cdot} \\
wenzelm@26767
   444
    @{command_def "ML_command"} & : & \isartrans{\cdot}{\cdot} \\
wenzelm@26767
   445
    @{command_def "setup"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   446
    @{command_def "method_setup"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   447
  \end{matharray}
wenzelm@26767
   448
wenzelm@26767
   449
  \begin{rail}
wenzelm@26767
   450
    'use' name
wenzelm@26767
   451
    ;
wenzelm@26767
   452
    ('ML' | 'ML\_val' | 'ML\_command' | 'setup') text
wenzelm@26767
   453
    ;
wenzelm@26767
   454
    'method\_setup' name '=' text text
wenzelm@26767
   455
    ;
wenzelm@26767
   456
  \end{rail}
wenzelm@26767
   457
wenzelm@26767
   458
  \begin{descr}
wenzelm@26767
   459
wenzelm@26767
   460
  \item [@{command "use"}~@{text "file"}] reads and executes ML
wenzelm@26767
   461
  commands from @{text "file"}.  The current theory context is passed
wenzelm@26767
   462
  down to the ML toplevel and may be modified, using @{ML
wenzelm@26767
   463
  "Context.>>"} or derived ML commands.  The file name is checked with
wenzelm@26767
   464
  the @{keyword_ref "uses"} dependency declaration given in the theory
wenzelm@26767
   465
  header (see also \secref{sec:begin-thy}).
wenzelm@26767
   466
  
wenzelm@26767
   467
  \item [@{command "ML"}~@{text "text"}] is similar to @{command
wenzelm@26767
   468
  "use"}, but executes ML commands directly from the given @{text
wenzelm@26767
   469
  "text"}.
wenzelm@26767
   470
wenzelm@26767
   471
  \item [@{command "ML_val"} and @{command "ML_command"}] are
wenzelm@26767
   472
  diagnostic versions of @{command "ML"}, which means that the context
wenzelm@26767
   473
  may not be updated.  @{command "ML_val"} echos the bindings produced
wenzelm@26767
   474
  at the ML toplevel, but @{command "ML_command"} is silent.
wenzelm@26767
   475
  
wenzelm@26767
   476
  \item [@{command "setup"}~@{text "text"}] changes the current theory
wenzelm@26767
   477
  context by applying @{text "text"}, which refers to an ML expression
wenzelm@26767
   478
  of type @{ML_type "theory -> theory"}.  This enables to initialize
wenzelm@26767
   479
  any object-logic specific tools and packages written in ML, for
wenzelm@26767
   480
  example.
wenzelm@26767
   481
  
wenzelm@26767
   482
  \item [@{command "method_setup"}~@{text "name = text description"}]
wenzelm@26767
   483
  defines a proof method in the current theory.  The given @{text
wenzelm@26767
   484
  "text"} has to be an ML expression of type @{ML_type "Args.src ->
wenzelm@26767
   485
  Proof.context -> Proof.method"}.  Parsing concrete method syntax
wenzelm@26767
   486
  from @{ML_type Args.src} input can be quite tedious in general.  The
wenzelm@26767
   487
  following simple examples are for methods without any explicit
wenzelm@26767
   488
  arguments, or a list of theorems, respectively.
wenzelm@26767
   489
wenzelm@26767
   490
%FIXME proper antiquotations
wenzelm@26767
   491
{\footnotesize
wenzelm@26767
   492
\begin{verbatim}
wenzelm@26767
   493
 Method.no_args (Method.METHOD (fn facts => foobar_tac))
wenzelm@26767
   494
 Method.thms_args (fn thms => Method.METHOD (fn facts => foobar_tac))
wenzelm@26767
   495
 Method.ctxt_args (fn ctxt => Method.METHOD (fn facts => foobar_tac))
wenzelm@26767
   496
 Method.thms_ctxt_args (fn thms => fn ctxt =>
wenzelm@26767
   497
    Method.METHOD (fn facts => foobar_tac))
wenzelm@26767
   498
\end{verbatim}
wenzelm@26767
   499
}
wenzelm@26767
   500
wenzelm@26767
   501
  Note that mere tactic emulations may ignore the @{text facts}
wenzelm@26767
   502
  parameter above.  Proper proof methods would do something
wenzelm@26767
   503
  appropriate with the list of current facts, though.  Single-rule
wenzelm@26767
   504
  methods usually do strict forward-chaining (e.g.\ by using @{ML
wenzelm@26767
   505
  Drule.multi_resolves}), while automatic ones just insert the facts
wenzelm@26767
   506
  using @{ML Method.insert_tac} before applying the main tactic.
wenzelm@26767
   507
wenzelm@26767
   508
  \end{descr}
wenzelm@26767
   509
*}
wenzelm@26767
   510
wenzelm@26767
   511
wenzelm@26767
   512
subsection {* Syntax translation functions *}
wenzelm@26767
   513
wenzelm@26767
   514
text {*
wenzelm@26767
   515
  \begin{matharray}{rcl}
wenzelm@26767
   516
    @{command_def "parse_ast_translation"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   517
    @{command_def "parse_translation"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   518
    @{command_def "print_translation"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   519
    @{command_def "typed_print_translation"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   520
    @{command_def "print_ast_translation"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   521
    @{command_def "token_translation"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   522
  \end{matharray}
wenzelm@26767
   523
wenzelm@26767
   524
  \begin{rail}
wenzelm@26767
   525
  ( 'parse\_ast\_translation' | 'parse\_translation' | 'print\_translation' |
wenzelm@26767
   526
    'typed\_print\_translation' | 'print\_ast\_translation' ) ('(advanced)')? text
wenzelm@26767
   527
  ;
wenzelm@26767
   528
wenzelm@26767
   529
  'token\_translation' text
wenzelm@26767
   530
  ;
wenzelm@26767
   531
  \end{rail}
wenzelm@26767
   532
wenzelm@26767
   533
  Syntax translation functions written in ML admit almost arbitrary
wenzelm@26767
   534
  manipulations of Isabelle's inner syntax.  Any of the above commands
wenzelm@26767
   535
  have a single \railqtok{text} argument that refers to an ML
wenzelm@26767
   536
  expression of appropriate type, which are as follows by default:
wenzelm@26767
   537
wenzelm@26767
   538
%FIXME proper antiquotations
wenzelm@26767
   539
\begin{ttbox}
wenzelm@26767
   540
val parse_ast_translation   : (string * (ast list -> ast)) list
wenzelm@26767
   541
val parse_translation       : (string * (term list -> term)) list
wenzelm@26767
   542
val print_translation       : (string * (term list -> term)) list
wenzelm@26767
   543
val typed_print_translation :
wenzelm@26767
   544
  (string * (bool -> typ -> term list -> term)) list
wenzelm@26767
   545
val print_ast_translation   : (string * (ast list -> ast)) list
wenzelm@26767
   546
val token_translation       :
wenzelm@26767
   547
  (string * string * (string -> string * real)) list
wenzelm@26767
   548
\end{ttbox}
wenzelm@26767
   549
wenzelm@26767
   550
  If the @{text "(advanced)"} option is given, the corresponding
wenzelm@26767
   551
  translation functions may depend on the current theory or proof
wenzelm@26767
   552
  context.  This allows to implement advanced syntax mechanisms, as
wenzelm@26767
   553
  translations functions may refer to specific theory declarations or
wenzelm@26767
   554
  auxiliary proof data.
wenzelm@26767
   555
wenzelm@26767
   556
  See also \cite[\S8]{isabelle-ref} for more information on the
wenzelm@26767
   557
  general concept of syntax transformations in Isabelle.
wenzelm@26767
   558
wenzelm@26767
   559
%FIXME proper antiquotations
wenzelm@26767
   560
\begin{ttbox}
wenzelm@26767
   561
val parse_ast_translation:
wenzelm@26767
   562
  (string * (Context.generic -> ast list -> ast)) list
wenzelm@26767
   563
val parse_translation:
wenzelm@26767
   564
  (string * (Context.generic -> term list -> term)) list
wenzelm@26767
   565
val print_translation:
wenzelm@26767
   566
  (string * (Context.generic -> term list -> term)) list
wenzelm@26767
   567
val typed_print_translation:
wenzelm@26767
   568
  (string * (Context.generic -> bool -> typ -> term list -> term)) list
wenzelm@26767
   569
val print_ast_translation:
wenzelm@26767
   570
  (string * (Context.generic -> ast list -> ast)) list
wenzelm@26767
   571
\end{ttbox}
wenzelm@26767
   572
*}
wenzelm@26767
   573
wenzelm@26767
   574
wenzelm@26767
   575
subsection {* Oracles *}
wenzelm@26767
   576
wenzelm@26767
   577
text {*
wenzelm@26767
   578
  \begin{matharray}{rcl}
wenzelm@26767
   579
    @{command_def "oracle"} & : & \isartrans{theory}{theory} \\
wenzelm@26767
   580
  \end{matharray}
wenzelm@26767
   581
wenzelm@26767
   582
  The oracle interface promotes a given ML function @{ML_text
wenzelm@26777
   583
  "theory -> T -> term"} to @{ML_text "theory -> T -> thm"}, for some
wenzelm@26777
   584
  type @{ML_text T} given by the user.  This acts like an infinitary
wenzelm@26767
   585
  specification of axioms -- there is no internal check of the
wenzelm@26767
   586
  correctness of the results!  The inference kernel records oracle
wenzelm@26767
   587
  invocations within the internal derivation object of theorems, and
wenzelm@26767
   588
  the pretty printer attaches ``@{text "[!]"}'' to indicate results
wenzelm@26767
   589
  that are not fully checked by Isabelle inferences.
wenzelm@26767
   590
wenzelm@26767
   591
  \begin{rail}
wenzelm@26767
   592
    'oracle' name '(' type ')' '=' text
wenzelm@26767
   593
    ;
wenzelm@26767
   594
  \end{rail}
wenzelm@26767
   595
wenzelm@26767
   596
  \begin{descr}
wenzelm@26767
   597
wenzelm@26767
   598
  \item [@{command "oracle"}~@{text "name (type) = text"}] turns the
wenzelm@26777
   599
  given ML expression @{text "text"} of type
wenzelm@26777
   600
  @{ML_text "theory ->"}~@{text "type"}~@{ML_text "-> term"} into an
wenzelm@26777
   601
  ML function of type
wenzelm@26777
   602
  @{ML_text "theory ->"}~@{text "type"}~@{ML_text "-> thm"}, which is
wenzelm@26777
   603
  bound to the global identifier @{ML_text name}.
wenzelm@26767
   604
wenzelm@26767
   605
  \end{descr}
wenzelm@26767
   606
*}
wenzelm@26767
   607
wenzelm@26767
   608
wenzelm@26767
   609
section {* Proof commands *}
wenzelm@26767
   610
wenzelm@26767
   611
subsection {* Markup commands \label{sec:markup-prf} *}
wenzelm@26767
   612
wenzelm@26767
   613
text {*
wenzelm@26767
   614
  \begin{matharray}{rcl}
wenzelm@26767
   615
    @{command_def "sect"} & : & \isartrans{proof}{proof} \\
wenzelm@26767
   616
    @{command_def "subsect"} & : & \isartrans{proof}{proof} \\
wenzelm@26767
   617
    @{command_def "subsubsect"} & : & \isartrans{proof}{proof} \\
wenzelm@26767
   618
    @{command_def "txt"} & : & \isartrans{proof}{proof} \\
wenzelm@26767
   619
    @{command_def "txt_raw"} & : & \isartrans{proof}{proof} \\
wenzelm@26767
   620
  \end{matharray}
wenzelm@26767
   621
wenzelm@26767
   622
  These markup commands for proof mode closely correspond to the ones
wenzelm@26767
   623
  of theory mode (see \S\ref{sec:markup-thy}).
wenzelm@26767
   624
wenzelm@26767
   625
  \begin{rail}
wenzelm@26767
   626
    ('sect' | 'subsect' | 'subsubsect' | 'txt' | 'txt\_raw') text
wenzelm@26767
   627
    ;
wenzelm@26767
   628
  \end{rail}
wenzelm@26767
   629
*}
wenzelm@26767
   630
wenzelm@26767
   631
wenzelm@26767
   632
section {* Other commands *}
wenzelm@26767
   633
wenzelm@26767
   634
subsection {* Diagnostics *}
wenzelm@26767
   635
wenzelm@26767
   636
text {*
wenzelm@26767
   637
  \begin{matharray}{rcl}
wenzelm@26866
   638
    @{command_def "pr"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@26866
   639
    @{command_def "thm"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   640
    @{command_def "term"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   641
    @{command_def "prop"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   642
    @{command_def "typ"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   643
    @{command_def "prf"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   644
    @{command_def "full_prf"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26767
   645
  \end{matharray}
wenzelm@26767
   646
wenzelm@26767
   647
  These diagnostic commands assist interactive development.  Note that
wenzelm@26767
   648
  @{command undo} does not apply here, the theory or proof
wenzelm@26767
   649
  configuration is not changed.
wenzelm@26767
   650
wenzelm@26767
   651
  \begin{rail}
wenzelm@26767
   652
    'pr' modes? nat? (',' nat)?
wenzelm@26767
   653
    ;
wenzelm@26767
   654
    'thm' modes? thmrefs
wenzelm@26767
   655
    ;
wenzelm@26767
   656
    'term' modes? term
wenzelm@26767
   657
    ;
wenzelm@26767
   658
    'prop' modes? prop
wenzelm@26767
   659
    ;
wenzelm@26767
   660
    'typ' modes? type
wenzelm@26767
   661
    ;
wenzelm@26767
   662
    'prf' modes? thmrefs?
wenzelm@26767
   663
    ;
wenzelm@26767
   664
    'full\_prf' modes? thmrefs?
wenzelm@26767
   665
    ;
wenzelm@26767
   666
wenzelm@26767
   667
    modes: '(' (name + ) ')'
wenzelm@26767
   668
    ;
wenzelm@26767
   669
  \end{rail}
wenzelm@26767
   670
wenzelm@26767
   671
  \begin{descr}
wenzelm@26767
   672
wenzelm@26767
   673
  \item [@{command "pr"}~@{text "goals, prems"}] prints the current
wenzelm@26767
   674
  proof state (if present), including the proof context, current facts
wenzelm@26767
   675
  and goals.  The optional limit arguments affect the number of goals
wenzelm@26767
   676
  and premises to be displayed, which is initially 10 for both.
wenzelm@26767
   677
  Omitting limit values leaves the current setting unchanged.
wenzelm@26767
   678
wenzelm@26767
   679
  \item [@{command "thm"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] retrieves
wenzelm@26767
   680
  theorems from the current theory or proof context.  Note that any
wenzelm@26767
   681
  attributes included in the theorem specifications are applied to a
wenzelm@26767
   682
  temporary context derived from the current theory or proof; the
wenzelm@26767
   683
  result is discarded, i.e.\ attributes involved in @{text "a\<^sub>1,
wenzelm@26767
   684
  \<dots>, a\<^sub>n"} do not have any permanent effect.
wenzelm@26767
   685
wenzelm@26767
   686
  \item [@{command "term"}~@{text t} and @{command "prop"}~@{text \<phi>}]
wenzelm@26767
   687
  read, type-check and print terms or propositions according to the
wenzelm@26767
   688
  current theory or proof context; the inferred type of @{text t} is
wenzelm@26767
   689
  output as well.  Note that these commands are also useful in
wenzelm@26767
   690
  inspecting the current environment of term abbreviations.
wenzelm@26767
   691
wenzelm@26767
   692
  \item [@{command "typ"}~@{text \<tau>}] reads and prints types of the
wenzelm@26767
   693
  meta-logic according to the current theory or proof context.
wenzelm@26767
   694
wenzelm@26767
   695
  \item [@{command "prf"}] displays the (compact) proof term of the
wenzelm@26767
   696
  current proof state (if present), or of the given theorems. Note
wenzelm@26767
   697
  that this requires proof terms to be switched on for the current
wenzelm@26767
   698
  object logic (see the ``Proof terms'' section of the Isabelle
wenzelm@26767
   699
  reference manual for information on how to do this).
wenzelm@26767
   700
wenzelm@26767
   701
  \item [@{command "full_prf"}] is like @{command "prf"}, but displays
wenzelm@26767
   702
  the full proof term, i.e.\ also displays information omitted in the
wenzelm@26777
   703
  compact proof term, which is denoted by ``@{text _}'' placeholders
wenzelm@26777
   704
  there.
wenzelm@26767
   705
wenzelm@26767
   706
  \end{descr}
wenzelm@26767
   707
wenzelm@26767
   708
  All of the diagnostic commands above admit a list of @{text modes}
wenzelm@26767
   709
  to be specified, which is appended to the current print mode (see
wenzelm@26767
   710
  also \cite{isabelle-ref}).  Thus the output behavior may be modified
wenzelm@26767
   711
  according particular print mode features.  For example, @{command
wenzelm@26767
   712
  "pr"}~@{text "(latex xsymbols symbols)"} would print the current
wenzelm@26767
   713
  proof state with mathematical symbols and special characters
wenzelm@26767
   714
  represented in {\LaTeX} source, according to the Isabelle style
wenzelm@26767
   715
  \cite{isabelle-sys}.
wenzelm@26767
   716
wenzelm@26767
   717
  Note that antiquotations (cf.\ \secref{sec:antiq}) provide a more
wenzelm@26767
   718
  systematic way to include formal items into the printed text
wenzelm@26767
   719
  document.
wenzelm@26767
   720
*}
wenzelm@26767
   721
wenzelm@26767
   722
wenzelm@26767
   723
subsection {* Inspecting the context *}
wenzelm@26767
   724
wenzelm@26767
   725
text {*
wenzelm@26767
   726
  \begin{matharray}{rcl}
wenzelm@26866
   727
    @{command_def "print_commands"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@26866
   728
    @{command_def "print_theory"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   729
    @{command_def "print_syntax"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   730
    @{command_def "print_methods"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   731
    @{command_def "print_attributes"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   732
    @{command_def "print_theorems"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   733
    @{command_def "find_theorems"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26894
   734
    @{command_def "thm_deps"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26866
   735
    @{command_def "print_facts"}@{text "\<^sup>*"} & : & \isarkeep{proof} \\
wenzelm@26866
   736
    @{command_def "print_binds"}@{text "\<^sup>*"} & : & \isarkeep{proof} \\
wenzelm@26767
   737
  \end{matharray}
wenzelm@26767
   738
wenzelm@26767
   739
  \begin{rail}
wenzelm@26767
   740
    'print\_theory' ( '!'?)
wenzelm@26767
   741
    ;
wenzelm@26767
   742
wenzelm@26767
   743
    'find\_theorems' (('(' (nat)? ('with\_dups')? ')')?) (criterion *)
wenzelm@26767
   744
    ;
wenzelm@26767
   745
    criterion: ('-'?) ('name' ':' nameref | 'intro' | 'elim' | 'dest' |
wenzelm@26767
   746
      'simp' ':' term | term)
wenzelm@26767
   747
    ;
wenzelm@26767
   748
    'thm\_deps' thmrefs
wenzelm@26767
   749
    ;
wenzelm@26767
   750
  \end{rail}
wenzelm@26767
   751
wenzelm@26767
   752
  These commands print certain parts of the theory and proof context.
wenzelm@26767
   753
  Note that there are some further ones available, such as for the set
wenzelm@26767
   754
  of rules declared for simplifications.
wenzelm@26767
   755
wenzelm@26767
   756
  \begin{descr}
wenzelm@26767
   757
  
wenzelm@26767
   758
  \item [@{command "print_commands"}] prints Isabelle's outer theory
wenzelm@26767
   759
  syntax, including keywords and command.
wenzelm@26767
   760
  
wenzelm@26767
   761
  \item [@{command "print_theory"}] prints the main logical content of
wenzelm@26767
   762
  the theory context; the ``@{text "!"}'' option indicates extra
wenzelm@26767
   763
  verbosity.
wenzelm@26767
   764
wenzelm@26767
   765
  \item [@{command "print_syntax"}] prints the inner syntax of types
wenzelm@26767
   766
  and terms, depending on the current context.  The output can be very
wenzelm@26767
   767
  verbose, including grammar tables and syntax translation rules.  See
wenzelm@26767
   768
  \cite[\S7, \S8]{isabelle-ref} for further information on Isabelle's
wenzelm@26767
   769
  inner syntax.
wenzelm@26767
   770
  
wenzelm@26767
   771
  \item [@{command "print_methods"}] prints all proof methods
wenzelm@26767
   772
  available in the current theory context.
wenzelm@26767
   773
  
wenzelm@26767
   774
  \item [@{command "print_attributes"}] prints all attributes
wenzelm@26767
   775
  available in the current theory context.
wenzelm@26767
   776
  
wenzelm@26767
   777
  \item [@{command "print_theorems"}] prints theorems resulting from
wenzelm@26767
   778
  the last command.
wenzelm@26767
   779
  
wenzelm@26767
   780
  \item [@{command "find_theorems"}~@{text criteria}] retrieves facts
wenzelm@26767
   781
  from the theory or proof context matching all of given search
wenzelm@26767
   782
  criteria.  The criterion @{text "name: p"} selects all theorems
wenzelm@26767
   783
  whose fully qualified name matches pattern @{text p}, which may
wenzelm@26767
   784
  contain ``@{text "*"}'' wildcards.  The criteria @{text intro},
wenzelm@26767
   785
  @{text elim}, and @{text dest} select theorems that match the
wenzelm@26767
   786
  current goal as introduction, elimination or destruction rules,
wenzelm@26767
   787
  respectively.  The criterion @{text "simp: t"} selects all rewrite
wenzelm@26767
   788
  rules whose left-hand side matches the given term.  The criterion
wenzelm@26767
   789
  term @{text t} selects all theorems that contain the pattern @{text
wenzelm@26767
   790
  t} -- as usual, patterns may contain occurrences of the dummy
wenzelm@26777
   791
  ``@{text _}'', schematic variables, and type constraints.
wenzelm@26767
   792
  
wenzelm@26767
   793
  Criteria can be preceded by ``@{text "-"}'' to select theorems that
wenzelm@26767
   794
  do \emph{not} match. Note that giving the empty list of criteria
wenzelm@26767
   795
  yields \emph{all} currently known facts.  An optional limit for the
wenzelm@26767
   796
  number of printed facts may be given; the default is 40.  By
wenzelm@26767
   797
  default, duplicates are removed from the search result. Use
wenzelm@26894
   798
  @{text with_dups} to display duplicates.
wenzelm@26767
   799
  
wenzelm@26767
   800
  \item [@{command "thm_deps"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}]
wenzelm@26767
   801
  visualizes dependencies of facts, using Isabelle's graph browser
wenzelm@26767
   802
  tool (see also \cite{isabelle-sys}).
wenzelm@26767
   803
  
wenzelm@26767
   804
  \item [@{command "print_facts"}] prints all local facts of the
wenzelm@26767
   805
  current context, both named and unnamed ones.
wenzelm@26767
   806
  
wenzelm@26767
   807
  \item [@{command "print_binds"}] prints all term abbreviations
wenzelm@26767
   808
  present in the context.
wenzelm@26767
   809
wenzelm@26767
   810
  \end{descr}
wenzelm@26767
   811
*}
wenzelm@26767
   812
wenzelm@26767
   813
wenzelm@26767
   814
subsection {* History commands \label{sec:history} *}
wenzelm@26767
   815
wenzelm@26767
   816
text {*
wenzelm@26767
   817
  \begin{matharray}{rcl}
wenzelm@26767
   818
    @{command_def "undo"}^{{ * }{ * }} & : & \isarkeep{\cdot} \\
wenzelm@26767
   819
    @{command_def "redo"}^{{ * }{ * }} & : & \isarkeep{\cdot} \\
wenzelm@26767
   820
    @{command_def "kill"}^{{ * }{ * }} & : & \isarkeep{\cdot} \\
wenzelm@26767
   821
  \end{matharray}
wenzelm@26767
   822
wenzelm@26767
   823
  The Isabelle/Isar top-level maintains a two-stage history, for
wenzelm@26767
   824
  theory and proof state transformation.  Basically, any command can
wenzelm@26767
   825
  be undone using @{command "undo"}, excluding mere diagnostic
wenzelm@26767
   826
  elements.  Its effect may be revoked via @{command "redo"}, unless
wenzelm@26767
   827
  the corresponding @{command "undo"} step has crossed the beginning
wenzelm@26767
   828
  of a proof or theory.  The @{command "kill"} command aborts the
wenzelm@26767
   829
  current history node altogether, discontinuing a proof or even the
wenzelm@26767
   830
  whole theory.  This operation is \emph{not} undo-able.
wenzelm@26767
   831
wenzelm@26767
   832
  \begin{warn}
wenzelm@26767
   833
    History commands should never be used with user interfaces such as
wenzelm@26767
   834
    Proof~General \cite{proofgeneral,Aspinall:TACAS:2000}, which takes
wenzelm@26767
   835
    care of stepping forth and back itself.  Interfering by manual
wenzelm@26767
   836
    @{command "undo"}, @{command "redo"}, or even @{command "kill"}
wenzelm@26767
   837
    commands would quickly result in utter confusion.
wenzelm@26767
   838
  \end{warn}
wenzelm@26767
   839
*}
wenzelm@26767
   840
wenzelm@26767
   841
wenzelm@26767
   842
subsection {* System operations *}
wenzelm@26767
   843
wenzelm@26767
   844
text {*
wenzelm@26767
   845
  \begin{matharray}{rcl}
wenzelm@26866
   846
    @{command_def "cd"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@26866
   847
    @{command_def "pwd"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@26866
   848
    @{command_def "use_thy"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@26866
   849
    @{command_def "display_drafts"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@26866
   850
    @{command_def "print_drafts"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@26767
   851
  \end{matharray}
wenzelm@26767
   852
wenzelm@26767
   853
  \begin{rail}
wenzelm@26767
   854
    ('cd' | 'use\_thy' | 'update\_thy') name
wenzelm@26767
   855
    ;
wenzelm@26767
   856
    ('display\_drafts' | 'print\_drafts') (name +)
wenzelm@26767
   857
    ;
wenzelm@26767
   858
  \end{rail}
wenzelm@26767
   859
wenzelm@26767
   860
  \begin{descr}
wenzelm@26767
   861
wenzelm@26767
   862
  \item [@{command "cd"}~@{text path}] changes the current directory
wenzelm@26767
   863
  of the Isabelle process.
wenzelm@26767
   864
wenzelm@26767
   865
  \item [@{command "pwd"}] prints the current working directory.
wenzelm@26767
   866
wenzelm@26767
   867
  \item [@{command "use_thy"}~@{text A}] preload theory @{text A}.
wenzelm@26767
   868
  These system commands are scarcely used when working interactively,
wenzelm@26767
   869
  since loading of theories is done automatically as required.
wenzelm@26767
   870
wenzelm@26767
   871
  \item [@{command "display_drafts"}~@{text paths} and @{command
wenzelm@26767
   872
  "print_drafts"}~@{text paths}] perform simple output of a given list
wenzelm@26767
   873
  of raw source files.  Only those symbols that do not require
wenzelm@26767
   874
  additional {\LaTeX} packages are displayed properly, everything else
wenzelm@26767
   875
  is left verbatim.
wenzelm@26767
   876
wenzelm@26767
   877
  \end{descr}
wenzelm@26767
   878
*}
wenzelm@26767
   879
wenzelm@26767
   880
end