src/Doc/IsarRef/Generic.thy
author wenzelm
Sun, 26 Jan 2014 14:01:19 +0100
changeset 55152 a56099a6447a
parent 55112 b1a5d603fd12
permissions -rw-r--r--
discontinued obsolete attribute "standard";
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
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
     5
chapter {* Generic tools and packages \label{ch:gen-tools} *}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
     6
42655
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
     7
section {* Configuration options \label{sec:config} *}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
     8
40291
012ed4426fda support for real valued configuration options;
wenzelm
parents: 40255
diff changeset
     9
text {* Isabelle/Pure maintains a record of named configuration
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:
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    19
*}
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    20
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    21
declare [[show_main_goal = false]]
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    22
42655
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    23
notepad
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    24
begin
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    25
  note [[show_main_goal = true]]
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    26
end
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    27
eb95e2f3b218 updated configuration options -- no ML here;
wenzelm
parents: 42651
diff changeset
    28
text {* For historical reasons, some tools cannot take the full proof
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    29
  context into account and merely refer to the background theory.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    30
  This is accommodated by configuration options being declared as
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    31
  ``global'', which may not be changed within a local context.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    32
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    33
  \begin{matharray}{rcll}
52060
179236c82c2a renamed 'print_configs' to 'print_options';
wenzelm
parents: 52037
diff changeset
    34
    @{command_def "print_options"} & : & @{text "context \<rightarrow>"} \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    35
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    36
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    37
  @{rail \<open>
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
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    41
  \begin{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    42
  
52060
179236c82c2a renamed 'print_configs' to 'print_options';
wenzelm
parents: 52037
diff changeset
    43
  \item @{command "print_options"} prints the available configuration
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    44
  options, with names, types, and current values.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    45
  
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    46
  \item @{text "name = value"} as an attribute expression modifies the
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    47
  named option, with the syntax of the value depending on the option's
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    48
  type.  For @{ML_type bool} the default value is @{text true}.  Any
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    49
  attempt to change a global option in a local context is ignored.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    50
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    51
  \end{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    52
*}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    53
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    54
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26901
diff changeset
    55
section {* Basic proof tools *}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    56
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    57
subsection {* Miscellaneous methods and attributes \label{sec:misc-meth-att} *}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    58
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    59
text {*
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    60
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    61
    @{method_def unfold} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    62
    @{method_def fold} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    63
    @{method_def insert} & : & @{text method} \\[0.5ex]
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    64
    @{method_def erule}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    65
    @{method_def drule}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    66
    @{method_def frule}@{text "\<^sup>*"} & : & @{text method} \\
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
    67
    @{method_def intro} & : & @{text method} \\
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
    68
    @{method_def elim} & : & @{text method} \\
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    69
    @{method_def succeed} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
    70
    @{method_def fail} & : & @{text method} \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    71
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    72
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
    73
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
    74
    (@@{method fold} | @@{method unfold} | @@{method insert}) @{syntax thmrefs}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    75
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
    76
    (@@{method erule} | @@{method drule} | @@{method frule})
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
    77
      ('(' @{syntax nat} ')')? @{syntax thmrefs}
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
    78
    ;
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
    79
    (@@{method intro} | @@{method elim}) @{syntax thmrefs}?
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
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    82
  \begin{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    83
  
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    84
  \item @{method unfold}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and @{method fold}~@{text
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    85
  "a\<^sub>1 \<dots> a\<^sub>n"} expand (or fold back) the given definitions throughout
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    86
  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
    87
  subject to rewriting as well.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    88
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    89
  \item @{method insert}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} inserts theorems as facts
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    90
  into all goals of the proof state.  Note that current facts
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
    91
  indicated for forward chaining are ignored.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
    92
30397
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    93
  \item @{method erule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}, @{method
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    94
  drule}~@{text "a\<^sub>1 \<dots> a\<^sub>n"}, and @{method frule}~@{text
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    95
  "a\<^sub>1 \<dots> a\<^sub>n"} are similar to the basic @{method rule}
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    96
  method (see \secref{sec:pure-meth-att}), but apply rules by
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    97
  elim-resolution, destruct-resolution, and forward-resolution,
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    98
  respectively \cite{isabelle-implementation}.  The optional natural
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
    99
  number argument (default 0) specifies additional assumption steps to
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
   100
  be performed here.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   101
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   102
  Note that these methods are improper ones, mainly serving for
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   103
  experimentation and tactic script emulation.  Different modes of
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   104
  basic rule application are usually expressed in Isar at the proof
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   105
  language level, rather than via implicit proof state manipulations.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   106
  For example, a proper single-step elimination would be done using
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   107
  the plain @{method rule} method, with forward chaining of current
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   108
  facts.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   109
43365
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   110
  \item @{method intro} and @{method elim} repeatedly refine some goal
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   111
  by intro- or elim-resolution, after having inserted any chained
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   112
  facts.  Exactly the rules given as arguments are taken into account;
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   113
  this allows fine-tuned decomposition of a proof problem, in contrast
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   114
  to common automated tools.
f8944cb2468f tuned sections;
wenzelm
parents: 43332
diff changeset
   115
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   116
  \item @{method succeed} yields a single (unchanged) result; it is
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   117
  the identity of the ``@{text ","}'' 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
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   120
  \item @{method fail} yields an empty result sequence; it is the
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   121
  identity of the ``@{text "|"}'' method combinator (cf.\
28754
6f2e67a3dfaa moved section "Proof method expressions" to proof chapter;
wenzelm
parents: 27248
diff changeset
   122
  \secref{sec:proof-meth}).
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   123
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   124
  \end{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   125
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   126
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   127
    @{attribute_def tagged} & : & @{text attribute} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   128
    @{attribute_def untagged} & : & @{text attribute} \\[0.5ex]
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   129
    @{attribute_def THEN} & : & @{text attribute} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   130
    @{attribute_def unfolded} & : & @{text attribute} \\
47497
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   131
    @{attribute_def folded} & : & @{text attribute} \\
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   132
    @{attribute_def abs_def} & : & @{text attribute} \\[0.5ex]
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   133
    @{attribute_def rotated} & : & @{text attribute} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   134
    @{attribute_def (Pure) elim_format} & : & @{text attribute} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   135
    @{attribute_def no_vars}@{text "\<^sup>*"} & : & @{text attribute} \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   136
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   137
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   138
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   139
    @@{attribute tagged} @{syntax name} @{syntax name}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   140
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   141
    @@{attribute untagged} @{syntax name}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   142
    ;
48205
09c2a3d9aa22 discontinued obsolete attribute "COMP";
wenzelm
parents: 47967
diff changeset
   143
    @@{attribute THEN} ('[' @{syntax nat} ']')? @{syntax thmref}
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 unfolded} | @@{attribute folded}) @{syntax thmrefs}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   146
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   147
    @@{attribute rotated} @{syntax int}?
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   148
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   149
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   150
  \begin{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   151
28764
b65194fe4434 fixed/tuned syntax for attribute "tagged";
wenzelm
parents: 28761
diff changeset
   152
  \item @{attribute tagged}~@{text "name value"} and @{attribute
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   153
  untagged}~@{text name} add and remove \emph{tags} of some theorem.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   154
  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
   155
  The first string is considered the tag name, the second its value.
b65194fe4434 fixed/tuned syntax for attribute "tagged";
wenzelm
parents: 28761
diff changeset
   156
  Note that @{attribute untagged} removes any tags of the same name.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   157
48205
09c2a3d9aa22 discontinued obsolete attribute "COMP";
wenzelm
parents: 47967
diff changeset
   158
  \item @{attribute THEN}~@{text a} composes rules by resolution; it
09c2a3d9aa22 discontinued obsolete attribute "COMP";
wenzelm
parents: 47967
diff changeset
   159
  resolves with the first premise of @{text a} (an alternative
09c2a3d9aa22 discontinued obsolete attribute "COMP";
wenzelm
parents: 47967
diff changeset
   160
  position may be also specified).  See also @{ML_op "RS"} in
09c2a3d9aa22 discontinued obsolete attribute "COMP";
wenzelm
parents: 47967
diff changeset
   161
  \cite{isabelle-implementation}.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   162
  
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   163
  \item @{attribute unfolded}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} and @{attribute
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   164
  folded}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} expand and fold back again the given
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   165
  definitions throughout a rule.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   166
47497
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   167
  \item @{attribute abs_def} turns an equation of the form @{prop "f x
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   168
  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
   169
  simp} or @{method unfold} steps always expand it.  This also works
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   170
  for object-logic equality.
c78c6e1ec75d document attribute "abs_def";
wenzelm
parents: 46706
diff changeset
   171
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   172
  \item @{attribute rotated}~@{text n} rotate the premises of a
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   173
  theorem by @{text n} (default 1).
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   174
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   175
  \item @{attribute (Pure) elim_format} turns a destruction rule into
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   176
  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
   177
  (PROP A \<Longrightarrow> PROP B) \<Longrightarrow> PROP B"}.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   178
  
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   179
  Note that the Classical Reasoner (\secref{sec:classical}) provides
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   180
  its own version of this operation.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   181
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   182
  \item @{attribute no_vars} replaces schematic variables by free
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   183
  ones; this is mainly for tuning output of pretty printed theorems.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   184
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   185
  \end{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   186
*}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   187
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   188
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   189
subsection {* Low-level equational reasoning *}
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   190
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   191
text {*
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   192
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   193
    @{method_def subst} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   194
    @{method_def hypsubst} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   195
    @{method_def split} & : & @{text method} \\
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   196
  \end{matharray}
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   197
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   198
  @{rail \<open>
55029
61a6bf7d4b02 clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents: 52060
diff changeset
   199
    @@{method subst} ('(' 'asm' ')')? \<newline> ('(' (@{syntax nat}+) ')')? @{syntax thmref}
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   200
    ;
44094
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   201
    @@{method split} @{syntax thmrefs}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   202
  \<close>}
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   203
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   204
  These methods provide low-level facilities for equational reasoning
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   205
  that are intended for specialized applications only.  Normally,
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   206
  single step calculations would be performed in a structured text
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   207
  (see also \secref{sec:calculation}), while the Simplifier methods
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   208
  provide the canonical way for automated normalization (see
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   209
  \secref{sec:simplifier}).
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   210
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   211
  \begin{description}
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   212
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   213
  \item @{method subst}~@{text eq} performs a single substitution step
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   214
  using rule @{text eq}, which may be either a meta or object
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   215
  equality.
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   216
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   217
  \item @{method subst}~@{text "(asm) eq"} substitutes in an
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   218
  assumption.
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   219
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   220
  \item @{method subst}~@{text "(i \<dots> j) eq"} performs several
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   221
  substitutions in the conclusion. The numbers @{text i} to @{text j}
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   222
  indicate the positions to substitute at.  Positions are ordered from
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   223
  the top of the term tree moving down from left to right. For
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   224
  example, in @{text "(a + b) + (c + d)"} there are three positions
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   225
  where commutativity of @{text "+"} is applicable: 1 refers to @{text
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   226
  "a + b"}, 2 to the whole term, and 3 to @{text "c + d"}.
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   227
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   228
  If the positions in the list @{text "(i \<dots> j)"} are non-overlapping
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   229
  (e.g.\ @{text "(2 3)"} in @{text "(a + b) + (c + d)"}) you may
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   230
  assume all substitutions are performed simultaneously.  Otherwise
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   231
  the behaviour of @{text subst} is not specified.
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   232
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   233
  \item @{method subst}~@{text "(asm) (i \<dots> j) eq"} performs the
27071
614c045c5fd4 clarification of "subst" by Lucas Dixon;
wenzelm
parents: 27044
diff changeset
   234
  substitutions in the assumptions. The positions refer to the
614c045c5fd4 clarification of "subst" by Lucas Dixon;
wenzelm
parents: 27044
diff changeset
   235
  assumptions in order from left to right.  For example, given in a
614c045c5fd4 clarification of "subst" by Lucas Dixon;
wenzelm
parents: 27044
diff changeset
   236
  goal of the form @{text "P (a + b) \<Longrightarrow> P (c + d) \<Longrightarrow> \<dots>"}, position 1 of
614c045c5fd4 clarification of "subst" by Lucas Dixon;
wenzelm
parents: 27044
diff changeset
   237
  commutativity of @{text "+"} is the subterm @{text "a + b"} and
614c045c5fd4 clarification of "subst" by Lucas Dixon;
wenzelm
parents: 27044
diff changeset
   238
  position 2 is the subterm @{text "c + d"}.
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   239
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   240
  \item @{method hypsubst} performs substitution using some
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   241
  assumption; this only works for equations of the form @{text "x =
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   242
  t"} where @{text x} is a free or bound variable.
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   243
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   244
  \item @{method split}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} performs single-step case
44094
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   245
  splitting using the given rules.  Splitting is performed in the
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   246
  conclusion or some assumption of the subgoal, depending of the
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   247
  structure of the rule.
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   248
  
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   249
  Note that the @{method simp} method already involves repeated
44094
f7bbfdf4b4a7 updated documentation of method "split" according to e6a4bb832b46;
wenzelm
parents: 43367
diff changeset
   250
  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
   251
  @{attribute split}, for example.
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   252
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   253
  \end{description}
27044
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   254
*}
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   255
c4eaa7140532 moved subst/hypsubst to "Basic proof tools";
wenzelm
parents: 27040
diff changeset
   256
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   257
subsection {* Further tactic emulations \label{sec:tactics} *}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   258
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   259
text {*
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   260
  The following improper proof methods emulate traditional tactics.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   261
  These admit direct access to the goal state, which is normally
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   262
  considered harmful!  In particular, this may involve both numbered
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   263
  goal addressing (default 1), and dynamic instantiation within the
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   264
  scope of some subgoal.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   265
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   266
  \begin{warn}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   267
    Dynamic instantiations refer to universally quantified parameters
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   268
    of a subgoal (the dynamic context) rather than fixed variables and
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   269
    term abbreviations of a (static) Isar context.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   270
  \end{warn}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   271
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   272
  Tactic emulation methods, unlike their ML counterparts, admit
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   273
  simultaneous instantiation from both dynamic and static contexts.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   274
  If names occur in both contexts goal parameters hide locally fixed
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   275
  variables.  Likewise, schematic variables refer to term
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   276
  abbreviations, if present in the static context.  Otherwise the
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   277
  schematic variable is interpreted as a schematic variable and left
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   278
  to be solved by unification with certain parts of the subgoal.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   279
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   280
  Note that the tactic emulation proof methods in Isabelle/Isar are
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   281
  consistently named @{text foo_tac}.  Note also that variable names
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   282
  occurring on left hand sides of instantiations must be preceded by a
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   283
  question mark if they coincide with a keyword or contain dots.  This
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   284
  is consistent with the attribute @{attribute "where"} (see
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   285
  \secref{sec:pure-meth-att}).
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   286
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   287
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   288
    @{method_def rule_tac}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   289
    @{method_def erule_tac}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   290
    @{method_def drule_tac}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   291
    @{method_def frule_tac}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   292
    @{method_def cut_tac}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   293
    @{method_def thin_tac}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   294
    @{method_def subgoal_tac}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   295
    @{method_def rename_tac}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   296
    @{method_def rotate_tac}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   297
    @{method_def tactic}@{text "\<^sup>*"} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   298
    @{method_def raw_tactic}@{text "\<^sup>*"} & : & @{text method} \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   299
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   300
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   301
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   302
    (@@{method rule_tac} | @@{method erule_tac} | @@{method drule_tac} |
55029
61a6bf7d4b02 clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents: 52060
diff changeset
   303
      @@{method frule_tac} | @@{method cut_tac} | @@{method thin_tac}) @{syntax goal_spec}? \<newline>
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   304
    ( dynamic_insts @'in' @{syntax thmref} | @{syntax thmrefs} )
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   305
    ;
42705
528a2ba8fa74 tuned some syntax names;
wenzelm
parents: 42704
diff changeset
   306
    @@{method subgoal_tac} @{syntax goal_spec}? (@{syntax prop} +)
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   307
    ;
42705
528a2ba8fa74 tuned some syntax names;
wenzelm
parents: 42704
diff changeset
   308
    @@{method rename_tac} @{syntax goal_spec}? (@{syntax name} +)
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   309
    ;
42705
528a2ba8fa74 tuned some syntax names;
wenzelm
parents: 42704
diff changeset
   310
    @@{method rotate_tac} @{syntax goal_spec}? @{syntax int}?
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   311
    ;
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   312
    (@@{method tactic} | @@{method raw_tactic}) @{syntax text}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   313
    ;
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   314
42617
77d239840285 more precise rail diagrams;
wenzelm
parents: 42596
diff changeset
   315
    dynamic_insts: ((@{syntax name} '=' @{syntax term}) + @'and')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   316
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   317
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   318
\begin{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   319
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   320
  \item @{method rule_tac} etc. do resolution of rules with explicit
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   321
  instantiation.  This works the same way as the ML tactics @{ML
30397
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
   322
  res_inst_tac} etc. (see \cite{isabelle-implementation})
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   323
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   324
  Multiple rules may be only given if there is no instantiation; then
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   325
  @{method rule_tac} is the same as @{ML resolve_tac} in ML (see
30397
b6212ae21656 markup antiquotation options;
wenzelm
parents: 30168
diff changeset
   326
  \cite{isabelle-implementation}).
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   327
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   328
  \item @{method cut_tac} inserts facts into the proof state as
46706
877d57975427 updated cut_tac, without loose references to implementation manual;
wenzelm
parents: 46494
diff changeset
   329
  assumption of a subgoal; instantiations may be given as well.  Note
877d57975427 updated cut_tac, without loose references to implementation manual;
wenzelm
parents: 46494
diff changeset
   330
  that the scope of schematic variables is spread over the main goal
877d57975427 updated cut_tac, without loose references to implementation manual;
wenzelm
parents: 46494
diff changeset
   331
  statement and rule premises are turned into new subgoals.  This is
877d57975427 updated cut_tac, without loose references to implementation manual;
wenzelm
parents: 46494
diff changeset
   332
  in contrast to the regular method @{method insert} which inserts
877d57975427 updated cut_tac, without loose references to implementation manual;
wenzelm
parents: 46494
diff changeset
   333
  closed rule statements.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   334
46277
aea65ff733b4 updated thin_tac;
wenzelm
parents: 46274
diff changeset
   335
  \item @{method thin_tac}~@{text \<phi>} deletes the specified premise
aea65ff733b4 updated thin_tac;
wenzelm
parents: 46274
diff changeset
   336
  from a subgoal.  Note that @{text \<phi>} may contain schematic
aea65ff733b4 updated thin_tac;
wenzelm
parents: 46274
diff changeset
   337
  variables, to abbreviate the intended proposition; the first
aea65ff733b4 updated thin_tac;
wenzelm
parents: 46274
diff changeset
   338
  matching subgoal premise will be deleted.  Removing useless premises
aea65ff733b4 updated thin_tac;
wenzelm
parents: 46274
diff changeset
   339
  from a subgoal increases its readability and can make search tactics
aea65ff733b4 updated thin_tac;
wenzelm
parents: 46274
diff changeset
   340
  run faster.
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   341
46271
e1b5460f1725 updated subgoal_tac;
wenzelm
parents: 46262
diff changeset
   342
  \item @{method subgoal_tac}~@{text "\<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"} adds the propositions
e1b5460f1725 updated subgoal_tac;
wenzelm
parents: 46262
diff changeset
   343
  @{text "\<phi>\<^sub>1 \<dots> \<phi>\<^sub>n"} as local premises to a subgoal, and poses the same
e1b5460f1725 updated subgoal_tac;
wenzelm
parents: 46262
diff changeset
   344
  as new subgoals (in the original context).
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   345
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   346
  \item @{method rename_tac}~@{text "x\<^sub>1 \<dots> x\<^sub>n"} renames parameters of a
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   347
  goal according to the list @{text "x\<^sub>1, \<dots>, x\<^sub>n"}, which refers to the
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   348
  \emph{suffix} of variables.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   349
46274
67139209b548 updated rotate_tac;
wenzelm
parents: 46271
diff changeset
   350
  \item @{method rotate_tac}~@{text n} rotates the premises of a
67139209b548 updated rotate_tac;
wenzelm
parents: 46271
diff changeset
   351
  subgoal by @{text n} positions: from right to left if @{text n} is
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   352
  positive, and from left to right if @{text n} is negative; the
46274
67139209b548 updated rotate_tac;
wenzelm
parents: 46271
diff changeset
   353
  default value is 1.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   354
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   355
  \item @{method tactic}~@{text "text"} produces a proof method from
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   356
  any ML text of type @{ML_type tactic}.  Apart from the usual ML
27223
8546e2407b31 method "tactic": only "facts" as bound value;
wenzelm
parents: 27209
diff changeset
   357
  environment and the current proof context, the ML code may refer to
8546e2407b31 method "tactic": only "facts" as bound value;
wenzelm
parents: 27209
diff changeset
   358
  the locally bound values @{ML_text facts}, which indicates any
8546e2407b31 method "tactic": only "facts" as bound value;
wenzelm
parents: 27209
diff changeset
   359
  current facts used for forward-chaining.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   360
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   361
  \item @{method raw_tactic} is similar to @{method tactic}, but
27223
8546e2407b31 method "tactic": only "facts" as bound value;
wenzelm
parents: 27209
diff changeset
   362
  presents the goal state in its raw internal form, where simultaneous
8546e2407b31 method "tactic": only "facts" as bound value;
wenzelm
parents: 27209
diff changeset
   363
  subgoals appear as conjunction of the logical framework instead of
8546e2407b31 method "tactic": only "facts" as bound value;
wenzelm
parents: 27209
diff changeset
   364
  the usual split into several subgoals.  While feature this is useful
8546e2407b31 method "tactic": only "facts" as bound value;
wenzelm
parents: 27209
diff changeset
   365
  for debugging of complex method definitions, it should not never
8546e2407b31 method "tactic": only "facts" as bound value;
wenzelm
parents: 27209
diff changeset
   366
  appear in production theories.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   367
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   368
  \end{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   369
*}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   370
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   371
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26901
diff changeset
   372
section {* The Simplifier \label{sec:simplifier} *}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   373
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   374
text {* The Simplifier performs conditional and unconditional
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   375
  rewriting and uses contextual information: rule declarations in the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   376
  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
   377
  well as chained facts and subgoal premises (``local assumptions'').
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   378
  There are several general hooks that allow to modify the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   379
  simplification strategy, or incorporate other proof tools that solve
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   380
  sub-problems, produce rewrite rules on demand etc.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   381
50075
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   382
  The rewriting strategy is always strictly bottom up, except for
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   383
  congruence rules, which are applied while descending into a term.
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   384
  Conditions in conditional rewrite rules are solved recursively
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   385
  before the rewrite rule is applied.
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   386
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   387
  The default Simplifier setup of major object logics (HOL, HOLCF,
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   388
  FOL, ZF) makes the Simplifier ready for immediate use, without
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   389
  engaging into the internal structures.  Thus it serves as
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   390
  general-purpose proof tool with the main focus on equational
50075
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   391
  reasoning, and a bit more than that.
ceb877c315a1 (re)moved old material about Simplifier;
wenzelm
parents: 50071
diff changeset
   392
*}
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   393
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   394
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   395
subsection {* Simplification methods \label{sec:simp-meth} *}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   396
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   397
text {*
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   398
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   399
    @{method_def simp} & : & @{text method} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   400
    @{method_def simp_all} & : & @{text method} \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   401
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   402
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   403
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   404
    (@@{method simp} | @@{method simp_all}) opt? (@{syntax simpmod} * )
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   405
    ;
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   406
40255
9ffbc25e1606 eliminated obsolete \_ escapes in rail environments;
wenzelm
parents: 35613
diff changeset
   407
    opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use' | 'asm_lr' ) ')'
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   408
    ;
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   409
    @{syntax_def simpmod}: ('add' | 'del' | 'only' | 'split' (() | 'add' | 'del') |
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   410
      'cong' (() | 'add' | 'del')) ':' @{syntax thmrefs}
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   411
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   412
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   413
  \begin{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   414
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   415
  \item @{method simp} invokes the Simplifier on the first subgoal,
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   416
  after inserting chained facts as additional goal premises; further
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   417
  rule declarations may be included via @{text "(simp add: facts)"}.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   418
  The proof method fails if the subgoal remains unchanged after
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   419
  simplification.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   420
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   421
  Note that the original goal premises and chained facts are subject
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   422
  to simplification themselves, while declarations via @{text
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   423
  "add"}/@{text "del"} merely follow the policies of the object-logic
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   424
  to extract rewrite rules from theorems, without further
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   425
  simplification.  This may lead to slightly different behavior in
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   426
  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
   427
  boundary situations to perform the intended simplification step!
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   428
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   429
  \medskip The @{text only} modifier first removes all other rewrite
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   430
  rules, looper tactics (including split rules), congruence rules, and
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   431
  then behaves like @{text add}.  Implicit solvers remain, which means
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   432
  that trivial rules like reflexivity or introduction of @{text
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   433
  "True"} are available to solve the simplified subgoals, but also
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   434
  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
   435
  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
   436
  compared to English!
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   437
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   438
  \medskip The @{text split} modifiers add or delete rules for the
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   439
  Splitter (see also \secref{sec:simp-strategies} on the looper).
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   440
  This works only if the Simplifier method has been properly setup to
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   441
  include the Splitter (all major object logics such HOL, HOLCF, FOL,
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   442
  ZF do this already).
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   443
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   444
  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
   445
  single-step case splitting.  The effect of repeatedly applying
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   446
  @{text "(split thms)"} can be imitated by ``@{text "(simp only:
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   447
  split: thms)"}''.
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   448
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   449
  \medskip The @{text cong} modifiers add or delete Simplifier
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   450
  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
   451
  to add.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   452
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   453
  \item @{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
   454
  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
   455
  in Isabelle.\footnote{The order is irrelevant for goals without
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   456
  schematic variables, so simplification might actually be performed
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   457
  in parallel here.}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   458
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   459
  Chained facts are inserted into all subgoals, before the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   460
  simplification process starts.  Further rule declarations are the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   461
  same as for @{method simp}.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   462
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   463
  The proof method fails if all subgoals remain unchanged after
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   464
  simplification.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   465
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   466
  \end{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   467
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   468
  By default the Simplifier methods above take local assumptions fully
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   469
  into account, using equational assumptions in the subsequent
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   470
  normalization process, or simplifying assumptions themselves.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   471
  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
   472
  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
   473
  follows.\footnote{Unlike the corresponding Isar proof methods, the
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   474
  ML tactics do not insist in changing the goal state.}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   475
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   476
  \begin{center}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   477
  \small
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   478
  \begin{supertabular}{|l|l|p{0.3\textwidth}|}
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   479
  \hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   480
  Isar method & ML tactic & behavior \\\hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   481
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   482
  @{text "(simp (no_asm))"} & @{ML simp_tac} & assumptions are ignored
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   483
  completely \\\hline
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   484
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   485
  @{text "(simp (no_asm_simp))"} & @{ML asm_simp_tac} & assumptions
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   486
  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
   487
  themselves simplified \\\hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   488
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   489
  @{text "(simp (no_asm_use))"} & @{ML full_simp_tac} & assumptions
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   490
  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
   491
  or the conclusion \\\hline
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   492
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   493
  @{text "(simp)"} & @{ML asm_full_simp_tac} & assumptions are used in
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   494
  the simplification of the conclusion and to simplify other
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   495
  assumptions \\\hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   496
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   497
  @{text "(simp (asm_lr))"} & @{ML asm_lr_simp_tac} & compatibility
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   498
  mode: an assumption is only used for simplifying assumptions which
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   499
  are to the right of it \\\hline
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   500
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   501
  \end{supertabular}
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   502
  \end{center}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   503
*}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   504
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   505
50064
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   506
subsubsection {* Examples *}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   507
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   508
text {* We consider basic algebraic simplifications in Isabelle/HOL.
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   509
  The rather trivial goal @{prop "0 + (x + 0) = x + 0 + 0"} looks like
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   510
  a good candidate to be solved by a single call of @{method simp}:
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   511
*}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   512
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   513
lemma "0 + (x + 0) = x + 0 + 0" apply simp? oops
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   514
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   515
text {* The above attempt \emph{fails}, because @{term "0"} and @{term
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   516
  "op +"} in the HOL library are declared as generic type class
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   517
  operations, without stating any algebraic laws yet.  More specific
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   518
  types are required to get access to certain standard simplifications
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   519
  of the theory context, e.g.\ like this: *}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   520
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   521
lemma fixes x :: nat shows "0 + (x + 0) = x + 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   522
lemma fixes x :: int shows "0 + (x + 0) = x + 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   523
lemma fixes x :: "'a :: monoid_add" shows "0 + (x + 0) = x + 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   524
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   525
text {*
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   526
  \medskip In many cases, assumptions of a subgoal are also needed in
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   527
  the simplification process.  For example:
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   528
*}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   529
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   530
lemma fixes x :: nat shows "x = 0 \<Longrightarrow> x + x = 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   531
lemma fixes x :: nat assumes "x = 0" shows "x + x = 0" apply simp oops
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   532
lemma fixes x :: nat assumes "x = 0" shows "x + x = 0" using assms by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   533
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   534
text {* As seen above, local assumptions that shall contribute to
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   535
  simplification need to be part of the subgoal already, or indicated
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   536
  explicitly for use by the subsequent method invocation.  Both too
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   537
  little or too much information can make simplification fail, for
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   538
  different reasons.
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   539
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   540
  In the next example the malicious assumption @{prop "\<And>x::nat. f x =
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   541
  g (f (g x))"} does not contribute to solve the problem, but makes
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   542
  the default @{method simp} method loop: the rewrite rule @{text "f
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   543
  ?x \<equiv> g (f (g ?x))"} extracted from the assumption does not
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   544
  terminate.  The Simplifier notices certain simple forms of
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   545
  nontermination, but not this one.  The problem can be solved
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   546
  nonetheless, by ignoring assumptions via special options as
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   547
  explained before:
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   548
*}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   549
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   550
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
   551
  by (simp (no_asm))
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   552
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   553
text {* The latter form is typical for long unstructured proof
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   554
  scripts, where the control over the goal content is limited.  In
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   555
  structured proofs it is usually better to avoid pushing too many
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   556
  facts into the goal state in the first place.  Assumptions in the
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   557
  Isar proof context do not intrude the reasoning if not used
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   558
  explicitly.  This is illustrated for a toplevel statement and a
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   559
  local proof body as follows:
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   560
*}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   561
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   562
lemma
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   563
  assumes "\<And>x::nat. f x = g (f (g x))"
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   564
  shows "f 0 = f 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   565
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   566
notepad
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   567
begin
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   568
  assume "\<And>x::nat. f x = g (f (g x))"
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   569
  have "f 0 = f 0 + 0" by simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   570
end
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   571
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   572
text {* \medskip Because assumptions may simplify each other, there
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   573
  can be very subtle cases of nontermination. For example, the regular
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   574
  @{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
   575
  \<Longrightarrow> Q"} gives rise to the infinite reduction sequence
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   576
  \[
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   577
  @{text "P (f x)"} \stackrel{@{text "f x \<equiv> f y"}}{\longmapsto}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   578
  @{text "P (f y)"} \stackrel{@{text "y \<equiv> x"}}{\longmapsto}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   579
  @{text "P (f x)"} \stackrel{@{text "f x \<equiv> f y"}}{\longmapsto} \cdots
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   580
  \]
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   581
  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
   582
  Q"} terminates (without solving the goal):
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   583
*}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   584
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   585
lemma "y = x \<Longrightarrow> f x = f y \<Longrightarrow> P (f x) \<Longrightarrow> Q"
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   586
  apply simp
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   587
  oops
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   588
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   589
text {* See also \secref{sec:simp-config} for options to enable
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   590
  Simplifier trace mode, which often helps to diagnose problems with
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   591
  rewrite systems.
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   592
*}
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   593
e08cc8b20564 refurbished Simplifier examples;
wenzelm
parents: 50063
diff changeset
   594
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   595
subsection {* Declaring rules \label{sec:simp-rules} *}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   596
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   597
text {*
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   598
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   599
    @{attribute_def simp} & : & @{text attribute} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   600
    @{attribute_def split} & : & @{text attribute} \\
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   601
    @{attribute_def cong} & : & @{text attribute} \\
50077
wenzelm
parents: 50076
diff changeset
   602
    @{command_def "print_simpset"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   603
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   604
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   605
  @{rail \<open>
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   606
    (@@{attribute simp} | @@{attribute split} | @@{attribute cong})
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   607
      (() | 'add' | 'del')
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   608
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   609
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   610
  \begin{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   611
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   612
  \item @{attribute simp} declares rewrite rules, by adding or
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   613
  deleting them from the simpset within the theory or proof context.
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   614
  Rewrite rules are theorems expressing some form of equality, for
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   615
  example:
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   616
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   617
  @{text "Suc ?m + ?n = ?m + Suc ?n"} \\
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   618
  @{text "?P \<and> ?P \<longleftrightarrow> ?P"} \\
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   619
  @{text "?A \<union> ?B \<equiv> {x. x \<in> ?A \<or> x \<in> ?B}"}
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   620
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   621
  \smallskip
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   622
  Conditional rewrites such as @{text "?m < ?n \<Longrightarrow> ?m div ?n = 0"} are
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   623
  also permitted; the conditions can be arbitrary formulas.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   624
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   625
  \medskip Internally, all rewrite rules are translated into Pure
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   626
  equalities, theorems with conclusion @{text "lhs \<equiv> rhs"}. The
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   627
  simpset contains a function for extracting equalities from arbitrary
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   628
  theorems, which is usually installed when the object-logic is
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   629
  configured initially. For example, @{text "\<not> ?x \<in> {}"} could be
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   630
  turned into @{text "?x \<in> {} \<equiv> False"}. Theorems that are declared as
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   631
  @{attribute simp} and local assumptions within a goal are treated
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   632
  uniformly in this respect.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   633
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   634
  The Simplifier accepts the following formats for the @{text "lhs"}
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   635
  term:
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   636
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   637
  \begin{enumerate}
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   638
50076
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   639
  \item First-order patterns, considering the sublanguage of
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   640
  application of constant operators to variable operands, without
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   641
  @{text "\<lambda>"}-abstractions or functional variables.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   642
  For example:
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   643
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   644
  @{text "(?x + ?y) + ?z \<equiv> ?x + (?y + ?z)"} \\
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   645
  @{text "f (f ?x ?y) ?z \<equiv> f ?x (f ?y ?z)"}
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   646
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   647
  \item Higher-order patterns in the sense of \cite{nipkow-patterns}.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   648
  These are terms in @{text "\<beta>"}-normal form (this will always be the
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   649
  case unless you have done something strange) where each occurrence
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   650
  of an unknown is of the form @{text "?F x\<^sub>1 \<dots> x\<^sub>n"}, where the
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   651
  @{text "x\<^sub>i"} are distinct bound variables.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   652
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   653
  For example, @{text "(\<forall>x. ?P x \<and> ?Q x) \<equiv> (\<forall>x. ?P x) \<and> (\<forall>x. ?Q x)"}
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   654
  or its symmetric form, since the @{text "rhs"} is also a
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   655
  higher-order pattern.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   656
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   657
  \item Physical first-order patterns over raw @{text "\<lambda>"}-term
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   658
  structure without @{text "\<alpha>\<beta>\<eta>"}-equality; abstractions and bound
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   659
  variables are treated like quasi-constant term material.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   660
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   661
  For example, the rule @{text "?f ?x \<in> range ?f = True"} rewrites the
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   662
  term @{text "g a \<in> range g"} to @{text "True"}, but will fail to
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   663
  match @{text "g (h b) \<in> range (\<lambda>x. g (h x))"}. However, offending
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   664
  subterms (in our case @{text "?f ?x"}, which is not a pattern) can
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   665
  be replaced by adding new variables and conditions like this: @{text
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   666
  "?y = ?f ?x \<Longrightarrow> ?y \<in> range ?f = True"} is acceptable as a conditional
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   667
  rewrite rule of the second category since conditions can be
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   668
  arbitrary terms.
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   669
c5cc24781cbf updated explanation of rewrite rules;
wenzelm
parents: 50075
diff changeset
   670
  \end{enumerate}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   671
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   672
  \item @{attribute split} declares case split rules.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   673
45645
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   674
  \item @{attribute cong} declares congruence rules to the Simplifier
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   675
  context.
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   676
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   677
  Congruence rules are equalities of the form @{text [display]
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   678
  "\<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
   679
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   680
  This controls the simplification of the arguments of @{text f}.  For
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   681
  example, some arguments can be simplified under additional
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   682
  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
   683
  (?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
   684
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   685
  Given this rule, the simplifier assumes @{text "?Q\<^sub>1"} and extracts
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   686
  rewrite rules from it when simplifying @{text "?P\<^sub>2"}.  Such local
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   687
  assumptions are effective for rewriting formulae such as @{text "x =
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   688
  0 \<longrightarrow> y + x = y"}.
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   689
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   690
  %FIXME
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   691
  %The local assumptions are also provided as theorems to the solver;
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   692
  %see \secref{sec:simp-solver} below.
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   693
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   694
  \medskip The following congruence rule for bounded quantifiers also
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   695
  supplies contextual information --- about the bound variable:
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   696
  @{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
   697
    (\<forall>x \<in> ?A. ?P x) \<longleftrightarrow> (\<forall>x \<in> ?B. ?Q x)"}
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   698
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   699
  \medskip This congruence rule for conditional expressions can
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   700
  supply contextual information for simplifying the arms:
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   701
  @{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
   702
    (if ?p then ?a else ?b) = (if ?q then ?c else ?d)"}
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   703
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   704
  A congruence rule can also \emph{prevent} simplification of some
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   705
  arguments.  Here is an alternative congruence rule for conditional
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   706
  expressions that conforms to non-strict functional evaluation:
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   707
  @{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
   708
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   709
  Only the first argument is simplified; the others remain unchanged.
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   710
  This can make simplification much faster, but may require an extra
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   711
  case split over the condition @{text "?q"} to prove the goal.
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   712
50077
wenzelm
parents: 50076
diff changeset
   713
  \item @{command "print_simpset"} prints the collection of rules
wenzelm
parents: 50076
diff changeset
   714
  declared to the Simplifier, which is also known as ``simpset''
wenzelm
parents: 50076
diff changeset
   715
  internally.
wenzelm
parents: 50076
diff changeset
   716
wenzelm
parents: 50076
diff changeset
   717
  For historical reasons, simpsets may occur independently from the
wenzelm
parents: 50076
diff changeset
   718
  current context, but are conceptually dependent on it.  When the
wenzelm
parents: 50076
diff changeset
   719
  Simplifier is invoked via one of its main entry points in the Isar
wenzelm
parents: 50076
diff changeset
   720
  source language (as proof method \secref{sec:simp-meth} or rule
wenzelm
parents: 50076
diff changeset
   721
  attribute \secref{sec:simp-meth}), its simpset is derived from the
wenzelm
parents: 50076
diff changeset
   722
  current proof context, and carries a back-reference to that for
wenzelm
parents: 50076
diff changeset
   723
  other tools that might get invoked internally (e.g.\ simplification
wenzelm
parents: 50076
diff changeset
   724
  procedures \secref{sec:simproc}).  A mismatch of the context of the
wenzelm
parents: 50076
diff changeset
   725
  simpset and the context of the problem being simplified may lead to
wenzelm
parents: 50076
diff changeset
   726
  unexpected results.
wenzelm
parents: 50076
diff changeset
   727
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   728
  \end{description}
50065
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   729
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   730
  The implicit simpset of the theory context is propagated
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   731
  monotonically through the theory hierarchy: forming a new theory,
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   732
  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
   733
  point.  Also note that definitional packages like @{command
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   734
  "datatype"}, @{command "primrec"}, @{command "fun"} routinely
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   735
  declare Simplifier rules to the target context, while plain
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   736
  @{command "definition"} is an exception in \emph{not} declaring
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   737
  anything.
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   738
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   739
  \medskip It is up the user to manipulate the current simpset further
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   740
  by explicitly adding or deleting theorems as simplification rules,
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   741
  or installing other tools via simplification procedures
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   742
  (\secref{sec:simproc}).  Good simpsets are hard to design.  Rules
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   743
  that obviously simplify, like @{text "?n + 0 \<equiv> ?n"} are good
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   744
  candidates for the implicit simpset, unless a special
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   745
  non-normalizing behavior of certain operations is intended.  More
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   746
  specific rules (such as distributive laws, which duplicate subterms)
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   747
  should be added only for specific proof steps.  Conversely,
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   748
  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
   749
  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
   750
  designed simpset.
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   751
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   752
  \begin{warn}
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   753
  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
   754
  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
   755
  ancestors have deleted simplification rules because they are no
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   756
  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
   757
  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
   758
  in the theory body.
7c01dc2dcb8c more on Simplifier rules, based on old material;
wenzelm
parents: 50064
diff changeset
   759
  \end{warn}
45645
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   760
*}
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   761
4014bc2a09ff modernized section about congruence rules;
wenzelm
parents: 44911
diff changeset
   762
50080
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   763
subsection {* Ordered rewriting with permutative rules *}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   764
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   765
text {* A rewrite rule is \emph{permutative} if the left-hand side and
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   766
  right-hand side are the equal up to renaming of variables.  The most
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   767
  common permutative rule is commutativity: @{text "?x + ?y = ?y +
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   768
  ?x"}.  Other examples include @{text "(?x - ?y) - ?z = (?x - ?z) -
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   769
  ?y"} in arithmetic and @{text "insert ?x (insert ?y ?A) = insert ?y
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   770
  (insert ?x ?A)"} for sets.  Such rules are common enough to merit
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   771
  special attention.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   772
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   773
  Because ordinary rewriting loops given such rules, the Simplifier
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   774
  employs a special strategy, called \emph{ordered rewriting}.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   775
  Permutative rules are detected and only applied if the rewriting
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   776
  step decreases the redex wrt.\ a given term ordering.  For example,
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   777
  commutativity rewrites @{text "b + a"} to @{text "a + b"}, but then
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   778
  stops, because the redex cannot be decreased further in the sense of
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   779
  the term ordering.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   780
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   781
  The default is lexicographic ordering of term structure, but this
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   782
  could be also changed locally for special applications via
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   783
  @{index_ML Simplifier.set_termless} in Isabelle/ML.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   784
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   785
  \medskip Permutative rewrite rules are declared to the Simplifier
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   786
  just like other rewrite rules.  Their special status is recognized
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   787
  automatically, and their application is guarded by the term ordering
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   788
  accordingly. *}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   789
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   790
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   791
subsubsection {* Rewriting with AC operators *}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   792
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   793
text {* Ordered rewriting is particularly effective in the case of
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   794
  associative-commutative operators.  (Associativity by itself is not
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   795
  permutative.)  When dealing with an AC-operator @{text "f"}, keep
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   796
  the following points in mind:
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   797
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   798
  \begin{itemize}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   799
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   800
  \item The associative law must always be oriented from left to
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   801
  right, namely @{text "f (f x y) z = f x (f y z)"}.  The opposite
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   802
  orientation, if used with commutativity, leads to looping in
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   803
  conjunction with the standard term order.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   804
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   805
  \item To complete your set of rewrite rules, you must add not just
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   806
  associativity (A) and commutativity (C) but also a derived rule
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   807
  \emph{left-commutativity} (LC): @{text "f x (f y z) = f y (f x z)"}.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   808
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   809
  \end{itemize}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   810
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   811
  Ordered rewriting with the combination of A, C, and LC sorts a term
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   812
  lexicographically --- the rewriting engine imitates bubble-sort.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   813
*}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   814
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   815
locale AC_example =
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   816
  fixes f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infix "\<bullet>" 60)
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   817
  assumes assoc: "(x \<bullet> y) \<bullet> z = x \<bullet> (y \<bullet> z)"
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   818
  assumes commute: "x \<bullet> y = y \<bullet> x"
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   819
begin
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   820
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   821
lemma left_commute: "x \<bullet> (y \<bullet> z) = y \<bullet> (x \<bullet> z)"
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   822
proof -
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   823
  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
   824
  then show ?thesis by (simp only: assoc)
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   825
qed
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   826
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   827
lemmas AC_rules = assoc commute left_commute
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   828
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   829
text {* Thus the Simplifier is able to establish equalities with
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   830
  arbitrary permutations of subterms, by normalizing to a common
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   831
  standard form.  For example: *}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   832
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   833
lemma "(b \<bullet> c) \<bullet> a = xxx"
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   834
  apply (simp only: AC_rules)
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   835
  txt {* @{subgoals} *}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   836
  oops
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   837
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   838
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
   839
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
   840
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
   841
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   842
end
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   843
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   844
text {* Martin and Nipkow \cite{martin-nipkow} discuss the theory and
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   845
  give many examples; other algebraic structures are amenable to
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   846
  ordered rewriting, such as boolean rings.  The Boyer-Moore theorem
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   847
  prover \cite{bm88book} also employs ordered rewriting.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   848
*}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   849
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   850
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   851
subsubsection {* Re-orienting equalities *}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   852
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   853
text {* Another application of ordered rewriting uses the derived rule
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   854
  @{thm [source] eq_commute}: @{thm [source = false] eq_commute} to
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   855
  reverse equations.
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   856
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   857
  This is occasionally useful to re-orient local assumptions according
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   858
  to the term ordering, when other built-in mechanisms of
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   859
  reorientation and mutual simplification fail to apply.  *}
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   860
200f749c96db updated section on ordered rewriting;
wenzelm
parents: 50079
diff changeset
   861
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   862
subsection {* Configuration options \label{sec:simp-config} *}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   863
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   864
text {*
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   865
  \begin{tabular}{rcll}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   866
    @{attribute_def simp_depth_limit} & : & @{text attribute} & default @{text 100} \\
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   867
    @{attribute_def simp_trace} & : & @{text attribute} & default @{text false} \\
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   868
    @{attribute_def simp_trace_depth_limit} & : & @{text attribute} & default @{text 1} \\
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   869
    @{attribute_def simp_debug} & : & @{text attribute} & default @{text false} \\
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   870
  \end{tabular}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   871
  \medskip
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   872
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   873
  These configurations options control further aspects of the Simplifier.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   874
  See also \secref{sec:config}.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   875
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   876
  \begin{description}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   877
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   878
  \item @{attribute simp_depth_limit} limits the number of recursive
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   879
  invocations of the Simplifier during conditional rewriting.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   880
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   881
  \item @{attribute simp_trace} makes the Simplifier output internal
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   882
  operations.  This includes rewrite steps, but also bookkeeping like
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   883
  modifications of the simpset.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   884
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   885
  \item @{attribute simp_trace_depth_limit} limits the effect of
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   886
  @{attribute simp_trace} to the given depth of recursive Simplifier
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   887
  invocations (when solving conditions of rewrite rules).
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   888
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   889
  \item @{attribute simp_debug} makes the Simplifier output some extra
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   890
  information about internal operations.  This includes any attempted
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   891
  invocation of simplification procedures.
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   892
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   893
  \end{description}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   894
*}
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   895
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   896
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
   897
subsection {* Simplification procedures \label{sec:simproc} *}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   898
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   899
text {* Simplification procedures are ML functions that produce proven
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   900
  rewrite rules on demand.  They are associated with higher-order
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   901
  patterns that approximate the left-hand sides of equations.  The
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   902
  Simplifier first matches the current redex against one of the LHS
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   903
  patterns; if this succeeds, the corresponding ML function is
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   904
  invoked, passing the Simplifier context and redex term.  Thus rules
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   905
  may be specifically fashioned for particular situations, resulting
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   906
  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
   907
  rules.
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   908
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   909
  Any successful result needs to be a (possibly conditional) rewrite
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   910
  rule @{text "t \<equiv> u"} that is applicable to the current redex.  The
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   911
  rule will be applied just as any ordinary rewrite rule.  It is
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   912
  expected to be already in \emph{internal form}, bypassing the
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   913
  automatic preprocessing of object-level equivalences.
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   914
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   915
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   916
    @{command_def "simproc_setup"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
   917
    simproc & : & @{text attribute} \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   918
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   919
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   920
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   921
    @@{command simproc_setup} @{syntax name} '(' (@{syntax term} + '|') ')' '='
55029
61a6bf7d4b02 clarified @{rail} syntax: prefer explicit \<newline> symbol;
wenzelm
parents: 52060
diff changeset
   922
      @{syntax text} \<newline> (@'identifier' (@{syntax nameref}+))?
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   923
    ;
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   924
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
   925
    @@{attribute simproc} (('add' ':')? | 'del' ':') (@{syntax name}+)
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
   926
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   927
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   928
  \begin{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   929
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   930
  \item @{command "simproc_setup"} defines a named simplification
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   931
  procedure that is invoked by the Simplifier whenever any of the
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   932
  given term patterns match the current redex.  The implementation,
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   933
  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
   934
  "morphism -> simpset -> cterm -> thm option"}, where the @{ML_type
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   935
  cterm} represents the current redex @{text r} and the result is
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   936
  supposed to be some proven rewrite rule @{text "r \<equiv> r'"} (or a
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   937
  generalized version), or @{ML NONE} to indicate failure.  The
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   938
  @{ML_type simpset} argument holds the full context of the current
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   939
  Simplifier invocation, including the actual Isar proof context.  The
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   940
  @{ML_type morphism} informs about the difference of the original
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   941
  compilation context wrt.\ the one of the actual application later
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   942
  on.  The optional @{keyword "identifier"} specifies theorems that
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   943
  represent the logical content of the abstract theory of this
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   944
  simproc.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   945
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   946
  Morphisms and identifiers are only relevant for simprocs that are
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   947
  defined within a local target context, e.g.\ in a locale.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   948
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   949
  \item @{text "simproc add: name"} and @{text "simproc del: name"}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   950
  add or delete named simprocs to the current Simplifier context.  The
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   951
  default is to add a simproc.  Note that @{command "simproc_setup"}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   952
  already adds the new simproc to the subsequent context.
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   953
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
   954
  \end{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   955
*}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   956
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
   957
42925
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   958
subsubsection {* Example *}
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   959
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   960
text {* The following simplification procedure for @{thm
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   961
  [source=false, show_types] unit_eq} in HOL performs fine-grained
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   962
  control over rule application, beyond higher-order pattern matching.
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   963
  Declaring @{thm unit_eq} as @{attribute simp} directly would make
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   964
  the simplifier loop!  Note that a version of this simplification
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   965
  procedure is already active in Isabelle/HOL.  *}
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   966
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   967
simproc_setup unit ("x::unit") = {*
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   968
  fn _ => fn _ => fn ct =>
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   969
    if HOLogic.is_unit (term_of ct) then NONE
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   970
    else SOME (mk_meta_eq @{thm unit_eq})
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   971
*}
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   972
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   973
text {* Since the Simplifier applies simplification procedures
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   974
  frequently, it is important to make the failure check in ML
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   975
  reasonably fast. *}
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   976
c6c4f997ad87 updated and re-unified material on simprocs;
wenzelm
parents: 42705
diff changeset
   977
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   978
subsection {* Configurable Simplifier strategies \label{sec:simp-strategies} *}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   979
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   980
text {* The core term-rewriting engine of the Simplifier is normally
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   981
  used in combination with some add-on components that modify the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   982
  strategy and allow to integrate other non-Simplifier proof tools.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   983
  These may be reconfigured in ML as explained below.  Even if the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   984
  default strategies of object-logics like Isabelle/HOL are used
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   985
  unchanged, it helps to understand how the standard Simplifier
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   986
  strategies work. *}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   987
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   988
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   989
subsubsection {* The subgoaler *}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   990
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   991
text {*
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   992
  \begin{mldecls}
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   993
  @{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
   994
  Proof.context -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
   995
  @{index_ML Simplifier.prems_of: "Proof.context -> thm list"} \\
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   996
  \end{mldecls}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   997
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   998
  The subgoaler is the tactic used to solve subgoals arising out of
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
   999
  conditional rewrite rules or congruence rules.  The default should
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1000
  be simplification itself.  In rare situations, this strategy may
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1001
  need to be changed.  For example, if the premise of a conditional
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1002
  rule is an instance of its conclusion, as in @{text "Suc ?m < ?n \<Longrightarrow>
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1003
  ?m < ?n"}, the default strategy could loop.  % FIXME !??
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1004
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1005
  \begin{description}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1006
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1007
  \item @{ML Simplifier.set_subgoaler}~@{text "tac ctxt"} sets the
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1008
  subgoaler of the context to @{text "tac"}.  The tactic will
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1009
  be applied to the context of the running Simplifier instance.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1010
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1011
  \item @{ML Simplifier.prems_of}~@{text "ctxt"} retrieves the current
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1012
  set of premises from the context.  This may be non-empty only if
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1013
  the Simplifier has been told to utilize local assumptions in the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1014
  first place (cf.\ the options in \secref{sec:simp-meth}).
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1015
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1016
  \end{description}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1017
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1018
  As an example, consider the following alternative subgoaler:
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1019
*}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1020
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1021
ML {*
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1022
  fun subgoaler_tac ctxt =
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1023
    assume_tac ORELSE'
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1024
    resolve_tac (Simplifier.prems_of ctxt) ORELSE'
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1025
    asm_simp_tac ctxt
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1026
*}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1027
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1028
text {* This tactic first tries to solve the subgoal by assumption or
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1029
  by resolving with with one of the premises, calling simplification
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1030
  only if that fails. *}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1031
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1032
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1033
subsubsection {* The solver *}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1034
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1035
text {*
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1036
  \begin{mldecls}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1037
  @{index_ML_type solver} \\
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1038
  @{index_ML Simplifier.mk_solver: "string ->
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1039
  (Proof.context -> int -> tactic) -> solver"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1040
  @{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
  1041
  @{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
  1042
  @{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
  1043
  @{index_ML_op addSSolver: "Proof.context * solver -> Proof.context"} \\
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1044
  \end{mldecls}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1045
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1046
  A solver is a tactic that attempts to solve a subgoal after
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1047
  simplification.  Its core functionality is to prove trivial subgoals
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1048
  such as @{prop "True"} and @{text "t = t"}, but object-logics might
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1049
  be more ambitious.  For example, Isabelle/HOL performs a restricted
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1050
  version of linear arithmetic here.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1051
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1052
  Solvers are packaged up in abstract type @{ML_type solver}, with
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1053
  @{ML Simplifier.mk_solver} as the only operation to create a solver.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1054
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1055
  \medskip Rewriting does not instantiate unknowns.  For example,
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1056
  rewriting alone cannot prove @{text "a \<in> ?A"} since this requires
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1057
  instantiating @{text "?A"}.  The solver, however, is an arbitrary
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1058
  tactic and may instantiate unknowns as it pleases.  This is the only
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1059
  way the Simplifier can handle a conditional rewrite rule whose
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1060
  condition contains extra variables.  When a simplification tactic is
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1061
  to be combined with other provers, especially with the Classical
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1062
  Reasoner, it is important whether it can be considered safe or not.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1063
  For this reason a simpset contains two solvers: safe and unsafe.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1064
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1065
  The standard simplification strategy solely uses the unsafe solver,
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1066
  which is appropriate in most cases.  For special applications where
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1067
  the simplification process is not allowed to instantiate unknowns
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1068
  within the goal, simplification starts with the safe solver, but may
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1069
  still apply the ordinary unsafe one in nested simplifications for
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1070
  conditional rules or congruences. Note that in this way the overall
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1071
  tactic is not totally safe: it may instantiate unknowns that appear
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1072
  also in other subgoals.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1073
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1074
  \begin{description}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1075
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1076
  \item @{ML Simplifier.mk_solver}~@{text "name tac"} turns @{text
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1077
  "tac"} into a solver; the @{text "name"} is only attached as a
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1078
  comment and has no further significance.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1079
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1080
  \item @{text "ctxt setSSolver solver"} installs @{text "solver"} as
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1081
  the safe solver of @{text "ctxt"}.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1082
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1083
  \item @{text "ctxt addSSolver solver"} adds @{text "solver"} as an
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1084
  additional safe solver; it will be tried after the solvers which had
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1085
  already been present in @{text "ctxt"}.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1086
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1087
  \item @{text "ctxt setSolver solver"} installs @{text "solver"} as the
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1088
  unsafe solver of @{text "ctxt"}.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1089
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1090
  \item @{text "ctxt addSolver solver"} adds @{text "solver"} as an
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1091
  additional unsafe solver; it will be tried after the solvers which
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1092
  had already been present in @{text "ctxt"}.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1093
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1094
  \end{description}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1095
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1096
  \medskip The solver tactic is invoked with the context of the
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1097
  running Simplifier.  Further operations
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1098
  may be used to retrieve relevant information, such as the list of
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1099
  local Simplifier premises via @{ML Simplifier.prems_of} --- this
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1100
  list may be non-empty only if the Simplifier runs in a mode that
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1101
  utilizes local assumptions (see also \secref{sec:simp-meth}).  The
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1102
  solver is also presented the full goal including its assumptions in
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1103
  any case.  Thus it can use these (e.g.\ by calling @{ML
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1104
  assume_tac}), even if the Simplifier proper happens to ignore local
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1105
  premises at the moment.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1106
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1107
  \medskip As explained before, the subgoaler is also used to solve
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1108
  the premises of congruence rules.  These are usually of the form
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1109
  @{text "s = ?x"}, where @{text "s"} needs to be simplified and
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1110
  @{text "?x"} needs to be instantiated with the result.  Typically,
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1111
  the subgoaler will invoke the Simplifier at some point, which will
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1112
  eventually call the solver.  For this reason, solver tactics must be
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1113
  prepared to solve goals of the form @{text "t = ?x"}, usually by
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1114
  reflexivity.  In particular, reflexivity should be tried before any
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1115
  of the fancy automated proof tools.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1116
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1117
  It may even happen that due to simplification the subgoal is no
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1118
  longer an equality.  For example, @{text "False \<longleftrightarrow> ?Q"} could be
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1119
  rewritten to @{text "\<not> ?Q"}.  To cover this case, the solver could
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1120
  try resolving with the theorem @{text "\<not> False"} of the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1121
  object-logic.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1122
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1123
  \medskip
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1124
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1125
  \begin{warn}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1126
  If a premise of a congruence rule cannot be proved, then the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1127
  congruence is ignored.  This should only happen if the rule is
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1128
  \emph{conditional} --- that is, contains premises not of the form
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1129
  @{text "t = ?x"}.  Otherwise it indicates that some congruence rule,
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1130
  or possibly the subgoaler or solver, is faulty.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1131
  \end{warn}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1132
*}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1133
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1134
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1135
subsubsection {* The looper *}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1136
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1137
text {*
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1138
  \begin{mldecls}
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1139
  @{index_ML_op setloop: "Proof.context *
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1140
  (Proof.context -> int -> tactic) -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1141
  @{index_ML_op addloop: "Proof.context *
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1142
  (string * (Proof.context -> int -> tactic))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1143
  -> Proof.context"} \\
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1144
  @{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
  1145
  @{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
  1146
  @{index_ML Splitter.del_split: "thm -> Proof.context -> Proof.context"} \\
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1147
  \end{mldecls}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1148
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1149
  The looper is a list of tactics that are applied after
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1150
  simplification, in case the solver failed to solve the simplified
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1151
  goal.  If the looper succeeds, the simplification process is started
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1152
  all over again.  Each of the subgoals generated by the looper is
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1153
  attacked in turn, in reverse order.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1154
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1155
  A typical looper is \emph{case splitting}: the expansion of a
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1156
  conditional.  Another possibility is to apply an elimination rule on
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1157
  the assumptions.  More adventurous loopers could start an induction.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1158
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1159
  \begin{description}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1160
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1161
  \item @{text "ctxt setloop tac"} installs @{text "tac"} as the only
52037
837211662fb8 tuned signature -- depend on context by default;
wenzelm
parents: 51717
diff changeset
  1162
  looper tactic of @{text "ctxt"}.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1163
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1164
  \item @{text "ctxt addloop (name, tac)"} adds @{text "tac"} as an
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1165
  additional looper tactic with name @{text "name"}, which is
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1166
  significant for managing the collection of loopers.  The tactic will
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1167
  be tried after the looper tactics that had already been present in
52037
837211662fb8 tuned signature -- depend on context by default;
wenzelm
parents: 51717
diff changeset
  1168
  @{text "ctxt"}.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1169
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1170
  \item @{text "ctxt delloop name"} deletes the looper tactic that was
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1171
  associated with @{text "name"} from @{text "ctxt"}.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1172
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1173
  \item @{ML Splitter.add_split}~@{text "thm ctxt"} adds split tactics
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1174
  for @{text "thm"} as additional looper tactics of @{text "ctxt"}.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1175
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1176
  \item @{ML Splitter.del_split}~@{text "thm ctxt"} deletes the split
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1177
  tactic corresponding to @{text thm} from the looper tactics of
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51703
diff changeset
  1178
  @{text "ctxt"}.
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1179
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1180
  \end{description}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1181
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1182
  The splitter replaces applications of a given function; the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1183
  right-hand side of the replacement can be anything.  For example,
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1184
  here is a splitting rule for conditional expressions:
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1185
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1186
  @{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
  1187
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1188
  Another example is the elimination operator for Cartesian products
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1189
  (which happens to be called @{text split} in Isabelle/HOL:
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1190
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1191
  @{text [display] "?P (split ?f ?p) \<longleftrightarrow> (\<forall>a b. ?p = (a, b) \<longrightarrow> ?P (f a b))"}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1192
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1193
  For technical reasons, there is a distinction between case splitting
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1194
  in the conclusion and in the premises of a subgoal.  The former is
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1195
  done by @{ML Splitter.split_tac} with rules like @{thm [source]
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1196
  split_if} or @{thm [source] option.split}, which do not split the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1197
  subgoal, while the latter is done by @{ML Splitter.split_asm_tac}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1198
  with rules like @{thm [source] split_if_asm} or @{thm [source]
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1199
  option.split_asm}, which split the subgoal.  The function @{ML
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1200
  Splitter.add_split} automatically takes care of which tactic to
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1201
  call, analyzing the form of the rules given as argument; it is the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1202
  same operation behind @{text "split"} attribute or method modifier
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1203
  syntax in the Isar source language.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1204
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1205
  Case splits should be allowed only when necessary; they are
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1206
  expensive and hard to control.  Case-splitting on if-expressions in
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1207
  the conclusion is usually beneficial, so it is enabled by default in
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1208
  Isabelle/HOL and Isabelle/FOL/ZF.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1209
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1210
  \begin{warn}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1211
  With @{ML Splitter.split_asm_tac} as looper component, the
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1212
  Simplifier may split subgoals!  This might cause unexpected problems
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1213
  in tactic expressions that silently assume 0 or 1 subgoals after
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1214
  simplification.
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1215
  \end{warn}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1216
*}
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1217
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1218
50063
7e491da6bcbd more on the Simplifier, based on old material;
wenzelm
parents: 48985
diff changeset
  1219
subsection {* Forward simplification \label{sec:simp-forward} *}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1220
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1221
text {*
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1222
  \begin{matharray}{rcl}
28761
9ec4482c9201 updated/refined types of Isar language elements, removed special LaTeX macros;
wenzelm
parents: 28760
diff changeset
  1223
    @{attribute_def simplified} & : & @{text attribute} \\
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1224
  \end{matharray}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1225
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1226
  @{rail \<open>
42596
6c621a9d612a modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents: 40291
diff changeset
  1227
    @@{attribute simplified} opt? @{syntax thmrefs}?
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1228
    ;
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1229
40255
9ffbc25e1606 eliminated obsolete \_ escapes in rail environments;
wenzelm
parents: 35613
diff changeset
  1230
    opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use') ')'
55112
b1a5d603fd12 prefer rail cartouche -- avoid back-slashed quotes;
wenzelm
parents: 55029
diff changeset
  1231
  \<close>}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1232
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1233
  \begin{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1234
  
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1235
  \item @{attribute simplified}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} causes a theorem to
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1236
  be simplified, either by exactly the specified rules @{text "a\<^sub>1, \<dots>,
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1237
  a\<^sub>n"}, or the implicit Simplifier context if no arguments are given.
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1238
  The result is fully simplified by default, including assumptions and
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1239
  conclusion; the options @{text no_asm} etc.\ tune the Simplifier in
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1240
  the same way as the for the @{text simp} method.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1241
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1242
  Note that forward simplification restricts the simplifier to its
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1243
  most basic operation of term rewriting; solver and looper tactics
50079
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1244
  (\secref{sec:simp-strategies}) are \emph{not} involved here.  The
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1245
  @{attribute simplified} attribute should be only rarely required
5c36db9db335 updated subgoaler/solver/looper;
wenzelm
parents: 50077
diff changeset
  1246
  under normal circumstances.
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1247
28760
cbc435f7b16b unified use of declaration environment with IsarImplementation;
wenzelm
parents: 28754
diff changeset
  1248
  \end{description}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1249
*}
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1250
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1251
27040
3d3e6e07b931 major reorganization of document structure;
wenzelm
parents: 26901
diff changeset
  1252
section {* The Classical Reasoner \label{sec:classical} *}
26782
19363c70b5c4 converted generic.tex to Thy/Generic.thy;
wenzelm
parents:
diff changeset
  1253
42930
41394a61cca9 updated and re-unified classical proof methods;
wenzelm
parents: 42929
diff changeset
  1254
subsection {* Basic concepts *}
42927
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1255
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1256
text {* Although Isabelle is generic, many users will be working in
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1257
  some extension of classical first-order logic.  Isabelle/ZF is built
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1258
  upon theory FOL, while Isabelle/HOL conceptually contains
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1259
  first-order logic as a fragment.  Theorem-proving in predicate logic
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1260
  is undecidable, but many automated strategies have been developed to
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1261
  assist in this task.
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1262
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1263
  Isabelle's classical reasoner is a generic package that accepts
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1264
  certain information about a logic and delivers a suite of automatic
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1265
  proof tools, based on rules that are classified and declared in the
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1266
  context.  These proof procedures are slow and simplistic compared
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1267
  with high-end automated theorem provers, but they can save
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1268
  considerable time and effort in practice.  They can prove theorems
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1269
  such as Pelletier's \cite{pelletier86} problems 40 and 41 in a few
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1270
  milliseconds (including full proof reconstruction): *}
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1271
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1272
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
  1273
  by blast
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
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
  1276
  by blast
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1277
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1278
text {* The proof tools are generic.  They are not restricted to
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1279
  first-order logic, and have been heavily used in the development of
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1280
  the Isabelle/HOL library and applications.  The tactics can be
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1281
  traced, and their components can be called directly; in this manner,
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1282
  any proof can be viewed interactively.  *}
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1283
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1284
c40adab7568e moved/updated introduction to Classical Reasoner;
wenzelm
parents: 42925
diff changeset
  1285
subsubsection {* The sequent calculus *}