10879
|
1 |
% $Id$
|
|
2 |
This section describes advanced features of inductive definitions.
|
|
3 |
The premises of introduction rules may contain universal quantifiers and
|
|
4 |
monotonic functions. Theorems may be proved by rule inversion.
|
|
5 |
|
|
6 |
\subsection{Universal Quantifiers in Introduction Rules}
|
|
7 |
\label{sec:gterm-datatype}
|
|
8 |
|
|
9 |
As a running example, this section develops the theory of \textbf{ground
|
|
10 |
terms}: terms constructed from constant and function
|
|
11 |
symbols but not variables. To simplify matters further, we regard a
|
|
12 |
constant as a function applied to the null argument list. Let us declare a
|
|
13 |
datatype \isa{gterm} for the type of ground terms. It is a type constructor
|
|
14 |
whose argument is a type of function symbols.
|
|
15 |
\begin{isabelle}
|
|
16 |
\isacommand{datatype}\ 'f\ gterm\ =\ Apply\ 'f\ "'f\ gterm\ list"
|
|
17 |
\end{isabelle}
|
|
18 |
To try it out, we declare a datatype of some integer operations:
|
|
19 |
integer constants, the unary minus operator and the addition
|
|
20 |
operator.
|
|
21 |
\begin{isabelle}
|
|
22 |
\isacommand{datatype}\ integer_op\ =\ Number\ int\ |\ UnaryMinus\ |\ Plus
|
|
23 |
\end{isabelle}
|
|
24 |
Now the type \isa{integer\_op gterm} denotes the ground
|
|
25 |
terms built over those symbols.
|
|
26 |
|
|
27 |
The type constructor \texttt{gterm} can be generalized to a function
|
|
28 |
over sets. It returns
|
|
29 |
the set of ground terms that can be formed over a set \isa{F} of function symbols. For
|
|
30 |
example, we could consider the set of ground terms formed from the finite
|
10889
|
31 |
set \isa{\isacharbraceleft Number 2, UnaryMinus,
|
|
32 |
Plus\isacharbraceright}.
|
10879
|
33 |
|
|
34 |
This concept is inductive. If we have a list \isa{args} of ground terms
|
|
35 |
over~\isa{F} and a function symbol \isa{f} in \isa{F}, then we
|
|
36 |
can apply \isa{f} to \isa{args} to obtain another ground term.
|
|
37 |
The only difficulty is that the argument list may be of any length. Hitherto,
|
|
38 |
each rule in an inductive definition referred to the inductively
|
|
39 |
defined set a fixed number of times, typically once or twice.
|
|
40 |
A universal quantifier in the premise of the introduction rule
|
|
41 |
expresses that every element of \isa{args} belongs
|
|
42 |
to our inductively defined set: is a ground term
|
|
43 |
over~\isa{F}. The function {\isa{set}} denotes the set of elements in a given
|
|
44 |
list.
|
|
45 |
\begin{isabelle}
|
|
46 |
\isacommand{consts}\ gterms\ ::\ "'f\ set\ \isasymRightarrow \ 'f\ gterm\ set"\isanewline
|
|
47 |
\isacommand{inductive}\ "gterms\ F"\isanewline
|
|
48 |
\isakeyword{intros}\isanewline
|
|
49 |
step[intro!]:\ "\isasymlbrakk \isasymforall t\ \isasymin \ set\ args.\ t\ \isasymin \ gterms\ F;\ \ f\ \isasymin \ F\isasymrbrakk \isanewline
|
|
50 |
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ (Apply\ f\ args)\ \isasymin \ gterms\
|
|
51 |
F"
|
|
52 |
\end{isabelle}
|
|
53 |
|
|
54 |
To demonstrate a proof from this definition, let us
|
|
55 |
show that the function \isa{gterms}
|
|
56 |
is \textbf{monotonic}. We shall need this concept shortly.
|
|
57 |
\begin{isabelle}
|
|
58 |
\isacommand{lemma}\ gterms_mono:\ "F\isasymsubseteq G\ \isasymLongrightarrow \ gterms\ F\ \isasymsubseteq \ gterms\ G"\isanewline
|
|
59 |
\isacommand{apply}\ clarify\isanewline
|
|
60 |
\isacommand{apply}\ (erule\ gterms.induct)\isanewline
|
|
61 |
\isacommand{apply}\ blast\isanewline
|
|
62 |
\isacommand{done}
|
|
63 |
\end{isabelle}
|
|
64 |
Intuitively, this theorem says that
|
|
65 |
enlarging the set of function symbols enlarges the set of ground
|
|
66 |
terms. The proof is a trivial rule induction.
|
|
67 |
First we use the \isa{clarify} method to assume the existence of an element of
|
|
68 |
\isa{terms~F}. (We could have used \isa{intro subsetI}.) We then
|
|
69 |
apply rule induction. Here is the resulting subgoal:
|
|
70 |
\begin{isabelle}
|
|
71 |
\ 1.\ \isasymAnd x\ args\ f.\isanewline
|
|
72 |
\ \ \ \ \ \ \ \isasymlbrakk F\ \isasymsubseteq \ G;\ \isasymforall t\isasymin set\ args.\ t\ \isasymin \ gterms\ F\ \isasymand \ t\ \isasymin \ gterms\ G;\ f\ \isasymin \ F\isasymrbrakk \isanewline
|
|
73 |
\ \ \ \ \ \ \ \isasymLongrightarrow \ Apply\ f\ args\ \isasymin \ gterms\ G%
|
|
74 |
\end{isabelle}
|
|
75 |
%
|
|
76 |
The assumptions state that \isa{f} belongs
|
|
77 |
to~\isa{F}, which is included in~\isa{G}, and that every element of the list \isa{args} is
|
|
78 |
a ground term over~\isa{G}. The \isa{blast} method finds this chain of reasoning easily.
|
|
79 |
|
|
80 |
\begin{warn}
|
|
81 |
Why do we call this function \isa{gterms} instead
|
|
82 |
of {\isa{gterm}}? A constant may have the same name as a type. However,
|
|
83 |
name clashes could arise in the theorems that Isabelle generates.
|
|
84 |
Our choice of names keeps {\isa{gterms.induct}} separate from
|
|
85 |
{\isa{gterm.induct}}.
|
|
86 |
\end{warn}
|
|
87 |
|
|
88 |
|
|
89 |
\subsection{Rule Inversion}\label{sec:rule-inversion}
|
|
90 |
|
|
91 |
Case analysis on an inductive definition is called \textbf{rule inversion}.
|
|
92 |
It is frequently used in proofs about operational semantics. It can be
|
|
93 |
highly effective when it is applied automatically. Let us look at how rule
|
|
94 |
inversion is done in Isabelle.
|
|
95 |
|
|
96 |
Recall that \isa{even} is the minimal set closed under these two rules:
|
|
97 |
\begin{isabelle}
|
|
98 |
0\ \isasymin \ even\isanewline
|
|
99 |
n\ \isasymin \ even\ \isasymLongrightarrow \ (Suc\ (Suc\ n))\ \isasymin
|
|
100 |
\ even
|
|
101 |
\end{isabelle}
|
|
102 |
Minimality means that \isa{even} contains only the elements that these
|
|
103 |
rules force it to contain. If we are told that \isa{a}
|
|
104 |
belongs to
|
|
105 |
\isa{even} then there are only two possibilities. Either \isa{a} is \isa{0}
|
|
106 |
or else \isa{a} has the form \isa{Suc(Suc~n)}, for an arbitrary \isa{n}
|
|
107 |
that belongs to
|
|
108 |
\isa{even}. That is the gist of the \isa{cases} rule, which Isabelle proves
|
|
109 |
for us when it accepts an inductive definition:
|
|
110 |
\begin{isabelle}
|
|
111 |
\isasymlbrakk a\ \isasymin \ even;\isanewline
|
|
112 |
\ a\ =\ 0\ \isasymLongrightarrow \ P;\isanewline
|
|
113 |
\ \isasymAnd n.\ \isasymlbrakk a\ =\ Suc(Suc\ n);\ n\ \isasymin \
|
|
114 |
even\isasymrbrakk \ \isasymLongrightarrow \ P\isasymrbrakk \
|
|
115 |
\isasymLongrightarrow \ P
|
|
116 |
\rulename{even.cases}
|
|
117 |
\end{isabelle}
|
|
118 |
|
|
119 |
This general rule is less useful than instances of it for
|
|
120 |
specific patterns. For example, if \isa{a} has the form
|
|
121 |
\isa{Suc(Suc~n)} then the first case becomes irrelevant, while the second
|
|
122 |
case tells us that \isa{n} belongs to \isa{even}. Isabelle will generate
|
|
123 |
this instance for us:
|
|
124 |
\begin{isabelle}
|
|
125 |
\isacommand{inductive\_cases}\ Suc_Suc_cases\ [elim!]:
|
|
126 |
\ "Suc(Suc\ n)\ \isasymin \ even"
|
|
127 |
\end{isabelle}
|
|
128 |
The \isacommand{inductive\_cases} command generates an instance of the
|
|
129 |
\isa{cases} rule for the supplied pattern and gives it the supplied name:
|
|
130 |
%
|
|
131 |
\begin{isabelle}
|
|
132 |
\isasymlbrakk Suc\ (Suc\ n)\ \isasymin \ even;\ n\ \isasymin \ even\
|
|
133 |
\isasymLongrightarrow \ P\isasymrbrakk \ \isasymLongrightarrow \ P%
|
|
134 |
\rulename{Suc_Suc_cases}
|
|
135 |
\end{isabelle}
|
|
136 |
%
|
|
137 |
Applying this as an elimination rule yields one case where \isa{even.cases}
|
|
138 |
would yield two. Rule inversion works well when the conclusions of the
|
|
139 |
introduction rules involve datatype constructors like \isa{Suc} and \isa{\#}
|
|
140 |
(list `cons'); freeness reasoning discards all but one or two cases.
|
|
141 |
|
|
142 |
In the \isacommand{inductive\_cases} command we supplied an
|
|
143 |
attribute, \isa{elim!}, indicating that this elimination rule can be applied
|
|
144 |
aggressively. The original
|
|
145 |
\isa{cases} rule would loop if used in that manner because the
|
|
146 |
pattern~\isa{a} matches everything.
|
|
147 |
|
|
148 |
The rule \isa{Suc_Suc_cases} is equivalent to the following implication:
|
|
149 |
\begin{isabelle}
|
|
150 |
Suc (Suc\ n)\ \isasymin \ even\ \isasymLongrightarrow \ n\ \isasymin \
|
|
151 |
even
|
|
152 |
\end{isabelle}
|
|
153 |
%
|
|
154 |
In {\S}\ref{sec:gen-rule-induction} we devoted some effort to proving precisely
|
|
155 |
this result. Yet we could have obtained it by a one-line declaration.
|
|
156 |
This example also justifies the terminology \textbf{rule inversion}: the new
|
|
157 |
rule inverts the introduction rule \isa{even.step}.
|
|
158 |
|
|
159 |
For one-off applications of rule inversion, use the \isa{ind_cases} method.
|
|
160 |
Here is an example:
|
|
161 |
\begin{isabelle}
|
|
162 |
\isacommand{apply}\ (ind_cases\ "Suc(Suc\ n)\ \isasymin \ even")
|
|
163 |
\end{isabelle}
|
|
164 |
The specified instance of the \isa{cases} rule is generated, applied, and
|
|
165 |
discarded.
|
|
166 |
|
|
167 |
\medskip
|
|
168 |
Let us try rule inversion on our ground terms example:
|
|
169 |
\begin{isabelle}
|
|
170 |
\isacommand{inductive\_cases}\ gterm_Apply_elim\ [elim!]:\ "Apply\ f\ args\
|
|
171 |
\isasymin\ gterms\ F"
|
|
172 |
\end{isabelle}
|
|
173 |
%
|
|
174 |
Here is the result. No cases are discarded (there was only one to begin
|
|
175 |
with) but the rule applies specifically to the pattern \isa{Apply\ f\ args}.
|
|
176 |
It can be applied repeatedly as an elimination rule without looping, so we
|
|
177 |
have given the
|
|
178 |
\isa{elim!}\ attribute.
|
|
179 |
\begin{isabelle}
|
|
180 |
\isasymlbrakk Apply\ f\ args\ \isasymin \ gterms\ F;\isanewline
|
|
181 |
\ \isasymlbrakk
|
|
182 |
\isasymforall t\isasymin set\ args.\ t\ \isasymin \ gterms\ F;\ f\ \isasymin
|
|
183 |
\ F\isasymrbrakk \ \isasymLongrightarrow \ P\isasymrbrakk\isanewline
|
|
184 |
\isasymLongrightarrow \ P%
|
|
185 |
\rulename{gterm_Apply_elim}
|
|
186 |
\end{isabelle}
|
|
187 |
|
|
188 |
This rule replaces an assumption about \isa{Apply\ f\ args} by
|
|
189 |
assumptions about \isa{f} and~\isa{args}. Here is a proof in which this
|
|
190 |
inference is essential. We show that if \isa{t} is a ground term over both
|
|
191 |
of the sets
|
|
192 |
\isa{F} and~\isa{G} then it is also a ground term over their intersection,
|
|
193 |
\isa{F\isasyminter G}.
|
|
194 |
\begin{isabelle}
|
|
195 |
\isacommand{lemma}\ gterms_IntI\ [rule_format]:\isanewline
|
|
196 |
\ \ \ \ \ "t\ \isasymin \ gterms\ F\ \isasymLongrightarrow \ t\ \isasymin \ gterms\ G\ \isasymlongrightarrow \ t\ \isasymin \ gterms\ (F\isasyminter G)"\isanewline
|
|
197 |
\isacommand{apply}\ (erule\ gterms.induct)\isanewline
|
|
198 |
\isacommand{apply}\ blast\isanewline
|
|
199 |
\isacommand{done}
|
|
200 |
\end{isabelle}
|
|
201 |
%
|
|
202 |
The proof begins with rule induction over the definition of
|
|
203 |
\isa{gterms}, which leaves a single subgoal:
|
|
204 |
\begin{isabelle}
|
|
205 |
1.\ \isasymAnd args\ f.\isanewline
|
|
206 |
\ \ \ \ \ \ \isasymlbrakk \isasymforall t\isasymin set\ args.\ t\ \isasymin \ gterms\ F\ \isasymand\isanewline
|
|
207 |
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (t\ \isasymin \ gterms\ G\ \isasymlongrightarrow \ t\ \isasymin \ gterms\ (F\ \isasyminter \ G));\isanewline
|
|
208 |
\ \ \ \ \ \ \ f\ \isasymin \ F\isasymrbrakk \isanewline
|
|
209 |
\ \ \ \ \ \ \isasymLongrightarrow \ Apply\ f\ args\ \isasymin \ gterms\ G\ \isasymlongrightarrow \ Apply\ f\ args\ \isasymin \ gterms\ (F\ \isasyminter \ G)
|
|
210 |
\end{isabelle}
|
|
211 |
%
|
|
212 |
The induction hypothesis states that every element of \isa{args} belongs to
|
|
213 |
\isa{gterms\ (F\ \isasyminter \ G)} --- provided it already belongs to
|
|
214 |
\isa{gterms\ G}. How do we meet that condition?
|
|
215 |
|
|
216 |
By assuming (as we may) the formula \isa{Apply\ f\ args\ \isasymin \ gterms\
|
|
217 |
G}. Rule inversion, in the form of \isa{gterm_Apply_elim}, infers that every
|
|
218 |
element of \isa{args} belongs to
|
|
219 |
\isa{gterms~G}. It also yields \isa{f\ \isasymin \ G}, which will allow us
|
|
220 |
to conclude \isa{f\ \isasymin \ F\ \isasyminter \ G}. All of this reasoning
|
|
221 |
is done by \isa{blast}.
|
|
222 |
|
|
223 |
\medskip
|
|
224 |
|
|
225 |
To summarize, every inductive definition produces a \isa{cases} rule. The
|
|
226 |
\isacommand{inductive\_cases} command stores an instance of the \isa{cases}
|
|
227 |
rule for a given pattern. Within a proof, the \isa{ind_cases} method
|
|
228 |
applies an instance of the \isa{cases}
|
|
229 |
rule.
|
|
230 |
|
|
231 |
|
|
232 |
\subsection{Continuing the Ground Terms Example}
|
|
233 |
|
|
234 |
Call a term \textbf{well-formed} if each symbol occurring in it has
|
|
235 |
the correct number of arguments. To formalize this concept, we
|
|
236 |
introduce a function mapping each symbol to its \textbf{arity}, a natural
|
|
237 |
number.
|
|
238 |
|
|
239 |
Let us define the set of well-formed ground terms.
|
|
240 |
Suppose we are given a function called \isa{arity}, specifying the arities to be used.
|
|
241 |
In the inductive step, we have a list \isa{args} of such terms and a function
|
|
242 |
symbol~\isa{f}. If the length of the list matches the function's arity
|
|
243 |
then applying \isa{f} to \isa{args} yields a well-formed term.
|
|
244 |
\begin{isabelle}
|
|
245 |
\isacommand{consts}\ well_formed_gterm\ ::\ "('f\ \isasymRightarrow \ nat)\ \isasymRightarrow \ 'f\ gterm\ set"\isanewline
|
|
246 |
\isacommand{inductive}\ "well_formed_gterm\ arity"\isanewline
|
|
247 |
\isakeyword{intros}\isanewline
|
|
248 |
step[intro!]:\ "\isasymlbrakk \isasymforall t\ \isasymin \ set\ args.\ t\ \isasymin \ well_formed_gterm\ arity;\ \ \isanewline
|
|
249 |
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ length\ args\ =\ arity\ f\isasymrbrakk \isanewline
|
|
250 |
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ (Apply\ f\ args)\ \isasymin \ well_formed_gterm\
|
|
251 |
arity"
|
|
252 |
\end{isabelle}
|
|
253 |
%
|
|
254 |
The inductive definition neatly captures the reasoning above.
|
|
255 |
It is just an elaboration of the previous one, consisting of a single
|
|
256 |
introduction rule. The universal quantification over the
|
|
257 |
\isa{set} of arguments expresses that all of them are well-formed.
|
|
258 |
|
|
259 |
\subsection{Alternative Definition Using a Monotonic Function}
|
|
260 |
|
|
261 |
An inductive definition may refer to the inductively defined
|
|
262 |
set through an arbitrary monotonic function. To demonstrate this
|
|
263 |
powerful feature, let us
|
|
264 |
change the inductive definition above, replacing the
|
|
265 |
quantifier by a use of the function \isa{lists}. This
|
|
266 |
function, from the Isabelle theory of lists, is analogous to the
|
|
267 |
function \isa{gterms} declared above: if \isa{A} is a set then
|
|
268 |
{\isa{lists A}} is the set of lists whose elements belong to
|
|
269 |
\isa{A}.
|
|
270 |
|
|
271 |
In the inductive definition of well-formed terms, examine the one
|
|
272 |
introduction rule. The first premise states that \isa{args} belongs to
|
|
273 |
the \isa{lists} of well-formed terms. This formulation is more
|
|
274 |
direct, if more obscure, than using a universal quantifier.
|
|
275 |
\begin{isabelle}
|
|
276 |
\isacommand{consts}\ well_formed_gterm'\ ::\ "('f\ \isasymRightarrow \ nat)\ \isasymRightarrow \ 'f\ gterm\ set"\isanewline
|
|
277 |
\isacommand{inductive}\ "well_formed_gterm'\ arity"\isanewline
|
|
278 |
\isakeyword{intros}\isanewline
|
|
279 |
step[intro!]:\ "\isasymlbrakk args\ \isasymin \ lists\ (well_formed_gterm'\ arity);\ \ \isanewline
|
|
280 |
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ length\ args\ =\ arity\ f\isasymrbrakk \isanewline
|
|
281 |
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \isasymLongrightarrow \ (Apply\ f\ args)\ \isasymin \ well_formed_gterm'\ arity"\isanewline
|
|
282 |
\isakeyword{monos}\ lists_mono
|
|
283 |
\end{isabelle}
|
|
284 |
|
|
285 |
We must cite the theorem \isa{lists_mono} in order to justify
|
|
286 |
using the function \isa{lists}.
|
|
287 |
\begin{isabelle}
|
|
288 |
A\ \isasymsubseteq\ B\ \isasymLongrightarrow \ lists\ A\ \isasymsubseteq
|
|
289 |
\ lists\ B\rulename{lists_mono}
|
|
290 |
\end{isabelle}
|
|
291 |
%
|
|
292 |
Why must the function be monotonic? An inductive definition describes
|
|
293 |
an iterative construction: each element of the set is constructed by a
|
|
294 |
finite number of introduction rule applications. For example, the
|
|
295 |
elements of \isa{even} are constructed by finitely many applications of
|
|
296 |
the rules
|
|
297 |
\begin{isabelle}
|
|
298 |
0\ \isasymin \ even\isanewline
|
|
299 |
n\ \isasymin \ even\ \isasymLongrightarrow \ (Suc\ (Suc\ n))\ \isasymin
|
|
300 |
\ even
|
|
301 |
\end{isabelle}
|
|
302 |
All references to a set in its
|
|
303 |
inductive definition must be positive. Applications of an
|
|
304 |
introduction rule cannot invalidate previous applications, allowing the
|
|
305 |
construction process to converge.
|
|
306 |
The following pair of rules do not constitute an inductive definition:
|
|
307 |
\begin{isabelle}
|
|
308 |
0\ \isasymin \ even\isanewline
|
|
309 |
n\ \isasymnotin \ even\ \isasymLongrightarrow \ (Suc\ n)\ \isasymin
|
|
310 |
\ even
|
|
311 |
\end{isabelle}
|
|
312 |
%
|
|
313 |
Showing that 4 is even using these rules requires showing that 3 is not
|
|
314 |
even. It is far from trivial to show that this set of rules
|
|
315 |
characterizes the even numbers.
|
|
316 |
|
|
317 |
Even with its use of the function \isa{lists}, the premise of our
|
|
318 |
introduction rule is positive:
|
|
319 |
\begin{isabelle}
|
|
320 |
args\ \isasymin \ lists\ (well_formed_gterm'\ arity)
|
|
321 |
\end{isabelle}
|
|
322 |
To apply the rule we construct a list \isa{args} of previously
|
|
323 |
constructed well-formed terms. We obtain a
|
|
324 |
new term, \isa{Apply\ f\ args}. Because \isa{lists} is monotonic,
|
|
325 |
applications of the rule remain valid as new terms are constructed.
|
|
326 |
Further lists of well-formed
|
|
327 |
terms become available and none are taken away.
|
|
328 |
|
|
329 |
|
|
330 |
\subsection{A Proof of Equivalence}
|
|
331 |
|
|
332 |
We naturally hope that these two inductive definitions of ``well-formed''
|
|
333 |
coincide. The equality can be proved by separate inclusions in
|
|
334 |
each direction. Each is a trivial rule induction.
|
|
335 |
\begin{isabelle}
|
|
336 |
\isacommand{lemma}\ "well_formed_gterm\ arity\ \isasymsubseteq \ well_formed_gterm'\ arity"\isanewline
|
|
337 |
\isacommand{apply}\ clarify\isanewline
|
|
338 |
\isacommand{apply}\ (erule\ well_formed_gterm.induct)\isanewline
|
|
339 |
\isacommand{apply}\ auto\isanewline
|
|
340 |
\isacommand{done}
|
|
341 |
\end{isabelle}
|
|
342 |
|
|
343 |
The \isa{clarify} method gives
|
|
344 |
us an element of \isa{well_formed_gterm\ arity} on which to perform
|
|
345 |
induction. The resulting subgoal can be proved automatically:
|
|
346 |
\begin{isabelle}
|
|
347 |
{\isadigit{1}}{\isachardot}\ {\isasymAnd}x\ args\ f{\isachardot}\isanewline
|
|
348 |
\ \ \ \ \ \ {\isasymlbrakk}{\isasymforall}t{\isasymin}set\ args{\isachardot}\isanewline
|
|
349 |
\ \ \ \ \ \ \ \ \ \ t\ {\isasymin}\ well{\isacharunderscore}formed{\isacharunderscore}gterm\ arity\ {\isasymand}\ t\ {\isasymin}\ well{\isacharunderscore}formed{\isacharunderscore}gterm{\isacharprime}\ arity{\isacharsemicolon}\isanewline
|
|
350 |
\ \ \ \ \ \ \ length\ args\ {\isacharequal}\ arity\ f{\isasymrbrakk}\isanewline
|
|
351 |
\ \ \ \ \ \ {\isasymLongrightarrow}\ Apply\ f\ args\ {\isasymin}\ well{\isacharunderscore}formed{\isacharunderscore}gterm{\isacharprime}\ arity%
|
|
352 |
\end{isabelle}
|
|
353 |
%
|
|
354 |
This proof resembles the one given in
|
|
355 |
{\S}\ref{sec:gterm-datatype} above, especially in the form of the
|
|
356 |
induction hypothesis. Next, we consider the opposite inclusion:
|
|
357 |
\begin{isabelle}
|
|
358 |
\isacommand{lemma}\ "well_formed_gterm'\ arity\ \isasymsubseteq \ well_formed_gterm\ arity"\isanewline
|
|
359 |
\isacommand{apply}\ clarify\isanewline
|
|
360 |
\isacommand{apply}\ (erule\ well_formed_gterm'.induct)\isanewline
|
|
361 |
\isacommand{apply}\ auto\isanewline
|
|
362 |
\isacommand{done}
|
|
363 |
\end{isabelle}
|
|
364 |
%
|
|
365 |
The proof script is identical, but the subgoal after applying induction may
|
|
366 |
be surprising:
|
|
367 |
\begin{isabelle}
|
|
368 |
1.\ \isasymAnd x\ args\ f.\isanewline
|
|
369 |
\ \ \ \ \ \ \isasymlbrakk args\ \isasymin \ lists\ (well_formed_gterm'\ arity\ \isasyminter\isanewline
|
|
370 |
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \isacharbraceleft u.\ u\ \isasymin \ well_formed_gterm\ arity\isacharbraceright );\isanewline
|
|
371 |
\ \ \ \ \ \ \ length\ args\ =\ arity\ f\isasymrbrakk \isanewline
|
|
372 |
\ \ \ \ \ \ \isasymLongrightarrow \ Apply\ f\ args\ \isasymin \ well_formed_gterm\ arity%
|
|
373 |
\end{isabelle}
|
|
374 |
The induction hypothesis contains an application of \isa{lists}. Using a
|
|
375 |
monotonic function in the inductive definition always has this effect. The
|
|
376 |
subgoal may look uninviting, but fortunately a useful rewrite rule concerning
|
|
377 |
\isa{lists} is available:
|
|
378 |
\begin{isabelle}
|
|
379 |
lists\ (A\ \isasyminter \ B)\ =\ lists\ A\ \isasyminter \ lists\ B
|
|
380 |
\rulename{lists_Int_eq}
|
|
381 |
\end{isabelle}
|
|
382 |
%
|
|
383 |
Thanks to this default simplification rule, the induction hypothesis
|
|
384 |
is quickly replaced by its two parts:
|
|
385 |
\begin{isabelle}
|
|
386 |
\ \ \ \ \ \ \ args\ \isasymin \ lists\ (well_formed_gterm'\ arity)\isanewline
|
|
387 |
\ \ \ \ \ \ \ args\ \isasymin \ lists\ (well_formed_gterm\ arity)
|
|
388 |
\end{isabelle}
|
|
389 |
Invoking the rule \isa{well_formed_gterm.step} completes the proof. The
|
|
390 |
call to
|
|
391 |
\isa{auto} does all this work.
|
|
392 |
|
|
393 |
This example is typical of how monotonic functions can be used. In
|
|
394 |
particular, a rewrite rule analogous to \isa{lists_Int_eq} holds in most
|
|
395 |
cases. Monotonicity implies one direction of this set equality; we have
|
|
396 |
this theorem:
|
|
397 |
\begin{isabelle}
|
|
398 |
mono\ f\ \isasymLongrightarrow \ f\ (A\ \isasyminter \ B)\ \isasymsubseteq \
|
|
399 |
f\ A\ \isasyminter \ f\ B%
|
|
400 |
\rulename{mono_Int}
|
|
401 |
\end{isabelle}
|
|
402 |
|
|
403 |
|
|
404 |
To summarize: a universal quantifier in an introduction rule
|
|
405 |
lets it refer to any number of instances of
|
|
406 |
the inductively defined set. A monotonic function in an introduction
|
|
407 |
rule lets it refer to constructions over the inductively defined
|
|
408 |
set. Each element of an inductively defined set is created
|
|
409 |
through finitely many applications of the introduction rules. So each rule
|
|
410 |
must be positive, and never can it refer to \textit{infinitely} many
|
|
411 |
previous instances of the inductively defined set.
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
\begin{exercise}
|
|
416 |
Prove this theorem, one direction of which was proved in
|
|
417 |
{\S}\ref{sec:rule-inversion} above.
|
|
418 |
\begin{isabelle}
|
|
419 |
\isacommand{lemma}\ gterms_Int_eq\ [simp]:\ "gterms\ (F\isasyminter G)\ =\
|
|
420 |
gterms\ F\ \isasyminter \ gterms\ G"\isanewline
|
|
421 |
\end{isabelle}
|
|
422 |
\end{exercise}
|
|
423 |
|
|
424 |
|
|
425 |
\begin{exercise}
|
|
426 |
A function mapping function symbols to their
|
|
427 |
types is called a \textbf{signature}. Given a type
|
|
428 |
ranging over type symbols, we can represent a function's type by a
|
|
429 |
list of argument types paired with the result type.
|
|
430 |
Complete this inductive definition:
|
|
431 |
\begin{isabelle}
|
|
432 |
\isacommand{consts}\ well_typed_gterm::\ "('f\ \isasymRightarrow \ 't\ list\ *\ 't)\ \isasymRightarrow \ ('f\ gterm\ *\ 't)set"\isanewline
|
|
433 |
\isacommand{inductive}\ "well_typed_gterm\ sig"\isanewline
|
|
434 |
\end{isabelle}
|
|
435 |
\end{exercise}
|