37614
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Inductive{\isacharunderscore}Predicate}%
|
|
4 |
%
|
|
5 |
\isadelimtheory
|
|
6 |
%
|
|
7 |
\endisadelimtheory
|
|
8 |
%
|
|
9 |
\isatagtheory
|
|
10 |
\isacommand{theory}\isamarkupfalse%
|
|
11 |
\ Inductive{\isacharunderscore}Predicate\isanewline
|
|
12 |
\isakeyword{imports}\ Setup\isanewline
|
|
13 |
\isakeyword{begin}%
|
|
14 |
\endisatagtheory
|
|
15 |
{\isafoldtheory}%
|
|
16 |
%
|
|
17 |
\isadelimtheory
|
|
18 |
%
|
|
19 |
\endisadelimtheory
|
|
20 |
%
|
|
21 |
\isamarkupsubsection{Inductive Predicates%
|
|
22 |
}
|
|
23 |
\isamarkuptrue%
|
|
24 |
%
|
|
25 |
\begin{isamarkuptext}%
|
|
26 |
To execute inductive predicates, a special preprocessor, the predicate
|
|
27 |
compiler, generates code equations from the introduction rules of the predicates.
|
|
28 |
The mechanisms of this compiler are described in \cite{Berghofer-Bulwahn-Haftmann:2009:TPHOL}.
|
|
29 |
Consider the simple predicate \isa{append} given by these two
|
|
30 |
introduction rules:%
|
|
31 |
\end{isamarkuptext}%
|
|
32 |
\isamarkuptrue%
|
|
33 |
%
|
|
34 |
\isadelimquote
|
|
35 |
%
|
|
36 |
\endisadelimquote
|
|
37 |
%
|
|
38 |
\isatagquote
|
|
39 |
%
|
|
40 |
\begin{isamarkuptext}%
|
|
41 |
\isa{append\ {\isacharbrackleft}{\isacharbrackright}\ ys\ ys}\\
|
|
42 |
\noindent\isa{append\ xs\ ys\ zs\ {\isasymLongrightarrow}\ append\ {\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}\ ys\ {\isacharparenleft}x\ {\isacharhash}\ zs{\isacharparenright}}%
|
|
43 |
\end{isamarkuptext}%
|
|
44 |
\isamarkuptrue%
|
|
45 |
%
|
|
46 |
\endisatagquote
|
|
47 |
{\isafoldquote}%
|
|
48 |
%
|
|
49 |
\isadelimquote
|
|
50 |
%
|
|
51 |
\endisadelimquote
|
|
52 |
%
|
|
53 |
\begin{isamarkuptext}%
|
|
54 |
\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}}}}}:%
|
|
55 |
\end{isamarkuptext}%
|
|
56 |
\isamarkuptrue%
|
|
57 |
%
|
|
58 |
\isadelimquote
|
|
59 |
%
|
|
60 |
\endisadelimquote
|
|
61 |
%
|
|
62 |
\isatagquote
|
|
63 |
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
|
|
64 |
\ append\ \isacommand{{\isachardot}}\isamarkupfalse%
|
|
65 |
%
|
|
66 |
\endisatagquote
|
|
67 |
{\isafoldquote}%
|
|
68 |
%
|
|
69 |
\isadelimquote
|
|
70 |
%
|
|
71 |
\endisadelimquote
|
|
72 |
%
|
|
73 |
\begin{isamarkuptext}%
|
|
74 |
\noindent The \hyperlink{command.code-pred}{\mbox{\isa{\isacommand{code{\isacharunderscore}pred}}}} command takes the name
|
|
75 |
of the inductive predicate and then you put a period to discharge
|
|
76 |
a trivial correctness proof.
|
|
77 |
The compiler infers possible modes
|
|
78 |
for the predicate and produces the derived code equations.
|
|
79 |
Modes annotate which (parts of the) arguments are to be taken as input,
|
|
80 |
and which output. Modes are similar to types, but use the notation \isa{i}
|
|
81 |
for input and \isa{o} for output.
|
|
82 |
|
|
83 |
For \isa{append}, the compiler can infer the following modes:
|
|
84 |
\begin{itemize}
|
|
85 |
\item \isa{i\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ bool}
|
|
86 |
\item \isa{i\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool}
|
|
87 |
\item \isa{o\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ bool}
|
|
88 |
\end{itemize}
|
|
89 |
You can compute sets of predicates using \indexdef{}{command}{values}\hypertarget{command.values}{\hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}}}:%
|
|
90 |
\end{isamarkuptext}%
|
|
91 |
\isamarkuptrue%
|
|
92 |
%
|
|
93 |
\isadelimquote
|
|
94 |
%
|
|
95 |
\endisadelimquote
|
|
96 |
%
|
|
97 |
\isatagquote
|
|
98 |
\isacommand{values}\isamarkupfalse%
|
|
99 |
\ {\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}%
|
|
100 |
\endisatagquote
|
|
101 |
{\isafoldquote}%
|
|
102 |
%
|
|
103 |
\isadelimquote
|
|
104 |
%
|
|
105 |
\endisadelimquote
|
|
106 |
%
|
|
107 |
\begin{isamarkuptext}%
|
|
108 |
\noindent outputs \isa{{\isacharbraceleft}{\isacharbrackleft}{\isadigit{1}}{\isacharcomma}\ {\isadigit{2}}{\isacharcomma}\ {\isadigit{3}}{\isacharcomma}\ {\isadigit{4}}{\isacharcomma}\ {\isadigit{5}}{\isacharbrackright}{\isacharbraceright}}, and%
|
|
109 |
\end{isamarkuptext}%
|
|
110 |
\isamarkuptrue%
|
|
111 |
%
|
|
112 |
\isadelimquote
|
|
113 |
%
|
|
114 |
\endisadelimquote
|
|
115 |
%
|
|
116 |
\isatagquote
|
|
117 |
\isacommand{values}\isamarkupfalse%
|
|
118 |
\ {\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}%
|
|
119 |
\endisatagquote
|
|
120 |
{\isafoldquote}%
|
|
121 |
%
|
|
122 |
\isadelimquote
|
|
123 |
%
|
|
124 |
\endisadelimquote
|
|
125 |
%
|
|
126 |
\begin{isamarkuptext}%
|
|
127 |
\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}}.%
|
|
128 |
\end{isamarkuptext}%
|
|
129 |
\isamarkuptrue%
|
|
130 |
%
|
|
131 |
\begin{isamarkuptext}%
|
|
132 |
\noindent If you are only interested in the first elements of the set
|
|
133 |
comprehension (with respect to a depth-first search on the introduction rules), you can
|
|
134 |
pass an argument to
|
|
135 |
\hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}} to specify the number of elements you want:%
|
|
136 |
\end{isamarkuptext}%
|
|
137 |
\isamarkuptrue%
|
|
138 |
%
|
|
139 |
\isadelimquote
|
|
140 |
%
|
|
141 |
\endisadelimquote
|
|
142 |
%
|
|
143 |
\isatagquote
|
|
144 |
\isacommand{values}\isamarkupfalse%
|
|
145 |
\ {\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
|
|
146 |
\isacommand{values}\isamarkupfalse%
|
|
147 |
\ {\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}%
|
|
148 |
\endisatagquote
|
|
149 |
{\isafoldquote}%
|
|
150 |
%
|
|
151 |
\isadelimquote
|
|
152 |
%
|
|
153 |
\endisadelimquote
|
|
154 |
%
|
|
155 |
\begin{isamarkuptext}%
|
|
156 |
\noindent The \hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}} command can only compute set
|
|
157 |
comprehensions for which a mode has been inferred.
|
|
158 |
|
|
159 |
The code equations for a predicate are made available as theorems with
|
|
160 |
the suffix \isa{equation}, and can be inspected with:%
|
|
161 |
\end{isamarkuptext}%
|
|
162 |
\isamarkuptrue%
|
|
163 |
%
|
|
164 |
\isadelimquote
|
|
165 |
%
|
|
166 |
\endisadelimquote
|
|
167 |
%
|
|
168 |
\isatagquote
|
|
169 |
\isacommand{thm}\isamarkupfalse%
|
|
170 |
\ append{\isachardot}equation%
|
|
171 |
\endisatagquote
|
|
172 |
{\isafoldquote}%
|
|
173 |
%
|
|
174 |
\isadelimquote
|
|
175 |
%
|
|
176 |
\endisadelimquote
|
|
177 |
%
|
|
178 |
\begin{isamarkuptext}%
|
|
179 |
\noindent More advanced options are described in the following subsections.%
|
|
180 |
\end{isamarkuptext}%
|
|
181 |
\isamarkuptrue%
|
|
182 |
%
|
|
183 |
\isamarkupsubsubsection{Alternative names for functions%
|
|
184 |
}
|
|
185 |
\isamarkuptrue%
|
|
186 |
%
|
|
187 |
\begin{isamarkuptext}%
|
|
188 |
By default, the functions generated from a predicate are named after the predicate with the
|
|
189 |
mode mangled into the name (e.g., \isa{append{\isacharunderscore}i{\isacharunderscore}i{\isacharunderscore}o}).
|
|
190 |
You can specify your own names as follows:%
|
|
191 |
\end{isamarkuptext}%
|
|
192 |
\isamarkuptrue%
|
|
193 |
%
|
|
194 |
\isadelimquote
|
|
195 |
%
|
|
196 |
\endisadelimquote
|
|
197 |
%
|
|
198 |
\isatagquote
|
|
199 |
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
|
|
200 |
\ {\isacharparenleft}modes{\isacharcolon}\ i\ {\isacharequal}{\isachargreater}\ i\ {\isacharequal}{\isachargreater}\ o\ {\isacharequal}{\isachargreater}\ bool\ as\ concat{\isacharcomma}\isanewline
|
|
201 |
\ \ o\ {\isacharequal}{\isachargreater}\ o\ {\isacharequal}{\isachargreater}\ i\ {\isacharequal}{\isachargreater}\ bool\ as\ split{\isacharcomma}\isanewline
|
|
202 |
\ \ i\ {\isacharequal}{\isachargreater}\ o\ {\isacharequal}{\isachargreater}\ i\ {\isacharequal}{\isachargreater}\ bool\ as\ suffix{\isacharparenright}\ append\ \isacommand{{\isachardot}}\isamarkupfalse%
|
|
203 |
%
|
|
204 |
\endisatagquote
|
|
205 |
{\isafoldquote}%
|
|
206 |
%
|
|
207 |
\isadelimquote
|
|
208 |
%
|
|
209 |
\endisadelimquote
|
|
210 |
%
|
|
211 |
\isamarkupsubsubsection{Alternative introduction rules%
|
|
212 |
}
|
|
213 |
\isamarkuptrue%
|
|
214 |
%
|
|
215 |
\begin{isamarkuptext}%
|
|
216 |
Sometimes the introduction rules of an predicate are not executable because they contain
|
|
217 |
non-executable constants or specific modes could not be inferred.
|
|
218 |
It is also possible that the introduction rules yield a function that loops forever
|
|
219 |
due to the execution in a depth-first search manner.
|
|
220 |
Therefore, you can declare alternative introduction rules for predicates with the attribute
|
|
221 |
\hyperlink{attribute.code-pred-intro}{\mbox{\isa{code{\isacharunderscore}pred{\isacharunderscore}intro}}}.
|
|
222 |
For example, the transitive closure is defined by:%
|
|
223 |
\end{isamarkuptext}%
|
|
224 |
\isamarkuptrue%
|
|
225 |
%
|
|
226 |
\isadelimquote
|
|
227 |
%
|
|
228 |
\endisadelimquote
|
|
229 |
%
|
|
230 |
\isatagquote
|
|
231 |
%
|
|
232 |
\begin{isamarkuptext}%
|
|
233 |
\isa{r\ a\ b\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ b}\\
|
|
234 |
\noindent \isa{{\isasymlbrakk}r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ b{\isacharsemicolon}\ r\ b\ c{\isasymrbrakk}\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ c}%
|
|
235 |
\end{isamarkuptext}%
|
|
236 |
\isamarkuptrue%
|
|
237 |
%
|
|
238 |
\endisatagquote
|
|
239 |
{\isafoldquote}%
|
|
240 |
%
|
|
241 |
\isadelimquote
|
|
242 |
%
|
|
243 |
\endisadelimquote
|
|
244 |
%
|
|
245 |
\begin{isamarkuptext}%
|
|
246 |
\noindent These rules do not suit well for executing the transitive closure
|
|
247 |
with the mode \isa{{\isacharparenleft}i\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool{\isacharparenright}\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool}, as the second rule will
|
|
248 |
cause an infinite loop in the recursive call.
|
|
249 |
This can be avoided using the following alternative rules which are
|
|
250 |
declared to the predicate compiler by the attribute \hyperlink{attribute.code-pred-intro}{\mbox{\isa{code{\isacharunderscore}pred{\isacharunderscore}intro}}}:%
|
|
251 |
\end{isamarkuptext}%
|
|
252 |
\isamarkuptrue%
|
|
253 |
%
|
|
254 |
\isadelimquote
|
|
255 |
%
|
|
256 |
\endisadelimquote
|
|
257 |
%
|
|
258 |
\isatagquote
|
|
259 |
\isacommand{lemma}\isamarkupfalse%
|
|
260 |
\ {\isacharbrackleft}code{\isacharunderscore}pred{\isacharunderscore}intro{\isacharbrackright}{\isacharcolon}\isanewline
|
|
261 |
\ \ {\isachardoublequoteopen}r\ a\ b\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ b{\isachardoublequoteclose}\isanewline
|
|
262 |
\ \ {\isachardoublequoteopen}r\ a\ b\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ b\ c\ {\isasymLongrightarrow}\ r\isactrlsup {\isacharplus}\isactrlsup {\isacharplus}\ a\ c{\isachardoublequoteclose}\isanewline
|
|
263 |
\isacommand{by}\isamarkupfalse%
|
|
264 |
\ auto%
|
|
265 |
\endisatagquote
|
|
266 |
{\isafoldquote}%
|
|
267 |
%
|
|
268 |
\isadelimquote
|
|
269 |
%
|
|
270 |
\endisadelimquote
|
|
271 |
%
|
|
272 |
\begin{isamarkuptext}%
|
|
273 |
\noindent After declaring all alternative rules for the transitive closure,
|
|
274 |
you invoke \hyperlink{command.code-pred}{\mbox{\isa{\isacommand{code{\isacharunderscore}pred}}}} as usual.
|
|
275 |
As you have declared alternative rules for the predicate, you are urged to prove that these
|
|
276 |
introduction rules are complete, i.e., that you can derive an elimination rule for the
|
|
277 |
alternative rules:%
|
|
278 |
\end{isamarkuptext}%
|
|
279 |
\isamarkuptrue%
|
|
280 |
%
|
|
281 |
\isadelimquote
|
|
282 |
%
|
|
283 |
\endisadelimquote
|
|
284 |
%
|
|
285 |
\isatagquote
|
|
286 |
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
|
|
287 |
\ tranclp\isanewline
|
|
288 |
\isacommand{proof}\isamarkupfalse%
|
|
289 |
\ {\isacharminus}\isanewline
|
|
290 |
\ \ \isacommand{case}\isamarkupfalse%
|
|
291 |
\ tranclp\isanewline
|
|
292 |
\ \ \isacommand{from}\isamarkupfalse%
|
|
293 |
\ this\ converse{\isacharunderscore}tranclpE{\isacharbrackleft}OF\ this{\isacharparenleft}{\isadigit{1}}{\isacharparenright}{\isacharbrackright}\ \isacommand{show}\isamarkupfalse%
|
|
294 |
\ thesis\ \isacommand{by}\isamarkupfalse%
|
|
295 |
\ metis\isanewline
|
|
296 |
\isacommand{qed}\isamarkupfalse%
|
|
297 |
%
|
|
298 |
\endisatagquote
|
|
299 |
{\isafoldquote}%
|
|
300 |
%
|
|
301 |
\isadelimquote
|
|
302 |
%
|
|
303 |
\endisadelimquote
|
|
304 |
%
|
|
305 |
\begin{isamarkuptext}%
|
|
306 |
\noindent Alternative rules can also be used for constants that have not
|
|
307 |
been defined inductively. For example, the lexicographic order which
|
|
308 |
is defined as:%
|
|
309 |
\end{isamarkuptext}%
|
|
310 |
\isamarkuptrue%
|
|
311 |
%
|
|
312 |
\isadelimquote
|
|
313 |
%
|
|
314 |
\endisadelimquote
|
|
315 |
%
|
|
316 |
\isatagquote
|
|
317 |
%
|
|
318 |
\begin{isamarkuptext}%
|
|
319 |
\begin{isabelle}%
|
|
320 |
lexord\ r\ {\isacharequal}\isanewline
|
|
321 |
{\isacharbraceleft}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}{\isachardot}\isanewline
|
|
322 |
\isaindent{\ }{\isasymexists}a\ v{\isachardot}\ y\ {\isacharequal}\ x\ {\isacharat}\ a\ {\isacharhash}\ v\ {\isasymor}\isanewline
|
|
323 |
\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}%
|
|
324 |
\end{isabelle}%
|
|
325 |
\end{isamarkuptext}%
|
|
326 |
\isamarkuptrue%
|
|
327 |
%
|
|
328 |
\endisatagquote
|
|
329 |
{\isafoldquote}%
|
|
330 |
%
|
|
331 |
\isadelimquote
|
|
332 |
%
|
|
333 |
\endisadelimquote
|
|
334 |
%
|
|
335 |
\begin{isamarkuptext}%
|
|
336 |
\noindent To make it executable, you can derive the following two rules and prove the
|
|
337 |
elimination rule:%
|
|
338 |
\end{isamarkuptext}%
|
|
339 |
\isamarkuptrue%
|
|
340 |
%
|
|
341 |
\isadelimproof
|
|
342 |
%
|
|
343 |
\endisadelimproof
|
|
344 |
%
|
|
345 |
\isatagproof
|
|
346 |
%
|
|
347 |
\endisatagproof
|
|
348 |
{\isafoldproof}%
|
|
349 |
%
|
|
350 |
\isadelimproof
|
|
351 |
%
|
|
352 |
\endisadelimproof
|
|
353 |
%
|
|
354 |
\isadelimquote
|
|
355 |
%
|
|
356 |
\endisadelimquote
|
|
357 |
%
|
|
358 |
\isatagquote
|
|
359 |
\isacommand{lemma}\isamarkupfalse%
|
|
360 |
\ {\isacharbrackleft}code{\isacharunderscore}pred{\isacharunderscore}intro{\isacharbrackright}{\isacharcolon}\isanewline
|
|
361 |
\ \ {\isachardoublequoteopen}append\ xs\ {\isacharparenleft}a\ {\isacharhash}\ v{\isacharparenright}\ ys\ {\isasymLongrightarrow}\ lexord\ r\ {\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
|
362 |
\isacommand{lemma}\isamarkupfalse%
|
|
363 |
\ {\isacharbrackleft}code{\isacharunderscore}pred{\isacharunderscore}intro{\isacharbrackright}{\isacharcolon}\isanewline
|
|
364 |
\ \ {\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
|
|
365 |
\ \ {\isasymLongrightarrow}\ lexord\ r\ {\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
|
366 |
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
|
|
367 |
\ lexord%
|
|
368 |
\endisatagquote
|
|
369 |
{\isafoldquote}%
|
|
370 |
%
|
|
371 |
\isadelimquote
|
|
372 |
%
|
|
373 |
\endisadelimquote
|
|
374 |
%
|
|
375 |
\isamarkupsubsubsection{Options for values%
|
|
376 |
}
|
|
377 |
\isamarkuptrue%
|
|
378 |
%
|
|
379 |
\begin{isamarkuptext}%
|
|
380 |
In the presence of higher-order predicates, multiple modes for some predicate could be inferred
|
|
381 |
that are not disambiguated by the pattern of the set comprehension.
|
|
382 |
To disambiguate the modes for the arguments of a predicate, you can state
|
|
383 |
the modes explicitly in the \hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}} command.
|
|
384 |
Consider the simple predicate \isa{succ}:%
|
|
385 |
\end{isamarkuptext}%
|
|
386 |
\isamarkuptrue%
|
|
387 |
\isacommand{inductive}\isamarkupfalse%
|
|
388 |
\ succ\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\isanewline
|
|
389 |
\isakeyword{where}\isanewline
|
|
390 |
\ \ {\isachardoublequoteopen}succ\ {\isadigit{0}}\ {\isacharparenleft}Suc\ {\isadigit{0}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
|
391 |
{\isacharbar}\ {\isachardoublequoteopen}succ\ x\ y\ {\isasymLongrightarrow}\ succ\ {\isacharparenleft}Suc\ x{\isacharparenright}\ {\isacharparenleft}Suc\ y{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
|
392 |
\isanewline
|
|
393 |
\isacommand{code{\isacharunderscore}pred}\isamarkupfalse%
|
|
394 |
\ succ%
|
|
395 |
\isadelimproof
|
|
396 |
\ %
|
|
397 |
\endisadelimproof
|
|
398 |
%
|
|
399 |
\isatagproof
|
|
400 |
\isacommand{{\isachardot}}\isamarkupfalse%
|
|
401 |
%
|
|
402 |
\endisatagproof
|
|
403 |
{\isafoldproof}%
|
|
404 |
%
|
|
405 |
\isadelimproof
|
|
406 |
%
|
|
407 |
\endisadelimproof
|
|
408 |
%
|
|
409 |
\begin{isamarkuptext}%
|
|
410 |
\noindent For this, the predicate compiler can infer modes \isa{o\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool}, \isa{i\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool},
|
|
411 |
\isa{o\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ bool} and \isa{i\ {\isasymRightarrow}\ i\ {\isasymRightarrow}\ bool}.
|
|
412 |
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
|
|
413 |
modes for the predicate \isa{succ} are possible and here the first mode \isa{o\ {\isasymRightarrow}\ o\ {\isasymRightarrow}\ bool}
|
|
414 |
is chosen. To choose another mode for the argument, you can declare the mode for the argument between
|
|
415 |
the \hyperlink{command.values}{\mbox{\isa{\isacommand{values}}}} and the number of elements.%
|
|
416 |
\end{isamarkuptext}%
|
|
417 |
\isamarkuptrue%
|
|
418 |
%
|
|
419 |
\isadelimquote
|
|
420 |
%
|
|
421 |
\endisadelimquote
|
|
422 |
%
|
|
423 |
\isatagquote
|
|
424 |
\isacommand{values}\isamarkupfalse%
|
|
425 |
\ {\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
|
|
426 |
\isacommand{values}\isamarkupfalse%
|
|
427 |
\ {\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}%
|
|
428 |
\endisatagquote
|
|
429 |
{\isafoldquote}%
|
|
430 |
%
|
|
431 |
\isadelimquote
|
|
432 |
%
|
|
433 |
\endisadelimquote
|
|
434 |
%
|
|
435 |
\isamarkupsubsubsection{Embedding into functional code within Isabelle/HOL%
|
|
436 |
}
|
|
437 |
\isamarkuptrue%
|
|
438 |
%
|
|
439 |
\begin{isamarkuptext}%
|
|
440 |
To embed the computation of an inductive predicate into functions that are defined in Isabelle/HOL,
|
|
441 |
you have a number of options:
|
|
442 |
\begin{itemize}
|
|
443 |
\item You want to use the first-order predicate with the mode
|
|
444 |
where all arguments are input. Then you can use the predicate directly, e.g.
|
|
445 |
\begin{quote}
|
|
446 |
\isa{valid{\isacharunderscore}suffix\ ys\ zs\ {\isacharequal}}\\
|
|
447 |
\isa{{\isacharparenleft}if\ append\ {\isacharbrackleft}Suc\ {\isadigit{0}}{\isacharcomma}\ {\isadigit{2}}{\isacharbrackright}\ ys\ zs\ then\ Some\ ys\ else\ None{\isacharparenright}}
|
|
448 |
\end{quote}
|
|
449 |
\item If you know that the execution returns only one value (it is deterministic), then you can
|
|
450 |
use the combinator \isa{Predicate{\isachardot}the}, e.g., a functional concatenation of lists
|
|
451 |
is defined with
|
|
452 |
\begin{quote}
|
|
453 |
\isa{functional{\isacharunderscore}concat\ xs\ ys\ {\isacharequal}\ Predicate{\isachardot}the\ {\isacharparenleft}append{\isacharunderscore}i{\isacharunderscore}i{\isacharunderscore}o\ xs\ ys{\isacharparenright}}
|
|
454 |
\end{quote}
|
|
455 |
Note that if the evaluation does not return a unique value, it raises a run-time error
|
|
456 |
\isa{not{\isacharunderscore}unique}.
|
|
457 |
\end{itemize}%
|
|
458 |
\end{isamarkuptext}%
|
|
459 |
\isamarkuptrue%
|
|
460 |
%
|
|
461 |
\isamarkupsubsubsection{Further Examples%
|
|
462 |
}
|
|
463 |
\isamarkuptrue%
|
|
464 |
%
|
|
465 |
\begin{isamarkuptext}%
|
|
466 |
Further examples for compiling inductive predicates can be found in
|
|
467 |
the \isa{HOL{\isacharslash}ex{\isacharslash}Predicate{\isacharunderscore}Compile{\isacharunderscore}ex} theory file.
|
|
468 |
There are also some examples in the Archive of Formal Proofs, notably
|
|
469 |
in the \isa{POPLmark{\isacharminus}deBruijn} and the \isa{FeatherweightJava} sessions.%
|
|
470 |
\end{isamarkuptext}%
|
|
471 |
\isamarkuptrue%
|
|
472 |
%
|
|
473 |
\isadelimtheory
|
|
474 |
%
|
|
475 |
\endisadelimtheory
|
|
476 |
%
|
|
477 |
\isatagtheory
|
|
478 |
\isacommand{end}\isamarkupfalse%
|
|
479 |
%
|
|
480 |
\endisatagtheory
|
|
481 |
{\isafoldtheory}%
|
|
482 |
%
|
|
483 |
\isadelimtheory
|
|
484 |
%
|
|
485 |
\endisadelimtheory
|
|
486 |
\isanewline
|
|
487 |
\end{isabellebody}%
|
|
488 |
%%% Local Variables:
|
|
489 |
%%% mode: latex
|
|
490 |
%%% TeX-master: "root"
|
|
491 |
%%% End:
|