doc-src/IsarRef/Thy/Misc.thy
author wenzelm
Tue, 03 Jun 2008 00:05:06 +0200
changeset 27056 4bf8710b3242
child 27598 b66e257b75f5
permissions -rw-r--r--
moved stuff from pure.thy to Misc.thy;
wenzelm@27056
     1
(* $Id$ *)
wenzelm@27056
     2
wenzelm@27056
     3
theory Misc
wenzelm@27056
     4
imports Main
wenzelm@27056
     5
begin
wenzelm@27056
     6
wenzelm@27056
     7
chapter {* Other commands \label{ch:pure-syntax} *}
wenzelm@27056
     8
wenzelm@27056
     9
section {* Diagnostics *}
wenzelm@27056
    10
wenzelm@27056
    11
text {*
wenzelm@27056
    12
  \begin{matharray}{rcl}
wenzelm@27056
    13
    @{command_def "pr"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@27056
    14
    @{command_def "thm"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
    15
    @{command_def "term"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
    16
    @{command_def "prop"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
    17
    @{command_def "typ"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
    18
    @{command_def "prf"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
    19
    @{command_def "full_prf"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
    20
  \end{matharray}
wenzelm@27056
    21
wenzelm@27056
    22
  These diagnostic commands assist interactive development.  Note that
wenzelm@27056
    23
  @{command undo} does not apply here, the theory or proof
wenzelm@27056
    24
  configuration is not changed.
wenzelm@27056
    25
wenzelm@27056
    26
  \begin{rail}
wenzelm@27056
    27
    'pr' modes? nat? (',' nat)?
wenzelm@27056
    28
    ;
wenzelm@27056
    29
    'thm' modes? thmrefs
wenzelm@27056
    30
    ;
wenzelm@27056
    31
    'term' modes? term
wenzelm@27056
    32
    ;
wenzelm@27056
    33
    'prop' modes? prop
wenzelm@27056
    34
    ;
wenzelm@27056
    35
    'typ' modes? type
wenzelm@27056
    36
    ;
wenzelm@27056
    37
    'prf' modes? thmrefs?
wenzelm@27056
    38
    ;
wenzelm@27056
    39
    'full\_prf' modes? thmrefs?
wenzelm@27056
    40
    ;
wenzelm@27056
    41
wenzelm@27056
    42
    modes: '(' (name + ) ')'
wenzelm@27056
    43
    ;
wenzelm@27056
    44
  \end{rail}
wenzelm@27056
    45
wenzelm@27056
    46
  \begin{descr}
wenzelm@27056
    47
wenzelm@27056
    48
  \item [@{command "pr"}~@{text "goals, prems"}] prints the current
wenzelm@27056
    49
  proof state (if present), including the proof context, current facts
wenzelm@27056
    50
  and goals.  The optional limit arguments affect the number of goals
wenzelm@27056
    51
  and premises to be displayed, which is initially 10 for both.
wenzelm@27056
    52
  Omitting limit values leaves the current setting unchanged.
wenzelm@27056
    53
wenzelm@27056
    54
  \item [@{command "thm"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] retrieves
wenzelm@27056
    55
  theorems from the current theory or proof context.  Note that any
wenzelm@27056
    56
  attributes included in the theorem specifications are applied to a
wenzelm@27056
    57
  temporary context derived from the current theory or proof; the
wenzelm@27056
    58
  result is discarded, i.e.\ attributes involved in @{text "a\<^sub>1,
wenzelm@27056
    59
  \<dots>, a\<^sub>n"} do not have any permanent effect.
wenzelm@27056
    60
wenzelm@27056
    61
  \item [@{command "term"}~@{text t} and @{command "prop"}~@{text \<phi>}]
wenzelm@27056
    62
  read, type-check and print terms or propositions according to the
wenzelm@27056
    63
  current theory or proof context; the inferred type of @{text t} is
wenzelm@27056
    64
  output as well.  Note that these commands are also useful in
wenzelm@27056
    65
  inspecting the current environment of term abbreviations.
wenzelm@27056
    66
wenzelm@27056
    67
  \item [@{command "typ"}~@{text \<tau>}] reads and prints types of the
wenzelm@27056
    68
  meta-logic according to the current theory or proof context.
wenzelm@27056
    69
wenzelm@27056
    70
  \item [@{command "prf"}] displays the (compact) proof term of the
wenzelm@27056
    71
  current proof state (if present), or of the given theorems. Note
wenzelm@27056
    72
  that this requires proof terms to be switched on for the current
wenzelm@27056
    73
  object logic (see the ``Proof terms'' section of the Isabelle
wenzelm@27056
    74
  reference manual for information on how to do this).
wenzelm@27056
    75
wenzelm@27056
    76
  \item [@{command "full_prf"}] is like @{command "prf"}, but displays
wenzelm@27056
    77
  the full proof term, i.e.\ also displays information omitted in the
wenzelm@27056
    78
  compact proof term, which is denoted by ``@{text _}'' placeholders
wenzelm@27056
    79
  there.
wenzelm@27056
    80
wenzelm@27056
    81
  \end{descr}
wenzelm@27056
    82
wenzelm@27056
    83
  All of the diagnostic commands above admit a list of @{text modes}
wenzelm@27056
    84
  to be specified, which is appended to the current print mode (see
wenzelm@27056
    85
  also \cite{isabelle-ref}).  Thus the output behavior may be modified
wenzelm@27056
    86
  according particular print mode features.  For example, @{command
wenzelm@27056
    87
  "pr"}~@{text "(latex xsymbols symbols)"} would print the current
wenzelm@27056
    88
  proof state with mathematical symbols and special characters
wenzelm@27056
    89
  represented in {\LaTeX} source, according to the Isabelle style
wenzelm@27056
    90
  \cite{isabelle-sys}.
wenzelm@27056
    91
wenzelm@27056
    92
  Note that antiquotations (cf.\ \secref{sec:antiq}) provide a more
wenzelm@27056
    93
  systematic way to include formal items into the printed text
wenzelm@27056
    94
  document.
wenzelm@27056
    95
*}
wenzelm@27056
    96
wenzelm@27056
    97
wenzelm@27056
    98
section {* Inspecting the context *}
wenzelm@27056
    99
wenzelm@27056
   100
text {*
wenzelm@27056
   101
  \begin{matharray}{rcl}
wenzelm@27056
   102
    @{command_def "print_commands"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@27056
   103
    @{command_def "print_theory"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
   104
    @{command_def "print_syntax"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
   105
    @{command_def "print_methods"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
   106
    @{command_def "print_attributes"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
   107
    @{command_def "print_theorems"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
   108
    @{command_def "find_theorems"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
   109
    @{command_def "thm_deps"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@27056
   110
    @{command_def "print_facts"}@{text "\<^sup>*"} & : & \isarkeep{proof} \\
wenzelm@27056
   111
    @{command_def "print_binds"}@{text "\<^sup>*"} & : & \isarkeep{proof} \\
wenzelm@27056
   112
  \end{matharray}
wenzelm@27056
   113
wenzelm@27056
   114
  \begin{rail}
wenzelm@27056
   115
    'print\_theory' ( '!'?)
wenzelm@27056
   116
    ;
wenzelm@27056
   117
wenzelm@27056
   118
    'find\_theorems' (('(' (nat)? ('with\_dups')? ')')?) (criterion *)
wenzelm@27056
   119
    ;
wenzelm@27056
   120
    criterion: ('-'?) ('name' ':' nameref | 'intro' | 'elim' | 'dest' |
wenzelm@27056
   121
      'simp' ':' term | term)
wenzelm@27056
   122
    ;
wenzelm@27056
   123
    'thm\_deps' thmrefs
wenzelm@27056
   124
    ;
wenzelm@27056
   125
  \end{rail}
wenzelm@27056
   126
wenzelm@27056
   127
  These commands print certain parts of the theory and proof context.
wenzelm@27056
   128
  Note that there are some further ones available, such as for the set
wenzelm@27056
   129
  of rules declared for simplifications.
wenzelm@27056
   130
wenzelm@27056
   131
  \begin{descr}
wenzelm@27056
   132
  
wenzelm@27056
   133
  \item [@{command "print_commands"}] prints Isabelle's outer theory
wenzelm@27056
   134
  syntax, including keywords and command.
wenzelm@27056
   135
  
wenzelm@27056
   136
  \item [@{command "print_theory"}] prints the main logical content of
wenzelm@27056
   137
  the theory context; the ``@{text "!"}'' option indicates extra
wenzelm@27056
   138
  verbosity.
wenzelm@27056
   139
wenzelm@27056
   140
  \item [@{command "print_syntax"}] prints the inner syntax of types
wenzelm@27056
   141
  and terms, depending on the current context.  The output can be very
wenzelm@27056
   142
  verbose, including grammar tables and syntax translation rules.  See
wenzelm@27056
   143
  \cite[\S7, \S8]{isabelle-ref} for further information on Isabelle's
wenzelm@27056
   144
  inner syntax.
wenzelm@27056
   145
  
wenzelm@27056
   146
  \item [@{command "print_methods"}] prints all proof methods
wenzelm@27056
   147
  available in the current theory context.
wenzelm@27056
   148
  
wenzelm@27056
   149
  \item [@{command "print_attributes"}] prints all attributes
wenzelm@27056
   150
  available in the current theory context.
wenzelm@27056
   151
  
wenzelm@27056
   152
  \item [@{command "print_theorems"}] prints theorems resulting from
wenzelm@27056
   153
  the last command.
wenzelm@27056
   154
  
wenzelm@27056
   155
  \item [@{command "find_theorems"}~@{text criteria}] retrieves facts
wenzelm@27056
   156
  from the theory or proof context matching all of given search
wenzelm@27056
   157
  criteria.  The criterion @{text "name: p"} selects all theorems
wenzelm@27056
   158
  whose fully qualified name matches pattern @{text p}, which may
wenzelm@27056
   159
  contain ``@{text "*"}'' wildcards.  The criteria @{text intro},
wenzelm@27056
   160
  @{text elim}, and @{text dest} select theorems that match the
wenzelm@27056
   161
  current goal as introduction, elimination or destruction rules,
wenzelm@27056
   162
  respectively.  The criterion @{text "simp: t"} selects all rewrite
wenzelm@27056
   163
  rules whose left-hand side matches the given term.  The criterion
wenzelm@27056
   164
  term @{text t} selects all theorems that contain the pattern @{text
wenzelm@27056
   165
  t} -- as usual, patterns may contain occurrences of the dummy
wenzelm@27056
   166
  ``@{text _}'', schematic variables, and type constraints.
wenzelm@27056
   167
  
wenzelm@27056
   168
  Criteria can be preceded by ``@{text "-"}'' to select theorems that
wenzelm@27056
   169
  do \emph{not} match. Note that giving the empty list of criteria
wenzelm@27056
   170
  yields \emph{all} currently known facts.  An optional limit for the
wenzelm@27056
   171
  number of printed facts may be given; the default is 40.  By
wenzelm@27056
   172
  default, duplicates are removed from the search result. Use
wenzelm@27056
   173
  @{text with_dups} to display duplicates.
wenzelm@27056
   174
  
wenzelm@27056
   175
  \item [@{command "thm_deps"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}]
wenzelm@27056
   176
  visualizes dependencies of facts, using Isabelle's graph browser
wenzelm@27056
   177
  tool (see also \cite{isabelle-sys}).
wenzelm@27056
   178
  
wenzelm@27056
   179
  \item [@{command "print_facts"}] prints all local facts of the
wenzelm@27056
   180
  current context, both named and unnamed ones.
wenzelm@27056
   181
  
wenzelm@27056
   182
  \item [@{command "print_binds"}] prints all term abbreviations
wenzelm@27056
   183
  present in the context.
wenzelm@27056
   184
wenzelm@27056
   185
  \end{descr}
wenzelm@27056
   186
*}
wenzelm@27056
   187
wenzelm@27056
   188
wenzelm@27056
   189
section {* History commands \label{sec:history} *}
wenzelm@27056
   190
wenzelm@27056
   191
text {*
wenzelm@27056
   192
  \begin{matharray}{rcl}
wenzelm@27056
   193
    @{command_def "undo"}^{{ * }{ * }} & : & \isarkeep{\cdot} \\
wenzelm@27056
   194
    @{command_def "redo"}^{{ * }{ * }} & : & \isarkeep{\cdot} \\
wenzelm@27056
   195
    @{command_def "kill"}^{{ * }{ * }} & : & \isarkeep{\cdot} \\
wenzelm@27056
   196
  \end{matharray}
wenzelm@27056
   197
wenzelm@27056
   198
  The Isabelle/Isar top-level maintains a two-stage history, for
wenzelm@27056
   199
  theory and proof state transformation.  Basically, any command can
wenzelm@27056
   200
  be undone using @{command "undo"}, excluding mere diagnostic
wenzelm@27056
   201
  elements.  Its effect may be revoked via @{command "redo"}, unless
wenzelm@27056
   202
  the corresponding @{command "undo"} step has crossed the beginning
wenzelm@27056
   203
  of a proof or theory.  The @{command "kill"} command aborts the
wenzelm@27056
   204
  current history node altogether, discontinuing a proof or even the
wenzelm@27056
   205
  whole theory.  This operation is \emph{not} undo-able.
wenzelm@27056
   206
wenzelm@27056
   207
  \begin{warn}
wenzelm@27056
   208
    History commands should never be used with user interfaces such as
wenzelm@27056
   209
    Proof~General \cite{proofgeneral,Aspinall:TACAS:2000}, which takes
wenzelm@27056
   210
    care of stepping forth and back itself.  Interfering by manual
wenzelm@27056
   211
    @{command "undo"}, @{command "redo"}, or even @{command "kill"}
wenzelm@27056
   212
    commands would quickly result in utter confusion.
wenzelm@27056
   213
  \end{warn}
wenzelm@27056
   214
*}
wenzelm@27056
   215
wenzelm@27056
   216
wenzelm@27056
   217
section {* System commands *}
wenzelm@27056
   218
wenzelm@27056
   219
text {*
wenzelm@27056
   220
  \begin{matharray}{rcl}
wenzelm@27056
   221
    @{command_def "cd"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@27056
   222
    @{command_def "pwd"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@27056
   223
    @{command_def "use_thy"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
wenzelm@27056
   224
  \end{matharray}
wenzelm@27056
   225
wenzelm@27056
   226
  \begin{rail}
wenzelm@27056
   227
    ('cd' | 'use\_thy' | 'update\_thy') name
wenzelm@27056
   228
    ;
wenzelm@27056
   229
  \end{rail}
wenzelm@27056
   230
wenzelm@27056
   231
  \begin{descr}
wenzelm@27056
   232
wenzelm@27056
   233
  \item [@{command "cd"}~@{text path}] changes the current directory
wenzelm@27056
   234
  of the Isabelle process.
wenzelm@27056
   235
wenzelm@27056
   236
  \item [@{command "pwd"}] prints the current working directory.
wenzelm@27056
   237
wenzelm@27056
   238
  \item [@{command "use_thy"}~@{text A}] preload theory @{text A}.
wenzelm@27056
   239
  These system commands are scarcely used when working interactively,
wenzelm@27056
   240
  since loading of theories is done automatically as required.
wenzelm@27056
   241
wenzelm@27056
   242
  \end{descr}
wenzelm@27056
   243
*}
wenzelm@27056
   244
wenzelm@27056
   245
end