doc-src/IsarRef/Thy/Generic.thy
author wenzelm
Sun, 08 Jun 2008 14:30:07 +0200
changeset 27092 3d79bbdaf2ef
parent 27071 614c045c5fd4
child 27209 388fd72e9f26
permissions -rw-r--r--
simp: depth_limit is now a configuration option;
wenzelm@26782
     1
(* $Id$ *)
wenzelm@26782
     2
wenzelm@26782
     3
theory Generic
wenzelm@26894
     4
imports Main
wenzelm@26782
     5
begin
wenzelm@26782
     6
wenzelm@26782
     7
chapter {* Generic tools and packages \label{ch:gen-tools} *}
wenzelm@26782
     8
wenzelm@27040
     9
section {* Configuration options *}
wenzelm@26782
    10
wenzelm@26782
    11
text {*
wenzelm@26782
    12
  Isabelle/Pure maintains a record of named configuration options
wenzelm@26782
    13
  within the theory or proof context, with values of type @{ML_type
wenzelm@26782
    14
  bool}, @{ML_type int}, or @{ML_type string}.  Tools may declare
wenzelm@26782
    15
  options in ML, and then refer to these values (relative to the
wenzelm@26782
    16
  context).  Thus global reference variables are easily avoided.  The
wenzelm@26782
    17
  user may change the value of a configuration option by means of an
wenzelm@26782
    18
  associated attribute of the same name.  This form of context
wenzelm@26782
    19
  declaration works particularly well with commands such as @{command
wenzelm@26782
    20
  "declare"} or @{command "using"}.
wenzelm@26782
    21
wenzelm@26782
    22
  For historical reasons, some tools cannot take the full proof
wenzelm@26782
    23
  context into account and merely refer to the background theory.
wenzelm@26782
    24
  This is accommodated by configuration options being declared as
wenzelm@26782
    25
  ``global'', which may not be changed within a local context.
wenzelm@26782
    26
wenzelm@26782
    27
  \begin{matharray}{rcll}
wenzelm@26782
    28
    @{command_def "print_configs"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26782
    29
  \end{matharray}
wenzelm@26782
    30
wenzelm@26782
    31
  \begin{rail}
wenzelm@26782
    32
    name ('=' ('true' | 'false' | int | name))?
wenzelm@26782
    33
  \end{rail}
wenzelm@26782
    34
wenzelm@26782
    35
  \begin{descr}
wenzelm@26782
    36
  
wenzelm@26782
    37
  \item [@{command "print_configs"}] prints the available
wenzelm@26782
    38
  configuration options, with names, types, and current values.
wenzelm@26782
    39
  
wenzelm@26782
    40
  \item [@{text "name = value"}] as an attribute expression modifies
wenzelm@26782
    41
  the named option, with the syntax of the value depending on the
wenzelm@26782
    42
  option's type.  For @{ML_type bool} the default value is @{text
wenzelm@26782
    43
  true}.  Any attempt to change a global option in a local context is
wenzelm@26782
    44
  ignored.
wenzelm@26782
    45
wenzelm@26782
    46
  \end{descr}
wenzelm@26782
    47
*}
wenzelm@26782
    48
wenzelm@26782
    49
wenzelm@27040
    50
section {* Basic proof tools *}
wenzelm@26782
    51
wenzelm@26782
    52
subsection {* Miscellaneous methods and attributes \label{sec:misc-meth-att} *}
wenzelm@26782
    53
wenzelm@26782
    54
text {*
wenzelm@26782
    55
  \begin{matharray}{rcl}
wenzelm@26782
    56
    @{method_def unfold} & : & \isarmeth \\
wenzelm@26782
    57
    @{method_def fold} & : & \isarmeth \\
wenzelm@26782
    58
    @{method_def insert} & : & \isarmeth \\[0.5ex]
wenzelm@26782
    59
    @{method_def erule}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
    60
    @{method_def drule}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
    61
    @{method_def frule}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
    62
    @{method_def succeed} & : & \isarmeth \\
wenzelm@26782
    63
    @{method_def fail} & : & \isarmeth \\
wenzelm@26782
    64
  \end{matharray}
wenzelm@26782
    65
wenzelm@26782
    66
  \begin{rail}
wenzelm@26782
    67
    ('fold' | 'unfold' | 'insert') thmrefs
wenzelm@26782
    68
    ;
wenzelm@26782
    69
    ('erule' | 'drule' | 'frule') ('('nat')')? thmrefs
wenzelm@26782
    70
    ;
wenzelm@26782
    71
  \end{rail}
wenzelm@26782
    72
wenzelm@26782
    73
  \begin{descr}
wenzelm@26782
    74
  
wenzelm@26782
    75
  \item [@{method unfold}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and @{method
wenzelm@26782
    76
  fold}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] expand (or fold back) the
wenzelm@26782
    77
  given definitions throughout all goals; any chained facts provided
wenzelm@26782
    78
  are inserted into the goal and subject to rewriting as well.
wenzelm@26782
    79
wenzelm@26782
    80
  \item [@{method insert}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] inserts
wenzelm@26782
    81
  theorems as facts into all goals of the proof state.  Note that
wenzelm@26782
    82
  current facts indicated for forward chaining are ignored.
wenzelm@26782
    83
wenzelm@26782
    84
  \item [@{method erule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}, @{method
wenzelm@26782
    85
  drule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}, and @{method frule}~@{text
wenzelm@26782
    86
  "a\<^sub>1 \<dots> a\<^sub>n"}] are similar to the basic @{method rule}
wenzelm@26782
    87
  method (see \secref{sec:pure-meth-att}), but apply rules by
wenzelm@26782
    88
  elim-resolution, destruct-resolution, and forward-resolution,
wenzelm@26782
    89
  respectively \cite{isabelle-ref}.  The optional natural number
wenzelm@26782
    90
  argument (default 0) specifies additional assumption steps to be
wenzelm@26782
    91
  performed here.
wenzelm@26782
    92
wenzelm@26782
    93
  Note that these methods are improper ones, mainly serving for
wenzelm@26782
    94
  experimentation and tactic script emulation.  Different modes of
wenzelm@26782
    95
  basic rule application are usually expressed in Isar at the proof
wenzelm@26782
    96
  language level, rather than via implicit proof state manipulations.
wenzelm@26782
    97
  For example, a proper single-step elimination would be done using
wenzelm@26782
    98
  the plain @{method rule} method, with forward chaining of current
wenzelm@26782
    99
  facts.
wenzelm@26782
   100
wenzelm@26782
   101
  \item [@{method succeed}] yields a single (unchanged) result; it is
wenzelm@26782
   102
  the identity of the ``@{text ","}'' method combinator (cf.\
wenzelm@26782
   103
  \secref{sec:syn-meth}).
wenzelm@26782
   104
wenzelm@26782
   105
  \item [@{method fail}] yields an empty result sequence; it is the
wenzelm@26782
   106
  identity of the ``@{text "|"}'' method combinator (cf.\
wenzelm@26782
   107
  \secref{sec:syn-meth}).
wenzelm@26782
   108
wenzelm@26782
   109
  \end{descr}
wenzelm@26782
   110
wenzelm@26782
   111
  \begin{matharray}{rcl}
wenzelm@26782
   112
    @{attribute_def tagged} & : & \isaratt \\
wenzelm@26782
   113
    @{attribute_def untagged} & : & \isaratt \\[0.5ex]
wenzelm@26782
   114
    @{attribute_def THEN} & : & \isaratt \\
wenzelm@26782
   115
    @{attribute_def COMP} & : & \isaratt \\[0.5ex]
wenzelm@26782
   116
    @{attribute_def unfolded} & : & \isaratt \\
wenzelm@26782
   117
    @{attribute_def folded} & : & \isaratt \\[0.5ex]
wenzelm@26782
   118
    @{attribute_def rotated} & : & \isaratt \\
wenzelm@26782
   119
    @{attribute_def (Pure) elim_format} & : & \isaratt \\
wenzelm@26782
   120
    @{attribute_def standard}@{text "\<^sup>*"} & : & \isaratt \\
wenzelm@26782
   121
    @{attribute_def no_vars}@{text "\<^sup>*"} & : & \isaratt \\
wenzelm@26782
   122
  \end{matharray}
wenzelm@26782
   123
wenzelm@26782
   124
  \begin{rail}
wenzelm@26782
   125
    'tagged' nameref
wenzelm@26782
   126
    ;
wenzelm@26782
   127
    'untagged' name
wenzelm@26782
   128
    ;
wenzelm@26782
   129
    ('THEN' | 'COMP') ('[' nat ']')? thmref
wenzelm@26782
   130
    ;
wenzelm@26782
   131
    ('unfolded' | 'folded') thmrefs
wenzelm@26782
   132
    ;
wenzelm@26782
   133
    'rotated' ( int )?
wenzelm@26782
   134
  \end{rail}
wenzelm@26782
   135
wenzelm@26782
   136
  \begin{descr}
wenzelm@26782
   137
wenzelm@26782
   138
  \item [@{attribute tagged}~@{text "name arg"} and @{attribute
wenzelm@26782
   139
  untagged}~@{text name}] add and remove \emph{tags} of some theorem.
wenzelm@26782
   140
  Tags may be any list of string pairs that serve as formal comment.
wenzelm@26782
   141
  The first string is considered the tag name, the second its
wenzelm@26782
   142
  argument.  Note that @{attribute untagged} removes any tags of the
wenzelm@26782
   143
  same name.
wenzelm@26782
   144
wenzelm@26782
   145
  \item [@{attribute THEN}~@{text a} and @{attribute COMP}~@{text a}]
wenzelm@26782
   146
  compose rules by resolution.  @{attribute THEN} resolves with the
wenzelm@26782
   147
  first premise of @{text a} (an alternative position may be also
wenzelm@26782
   148
  specified); the @{attribute COMP} version skips the automatic
wenzelm@26782
   149
  lifting process that is normally intended (cf.\ @{ML "op RS"} and
wenzelm@26782
   150
  @{ML "op COMP"} in \cite[\S5]{isabelle-ref}).
wenzelm@26782
   151
  
wenzelm@26782
   152
  \item [@{attribute unfolded}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and
wenzelm@26782
   153
  @{attribute folded}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] expand and fold
wenzelm@26782
   154
  back again the given definitions throughout a rule.
wenzelm@26782
   155
wenzelm@26782
   156
  \item [@{attribute rotated}~@{text n}] rotate the premises of a
wenzelm@26782
   157
  theorem by @{text n} (default 1).
wenzelm@26782
   158
wenzelm@27044
   159
  \item [@{attribute (Pure) elim_format}] turns a destruction rule
wenzelm@27044
   160
  into elimination rule format, by resolving with the rule @{prop
wenzelm@27044
   161
  "PROP A \<Longrightarrow> (PROP A \<Longrightarrow> PROP B) \<Longrightarrow> PROP B"}.
wenzelm@26782
   162
  
wenzelm@26782
   163
  Note that the Classical Reasoner (\secref{sec:classical}) provides
wenzelm@26782
   164
  its own version of this operation.
wenzelm@26782
   165
wenzelm@26782
   166
  \item [@{attribute standard}] puts a theorem into the standard form
wenzelm@26782
   167
  of object-rules at the outermost theory level.  Note that this
wenzelm@26782
   168
  operation violates the local proof context (including active
wenzelm@26782
   169
  locales).
wenzelm@26782
   170
wenzelm@26782
   171
  \item [@{attribute no_vars}] replaces schematic variables by free
wenzelm@26782
   172
  ones; this is mainly for tuning output of pretty printed theorems.
wenzelm@26782
   173
wenzelm@26782
   174
  \end{descr}
wenzelm@26782
   175
*}
wenzelm@26782
   176
wenzelm@26782
   177
wenzelm@27044
   178
subsection {* Low-level equational reasoning *}
wenzelm@27044
   179
wenzelm@27044
   180
text {*
wenzelm@27044
   181
  \begin{matharray}{rcl}
wenzelm@27044
   182
    @{method_def subst} & : & \isarmeth \\
wenzelm@27044
   183
    @{method_def hypsubst} & : & \isarmeth \\
wenzelm@27044
   184
    @{method_def split} & : & \isarmeth \\
wenzelm@27044
   185
  \end{matharray}
wenzelm@27044
   186
wenzelm@27044
   187
  \begin{rail}
wenzelm@27044
   188
    'subst' ('(' 'asm' ')')? ('(' (nat+) ')')? thmref
wenzelm@27044
   189
    ;
wenzelm@27044
   190
    'split' ('(' 'asm' ')')? thmrefs
wenzelm@27044
   191
    ;
wenzelm@27044
   192
  \end{rail}
wenzelm@27044
   193
wenzelm@27044
   194
  These methods provide low-level facilities for equational reasoning
wenzelm@27044
   195
  that are intended for specialized applications only.  Normally,
wenzelm@27044
   196
  single step calculations would be performed in a structured text
wenzelm@27044
   197
  (see also \secref{sec:calculation}), while the Simplifier methods
wenzelm@27044
   198
  provide the canonical way for automated normalization (see
wenzelm@27044
   199
  \secref{sec:simplifier}).
wenzelm@27044
   200
wenzelm@27044
   201
  \begin{descr}
wenzelm@27044
   202
wenzelm@27044
   203
  \item [@{method subst}~@{text eq}] performs a single substitution
wenzelm@27044
   204
  step using rule @{text eq}, which may be either a meta or object
wenzelm@27044
   205
  equality.
wenzelm@27044
   206
wenzelm@27044
   207
  \item [@{method subst}~@{text "(asm) eq"}] substitutes in an
wenzelm@27044
   208
  assumption.
wenzelm@27044
   209
wenzelm@27044
   210
  \item [@{method subst}~@{text "(i \<dots> j) eq"}] performs several
wenzelm@27044
   211
  substitutions in the conclusion. The numbers @{text i} to @{text j}
wenzelm@27044
   212
  indicate the positions to substitute at.  Positions are ordered from
wenzelm@27044
   213
  the top of the term tree moving down from left to right. For
wenzelm@27044
   214
  example, in @{text "(a + b) + (c + d)"} there are three positions
wenzelm@27071
   215
  where commutativity of @{text "+"} is applicable: 1 refers to
wenzelm@27071
   216
  @{text "a + b"}, 2 to the whole term, and 3 to @{text "c + d"}.
wenzelm@27044
   217
wenzelm@27044
   218
  If the positions in the list @{text "(i \<dots> j)"} are non-overlapping
wenzelm@27044
   219
  (e.g.\ @{text "(2 3)"} in @{text "(a + b) + (c + d)"}) you may
wenzelm@27044
   220
  assume all substitutions are performed simultaneously.  Otherwise
wenzelm@27044
   221
  the behaviour of @{text subst} is not specified.
wenzelm@27044
   222
wenzelm@27044
   223
  \item [@{method subst}~@{text "(asm) (i \<dots> j) eq"}] performs the
wenzelm@27071
   224
  substitutions in the assumptions. The positions refer to the
wenzelm@27071
   225
  assumptions in order from left to right.  For example, given in a
wenzelm@27071
   226
  goal of the form @{text "P (a + b) \<Longrightarrow> P (c + d) \<Longrightarrow> \<dots>"}, position 1 of
wenzelm@27071
   227
  commutativity of @{text "+"} is the subterm @{text "a + b"} and
wenzelm@27071
   228
  position 2 is the subterm @{text "c + d"}.
wenzelm@27044
   229
wenzelm@27044
   230
  \item [@{method hypsubst}] performs substitution using some
wenzelm@27044
   231
  assumption; this only works for equations of the form @{text "x =
wenzelm@27044
   232
  t"} where @{text x} is a free or bound variable.
wenzelm@27044
   233
wenzelm@27044
   234
  \item [@{method split}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}] performs
wenzelm@27044
   235
  single-step case splitting using the given rules.  By default,
wenzelm@27044
   236
  splitting is performed in the conclusion of a goal; the @{text
wenzelm@27044
   237
  "(asm)"} option indicates to operate on assumptions instead.
wenzelm@27044
   238
  
wenzelm@27044
   239
  Note that the @{method simp} method already involves repeated
wenzelm@27044
   240
  application of split rules as declared in the current context.
wenzelm@27044
   241
wenzelm@27044
   242
  \end{descr}
wenzelm@27044
   243
*}
wenzelm@27044
   244
wenzelm@27044
   245
wenzelm@26782
   246
subsection {* Further tactic emulations \label{sec:tactics} *}
wenzelm@26782
   247
wenzelm@26782
   248
text {*
wenzelm@26782
   249
  The following improper proof methods emulate traditional tactics.
wenzelm@26782
   250
  These admit direct access to the goal state, which is normally
wenzelm@26782
   251
  considered harmful!  In particular, this may involve both numbered
wenzelm@26782
   252
  goal addressing (default 1), and dynamic instantiation within the
wenzelm@26782
   253
  scope of some subgoal.
wenzelm@26782
   254
wenzelm@26782
   255
  \begin{warn}
wenzelm@26782
   256
    Dynamic instantiations refer to universally quantified parameters
wenzelm@26782
   257
    of a subgoal (the dynamic context) rather than fixed variables and
wenzelm@26782
   258
    term abbreviations of a (static) Isar context.
wenzelm@26782
   259
  \end{warn}
wenzelm@26782
   260
wenzelm@26782
   261
  Tactic emulation methods, unlike their ML counterparts, admit
wenzelm@26782
   262
  simultaneous instantiation from both dynamic and static contexts.
wenzelm@26782
   263
  If names occur in both contexts goal parameters hide locally fixed
wenzelm@26782
   264
  variables.  Likewise, schematic variables refer to term
wenzelm@26782
   265
  abbreviations, if present in the static context.  Otherwise the
wenzelm@26782
   266
  schematic variable is interpreted as a schematic variable and left
wenzelm@26782
   267
  to be solved by unification with certain parts of the subgoal.
wenzelm@26782
   268
wenzelm@26782
   269
  Note that the tactic emulation proof methods in Isabelle/Isar are
wenzelm@26782
   270
  consistently named @{text foo_tac}.  Note also that variable names
wenzelm@26782
   271
  occurring on left hand sides of instantiations must be preceded by a
wenzelm@26782
   272
  question mark if they coincide with a keyword or contain dots.  This
wenzelm@26782
   273
  is consistent with the attribute @{attribute "where"} (see
wenzelm@26782
   274
  \secref{sec:pure-meth-att}).
wenzelm@26782
   275
wenzelm@26782
   276
  \begin{matharray}{rcl}
wenzelm@26782
   277
    @{method_def rule_tac}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   278
    @{method_def erule_tac}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   279
    @{method_def drule_tac}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   280
    @{method_def frule_tac}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   281
    @{method_def cut_tac}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   282
    @{method_def thin_tac}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   283
    @{method_def subgoal_tac}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   284
    @{method_def rename_tac}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   285
    @{method_def rotate_tac}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   286
    @{method_def tactic}@{text "\<^sup>*"} & : & \isarmeth \\
wenzelm@26782
   287
  \end{matharray}
wenzelm@26782
   288
wenzelm@26782
   289
  \begin{rail}
wenzelm@26782
   290
    ( 'rule\_tac' | 'erule\_tac' | 'drule\_tac' | 'frule\_tac' | 'cut\_tac' | 'thin\_tac' ) goalspec?
wenzelm@26782
   291
    ( insts thmref | thmrefs )
wenzelm@26782
   292
    ;
wenzelm@26782
   293
    'subgoal\_tac' goalspec? (prop +)
wenzelm@26782
   294
    ;
wenzelm@26782
   295
    'rename\_tac' goalspec? (name +)
wenzelm@26782
   296
    ;
wenzelm@26782
   297
    'rotate\_tac' goalspec? int?
wenzelm@26782
   298
    ;
wenzelm@26782
   299
    'tactic' text
wenzelm@26782
   300
    ;
wenzelm@26782
   301
wenzelm@26782
   302
    insts: ((name '=' term) + 'and') 'in'
wenzelm@26782
   303
    ;
wenzelm@26782
   304
  \end{rail}
wenzelm@26782
   305
wenzelm@26782
   306
\begin{descr}
wenzelm@26782
   307
wenzelm@26782
   308
  \item [@{method rule_tac} etc.] do resolution of rules with explicit
wenzelm@26782
   309
  instantiation.  This works the same way as the ML tactics @{ML
wenzelm@26782
   310
  res_inst_tac} etc. (see \cite[\S3]{isabelle-ref}).
wenzelm@26782
   311
wenzelm@26782
   312
  Multiple rules may be only given if there is no instantiation; then
wenzelm@26782
   313
  @{method rule_tac} is the same as @{ML resolve_tac} in ML (see
wenzelm@26782
   314
  \cite[\S3]{isabelle-ref}).
wenzelm@26782
   315
wenzelm@26782
   316
  \item [@{method cut_tac}] inserts facts into the proof state as
wenzelm@26782
   317
  assumption of a subgoal, see also @{ML cut_facts_tac} in
wenzelm@26782
   318
  \cite[\S3]{isabelle-ref}.  Note that the scope of schematic
wenzelm@26782
   319
  variables is spread over the main goal statement.  Instantiations
wenzelm@26782
   320
  may be given as well, see also ML tactic @{ML cut_inst_tac} in
wenzelm@26782
   321
  \cite[\S3]{isabelle-ref}.
wenzelm@26782
   322
wenzelm@26782
   323
  \item [@{method thin_tac}~@{text \<phi>}] deletes the specified
wenzelm@26782
   324
  assumption from a subgoal; note that @{text \<phi>} may contain schematic
wenzelm@26782
   325
  variables.  See also @{ML thin_tac} in \cite[\S3]{isabelle-ref}.
wenzelm@26782
   326
wenzelm@26782
   327
  \item [@{method subgoal_tac}~@{text \<phi>}] adds @{text \<phi>} as an
wenzelm@26782
   328
  assumption to a subgoal.  See also @{ML subgoal_tac} and @{ML
wenzelm@26782
   329
  subgoals_tac} in \cite[\S3]{isabelle-ref}.
wenzelm@26782
   330
wenzelm@26782
   331
  \item [@{method rename_tac}~@{text "x\<^sub>1 \<dots> x\<^sub>n"}] renames
wenzelm@26782
   332
  parameters of a goal according to the list @{text "x\<^sub>1, \<dots>,
wenzelm@26782
   333
  x\<^sub>n"}, which refers to the \emph{suffix} of variables.
wenzelm@26782
   334
wenzelm@26782
   335
  \item [@{method rotate_tac}~@{text n}] rotates the assumptions of a
wenzelm@26782
   336
  goal by @{text n} positions: from right to left if @{text n} is
wenzelm@26782
   337
  positive, and from left to right if @{text n} is negative; the
wenzelm@26782
   338
  default value is 1.  See also @{ML rotate_tac} in
wenzelm@26782
   339
  \cite[\S3]{isabelle-ref}.
wenzelm@26782
   340
wenzelm@26782
   341
  \item [@{method tactic}~@{text "text"}] produces a proof method from
wenzelm@26782
   342
  any ML text of type @{ML_type tactic}.  Apart from the usual ML
wenzelm@26782
   343
  environment and the current implicit theory context, the ML code may
wenzelm@26782
   344
  refer to the following locally bound values:
wenzelm@26782
   345
wenzelm@26782
   346
%FIXME check
wenzelm@26782
   347
{\footnotesize\begin{verbatim}
wenzelm@26782
   348
val ctxt  : Proof.context
wenzelm@26782
   349
val facts : thm list
wenzelm@26782
   350
val thm   : string -> thm
wenzelm@26782
   351
val thms  : string -> thm list
wenzelm@26782
   352
\end{verbatim}}
wenzelm@26782
   353
wenzelm@26782
   354
  Here @{ML_text ctxt} refers to the current proof context, @{ML_text
wenzelm@26782
   355
  facts} indicates any current facts for forward-chaining, and @{ML
wenzelm@26782
   356
  thm}~/~@{ML thms} retrieve named facts (including global theorems)
wenzelm@26782
   357
  from the context.
wenzelm@26782
   358
wenzelm@26782
   359
  \end{descr}
wenzelm@26782
   360
*}
wenzelm@26782
   361
wenzelm@26782
   362
wenzelm@27040
   363
section {* The Simplifier \label{sec:simplifier} *}
wenzelm@26782
   364
wenzelm@27040
   365
subsection {* Simplification methods *}
wenzelm@26782
   366
wenzelm@26782
   367
text {*
wenzelm@26782
   368
  \begin{matharray}{rcl}
wenzelm@26782
   369
    @{method_def simp} & : & \isarmeth \\
wenzelm@26782
   370
    @{method_def simp_all} & : & \isarmeth \\
wenzelm@26782
   371
  \end{matharray}
wenzelm@26782
   372
wenzelm@26782
   373
  \indexouternonterm{simpmod}
wenzelm@26782
   374
  \begin{rail}
wenzelm@26782
   375
    ('simp' | 'simp\_all') ('!' ?) opt? (simpmod *)
wenzelm@26782
   376
    ;
wenzelm@26782
   377
wenzelm@27092
   378
    opt: '(' ('no\_asm' | 'no\_asm\_simp' | 'no\_asm\_use' | 'asm\_lr' ) ')'
wenzelm@26782
   379
    ;
wenzelm@26782
   380
    simpmod: ('add' | 'del' | 'only' | 'cong' (() | 'add' | 'del') |
wenzelm@26782
   381
      'split' (() | 'add' | 'del')) ':' thmrefs
wenzelm@26782
   382
    ;
wenzelm@26782
   383
  \end{rail}
wenzelm@26782
   384
wenzelm@26782
   385
  \begin{descr}
wenzelm@26782
   386
wenzelm@26782
   387
  \item [@{method simp}] invokes the Simplifier, after declaring
wenzelm@26782
   388
  additional rules according to the arguments given.  Note that the
wenzelm@26782
   389
  \railtterm{only} modifier first removes all other rewrite rules,
wenzelm@26782
   390
  congruences, and looper tactics (including splits), and then behaves
wenzelm@26782
   391
  like \railtterm{add}.
wenzelm@26782
   392
wenzelm@26782
   393
  \medskip The \railtterm{cong} modifiers add or delete Simplifier
wenzelm@26782
   394
  congruence rules (see also \cite{isabelle-ref}), the default is to
wenzelm@26782
   395
  add.
wenzelm@26782
   396
wenzelm@26782
   397
  \medskip The \railtterm{split} modifiers add or delete rules for the
wenzelm@26782
   398
  Splitter (see also \cite{isabelle-ref}), the default is to add.
wenzelm@26782
   399
  This works only if the Simplifier method has been properly setup to
wenzelm@26782
   400
  include the Splitter (all major object logics such HOL, HOLCF, FOL,
wenzelm@26782
   401
  ZF do this already).
wenzelm@26782
   402
wenzelm@26782
   403
  \item [@{method simp_all}] is similar to @{method simp}, but acts on
wenzelm@26782
   404
  all goals (backwards from the last to the first one).
wenzelm@26782
   405
wenzelm@26782
   406
  \end{descr}
wenzelm@26782
   407
wenzelm@26782
   408
  By default the Simplifier methods take local assumptions fully into
wenzelm@26782
   409
  account, using equational assumptions in the subsequent
wenzelm@26782
   410
  normalization process, or simplifying assumptions themselves (cf.\
wenzelm@26782
   411
  @{ML asm_full_simp_tac} in \cite[\S10]{isabelle-ref}).  In
wenzelm@26782
   412
  structured proofs this is usually quite well behaved in practice:
wenzelm@26782
   413
  just the local premises of the actual goal are involved, additional
wenzelm@26782
   414
  facts may be inserted via explicit forward-chaining (via @{command
wenzelm@26782
   415
  "then"}, @{command "from"}, @{command "using"} etc.).  The full
wenzelm@26782
   416
  context of premises is only included if the ``@{text "!"}'' (bang)
wenzelm@26782
   417
  argument is given, which should be used with some care, though.
wenzelm@26782
   418
wenzelm@26782
   419
  Additional Simplifier options may be specified to tune the behavior
wenzelm@26782
   420
  further (mostly for unstructured scripts with many accidental local
wenzelm@26782
   421
  facts): ``@{text "(no_asm)"}'' means assumptions are ignored
wenzelm@26782
   422
  completely (cf.\ @{ML simp_tac}), ``@{text "(no_asm_simp)"}'' means
wenzelm@26782
   423
  assumptions are used in the simplification of the conclusion but are
wenzelm@26782
   424
  not themselves simplified (cf.\ @{ML asm_simp_tac}), and ``@{text
wenzelm@26782
   425
  "(no_asm_use)"}'' means assumptions are simplified but are not used
wenzelm@26782
   426
  in the simplification of each other or the conclusion (cf.\ @{ML
wenzelm@26782
   427
  full_simp_tac}).  For compatibility reasons, there is also an option
wenzelm@26782
   428
  ``@{text "(asm_lr)"}'', which means that an assumption is only used
wenzelm@26782
   429
  for simplifying assumptions which are to the right of it (cf.\ @{ML
wenzelm@26782
   430
  asm_lr_simp_tac}).
wenzelm@26782
   431
wenzelm@27092
   432
  The configuration option @{text "depth_limit"} limits the number of
wenzelm@26782
   433
  recursive invocations of the simplifier during conditional
wenzelm@26782
   434
  rewriting.
wenzelm@26782
   435
wenzelm@26782
   436
  \medskip The Splitter package is usually configured to work as part
wenzelm@26782
   437
  of the Simplifier.  The effect of repeatedly applying @{ML
wenzelm@26782
   438
  split_tac} can be simulated by ``@{text "(simp only: split:
wenzelm@26782
   439
  a\<^sub>1 \<dots> a\<^sub>n)"}''.  There is also a separate @{text split}
wenzelm@26782
   440
  method available for single-step case splitting.
wenzelm@26782
   441
*}
wenzelm@26782
   442
wenzelm@26782
   443
wenzelm@27040
   444
subsection {* Declaring rules *}
wenzelm@26782
   445
wenzelm@26782
   446
text {*
wenzelm@26782
   447
  \begin{matharray}{rcl}
wenzelm@26782
   448
    @{command_def "print_simpset"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26782
   449
    @{attribute_def simp} & : & \isaratt \\
wenzelm@26782
   450
    @{attribute_def cong} & : & \isaratt \\
wenzelm@26782
   451
    @{attribute_def split} & : & \isaratt \\
wenzelm@26782
   452
  \end{matharray}
wenzelm@26782
   453
wenzelm@26782
   454
  \begin{rail}
wenzelm@26782
   455
    ('simp' | 'cong' | 'split') (() | 'add' | 'del')
wenzelm@26782
   456
    ;
wenzelm@26782
   457
  \end{rail}
wenzelm@26782
   458
wenzelm@26782
   459
  \begin{descr}
wenzelm@26782
   460
wenzelm@26782
   461
  \item [@{command "print_simpset"}] prints the collection of rules
wenzelm@26782
   462
  declared to the Simplifier, which is also known as ``simpset''
wenzelm@26782
   463
  internally \cite{isabelle-ref}.
wenzelm@26782
   464
wenzelm@26782
   465
  \item [@{attribute simp}] declares simplification rules.
wenzelm@26782
   466
wenzelm@26782
   467
  \item [@{attribute cong}] declares congruence rules.
wenzelm@26782
   468
wenzelm@26782
   469
  \item [@{attribute split}] declares case split rules.
wenzelm@26782
   470
wenzelm@26782
   471
  \end{descr}
wenzelm@26782
   472
*}
wenzelm@26782
   473
wenzelm@26782
   474
wenzelm@27040
   475
subsection {* Simplification procedures *}
wenzelm@26782
   476
wenzelm@26782
   477
text {*
wenzelm@26782
   478
  \begin{matharray}{rcl}
wenzelm@26782
   479
    @{command_def "simproc_setup"} & : & \isarkeep{local{\dsh}theory} \\
wenzelm@26782
   480
    simproc & : & \isaratt \\
wenzelm@26782
   481
  \end{matharray}
wenzelm@26782
   482
wenzelm@26782
   483
  \begin{rail}
wenzelm@26782
   484
    'simproc\_setup' name '(' (term + '|') ')' '=' text \\ ('identifier' (nameref+))?
wenzelm@26782
   485
    ;
wenzelm@26782
   486
wenzelm@26782
   487
    'simproc' (('add' ':')? | 'del' ':') (name+)
wenzelm@26782
   488
    ;
wenzelm@26782
   489
  \end{rail}
wenzelm@26782
   490
wenzelm@26782
   491
  \begin{descr}
wenzelm@26782
   492
wenzelm@26782
   493
  \item [@{command "simproc_setup"}] defines a named simplification
wenzelm@26782
   494
  procedure that is invoked by the Simplifier whenever any of the
wenzelm@26782
   495
  given term patterns match the current redex.  The implementation,
wenzelm@26782
   496
  which is provided as ML source text, needs to be of type @{ML_type
wenzelm@26782
   497
  "morphism -> simpset -> cterm -> thm option"}, where the @{ML_type
wenzelm@26782
   498
  cterm} represents the current redex @{text r} and the result is
wenzelm@26782
   499
  supposed to be some proven rewrite rule @{text "r \<equiv> r'"} (or a
wenzelm@26782
   500
  generalized version), or @{ML NONE} to indicate failure.  The
wenzelm@26782
   501
  @{ML_type simpset} argument holds the full context of the current
wenzelm@26782
   502
  Simplifier invocation, including the actual Isar proof context.  The
wenzelm@26782
   503
  @{ML_type morphism} informs about the difference of the original
wenzelm@26782
   504
  compilation context wrt.\ the one of the actual application later
wenzelm@26782
   505
  on.  The optional @{keyword "identifier"} specifies theorems that
wenzelm@26782
   506
  represent the logical content of the abstract theory of this
wenzelm@26782
   507
  simproc.
wenzelm@26782
   508
wenzelm@26782
   509
  Morphisms and identifiers are only relevant for simprocs that are
wenzelm@26782
   510
  defined within a local target context, e.g.\ in a locale.
wenzelm@26782
   511
wenzelm@26782
   512
  \item [@{text "simproc add: name"} and @{text "simproc del: name"}]
wenzelm@26782
   513
  add or delete named simprocs to the current Simplifier context.  The
wenzelm@26782
   514
  default is to add a simproc.  Note that @{command "simproc_setup"}
wenzelm@26782
   515
  already adds the new simproc to the subsequent context.
wenzelm@26782
   516
wenzelm@26782
   517
  \end{descr}
wenzelm@26782
   518
*}
wenzelm@26782
   519
wenzelm@26782
   520
wenzelm@27040
   521
subsection {* Forward simplification *}
wenzelm@26782
   522
wenzelm@26782
   523
text {*
wenzelm@26782
   524
  \begin{matharray}{rcl}
wenzelm@26782
   525
    @{attribute_def simplified} & : & \isaratt \\
wenzelm@26782
   526
  \end{matharray}
wenzelm@26782
   527
wenzelm@26782
   528
  \begin{rail}
wenzelm@26782
   529
    'simplified' opt? thmrefs?
wenzelm@26782
   530
    ;
wenzelm@26782
   531
wenzelm@26789
   532
    opt: '(' ('no\_asm' | 'no\_asm\_simp' | 'no\_asm\_use') ')'
wenzelm@26782
   533
    ;
wenzelm@26782
   534
  \end{rail}
wenzelm@26782
   535
wenzelm@26782
   536
  \begin{descr}
wenzelm@26782
   537
  
wenzelm@26782
   538
  \item [@{attribute simplified}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}]
wenzelm@26782
   539
  causes a theorem to be simplified, either by exactly the specified
wenzelm@26782
   540
  rules @{text "a\<^sub>1, \<dots>, a\<^sub>n"}, or the implicit Simplifier
wenzelm@26782
   541
  context if no arguments are given.  The result is fully simplified
wenzelm@26782
   542
  by default, including assumptions and conclusion; the options @{text
wenzelm@26782
   543
  no_asm} etc.\ tune the Simplifier in the same way as the for the
wenzelm@26782
   544
  @{text simp} method.
wenzelm@26782
   545
wenzelm@26782
   546
  Note that forward simplification restricts the simplifier to its
wenzelm@26782
   547
  most basic operation of term rewriting; solver and looper tactics
wenzelm@26782
   548
  \cite{isabelle-ref} are \emph{not} involved here.  The @{text
wenzelm@26782
   549
  simplified} attribute should be only rarely required under normal
wenzelm@26782
   550
  circumstances.
wenzelm@26782
   551
wenzelm@26782
   552
  \end{descr}
wenzelm@26782
   553
*}
wenzelm@26782
   554
wenzelm@26782
   555
wenzelm@27040
   556
section {* The Classical Reasoner \label{sec:classical} *}
wenzelm@26782
   557
wenzelm@27040
   558
subsection {* Basic methods *}
wenzelm@26782
   559
wenzelm@26782
   560
text {*
wenzelm@26782
   561
  \begin{matharray}{rcl}
wenzelm@26782
   562
    @{method_def rule} & : & \isarmeth \\
wenzelm@26782
   563
    @{method_def contradiction} & : & \isarmeth \\
wenzelm@26782
   564
    @{method_def intro} & : & \isarmeth \\
wenzelm@26782
   565
    @{method_def elim} & : & \isarmeth \\
wenzelm@26782
   566
  \end{matharray}
wenzelm@26782
   567
wenzelm@26782
   568
  \begin{rail}
wenzelm@26782
   569
    ('rule' | 'intro' | 'elim') thmrefs?
wenzelm@26782
   570
    ;
wenzelm@26782
   571
  \end{rail}
wenzelm@26782
   572
wenzelm@26782
   573
  \begin{descr}
wenzelm@26782
   574
wenzelm@26782
   575
  \item [@{method rule}] as offered by the Classical Reasoner is a
wenzelm@26782
   576
  refinement over the primitive one (see \secref{sec:pure-meth-att}).
wenzelm@26782
   577
  Both versions essentially work the same, but the classical version
wenzelm@26782
   578
  observes the classical rule context in addition to that of
wenzelm@26782
   579
  Isabelle/Pure.
wenzelm@26782
   580
wenzelm@26782
   581
  Common object logics (HOL, ZF, etc.) declare a rich collection of
wenzelm@26782
   582
  classical rules (even if these would qualify as intuitionistic
wenzelm@26782
   583
  ones), but only few declarations to the rule context of
wenzelm@26782
   584
  Isabelle/Pure (\secref{sec:pure-meth-att}).
wenzelm@26782
   585
wenzelm@26782
   586
  \item [@{method contradiction}] solves some goal by contradiction,
wenzelm@26782
   587
  deriving any result from both @{text "\<not> A"} and @{text A}.  Chained
wenzelm@26782
   588
  facts, which are guaranteed to participate, may appear in either
wenzelm@26782
   589
  order.
wenzelm@26782
   590
wenzelm@26901
   591
  \item [@{method intro} and @{method elim}] repeatedly refine some
wenzelm@26901
   592
  goal by intro- or elim-resolution, after having inserted any chained
wenzelm@26901
   593
  facts.  Exactly the rules given as arguments are taken into account;
wenzelm@26901
   594
  this allows fine-tuned decomposition of a proof problem, in contrast
wenzelm@26901
   595
  to common automated tools.
wenzelm@26782
   596
wenzelm@26782
   597
  \end{descr}
wenzelm@26782
   598
*}
wenzelm@26782
   599
wenzelm@26782
   600
wenzelm@27040
   601
subsection {* Automated methods *}
wenzelm@26782
   602
wenzelm@26782
   603
text {*
wenzelm@26782
   604
  \begin{matharray}{rcl}
wenzelm@26782
   605
    @{method_def blast} & : & \isarmeth \\
wenzelm@26782
   606
    @{method_def fast} & : & \isarmeth \\
wenzelm@26782
   607
    @{method_def slow} & : & \isarmeth \\
wenzelm@26782
   608
    @{method_def best} & : & \isarmeth \\
wenzelm@26782
   609
    @{method_def safe} & : & \isarmeth \\
wenzelm@26782
   610
    @{method_def clarify} & : & \isarmeth \\
wenzelm@26782
   611
  \end{matharray}
wenzelm@26782
   612
wenzelm@26782
   613
  \indexouternonterm{clamod}
wenzelm@26782
   614
  \begin{rail}
wenzelm@26782
   615
    'blast' ('!' ?) nat? (clamod *)
wenzelm@26782
   616
    ;
wenzelm@26782
   617
    ('fast' | 'slow' | 'best' | 'safe' | 'clarify') ('!' ?) (clamod *)
wenzelm@26782
   618
    ;
wenzelm@26782
   619
wenzelm@26782
   620
    clamod: (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del') ':' thmrefs
wenzelm@26782
   621
    ;
wenzelm@26782
   622
  \end{rail}
wenzelm@26782
   623
wenzelm@26782
   624
  \begin{descr}
wenzelm@26782
   625
wenzelm@26782
   626
  \item [@{method blast}] refers to the classical tableau prover (see
wenzelm@26782
   627
  @{ML blast_tac} in \cite[\S11]{isabelle-ref}).  The optional
wenzelm@26782
   628
  argument specifies a user-supplied search bound (default 20).
wenzelm@26782
   629
wenzelm@26782
   630
  \item [@{method fast}, @{method slow}, @{method best}, @{method
wenzelm@26782
   631
  safe}, and @{method clarify}] refer to the generic classical
wenzelm@26782
   632
  reasoner.  See @{ML fast_tac}, @{ML slow_tac}, @{ML best_tac}, @{ML
wenzelm@26782
   633
  safe_tac}, and @{ML clarify_tac} in \cite[\S11]{isabelle-ref} for
wenzelm@26782
   634
  more information.
wenzelm@26782
   635
wenzelm@26782
   636
  \end{descr}
wenzelm@26782
   637
wenzelm@26782
   638
  Any of the above methods support additional modifiers of the context
wenzelm@26782
   639
  of classical rules.  Their semantics is analogous to the attributes
wenzelm@26782
   640
  given before.  Facts provided by forward chaining are inserted into
wenzelm@26782
   641
  the goal before commencing proof search.  The ``@{text
wenzelm@26782
   642
  "!"}''~argument causes the full context of assumptions to be
wenzelm@26782
   643
  included as well.
wenzelm@26782
   644
*}
wenzelm@26782
   645
wenzelm@26782
   646
wenzelm@27040
   647
subsection {* Combined automated methods \label{sec:clasimp} *}
wenzelm@26782
   648
wenzelm@26782
   649
text {*
wenzelm@26782
   650
  \begin{matharray}{rcl}
wenzelm@26782
   651
    @{method_def auto} & : & \isarmeth \\
wenzelm@26782
   652
    @{method_def force} & : & \isarmeth \\
wenzelm@26782
   653
    @{method_def clarsimp} & : & \isarmeth \\
wenzelm@26782
   654
    @{method_def fastsimp} & : & \isarmeth \\
wenzelm@26782
   655
    @{method_def slowsimp} & : & \isarmeth \\
wenzelm@26782
   656
    @{method_def bestsimp} & : & \isarmeth \\
wenzelm@26782
   657
  \end{matharray}
wenzelm@26782
   658
wenzelm@26782
   659
  \indexouternonterm{clasimpmod}
wenzelm@26782
   660
  \begin{rail}
wenzelm@26782
   661
    'auto' '!'? (nat nat)? (clasimpmod *)
wenzelm@26782
   662
    ;
wenzelm@26782
   663
    ('force' | 'clarsimp' | 'fastsimp' | 'slowsimp' | 'bestsimp') '!'? (clasimpmod *)
wenzelm@26782
   664
    ;
wenzelm@26782
   665
wenzelm@26782
   666
    clasimpmod: ('simp' (() | 'add' | 'del' | 'only') |
wenzelm@26782
   667
      ('cong' | 'split') (() | 'add' | 'del') |
wenzelm@26782
   668
      'iff' (((() | 'add') '?'?) | 'del') |
wenzelm@26782
   669
      (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del')) ':' thmrefs
wenzelm@26782
   670
  \end{rail}
wenzelm@26782
   671
wenzelm@26782
   672
  \begin{descr}
wenzelm@26782
   673
wenzelm@26782
   674
  \item [@{method auto}, @{method force}, @{method clarsimp}, @{method
wenzelm@26782
   675
  fastsimp}, @{method slowsimp}, and @{method bestsimp}] provide
wenzelm@26782
   676
  access to Isabelle's combined simplification and classical reasoning
wenzelm@26782
   677
  tactics.  These correspond to @{ML auto_tac}, @{ML force_tac}, @{ML
wenzelm@26782
   678
  clarsimp_tac}, and Classical Reasoner tactics with the Simplifier
wenzelm@26782
   679
  added as wrapper, see \cite[\S11]{isabelle-ref} for more
wenzelm@26782
   680
  information.  The modifier arguments correspond to those given in
wenzelm@26782
   681
  \secref{sec:simplifier} and \secref{sec:classical}.  Just note that
wenzelm@26782
   682
  the ones related to the Simplifier are prefixed by \railtterm{simp}
wenzelm@26782
   683
  here.
wenzelm@26782
   684
wenzelm@26782
   685
  Facts provided by forward chaining are inserted into the goal before
wenzelm@26782
   686
  doing the search.  The ``@{text "!"}'' argument causes the full
wenzelm@26782
   687
  context of assumptions to be included as well.
wenzelm@26782
   688
wenzelm@26782
   689
  \end{descr}
wenzelm@26782
   690
*}
wenzelm@26782
   691
wenzelm@26782
   692
wenzelm@27040
   693
subsection {* Declaring rules *}
wenzelm@26782
   694
wenzelm@26782
   695
text {*
wenzelm@26782
   696
  \begin{matharray}{rcl}
wenzelm@26782
   697
    @{command_def "print_claset"}@{text "\<^sup>*"} & : & \isarkeep{theory~|~proof} \\
wenzelm@26782
   698
    @{attribute_def intro} & : & \isaratt \\
wenzelm@26782
   699
    @{attribute_def elim} & : & \isaratt \\
wenzelm@26782
   700
    @{attribute_def dest} & : & \isaratt \\
wenzelm@26782
   701
    @{attribute_def rule} & : & \isaratt \\
wenzelm@26782
   702
    @{attribute_def iff} & : & \isaratt \\
wenzelm@26782
   703
  \end{matharray}
wenzelm@26782
   704
wenzelm@26782
   705
  \begin{rail}
wenzelm@26782
   706
    ('intro' | 'elim' | 'dest') ('!' | () | '?') nat?
wenzelm@26782
   707
    ;
wenzelm@26782
   708
    'rule' 'del'
wenzelm@26782
   709
    ;
wenzelm@26782
   710
    'iff' (((() | 'add') '?'?) | 'del')
wenzelm@26782
   711
    ;
wenzelm@26782
   712
  \end{rail}
wenzelm@26782
   713
wenzelm@26782
   714
  \begin{descr}
wenzelm@26782
   715
wenzelm@26782
   716
  \item [@{command "print_claset"}] prints the collection of rules
wenzelm@26782
   717
  declared to the Classical Reasoner, which is also known as
wenzelm@26782
   718
  ``claset'' internally \cite{isabelle-ref}.
wenzelm@26782
   719
  
wenzelm@26782
   720
  \item [@{attribute intro}, @{attribute elim}, and @{attribute dest}]
wenzelm@26782
   721
  declare introduction, elimination, and destruction rules,
wenzelm@26782
   722
  respectively.  By default, rules are considered as \emph{unsafe}
wenzelm@26782
   723
  (i.e.\ not applied blindly without backtracking), while ``@{text
wenzelm@26782
   724
  "!"}'' classifies as \emph{safe}.  Rule declarations marked by
wenzelm@26782
   725
  ``@{text "?"}'' coincide with those of Isabelle/Pure, cf.\
wenzelm@26782
   726
  \secref{sec:pure-meth-att} (i.e.\ are only applied in single steps
wenzelm@26782
   727
  of the @{method rule} method).  The optional natural number
wenzelm@26782
   728
  specifies an explicit weight argument, which is ignored by automated
wenzelm@26782
   729
  tools, but determines the search order of single rule steps.
wenzelm@26782
   730
wenzelm@26782
   731
  \item [@{attribute rule}~@{text del}] deletes introduction,
wenzelm@26782
   732
  elimination, or destruction rules from the context.
wenzelm@26782
   733
wenzelm@26782
   734
  \item [@{attribute iff}] declares logical equivalences to the
wenzelm@26782
   735
  Simplifier and the Classical reasoner at the same time.
wenzelm@26782
   736
  Non-conditional rules result in a ``safe'' introduction and
wenzelm@26782
   737
  elimination pair; conditional ones are considered ``unsafe''.  Rules
wenzelm@26782
   738
  with negative conclusion are automatically inverted (using @{text
wenzelm@26789
   739
  "\<not>"}-elimination internally).
wenzelm@26782
   740
wenzelm@26782
   741
  The ``@{text "?"}'' version of @{attribute iff} declares rules to
wenzelm@26782
   742
  the Isabelle/Pure context only, and omits the Simplifier
wenzelm@26782
   743
  declaration.
wenzelm@26782
   744
wenzelm@26782
   745
  \end{descr}
wenzelm@26782
   746
*}
wenzelm@26782
   747
wenzelm@26782
   748
wenzelm@27040
   749
subsection {* Classical operations *}
wenzelm@26782
   750
wenzelm@26782
   751
text {*
wenzelm@26782
   752
  \begin{matharray}{rcl}
wenzelm@26782
   753
    @{attribute_def swapped} & : & \isaratt \\
wenzelm@26782
   754
  \end{matharray}
wenzelm@26782
   755
wenzelm@26782
   756
  \begin{descr}
wenzelm@26782
   757
wenzelm@26782
   758
  \item [@{attribute swapped}] turns an introduction rule into an
wenzelm@26782
   759
  elimination, by resolving with the classical swap principle @{text
wenzelm@26782
   760
  "(\<not> B \<Longrightarrow> A) \<Longrightarrow> (\<not> A \<Longrightarrow> B)"}.
wenzelm@26782
   761
wenzelm@26782
   762
  \end{descr}
wenzelm@26782
   763
*}
wenzelm@26782
   764
wenzelm@26782
   765
wenzelm@27044
   766
section {* Object-logic setup \label{sec:object-logic} *}
wenzelm@26790
   767
wenzelm@26790
   768
text {*
wenzelm@26790
   769
  \begin{matharray}{rcl}
wenzelm@26790
   770
    @{command_def "judgment"} & : & \isartrans{theory}{theory} \\
wenzelm@26790
   771
    @{method_def atomize} & : & \isarmeth \\
wenzelm@26790
   772
    @{attribute_def atomize} & : & \isaratt \\
wenzelm@26790
   773
    @{attribute_def rule_format} & : & \isaratt \\
wenzelm@26790
   774
    @{attribute_def rulify} & : & \isaratt \\
wenzelm@26790
   775
  \end{matharray}
wenzelm@26790
   776
wenzelm@26790
   777
  The very starting point for any Isabelle object-logic is a ``truth
wenzelm@26790
   778
  judgment'' that links object-level statements to the meta-logic
wenzelm@26790
   779
  (with its minimal language of @{text prop} that covers universal
wenzelm@26790
   780
  quantification @{text "\<And>"} and implication @{text "\<Longrightarrow>"}).
wenzelm@26790
   781
wenzelm@26790
   782
  Common object-logics are sufficiently expressive to internalize rule
wenzelm@26790
   783
  statements over @{text "\<And>"} and @{text "\<Longrightarrow>"} within their own
wenzelm@26790
   784
  language.  This is useful in certain situations where a rule needs
wenzelm@26790
   785
  to be viewed as an atomic statement from the meta-level perspective,
wenzelm@26790
   786
  e.g.\ @{text "\<And>x. x \<in> A \<Longrightarrow> P x"} versus @{text "\<forall>x \<in> A. P x"}.
wenzelm@26790
   787
wenzelm@26790
   788
  From the following language elements, only the @{method atomize}
wenzelm@26790
   789
  method and @{attribute rule_format} attribute are occasionally
wenzelm@26790
   790
  required by end-users, the rest is for those who need to setup their
wenzelm@26790
   791
  own object-logic.  In the latter case existing formulations of
wenzelm@26790
   792
  Isabelle/FOL or Isabelle/HOL may be taken as realistic examples.
wenzelm@26790
   793
wenzelm@26790
   794
  Generic tools may refer to the information provided by object-logic
wenzelm@26790
   795
  declarations internally.
wenzelm@26790
   796
wenzelm@26790
   797
  \begin{rail}
wenzelm@26790
   798
    'judgment' constdecl
wenzelm@26790
   799
    ;
wenzelm@26790
   800
    'atomize' ('(' 'full' ')')?
wenzelm@26790
   801
    ;
wenzelm@26790
   802
    'rule\_format' ('(' 'noasm' ')')?
wenzelm@26790
   803
    ;
wenzelm@26790
   804
  \end{rail}
wenzelm@26790
   805
wenzelm@26790
   806
  \begin{descr}
wenzelm@26790
   807
  
wenzelm@26790
   808
  \item [@{command "judgment"}~@{text "c :: \<sigma> (mx)"}] declares
wenzelm@26790
   809
  constant @{text c} as the truth judgment of the current
wenzelm@26790
   810
  object-logic.  Its type @{text \<sigma>} should specify a coercion of the
wenzelm@26790
   811
  category of object-level propositions to @{text prop} of the Pure
wenzelm@26790
   812
  meta-logic; the mixfix annotation @{text "(mx)"} would typically
wenzelm@26790
   813
  just link the object language (internally of syntactic category
wenzelm@26790
   814
  @{text logic}) with that of @{text prop}.  Only one @{command
wenzelm@26790
   815
  "judgment"} declaration may be given in any theory development.
wenzelm@26790
   816
  
wenzelm@26790
   817
  \item [@{method atomize} (as a method)] rewrites any non-atomic
wenzelm@26790
   818
  premises of a sub-goal, using the meta-level equations declared via
wenzelm@26790
   819
  @{attribute atomize} (as an attribute) beforehand.  As a result,
wenzelm@26790
   820
  heavily nested goals become amenable to fundamental operations such
wenzelm@26790
   821
  as resolution (cf.\ the @{method rule} method).  Giving the ``@{text
wenzelm@26790
   822
  "(full)"}'' option here means to turn the whole subgoal into an
wenzelm@26790
   823
  object-statement (if possible), including the outermost parameters
wenzelm@26790
   824
  and assumptions as well.
wenzelm@26790
   825
wenzelm@26790
   826
  A typical collection of @{attribute atomize} rules for a particular
wenzelm@26790
   827
  object-logic would provide an internalization for each of the
wenzelm@26790
   828
  connectives of @{text "\<And>"}, @{text "\<Longrightarrow>"}, and @{text "\<equiv>"}.
wenzelm@26790
   829
  Meta-level conjunction should be covered as well (this is
wenzelm@26790
   830
  particularly important for locales, see \secref{sec:locale}).
wenzelm@26790
   831
wenzelm@26790
   832
  \item [@{attribute rule_format}] rewrites a theorem by the
wenzelm@26790
   833
  equalities declared as @{attribute rulify} rules in the current
wenzelm@26790
   834
  object-logic.  By default, the result is fully normalized, including
wenzelm@26790
   835
  assumptions and conclusions at any depth.  The @{text "(no_asm)"}
wenzelm@26790
   836
  option restricts the transformation to the conclusion of a rule.
wenzelm@26790
   837
wenzelm@26790
   838
  In common object-logics (HOL, FOL, ZF), the effect of @{attribute
wenzelm@26790
   839
  rule_format} is to replace (bounded) universal quantification
wenzelm@26790
   840
  (@{text "\<forall>"}) and implication (@{text "\<longrightarrow>"}) by the corresponding
wenzelm@26790
   841
  rule statements over @{text "\<And>"} and @{text "\<Longrightarrow>"}.
wenzelm@26790
   842
wenzelm@26790
   843
  \end{descr}
wenzelm@26790
   844
*}
wenzelm@26790
   845
wenzelm@26782
   846
end