| 
10217
 | 
     1  | 
%
  | 
| 
 | 
     2  | 
\begin{isabellebody}%
 | 
| 
 | 
     3  | 
\def\isabellecontext{AB}%
 | 
| 
17056
 | 
     4  | 
%
  | 
| 
 | 
     5  | 
\isadelimtheory
  | 
| 
 | 
     6  | 
%
  | 
| 
 | 
     7  | 
\endisadelimtheory
  | 
| 
 | 
     8  | 
%
  | 
| 
 | 
     9  | 
\isatagtheory
  | 
| 
 | 
    10  | 
%
  | 
| 
 | 
    11  | 
\endisatagtheory
  | 
| 
 | 
    12  | 
{\isafoldtheory}%
 | 
| 
 | 
    13  | 
%
  | 
| 
 | 
    14  | 
\isadelimtheory
  | 
| 
 | 
    15  | 
%
  | 
| 
 | 
    16  | 
\endisadelimtheory
  | 
| 
10225
 | 
    17  | 
%
  | 
| 
10878
 | 
    18  | 
\isamarkupsection{Case Study: A Context Free Grammar%
 | 
| 
10395
 | 
    19  | 
}
  | 
| 
11866
 | 
    20  | 
\isamarkuptrue%
  | 
| 
10236
 | 
    21  | 
%
  | 
| 
 | 
    22  | 
\begin{isamarkuptext}%
 | 
| 
10242
 | 
    23  | 
\label{sec:CFG}
 | 
| 
11494
 | 
    24  | 
\index{grammars!defining inductively|(}%
 | 
| 
10236
 | 
    25  | 
Grammars are nothing but shorthands for inductive definitions of nonterminals
  | 
| 
 | 
    26  | 
which represent sets of strings. For example, the production
  | 
| 
 | 
    27  | 
$A \to B c$ is short for
  | 
| 
 | 
    28  | 
\[ w \in B \Longrightarrow wc \in A \]
  | 
| 
10878
 | 
    29  | 
This section demonstrates this idea with an example
  | 
| 
 | 
    30  | 
due to Hopcroft and Ullman, a grammar for generating all words with an
  | 
| 
 | 
    31  | 
equal number of $a$'s and~$b$'s:
  | 
| 
10236
 | 
    32  | 
\begin{eqnarray}
 | 
| 
 | 
    33  | 
S &\to& \epsilon \mid b A \mid a B \nonumber\\
  | 
| 
 | 
    34  | 
A &\to& a S \mid b A A \nonumber\\
  | 
| 
 | 
    35  | 
B &\to& b S \mid a B B \nonumber
  | 
| 
 | 
    36  | 
\end{eqnarray}
 | 
| 
10878
 | 
    37  | 
At the end we say a few words about the relationship between
  | 
| 
 | 
    38  | 
the original proof \cite[p.\ts81]{HopcroftUllman} and our formal version.
 | 
| 
10236
 | 
    39  | 
  | 
| 
10299
 | 
    40  | 
We start by fixing the alphabet, which consists only of \isa{a}'s
 | 
| 
10878
 | 
    41  | 
and~\isa{b}'s:%
 | 
| 
10236
 | 
    42  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
    43  | 
\isamarkuptrue%
  | 
| 
 | 
    44  | 
\isacommand{datatype}\isamarkupfalse%
 | 
| 
 | 
    45  | 
\ alfa\ {\isacharequal}\ a\ {\isacharbar}\ b%
 | 
| 
10236
 | 
    46  | 
\begin{isamarkuptext}%
 | 
| 
 | 
    47  | 
\noindent
  | 
| 
10299
 | 
    48  | 
For convenience we include the following easy lemmas as simplification rules:%
  | 
| 
10236
 | 
    49  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
    50  | 
\isamarkuptrue%
  | 
| 
 | 
    51  | 
\isacommand{lemma}\isamarkupfalse%
 | 
| 
 | 
    52  | 
\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}x\ {\isasymnoteq}\ a{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}x\ {\isacharequal}\ b{\isacharparenright}\ {\isasymand}\ {\isacharparenleft}x\ {\isasymnoteq}\ b{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}x\ {\isacharequal}\ a{\isacharparenright}{\isachardoublequoteclose}\isanewline
 | 
| 
17056
 | 
    53  | 
%
  | 
| 
 | 
    54  | 
\isadelimproof
  | 
| 
 | 
    55  | 
%
  | 
| 
 | 
    56  | 
\endisadelimproof
  | 
| 
 | 
    57  | 
%
  | 
| 
 | 
    58  | 
\isatagproof
  | 
| 
17175
 | 
    59  | 
\isacommand{by}\isamarkupfalse%
 | 
| 
 | 
    60  | 
\ {\isacharparenleft}case{\isacharunderscore}tac\ x{\isacharcomma}\ auto{\isacharparenright}%
 | 
| 
17056
 | 
    61  | 
\endisatagproof
  | 
| 
 | 
    62  | 
{\isafoldproof}%
 | 
| 
 | 
    63  | 
%
  | 
| 
 | 
    64  | 
\isadelimproof
  | 
| 
 | 
    65  | 
%
  | 
| 
 | 
    66  | 
\endisadelimproof
  | 
| 
11866
 | 
    67  | 
%
  | 
| 
10236
 | 
    68  | 
\begin{isamarkuptext}%
 | 
| 
 | 
    69  | 
\noindent
  | 
| 
 | 
    70  | 
Words over this alphabet are of type \isa{alfa\ list}, and
 | 
| 
23733
 | 
    71  | 
the three nonterminals are declared as sets of such words.
  | 
| 
10878
 | 
    72  | 
The productions above are recast as a \emph{mutual} inductive
 | 
| 
10242
 | 
    73  | 
definition\index{inductive definition!simultaneous}
 | 
| 
10878
 | 
    74  | 
of \isa{S}, \isa{A} and~\isa{B}:%
 | 
| 
10236
 | 
    75  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
    76  | 
\isamarkuptrue%
  | 
| 
23733
 | 
    77  | 
\isacommand{inductive{\isacharunderscore}set}\isamarkupfalse%
 | 
| 
 | 
    78  | 
\isanewline
  | 
| 
25330
 | 
    79  | 
\ \ S\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}alfa\ list\ set{\isachardoublequoteclose}\ \isakeyword{and}\isanewline
 | 
| 
 | 
    80  | 
\ \ A\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}alfa\ list\ set{\isachardoublequoteclose}\ \isakeyword{and}\isanewline
 | 
| 
 | 
    81  | 
\ \ B\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}alfa\ list\ set{\isachardoublequoteclose}\isanewline
 | 
| 
23733
 | 
    82  | 
\isakeyword{where}\isanewline
 | 
| 
17175
 | 
    83  | 
\ \ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}\ {\isasymin}\ S{\isachardoublequoteclose}\isanewline
 | 
| 
23733
 | 
    84  | 
{\isacharbar}\ {\isachardoublequoteopen}w\ {\isasymin}\ A\ {\isasymLongrightarrow}\ b{\isacharhash}w\ {\isasymin}\ S{\isachardoublequoteclose}\isanewline
 | 
| 
 | 
    85  | 
{\isacharbar}\ {\isachardoublequoteopen}w\ {\isasymin}\ B\ {\isasymLongrightarrow}\ a{\isacharhash}w\ {\isasymin}\ S{\isachardoublequoteclose}\isanewline
 | 
| 
10217
 | 
    86  | 
\isanewline
  | 
| 
23733
 | 
    87  | 
{\isacharbar}\ {\isachardoublequoteopen}w\ {\isasymin}\ S\ \ \ \ \ \ \ \ {\isasymLongrightarrow}\ a{\isacharhash}w\ \ \ {\isasymin}\ A{\isachardoublequoteclose}\isanewline
 | 
| 
 | 
    88  | 
{\isacharbar}\ {\isachardoublequoteopen}{\isasymlbrakk}\ v{\isasymin}A{\isacharsemicolon}\ w{\isasymin}A\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ b{\isacharhash}v{\isacharat}w\ {\isasymin}\ A{\isachardoublequoteclose}\isanewline
 | 
| 
10217
 | 
    89  | 
\isanewline
  | 
| 
23733
 | 
    90  | 
{\isacharbar}\ {\isachardoublequoteopen}w\ {\isasymin}\ S\ \ \ \ \ \ \ \ \ \ \ \ {\isasymLongrightarrow}\ b{\isacharhash}w\ \ \ {\isasymin}\ B{\isachardoublequoteclose}\isanewline
 | 
| 
 | 
    91  | 
{\isacharbar}\ {\isachardoublequoteopen}{\isasymlbrakk}\ v\ {\isasymin}\ B{\isacharsemicolon}\ w\ {\isasymin}\ B\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ a{\isacharhash}v{\isacharat}w\ {\isasymin}\ B{\isachardoublequoteclose}%
 | 
| 
10236
 | 
    92  | 
\begin{isamarkuptext}%
 | 
| 
 | 
    93  | 
\noindent
  | 
| 
10878
 | 
    94  | 
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
 | 
| 
 | 
    95  | 
induction, so is the proof: we show at the same time that all words in
  | 
| 
27167
 | 
    96  | 
\isa{A} contain one more \isa{a} than \isa{b} and all words in \isa{B} contain one more \isa{b} than \isa{a}.%
 | 
| 
10236
 | 
    97  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
    98  | 
\isamarkuptrue%
  | 
| 
 | 
    99  | 
\isacommand{lemma}\isamarkupfalse%
 | 
| 
 | 
   100  | 
\ correctness{\isacharcolon}\isanewline
 | 
| 
23380
 | 
   101  | 
\ \ {\isachardoublequoteopen}{\isacharparenleft}w\ {\isasymin}\ S\ {\isasymlongrightarrow}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}{\isacharparenright}\ \ \ \ \ {\isasymand}\isanewline
 | 
| 
 | 
   102  | 
\ \ \ {\isacharparenleft}w\ {\isasymin}\ A\ {\isasymlongrightarrow}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}{\isacharparenright}\ {\isasymand}\isanewline
 | 
| 
 | 
   103  | 
\ \ \ {\isacharparenleft}w\ {\isasymin}\ B\ {\isasymlongrightarrow}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}{\isacharparenright}{\isachardoublequoteclose}%
 | 
| 
17056
 | 
   104  | 
\isadelimproof
  | 
| 
 | 
   105  | 
%
  | 
| 
 | 
   106  | 
\endisadelimproof
  | 
| 
 | 
   107  | 
%
  | 
| 
 | 
   108  | 
\isatagproof
  | 
| 
16069
 | 
   109  | 
%
  | 
| 
 | 
   110  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   111  | 
\noindent
  | 
| 
23380
 | 
   112  | 
These propositions are expressed with the help of the predefined \isa{filter} function on lists, which has the convenient syntax \isa{{\isacharbrackleft}x{\isasymleftarrow}xs{\isachardot}\ P\ x{\isacharbrackright}}, the list of all elements \isa{x} in \isa{xs} such that \isa{P\ x}
 | 
| 
16069
 | 
   113  | 
holds. Remember that on lists \isa{size} and \isa{length} are synonymous.
 | 
| 
 | 
   114  | 
  | 
| 
 | 
   115  | 
The proof itself is by rule induction and afterwards automatic:%
  | 
| 
 | 
   116  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   117  | 
\isamarkuptrue%
  | 
| 
 | 
   118  | 
\isacommand{by}\isamarkupfalse%
 | 
| 
 | 
   119  | 
\ {\isacharparenleft}rule\ S{\isacharunderscore}A{\isacharunderscore}B{\isachardot}induct{\isacharcomma}\ auto{\isacharparenright}%
 | 
| 
17056
 | 
   120  | 
\endisatagproof
  | 
| 
 | 
   121  | 
{\isafoldproof}%
 | 
| 
 | 
   122  | 
%
  | 
| 
 | 
   123  | 
\isadelimproof
  | 
| 
 | 
   124  | 
%
  | 
| 
 | 
   125  | 
\endisadelimproof
  | 
| 
11866
 | 
   126  | 
%
  | 
| 
10236
 | 
   127  | 
\begin{isamarkuptext}%
 | 
| 
 | 
   128  | 
\noindent
  | 
| 
 | 
   129  | 
This may seem surprising at first, and is indeed an indication of the power
  | 
| 
 | 
   130  | 
of inductive definitions. But it is also quite straightforward. For example,
  | 
| 
 | 
   131  | 
consider the production $A \to b A A$: if $v,w \in A$ and the elements of $A$
  | 
| 
10878
 | 
   132  | 
contain one more $a$ than~$b$'s, then $bvw$ must again contain one more $a$
  | 
| 
 | 
   133  | 
than~$b$'s.
  | 
| 
10236
 | 
   134  | 
  | 
| 
 | 
   135  | 
As usual, the correctness of syntactic descriptions is easy, but completeness
  | 
| 
 | 
   136  | 
is hard: does \isa{S} contain \emph{all} words with an equal number of
 | 
| 
 | 
   137  | 
\isa{a}'s and \isa{b}'s? It turns out that this proof requires the
 | 
| 
10878
 | 
   138  | 
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
 | 
   139  | 
\isa{b}. This is best seen by imagining counting the difference between the
 | 
| 
10283
 | 
   140  | 
number of \isa{a}'s and \isa{b}'s starting at the left end of the
 | 
| 
 | 
   141  | 
word. We start with 0 and end (at the right end) with 2. Since each move to the
  | 
| 
10236
 | 
   142  | 
right increases or decreases the difference by 1, we must have passed through
  | 
| 
 | 
   143  | 
1 on our way from 0 to 2. Formally, we appeal to the following discrete
  | 
| 
 | 
   144  | 
intermediate value theorem \isa{nat{\isadigit{0}}{\isacharunderscore}intermed{\isacharunderscore}int{\isacharunderscore}val}
 | 
| 
 | 
   145  | 
\begin{isabelle}%
 | 
| 
19654
 | 
   146  | 
\ \ \ \ \ {\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}\isanewline
 | 
| 
 | 
   147  | 
\isaindent{\ \ \ \ \ }{\isasymLongrightarrow}\ {\isasymexists}i{\isasymle}n{\isachardot}\ f\ i\ {\isacharequal}\ k%
 | 
| 
10236
 | 
   148  | 
\end{isabelle}
 | 
| 
 | 
   149  | 
where \isa{f} is of type \isa{nat\ {\isasymRightarrow}\ int}, \isa{int} are the integers,
 | 
| 
11308
 | 
   150  | 
\isa{{\isasymbar}{\isachardot}{\isasymbar}} is the absolute value function\footnote{See
 | 
| 
 | 
   151  | 
Table~\ref{tab:ascii} in the Appendix for the correct \textsc{ascii}
 | 
| 
11708
 | 
   152  | 
syntax.}, and \isa{{\isadigit{1}}} is the integer 1 (see \S\ref{sec:numbers}).
 | 
| 
10236
 | 
   153  | 
  | 
| 
11147
 | 
   154  | 
First we show that our specific function, the difference between the
  | 
| 
10236
 | 
   155  | 
numbers of \isa{a}'s and \isa{b}'s, does indeed only change by 1 in every
 | 
| 
 | 
   156  | 
move to the right. At this point we also start generalizing from \isa{a}'s
 | 
| 
 | 
   157  | 
and \isa{b}'s to an arbitrary property \isa{P}. Otherwise we would have
 | 
| 
 | 
   158  | 
to prove the desired lemma twice, once as stated above and once with the
  | 
| 
 | 
   159  | 
roles of \isa{a}'s and \isa{b}'s interchanged.%
 | 
| 
 | 
   160  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
   161  | 
\isamarkuptrue%
  | 
| 
 | 
   162  | 
\isacommand{lemma}\isamarkupfalse%
 | 
| 
 | 
   163  | 
\ step{\isadigit{1}}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymforall}i\ {\isacharless}\ size\ w{\isachardot}\isanewline
 | 
| 
23380
 | 
   164  | 
\ \ {\isasymbar}{\isacharparenleft}int{\isacharparenleft}size{\isacharbrackleft}x{\isasymleftarrow}take\ {\isacharparenleft}i{\isacharplus}{\isadigit{1}}{\isacharparenright}\ w{\isachardot}\ P\ x{\isacharbrackright}{\isacharparenright}{\isacharminus}int{\isacharparenleft}size{\isacharbrackleft}x{\isasymleftarrow}take\ {\isacharparenleft}i{\isacharplus}{\isadigit{1}}{\isacharparenright}\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharparenright}{\isacharparenright}\isanewline
 | 
| 
 | 
   165  | 
\ \ \ {\isacharminus}\ {\isacharparenleft}int{\isacharparenleft}size{\isacharbrackleft}x{\isasymleftarrow}take\ i\ w{\isachardot}\ P\ x{\isacharbrackright}{\isacharparenright}{\isacharminus}int{\isacharparenleft}size{\isacharbrackleft}x{\isasymleftarrow}take\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharparenright}{\isacharparenright}{\isasymbar}\ {\isasymle}\ {\isadigit{1}}{\isachardoublequoteclose}%
 | 
| 
17056
 | 
   166  | 
\isadelimproof
  | 
| 
 | 
   167  | 
%
  | 
| 
 | 
   168  | 
\endisadelimproof
  | 
| 
 | 
   169  | 
%
  | 
| 
 | 
   170  | 
\isatagproof
  | 
| 
16069
 | 
   171  | 
%
  | 
| 
 | 
   172  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   173  | 
\noindent
  | 
| 
 | 
   174  | 
The lemma is a bit hard to read because of the coercion function
  | 
| 
 | 
   175  | 
\isa{int\ {\isacharcolon}{\isacharcolon}\ nat\ {\isasymRightarrow}\ int}. It is required because \isa{size} returns
 | 
| 
 | 
   176  | 
a natural number, but subtraction on type~\isa{nat} will do the wrong thing.
 | 
| 
 | 
   177  | 
Function \isa{take} is predefined and \isa{take\ i\ xs} is the prefix of
 | 
| 
 | 
   178  | 
length \isa{i} of \isa{xs}; below we also need \isa{drop\ i\ xs}, which
 | 
| 
 | 
   179  | 
is what remains after that prefix has been dropped from \isa{xs}.
 | 
| 
 | 
   180  | 
  | 
| 
 | 
   181  | 
The proof is by induction on \isa{w}, with a trivial base case, and a not
 | 
| 
 | 
   182  | 
so trivial induction step. Since it is essentially just arithmetic, we do not
  | 
| 
 | 
   183  | 
discuss it.%
  | 
| 
 | 
   184  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   185  | 
\isamarkuptrue%
  | 
| 
 | 
   186  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   187  | 
{\isacharparenleft}induct{\isacharunderscore}tac\ w{\isacharparenright}\isanewline
 | 
| 
 | 
   188  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   189  | 
{\isacharparenleft}auto\ simp\ add{\isacharcolon}\ abs{\isacharunderscore}if\ take{\isacharunderscore}Cons\ split{\isacharcolon}\ nat{\isachardot}split{\isacharparenright}\isanewline
 | 
| 
 | 
   190  | 
\isacommand{done}\isamarkupfalse%
 | 
| 
 | 
   191  | 
%
  | 
| 
17056
 | 
   192  | 
\endisatagproof
  | 
| 
 | 
   193  | 
{\isafoldproof}%
 | 
| 
 | 
   194  | 
%
  | 
| 
 | 
   195  | 
\isadelimproof
  | 
| 
 | 
   196  | 
%
  | 
| 
 | 
   197  | 
\endisadelimproof
  | 
| 
11866
 | 
   198  | 
%
  | 
| 
10236
 | 
   199  | 
\begin{isamarkuptext}%
 | 
| 
11494
 | 
   200  | 
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
 | 
   201  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
   202  | 
\isamarkuptrue%
  | 
| 
 | 
   203  | 
\isacommand{lemma}\isamarkupfalse%
 | 
| 
 | 
   204  | 
\ part{\isadigit{1}}{\isacharcolon}\isanewline
 | 
| 
23380
 | 
   205  | 
\ {\isachardoublequoteopen}size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{2}}\ {\isasymLongrightarrow}\isanewline
 | 
| 
 | 
   206  | 
\ \ {\isasymexists}i{\isasymle}size\ w{\isachardot}\ size{\isacharbrackleft}x{\isasymleftarrow}take\ i\ w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}take\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{1}}{\isachardoublequoteclose}%
 | 
| 
17056
 | 
   207  | 
\isadelimproof
  | 
| 
 | 
   208  | 
%
  | 
| 
 | 
   209  | 
\endisadelimproof
  | 
| 
 | 
   210  | 
%
  | 
| 
 | 
   211  | 
\isatagproof
  | 
| 
16069
 | 
   212  | 
%
  | 
| 
 | 
   213  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   214  | 
\noindent
  | 
| 
 | 
   215  | 
This is proved by \isa{force} with the help of the intermediate value theorem,
 | 
| 
 | 
   216  | 
instantiated appropriately and with its first premise disposed of by lemma
  | 
| 
 | 
   217  | 
\isa{step{\isadigit{1}}}:%
 | 
| 
 | 
   218  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   219  | 
\isamarkuptrue%
  | 
| 
 | 
   220  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   221  | 
{\isacharparenleft}insert\ nat{\isadigit{0}}{\isacharunderscore}intermed{\isacharunderscore}int{\isacharunderscore}val{\isacharbrackleft}OF\ step{\isadigit{1}}{\isacharcomma}\ of\ {\isachardoublequoteopen}P{\isachardoublequoteclose}\ {\isachardoublequoteopen}w{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isadigit{1}}{\isachardoublequoteclose}{\isacharbrackright}{\isacharparenright}\isanewline
 | 
| 
 | 
   222  | 
\isacommand{by}\isamarkupfalse%
 | 
| 
 | 
   223  | 
\ force%
  | 
| 
17056
 | 
   224  | 
\endisatagproof
  | 
| 
 | 
   225  | 
{\isafoldproof}%
 | 
| 
 | 
   226  | 
%
  | 
| 
 | 
   227  | 
\isadelimproof
  | 
| 
 | 
   228  | 
%
  | 
| 
 | 
   229  | 
\endisadelimproof
  | 
| 
11866
 | 
   230  | 
%
  | 
| 
10236
 | 
   231  | 
\begin{isamarkuptext}%
 | 
| 
 | 
   232  | 
\noindent
  | 
| 
 | 
   233  | 
  | 
| 
 | 
   234  | 
Lemma \isa{part{\isadigit{1}}} tells us only about the prefix \isa{take\ i\ w}.
 | 
| 
10878
 | 
   235  | 
An easy lemma deals with the suffix \isa{drop\ i\ w}:%
 | 
| 
10236
 | 
   236  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
   237  | 
\isamarkuptrue%
  | 
| 
 | 
   238  | 
\isacommand{lemma}\isamarkupfalse%
 | 
| 
 | 
   239  | 
\ part{\isadigit{2}}{\isacharcolon}\isanewline
 | 
| 
23380
 | 
   240  | 
\ \ {\isachardoublequoteopen}{\isasymlbrakk}size{\isacharbrackleft}x{\isasymleftarrow}take\ i\ w\ {\isacharat}\ drop\ i\ w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\isanewline
 | 
| 
 | 
   241  | 
\ \ \ \ size{\isacharbrackleft}x{\isasymleftarrow}take\ i\ w\ {\isacharat}\ drop\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{2}}{\isacharsemicolon}\isanewline
 | 
| 
 | 
   242  | 
\ \ \ \ size{\isacharbrackleft}x{\isasymleftarrow}take\ i\ w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}take\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{1}}{\isasymrbrakk}\isanewline
 | 
| 
 | 
   243  | 
\ \ \ {\isasymLongrightarrow}\ size{\isacharbrackleft}x{\isasymleftarrow}drop\ i\ w{\isachardot}\ P\ x{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}drop\ i\ w{\isachardot}\ {\isasymnot}P\ x{\isacharbrackright}{\isacharplus}{\isadigit{1}}{\isachardoublequoteclose}\isanewline
 | 
| 
17056
 | 
   244  | 
%
  | 
| 
 | 
   245  | 
\isadelimproof
  | 
| 
 | 
   246  | 
%
  | 
| 
 | 
   247  | 
\endisadelimproof
  | 
| 
 | 
   248  | 
%
  | 
| 
 | 
   249  | 
\isatagproof
  | 
| 
17175
 | 
   250  | 
\isacommand{by}\isamarkupfalse%
 | 
| 
 | 
   251  | 
{\isacharparenleft}simp\ del{\isacharcolon}\ append{\isacharunderscore}take{\isacharunderscore}drop{\isacharunderscore}id{\isacharparenright}%
 | 
| 
17056
 | 
   252  | 
\endisatagproof
  | 
| 
 | 
   253  | 
{\isafoldproof}%
 | 
| 
 | 
   254  | 
%
  | 
| 
 | 
   255  | 
\isadelimproof
  | 
| 
 | 
   256  | 
%
  | 
| 
 | 
   257  | 
\endisadelimproof
  | 
| 
11866
 | 
   258  | 
%
  | 
| 
10236
 | 
   259  | 
\begin{isamarkuptext}%
 | 
| 
 | 
   260  | 
\noindent
  | 
| 
11257
 | 
   261  | 
In the proof we have disabled the normally useful lemma
  | 
| 
10878
 | 
   262  | 
\begin{isabelle}
 | 
| 
 | 
   263  | 
\isa{take\ n\ xs\ {\isacharat}\ drop\ n\ xs\ {\isacharequal}\ xs}
 | 
| 
 | 
   264  | 
\rulename{append_take_drop_id}
 | 
| 
 | 
   265  | 
\end{isabelle}
 | 
| 
11257
 | 
   266  | 
to allow the simplifier to apply the following lemma instead:
  | 
| 
 | 
   267  | 
\begin{isabelle}%
 | 
| 
 | 
   268  | 
\ \ \ \ \ {\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}%
 | 
| 
 | 
   269  | 
\end{isabelle}
 | 
| 
10236
 | 
   270  | 
  | 
| 
 | 
   271  | 
To dispose of trivial cases automatically, the rules of the inductive
  | 
| 
 | 
   272  | 
definition are declared simplification rules:%
  | 
| 
 | 
   273  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
   274  | 
\isamarkuptrue%
  | 
| 
 | 
   275  | 
\isacommand{declare}\isamarkupfalse%
 | 
| 
 | 
   276  | 
\ S{\isacharunderscore}A{\isacharunderscore}B{\isachardot}intros{\isacharbrackleft}simp{\isacharbrackright}%
 | 
| 
10236
 | 
   277  | 
\begin{isamarkuptext}%
 | 
| 
 | 
   278  | 
\noindent
  | 
| 
 | 
   279  | 
This could have been done earlier but was not necessary so far.
  | 
| 
 | 
   280  | 
  | 
| 
 | 
   281  | 
The completeness theorem tells us that if a word has the same number of
  | 
| 
10878
 | 
   282  | 
\isa{a}'s and \isa{b}'s, then it is in \isa{S}, and similarly 
 | 
| 
 | 
   283  | 
for \isa{A} and \isa{B}:%
 | 
| 
10236
 | 
   284  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
   285  | 
\isamarkuptrue%
  | 
| 
 | 
   286  | 
\isacommand{theorem}\isamarkupfalse%
 | 
| 
 | 
   287  | 
\ completeness{\isacharcolon}\isanewline
 | 
| 
23380
 | 
   288  | 
\ \ {\isachardoublequoteopen}{\isacharparenleft}size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ \ \ \ \ {\isasymlongrightarrow}\ w\ {\isasymin}\ S{\isacharparenright}\ {\isasymand}\isanewline
 | 
| 
 | 
   289  | 
\ \ \ {\isacharparenleft}size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}\ {\isasymlongrightarrow}\ w\ {\isasymin}\ A{\isacharparenright}\ {\isasymand}\isanewline
 | 
| 
 | 
   290  | 
\ \ \ {\isacharparenleft}size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}b{\isacharbrackright}\ {\isacharequal}\ size{\isacharbrackleft}x{\isasymleftarrow}w{\isachardot}\ x{\isacharequal}a{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}\ {\isasymlongrightarrow}\ w\ {\isasymin}\ B{\isacharparenright}{\isachardoublequoteclose}%
 | 
| 
17056
 | 
   291  | 
\isadelimproof
  | 
| 
 | 
   292  | 
%
  | 
| 
 | 
   293  | 
\endisadelimproof
  | 
| 
 | 
   294  | 
%
  | 
| 
 | 
   295  | 
\isatagproof
  | 
| 
16069
 | 
   296  | 
%
  | 
| 
 | 
   297  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   298  | 
\noindent
  | 
| 
 | 
   299  | 
The proof is by induction on \isa{w}. Structural induction would fail here
 | 
| 
 | 
   300  | 
because, as we can see from the grammar, we need to make bigger steps than
  | 
| 
 | 
   301  | 
merely appending a single letter at the front. Hence we induct on the length
  | 
| 
 | 
   302  | 
of \isa{w}, using the induction rule \isa{length{\isacharunderscore}induct}:%
 | 
| 
 | 
   303  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   304  | 
\isamarkuptrue%
  | 
| 
 | 
   305  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
27167
 | 
   306  | 
{\isacharparenleft}induct{\isacharunderscore}tac\ w\ rule{\isacharcolon}\ length{\isacharunderscore}induct{\isacharparenright}\isanewline
 | 
| 
 | 
   307  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   308  | 
{\isacharparenleft}rename{\isacharunderscore}tac\ w{\isacharparenright}%
 | 
| 
16069
 | 
   309  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   310  | 
\noindent
  | 
| 
 | 
   311  | 
The \isa{rule} parameter tells \isa{induct{\isacharunderscore}tac} explicitly which induction
 | 
| 
 | 
   312  | 
rule to use. For details see \S\ref{sec:complete-ind} below.
 | 
| 
 | 
   313  | 
In this case the result is that we may assume the lemma already
  | 
| 
27167
 | 
   314  | 
holds for all words shorter than \isa{w}. Because the induction step renames
 | 
| 
 | 
   315  | 
the induction variable we rename it back to \isa{w}.
 | 
| 
16069
 | 
   316  | 
  | 
| 
 | 
   317  | 
The proof continues with a case distinction on \isa{w},
 | 
| 
 | 
   318  | 
on whether \isa{w} is empty or not.%
 | 
| 
 | 
   319  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   320  | 
\isamarkuptrue%
  | 
| 
 | 
   321  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   322  | 
{\isacharparenleft}case{\isacharunderscore}tac\ w{\isacharparenright}\isanewline
 | 
| 
 | 
   323  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
17181
 | 
   324  | 
{\isacharparenleft}simp{\isacharunderscore}all{\isacharparenright}%
 | 
| 
16069
 | 
   325  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   326  | 
\noindent
  | 
| 
 | 
   327  | 
Simplification disposes of the base case and leaves only a conjunction
  | 
| 
 | 
   328  | 
of two step cases to be proved:
  | 
| 
 | 
   329  | 
if \isa{w\ {\isacharequal}\ a\ {\isacharhash}\ v} and \begin{isabelle}%
 | 
| 
23380
 | 
   330  | 
\ \ \ \ \ length\ {\isacharparenleft}if\ x\ {\isacharequal}\ a\ then\ {\isacharbrackleft}x\ {\isasymin}\ v{\isacharbrackright}\ else\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\isanewline
 | 
| 
 | 
   331  | 
\isaindent{\ \ \ \ \ }length\ {\isacharparenleft}if\ x\ {\isacharequal}\ b\ then\ {\isacharbrackleft}x\ {\isasymin}\ v{\isacharbrackright}\ else\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharplus}\ {\isadigit{2}}%
 | 
| 
16069
 | 
   332  | 
\end{isabelle} then
 | 
| 
 | 
   333  | 
\isa{b\ {\isacharhash}\ v\ {\isasymin}\ A}, and similarly for \isa{w\ {\isacharequal}\ b\ {\isacharhash}\ v}.
 | 
| 
 | 
   334  | 
We only consider the first case in detail.
  | 
| 
 | 
   335  | 
  | 
| 
 | 
   336  | 
After breaking the conjunction up into two cases, we can apply
  | 
| 
 | 
   337  | 
\isa{part{\isadigit{1}}} to the assumption that \isa{w} contains two more \isa{a}'s than \isa{b}'s.%
 | 
| 
 | 
   338  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   339  | 
\isamarkuptrue%
  | 
| 
 | 
   340  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   341  | 
{\isacharparenleft}rule\ conjI{\isacharparenright}\isanewline
 | 
| 
 | 
   342  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   343  | 
{\isacharparenleft}clarify{\isacharparenright}\isanewline
 | 
| 
 | 
   344  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   345  | 
{\isacharparenleft}frule\ part{\isadigit{1}}{\isacharbrackleft}of\ {\isachardoublequoteopen}{\isasymlambda}x{\isachardot}\ x{\isacharequal}a{\isachardoublequoteclose}{\isacharcomma}\ simplified{\isacharbrackright}{\isacharparenright}\isanewline
 | 
| 
 | 
   346  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   347  | 
{\isacharparenleft}clarify{\isacharparenright}%
 | 
| 
16069
 | 
   348  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   349  | 
\noindent
  | 
| 
 | 
   350  | 
This yields an index \isa{i\ {\isasymle}\ length\ v} such that
 | 
| 
 | 
   351  | 
\begin{isabelle}%
 | 
| 
23380
 | 
   352  | 
\ \ \ \ \ length\ {\isacharbrackleft}x{\isasymleftarrow}take\ i\ v\ {\isachardot}\ x\ {\isacharequal}\ a{\isacharbrackright}\ {\isacharequal}\ length\ {\isacharbrackleft}x{\isasymleftarrow}take\ i\ v\ {\isachardot}\ x\ {\isacharequal}\ b{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}%
 | 
| 
16069
 | 
   353  | 
\end{isabelle}
 | 
| 
 | 
   354  | 
With the help of \isa{part{\isadigit{2}}} it follows that
 | 
| 
 | 
   355  | 
\begin{isabelle}%
 | 
| 
23380
 | 
   356  | 
\ \ \ \ \ length\ {\isacharbrackleft}x{\isasymleftarrow}drop\ i\ v\ {\isachardot}\ x\ {\isacharequal}\ a{\isacharbrackright}\ {\isacharequal}\ length\ {\isacharbrackleft}x{\isasymleftarrow}drop\ i\ v\ {\isachardot}\ x\ {\isacharequal}\ b{\isacharbrackright}\ {\isacharplus}\ {\isadigit{1}}%
 | 
| 
16069
 | 
   357  | 
\end{isabelle}%
 | 
| 
 | 
   358  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   359  | 
\isamarkuptrue%
  | 
| 
 | 
   360  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   361  | 
{\isacharparenleft}drule\ part{\isadigit{2}}{\isacharbrackleft}of\ {\isachardoublequoteopen}{\isasymlambda}x{\isachardot}\ x{\isacharequal}a{\isachardoublequoteclose}{\isacharcomma}\ simplified{\isacharbrackright}{\isacharparenright}\isanewline
 | 
| 
 | 
   362  | 
\ \ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   363  | 
{\isacharparenleft}assumption{\isacharparenright}%
 | 
| 
16069
 | 
   364  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   365  | 
\noindent
  | 
| 
 | 
   366  | 
Now it is time to decompose \isa{v} in the conclusion \isa{b\ {\isacharhash}\ v\ {\isasymin}\ A}
 | 
| 
 | 
   367  | 
into \isa{take\ i\ v\ {\isacharat}\ drop\ i\ v},%
 | 
| 
 | 
   368  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   369  | 
\isamarkuptrue%
  | 
| 
 | 
   370  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   371  | 
{\isacharparenleft}rule{\isacharunderscore}tac\ n{\isadigit{1}}{\isacharequal}i\ \isakeyword{and}\ t{\isacharequal}v\ \isakeyword{in}\ subst{\isacharbrackleft}OF\ append{\isacharunderscore}take{\isacharunderscore}drop{\isacharunderscore}id{\isacharbrackright}{\isacharparenright}%
 | 
| 
16069
 | 
   372  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   373  | 
\noindent
  | 
| 
 | 
   374  | 
(the variables \isa{n{\isadigit{1}}} and \isa{t} are the result of composing the
 | 
| 
 | 
   375  | 
theorems \isa{subst} and \isa{append{\isacharunderscore}take{\isacharunderscore}drop{\isacharunderscore}id})
 | 
| 
 | 
   376  | 
after which the appropriate rule of the grammar reduces the goal
  | 
| 
 | 
   377  | 
to the two subgoals \isa{take\ i\ v\ {\isasymin}\ A} and \isa{drop\ i\ v\ {\isasymin}\ A}:%
 | 
| 
 | 
   378  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   379  | 
\isamarkuptrue%
  | 
| 
 | 
   380  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   381  | 
{\isacharparenleft}rule\ S{\isacharunderscore}A{\isacharunderscore}B{\isachardot}intros{\isacharparenright}%
 | 
| 
16069
 | 
   382  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   383  | 
Both subgoals follow from the induction hypothesis because both \isa{take\ i\ v} and \isa{drop\ i\ v} are shorter than \isa{w}:%
 | 
| 
 | 
   384  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   385  | 
\isamarkuptrue%
  | 
| 
 | 
   386  | 
\ \ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   387  | 
{\isacharparenleft}force\ simp\ add{\isacharcolon}\ min{\isacharunderscore}less{\isacharunderscore}iff{\isacharunderscore}disj{\isacharparenright}\isanewline
 | 
| 
 | 
   388  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   389  | 
{\isacharparenleft}force\ split\ add{\isacharcolon}\ nat{\isacharunderscore}diff{\isacharunderscore}split{\isacharparenright}%
 | 
| 
16069
 | 
   390  | 
\begin{isamarkuptxt}%
 | 
| 
 | 
   391  | 
The case \isa{w\ {\isacharequal}\ b\ {\isacharhash}\ v} is proved analogously:%
 | 
| 
 | 
   392  | 
\end{isamarkuptxt}%
 | 
| 
17175
 | 
   393  | 
\isamarkuptrue%
  | 
| 
 | 
   394  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   395  | 
{\isacharparenleft}clarify{\isacharparenright}\isanewline
 | 
| 
 | 
   396  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   397  | 
{\isacharparenleft}frule\ part{\isadigit{1}}{\isacharbrackleft}of\ {\isachardoublequoteopen}{\isasymlambda}x{\isachardot}\ x{\isacharequal}b{\isachardoublequoteclose}{\isacharcomma}\ simplified{\isacharbrackright}{\isacharparenright}\isanewline
 | 
| 
 | 
   398  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   399  | 
{\isacharparenleft}clarify{\isacharparenright}\isanewline
 | 
| 
 | 
   400  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   401  | 
{\isacharparenleft}drule\ part{\isadigit{2}}{\isacharbrackleft}of\ {\isachardoublequoteopen}{\isasymlambda}x{\isachardot}\ x{\isacharequal}b{\isachardoublequoteclose}{\isacharcomma}\ simplified{\isacharbrackright}{\isacharparenright}\isanewline
 | 
| 
 | 
   402  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   403  | 
{\isacharparenleft}assumption{\isacharparenright}\isanewline
 | 
| 
 | 
   404  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   405  | 
{\isacharparenleft}rule{\isacharunderscore}tac\ n{\isadigit{1}}{\isacharequal}i\ \isakeyword{and}\ t{\isacharequal}v\ \isakeyword{in}\ subst{\isacharbrackleft}OF\ append{\isacharunderscore}take{\isacharunderscore}drop{\isacharunderscore}id{\isacharbrackright}{\isacharparenright}\isanewline
 | 
| 
 | 
   406  | 
\isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   407  | 
{\isacharparenleft}rule\ S{\isacharunderscore}A{\isacharunderscore}B{\isachardot}intros{\isacharparenright}\isanewline
 | 
| 
 | 
   408  | 
\ \isacommand{apply}\isamarkupfalse%
 | 
| 
 | 
   409  | 
{\isacharparenleft}force\ simp\ add{\isacharcolon}\ min{\isacharunderscore}less{\isacharunderscore}iff{\isacharunderscore}disj{\isacharparenright}\isanewline
 | 
| 
 | 
   410  | 
\isacommand{by}\isamarkupfalse%
 | 
| 
 | 
   411  | 
{\isacharparenleft}force\ simp\ add{\isacharcolon}\ min{\isacharunderscore}less{\isacharunderscore}iff{\isacharunderscore}disj\ split\ add{\isacharcolon}\ nat{\isacharunderscore}diff{\isacharunderscore}split{\isacharparenright}%
 | 
| 
17056
 | 
   412  | 
\endisatagproof
  | 
| 
 | 
   413  | 
{\isafoldproof}%
 | 
| 
 | 
   414  | 
%
  | 
| 
 | 
   415  | 
\isadelimproof
  | 
| 
 | 
   416  | 
%
  | 
| 
 | 
   417  | 
\endisadelimproof
  | 
| 
11866
 | 
   418  | 
%
  | 
| 
10236
 | 
   419  | 
\begin{isamarkuptext}%
 | 
| 
10878
 | 
   420  | 
We conclude this section with a comparison of our proof with 
  | 
| 
11494
 | 
   421  | 
Hopcroft\index{Hopcroft, J. E.} and Ullman's\index{Ullman, J. D.}
 | 
| 
 | 
   422  | 
\cite[p.\ts81]{HopcroftUllman}.
 | 
| 
 | 
   423  | 
For a start, the textbook
  | 
| 
11257
 | 
   424  | 
grammar, for no good reason, excludes the empty word, thus complicating
  | 
| 
 | 
   425  | 
matters just a little bit: they have 8 instead of our 7 productions.
  | 
| 
10236
 | 
   426  | 
  | 
| 
11158
 | 
   427  | 
More importantly, the proof itself is different: rather than
  | 
| 
 | 
   428  | 
separating the two directions, they perform one induction on the
  | 
| 
 | 
   429  | 
length of a word. This deprives them of the beauty of rule induction,
  | 
| 
 | 
   430  | 
and in the easy direction (correctness) their reasoning is more
  | 
| 
 | 
   431  | 
detailed than our \isa{auto}. For the hard part (completeness), they
 | 
| 
 | 
   432  | 
consider just one of the cases that our \isa{simp{\isacharunderscore}all} disposes of
 | 
| 
 | 
   433  | 
automatically. Then they conclude the proof by saying about the
  | 
| 
 | 
   434  | 
remaining cases: ``We do this in a manner similar to our method of
  | 
| 
 | 
   435  | 
proof for part (1); this part is left to the reader''. But this is
  | 
| 
 | 
   436  | 
precisely the part that requires the intermediate value theorem and
  | 
| 
 | 
   437  | 
thus is not at all similar to the other cases (which are automatic in
  | 
| 
 | 
   438  | 
Isabelle). The authors are at least cavalier about this point and may
  | 
| 
 | 
   439  | 
even have overlooked the slight difficulty lurking in the omitted
  | 
| 
11494
 | 
   440  | 
cases.  Such errors are found in many pen-and-paper proofs when they
  | 
| 
 | 
   441  | 
are scrutinized formally.%
  | 
| 
 | 
   442  | 
\index{grammars!defining inductively|)}%
 | 
| 
10236
 | 
   443  | 
\end{isamarkuptext}%
 | 
| 
17175
 | 
   444  | 
\isamarkuptrue%
  | 
| 
17056
 | 
   445  | 
%
  | 
| 
 | 
   446  | 
\isadelimtheory
  | 
| 
 | 
   447  | 
%
  | 
| 
 | 
   448  | 
\endisadelimtheory
  | 
| 
 | 
   449  | 
%
  | 
| 
 | 
   450  | 
\isatagtheory
  | 
| 
 | 
   451  | 
%
  | 
| 
 | 
   452  | 
\endisatagtheory
  | 
| 
 | 
   453  | 
{\isafoldtheory}%
 | 
| 
 | 
   454  | 
%
  | 
| 
 | 
   455  | 
\isadelimtheory
  | 
| 
 | 
   456  | 
%
  | 
| 
 | 
   457  | 
\endisadelimtheory
  | 
| 
10217
 | 
   458  | 
\end{isabellebody}%
 | 
| 
 | 
   459  | 
%%% Local Variables:
  | 
| 
 | 
   460  | 
%%% mode: latex
  | 
| 
 | 
   461  | 
%%% TeX-master: "root"
  | 
| 
 | 
   462  | 
%%% End:
  |