doc-src/Codegen/Thy/document/Program.tex
author haftmann
Wed, 23 Dec 2009 08:31:15 +0100
changeset 34173 458ced35abb8
parent 33926 dd017d9db05f
child 34155 14aaccb399b3
permissions -rw-r--r--
reduced code generator cache to the baremost minimum
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28447
haftmann
parents:
diff changeset
     1
%
haftmann
parents:
diff changeset
     2
\begin{isabellebody}%
haftmann
parents:
diff changeset
     3
\def\isabellecontext{Program}%
haftmann
parents:
diff changeset
     4
%
haftmann
parents:
diff changeset
     5
\isadelimtheory
haftmann
parents:
diff changeset
     6
%
haftmann
parents:
diff changeset
     7
\endisadelimtheory
haftmann
parents:
diff changeset
     8
%
haftmann
parents:
diff changeset
     9
\isatagtheory
haftmann
parents:
diff changeset
    10
\isacommand{theory}\isamarkupfalse%
haftmann
parents:
diff changeset
    11
\ Program\isanewline
haftmann
parents:
diff changeset
    12
\isakeyword{imports}\ Introduction\isanewline
haftmann
parents:
diff changeset
    13
\isakeyword{begin}%
haftmann
parents:
diff changeset
    14
\endisatagtheory
haftmann
parents:
diff changeset
    15
{\isafoldtheory}%
haftmann
parents:
diff changeset
    16
%
haftmann
parents:
diff changeset
    17
\isadelimtheory
haftmann
parents:
diff changeset
    18
%
haftmann
parents:
diff changeset
    19
\endisadelimtheory
haftmann
parents:
diff changeset
    20
%
haftmann
parents:
diff changeset
    21
\isamarkupsection{Turning Theories into Programs \label{sec:program}%
haftmann
parents:
diff changeset
    22
}
haftmann
parents:
diff changeset
    23
\isamarkuptrue%
haftmann
parents:
diff changeset
    24
%
haftmann
parents:
diff changeset
    25
\isamarkupsubsection{The \isa{Isabelle{\isacharslash}HOL} default setup%
haftmann
parents:
diff changeset
    26
}
haftmann
parents:
diff changeset
    27
\isamarkuptrue%
haftmann
parents:
diff changeset
    28
%
haftmann
parents:
diff changeset
    29
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
    30
We have already seen how by default equations stemming from
haftmann
parents:
diff changeset
    31
  \hyperlink{command.definition}{\mbox{\isa{\isacommand{definition}}}}/\hyperlink{command.primrec}{\mbox{\isa{\isacommand{primrec}}}}/\hyperlink{command.fun}{\mbox{\isa{\isacommand{fun}}}}
haftmann
parents:
diff changeset
    32
  statements are used for code generation.  This default behaviour
29560
fa6c5d62adf5 "code equation" replaces "defining equation"
haftmann
parents: 29297
diff changeset
    33
  can be changed, e.g. by providing different code equations.
28593
f087237af65d continued codegen tutorial
haftmann
parents: 28564
diff changeset
    34
  All kinds of customisation shown in this section is \emph{safe}
28447
haftmann
parents:
diff changeset
    35
  in the sense that the user does not have to worry about
haftmann
parents:
diff changeset
    36
  correctness -- all programs generatable that way are partially
haftmann
parents:
diff changeset
    37
  correct.%
haftmann
parents:
diff changeset
    38
\end{isamarkuptext}%
haftmann
parents:
diff changeset
    39
\isamarkuptrue%
haftmann
parents:
diff changeset
    40
%
haftmann
parents:
diff changeset
    41
\isamarkupsubsection{Selecting code equations%
haftmann
parents:
diff changeset
    42
}
haftmann
parents:
diff changeset
    43
\isamarkuptrue%
haftmann
parents:
diff changeset
    44
%
haftmann
parents:
diff changeset
    45
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
    46
Coming back to our introductory example, we
29560
fa6c5d62adf5 "code equation" replaces "defining equation"
haftmann
parents: 29297
diff changeset
    47
  could provide an alternative code equations for \isa{dequeue}
28447
haftmann
parents:
diff changeset
    48
  explicitly:%
haftmann
parents:
diff changeset
    49
\end{isamarkuptext}%
haftmann
parents:
diff changeset
    50
\isamarkuptrue%
haftmann
parents:
diff changeset
    51
%
28564
haftmann
parents: 28562
diff changeset
    52
\isadelimquote
28447
haftmann
parents:
diff changeset
    53
%
28564
haftmann
parents: 28562
diff changeset
    54
\endisadelimquote
28447
haftmann
parents:
diff changeset
    55
%
28564
haftmann
parents: 28562
diff changeset
    56
\isatagquote
28447
haftmann
parents:
diff changeset
    57
\isacommand{lemma}\isamarkupfalse%
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28462
diff changeset
    58
\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    59
\ \ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    60
\ \ \ \ \ {\isacharparenleft}if\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ then\ {\isacharparenleft}None{\isacharcomma}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    61
\ \ \ \ \ \ \ else\ dequeue\ {\isacharparenleft}AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharparenleft}rev\ xs{\isacharparenright}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    62
\ \ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharparenleft}y\ {\isacharhash}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    63
\ \ \ \ \ {\isacharparenleft}Some\ y{\isacharcomma}\ AQueue\ xs\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
28447
haftmann
parents:
diff changeset
    64
\ \ \isacommand{by}\isamarkupfalse%
haftmann
parents:
diff changeset
    65
\ {\isacharparenleft}cases\ xs{\isacharcomma}\ simp{\isacharunderscore}all{\isacharparenright}\ {\isacharparenleft}cases\ {\isachardoublequoteopen}rev\ xs{\isachardoublequoteclose}{\isacharcomma}\ simp{\isacharunderscore}all{\isacharparenright}%
28564
haftmann
parents: 28562
diff changeset
    66
\endisatagquote
haftmann
parents: 28562
diff changeset
    67
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
    68
%
28564
haftmann
parents: 28562
diff changeset
    69
\isadelimquote
28447
haftmann
parents:
diff changeset
    70
%
28564
haftmann
parents: 28562
diff changeset
    71
\endisadelimquote
28447
haftmann
parents:
diff changeset
    72
%
haftmann
parents:
diff changeset
    73
\begin{isamarkuptext}%
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28462
diff changeset
    74
\noindent The annotation \isa{{\isacharbrackleft}code{\isacharbrackright}} is an \isa{Isar}
28447
haftmann
parents:
diff changeset
    75
  \isa{attribute} which states that the given theorems should be
29560
fa6c5d62adf5 "code equation" replaces "defining equation"
haftmann
parents: 29297
diff changeset
    76
  considered as code equations for a \isa{fun} statement --
28447
haftmann
parents:
diff changeset
    77
  the corresponding constant is determined syntactically.  The resulting code:%
haftmann
parents:
diff changeset
    78
\end{isamarkuptext}%
haftmann
parents:
diff changeset
    79
\isamarkuptrue%
haftmann
parents:
diff changeset
    80
%
28564
haftmann
parents: 28562
diff changeset
    81
\isadelimquote
28447
haftmann
parents:
diff changeset
    82
%
28564
haftmann
parents: 28562
diff changeset
    83
\endisadelimquote
28447
haftmann
parents:
diff changeset
    84
%
28564
haftmann
parents: 28562
diff changeset
    85
\isatagquote
28447
haftmann
parents:
diff changeset
    86
%
haftmann
parents:
diff changeset
    87
\begin{isamarkuptext}%
28727
185110a4b97a clarified verbatim vs. typewriter
haftmann
parents: 28714
diff changeset
    88
\isatypewriter%
28447
haftmann
parents:
diff changeset
    89
\noindent%
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28727
diff changeset
    90
\hspace*{0pt}dequeue ::~forall a.~Queue a -> (Maybe a,~Queue a);\\
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    91
\hspace*{0pt}dequeue (AQueue xs (y :~ys)) = (Just y,~AQueue xs ys);\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    92
\hspace*{0pt}dequeue (AQueue xs []) =\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    93
\hspace*{0pt} ~(if nulla xs then (Nothing,~AQueue [] [])\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    94
\hspace*{0pt} ~~~else dequeue (AQueue [] (rev xs)));%
28447
haftmann
parents:
diff changeset
    95
\end{isamarkuptext}%
haftmann
parents:
diff changeset
    96
\isamarkuptrue%
haftmann
parents:
diff changeset
    97
%
28564
haftmann
parents: 28562
diff changeset
    98
\endisatagquote
haftmann
parents: 28562
diff changeset
    99
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   100
%
28564
haftmann
parents: 28562
diff changeset
   101
\isadelimquote
28447
haftmann
parents:
diff changeset
   102
%
28564
haftmann
parents: 28562
diff changeset
   103
\endisadelimquote
28447
haftmann
parents:
diff changeset
   104
%
haftmann
parents:
diff changeset
   105
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   106
\noindent You may note that the equality test \isa{xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}} has been
haftmann
parents:
diff changeset
   107
  replaced by the predicate \isa{null\ xs}.  This is due to the default
haftmann
parents:
diff changeset
   108
  setup in the \qn{preprocessor} to be discussed further below (\secref{sec:preproc}).
haftmann
parents:
diff changeset
   109
haftmann
parents:
diff changeset
   110
  Changing the default constructor set of datatypes is also
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   111
  possible.  See \secref{sec:datatypes} for an example.
28447
haftmann
parents:
diff changeset
   112
haftmann
parents:
diff changeset
   113
  As told in \secref{sec:concept}, code generation is based
haftmann
parents:
diff changeset
   114
  on a structured collection of code theorems.
haftmann
parents:
diff changeset
   115
  For explorative purpose, this collection
haftmann
parents:
diff changeset
   116
  may be inspected using the \hyperlink{command.code-thms}{\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}} command:%
haftmann
parents:
diff changeset
   117
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   118
\isamarkuptrue%
haftmann
parents:
diff changeset
   119
%
28564
haftmann
parents: 28562
diff changeset
   120
\isadelimquote
28447
haftmann
parents:
diff changeset
   121
%
28564
haftmann
parents: 28562
diff changeset
   122
\endisadelimquote
28447
haftmann
parents:
diff changeset
   123
%
28564
haftmann
parents: 28562
diff changeset
   124
\isatagquote
28447
haftmann
parents:
diff changeset
   125
\isacommand{code{\isacharunderscore}thms}\isamarkupfalse%
haftmann
parents:
diff changeset
   126
\ dequeue%
28564
haftmann
parents: 28562
diff changeset
   127
\endisatagquote
haftmann
parents: 28562
diff changeset
   128
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   129
%
28564
haftmann
parents: 28562
diff changeset
   130
\isadelimquote
28447
haftmann
parents:
diff changeset
   131
%
28564
haftmann
parents: 28562
diff changeset
   132
\endisadelimquote
28447
haftmann
parents:
diff changeset
   133
%
haftmann
parents:
diff changeset
   134
\begin{isamarkuptext}%
29560
fa6c5d62adf5 "code equation" replaces "defining equation"
haftmann
parents: 29297
diff changeset
   135
\noindent prints a table with \emph{all} code equations
28447
haftmann
parents:
diff changeset
   136
  for \isa{dequeue}, including
29560
fa6c5d62adf5 "code equation" replaces "defining equation"
haftmann
parents: 29297
diff changeset
   137
  \emph{all} code equations those equations depend
28447
haftmann
parents:
diff changeset
   138
  on recursively.
haftmann
parents:
diff changeset
   139
  
haftmann
parents:
diff changeset
   140
  Similarly, the \hyperlink{command.code-deps}{\mbox{\isa{\isacommand{code{\isacharunderscore}deps}}}} command shows a graph
29560
fa6c5d62adf5 "code equation" replaces "defining equation"
haftmann
parents: 29297
diff changeset
   141
  visualising dependencies between code equations.%
28447
haftmann
parents:
diff changeset
   142
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   143
\isamarkuptrue%
haftmann
parents:
diff changeset
   144
%
haftmann
parents:
diff changeset
   145
\isamarkupsubsection{\isa{class} and \isa{instantiation}%
haftmann
parents:
diff changeset
   146
}
haftmann
parents:
diff changeset
   147
\isamarkuptrue%
haftmann
parents:
diff changeset
   148
%
haftmann
parents:
diff changeset
   149
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   150
Concerning type classes and code generation, let us examine an example
haftmann
parents:
diff changeset
   151
  from abstract algebra:%
haftmann
parents:
diff changeset
   152
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   153
\isamarkuptrue%
haftmann
parents:
diff changeset
   154
%
28564
haftmann
parents: 28562
diff changeset
   155
\isadelimquote
28447
haftmann
parents:
diff changeset
   156
%
28564
haftmann
parents: 28562
diff changeset
   157
\endisadelimquote
28447
haftmann
parents:
diff changeset
   158
%
28564
haftmann
parents: 28562
diff changeset
   159
\isatagquote
28447
haftmann
parents:
diff changeset
   160
\isacommand{class}\isamarkupfalse%
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   161
\ semigroup\ {\isacharequal}\isanewline
28447
haftmann
parents:
diff changeset
   162
\ \ \isakeyword{fixes}\ mult\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymotimes}{\isachardoublequoteclose}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}\isanewline
haftmann
parents:
diff changeset
   163
\ \ \isakeyword{assumes}\ assoc{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isasymotimes}\ z\ {\isacharequal}\ x\ {\isasymotimes}\ {\isacharparenleft}y\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   164
\isanewline
haftmann
parents:
diff changeset
   165
\isacommand{class}\isamarkupfalse%
haftmann
parents:
diff changeset
   166
\ monoid\ {\isacharequal}\ semigroup\ {\isacharplus}\isanewline
haftmann
parents:
diff changeset
   167
\ \ \isakeyword{fixes}\ neutral\ {\isacharcolon}{\isacharcolon}\ {\isacharprime}a\ {\isacharparenleft}{\isachardoublequoteopen}{\isasymone}{\isachardoublequoteclose}{\isacharparenright}\isanewline
haftmann
parents:
diff changeset
   168
\ \ \isakeyword{assumes}\ neutl{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ x\ {\isacharequal}\ x{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   169
\ \ \ \ \isakeyword{and}\ neutr{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   170
\isanewline
haftmann
parents:
diff changeset
   171
\isacommand{instantiation}\isamarkupfalse%
haftmann
parents:
diff changeset
   172
\ nat\ {\isacharcolon}{\isacharcolon}\ monoid\isanewline
haftmann
parents:
diff changeset
   173
\isakeyword{begin}\isanewline
haftmann
parents:
diff changeset
   174
\isanewline
haftmann
parents:
diff changeset
   175
\isacommand{primrec}\isamarkupfalse%
haftmann
parents:
diff changeset
   176
\ mult{\isacharunderscore}nat\ \isakeyword{where}\isanewline
haftmann
parents:
diff changeset
   177
\ \ \ \ {\isachardoublequoteopen}{\isadigit{0}}\ {\isasymotimes}\ n\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   178
\ \ {\isacharbar}\ {\isachardoublequoteopen}Suc\ m\ {\isasymotimes}\ n\ {\isacharequal}\ n\ {\isacharplus}\ m\ {\isasymotimes}\ n{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   179
\isanewline
haftmann
parents:
diff changeset
   180
\isacommand{definition}\isamarkupfalse%
haftmann
parents:
diff changeset
   181
\ neutral{\isacharunderscore}nat\ \isakeyword{where}\isanewline
haftmann
parents:
diff changeset
   182
\ \ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ Suc\ {\isadigit{0}}{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   183
\isanewline
haftmann
parents:
diff changeset
   184
\isacommand{lemma}\isamarkupfalse%
haftmann
parents:
diff changeset
   185
\ add{\isacharunderscore}mult{\isacharunderscore}distrib{\isacharcolon}\isanewline
haftmann
parents:
diff changeset
   186
\ \ \isakeyword{fixes}\ n\ m\ q\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
haftmann
parents:
diff changeset
   187
\ \ \isakeyword{shows}\ {\isachardoublequoteopen}{\isacharparenleft}n\ {\isacharplus}\ m{\isacharparenright}\ {\isasymotimes}\ q\ {\isacharequal}\ n\ {\isasymotimes}\ q\ {\isacharplus}\ m\ {\isasymotimes}\ q{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   188
\ \ \isacommand{by}\isamarkupfalse%
haftmann
parents:
diff changeset
   189
\ {\isacharparenleft}induct\ n{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
haftmann
parents:
diff changeset
   190
\isanewline
haftmann
parents:
diff changeset
   191
\isacommand{instance}\isamarkupfalse%
haftmann
parents:
diff changeset
   192
\ \isacommand{proof}\isamarkupfalse%
haftmann
parents:
diff changeset
   193
\isanewline
haftmann
parents:
diff changeset
   194
\ \ \isacommand{fix}\isamarkupfalse%
haftmann
parents:
diff changeset
   195
\ m\ n\ q\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
haftmann
parents:
diff changeset
   196
\ \ \isacommand{show}\isamarkupfalse%
haftmann
parents:
diff changeset
   197
\ {\isachardoublequoteopen}m\ {\isasymotimes}\ n\ {\isasymotimes}\ q\ {\isacharequal}\ m\ {\isasymotimes}\ {\isacharparenleft}n\ {\isasymotimes}\ q{\isacharparenright}{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   198
\ \ \ \ \isacommand{by}\isamarkupfalse%
haftmann
parents:
diff changeset
   199
\ {\isacharparenleft}induct\ m{\isacharparenright}\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ add{\isacharunderscore}mult{\isacharunderscore}distrib{\isacharparenright}\isanewline
haftmann
parents:
diff changeset
   200
\ \ \isacommand{show}\isamarkupfalse%
haftmann
parents:
diff changeset
   201
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   202
\ \ \ \ \isacommand{by}\isamarkupfalse%
haftmann
parents:
diff changeset
   203
\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutral{\isacharunderscore}nat{\isacharunderscore}def{\isacharparenright}\isanewline
haftmann
parents:
diff changeset
   204
\ \ \isacommand{show}\isamarkupfalse%
haftmann
parents:
diff changeset
   205
\ {\isachardoublequoteopen}m\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ m{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   206
\ \ \ \ \isacommand{by}\isamarkupfalse%
haftmann
parents:
diff changeset
   207
\ {\isacharparenleft}induct\ m{\isacharparenright}\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ neutral{\isacharunderscore}nat{\isacharunderscore}def{\isacharparenright}\isanewline
haftmann
parents:
diff changeset
   208
\isacommand{qed}\isamarkupfalse%
haftmann
parents:
diff changeset
   209
\isanewline
haftmann
parents:
diff changeset
   210
\isanewline
haftmann
parents:
diff changeset
   211
\isacommand{end}\isamarkupfalse%
haftmann
parents:
diff changeset
   212
%
28564
haftmann
parents: 28562
diff changeset
   213
\endisatagquote
haftmann
parents: 28562
diff changeset
   214
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   215
%
28564
haftmann
parents: 28562
diff changeset
   216
\isadelimquote
28447
haftmann
parents:
diff changeset
   217
%
28564
haftmann
parents: 28562
diff changeset
   218
\endisadelimquote
28447
haftmann
parents:
diff changeset
   219
%
haftmann
parents:
diff changeset
   220
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   221
\noindent We define the natural operation of the natural numbers
haftmann
parents:
diff changeset
   222
  on monoids:%
haftmann
parents:
diff changeset
   223
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   224
\isamarkuptrue%
haftmann
parents:
diff changeset
   225
%
28564
haftmann
parents: 28562
diff changeset
   226
\isadelimquote
28447
haftmann
parents:
diff changeset
   227
%
28564
haftmann
parents: 28562
diff changeset
   228
\endisadelimquote
28447
haftmann
parents:
diff changeset
   229
%
28564
haftmann
parents: 28562
diff changeset
   230
\isatagquote
28447
haftmann
parents:
diff changeset
   231
\isacommand{primrec}\isamarkupfalse%
haftmann
parents:
diff changeset
   232
\ {\isacharparenleft}\isakeyword{in}\ monoid{\isacharparenright}\ pow\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
haftmann
parents:
diff changeset
   233
\ \ \ \ {\isachardoublequoteopen}pow\ {\isadigit{0}}\ a\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   234
\ \ {\isacharbar}\ {\isachardoublequoteopen}pow\ {\isacharparenleft}Suc\ n{\isacharparenright}\ a\ {\isacharequal}\ a\ {\isasymotimes}\ pow\ n\ a{\isachardoublequoteclose}%
28564
haftmann
parents: 28562
diff changeset
   235
\endisatagquote
haftmann
parents: 28562
diff changeset
   236
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   237
%
28564
haftmann
parents: 28562
diff changeset
   238
\isadelimquote
28447
haftmann
parents:
diff changeset
   239
%
28564
haftmann
parents: 28562
diff changeset
   240
\endisadelimquote
28447
haftmann
parents:
diff changeset
   241
%
haftmann
parents:
diff changeset
   242
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   243
\noindent This we use to define the discrete exponentiation function:%
haftmann
parents:
diff changeset
   244
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   245
\isamarkuptrue%
haftmann
parents:
diff changeset
   246
%
28564
haftmann
parents: 28562
diff changeset
   247
\isadelimquote
28447
haftmann
parents:
diff changeset
   248
%
28564
haftmann
parents: 28562
diff changeset
   249
\endisadelimquote
28447
haftmann
parents:
diff changeset
   250
%
28564
haftmann
parents: 28562
diff changeset
   251
\isatagquote
28447
haftmann
parents:
diff changeset
   252
\isacommand{definition}\isamarkupfalse%
haftmann
parents:
diff changeset
   253
\ bexp\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
haftmann
parents:
diff changeset
   254
\ \ {\isachardoublequoteopen}bexp\ n\ {\isacharequal}\ pow\ n\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ {\isadigit{0}}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}%
28564
haftmann
parents: 28562
diff changeset
   255
\endisatagquote
haftmann
parents: 28562
diff changeset
   256
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   257
%
28564
haftmann
parents: 28562
diff changeset
   258
\isadelimquote
28447
haftmann
parents:
diff changeset
   259
%
28564
haftmann
parents: 28562
diff changeset
   260
\endisadelimquote
28447
haftmann
parents:
diff changeset
   261
%
haftmann
parents:
diff changeset
   262
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   263
\noindent The corresponding code:%
haftmann
parents:
diff changeset
   264
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   265
\isamarkuptrue%
haftmann
parents:
diff changeset
   266
%
28564
haftmann
parents: 28562
diff changeset
   267
\isadelimquote
28447
haftmann
parents:
diff changeset
   268
%
28564
haftmann
parents: 28562
diff changeset
   269
\endisadelimquote
28447
haftmann
parents:
diff changeset
   270
%
28564
haftmann
parents: 28562
diff changeset
   271
\isatagquote
28447
haftmann
parents:
diff changeset
   272
%
haftmann
parents:
diff changeset
   273
\begin{isamarkuptext}%
28727
185110a4b97a clarified verbatim vs. typewriter
haftmann
parents: 28714
diff changeset
   274
\isatypewriter%
28447
haftmann
parents:
diff changeset
   275
\noindent%
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   276
\hspace*{0pt}module Example where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   277
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   278
\hspace*{0pt}\\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29798
diff changeset
   279
\hspace*{0pt}data Nat = Zero{\char95}nat | Suc Nat;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   280
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   281
\hspace*{0pt}class Semigroup a where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   282
\hspace*{0pt} ~mult ::~a -> a -> a;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   283
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   284
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   285
\hspace*{0pt}class (Semigroup a) => Monoid a where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   286
\hspace*{0pt} ~neutral ::~a;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   287
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   288
\hspace*{0pt}\\
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28727
diff changeset
   289
\hspace*{0pt}pow ::~forall a.~(Monoid a) => Nat -> a -> a;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   290
\hspace*{0pt}pow Zero{\char95}nat a = neutral;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   291
\hspace*{0pt}pow (Suc n) a = mult a (pow n a);\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   292
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   293
\hspace*{0pt}plus{\char95}nat ::~Nat -> Nat -> Nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   294
\hspace*{0pt}plus{\char95}nat (Suc m) n = plus{\char95}nat m (Suc n);\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   295
\hspace*{0pt}plus{\char95}nat Zero{\char95}nat n = n;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   296
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   297
\hspace*{0pt}neutral{\char95}nat ::~Nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   298
\hspace*{0pt}neutral{\char95}nat = Suc Zero{\char95}nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   299
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   300
\hspace*{0pt}mult{\char95}nat ::~Nat -> Nat -> Nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   301
\hspace*{0pt}mult{\char95}nat Zero{\char95}nat n = Zero{\char95}nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   302
\hspace*{0pt}mult{\char95}nat (Suc m) n = plus{\char95}nat n (mult{\char95}nat m n);\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   303
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   304
\hspace*{0pt}instance Semigroup Nat where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   305
\hspace*{0pt} ~mult = mult{\char95}nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   306
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   307
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   308
\hspace*{0pt}instance Monoid Nat where {\char123}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   309
\hspace*{0pt} ~neutral = neutral{\char95}nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   310
\hspace*{0pt}{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   311
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   312
\hspace*{0pt}bexp ::~Nat -> Nat;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   313
\hspace*{0pt}bexp n = pow n (Suc (Suc Zero{\char95}nat));\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   314
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   315
\hspace*{0pt}{\char125}%
28447
haftmann
parents:
diff changeset
   316
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   317
\isamarkuptrue%
haftmann
parents:
diff changeset
   318
%
28564
haftmann
parents: 28562
diff changeset
   319
\endisatagquote
haftmann
parents: 28562
diff changeset
   320
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   321
%
28564
haftmann
parents: 28562
diff changeset
   322
\isadelimquote
28447
haftmann
parents:
diff changeset
   323
%
28564
haftmann
parents: 28562
diff changeset
   324
\endisadelimquote
28447
haftmann
parents:
diff changeset
   325
%
haftmann
parents:
diff changeset
   326
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   327
\noindent This is a convenient place to show how explicit dictionary construction
haftmann
parents:
diff changeset
   328
  manifests in generated code (here, the same example in \isa{SML}):%
haftmann
parents:
diff changeset
   329
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   330
\isamarkuptrue%
haftmann
parents:
diff changeset
   331
%
28564
haftmann
parents: 28562
diff changeset
   332
\isadelimquote
28447
haftmann
parents:
diff changeset
   333
%
28564
haftmann
parents: 28562
diff changeset
   334
\endisadelimquote
28447
haftmann
parents:
diff changeset
   335
%
28564
haftmann
parents: 28562
diff changeset
   336
\isatagquote
28447
haftmann
parents:
diff changeset
   337
%
haftmann
parents:
diff changeset
   338
\begin{isamarkuptext}%
28727
185110a4b97a clarified verbatim vs. typewriter
haftmann
parents: 28714
diff changeset
   339
\isatypewriter%
28447
haftmann
parents:
diff changeset
   340
\noindent%
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   341
\hspace*{0pt}structure Example = \\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   342
\hspace*{0pt}struct\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   343
\hspace*{0pt}\\
30121
5c7bcb296600 updated generated files;
wenzelm
parents: 29798
diff changeset
   344
\hspace*{0pt}datatype nat = Zero{\char95}nat | Suc of nat;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   345
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   346
\hspace*{0pt}type 'a semigroup = {\char123}mult :~'a -> 'a -> 'a{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   347
\hspace*{0pt}fun mult (A{\char95}:'a semigroup) = {\char35}mult A{\char95};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   348
\hspace*{0pt}\\
31544
19b77b1de188 updated generated files;
wenzelm
parents: 31254
diff changeset
   349
\hspace*{0pt}type 'a monoid = {\char123}semigroup{\char95}monoid :~'a semigroup,~neutral :~'a{\char125};\\
19b77b1de188 updated generated files;
wenzelm
parents: 31254
diff changeset
   350
\hspace*{0pt}fun semigroup{\char95}monoid (A{\char95}:'a monoid) = {\char35}semigroup{\char95}monoid A{\char95};\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   351
\hspace*{0pt}fun neutral (A{\char95}:'a monoid) = {\char35}neutral A{\char95};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   352
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   353
\hspace*{0pt}fun pow A{\char95}~Zero{\char95}nat a = neutral A{\char95}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   354
\hspace*{0pt} ~| pow A{\char95}~(Suc n) a = mult (semigroup{\char95}monoid A{\char95}) a (pow A{\char95}~n a);\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   355
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   356
\hspace*{0pt}fun plus{\char95}nat (Suc m) n = plus{\char95}nat m (Suc n)\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   357
\hspace*{0pt} ~| plus{\char95}nat Zero{\char95}nat n = n;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   358
\hspace*{0pt}\\
33707
68841fb382e0 dropped obsolete documentation; updated generated sources
haftmann
parents: 32000
diff changeset
   359
\hspace*{0pt}val neutral{\char95}nat :~nat = Suc Zero{\char95}nat;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   360
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   361
\hspace*{0pt}fun mult{\char95}nat Zero{\char95}nat n = Zero{\char95}nat\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   362
\hspace*{0pt} ~| mult{\char95}nat (Suc m) n = plus{\char95}nat n (mult{\char95}nat m n);\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   363
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   364
\hspace*{0pt}val semigroup{\char95}nat = {\char123}mult = mult{\char95}nat{\char125}~:~nat semigroup;\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   365
\hspace*{0pt}\\
31544
19b77b1de188 updated generated files;
wenzelm
parents: 31254
diff changeset
   366
\hspace*{0pt}val monoid{\char95}nat = {\char123}semigroup{\char95}monoid = semigroup{\char95}nat,~neutral = neutral{\char95}nat{\char125}\\
19b77b1de188 updated generated files;
wenzelm
parents: 31254
diff changeset
   367
\hspace*{0pt} ~:~nat monoid;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   368
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   369
\hspace*{0pt}fun bexp n = pow monoid{\char95}nat n (Suc (Suc Zero{\char95}nat));\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   370
\hspace*{0pt}\\
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28727
diff changeset
   371
\hspace*{0pt}end;~(*struct Example*)%
28447
haftmann
parents:
diff changeset
   372
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   373
\isamarkuptrue%
haftmann
parents:
diff changeset
   374
%
28564
haftmann
parents: 28562
diff changeset
   375
\endisatagquote
haftmann
parents: 28562
diff changeset
   376
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   377
%
28564
haftmann
parents: 28562
diff changeset
   378
\isadelimquote
28447
haftmann
parents:
diff changeset
   379
%
28564
haftmann
parents: 28562
diff changeset
   380
\endisadelimquote
28447
haftmann
parents:
diff changeset
   381
%
haftmann
parents:
diff changeset
   382
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   383
\noindent Note the parameters with trailing underscore (\verb|A_|)
haftmann
parents:
diff changeset
   384
    which are the dictionary parameters.%
haftmann
parents:
diff changeset
   385
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   386
\isamarkuptrue%
haftmann
parents:
diff changeset
   387
%
haftmann
parents:
diff changeset
   388
\isamarkupsubsection{The preprocessor \label{sec:preproc}%
haftmann
parents:
diff changeset
   389
}
haftmann
parents:
diff changeset
   390
\isamarkuptrue%
haftmann
parents:
diff changeset
   391
%
haftmann
parents:
diff changeset
   392
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   393
Before selected function theorems are turned into abstract
haftmann
parents:
diff changeset
   394
  code, a chain of definitional transformation steps is carried
haftmann
parents:
diff changeset
   395
  out: \emph{preprocessing}.  In essence, the preprocessor
haftmann
parents:
diff changeset
   396
  consists of two components: a \emph{simpset} and \emph{function transformers}.
haftmann
parents:
diff changeset
   397
32000
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   398
  The \emph{simpset} allows to employ the full generality of the
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   399
  Isabelle simplifier.  Due to the interpretation of theorems as code
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   400
  equations, rewrites are applied to the right hand side and the
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   401
  arguments of the left hand side of an equation, but never to the
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   402
  constant heading the left hand side.  An important special case are
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   403
  \emph{unfold theorems} which may be declared and undeclared using
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   404
  the \hyperlink{attribute.code-unfold}{\mbox{\isa{code{\isacharunderscore}unfold}}} or \emph{\hyperlink{attribute.code-unfold}{\mbox{\isa{code{\isacharunderscore}unfold}}} del}
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   405
  attribute respectively.
28447
haftmann
parents:
diff changeset
   406
haftmann
parents:
diff changeset
   407
  Some common applications:%
haftmann
parents:
diff changeset
   408
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   409
\isamarkuptrue%
haftmann
parents:
diff changeset
   410
%
haftmann
parents:
diff changeset
   411
\begin{itemize}
haftmann
parents:
diff changeset
   412
%
haftmann
parents:
diff changeset
   413
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   414
\item replacing non-executable constructs by executable ones:%
haftmann
parents:
diff changeset
   415
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   416
\isamarkuptrue%
haftmann
parents:
diff changeset
   417
%
28564
haftmann
parents: 28562
diff changeset
   418
\isadelimquote
28447
haftmann
parents:
diff changeset
   419
%
28564
haftmann
parents: 28562
diff changeset
   420
\endisadelimquote
28447
haftmann
parents:
diff changeset
   421
%
28564
haftmann
parents: 28562
diff changeset
   422
\isatagquote
28447
haftmann
parents:
diff changeset
   423
\isacommand{lemma}\isamarkupfalse%
32000
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   424
\ {\isacharbrackleft}code{\isacharunderscore}inline{\isacharbrackright}{\isacharcolon}\isanewline
28447
haftmann
parents:
diff changeset
   425
\ \ {\isachardoublequoteopen}x\ {\isasymin}\ set\ xs\ {\isasymlongleftrightarrow}\ x\ mem\ xs{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
haftmann
parents:
diff changeset
   426
\ {\isacharparenleft}induct\ xs{\isacharparenright}\ simp{\isacharunderscore}all%
28564
haftmann
parents: 28562
diff changeset
   427
\endisatagquote
haftmann
parents: 28562
diff changeset
   428
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   429
%
28564
haftmann
parents: 28562
diff changeset
   430
\isadelimquote
28447
haftmann
parents:
diff changeset
   431
%
28564
haftmann
parents: 28562
diff changeset
   432
\endisadelimquote
28447
haftmann
parents:
diff changeset
   433
%
haftmann
parents:
diff changeset
   434
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   435
\item eliminating superfluous constants:%
haftmann
parents:
diff changeset
   436
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   437
\isamarkuptrue%
haftmann
parents:
diff changeset
   438
%
28564
haftmann
parents: 28562
diff changeset
   439
\isadelimquote
28447
haftmann
parents:
diff changeset
   440
%
28564
haftmann
parents: 28562
diff changeset
   441
\endisadelimquote
28447
haftmann
parents:
diff changeset
   442
%
28564
haftmann
parents: 28562
diff changeset
   443
\isatagquote
28447
haftmann
parents:
diff changeset
   444
\isacommand{lemma}\isamarkupfalse%
32000
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   445
\ {\isacharbrackleft}code{\isacharunderscore}inline{\isacharbrackright}{\isacharcolon}\isanewline
28447
haftmann
parents:
diff changeset
   446
\ \ {\isachardoublequoteopen}{\isadigit{1}}\ {\isacharequal}\ Suc\ {\isadigit{0}}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
haftmann
parents:
diff changeset
   447
\ simp%
28564
haftmann
parents: 28562
diff changeset
   448
\endisatagquote
haftmann
parents: 28562
diff changeset
   449
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   450
%
28564
haftmann
parents: 28562
diff changeset
   451
\isadelimquote
28447
haftmann
parents:
diff changeset
   452
%
28564
haftmann
parents: 28562
diff changeset
   453
\endisadelimquote
28447
haftmann
parents:
diff changeset
   454
%
haftmann
parents:
diff changeset
   455
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   456
\item replacing executable but inconvenient constructs:%
haftmann
parents:
diff changeset
   457
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   458
\isamarkuptrue%
haftmann
parents:
diff changeset
   459
%
28564
haftmann
parents: 28562
diff changeset
   460
\isadelimquote
28447
haftmann
parents:
diff changeset
   461
%
28564
haftmann
parents: 28562
diff changeset
   462
\endisadelimquote
28447
haftmann
parents:
diff changeset
   463
%
28564
haftmann
parents: 28562
diff changeset
   464
\isatagquote
28447
haftmann
parents:
diff changeset
   465
\isacommand{lemma}\isamarkupfalse%
32000
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   466
\ {\isacharbrackleft}code{\isacharunderscore}inline{\isacharbrackright}{\isacharcolon}\isanewline
28447
haftmann
parents:
diff changeset
   467
\ \ {\isachardoublequoteopen}xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymlongleftrightarrow}\ List{\isachardot}null\ xs{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse%
haftmann
parents:
diff changeset
   468
\ {\isacharparenleft}induct\ xs{\isacharparenright}\ simp{\isacharunderscore}all%
28564
haftmann
parents: 28562
diff changeset
   469
\endisatagquote
haftmann
parents: 28562
diff changeset
   470
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   471
%
28564
haftmann
parents: 28562
diff changeset
   472
\isadelimquote
28447
haftmann
parents:
diff changeset
   473
%
28564
haftmann
parents: 28562
diff changeset
   474
\endisadelimquote
28447
haftmann
parents:
diff changeset
   475
%
haftmann
parents:
diff changeset
   476
\end{itemize}
haftmann
parents:
diff changeset
   477
%
haftmann
parents:
diff changeset
   478
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   479
\noindent \emph{Function transformers} provide a very general interface,
haftmann
parents:
diff changeset
   480
  transforming a list of function theorems to another
haftmann
parents:
diff changeset
   481
  list of function theorems, provided that neither the heading
haftmann
parents:
diff changeset
   482
  constant nor its type change.  The \isa{{\isadigit{0}}} / \isa{Suc}
haftmann
parents:
diff changeset
   483
  pattern elimination implemented in
haftmann
parents:
diff changeset
   484
  theory \isa{Efficient{\isacharunderscore}Nat} (see \secref{eff_nat}) uses this
haftmann
parents:
diff changeset
   485
  interface.
haftmann
parents:
diff changeset
   486
haftmann
parents:
diff changeset
   487
  \noindent The current setup of the preprocessor may be inspected using
31254
03a35fbc9dc6 documented print_codeproc command
haftmann
parents: 31150
diff changeset
   488
  the \hyperlink{command.print-codeproc}{\mbox{\isa{\isacommand{print{\isacharunderscore}codeproc}}}} command.
28447
haftmann
parents:
diff changeset
   489
  \hyperlink{command.code-thms}{\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}} provides a convenient
haftmann
parents:
diff changeset
   490
  mechanism to inspect the impact of a preprocessor setup
29560
fa6c5d62adf5 "code equation" replaces "defining equation"
haftmann
parents: 29297
diff changeset
   491
  on code equations.
28447
haftmann
parents:
diff changeset
   492
haftmann
parents:
diff changeset
   493
  \begin{warn}
32000
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   494
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   495
    Attribute \hyperlink{attribute.code-unfold}{\mbox{\isa{code{\isacharunderscore}unfold}}} also applies to the
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   496
    preprocessor of the ancient \isa{SML\ code\ generator}; in case
6f07563dc8a9 updated to changes in sources; tuned
haftmann
parents: 31848
diff changeset
   497
    this is not what you intend, use \hyperlink{attribute.code-inline}{\mbox{\isa{code{\isacharunderscore}inline}}} instead.
28447
haftmann
parents:
diff changeset
   498
  \end{warn}%
haftmann
parents:
diff changeset
   499
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   500
\isamarkuptrue%
haftmann
parents:
diff changeset
   501
%
haftmann
parents:
diff changeset
   502
\isamarkupsubsection{Datatypes \label{sec:datatypes}%
haftmann
parents:
diff changeset
   503
}
haftmann
parents:
diff changeset
   504
\isamarkuptrue%
haftmann
parents:
diff changeset
   505
%
haftmann
parents:
diff changeset
   506
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   507
Conceptually, any datatype is spanned by a set of
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   508
  \emph{constructors} 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
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   509
  \isa{{\isasymtau}}.  The HOL datatype package by default registers any new
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   510
  datatype in the table of datatypes, which may be inspected using the
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   511
  \hyperlink{command.print-codesetup}{\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}} command.
28447
haftmann
parents:
diff changeset
   512
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   513
  In some cases, it is appropriate to alter or extend this table.  As
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   514
  an example, we will develop an alternative representation of the
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   515
  queue example given in \secref{sec:intro}.  The amortised
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   516
  representation is convenient for generating code but exposes its
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   517
  \qt{implementation} details, which may be cumbersome when proving
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   518
  theorems about it.  Therefore, here a simple, straightforward
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   519
  representation of queues:%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   520
\end{isamarkuptext}%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   521
\isamarkuptrue%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   522
%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   523
\isadelimquote
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   524
%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   525
\endisadelimquote
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   526
%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   527
\isatagquote
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   528
\isacommand{datatype}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   529
\ {\isacharprime}a\ queue\ {\isacharequal}\ Queue\ {\isachardoublequoteopen}{\isacharprime}a\ list{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   530
\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   531
\isacommand{definition}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   532
\ empty\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   533
\ \ {\isachardoublequoteopen}empty\ {\isacharequal}\ Queue\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   534
\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   535
\isacommand{primrec}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   536
\ enqueue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ queue\ {\isasymRightarrow}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   537
\ \ {\isachardoublequoteopen}enqueue\ x\ {\isacharparenleft}Queue\ xs{\isacharparenright}\ {\isacharequal}\ Queue\ {\isacharparenleft}xs\ {\isacharat}\ {\isacharbrackleft}x{\isacharbrackright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   538
\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   539
\isacommand{fun}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   540
\ dequeue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ queue\ {\isasymRightarrow}\ {\isacharprime}a\ option\ {\isasymtimes}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   541
\ \ \ \ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}Queue\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}None{\isacharcomma}\ Queue\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   542
\ \ {\isacharbar}\ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}Queue\ {\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}Some\ x{\isacharcomma}\ Queue\ xs{\isacharparenright}{\isachardoublequoteclose}%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   543
\endisatagquote
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   544
{\isafoldquote}%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   545
%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   546
\isadelimquote
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   547
%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   548
\endisadelimquote
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   549
%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   550
\begin{isamarkuptext}%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   551
\noindent This we can use directly for proving;  for executing,
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   552
  we provide an alternative characterisation:%
28447
haftmann
parents:
diff changeset
   553
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   554
\isamarkuptrue%
haftmann
parents:
diff changeset
   555
%
28564
haftmann
parents: 28562
diff changeset
   556
\isadelimquote
28447
haftmann
parents:
diff changeset
   557
%
28564
haftmann
parents: 28562
diff changeset
   558
\endisadelimquote
28447
haftmann
parents:
diff changeset
   559
%
28564
haftmann
parents: 28562
diff changeset
   560
\isatagquote
28447
haftmann
parents:
diff changeset
   561
\isacommand{definition}\isamarkupfalse%
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   562
\ AQueue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   563
\ \ {\isachardoublequoteopen}AQueue\ xs\ ys\ {\isacharequal}\ Queue\ {\isacharparenleft}ys\ {\isacharat}\ rev\ xs{\isacharparenright}{\isachardoublequoteclose}\isanewline
28447
haftmann
parents:
diff changeset
   564
\isanewline
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   565
\isacommand{code{\isacharunderscore}datatype}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   566
\ AQueue%
28564
haftmann
parents: 28562
diff changeset
   567
\endisatagquote
haftmann
parents: 28562
diff changeset
   568
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   569
%
28564
haftmann
parents: 28562
diff changeset
   570
\isadelimquote
28447
haftmann
parents:
diff changeset
   571
%
28564
haftmann
parents: 28562
diff changeset
   572
\endisadelimquote
28447
haftmann
parents:
diff changeset
   573
%
haftmann
parents:
diff changeset
   574
\begin{isamarkuptext}%
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   575
\noindent Here we define a \qt{constructor} \isa{AQueue} which
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   576
  is defined in terms of \isa{Queue} and interprets its arguments
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   577
  according to what the \emph{content} of an amortised queue is supposed
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   578
  to be.  Equipped with this, we are able to prove the following equations
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   579
  for our primitive queue operations which \qt{implement} the simple
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   580
  queues in an amortised fashion:%
28447
haftmann
parents:
diff changeset
   581
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   582
\isamarkuptrue%
haftmann
parents:
diff changeset
   583
%
28564
haftmann
parents: 28562
diff changeset
   584
\isadelimquote
28447
haftmann
parents:
diff changeset
   585
%
28564
haftmann
parents: 28562
diff changeset
   586
\endisadelimquote
28447
haftmann
parents:
diff changeset
   587
%
28564
haftmann
parents: 28562
diff changeset
   588
\isatagquote
28447
haftmann
parents:
diff changeset
   589
\isacommand{lemma}\isamarkupfalse%
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   590
\ empty{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   591
\ \ {\isachardoublequoteopen}empty\ {\isacharequal}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   592
\ \ \isacommand{unfolding}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   593
\ AQueue{\isacharunderscore}def\ empty{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   594
\ simp\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   595
\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   596
\isacommand{lemma}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   597
\ enqueue{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   598
\ \ {\isachardoublequoteopen}enqueue\ x\ {\isacharparenleft}AQueue\ xs\ ys{\isacharparenright}\ {\isacharequal}\ AQueue\ {\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}\ ys{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   599
\ \ \isacommand{unfolding}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   600
\ AQueue{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   601
\ simp\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   602
\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   603
\isacommand{lemma}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   604
\ dequeue{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   605
\ \ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   606
\ \ \ \ {\isacharparenleft}if\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ then\ {\isacharparenleft}None{\isacharcomma}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   607
\ \ \ \ else\ dequeue\ {\isacharparenleft}AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharparenleft}rev\ xs{\isacharparenright}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   608
\ \ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharparenleft}y\ {\isacharhash}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}Some\ y{\isacharcomma}\ AQueue\ xs\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   609
\ \ \isacommand{unfolding}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   610
\ AQueue{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   611
\ simp{\isacharunderscore}all%
28564
haftmann
parents: 28562
diff changeset
   612
\endisatagquote
haftmann
parents: 28562
diff changeset
   613
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   614
%
28564
haftmann
parents: 28562
diff changeset
   615
\isadelimquote
28447
haftmann
parents:
diff changeset
   616
%
28564
haftmann
parents: 28562
diff changeset
   617
\endisadelimquote
28447
haftmann
parents:
diff changeset
   618
%
haftmann
parents:
diff changeset
   619
\begin{isamarkuptext}%
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   620
\noindent For completeness, we provide a substitute for the
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   621
  \isa{case} combinator on queues:%
28447
haftmann
parents:
diff changeset
   622
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   623
\isamarkuptrue%
haftmann
parents:
diff changeset
   624
%
28564
haftmann
parents: 28562
diff changeset
   625
\isadelimquote
28447
haftmann
parents:
diff changeset
   626
%
28564
haftmann
parents: 28562
diff changeset
   627
\endisadelimquote
28447
haftmann
parents:
diff changeset
   628
%
28564
haftmann
parents: 28562
diff changeset
   629
\isatagquote
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   630
\isacommand{lemma}\isamarkupfalse%
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   631
\ queue{\isacharunderscore}case{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   632
\ \ {\isachardoublequoteopen}queue{\isacharunderscore}case\ f\ {\isacharparenleft}AQueue\ xs\ ys{\isacharparenright}\ {\isacharequal}\ f\ {\isacharparenleft}ys\ {\isacharat}\ rev\ xs{\isacharparenright}{\isachardoublequoteclose}\isanewline
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   633
\ \ \isacommand{unfolding}\isamarkupfalse%
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   634
\ AQueue{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse%
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   635
\ simp%
28564
haftmann
parents: 28562
diff changeset
   636
\endisatagquote
haftmann
parents: 28562
diff changeset
   637
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   638
%
28564
haftmann
parents: 28562
diff changeset
   639
\isadelimquote
28447
haftmann
parents:
diff changeset
   640
%
28564
haftmann
parents: 28562
diff changeset
   641
\endisadelimquote
28447
haftmann
parents:
diff changeset
   642
%
haftmann
parents:
diff changeset
   643
\begin{isamarkuptext}%
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   644
\noindent The resulting code looks as expected:%
28447
haftmann
parents:
diff changeset
   645
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   646
\isamarkuptrue%
haftmann
parents:
diff changeset
   647
%
28564
haftmann
parents: 28562
diff changeset
   648
\isadelimquote
28447
haftmann
parents:
diff changeset
   649
%
28564
haftmann
parents: 28562
diff changeset
   650
\endisadelimquote
28447
haftmann
parents:
diff changeset
   651
%
28564
haftmann
parents: 28562
diff changeset
   652
\isatagquote
28447
haftmann
parents:
diff changeset
   653
%
haftmann
parents:
diff changeset
   654
\begin{isamarkuptext}%
28727
185110a4b97a clarified verbatim vs. typewriter
haftmann
parents: 28714
diff changeset
   655
\isatypewriter%
28447
haftmann
parents:
diff changeset
   656
\noindent%
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   657
\hspace*{0pt}structure Example = \\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   658
\hspace*{0pt}struct\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   659
\hspace*{0pt}\\
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   660
\hspace*{0pt}fun foldl f a [] = a\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   661
\hspace*{0pt} ~| foldl f a (x ::~xs) = foldl f (f a x) xs;\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   662
\hspace*{0pt}\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   663
\hspace*{0pt}fun rev xs = foldl (fn xsa => fn x => x ::~xsa) [] xs;\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   664
\hspace*{0pt}\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   665
\hspace*{0pt}fun null [] = true\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   666
\hspace*{0pt} ~| null (x ::~xs) = false;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   667
\hspace*{0pt}\\
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   668
\hspace*{0pt}datatype 'a queue = AQueue of 'a list * 'a list;\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   669
\hspace*{0pt}\\
33707
68841fb382e0 dropped obsolete documentation; updated generated sources
haftmann
parents: 32000
diff changeset
   670
\hspace*{0pt}val empty :~'a queue = AQueue ([],~[]);\\
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   671
\hspace*{0pt}\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   672
\hspace*{0pt}fun dequeue (AQueue (xs,~y ::~ys)) = (SOME y,~AQueue (xs,~ys))\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   673
\hspace*{0pt} ~| dequeue (AQueue (xs,~[])) =\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   674
\hspace*{0pt} ~~~(if null xs then (NONE,~AQueue ([],~[]))\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   675
\hspace*{0pt} ~~~~~else dequeue (AQueue ([],~rev xs)));\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   676
\hspace*{0pt}\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   677
\hspace*{0pt}fun enqueue x (AQueue (xs,~ys)) = AQueue (x ::~xs,~ys);\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   678
\hspace*{0pt}\\
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28727
diff changeset
   679
\hspace*{0pt}end;~(*struct Example*)%
28447
haftmann
parents:
diff changeset
   680
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   681
\isamarkuptrue%
haftmann
parents:
diff changeset
   682
%
28564
haftmann
parents: 28562
diff changeset
   683
\endisatagquote
haftmann
parents: 28562
diff changeset
   684
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   685
%
28564
haftmann
parents: 28562
diff changeset
   686
\isadelimquote
28447
haftmann
parents:
diff changeset
   687
%
28564
haftmann
parents: 28562
diff changeset
   688
\endisadelimquote
28447
haftmann
parents:
diff changeset
   689
%
haftmann
parents:
diff changeset
   690
\begin{isamarkuptext}%
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   691
\noindent From this example, it can be glimpsed that using own
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   692
  constructor sets is a little delicate since it changes the set of
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   693
  valid patterns for values of that type.  Without going into much
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   694
  detail, here some practical hints:
28447
haftmann
parents:
diff changeset
   695
haftmann
parents:
diff changeset
   696
  \begin{itemize}
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   697
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   698
    \item When changing the constructor set for datatypes, take care
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   699
      to provide alternative equations for the \isa{case} combinator.
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   700
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   701
    \item Values in the target language need not to be normalised --
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   702
      different values in the target language may represent the same
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   703
      value in the logic.
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   704
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   705
    \item Usually, a good methodology to deal with the subtleties of
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   706
      pattern matching is to see the type as an abstract type: provide
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   707
      a set of operations which operate on the concrete representation
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   708
      of the type, and derive further operations by combinations of
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   709
      these primitive ones, without relying on a particular
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   710
      representation.
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   711
28447
haftmann
parents:
diff changeset
   712
  \end{itemize}%
haftmann
parents:
diff changeset
   713
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   714
\isamarkuptrue%
haftmann
parents:
diff changeset
   715
%
30938
c6c9359e474c wellsortedness is no issue for a user manual any more
haftmann
parents: 30227
diff changeset
   716
\isamarkupsubsection{Equality%
28447
haftmann
parents:
diff changeset
   717
}
haftmann
parents:
diff changeset
   718
\isamarkuptrue%
haftmann
parents:
diff changeset
   719
%
haftmann
parents:
diff changeset
   720
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   721
Surely you have already noticed how equality is treated
haftmann
parents:
diff changeset
   722
  by the code generator:%
haftmann
parents:
diff changeset
   723
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   724
\isamarkuptrue%
haftmann
parents:
diff changeset
   725
%
28564
haftmann
parents: 28562
diff changeset
   726
\isadelimquote
28447
haftmann
parents:
diff changeset
   727
%
28564
haftmann
parents: 28562
diff changeset
   728
\endisadelimquote
28447
haftmann
parents:
diff changeset
   729
%
28564
haftmann
parents: 28562
diff changeset
   730
\isatagquote
28447
haftmann
parents:
diff changeset
   731
\isacommand{primrec}\isamarkupfalse%
haftmann
parents:
diff changeset
   732
\ collect{\isacharunderscore}duplicates\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
haftmann
parents:
diff changeset
   733
\ \ {\isachardoublequoteopen}collect{\isacharunderscore}duplicates\ xs\ ys\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ xs{\isachardoublequoteclose}\isanewline
haftmann
parents:
diff changeset
   734
\ \ {\isacharbar}\ {\isachardoublequoteopen}collect{\isacharunderscore}duplicates\ xs\ ys\ {\isacharparenleft}z{\isacharhash}zs{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}if\ z\ {\isasymin}\ set\ xs\isanewline
haftmann
parents:
diff changeset
   735
\ \ \ \ \ \ then\ if\ z\ {\isasymin}\ set\ ys\isanewline
haftmann
parents:
diff changeset
   736
\ \ \ \ \ \ \ \ then\ collect{\isacharunderscore}duplicates\ xs\ ys\ zs\isanewline
haftmann
parents:
diff changeset
   737
\ \ \ \ \ \ \ \ else\ collect{\isacharunderscore}duplicates\ xs\ {\isacharparenleft}z{\isacharhash}ys{\isacharparenright}\ zs\isanewline
haftmann
parents:
diff changeset
   738
\ \ \ \ \ \ else\ collect{\isacharunderscore}duplicates\ {\isacharparenleft}z{\isacharhash}xs{\isacharparenright}\ {\isacharparenleft}z{\isacharhash}ys{\isacharparenright}\ zs{\isacharparenright}{\isachardoublequoteclose}%
28564
haftmann
parents: 28562
diff changeset
   739
\endisatagquote
haftmann
parents: 28562
diff changeset
   740
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   741
%
28564
haftmann
parents: 28562
diff changeset
   742
\isadelimquote
28447
haftmann
parents:
diff changeset
   743
%
28564
haftmann
parents: 28562
diff changeset
   744
\endisadelimquote
28447
haftmann
parents:
diff changeset
   745
%
haftmann
parents:
diff changeset
   746
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   747
\noindent The membership test during preprocessing is rewritten,
haftmann
parents:
diff changeset
   748
  resulting in \isa{op\ mem}, which itself
haftmann
parents:
diff changeset
   749
  performs an explicit equality check.%
haftmann
parents:
diff changeset
   750
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   751
\isamarkuptrue%
haftmann
parents:
diff changeset
   752
%
28564
haftmann
parents: 28562
diff changeset
   753
\isadelimquote
28447
haftmann
parents:
diff changeset
   754
%
28564
haftmann
parents: 28562
diff changeset
   755
\endisadelimquote
28447
haftmann
parents:
diff changeset
   756
%
28564
haftmann
parents: 28562
diff changeset
   757
\isatagquote
28447
haftmann
parents:
diff changeset
   758
%
haftmann
parents:
diff changeset
   759
\begin{isamarkuptext}%
28727
185110a4b97a clarified verbatim vs. typewriter
haftmann
parents: 28714
diff changeset
   760
\isatypewriter%
28447
haftmann
parents:
diff changeset
   761
\noindent%
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   762
\hspace*{0pt}structure Example = \\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   763
\hspace*{0pt}struct\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   764
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   765
\hspace*{0pt}type 'a eq = {\char123}eq :~'a -> 'a -> bool{\char125};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   766
\hspace*{0pt}fun eq (A{\char95}:'a eq) = {\char35}eq A{\char95};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   767
\hspace*{0pt}\\
31045
f0c7607bb295 updated generated file
haftmann
parents: 30938
diff changeset
   768
\hspace*{0pt}fun eqa A{\char95}~a b = eq A{\char95}~a b;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   769
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   770
\hspace*{0pt}fun member A{\char95}~x [] = false\\
31045
f0c7607bb295 updated generated file
haftmann
parents: 30938
diff changeset
   771
\hspace*{0pt} ~| member A{\char95}~x (y ::~ys) = eqa A{\char95}~x y orelse member A{\char95}~x ys;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   772
\hspace*{0pt}\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   773
\hspace*{0pt}fun collect{\char95}duplicates A{\char95}~xs ys [] = xs\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   774
\hspace*{0pt} ~| collect{\char95}duplicates A{\char95}~xs ys (z ::~zs) =\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   775
\hspace*{0pt} ~~~(if member A{\char95}~z xs\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   776
\hspace*{0pt} ~~~~~then (if member A{\char95}~z ys then collect{\char95}duplicates A{\char95}~xs ys zs\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   777
\hspace*{0pt} ~~~~~~~~~~~~else collect{\char95}duplicates A{\char95}~xs (z ::~ys) zs)\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   778
\hspace*{0pt} ~~~~~else collect{\char95}duplicates A{\char95}~(z ::~xs) (z ::~ys) zs);\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   779
\hspace*{0pt}\\
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28727
diff changeset
   780
\hspace*{0pt}end;~(*struct Example*)%
28447
haftmann
parents:
diff changeset
   781
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   782
\isamarkuptrue%
haftmann
parents:
diff changeset
   783
%
28564
haftmann
parents: 28562
diff changeset
   784
\endisatagquote
haftmann
parents: 28562
diff changeset
   785
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   786
%
28564
haftmann
parents: 28562
diff changeset
   787
\isadelimquote
28447
haftmann
parents:
diff changeset
   788
%
28564
haftmann
parents: 28562
diff changeset
   789
\endisadelimquote
28447
haftmann
parents:
diff changeset
   790
%
haftmann
parents:
diff changeset
   791
\begin{isamarkuptext}%
haftmann
parents:
diff changeset
   792
\noindent Obviously, polymorphic equality is implemented the Haskell
haftmann
parents:
diff changeset
   793
  way using a type class.  How is this achieved?  HOL introduces
haftmann
parents:
diff changeset
   794
  an explicit class \isa{eq} with a corresponding operation
haftmann
parents:
diff changeset
   795
  \isa{eq{\isacharunderscore}class{\isachardot}eq} such that \isa{eq{\isacharunderscore}class{\isachardot}eq\ {\isacharequal}\ op\ {\isacharequal}}.
haftmann
parents:
diff changeset
   796
  The preprocessing framework does the rest by propagating the
29560
fa6c5d62adf5 "code equation" replaces "defining equation"
haftmann
parents: 29297
diff changeset
   797
  \isa{eq} constraints through all dependent code equations.
28447
haftmann
parents:
diff changeset
   798
  For datatypes, instances of \isa{eq} are implicitly derived
haftmann
parents:
diff changeset
   799
  when possible.  For other types, you may instantiate \isa{eq}
33707
68841fb382e0 dropped obsolete documentation; updated generated sources
haftmann
parents: 32000
diff changeset
   800
  manually like any other type class.%
28447
haftmann
parents:
diff changeset
   801
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   802
\isamarkuptrue%
haftmann
parents:
diff changeset
   803
%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   804
\isamarkupsubsection{Explicit partiality%
28447
haftmann
parents:
diff changeset
   805
}
haftmann
parents:
diff changeset
   806
\isamarkuptrue%
haftmann
parents:
diff changeset
   807
%
haftmann
parents:
diff changeset
   808
\begin{isamarkuptext}%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   809
Partiality usually enters the game by partial patterns, as
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   810
  in the following example, again for amortised queues:%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   811
\end{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   812
\isamarkuptrue%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   813
%
28564
haftmann
parents: 28562
diff changeset
   814
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   815
%
28564
haftmann
parents: 28562
diff changeset
   816
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   817
%
28564
haftmann
parents: 28562
diff changeset
   818
\isatagquote
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   819
\isacommand{definition}\isamarkupfalse%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   820
\ strict{\isacharunderscore}dequeue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ queue\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   821
\ \ {\isachardoublequoteopen}strict{\isacharunderscore}dequeue\ q\ {\isacharequal}\ {\isacharparenleft}case\ dequeue\ q\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   822
\ \ \ \ of\ {\isacharparenleft}Some\ x{\isacharcomma}\ q{\isacharprime}{\isacharparenright}\ {\isasymRightarrow}\ {\isacharparenleft}x{\isacharcomma}\ q{\isacharprime}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   823
\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   824
\isacommand{lemma}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   825
\ strict{\isacharunderscore}dequeue{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   826
\ \ {\isachardoublequoteopen}strict{\isacharunderscore}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharparenleft}y\ {\isacharhash}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}y{\isacharcomma}\ AQueue\ xs\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   827
\ \ {\isachardoublequoteopen}strict{\isacharunderscore}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   828
\ \ \ \ {\isacharparenleft}case\ rev\ xs\ of\ y\ {\isacharhash}\ ys\ {\isasymRightarrow}\ {\isacharparenleft}y{\isacharcomma}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ ys{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   829
\ \ \isacommand{by}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   830
\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ strict{\isacharunderscore}dequeue{\isacharunderscore}def\ dequeue{\isacharunderscore}AQueue\ split{\isacharcolon}\ list{\isachardot}splits{\isacharparenright}%
28564
haftmann
parents: 28562
diff changeset
   831
\endisatagquote
haftmann
parents: 28562
diff changeset
   832
{\isafoldquote}%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   833
%
28564
haftmann
parents: 28562
diff changeset
   834
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   835
%
28564
haftmann
parents: 28562
diff changeset
   836
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   837
%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   838
\begin{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   839
\noindent In the corresponding code, there is no equation
30227
853abb4853cc tuned manuals
haftmann
parents: 30226
diff changeset
   840
  for the pattern \isa{AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}}:%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   841
\end{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   842
\isamarkuptrue%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   843
%
28564
haftmann
parents: 28562
diff changeset
   844
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   845
%
28564
haftmann
parents: 28562
diff changeset
   846
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   847
%
28564
haftmann
parents: 28562
diff changeset
   848
\isatagquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   849
%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   850
\begin{isamarkuptext}%
28727
185110a4b97a clarified verbatim vs. typewriter
haftmann
parents: 28714
diff changeset
   851
\isatypewriter%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   852
\noindent%
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28727
diff changeset
   853
\hspace*{0pt}strict{\char95}dequeue ::~forall a.~Queue a -> (a,~Queue a);\\
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   854
\hspace*{0pt}strict{\char95}dequeue (AQueue xs []) =\\
31848
e5ab21d14974 updated generated document
haftmann
parents: 31544
diff changeset
   855
\hspace*{0pt} ~let {\char123}\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   856
\hspace*{0pt} ~~~(y :~ys) = rev xs;\\
31848
e5ab21d14974 updated generated document
haftmann
parents: 31544
diff changeset
   857
\hspace*{0pt} ~{\char125}~in (y,~AQueue [] ys);\\
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   858
\hspace*{0pt}strict{\char95}dequeue (AQueue xs (y :~ys)) = (y,~AQueue xs ys);%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   859
\end{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   860
\isamarkuptrue%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   861
%
28564
haftmann
parents: 28562
diff changeset
   862
\endisatagquote
haftmann
parents: 28562
diff changeset
   863
{\isafoldquote}%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   864
%
28564
haftmann
parents: 28562
diff changeset
   865
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   866
%
28564
haftmann
parents: 28562
diff changeset
   867
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   868
%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   869
\begin{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   870
\noindent In some cases it is desirable to have this
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   871
  pseudo-\qt{partiality} more explicitly, e.g.~as follows:%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   872
\end{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   873
\isamarkuptrue%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   874
%
28564
haftmann
parents: 28562
diff changeset
   875
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   876
%
28564
haftmann
parents: 28562
diff changeset
   877
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   878
%
28564
haftmann
parents: 28562
diff changeset
   879
\isatagquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   880
\isacommand{axiomatization}\isamarkupfalse%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   881
\ empty{\isacharunderscore}queue\ {\isacharcolon}{\isacharcolon}\ {\isacharprime}a\isanewline
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   882
\isanewline
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   883
\isacommand{definition}\isamarkupfalse%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   884
\ strict{\isacharunderscore}dequeue{\isacharprime}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ queue\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   885
\ \ {\isachardoublequoteopen}strict{\isacharunderscore}dequeue{\isacharprime}\ q\ {\isacharequal}\ {\isacharparenleft}case\ dequeue\ q\ of\ {\isacharparenleft}Some\ x{\isacharcomma}\ q{\isacharprime}{\isacharparenright}\ {\isasymRightarrow}\ {\isacharparenleft}x{\isacharcomma}\ q{\isacharprime}{\isacharparenright}\ {\isacharbar}\ {\isacharunderscore}\ {\isasymRightarrow}\ empty{\isacharunderscore}queue{\isacharparenright}{\isachardoublequoteclose}\isanewline
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   886
\isanewline
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   887
\isacommand{lemma}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   888
\ strict{\isacharunderscore}dequeue{\isacharprime}{\isacharunderscore}AQueue\ {\isacharbrackleft}code{\isacharbrackright}{\isacharcolon}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   889
\ \ {\isachardoublequoteopen}strict{\isacharunderscore}dequeue{\isacharprime}\ {\isacharparenleft}AQueue\ xs\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}if\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ then\ empty{\isacharunderscore}queue\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   890
\ \ \ \ \ else\ strict{\isacharunderscore}dequeue{\isacharprime}\ {\isacharparenleft}AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharparenleft}rev\ xs{\isacharparenright}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   891
\ \ {\isachardoublequoteopen}strict{\isacharunderscore}dequeue{\isacharprime}\ {\isacharparenleft}AQueue\ xs\ {\isacharparenleft}y\ {\isacharhash}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   892
\ \ \ \ \ {\isacharparenleft}y{\isacharcomma}\ AQueue\ xs\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   893
\ \ \isacommand{by}\isamarkupfalse%
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   894
\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ strict{\isacharunderscore}dequeue{\isacharprime}{\isacharunderscore}def\ dequeue{\isacharunderscore}AQueue\ split{\isacharcolon}\ list{\isachardot}splits{\isacharparenright}%
28564
haftmann
parents: 28562
diff changeset
   895
\endisatagquote
haftmann
parents: 28562
diff changeset
   896
{\isafoldquote}%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   897
%
28564
haftmann
parents: 28562
diff changeset
   898
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   899
%
28564
haftmann
parents: 28562
diff changeset
   900
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   901
%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   902
\begin{isamarkuptext}%
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   903
Observe that on the right hand side of the definition of \isa{strict{\isacharunderscore}dequeue{\isacharprime}} the constant \isa{empty{\isacharunderscore}queue} occurs
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   904
  which is unspecified.
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   905
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   906
  Normally, if constants without any code equations occur in a
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   907
  program, the code generator complains (since in most cases this is
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   908
  not what the user expects).  But such constants can also be thought
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   909
  of as function definitions with no equations which always fail,
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   910
  since there is never a successful pattern match on the left hand
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   911
  side.  In order to categorise a constant into that category
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   912
  explicitly, use \hyperlink{command.code-abort}{\mbox{\isa{\isacommand{code{\isacharunderscore}abort}}}}:%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   913
\end{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   914
\isamarkuptrue%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   915
%
28564
haftmann
parents: 28562
diff changeset
   916
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   917
%
28564
haftmann
parents: 28562
diff changeset
   918
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   919
%
28564
haftmann
parents: 28562
diff changeset
   920
\isatagquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   921
\isacommand{code{\isacharunderscore}abort}\isamarkupfalse%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   922
\ empty{\isacharunderscore}queue%
28564
haftmann
parents: 28562
diff changeset
   923
\endisatagquote
haftmann
parents: 28562
diff changeset
   924
{\isafoldquote}%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   925
%
28564
haftmann
parents: 28562
diff changeset
   926
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   927
%
28564
haftmann
parents: 28562
diff changeset
   928
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   929
%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   930
\begin{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   931
\noindent Then the code generator will just insert an error or
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   932
  exception at the appropriate position:%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   933
\end{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   934
\isamarkuptrue%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   935
%
28564
haftmann
parents: 28562
diff changeset
   936
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   937
%
28564
haftmann
parents: 28562
diff changeset
   938
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   939
%
28564
haftmann
parents: 28562
diff changeset
   940
\isatagquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   941
%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   942
\begin{isamarkuptext}%
28727
185110a4b97a clarified verbatim vs. typewriter
haftmann
parents: 28714
diff changeset
   943
\isatypewriter%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   944
\noindent%
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28727
diff changeset
   945
\hspace*{0pt}empty{\char95}queue ::~forall a.~a;\\
28714
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   946
\hspace*{0pt}empty{\char95}queue = error {\char34}empty{\char95}queue{\char34};\\
1992553cccfe improved verbatim mechanism
haftmann
parents: 28593
diff changeset
   947
\hspace*{0pt}\\
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28727
diff changeset
   948
\hspace*{0pt}strict{\char95}dequeue' ::~forall a.~Queue a -> (a,~Queue a);\\
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   949
\hspace*{0pt}strict{\char95}dequeue' (AQueue xs (y :~ys)) = (y,~AQueue xs ys);\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   950
\hspace*{0pt}strict{\char95}dequeue' (AQueue xs []) =\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   951
\hspace*{0pt} ~(if nulla xs then empty{\char95}queue\\
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
   952
\hspace*{0pt} ~~~else strict{\char95}dequeue' (AQueue [] (rev xs)));%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   953
\end{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   954
\isamarkuptrue%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   955
%
28564
haftmann
parents: 28562
diff changeset
   956
\endisatagquote
haftmann
parents: 28562
diff changeset
   957
{\isafoldquote}%
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   958
%
28564
haftmann
parents: 28562
diff changeset
   959
\isadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   960
%
28564
haftmann
parents: 28562
diff changeset
   961
\endisadelimquote
28462
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   962
%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   963
\begin{isamarkuptext}%
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   964
\noindent This feature however is rarely needed in practice.
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   965
  Note also that the \isa{HOL} default setup already declares
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   966
  \isa{undefined} as \hyperlink{command.code-abort}{\mbox{\isa{\isacommand{code{\isacharunderscore}abort}}}}, which is most
6ec603695aaf added partiality section
haftmann
parents: 28456
diff changeset
   967
  likely to be used in such situations.%
28447
haftmann
parents:
diff changeset
   968
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   969
\isamarkuptrue%
haftmann
parents:
diff changeset
   970
%
33926
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   971
\isamarkupsubsection{Inductive Predicates%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   972
}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   973
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   974
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   975
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   976
To execute inductive predicates, a special preprocessor, the predicate
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   977
 compiler, generates code equations from the introduction rules of the predicates.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   978
The mechanisms of this compiler are described in \cite{Berghofer-Bulwahn-Haftmann:2009:TPHOL}.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   979
Consider the simple predicate \isa{append} given by these two
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   980
introduction rules:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   981
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   982
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   983
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   984
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   985
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   986
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   987
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   988
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   989
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   990
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   991
\isa{append\ {\isacharbrackleft}{\isacharbrackright}\ ys\ ys}\\
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   992
\noindent\isa{append\ xs\ ys\ zs\ {\isasymLongrightarrow}\ append\ {\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}\ ys\ {\isacharparenleft}x\ {\isacharhash}\ zs{\isacharparenright}}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   993
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   994
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   995
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   996
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   997
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   998
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
   999
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1000
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1001
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1002
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1003
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1004
\noindent To invoke the compiler, simply use \indexdef{}{command}{code\_pred}\hypertarget{command.code-pred}{\hyperlink{command.code-pred}{\mbox{\isa{\isacommand{code{\isacharunderscore}pred}}}}}:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1005
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1006
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1007
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1008
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1009
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1010
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1011
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1012
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1013
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1014
\ append\ \isacommand{{\isachardot}}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1015
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1016
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1017
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1018
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1019
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1020
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1021
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1022
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1023
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1024
\noindent The \hyperlink{command.code-pred}{\mbox{\isa{\isacommand{code{\isacharunderscore}pred}}}} command takes the name
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1025
of the inductive predicate and then you put a period to discharge
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1026
a trivial correctness proof. 
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1027
The compiler infers possible modes 
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1028
for the predicate and produces the derived code equations.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1029
Modes annotate which (parts of the) arguments are to be taken as input,
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1030
and which output. Modes are similar to types, but use the notation \isa{i}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1031
for input and \isa{o} for output.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1032
 
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1033
For \isa{append}, the compiler can infer the following modes:
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1034
\begin{itemize}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1035
\item \isa{i\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ bool}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1036
\item \isa{i\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1037
\item \isa{o\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ bool}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1038
\end{itemize}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1039
You can compute sets of predicates using \indexdef{}{command}{values}\hypertarget{command.values}{\hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}}}:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1040
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1041
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1042
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1043
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1044
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1045
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1046
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1047
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1048
\isacommand{values}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1049
\ {\isachardoublequoteopen}{\isacharbraceleft}zs{\isachardot}\ append\ {\isacharbrackleft}{\isacharparenleft}{\isadigit{1}}{\isacharcolon}{\isacharcolon}nat{\isacharparenright}{\isacharcomma}{\isadigit{2}}{\isacharcomma}{\isadigit{3}}{\isacharbrackright}\ {\isacharbrackleft}{\isadigit{4}}{\isacharcomma}{\isadigit{5}}{\isacharbrackright}\ zs{\isacharbraceright}{\isachardoublequoteclose}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1050
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1051
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1052
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1053
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1054
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1055
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1056
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1057
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1058
\noindent outputs \isa{{\isacharbraceleft}{\isacharbrackleft}{\isadigit{1}}{\isacharcomma}\ {\isadigit{2}}{\isacharcomma}\ {\isadigit{3}}{\isacharcomma}\ {\isadigit{4}}{\isacharcomma}\ {\isadigit{5}}{\isacharbrackright}{\isacharbraceright}}, and%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1059
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1060
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1061
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1062
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1063
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1064
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1065
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1066
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1067
\isacommand{values}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1068
\ {\isachardoublequoteopen}{\isacharbraceleft}{\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isachardot}\ append\ xs\ ys\ {\isacharbrackleft}{\isacharparenleft}{\isadigit{2}}{\isacharcolon}{\isacharcolon}nat{\isacharparenright}{\isacharcomma}{\isadigit{3}}{\isacharbrackright}{\isacharbraceright}{\isachardoublequoteclose}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1069
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1070
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1071
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1072
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1073
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1074
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1075
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1076
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1077
\noindent outputs \isa{{\isacharbraceleft}{\isacharparenleft}{\isacharbrackleft}{\isacharbrackright}{\isacharcomma}\ {\isacharbrackleft}{\isadigit{2}}{\isacharcomma}\ {\isadigit{3}}{\isacharbrackright}{\isacharparenright}{\isacharcomma}\ {\isacharparenleft}{\isacharbrackleft}{\isadigit{2}}{\isacharbrackright}{\isacharcomma}\ {\isacharbrackleft}{\isadigit{3}}{\isacharbrackright}{\isacharparenright}{\isacharcomma}\ {\isacharparenleft}{\isacharbrackleft}{\isadigit{2}}{\isacharcomma}\ {\isadigit{3}}{\isacharbrackright}{\isacharcomma}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharbraceright}}.%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1078
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1079
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1080
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1081
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1082
\noindent If you are only interested in the first elements of the set
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1083
comprehension (with respect to a depth-first search on the introduction rules), you can
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1084
pass an argument to
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1085
\hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}} to specify the number of elements you want:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1086
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1087
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1088
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1089
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1090
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1091
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1092
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1093
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1094
\isacommand{values}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1095
\ {\isadigit{1}}\ {\isachardoublequoteopen}{\isacharbraceleft}{\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isachardot}\ append\ xs\ ys\ {\isacharbrackleft}{\isacharparenleft}{\isadigit{1}}{\isacharcolon}{\isacharcolon}nat{\isacharparenright}{\isacharcomma}{\isadigit{2}}{\isacharcomma}{\isadigit{3}}{\isacharcomma}{\isadigit{4}}{\isacharbrackright}{\isacharbraceright}{\isachardoublequoteclose}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1096
\isacommand{values}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1097
\ {\isadigit{3}}\ {\isachardoublequoteopen}{\isacharbraceleft}{\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isachardot}\ append\ xs\ ys\ {\isacharbrackleft}{\isacharparenleft}{\isadigit{1}}{\isacharcolon}{\isacharcolon}nat{\isacharparenright}{\isacharcomma}{\isadigit{2}}{\isacharcomma}{\isadigit{3}}{\isacharcomma}{\isadigit{4}}{\isacharbrackright}{\isacharbraceright}{\isachardoublequoteclose}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1098
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1099
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1100
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1101
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1102
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1103
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1104
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1105
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1106
\noindent The \hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}} command can only compute set
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1107
 comprehensions for which a mode has been inferred.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1108
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1109
The code equations for a predicate are made available as theorems with
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1110
 the suffix \isa{equation}, and can be inspected with:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1111
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1112
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1113
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1114
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1115
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1116
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1117
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1118
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1119
\isacommand{thm}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1120
\ append{\isachardot}equation%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1121
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1122
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1123
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1124
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1125
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1126
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1127
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1128
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1129
\noindent More advanced options are described in the following subsections.%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1130
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1131
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1132
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1133
\isamarkupsubsubsection{Alternative names for functions%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1134
}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1135
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1136
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1137
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1138
By default, the functions generated from a predicate are named after the predicate with the
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1139
mode mangled into the name (e.g., \isa{append{\isacharunderscore}i{\isacharunderscore}i{\isacharunderscore}o}).
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1140
You can specify your own names as follows:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1141
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1142
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1143
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1144
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1145
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1146
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1147
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1148
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1149
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1150
\ {\isacharparenleft}modes{\isacharcolon}\ i\ {\isacharequal}{\isachargreater}\ i\ {\isacharequal}{\isachargreater}\ o\ {\isacharequal}{\isachargreater}\ bool\ as\ concat{\isacharcomma}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1151
\ \ o\ {\isacharequal}{\isachargreater}\ o\ {\isacharequal}{\isachargreater}\ i\ {\isacharequal}{\isachargreater}\ bool\ as\ split{\isacharcomma}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1152
\ \ i\ {\isacharequal}{\isachargreater}\ o\ {\isacharequal}{\isachargreater}\ i\ {\isacharequal}{\isachargreater}\ bool\ as\ suffix{\isacharparenright}\ append\ \isacommand{{\isachardot}}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1153
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1154
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1155
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1156
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1157
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1158
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1159
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1160
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1161
\isamarkupsubsubsection{Alternative introduction rules%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1162
}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1163
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1164
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1165
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1166
Sometimes the introduction rules of an predicate are not executable because they contain
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1167
non-executable constants or specific modes could not be inferred.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1168
It is also possible that the introduction rules yield a function that loops forever
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1169
due to the execution in a depth-first search manner.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1170
Therefore, you can declare alternative introduction rules for predicates with the attribute
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1171
\hyperlink{attribute.code-pred-intro}{\mbox{\isa{code{\isacharunderscore}pred{\isacharunderscore}intro}}}.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1172
For example, the transitive closure is defined by:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1173
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1174
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1175
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1176
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1177
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1178
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1179
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1180
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1181
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1182
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1183
\isa{r\ a\ b\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ b}\\
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1184
\noindent \isa{{\isasymlbrakk}r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ b{\isacharsemicolon}\ r\ b\ c{\isasymrbrakk}\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ c}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1185
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1186
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1187
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1188
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1189
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1190
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1191
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1192
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1193
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1194
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1195
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1196
\noindent These rules do not suit well for executing the transitive closure 
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1197
with the mode \isa{{\isacharparenleft}i\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool{\isacharparenright}\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool}, as the second rule will
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1198
cause an infinite loop in the recursive call.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1199
This can be avoided using the following alternative rules which are
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1200
declared to the predicate compiler by the attribute \hyperlink{attribute.code-pred-intro}{\mbox{\isa{code{\isacharunderscore}pred{\isacharunderscore}intro}}}:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1201
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1202
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1203
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1204
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1205
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1206
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1207
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1208
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1209
\isacommand{lemma}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1210
\ {\isacharbrackleft}code{\isacharunderscore}pred{\isacharunderscore}intro{\isacharbrackright}{\isacharcolon}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1211
\ \ {\isachardoublequoteopen}r\ a\ b\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ b{\isachardoublequoteclose}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1212
\ \ {\isachardoublequoteopen}r\ a\ b\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ b\ c\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ c{\isachardoublequoteclose}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1213
\isacommand{by}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1214
\ auto%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1215
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1216
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1217
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1218
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1219
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1220
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1221
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1222
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1223
\noindent After declaring all alternative rules for the transitive closure,
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1224
you invoke \hyperlink{command.code-pred}{\mbox{\isa{\isacommand{code{\isacharunderscore}pred}}}} as usual.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1225
As you have declared alternative rules for the predicate, you are urged to prove that these
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1226
introduction rules are complete, i.e., that you can derive an elimination rule for the
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1227
alternative rules:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1228
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1229
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1230
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1231
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1232
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1233
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1234
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1235
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1236
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1237
\ tranclp\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1238
\isacommand{proof}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1239
\ {\isacharminus}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1240
\ \ \isacommand{case}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1241
\ tranclp\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1242
\ \ \isacommand{from}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1243
\ this\ converse{\isacharunderscore}tranclpE{\isacharbrackleft}OF\ this{\isacharparenleft}{\isadigit{1}}{\isacharparenright}{\isacharbrackright}\ \isacommand{show}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1244
\ thesis\ \isacommand{by}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1245
\ metis\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1246
\isacommand{qed}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1247
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1248
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1249
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1250
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1251
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1252
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1253
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1254
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1255
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1256
\noindent Alternative rules can also be used for constants that have not
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1257
been defined inductively. For example, the lexicographic order which
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1258
is defined as:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1259
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1260
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1261
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1262
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1263
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1264
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1265
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1266
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1267
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1268
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1269
\begin{isabelle}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1270
lexord\ r\ {\isasymequiv}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1271
{\isacharbraceleft}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}{\isachardot}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1272
\isaindent{\ }{\isasymexists}a\ v{\isachardot}\ y\ {\isacharequal}\ x\ {\isacharat}\ a\ {\isacharhash}\ v\ {\isasymor}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1273
\isaindent{\ {\isasymexists}a\ v{\isachardot}\ }{\isacharparenleft}{\isasymexists}u\ a\ b\ v\ w{\isachardot}\ {\isacharparenleft}a{\isacharcomma}\ b{\isacharparenright}\ {\isasymin}\ r\ {\isasymand}\ x\ {\isacharequal}\ u\ {\isacharat}\ a\ {\isacharhash}\ v\ {\isasymand}\ y\ {\isacharequal}\ u\ {\isacharat}\ b\ {\isacharhash}\ w{\isacharparenright}{\isacharbraceright}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1274
\end{isabelle}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1275
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1276
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1277
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1278
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1279
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1280
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1281
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1282
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1283
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1284
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1285
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1286
\noindent To make it executable, you can derive the following two rules and prove the
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1287
elimination rule:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1288
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1289
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1290
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1291
\isadelimproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1292
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1293
\endisadelimproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1294
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1295
\isatagproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1296
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1297
\endisatagproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1298
{\isafoldproof}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1299
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1300
\isadelimproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1301
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1302
\endisadelimproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1303
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1304
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1305
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1306
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1307
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1308
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1309
\isacommand{lemma}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1310
\ {\isacharbrackleft}code{\isacharunderscore}pred{\isacharunderscore}intro{\isacharbrackright}{\isacharcolon}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1311
\ \ {\isachardoublequoteopen}append\ xs\ {\isacharparenleft}a\ {\isacharhash}\ v{\isacharparenright}\ ys\ {\isasymLongrightarrow}\ lexord\ r\ {\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1312
\isacommand{lemma}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1313
\ {\isacharbrackleft}code{\isacharunderscore}pred{\isacharunderscore}intro{\isacharbrackright}{\isacharcolon}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1314
\ \ {\isachardoublequoteopen}append\ u\ {\isacharparenleft}a\ {\isacharhash}\ v{\isacharparenright}\ xs\ {\isasymLongrightarrow}\ append\ u\ {\isacharparenleft}b\ {\isacharhash}\ w{\isacharparenright}\ ys\ {\isasymLongrightarrow}\ r\ {\isacharparenleft}a{\isacharcomma}\ b{\isacharparenright}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1315
\ \ {\isasymLongrightarrow}\ lexord\ r\ {\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1316
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1317
\ lexord%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1318
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1319
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1320
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1321
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1322
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1323
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1324
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1325
\isamarkupsubsubsection{Options for values%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1326
}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1327
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1328
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1329
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1330
In the presence of higher-order predicates, multiple modes for some predicate could be inferred
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1331
that are not disambiguated by the pattern of the set comprehension.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1332
To disambiguate the modes for the arguments of a predicate, you can state
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1333
the modes explicitly in the \hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}} command. 
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1334
Consider the simple predicate \isa{succ}:%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1335
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1336
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1337
\isacommand{inductive}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1338
\ succ\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1339
\isakeyword{where}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1340
\ \ {\isachardoublequoteopen}succ\ {\isadigit{0}}\ {\isacharparenleft}Suc\ {\isadigit{0}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1341
{\isacharbar}\ {\isachardoublequoteopen}succ\ x\ y\ {\isasymLongrightarrow}\ succ\ {\isacharparenleft}Suc\ x{\isacharparenright}\ {\isacharparenleft}Suc\ y{\isacharparenright}{\isachardoublequoteclose}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1342
\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1343
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1344
\ succ%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1345
\isadelimproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1346
\ %
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1347
\endisadelimproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1348
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1349
\isatagproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1350
\isacommand{{\isachardot}}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1351
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1352
\endisatagproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1353
{\isafoldproof}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1354
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1355
\isadelimproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1356
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1357
\endisadelimproof
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1358
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1359
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1360
\noindent For this, the predicate compiler can infer modes \isa{o\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool}, \isa{i\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool},
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1361
  \isa{o\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ bool} and \isa{i\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ bool}.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1362
The invocation of \hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}} \isa{{\isacharbraceleft}n{\isachardot}\ tranclp\ succ\ {\isadigit{1}}{\isadigit{0}}\ n{\isacharbraceright}} loops, as multiple
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1363
modes for the predicate \isa{succ} are possible and here the first mode \isa{o\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1364
is chosen. To choose another mode for the argument, you can declare the mode for the argument between
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1365
the \hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}} and the number of elements.%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1366
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1367
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1368
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1369
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1370
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1371
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1372
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1373
\isatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1374
\isacommand{values}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1375
\ {\isacharbrackleft}mode{\isacharcolon}\ i\ {\isacharequal}{\isachargreater}\ o\ {\isacharequal}{\isachargreater}\ bool{\isacharbrackright}\ {\isadigit{2}}{\isadigit{0}}\ {\isachardoublequoteopen}{\isacharbraceleft}n{\isachardot}\ tranclp\ succ\ {\isadigit{1}}{\isadigit{0}}\ n{\isacharbraceright}{\isachardoublequoteclose}\isanewline
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1376
\isacommand{values}\isamarkupfalse%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1377
\ {\isacharbrackleft}mode{\isacharcolon}\ o\ {\isacharequal}{\isachargreater}\ i\ {\isacharequal}{\isachargreater}\ bool{\isacharbrackright}\ {\isadigit{1}}{\isadigit{0}}\ {\isachardoublequoteopen}{\isacharbraceleft}n{\isachardot}\ tranclp\ succ\ n\ {\isadigit{1}}{\isadigit{0}}{\isacharbraceright}{\isachardoublequoteclose}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1378
\endisatagquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1379
{\isafoldquote}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1380
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1381
\isadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1382
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1383
\endisadelimquote
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1384
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1385
\isamarkupsubsubsection{Embedding into functional code within Isabelle/HOL%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1386
}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1387
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1388
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1389
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1390
To embed the computation of an inductive predicate into functions that are defined in Isabelle/HOL,
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1391
you have a number of options:
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1392
\begin{itemize}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1393
\item You want to use the first-order predicate with the mode
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1394
  where all arguments are input. Then you can use the predicate directly, e.g.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1395
\begin{quote}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1396
  \isa{valid{\isacharunderscore}suffix\ ys\ zs\ {\isacharequal}}\\
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1397
  \isa{{\isacharparenleft}if\ append\ {\isacharbrackleft}Suc\ {\isadigit{0}}{\isacharcomma}\ {\isadigit{2}}{\isacharbrackright}\ ys\ zs\ then\ Some\ ys\ else\ None{\isacharparenright}}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1398
\end{quote}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1399
\item If you know that the execution returns only one value (it is deterministic), then you can
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1400
  use the combinator \isa{Predicate{\isachardot}the}, e.g., a functional concatenation of lists
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1401
  is defined with
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1402
\begin{quote}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1403
  \isa{functional{\isacharunderscore}concat\ xs\ ys\ {\isacharequal}\ Predicate{\isachardot}the\ {\isacharparenleft}append{\isacharunderscore}i{\isacharunderscore}i{\isacharunderscore}o\ xs\ ys{\isacharparenright}}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1404
\end{quote}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1405
  Note that if the evaluation does not return a unique value, it raises a run-time error
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1406
  \isa{not{\isacharunderscore}unique}.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1407
\end{itemize}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1408
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1409
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1410
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1411
\isamarkupsubsubsection{Further Examples%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1412
}
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1413
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1414
%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1415
\begin{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1416
Further examples for compiling inductive predicates can be found in
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1417
the \isa{HOL{\isacharslash}ex{\isacharslash}Predicate{\isacharunderscore}Compile{\isacharunderscore}ex} theory file.
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1418
There are also some examples in the Archive of Formal Proofs, notably
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1419
in the \isa{POPLmark{\isacharminus}deBruijn} and the \isa{FeatherweightJava} sessions.%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1420
\end{isamarkuptext}%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1421
\isamarkuptrue%
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1422
%
28447
haftmann
parents:
diff changeset
  1423
\isadelimtheory
haftmann
parents:
diff changeset
  1424
%
haftmann
parents:
diff changeset
  1425
\endisadelimtheory
haftmann
parents:
diff changeset
  1426
%
haftmann
parents:
diff changeset
  1427
\isatagtheory
haftmann
parents:
diff changeset
  1428
\isacommand{end}\isamarkupfalse%
haftmann
parents:
diff changeset
  1429
%
haftmann
parents:
diff changeset
  1430
\endisatagtheory
haftmann
parents:
diff changeset
  1431
{\isafoldtheory}%
haftmann
parents:
diff changeset
  1432
%
haftmann
parents:
diff changeset
  1433
\isadelimtheory
haftmann
parents:
diff changeset
  1434
%
haftmann
parents:
diff changeset
  1435
\endisadelimtheory
haftmann
parents:
diff changeset
  1436
\isanewline
33926
dd017d9db05f adding subsection about the predicate compiler to the code generator tutorial
bulwahn
parents: 33707
diff changeset
  1437
\end{isabellebody}%
28447
haftmann
parents:
diff changeset
  1438
%%% Local Variables:
haftmann
parents:
diff changeset
  1439
%%% mode: latex
haftmann
parents:
diff changeset
  1440
%%% TeX-master: "root"
haftmann
parents:
diff changeset
  1441
%%% End: