doc-src/TutorialI/Trie/document/Trie.tex
author wenzelm
Sat, 20 Oct 2001 22:07:44 +0200
changeset 11857 cc3d971fe66a
parent 11480 0fba0357c04c
child 11866 fbd097aec213
permissions -rw-r--r--
got rid of separate root.tex;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9722
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
     1
%
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
     2
\begin{isabellebody}%
9924
3370f6aa3200 updated;
wenzelm
parents: 9792
diff changeset
     3
\def\isabellecontext{Trie}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     4
%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     5
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     6
To minimize running time, each node of a trie should contain an array that maps
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10187
diff changeset
     7
letters to subtries. We have chosen a
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
     8
representation where the subtries are held in an association list, i.e.\ a
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
     9
list of (letter,trie) pairs.  Abstracting over the alphabet \isa{{\isacharprime}a} and the
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
    10
values \isa{{\isacharprime}v} we define a trie as follows:%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    11
\end{isamarkuptext}%
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    12
\isacommand{datatype}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}v{\isacharparenright}trie\ {\isacharequal}\ Trie\ \ {\isachardoublequote}{\isacharprime}v\ option{\isachardoublequote}\ \ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isacharasterisk}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}v{\isacharparenright}trie{\isacharparenright}list{\isachardoublequote}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    13
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    14
\noindent
11480
0fba0357c04c Getting it working again with 1' instead of 1
paulson
parents: 11309
diff changeset
    15
\index{datatypes!and nested recursion}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    16
The first component is the optional value, the second component the
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    17
association list of subtries.  This is an example of nested recursion involving products,
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    18
which is fine because products are datatypes as well.
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    19
We define two selector functions:%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    20
\end{isamarkuptext}%
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    21
\isacommand{consts}\ value\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}v{\isacharparenright}trie\ {\isasymRightarrow}\ {\isacharprime}v\ option{\isachardoublequote}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    22
\ \ \ \ \ \ \ alist\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}v{\isacharparenright}trie\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isacharasterisk}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}v{\isacharparenright}trie{\isacharparenright}list{\isachardoublequote}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    23
\isacommand{primrec}\ {\isachardoublequote}value{\isacharparenleft}Trie\ ov\ al{\isacharparenright}\ {\isacharequal}\ ov{\isachardoublequote}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    24
\isacommand{primrec}\ {\isachardoublequote}alist{\isacharparenleft}Trie\ ov\ al{\isacharparenright}\ {\isacharequal}\ al{\isachardoublequote}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    25
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    26
\noindent
11309
d666f11ca2d4 minor suggestions by Tanja Vos
paulson
parents: 11304
diff changeset
    27
Association lists come with a generic lookup function.  Its result
d666f11ca2d4 minor suggestions by Tanja Vos
paulson
parents: 11304
diff changeset
    28
involves type \isa{option} because a lookup can fail:%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    29
\end{isamarkuptext}%
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    30
\isacommand{consts}\ \ \ assoc\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}key\ {\isacharasterisk}\ {\isacharprime}val{\isacharparenright}list\ {\isasymRightarrow}\ {\isacharprime}key\ {\isasymRightarrow}\ {\isacharprime}val\ option{\isachardoublequote}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    31
\isacommand{primrec}\ {\isachardoublequote}assoc\ {\isacharbrackleft}{\isacharbrackright}\ x\ {\isacharequal}\ None{\isachardoublequote}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    32
\ \ \ \ \ \ \ \ {\isachardoublequote}assoc\ {\isacharparenleft}p{\isacharhash}ps{\isacharparenright}\ x\ {\isacharequal}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    33
\ \ \ \ \ \ \ \ \ \ \ {\isacharparenleft}let\ {\isacharparenleft}a{\isacharcomma}b{\isacharparenright}\ {\isacharequal}\ p\ in\ if\ a{\isacharequal}x\ then\ Some\ b\ else\ assoc\ ps\ x{\isacharparenright}{\isachardoublequote}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    34
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    35
Now we can define the lookup function for tries. It descends into the trie
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    36
examining the letters of the search string one by one. As
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    37
recursion on lists is simpler than on tries, let us express this as primitive
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    38
recursion on the search string argument:%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    39
\end{isamarkuptext}%
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    40
\isacommand{consts}\ \ \ lookup\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}v{\isacharparenright}trie\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}v\ option{\isachardoublequote}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    41
\isacommand{primrec}\ {\isachardoublequote}lookup\ t\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ value\ t{\isachardoublequote}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    42
\ \ \ \ \ \ \ \ {\isachardoublequote}lookup\ t\ {\isacharparenleft}a{\isacharhash}as{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}case\ assoc\ {\isacharparenleft}alist\ t{\isacharparenright}\ a\ of\isanewline
9521
c396d1092430 updated;
wenzelm
parents: 9458
diff changeset
    43
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ None\ {\isasymRightarrow}\ None\isanewline
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    44
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbar}\ Some\ at\ {\isasymRightarrow}\ lookup\ at\ as{\isacharparenright}{\isachardoublequote}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    45
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    46
As a first simple property we prove that looking up a string in the empty
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
    47
trie \isa{Trie\ None\ {\isacharbrackleft}{\isacharbrackright}} always returns \isa{None}. The proof merely
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    48
distinguishes the two cases whether the search string is empty or not:%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    49
\end{isamarkuptext}%
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    50
\isacommand{lemma}\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}lookup\ {\isacharparenleft}Trie\ None\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ as\ {\isacharequal}\ None{\isachardoublequote}\isanewline
10171
59d6633835fa *** empty log message ***
nipkow
parents: 9933
diff changeset
    51
\isacommand{apply}{\isacharparenleft}case{\isacharunderscore}tac\ as{\isacharcomma}\ simp{\isacharunderscore}all{\isacharparenright}\isanewline
59d6633835fa *** empty log message ***
nipkow
parents: 9933
diff changeset
    52
\isacommand{done}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    53
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    54
Things begin to get interesting with the definition of an update function
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    55
that adds a new (string,value) pair to a trie, overwriting the old value
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    56
associated with that string:%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    57
\end{isamarkuptext}%
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    58
\isacommand{consts}\ update\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}v{\isacharparenright}trie\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}v\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}v{\isacharparenright}trie{\isachardoublequote}\isanewline
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    59
\isacommand{primrec}\isanewline
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    60
\ \ {\isachardoublequote}update\ t\ {\isacharbrackleft}{\isacharbrackright}\ \ \ \ \ v\ {\isacharequal}\ Trie\ {\isacharparenleft}Some\ v{\isacharparenright}\ {\isacharparenleft}alist\ t{\isacharparenright}{\isachardoublequote}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    61
\ \ {\isachardoublequote}update\ t\ {\isacharparenleft}a{\isacharhash}as{\isacharparenright}\ v\ {\isacharequal}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    62
\ \ \ \ \ {\isacharparenleft}let\ tt\ {\isacharequal}\ {\isacharparenleft}case\ assoc\ {\isacharparenleft}alist\ t{\isacharparenright}\ a\ of\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    63
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ None\ {\isasymRightarrow}\ Trie\ None\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbar}\ Some\ at\ {\isasymRightarrow}\ at{\isacharparenright}\isanewline
10795
9e888d60d3e5 minor edits to Chapters 1-3
paulson
parents: 10187
diff changeset
    64
\ \ \ \ \ \ in\ Trie\ {\isacharparenleft}value\ t{\isacharparenright}\ {\isacharparenleft}{\isacharparenleft}a{\isacharcomma}update\ tt\ as\ v{\isacharparenright}\ {\isacharhash}\ alist\ t{\isacharparenright}{\isacharparenright}{\isachardoublequote}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    65
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    66
\noindent
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    67
The base case is obvious. In the recursive case the subtrie
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    68
\isa{tt} associated with the first letter \isa{a} is extracted,
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    69
recursively updated, and then placed in front of the association list.
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    70
The old subtrie associated with \isa{a} is still in the association list
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    71
but no longer accessible via \isa{assoc}. Clearly, there is room here for
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    72
optimizations!
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    73
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    74
Before we start on any proofs about \isa{update} we tell the simplifier to
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    75
expand all \isa{let}s and to split all \isa{case}-constructs over
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    76
options:%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    77
\end{isamarkuptext}%
9933
9feb1e0c4cb3 *** empty log message ***
nipkow
parents: 9924
diff changeset
    78
\isacommand{declare}\ Let{\isacharunderscore}def{\isacharbrackleft}simp{\isacharbrackright}\ option{\isachardot}split{\isacharbrackleft}split{\isacharbrackright}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    79
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    80
\noindent
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    81
The reason becomes clear when looking (probably after a failed proof
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    82
attempt) at the body of \isa{update}: it contains both
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    83
\isa{let} and a case distinction over type \isa{option}.
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    84
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    85
Our main goal is to prove the correct interaction of \isa{update} and
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    86
\isa{lookup}:%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    87
\end{isamarkuptext}%
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    88
\isacommand{theorem}\ {\isachardoublequote}{\isasymforall}t\ v\ bs{\isachardot}\ lookup\ {\isacharparenleft}update\ t\ as\ v{\isacharparenright}\ bs\ {\isacharequal}\isanewline
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
    89
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharparenleft}if\ as{\isacharequal}bs\ then\ Some\ v\ else\ lookup\ t\ bs{\isacharparenright}{\isachardoublequote}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    90
\begin{isamarkuptxt}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    91
\noindent
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    92
Our plan is to induct on \isa{as}; hence the remaining variables are
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    93
quantified. From the definitions it is clear that induction on either
11480
0fba0357c04c Getting it working again with 1' instead of 1
paulson
parents: 11309
diff changeset
    94
\isa{as} or \isa{bs} is required. The choice of \isa{as} is 
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    95
guided by the intuition that simplification of \isa{lookup} might be easier
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    96
if \isa{update} has already been simplified, which can only happen if
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    97
\isa{as} is instantiated.
11480
0fba0357c04c Getting it working again with 1' instead of 1
paulson
parents: 11309
diff changeset
    98
The start of the proof is conventional:%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
    99
\end{isamarkuptxt}%
9674
f789d2490669 updated;
wenzelm
parents: 9541
diff changeset
   100
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ as{\isacharcomma}\ auto{\isacharparenright}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   101
\begin{isamarkuptxt}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   102
\noindent
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   103
Unfortunately, this time we are left with three intimidating looking subgoals:
9723
a977245dfc8a *** empty log message ***
nipkow
parents: 9722
diff changeset
   104
\begin{isabelle}
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   105
~1.~\dots~{\isasymLongrightarrow}~lookup~\dots~bs~=~lookup~t~bs\isanewline
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   106
~2.~\dots~{\isasymLongrightarrow}~lookup~\dots~bs~=~lookup~t~bs\isanewline
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
   107
~3.~\dots~{\isasymLongrightarrow}~lookup~\dots~bs~=~lookup~t~bs
9723
a977245dfc8a *** empty log message ***
nipkow
parents: 9722
diff changeset
   108
\end{isabelle}
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   109
Clearly, if we want to make headway we have to instantiate \isa{bs} as
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   110
well now. It turns out that instead of induction, case distinction
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   111
suffices:%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   112
\end{isamarkuptxt}%
10171
59d6633835fa *** empty log message ***
nipkow
parents: 9933
diff changeset
   113
\isacommand{apply}{\isacharparenleft}case{\isacharunderscore}tac{\isacharbrackleft}{\isacharbang}{\isacharbrackright}\ bs{\isacharcomma}\ auto{\isacharparenright}\isanewline
59d6633835fa *** empty log message ***
nipkow
parents: 9933
diff changeset
   114
\isacommand{done}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   115
\begin{isamarkuptext}%
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   116
\noindent
11480
0fba0357c04c Getting it working again with 1' instead of 1
paulson
parents: 11309
diff changeset
   117
\index{subgoal numbering}%
9541
d17c0b34d5c8 *** empty log message ***
nipkow
parents: 9521
diff changeset
   118
All methods ending in \isa{tac} take an optional first argument that
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
   119
specifies the range of subgoals they are applied to, where \isa{{\isacharbrackleft}{\isacharbang}{\isacharbrackright}} means
10187
0376cccd9118 *** empty log message ***
nipkow
parents: 10171
diff changeset
   120
all subgoals, i.e.\ \isa{{\isacharbrackleft}{\isadigit{1}}{\isacharminus}{\isadigit{3}}{\isacharbrackright}} in our case. Individual subgoal numbers,
0376cccd9118 *** empty log message ***
nipkow
parents: 10171
diff changeset
   121
e.g. \isa{{\isacharbrackleft}{\isadigit{2}}{\isacharbrackright}} are also allowed.
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   122
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   123
This proof may look surprisingly straightforward. However, note that this
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
   124
comes at a cost: the proof script is unreadable because the intermediate
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
   125
proof states are invisible, and we rely on the (possibly brittle) magic of
10971
6852682eaf16 *** empty log message ***
nipkow
parents: 10795
diff changeset
   126
\isa{auto} (\isa{simp{\isacharunderscore}all} will not do --- try it) to split the subgoals
9792
bbefb6ce5cb2 *** empty log message ***
nipkow
parents: 9723
diff changeset
   127
of the induction up in such a way that case distinction on \isa{bs} makes
11480
0fba0357c04c Getting it working again with 1' instead of 1
paulson
parents: 11309
diff changeset
   128
sense and solves the proof. 
11294
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   129
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   130
\begin{exercise}
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   131
  Modify \isa{update} (and its type) such that it allows both insertion and
11304
0db2a02bff99 auto update
paulson
parents: 11294
diff changeset
   132
  deletion of entries with a single function.  Prove the corresponding version 
0db2a02bff99 auto update
paulson
parents: 11294
diff changeset
   133
  of the main theorem above.
0db2a02bff99 auto update
paulson
parents: 11294
diff changeset
   134
  Optimize your function such that it shrinks tries after
0db2a02bff99 auto update
paulson
parents: 11294
diff changeset
   135
  deletion if possible.
11294
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   136
\end{exercise}
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   137
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   138
\begin{exercise}
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   139
  Write an improved version of \isa{update} that does not suffer from the
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   140
  space leak (pointed out above) caused by not deleting overwritten entries
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   141
  from the association list. Prove the main theorem for your improved
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   142
  \isa{update}.
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   143
\end{exercise}
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   144
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   145
\begin{exercise}
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   146
  Conceptually, each node contains a mapping from letters to optional
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   147
  subtries. Above we have implemented this by means of an association
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   148
  list. Replay the development replacing \isa{{\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isacharprime}v{\isacharparenright}\ trie{\isacharparenright}\ list}
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   149
  with \isa{{\isacharprime}a\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isacharprime}v{\isacharparenright}\ trie\ option}.
16481a4cc9f3 *** empty log message ***
nipkow
parents: 10978
diff changeset
   150
\end{exercise}%
8749
2665170f104a Adding generated files
nipkow
parents:
diff changeset
   151
\end{isamarkuptext}%
9722
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
   152
\end{isabellebody}%
9145
9f7b8de5bfaf updated;
wenzelm
parents: 8771
diff changeset
   153
%%% Local Variables:
9f7b8de5bfaf updated;
wenzelm
parents: 8771
diff changeset
   154
%%% mode: latex
9f7b8de5bfaf updated;
wenzelm
parents: 8771
diff changeset
   155
%%% TeX-master: "root"
9f7b8de5bfaf updated;
wenzelm
parents: 8771
diff changeset
   156
%%% End: