comparison src/MoreDep.v @ 213:c4b1c0de7af9

Start of MoreDep port; new [dep_destruct] based on [dependent destruction]
author Adam Chlipala <adamc@hcoop.net>
date Wed, 11 Nov 2009 10:27:47 -0500
parents cbf2f74a5130
children 768889c969e9
comparison
equal deleted inserted replaced
212:3227be370687 213:c4b1c0de7af9
1 (* Copyright (c) 2008, Adam Chlipala 1 (* Copyright (c) 2008-2009, Adam Chlipala
2 * 2 *
3 * This work is licensed under a 3 * This work is licensed under a
4 * Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 4 * Creative Commons Attribution-Noncommercial-No Derivative Works 3.0
5 * Unported License. 5 * Unported License.
6 * The license text is available at: 6 * The license text is available at:
36 36
37 (** We see that, within its section, [ilist] is given type [nat -> Set]. Previously, every inductive type we have seen has either had plain [Set] as its type or has been a predicate with some type ending in [Prop]. The full generality of inductive definitions lets us integrate the expressivity of predicates directly into our normal programming. 37 (** We see that, within its section, [ilist] is given type [nat -> Set]. Previously, every inductive type we have seen has either had plain [Set] as its type or has been a predicate with some type ending in [Prop]. The full generality of inductive definitions lets us integrate the expressivity of predicates directly into our normal programming.
38 38
39 The [nat] argument to [ilist] tells us the length of the list. The types of [ilist]'s constructors tell us that a [Nil] list has length [O] and that a [Cons] list has length one greater than the length of its sublist. We may apply [ilist] to any natural number, even natural numbers that are only known at runtime. It is this breaking of the %\textit{%#<i>#phase distinction#</i>#%}% that characterizes [ilist] as %\textit{%#<i>#dependently typed#</i>#%}%. 39 The [nat] argument to [ilist] tells us the length of the list. The types of [ilist]'s constructors tell us that a [Nil] list has length [O] and that a [Cons] list has length one greater than the length of its sublist. We may apply [ilist] to any natural number, even natural numbers that are only known at runtime. It is this breaking of the %\textit{%#<i>#phase distinction#</i>#%}% that characterizes [ilist] as %\textit{%#<i>#dependently typed#</i>#%}%.
40 40
41 In expositions of list types, we usually see the length function defined first, but here that would not be a very productive function to code. Instead, let us implement list concatenation. 41 In expositions of list types, we usually see the length function defined first, but here that would not be a very productive function to code. Instead, let us implement list concatenation. *)
42 42
43 [[ 43 Fixpoint app n1 (ls1 : ilist n1) n2 (ls2 : ilist n2) : ilist (n1 + n2) :=
44 Fixpoint app n1 (ls1 : ilist n1) n2 (ls2 : ilist n2) {struct ls1} : ilist (n1 + n2) := 44 match ls1 with
45 match ls1 with 45 | Nil => ls2
46 | Nil => ls2 46 | Cons _ x ls1' => Cons x (app ls1' ls2)
47 | Cons _ x ls1' => Cons x (app ls1' ls2) 47 end.
48 end. 48
49 49 (** In Coq version 8.1 and earlier, this definition leads to an error message:
50 Coq is not happy with this definition:
51 50
52 [[ 51 [[
53 The term "ls2" has type "ilist n2" while it is expected to have type 52 The term "ls2" has type "ilist n2" while it is expected to have type
54 "ilist (?14 + n2)" 53 "ilist (?14 + n2)"
54
55 ]] 55 ]]
56 56
57 We see the return of a problem we have considered before. Without explicit annotations, Coq does not enrich our typing assumptions in the branches of a [match] expression. It is clear that the unification variable [?14] should be resolved to 0 in this context, so that we have [0 + n2] reducing to [n2], but Coq does not realize that. We cannot fix the problem using just the simple [return] clauses we applied in the last chapter. We need to combine a [return] clause with a new kind of annotation, an [in] clause. *) 57 In Coq's core language, without explicit annotations, Coq does not enrich our typing assumptions in the branches of a [match] expression. It is clear that the unification variable [?14] should be resolved to 0 in this context, so that we have [0 + n2] reducing to [n2], but Coq does not realize that. We cannot fix the problem using just the simple [return] clauses we applied in the last chapter. We need to combine a [return] clause with a new kind of annotation, an [in] clause. This is exactly what the inference heuristics do in Coq 8.2 and later.
58
59 Specifically, Coq infers the following definition from the simpler one. *)
58 60
59 (* EX: Implement concatenation *) 61 (* EX: Implement concatenation *)
60 62
61 (* begin thide *) 63 (* begin thide *)
62 Fixpoint app n1 (ls1 : ilist n1) n2 (ls2 : ilist n2) {struct ls1} : ilist (n1 + n2) := 64 Fixpoint app' n1 (ls1 : ilist n1) n2 (ls2 : ilist n2) : ilist (n1 + n2) :=
63 match ls1 in (ilist n1) return (ilist (n1 + n2)) with 65 match ls1 in (ilist n1) return (ilist (n1 + n2)) with
64 | Nil => ls2 66 | Nil => ls2
65 | Cons _ x ls1' => Cons x (app ls1' ls2) 67 | Cons _ x ls1' => Cons x (app' ls1' ls2)
66 end. 68 end.
67 (* end thide *) 69 (* end thide *)
68 70
69 (** This version of [app] passes the type checker. Using [return] alone allowed us to express a dependency of the [match] result type on the %\textit{%#<i>#value#</i>#%}% of the discriminee. What [in] adds to our arsenal is a way of expressing a dependency on the %\textit{%#<i>#type#</i>#%}% of the discriminee. Specifically, the [n1] in the [in] clause above is a %\textit{%#<i>#binding occurrence#</i>#%}% whose scope is the [return] clause. 71 (** Using [return] alone allowed us to express a dependency of the [match] result type on the %\textit{%#<i>#value#</i>#%}% of the discriminee. What [in] adds to our arsenal is a way of expressing a dependency on the %\textit{%#<i>#type#</i>#%}% of the discriminee. Specifically, the [n1] in the [in] clause above is a %\textit{%#<i>#binding occurrence#</i>#%}% whose scope is the [return] clause.
70 72
71 We may use [in] clauses only to bind names for the arguments of an inductive type family. That is, each [in] clause must be an inductive type family name applied to a sequence of underscores and variable names of the proper length. The positions for %\textit{%#<i>#parameters#</i>#%}% to the type family must all be underscores. Parameters are those arguments declared with section variables or with entries to the left of the first colon in an inductive definition. They cannot vary depending on which constructor was used to build the discriminee, so Coq prohibits pointless matches on them. It is those arguments defined in the type to the right of the colon that we may name with [in] clauses. 73 We may use [in] clauses only to bind names for the arguments of an inductive type family. That is, each [in] clause must be an inductive type family name applied to a sequence of underscores and variable names of the proper length. The positions for %\textit{%#<i>#parameters#</i>#%}% to the type family must all be underscores. Parameters are those arguments declared with section variables or with entries to the left of the first colon in an inductive definition. They cannot vary depending on which constructor was used to build the discriminee, so Coq prohibits pointless matches on them. It is those arguments defined in the type to the right of the colon that we may name with [in] clauses.
72 74
73 Our [app] function could be typed in so-called %\textit{%#<i>#stratified#</i>#%}% type systems, which avoid true dependency. We could consider the length indices to lists to live in a separate, compile-time-only universe from the lists themselves. Our next example would be harder to implement in a stratified system. We write an injection function from regular lists to length-indexed lists. A stratified implementation would need to duplicate the definition of lists across compile-time and run-time versions, and the run-time versions would need to be indexed by the compile-time versions. *) 75 Our [app] function could be typed in so-called %\textit{%#<i>#stratified#</i>#%}% type systems, which avoid true dependency. We could consider the length indices to lists to live in a separate, compile-time-only universe from the lists themselves. Our next example would be harder to implement in a stratified system. We write an injection function from regular lists to length-indexed lists. A stratified implementation would need to duplicate the definition of lists across compile-time and run-time versions, and the run-time versions would need to be indexed by the compile-time versions. *)
74 76
75 (* EX: Implement injection from normal lists *) 77 (* EX: Implement injection from normal lists *)
76 78
77 (* begin thide *) 79 (* begin thide *)
78 Fixpoint inject (ls : list A) : ilist (length ls) := 80 Fixpoint inject (ls : list A) : ilist (length ls) :=
79 match ls return (ilist (length ls)) with 81 match ls with
80 | nil => Nil 82 | nil => Nil
81 | h :: t => Cons h (inject t) 83 | h :: t => Cons h (inject t)
82 end. 84 end.
83 85
84 (** We can define an inverse conversion and prove that it really is an inverse. *) 86 (** We can define an inverse conversion and prove that it really is an inverse. *)
85 87
86 Fixpoint unject n (ls : ilist n) {struct ls} : list A := 88 Fixpoint unject n (ls : ilist n) : list A :=
87 match ls with 89 match ls with
88 | Nil => nil 90 | Nil => nil
89 | Cons _ h t => h :: unject t 91 | Cons _ h t => h :: unject t
90 end. 92 end.
91 93
102 Definition hd n (ls : ilist (S n)) : A := 104 Definition hd n (ls : ilist (S n)) : A :=
103 match ls with 105 match ls with
104 | Nil => ??? 106 | Nil => ???
105 | Cons _ h _ => h 107 | Cons _ h _ => h
106 end. 108 end.
109
110 ]]
107 111
108 It is not clear what to write for the [Nil] case, so we are stuck before we even turn our function over to the type checker. We could try omitting the [Nil] case: 112 It is not clear what to write for the [Nil] case, so we are stuck before we even turn our function over to the type checker. We could try omitting the [Nil] case:
109 113
110 [[ 114 [[
111 Definition hd n (ls : ilist (S n)) : A := 115 Definition hd n (ls : ilist (S n)) : A :=
112 match ls with 116 match ls with
113 | Cons _ h _ => h 117 | Cons _ h _ => h
114 end. 118 end.
115 119
116 [[
117 Error: Non exhaustive pattern-matching: no clause found for pattern Nil 120 Error: Non exhaustive pattern-matching: no clause found for pattern Nil
121
118 ]] 122 ]]
119 123
120 Unlike in ML, we cannot use inexhaustive pattern matching, becuase there is no conception of a %\texttt{%#<tt>#Match#</tt>#%}% exception to be thrown. We might try using an [in] clause somehow. 124 Unlike in ML, we cannot use inexhaustive pattern matching, becuase there is no conception of a %\texttt{%#<tt>#Match#</tt>#%}% exception to be thrown. We might try using an [in] clause somehow.
121 125
122 [[ 126 [[
123 Definition hd n (ls : ilist (S n)) : A := 127 Definition hd n (ls : ilist (S n)) : A :=
124 match ls in (ilist (S n)) with 128 match ls in (ilist (S n)) with
125 | Cons _ h _ => h 129 | Cons _ h _ => h
126 end. 130 end.
127 131
128 [[
129 Error: The reference n was not found in the current environment 132 Error: The reference n was not found in the current environment
133
130 ]] 134 ]]
131 135
132 In this and other cases, we feel like we want [in] clauses with type family arguments that are not variables. Unfortunately, Coq only supports variables in those positions. A completely general mechanism could only be supported with a solution to the problem of higher-order unification, which is undecidable. There %\textit{%#<i>#are#</i>#%}% useful heuristics for handling non-variable indices which are gradually making their way into Coq, but we will spend some time in this and the next few chapters on effective pattern matching on dependent types using only the primitive [match] annotations. 136 In this and other cases, we feel like we want [in] clauses with type family arguments that are not variables. Unfortunately, Coq only supports variables in those positions. A completely general mechanism could only be supported with a solution to the problem of higher-order unification, which is undecidable. There %\textit{%#<i>#are#</i>#%}% useful heuristics for handling non-variable indices which are gradually making their way into Coq, but we will spend some time in this and the next few chapters on effective pattern matching on dependent types using only the primitive [match] annotations.
133 137
134 Our final, working attempt at [hd] uses an auxiliary function and a surprising [return] annotation. *) 138 Our final, working attempt at [hd] uses an auxiliary function and a surprising [return] annotation. *)
183 187
184 (** [typeDenote] compiles types of our object language into "native" Coq types. It is deceptively easy to implement. The only new thing we see is the [%type] annotation, which tells Coq to parse the [match] expression using the notations associated with types. Without this annotation, the [*] would be interpreted as multiplication on naturals, rather than as the product type constructor. [type] is one example of an identifer bound to a %\textit{%#<i>#notation scope#</i>#%}%. We will deal more explicitly with notations and notation scopes in later chapters. 188 (** [typeDenote] compiles types of our object language into "native" Coq types. It is deceptively easy to implement. The only new thing we see is the [%type] annotation, which tells Coq to parse the [match] expression using the notations associated with types. Without this annotation, the [*] would be interpreted as multiplication on naturals, rather than as the product type constructor. [type] is one example of an identifer bound to a %\textit{%#<i>#notation scope#</i>#%}%. We will deal more explicitly with notations and notation scopes in later chapters.
185 189
186 We can define a function [expDenote] that is typed in terms of [typeDenote]. *) 190 We can define a function [expDenote] that is typed in terms of [typeDenote]. *)
187 191
188 Fixpoint expDenote t (e : exp t) {struct e} : typeDenote t := 192 Fixpoint expDenote t (e : exp t) : typeDenote t :=
189 match e in (exp t) return (typeDenote t) with 193 match e with
190 | NConst n => n 194 | NConst n => n
191 | Plus e1 e2 => expDenote e1 + expDenote e2 195 | Plus e1 e2 => expDenote e1 + expDenote e2
192 | Eq e1 e2 => if eq_nat_dec (expDenote e1) (expDenote e2) then true else false 196 | Eq e1 e2 => if eq_nat_dec (expDenote e1) (expDenote e2) then true else false
193 197
194 | BConst b => b 198 | BConst b => b
198 | Pair _ _ e1 e2 => (expDenote e1, expDenote e2) 202 | Pair _ _ e1 e2 => (expDenote e1, expDenote e2)
199 | Fst _ _ e' => fst (expDenote e') 203 | Fst _ _ e' => fst (expDenote e')
200 | Snd _ _ e' => snd (expDenote e') 204 | Snd _ _ e' => snd (expDenote e')
201 end. 205 end.
202 206
203 (** Again we find that an [in] annotation is essential for type-checking a function. Besides that, the definition is routine. In fact, it is less complicated than what we would write in ML or Haskell 98, since we do not need to worry about pushing final values in and out of an algebraic datatype. The only unusual thing is the use of an expression of the form [if E then true else false] in the [Eq] case. Remember that [eq_nat_dec] has a rich dependent type, rather than a simple boolean type. Coq's native [if] is overloaded to work on a test of any two-constructor type, so we can use [if] to build a simple boolean from the [sumbool] that [eq_nat_dec] returns. 207 (** Despite the fancy type, the function definition is routine. In fact, it is less complicated than what we would write in ML or Haskell 98, since we do not need to worry about pushing final values in and out of an algebraic datatype. The only unusual thing is the use of an expression of the form [if E then true else false] in the [Eq] case. Remember that [eq_nat_dec] has a rich dependent type, rather than a simple boolean type. Coq's native [if] is overloaded to work on a test of any two-constructor type, so we can use [if] to build a simple boolean from the [sumbool] that [eq_nat_dec] returns.
204 208
205 We can implement our old favorite, a constant folding function, and prove it correct. It will be useful to write a function [pairOut] that checks if an [exp] of [Prod] type is a pair, returning its two components if so. Unsurprisingly, a first attempt leads to a type error. 209 We can implement our old favorite, a constant folding function, and prove it correct. It will be useful to write a function [pairOut] that checks if an [exp] of [Prod] type is a pair, returning its two components if so. Unsurprisingly, a first attempt leads to a type error.
206 210
207 [[ 211 [[
208 Definition pairOut t1 t2 (e : exp (Prod t1 t2)) : option (exp t1 * exp t2) := 212 Definition pairOut t1 t2 (e : exp (Prod t1 t2)) : option (exp t1 * exp t2) :=
209 match e in (exp (Prod t1 t2)) return option (exp t1 * exp t2) with 213 match e in (exp (Prod t1 t2)) return option (exp t1 * exp t2) with
210 | Pair _ _ e1 e2 => Some (e1, e2) 214 | Pair _ _ e1 e2 => Some (e1, e2)
211 | _ => None 215 | _ => None
212 end. 216 end.
213 217
214 [[
215 Error: The reference t2 was not found in the current environment 218 Error: The reference t2 was not found in the current environment
216 ]] 219 ]]
217 220
218 We run again into the problem of not being able to specify non-variable arguments in [in] clauses. The problem would just be hopeless without a use of an [in] clause, though, since the result type of the [match] depends on an argument to [exp]. Our solution will be to use a more general type, as we did for [hd]. First, we define a type-valued function to use in assigning a type to [pairOut]. *) 221 We run again into the problem of not being able to specify non-variable arguments in [in] clauses. The problem would just be hopeless without a use of an [in] clause, though, since the result type of the [match] depends on an argument to [exp]. Our solution will be to use a more general type, as we did for [hd]. First, we define a type-valued function to use in assigning a type to [pairOut]. *)
219 222
220 (* EX: Define a function [pairOut : forall t1 t2, exp (Prod t1 t2) -> option (exp t1 * exp t2)] *) 223 (* EX: Define a function [pairOut : forall t1 t2, exp (Prod t1 t2) -> option (exp t1 * exp t2)] *)
221 224
243 end. 246 end.
244 (* end thide *) 247 (* end thide *)
245 248
246 (** There is one important subtlety in this definition. Coq allows us to use convenient ML-style pattern matching notation, but, internally and in proofs, we see that patterns are expanded out completely, matching one level of inductive structure at a time. Thus, the default case in the [match] above expands out to one case for each constructor of [exp] besides [Pair], and the underscore in [pairOutDefault _] is resolved differently in each case. From an ML or Haskell programmer's perspective, what we have here is type inference determining which code is run (returning either [None] or [tt]), which goes beyond what is possible with type inference guiding parametric polymorphism in Hindley-Milner languages, but is similar to what goes on with Haskell type classes. 249 (** There is one important subtlety in this definition. Coq allows us to use convenient ML-style pattern matching notation, but, internally and in proofs, we see that patterns are expanded out completely, matching one level of inductive structure at a time. Thus, the default case in the [match] above expands out to one case for each constructor of [exp] besides [Pair], and the underscore in [pairOutDefault _] is resolved differently in each case. From an ML or Haskell programmer's perspective, what we have here is type inference determining which code is run (returning either [None] or [tt]), which goes beyond what is possible with type inference guiding parametric polymorphism in Hindley-Milner languages, but is similar to what goes on with Haskell type classes.
247 250
248 With [pairOut] available, we can write [cfold] in a straightforward way. There are really no surprises beyond that Coq verifies that this code has such an expressive type, given the small annotation burden. *) 251 With [pairOut] available, we can write [cfold] in a straightforward way. There are really no surprises beyond that Coq verifies that this code has such an expressive type, given the small annotation burden. In some places, we see that Coq's [match] annotation inference is too smart for its own good, and we have to turn that inference off by writing [return _]. *)
249 252
250 Fixpoint cfold t (e : exp t) : exp t := 253 Fixpoint cfold t (e : exp t) : exp t :=
251 match e with 254 match e with
252 | NConst n => NConst n 255 | NConst n => NConst n
253 | Plus e1 e2 => 256 | Plus e1 e2 =>
303 induction e; crush. 306 induction e; crush.
304 307
305 (** The first remaining subgoal is: 308 (** The first remaining subgoal is:
306 309
307 [[ 310 [[
308
309 expDenote (cfold e1) + expDenote (cfold e2) = 311 expDenote (cfold e1) + expDenote (cfold e2) =
310 expDenote 312 expDenote
311 match cfold e1 with 313 match cfold e1 with
312 | NConst n1 => 314 | NConst n1 =>
313 match cfold e2 with 315 match cfold e2 with
328 | If _ _ _ _ => Plus (cfold e1) (cfold e2) 330 | If _ _ _ _ => Plus (cfold e1) (cfold e2)
329 | Pair _ _ _ _ => Plus (cfold e1) (cfold e2) 331 | Pair _ _ _ _ => Plus (cfold e1) (cfold e2)
330 | Fst _ _ _ => Plus (cfold e1) (cfold e2) 332 | Fst _ _ _ => Plus (cfold e1) (cfold e2)
331 | Snd _ _ _ => Plus (cfold e1) (cfold e2) 333 | Snd _ _ _ => Plus (cfold e1) (cfold e2)
332 end 334 end
335
333 ]] 336 ]]
334 337
335 We would like to do a case analysis on [cfold e1], and we attempt that in the way that has worked so far. 338 We would like to do a case analysis on [cfold e1], and we attempt that in the way that has worked so far.
336 339
337 [[ 340 [[
338 destruct (cfold e1). 341 destruct (cfold e1).
339 342
340 [[
341 User error: e1 is used in hypothesis e 343 User error: e1 is used in hypothesis e
344
342 ]] 345 ]]
343 346
344 Coq gives us another cryptic error message. Like so many others, this one basically means that Coq is not able to build some proof about dependent types. It is hard to generate helpful and specific error messages for problems like this, since that would require some kind of understanding of the dependency structure of a piece of code. We will encounter many examples of case-specific tricks for recovering from errors like this one. 347 Coq gives us another cryptic error message. Like so many others, this one basically means that Coq is not able to build some proof about dependent types. It is hard to generate helpful and specific error messages for problems like this, since that would require some kind of understanding of the dependency structure of a piece of code. We will encounter many examples of case-specific tricks for recovering from errors like this one.
345 348
346 For our current proof, we can use a tactic [dep_destruct] defined in the book [Tactics] module. General elimination/inversion of dependently-typed hypotheses is undecidable, since it must be implemented with [match] expressions that have the restriction on [in] clauses that we have already discussed. [dep_destruct] makes a best effort to handle some common cases. In a future chapter, we will learn about the explicit manipulation of equality proofs that is behind [dep_destruct]'s implementation in Ltac, but for now, we treat it as a useful black box. *) 349 For our current proof, we can use a tactic [dep_destruct] defined in the book [Tactics] module. General elimination/inversion of dependently-typed hypotheses is undecidable, since it must be implemented with [match] expressions that have the restriction on [in] clauses that we have already discussed. [dep_destruct] makes a best effort to handle some common cases, relying upon the more primitive [dependent destruction] tactic that comes with Coq. In a future chapter, we will learn about the explicit manipulation of equality proofs that is behind [dep_destruct]'s implementation in Ltac, but for now, we treat it as a useful black box. *)
347 350
348 dep_destruct (cfold e1). 351 dep_destruct (cfold e1).
349 352
350 (** This successfully breaks the subgoal into 5 new subgoals, one for each constructor of [exp] that could produce an [exp Nat]. Note that [dep_destruct] is successful in ruling out the other cases automatically, in effect automating some of the work that we have done manually in implementing functions like [hd] and [pairOut]. 353 (** This successfully breaks the subgoal into 5 new subgoals, one for each constructor of [exp] that could produce an [exp Nat]. Note that [dep_destruct] is successful in ruling out the other cases automatically, in effect automating some of the work that we have done manually in implementing functions like [hd] and [pairOut].
351 354
352 This is the only new trick we need to learn to complete the proof. We can back up and give a short, automated proof. *) 355 This is the only new trick we need to learn to complete the proof. We can back up and give a short, automated proof. The main inconvenience in the proof is that we cannot write a pattern that matches a [match] without including a case for every constructor of the inductive type we match over. *)
353 356
354 Restart. 357 Restart.
355 358
356 induction e; crush; 359 induction e; crush;
357 repeat (match goal with 360 repeat (match goal with
358 | [ |- context[cfold ?E] ] => dep_destruct (cfold E) 361 | [ |- context[match cfold ?E with NConst _ => _ | Plus _ _ => _
362 | Eq _ _ => _ | BConst _ => _ | And _ _ => _
363 | If _ _ _ _ => _ | Pair _ _ _ _ => _
364 | Fst _ _ _ => _ | Snd _ _ _ => _ end] ] =>
365 dep_destruct (cfold E)
366 | [ |- context[match pairOut (cfold ?E) with Some _ => _
367 | None => _ end] ] =>
368 dep_destruct (cfold E)
359 | [ |- (if ?E then _ else _) = _ ] => destruct E 369 | [ |- (if ?E then _ else _) = _ ] => destruct E
360 end; crush). 370 end; crush).
361 Qed. 371 Qed.
362 (* end thide *) 372 (* end thide *)
363 373
541 present z (projT2 (balance1 a y b)) 551 present z (projT2 (balance1 a y b))
542 <-> rpresent z a \/ z = y \/ present z b. 552 <-> rpresent z a \/ z = y \/ present z b.
543 destruct a; present_balance. 553 destruct a; present_balance.
544 Qed. 554 Qed.
545 555
546 Lemma present_balance2 : forall n (a : rtree n) (y : nat) c2 (b : rbtree c2 n) , 556 Lemma present_balance2 : forall n (a : rtree n) (y : nat) c2 (b : rbtree c2 n),
547 present z (projT2 (balance2 a y b)) 557 present z (projT2 (balance2 a y b))
548 <-> rpresent z a \/ z = y \/ present z b. 558 <-> rpresent z a \/ z = y \/ present z b.
549 destruct a; present_balance. 559 destruct a; present_balance.
550 Qed. 560 Qed.
551 561
587 end 597 end
588 end; 598 end;
589 tauto. 599 tauto.
590 Qed. 600 Qed.
591 601
592 Ltac present_insert t := 602 Ltac present_insert :=
593 unfold insert; inversion t; 603 unfold insert; intros n t; inversion t;
594 generalize (present_ins t); simpl; 604 generalize (present_ins t); simpl;
595 dep_destruct (ins t); tauto. 605 dep_destruct (ins t); tauto.
596 606
597 Theorem present_insert_Red : forall n (t : rbtree Red n), 607 Theorem present_insert_Red : forall n (t : rbtree Red n),
598 present z (insert t) 608 present z (insert t)
599 <-> (z = x \/ present z t). 609 <-> (z = x \/ present z t).
600 intros; present_insert t. 610 present_insert.
601 Qed. 611 Qed.
602 612
603 Theorem present_insert_Black : forall n (t : rbtree Black n), 613 Theorem present_insert_Black : forall n (t : rbtree Black n),
604 present z (projT2 (insert t)) 614 present z (projT2 (insert t))
605 <-> (z = x \/ present z t). 615 <-> (z = x \/ present z t).
606 intros; present_insert t. 616 present_insert.
607 Qed. 617 Qed.
608 End present. 618 End present.
609 End insert. 619 End insert.
610 620
611 621