doc-src/TutorialI/Inductive/document/AB.tex
author paulson
Wed, 18 May 2005 10:23:47 +0200
changeset 15997 c71031d7988c
parent 15481 fc075ae929e4
child 16069 3f2a9f400168
permissions -rw-r--r--
consolidation and simplification
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10217
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
     1
%
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
     2
\begin{isabellebody}%
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
     3
\def\isabellecontext{AB}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
     4
\isamarkupfalse%
10225
b9fd52525b69 *** empty log message ***
nipkow
parents: 10217
diff changeset
     5
%
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
     6
\isamarkupsection{Case Study: A Context Free Grammar%
10395
7ef380745743 updated;
wenzelm
parents: 10299
diff changeset
     7
}
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
     8
\isamarkuptrue%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
     9
%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    10
\begin{isamarkuptext}%
10242
028f54cd2cc9 *** empty log message ***
nipkow
parents: 10237
diff changeset
    11
\label{sec:CFG}
11494
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
    12
\index{grammars!defining inductively|(}%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    13
Grammars are nothing but shorthands for inductive definitions of nonterminals
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    14
which represent sets of strings. For example, the production
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    15
$A \to B c$ is short for
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    16
\[ w \in B \Longrightarrow wc \in A \]
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    17
This section demonstrates this idea with an example
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    18
due to Hopcroft and Ullman, a grammar for generating all words with an
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    19
equal number of $a$'s and~$b$'s:
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    20
\begin{eqnarray}
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    21
S &\to& \epsilon \mid b A \mid a B \nonumber\\
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    22
A &\to& a S \mid b A A \nonumber\\
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    23
B &\to& b S \mid a B B \nonumber
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    24
\end{eqnarray}
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    25
At the end we say a few words about the relationship between
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    26
the original proof \cite[p.\ts81]{HopcroftUllman} and our formal version.
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    27
10299
8627da9246da auto gen
paulson
parents: 10283
diff changeset
    28
We start by fixing the alphabet, which consists only of \isa{a}'s
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    29
and~\isa{b}'s:%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    30
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    31
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    32
\isacommand{datatype}\ alfa\ {\isacharequal}\ a\ {\isacharbar}\ b\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    33
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    34
\begin{isamarkuptext}%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    35
\noindent
10299
8627da9246da auto gen
paulson
parents: 10283
diff changeset
    36
For convenience we include the following easy lemmas as simplification rules:%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    37
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    38
\isamarkuptrue%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    39
\isacommand{lemma}\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x\ {\isasymnoteq}\ a{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}x\ {\isacharequal}\ b{\isacharparenright}\ {\isasymand}\ {\isacharparenleft}x\ {\isasymnoteq}\ b{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}x\ {\isacharequal}\ a{\isacharparenright}{\isachardoublequote}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    40
\isamarkupfalse%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
    41
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    42
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    43
\begin{isamarkuptext}%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    44
\noindent
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    45
Words over this alphabet are of type \isa{alfa\ list}, and
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    46
the three nonterminals are declared as sets of such words:%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    47
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    48
\isamarkuptrue%
10217
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
    49
\isacommand{consts}\ S\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}alfa\ list\ set{\isachardoublequote}\isanewline
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
    50
\ \ \ \ \ \ \ A\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}alfa\ list\ set{\isachardoublequote}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    51
\ \ \ \ \ \ \ B\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}alfa\ list\ set{\isachardoublequote}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    52
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    53
\begin{isamarkuptext}%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    54
\noindent
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    55
The productions above are recast as a \emph{mutual} inductive
10242
028f54cd2cc9 *** empty log message ***
nipkow
parents: 10237
diff changeset
    56
definition\index{inductive definition!simultaneous}
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    57
of \isa{S}, \isa{A} and~\isa{B}:%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    58
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    59
\isamarkuptrue%
10217
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
    60
\isacommand{inductive}\ S\ A\ B\isanewline
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
    61
\isakeyword{intros}\isanewline
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    62
\ \ {\isachardoublequote}{\isacharbrackleft}{\isacharbrackright}\ {\isasymin}\ S{\isachardoublequote}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    63
\ \ {\isachardoublequote}w\ {\isasymin}\ A\ {\isasymLongrightarrow}\ b{\isacharhash}w\ {\isasymin}\ S{\isachardoublequote}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    64
\ \ {\isachardoublequote}w\ {\isasymin}\ B\ {\isasymLongrightarrow}\ a{\isacharhash}w\ {\isasymin}\ S{\isachardoublequote}\isanewline
10217
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
    65
\isanewline
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    66
\ \ {\isachardoublequote}w\ {\isasymin}\ S\ \ \ \ \ \ \ \ {\isasymLongrightarrow}\ a{\isacharhash}w\ \ \ {\isasymin}\ A{\isachardoublequote}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    67
\ \ {\isachardoublequote}{\isasymlbrakk}\ v{\isasymin}A{\isacharsemicolon}\ w{\isasymin}A\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ b{\isacharhash}v{\isacharat}w\ {\isasymin}\ A{\isachardoublequote}\isanewline
10217
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
    68
\isanewline
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    69
\ \ {\isachardoublequote}w\ {\isasymin}\ S\ \ \ \ \ \ \ \ \ \ \ \ {\isasymLongrightarrow}\ b{\isacharhash}w\ \ \ {\isasymin}\ B{\isachardoublequote}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    70
\ \ {\isachardoublequote}{\isasymlbrakk}\ v\ {\isasymin}\ B{\isacharsemicolon}\ w\ {\isasymin}\ B\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ a{\isacharhash}v{\isacharat}w\ {\isasymin}\ B{\isachardoublequote}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    71
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    72
\begin{isamarkuptext}%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    73
\noindent
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    74
First we show that all words in \isa{S} contain the same number of \isa{a}'s and \isa{b}'s. Since the definition of \isa{S} is by mutual
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    75
induction, so is the proof: we show at the same time that all words in
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    76
\isa{A} contain one more \isa{a} than \isa{b} and all words in \isa{B} contains one more \isa{b} than \isa{a}.%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    77
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    78
\isamarkuptrue%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    79
\isacommand{lemma}\ correctness{\isacharcolon}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    80
\ \ {\isachardoublequote}{\isacharparenleft}w\ {\isasymin}\ S\ {\isasymlongrightarrow}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}{\isacharparenright}\ \ \ \ \ {\isasymand}\isanewline
10237
875bf54b5d74 *** empty log message ***
nipkow
parents: 10236
diff changeset
    81
\ \ \ {\isacharparenleft}w\ {\isasymin}\ A\ {\isasymlongrightarrow}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}{\isacharparenright}\ {\isasymand}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    82
\ \ \ {\isacharparenleft}w\ {\isasymin}\ B\ {\isasymlongrightarrow}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    83
\isamarkuptrue%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
    84
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
    85
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    86
\begin{isamarkuptext}%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    87
\noindent
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    88
This may seem surprising at first, and is indeed an indication of the power
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    89
of inductive definitions. But it is also quite straightforward. For example,
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    90
consider the production $A \to b A A$: if $v,w \in A$ and the elements of $A$
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    91
contain one more $a$ than~$b$'s, then $bvw$ must again contain one more $a$
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    92
than~$b$'s.
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    93
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    94
As usual, the correctness of syntactic descriptions is easy, but completeness
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    95
is hard: does \isa{S} contain \emph{all} words with an equal number of
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    96
\isa{a}'s and \isa{b}'s? It turns out that this proof requires the
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
    97
following lemma: every string with two more \isa{a}'s than \isa{b}'s can be cut somewhere such that each half has one more \isa{a} than
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
    98
\isa{b}. This is best seen by imagining counting the difference between the
10283
ff003e2b790c *** empty log message ***
nipkow
parents: 10242
diff changeset
    99
number of \isa{a}'s and \isa{b}'s starting at the left end of the
ff003e2b790c *** empty log message ***
nipkow
parents: 10242
diff changeset
   100
word. We start with 0 and end (at the right end) with 2. Since each move to the
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   101
right increases or decreases the difference by 1, we must have passed through
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   102
1 on our way from 0 to 2. Formally, we appeal to the following discrete
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   103
intermediate value theorem \isa{nat{\isadigit{0}}{\isacharunderscore}intermed{\isacharunderscore}int{\isacharunderscore}val}
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   104
\begin{isabelle}%
14379
ea10a8c3e9cf updated links to the old ftp site
paulson
parents: 13791
diff changeset
   105
\ \ \ \ \ {\isasymlbrakk}{\isasymforall}i{\isacharless}n{\isachardot}\ {\isasymbar}f\ {\isacharparenleft}i\ {\isacharplus}\ {\isadigit{1}}{\isacharparenright}\ {\isacharminus}\ f\ i{\isasymbar}\ {\isasymle}\ {\isadigit{1}}{\isacharsemicolon}\ f\ {\isadigit{0}}\ {\isasymle}\ k{\isacharsemicolon}\ k\ {\isasymle}\ f\ n{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isasymexists}i{\isasymle}n{\isachardot}\ f\ i\ {\isacharequal}\ k%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   106
\end{isabelle}
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   107
where \isa{f} is of type \isa{nat\ {\isasymRightarrow}\ int}, \isa{int} are the integers,
11308
b28bbb153603 *** empty log message ***
nipkow
parents: 11257
diff changeset
   108
\isa{{\isasymbar}{\isachardot}{\isasymbar}} is the absolute value function\footnote{See
b28bbb153603 *** empty log message ***
nipkow
parents: 11257
diff changeset
   109
Table~\ref{tab:ascii} in the Appendix for the correct \textsc{ascii}
11708
d27253c4594f *** empty log message ***
wenzelm
parents: 11494
diff changeset
   110
syntax.}, and \isa{{\isadigit{1}}} is the integer 1 (see \S\ref{sec:numbers}).
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   111
11147
d848c6693185 *** empty log message ***
nipkow
parents: 10950
diff changeset
   112
First we show that our specific function, the difference between the
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   113
numbers of \isa{a}'s and \isa{b}'s, does indeed only change by 1 in every
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   114
move to the right. At this point we also start generalizing from \isa{a}'s
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   115
and \isa{b}'s to an arbitrary property \isa{P}. Otherwise we would have
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   116
to prove the desired lemma twice, once as stated above and once with the
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   117
roles of \isa{a}'s and \isa{b}'s interchanged.%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   118
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   119
\isamarkuptrue%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   120
\isacommand{lemma}\ step{\isadigit{1}}{\isacharcolon}\ {\isachardoublequote}{\isasymforall}i\ {\isacharless}\ size\ w{\isachardot}\isanewline
10608
620647438780 *** empty log message ***
nipkow
parents: 10601
diff changeset
   121
\ \ {\isasymbar}{\isacharparenleft}int{\isacharparenleft}size{\isacharbrackleft}x{\isasymin}take\ {\isacharparenleft}i{\isacharplus}{\isadigit{1}}{\isacharparenright}\ w{\isachardot}\ P\ x{\isacharbrackright}{\isacharparenright}{\isacharminus}int{\isacharparenleft}size{\isacharbrackleft}x{\isasymin}take\ {\isacharparenleft}i{\isacharplus}{\isadigit{1}}{\isacharparenright}\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharparenright}{\isacharparenright}\isanewline
11870
181bd2050cf4 Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11866
diff changeset
   122
\ \ \ {\isacharminus}\ {\isacharparenleft}int{\isacharparenleft}size{\isacharbrackleft}x{\isasymin}take\ i\ w{\isachardot}\ P\ x{\isacharbrackright}{\isacharparenright}{\isacharminus}int{\isacharparenleft}size{\isacharbrackleft}x{\isasymin}take\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharparenright}{\isacharparenright}{\isasymbar}\ {\isasymle}\ {\isadigit{1}}{\isachardoublequote}\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   123
\isamarkuptrue%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   124
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   125
\isamarkupfalse%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   126
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   127
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   128
\begin{isamarkuptext}%
11494
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
   129
Finally we come to the above-mentioned lemma about cutting in half a word with two more elements of one sort than of the other sort:%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   130
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   131
\isamarkuptrue%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   132
\isacommand{lemma}\ part{\isadigit{1}}{\isacharcolon}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   133
\ {\isachardoublequote}size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{2}}\ {\isasymLongrightarrow}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   134
\ \ {\isasymexists}i{\isasymle}size\ w{\isachardot}\ size{\isacharbrackleft}x{\isasymin}take\ i\ w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}take\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{1}}{\isachardoublequote}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   135
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   136
\isamarkupfalse%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   137
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   138
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   139
\begin{isamarkuptext}%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   140
\noindent
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   141
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   142
Lemma \isa{part{\isadigit{1}}} tells us only about the prefix \isa{take\ i\ w}.
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
   143
An easy lemma deals with the suffix \isa{drop\ i\ w}:%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   144
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   145
\isamarkuptrue%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   146
\isacommand{lemma}\ part{\isadigit{2}}{\isacharcolon}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   147
\ \ {\isachardoublequote}{\isasymlbrakk}size{\isacharbrackleft}x{\isasymin}take\ i\ w\ {\isacharat}\ drop\ i\ w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   148
\ \ \ \ size{\isacharbrackleft}x{\isasymin}take\ i\ w\ {\isacharat}\ drop\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{2}}{\isacharsemicolon}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   149
\ \ \ \ size{\isacharbrackleft}x{\isasymin}take\ i\ w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}take\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{1}}{\isasymrbrakk}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   150
\ \ \ {\isasymLongrightarrow}\ size{\isacharbrackleft}x{\isasymin}drop\ i\ w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}drop\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{1}}{\isachardoublequote}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   151
\isamarkupfalse%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   152
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   153
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   154
\begin{isamarkuptext}%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   155
\noindent
11257
622331bbdb7f *** empty log message ***
nipkow
parents: 11158
diff changeset
   156
In the proof we have disabled the normally useful lemma
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
   157
\begin{isabelle}
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
   158
\isa{take\ n\ xs\ {\isacharat}\ drop\ n\ xs\ {\isacharequal}\ xs}
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
   159
\rulename{append_take_drop_id}
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
   160
\end{isabelle}
11257
622331bbdb7f *** empty log message ***
nipkow
parents: 11158
diff changeset
   161
to allow the simplifier to apply the following lemma instead:
622331bbdb7f *** empty log message ***
nipkow
parents: 11158
diff changeset
   162
\begin{isabelle}%
622331bbdb7f *** empty log message ***
nipkow
parents: 11158
diff changeset
   163
\ \ \ \ \ {\isacharbrackleft}x{\isasymin}xs{\isacharat}ys{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\ {\isacharbrackleft}x{\isasymin}xs{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharat}\ {\isacharbrackleft}x{\isasymin}ys{\isachardot}\ P\ x{\isacharbrackright}%
622331bbdb7f *** empty log message ***
nipkow
parents: 11158
diff changeset
   164
\end{isabelle}
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   165
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   166
To dispose of trivial cases automatically, the rules of the inductive
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   167
definition are declared simplification rules:%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   168
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   169
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   170
\isacommand{declare}\ S{\isacharunderscore}A{\isacharunderscore}B{\isachardot}intros{\isacharbrackleft}simp{\isacharbrackright}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   171
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   172
\begin{isamarkuptext}%
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   173
\noindent
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   174
This could have been done earlier but was not necessary so far.
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   175
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   176
The completeness theorem tells us that if a word has the same number of
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
   177
\isa{a}'s and \isa{b}'s, then it is in \isa{S}, and similarly 
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
   178
for \isa{A} and \isa{B}:%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   179
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   180
\isamarkuptrue%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   181
\isacommand{theorem}\ completeness{\isacharcolon}\isanewline
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   182
\ \ {\isachardoublequote}{\isacharparenleft}size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ \ \ \ \ {\isasymlongrightarrow}\ w\ {\isasymin}\ S{\isacharparenright}\ {\isasymand}\isanewline
10237
875bf54b5d74 *** empty log message ***
nipkow
parents: 10236
diff changeset
   183
\ \ \ {\isacharparenleft}size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}\ {\isasymlongrightarrow}\ w\ {\isasymin}\ A{\isacharparenright}\ {\isasymand}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   184
\ \ \ {\isacharparenleft}size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymin}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}\ {\isasymlongrightarrow}\ w\ {\isasymin}\ B{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   185
\isamarkuptrue%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   186
\isamarkupfalse%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   187
\isamarkupfalse%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   188
\isamarkuptrue%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   189
\isamarkupfalse%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   190
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   191
\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   192
\isamarkuptrue%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   193
\isamarkupfalse%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   194
\isamarkupfalse%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   195
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   196
\isamarkupfalse%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   197
\isamarkuptrue%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   198
\isamarkupfalse%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   199
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   200
\isamarkuptrue%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   201
\isamarkupfalse%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   202
\isamarkuptrue%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   203
\isamarkupfalse%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   204
\isamarkuptrue%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   205
\isamarkupfalse%
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   206
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   207
\isamarkuptrue%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   208
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   209
\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   210
\isamarkupfalse%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   211
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   212
\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   213
\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   214
\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   215
\isamarkupfalse%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 14379
diff changeset
   216
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   217
%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   218
\begin{isamarkuptext}%
10878
b254d5ad6dd4 auto update
paulson
parents: 10696
diff changeset
   219
We conclude this section with a comparison of our proof with 
11494
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
   220
Hopcroft\index{Hopcroft, J. E.} and Ullman's\index{Ullman, J. D.}
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
   221
\cite[p.\ts81]{HopcroftUllman}.
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
   222
For a start, the textbook
11257
622331bbdb7f *** empty log message ***
nipkow
parents: 11158
diff changeset
   223
grammar, for no good reason, excludes the empty word, thus complicating
622331bbdb7f *** empty log message ***
nipkow
parents: 11158
diff changeset
   224
matters just a little bit: they have 8 instead of our 7 productions.
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   225
11158
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   226
More importantly, the proof itself is different: rather than
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   227
separating the two directions, they perform one induction on the
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   228
length of a word. This deprives them of the beauty of rule induction,
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   229
and in the easy direction (correctness) their reasoning is more
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   230
detailed than our \isa{auto}. For the hard part (completeness), they
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   231
consider just one of the cases that our \isa{simp{\isacharunderscore}all} disposes of
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   232
automatically. Then they conclude the proof by saying about the
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   233
remaining cases: ``We do this in a manner similar to our method of
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   234
proof for part (1); this part is left to the reader''. But this is
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   235
precisely the part that requires the intermediate value theorem and
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   236
thus is not at all similar to the other cases (which are automatic in
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   237
Isabelle). The authors are at least cavalier about this point and may
5652018b809a *** empty log message ***
nipkow
parents: 11147
diff changeset
   238
even have overlooked the slight difficulty lurking in the omitted
11494
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
   239
cases.  Such errors are found in many pen-and-paper proofs when they
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
   240
are scrutinized formally.%
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
   241
\index{grammars!defining inductively|)}%
10236
7626cb4e1407 *** empty log message ***
nipkow
parents: 10225
diff changeset
   242
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   243
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11708
diff changeset
   244
\isamarkupfalse%
10217
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
   245
\end{isabellebody}%
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
   246
%%% Local Variables:
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
   247
%%% mode: latex
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
   248
%%% TeX-master: "root"
e61e7e1eacaf *** empty log message ***
nipkow
parents:
diff changeset
   249
%%% End: