doc-src/Codegen/Thy/document/Evaluation.tex
author wenzelm
Mon, 30 Jul 2012 17:03:24 +0200
changeset 48609 0090fab725e3
parent 46563 0ad69b30b39c
permissions -rw-r--r--
removed some old material (inactive since 2002/2003);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
     1
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
     2
\begin{isabellebody}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
     3
\def\isabellecontext{Evaluation}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
     4
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
     5
\isadelimtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
     6
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
     7
\endisadelimtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
     8
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
     9
\isatagtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    10
\isacommand{theory}\isamarkupfalse%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    11
\ Evaluation\isanewline
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    12
\isakeyword{imports}\ Setup\isanewline
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    13
\isakeyword{begin}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    14
\endisatagtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    15
{\isafoldtheory}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    16
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    17
\isadelimtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    18
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    19
\endisadelimtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    20
%
40755
d73659e8ccdd updated generated documents
haftmann
parents: 40406
diff changeset
    21
\isamarkupsection{Evaluation \label{sec:evaluation}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    22
}
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    23
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    24
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    25
\begin{isamarkuptext}%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    26
Recalling \secref{sec:principle}, code generation turns a system of
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    27
  equations into a program with the \emph{same} equational semantics.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    28
  As a consequence, this program can be used as a \emph{rewrite
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    29
  engine} for terms: rewriting a term \isa{t} using a program to a
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
    30
  term \isa{t{\isaliteral{27}{\isacharprime}}} yields the theorems \isa{t\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ t{\isaliteral{27}{\isacharprime}}}.  This
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    31
  application of code generation in the following is referred to as
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    32
  \emph{evaluation}.%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    33
\end{isamarkuptext}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    34
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    35
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    36
\isamarkupsubsection{Evaluation techniques%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    37
}
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    38
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    39
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    40
\begin{isamarkuptext}%
40350
1ef7ee8dd165 fixed typos
haftmann
parents: 39745
diff changeset
    41
The existing infrastructure provides a rich palette of evaluation
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    42
  techniques, each comprising different aspects:
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    43
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    44
  \begin{description}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    45
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    46
    \item[Expressiveness.]  Depending on how good symbolic computation
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    47
      is supported, the class of terms which can be evaluated may be
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    48
      bigger or smaller.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    49
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    50
    \item[Efficiency.]  The more machine-near the technique, the
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    51
      faster it is.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    52
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    53
    \item[Trustability.]  Techniques which a huge (and also probably
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    54
      more configurable infrastructure) are more fragile and less
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    55
      trustable.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    56
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    57
  \end{description}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    58
\end{isamarkuptext}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    59
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    60
%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    61
\isamarkupsubsubsection{The simplifier (\isa{simp})%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    62
}
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    63
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    64
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    65
\begin{isamarkuptext}%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    66
The simplest way for evaluation is just using the simplifier with
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    67
  the original code equations of the underlying program.  This gives
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    68
  fully symbolic evaluation and highest trustablity, with the usual
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    69
  performance of the simplifier.  Note that for operations on abstract
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    70
  datatypes (cf.~\secref{sec:invariant}), the original theorems as
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    71
  given by the users are used, not the modified ones.%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    72
\end{isamarkuptext}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    73
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    74
%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    75
\isamarkupsubsubsection{Normalization by evaluation (\isa{nbe})%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    76
}
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    77
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    78
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    79
\begin{isamarkuptext}%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    80
Normalization by evaluation \cite{Aehlig-Haftmann-Nipkow:2008:nbe}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    81
  provides a comparably fast partially symbolic evaluation which
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    82
  permits also normalization of functions and uninterpreted symbols;
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    83
  the stack of code to be trusted is considerable.%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    84
\end{isamarkuptext}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    85
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    86
%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    87
\isamarkupsubsubsection{Evaluation in ML (\isa{code})%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    88
}
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    89
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    90
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
    91
\begin{isamarkuptext}%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    92
Highest performance can be achieved by evaluation in ML, at the cost
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    93
  of being restricted to ground results and a layered stack of code to
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    94
  be trusted, including code generator configurations by the user.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    95
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    96
  Evaluation is carried out in a target language \emph{Eval} which
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    97
  inherits from \emph{SML} but for convenience uses parts of the
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
    98
  Isabelle runtime environment.  The soundness of computation carried
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
    99
  out there depends crucially on the correctness of the code
39643
29cc021398fc corrections and tuning
haftmann
parents: 39609
diff changeset
   100
  generator setup; this is one of the reasons why you should not use
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   101
  adaptation (see \secref{sec:adaptation}) frivolously.%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   102
\end{isamarkuptext}%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   103
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   104
%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   105
\isamarkupsubsection{Aspects of evaluation%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   106
}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   107
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   108
%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   109
\begin{isamarkuptext}%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   110
Each of the techniques can be combined with different aspects.  The
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   111
  most important distinction is between dynamic and static evaluation.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   112
  Dynamic evaluation takes the code generator configuration \qt{as it
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   113
  is} at the point where evaluation is issued.  Best example is the
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   114
  \indexdef{}{command}{value}\hypertarget{command.value}{\hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}}} command which allows ad-hoc evaluation of
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   115
  terms:%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   116
\end{isamarkuptext}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   117
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   118
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   119
\isadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   120
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   121
\endisadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   122
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   123
\isatagquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   124
\isacommand{value}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   125
\ {\isaliteral{22}{\isachardoublequoteopen}}{\isadigit{4}}{\isadigit{2}}\ {\isaliteral{2F}{\isacharslash}}\ {\isaliteral{28}{\isacharparenleft}}{\isadigit{1}}{\isadigit{2}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   126
\endisatagquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   127
{\isafoldquote}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   128
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   129
\isadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   130
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   131
\endisadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   132
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   133
\begin{isamarkuptext}%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   134
\noindent By default \hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}} tries all available evaluation
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   135
  techniques and prints the result of the first succeeding one.  A particular
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   136
  technique may be specified in square brackets, e.g.%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   137
\end{isamarkuptext}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   138
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   139
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   140
\isadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   141
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   142
\endisadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   143
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   144
\isatagquote
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   145
\isacommand{value}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   146
\ {\isaliteral{5B}{\isacharbrackleft}}nbe{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isadigit{4}}{\isadigit{2}}\ {\isaliteral{2F}{\isacharslash}}\ {\isaliteral{28}{\isacharparenleft}}{\isadigit{1}}{\isadigit{2}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   147
\endisatagquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   148
{\isafoldquote}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   149
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   150
\isadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   151
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   152
\endisadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   153
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   154
\begin{isamarkuptext}%
43656
9ece73262746 adding documentation of the value antiquotation to the code generation manual
bulwahn
parents: 41185
diff changeset
   155
To employ dynamic evaluation in the document generation, there is also
9ece73262746 adding documentation of the value antiquotation to the code generation manual
bulwahn
parents: 41185
diff changeset
   156
  a \isa{value} antiquotation. By default, it also tries all available evaluation
9ece73262746 adding documentation of the value antiquotation to the code generation manual
bulwahn
parents: 41185
diff changeset
   157
  techniques and prints the result of the first succeeding one, unless a particular
9ece73262746 adding documentation of the value antiquotation to the code generation manual
bulwahn
parents: 41185
diff changeset
   158
  technique is specified in square brackets.
9ece73262746 adding documentation of the value antiquotation to the code generation manual
bulwahn
parents: 41185
diff changeset
   159
9ece73262746 adding documentation of the value antiquotation to the code generation manual
bulwahn
parents: 41185
diff changeset
   160
  Static evaluation freezes the code generator configuration at a
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   161
  certain point and uses this context whenever evaluation is issued
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   162
  later on.  This is particularly appropriate for proof procedures
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   163
  which use evaluation, since then the behaviour of evaluation is not
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   164
  changed or even compromised later on by actions of the user.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   165
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   166
  As a technical complication, terms after evaluation in ML must be
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   167
  turned into Isabelle's internal term representation again.  Since
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   168
  this is also configurable, it is never fully trusted.  For this
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   169
  reason, evaluation in ML comes with further aspects:
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   170
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   171
  \begin{description}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   172
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   173
    \item[Plain evaluation.]  A term is normalized using the provided
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   174
      term reconstruction from ML to Isabelle; for applications which
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   175
      do not need to be fully trusted.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   176
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   177
    \item[Property conversion.]  Evaluates propositions; since these
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   178
      are monomorphic, the term reconstruction is fixed once and for all
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   179
      and therefore trustable.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   180
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   181
    \item[Conversion.]  Evaluates an arbitrary term \isa{t} first
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   182
      by plain evaluation and certifies the result \isa{t{\isaliteral{27}{\isacharprime}}} by
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   183
      checking the equation \isa{t\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ t{\isaliteral{27}{\isacharprime}}} using property
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   184
      conversion.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   185
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   186
  \end{description}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   187
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   188
  \noindent The picture is further complicated by the roles of
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   189
  exceptions.  Here three cases have to be distinguished:
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   190
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   191
  \begin{itemize}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   192
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   193
    \item Evaluation of \isa{t} terminates with a result \isa{t{\isaliteral{27}{\isacharprime}}}.
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   194
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   195
    \item Evaluation of \isa{t} terminates which en exception
40350
1ef7ee8dd165 fixed typos
haftmann
parents: 39745
diff changeset
   196
      indicating a pattern match failure or a non-implemented
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   197
      function.  As sketched in \secref{sec:partiality}, this can be
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   198
      interpreted as partiality.
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   199
     
39643
29cc021398fc corrections and tuning
haftmann
parents: 39609
diff changeset
   200
    \item Evaluation raises any other kind of exception.
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   201
     
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   202
  \end{itemize}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   203
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   204
  \noindent For conversions, the first case yields the equation \isa{t\ {\isaliteral{3D}{\isacharequal}}\ t{\isaliteral{27}{\isacharprime}}}, the second defaults to reflexivity \isa{t\ {\isaliteral{3D}{\isacharequal}}\ t}.
39643
29cc021398fc corrections and tuning
haftmann
parents: 39609
diff changeset
   205
  Exceptions of the third kind are propagated to the user.
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   206
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   207
  By default return values of plain evaluation are optional, yielding
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   208
  \isa{SOME\ t{\isaliteral{27}{\isacharprime}}} in the first case, \isa{NONE} in the
40350
1ef7ee8dd165 fixed typos
haftmann
parents: 39745
diff changeset
   209
  second, and propagating the exception in the third case.  A strict
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   210
  variant of plain evaluation either yields \isa{t{\isaliteral{27}{\isacharprime}}} or propagates
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   211
  any exception, a liberal variant caputures any exception in a result
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   212
  of type \isa{Exn{\isaliteral{2E}{\isachardot}}result}.
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   213
  
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   214
  For property conversion (which coincides with conversion except for
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   215
  evaluation in ML), methods are provided which solve a given goal by
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   216
  evaluation.%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   217
\end{isamarkuptext}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   218
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   219
%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   220
\isamarkupsubsection{Schematic overview%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   221
}
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   222
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   223
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   224
\begin{isamarkuptext}%
39693
2ef15ec8e7dc tuned schema table
haftmann
parents: 39643
diff changeset
   225
\newcommand{\ttsize}{\fontsize{5.8pt}{8pt}\selectfont}
2ef15ec8e7dc tuned schema table
haftmann
parents: 39643
diff changeset
   226
  \fontsize{9pt}{12pt}\selectfont
2ef15ec8e7dc tuned schema table
haftmann
parents: 39643
diff changeset
   227
  \begin{tabular}{ll||c|c|c}
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   228
    & & \isa{simp} & \isa{nbe} & \isa{code} \tabularnewline \hline \hline
39693
2ef15ec8e7dc tuned schema table
haftmann
parents: 39643
diff changeset
   229
    \multirow{5}{1ex}{\rotatebox{90}{dynamic}}
2ef15ec8e7dc tuned schema table
haftmann
parents: 39643
diff changeset
   230
      & interactive evaluation 
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   231
      & \hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}} \isa{{\isaliteral{5B}{\isacharbrackleft}}simp{\isaliteral{5D}{\isacharbrackright}}} & \hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}} \isa{{\isaliteral{5B}{\isacharbrackleft}}nbe{\isaliteral{5D}{\isacharbrackright}}} & \hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}} \isa{{\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}}
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   232
      \tabularnewline
39693
2ef15ec8e7dc tuned schema table
haftmann
parents: 39643
diff changeset
   233
    & plain evaluation & & & \ttsize\verb|Code_Evaluation.dynamic_value| \tabularnewline \cline{2-5}
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   234
    & evaluation method & \hyperlink{method.code-simp}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}simp}}} & \hyperlink{method.normalization}{\mbox{\isa{normalization}}} & \hyperlink{method.eval}{\mbox{\isa{eval}}} \tabularnewline
39693
2ef15ec8e7dc tuned schema table
haftmann
parents: 39643
diff changeset
   235
    & property conversion & & & \ttsize\verb|Code_Runtime.dynamic_holds_conv| \tabularnewline \cline{2-5}
41184
5c6f44d22f51 simplified evaluation function names
haftmann
parents: 40755
diff changeset
   236
    & conversion & \ttsize\verb|Code_Simp.dynamic_conv| & \ttsize\verb|Nbe.dynamic_conv|
5c6f44d22f51 simplified evaluation function names
haftmann
parents: 40755
diff changeset
   237
      & \ttsize\verb|Code_Evaluation.dynamic_conv| \tabularnewline \hline \hline
39693
2ef15ec8e7dc tuned schema table
haftmann
parents: 39643
diff changeset
   238
    \multirow{3}{1ex}{\rotatebox{90}{static}}
41185
d5f0e556ffd3 updated generated files
haftmann
parents: 41184
diff changeset
   239
    & plain evaluation & & & \ttsize\verb|Code_Evaluation.static_value| \tabularnewline \cline{2-5}
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   240
    & property conversion & &
39693
2ef15ec8e7dc tuned schema table
haftmann
parents: 39643
diff changeset
   241
      & \ttsize\verb|Code_Runtime.static_holds_conv| \tabularnewline \cline{2-5}
41184
5c6f44d22f51 simplified evaluation function names
haftmann
parents: 40755
diff changeset
   242
    & conversion & \ttsize\verb|Code_Simp.static_conv|
5c6f44d22f51 simplified evaluation function names
haftmann
parents: 40755
diff changeset
   243
      & \ttsize\verb|Nbe.static_conv|
5c6f44d22f51 simplified evaluation function names
haftmann
parents: 40755
diff changeset
   244
      & \ttsize\verb|Code_Evaluation.static_conv|
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   245
  \end{tabular}%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   246
\end{isamarkuptext}%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   247
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   248
%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   249
\isamarkupsubsection{Intimate connection between logic and system runtime%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   250
}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   251
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   252
%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   253
\begin{isamarkuptext}%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   254
The toolbox of static evaluation conversions forms a reasonable base
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   255
  to interweave generated code and system tools.  However in some
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   256
  situations more direct interaction is desirable.%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   257
\end{isamarkuptext}%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   258
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   259
%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   260
\isamarkupsubsubsection{Static embedding of generated code into system runtime -- the \isa{code} antiquotation%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   261
}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   262
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   263
%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   264
\begin{isamarkuptext}%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   265
The \isa{code} antiquotation allows to include constants from
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   266
  generated code directly into ML system code, as in the following toy
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   267
  example:%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   268
\end{isamarkuptext}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   269
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   270
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   271
\isadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   272
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   273
\endisadelimquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   274
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   275
\isatagquote
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   276
\isacommand{datatype}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   277
\ form\ {\isaliteral{3D}{\isacharequal}}\ T\ {\isaliteral{7C}{\isacharbar}}\ F\ {\isaliteral{7C}{\isacharbar}}\ And\ form\ form\ {\isaliteral{7C}{\isacharbar}}\ Or\ form\ form\ %
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   278
\endisatagquote
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   279
{\isafoldquote}%
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   280
%
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   281
\isadelimquote
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   282
%
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   283
\endisadelimquote
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   284
%
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   285
\isadelimquotett
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   286
\ %
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   287
\endisadelimquotett
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   288
%
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   289
\isatagquotett
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   290
\isacommand{ML}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   291
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   292
\ \ fun\ eval{\isaliteral{5F}{\isacharunderscore}}form\ %
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   293
\isaantiq
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   294
code\ T{}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   295
\endisaantiq
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   296
\ {\isaliteral{3D}{\isacharequal}}\ true\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   297
\ \ \ \ {\isaliteral{7C}{\isacharbar}}\ eval{\isaliteral{5F}{\isacharunderscore}}form\ %
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   298
\isaantiq
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   299
code\ F{}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   300
\endisaantiq
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   301
\ {\isaliteral{3D}{\isacharequal}}\ false\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   302
\ \ \ \ {\isaliteral{7C}{\isacharbar}}\ eval{\isaliteral{5F}{\isacharunderscore}}form\ {\isaliteral{28}{\isacharparenleft}}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   303
\isaantiq
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   304
code\ And{}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   305
\endisaantiq
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   306
\ {\isaliteral{28}{\isacharparenleft}}p{\isaliteral{2C}{\isacharcomma}}\ q{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   307
\ \ \ \ \ \ \ \ eval{\isaliteral{5F}{\isacharunderscore}}form\ p\ andalso\ eval{\isaliteral{5F}{\isacharunderscore}}form\ q\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   308
\ \ \ \ {\isaliteral{7C}{\isacharbar}}\ eval{\isaliteral{5F}{\isacharunderscore}}form\ {\isaliteral{28}{\isacharparenleft}}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   309
\isaantiq
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   310
code\ Or{}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   311
\endisaantiq
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   312
\ {\isaliteral{28}{\isacharparenleft}}p{\isaliteral{2C}{\isacharcomma}}\ q{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   313
\ \ \ \ \ \ \ \ eval{\isaliteral{5F}{\isacharunderscore}}form\ p\ orelse\ eval{\isaliteral{5F}{\isacharunderscore}}form\ q{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   314
{\isaliteral{2A7D}{\isacharverbatimclose}}%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   315
\endisatagquotett
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   316
{\isafoldquotett}%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   317
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   318
\isadelimquotett
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   319
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39712
diff changeset
   320
\endisadelimquotett
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   321
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   322
\begin{isamarkuptext}%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   323
\noindent \isa{code} takes as argument the name of a constant;
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   324
  after the whole ML is read, the necessary code is generated
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   325
  transparently and the corresponding constant names are inserted.
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   326
  This technique also allows to use pattern matching on constructors
39643
29cc021398fc corrections and tuning
haftmann
parents: 39609
diff changeset
   327
  stemming from compiled datatypes.  Note that the \isa{code}
29cc021398fc corrections and tuning
haftmann
parents: 39609
diff changeset
   328
  antiquotation may not refer to constants which carry adaptations;
29cc021398fc corrections and tuning
haftmann
parents: 39609
diff changeset
   329
  here you have to refer to the corresponding adapted code directly.
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   330
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   331
  For a less simplistic example, theory \isa{Approximation} in
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   332
  the \isa{Decision{\isaliteral{5F}{\isacharunderscore}}Procs} session is a good reference.%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   333
\end{isamarkuptext}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   334
\isamarkuptrue%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   335
%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   336
\isamarkupsubsubsection{Static embedding of generated code into system runtime -- \isa{code{\isaliteral{5F}{\isacharunderscore}}reflect}%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   337
}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   338
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   339
%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   340
\begin{isamarkuptext}%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   341
The \isa{code} antiquoation is lightweight, but the generated code
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   342
  is only accessible while the ML section is processed.  Sometimes this
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   343
  is not appropriate, especially if the generated code contains datatype
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   344
  declarations which are shared with other parts of the system.  In these
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   345
  cases, \indexdef{}{command}{code\_reflect}\hypertarget{command.code-reflect}{\hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}}} can be used:%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   346
\end{isamarkuptext}%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   347
\isamarkuptrue%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   348
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   349
\isadelimquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   350
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   351
\endisadelimquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   352
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   353
\isatagquote
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   354
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}\isamarkupfalse%
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   355
\ Sum{\isaliteral{5F}{\isacharunderscore}}Type\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   356
\ \ \isakeyword{datatypes}\ sum\ {\isaliteral{3D}{\isacharequal}}\ Inl\ {\isaliteral{7C}{\isacharbar}}\ Inr\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   357
\ \ \isakeyword{functions}\ {\isaliteral{22}{\isachardoublequoteopen}}Sum{\isaliteral{5F}{\isacharunderscore}}Type{\isaliteral{2E}{\isachardot}}Projl{\isaliteral{22}{\isachardoublequoteclose}}\ {\isaliteral{22}{\isachardoublequoteopen}}Sum{\isaliteral{5F}{\isacharunderscore}}Type{\isaliteral{2E}{\isachardot}}Projr{\isaliteral{22}{\isachardoublequoteclose}}%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   358
\endisatagquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   359
{\isafoldquote}%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   360
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   361
\isadelimquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   362
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   363
\endisadelimquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   364
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   365
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   366
\noindent \indexdef{}{command}{code\_reflect}\hypertarget{command.code-reflect}{\hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}}} takes a structure name and
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   367
  references to datatypes and functions; for these code is compiled
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   368
  into the named ML structure and the \emph{Eval} target is modified
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   369
  in a way that future code generation will reference these
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   370
  precompiled versions of the given datatypes and functions.  This
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   371
  also allows to refer to the referenced datatypes and functions from
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   372
  arbitrary ML code as well.
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   373
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   374
  A typical example for \hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}} can be found in the
46563
0ad69b30b39c updated generated files (cf. 8d51b375e926);
wenzelm
parents: 46523
diff changeset
   375
  \isa{Predicate} theory.%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   376
\end{isamarkuptext}%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   377
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   378
%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   379
\isamarkupsubsubsection{Separate compilation -- \isa{code{\isaliteral{5F}{\isacharunderscore}}reflect}%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   380
}
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   381
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   382
%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   383
\begin{isamarkuptext}%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   384
For technical reasons it is sometimes necessary to separate
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   385
  generation and compilation of code which is supposed to be used in
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   386
  the system runtime.  For this \hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}} with an
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   387
  optional \isa{file} argument can be used:%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   388
\end{isamarkuptext}%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   389
\isamarkuptrue%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   390
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   391
\isadelimquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   392
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   393
\endisadelimquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   394
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   395
\isatagquote
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   396
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}\isamarkupfalse%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   397
\ Rat\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   398
\ \ \isakeyword{datatypes}\ rat\ {\isaliteral{3D}{\isacharequal}}\ Frct\isanewline
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   399
\ \ \isakeyword{functions}\ Fract\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   400
\ \ \ \ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}plus\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}minus\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   401
\ \ \ \ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}times\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}divide\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 40350
diff changeset
   402
\ \ \isakeyword{file}\ {\isaliteral{22}{\isachardoublequoteopen}}examples{\isaliteral{2F}{\isacharslash}}rat{\isaliteral{2E}{\isachardot}}ML{\isaliteral{22}{\isachardoublequoteclose}}%
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   403
\endisatagquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   404
{\isafoldquote}%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   405
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   406
\isadelimquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   407
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   408
\endisadelimquote
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   409
%
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   410
\begin{isamarkuptext}%
39643
29cc021398fc corrections and tuning
haftmann
parents: 39609
diff changeset
   411
\noindent This merely generates the referenced code to the given
39609
0af12dea761f sections on @{code} and code_reflect
haftmann
parents: 39599
diff changeset
   412
  file which can be included into the system runtime later on.%
39599
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   413
\end{isamarkuptext}%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   414
\isamarkuptrue%
d9c247f7afa3 continued section abut evaluation
haftmann
parents: 39068
diff changeset
   415
%
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   416
\isadelimtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   417
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   418
\endisadelimtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   419
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   420
\isatagtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   421
\isacommand{end}\isamarkupfalse%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   422
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   423
\endisatagtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   424
{\isafoldtheory}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   425
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   426
\isadelimtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   427
%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   428
\endisadelimtheory
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   429
\isanewline
46523
7ca897381b26 update of generated documents
haftmann
parents: 43656
diff changeset
   430
\isanewline
38560
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   431
\end{isabellebody}%
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   432
%%% Local Variables:
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   433
%%% mode: latex
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   434
%%% TeX-master: "root"
004c35739d75 added generated file;
wenzelm
parents:
diff changeset
   435
%%% End: