src/Doc/IsarRef/Generic.thy
author wenzelm
Sun Nov 04 20:11:19 2012 +0100 (2012-11-04)
changeset 50068 310e9b810bbf
parent 50065 7c01dc2dcb8c
child 50070 e447ad4d6edd
permissions -rw-r--r--
tuned;
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@42655
     7
section {* Configuration options \label{sec:config} *}
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@42655
    17
  commands such as @{command "declare"} or @{command "using"} like
wenzelm@42655
    18
  this:
wenzelm@42655
    19
*}
wenzelm@42655
    20
wenzelm@42655
    21
declare [[show_main_goal = false]]
wenzelm@26782
    22
wenzelm@42655
    23
notepad
wenzelm@42655
    24
begin
wenzelm@42655
    25
  note [[show_main_goal = true]]
wenzelm@42655
    26
end
wenzelm@42655
    27
wenzelm@42655
    28
text {* For historical reasons, some tools cannot take the full proof
wenzelm@26782
    29
  context into account and merely refer to the background theory.
wenzelm@26782
    30
  This is accommodated by configuration options being declared as
wenzelm@26782
    31
  ``global'', which may not be changed within a local context.
wenzelm@26782
    32
wenzelm@26782
    33
  \begin{matharray}{rcll}
wenzelm@28761
    34
    @{command_def "print_configs"} & : & @{text "context \<rightarrow>"} \\
wenzelm@26782
    35
  \end{matharray}
wenzelm@26782
    36
wenzelm@42596
    37
  @{rail "
wenzelm@42596
    38
    @{syntax name} ('=' ('true' | 'false' | @{syntax int} | @{syntax float} | @{syntax name}))?
wenzelm@42596
    39
  "}
wenzelm@26782
    40
wenzelm@28760
    41
  \begin{description}
wenzelm@26782
    42
  
wenzelm@28760
    43
  \item @{command "print_configs"} prints the available configuration
wenzelm@28760
    44
  options, with names, types, and current values.
wenzelm@26782
    45
  
wenzelm@28760
    46
  \item @{text "name = value"} as an attribute expression modifies the
wenzelm@28760
    47
  named option, with the syntax of the value depending on the option's
wenzelm@28760
    48
  type.  For @{ML_type bool} the default value is @{text true}.  Any
wenzelm@28760
    49
  attempt to change a global option in a local context is ignored.
wenzelm@26782
    50
wenzelm@28760
    51
  \end{description}
wenzelm@26782
    52
*}
wenzelm@26782
    53
wenzelm@26782
    54
wenzelm@27040
    55
section {* Basic proof tools *}
wenzelm@26782
    56
wenzelm@26782
    57
subsection {* Miscellaneous methods and attributes \label{sec:misc-meth-att} *}
wenzelm@26782
    58
wenzelm@26782
    59
text {*
wenzelm@26782
    60
  \begin{matharray}{rcl}
wenzelm@28761
    61
    @{method_def unfold} & : & @{text method} \\
wenzelm@28761
    62
    @{method_def fold} & : & @{text method} \\
wenzelm@28761
    63
    @{method_def insert} & : & @{text method} \\[0.5ex]
wenzelm@28761
    64
    @{method_def erule}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
    65
    @{method_def drule}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
    66
    @{method_def frule}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@43365
    67
    @{method_def intro} & : & @{text method} \\
wenzelm@43365
    68
    @{method_def elim} & : & @{text method} \\
wenzelm@28761
    69
    @{method_def succeed} & : & @{text method} \\
wenzelm@28761
    70
    @{method_def fail} & : & @{text method} \\
wenzelm@26782
    71
  \end{matharray}
wenzelm@26782
    72
wenzelm@42596
    73
  @{rail "
wenzelm@42596
    74
    (@@{method fold} | @@{method unfold} | @@{method insert}) @{syntax thmrefs}
wenzelm@26782
    75
    ;
wenzelm@42596
    76
    (@@{method erule} | @@{method drule} | @@{method frule})
wenzelm@42596
    77
      ('(' @{syntax nat} ')')? @{syntax thmrefs}
wenzelm@43365
    78
    ;
wenzelm@43365
    79
    (@@{method intro} | @@{method elim}) @{syntax thmrefs}?
wenzelm@42596
    80
  "}
wenzelm@26782
    81
wenzelm@28760
    82
  \begin{description}
wenzelm@26782
    83
  
wenzelm@28760
    84
  \item @{method unfold}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and @{method fold}~@{text
wenzelm@28760
    85
  "a\<^sub>1 \<dots> a\<^sub>n"} expand (or fold back) the given definitions throughout
wenzelm@28760
    86
  all goals; any chained facts provided are inserted into the goal and
wenzelm@28760
    87
  subject to rewriting as well.
wenzelm@26782
    88
wenzelm@28760
    89
  \item @{method insert}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} inserts theorems as facts
wenzelm@28760
    90
  into all goals of the proof state.  Note that current facts
wenzelm@28760
    91
  indicated for forward chaining are ignored.
wenzelm@26782
    92
wenzelm@30397
    93
  \item @{method erule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}, @{method
wenzelm@30397
    94
  drule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}, and @{method frule}~@{text
wenzelm@30397
    95
  "a\<^sub>1 \<dots> a\<^sub>n"} are similar to the basic @{method rule}
wenzelm@30397
    96
  method (see \secref{sec:pure-meth-att}), but apply rules by
wenzelm@30397
    97
  elim-resolution, destruct-resolution, and forward-resolution,
wenzelm@30397
    98
  respectively \cite{isabelle-implementation}.  The optional natural
wenzelm@30397
    99
  number argument (default 0) specifies additional assumption steps to
wenzelm@30397
   100
  be performed here.
wenzelm@26782
   101
wenzelm@26782
   102
  Note that these methods are improper ones, mainly serving for
wenzelm@26782
   103
  experimentation and tactic script emulation.  Different modes of
wenzelm@26782
   104
  basic rule application are usually expressed in Isar at the proof
wenzelm@26782
   105
  language level, rather than via implicit proof state manipulations.
wenzelm@26782
   106
  For example, a proper single-step elimination would be done using
wenzelm@26782
   107
  the plain @{method rule} method, with forward chaining of current
wenzelm@26782
   108
  facts.
wenzelm@26782
   109
wenzelm@43365
   110
  \item @{method intro} and @{method elim} repeatedly refine some goal
wenzelm@43365
   111
  by intro- or elim-resolution, after having inserted any chained
wenzelm@43365
   112
  facts.  Exactly the rules given as arguments are taken into account;
wenzelm@43365
   113
  this allows fine-tuned decomposition of a proof problem, in contrast
wenzelm@43365
   114
  to common automated tools.
wenzelm@43365
   115
wenzelm@28760
   116
  \item @{method succeed} yields a single (unchanged) result; it is
wenzelm@26782
   117
  the identity of the ``@{text ","}'' method combinator (cf.\
wenzelm@28754
   118
  \secref{sec:proof-meth}).
wenzelm@26782
   119
wenzelm@28760
   120
  \item @{method fail} yields an empty result sequence; it is the
wenzelm@26782
   121
  identity of the ``@{text "|"}'' method combinator (cf.\
wenzelm@28754
   122
  \secref{sec:proof-meth}).
wenzelm@26782
   123
wenzelm@28760
   124
  \end{description}
wenzelm@26782
   125
wenzelm@26782
   126
  \begin{matharray}{rcl}
wenzelm@28761
   127
    @{attribute_def tagged} & : & @{text attribute} \\
wenzelm@28761
   128
    @{attribute_def untagged} & : & @{text attribute} \\[0.5ex]
wenzelm@28761
   129
    @{attribute_def THEN} & : & @{text attribute} \\
wenzelm@28761
   130
    @{attribute_def unfolded} & : & @{text attribute} \\
wenzelm@47497
   131
    @{attribute_def folded} & : & @{text attribute} \\
wenzelm@47497
   132
    @{attribute_def abs_def} & : & @{text attribute} \\[0.5ex]
wenzelm@28761
   133
    @{attribute_def rotated} & : & @{text attribute} \\
wenzelm@28761
   134
    @{attribute_def (Pure) elim_format} & : & @{text attribute} \\
wenzelm@28761
   135
    @{attribute_def standard}@{text "\<^sup>*"} & : & @{text attribute} \\
wenzelm@28761
   136
    @{attribute_def no_vars}@{text "\<^sup>*"} & : & @{text attribute} \\
wenzelm@26782
   137
  \end{matharray}
wenzelm@26782
   138
wenzelm@42596
   139
  @{rail "
wenzelm@42596
   140
    @@{attribute tagged} @{syntax name} @{syntax name}
wenzelm@26782
   141
    ;
wenzelm@42596
   142
    @@{attribute untagged} @{syntax name}
wenzelm@26782
   143
    ;
wenzelm@48205
   144
    @@{attribute THEN} ('[' @{syntax nat} ']')? @{syntax thmref}
wenzelm@26782
   145
    ;
wenzelm@42596
   146
    (@@{attribute unfolded} | @@{attribute folded}) @{syntax thmrefs}
wenzelm@26782
   147
    ;
wenzelm@42596
   148
    @@{attribute rotated} @{syntax int}?
wenzelm@42596
   149
  "}
wenzelm@26782
   150
wenzelm@28760
   151
  \begin{description}
wenzelm@26782
   152
wenzelm@28764
   153
  \item @{attribute tagged}~@{text "name value"} and @{attribute
wenzelm@28760
   154
  untagged}~@{text name} add and remove \emph{tags} of some theorem.
wenzelm@26782
   155
  Tags may be any list of string pairs that serve as formal comment.
wenzelm@28764
   156
  The first string is considered the tag name, the second its value.
wenzelm@28764
   157
  Note that @{attribute untagged} removes any tags of the same name.
wenzelm@26782
   158
wenzelm@48205
   159
  \item @{attribute THEN}~@{text a} composes rules by resolution; it
wenzelm@48205
   160
  resolves with the first premise of @{text a} (an alternative
wenzelm@48205
   161
  position may be also specified).  See also @{ML_op "RS"} in
wenzelm@48205
   162
  \cite{isabelle-implementation}.
wenzelm@26782
   163
  
wenzelm@28760
   164
  \item @{attribute unfolded}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and @{attribute
wenzelm@28760
   165
  folded}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} expand and fold back again the given
wenzelm@28760
   166
  definitions throughout a rule.
wenzelm@26782
   167
wenzelm@47497
   168
  \item @{attribute abs_def} turns an equation of the form @{prop "f x
wenzelm@47497
   169
  y \<equiv> t"} into @{prop "f \<equiv> \<lambda>x y. t"}, which ensures that @{method
wenzelm@47497
   170
  simp} or @{method unfold} steps always expand it.  This also works
wenzelm@47497
   171
  for object-logic equality.
wenzelm@47497
   172
wenzelm@28760
   173
  \item @{attribute rotated}~@{text n} rotate the premises of a
wenzelm@26782
   174
  theorem by @{text n} (default 1).
wenzelm@26782
   175
wenzelm@28760
   176
  \item @{attribute (Pure) elim_format} turns a destruction rule into
wenzelm@28760
   177
  elimination rule format, by resolving with the rule @{prop "PROP A \<Longrightarrow>
wenzelm@28760
   178
  (PROP A \<Longrightarrow> PROP B) \<Longrightarrow> PROP B"}.
wenzelm@26782
   179
  
wenzelm@26782
   180
  Note that the Classical Reasoner (\secref{sec:classical}) provides
wenzelm@26782
   181
  its own version of this operation.
wenzelm@26782
   182
wenzelm@28760
   183
  \item @{attribute standard} puts a theorem into the standard form of
wenzelm@28760
   184
  object-rules at the outermost theory level.  Note that this
wenzelm@26782
   185
  operation violates the local proof context (including active
wenzelm@26782
   186
  locales).
wenzelm@26782
   187
wenzelm@28760
   188
  \item @{attribute no_vars} replaces schematic variables by free
wenzelm@26782
   189
  ones; this is mainly for tuning output of pretty printed theorems.
wenzelm@26782
   190
wenzelm@28760
   191
  \end{description}
wenzelm@26782
   192
*}
wenzelm@26782
   193
wenzelm@26782
   194
wenzelm@27044
   195
subsection {* Low-level equational reasoning *}
wenzelm@27044
   196
wenzelm@27044
   197
text {*
wenzelm@27044
   198
  \begin{matharray}{rcl}
wenzelm@28761
   199
    @{method_def subst} & : & @{text method} \\
wenzelm@28761
   200
    @{method_def hypsubst} & : & @{text method} \\
wenzelm@28761
   201
    @{method_def split} & : & @{text method} \\
wenzelm@27044
   202
  \end{matharray}
wenzelm@27044
   203
wenzelm@42596
   204
  @{rail "
wenzelm@42704
   205
    @@{method subst} ('(' 'asm' ')')? \\ ('(' (@{syntax nat}+) ')')? @{syntax thmref}
wenzelm@27044
   206
    ;
wenzelm@44094
   207
    @@{method split} @{syntax thmrefs}
wenzelm@42596
   208
  "}
wenzelm@27044
   209
wenzelm@27044
   210
  These methods provide low-level facilities for equational reasoning
wenzelm@27044
   211
  that are intended for specialized applications only.  Normally,
wenzelm@27044
   212
  single step calculations would be performed in a structured text
wenzelm@27044
   213
  (see also \secref{sec:calculation}), while the Simplifier methods
wenzelm@27044
   214
  provide the canonical way for automated normalization (see
wenzelm@27044
   215
  \secref{sec:simplifier}).
wenzelm@27044
   216
wenzelm@28760
   217
  \begin{description}
wenzelm@27044
   218
wenzelm@28760
   219
  \item @{method subst}~@{text eq} performs a single substitution step
wenzelm@28760
   220
  using rule @{text eq}, which may be either a meta or object
wenzelm@27044
   221
  equality.
wenzelm@27044
   222
wenzelm@28760
   223
  \item @{method subst}~@{text "(asm) eq"} substitutes in an
wenzelm@27044
   224
  assumption.
wenzelm@27044
   225
wenzelm@28760
   226
  \item @{method subst}~@{text "(i \<dots> j) eq"} performs several
wenzelm@27044
   227
  substitutions in the conclusion. The numbers @{text i} to @{text j}
wenzelm@27044
   228
  indicate the positions to substitute at.  Positions are ordered from
wenzelm@27044
   229
  the top of the term tree moving down from left to right. For
wenzelm@27044
   230
  example, in @{text "(a + b) + (c + d)"} there are three positions
wenzelm@28760
   231
  where commutativity of @{text "+"} is applicable: 1 refers to @{text
wenzelm@28760
   232
  "a + b"}, 2 to the whole term, and 3 to @{text "c + d"}.
wenzelm@27044
   233
wenzelm@27044
   234
  If the positions in the list @{text "(i \<dots> j)"} are non-overlapping
wenzelm@27044
   235
  (e.g.\ @{text "(2 3)"} in @{text "(a + b) + (c + d)"}) you may
wenzelm@27044
   236
  assume all substitutions are performed simultaneously.  Otherwise
wenzelm@27044
   237
  the behaviour of @{text subst} is not specified.
wenzelm@27044
   238
wenzelm@28760
   239
  \item @{method subst}~@{text "(asm) (i \<dots> j) eq"} performs the
wenzelm@27071
   240
  substitutions in the assumptions. The positions refer to the
wenzelm@27071
   241
  assumptions in order from left to right.  For example, given in a
wenzelm@27071
   242
  goal of the form @{text "P (a + b) \<Longrightarrow> P (c + d) \<Longrightarrow> \<dots>"}, position 1 of
wenzelm@27071
   243
  commutativity of @{text "+"} is the subterm @{text "a + b"} and
wenzelm@27071
   244
  position 2 is the subterm @{text "c + d"}.
wenzelm@27044
   245
wenzelm@28760
   246
  \item @{method hypsubst} performs substitution using some
wenzelm@27044
   247
  assumption; this only works for equations of the form @{text "x =
wenzelm@27044
   248
  t"} where @{text x} is a free or bound variable.
wenzelm@27044
   249
wenzelm@28760
   250
  \item @{method split}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} performs single-step case
wenzelm@44094
   251
  splitting using the given rules.  Splitting is performed in the
wenzelm@44094
   252
  conclusion or some assumption of the subgoal, depending of the
wenzelm@44094
   253
  structure of the rule.
wenzelm@27044
   254
  
wenzelm@27044
   255
  Note that the @{method simp} method already involves repeated
wenzelm@44094
   256
  application of split rules as declared in the current context, using
wenzelm@44094
   257
  @{attribute split}, for example.
wenzelm@27044
   258
wenzelm@28760
   259
  \end{description}
wenzelm@27044
   260
*}
wenzelm@27044
   261
wenzelm@27044
   262
wenzelm@26782
   263
subsection {* Further tactic emulations \label{sec:tactics} *}
wenzelm@26782
   264
wenzelm@26782
   265
text {*
wenzelm@26782
   266
  The following improper proof methods emulate traditional tactics.
wenzelm@26782
   267
  These admit direct access to the goal state, which is normally
wenzelm@26782
   268
  considered harmful!  In particular, this may involve both numbered
wenzelm@26782
   269
  goal addressing (default 1), and dynamic instantiation within the
wenzelm@26782
   270
  scope of some subgoal.
wenzelm@26782
   271
wenzelm@26782
   272
  \begin{warn}
wenzelm@26782
   273
    Dynamic instantiations refer to universally quantified parameters
wenzelm@26782
   274
    of a subgoal (the dynamic context) rather than fixed variables and
wenzelm@26782
   275
    term abbreviations of a (static) Isar context.
wenzelm@26782
   276
  \end{warn}
wenzelm@26782
   277
wenzelm@26782
   278
  Tactic emulation methods, unlike their ML counterparts, admit
wenzelm@26782
   279
  simultaneous instantiation from both dynamic and static contexts.
wenzelm@26782
   280
  If names occur in both contexts goal parameters hide locally fixed
wenzelm@26782
   281
  variables.  Likewise, schematic variables refer to term
wenzelm@26782
   282
  abbreviations, if present in the static context.  Otherwise the
wenzelm@26782
   283
  schematic variable is interpreted as a schematic variable and left
wenzelm@26782
   284
  to be solved by unification with certain parts of the subgoal.
wenzelm@26782
   285
wenzelm@26782
   286
  Note that the tactic emulation proof methods in Isabelle/Isar are
wenzelm@26782
   287
  consistently named @{text foo_tac}.  Note also that variable names
wenzelm@26782
   288
  occurring on left hand sides of instantiations must be preceded by a
wenzelm@26782
   289
  question mark if they coincide with a keyword or contain dots.  This
wenzelm@26782
   290
  is consistent with the attribute @{attribute "where"} (see
wenzelm@26782
   291
  \secref{sec:pure-meth-att}).
wenzelm@26782
   292
wenzelm@26782
   293
  \begin{matharray}{rcl}
wenzelm@28761
   294
    @{method_def rule_tac}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   295
    @{method_def erule_tac}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   296
    @{method_def drule_tac}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   297
    @{method_def frule_tac}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   298
    @{method_def cut_tac}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   299
    @{method_def thin_tac}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   300
    @{method_def subgoal_tac}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   301
    @{method_def rename_tac}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   302
    @{method_def rotate_tac}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   303
    @{method_def tactic}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@28761
   304
    @{method_def raw_tactic}@{text "\<^sup>*"} & : & @{text method} \\
wenzelm@26782
   305
  \end{matharray}
wenzelm@26782
   306
wenzelm@42596
   307
  @{rail "
wenzelm@42596
   308
    (@@{method rule_tac} | @@{method erule_tac} | @@{method drule_tac} |
wenzelm@42705
   309
      @@{method frule_tac} | @@{method cut_tac} | @@{method thin_tac}) @{syntax goal_spec}? \\
wenzelm@42617
   310
    ( dynamic_insts @'in' @{syntax thmref} | @{syntax thmrefs} )
wenzelm@26782
   311
    ;
wenzelm@42705
   312
    @@{method subgoal_tac} @{syntax goal_spec}? (@{syntax prop} +)
wenzelm@42596
   313
    ;
wenzelm@42705
   314
    @@{method rename_tac} @{syntax goal_spec}? (@{syntax name} +)
wenzelm@26782
   315
    ;
wenzelm@42705
   316
    @@{method rotate_tac} @{syntax goal_spec}? @{syntax int}?
wenzelm@26782
   317
    ;
wenzelm@42596
   318
    (@@{method tactic} | @@{method raw_tactic}) @{syntax text}
wenzelm@26782
   319
    ;
wenzelm@26782
   320
wenzelm@42617
   321
    dynamic_insts: ((@{syntax name} '=' @{syntax term}) + @'and')
wenzelm@42617
   322
  "}
wenzelm@26782
   323
wenzelm@28760
   324
\begin{description}
wenzelm@26782
   325
wenzelm@28760
   326
  \item @{method rule_tac} etc. do resolution of rules with explicit
wenzelm@26782
   327
  instantiation.  This works the same way as the ML tactics @{ML
wenzelm@30397
   328
  res_inst_tac} etc. (see \cite{isabelle-implementation})
wenzelm@26782
   329
wenzelm@26782
   330
  Multiple rules may be only given if there is no instantiation; then
wenzelm@26782
   331
  @{method rule_tac} is the same as @{ML resolve_tac} in ML (see
wenzelm@30397
   332
  \cite{isabelle-implementation}).
wenzelm@26782
   333
wenzelm@28760
   334
  \item @{method cut_tac} inserts facts into the proof state as
wenzelm@46706
   335
  assumption of a subgoal; instantiations may be given as well.  Note
wenzelm@46706
   336
  that the scope of schematic variables is spread over the main goal
wenzelm@46706
   337
  statement and rule premises are turned into new subgoals.  This is
wenzelm@46706
   338
  in contrast to the regular method @{method insert} which inserts
wenzelm@46706
   339
  closed rule statements.
wenzelm@26782
   340
wenzelm@46277
   341
  \item @{method thin_tac}~@{text \<phi>} deletes the specified premise
wenzelm@46277
   342
  from a subgoal.  Note that @{text \<phi>} may contain schematic
wenzelm@46277
   343
  variables, to abbreviate the intended proposition; the first
wenzelm@46277
   344
  matching subgoal premise will be deleted.  Removing useless premises
wenzelm@46277
   345
  from a subgoal increases its readability and can make search tactics
wenzelm@46277
   346
  run faster.
wenzelm@28760
   347
wenzelm@46271
   348
  \item @{method subgoal_tac}~@{text "\<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"} adds the propositions
wenzelm@46271
   349
  @{text "\<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"} as local premises to a subgoal, and poses the same
wenzelm@46271
   350
  as new subgoals (in the original context).
wenzelm@26782
   351
wenzelm@28760
   352
  \item @{method rename_tac}~@{text "x\<^sub>1 \<dots> x\<^sub>n"} renames parameters of a
wenzelm@28760
   353
  goal according to the list @{text "x\<^sub>1, \<dots>, x\<^sub>n"}, which refers to the
wenzelm@28760
   354
  \emph{suffix} of variables.
wenzelm@26782
   355
wenzelm@46274
   356
  \item @{method rotate_tac}~@{text n} rotates the premises of a
wenzelm@46274
   357
  subgoal by @{text n} positions: from right to left if @{text n} is
wenzelm@26782
   358
  positive, and from left to right if @{text n} is negative; the
wenzelm@46274
   359
  default value is 1.
wenzelm@26782
   360
wenzelm@28760
   361
  \item @{method tactic}~@{text "text"} produces a proof method from
wenzelm@26782
   362
  any ML text of type @{ML_type tactic}.  Apart from the usual ML
wenzelm@27223
   363
  environment and the current proof context, the ML code may refer to
wenzelm@27223
   364
  the locally bound values @{ML_text facts}, which indicates any
wenzelm@27223
   365
  current facts used for forward-chaining.
wenzelm@26782
   366
wenzelm@28760
   367
  \item @{method raw_tactic} is similar to @{method tactic}, but
wenzelm@27223
   368
  presents the goal state in its raw internal form, where simultaneous
wenzelm@27223
   369
  subgoals appear as conjunction of the logical framework instead of
wenzelm@27223
   370
  the usual split into several subgoals.  While feature this is useful
wenzelm@27223
   371
  for debugging of complex method definitions, it should not never
wenzelm@27223
   372
  appear in production theories.
wenzelm@26782
   373
wenzelm@28760
   374
  \end{description}
wenzelm@26782
   375
*}
wenzelm@26782
   376
wenzelm@26782
   377
wenzelm@27040
   378
section {* The Simplifier \label{sec:simplifier} *}
wenzelm@26782
   379
wenzelm@50063
   380
text {* The Simplifier performs conditional and unconditional
wenzelm@50063
   381
  rewriting and uses contextual information: rule declarations in the
wenzelm@50063
   382
  background theory or local proof context are taken into account, as
wenzelm@50063
   383
  well as chained facts and subgoal premises (``local assumptions'').
wenzelm@50063
   384
  There are several general hooks that allow to modify the
wenzelm@50063
   385
  simplification strategy, or incorporate other proof tools that solve
wenzelm@50063
   386
  sub-problems, produce rewrite rules on demand etc.
wenzelm@50063
   387
wenzelm@50063
   388
  The default Simplifier setup of major object logics (HOL, HOLCF,
wenzelm@50063
   389
  FOL, ZF) makes the Simplifier ready for immediate use, without
wenzelm@50063
   390
  engaging into the internal structures.  Thus it serves as
wenzelm@50063
   391
  general-purpose proof tool with the main focus on equational
wenzelm@50063
   392
  reasoning, and a bit more than that.  *}
wenzelm@50063
   393
wenzelm@50063
   394
wenzelm@50063
   395
subsection {* Simplification methods \label{sec:simp-meth} *}
wenzelm@26782
   396
wenzelm@26782
   397
text {*
wenzelm@26782
   398
  \begin{matharray}{rcl}
wenzelm@28761
   399
    @{method_def simp} & : & @{text method} \\
wenzelm@28761
   400
    @{method_def simp_all} & : & @{text method} \\
wenzelm@26782
   401
  \end{matharray}
wenzelm@26782
   402
wenzelm@42596
   403
  @{rail "
wenzelm@42596
   404
    (@@{method simp} | @@{method simp_all}) opt? (@{syntax simpmod} * )
wenzelm@26782
   405
    ;
wenzelm@26782
   406
wenzelm@40255
   407
    opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use' | 'asm_lr' ) ')'
wenzelm@26782
   408
    ;
wenzelm@50063
   409
    @{syntax_def simpmod}: ('add' | 'del' | 'only' | 'split' (() | 'add' | 'del') |
wenzelm@50063
   410
      'cong' (() | 'add' | 'del')) ':' @{syntax thmrefs}
wenzelm@42596
   411
  "}
wenzelm@26782
   412
wenzelm@28760
   413
  \begin{description}
wenzelm@26782
   414
wenzelm@50063
   415
  \item @{method simp} invokes the Simplifier on the first subgoal,
wenzelm@50063
   416
  after inserting chained facts as additional goal premises; further
wenzelm@50063
   417
  rule declarations may be included via @{text "(simp add: facts)"}.
wenzelm@50063
   418
  The proof method fails if the subgoal remains unchanged after
wenzelm@50063
   419
  simplification.
wenzelm@26782
   420
wenzelm@50063
   421
  Note that the original goal premises and chained facts are subject
wenzelm@50063
   422
  to simplification themselves, while declarations via @{text
wenzelm@50063
   423
  "add"}/@{text "del"} merely follow the policies of the object-logic
wenzelm@50063
   424
  to extract rewrite rules from theorems, without further
wenzelm@50063
   425
  simplification.  This may lead to slightly different behavior in
wenzelm@50063
   426
  either case, which might be required precisely like that in some
wenzelm@50063
   427
  boundary situations to perform the intended simplification step!
wenzelm@50063
   428
wenzelm@50063
   429
  \medskip The @{text only} modifier first removes all other rewrite
wenzelm@50063
   430
  rules, looper tactics (including split rules), congruence rules, and
wenzelm@50063
   431
  then behaves like @{text add}.  Implicit solvers remain, which means
wenzelm@50063
   432
  that trivial rules like reflexivity or introduction of @{text
wenzelm@50063
   433
  "True"} are available to solve the simplified subgoals, but also
wenzelm@50063
   434
  non-trivial tools like linear arithmetic in HOL.  The latter may
wenzelm@50063
   435
  lead to some surprise of the meaning of ``only'' in Isabelle/HOL
wenzelm@50063
   436
  compared to English!
wenzelm@26782
   437
wenzelm@42596
   438
  \medskip The @{text split} modifiers add or delete rules for the
wenzelm@26782
   439
  Splitter (see also \cite{isabelle-ref}), the default is to add.
wenzelm@26782
   440
  This works only if the Simplifier method has been properly setup to
wenzelm@26782
   441
  include the Splitter (all major object logics such HOL, HOLCF, FOL,
wenzelm@26782
   442
  ZF do this already).
wenzelm@26782
   443
wenzelm@50065
   444
  There is also a separate @{method_ref split} method available for
wenzelm@50065
   445
  single-step case splitting.  The effect of repeatedly applying
wenzelm@50065
   446
  @{text "(split thms)"} can be imitated by ``@{text "(simp only:
wenzelm@50065
   447
  split: thms)"}''.
wenzelm@50065
   448
wenzelm@50063
   449
  \medskip The @{text cong} modifiers add or delete Simplifier
wenzelm@50063
   450
  congruence rules (see also \secref{sec:simp-rules}); the default is
wenzelm@50063
   451
  to add.
wenzelm@50063
   452
wenzelm@28760
   453
  \item @{method simp_all} is similar to @{method simp}, but acts on
wenzelm@50063
   454
  all goals, working backwards from the last to the first one as usual
wenzelm@50063
   455
  in Isabelle.\footnote{The order is irrelevant for goals without
wenzelm@50063
   456
  schematic variables, so simplification might actually be performed
wenzelm@50063
   457
  in parallel here.}
wenzelm@50063
   458
wenzelm@50063
   459
  Chained facts are inserted into all subgoals, before the
wenzelm@50063
   460
  simplification process starts.  Further rule declarations are the
wenzelm@50063
   461
  same as for @{method simp}.
wenzelm@50063
   462
wenzelm@50063
   463
  The proof method fails if all subgoals remain unchanged after
wenzelm@50063
   464
  simplification.
wenzelm@26782
   465
wenzelm@28760
   466
  \end{description}
wenzelm@26782
   467
wenzelm@50063
   468
  By default the Simplifier methods above take local assumptions fully
wenzelm@50063
   469
  into account, using equational assumptions in the subsequent
wenzelm@50063
   470
  normalization process, or simplifying assumptions themselves.
wenzelm@50063
   471
  Further options allow to fine-tune the behavior of the Simplifier
wenzelm@50063
   472
  in this respect, corresponding to a variety of ML tactics as
wenzelm@50063
   473
  follows.\footnote{Unlike the corresponding Isar proof methods, the
wenzelm@50063
   474
  ML tactics do not insist in changing the goal state.}
wenzelm@50063
   475
wenzelm@50063
   476
  \begin{center}
wenzelm@50063
   477
  \small
wenzelm@50065
   478
  \begin{supertabular}{|l|l|p{0.3\textwidth}|}
wenzelm@50063
   479
  \hline
wenzelm@50063
   480
  Isar method & ML tactic & behavior \\\hline
wenzelm@50063
   481
wenzelm@50063
   482
  @{text "(simp (no_asm))"} & @{ML simp_tac} & assumptions are ignored
wenzelm@50063
   483
  completely \\\hline
wenzelm@26782
   484
wenzelm@50063
   485
  @{text "(simp (no_asm_simp))"} & @{ML asm_simp_tac} & assumptions
wenzelm@50063
   486
  are used in the simplification of the conclusion but are not
wenzelm@50063
   487
  themselves simplified \\\hline
wenzelm@50063
   488
wenzelm@50063
   489
  @{text "(simp (no_asm_use))"} & @{ML full_simp_tac} & assumptions
wenzelm@50063
   490
  are simplified but are not used in the simplification of each other
wenzelm@50063
   491
  or the conclusion \\\hline
wenzelm@26782
   492
wenzelm@50063
   493
  @{text "(simp)"} & @{ML asm_full_simp_tac} & assumptions are used in
wenzelm@50063
   494
  the simplification of the conclusion and to simplify other
wenzelm@50063
   495
  assumptions \\\hline
wenzelm@50063
   496
wenzelm@50063
   497
  @{text "(simp (asm_lr))"} & @{ML asm_lr_simp_tac} & compatibility
wenzelm@50063
   498
  mode: an assumption is only used for simplifying assumptions which
wenzelm@50063
   499
  are to the right of it \\\hline
wenzelm@50063
   500
wenzelm@50065
   501
  \end{supertabular}
wenzelm@50063
   502
  \end{center}
wenzelm@26782
   503
*}
wenzelm@26782
   504
wenzelm@26782
   505
wenzelm@50064
   506
subsubsection {* Examples *}
wenzelm@50064
   507
wenzelm@50064
   508
text {* We consider basic algebraic simplifications in Isabelle/HOL.
wenzelm@50064
   509
  The rather trivial goal @{prop "0 + (x + 0) = x + 0 + 0"} looks like
wenzelm@50064
   510
  a good candidate to be solved by a single call of @{method simp}:
wenzelm@50064
   511
*}
wenzelm@50064
   512
wenzelm@50064
   513
lemma "0 + (x + 0) = x + 0 + 0" apply simp? oops
wenzelm@50064
   514
wenzelm@50064
   515
text {* The above attempt \emph{fails}, because @{term "0"} and @{term
wenzelm@50064
   516
  "op +"} in the HOL library are declared as generic type class
wenzelm@50064
   517
  operations, without stating any algebraic laws yet.  More specific
wenzelm@50064
   518
  types are required to get access to certain standard simplifications
wenzelm@50064
   519
  of the theory context, e.g.\ like this: *}
wenzelm@50064
   520
wenzelm@50064
   521
lemma fixes x :: nat shows "0 + (x + 0) = x + 0 + 0" by simp
wenzelm@50064
   522
lemma fixes x :: int shows "0 + (x + 0) = x + 0 + 0" by simp
wenzelm@50064
   523
lemma fixes x :: "'a :: monoid_add" shows "0 + (x + 0) = x + 0 + 0" by simp
wenzelm@50064
   524
wenzelm@50064
   525
text {*
wenzelm@50064
   526
  \medskip In many cases, assumptions of a subgoal are also needed in
wenzelm@50064
   527
  the simplification process.  For example:
wenzelm@50064
   528
*}
wenzelm@50064
   529
wenzelm@50064
   530
lemma fixes x :: nat shows "x = 0 \<Longrightarrow> x + x = 0" by simp
wenzelm@50064
   531
lemma fixes x :: nat assumes "x = 0" shows "x + x = 0" apply simp oops
wenzelm@50064
   532
lemma fixes x :: nat assumes "x = 0" shows "x + x = 0" using assms by simp
wenzelm@50064
   533
wenzelm@50064
   534
text {* As seen above, local assumptions that shall contribute to
wenzelm@50064
   535
  simplification need to be part of the subgoal already, or indicated
wenzelm@50064
   536
  explicitly for use by the subsequent method invocation.  Both too
wenzelm@50064
   537
  little or too much information can make simplification fail, for
wenzelm@50064
   538
  different reasons.
wenzelm@50064
   539
wenzelm@50064
   540
  In the next example the malicious assumption @{prop "\<And>x::nat. f x =
wenzelm@50064
   541
  g (f (g x))"} does not contribute to solve the problem, but makes
wenzelm@50064
   542
  the default @{method simp} method loop: the rewrite rule @{text "f
wenzelm@50064
   543
  ?x \<equiv> g (f (g ?x))"} extracted from the assumption does not
wenzelm@50064
   544
  terminate.  The Simplifier notices certain simple forms of
wenzelm@50064
   545
  nontermination, but not this one.  The problem can be solved
wenzelm@50064
   546
  nonetheless, by ignoring assumptions via special options as
wenzelm@50064
   547
  explained before:
wenzelm@50064
   548
*}
wenzelm@50064
   549
wenzelm@50064
   550
lemma "(\<And>x::nat. f x = g (f (g x))) \<Longrightarrow> f 0 = f 0 + 0"
wenzelm@50064
   551
  by (simp (no_asm))
wenzelm@50064
   552
wenzelm@50064
   553
text {* The latter form is typical for long unstructured proof
wenzelm@50064
   554
  scripts, where the control over the goal content is limited.  In
wenzelm@50064
   555
  structured proofs it is usually better to avoid pushing too many
wenzelm@50064
   556
  facts into the goal state in the first place.  Assumptions in the
wenzelm@50064
   557
  Isar proof context do not intrude the reasoning if not used
wenzelm@50064
   558
  explicitly.  This is illustrated for a toplevel statement and a
wenzelm@50064
   559
  local proof body as follows:
wenzelm@50064
   560
*}
wenzelm@50064
   561
wenzelm@50064
   562
lemma
wenzelm@50064
   563
  assumes "\<And>x::nat. f x = g (f (g x))"
wenzelm@50064
   564
  shows "f 0 = f 0 + 0" by simp
wenzelm@50064
   565
wenzelm@50064
   566
notepad
wenzelm@50064
   567
begin
wenzelm@50064
   568
  assume "\<And>x::nat. f x = g (f (g x))"
wenzelm@50064
   569
  have "f 0 = f 0 + 0" by simp
wenzelm@50064
   570
end
wenzelm@50064
   571
wenzelm@50064
   572
text {* \medskip Because assumptions may simplify each other, there
wenzelm@50064
   573
  can be very subtle cases of nontermination. For example, the regular
wenzelm@50064
   574
  @{method simp} method applied to @{prop "P (f x) \<Longrightarrow> y = x \<Longrightarrow> f x = f y
wenzelm@50064
   575
  \<Longrightarrow> Q"} gives rise to the infinite reduction sequence
wenzelm@50064
   576
  \[
wenzelm@50064
   577
  @{text "P (f x)"} \stackrel{@{text "f x \<equiv> f y"}}{\longmapsto}
wenzelm@50064
   578
  @{text "P (f y)"} \stackrel{@{text "y \<equiv> x"}}{\longmapsto}
wenzelm@50064
   579
  @{text "P (f x)"} \stackrel{@{text "f x \<equiv> f y"}}{\longmapsto} \cdots
wenzelm@50064
   580
  \]
wenzelm@50064
   581
  whereas applying the same to @{prop "y = x \<Longrightarrow> f x = f y \<Longrightarrow> P (f x) \<Longrightarrow>
wenzelm@50064
   582
  Q"} terminates (without solving the goal):
wenzelm@50064
   583
*}
wenzelm@50064
   584
wenzelm@50064
   585
lemma "y = x \<Longrightarrow> f x = f y \<Longrightarrow> P (f x) \<Longrightarrow> Q"
wenzelm@50064
   586
  apply simp
wenzelm@50064
   587
  oops
wenzelm@50064
   588
wenzelm@50064
   589
text {* See also \secref{sec:simp-config} for options to enable
wenzelm@50064
   590
  Simplifier trace mode, which often helps to diagnose problems with
wenzelm@50064
   591
  rewrite systems.
wenzelm@50064
   592
*}
wenzelm@50064
   593
wenzelm@50064
   594
wenzelm@50063
   595
subsection {* Declaring rules \label{sec:simp-rules} *}
wenzelm@26782
   596
wenzelm@26782
   597
text {*
wenzelm@26782
   598
  \begin{matharray}{rcl}
wenzelm@28761
   599
    @{command_def "print_simpset"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28761
   600
    @{attribute_def simp} & : & @{text attribute} \\
wenzelm@28761
   601
    @{attribute_def split} & : & @{text attribute} \\
wenzelm@50063
   602
    @{attribute_def cong} & : & @{text attribute} \\
wenzelm@26782
   603
  \end{matharray}
wenzelm@26782
   604
wenzelm@42596
   605
  @{rail "
wenzelm@50063
   606
    (@@{attribute simp} | @@{attribute split} | @@{attribute cong})
wenzelm@50063
   607
      (() | 'add' | 'del')
wenzelm@42596
   608
  "}
wenzelm@26782
   609
wenzelm@28760
   610
  \begin{description}
wenzelm@26782
   611
wenzelm@28760
   612
  \item @{command "print_simpset"} prints the collection of rules
wenzelm@26782
   613
  declared to the Simplifier, which is also known as ``simpset''
wenzelm@50063
   614
  internally.
wenzelm@50063
   615
wenzelm@50063
   616
  For historical reasons, simpsets may occur independently from the
wenzelm@50063
   617
  current context, but are conceptually dependent on it.  When the
wenzelm@50063
   618
  Simplifier is invoked via one of its main entry points in the Isar
wenzelm@50063
   619
  source language (as proof method \secref{sec:simp-meth} or rule
wenzelm@50063
   620
  attribute \secref{sec:simp-meth}), its simpset is derived from the
wenzelm@50063
   621
  current proof context, and carries a back-reference to that for
wenzelm@50063
   622
  other tools that might get invoked internally (e.g.\ simplification
wenzelm@50063
   623
  procedures \secref{sec:simproc}).  A mismatch of the context of the
wenzelm@50063
   624
  simpset and the context of the problem being simplified may lead to
wenzelm@50063
   625
  unexpected results.
wenzelm@26782
   626
wenzelm@50065
   627
  \item @{attribute simp} declares simplification rules, by adding or
wenzelm@50065
   628
  deleting them from the simpset within the theory or proof context.
wenzelm@50065
   629
wenzelm@50065
   630
  Internally, all rewrite rules have to be expressed as Pure
wenzelm@50065
   631
  equalities, potentially with some conditions of arbitrary form.
wenzelm@50065
   632
  Such rewrite rules in Pure are derived automatically from
wenzelm@50065
   633
  object-level equations that are supplied by the user.
wenzelm@26782
   634
wenzelm@28760
   635
  \item @{attribute split} declares case split rules.
wenzelm@26782
   636
wenzelm@45645
   637
  \item @{attribute cong} declares congruence rules to the Simplifier
wenzelm@45645
   638
  context.
wenzelm@45645
   639
wenzelm@45645
   640
  Congruence rules are equalities of the form @{text [display]
wenzelm@45645
   641
  "\<dots> \<Longrightarrow> f ?x\<^sub>1 \<dots> ?x\<^sub>n = f ?y\<^sub>1 \<dots> ?y\<^sub>n"}
wenzelm@45645
   642
wenzelm@45645
   643
  This controls the simplification of the arguments of @{text f}.  For
wenzelm@45645
   644
  example, some arguments can be simplified under additional
wenzelm@45645
   645
  assumptions: @{text [display] "?P\<^sub>1 \<longleftrightarrow> ?Q\<^sub>1 \<Longrightarrow> (?Q\<^sub>1 \<Longrightarrow> ?P\<^sub>2 \<longleftrightarrow> ?Q\<^sub>2) \<Longrightarrow>
wenzelm@45645
   646
  (?P\<^sub>1 \<longrightarrow> ?P\<^sub>2) \<longleftrightarrow> (?Q\<^sub>1 \<longrightarrow> ?Q\<^sub>2)"}
wenzelm@45645
   647
wenzelm@45645
   648
  Given this rule, the simplifier assumes @{text "?Q\<^sub>1"} and extracts
wenzelm@45645
   649
  rewrite rules from it when simplifying @{text "?P\<^sub>2"}.  Such local
wenzelm@45645
   650
  assumptions are effective for rewriting formulae such as @{text "x =
wenzelm@45645
   651
  0 \<longrightarrow> y + x = y"}.
wenzelm@45645
   652
wenzelm@45645
   653
  %FIXME
wenzelm@45645
   654
  %The local assumptions are also provided as theorems to the solver;
wenzelm@45645
   655
  %see \secref{sec:simp-solver} below.
wenzelm@45645
   656
wenzelm@45645
   657
  \medskip The following congruence rule for bounded quantifiers also
wenzelm@45645
   658
  supplies contextual information --- about the bound variable:
wenzelm@45645
   659
  @{text [display] "(?A = ?B) \<Longrightarrow> (\<And>x. x \<in> ?B \<Longrightarrow> ?P x \<longleftrightarrow> ?Q x) \<Longrightarrow>
wenzelm@45645
   660
    (\<forall>x \<in> ?A. ?P x) \<longleftrightarrow> (\<forall>x \<in> ?B. ?Q x)"}
wenzelm@45645
   661
wenzelm@45645
   662
  \medskip This congruence rule for conditional expressions can
wenzelm@45645
   663
  supply contextual information for simplifying the arms:
wenzelm@45645
   664
  @{text [display] "?p = ?q \<Longrightarrow> (?q \<Longrightarrow> ?a = ?c) \<Longrightarrow> (\<not> ?q \<Longrightarrow> ?b = ?d) \<Longrightarrow>
wenzelm@45645
   665
    (if ?p then ?a else ?b) = (if ?q then ?c else ?d)"}
wenzelm@45645
   666
wenzelm@45645
   667
  A congruence rule can also \emph{prevent} simplification of some
wenzelm@45645
   668
  arguments.  Here is an alternative congruence rule for conditional
wenzelm@45645
   669
  expressions that conforms to non-strict functional evaluation:
wenzelm@45645
   670
  @{text [display] "?p = ?q \<Longrightarrow> (if ?p then ?a else ?b) = (if ?q then ?a else ?b)"}
wenzelm@45645
   671
wenzelm@45645
   672
  Only the first argument is simplified; the others remain unchanged.
wenzelm@45645
   673
  This can make simplification much faster, but may require an extra
wenzelm@45645
   674
  case split over the condition @{text "?q"} to prove the goal.
wenzelm@50063
   675
wenzelm@50063
   676
  \end{description}
wenzelm@50065
   677
wenzelm@50065
   678
  The implicit simpset of the theory context is propagated
wenzelm@50065
   679
  monotonically through the theory hierarchy: forming a new theory,
wenzelm@50065
   680
  the union of the simpsets of its imports are taken as starting
wenzelm@50065
   681
  point.  Also note that definitional packages like @{command
wenzelm@50065
   682
  "datatype"}, @{command "primrec"}, @{command "fun"} routinely
wenzelm@50065
   683
  declare Simplifier rules to the target context, while plain
wenzelm@50065
   684
  @{command "definition"} is an exception in \emph{not} declaring
wenzelm@50065
   685
  anything.
wenzelm@50065
   686
wenzelm@50065
   687
  \medskip It is up the user to manipulate the current simpset further
wenzelm@50065
   688
  by explicitly adding or deleting theorems as simplification rules,
wenzelm@50065
   689
  or installing other tools via simplification procedures
wenzelm@50065
   690
  (\secref{sec:simproc}).  Good simpsets are hard to design.  Rules
wenzelm@50065
   691
  that obviously simplify, like @{text "?n + 0 \<equiv> ?n"} are good
wenzelm@50065
   692
  candidates for the implicit simpset, unless a special
wenzelm@50065
   693
  non-normalizing behavior of certain operations is intended.  More
wenzelm@50065
   694
  specific rules (such as distributive laws, which duplicate subterms)
wenzelm@50065
   695
  should be added only for specific proof steps.  Conversely,
wenzelm@50065
   696
  sometimes a rule needs to be deleted just for some part of a proof.
wenzelm@50065
   697
  The need of frequent additions or deletions may indicate a poorly
wenzelm@50065
   698
  designed simpset.
wenzelm@50065
   699
wenzelm@50065
   700
  \begin{warn}
wenzelm@50065
   701
  The union of simpsets from theory imports (as described above) is
wenzelm@50065
   702
  not always a good starting point for the new theory.  If some
wenzelm@50065
   703
  ancestors have deleted simplification rules because they are no
wenzelm@50065
   704
  longer wanted, while others have left those rules in, then the union
wenzelm@50065
   705
  will contain the unwanted rules, and thus have to be deleted again
wenzelm@50065
   706
  in the theory body.
wenzelm@50065
   707
  \end{warn}
wenzelm@45645
   708
*}
wenzelm@45645
   709
wenzelm@45645
   710
wenzelm@50063
   711
subsection {* Configuration options \label{sec:simp-config} *}
wenzelm@50063
   712
wenzelm@50063
   713
text {*
wenzelm@50063
   714
  \begin{tabular}{rcll}
wenzelm@50063
   715
    @{attribute_def simp_depth_limit} & : & @{text attribute} & default @{text 100} \\
wenzelm@50063
   716
    @{attribute_def simp_trace} & : & @{text attribute} & default @{text false} \\
wenzelm@50063
   717
    @{attribute_def simp_trace_depth_limit} & : & @{text attribute} & default @{text 1} \\
wenzelm@50063
   718
    @{attribute_def simp_debug} & : & @{text attribute} & default @{text false} \\
wenzelm@50063
   719
  \end{tabular}
wenzelm@50063
   720
  \medskip
wenzelm@50063
   721
wenzelm@50063
   722
  These configurations options control further aspects of the Simplifier.
wenzelm@50063
   723
  See also \secref{sec:config}.
wenzelm@50063
   724
wenzelm@50063
   725
  \begin{description}
wenzelm@50063
   726
wenzelm@50063
   727
  \item @{attribute simp_depth_limit} limits the number of recursive
wenzelm@50063
   728
  invocations of the Simplifier during conditional rewriting.
wenzelm@50063
   729
wenzelm@50063
   730
  \item @{attribute simp_trace} makes the Simplifier output internal
wenzelm@50063
   731
  operations.  This includes rewrite steps, but also bookkeeping like
wenzelm@50063
   732
  modifications of the simpset.
wenzelm@50063
   733
wenzelm@50063
   734
  \item @{attribute simp_trace_depth_limit} limits the effect of
wenzelm@50063
   735
  @{attribute simp_trace} to the given depth of recursive Simplifier
wenzelm@50063
   736
  invocations (when solving conditions of rewrite rules).
wenzelm@50063
   737
wenzelm@50063
   738
  \item @{attribute simp_debug} makes the Simplifier output some extra
wenzelm@50063
   739
  information about internal operations.  This includes any attempted
wenzelm@50063
   740
  invocation of simplification procedures.
wenzelm@50063
   741
wenzelm@50063
   742
  \end{description}
wenzelm@50063
   743
*}
wenzelm@50063
   744
wenzelm@50063
   745
wenzelm@50063
   746
subsection {* Simplification procedures \label{sec:simproc} *}
wenzelm@26782
   747
wenzelm@42925
   748
text {* Simplification procedures are ML functions that produce proven
wenzelm@42925
   749
  rewrite rules on demand.  They are associated with higher-order
wenzelm@42925
   750
  patterns that approximate the left-hand sides of equations.  The
wenzelm@42925
   751
  Simplifier first matches the current redex against one of the LHS
wenzelm@42925
   752
  patterns; if this succeeds, the corresponding ML function is
wenzelm@42925
   753
  invoked, passing the Simplifier context and redex term.  Thus rules
wenzelm@42925
   754
  may be specifically fashioned for particular situations, resulting
wenzelm@42925
   755
  in a more powerful mechanism than term rewriting by a fixed set of
wenzelm@42925
   756
  rules.
wenzelm@42925
   757
wenzelm@42925
   758
  Any successful result needs to be a (possibly conditional) rewrite
wenzelm@42925
   759
  rule @{text "t \<equiv> u"} that is applicable to the current redex.  The
wenzelm@42925
   760
  rule will be applied just as any ordinary rewrite rule.  It is
wenzelm@42925
   761
  expected to be already in \emph{internal form}, bypassing the
wenzelm@42925
   762
  automatic preprocessing of object-level equivalences.
wenzelm@42925
   763
wenzelm@26782
   764
  \begin{matharray}{rcl}
wenzelm@28761
   765
    @{command_def "simproc_setup"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
wenzelm@28761
   766
    simproc & : & @{text attribute} \\
wenzelm@26782
   767
  \end{matharray}
wenzelm@26782
   768
wenzelm@42596
   769
  @{rail "
wenzelm@42596
   770
    @@{command simproc_setup} @{syntax name} '(' (@{syntax term} + '|') ')' '='
wenzelm@42596
   771
      @{syntax text} \\ (@'identifier' (@{syntax nameref}+))?
wenzelm@26782
   772
    ;
wenzelm@26782
   773
wenzelm@42596
   774
    @@{attribute simproc} (('add' ':')? | 'del' ':') (@{syntax name}+)
wenzelm@42596
   775
  "}
wenzelm@26782
   776
wenzelm@28760
   777
  \begin{description}
wenzelm@26782
   778
wenzelm@28760
   779
  \item @{command "simproc_setup"} defines a named simplification
wenzelm@26782
   780
  procedure that is invoked by the Simplifier whenever any of the
wenzelm@26782
   781
  given term patterns match the current redex.  The implementation,
wenzelm@26782
   782
  which is provided as ML source text, needs to be of type @{ML_type
wenzelm@26782
   783
  "morphism -> simpset -> cterm -> thm option"}, where the @{ML_type
wenzelm@26782
   784
  cterm} represents the current redex @{text r} and the result is
wenzelm@26782
   785
  supposed to be some proven rewrite rule @{text "r \<equiv> r'"} (or a
wenzelm@26782
   786
  generalized version), or @{ML NONE} to indicate failure.  The
wenzelm@26782
   787
  @{ML_type simpset} argument holds the full context of the current
wenzelm@26782
   788
  Simplifier invocation, including the actual Isar proof context.  The
wenzelm@26782
   789
  @{ML_type morphism} informs about the difference of the original
wenzelm@26782
   790
  compilation context wrt.\ the one of the actual application later
wenzelm@26782
   791
  on.  The optional @{keyword "identifier"} specifies theorems that
wenzelm@26782
   792
  represent the logical content of the abstract theory of this
wenzelm@26782
   793
  simproc.
wenzelm@26782
   794
wenzelm@26782
   795
  Morphisms and identifiers are only relevant for simprocs that are
wenzelm@26782
   796
  defined within a local target context, e.g.\ in a locale.
wenzelm@26782
   797
wenzelm@28760
   798
  \item @{text "simproc add: name"} and @{text "simproc del: name"}
wenzelm@26782
   799
  add or delete named simprocs to the current Simplifier context.  The
wenzelm@26782
   800
  default is to add a simproc.  Note that @{command "simproc_setup"}
wenzelm@26782
   801
  already adds the new simproc to the subsequent context.
wenzelm@26782
   802
wenzelm@28760
   803
  \end{description}
wenzelm@26782
   804
*}
wenzelm@26782
   805
wenzelm@26782
   806
wenzelm@42925
   807
subsubsection {* Example *}
wenzelm@42925
   808
wenzelm@42925
   809
text {* The following simplification procedure for @{thm
wenzelm@42925
   810
  [source=false, show_types] unit_eq} in HOL performs fine-grained
wenzelm@42925
   811
  control over rule application, beyond higher-order pattern matching.
wenzelm@42925
   812
  Declaring @{thm unit_eq} as @{attribute simp} directly would make
wenzelm@42925
   813
  the simplifier loop!  Note that a version of this simplification
wenzelm@42925
   814
  procedure is already active in Isabelle/HOL.  *}
wenzelm@42925
   815
wenzelm@42925
   816
simproc_setup unit ("x::unit") = {*
wenzelm@42925
   817
  fn _ => fn _ => fn ct =>
wenzelm@42925
   818
    if HOLogic.is_unit (term_of ct) then NONE
wenzelm@42925
   819
    else SOME (mk_meta_eq @{thm unit_eq})
wenzelm@42925
   820
*}
wenzelm@42925
   821
wenzelm@42925
   822
text {* Since the Simplifier applies simplification procedures
wenzelm@42925
   823
  frequently, it is important to make the failure check in ML
wenzelm@42925
   824
  reasonably fast. *}
wenzelm@42925
   825
wenzelm@42925
   826
wenzelm@50063
   827
subsection {* Forward simplification \label{sec:simp-forward} *}
wenzelm@26782
   828
wenzelm@26782
   829
text {*
wenzelm@26782
   830
  \begin{matharray}{rcl}
wenzelm@28761
   831
    @{attribute_def simplified} & : & @{text attribute} \\
wenzelm@26782
   832
  \end{matharray}
wenzelm@26782
   833
wenzelm@42596
   834
  @{rail "
wenzelm@42596
   835
    @@{attribute simplified} opt? @{syntax thmrefs}?
wenzelm@26782
   836
    ;
wenzelm@26782
   837
wenzelm@40255
   838
    opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use') ')'
wenzelm@42596
   839
  "}
wenzelm@26782
   840
wenzelm@28760
   841
  \begin{description}
wenzelm@26782
   842
  
wenzelm@28760
   843
  \item @{attribute simplified}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} causes a theorem to
wenzelm@28760
   844
  be simplified, either by exactly the specified rules @{text "a\<^sub>1, \<dots>,
wenzelm@28760
   845
  a\<^sub>n"}, or the implicit Simplifier context if no arguments are given.
wenzelm@28760
   846
  The result is fully simplified by default, including assumptions and
wenzelm@28760
   847
  conclusion; the options @{text no_asm} etc.\ tune the Simplifier in
wenzelm@28760
   848
  the same way as the for the @{text simp} method.
wenzelm@26782
   849
wenzelm@26782
   850
  Note that forward simplification restricts the simplifier to its
wenzelm@26782
   851
  most basic operation of term rewriting; solver and looper tactics
wenzelm@50068
   852
  \cite{isabelle-ref} are \emph{not} involved here.  The @{attribute
wenzelm@26782
   853
  simplified} attribute should be only rarely required under normal
wenzelm@26782
   854
  circumstances.
wenzelm@26782
   855
wenzelm@28760
   856
  \end{description}
wenzelm@26782
   857
*}
wenzelm@26782
   858
wenzelm@26782
   859
wenzelm@27040
   860
section {* The Classical Reasoner \label{sec:classical} *}
wenzelm@26782
   861
wenzelm@42930
   862
subsection {* Basic concepts *}
wenzelm@42927
   863
wenzelm@42927
   864
text {* Although Isabelle is generic, many users will be working in
wenzelm@42927
   865
  some extension of classical first-order logic.  Isabelle/ZF is built
wenzelm@42927
   866
  upon theory FOL, while Isabelle/HOL conceptually contains
wenzelm@42927
   867
  first-order logic as a fragment.  Theorem-proving in predicate logic
wenzelm@42927
   868
  is undecidable, but many automated strategies have been developed to
wenzelm@42927
   869
  assist in this task.
wenzelm@42927
   870
wenzelm@42927
   871
  Isabelle's classical reasoner is a generic package that accepts
wenzelm@42927
   872
  certain information about a logic and delivers a suite of automatic
wenzelm@42927
   873
  proof tools, based on rules that are classified and declared in the
wenzelm@42927
   874
  context.  These proof procedures are slow and simplistic compared
wenzelm@42927
   875
  with high-end automated theorem provers, but they can save
wenzelm@42927
   876
  considerable time and effort in practice.  They can prove theorems
wenzelm@42927
   877
  such as Pelletier's \cite{pelletier86} problems 40 and 41 in a few
wenzelm@42927
   878
  milliseconds (including full proof reconstruction): *}
wenzelm@42927
   879
wenzelm@42927
   880
lemma "(\<exists>y. \<forall>x. F x y \<longleftrightarrow> F x x) \<longrightarrow> \<not> (\<forall>x. \<exists>y. \<forall>z. F z y \<longleftrightarrow> \<not> F z x)"
wenzelm@42927
   881
  by blast
wenzelm@42927
   882
wenzelm@42927
   883
lemma "(\<forall>z. \<exists>y. \<forall>x. f x y \<longleftrightarrow> f x z \<and> \<not> f x x) \<longrightarrow> \<not> (\<exists>z. \<forall>x. f x z)"
wenzelm@42927
   884
  by blast
wenzelm@42927
   885
wenzelm@42927
   886
text {* The proof tools are generic.  They are not restricted to
wenzelm@42927
   887
  first-order logic, and have been heavily used in the development of
wenzelm@42927
   888
  the Isabelle/HOL library and applications.  The tactics can be
wenzelm@42927
   889
  traced, and their components can be called directly; in this manner,
wenzelm@42927
   890
  any proof can be viewed interactively.  *}
wenzelm@42927
   891
wenzelm@42927
   892
wenzelm@42927
   893
subsubsection {* The sequent calculus *}
wenzelm@42927
   894
wenzelm@42927
   895
text {* Isabelle supports natural deduction, which is easy to use for
wenzelm@42927
   896
  interactive proof.  But natural deduction does not easily lend
wenzelm@42927
   897
  itself to automation, and has a bias towards intuitionism.  For
wenzelm@42927
   898
  certain proofs in classical logic, it can not be called natural.
wenzelm@42927
   899
  The \emph{sequent calculus}, a generalization of natural deduction,
wenzelm@42927
   900
  is easier to automate.
wenzelm@42927
   901
wenzelm@42927
   902
  A \textbf{sequent} has the form @{text "\<Gamma> \<turnstile> \<Delta>"}, where @{text "\<Gamma>"}
wenzelm@42927
   903
  and @{text "\<Delta>"} are sets of formulae.\footnote{For first-order
wenzelm@42927
   904
  logic, sequents can equivalently be made from lists or multisets of
wenzelm@42927
   905
  formulae.} The sequent @{text "P\<^sub>1, \<dots>, P\<^sub>m \<turnstile> Q\<^sub>1, \<dots>, Q\<^sub>n"} is
wenzelm@42927
   906
  \textbf{valid} if @{text "P\<^sub>1 \<and> \<dots> \<and> P\<^sub>m"} implies @{text "Q\<^sub>1 \<or> \<dots> \<or>
wenzelm@42927
   907
  Q\<^sub>n"}.  Thus @{text "P\<^sub>1, \<dots>, P\<^sub>m"} represent assumptions, each of which
wenzelm@42927
   908
  is true, while @{text "Q\<^sub>1, \<dots>, Q\<^sub>n"} represent alternative goals.  A
wenzelm@42927
   909
  sequent is \textbf{basic} if its left and right sides have a common
wenzelm@42927
   910
  formula, as in @{text "P, Q \<turnstile> Q, R"}; basic sequents are trivially
wenzelm@42927
   911
  valid.
wenzelm@42927
   912
wenzelm@42927
   913
  Sequent rules are classified as \textbf{right} or \textbf{left},
wenzelm@42927
   914
  indicating which side of the @{text "\<turnstile>"} symbol they operate on.
wenzelm@42927
   915
  Rules that operate on the right side are analogous to natural
wenzelm@42927
   916
  deduction's introduction rules, and left rules are analogous to
wenzelm@42927
   917
  elimination rules.  The sequent calculus analogue of @{text "(\<longrightarrow>I)"}
wenzelm@42927
   918
  is the rule
wenzelm@42927
   919
  \[
wenzelm@42927
   920
  \infer[@{text "(\<longrightarrow>R)"}]{@{text "\<Gamma> \<turnstile> \<Delta>, P \<longrightarrow> Q"}}{@{text "P, \<Gamma> \<turnstile> \<Delta>, Q"}}
wenzelm@42927
   921
  \]
wenzelm@42927
   922
  Applying the rule backwards, this breaks down some implication on
wenzelm@42927
   923
  the right side of a sequent; @{text "\<Gamma>"} and @{text "\<Delta>"} stand for
wenzelm@42927
   924
  the sets of formulae that are unaffected by the inference.  The
wenzelm@42927
   925
  analogue of the pair @{text "(\<or>I1)"} and @{text "(\<or>I2)"} is the
wenzelm@42927
   926
  single rule
wenzelm@42927
   927
  \[
wenzelm@42927
   928
  \infer[@{text "(\<or>R)"}]{@{text "\<Gamma> \<turnstile> \<Delta>, P \<or> Q"}}{@{text "\<Gamma> \<turnstile> \<Delta>, P, Q"}}
wenzelm@42927
   929
  \]
wenzelm@42927
   930
  This breaks down some disjunction on the right side, replacing it by
wenzelm@42927
   931
  both disjuncts.  Thus, the sequent calculus is a kind of
wenzelm@42927
   932
  multiple-conclusion logic.
wenzelm@42927
   933
wenzelm@42927
   934
  To illustrate the use of multiple formulae on the right, let us
wenzelm@42927
   935
  prove the classical theorem @{text "(P \<longrightarrow> Q) \<or> (Q \<longrightarrow> P)"}.  Working
wenzelm@42927
   936
  backwards, we reduce this formula to a basic sequent:
wenzelm@42927
   937
  \[
wenzelm@42927
   938
  \infer[@{text "(\<or>R)"}]{@{text "\<turnstile> (P \<longrightarrow> Q) \<or> (Q \<longrightarrow> P)"}}
wenzelm@42927
   939
    {\infer[@{text "(\<longrightarrow>R)"}]{@{text "\<turnstile> (P \<longrightarrow> Q), (Q \<longrightarrow> P)"}}
wenzelm@42927
   940
      {\infer[@{text "(\<longrightarrow>R)"}]{@{text "P \<turnstile> Q, (Q \<longrightarrow> P)"}}
wenzelm@42927
   941
        {@{text "P, Q \<turnstile> Q, P"}}}}
wenzelm@42927
   942
  \]
wenzelm@42927
   943
wenzelm@42927
   944
  This example is typical of the sequent calculus: start with the
wenzelm@42927
   945
  desired theorem and apply rules backwards in a fairly arbitrary
wenzelm@42927
   946
  manner.  This yields a surprisingly effective proof procedure.
wenzelm@42927
   947
  Quantifiers add only few complications, since Isabelle handles
wenzelm@42927
   948
  parameters and schematic variables.  See \cite[Chapter
wenzelm@42927
   949
  10]{paulson-ml2} for further discussion.  *}
wenzelm@42927
   950
wenzelm@42927
   951
wenzelm@42927
   952
subsubsection {* Simulating sequents by natural deduction *}
wenzelm@42927
   953
wenzelm@42927
   954
text {* Isabelle can represent sequents directly, as in the
wenzelm@42927
   955
  object-logic LK.  But natural deduction is easier to work with, and
wenzelm@42927
   956
  most object-logics employ it.  Fortunately, we can simulate the
wenzelm@42927
   957
  sequent @{text "P\<^sub>1, \<dots>, P\<^sub>m \<turnstile> Q\<^sub>1, \<dots>, Q\<^sub>n"} by the Isabelle formula
wenzelm@42927
   958
  @{text "P\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> P\<^sub>m \<Longrightarrow> \<not> Q\<^sub>2 \<Longrightarrow> ... \<Longrightarrow> \<not> Q\<^sub>n \<Longrightarrow> Q\<^sub>1"} where the order of
wenzelm@42927
   959
  the assumptions and the choice of @{text "Q\<^sub>1"} are arbitrary.
wenzelm@42927
   960
  Elim-resolution plays a key role in simulating sequent proofs.
wenzelm@42927
   961
wenzelm@42927
   962
  We can easily handle reasoning on the left.  Elim-resolution with
wenzelm@42927
   963
  the rules @{text "(\<or>E)"}, @{text "(\<bottom>E)"} and @{text "(\<exists>E)"} achieves
wenzelm@42927
   964
  a similar effect as the corresponding sequent rules.  For the other
wenzelm@42927
   965
  connectives, we use sequent-style elimination rules instead of
wenzelm@42927
   966
  destruction rules such as @{text "(\<and>E1, 2)"} and @{text "(\<forall>E)"}.
wenzelm@42927
   967
  But note that the rule @{text "(\<not>L)"} has no effect under our
wenzelm@42927
   968
  representation of sequents!
wenzelm@42927
   969
  \[
wenzelm@42927
   970
  \infer[@{text "(\<not>L)"}]{@{text "\<not> P, \<Gamma> \<turnstile> \<Delta>"}}{@{text "\<Gamma> \<turnstile> \<Delta>, P"}}
wenzelm@42927
   971
  \]
wenzelm@42927
   972
wenzelm@42927
   973
  What about reasoning on the right?  Introduction rules can only
wenzelm@42927
   974
  affect the formula in the conclusion, namely @{text "Q\<^sub>1"}.  The
wenzelm@42927
   975
  other right-side formulae are represented as negated assumptions,
wenzelm@42927
   976
  @{text "\<not> Q\<^sub>2, \<dots>, \<not> Q\<^sub>n"}.  In order to operate on one of these, it
wenzelm@42927
   977
  must first be exchanged with @{text "Q\<^sub>1"}.  Elim-resolution with the
wenzelm@42927
   978
  @{text swap} rule has this effect: @{text "\<not> P \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> R"}
wenzelm@42927
   979
wenzelm@42927
   980
  To ensure that swaps occur only when necessary, each introduction
wenzelm@42927
   981
  rule is converted into a swapped form: it is resolved with the
wenzelm@42927
   982
  second premise of @{text "(swap)"}.  The swapped form of @{text
wenzelm@42927
   983
  "(\<and>I)"}, which might be called @{text "(\<not>\<and>E)"}, is
wenzelm@42927
   984
  @{text [display] "\<not> (P \<and> Q) \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> (\<not> R \<Longrightarrow> Q) \<Longrightarrow> R"}
wenzelm@42927
   985
wenzelm@42927
   986
  Similarly, the swapped form of @{text "(\<longrightarrow>I)"} is
wenzelm@42927
   987
  @{text [display] "\<not> (P \<longrightarrow> Q) \<Longrightarrow> (\<not> R \<Longrightarrow> P \<Longrightarrow> Q) \<Longrightarrow> R"}
wenzelm@42927
   988
wenzelm@42927
   989
  Swapped introduction rules are applied using elim-resolution, which
wenzelm@42927
   990
  deletes the negated formula.  Our representation of sequents also
wenzelm@42927
   991
  requires the use of ordinary introduction rules.  If we had no
wenzelm@42927
   992
  regard for readability of intermediate goal states, we could treat
wenzelm@42927
   993
  the right side more uniformly by representing sequents as @{text
wenzelm@42927
   994
  [display] "P\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> P\<^sub>m \<Longrightarrow> \<not> Q\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> \<not> Q\<^sub>n \<Longrightarrow> \<bottom>"}
wenzelm@42927
   995
*}
wenzelm@42927
   996
wenzelm@42927
   997
wenzelm@42927
   998
subsubsection {* Extra rules for the sequent calculus *}
wenzelm@42927
   999
wenzelm@42927
  1000
text {* As mentioned, destruction rules such as @{text "(\<and>E1, 2)"} and
wenzelm@42927
  1001
  @{text "(\<forall>E)"} must be replaced by sequent-style elimination rules.
wenzelm@42927
  1002
  In addition, we need rules to embody the classical equivalence
wenzelm@42927
  1003
  between @{text "P \<longrightarrow> Q"} and @{text "\<not> P \<or> Q"}.  The introduction
wenzelm@42927
  1004
  rules @{text "(\<or>I1, 2)"} are replaced by a rule that simulates
wenzelm@42927
  1005
  @{text "(\<or>R)"}: @{text [display] "(\<not> Q \<Longrightarrow> P) \<Longrightarrow> P \<or> Q"}
wenzelm@42927
  1006
wenzelm@42927
  1007
  The destruction rule @{text "(\<longrightarrow>E)"} is replaced by @{text [display]
wenzelm@42927
  1008
  "(P \<longrightarrow> Q) \<Longrightarrow> (\<not> P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"}
wenzelm@42927
  1009
wenzelm@42927
  1010
  Quantifier replication also requires special rules.  In classical
wenzelm@42927
  1011
  logic, @{text "\<exists>x. P x"} is equivalent to @{text "\<not> (\<forall>x. \<not> P x)"};
wenzelm@42927
  1012
  the rules @{text "(\<exists>R)"} and @{text "(\<forall>L)"} are dual:
wenzelm@42927
  1013
  \[
wenzelm@42927
  1014
  \infer[@{text "(\<exists>R)"}]{@{text "\<Gamma> \<turnstile> \<Delta>, \<exists>x. P x"}}{@{text "\<Gamma> \<turnstile> \<Delta>, \<exists>x. P x, P t"}}
wenzelm@42927
  1015
  \qquad
wenzelm@42927
  1016
  \infer[@{text "(\<forall>L)"}]{@{text "\<forall>x. P x, \<Gamma> \<turnstile> \<Delta>"}}{@{text "P t, \<forall>x. P x, \<Gamma> \<turnstile> \<Delta>"}}
wenzelm@42927
  1017
  \]
wenzelm@42927
  1018
  Thus both kinds of quantifier may be replicated.  Theorems requiring
wenzelm@42927
  1019
  multiple uses of a universal formula are easy to invent; consider
wenzelm@42927
  1020
  @{text [display] "(\<forall>x. P x \<longrightarrow> P (f x)) \<and> P a \<longrightarrow> P (f\<^sup>n a)"} for any
wenzelm@42927
  1021
  @{text "n > 1"}.  Natural examples of the multiple use of an
wenzelm@42927
  1022
  existential formula are rare; a standard one is @{text "\<exists>x. \<forall>y. P x
wenzelm@42927
  1023
  \<longrightarrow> P y"}.
wenzelm@42927
  1024
wenzelm@42927
  1025
  Forgoing quantifier replication loses completeness, but gains
wenzelm@42927
  1026
  decidability, since the search space becomes finite.  Many useful
wenzelm@42927
  1027
  theorems can be proved without replication, and the search generally
wenzelm@42927
  1028
  delivers its verdict in a reasonable time.  To adopt this approach,
wenzelm@42927
  1029
  represent the sequent rules @{text "(\<exists>R)"}, @{text "(\<exists>L)"} and
wenzelm@42927
  1030
  @{text "(\<forall>R)"} by @{text "(\<exists>I)"}, @{text "(\<exists>E)"} and @{text "(\<forall>I)"},
wenzelm@42927
  1031
  respectively, and put @{text "(\<forall>E)"} into elimination form: @{text
wenzelm@42927
  1032
  [display] "\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> Q) \<Longrightarrow> Q"}
wenzelm@42927
  1033
wenzelm@42927
  1034
  Elim-resolution with this rule will delete the universal formula
wenzelm@42927
  1035
  after a single use.  To replicate universal quantifiers, replace the
wenzelm@42927
  1036
  rule by @{text [display] "\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> \<forall>x. P x \<Longrightarrow> Q) \<Longrightarrow> Q"}
wenzelm@42927
  1037
wenzelm@42927
  1038
  To replicate existential quantifiers, replace @{text "(\<exists>I)"} by
wenzelm@42927
  1039
  @{text [display] "(\<not> (\<exists>x. P x) \<Longrightarrow> P t) \<Longrightarrow> \<exists>x. P x"}
wenzelm@42927
  1040
wenzelm@42927
  1041
  All introduction rules mentioned above are also useful in swapped
wenzelm@42927
  1042
  form.
wenzelm@42927
  1043
wenzelm@42927
  1044
  Replication makes the search space infinite; we must apply the rules
wenzelm@42927
  1045
  with care.  The classical reasoner distinguishes between safe and
wenzelm@42927
  1046
  unsafe rules, applying the latter only when there is no alternative.
wenzelm@42927
  1047
  Depth-first search may well go down a blind alley; best-first search
wenzelm@42927
  1048
  is better behaved in an infinite search space.  However, quantifier
wenzelm@42927
  1049
  replication is too expensive to prove any but the simplest theorems.
wenzelm@42927
  1050
*}
wenzelm@42927
  1051
wenzelm@42927
  1052
wenzelm@42928
  1053
subsection {* Rule declarations *}
wenzelm@42928
  1054
wenzelm@42928
  1055
text {* The proof tools of the Classical Reasoner depend on
wenzelm@42928
  1056
  collections of rules declared in the context, which are classified
wenzelm@42928
  1057
  as introduction, elimination or destruction and as \emph{safe} or
wenzelm@42928
  1058
  \emph{unsafe}.  In general, safe rules can be attempted blindly,
wenzelm@42928
  1059
  while unsafe rules must be used with care.  A safe rule must never
wenzelm@42928
  1060
  reduce a provable goal to an unprovable set of subgoals.
wenzelm@42928
  1061
wenzelm@42928
  1062
  The rule @{text "P \<Longrightarrow> P \<or> Q"} is unsafe because it reduces @{text "P
wenzelm@42928
  1063
  \<or> Q"} to @{text "P"}, which might turn out as premature choice of an
wenzelm@42928
  1064
  unprovable subgoal.  Any rule is unsafe whose premises contain new
wenzelm@42928
  1065
  unknowns.  The elimination rule @{text "\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> Q) \<Longrightarrow> Q"} is
wenzelm@42928
  1066
  unsafe, since it is applied via elim-resolution, which discards the
wenzelm@42928
  1067
  assumption @{text "\<forall>x. P x"} and replaces it by the weaker
wenzelm@42928
  1068
  assumption @{text "P t"}.  The rule @{text "P t \<Longrightarrow> \<exists>x. P x"} is
wenzelm@42928
  1069
  unsafe for similar reasons.  The quantifier duplication rule @{text
wenzelm@42928
  1070
  "\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> \<forall>x. P x \<Longrightarrow> Q) \<Longrightarrow> Q"} is unsafe in a different sense:
wenzelm@42928
  1071
  since it keeps the assumption @{text "\<forall>x. P x"}, it is prone to
wenzelm@42928
  1072
  looping.  In classical first-order logic, all rules are safe except
wenzelm@42928
  1073
  those mentioned above.
wenzelm@42928
  1074
wenzelm@42928
  1075
  The safe~/ unsafe distinction is vague, and may be regarded merely
wenzelm@42928
  1076
  as a way of giving some rules priority over others.  One could argue
wenzelm@42928
  1077
  that @{text "(\<or>E)"} is unsafe, because repeated application of it
wenzelm@42928
  1078
  could generate exponentially many subgoals.  Induction rules are
wenzelm@42928
  1079
  unsafe because inductive proofs are difficult to set up
wenzelm@42928
  1080
  automatically.  Any inference is unsafe that instantiates an unknown
wenzelm@42928
  1081
  in the proof state --- thus matching must be used, rather than
wenzelm@42928
  1082
  unification.  Even proof by assumption is unsafe if it instantiates
wenzelm@42928
  1083
  unknowns shared with other subgoals.
wenzelm@42928
  1084
wenzelm@42928
  1085
  \begin{matharray}{rcl}
wenzelm@42928
  1086
    @{command_def "print_claset"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@42928
  1087
    @{attribute_def intro} & : & @{text attribute} \\
wenzelm@42928
  1088
    @{attribute_def elim} & : & @{text attribute} \\
wenzelm@42928
  1089
    @{attribute_def dest} & : & @{text attribute} \\
wenzelm@42928
  1090
    @{attribute_def rule} & : & @{text attribute} \\
wenzelm@42928
  1091
    @{attribute_def iff} & : & @{text attribute} \\
wenzelm@42928
  1092
    @{attribute_def swapped} & : & @{text attribute} \\
wenzelm@42928
  1093
  \end{matharray}
wenzelm@42928
  1094
wenzelm@42928
  1095
  @{rail "
wenzelm@42928
  1096
    (@@{attribute intro} | @@{attribute elim} | @@{attribute dest}) ('!' | () | '?') @{syntax nat}?
wenzelm@42928
  1097
    ;
wenzelm@42928
  1098
    @@{attribute rule} 'del'
wenzelm@42928
  1099
    ;
wenzelm@42928
  1100
    @@{attribute iff} (((() | 'add') '?'?) | 'del')
wenzelm@42928
  1101
  "}
wenzelm@42928
  1102
wenzelm@42928
  1103
  \begin{description}
wenzelm@42928
  1104
wenzelm@42928
  1105
  \item @{command "print_claset"} prints the collection of rules
wenzelm@42928
  1106
  declared to the Classical Reasoner, i.e.\ the @{ML_type claset}
wenzelm@42928
  1107
  within the context.
wenzelm@42928
  1108
wenzelm@42928
  1109
  \item @{attribute intro}, @{attribute elim}, and @{attribute dest}
wenzelm@42928
  1110
  declare introduction, elimination, and destruction rules,
wenzelm@42928
  1111
  respectively.  By default, rules are considered as \emph{unsafe}
wenzelm@42928
  1112
  (i.e.\ not applied blindly without backtracking), while ``@{text
wenzelm@42928
  1113
  "!"}'' classifies as \emph{safe}.  Rule declarations marked by
wenzelm@42928
  1114
  ``@{text "?"}'' coincide with those of Isabelle/Pure, cf.\
wenzelm@42928
  1115
  \secref{sec:pure-meth-att} (i.e.\ are only applied in single steps
wenzelm@42928
  1116
  of the @{method rule} method).  The optional natural number
wenzelm@42928
  1117
  specifies an explicit weight argument, which is ignored by the
wenzelm@42928
  1118
  automated reasoning tools, but determines the search order of single
wenzelm@42928
  1119
  rule steps.
wenzelm@42928
  1120
wenzelm@42928
  1121
  Introduction rules are those that can be applied using ordinary
wenzelm@42928
  1122
  resolution.  Their swapped forms are generated internally, which
wenzelm@42928
  1123
  will be applied using elim-resolution.  Elimination rules are
wenzelm@42928
  1124
  applied using elim-resolution.  Rules are sorted by the number of
wenzelm@42928
  1125
  new subgoals they will yield; rules that generate the fewest
wenzelm@42928
  1126
  subgoals will be tried first.  Otherwise, later declarations take
wenzelm@42928
  1127
  precedence over earlier ones.
wenzelm@42928
  1128
wenzelm@42928
  1129
  Rules already present in the context with the same classification
wenzelm@42928
  1130
  are ignored.  A warning is printed if the rule has already been
wenzelm@42928
  1131
  added with some other classification, but the rule is added anyway
wenzelm@42928
  1132
  as requested.
wenzelm@42928
  1133
wenzelm@42928
  1134
  \item @{attribute rule}~@{text del} deletes all occurrences of a
wenzelm@42928
  1135
  rule from the classical context, regardless of its classification as
wenzelm@42928
  1136
  introduction~/ elimination~/ destruction and safe~/ unsafe.
wenzelm@42928
  1137
wenzelm@42928
  1138
  \item @{attribute iff} declares logical equivalences to the
wenzelm@42928
  1139
  Simplifier and the Classical reasoner at the same time.
wenzelm@42928
  1140
  Non-conditional rules result in a safe introduction and elimination
wenzelm@42928
  1141
  pair; conditional ones are considered unsafe.  Rules with negative
wenzelm@42928
  1142
  conclusion are automatically inverted (using @{text "\<not>"}-elimination
wenzelm@42928
  1143
  internally).
wenzelm@42928
  1144
wenzelm@42928
  1145
  The ``@{text "?"}'' version of @{attribute iff} declares rules to
wenzelm@42928
  1146
  the Isabelle/Pure context only, and omits the Simplifier
wenzelm@42928
  1147
  declaration.
wenzelm@42928
  1148
wenzelm@42928
  1149
  \item @{attribute swapped} turns an introduction rule into an
wenzelm@42928
  1150
  elimination, by resolving with the classical swap principle @{text
wenzelm@42928
  1151
  "\<not> P \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> R"} in the second position.  This is mainly for
wenzelm@42928
  1152
  illustrative purposes: the Classical Reasoner already swaps rules
wenzelm@42928
  1153
  internally as explained above.
wenzelm@42928
  1154
wenzelm@28760
  1155
  \end{description}
wenzelm@26782
  1156
*}
wenzelm@26782
  1157
wenzelm@26782
  1158
wenzelm@43365
  1159
subsection {* Structured methods *}
wenzelm@43365
  1160
wenzelm@43365
  1161
text {*
wenzelm@43365
  1162
  \begin{matharray}{rcl}
wenzelm@43365
  1163
    @{method_def rule} & : & @{text method} \\
wenzelm@43365
  1164
    @{method_def contradiction} & : & @{text method} \\
wenzelm@43365
  1165
  \end{matharray}
wenzelm@43365
  1166
wenzelm@43365
  1167
  @{rail "
wenzelm@43365
  1168
    @@{method rule} @{syntax thmrefs}?
wenzelm@43365
  1169
  "}
wenzelm@43365
  1170
wenzelm@43365
  1171
  \begin{description}
wenzelm@43365
  1172
wenzelm@43365
  1173
  \item @{method rule} as offered by the Classical Reasoner is a
wenzelm@43365
  1174
  refinement over the Pure one (see \secref{sec:pure-meth-att}).  Both
wenzelm@43365
  1175
  versions work the same, but the classical version observes the
wenzelm@43365
  1176
  classical rule context in addition to that of Isabelle/Pure.
wenzelm@43365
  1177
wenzelm@43365
  1178
  Common object logics (HOL, ZF, etc.) declare a rich collection of
wenzelm@43365
  1179
  classical rules (even if these would qualify as intuitionistic
wenzelm@43365
  1180
  ones), but only few declarations to the rule context of
wenzelm@43365
  1181
  Isabelle/Pure (\secref{sec:pure-meth-att}).
wenzelm@43365
  1182
wenzelm@43365
  1183
  \item @{method contradiction} solves some goal by contradiction,
wenzelm@43365
  1184
  deriving any result from both @{text "\<not> A"} and @{text A}.  Chained
wenzelm@43365
  1185
  facts, which are guaranteed to participate, may appear in either
wenzelm@43365
  1186
  order.
wenzelm@43365
  1187
wenzelm@43365
  1188
  \end{description}
wenzelm@43365
  1189
*}
wenzelm@43365
  1190
wenzelm@43365
  1191
wenzelm@27040
  1192
subsection {* Automated methods *}
wenzelm@26782
  1193
wenzelm@26782
  1194
text {*
wenzelm@26782
  1195
  \begin{matharray}{rcl}
wenzelm@28761
  1196
    @{method_def blast} & : & @{text method} \\
wenzelm@42930
  1197
    @{method_def auto} & : & @{text method} \\
wenzelm@42930
  1198
    @{method_def force} & : & @{text method} \\
wenzelm@28761
  1199
    @{method_def fast} & : & @{text method} \\
wenzelm@28761
  1200
    @{method_def slow} & : & @{text method} \\
wenzelm@28761
  1201
    @{method_def best} & : & @{text method} \\
nipkow@44911
  1202
    @{method_def fastforce} & : & @{text method} \\
wenzelm@28761
  1203
    @{method_def slowsimp} & : & @{text method} \\
wenzelm@28761
  1204
    @{method_def bestsimp} & : & @{text method} \\
wenzelm@43367
  1205
    @{method_def deepen} & : & @{text method} \\
wenzelm@26782
  1206
  \end{matharray}
wenzelm@26782
  1207
wenzelm@42596
  1208
  @{rail "
wenzelm@42930
  1209
    @@{method blast} @{syntax nat}? (@{syntax clamod} * )
wenzelm@42930
  1210
    ;
wenzelm@42596
  1211
    @@{method auto} (@{syntax nat} @{syntax nat})? (@{syntax clasimpmod} * )
wenzelm@26782
  1212
    ;
wenzelm@42930
  1213
    @@{method force} (@{syntax clasimpmod} * )
wenzelm@42930
  1214
    ;
wenzelm@42930
  1215
    (@@{method fast} | @@{method slow} | @@{method best}) (@{syntax clamod} * )
wenzelm@26782
  1216
    ;
nipkow@44911
  1217
    (@@{method fastforce} | @@{method slowsimp} | @@{method bestsimp})
wenzelm@42930
  1218
      (@{syntax clasimpmod} * )
wenzelm@42930
  1219
    ;
wenzelm@43367
  1220
    @@{method deepen} (@{syntax nat} ?) (@{syntax clamod} * )
wenzelm@43367
  1221
    ;
wenzelm@42930
  1222
    @{syntax_def clamod}:
wenzelm@42930
  1223
      (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del') ':' @{syntax thmrefs}
wenzelm@42930
  1224
    ;
wenzelm@42596
  1225
    @{syntax_def clasimpmod}: ('simp' (() | 'add' | 'del' | 'only') |
wenzelm@26782
  1226
      ('cong' | 'split') (() | 'add' | 'del') |
wenzelm@26782
  1227
      'iff' (((() | 'add') '?'?) | 'del') |
wenzelm@42596
  1228
      (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del')) ':' @{syntax thmrefs}
wenzelm@42596
  1229
  "}
wenzelm@26782
  1230
wenzelm@28760
  1231
  \begin{description}
wenzelm@26782
  1232
wenzelm@42930
  1233
  \item @{method blast} is a separate classical tableau prover that
wenzelm@42930
  1234
  uses the same classical rule declarations as explained before.
wenzelm@42930
  1235
wenzelm@42930
  1236
  Proof search is coded directly in ML using special data structures.
wenzelm@42930
  1237
  A successful proof is then reconstructed using regular Isabelle
wenzelm@42930
  1238
  inferences.  It is faster and more powerful than the other classical
wenzelm@42930
  1239
  reasoning tools, but has major limitations too.
wenzelm@42930
  1240
wenzelm@42930
  1241
  \begin{itemize}
wenzelm@42930
  1242
wenzelm@42930
  1243
  \item It does not use the classical wrapper tacticals, such as the
nipkow@44911
  1244
  integration with the Simplifier of @{method fastforce}.
wenzelm@42930
  1245
wenzelm@42930
  1246
  \item It does not perform higher-order unification, as needed by the
wenzelm@42930
  1247
  rule @{thm [source=false] rangeI} in HOL.  There are often
wenzelm@42930
  1248
  alternatives to such rules, for example @{thm [source=false]
wenzelm@42930
  1249
  range_eqI}.
wenzelm@42930
  1250
wenzelm@42930
  1251
  \item Function variables may only be applied to parameters of the
wenzelm@42930
  1252
  subgoal.  (This restriction arises because the prover does not use
wenzelm@42930
  1253
  higher-order unification.)  If other function variables are present
wenzelm@42930
  1254
  then the prover will fail with the message \texttt{Function Var's
wenzelm@42930
  1255
  argument not a bound variable}.
wenzelm@42930
  1256
wenzelm@42930
  1257
  \item Its proof strategy is more general than @{method fast} but can
wenzelm@42930
  1258
  be slower.  If @{method blast} fails or seems to be running forever,
wenzelm@42930
  1259
  try @{method fast} and the other proof tools described below.
wenzelm@42930
  1260
wenzelm@42930
  1261
  \end{itemize}
wenzelm@42930
  1262
wenzelm@42930
  1263
  The optional integer argument specifies a bound for the number of
wenzelm@42930
  1264
  unsafe steps used in a proof.  By default, @{method blast} starts
wenzelm@42930
  1265
  with a bound of 0 and increases it successively to 20.  In contrast,
wenzelm@42930
  1266
  @{text "(blast lim)"} tries to prove the goal using a search bound
wenzelm@42930
  1267
  of @{text "lim"}.  Sometimes a slow proof using @{method blast} can
wenzelm@42930
  1268
  be made much faster by supplying the successful search bound to this
wenzelm@42930
  1269
  proof method instead.
wenzelm@42930
  1270
wenzelm@42930
  1271
  \item @{method auto} combines classical reasoning with
wenzelm@42930
  1272
  simplification.  It is intended for situations where there are a lot
wenzelm@42930
  1273
  of mostly trivial subgoals; it proves all the easy ones, leaving the
wenzelm@42930
  1274
  ones it cannot prove.  Occasionally, attempting to prove the hard
wenzelm@42930
  1275
  ones may take a long time.
wenzelm@42930
  1276
wenzelm@43332
  1277
  The optional depth arguments in @{text "(auto m n)"} refer to its
wenzelm@43332
  1278
  builtin classical reasoning procedures: @{text m} (default 4) is for
wenzelm@43332
  1279
  @{method blast}, which is tried first, and @{text n} (default 2) is
wenzelm@43332
  1280
  for a slower but more general alternative that also takes wrappers
wenzelm@43332
  1281
  into account.
wenzelm@42930
  1282
wenzelm@42930
  1283
  \item @{method force} is intended to prove the first subgoal
wenzelm@42930
  1284
  completely, using many fancy proof tools and performing a rather
wenzelm@42930
  1285
  exhaustive search.  As a result, proof attempts may take rather long
wenzelm@42930
  1286
  or diverge easily.
wenzelm@42930
  1287
wenzelm@42930
  1288
  \item @{method fast}, @{method best}, @{method slow} attempt to
wenzelm@42930
  1289
  prove the first subgoal using sequent-style reasoning as explained
wenzelm@42930
  1290
  before.  Unlike @{method blast}, they construct proofs directly in
wenzelm@42930
  1291
  Isabelle.
wenzelm@26782
  1292
wenzelm@42930
  1293
  There is a difference in search strategy and back-tracking: @{method
wenzelm@42930
  1294
  fast} uses depth-first search and @{method best} uses best-first
wenzelm@42930
  1295
  search (guided by a heuristic function: normally the total size of
wenzelm@42930
  1296
  the proof state).
wenzelm@42930
  1297
wenzelm@42930
  1298
  Method @{method slow} is like @{method fast}, but conducts a broader
wenzelm@42930
  1299
  search: it may, when backtracking from a failed proof attempt, undo
wenzelm@42930
  1300
  even the step of proving a subgoal by assumption.
wenzelm@42930
  1301
wenzelm@47967
  1302
  \item @{method fastforce}, @{method slowsimp}, @{method bestsimp}
wenzelm@47967
  1303
  are like @{method fast}, @{method slow}, @{method best},
wenzelm@47967
  1304
  respectively, but use the Simplifier as additional wrapper. The name
wenzelm@47967
  1305
  @{method fastforce}, reflects the behaviour of this popular method
wenzelm@47967
  1306
  better without requiring an understanding of its implementation.
wenzelm@42930
  1307
wenzelm@43367
  1308
  \item @{method deepen} works by exhaustive search up to a certain
wenzelm@43367
  1309
  depth.  The start depth is 4 (unless specified explicitly), and the
wenzelm@43367
  1310
  depth is increased iteratively up to 10.  Unsafe rules are modified
wenzelm@43367
  1311
  to preserve the formula they act on, so that it be used repeatedly.
wenzelm@43367
  1312
  This method can prove more goals than @{method fast}, but is much
wenzelm@43367
  1313
  slower, for example if the assumptions have many universal
wenzelm@43367
  1314
  quantifiers.
wenzelm@43367
  1315
wenzelm@42930
  1316
  \end{description}
wenzelm@42930
  1317
wenzelm@42930
  1318
  Any of the above methods support additional modifiers of the context
wenzelm@42930
  1319
  of classical (and simplifier) rules, but the ones related to the
wenzelm@42930
  1320
  Simplifier are explicitly prefixed by @{text simp} here.  The
wenzelm@42930
  1321
  semantics of these ad-hoc rule declarations is analogous to the
wenzelm@42930
  1322
  attributes given before.  Facts provided by forward chaining are
wenzelm@42930
  1323
  inserted into the goal before commencing proof search.
wenzelm@42930
  1324
*}
wenzelm@42930
  1325
wenzelm@42930
  1326
wenzelm@42930
  1327
subsection {* Semi-automated methods *}
wenzelm@42930
  1328
wenzelm@42930
  1329
text {* These proof methods may help in situations when the
wenzelm@42930
  1330
  fully-automated tools fail.  The result is a simpler subgoal that
wenzelm@42930
  1331
  can be tackled by other means, such as by manual instantiation of
wenzelm@42930
  1332
  quantifiers.
wenzelm@42930
  1333
wenzelm@42930
  1334
  \begin{matharray}{rcl}
wenzelm@42930
  1335
    @{method_def safe} & : & @{text method} \\
wenzelm@42930
  1336
    @{method_def clarify} & : & @{text method} \\
wenzelm@42930
  1337
    @{method_def clarsimp} & : & @{text method} \\
wenzelm@42930
  1338
  \end{matharray}
wenzelm@42930
  1339
wenzelm@42930
  1340
  @{rail "
wenzelm@42930
  1341
    (@@{method safe} | @@{method clarify}) (@{syntax clamod} * )
wenzelm@42930
  1342
    ;
wenzelm@42930
  1343
    @@{method clarsimp} (@{syntax clasimpmod} * )
wenzelm@42930
  1344
  "}
wenzelm@42930
  1345
wenzelm@42930
  1346
  \begin{description}
wenzelm@42930
  1347
wenzelm@42930
  1348
  \item @{method safe} repeatedly performs safe steps on all subgoals.
wenzelm@42930
  1349
  It is deterministic, with at most one outcome.
wenzelm@42930
  1350
wenzelm@43366
  1351
  \item @{method clarify} performs a series of safe steps without
wenzelm@43366
  1352
  splitting subgoals; see also @{ML clarify_step_tac}.
wenzelm@42930
  1353
wenzelm@42930
  1354
  \item @{method clarsimp} acts like @{method clarify}, but also does
wenzelm@42930
  1355
  simplification.  Note that if the Simplifier context includes a
wenzelm@42930
  1356
  splitter for the premises, the subgoal may still be split.
wenzelm@26782
  1357
wenzelm@28760
  1358
  \end{description}
wenzelm@26782
  1359
*}
wenzelm@26782
  1360
wenzelm@26782
  1361
wenzelm@43366
  1362
subsection {* Single-step tactics *}
wenzelm@43366
  1363
wenzelm@43366
  1364
text {*
wenzelm@43366
  1365
  \begin{matharray}{rcl}
wenzelm@43366
  1366
    @{index_ML safe_step_tac: "Proof.context -> int -> tactic"} \\
wenzelm@43366
  1367
    @{index_ML inst_step_tac: "Proof.context -> int -> tactic"} \\
wenzelm@43366
  1368
    @{index_ML step_tac: "Proof.context -> int -> tactic"} \\
wenzelm@43366
  1369
    @{index_ML slow_step_tac: "Proof.context -> int -> tactic"} \\
wenzelm@43366
  1370
    @{index_ML clarify_step_tac: "Proof.context -> int -> tactic"} \\
wenzelm@43366
  1371
  \end{matharray}
wenzelm@43366
  1372
wenzelm@43366
  1373
  These are the primitive tactics behind the (semi)automated proof
wenzelm@43366
  1374
  methods of the Classical Reasoner.  By calling them yourself, you
wenzelm@43366
  1375
  can execute these procedures one step at a time.
wenzelm@43366
  1376
wenzelm@43366
  1377
  \begin{description}
wenzelm@43366
  1378
wenzelm@43366
  1379
  \item @{ML safe_step_tac}~@{text "ctxt i"} performs a safe step on
wenzelm@43366
  1380
  subgoal @{text i}.  The safe wrapper tacticals are applied to a
wenzelm@43366
  1381
  tactic that may include proof by assumption or Modus Ponens (taking
wenzelm@43366
  1382
  care not to instantiate unknowns), or substitution.
wenzelm@43366
  1383
wenzelm@43366
  1384
  \item @{ML inst_step_tac} is like @{ML safe_step_tac}, but allows
wenzelm@43366
  1385
  unknowns to be instantiated.
wenzelm@43366
  1386
wenzelm@43366
  1387
  \item @{ML step_tac}~@{text "ctxt i"} is the basic step of the proof
wenzelm@43366
  1388
  procedure.  The unsafe wrapper tacticals are applied to a tactic
wenzelm@43366
  1389
  that tries @{ML safe_tac}, @{ML inst_step_tac}, or applies an unsafe
wenzelm@43366
  1390
  rule from the context.
wenzelm@43366
  1391
wenzelm@43366
  1392
  \item @{ML slow_step_tac} resembles @{ML step_tac}, but allows
wenzelm@43366
  1393
  backtracking between using safe rules with instantiation (@{ML
wenzelm@43366
  1394
  inst_step_tac}) and using unsafe rules.  The resulting search space
wenzelm@43366
  1395
  is larger.
wenzelm@43366
  1396
wenzelm@43366
  1397
  \item @{ML clarify_step_tac}~@{text "ctxt i"} performs a safe step
wenzelm@43366
  1398
  on subgoal @{text i}.  No splitting step is applied; for example,
wenzelm@43366
  1399
  the subgoal @{text "A \<and> B"} is left as a conjunction.  Proof by
wenzelm@43366
  1400
  assumption, Modus Ponens, etc., may be performed provided they do
wenzelm@43366
  1401
  not instantiate unknowns.  Assumptions of the form @{text "x = t"}
wenzelm@43366
  1402
  may be eliminated.  The safe wrapper tactical is applied.
wenzelm@43366
  1403
wenzelm@43366
  1404
  \end{description}
wenzelm@43366
  1405
*}
wenzelm@43366
  1406
wenzelm@43366
  1407
wenzelm@27044
  1408
section {* Object-logic setup \label{sec:object-logic} *}
wenzelm@26790
  1409
wenzelm@26790
  1410
text {*
wenzelm@26790
  1411
  \begin{matharray}{rcl}
wenzelm@28761
  1412
    @{command_def "judgment"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28761
  1413
    @{method_def atomize} & : & @{text method} \\
wenzelm@28761
  1414
    @{attribute_def atomize} & : & @{text attribute} \\
wenzelm@28761
  1415
    @{attribute_def rule_format} & : & @{text attribute} \\
wenzelm@28761
  1416
    @{attribute_def rulify} & : & @{text attribute} \\
wenzelm@26790
  1417
  \end{matharray}
wenzelm@26790
  1418
wenzelm@26790
  1419
  The very starting point for any Isabelle object-logic is a ``truth
wenzelm@26790
  1420
  judgment'' that links object-level statements to the meta-logic
wenzelm@26790
  1421
  (with its minimal language of @{text prop} that covers universal
wenzelm@26790
  1422
  quantification @{text "\<And>"} and implication @{text "\<Longrightarrow>"}).
wenzelm@26790
  1423
wenzelm@26790
  1424
  Common object-logics are sufficiently expressive to internalize rule
wenzelm@26790
  1425
  statements over @{text "\<And>"} and @{text "\<Longrightarrow>"} within their own
wenzelm@26790
  1426
  language.  This is useful in certain situations where a rule needs
wenzelm@26790
  1427
  to be viewed as an atomic statement from the meta-level perspective,
wenzelm@26790
  1428
  e.g.\ @{text "\<And>x. x \<in> A \<Longrightarrow> P x"} versus @{text "\<forall>x \<in> A. P x"}.
wenzelm@26790
  1429
wenzelm@26790
  1430
  From the following language elements, only the @{method atomize}
wenzelm@26790
  1431
  method and @{attribute rule_format} attribute are occasionally
wenzelm@26790
  1432
  required by end-users, the rest is for those who need to setup their
wenzelm@26790
  1433
  own object-logic.  In the latter case existing formulations of
wenzelm@26790
  1434
  Isabelle/FOL or Isabelle/HOL may be taken as realistic examples.
wenzelm@26790
  1435
wenzelm@26790
  1436
  Generic tools may refer to the information provided by object-logic
wenzelm@26790
  1437
  declarations internally.
wenzelm@26790
  1438
wenzelm@42596
  1439
  @{rail "
wenzelm@46494
  1440
    @@{command judgment} @{syntax name} '::' @{syntax type} @{syntax mixfix}?
wenzelm@26790
  1441
    ;
wenzelm@42596
  1442
    @@{attribute atomize} ('(' 'full' ')')?
wenzelm@26790
  1443
    ;
wenzelm@42596
  1444
    @@{attribute rule_format} ('(' 'noasm' ')')?
wenzelm@42596
  1445
  "}
wenzelm@26790
  1446
wenzelm@28760
  1447
  \begin{description}
wenzelm@26790
  1448
  
wenzelm@28760
  1449
  \item @{command "judgment"}~@{text "c :: \<sigma> (mx)"} declares constant
wenzelm@28760
  1450
  @{text c} as the truth judgment of the current object-logic.  Its
wenzelm@28760
  1451
  type @{text \<sigma>} should specify a coercion of the category of
wenzelm@28760
  1452
  object-level propositions to @{text prop} of the Pure meta-logic;
wenzelm@28760
  1453
  the mixfix annotation @{text "(mx)"} would typically just link the
wenzelm@28760
  1454
  object language (internally of syntactic category @{text logic})
wenzelm@28760
  1455
  with that of @{text prop}.  Only one @{command "judgment"}
wenzelm@28760
  1456
  declaration may be given in any theory development.
wenzelm@26790
  1457
  
wenzelm@28760
  1458
  \item @{method atomize} (as a method) rewrites any non-atomic
wenzelm@26790
  1459
  premises of a sub-goal, using the meta-level equations declared via
wenzelm@26790
  1460
  @{attribute atomize} (as an attribute) beforehand.  As a result,
wenzelm@26790
  1461
  heavily nested goals become amenable to fundamental operations such
wenzelm@42626
  1462
  as resolution (cf.\ the @{method (Pure) rule} method).  Giving the ``@{text
wenzelm@26790
  1463
  "(full)"}'' option here means to turn the whole subgoal into an
wenzelm@26790
  1464
  object-statement (if possible), including the outermost parameters
wenzelm@26790
  1465
  and assumptions as well.
wenzelm@26790
  1466
wenzelm@26790
  1467
  A typical collection of @{attribute atomize} rules for a particular
wenzelm@26790
  1468
  object-logic would provide an internalization for each of the
wenzelm@26790
  1469
  connectives of @{text "\<And>"}, @{text "\<Longrightarrow>"}, and @{text "\<equiv>"}.
wenzelm@26790
  1470
  Meta-level conjunction should be covered as well (this is
wenzelm@26790
  1471
  particularly important for locales, see \secref{sec:locale}).
wenzelm@26790
  1472
wenzelm@28760
  1473
  \item @{attribute rule_format} rewrites a theorem by the equalities
wenzelm@28760
  1474
  declared as @{attribute rulify} rules in the current object-logic.
wenzelm@28760
  1475
  By default, the result is fully normalized, including assumptions
wenzelm@28760
  1476
  and conclusions at any depth.  The @{text "(no_asm)"} option
wenzelm@28760
  1477
  restricts the transformation to the conclusion of a rule.
wenzelm@26790
  1478
wenzelm@26790
  1479
  In common object-logics (HOL, FOL, ZF), the effect of @{attribute
wenzelm@26790
  1480
  rule_format} is to replace (bounded) universal quantification
wenzelm@26790
  1481
  (@{text "\<forall>"}) and implication (@{text "\<longrightarrow>"}) by the corresponding
wenzelm@26790
  1482
  rule statements over @{text "\<And>"} and @{text "\<Longrightarrow>"}.
wenzelm@26790
  1483
wenzelm@28760
  1484
  \end{description}
wenzelm@26790
  1485
*}
wenzelm@26790
  1486
wenzelm@26782
  1487
end