doc-src/TutorialI/Advanced/document/simp.tex
author boehmes
Wed, 12 May 2010 23:54:00 +0200
changeset 36896 c030819254d3
parent 17187 45bee2f6e61f
child 40406 313a24b66a8d
permissions -rw-r--r--
use proper context operations (for fresh names of type and term variables, and for hypothetical definitions), monomorphize theorems (instead of terms, necessary for hypothetical definitions made during lambda lifting)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
     1
%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
     2
\begin{isabellebody}%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
     3
\def\isabellecontext{simp}%
17056
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
     4
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
     5
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
     6
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
     7
\endisadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
     8
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
     9
\isatagtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
    10
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
    11
\endisatagtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
    12
{\isafoldtheory}%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
    13
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
    14
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
    15
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
    16
\endisadelimtheory
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    17
%
10395
7ef380745743 updated;
wenzelm
parents: 10281
diff changeset
    18
\isamarkupsection{Simplification%
7ef380745743 updated;
wenzelm
parents: 10281
diff changeset
    19
}
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    20
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    21
%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    22
\begin{isamarkuptext}%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    23
\label{sec:simplification-II}\index{simplification|(}
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
    24
This section describes features not covered until now.  It also
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
    25
outlines the simplification process itself, which can be helpful
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
    26
when the simplifier does not do what you expect of it.%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    27
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    28
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    29
%
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
    30
\isamarkupsubsection{Advanced Features%
10395
7ef380745743 updated;
wenzelm
parents: 10281
diff changeset
    31
}
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    32
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    33
%
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
    34
\isamarkupsubsubsection{Congruence Rules%
10395
7ef380745743 updated;
wenzelm
parents: 10281
diff changeset
    35
}
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    36
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    37
%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    38
\begin{isamarkuptext}%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    39
\label{sec:simp-cong}
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
    40
While simplifying the conclusion $Q$
13191
05a9929ee10e *** empty log message ***
nipkow
parents: 11866
diff changeset
    41
of $P \Imp Q$, it is legal to use the assumption $P$.
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
    42
For $\Imp$ this policy is hardwired, but 
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
    43
contextual information can also be made available for other
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    44
operators. For example, \isa{xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymlongrightarrow}\ xs\ {\isacharat}\ xs\ {\isacharequal}\ xs} simplifies to \isa{True} because we may use \isa{xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}} when simplifying \isa{xs\ {\isacharat}\ xs\ {\isacharequal}\ xs}. The generation of contextual information during simplification is
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    45
controlled by so-called \bfindex{congruence rules}. This is the one for
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    46
\isa{{\isasymlongrightarrow}}:
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    47
\begin{isabelle}%
10696
76d7f6c9a14c *** empty log message ***
nipkow
parents: 10668
diff changeset
    48
\ \ \ \ \ {\isasymlbrakk}P\ {\isacharequal}\ P{\isacharprime}{\isacharsemicolon}\ P{\isacharprime}\ {\isasymLongrightarrow}\ Q\ {\isacharequal}\ Q{\isacharprime}{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharparenleft}P\ {\isasymlongrightarrow}\ Q{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}P{\isacharprime}\ {\isasymlongrightarrow}\ Q{\isacharprime}{\isacharparenright}%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    49
\end{isabelle}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    50
It should be read as follows:
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    51
In order to simplify \isa{P\ {\isasymlongrightarrow}\ Q} to \isa{P{\isacharprime}\ {\isasymlongrightarrow}\ Q{\isacharprime}},
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    52
simplify \isa{P} to \isa{P{\isacharprime}}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    53
and assume \isa{P{\isacharprime}} when simplifying \isa{Q} to \isa{Q{\isacharprime}}.
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    54
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    55
Here are some more examples.  The congruence rules for bounded
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    56
quantifiers supply contextual information about the bound variable:
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    57
\begin{isabelle}%
10696
76d7f6c9a14c *** empty log message ***
nipkow
parents: 10668
diff changeset
    58
\ \ \ \ \ {\isasymlbrakk}A\ {\isacharequal}\ B{\isacharsemicolon}\ {\isasymAnd}x{\isachardot}\ x\ {\isasymin}\ B\ {\isasymLongrightarrow}\ P\ x\ {\isacharequal}\ Q\ x{\isasymrbrakk}\isanewline
10950
aa788fcb75a5 updated;
wenzelm
parents: 10878
diff changeset
    59
\isaindent{\ \ \ \ \ }{\isasymLongrightarrow}\ {\isacharparenleft}{\isasymforall}x{\isasymin}A{\isachardot}\ P\ x{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}{\isasymforall}x{\isasymin}B{\isachardot}\ Q\ x{\isacharparenright}%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    60
\end{isabelle}
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
    61
One congruence rule for conditional expressions supplies contextual
11196
bb4ede27fcb7 *** empty log message ***
nipkow
parents: 10978
diff changeset
    62
information for simplifying the \isa{then} and \isa{else} cases:
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    63
\begin{isabelle}%
10696
76d7f6c9a14c *** empty log message ***
nipkow
parents: 10668
diff changeset
    64
\ \ \ \ \ {\isasymlbrakk}b\ {\isacharequal}\ c{\isacharsemicolon}\ c\ {\isasymLongrightarrow}\ x\ {\isacharequal}\ u{\isacharsemicolon}\ {\isasymnot}\ c\ {\isasymLongrightarrow}\ y\ {\isacharequal}\ v{\isasymrbrakk}\isanewline
10950
aa788fcb75a5 updated;
wenzelm
parents: 10878
diff changeset
    65
\isaindent{\ \ \ \ \ }{\isasymLongrightarrow}\ {\isacharparenleft}if\ b\ then\ x\ else\ y{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}if\ c\ then\ u\ else\ v{\isacharparenright}%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    66
\end{isabelle}
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
    67
An alternative congruence rule for conditional expressions
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
    68
actually \emph{prevents} simplification of some arguments:
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    69
\begin{isabelle}%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    70
\ \ \ \ \ b\ {\isacharequal}\ c\ {\isasymLongrightarrow}\ {\isacharparenleft}if\ b\ then\ x\ else\ y{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}if\ c\ then\ x\ else\ y{\isacharparenright}%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    71
\end{isabelle}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    72
Only the first argument is simplified; the others remain unchanged.
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    73
This makes simplification much faster and is faithful to the evaluation
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    74
strategy in programming languages, which is why this is the default
11196
bb4ede27fcb7 *** empty log message ***
nipkow
parents: 10978
diff changeset
    75
congruence rule for \isa{if}. Analogous rules control the evaluation of
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    76
\isa{case} expressions.
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    77
11458
09a6c44a48ea numerous stylistic changes and indexing
paulson
parents: 11216
diff changeset
    78
You can declare your own congruence rules with the attribute \attrdx{cong},
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    79
either globally, in the usual manner,
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    80
\begin{quote}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    81
\isacommand{declare} \textit{theorem-name} \isa{{\isacharbrackleft}cong{\isacharbrackright}}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    82
\end{quote}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    83
or locally in a \isa{simp} call by adding the modifier
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    84
\begin{quote}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    85
\isa{cong{\isacharcolon}} \textit{list of theorem names}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    86
\end{quote}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    87
The effect is reversed by \isa{cong\ del} instead of \isa{cong}.
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    88
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    89
\begin{warn}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    90
The congruence rule \isa{conj{\isacharunderscore}cong}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    91
\begin{isabelle}%
10696
76d7f6c9a14c *** empty log message ***
nipkow
parents: 10668
diff changeset
    92
\ \ \ \ \ {\isasymlbrakk}P\ {\isacharequal}\ P{\isacharprime}{\isacharsemicolon}\ P{\isacharprime}\ {\isasymLongrightarrow}\ Q\ {\isacharequal}\ Q{\isacharprime}{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharparenleft}P\ {\isasymand}\ Q{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}P{\isacharprime}\ {\isasymand}\ Q{\isacharprime}{\isacharparenright}%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    93
\end{isabelle}
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
    94
\par\noindent
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
    95
is occasionally useful but is not a default rule; you have to declare it explicitly.
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    96
\end{warn}%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    97
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    98
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
    99
%
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   100
\isamarkupsubsubsection{Permutative Rewrite Rules%
10395
7ef380745743 updated;
wenzelm
parents: 10281
diff changeset
   101
}
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
   102
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   103
%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   104
\begin{isamarkuptext}%
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   105
\index{rewrite rules!permutative|bold}%
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   106
An equation is a \textbf{permutative rewrite rule} if the left-hand
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   107
side and right-hand side are the same up to renaming of variables.  The most
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   108
common permutative rule is commutativity: \isa{x\ {\isacharplus}\ y\ {\isacharequal}\ y\ {\isacharplus}\ x}.  Other examples
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   109
include \isa{x\ {\isacharminus}\ y\ {\isacharminus}\ z\ {\isacharequal}\ x\ {\isacharminus}\ z\ {\isacharminus}\ y} in arithmetic and \isa{insert\ x\ {\isacharparenleft}insert\ y\ A{\isacharparenright}\ {\isacharequal}\ insert\ y\ {\isacharparenleft}insert\ x\ A{\isacharparenright}} for sets. Such rules are problematic because
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   110
once they apply, they can be used forever. The simplifier is aware of this
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   111
danger and treats permutative rules by means of a special strategy, called
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   112
\bfindex{ordered rewriting}: a permutative rewrite
10978
5eebea8f359f *** empty log message ***
nipkow
parents: 10950
diff changeset
   113
rule is only applied if the term becomes smaller with respect to a fixed
5eebea8f359f *** empty log message ***
nipkow
parents: 10950
diff changeset
   114
lexicographic ordering on terms. For example, commutativity rewrites
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   115
\isa{b\ {\isacharplus}\ a} to \isa{a\ {\isacharplus}\ b}, but then stops because \isa{a\ {\isacharplus}\ b} is strictly
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   116
smaller than \isa{b\ {\isacharplus}\ a}.  Permutative rewrite rules can be turned into
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   117
simplification rules in the usual manner via the \isa{simp} attribute; the
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   118
simplifier recognizes their special status automatically.
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   119
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   120
Permutative rewrite rules are most effective in the case of
10281
9554ce1c2e54 *** empty log message ***
nipkow
parents: 10186
diff changeset
   121
associative-commutative functions.  (Associativity by itself is not
9554ce1c2e54 *** empty log message ***
nipkow
parents: 10186
diff changeset
   122
permutative.)  When dealing with an AC-function~$f$, keep the
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   123
following points in mind:
10281
9554ce1c2e54 *** empty log message ***
nipkow
parents: 10186
diff changeset
   124
\begin{itemize}\index{associative-commutative function}
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   125
  
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   126
\item The associative law must always be oriented from left to right,
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   127
  namely $f(f(x,y),z) = f(x,f(y,z))$.  The opposite orientation, if
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   128
  used with commutativity, can lead to nontermination.
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   129
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   130
\item To complete your set of rewrite rules, you must add not just
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   131
  associativity~(A) and commutativity~(C) but also a derived rule, {\bf
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   132
    left-com\-mut\-ativ\-ity} (LC): $f(x,f(y,z)) = f(y,f(x,z))$.
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   133
\end{itemize}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   134
Ordered rewriting with the combination of A, C, and LC sorts a term
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   135
lexicographically:
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   136
\[\def\maps#1{~\stackrel{#1}{\leadsto}~}
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   137
 f(f(b,c),a) \maps{A} f(b,f(c,a)) \maps{C} f(b,f(a,c)) \maps{LC} f(a,f(b,c)) \]
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   138
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   139
Note that ordered rewriting for \isa{{\isacharplus}} and \isa{{\isacharasterisk}} on numbers is rarely
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   140
necessary because the built-in arithmetic prover often succeeds without
11196
bb4ede27fcb7 *** empty log message ***
nipkow
parents: 10978
diff changeset
   141
such tricks.%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   142
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
   143
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   144
%
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   145
\isamarkupsubsection{How the Simplifier Works%
10395
7ef380745743 updated;
wenzelm
parents: 10281
diff changeset
   146
}
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
   147
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   148
%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   149
\begin{isamarkuptext}%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   150
\label{sec:SimpHow}
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   151
Roughly speaking, the simplifier proceeds bottom-up: subterms are simplified
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   152
first.  A conditional equation is only applied if its condition can be
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   153
proved, again by simplification.  Below we explain some special features of
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   154
the rewriting process.%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   155
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
   156
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   157
%
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   158
\isamarkupsubsubsection{Higher-Order Patterns%
10395
7ef380745743 updated;
wenzelm
parents: 10281
diff changeset
   159
}
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
   160
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   161
%
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   162
\begin{isamarkuptext}%
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   163
\index{simplification rule|(}
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   164
So far we have pretended the simplifier can deal with arbitrary
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   165
rewrite rules. This is not quite true.  For reasons of feasibility,
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   166
the simplifier expects the
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   167
left-hand side of each rule to be a so-called \emph{higher-order
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   168
pattern}~\cite{nipkow-patterns}\indexbold{patterns!higher-order}. 
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   169
This restricts where
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   170
unknowns may occur.  Higher-order patterns are terms in $\beta$-normal
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   171
form.  (This means there are no subterms of the form $(\lambda x. M)(N)$.)  
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   172
Each occurrence of an unknown is of the form
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   173
$\Var{f}~x@1~\dots~x@n$, where the $x@i$ are distinct bound
10978
5eebea8f359f *** empty log message ***
nipkow
parents: 10950
diff changeset
   174
variables. Thus all ordinary rewrite rules, where all unknowns are
14270
342451d763f9 More re-organising of numerical theorems
paulson
parents: 13778
diff changeset
   175
of base type, for example \isa{{\isacharquery}a\ {\isacharplus}\ {\isacharquery}b\ {\isacharplus}\ {\isacharquery}c\ {\isacharequal}\ {\isacharquery}a\ {\isacharplus}\ {\isacharparenleft}{\isacharquery}b\ {\isacharplus}\ {\isacharquery}c{\isacharparenright}}, are acceptable: if an unknown is
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   176
of base type, it cannot have any arguments. Additionally, the rule
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   177
\isa{{\isacharparenleft}{\isasymforall}x{\isachardot}\ {\isacharquery}P\ x\ {\isasymand}\ {\isacharquery}Q\ x{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}{\isacharparenleft}{\isasymforall}x{\isachardot}\ {\isacharquery}P\ x{\isacharparenright}\ {\isasymand}\ {\isacharparenleft}{\isasymforall}x{\isachardot}\ {\isacharquery}Q\ x{\isacharparenright}{\isacharparenright}} is also acceptable, in
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   178
both directions: all arguments of the unknowns \isa{{\isacharquery}P} and
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   179
\isa{{\isacharquery}Q} are distinct bound variables.
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   180
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   181
If the left-hand side is not a higher-order pattern, all is not lost.
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   182
The simplifier will still try to apply the rule provided it
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   183
matches directly: without much $\lambda$-calculus hocus
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   184
pocus.  For example, \isa{{\isacharparenleft}{\isacharquery}f\ {\isacharquery}x\ {\isasymin}\ range\ {\isacharquery}f{\isacharparenright}\ {\isacharequal}\ True} rewrites
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   185
\isa{g\ a\ {\isasymin}\ range\ g} to \isa{True}, but will fail to match
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   186
\isa{g{\isacharparenleft}h\ b{\isacharparenright}\ {\isasymin}\ range{\isacharparenleft}{\isasymlambda}x{\isachardot}\ g{\isacharparenleft}h\ x{\isacharparenright}{\isacharparenright}}.  However, you can
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   187
eliminate the offending subterms --- those that are not patterns ---
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   188
by adding new variables and conditions.
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   189
In our example, we eliminate \isa{{\isacharquery}f\ {\isacharquery}x} and obtain
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   190
 \isa{{\isacharquery}y\ {\isacharequal}\ {\isacharquery}f\ {\isacharquery}x\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isacharquery}y\ {\isasymin}\ range\ {\isacharquery}f{\isacharparenright}\ {\isacharequal}\ True}, which is fine
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   191
as a conditional rewrite rule since conditions can be arbitrary
11494
23a118849801 revisions and indexing
paulson
parents: 11458
diff changeset
   192
terms.  However, this trick is not a panacea because the newly
11196
bb4ede27fcb7 *** empty log message ***
nipkow
parents: 10978
diff changeset
   193
introduced conditions may be hard to solve.
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   194
  
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   195
There is no restriction on the form of the right-hand
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   196
sides.  They may not contain extraneous term or type variables, though.%
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   197
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
   198
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   199
%
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   200
\isamarkupsubsubsection{The Preprocessor%
10395
7ef380745743 updated;
wenzelm
parents: 10281
diff changeset
   201
}
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
   202
\isamarkuptrue%
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   203
%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   204
\begin{isamarkuptext}%
10845
3696bc935bbd *** empty log message ***
nipkow
parents: 10795
diff changeset
   205
\label{sec:simp-preprocessor}
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   206
When a theorem is declared a simplification rule, it need not be a
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   207
conditional equation already.  The simplifier will turn it into a set of
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   208
conditional equations automatically.  For example, \isa{f\ x\ {\isacharequal}\ g\ x\ {\isasymand}\ h\ x\ {\isacharequal}\ k\ x} becomes the two separate
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   209
simplification rules \isa{f\ x\ {\isacharequal}\ g\ x} and \isa{h\ x\ {\isacharequal}\ k\ x}. In
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   210
general, the input theorem is converted as follows:
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   211
\begin{eqnarray}
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   212
\neg P &\mapsto& P = \hbox{\isa{False}} \nonumber\\
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   213
P \longrightarrow Q &\mapsto& P \Longrightarrow Q \nonumber\\
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   214
P \land Q &\mapsto& P,\ Q \nonumber\\
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   215
\forall x.~P~x &\mapsto& P~\Var{x}\nonumber\\
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   216
\forall x \in A.\ P~x &\mapsto& \Var{x} \in A \Longrightarrow P~\Var{x} \nonumber\\
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   217
\isa{if}\ P\ \isa{then}\ Q\ \isa{else}\ R &\mapsto&
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   218
 P \Longrightarrow Q,\ \neg P \Longrightarrow R \nonumber
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   219
\end{eqnarray}
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   220
Once this conversion process is finished, all remaining non-equations
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   221
$P$ are turned into trivial equations $P =\isa{True}$.
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   222
For example, the formula 
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   223
\begin{center}\isa{{\isacharparenleft}p\ {\isasymlongrightarrow}\ t\ {\isacharequal}\ u\ {\isasymand}\ {\isasymnot}\ r{\isacharparenright}\ {\isasymand}\ s}\end{center}
10845
3696bc935bbd *** empty log message ***
nipkow
parents: 10795
diff changeset
   224
is converted into the three rules
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   225
\begin{center}
10878
b254d5ad6dd4 auto update
paulson
parents: 10845
diff changeset
   226
\isa{p\ {\isasymLongrightarrow}\ t\ {\isacharequal}\ u},\quad  \isa{p\ {\isasymLongrightarrow}\ r\ {\isacharequal}\ False},\quad  \isa{s\ {\isacharequal}\ True}.
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   227
\end{center}
499637e8f2c6 *** empty log message ***
nipkow
parents: 9993
diff changeset
   228
\index{simplification rule|)}
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   229
\index{simplification|)}%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   230
\end{isamarkuptext}%
17175
1eced27ee0e1 updated;
wenzelm
parents: 17056
diff changeset
   231
\isamarkuptrue%
17056
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   232
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   233
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   234
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   235
\endisadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   236
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   237
\isatagtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   238
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   239
\endisatagtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   240
{\isafoldtheory}%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   241
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   242
\isadelimtheory
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   243
%
05fc32a23b8b updated;
wenzelm
parents: 14270
diff changeset
   244
\endisadelimtheory
9993
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   245
\end{isabellebody}%
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   246
%%% Local Variables:
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   247
%%% mode: latex
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   248
%%% TeX-master: "root"
c0f7fb6e538e *** empty log message ***
nipkow
parents:
diff changeset
   249
%%% End: