38560
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Evaluation}%
|
|
4 |
%
|
|
5 |
\isadelimtheory
|
|
6 |
%
|
|
7 |
\endisadelimtheory
|
|
8 |
%
|
|
9 |
\isatagtheory
|
|
10 |
\isacommand{theory}\isamarkupfalse%
|
|
11 |
\ Evaluation\isanewline
|
|
12 |
\isakeyword{imports}\ Setup\isanewline
|
|
13 |
\isakeyword{begin}%
|
|
14 |
\endisatagtheory
|
|
15 |
{\isafoldtheory}%
|
|
16 |
%
|
|
17 |
\isadelimtheory
|
|
18 |
%
|
|
19 |
\endisadelimtheory
|
|
20 |
%
|
|
21 |
\isamarkupsection{Evaluation%
|
|
22 |
}
|
|
23 |
\isamarkuptrue%
|
|
24 |
%
|
|
25 |
\begin{isamarkuptext}%
|
|
26 |
Introduction%
|
|
27 |
\end{isamarkuptext}%
|
|
28 |
\isamarkuptrue%
|
|
29 |
%
|
|
30 |
\isamarkupsubsection{Evaluation techniques%
|
|
31 |
}
|
|
32 |
\isamarkuptrue%
|
|
33 |
%
|
|
34 |
\begin{isamarkuptext}%
|
|
35 |
simplifier%
|
|
36 |
\end{isamarkuptext}%
|
|
37 |
\isamarkuptrue%
|
|
38 |
%
|
|
39 |
\begin{isamarkuptext}%
|
|
40 |
nbe%
|
|
41 |
\end{isamarkuptext}%
|
|
42 |
\isamarkuptrue%
|
|
43 |
%
|
|
44 |
\begin{isamarkuptext}%
|
|
45 |
eval target: SML standalone vs. Isabelle/SML, example, soundness%
|
|
46 |
\end{isamarkuptext}%
|
|
47 |
\isamarkuptrue%
|
|
48 |
%
|
|
49 |
\isamarkupsubsection{Dynamic evaluation%
|
|
50 |
}
|
|
51 |
\isamarkuptrue%
|
|
52 |
%
|
|
53 |
\begin{isamarkuptext}%
|
|
54 |
value (three variants)%
|
|
55 |
\end{isamarkuptext}%
|
|
56 |
\isamarkuptrue%
|
|
57 |
%
|
|
58 |
\begin{isamarkuptext}%
|
|
59 |
methods (three variants)%
|
|
60 |
\end{isamarkuptext}%
|
|
61 |
\isamarkuptrue%
|
|
62 |
%
|
|
63 |
\begin{isamarkuptext}%
|
|
64 |
corresponding ML interfaces%
|
|
65 |
\end{isamarkuptext}%
|
|
66 |
\isamarkuptrue%
|
|
67 |
%
|
|
68 |
\isamarkupsubsection{Static evaluation%
|
|
69 |
}
|
|
70 |
\isamarkuptrue%
|
|
71 |
%
|
|
72 |
\begin{isamarkuptext}%
|
|
73 |
code_simp, nbe (tbd), Eval (tbd, in simple fashion)%
|
|
74 |
\end{isamarkuptext}%
|
|
75 |
\isamarkuptrue%
|
|
76 |
%
|
|
77 |
\begin{isamarkuptext}%
|
|
78 |
hand-written: code antiquotation%
|
|
79 |
\end{isamarkuptext}%
|
|
80 |
\isamarkuptrue%
|
|
81 |
%
|
|
82 |
\isamarkupsubsection{Hybrid techniques%
|
|
83 |
}
|
|
84 |
\isamarkuptrue%
|
|
85 |
%
|
|
86 |
\begin{isamarkuptext}%
|
|
87 |
code reflect runtime%
|
|
88 |
\end{isamarkuptext}%
|
|
89 |
\isamarkuptrue%
|
|
90 |
%
|
|
91 |
\begin{isamarkuptext}%
|
|
92 |
code reflect external%
|
|
93 |
\end{isamarkuptext}%
|
|
94 |
\isamarkuptrue%
|
|
95 |
%
|
|
96 |
\begin{isamarkuptext}%
|
|
97 |
FIXME here the old sections follow%
|
|
98 |
\end{isamarkuptext}%
|
|
99 |
\isamarkuptrue%
|
|
100 |
%
|
|
101 |
\isamarkupsubsection{Evaluation oracle%
|
|
102 |
}
|
|
103 |
\isamarkuptrue%
|
|
104 |
%
|
|
105 |
\begin{isamarkuptext}%
|
|
106 |
Code generation may also be used to \emph{evaluate} expressions
|
|
107 |
(using \isa{SML} as target language of course).
|
|
108 |
For instance, the \indexdef{}{command}{value}\hypertarget{command.value}{\hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}}} reduces an expression to a
|
|
109 |
normal form with respect to the underlying code equations:%
|
|
110 |
\end{isamarkuptext}%
|
|
111 |
\isamarkuptrue%
|
|
112 |
%
|
|
113 |
\isadelimquote
|
|
114 |
%
|
|
115 |
\endisadelimquote
|
|
116 |
%
|
|
117 |
\isatagquote
|
|
118 |
\isacommand{value}\isamarkupfalse%
|
|
119 |
\ {\isachardoublequoteopen}{\isadigit{4}}{\isadigit{2}}\ {\isacharslash}\ {\isacharparenleft}{\isadigit{1}}{\isadigit{2}}\ {\isacharcolon}{\isacharcolon}\ rat{\isacharparenright}{\isachardoublequoteclose}%
|
|
120 |
\endisatagquote
|
|
121 |
{\isafoldquote}%
|
|
122 |
%
|
|
123 |
\isadelimquote
|
|
124 |
%
|
|
125 |
\endisadelimquote
|
|
126 |
%
|
|
127 |
\begin{isamarkuptext}%
|
|
128 |
\noindent will display \isa{{\isadigit{7}}\ {\isacharslash}\ {\isadigit{2}}}.
|
|
129 |
|
|
130 |
The \hyperlink{method.eval}{\mbox{\isa{eval}}} method tries to reduce a goal by code generation to \isa{True}
|
|
131 |
and solves it in that case, but fails otherwise:%
|
|
132 |
\end{isamarkuptext}%
|
|
133 |
\isamarkuptrue%
|
|
134 |
%
|
|
135 |
\isadelimquote
|
|
136 |
%
|
|
137 |
\endisadelimquote
|
|
138 |
%
|
|
139 |
\isatagquote
|
|
140 |
\isacommand{lemma}\isamarkupfalse%
|
|
141 |
\ {\isachardoublequoteopen}{\isadigit{4}}{\isadigit{2}}\ {\isacharslash}\ {\isacharparenleft}{\isadigit{1}}{\isadigit{2}}\ {\isacharcolon}{\isacharcolon}\ rat{\isacharparenright}\ {\isacharequal}\ {\isadigit{7}}\ {\isacharslash}\ {\isadigit{2}}{\isachardoublequoteclose}\isanewline
|
|
142 |
\ \ \isacommand{by}\isamarkupfalse%
|
|
143 |
\ eval%
|
|
144 |
\endisatagquote
|
|
145 |
{\isafoldquote}%
|
|
146 |
%
|
|
147 |
\isadelimquote
|
|
148 |
%
|
|
149 |
\endisadelimquote
|
|
150 |
%
|
|
151 |
\begin{isamarkuptext}%
|
|
152 |
\noindent The soundness of the \hyperlink{method.eval}{\mbox{\isa{eval}}} method depends crucially
|
|
153 |
on the correctness of the code generator; this is one of the reasons
|
|
154 |
why you should not use adaptation (see \secref{sec:adaptation}) frivolously.%
|
|
155 |
\end{isamarkuptext}%
|
|
156 |
\isamarkuptrue%
|
|
157 |
%
|
|
158 |
\isamarkupsubsubsection{Code antiquotation%
|
|
159 |
}
|
|
160 |
\isamarkuptrue%
|
|
161 |
%
|
|
162 |
\begin{isamarkuptext}%
|
|
163 |
In scenarios involving techniques like reflection it is quite common
|
|
164 |
that code generated from a theory forms the basis for implementing
|
|
165 |
a proof procedure in \isa{SML}. To facilitate interfacing of generated code
|
|
166 |
with system code, the code generator provides a \isa{code} antiquotation:%
|
|
167 |
\end{isamarkuptext}%
|
|
168 |
\isamarkuptrue%
|
|
169 |
%
|
|
170 |
\isadelimquote
|
|
171 |
%
|
|
172 |
\endisadelimquote
|
|
173 |
%
|
|
174 |
\isatagquote
|
|
175 |
\isacommand{datatype}\isamarkupfalse%
|
|
176 |
\ form\ {\isacharequal}\ T\ {\isacharbar}\ F\ {\isacharbar}\ And\ form\ form\ {\isacharbar}\ Or\ form\ form\ %
|
|
177 |
\endisatagquote
|
|
178 |
{\isafoldquote}%
|
|
179 |
%
|
|
180 |
\isadelimquote
|
|
181 |
%
|
|
182 |
\endisadelimquote
|
|
183 |
%
|
|
184 |
\isadelimquotett
|
|
185 |
\ %
|
|
186 |
\endisadelimquotett
|
|
187 |
%
|
|
188 |
\isatagquotett
|
|
189 |
\isacommand{ML}\isamarkupfalse%
|
|
190 |
\ {\isacharverbatimopen}\isanewline
|
|
191 |
\ \ fun\ eval{\isacharunderscore}form\ %
|
|
192 |
\isaantiq
|
|
193 |
code\ T%
|
|
194 |
\endisaantiq
|
|
195 |
\ {\isacharequal}\ true\isanewline
|
|
196 |
\ \ \ \ {\isacharbar}\ eval{\isacharunderscore}form\ %
|
|
197 |
\isaantiq
|
|
198 |
code\ F%
|
|
199 |
\endisaantiq
|
|
200 |
\ {\isacharequal}\ false\isanewline
|
|
201 |
\ \ \ \ {\isacharbar}\ eval{\isacharunderscore}form\ {\isacharparenleft}%
|
|
202 |
\isaantiq
|
|
203 |
code\ And%
|
|
204 |
\endisaantiq
|
|
205 |
\ {\isacharparenleft}p{\isacharcomma}\ q{\isacharparenright}{\isacharparenright}\ {\isacharequal}\isanewline
|
|
206 |
\ \ \ \ \ \ \ \ eval{\isacharunderscore}form\ p\ andalso\ eval{\isacharunderscore}form\ q\isanewline
|
|
207 |
\ \ \ \ {\isacharbar}\ eval{\isacharunderscore}form\ {\isacharparenleft}%
|
|
208 |
\isaantiq
|
|
209 |
code\ Or%
|
|
210 |
\endisaantiq
|
|
211 |
\ {\isacharparenleft}p{\isacharcomma}\ q{\isacharparenright}{\isacharparenright}\ {\isacharequal}\isanewline
|
|
212 |
\ \ \ \ \ \ \ \ eval{\isacharunderscore}form\ p\ orelse\ eval{\isacharunderscore}form\ q{\isacharsemicolon}\isanewline
|
|
213 |
{\isacharverbatimclose}%
|
|
214 |
\endisatagquotett
|
|
215 |
{\isafoldquotett}%
|
|
216 |
%
|
|
217 |
\isadelimquotett
|
|
218 |
%
|
|
219 |
\endisadelimquotett
|
|
220 |
%
|
|
221 |
\begin{isamarkuptext}%
|
|
222 |
\noindent \isa{code} takes as argument the name of a constant; after the
|
|
223 |
whole \isa{SML} is read, the necessary code is generated transparently
|
|
224 |
and the corresponding constant names are inserted. This technique also
|
|
225 |
allows to use pattern matching on constructors stemming from compiled
|
|
226 |
\isa{datatypes}.
|
|
227 |
|
39068
|
228 |
For a less simplistic example, theory \isa{Ferrack} is
|
38560
|
229 |
a good reference.%
|
|
230 |
\end{isamarkuptext}%
|
|
231 |
\isamarkuptrue%
|
|
232 |
%
|
|
233 |
\isadelimtheory
|
|
234 |
%
|
|
235 |
\endisadelimtheory
|
|
236 |
%
|
|
237 |
\isatagtheory
|
|
238 |
\isacommand{end}\isamarkupfalse%
|
|
239 |
%
|
|
240 |
\endisatagtheory
|
|
241 |
{\isafoldtheory}%
|
|
242 |
%
|
|
243 |
\isadelimtheory
|
|
244 |
%
|
|
245 |
\endisadelimtheory
|
|
246 |
\isanewline
|
|
247 |
\end{isabellebody}%
|
|
248 |
%%% Local Variables:
|
|
249 |
%%% mode: latex
|
|
250 |
%%% TeX-master: "root"
|
|
251 |
%%% End:
|