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