src/Doc/Isar_Ref/Generic.thy
author wenzelm
Tue, 20 Oct 2015 23:53:40 +0200
changeset 61493 0debd22f0c0e
parent 61477 e467ae7aa808
child 61572 ddb3ac3fef45
permissions -rw-r--r--
isabelle update_cartouches -t;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
     1
theory Generic
42651
e3fdb7c96be5 formal Base theory;
wenzelm
parents: 42626
diff changeset
     2
imports Base Main
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
     3
begin
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
     4
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
     5
chapter \<open>Generic tools and packages \label{ch:gen-tools}\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
     6
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
     7
section \<open>Configuration options \label{sec:config}\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
     8
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
     9
text \<open>Isabelle/Pure maintains a record of named configuration
40291
012ed4426fda support for real valued configuration options;
wenzelm
parents: 40255
diff changeset
    10
  options within the theory or proof context, with values of type
012ed4426fda support for real valued configuration options;
wenzelm
parents: 40255
diff changeset
    11
  @{ML_type bool}, @{ML_type int}, @{ML_type real}, or @{ML_type
012ed4426fda support for real valued configuration options;
wenzelm
parents: 40255
diff changeset
    12
  string}.  Tools may declare options in ML, and then refer to these
012ed4426fda support for real valued configuration options;
wenzelm
parents: 40255
diff changeset
    13
  values (relative to the context).  Thus global reference variables
012ed4426fda support for real valued configuration options;
wenzelm
parents: 40255
diff changeset
    14
  are easily avoided.  The user may change the value of a
012ed4426fda support for real valued configuration options;
wenzelm
parents: 40255
diff changeset
    15
  configuration option by means of an associated attribute of the same
012ed4426fda support for real valued configuration options;
wenzelm
parents: 40255
diff changeset
    16
  name.  This form of context declaration works particularly well with
42655
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    17
  commands such as @{command "declare"} or @{command "using"} like
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    18
  this:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    19
\<close>
42655
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    20
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
    21
(*<*)experiment begin(*>*)
42655
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    22
declare [[show_main_goal = false]]
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    23
42655
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    24
notepad
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    25
begin
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    26
  note [[show_main_goal = true]]
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    27
end
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
    28
(*<*)end(*>*)
42655
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    29
59921
5b919b13feee obsolete (see 8b7caf447357);
wenzelm
parents: 59917
diff changeset
    30
text \<open>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    31
  \begin{matharray}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    32
    @{command_def "print_options"} & : & \<open>context \<rightarrow>\<close> \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    33
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    34
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    35
  @{rail \<open>
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
    36
    @@{command print_options} ('!'?)
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
    37
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
    38
    @{syntax name} ('=' ('true' | 'false' | @{syntax int} | @{syntax float} | @{syntax name}))?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    39
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    40
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
    41
  \<^descr> @{command "print_options"} prints the available configuration
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    42
  options, with names, types, and current values; the ``\<open>!\<close>'' option
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
    43
  indicates extra verbosity.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    44
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    45
  \<^descr> \<open>name = value\<close> as an attribute expression modifies the
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    46
  named option, with the syntax of the value depending on the option's
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    47
  type.  For @{ML_type bool} the default value is \<open>true\<close>.  Any
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    48
  attempt to change a global option in a local context is ignored.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    49
\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    50
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    51
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    52
section \<open>Basic proof tools\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    53
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    54
subsection \<open>Miscellaneous methods and attributes \label{sec:misc-meth-att}\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    55
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
    56
text \<open>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    57
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    58
    @{method_def unfold} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    59
    @{method_def fold} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    60
    @{method_def insert} & : & \<open>method\<close> \\[0.5ex]
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    61
    @{method_def erule}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    62
    @{method_def drule}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    63
    @{method_def frule}\<open>\<^sup>*\<close> & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    64
    @{method_def intro} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    65
    @{method_def elim} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    66
    @{method_def fail} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    67
    @{method_def succeed} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    68
    @{method_def sleep} & : & \<open>method\<close> \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    69
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    70
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    71
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
    72
    (@@{method fold} | @@{method unfold} | @@{method insert}) @{syntax thmrefs}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    73
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
    74
    (@@{method erule} | @@{method drule} | @@{method frule})
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
    75
      ('(' @{syntax nat} ')')? @{syntax thmrefs}
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
    76
    ;
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
    77
    (@@{method intro} | @@{method elim}) @{syntax thmrefs}?
60556
wenzelm
parents: 60554
diff changeset
    78
    ;
wenzelm
parents: 60554
diff changeset
    79
    @@{method sleep} @{syntax real}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    80
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    81
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    82
  \<^descr> @{method unfold}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> and @{method fold}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> expand (or fold back) the given definitions throughout
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    83
  all goals; any chained facts provided are inserted into the goal and
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    84
  subject to rewriting as well.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    85
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    86
  \<^descr> @{method insert}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> inserts theorems as facts
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    87
  into all goals of the proof state.  Note that current facts
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    88
  indicated for forward chaining are ignored.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    89
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    90
  \<^descr> @{method erule}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close>, @{method
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
    91
  drule}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close>, and @{method frule}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> are similar to the basic @{method rule}
30397
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    92
  method (see \secref{sec:pure-meth-att}), but apply rules by
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    93
  elim-resolution, destruct-resolution, and forward-resolution,
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58310
diff changeset
    94
  respectively @{cite "isabelle-implementation"}.  The optional natural
30397
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    95
  number argument (default 0) specifies additional assumption steps to
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    96
  be performed here.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    97
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    98
  Note that these methods are improper ones, mainly serving for
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    99
  experimentation and tactic script emulation.  Different modes of
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   100
  basic rule application are usually expressed in Isar at the proof
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   101
  language level, rather than via implicit proof state manipulations.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   102
  For example, a proper single-step elimination would be done using
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   103
  the plain @{method rule} method, with forward chaining of current
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   104
  facts.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   105
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   106
  \<^descr> @{method intro} and @{method elim} repeatedly refine some goal
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   107
  by intro- or elim-resolution, after having inserted any chained
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   108
  facts.  Exactly the rules given as arguments are taken into account;
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   109
  this allows fine-tuned decomposition of a proof problem, in contrast
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   110
  to common automated tools.
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   111
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   112
  \<^descr> @{method fail} yields an empty result sequence; it is the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   113
  identity of the ``\<open>|\<close>'' method combinator (cf.\
60554
c0e1c121c7c0 added method "sleep";
wenzelm
parents: 60484
diff changeset
   114
  \secref{sec:proof-meth}).
c0e1c121c7c0 added method "sleep";
wenzelm
parents: 60484
diff changeset
   115
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   116
  \<^descr> @{method succeed} yields a single (unchanged) result; it is
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   117
  the identity of the ``\<open>,\<close>'' method combinator (cf.\
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27248
diff changeset
   118
  \secref{sec:proof-meth}).
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   119
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   120
  \<^descr> @{method sleep}~\<open>s\<close> succeeds after a real-time delay of \<open>s\<close> seconds. This is occasionally useful for demonstration and testing
60554
c0e1c121c7c0 added method "sleep";
wenzelm
parents: 60484
diff changeset
   121
  purposes.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   122
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   123
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   124
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   125
    @{attribute_def tagged} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   126
    @{attribute_def untagged} & : & \<open>attribute\<close> \\[0.5ex]
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   127
    @{attribute_def THEN} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   128
    @{attribute_def unfolded} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   129
    @{attribute_def folded} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   130
    @{attribute_def abs_def} & : & \<open>attribute\<close> \\[0.5ex]
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   131
    @{attribute_def rotated} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   132
    @{attribute_def (Pure) elim_format} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   133
    @{attribute_def no_vars}\<open>\<^sup>*\<close> & : & \<open>attribute\<close> \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   134
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   135
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   136
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   137
    @@{attribute tagged} @{syntax name} @{syntax name}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   138
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   139
    @@{attribute untagged} @{syntax name}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   140
    ;
48205
09c2a3d9aa22 discontinued obsolete attribute "COMP";
wenzelm
parents: 47967
diff changeset
   141
    @@{attribute THEN} ('[' @{syntax nat} ']')? @{syntax thmref}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   142
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   143
    (@@{attribute unfolded} | @@{attribute folded}) @{syntax thmrefs}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   144
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   145
    @@{attribute rotated} @{syntax int}?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   146
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   147
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   148
  \<^descr> @{attribute tagged}~\<open>name value\<close> and @{attribute
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   149
  untagged}~\<open>name\<close> add and remove \<^emph>\<open>tags\<close> of some theorem.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   150
  Tags may be any list of string pairs that serve as formal comment.
28764
b65194fe4434 fixed/tuned syntax for attribute "tagged";
wenzelm
parents: 28761
diff changeset
   151
  The first string is considered the tag name, the second its value.
b65194fe4434 fixed/tuned syntax for attribute "tagged";
wenzelm
parents: 28761
diff changeset
   152
  Note that @{attribute untagged} removes any tags of the same name.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   153
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   154
  \<^descr> @{attribute THEN}~\<open>a\<close> composes rules by resolution; it
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   155
  resolves with the first premise of \<open>a\<close> (an alternative
48205
09c2a3d9aa22 discontinued obsolete attribute "COMP";
wenzelm
parents: 47967
diff changeset
   156
  position may be also specified).  See also @{ML_op "RS"} in
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58310
diff changeset
   157
  @{cite "isabelle-implementation"}.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   158
  
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   159
  \<^descr> @{attribute unfolded}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> and @{attribute
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   160
  folded}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> expand and fold back again the given
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   161
  definitions throughout a rule.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   162
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   163
  \<^descr> @{attribute abs_def} turns an equation of the form @{prop "f x
47497
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   164
  y \<equiv> t"} into @{prop "f \<equiv> \<lambda>x y. t"}, which ensures that @{method
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   165
  simp} or @{method unfold} steps always expand it.  This also works
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   166
  for object-logic equality.
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   167
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   168
  \<^descr> @{attribute rotated}~\<open>n\<close> rotate the premises of a
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   169
  theorem by \<open>n\<close> (default 1).
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   170
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   171
  \<^descr> @{attribute (Pure) elim_format} turns a destruction rule into
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   172
  elimination rule format, by resolving with the rule @{prop "PROP A \<Longrightarrow>
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   173
  (PROP A \<Longrightarrow> PROP B) \<Longrightarrow> PROP B"}.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   174
  
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   175
  Note that the Classical Reasoner (\secref{sec:classical}) provides
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   176
  its own version of this operation.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   177
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   178
  \<^descr> @{attribute no_vars} replaces schematic variables by free
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   179
  ones; this is mainly for tuning output of pretty printed theorems.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   180
\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   181
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   182
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   183
subsection \<open>Low-level equational reasoning\<close>
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   184
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   185
text \<open>
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   186
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   187
    @{method_def subst} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   188
    @{method_def hypsubst} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   189
    @{method_def split} & : & \<open>method\<close> \\
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   190
  \end{matharray}
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   191
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   192
  @{rail \<open>
55029
61a6bf7d4b02 clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents: 52060
diff changeset
   193
    @@{method subst} ('(' 'asm' ')')? \<newline> ('(' (@{syntax nat}+) ')')? @{syntax thmref}
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   194
    ;
44094
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   195
    @@{method split} @{syntax thmrefs}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   196
  \<close>}
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   197
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   198
  These methods provide low-level facilities for equational reasoning
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   199
  that are intended for specialized applications only.  Normally,
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   200
  single step calculations would be performed in a structured text
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   201
  (see also \secref{sec:calculation}), while the Simplifier methods
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   202
  provide the canonical way for automated normalization (see
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   203
  \secref{sec:simplifier}).
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   204
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   205
  \<^descr> @{method subst}~\<open>eq\<close> performs a single substitution step
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   206
  using rule \<open>eq\<close>, which may be either a meta or object
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   207
  equality.
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   208
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   209
  \<^descr> @{method subst}~\<open>(asm) eq\<close> substitutes in an
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   210
  assumption.
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   211
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   212
  \<^descr> @{method subst}~\<open>(i \<dots> j) eq\<close> performs several
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   213
  substitutions in the conclusion. The numbers \<open>i\<close> to \<open>j\<close>
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   214
  indicate the positions to substitute at.  Positions are ordered from
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   215
  the top of the term tree moving down from left to right. For
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   216
  example, in \<open>(a + b) + (c + d)\<close> there are three positions
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   217
  where commutativity of \<open>+\<close> is applicable: 1 refers to \<open>a + b\<close>, 2 to the whole term, and 3 to \<open>c + d\<close>.
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   218
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   219
  If the positions in the list \<open>(i \<dots> j)\<close> are non-overlapping
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   220
  (e.g.\ \<open>(2 3)\<close> in \<open>(a + b) + (c + d)\<close>) you may
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   221
  assume all substitutions are performed simultaneously.  Otherwise
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   222
  the behaviour of \<open>subst\<close> is not specified.
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   223
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   224
  \<^descr> @{method subst}~\<open>(asm) (i \<dots> j) eq\<close> performs the
27071
614c045c5fd4 clarification of "subst" by Lucas Dixon;
wenzelm
parents: 27044
diff changeset
   225
  substitutions in the assumptions. The positions refer to the
614c045c5fd4 clarification of "subst" by Lucas Dixon;
wenzelm
parents: 27044
diff changeset
   226
  assumptions in order from left to right.  For example, given in a
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   227
  goal of the form \<open>P (a + b) \<Longrightarrow> P (c + d) \<Longrightarrow> \<dots>\<close>, position 1 of
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   228
  commutativity of \<open>+\<close> is the subterm \<open>a + b\<close> and
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   229
  position 2 is the subterm \<open>c + d\<close>.
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   230
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   231
  \<^descr> @{method hypsubst} performs substitution using some
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   232
  assumption; this only works for equations of the form \<open>x =
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   233
  t\<close> where \<open>x\<close> is a free or bound variable.
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   234
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   235
  \<^descr> @{method split}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> performs single-step case
44094
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   236
  splitting using the given rules.  Splitting is performed in the
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   237
  conclusion or some assumption of the subgoal, depending of the
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   238
  structure of the rule.
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   239
  
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   240
  Note that the @{method simp} method already involves repeated
44094
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   241
  application of split rules as declared in the current context, using
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   242
  @{attribute split}, for example.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   243
\<close>
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   244
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   245
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   246
section \<open>The Simplifier \label{sec:simplifier}\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   247
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   248
text \<open>The Simplifier performs conditional and unconditional
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   249
  rewriting and uses contextual information: rule declarations in the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   250
  background theory or local proof context are taken into account, as
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   251
  well as chained facts and subgoal premises (``local assumptions'').
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   252
  There are several general hooks that allow to modify the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   253
  simplification strategy, or incorporate other proof tools that solve
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   254
  sub-problems, produce rewrite rules on demand etc.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   255
50075
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   256
  The rewriting strategy is always strictly bottom up, except for
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   257
  congruence rules, which are applied while descending into a term.
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   258
  Conditions in conditional rewrite rules are solved recursively
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   259
  before the rewrite rule is applied.
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   260
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   261
  The default Simplifier setup of major object logics (HOL, HOLCF,
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   262
  FOL, ZF) makes the Simplifier ready for immediate use, without
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   263
  engaging into the internal structures.  Thus it serves as
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   264
  general-purpose proof tool with the main focus on equational
50075
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   265
  reasoning, and a bit more than that.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   266
\<close>
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   267
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   268
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   269
subsection \<open>Simplification methods \label{sec:simp-meth}\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   270
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   271
text \<open>
57591
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   272
  \begin{tabular}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   273
    @{method_def simp} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   274
    @{method_def simp_all} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   275
    @{attribute_def simp_depth_limit} & : & \<open>attribute\<close> & default \<open>100\<close> \\
57591
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   276
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   277
  \<^medskip>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   278
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   279
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   280
    (@@{method simp} | @@{method simp_all}) opt? (@{syntax simpmod} * )
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   281
    ;
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   282
40255
9ffbc25e1606 eliminated obsolete \_ escapes in rail environments;
wenzelm
parents: 35613
diff changeset
   283
    opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use' | 'asm_lr' ) ')'
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   284
    ;
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   285
    @{syntax_def simpmod}: ('add' | 'del' | 'only' | 'split' (() | 'add' | 'del') |
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   286
      'cong' (() | 'add' | 'del')) ':' @{syntax thmrefs}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   287
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   288
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   289
  \<^descr> @{method simp} invokes the Simplifier on the first subgoal,
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   290
  after inserting chained facts as additional goal premises; further
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   291
  rule declarations may be included via \<open>(simp add: facts)\<close>.
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   292
  The proof method fails if the subgoal remains unchanged after
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   293
  simplification.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   294
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   295
  Note that the original goal premises and chained facts are subject
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   296
  to simplification themselves, while declarations via \<open>add\<close>/\<open>del\<close> merely follow the policies of the object-logic
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   297
  to extract rewrite rules from theorems, without further
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   298
  simplification.  This may lead to slightly different behavior in
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   299
  either case, which might be required precisely like that in some
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   300
  boundary situations to perform the intended simplification step!
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   301
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   302
  \<^medskip>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   303
  The \<open>only\<close> modifier first removes all other rewrite
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   304
  rules, looper tactics (including split rules), congruence rules, and
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   305
  then behaves like \<open>add\<close>.  Implicit solvers remain, which means
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   306
  that trivial rules like reflexivity or introduction of \<open>True\<close> are available to solve the simplified subgoals, but also
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   307
  non-trivial tools like linear arithmetic in HOL.  The latter may
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   308
  lead to some surprise of the meaning of ``only'' in Isabelle/HOL
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   309
  compared to English!
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   310
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   311
  \<^medskip>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   312
  The \<open>split\<close> modifiers add or delete rules for the
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   313
  Splitter (see also \secref{sec:simp-strategies} on the looper).
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   314
  This works only if the Simplifier method has been properly setup to
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   315
  include the Splitter (all major object logics such HOL, HOLCF, FOL,
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   316
  ZF do this already).
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   317
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   318
  There is also a separate @{method_ref split} method available for
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   319
  single-step case splitting.  The effect of repeatedly applying
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   320
  \<open>(split thms)\<close> can be imitated by ``\<open>(simp only:
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   321
  split: thms)\<close>''.
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   322
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   323
  \<^medskip>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   324
  The \<open>cong\<close> modifiers add or delete Simplifier
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   325
  congruence rules (see also \secref{sec:simp-rules}); the default is
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   326
  to add.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   327
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   328
  \<^descr> @{method simp_all} is similar to @{method simp}, but acts on
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   329
  all goals, working backwards from the last to the first one as usual
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   330
  in Isabelle.\footnote{The order is irrelevant for goals without
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   331
  schematic variables, so simplification might actually be performed
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   332
  in parallel here.}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   333
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   334
  Chained facts are inserted into all subgoals, before the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   335
  simplification process starts.  Further rule declarations are the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   336
  same as for @{method simp}.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   337
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   338
  The proof method fails if all subgoals remain unchanged after
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   339
  simplification.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   340
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   341
  \<^descr> @{attribute simp_depth_limit} limits the number of recursive
57591
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   342
  invocations of the Simplifier during conditional rewriting.
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   343
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   344
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   345
  By default the Simplifier methods above take local assumptions fully
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   346
  into account, using equational assumptions in the subsequent
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   347
  normalization process, or simplifying assumptions themselves.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   348
  Further options allow to fine-tune the behavior of the Simplifier
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   349
  in this respect, corresponding to a variety of ML tactics as
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   350
  follows.\footnote{Unlike the corresponding Isar proof methods, the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   351
  ML tactics do not insist in changing the goal state.}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   352
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   353
  \begin{center}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   354
  \small
59782
wenzelm
parents: 59780
diff changeset
   355
  \begin{tabular}{|l|l|p{0.3\textwidth}|}
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   356
  \hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   357
  Isar method & ML tactic & behavior \\\hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   358
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   359
  \<open>(simp (no_asm))\<close> & @{ML simp_tac} & assumptions are ignored
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   360
  completely \\\hline
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   361
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   362
  \<open>(simp (no_asm_simp))\<close> & @{ML asm_simp_tac} & assumptions
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   363
  are used in the simplification of the conclusion but are not
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   364
  themselves simplified \\\hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   365
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   366
  \<open>(simp (no_asm_use))\<close> & @{ML full_simp_tac} & assumptions
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   367
  are simplified but are not used in the simplification of each other
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   368
  or the conclusion \\\hline
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   369
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   370
  \<open>(simp)\<close> & @{ML asm_full_simp_tac} & assumptions are used in
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   371
  the simplification of the conclusion and to simplify other
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   372
  assumptions \\\hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   373
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   374
  \<open>(simp (asm_lr))\<close> & @{ML asm_lr_simp_tac} & compatibility
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   375
  mode: an assumption is only used for simplifying assumptions which
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   376
  are to the right of it \\\hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   377
59782
wenzelm
parents: 59780
diff changeset
   378
  \end{tabular}
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   379
  \end{center}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   380
\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   381
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   382
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   383
subsubsection \<open>Examples\<close>
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   384
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   385
text \<open>We consider basic algebraic simplifications in Isabelle/HOL.
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   386
  The rather trivial goal @{prop "0 + (x + 0) = x + 0 + 0"} looks like
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   387
  a good candidate to be solved by a single call of @{method simp}:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   388
\<close>
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   389
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   390
lemma "0 + (x + 0) = x + 0 + 0" apply simp? oops
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   391
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   392
text \<open>The above attempt \<^emph>\<open>fails\<close>, because @{term "0"} and @{term
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   393
  "op +"} in the HOL library are declared as generic type class
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   394
  operations, without stating any algebraic laws yet.  More specific
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   395
  types are required to get access to certain standard simplifications
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   396
  of the theory context, e.g.\ like this:\<close>
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   397
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   398
lemma fixes x :: nat shows "0 + (x + 0) = x + 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   399
lemma fixes x :: int shows "0 + (x + 0) = x + 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   400
lemma fixes x :: "'a :: monoid_add" shows "0 + (x + 0) = x + 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   401
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   402
text \<open>
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   403
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   404
  In many cases, assumptions of a subgoal are also needed in
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   405
  the simplification process.  For example:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   406
\<close>
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   407
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   408
lemma fixes x :: nat shows "x = 0 \<Longrightarrow> x + x = 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   409
lemma fixes x :: nat assumes "x = 0" shows "x + x = 0" apply simp oops
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   410
lemma fixes x :: nat assumes "x = 0" shows "x + x = 0" using assms by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   411
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   412
text \<open>As seen above, local assumptions that shall contribute to
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   413
  simplification need to be part of the subgoal already, or indicated
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   414
  explicitly for use by the subsequent method invocation.  Both too
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   415
  little or too much information can make simplification fail, for
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   416
  different reasons.
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   417
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   418
  In the next example the malicious assumption @{prop "\<And>x::nat. f x =
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   419
  g (f (g x))"} does not contribute to solve the problem, but makes
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   420
  the default @{method simp} method loop: the rewrite rule \<open>f
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   421
  ?x \<equiv> g (f (g ?x))\<close> extracted from the assumption does not
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   422
  terminate.  The Simplifier notices certain simple forms of
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   423
  nontermination, but not this one.  The problem can be solved
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   424
  nonetheless, by ignoring assumptions via special options as
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   425
  explained before:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   426
\<close>
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   427
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   428
lemma "(\<And>x::nat. f x = g (f (g x))) \<Longrightarrow> f 0 = f 0 + 0"
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   429
  by (simp (no_asm))
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   430
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   431
text \<open>The latter form is typical for long unstructured proof
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   432
  scripts, where the control over the goal content is limited.  In
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   433
  structured proofs it is usually better to avoid pushing too many
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   434
  facts into the goal state in the first place.  Assumptions in the
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   435
  Isar proof context do not intrude the reasoning if not used
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   436
  explicitly.  This is illustrated for a toplevel statement and a
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   437
  local proof body as follows:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   438
\<close>
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   439
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   440
lemma
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   441
  assumes "\<And>x::nat. f x = g (f (g x))"
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   442
  shows "f 0 = f 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   443
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   444
notepad
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   445
begin
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   446
  assume "\<And>x::nat. f x = g (f (g x))"
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   447
  have "f 0 = f 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   448
end
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   449
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   450
text \<open>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   451
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   452
  Because assumptions may simplify each other, there
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   453
  can be very subtle cases of nontermination. For example, the regular
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   454
  @{method simp} method applied to @{prop "P (f x) \<Longrightarrow> y = x \<Longrightarrow> f x = f y
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   455
  \<Longrightarrow> Q"} gives rise to the infinite reduction sequence
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   456
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   457
  \<open>P (f x)\<close> \stackrel{\<open>f x \<equiv> f y\<close>}{\longmapsto}
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   458
  \<open>P (f y)\<close> \stackrel{\<open>y \<equiv> x\<close>}{\longmapsto}
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   459
  \<open>P (f x)\<close> \stackrel{\<open>f x \<equiv> f y\<close>}{\longmapsto} \cdots
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   460
  \]
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   461
  whereas applying the same to @{prop "y = x \<Longrightarrow> f x = f y \<Longrightarrow> P (f x) \<Longrightarrow>
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   462
  Q"} terminates (without solving the goal):
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   463
\<close>
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   464
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   465
lemma "y = x \<Longrightarrow> f x = f y \<Longrightarrow> P (f x) \<Longrightarrow> Q"
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   466
  apply simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   467
  oops
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   468
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   469
text \<open>See also \secref{sec:simp-trace} for options to enable
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   470
  Simplifier trace mode, which often helps to diagnose problems with
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   471
  rewrite systems.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   472
\<close>
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   473
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   474
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   475
subsection \<open>Declaring rules \label{sec:simp-rules}\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   476
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   477
text \<open>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   478
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   479
    @{attribute_def simp} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   480
    @{attribute_def split} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   481
    @{attribute_def cong} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   482
    @{command_def "print_simpset"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   483
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   484
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   485
  @{rail \<open>
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   486
    (@@{attribute simp} | @@{attribute split} | @@{attribute cong})
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   487
      (() | 'add' | 'del')
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   488
    ;
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   489
    @@{command print_simpset} ('!'?)
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   490
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   491
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   492
  \<^descr> @{attribute simp} declares rewrite rules, by adding or
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   493
  deleting them from the simpset within the theory or proof context.
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   494
  Rewrite rules are theorems expressing some form of equality, for
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   495
  example:
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   496
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   497
  \<open>Suc ?m + ?n = ?m + Suc ?n\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   498
  \<open>?P \<and> ?P \<longleftrightarrow> ?P\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   499
  \<open>?A \<union> ?B \<equiv> {x. x \<in> ?A \<or> x \<in> ?B}\<close>
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   500
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   501
  \<^medskip>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   502
  Conditional rewrites such as \<open>?m < ?n \<Longrightarrow> ?m div ?n = 0\<close> are
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   503
  also permitted; the conditions can be arbitrary formulas.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   504
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   505
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   506
  Internally, all rewrite rules are translated into Pure
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   507
  equalities, theorems with conclusion \<open>lhs \<equiv> rhs\<close>. The
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   508
  simpset contains a function for extracting equalities from arbitrary
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   509
  theorems, which is usually installed when the object-logic is
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   510
  configured initially. For example, \<open>\<not> ?x \<in> {}\<close> could be
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   511
  turned into \<open>?x \<in> {} \<equiv> False\<close>. Theorems that are declared as
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   512
  @{attribute simp} and local assumptions within a goal are treated
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   513
  uniformly in this respect.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   514
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   515
  The Simplifier accepts the following formats for the \<open>lhs\<close>
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   516
  term:
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   517
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
   518
    \<^enum> First-order patterns, considering the sublanguage of
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   519
    application of constant operators to variable operands, without
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   520
    \<open>\<lambda>\<close>-abstractions or functional variables.
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   521
    For example:
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   522
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   523
    \<open>(?x + ?y) + ?z \<equiv> ?x + (?y + ?z)\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   524
    \<open>f (f ?x ?y) ?z \<equiv> f ?x (f ?y ?z)\<close>
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   525
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
   526
    \<^enum> Higher-order patterns in the sense of @{cite "nipkow-patterns"}.
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   527
    These are terms in \<open>\<beta>\<close>-normal form (this will always be the
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   528
    case unless you have done something strange) where each occurrence
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   529
    of an unknown is of the form \<open>?F x\<^sub>1 \<dots> x\<^sub>n\<close>, where the
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   530
    \<open>x\<^sub>i\<close> are distinct bound variables.
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   531
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   532
    For example, \<open>(\<forall>x. ?P x \<and> ?Q x) \<equiv> (\<forall>x. ?P x) \<and> (\<forall>x. ?Q x)\<close>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   533
    or its symmetric form, since the \<open>rhs\<close> is also a
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   534
    higher-order pattern.
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   535
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   536
    \<^enum> Physical first-order patterns over raw \<open>\<lambda>\<close>-term
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   537
    structure without \<open>\<alpha>\<beta>\<eta>\<close>-equality; abstractions and bound
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   538
    variables are treated like quasi-constant term material.
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   539
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   540
    For example, the rule \<open>?f ?x \<in> range ?f = True\<close> rewrites the
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   541
    term \<open>g a \<in> range g\<close> to \<open>True\<close>, but will fail to
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   542
    match \<open>g (h b) \<in> range (\<lambda>x. g (h x))\<close>. However, offending
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   543
    subterms (in our case \<open>?f ?x\<close>, which is not a pattern) can
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   544
    be replaced by adding new variables and conditions like this: \<open>?y = ?f ?x \<Longrightarrow> ?y \<in> range ?f = True\<close> is acceptable as a conditional
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   545
    rewrite rule of the second category since conditions can be
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
   546
    arbitrary terms.
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   547
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   548
  \<^descr> @{attribute split} declares case split rules.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   549
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   550
  \<^descr> @{attribute cong} declares congruence rules to the Simplifier
45645
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   551
  context.
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   552
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   553
  Congruence rules are equalities of the form @{text [display]
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   554
  "\<dots> \<Longrightarrow> f ?x\<^sub>1 \<dots> ?x\<^sub>n = f ?y\<^sub>1 \<dots> ?y\<^sub>n"}
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   555
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   556
  This controls the simplification of the arguments of \<open>f\<close>.  For
45645
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   557
  example, some arguments can be simplified under additional
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   558
  assumptions: @{text [display] "?P\<^sub>1 \<longleftrightarrow> ?Q\<^sub>1 \<Longrightarrow> (?Q\<^sub>1 \<Longrightarrow> ?P\<^sub>2 \<longleftrightarrow> ?Q\<^sub>2) \<Longrightarrow>
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   559
  (?P\<^sub>1 \<longrightarrow> ?P\<^sub>2) \<longleftrightarrow> (?Q\<^sub>1 \<longrightarrow> ?Q\<^sub>2)"}
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   560
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   561
  Given this rule, the Simplifier assumes \<open>?Q\<^sub>1\<close> and extracts
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   562
  rewrite rules from it when simplifying \<open>?P\<^sub>2\<close>.  Such local
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   563
  assumptions are effective for rewriting formulae such as \<open>x =
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   564
  0 \<longrightarrow> y + x = y\<close>.
45645
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   565
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   566
  %FIXME
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   567
  %The local assumptions are also provided as theorems to the solver;
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   568
  %see \secref{sec:simp-solver} below.
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   569
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   570
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   571
  The following congruence rule for bounded quantifiers also
45645
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   572
  supplies contextual information --- about the bound variable:
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   573
  @{text [display] "(?A = ?B) \<Longrightarrow> (\<And>x. x \<in> ?B \<Longrightarrow> ?P x \<longleftrightarrow> ?Q x) \<Longrightarrow>
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   574
    (\<forall>x \<in> ?A. ?P x) \<longleftrightarrow> (\<forall>x \<in> ?B. ?Q x)"}
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   575
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   576
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   577
  This congruence rule for conditional expressions can
45645
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   578
  supply contextual information for simplifying the arms:
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   579
  @{text [display] "?p = ?q \<Longrightarrow> (?q \<Longrightarrow> ?a = ?c) \<Longrightarrow> (\<not> ?q \<Longrightarrow> ?b = ?d) \<Longrightarrow>
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   580
    (if ?p then ?a else ?b) = (if ?q then ?c else ?d)"}
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   581
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   582
  A congruence rule can also \<^emph>\<open>prevent\<close> simplification of some
45645
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   583
  arguments.  Here is an alternative congruence rule for conditional
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   584
  expressions that conforms to non-strict functional evaluation:
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   585
  @{text [display] "?p = ?q \<Longrightarrow> (if ?p then ?a else ?b) = (if ?q then ?a else ?b)"}
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   586
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   587
  Only the first argument is simplified; the others remain unchanged.
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   588
  This can make simplification much faster, but may require an extra
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   589
  case split over the condition \<open>?q\<close> to prove the goal.
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   590
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   591
  \<^descr> @{command "print_simpset"} prints the collection of rules declared
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59905
diff changeset
   592
  to the Simplifier, which is also known as ``simpset'' internally; the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   593
  ``\<open>!\<close>'' option indicates extra verbosity.
50077
wenzelm
parents: 50076
diff changeset
   594
wenzelm
parents: 50076
diff changeset
   595
  For historical reasons, simpsets may occur independently from the
wenzelm
parents: 50076
diff changeset
   596
  current context, but are conceptually dependent on it.  When the
wenzelm
parents: 50076
diff changeset
   597
  Simplifier is invoked via one of its main entry points in the Isar
wenzelm
parents: 50076
diff changeset
   598
  source language (as proof method \secref{sec:simp-meth} or rule
wenzelm
parents: 50076
diff changeset
   599
  attribute \secref{sec:simp-meth}), its simpset is derived from the
wenzelm
parents: 50076
diff changeset
   600
  current proof context, and carries a back-reference to that for
wenzelm
parents: 50076
diff changeset
   601
  other tools that might get invoked internally (e.g.\ simplification
wenzelm
parents: 50076
diff changeset
   602
  procedures \secref{sec:simproc}).  A mismatch of the context of the
wenzelm
parents: 50076
diff changeset
   603
  simpset and the context of the problem being simplified may lead to
wenzelm
parents: 50076
diff changeset
   604
  unexpected results.
wenzelm
parents: 50076
diff changeset
   605
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   606
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   607
  The implicit simpset of the theory context is propagated
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   608
  monotonically through the theory hierarchy: forming a new theory,
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   609
  the union of the simpsets of its imports are taken as starting
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   610
  point.  Also note that definitional packages like @{command
58310
91ea607a34d8 updated news
blanchet
parents: 58305
diff changeset
   611
  "datatype"}, @{command "primrec"}, @{command "fun"} routinely
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   612
  declare Simplifier rules to the target context, while plain
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   613
  @{command "definition"} is an exception in \<^emph>\<open>not\<close> declaring
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   614
  anything.
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   615
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   616
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   617
  It is up the user to manipulate the current simpset further
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   618
  by explicitly adding or deleting theorems as simplification rules,
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   619
  or installing other tools via simplification procedures
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   620
  (\secref{sec:simproc}).  Good simpsets are hard to design.  Rules
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   621
  that obviously simplify, like \<open>?n + 0 \<equiv> ?n\<close> are good
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   622
  candidates for the implicit simpset, unless a special
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   623
  non-normalizing behavior of certain operations is intended.  More
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   624
  specific rules (such as distributive laws, which duplicate subterms)
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   625
  should be added only for specific proof steps.  Conversely,
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   626
  sometimes a rule needs to be deleted just for some part of a proof.
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   627
  The need of frequent additions or deletions may indicate a poorly
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   628
  designed simpset.
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   629
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   630
  \begin{warn}
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   631
  The union of simpsets from theory imports (as described above) is
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   632
  not always a good starting point for the new theory.  If some
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   633
  ancestors have deleted simplification rules because they are no
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   634
  longer wanted, while others have left those rules in, then the union
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   635
  will contain the unwanted rules, and thus have to be deleted again
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   636
  in the theory body.
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   637
  \end{warn}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   638
\<close>
45645
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   639
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   640
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   641
subsection \<open>Ordered rewriting with permutative rules\<close>
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   642
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   643
text \<open>A rewrite rule is \<^emph>\<open>permutative\<close> if the left-hand side and
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   644
  right-hand side are the equal up to renaming of variables.  The most
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   645
  common permutative rule is commutativity: \<open>?x + ?y = ?y +
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   646
  ?x\<close>.  Other examples include \<open>(?x - ?y) - ?z = (?x - ?z) -
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   647
  ?y\<close> in arithmetic and \<open>insert ?x (insert ?y ?A) = insert ?y
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   648
  (insert ?x ?A)\<close> for sets.  Such rules are common enough to merit
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   649
  special attention.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   650
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   651
  Because ordinary rewriting loops given such rules, the Simplifier
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   652
  employs a special strategy, called \<^emph>\<open>ordered rewriting\<close>.
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   653
  Permutative rules are detected and only applied if the rewriting
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   654
  step decreases the redex wrt.\ a given term ordering.  For example,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   655
  commutativity rewrites \<open>b + a\<close> to \<open>a + b\<close>, but then
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   656
  stops, because the redex cannot be decreased further in the sense of
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   657
  the term ordering.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   658
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   659
  The default is lexicographic ordering of term structure, but this
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   660
  could be also changed locally for special applications via
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   661
  @{index_ML Simplifier.set_termless} in Isabelle/ML.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   662
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   663
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   664
  Permutative rewrite rules are declared to the Simplifier
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   665
  just like other rewrite rules.  Their special status is recognized
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   666
  automatically, and their application is guarded by the term ordering
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   667
  accordingly.\<close>
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   668
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   669
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   670
subsubsection \<open>Rewriting with AC operators\<close>
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   671
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   672
text \<open>Ordered rewriting is particularly effective in the case of
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   673
  associative-commutative operators.  (Associativity by itself is not
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   674
  permutative.)  When dealing with an AC-operator \<open>f\<close>, keep
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   675
  the following points in mind:
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   676
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   677
  \<^item> The associative law must always be oriented from left to
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   678
  right, namely \<open>f (f x y) z = f x (f y z)\<close>.  The opposite
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   679
  orientation, if used with commutativity, leads to looping in
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   680
  conjunction with the standard term order.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   681
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   682
  \<^item> To complete your set of rewrite rules, you must add not just
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   683
  associativity (A) and commutativity (C) but also a derived rule
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   684
  \<^emph>\<open>left-commutativity\<close> (LC): \<open>f x (f y z) = f y (f x z)\<close>.
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   685
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   686
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   687
  Ordered rewriting with the combination of A, C, and LC sorts a term
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   688
  lexicographically --- the rewriting engine imitates bubble-sort.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   689
\<close>
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   690
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
   691
experiment
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   692
  fixes f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infix "\<bullet>" 60)
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   693
  assumes assoc: "(x \<bullet> y) \<bullet> z = x \<bullet> (y \<bullet> z)"
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   694
  assumes commute: "x \<bullet> y = y \<bullet> x"
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   695
begin
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   696
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   697
lemma left_commute: "x \<bullet> (y \<bullet> z) = y \<bullet> (x \<bullet> z)"
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   698
proof -
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   699
  have "(x \<bullet> y) \<bullet> z = (y \<bullet> x) \<bullet> z" by (simp only: commute)
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   700
  then show ?thesis by (simp only: assoc)
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   701
qed
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   702
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   703
lemmas AC_rules = assoc commute left_commute
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   704
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   705
text \<open>Thus the Simplifier is able to establish equalities with
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   706
  arbitrary permutations of subterms, by normalizing to a common
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   707
  standard form.  For example:\<close>
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   708
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   709
lemma "(b \<bullet> c) \<bullet> a = xxx"
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   710
  apply (simp only: AC_rules)
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   711
  txt \<open>@{subgoals}\<close>
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   712
  oops
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   713
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   714
lemma "(b \<bullet> c) \<bullet> a = a \<bullet> (b \<bullet> c)" by (simp only: AC_rules)
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   715
lemma "(b \<bullet> c) \<bullet> a = c \<bullet> (b \<bullet> a)" by (simp only: AC_rules)
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   716
lemma "(b \<bullet> c) \<bullet> a = (c \<bullet> b) \<bullet> a" by (simp only: AC_rules)
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   717
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   718
end
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   719
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   720
text \<open>Martin and Nipkow @{cite "martin-nipkow"} discuss the theory and
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   721
  give many examples; other algebraic structures are amenable to
56594
e3a06699a13f tuned spelling;
wenzelm
parents: 56451
diff changeset
   722
  ordered rewriting, such as Boolean rings.  The Boyer-Moore theorem
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58310
diff changeset
   723
  prover @{cite bm88book} also employs ordered rewriting.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   724
\<close>
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   725
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   726
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   727
subsubsection \<open>Re-orienting equalities\<close>
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   728
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   729
text \<open>Another application of ordered rewriting uses the derived rule
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   730
  @{thm [source] eq_commute}: @{thm [source = false] eq_commute} to
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   731
  reverse equations.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   732
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   733
  This is occasionally useful to re-orient local assumptions according
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   734
  to the term ordering, when other built-in mechanisms of
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   735
  reorientation and mutual simplification fail to apply.\<close>
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   736
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   737
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   738
subsection \<open>Simplifier tracing and debugging \label{sec:simp-trace}\<close>
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   739
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   740
text \<open>
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   741
  \begin{tabular}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   742
    @{attribute_def simp_trace} & : & \<open>attribute\<close> & default \<open>false\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   743
    @{attribute_def simp_trace_depth_limit} & : & \<open>attribute\<close> & default \<open>1\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   744
    @{attribute_def simp_debug} & : & \<open>attribute\<close> & default \<open>false\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   745
    @{attribute_def simp_trace_new} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   746
    @{attribute_def simp_break} & : & \<open>attribute\<close> \\
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   747
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   748
  \<^medskip>
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   749
57591
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   750
  @{rail \<open>
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   751
    @@{attribute simp_trace_new} ('interactive')? \<newline>
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   752
      ('mode' '=' ('full' | 'normal'))? \<newline>
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   753
      ('depth' '=' @{syntax nat})?
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   754
    ;
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   755
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   756
    @@{attribute simp_break} (@{syntax term}*)
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   757
  \<close>}
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   758
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   759
  These attributes and configurations options control various aspects of
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   760
  Simplifier tracing and debugging.
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   761
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   762
  \<^descr> @{attribute simp_trace} makes the Simplifier output internal
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   763
  operations.  This includes rewrite steps, but also bookkeeping like
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   764
  modifications of the simpset.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   765
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   766
  \<^descr> @{attribute simp_trace_depth_limit} limits the effect of
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   767
  @{attribute simp_trace} to the given depth of recursive Simplifier
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   768
  invocations (when solving conditions of rewrite rules).
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   769
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   770
  \<^descr> @{attribute simp_debug} makes the Simplifier output some extra
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   771
  information about internal operations.  This includes any attempted
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   772
  invocation of simplification procedures.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   773
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   774
  \<^descr> @{attribute simp_trace_new} controls Simplifier tracing within
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58310
diff changeset
   775
  Isabelle/PIDE applications, notably Isabelle/jEdit @{cite "isabelle-jedit"}.
57591
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   776
  This provides a hierarchical representation of the rewriting steps
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   777
  performed by the Simplifier.
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   778
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   779
  Users can configure the behaviour by specifying breakpoints, verbosity and
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   780
  enabling or disabling the interactive mode. In normal verbosity (the
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   781
  default), only rule applications matching a breakpoint will be shown to
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   782
  the user. In full verbosity, all rule applications will be logged.
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   783
  Interactive mode interrupts the normal flow of the Simplifier and defers
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   784
  the decision how to continue to the user via some GUI dialog.
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   785
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   786
  \<^descr> @{attribute simp_break} declares term or theorem breakpoints for
57591
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   787
  @{attribute simp_trace_new} as described above. Term breakpoints are
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   788
  patterns which are checked for matches on the redex of a rule application.
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   789
  Theorem breakpoints trigger when the corresponding theorem is applied in a
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   790
  rewrite step. For example:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   791
\<close>
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   792
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
   793
(*<*)experiment begin(*>*)
57591
8c095aef6769 clarified "simp_trace_new" and corresponding isar-ref section;
wenzelm
parents: 57590
diff changeset
   794
declare conjI [simp_break]
57590
06cb5375e189 more on "Simplifier trace" (by Lars Hupel);
wenzelm
parents: 56594
diff changeset
   795
declare [[simp_break "?x \<and> ?y"]]
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
   796
(*<*)end(*>*)
57590
06cb5375e189 more on "Simplifier trace" (by Lars Hupel);
wenzelm
parents: 56594
diff changeset
   797
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   798
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   799
subsection \<open>Simplification procedures \label{sec:simproc}\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   800
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   801
text \<open>Simplification procedures are ML functions that produce proven
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   802
  rewrite rules on demand.  They are associated with higher-order
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   803
  patterns that approximate the left-hand sides of equations.  The
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   804
  Simplifier first matches the current redex against one of the LHS
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   805
  patterns; if this succeeds, the corresponding ML function is
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   806
  invoked, passing the Simplifier context and redex term.  Thus rules
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   807
  may be specifically fashioned for particular situations, resulting
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   808
  in a more powerful mechanism than term rewriting by a fixed set of
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   809
  rules.
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   810
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   811
  Any successful result needs to be a (possibly conditional) rewrite
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   812
  rule \<open>t \<equiv> u\<close> that is applicable to the current redex.  The
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   813
  rule will be applied just as any ordinary rewrite rule.  It is
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
   814
  expected to be already in \<^emph>\<open>internal form\<close>, bypassing the
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   815
  automatic preprocessing of object-level equivalences.
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   816
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   817
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   818
    @{command_def "simproc_setup"} & : & \<open>local_theory \<rightarrow> local_theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   819
    simproc & : & \<open>attribute\<close> \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   820
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   821
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   822
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   823
    @@{command simproc_setup} @{syntax name} '(' (@{syntax term} + '|') ')' '='
55029
61a6bf7d4b02 clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents: 52060
diff changeset
   824
      @{syntax text} \<newline> (@'identifier' (@{syntax nameref}+))?
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   825
    ;
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   826
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   827
    @@{attribute simproc} (('add' ':')? | 'del' ':') (@{syntax name}+)
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   828
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   829
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
   830
  \<^descr> @{command "simproc_setup"} defines a named simplification
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   831
  procedure that is invoked by the Simplifier whenever any of the
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   832
  given term patterns match the current redex.  The implementation,
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   833
  which is provided as ML source text, needs to be of type @{ML_type
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   834
  "morphism -> simpset -> cterm -> thm option"}, where the @{ML_type
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   835
  cterm} represents the current redex \<open>r\<close> and the result is
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   836
  supposed to be some proven rewrite rule \<open>r \<equiv> r'\<close> (or a
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   837
  generalized version), or @{ML NONE} to indicate failure.  The
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   838
  @{ML_type simpset} argument holds the full context of the current
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   839
  Simplifier invocation, including the actual Isar proof context.  The
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   840
  @{ML_type morphism} informs about the difference of the original
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   841
  compilation context wrt.\ the one of the actual application later
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   842
  on.  The optional @{keyword "identifier"} specifies theorems that
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   843
  represent the logical content of the abstract theory of this
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   844
  simproc.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   845
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   846
  Morphisms and identifiers are only relevant for simprocs that are
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   847
  defined within a local target context, e.g.\ in a locale.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   848
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   849
  \<^descr> \<open>simproc add: name\<close> and \<open>simproc del: name\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   850
  add or delete named simprocs to the current Simplifier context.  The
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   851
  default is to add a simproc.  Note that @{command "simproc_setup"}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   852
  already adds the new simproc to the subsequent context.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   853
\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   854
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   855
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   856
subsubsection \<open>Example\<close>
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   857
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   858
text \<open>The following simplification procedure for @{thm
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   859
  [source=false, show_types] unit_eq} in HOL performs fine-grained
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   860
  control over rule application, beyond higher-order pattern matching.
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   861
  Declaring @{thm unit_eq} as @{attribute simp} directly would make
56594
e3a06699a13f tuned spelling;
wenzelm
parents: 56451
diff changeset
   862
  the Simplifier loop!  Note that a version of this simplification
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   863
  procedure is already active in Isabelle/HOL.\<close>
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   864
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
   865
(*<*)experiment begin(*>*)
59782
wenzelm
parents: 59780
diff changeset
   866
simproc_setup unit ("x::unit") =
wenzelm
parents: 59780
diff changeset
   867
  \<open>fn _ => fn _ => fn ct =>
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59498
diff changeset
   868
    if HOLogic.is_unit (Thm.term_of ct) then NONE
59782
wenzelm
parents: 59780
diff changeset
   869
    else SOME (mk_meta_eq @{thm unit_eq})\<close>
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
   870
(*<*)end(*>*)
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   871
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   872
text \<open>Since the Simplifier applies simplification procedures
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   873
  frequently, it is important to make the failure check in ML
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   874
  reasonably fast.\<close>
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   875
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   876
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   877
subsection \<open>Configurable Simplifier strategies \label{sec:simp-strategies}\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   878
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   879
text \<open>The core term-rewriting engine of the Simplifier is normally
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   880
  used in combination with some add-on components that modify the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   881
  strategy and allow to integrate other non-Simplifier proof tools.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   882
  These may be reconfigured in ML as explained below.  Even if the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   883
  default strategies of object-logics like Isabelle/HOL are used
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   884
  unchanged, it helps to understand how the standard Simplifier
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   885
  strategies work.\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   886
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   887
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   888
subsubsection \<open>The subgoaler\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   889
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   890
text \<open>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   891
  \begin{mldecls}
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   892
  @{index_ML Simplifier.set_subgoaler: "(Proof.context -> int -> tactic) ->
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   893
  Proof.context -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   894
  @{index_ML Simplifier.prems_of: "Proof.context -> thm list"} \\
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   895
  \end{mldecls}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   896
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   897
  The subgoaler is the tactic used to solve subgoals arising out of
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   898
  conditional rewrite rules or congruence rules.  The default should
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   899
  be simplification itself.  In rare situations, this strategy may
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   900
  need to be changed.  For example, if the premise of a conditional
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   901
  rule is an instance of its conclusion, as in \<open>Suc ?m < ?n \<Longrightarrow>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   902
  ?m < ?n\<close>, the default strategy could loop.  % FIXME !??
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   903
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   904
  \<^descr> @{ML Simplifier.set_subgoaler}~\<open>tac ctxt\<close> sets the
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   905
  subgoaler of the context to \<open>tac\<close>.  The tactic will
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   906
  be applied to the context of the running Simplifier instance.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   907
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   908
  \<^descr> @{ML Simplifier.prems_of}~\<open>ctxt\<close> retrieves the current
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   909
  set of premises from the context.  This may be non-empty only if
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   910
  the Simplifier has been told to utilize local assumptions in the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   911
  first place (cf.\ the options in \secref{sec:simp-meth}).
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   912
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   913
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   914
  As an example, consider the following alternative subgoaler:
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   915
\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   916
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
   917
ML_val \<open>
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   918
  fun subgoaler_tac ctxt =
58963
26bf09b95dda proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents: 58618
diff changeset
   919
    assume_tac ctxt ORELSE'
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 58963
diff changeset
   920
    resolve_tac ctxt (Simplifier.prems_of ctxt) ORELSE'
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   921
    asm_simp_tac ctxt
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   922
\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   923
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   924
text \<open>This tactic first tries to solve the subgoal by assumption or
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   925
  by resolving with with one of the premises, calling simplification
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   926
  only if that fails.\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   927
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   928
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   929
subsubsection \<open>The solver\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   930
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
   931
text \<open>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   932
  \begin{mldecls}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   933
  @{index_ML_type solver} \\
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   934
  @{index_ML Simplifier.mk_solver: "string ->
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   935
  (Proof.context -> int -> tactic) -> solver"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   936
  @{index_ML_op setSolver: "Proof.context * solver -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   937
  @{index_ML_op addSolver: "Proof.context * solver -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   938
  @{index_ML_op setSSolver: "Proof.context * solver -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   939
  @{index_ML_op addSSolver: "Proof.context * solver -> Proof.context"} \\
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   940
  \end{mldecls}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   941
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   942
  A solver is a tactic that attempts to solve a subgoal after
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   943
  simplification.  Its core functionality is to prove trivial subgoals
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   944
  such as @{prop "True"} and \<open>t = t\<close>, but object-logics might
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   945
  be more ambitious.  For example, Isabelle/HOL performs a restricted
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   946
  version of linear arithmetic here.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   947
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   948
  Solvers are packaged up in abstract type @{ML_type solver}, with
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   949
  @{ML Simplifier.mk_solver} as the only operation to create a solver.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   950
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   951
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   952
  Rewriting does not instantiate unknowns.  For example,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   953
  rewriting alone cannot prove \<open>a \<in> ?A\<close> since this requires
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   954
  instantiating \<open>?A\<close>.  The solver, however, is an arbitrary
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   955
  tactic and may instantiate unknowns as it pleases.  This is the only
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   956
  way the Simplifier can handle a conditional rewrite rule whose
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   957
  condition contains extra variables.  When a simplification tactic is
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   958
  to be combined with other provers, especially with the Classical
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   959
  Reasoner, it is important whether it can be considered safe or not.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   960
  For this reason a simpset contains two solvers: safe and unsafe.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   961
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   962
  The standard simplification strategy solely uses the unsafe solver,
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   963
  which is appropriate in most cases.  For special applications where
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   964
  the simplification process is not allowed to instantiate unknowns
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   965
  within the goal, simplification starts with the safe solver, but may
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   966
  still apply the ordinary unsafe one in nested simplifications for
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   967
  conditional rules or congruences. Note that in this way the overall
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   968
  tactic is not totally safe: it may instantiate unknowns that appear
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   969
  also in other subgoals.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   970
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   971
  \<^descr> @{ML Simplifier.mk_solver}~\<open>name tac\<close> turns \<open>tac\<close> into a solver; the \<open>name\<close> is only attached as a
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   972
  comment and has no further significance.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   973
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   974
  \<^descr> \<open>ctxt setSSolver solver\<close> installs \<open>solver\<close> as
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   975
  the safe solver of \<open>ctxt\<close>.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   976
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   977
  \<^descr> \<open>ctxt addSSolver solver\<close> adds \<open>solver\<close> as an
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   978
  additional safe solver; it will be tried after the solvers which had
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   979
  already been present in \<open>ctxt\<close>.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   980
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   981
  \<^descr> \<open>ctxt setSolver solver\<close> installs \<open>solver\<close> as the
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   982
  unsafe solver of \<open>ctxt\<close>.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   983
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   984
  \<^descr> \<open>ctxt addSolver solver\<close> adds \<open>solver\<close> as an
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   985
  additional unsafe solver; it will be tried after the solvers which
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
   986
  had already been present in \<open>ctxt\<close>.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   987
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   988
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   989
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
   990
  The solver tactic is invoked with the context of the
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   991
  running Simplifier.  Further operations
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   992
  may be used to retrieve relevant information, such as the list of
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   993
  local Simplifier premises via @{ML Simplifier.prems_of} --- this
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   994
  list may be non-empty only if the Simplifier runs in a mode that
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   995
  utilizes local assumptions (see also \secref{sec:simp-meth}).  The
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   996
  solver is also presented the full goal including its assumptions in
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   997
  any case.  Thus it can use these (e.g.\ by calling @{ML
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   998
  assume_tac}), even if the Simplifier proper happens to ignore local
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   999
  premises at the moment.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1000
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
  1001
  \<^medskip>
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
  1002
  As explained before, the subgoaler is also used to solve
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1003
  the premises of congruence rules.  These are usually of the form
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1004
  \<open>s = ?x\<close>, where \<open>s\<close> needs to be simplified and
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1005
  \<open>?x\<close> needs to be instantiated with the result.  Typically,
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1006
  the subgoaler will invoke the Simplifier at some point, which will
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1007
  eventually call the solver.  For this reason, solver tactics must be
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1008
  prepared to solve goals of the form \<open>t = ?x\<close>, usually by
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1009
  reflexivity.  In particular, reflexivity should be tried before any
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1010
  of the fancy automated proof tools.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1011
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1012
  It may even happen that due to simplification the subgoal is no
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1013
  longer an equality.  For example, \<open>False \<longleftrightarrow> ?Q\<close> could be
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1014
  rewritten to \<open>\<not> ?Q\<close>.  To cover this case, the solver could
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1015
  try resolving with the theorem \<open>\<not> False\<close> of the
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1016
  object-logic.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1017
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
  1018
  \<^medskip>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1019
  \begin{warn}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1020
  If a premise of a congruence rule cannot be proved, then the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1021
  congruence is ignored.  This should only happen if the rule is
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1022
  \<^emph>\<open>conditional\<close> --- that is, contains premises not of the form
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1023
  \<open>t = ?x\<close>.  Otherwise it indicates that some congruence rule,
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1024
  or possibly the subgoaler or solver, is faulty.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1025
  \end{warn}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1026
\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1027
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1028
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1029
subsubsection \<open>The looper\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1030
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1031
text \<open>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1032
  \begin{mldecls}
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1033
  @{index_ML_op setloop: "Proof.context *
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1034
  (Proof.context -> int -> tactic) -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1035
  @{index_ML_op addloop: "Proof.context *
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1036
  (string * (Proof.context -> int -> tactic))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1037
  -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1038
  @{index_ML_op delloop: "Proof.context * string -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1039
  @{index_ML Splitter.add_split: "thm -> Proof.context -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1040
  @{index_ML Splitter.del_split: "thm -> Proof.context -> Proof.context"} \\
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1041
  \end{mldecls}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1042
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1043
  The looper is a list of tactics that are applied after
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1044
  simplification, in case the solver failed to solve the simplified
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1045
  goal.  If the looper succeeds, the simplification process is started
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1046
  all over again.  Each of the subgoals generated by the looper is
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1047
  attacked in turn, in reverse order.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1048
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1049
  A typical looper is \<^emph>\<open>case splitting\<close>: the expansion of a
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1050
  conditional.  Another possibility is to apply an elimination rule on
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1051
  the assumptions.  More adventurous loopers could start an induction.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1052
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1053
  \<^descr> \<open>ctxt setloop tac\<close> installs \<open>tac\<close> as the only
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1054
  looper tactic of \<open>ctxt\<close>.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1055
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1056
  \<^descr> \<open>ctxt addloop (name, tac)\<close> adds \<open>tac\<close> as an
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1057
  additional looper tactic with name \<open>name\<close>, which is
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1058
  significant for managing the collection of loopers.  The tactic will
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1059
  be tried after the looper tactics that had already been present in
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1060
  \<open>ctxt\<close>.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1061
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1062
  \<^descr> \<open>ctxt delloop name\<close> deletes the looper tactic that was
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1063
  associated with \<open>name\<close> from \<open>ctxt\<close>.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1064
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1065
  \<^descr> @{ML Splitter.add_split}~\<open>thm ctxt\<close> adds split tactics
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1066
  for \<open>thm\<close> as additional looper tactics of \<open>ctxt\<close>.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1067
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1068
  \<^descr> @{ML Splitter.del_split}~\<open>thm ctxt\<close> deletes the split
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1069
  tactic corresponding to \<open>thm\<close> from the looper tactics of
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1070
  \<open>ctxt\<close>.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1071
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1072
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1073
  The splitter replaces applications of a given function; the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1074
  right-hand side of the replacement can be anything.  For example,
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1075
  here is a splitting rule for conditional expressions:
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1076
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1077
  @{text [display] "?P (if ?Q ?x ?y) \<longleftrightarrow> (?Q \<longrightarrow> ?P ?x) \<and> (\<not> ?Q \<longrightarrow> ?P ?y)"}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1078
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1079
  Another example is the elimination operator for Cartesian products
61424
c3658c18b7bc prod_case as canonical name for product type eliminator
haftmann
parents: 61421
diff changeset
  1080
  (which happens to be called @{const case_prod} in Isabelle/HOL:
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1081
61424
c3658c18b7bc prod_case as canonical name for product type eliminator
haftmann
parents: 61421
diff changeset
  1082
  @{text [display] "?P (case_prod ?f ?p) \<longleftrightarrow> (\<forall>a b. ?p = (a, b) \<longrightarrow> ?P (f a b))"}
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1083
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1084
  For technical reasons, there is a distinction between case splitting
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1085
  in the conclusion and in the premises of a subgoal.  The former is
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1086
  done by @{ML Splitter.split_tac} with rules like @{thm [source]
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1087
  split_if} or @{thm [source] option.split}, which do not split the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1088
  subgoal, while the latter is done by @{ML Splitter.split_asm_tac}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1089
  with rules like @{thm [source] split_if_asm} or @{thm [source]
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1090
  option.split_asm}, which split the subgoal.  The function @{ML
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1091
  Splitter.add_split} automatically takes care of which tactic to
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1092
  call, analyzing the form of the rules given as argument; it is the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1093
  same operation behind \<open>split\<close> attribute or method modifier
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1094
  syntax in the Isar source language.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1095
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1096
  Case splits should be allowed only when necessary; they are
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1097
  expensive and hard to control.  Case-splitting on if-expressions in
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1098
  the conclusion is usually beneficial, so it is enabled by default in
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1099
  Isabelle/HOL and Isabelle/FOL/ZF.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1100
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1101
  \begin{warn}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1102
  With @{ML Splitter.split_asm_tac} as looper component, the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1103
  Simplifier may split subgoals!  This might cause unexpected problems
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1104
  in tactic expressions that silently assume 0 or 1 subgoals after
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1105
  simplification.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1106
  \end{warn}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1107
\<close>
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1108
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1109
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1110
subsection \<open>Forward simplification \label{sec:simp-forward}\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1111
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1112
text \<open>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1113
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1114
    @{attribute_def simplified} & : & \<open>attribute\<close> \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1115
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1116
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1117
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
  1118
    @@{attribute simplified} opt? @{syntax thmrefs}?
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1119
    ;
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1120
40255
9ffbc25e1606 eliminated obsolete \_ escapes in rail environments;
wenzelm
parents: 35613
diff changeset
  1121
    opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use') ')'
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1122
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1123
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1124
  \<^descr> @{attribute simplified}~\<open>a\<^sub>1 \<dots> a\<^sub>n\<close> causes a theorem to
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1125
  be simplified, either by exactly the specified rules \<open>a\<^sub>1, \<dots>,
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1126
  a\<^sub>n\<close>, or the implicit Simplifier context if no arguments are given.
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1127
  The result is fully simplified by default, including assumptions and
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1128
  conclusion; the options \<open>no_asm\<close> etc.\ tune the Simplifier in
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1129
  the same way as the for the \<open>simp\<close> method.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1130
56594
e3a06699a13f tuned spelling;
wenzelm
parents: 56451
diff changeset
  1131
  Note that forward simplification restricts the Simplifier to its
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1132
  most basic operation of term rewriting; solver and looper tactics
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1133
  (\secref{sec:simp-strategies}) are \<^emph>\<open>not\<close> involved here.  The
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1134
  @{attribute simplified} attribute should be only rarely required
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1135
  under normal circumstances.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1136
\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1137
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1138
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1139
section \<open>The Classical Reasoner \label{sec:classical}\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1140
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1141
subsection \<open>Basic concepts\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1142
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1143
text \<open>Although Isabelle is generic, many users will be working in
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1144
  some extension of classical first-order logic.  Isabelle/ZF is built
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1145
  upon theory FOL, while Isabelle/HOL conceptually contains
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1146
  first-order logic as a fragment.  Theorem-proving in predicate logic
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1147
  is undecidable, but many automated strategies have been developed to
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1148
  assist in this task.
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1149
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1150
  Isabelle's classical reasoner is a generic package that accepts
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1151
  certain information about a logic and delivers a suite of automatic
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1152
  proof tools, based on rules that are classified and declared in the
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1153
  context.  These proof procedures are slow and simplistic compared
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1154
  with high-end automated theorem provers, but they can save
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1155
  considerable time and effort in practice.  They can prove theorems
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58310
diff changeset
  1156
  such as Pelletier's @{cite pelletier86} problems 40 and 41 in a few
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1157
  milliseconds (including full proof reconstruction):\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1158
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1159
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)"
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1160
  by blast
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1161
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1162
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)"
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1163
  by blast
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1164
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1165
text \<open>The proof tools are generic.  They are not restricted to
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1166
  first-order logic, and have been heavily used in the development of
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1167
  the Isabelle/HOL library and applications.  The tactics can be
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1168
  traced, and their components can be called directly; in this manner,
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1169
  any proof can be viewed interactively.\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1170
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1171
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1172
subsubsection \<open>The sequent calculus\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1173
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1174
text \<open>Isabelle supports natural deduction, which is easy to use for
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1175
  interactive proof.  But natural deduction does not easily lend
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1176
  itself to automation, and has a bias towards intuitionism.  For
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1177
  certain proofs in classical logic, it can not be called natural.
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1178
  The \<^emph>\<open>sequent calculus\<close>, a generalization of natural deduction,
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1179
  is easier to automate.
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1180
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1181
  A \<^bold>\<open>sequent\<close> has the form \<open>\<Gamma> \<turnstile> \<Delta>\<close>, where \<open>\<Gamma>\<close>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1182
  and \<open>\<Delta>\<close> are sets of formulae.\footnote{For first-order
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1183
  logic, sequents can equivalently be made from lists or multisets of
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1184
  formulae.} The sequent \<open>P\<^sub>1, \<dots>, P\<^sub>m \<turnstile> Q\<^sub>1, \<dots>, Q\<^sub>n\<close> is
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1185
  \<^bold>\<open>valid\<close> if \<open>P\<^sub>1 \<and> \<dots> \<and> P\<^sub>m\<close> implies \<open>Q\<^sub>1 \<or> \<dots> \<or>
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1186
  Q\<^sub>n\<close>.  Thus \<open>P\<^sub>1, \<dots>, P\<^sub>m\<close> represent assumptions, each of which
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1187
  is true, while \<open>Q\<^sub>1, \<dots>, Q\<^sub>n\<close> represent alternative goals.  A
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1188
  sequent is \<^bold>\<open>basic\<close> if its left and right sides have a common
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1189
  formula, as in \<open>P, Q \<turnstile> Q, R\<close>; basic sequents are trivially
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1190
  valid.
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1191
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1192
  Sequent rules are classified as \<^bold>\<open>right\<close> or \<^bold>\<open>left\<close>,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1193
  indicating which side of the \<open>\<turnstile>\<close> symbol they operate on.
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1194
  Rules that operate on the right side are analogous to natural
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1195
  deduction's introduction rules, and left rules are analogous to
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1196
  elimination rules.  The sequent calculus analogue of \<open>(\<longrightarrow>I)\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1197
  is the rule
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1198
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1199
  \infer[\<open>(\<longrightarrow>R)\<close>]{\<open>\<Gamma> \<turnstile> \<Delta>, P \<longrightarrow> Q\<close>}{\<open>P, \<Gamma> \<turnstile> \<Delta>, Q\<close>}
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1200
  \]
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1201
  Applying the rule backwards, this breaks down some implication on
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1202
  the right side of a sequent; \<open>\<Gamma>\<close> and \<open>\<Delta>\<close> stand for
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1203
  the sets of formulae that are unaffected by the inference.  The
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1204
  analogue of the pair \<open>(\<or>I1)\<close> and \<open>(\<or>I2)\<close> is the
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1205
  single rule
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1206
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1207
  \infer[\<open>(\<or>R)\<close>]{\<open>\<Gamma> \<turnstile> \<Delta>, P \<or> Q\<close>}{\<open>\<Gamma> \<turnstile> \<Delta>, P, Q\<close>}
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1208
  \]
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1209
  This breaks down some disjunction on the right side, replacing it by
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1210
  both disjuncts.  Thus, the sequent calculus is a kind of
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1211
  multiple-conclusion logic.
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1212
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1213
  To illustrate the use of multiple formulae on the right, let us
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1214
  prove the classical theorem \<open>(P \<longrightarrow> Q) \<or> (Q \<longrightarrow> P)\<close>.  Working
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1215
  backwards, we reduce this formula to a basic sequent:
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1216
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1217
  \infer[\<open>(\<or>R)\<close>]{\<open>\<turnstile> (P \<longrightarrow> Q) \<or> (Q \<longrightarrow> P)\<close>}
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1218
    {\infer[\<open>(\<longrightarrow>R)\<close>]{\<open>\<turnstile> (P \<longrightarrow> Q), (Q \<longrightarrow> P)\<close>}
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1219
      {\infer[\<open>(\<longrightarrow>R)\<close>]{\<open>P \<turnstile> Q, (Q \<longrightarrow> P)\<close>}
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1220
        {\<open>P, Q \<turnstile> Q, P\<close>}}}
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1221
  \]
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1222
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1223
  This example is typical of the sequent calculus: start with the
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1224
  desired theorem and apply rules backwards in a fairly arbitrary
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1225
  manner.  This yields a surprisingly effective proof procedure.
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1226
  Quantifiers add only few complications, since Isabelle handles
58552
66fed99e874f prefer @{cite} antiquotation;
wenzelm
parents: 58310
diff changeset
  1227
  parameters and schematic variables.  See @{cite \<open>Chapter 10\<close>
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1228
  "paulson-ml2"} for further discussion.\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1229
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1230
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1231
subsubsection \<open>Simulating sequents by natural deduction\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1232
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1233
text \<open>Isabelle can represent sequents directly, as in the
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1234
  object-logic LK.  But natural deduction is easier to work with, and
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1235
  most object-logics employ it.  Fortunately, we can simulate the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1236
  sequent \<open>P\<^sub>1, \<dots>, P\<^sub>m \<turnstile> Q\<^sub>1, \<dots>, Q\<^sub>n\<close> by the Isabelle formula
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1237
  \<open>P\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> P\<^sub>m \<Longrightarrow> \<not> Q\<^sub>2 \<Longrightarrow> ... \<Longrightarrow> \<not> Q\<^sub>n \<Longrightarrow> Q\<^sub>1\<close> where the order of
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1238
  the assumptions and the choice of \<open>Q\<^sub>1\<close> are arbitrary.
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1239
  Elim-resolution plays a key role in simulating sequent proofs.
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1240
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1241
  We can easily handle reasoning on the left.  Elim-resolution with
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1242
  the rules \<open>(\<or>E)\<close>, \<open>(\<bottom>E)\<close> and \<open>(\<exists>E)\<close> achieves
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1243
  a similar effect as the corresponding sequent rules.  For the other
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1244
  connectives, we use sequent-style elimination rules instead of
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1245
  destruction rules such as \<open>(\<and>E1, 2)\<close> and \<open>(\<forall>E)\<close>.
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1246
  But note that the rule \<open>(\<not>L)\<close> has no effect under our
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1247
  representation of sequents!
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1248
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1249
  \infer[\<open>(\<not>L)\<close>]{\<open>\<not> P, \<Gamma> \<turnstile> \<Delta>\<close>}{\<open>\<Gamma> \<turnstile> \<Delta>, P\<close>}
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1250
  \]
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1251
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1252
  What about reasoning on the right?  Introduction rules can only
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1253
  affect the formula in the conclusion, namely \<open>Q\<^sub>1\<close>.  The
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1254
  other right-side formulae are represented as negated assumptions,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1255
  \<open>\<not> Q\<^sub>2, \<dots>, \<not> Q\<^sub>n\<close>.  In order to operate on one of these, it
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1256
  must first be exchanged with \<open>Q\<^sub>1\<close>.  Elim-resolution with the
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1257
  \<open>swap\<close> rule has this effect: \<open>\<not> P \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> R\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1258
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1259
  To ensure that swaps occur only when necessary, each introduction
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1260
  rule is converted into a swapped form: it is resolved with the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1261
  second premise of \<open>(swap)\<close>.  The swapped form of \<open>(\<and>I)\<close>, which might be called \<open>(\<not>\<and>E)\<close>, is
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1262
  @{text [display] "\<not> (P \<and> Q) \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> (\<not> R \<Longrightarrow> Q) \<Longrightarrow> R"}
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1263
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1264
  Similarly, the swapped form of \<open>(\<longrightarrow>I)\<close> is
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1265
  @{text [display] "\<not> (P \<longrightarrow> Q) \<Longrightarrow> (\<not> R \<Longrightarrow> P \<Longrightarrow> Q) \<Longrightarrow> R"}
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1266
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1267
  Swapped introduction rules are applied using elim-resolution, which
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1268
  deletes the negated formula.  Our representation of sequents also
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1269
  requires the use of ordinary introduction rules.  If we had no
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1270
  regard for readability of intermediate goal states, we could treat
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1271
  the right side more uniformly by representing sequents as @{text
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1272
  [display] "P\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> P\<^sub>m \<Longrightarrow> \<not> Q\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> \<not> Q\<^sub>n \<Longrightarrow> \<bottom>"}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1273
\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1274
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1275
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1276
subsubsection \<open>Extra rules for the sequent calculus\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1277
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1278
text \<open>As mentioned, destruction rules such as \<open>(\<and>E1, 2)\<close> and
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1279
  \<open>(\<forall>E)\<close> must be replaced by sequent-style elimination rules.
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1280
  In addition, we need rules to embody the classical equivalence
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1281
  between \<open>P \<longrightarrow> Q\<close> and \<open>\<not> P \<or> Q\<close>.  The introduction
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1282
  rules \<open>(\<or>I1, 2)\<close> are replaced by a rule that simulates
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1283
  \<open>(\<or>R)\<close>: @{text [display] "(\<not> Q \<Longrightarrow> P) \<Longrightarrow> P \<or> Q"}
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1284
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1285
  The destruction rule \<open>(\<longrightarrow>E)\<close> is replaced by @{text [display]
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1286
  "(P \<longrightarrow> Q) \<Longrightarrow> (\<not> P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"}
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1287
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1288
  Quantifier replication also requires special rules.  In classical
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1289
  logic, \<open>\<exists>x. P x\<close> is equivalent to \<open>\<not> (\<forall>x. \<not> P x)\<close>;
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1290
  the rules \<open>(\<exists>R)\<close> and \<open>(\<forall>L)\<close> are dual:
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1291
  \[
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1292
  \infer[\<open>(\<exists>R)\<close>]{\<open>\<Gamma> \<turnstile> \<Delta>, \<exists>x. P x\<close>}{\<open>\<Gamma> \<turnstile> \<Delta>, \<exists>x. P x, P t\<close>}
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1293
  \qquad
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1294
  \infer[\<open>(\<forall>L)\<close>]{\<open>\<forall>x. P x, \<Gamma> \<turnstile> \<Delta>\<close>}{\<open>P t, \<forall>x. P x, \<Gamma> \<turnstile> \<Delta>\<close>}
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1295
  \]
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1296
  Thus both kinds of quantifier may be replicated.  Theorems requiring
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1297
  multiple uses of a universal formula are easy to invent; consider
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1298
  @{text [display] "(\<forall>x. P x \<longrightarrow> P (f x)) \<and> P a \<longrightarrow> P (f\<^sup>n a)"} for any
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1299
  \<open>n > 1\<close>.  Natural examples of the multiple use of an
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1300
  existential formula are rare; a standard one is \<open>\<exists>x. \<forall>y. P x
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1301
  \<longrightarrow> P y\<close>.
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1302
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1303
  Forgoing quantifier replication loses completeness, but gains
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1304
  decidability, since the search space becomes finite.  Many useful
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1305
  theorems can be proved without replication, and the search generally
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1306
  delivers its verdict in a reasonable time.  To adopt this approach,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1307
  represent the sequent rules \<open>(\<exists>R)\<close>, \<open>(\<exists>L)\<close> and
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1308
  \<open>(\<forall>R)\<close> by \<open>(\<exists>I)\<close>, \<open>(\<exists>E)\<close> and \<open>(\<forall>I)\<close>,
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1309
  respectively, and put \<open>(\<forall>E)\<close> into elimination form: @{text
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1310
  [display] "\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> Q) \<Longrightarrow> Q"}
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1311
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1312
  Elim-resolution with this rule will delete the universal formula
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1313
  after a single use.  To replicate universal quantifiers, replace the
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1314
  rule by @{text [display] "\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> \<forall>x. P x \<Longrightarrow> Q) \<Longrightarrow> Q"}
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1315
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1316
  To replicate existential quantifiers, replace \<open>(\<exists>I)\<close> by
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1317
  @{text [display] "(\<not> (\<exists>x. P x) \<Longrightarrow> P t) \<Longrightarrow> \<exists>x. P x"}
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1318
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1319
  All introduction rules mentioned above are also useful in swapped
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1320
  form.
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1321
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1322
  Replication makes the search space infinite; we must apply the rules
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1323
  with care.  The classical reasoner distinguishes between safe and
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1324
  unsafe rules, applying the latter only when there is no alternative.
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1325
  Depth-first search may well go down a blind alley; best-first search
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1326
  is better behaved in an infinite search space.  However, quantifier
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1327
  replication is too expensive to prove any but the simplest theorems.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1328
\<close>
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1329
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1330
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1331
subsection \<open>Rule declarations\<close>
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1332
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1333
text \<open>The proof tools of the Classical Reasoner depend on
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1334
  collections of rules declared in the context, which are classified
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1335
  as introduction, elimination or destruction and as \<^emph>\<open>safe\<close> or
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1336
  \<^emph>\<open>unsafe\<close>.  In general, safe rules can be attempted blindly,
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1337
  while unsafe rules must be used with care.  A safe rule must never
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1338
  reduce a provable goal to an unprovable set of subgoals.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1339
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1340
  The rule \<open>P \<Longrightarrow> P \<or> Q\<close> is unsafe because it reduces \<open>P
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1341
  \<or> Q\<close> to \<open>P\<close>, which might turn out as premature choice of an
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1342
  unprovable subgoal.  Any rule is unsafe whose premises contain new
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1343
  unknowns.  The elimination rule \<open>\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> Q) \<Longrightarrow> Q\<close> is
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1344
  unsafe, since it is applied via elim-resolution, which discards the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1345
  assumption \<open>\<forall>x. P x\<close> and replaces it by the weaker
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1346
  assumption \<open>P t\<close>.  The rule \<open>P t \<Longrightarrow> \<exists>x. P x\<close> is
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1347
  unsafe for similar reasons.  The quantifier duplication rule \<open>\<forall>x. P x \<Longrightarrow> (P t \<Longrightarrow> \<forall>x. P x \<Longrightarrow> Q) \<Longrightarrow> Q\<close> is unsafe in a different sense:
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1348
  since it keeps the assumption \<open>\<forall>x. P x\<close>, it is prone to
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1349
  looping.  In classical first-order logic, all rules are safe except
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1350
  those mentioned above.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1351
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1352
  The safe~/ unsafe distinction is vague, and may be regarded merely
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1353
  as a way of giving some rules priority over others.  One could argue
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1354
  that \<open>(\<or>E)\<close> is unsafe, because repeated application of it
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1355
  could generate exponentially many subgoals.  Induction rules are
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1356
  unsafe because inductive proofs are difficult to set up
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1357
  automatically.  Any inference is unsafe that instantiates an unknown
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1358
  in the proof state --- thus matching must be used, rather than
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1359
  unification.  Even proof by assumption is unsafe if it instantiates
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1360
  unknowns shared with other subgoals.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1361
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1362
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1363
    @{command_def "print_claset"}\<open>\<^sup>*\<close> & : & \<open>context \<rightarrow>\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1364
    @{attribute_def intro} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1365
    @{attribute_def elim} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1366
    @{attribute_def dest} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1367
    @{attribute_def rule} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1368
    @{attribute_def iff} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1369
    @{attribute_def swapped} & : & \<open>attribute\<close> \\
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1370
  \end{matharray}
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1371
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1372
  @{rail \<open>
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1373
    (@@{attribute intro} | @@{attribute elim} | @@{attribute dest}) ('!' | () | '?') @{syntax nat}?
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1374
    ;
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1375
    @@{attribute rule} 'del'
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1376
    ;
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1377
    @@{attribute iff} (((() | 'add') '?'?) | 'del')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1378
  \<close>}
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1379
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1380
  \<^descr> @{command "print_claset"} prints the collection of rules
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1381
  declared to the Classical Reasoner, i.e.\ the @{ML_type claset}
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1382
  within the context.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1383
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1384
  \<^descr> @{attribute intro}, @{attribute elim}, and @{attribute dest}
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1385
  declare introduction, elimination, and destruction rules,
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1386
  respectively.  By default, rules are considered as \<^emph>\<open>unsafe\<close>
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1387
  (i.e.\ not applied blindly without backtracking), while ``\<open>!\<close>'' classifies as \<^emph>\<open>safe\<close>.  Rule declarations marked by
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1388
  ``\<open>?\<close>'' coincide with those of Isabelle/Pure, cf.\
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1389
  \secref{sec:pure-meth-att} (i.e.\ are only applied in single steps
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1390
  of the @{method rule} method).  The optional natural number
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1391
  specifies an explicit weight argument, which is ignored by the
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1392
  automated reasoning tools, but determines the search order of single
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1393
  rule steps.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1394
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1395
  Introduction rules are those that can be applied using ordinary
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1396
  resolution.  Their swapped forms are generated internally, which
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1397
  will be applied using elim-resolution.  Elimination rules are
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1398
  applied using elim-resolution.  Rules are sorted by the number of
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1399
  new subgoals they will yield; rules that generate the fewest
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1400
  subgoals will be tried first.  Otherwise, later declarations take
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1401
  precedence over earlier ones.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1402
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1403
  Rules already present in the context with the same classification
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1404
  are ignored.  A warning is printed if the rule has already been
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1405
  added with some other classification, but the rule is added anyway
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1406
  as requested.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1407
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1408
  \<^descr> @{attribute rule}~\<open>del\<close> deletes all occurrences of a
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1409
  rule from the classical context, regardless of its classification as
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1410
  introduction~/ elimination~/ destruction and safe~/ unsafe.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1411
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1412
  \<^descr> @{attribute iff} declares logical equivalences to the
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1413
  Simplifier and the Classical reasoner at the same time.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1414
  Non-conditional rules result in a safe introduction and elimination
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1415
  pair; conditional ones are considered unsafe.  Rules with negative
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1416
  conclusion are automatically inverted (using \<open>\<not>\<close>-elimination
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1417
  internally).
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1418
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1419
  The ``\<open>?\<close>'' version of @{attribute iff} declares rules to
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1420
  the Isabelle/Pure context only, and omits the Simplifier
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1421
  declaration.
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1422
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1423
  \<^descr> @{attribute swapped} turns an introduction rule into an
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1424
  elimination, by resolving with the classical swap principle \<open>\<not> P \<Longrightarrow> (\<not> R \<Longrightarrow> P) \<Longrightarrow> R\<close> in the second position.  This is mainly for
42928
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1425
  illustrative purposes: the Classical Reasoner already swaps rules
9d946de41120 updated and re-unified classical rule declarations;
wenzelm
parents: 42927
diff changeset
  1426
  internally as explained above.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1427
\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1428
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1429
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1430
subsection \<open>Structured methods\<close>
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1431
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1432
text \<open>
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1433
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1434
    @{method_def rule} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1435
    @{method_def contradiction} & : & \<open>method\<close> \\
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1436
  \end{matharray}
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1437
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1438
  @{rail \<open>
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1439
    @@{method rule} @{syntax thmrefs}?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1440
  \<close>}
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1441
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1442
  \<^descr> @{method rule} as offered by the Classical Reasoner is a
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1443
  refinement over the Pure one (see \secref{sec:pure-meth-att}).  Both
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1444
  versions work the same, but the classical version observes the
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1445
  classical rule context in addition to that of Isabelle/Pure.
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1446
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1447
  Common object logics (HOL, ZF, etc.) declare a rich collection of
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1448
  classical rules (even if these would qualify as intuitionistic
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1449
  ones), but only few declarations to the rule context of
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1450
  Isabelle/Pure (\secref{sec:pure-meth-att}).
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1451
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1452
  \<^descr> @{method contradiction} solves some goal by contradiction,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1453
  deriving any result from both \<open>\<not> A\<close> and \<open>A\<close>.  Chained
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1454
  facts, which are guaranteed to participate, may appear in either
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1455
  order.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1456
\<close>
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1457
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
  1458
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1459
subsection \<open>Fully automated methods\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1460
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1461
text \<open>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1462
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1463
    @{method_def blast} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1464
    @{method_def auto} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1465
    @{method_def force} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1466
    @{method_def fast} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1467
    @{method_def slow} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1468
    @{method_def best} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1469
    @{method_def fastforce} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1470
    @{method_def slowsimp} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1471
    @{method_def bestsimp} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1472
    @{method_def deepen} & : & \<open>method\<close> \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1473
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1474
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1475
  @{rail \<open>
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1476
    @@{method blast} @{syntax nat}? (@{syntax clamod} * )
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1477
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
  1478
    @@{method auto} (@{syntax nat} @{syntax nat})? (@{syntax clasimpmod} * )
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1479
    ;
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1480
    @@{method force} (@{syntax clasimpmod} * )
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1481
    ;
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1482
    (@@{method fast} | @@{method slow} | @@{method best}) (@{syntax clamod} * )
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1483
    ;
44911
884d27ede438 fastsimp -> fastforce in doc
nipkow
parents: 44094
diff changeset
  1484
    (@@{method fastforce} | @@{method slowsimp} | @@{method bestsimp})
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1485
      (@{syntax clasimpmod} * )
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1486
    ;
43367
3f1469de9e47 cover method "deepen" concisely;
wenzelm
parents: 43366
diff changeset
  1487
    @@{method deepen} (@{syntax nat} ?) (@{syntax clamod} * )
3f1469de9e47 cover method "deepen" concisely;
wenzelm
parents: 43366
diff changeset
  1488
    ;
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1489
    @{syntax_def clamod}:
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1490
      (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del') ':' @{syntax thmrefs}
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1491
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
  1492
    @{syntax_def clasimpmod}: ('simp' (() | 'add' | 'del' | 'only') |
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1493
      ('cong' | 'split') (() | 'add' | 'del') |
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1494
      'iff' (((() | 'add') '?'?) | 'del') |
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
  1495
      (('intro' | 'elim' | 'dest') ('!' | () | '?') | 'del')) ':' @{syntax thmrefs}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1496
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1497
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1498
  \<^descr> @{method blast} is a separate classical tableau prover that
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1499
  uses the same classical rule declarations as explained before.
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1500
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1501
  Proof search is coded directly in ML using special data structures.
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1502
  A successful proof is then reconstructed using regular Isabelle
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1503
  inferences.  It is faster and more powerful than the other classical
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1504
  reasoning tools, but has major limitations too.
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1505
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
  1506
    \<^item> It does not use the classical wrapper tacticals, such as the
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1507
    integration with the Simplifier of @{method fastforce}.
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1508
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
  1509
    \<^item> It does not perform higher-order unification, as needed by the
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1510
    rule @{thm [source=false] rangeI} in HOL.  There are often
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1511
    alternatives to such rules, for example @{thm [source=false]
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1512
    range_eqI}.
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1513
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
  1514
    \<^item> Function variables may only be applied to parameters of the
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1515
    subgoal.  (This restriction arises because the prover does not use
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1516
    higher-order unification.)  If other function variables are present
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1517
    then the prover will fail with the message
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1518
    @{verbatim [display] \<open>Function unknown's argument not a bound variable\<close>}
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1519
61459
5f2ddeb15c06 clarified nesting of paragraphs: indentation is taken into account more uniformly;
wenzelm
parents: 61458
diff changeset
  1520
    \<^item> Its proof strategy is more general than @{method fast} but can
61458
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1521
    be slower.  If @{method blast} fails or seems to be running forever,
987533262fc2 Markdown support in document text;
wenzelm
parents: 61439
diff changeset
  1522
    try @{method fast} and the other proof tools described below.
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1523
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1524
  The optional integer argument specifies a bound for the number of
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1525
  unsafe steps used in a proof.  By default, @{method blast} starts
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1526
  with a bound of 0 and increases it successively to 20.  In contrast,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1527
  \<open>(blast lim)\<close> tries to prove the goal using a search bound
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1528
  of \<open>lim\<close>.  Sometimes a slow proof using @{method blast} can
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1529
  be made much faster by supplying the successful search bound to this
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1530
  proof method instead.
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1531
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1532
  \<^descr> @{method auto} combines classical reasoning with
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1533
  simplification.  It is intended for situations where there are a lot
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1534
  of mostly trivial subgoals; it proves all the easy ones, leaving the
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1535
  ones it cannot prove.  Occasionally, attempting to prove the hard
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1536
  ones may take a long time.
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1537
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1538
  The optional depth arguments in \<open>(auto m n)\<close> refer to its
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1539
  builtin classical reasoning procedures: \<open>m\<close> (default 4) is for
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1540
  @{method blast}, which is tried first, and \<open>n\<close> (default 2) is
43332
dca2c7c598f0 document depth arguments of method "auto";
wenzelm
parents: 42930
diff changeset
  1541
  for a slower but more general alternative that also takes wrappers
dca2c7c598f0 document depth arguments of method "auto";
wenzelm
parents: 42930
diff changeset
  1542
  into account.
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1543
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1544
  \<^descr> @{method force} is intended to prove the first subgoal
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1545
  completely, using many fancy proof tools and performing a rather
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1546
  exhaustive search.  As a result, proof attempts may take rather long
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1547
  or diverge easily.
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1548
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1549
  \<^descr> @{method fast}, @{method best}, @{method slow} attempt to
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1550
  prove the first subgoal using sequent-style reasoning as explained
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1551
  before.  Unlike @{method blast}, they construct proofs directly in
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1552
  Isabelle.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1553
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1554
  There is a difference in search strategy and back-tracking: @{method
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1555
  fast} uses depth-first search and @{method best} uses best-first
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1556
  search (guided by a heuristic function: normally the total size of
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1557
  the proof state).
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1558
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1559
  Method @{method slow} is like @{method fast}, but conducts a broader
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1560
  search: it may, when backtracking from a failed proof attempt, undo
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1561
  even the step of proving a subgoal by assumption.
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1562
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1563
  \<^descr> @{method fastforce}, @{method slowsimp}, @{method bestsimp}
47967
c422128d3889 discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents: 47497
diff changeset
  1564
  are like @{method fast}, @{method slow}, @{method best},
c422128d3889 discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents: 47497
diff changeset
  1565
  respectively, but use the Simplifier as additional wrapper. The name
c422128d3889 discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents: 47497
diff changeset
  1566
  @{method fastforce}, reflects the behaviour of this popular method
c422128d3889 discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents: 47497
diff changeset
  1567
  better without requiring an understanding of its implementation.
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1568
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1569
  \<^descr> @{method deepen} works by exhaustive search up to a certain
43367
3f1469de9e47 cover method "deepen" concisely;
wenzelm
parents: 43366
diff changeset
  1570
  depth.  The start depth is 4 (unless specified explicitly), and the
3f1469de9e47 cover method "deepen" concisely;
wenzelm
parents: 43366
diff changeset
  1571
  depth is increased iteratively up to 10.  Unsafe rules are modified
3f1469de9e47 cover method "deepen" concisely;
wenzelm
parents: 43366
diff changeset
  1572
  to preserve the formula they act on, so that it be used repeatedly.
3f1469de9e47 cover method "deepen" concisely;
wenzelm
parents: 43366
diff changeset
  1573
  This method can prove more goals than @{method fast}, but is much
3f1469de9e47 cover method "deepen" concisely;
wenzelm
parents: 43366
diff changeset
  1574
  slower, for example if the assumptions have many universal
3f1469de9e47 cover method "deepen" concisely;
wenzelm
parents: 43366
diff changeset
  1575
  quantifiers.
3f1469de9e47 cover method "deepen" concisely;
wenzelm
parents: 43366
diff changeset
  1576
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1577
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1578
  Any of the above methods support additional modifiers of the context
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1579
  of classical (and simplifier) rules, but the ones related to the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1580
  Simplifier are explicitly prefixed by \<open>simp\<close> here.  The
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1581
  semantics of these ad-hoc rule declarations is analogous to the
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1582
  attributes given before.  Facts provided by forward chaining are
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1583
  inserted into the goal before commencing proof search.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1584
\<close>
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1585
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1586
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1587
subsection \<open>Partially automated methods\<close>
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1588
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1589
text \<open>These proof methods may help in situations when the
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1590
  fully-automated tools fail.  The result is a simpler subgoal that
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1591
  can be tackled by other means, such as by manual instantiation of
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1592
  quantifiers.
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1593
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1594
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1595
    @{method_def safe} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1596
    @{method_def clarify} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1597
    @{method_def clarsimp} & : & \<open>method\<close> \\
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1598
  \end{matharray}
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1599
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1600
  @{rail \<open>
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1601
    (@@{method safe} | @@{method clarify}) (@{syntax clamod} * )
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1602
    ;
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1603
    @@{method clarsimp} (@{syntax clasimpmod} * )
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1604
  \<close>}
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1605
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1606
  \<^descr> @{method safe} repeatedly performs safe steps on all subgoals.
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1607
  It is deterministic, with at most one outcome.
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1608
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1609
  \<^descr> @{method clarify} performs a series of safe steps without
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1610
  splitting subgoals; see also @{method clarify_step}.
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1611
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1612
  \<^descr> @{method clarsimp} acts like @{method clarify}, but also does
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1613
  simplification.  Note that if the Simplifier context includes a
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1614
  splitter for the premises, the subgoal may still be split.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1615
\<close>
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1616
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1617
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1618
subsection \<open>Single-step tactics\<close>
43366
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1619
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1620
text \<open>
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1621
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1622
    @{method_def safe_step} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1623
    @{method_def inst_step} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1624
    @{method_def step} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1625
    @{method_def slow_step} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1626
    @{method_def clarify_step} & : &  \<open>method\<close> \\
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1627
  \end{matharray}
43366
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1628
50070
e447ad4d6edd avoid clash of terminology wrt. "semi-automated" in the sense of Isar (e.g. method "rule");
wenzelm
parents: 50068
diff changeset
  1629
  These are the primitive tactics behind the automated proof methods
e447ad4d6edd avoid clash of terminology wrt. "semi-automated" in the sense of Isar (e.g. method "rule");
wenzelm
parents: 50068
diff changeset
  1630
  of the Classical Reasoner.  By calling them yourself, you can
e447ad4d6edd avoid clash of terminology wrt. "semi-automated" in the sense of Isar (e.g. method "rule");
wenzelm
parents: 50068
diff changeset
  1631
  execute these procedures one step at a time.
43366
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1632
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1633
  \<^descr> @{method safe_step} performs a safe step on the first subgoal.
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1634
  The safe wrapper tacticals are applied to a tactic that may include
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1635
  proof by assumption or Modus Ponens (taking care not to instantiate
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1636
  unknowns), or substitution.
43366
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1637
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1638
  \<^descr> @{method inst_step} is like @{method safe_step}, but allows
43366
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1639
  unknowns to be instantiated.
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1640
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1641
  \<^descr> @{method step} is the basic step of the proof procedure, it
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1642
  operates on the first subgoal.  The unsafe wrapper tacticals are
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1643
  applied to a tactic that tries @{method safe}, @{method inst_step},
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1644
  or applies an unsafe rule from the context.
43366
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1645
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1646
  \<^descr> @{method slow_step} resembles @{method step}, but allows
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1647
  backtracking between using safe rules with instantiation (@{method
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1648
  inst_step}) and using unsafe rules.  The resulting search space is
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1649
  larger.
43366
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1650
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1651
  \<^descr> @{method clarify_step} performs a safe step on the first
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1652
  subgoal; no splitting step is applied.  For example, the subgoal
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1653
  \<open>A \<and> B\<close> is left as a conjunction.  Proof by assumption,
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1654
  Modus Ponens, etc., may be performed provided they do not
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1655
  instantiate unknowns.  Assumptions of the form \<open>x = t\<close> may
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1656
  be eliminated.  The safe wrapper tactical is applied.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1657
\<close>
43366
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1658
9cbcab5c780a moved/updated single-step tactics;
wenzelm
parents: 43365
diff changeset
  1659
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1660
subsection \<open>Modifying the search step\<close>
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1661
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1662
text \<open>
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1663
  \begin{mldecls}
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1664
    @{index_ML_type wrapper: "(int -> tactic) -> (int -> tactic)"} \\[0.5ex]
51703
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1665
    @{index_ML_op addSWrapper: "Proof.context *
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1666
  (string * (Proof.context -> wrapper)) -> Proof.context"} \\
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1667
    @{index_ML_op addSbefore: "Proof.context *
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1668
  (string * (Proof.context -> int -> tactic)) -> Proof.context"} \\
51703
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1669
    @{index_ML_op addSafter: "Proof.context *
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1670
  (string * (Proof.context -> int -> tactic)) -> Proof.context"} \\
51703
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1671
    @{index_ML_op delSWrapper: "Proof.context * string -> Proof.context"} \\[0.5ex]
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1672
    @{index_ML_op addWrapper: "Proof.context *
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1673
  (string * (Proof.context -> wrapper)) -> Proof.context"} \\
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1674
    @{index_ML_op addbefore: "Proof.context *
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1675
  (string * (Proof.context -> int -> tactic)) -> Proof.context"} \\
51703
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1676
    @{index_ML_op addafter: "Proof.context *
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1677
  (string * (Proof.context -> int -> tactic)) -> Proof.context"} \\
51703
f2e92fc0c8aa modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents: 50108
diff changeset
  1678
    @{index_ML_op delWrapper: "Proof.context * string -> Proof.context"} \\[0.5ex]
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1679
    @{index_ML addSss: "Proof.context -> Proof.context"} \\
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1680
    @{index_ML addss: "Proof.context -> Proof.context"} \\
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1681
  \end{mldecls}
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1682
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1683
  The proof strategy of the Classical Reasoner is simple.  Perform as
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1684
  many safe inferences as possible; or else, apply certain safe rules,
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1685
  allowing instantiation of unknowns; or else, apply an unsafe rule.
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1686
  The tactics also eliminate assumptions of the form \<open>x = t\<close>
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1687
  by substitution if they have been set up to do so.  They may perform
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1688
  a form of Modus Ponens: if there are assumptions \<open>P \<longrightarrow> Q\<close> and
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1689
  \<open>P\<close>, then replace \<open>P \<longrightarrow> Q\<close> by \<open>Q\<close>.
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1690
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1691
  The classical reasoning tools --- except @{method blast} --- allow
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1692
  to modify this basic proof strategy by applying two lists of
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1693
  arbitrary \<^emph>\<open>wrapper tacticals\<close> to it.  The first wrapper list,
50108
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1694
  which is considered to contain safe wrappers only, affects @{method
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1695
  safe_step} and all the tactics that call it.  The second one, which
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1696
  may contain unsafe wrappers, affects the unsafe parts of @{method
f171b5240c31 method setup for Classical steps;
wenzelm
parents: 50083
diff changeset
  1697
  step}, @{method slow_step}, and the tactics that call them.  A
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1698
  wrapper transforms each step of the search, for example by
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1699
  attempting other tactics before or after the original step tactic.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1700
  All members of a wrapper list are applied in turn to the respective
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1701
  step tactic.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1702
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1703
  Initially the two wrapper lists are empty, which means no
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1704
  modification of the step tactics. Safe and unsafe wrappers are added
59905
678c9e625782 misc tuning -- keep name space more clean;
wenzelm
parents: 59853
diff changeset
  1705
  to the context with the functions given below, supplying them with
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1706
  wrapper names.  These names may be used to selectively delete
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1707
  wrappers.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1708
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1709
  \<^descr> \<open>ctxt addSWrapper (name, wrapper)\<close> adds a new wrapper,
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1710
  which should yield a safe tactic, to modify the existing safe step
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1711
  tactic.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1712
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1713
  \<^descr> \<open>ctxt addSbefore (name, tac)\<close> adds the given tactic as a
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1714
  safe wrapper, such that it is tried \<^emph>\<open>before\<close> each safe step of
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1715
  the search.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1716
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1717
  \<^descr> \<open>ctxt addSafter (name, tac)\<close> adds the given tactic as a
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1718
  safe wrapper, such that it is tried when a safe step of the search
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1719
  would fail.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1720
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1721
  \<^descr> \<open>ctxt delSWrapper name\<close> deletes the safe wrapper with
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1722
  the given name.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1723
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1724
  \<^descr> \<open>ctxt addWrapper (name, wrapper)\<close> adds a new wrapper to
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1725
  modify the existing (unsafe) step tactic.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1726
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1727
  \<^descr> \<open>ctxt addbefore (name, tac)\<close> adds the given tactic as an
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1728
  unsafe wrapper, such that it its result is concatenated
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1729
  \<^emph>\<open>before\<close> the result of each unsafe step.
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1730
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1731
  \<^descr> \<open>ctxt addafter (name, tac)\<close> adds the given tactic as an
61477
e467ae7aa808 more control symbols;
wenzelm
parents: 61459
diff changeset
  1732
  unsafe wrapper, such that it its result is concatenated \<^emph>\<open>after\<close>
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1733
  the result of each unsafe step.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1734
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1735
  \<^descr> \<open>ctxt delWrapper name\<close> deletes the unsafe wrapper with
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1736
  the given name.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1737
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1738
  \<^descr> \<open>addSss\<close> adds the simpset of the context to its
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1739
  classical set. The assumptions and goal will be simplified, in a
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1740
  rather safe way, after each safe step of the search.
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1741
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1742
  \<^descr> \<open>addss\<close> adds the simpset of the context to its
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1743
  classical set. The assumptions and goal will be simplified, before
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1744
  the each unsafe step of the search.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1745
\<close>
50071
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1746
959548c3b947 moved classical wrappers to IsarRef;
wenzelm
parents: 50070
diff changeset
  1747
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1748
section \<open>Object-logic setup \label{sec:object-logic}\<close>
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1749
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1750
text \<open>
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1751
  \begin{matharray}{rcl}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1752
    @{command_def "judgment"} & : & \<open>theory \<rightarrow> theory\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1753
    @{method_def atomize} & : & \<open>method\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1754
    @{attribute_def atomize} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1755
    @{attribute_def rule_format} & : & \<open>attribute\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1756
    @{attribute_def rulify} & : & \<open>attribute\<close> \\
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1757
  \end{matharray}
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1758
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1759
  The very starting point for any Isabelle object-logic is a ``truth
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1760
  judgment'' that links object-level statements to the meta-logic
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1761
  (with its minimal language of \<open>prop\<close> that covers universal
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1762
  quantification \<open>\<And>\<close> and implication \<open>\<Longrightarrow>\<close>).
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1763
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1764
  Common object-logics are sufficiently expressive to internalize rule
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1765
  statements over \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close> within their own
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1766
  language.  This is useful in certain situations where a rule needs
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1767
  to be viewed as an atomic statement from the meta-level perspective,
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1768
  e.g.\ \<open>\<And>x. x \<in> A \<Longrightarrow> P x\<close> versus \<open>\<forall>x \<in> A. P x\<close>.
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1769
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1770
  From the following language elements, only the @{method atomize}
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1771
  method and @{attribute rule_format} attribute are occasionally
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1772
  required by end-users, the rest is for those who need to setup their
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1773
  own object-logic.  In the latter case existing formulations of
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1774
  Isabelle/FOL or Isabelle/HOL may be taken as realistic examples.
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1775
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1776
  Generic tools may refer to the information provided by object-logic
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1777
  declarations internally.
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1778
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1779
  @{rail \<open>
46494
ea2ae63336f3 clarified outer syntax "constdecl", which is only local to some rail diagrams;
wenzelm
parents: 46277
diff changeset
  1780
    @@{command judgment} @{syntax name} '::' @{syntax type} @{syntax mixfix}?
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1781
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
  1782
    @@{attribute atomize} ('(' 'full' ')')?
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1783
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
  1784
    @@{attribute rule_format} ('(' 'noasm' ')')?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1785
  \<close>}
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1786
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1787
  \<^descr> @{command "judgment"}~\<open>c :: \<sigma> (mx)\<close> declares constant
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1788
  \<open>c\<close> as the truth judgment of the current object-logic.  Its
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1789
  type \<open>\<sigma>\<close> should specify a coercion of the category of
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1790
  object-level propositions to \<open>prop\<close> of the Pure meta-logic;
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1791
  the mixfix annotation \<open>(mx)\<close> would typically just link the
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1792
  object language (internally of syntactic category \<open>logic\<close>)
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1793
  with that of \<open>prop\<close>.  Only one @{command "judgment"}
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1794
  declaration may be given in any theory development.
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1795
  
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1796
  \<^descr> @{method atomize} (as a method) rewrites any non-atomic
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1797
  premises of a sub-goal, using the meta-level equations declared via
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1798
  @{attribute atomize} (as an attribute) beforehand.  As a result,
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1799
  heavily nested goals become amenable to fundamental operations such
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1800
  as resolution (cf.\ the @{method (Pure) rule} method).  Giving the ``\<open>(full)\<close>'' option here means to turn the whole subgoal into an
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1801
  object-statement (if possible), including the outermost parameters
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1802
  and assumptions as well.
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1803
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1804
  A typical collection of @{attribute atomize} rules for a particular
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1805
  object-logic would provide an internalization for each of the
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1806
  connectives of \<open>\<And>\<close>, \<open>\<Longrightarrow>\<close>, and \<open>\<equiv>\<close>.
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1807
  Meta-level conjunction should be covered as well (this is
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1808
  particularly important for locales, see \secref{sec:locale}).
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1809
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1810
  \<^descr> @{attribute rule_format} rewrites a theorem by the equalities
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1811
  declared as @{attribute rulify} rules in the current object-logic.
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1812
  By default, the result is fully normalized, including assumptions
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1813
  and conclusions at any depth.  The \<open>(no_asm)\<close> option
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1814
  restricts the transformation to the conclusion of a rule.
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1815
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1816
  In common object-logics (HOL, FOL, ZF), the effect of @{attribute
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1817
  rule_format} is to replace (bounded) universal quantification
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1818
  (\<open>\<forall>\<close>) and implication (\<open>\<longrightarrow>\<close>) by the corresponding
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1819
  rule statements over \<open>\<And>\<close> and \<open>\<Longrightarrow>\<close>.
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1820
\<close>
26790
e8cc166ba123 converted "General logic setup";
wenzelm
parents: 26789
diff changeset
  1821
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1822
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1823
section \<open>Tracing higher-order unification\<close>
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1824
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1825
text \<open>
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1826
  \begin{tabular}{rcll}
61493
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1827
    @{attribute_def unify_trace_simp} & : & \<open>attribute\<close> & default \<open>false\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1828
    @{attribute_def unify_trace_types} & : & \<open>attribute\<close> & default \<open>false\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1829
    @{attribute_def unify_trace_bound} & : & \<open>attribute\<close> & default \<open>50\<close> \\
0debd22f0c0e isabelle update_cartouches -t;
wenzelm
parents: 61477
diff changeset
  1830
    @{attribute_def unify_search_bound} & : & \<open>attribute\<close> & default \<open>60\<close> \\
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1831
  \end{tabular}
61421
e0825405d398 more symbols;
wenzelm
parents: 61413
diff changeset
  1832
  \<^medskip>
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1833
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1834
  Higher-order unification works well in most practical situations,
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1835
  but sometimes needs extra care to identify problems.  These tracing
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1836
  options may help.
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1837
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1838
  \<^descr> @{attribute unify_trace_simp} controls tracing of the
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1839
  simplification phase of higher-order unification.
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1840
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1841
  \<^descr> @{attribute unify_trace_types} controls warnings of
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1842
  incompleteness, when unification is not considering all possible
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1843
  instantiations of schematic type variables.
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1844
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1845
  \<^descr> @{attribute unify_trace_bound} determines the depth where
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1846
  unification starts to print tracing information once it reaches
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1847
  depth; 0 for full tracing.  At the default value, tracing
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1848
  information is almost never printed in practice.
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1849
61439
2bf52eec4e8a more symbols;
wenzelm
parents: 61424
diff changeset
  1850
  \<^descr> @{attribute unify_search_bound} prevents unification from
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1851
  searching past the given depth.  Because of this bound, higher-order
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1852
  unification cannot return an infinite sequence, though it can return
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1853
  an exponentially long one.  The search rarely approaches the default
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1854
  value in practice.  If the search is cut off, unification prints a
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1855
  warning ``Unification bound exceeded''.
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1856
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1857
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1858
  \begin{warn}
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1859
  Options for unification cannot be modified in a local context.  Only
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1860
  the global theory content is taken into account.
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1861
  \end{warn}
58618
782f0b662cae more cartouches;
wenzelm
parents: 58552
diff changeset
  1862
\<close>
50083
01605e79c569 updated unification options;
wenzelm
parents: 50080
diff changeset
  1863
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1864
end