doc-src/Codegen/Thy/document/Refinement.tex
author haftmann
Mon, 27 Sep 2010 16:27:31 +0200
changeset 39745 3aa2bc9c5478
parent 39683 f75a01ee6c41
child 40352 8fd36f8a5cb7
permissions -rw-r--r--
combine quote and typewriter/tt tag
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     1
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     2
\begin{isabellebody}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     3
\def\isabellecontext{Refinement}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     4
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     5
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     6
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     7
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     8
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     9
\isatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    10
\isacommand{theory}\isamarkupfalse%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    11
\ Refinement\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    12
\isakeyword{imports}\ Setup\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    13
\isakeyword{begin}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    14
\endisatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    15
{\isafoldtheory}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    16
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    17
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    18
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    19
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    20
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    21
\isamarkupsection{Program and datatype refinement \label{sec:refinement}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    22
}
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    23
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    24
%
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    25
\begin{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    26
Code generation by shallow embedding (cf.~\secref{sec:principle})
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    27
  allows to choose code equations and datatype constructors freely,
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    28
  given that some very basic syntactic properties are met; this
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    29
  flexibility opens up mechanisms for refinement which allow to extend
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    30
  the scope and quality of generated code dramatically.%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    31
\end{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    32
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    33
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    34
\isamarkupsubsection{Program refinement%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    35
}
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    36
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    37
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    38
\begin{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    39
Program refinement works by choosing appropriate code equations
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    40
  explicitly (cf.~\label{sec:equations}); as example, we use Fibonacci
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    41
  numbers:%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    42
\end{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    43
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    44
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    45
\isadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    46
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    47
\endisadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    48
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    49
\isatagquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    50
\isacommand{fun}\isamarkupfalse%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    51
\ fib\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    52
\ \ \ \ {\isachardoublequoteopen}fib\ {\isadigit{0}}\ {\isacharequal}\ {\isadigit{0}}{\isachardoublequoteclose}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    53
\ \ {\isacharbar}\ {\isachardoublequoteopen}fib\ {\isacharparenleft}Suc\ {\isadigit{0}}{\isacharparenright}\ {\isacharequal}\ Suc\ {\isadigit{0}}{\isachardoublequoteclose}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    54
\ \ {\isacharbar}\ {\isachardoublequoteopen}fib\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ fib\ n\ {\isacharplus}\ fib\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isachardoublequoteclose}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    55
\endisatagquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    56
{\isafoldquote}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    57
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    58
\isadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    59
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    60
\endisadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    61
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    62
\begin{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    63
\noindent The runtime of the corresponding code grows exponential due
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    64
  to two recursive calls:%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    65
\end{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    66
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    67
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
    68
\isadelimquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    69
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
    70
\endisadelimquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    71
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
    72
\isatagquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    73
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    74
\begin{isamarkuptext}%
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
    75
fib\ {\isacharcolon}{\isacharcolon}\ Nat\ {\isacharminus}{\isachargreater}\ Nat{\isacharsemicolon}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
    76
fib\ Zero{\isacharunderscore}nat\ {\isacharequal}\ Zero{\isacharunderscore}nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
    77
fib\ {\isacharparenleft}Suc\ Zero{\isacharunderscore}nat{\isacharparenright}\ {\isacharequal}\ Suc\ Zero{\isacharunderscore}nat{\isacharsemicolon}\isanewline
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
    78
fib\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ plus{\isacharunderscore}nat\ {\isacharparenleft}fib\ n{\isacharparenright}\ {\isacharparenleft}fib\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}{\isacharsemicolon}\isanewline%
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    79
\end{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    80
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    81
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
    82
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
    83
{\isafoldquotetypewriter}%
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    84
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
    85
\isadelimquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    86
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
    87
\endisadelimquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    88
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    89
\begin{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    90
\noindent A more efficient implementation would use dynamic
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    91
  programming, e.g.~sharing of common intermediate results between
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    92
  recursive calls.  This idea is expressed by an auxiliary operation
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    93
  which computes a Fibonacci number and its successor simultaneously:%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    94
\end{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    95
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    96
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    97
\isadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    98
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
    99
\endisadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   100
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   101
\isatagquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   102
\isacommand{definition}\isamarkupfalse%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   103
\ fib{\isacharunderscore}step\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat\ {\isasymtimes}\ nat{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   104
\ \ {\isachardoublequoteopen}fib{\isacharunderscore}step\ n\ {\isacharequal}\ {\isacharparenleft}fib\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharcomma}\ fib\ n{\isacharparenright}{\isachardoublequoteclose}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   105
\endisatagquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   106
{\isafoldquote}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   107
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   108
\isadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   109
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   110
\endisadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   111
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   112
\begin{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   113
\noindent This operation can be implemented by recursion using
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   114
  dynamic programming:%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   115
\end{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   116
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   117
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   118
\isadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   119
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   120
\endisadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   121
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   122
\isatagquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   123
\isacommand{lemma}\isamarkupfalse%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   124
\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   125
\ \ {\isachardoublequoteopen}fib{\isacharunderscore}step\ {\isadigit{0}}\ {\isacharequal}\ {\isacharparenleft}Suc\ {\isadigit{0}}{\isacharcomma}\ {\isadigit{0}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   126
\ \ {\isachardoublequoteopen}fib{\isacharunderscore}step\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}let\ {\isacharparenleft}m{\isacharcomma}\ q{\isacharparenright}\ {\isacharequal}\ fib{\isacharunderscore}step\ n\ in\ {\isacharparenleft}m\ {\isacharplus}\ q{\isacharcomma}\ m{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   127
\ \ \isacommand{by}\isamarkupfalse%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   128
\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ fib{\isacharunderscore}step{\isacharunderscore}def{\isacharparenright}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   129
\endisatagquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   130
{\isafoldquote}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   131
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   132
\isadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   133
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   134
\endisadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   135
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   136
\begin{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   137
\noindent What remains is to implement \isa{fib} by \isa{fib{\isacharunderscore}step} as follows:%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   138
\end{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   139
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   140
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   141
\isadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   142
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   143
\endisadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   144
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   145
\isatagquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   146
\isacommand{lemma}\isamarkupfalse%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   147
\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   148
\ \ {\isachardoublequoteopen}fib\ {\isadigit{0}}\ {\isacharequal}\ {\isadigit{0}}{\isachardoublequoteclose}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   149
\ \ {\isachardoublequoteopen}fib\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ fst\ {\isacharparenleft}fib{\isacharunderscore}step\ n{\isacharparenright}{\isachardoublequoteclose}\isanewline
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   150
\ \ \isacommand{by}\isamarkupfalse%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   151
\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ fib{\isacharunderscore}step{\isacharunderscore}def{\isacharparenright}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   152
\endisatagquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   153
{\isafoldquote}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   154
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   155
\isadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   156
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   157
\endisadelimquote
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   158
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   159
\begin{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   160
\noindent The resulting code shows only linear growth of runtime:%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   161
\end{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   162
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   163
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   164
\isadelimquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   165
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   166
\endisadelimquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   167
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   168
\isatagquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   169
%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   170
\begin{isamarkuptext}%
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   171
fib{\isacharunderscore}step\ {\isacharcolon}{\isacharcolon}\ Nat\ {\isacharminus}{\isachargreater}\ {\isacharparenleft}Nat{\isacharcomma}\ Nat{\isacharparenright}{\isacharsemicolon}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   172
fib{\isacharunderscore}step\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ let\ {\isacharbraceleft}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   173
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharparenleft}m{\isacharcomma}\ q{\isacharparenright}\ {\isacharequal}\ fib{\isacharunderscore}step\ n{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   174
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {\isacharbraceright}\ in\ {\isacharparenleft}plus{\isacharunderscore}nat\ m\ q{\isacharcomma}\ m{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   175
fib{\isacharunderscore}step\ Zero{\isacharunderscore}nat\ {\isacharequal}\ {\isacharparenleft}Suc\ Zero{\isacharunderscore}nat{\isacharcomma}\ Zero{\isacharunderscore}nat{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   176
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   177
fib\ {\isacharcolon}{\isacharcolon}\ Nat\ {\isacharminus}{\isachargreater}\ Nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   178
fib\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ fst\ {\isacharparenleft}fib{\isacharunderscore}step\ n{\isacharparenright}{\isacharsemicolon}\isanewline
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   179
fib\ Zero{\isacharunderscore}nat\ {\isacharequal}\ Zero{\isacharunderscore}nat{\isacharsemicolon}\isanewline%
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   180
\end{isamarkuptext}%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   181
\isamarkuptrue%
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   182
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   183
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   184
{\isafoldquotetypewriter}%
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   185
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   186
\isadelimquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   187
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   188
\endisadelimquotetypewriter
38451
4c065e97ecee added section on program refinement
haftmann
parents: 38437
diff changeset
   189
%
38459
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   190
\isamarkupsubsection{Datatype refinement%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   191
}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   192
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   193
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   194
\begin{isamarkuptext}%
38459
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   195
Selecting specific code equations \emph{and} datatype constructors
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   196
  leads to datatype refinement.  As an example, we will develop an
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   197
  alternative representation of the queue example given in
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   198
  \secref{sec:queue_example}.  The amortised representation is
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   199
  convenient for generating code but exposes its \qt{implementation}
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   200
  details, which may be cumbersome when proving theorems about it.
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   201
  Therefore, here is a simple, straightforward representation of
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   202
  queues:%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   203
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   204
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   205
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   206
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   207
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   208
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   209
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   210
\isatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   211
\isacommand{datatype}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   212
\ {\isacharprime}a\ queue\ {\isacharequal}\ Queue\ {\isachardoublequoteopen}{\isacharprime}a\ list{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   213
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   214
\isacommand{definition}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   215
\ empty\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   216
\ \ {\isachardoublequoteopen}empty\ {\isacharequal}\ Queue\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   217
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   218
\isacommand{primrec}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   219
\ enqueue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ queue\ {\isasymRightarrow}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   220
\ \ {\isachardoublequoteopen}enqueue\ x\ {\isacharparenleft}Queue\ xs{\isacharparenright}\ {\isacharequal}\ Queue\ {\isacharparenleft}xs\ {\isacharat}\ {\isacharbrackleft}x{\isacharbrackright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   221
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   222
\isacommand{fun}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   223
\ dequeue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ queue\ {\isasymRightarrow}\ {\isacharprime}a\ option\ {\isasymtimes}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   224
\ \ \ \ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}Queue\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}None{\isacharcomma}\ Queue\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   225
\ \ {\isacharbar}\ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}Queue\ {\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}Some\ x{\isacharcomma}\ Queue\ xs{\isacharparenright}{\isachardoublequoteclose}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   226
\endisatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   227
{\isafoldquote}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   228
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   229
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   230
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   231
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   232
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   233
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   234
\noindent This we can use directly for proving;  for executing,
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   235
  we provide an alternative characterisation:%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   236
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   237
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   238
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   239
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   240
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   241
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   242
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   243
\isatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   244
\isacommand{definition}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   245
\ AQueue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   246
\ \ {\isachardoublequoteopen}AQueue\ xs\ ys\ {\isacharequal}\ Queue\ {\isacharparenleft}ys\ {\isacharat}\ rev\ xs{\isacharparenright}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   247
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   248
\isacommand{code{\isacharunderscore}datatype}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   249
\ AQueue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   250
\endisatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   251
{\isafoldquote}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   252
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   253
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   254
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   255
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   256
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   257
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   258
\noindent Here we define a \qt{constructor} \isa{AQueue} which
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   259
  is defined in terms of \isa{Queue} and interprets its arguments
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   260
  according to what the \emph{content} of an amortised queue is supposed
38459
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   261
  to be.
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   262
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   263
  The prerequisite for datatype constructors is only syntactical: a
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   264
  constructor must be of type \isa{{\isasymtau}\ {\isacharequal}\ {\isasymdots}\ {\isasymRightarrow}\ {\isasymkappa}\ {\isasymalpha}\isactrlisub {\isadigit{1}}\ {\isasymdots}\ {\isasymalpha}\isactrlisub n} where \isa{{\isacharbraceleft}{\isasymalpha}\isactrlisub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharcomma}\ {\isasymalpha}\isactrlisub n{\isacharbraceright}} is exactly the set of \emph{all} type variables in
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   265
  \isa{{\isasymtau}}; then \isa{{\isasymkappa}} is its corresponding datatype.  The
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   266
  HOL datatype package by default registers any new datatype with its
38511
abf95b39d65c use command_def more consciously
haftmann
parents: 38502
diff changeset
   267
  constructors, but this may be changed using \indexdef{}{command}{code\_datatype}\hypertarget{command.code-datatype}{\hyperlink{command.code-datatype}{\mbox{\isa{\isacommand{code{\isacharunderscore}datatype}}}}}; the currently chosen constructors can be inspected
38459
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   268
  using the \hyperlink{command.print-codesetup}{\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}} command.
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   269
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   270
  Equipped with this, we are able to prove the following equations
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   271
  for our primitive queue operations which \qt{implement} the simple
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   272
  queues in an amortised fashion:%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   273
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   274
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   275
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   276
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   277
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   278
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   279
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   280
\isatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   281
\isacommand{lemma}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   282
\ empty{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   283
\ \ {\isachardoublequoteopen}empty\ {\isacharequal}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   284
\ \ \isacommand{unfolding}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   285
\ AQueue{\isacharunderscore}def\ empty{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   286
\ simp\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   287
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   288
\isacommand{lemma}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   289
\ enqueue{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   290
\ \ {\isachardoublequoteopen}enqueue\ x\ {\isacharparenleft}AQueue\ xs\ ys{\isacharparenright}\ {\isacharequal}\ AQueue\ {\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}\ ys{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   291
\ \ \isacommand{unfolding}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   292
\ AQueue{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   293
\ simp\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   294
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   295
\isacommand{lemma}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   296
\ dequeue{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   297
\ \ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   298
\ \ \ \ {\isacharparenleft}if\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ then\ {\isacharparenleft}None{\isacharcomma}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   299
\ \ \ \ else\ dequeue\ {\isacharparenleft}AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharparenleft}rev\ xs{\isacharparenright}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   300
\ \ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharparenleft}y\ {\isacharhash}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}Some\ y{\isacharcomma}\ AQueue\ xs\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   301
\ \ \isacommand{unfolding}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   302
\ AQueue{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   303
\ simp{\isacharunderscore}all%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   304
\endisatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   305
{\isafoldquote}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   306
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   307
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   308
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   309
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   310
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   311
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   312
\noindent For completeness, we provide a substitute for the
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   313
  \isa{case} combinator on queues:%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   314
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   315
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   316
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   317
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   318
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   319
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   320
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   321
\isatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   322
\isacommand{lemma}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   323
\ queue{\isacharunderscore}case{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   324
\ \ {\isachardoublequoteopen}queue{\isacharunderscore}case\ f\ {\isacharparenleft}AQueue\ xs\ ys{\isacharparenright}\ {\isacharequal}\ f\ {\isacharparenleft}ys\ {\isacharat}\ rev\ xs{\isacharparenright}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   325
\ \ \isacommand{unfolding}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   326
\ AQueue{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   327
\ simp%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   328
\endisatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   329
{\isafoldquote}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   330
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   331
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   332
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   333
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   334
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   335
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   336
\noindent The resulting code looks as expected:%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   337
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   338
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   339
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   340
\isadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   341
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   342
\endisadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   343
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   344
\isatagquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   345
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   346
\begin{isamarkuptext}%
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   347
structure\ Example\ {\isacharcolon}\ sig\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   348
\ \ val\ id\ {\isacharcolon}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   349
\ \ val\ fold\ {\isacharcolon}\ {\isacharparenleft}{\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}b\ {\isacharminus}{\isachargreater}\ {\isacharprime}b{\isacharparenright}\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ list\ {\isacharminus}{\isachargreater}\ {\isacharprime}b\ {\isacharminus}{\isachargreater}\ {\isacharprime}b\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   350
\ \ val\ rev\ {\isacharcolon}\ {\isacharprime}a\ list\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ list\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   351
\ \ val\ null\ {\isacharcolon}\ {\isacharprime}a\ list\ {\isacharminus}{\isachargreater}\ bool\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   352
\ \ datatype\ {\isacharprime}a\ queue\ {\isacharequal}\ AQueue\ of\ {\isacharprime}a\ list\ {\isacharasterisk}\ {\isacharprime}a\ list\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   353
\ \ val\ empty\ {\isacharcolon}\ {\isacharprime}a\ queue\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   354
\ \ val\ dequeue\ {\isacharcolon}\ {\isacharprime}a\ queue\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ option\ {\isacharasterisk}\ {\isacharprime}a\ queue\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   355
\ \ val\ enqueue\ {\isacharcolon}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ queue\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ queue\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   356
end\ {\isacharequal}\ struct\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   357
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   358
fun\ id\ x\ {\isacharequal}\ {\isacharparenleft}fn\ xa\ {\isacharequal}{\isachargreater}\ xa{\isacharparenright}\ x{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   359
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   360
fun\ fold\ f\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ id\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   361
\ \ {\isacharbar}\ fold\ f\ {\isacharparenleft}x\ {\isacharcolon}{\isacharcolon}\ xs{\isacharparenright}\ {\isacharequal}\ fold\ f\ xs\ o\ f\ x{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   362
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   363
fun\ rev\ xs\ {\isacharequal}\ fold\ {\isacharparenleft}fn\ a\ {\isacharequal}{\isachargreater}\ fn\ b\ {\isacharequal}{\isachargreater}\ a\ {\isacharcolon}{\isacharcolon}\ b{\isacharparenright}\ xs\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   364
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   365
fun\ null\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ true\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   366
\ \ {\isacharbar}\ null\ {\isacharparenleft}x\ {\isacharcolon}{\isacharcolon}\ xs{\isacharparenright}\ {\isacharequal}\ false{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   367
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   368
datatype\ {\isacharprime}a\ queue\ {\isacharequal}\ AQueue\ of\ {\isacharprime}a\ list\ {\isacharasterisk}\ {\isacharprime}a\ list{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   369
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   370
val\ empty\ {\isacharcolon}\ {\isacharprime}a\ queue\ {\isacharequal}\ AQueue\ {\isacharparenleft}{\isacharbrackleft}{\isacharbrackright}{\isacharcomma}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   371
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   372
fun\ dequeue\ {\isacharparenleft}AQueue\ {\isacharparenleft}xs{\isacharcomma}\ y\ {\isacharcolon}{\isacharcolon}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}SOME\ y{\isacharcomma}\ AQueue\ {\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isacharparenright}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   373
\ \ {\isacharbar}\ dequeue\ {\isacharparenleft}AQueue\ {\isacharparenleft}xs{\isacharcomma}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharparenright}\ {\isacharequal}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   374
\ \ \ \ {\isacharparenleft}if\ null\ xs\ then\ {\isacharparenleft}NONE{\isacharcomma}\ AQueue\ {\isacharparenleft}{\isacharbrackleft}{\isacharbrackright}{\isacharcomma}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharparenright}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   375
\ \ \ \ \ \ else\ dequeue\ {\isacharparenleft}AQueue\ {\isacharparenleft}{\isacharbrackleft}{\isacharbrackright}{\isacharcomma}\ rev\ xs{\isacharparenright}{\isacharparenright}{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   376
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   377
fun\ enqueue\ x\ {\isacharparenleft}AQueue\ {\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ AQueue\ {\isacharparenleft}x\ {\isacharcolon}{\isacharcolon}\ xs{\isacharcomma}\ ys{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   378
\isanewline
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   379
end{\isacharsemicolon}\ {\isacharparenleft}{\isacharasterisk}struct\ Example{\isacharasterisk}{\isacharparenright}\isanewline%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   380
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   381
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   382
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   383
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   384
{\isafoldquotetypewriter}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   385
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   386
\isadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   387
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   388
\endisadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   389
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   390
\begin{isamarkuptext}%
38459
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   391
The same techniques can also be applied to types which are not
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   392
  specified as datatypes, e.g.~type \isa{int} is originally specified
38511
abf95b39d65c use command_def more consciously
haftmann
parents: 38502
diff changeset
   393
  as quotient type by means of \indexdef{}{command}{typedef}\hypertarget{command.typedef}{\hyperlink{command.typedef}{\mbox{\isa{\isacommand{typedef}}}}}, but for code
38459
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   394
  generation constants allowing construction of binary numeral values
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   395
  are used as constructors for \isa{int}.
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   396
38459
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   397
  This approach however fails if the representation of a type demands
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   398
  invariants; this issue is discussed in the next section.%
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   399
\end{isamarkuptext}%
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   400
\isamarkuptrue%
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   401
%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39210
diff changeset
   402
\isamarkupsubsection{Datatype refinement involving invariants \label{sec:invariant}%
38459
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   403
}
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   404
\isamarkuptrue%
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   405
%
cfe74b0eecb1 reworked section on simple datatype refinement
haftmann
parents: 38451
diff changeset
   406
\begin{isamarkuptext}%
38502
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   407
Datatype representation involving invariants require a dedicated
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   408
  setup for the type and its primitive operations.  As a running
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   409
  example, we implement a type \isa{{\isacharprime}a\ dlist} of list consisting
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   410
  of distinct elements.
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   411
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   412
  The first step is to decide on which representation the abstract
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   413
  type (in our example \isa{{\isacharprime}a\ dlist}) should be implemented.
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   414
  Here we choose \isa{{\isacharprime}a\ list}.  Then a conversion from the concrete
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   415
  type to the abstract type must be specified, here:%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   416
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   417
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   418
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   419
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   420
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   421
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   422
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   423
\isatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   424
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   425
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   426
\isa{Dlist\ {\isasymColon}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ dlist}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   427
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   428
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   429
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   430
\endisatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   431
{\isafoldquote}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   432
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   433
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   434
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   435
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   436
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   437
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   438
\noindent Next follows the specification of a suitable \emph{projection},
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   439
  i.e.~a conversion from abstract to concrete type:%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   440
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   441
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   442
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   443
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   444
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   445
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   446
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   447
\isatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   448
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   449
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   450
\isa{list{\isacharunderscore}of{\isacharunderscore}dlist\ {\isasymColon}\ {\isacharprime}a\ dlist\ {\isasymRightarrow}\ {\isacharprime}a\ list}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   451
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   452
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   453
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   454
\endisatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   455
{\isafoldquote}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   456
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   457
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   458
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   459
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   460
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   461
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   462
\noindent This projection must be specified such that the following
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   463
  \emph{abstract datatype certificate} can be proven:%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   464
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   465
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   466
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   467
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   468
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   469
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   470
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   471
\isatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   472
\isacommand{lemma}\isamarkupfalse%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   473
\ {\isacharbrackleft}code\ abstype{\isacharbrackright}{\isacharcolon}\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   474
\ \ {\isachardoublequoteopen}Dlist\ {\isacharparenleft}list{\isacharunderscore}of{\isacharunderscore}dlist\ dxs{\isacharparenright}\ {\isacharequal}\ dxs{\isachardoublequoteclose}\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   475
\ \ \isacommand{by}\isamarkupfalse%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   476
\ {\isacharparenleft}fact\ Dlist{\isacharunderscore}list{\isacharunderscore}of{\isacharunderscore}dlist{\isacharparenright}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   477
\endisatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   478
{\isafoldquote}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   479
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   480
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   481
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   482
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   483
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   484
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   485
\noindent Note that so far the invariant on representations
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   486
  (\isa{distinct\ {\isasymColon}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ bool}) has never been mentioned explicitly:
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   487
  the invariant is only referred to implicitly: all values in
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   488
  set \isa{{\isacharbraceleft}xs{\isachardot}\ list{\isacharunderscore}of{\isacharunderscore}dlist\ {\isacharparenleft}Dlist\ xs{\isacharparenright}\ {\isacharequal}\ xs{\isacharbraceright}} are invariant,
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   489
  and in our example this is exactly \isa{{\isacharbraceleft}xs{\isachardot}\ distinct\ xs{\isacharbraceright}}.
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   490
  
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   491
  The primitive operations on \isa{{\isacharprime}a\ dlist} are specified
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   492
  indirectly using the projection \isa{list{\isacharunderscore}of{\isacharunderscore}dlist}.  For
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   493
  the empty \isa{dlist}, \isa{Dlist{\isachardot}empty}, we finally want
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   494
  the code equation%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   495
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   496
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   497
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   498
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   499
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   500
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   501
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   502
\isatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   503
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   504
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   505
\isa{Dlist{\isachardot}empty\ {\isacharequal}\ Dlist\ {\isacharbrackleft}{\isacharbrackright}}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   506
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   507
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   508
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   509
\endisatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   510
{\isafoldquote}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   511
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   512
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   513
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   514
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   515
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   516
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   517
\noindent This we have to prove indirectly as follows:%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   518
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   519
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   520
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   521
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   522
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   523
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   524
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   525
\isatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   526
\isacommand{lemma}\isamarkupfalse%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   527
\ {\isacharbrackleft}code\ abstract{\isacharbrackright}{\isacharcolon}\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   528
\ \ {\isachardoublequoteopen}list{\isacharunderscore}of{\isacharunderscore}dlist\ Dlist{\isachardot}empty\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   529
\ \ \isacommand{by}\isamarkupfalse%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   530
\ {\isacharparenleft}fact\ list{\isacharunderscore}of{\isacharunderscore}dlist{\isacharunderscore}empty{\isacharparenright}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   531
\endisatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   532
{\isafoldquote}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   533
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   534
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   535
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   536
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   537
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   538
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   539
\noindent This equation logically encodes both the desired code
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   540
  equation and that the expression \isa{Dlist} is applied to obeys
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   541
  the implicit invariant.  Equations for insertion and removal are
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   542
  similar:%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   543
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   544
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   545
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   546
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   547
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   548
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   549
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   550
\isatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   551
\isacommand{lemma}\isamarkupfalse%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   552
\ {\isacharbrackleft}code\ abstract{\isacharbrackright}{\isacharcolon}\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   553
\ \ {\isachardoublequoteopen}list{\isacharunderscore}of{\isacharunderscore}dlist\ {\isacharparenleft}Dlist{\isachardot}insert\ x\ dxs{\isacharparenright}\ {\isacharequal}\ List{\isachardot}insert\ x\ {\isacharparenleft}list{\isacharunderscore}of{\isacharunderscore}dlist\ dxs{\isacharparenright}{\isachardoublequoteclose}\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   554
\ \ \isacommand{by}\isamarkupfalse%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   555
\ {\isacharparenleft}fact\ list{\isacharunderscore}of{\isacharunderscore}dlist{\isacharunderscore}insert{\isacharparenright}\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   556
\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   557
\isacommand{lemma}\isamarkupfalse%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   558
\ {\isacharbrackleft}code\ abstract{\isacharbrackright}{\isacharcolon}\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   559
\ \ {\isachardoublequoteopen}list{\isacharunderscore}of{\isacharunderscore}dlist\ {\isacharparenleft}Dlist{\isachardot}remove\ x\ dxs{\isacharparenright}\ {\isacharequal}\ remove{\isadigit{1}}\ x\ {\isacharparenleft}list{\isacharunderscore}of{\isacharunderscore}dlist\ dxs{\isacharparenright}{\isachardoublequoteclose}\isanewline
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   560
\ \ \isacommand{by}\isamarkupfalse%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   561
\ {\isacharparenleft}fact\ list{\isacharunderscore}of{\isacharunderscore}dlist{\isacharunderscore}remove{\isacharparenright}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   562
\endisatagquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   563
{\isafoldquote}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   564
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   565
\isadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   566
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   567
\endisadelimquote
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   568
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   569
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   570
\noindent Then the corresponding code is as follows:%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   571
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   572
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   573
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   574
\isadelimquotetypewriter
38502
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   575
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   576
\endisadelimquotetypewriter
38502
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   577
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   578
\isatagquotetypewriter
38502
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   579
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   580
\begin{isamarkuptext}%
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   581
module\ Example\ where\ {\isacharbraceleft}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   582
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   583
newtype\ Dlist\ a\ {\isacharequal}\ Dlist\ {\isacharbrackleft}a{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   584
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   585
empty\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ Dlist\ a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   586
empty\ {\isacharequal}\ Dlist\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   587
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   588
member\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ {\isacharparenleft}Eq\ a{\isacharparenright}\ {\isacharequal}{\isachargreater}\ {\isacharbrackleft}a{\isacharbrackright}\ {\isacharminus}{\isachargreater}\ a\ {\isacharminus}{\isachargreater}\ Bool{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   589
member\ {\isacharbrackleft}{\isacharbrackright}\ y\ {\isacharequal}\ False{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   590
member\ {\isacharparenleft}x\ {\isacharcolon}\ xs{\isacharparenright}\ y\ {\isacharequal}\ x\ {\isacharequal}{\isacharequal}\ y\ {\isacharbar}{\isacharbar}\ member\ xs\ y{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   591
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   592
insert\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ {\isacharparenleft}Eq\ a{\isacharparenright}\ {\isacharequal}{\isachargreater}\ a\ {\isacharminus}{\isachargreater}\ {\isacharbrackleft}a{\isacharbrackright}\ {\isacharminus}{\isachargreater}\ {\isacharbrackleft}a{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   593
insert\ x\ xs\ {\isacharequal}\ {\isacharparenleft}if\ member\ xs\ x\ then\ xs\ else\ x\ {\isacharcolon}\ xs{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   594
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   595
list{\isacharunderscore}of{\isacharunderscore}dlist\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ Dlist\ a\ {\isacharminus}{\isachargreater}\ {\isacharbrackleft}a{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   596
list{\isacharunderscore}of{\isacharunderscore}dlist\ {\isacharparenleft}Dlist\ x{\isacharparenright}\ {\isacharequal}\ x{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   597
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   598
inserta\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ {\isacharparenleft}Eq\ a{\isacharparenright}\ {\isacharequal}{\isachargreater}\ a\ {\isacharminus}{\isachargreater}\ Dlist\ a\ {\isacharminus}{\isachargreater}\ Dlist\ a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   599
inserta\ x\ dxs\ {\isacharequal}\ Dlist\ {\isacharparenleft}insert\ x\ {\isacharparenleft}list{\isacharunderscore}of{\isacharunderscore}dlist\ dxs{\isacharparenright}{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   600
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   601
remove{\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ {\isacharparenleft}Eq\ a{\isacharparenright}\ {\isacharequal}{\isachargreater}\ a\ {\isacharminus}{\isachargreater}\ {\isacharbrackleft}a{\isacharbrackright}\ {\isacharminus}{\isachargreater}\ {\isacharbrackleft}a{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   602
remove{\isadigit{1}}\ x\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   603
remove{\isadigit{1}}\ x\ {\isacharparenleft}y\ {\isacharcolon}\ xs{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}if\ x\ {\isacharequal}{\isacharequal}\ y\ then\ xs\ else\ y\ {\isacharcolon}\ remove{\isadigit{1}}\ x\ xs{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   604
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   605
remove\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ {\isacharparenleft}Eq\ a{\isacharparenright}\ {\isacharequal}{\isachargreater}\ a\ {\isacharminus}{\isachargreater}\ Dlist\ a\ {\isacharminus}{\isachargreater}\ Dlist\ a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   606
remove\ x\ dxs\ {\isacharequal}\ Dlist\ {\isacharparenleft}remove{\isadigit{1}}\ x\ {\isacharparenleft}list{\isacharunderscore}of{\isacharunderscore}dlist\ dxs{\isacharparenright}{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39599
diff changeset
   607
\isanewline
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   608
{\isacharbraceright}\isanewline%
38502
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   609
\end{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   610
\isamarkuptrue%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   611
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   612
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   613
{\isafoldquotetypewriter}%
38502
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   614
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   615
\isadelimquotetypewriter
38502
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   616
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   617
\endisadelimquotetypewriter
38502
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   618
%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   619
\begin{isamarkuptext}%
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   620
Typical data structures implemented by representations involving
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   621
  invariants are available in the library, e.g.~theories \hyperlink{theory.Fset}{\mbox{\isa{Fset}}} and \hyperlink{theory.Mapping}{\mbox{\isa{Mapping}}} specify sets (type \isa{{\isacharprime}a\ fset}) and
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   622
  key-value-mappings (type \isa{{\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isacharprime}b{\isacharparenright}\ mapping}) respectively;
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   623
  these can be implemented by distinct lists as presented here as
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   624
  example (theory \hyperlink{theory.Dlist}{\mbox{\isa{Dlist}}}) and red-black-trees respectively
c4b7ae8ea82e added quick and dirty section on invariants
haftmann
parents: 38459
diff changeset
   625
  (theory \hyperlink{theory.RBT}{\mbox{\isa{RBT}}}).%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   626
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   627
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   628
%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   629
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   630
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   631
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   632
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   633
\isatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   634
\isacommand{end}\isamarkupfalse%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   635
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   636
\endisatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   637
{\isafoldtheory}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   638
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   639
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   640
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   641
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   642
\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   643
\end{isabellebody}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   644
%%% Local Variables:
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   645
%%% mode: latex
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   646
%%% TeX-master: "root"
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   647
%%% End: