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