source: src/common/Identifiers.ma @ 2335

Last change on this file since 2335 was 2335, checked in by campbell, 7 years ago

Deal with goto labels in RTLabs to Cminor by fixing up goto statements
after the main translation to avoid generating extra skips in awkward
locations.

File size: 34.4 KB
Line 
1include "basics/types.ma".
2include "ASM/String.ma".
3include "utilities/binary/positive.ma".
4include "utilities/lists.ma".
5include "utilities/extralib.ma".
6include "common/Errors.ma".
7
8(* identifiers and their generators are tagged to differentiate them, and to
9   provide extra type checking. *)
10
11(* in common/PreIdentifiers.ma, via Errors.ma.
12inductive identifier (tag:String) : Type[0] ≝
13  an_identifier : Pos → identifier tag.
14*)
15
16record universe (tag:String) : Type[0] ≝
17{
18  next_identifier : Pos
19}.
20
21definition new_universe : ∀tag:String. universe tag ≝
22  λtag. mk_universe tag one.
23
24let rec fresh (tag:String) (u:universe tag) on u : identifier tag × (universe tag) ≝
25  let id ≝ next_identifier ? u in
26  〈an_identifier tag id, mk_universe tag (succ id)〉.
27
28
29let rec fresh_for_univ tag (id:identifier tag) (u:universe tag) on id : Prop ≝
30  match id with [ an_identifier p ⇒ p < next_identifier … u ].
31
32
33lemma fresh_is_fresh : ∀tag,id,u,u'.
34  〈id,u〉 = fresh tag u' →
35  fresh_for_univ tag id u.
36#tag * #id * #u * #u' #E whd in E:(???%); destruct //
37qed.
38
39lemma fresh_remains_fresh : ∀tag,id,id',u,u'.
40  fresh_for_univ tag id u →
41  〈id',u'〉 = fresh tag u →
42  fresh_for_univ tag id u'.
43#tag * #id * #id' * #u * #u' normalize #H #E destruct /2 by le_S/
44qed.
45
46lemma fresh_distinct : ∀tag,id,id',u,u'.
47  fresh_for_univ tag id u →
48  〈id',u'〉 = fresh tag u →
49  id ≠ id'.
50#tag * #id * #id' * #u * #u' normalize #H #E destruct % #E' destruct /2 by absurd/
51qed.
52
53
54let rec env_fresh_for_univ tag A (env:list (identifier tag × A)) (u:universe tag) on u : Prop ≝
55  All ? (λida. fresh_for_univ tag (\fst ida) u) env.
56
57lemma fresh_env_extend : ∀tag,A,env,u,u',id,a.
58  env_fresh_for_univ tag A env u →
59  〈id,u'〉 = fresh tag u →
60  env_fresh_for_univ tag A (〈id,a〉::env) u'.
61#tag #A #env * #u * #u' #id #a
62#H #E whd % [ @(fresh_is_fresh … E) | @(All_mp … H) * #id #a #H' /2 by fresh_remains_fresh/ ]
63qed.
64
65definition eq_identifier : ∀t. identifier t → identifier t → bool ≝
66  λt,l,r.
67  match l with
68  [ an_identifier l' ⇒
69    match r with
70    [ an_identifier r' ⇒
71      eqb l' r'
72    ]
73  ].
74
75lemma eq_identifier_elim : ∀P:bool → Type[0]. ∀t,x,y.
76  (x = y → P true) → (x ≠ y → P false) →
77  P (eq_identifier t x y).
78#P #t * #x * #y #T #F
79change with (P (eqb ??))
80@(eqb_elim x y P) [ /2 by / | * #H @F % #E destruct /2 by / ]
81qed.
82
83lemma eq_identifier_eq:
84  ∀tag: String.
85  ∀l.
86  ∀r.
87    eq_identifier tag l r = true → l = r.
88  #tag #l #r cases l cases r
89  #pos_l #pos_r
90  cases pos_l cases pos_r
91  [1:
92    #_ %
93  |2,3,4,7:
94    #p1_l normalize in ⊢ (% → ?);
95    #absurd destruct(absurd)
96  |5,9:
97    #p1_l #p1_r normalize in ⊢ (% → ?);
98    #relevant lapply (eqb_true_to_eq … relevant) #EQ >EQ %
99  |*:
100    #p_l #p_r normalize in ⊢ (% → ?);
101    #absurd destruct(absurd)
102  ]
103qed.
104
105axiom neq_identifier_neq:
106  ∀tag: String.
107  ∀l, r: identifier tag.
108    eq_identifier tag l r = false → (l = r → False).
109
110include "basics/deqsets.ma".
111definition Deq_identifier : String → DeqSet ≝ λtag.
112  mk_DeqSet (identifier tag) (eq_identifier tag) ?.
113#x#y @eq_identifier_elim /2 by conj/ * #H % [#ABS destruct(ABS) | #G elim (H G)]
114qed.
115
116unification hint 0 ≔ tag; D ≟ Deq_identifier tag
117(*-----------------------------------------------------*)⊢
118identifier tag ≡ carr D.
119
120definition word_of_identifier ≝
121  λt.
122  λl: identifier t.
123  match l with   
124  [ an_identifier l' ⇒ l'
125  ].
126
127lemma eq_identifier_refl : ∀tag,id. eq_identifier tag id id = true.
128#tag * #id whd in ⊢ (??%?); >eqb_n_n @refl
129qed.
130
131axiom eq_identifier_sym:
132  ∀tag: String.
133  ∀l  : identifier tag.
134  ∀r  : identifier tag.
135    eq_identifier tag l r = eq_identifier tag r l.
136
137lemma eq_identifier_false : ∀tag,x,y. x≠y → eq_identifier tag x y = false.
138#tag * #x * #y #NE normalize @not_eq_to_eqb_false /2 by not_to_not/
139qed.
140
141definition identifier_eq : ∀tag:String. ∀x,y:identifier tag. (x=y) + (x≠y).
142#tag * #x * #y lapply (refl ? (eqb x y)) cases (eqb x y) in ⊢ (???% → %);
143#E [ % | %2 ]
144lapply E @eqb_elim
145[ #H #_ >H @refl | 2,3: #_ #H destruct | #H #_ % #H' destruct /2 by absurd/ ]
146qed.
147
148definition identifier_of_nat : ∀tag:String. nat → identifier tag ≝
149  λtag,n. an_identifier tag (succ_pos_of_nat  n).
150
151
152(* States that all identifiers in an environment are distinct from one another. *)
153let rec distinct_env tag (A:Type[0]) (l:list (identifier tag × A)) on l : Prop ≝
154match l with
155[ nil ⇒ True
156| cons hd tl ⇒ All ? (λia. \fst hd ≠ \fst ia) tl ∧
157               distinct_env tag A tl
158].
159
160lemma distinct_env_append_l : ∀tag,A,l,r. distinct_env tag A (l@r) → distinct_env tag A l.
161#tag #A #l elim l
162[ //
163| * #id #a #tl #IH #r * #H1 #H2 % /2 by All_append_l/
164] qed.
165
166lemma distinct_env_append_r : ∀tag,A,l,r. distinct_env tag A (l@r) → distinct_env tag A r.
167#tag #A #l elim l
168[ //
169| * #id #a #tl #IH #r * #H1 #H2 /2 by /
170] qed.
171
172(* check_distinct_env is quadratic - we could pay more attention when building maps to make sure that
173   the original environment was distinct. *)
174
175axiom DuplicateVariable : String.
176
177let rec check_member_env tag (A:Type[0]) (id:identifier tag) (l:list (identifier tag × A)) on l : res (All ? (λia. id ≠ \fst ia) l) ≝
178match l return λl.res (All ?? l) with
179[ nil ⇒ OK ? I
180| cons hd tl ⇒
181    match identifier_eq tag id (\fst hd) with
182    [ inl _ ⇒ Error ? [MSG DuplicateVariable; CTX ? id]
183    | inr NE ⇒
184        do Htl ← check_member_env tag A id tl;
185        OK ? (conj ?? NE Htl)
186    ]
187].
188
189let rec check_distinct_env tag (A:Type[0]) (l:list (identifier tag × A)) on l : res (distinct_env tag A l) ≝
190match l return λl.res (distinct_env tag A l) with
191[ nil ⇒ OK ? I
192| cons hd tl ⇒
193    do Hhd ← check_member_env tag A (\fst hd) tl;
194    do Htl ← check_distinct_env tag A tl;
195    OK ? (conj ?? Hhd Htl)
196].
197
198
199
200
201(* Maps from identifiers to arbitrary types. *)
202
203include "common/PositiveMap.ma".
204
205inductive identifier_map (tag:String) (A:Type[0]) : Type[0] ≝
206  an_id_map : positive_map A → identifier_map tag A.
207 
208definition empty_map : ∀tag:String. ∀A. identifier_map tag A ≝
209  λtag,A. an_id_map tag A (pm_leaf A).
210
211let rec lookup tag A (m:identifier_map tag A) (l:identifier tag) on m : option A ≝
212  lookup_opt A (match l with [ an_identifier l' ⇒ l' ])
213               (match m with [ an_id_map m' ⇒ m' ]).
214
215definition lookup_def ≝
216λtag,A,m,l,d. match lookup tag A m l with [ None ⇒ d | Some x ⇒ x].
217
218definition member ≝
219  λtag,A.λm:identifier_map tag A.λl:identifier tag.
220  match lookup tag A m l with [ None ⇒ false | _ ⇒ true ].
221
222interpretation "identifier map membership" 'mem a b = (member ?? b a).
223
224definition lookup_safe : ∀tag,A.∀m : identifier_map tag A.∀i.i∈m → A ≝
225λtag,A,m,i.
226match lookup … m i return λx.match x in option return λ_.bool with [ _ ⇒ ?] → ? with
227[ Some x ⇒ λ_.x
228| None ⇒ λprf.⊥
229]. @prf qed.
230
231lemma lookup_eq_safe : ∀tag,A,m,i,prf.lookup tag A m i = Some ? (lookup_safe tag A m i prf).
232#tag #A #m #i whd in match (i∈m);
233whd in match lookup_safe; normalize nodelta
234cases (lookup ????) normalize nodelta [*] // qed.
235
236(* Always adds the identifier to the map. *)
237let rec add tag A (m:identifier_map tag A) (l:identifier tag) (a:A) on m : identifier_map tag A ≝
238  an_id_map tag A (insert A (match l with [ an_identifier l' ⇒ l' ]) a
239                            (match m with [ an_id_map m' ⇒ m' ])).
240
241lemma lookup_add_hit : ∀tag,A,m,i,a.
242  lookup tag A (add tag A m i a) i = Some ? a.
243#tag #A * #m * #i #a
244@lookup_opt_insert_hit
245qed.
246
247lemma lookup_def_add_hit : ∀tag,A,m,i,a,d.
248  lookup_def tag A (add tag A m i a) i d = a.
249#tag #A * #m * #i #a #d
250@lookup_insert_hit
251qed.
252
253lemma lookup_add_miss : ∀tag,A,m,i,j,a.
254  i ≠ j →
255  lookup tag A (add tag A m j a) i = lookup tag A m i.
256#tag #A * #m * #i * #j #a #H
257@lookup_opt_insert_miss /2 by not_to_not/
258qed.
259
260axiom lookup_def_add_miss : ∀tag,A,m,i,j,a,d.
261  i ≠ j →
262  lookup_def tag A (add tag A m j a) i d = lookup_def tag A m i d.
263
264lemma lookup_add_oblivious : ∀tag,A,m,i,j,a.
265  (lookup tag A m i ≠ None ?) →
266  lookup tag A (add tag A m j a) i ≠ None ?.
267#tag #A #m #i #j #a #H
268cases (identifier_eq ? i j)
269[ #E >E >lookup_add_hit % #N destruct
270| #NE >lookup_add_miss //
271] qed.
272
273lemma lookup_add_cases : ∀tag,A,m,i,j,a,v.
274  lookup tag A (add tag A m i a) j = Some ? v →
275  (i=j ∧ v = a) ∨ lookup tag A m j = Some ? v.
276#tag #A #m #i #j #a #v
277cases (identifier_eq ? i j)
278[ #E >E >lookup_add_hit #H %1 destruct % //
279| #NE >lookup_add_miss /2 by or_intror, sym_not_eq/
280] qed.
281
282(* Extract every identifier, value pair from the map. *)
283definition elements : ∀tag,A. identifier_map tag A → list (identifier tag × A) ≝
284λtag,A,m.
285  fold ?? (λl,a,el. 〈an_identifier tag l, a〉::el)
286          (match m with [ an_id_map m' ⇒ m' ]) [ ].
287
288(* Test a predicate on all of the entries in a map.  The predicate is given a
289   proof that the entry appears in the map. *)
290
291definition idmap_all : ∀tag,A. ∀m:identifier_map tag A. (∀id,a. lookup tag A m id = Some A a → bool) → bool ≝
292λtag,A,m,f. pm_all A (match m with [ an_id_map m' ⇒ m' ])
293                     (λp,a,H. f (an_identifier tag p) a ?).
294cases m in H ⊢ %; #m' normalize //
295qed.
296
297inductive idmap_pred_graph : ∀tag,A,m,id,a,L. ∀f:(∀id,a. lookup tag A m id = Some A a → bool). bool → Prop ≝
298| idmappg : ∀tag,A,m,id,a,L,f. idmap_pred_graph tag A m id a L f (f id a L).
299
300lemma idmap_pred_irr : ∀tag,A,m,id,a,L,L'. ∀f:(∀id,a. lookup tag A m id = Some A a → bool).
301  f id a L = f id a L'.
302#tag #A #m #id #a #L #L' #f
303cut (idmap_pred_graph tag A m id a L f (f id a L)) [ % ]
304cases (f id a L) #H
305cut (idmap_pred_graph tag A m id a L' f ?) [ 2,5: @H | 1,4: skip ] * //
306qed.
307
308lemma idmap_all_ok : ∀tag,A,m,f.
309  bool_to_Prop (idmap_all tag A m f) ↔ (∀id,a,H. f id a H).
310#tag #A * #m #f
311whd in match (idmap_all ????); @(iff_trans … (pm_all_ok …)) %
312[ #H * #id #a #PR lapply (H id a PR) #X @eq_true_to_b <X @idmap_pred_irr
313| #H #p #a #PR @H
314] qed.
315
316
317axiom MissingId : String.
318
319(* Only updates an existing entry; fails with an error otherwise. *)
320definition update : ∀tag,A. identifier_map tag A → identifier tag → A → res (identifier_map tag A) ≝
321λtag,A,m,l,a.
322  match update A (match l with [ an_identifier l' ⇒ l' ]) a
323                 (match m with [ an_id_map m' ⇒ m' ]) with
324  [ None ⇒ Error ? ([MSG MissingId; CTX tag l]) (* missing identifier *)
325  | Some m' ⇒ OK ? (an_id_map tag A m')
326  ].
327
328definition foldi:
329  ∀A, B: Type[0].
330  ∀tag: String.
331  (identifier tag -> A -> B -> B) -> identifier_map tag A -> B -> B ≝
332λA,B,tag,f,m,b.
333  match m with
334  [ an_id_map m' ⇒ fold A B (λbv. f (an_identifier ? bv)) m' b ].
335
336(* An informative, dependently-typed, fold. *)
337
338definition fold_inf:
339  ∀A, B: Type[0].
340  ∀tag: String.
341  ∀m:identifier_map tag A.
342  (∀id:identifier tag. ∀a:A. lookup … m id = Some A a → B → B) → B → B ≝
343λA,B,tag,m.
344  match m return λm. (∀id:identifier tag. ∀a:A. lookup … m id = Some A a → B → B) → B → B with
345  [ an_id_map m' ⇒ λf,b. pm_fold_inf A B m' (λbv,a,H. f (an_identifier ? bv) a H) b ].
346
347(* A predicate that an identifier is in a map, and a failure-avoiding lookup
348   and update using it. *)
349
350definition present : ∀tag,A. identifier_map tag A → identifier tag → Prop ≝
351λtag,A,m,i. lookup … m i ≠ None ?.
352
353lemma member_present : ∀tag,A,m,id.
354  member tag A m id = true → present tag A m id.
355#tag #A * #m #id normalize cases (lookup_opt A ??) normalize
356[ #E destruct
357| #x #E % #E' destruct
358] qed.
359
360lemma present_member : ∀tag,A,m,id.
361  present tag A m id → member tag A m id.
362#tag #A #m #id whd in ⊢ (% → ?%); cases (lookup ????) // * #H cases (H (refl ??))
363qed.
364
365definition lookup_present : ∀tag,A. ∀m:identifier_map tag A. ∀id. present ?? m id → A ≝
366λtag,A,m,id. match lookup ?? m id return λx. x ≠ None ? → ? with [ Some a ⇒ λ_. a | None ⇒ λH.⊥ ].
367cases H #H'  cases (H' (refl ??)) qed.
368
369lemma lookup_lookup_present : ∀tag,A,m,id,p.
370  lookup tag A m id = Some ? (lookup_present tag A m id p).
371#tag #A #m #id #p
372whd in p ⊢ (???(??%));
373cases (lookup tag A m id) in p ⊢ %;
374[ * #H @⊥ @H @refl
375| #a #H @refl
376] qed.
377
378lemma lookup_is_present : ∀tag,T,m,id,t.
379  lookup tag T m id = Some T t →
380  present ?? m id.
381#tag #T #m #id #t #L normalize >L % #E destruct
382qed.
383
384lemma lookup_present_eq : ∀tag,T,m,id,t.
385  lookup tag T m id = Some T t →
386  ∀H. lookup_present tag T m id H = t.
387#tag #T #m #id #t #L #H
388lapply (lookup_lookup_present … H) >L #E destruct %
389qed.
390
391
392definition update_present : ∀tag,A. ∀m:identifier_map tag A. ∀id. present ?? m id → A → identifier_map tag A ≝
393λtag,A,m,l,p,a.
394  let l' ≝ match l with [ an_identifier l' ⇒ l' ] in
395  let m' ≝ match m with [ an_id_map m' ⇒ m' ] in
396  let u' ≝ update A l' a m' in
397  match u' return λx. update ???? = x → ? with
398  [ None ⇒ λE.⊥
399  | Some m' ⇒ λ_. an_id_map tag A m'
400  ] (refl ? u').
401cases l in p E; cases m; -l' -m' #m' #l'
402whd in ⊢ (% → ?);
403 whd in ⊢ (?(??(???%%)?) → ??(??%?%)? → ?);
404#NL #U cases NL #H @H @(update_fail … U)
405qed.
406
407lemma update_still_present : ∀tag,A,m,id,a,id'.
408  ∀H:present tag A m id.
409  ∀H':present tag A m id'.
410  present tag A (update_present tag A m id' H' a) id.
411#tag #A * #m * #id #a * #id' #H #H'
412whd whd in ⊢ (?(??(???(%??????)?)?)); normalize nodelta
413cases (identifier_eq ? (an_identifier tag id) (an_identifier tag id'))
414[ #E >E @refute_none_by_refl #m' #U whd in ⊢ (?(??%?)); >(update_lookup_opt_same ????? U)
415  % #E' destruct
416| #NE @refute_none_by_refl #m' #U whd in ⊢ (?(??%?)); whd in ⊢ (?(??(??%%)?));
417  <(update_lookup_opt_other ????? U id) [ @H | % #E cases NE >E #H @H @refl ]
418] qed.
419
420lemma lookup_present_add_hit:
421  ∀tag, A, map, k, v, k_pres.
422    lookup_present tag A (add … map k v) k k_pres = v.
423  #tag #a #map #k #v #k_pres
424  lapply (lookup_lookup_present … (add … map k v) … k_pres)
425  >lookup_add_hit #Some_assm destruct(Some_assm)
426  <e0 %
427qed.
428
429lemma lookup_present_add_miss:
430  ∀tag, A, map, k, k', v, k_pres', k_pres''.
431    k' ≠ k →
432      lookup_present tag A (add … map k v) k' k_pres' = lookup_present tag A map k' k_pres''.
433  #tag #A #map #k #k' #v #k_pres' #k_pres'' #neq_assm
434  lapply (lookup_lookup_present … (add … map k v) ? k_pres')
435  >lookup_add_miss try assumption
436  #Some_assm
437  lapply (lookup_lookup_present … map k') >Some_assm #Some_assm'
438  lapply (Some_assm' k_pres'') #Some_assm'' destruct assumption
439qed.
440
441lemma present_add_present:
442  ∀tag, a, map, k, k', v.
443    k' ≠ k →
444      present tag a (add tag a map k v) k' →
445        present tag a map k'.
446  #tag #a #map #k #k' #v #neq_hyp #present_hyp
447  whd in match present; normalize nodelta
448  whd in match present in present_hyp; normalize nodelta in present_hyp;
449  cases (not_None_to_Some a … present_hyp) #v' #Some_eq_hyp
450  lapply (lookup_add_cases tag ?????? Some_eq_hyp) *
451  [1:
452    * #k_eq_hyp @⊥ /2/
453  |2:
454    #Some_eq_hyp' /2/
455  ]
456qed.
457
458lemma present_add_hit:
459  ∀tag, a, map, k, v.
460    present tag a (add tag a map k v) k.
461  #tag #a #map #k #v
462  whd >lookup_add_hit
463  % #absurd destruct
464qed.
465
466lemma present_add_miss:
467  ∀tag, a, map, k, k', v.
468    k' ≠ k → present tag a map k' → present tag a (add tag a map k v) k'.
469  #tag #a #map #k #k' #v #neq_assm #present_assm
470  whd >lookup_add_miss assumption
471qed.
472
473
474let rec fresh_for_map tag A (id:identifier tag) (m:identifier_map tag A) on id : Prop ≝
475  lookup … m id = None A.
476
477lemma fresh_for_empty_map : ∀tag,A,id.
478  fresh_for_map tag A id (empty_map tag A).
479#tag #A * #id //
480qed.
481
482definition fresh_map_for_univ ≝
483λtag,A. λm:identifier_map tag A. λu:universe tag.
484  ∀id. present tag A m id → fresh_for_univ tag id u.
485
486lemma fresh_fresh_for_map : ∀tag,A,m,id,u,u'.
487  fresh_map_for_univ tag A m u →
488  〈id,u'〉 = fresh tag u →
489  fresh_for_map tag A id m.
490#tag #A * #m * #id * #u * #u' whd in ⊢ (% → ???% → %);
491#FMU #E destruct lapply (FMU (an_identifier tag u)) whd in ⊢ ((% → %) → ?);
492generalize in ⊢ ((?(??%?) → ?) → ??%?); *
493[ // | #a #H @False_ind lapply (H ?) /2 by absurd/ % #E destruct
494qed.
495
496lemma fresh_map_preserved : ∀tag,A,m,u,u',id.
497  fresh_map_for_univ tag A m u →
498  〈id,u'〉 = fresh tag u →
499  fresh_map_for_univ tag A m u'.
500#tag #A #m #u * #u' #id whd in ⊢ (% → ? → %); #H #E
501#id' #PR @(fresh_remains_fresh … E) @H //
502qed.
503
504lemma fresh_map_add : ∀tag,A,m,u,id,a.
505  fresh_map_for_univ tag A m u →
506  fresh_for_univ tag id u →
507  fresh_map_for_univ tag A (add tag A m id a) u.
508#tag #A * #m #u #id #a #Hm #Hi
509#id' #PR cases (identifier_eq tag id' id)
510[ #E >E @Hi
511| #NE @Hm whd in PR;
512  change with (add tag A (an_id_map tag A m) id a) in PR:(?(??(???%?)?));
513  >lookup_add_miss in PR; //
514] qed.
515
516lemma present_not_fresh : ∀tag,A,m,id,id'.
517  present tag A m id →
518  fresh_for_map tag A id' m →
519  id ≠ id'.
520#tag #A #m #id * #id' whd in ⊢ (% → % → ?);
521* #NE #E % #E' destruct @(NE E)
522qed.
523
524lemma fresh_for_map_add : ∀tag,A,id,m,id',a.
525  id ≠ id' →
526  fresh_for_map tag A id m →
527  fresh_for_map tag A id (add tag A m id' a).
528#tag #A * #id #m #id' #a #NE #F
529whd >lookup_add_miss //
530qed.
531
532(* Extending the domain of a map (without necessarily preserving contents). *)
533
534definition extends_domain : ∀tag,A. identifier_map tag A → identifier_map tag A → Prop ≝
535λtag,A,m1,m2. ∀l. present ?? m1 l → present ?? m2 l.
536
537lemma extends_dom_trans : ∀tag,A,m1,m2,m3.
538  extends_domain tag A m1 m2 → extends_domain tag A m2 m3 → extends_domain tag A m1 m3.
539#tag #A #m1 #m2 #m3 #H1 #H2 #l #P1 @H2 @H1 @P1 qed.
540
541
542(* Sets *)
543
544definition identifier_set ≝ λtag.identifier_map tag unit.
545
546definition empty_set : ∀tag.identifier_set tag ≝ λtag.empty_map ….
547
548
549definition add_set : ∀tag.identifier_set tag → identifier tag → identifier_set tag ≝
550  λtag,s,i.add … s i it.
551
552definition singleton_set : ∀tag:String. identifier tag → identifier_set tag ≝
553λtag,i. add_set tag (empty_set tag) i.
554
555let rec union_set (tag:String) A B (s:identifier_map tag A) (s':identifier_map tag B) on s : identifier_set tag ≝
556  an_id_map tag unit (merge … (λo,o'.match o with [Some _ ⇒ Some ? it | None ⇒ !_ o'; return it])
557    (match s with [ an_id_map s0 ⇒ s0 ])
558    (match s' with [ an_id_map s1 ⇒ s1 ])).
559
560
561(* set minus is generalised to maps *)
562let rec minus_set (tag:String) A B (s:identifier_map tag A) (s':identifier_map tag B) on s : identifier_map tag A ≝
563  an_id_map tag A (merge A B A (λo,o'.match o' with [None ⇒ o | Some _ ⇒ None ?])
564    (match s with [ an_id_map s0 ⇒ s0 ])
565    (match s' with [ an_id_map s1 ⇒ s1 ])).
566
567notation "a ∖ b" left associative with precedence 55 for @{'setminus $a $b}.
568
569interpretation "identifier set union" 'union a b = (union_set ??? a b).
570notation "∅" non associative with precedence 90 for @{ 'empty }.
571interpretation "empty identifier set" 'empty = (empty_set ?).
572interpretation "singleton identifier set" 'singl a = (add_set ? (empty_set ?) a).
573interpretation "identifier map difference" 'setminus a b = (minus_set ??? a b).
574
575definition IdentifierSet : String → Setoid ≝ λtag.
576  mk_Setoid (identifier_set tag) (λs,s'.∀i.i ∈ s = (i ∈ s')) ???.
577  // qed.
578
579unification hint 0 ≔ tag;
580S ≟ IdentifierSet tag
581(*-----------------------------*)⊢
582identifier_set tag ≡ std_supp S.
583unification hint 0 ≔ tag;
584S ≟ IdentifierSet tag
585(*-----------------------------*)⊢
586identifier_map tag unit ≡ std_supp S.
587
588lemma mem_set_add : ∀tag,A.∀i,j : identifier tag.∀s,x.
589  i ∈ add ? A s j x = (eq_identifier ? i j ∨ i ∈ s).
590#tag #A *#i *#j *#s #x normalize
591@(eqb_elim i j)
592[#EQ destruct
593  >(lookup_opt_insert_hit A x j)
594|#NEQ >(lookup_opt_insert_miss … s NEQ)
595] elim (lookup_opt  A j s) normalize // qed.
596
597lemma mem_set_add_id : ∀tag,A,i,s,x.bool_to_Prop (i ∈ add tag A s i x).
598#tag #A #i #s #x >mem_set_add
599@eq_identifier_elim [#_ %| #ABS elim (absurd … (refl ? i) ABS)] qed.
600
601lemma in_map_domain : ∀tag,A.∀m : identifier_map tag A.∀i.
602  if i ∈ m then (∃s.lookup … m i = Some ? s) else (lookup … m i = None ?).
603#tag #A * #m * #i normalize
604elim (lookup_opt A i m) normalize
605[ % | #x %{x} % ]
606qed.
607
608lemma union_empty_l : ∀tag.∀s:identifier_set tag. ∅ ∪ s = s.
609#tag * normalize #m >map_opt_id_eq_ext // * %
610qed.
611
612lemma union_empty_r : ∀tag.∀s:identifier_set tag. s ∪ ∅ = s.
613#tag * * [//] *[2: *] #l#r normalize
614>map_opt_id_eq_ext [1,3: >map_opt_id_eq_ext [2,4: *] |*: *] //
615qed.
616
617lemma minus_empty_l : ∀tag,A.∀s:identifier_map tag A. ∅ ∖ s ≅ ∅.
618#tag #A * * [//] *[2:#x]#l#r * * normalize [1,4://]
619#p >lookup_opt_map elim (lookup_opt ???) normalize //
620qed.
621
622lemma minus_empty_r : ∀tag,A.∀s:identifier_map tag A. s ∖ ∅ = s.
623#tag #A * * [//] *[2:#x]#l#r normalize
624>map_opt_id >map_opt_id //
625qed.
626
627lemma mem_set_union : ∀tag.∀i : identifier tag.∀s,s' : identifier_set tag.
628  i ∈ (s ∪ s') = (i ∈ s ∨ i ∈ s').
629#tag * #i * #s * #s' normalize
630>lookup_opt_merge [2: @refl]
631elim (lookup_opt ???)
632elim (lookup_opt ???)
633normalize // qed.
634
635lemma mem_set_minus : ∀tag,A,B.∀i : identifier tag.∀s : identifier_map tag A.
636  ∀s' : identifier_map tag B.
637  i ∈ (s ∖ s') = (i ∈ s ∧ ¬ i ∈ s').
638#tag #A #B * #i * #s * #s' normalize
639>lookup_opt_merge [2: @refl]
640elim (lookup_opt ???)
641elim (lookup_opt ???)
642normalize // qed.
643
644lemma set_eq_ext_node : ∀tag.∀o,o',l,l',r,r'.
645  an_id_map tag ? (pm_node ? o l r) ≅ an_id_map … (pm_node ? o' l' r') →
646    o = o' ∧ an_id_map tag ? l ≅ an_id_map … l' ∧ an_id_map tag ? r ≅ an_id_map … r'.
647#tag#o#o'#l#l'#r#r'#H
648%[
649%[ lapply (H (an_identifier ? one))
650   elim o [2: *] elim o' [2,4: *] normalize // #EQ destruct
651 | *#p lapply (H (an_identifier ? (p0 p))) normalize //
652]| *#p lapply (H (an_identifier ? (p1 p))) normalize //
653]
654qed.
655
656lemma set_eq_ext_leaf : ∀tag,A.∀o,l,r.
657  (∀i.i∈an_id_map tag A (pm_node ? o l r) = false) →
658    o = None ? ∧ (∀i.i∈an_id_map tag ? l = false) ∧ (∀i.i∈an_id_map tag ? r = false).
659#tag#A#o#l#r#H
660%[
661%[ lapply (H (an_identifier ? one))
662   elim o [2: #a] normalize // #EQ destruct
663 | *#p lapply (H (an_identifier ? (p0 p))) normalize //
664]| *#p lapply (H (an_identifier ? (p1 p))) normalize //
665]
666qed.
667
668
669definition id_map_size : ∀tag : String.∀A. identifier_map tag A → ℕ ≝
670  λtag,A,s.match s with [an_id_map p ⇒ |p|].
671
672interpretation "identifier map domain size" 'norm s = (id_map_size ?? s).
673
674lemma set_eq_ext_empty_to_card : ∀tag,A.∀s : identifier_map tag A. (∀i.i∈s = false) → |s| = 0.
675#tag#A * #s elim s [//]
676#o#l#r normalize in ⊢((?→%)→(?→%)→?); #Hil #Hir #H
677elim (set_eq_ext_leaf … H) * #EQ destruct #Hl #Hr normalize
678>(Hil Hl) >(Hir Hr) // qed.
679
680lemma set_eq_ext_to_card : ∀tag.∀s,s' : identifier_set tag. s ≅ s' → |s| = |s'|.
681#tag *#s elim s
682[** [//] #o#l#r #H
683  >(set_eq_ext_empty_to_card … (std_symm … H)) //
684| #o#l#r normalize in ⊢((?→?→??%?)→(?→?→??%?)→?);
685  #Hil #Hir **
686  [#H @(set_eq_ext_empty_to_card … H)]
687  #o'#l'#r' #H elim (set_eq_ext_node … H) * #EQ destruct(EQ) #Hl #Hr
688  normalize >(Hil ? Hl) >(Hir ? Hr) //
689] qed.
690
691lemma add_size: ∀tag,A,s,i,x.
692  |add tag A s i x| = (if i ∈ s then 0 else 1) + |s|.
693#tag #A *#s *#i #x
694lapply (insert_size ? i x s)
695lapply (refl ? (lookup_opt ? i s))
696generalize in ⊢ (???%→?); * [2: #x']
697normalize #EQ >EQ normalize //
698qed.
699
700lemma mem_set_O_lt_card : ∀tag,A.∀i.∀s : identifier_map tag A. i ∈ s → |s| > 0.
701#tag #A * #i * #s normalize #H
702@(lookup_opt_O_lt_size … i)
703% #EQ >EQ in H; normalize *
704qed.
705
706(* NB: no control on values if applied to maps *)
707definition set_subset ≝ λtag,A,B.λs : identifier_map tag A.
708  λs' : identifier_map tag B. ∀i.i ∈ s → (bool_to_Prop (i ∈ s')).
709
710interpretation "identifier set subset" 'subseteq s s' = (set_subset ??? s s').
711
712lemma add_subset :
713  ∀tag,A,B.∀i : identifier tag.∀x.∀s : identifier_map ? A.∀s' : identifier_map ? B.
714    i ∈ s' → s ⊆ s' → add … s i x ⊆ s'.
715#tag#A#B#i#x#s#s' #H #G #j
716>mem_set_add
717@eq_identifier_elim #H' [* >H' @H | #js @(G ? js)]
718qed.
719
720definition set_forall : ∀tag,A.(identifier tag → Prop) →
721  identifier_map tag A → Prop ≝ λtag,A,P,m.∀i. i ∈ m → P i.
722 
723lemma set_forall_add : ∀tag,P,m,i.set_forall tag ? P m → P i →
724  set_forall tag ? P (add_set ? m i).
725#tag#P#m#i#Pm#Pi#j
726>mem_set_add
727@eq_identifier_elim
728[#EQ destruct(EQ) #_ @Pi
729|#_ @Pm
730]
731qed.
732
733include "utilities/proper.ma".
734
735lemma minus_subset : ∀tag,A,B.minus_set tag A B ⊨ set_subset … ++> set_subset … -+> set_subset ….
736#tag#A#B#s#s' #H #s'' #s''' #G #i
737>mem_set_minus >mem_set_minus
738#H' elim (andb_Prop_true … H') -H' #is #nis''
739>(H … is)
740elim (true_or_false_Prop (i∈s'''))
741[ #is''' >(G … is''') in nis''; *
742| #nis''' >nis''' %
743]
744qed.
745
746lemma subset_node : ∀tag,A,B.∀o,o',l,l',r,r'.
747  an_id_map tag A (pm_node ? o l r) ⊆ an_id_map tag B (pm_node ? o' l' r') →
748    opt_All ? (λ_.o' ≠ None ?) o ∧ an_id_map tag ? l ⊆ an_id_map tag  ? l' ∧
749      an_id_map tag ? r ⊆ an_id_map tag ? r'.
750#tag#A#B#o#o'#l#l'#r#r'#H
751%[%
752  [ lapply (H (an_identifier ? (one))) elim o [2: #a] elim o' [2:#b]
753    normalize // [#_ % #ABS destruct(ABS) | #G lapply (G I) *]
754  | *#p lapply (H (an_identifier ? (p0 p)))
755  ]
756 | *#p lapply (H (an_identifier ? (p1 p)))
757] #H @H
758qed.
759
760lemma subset_leaf : ∀tag,A.∀o,l,r.
761  an_id_map tag A (pm_node ? o l r) ⊆ ∅ →
762    o = None ? ∧ (∀i.i∈an_id_map tag ? l = false) ∧ (∀i.i∈an_id_map tag ? r = false).
763#tag#A#o#l#r#H
764%[
765%[ lapply (H (an_identifier ? one))
766   elim o [2: #a] normalize // #EQ lapply(EQ I) *
767 | *#p lapply (H (an_identifier ? (p0 p)))
768 ]
769|  *#p lapply (H (an_identifier ? (p1 p)))
770] normalize elim (lookup_opt ? p ?) normalize
771// #a #H lapply (H I) *
772qed.
773
774lemma subset_card : ∀tag,A,B.∀s : identifier_map tag A.∀s' : identifier_map tag B.
775  s ⊆ s' → |s| ≤ |s'|.
776#tag #A #B *#s elim s
777[ //
778| #o#l#r #Hil #Hir **
779  [ #H elim (subset_leaf … H) * #EQ >EQ #Hl #Hr
780    lapply (set_eq_ext_empty_to_card … Hl)
781    lapply (set_eq_ext_empty_to_card … Hr)
782    normalize //
783  | #o' #l' #r' #H elim (subset_node … H) *
784    elim o [2: #a] elim o' [2,4: #a']
785    [3: #G normalize in G; elim(absurd ? (refl ??) G)
786    |*: #_ #Hl #Hr lapply (Hil ? Hl) lapply (Hir ? Hr)
787      normalize #H1 #H2
788      [@le_S_S | @(transitive_le … (|l'|+|r'|)) [2: / by /]]
789      @le_plus assumption
790    ]
791  ]
792]
793qed.
794
795lemma mem_set_empty : ∀tag,A.∀i: identifier tag. i∈empty_map tag A = false.
796#tag #A * #i normalize %
797qed.
798
799lemma mem_set_singl_to_eq : ∀tag.∀i,j : identifier tag.i∈{(j)} → i = j.
800#tag
801#i #j >mem_set_add >mem_set_empty
802#H elim (orb_true_l … H) -H
803[@eq_identifier_elim [//] #_] #EQ destruct
804qed.
805
806lemma subset_add_set : ∀tag,i,s.s ⊆ add_set tag s i.
807#tag#i#s#j #H >mem_set_add >H
808>commutative_orb %
809qed.
810
811lemma add_set_monotonic : ∀tag,i,s,s'.s ⊆ s' → add_set tag s i ⊆ add_set tag s' i.
812#tag#i#s#s' #H #j >mem_set_add >mem_set_add
813@orb_elim elim (eq_identifier ???)
814whd lapply (H j) /2 by /
815qed.
816
817lemma transitive_subset : ∀tag,A.transitive ? (set_subset tag A A).
818#tag#A#s#s'#s''#H#G#i #is
819@(G … (H … is))
820qed.
821
822definition set_from_list : ∀tag.list (identifier tag) → identifier_map tag unit ≝
823  λtag.foldl … (add_set ?) ∅.
824
825coercion id_set_from_list : ∀tag.∀l : list (identifier tag).identifier_map tag unit ≝
826  set_from_list on _l : list (identifier ?) to identifier_map ? unit.
827
828lemma mem_map_domain : ∀tag,A.∀m : identifier_map tag A.∀i.
829i∈m → lookup … m i ≠ None ?.
830#tag#A * #m #i
831whd in match (i∈?);
832elim (lookup ????) normalize [2: #x]
833* % #EQ destruct(EQ)
834qed.
835
836
837
838lemma mem_list_as_set : ∀tag.∀l : list (identifier tag).
839  ∀i.i ∈ l → In ? l i.
840#tag #l @(list_elim_left … l)
841[ #i *
842| #t #h #Hi  #i
843  whd in ⊢ (?(???%?)→?);
844  >foldl_append
845  whd in ⊢ (?(???%?)→?);
846  >mem_set_add
847  @eq_identifier_elim
848  [ #EQi destruct(EQi)
849    #_ @Exists_append_r % %
850  | #_ #H @Exists_append_l @Hi assumption
851  ]
852]
853qed.
854
855lemma list_as_set_mem : ∀tag.∀l : list (identifier tag).
856  ∀i.In ? l i → i ∈ l.
857#tag #l @(list_elim_left … l)
858[ #i *
859| #t #h #Hi #i #H
860  whd in ⊢ (?(???%?));
861  >foldl_append
862  whd in ⊢ (?(???%?));
863  elim (Exists_append … H) -H
864  [ #H >mem_set_add
865    @eq_identifier_elim [//] #_ normalize
866    @Hi @H
867  | * [2: *] #EQi destruct(EQi) >mem_set_add_id %
868  ]
869]
870qed.
871
872lemma list_as_set_All : ∀tag,P.∀ l : list (identifier tag).
873  (∀i.i ∈ l → P i) → All ? P l.
874#tag #P #l @(list_elim_left … l)
875[ #_ %
876| #x #l' #Hi
877  whd in match (set_from_list … (l'@[x]));
878  >foldl_append
879  #H @All_append
880  [ @Hi #i #G @H
881    whd in ⊢ (?(???%?));
882    >mem_set_add @orb_Prop_r @G
883  | % [2: %]
884    @H
885    whd in ⊢ (?(???%?));
886    @mem_set_add_id
887  ]
888]
889qed.
890
891lemma All_list_as_set : ∀tag,P.∀ l : list (identifier tag).
892  All ? P l → ∀i.i ∈ l → P i.
893#tag #P #l @(list_elim_left … l)
894[ * #i *
895| #x #l' #Hi #H
896  lapply (All_append_l … H)
897  lapply (All_append_r … H)
898  * #Px * #Pl' #i
899  whd in match (set_from_list … (l'@[x]));
900  >foldl_append
901  >mem_set_add
902  @eq_identifier_elim
903  [ #EQx >EQx #_ @Px
904  | #_ whd in match (?∨?); @Hi @Pl'
905  ]
906]
907qed. 
908
909lemma map_mem_prop :
910  ∀tag,A.∀m : identifier_map tag A.∀i.
911  lookup ?? m i ≠ None ? → i ∈ m.
912#p #globals #m #i
913lapply (in_map_domain … m i)
914cases (i∈m)
915[ * #x #_ #_ %
916| #EQ >EQ * #ABS @ABS %
917] qed.
918
919
920(* Attempt to choose an entry in the map/set, and if successful return the entry
921   and the map/set without it. *)
922
923definition choose : ∀tag,A. identifier_map tag A → option (identifier tag × A × (identifier_map tag A)) ≝
924λtag,A,m.
925  match pm_choose A (match m with [ an_id_map m' ⇒ m' ]) with
926  [ None ⇒ None ?
927  | Some x ⇒ Some ? 〈〈an_identifier tag (\fst (\fst x)), \snd (\fst x)〉, an_id_map tag A (\snd x)〉
928  ].
929
930lemma choose_empty : ∀tag,A,m.
931  choose tag A m = None ? ↔ ∀id. lookup tag A m id = None ?.
932#tag #A * #m lapply (pm_choose_empty A m) * #H1 #H2 %
933[ normalize #C * @H1 cases (pm_choose A m) in C ⊢ %; [ // | normalize #x #E destruct ]
934| normalize #L lapply (pm_choose_empty A m) cases (pm_choose A m)
935  [ * #H1 #H2 normalize // | #x * #_ #H lapply (H ?) [ #p @(L (an_identifier ? p)) | #E destruct ] ]
936] qed.
937
938lemma choose_some : ∀tag,A,m,id,a,m'.
939  choose tag A m = Some ? 〈〈id,a〉,m'〉 →
940  lookup tag A m id = Some A a ∧
941  lookup tag A m' id = None A ∧
942  (∀id'. id = id' ∨ lookup tag A m id' = lookup tag A m' id').
943#tag #A * #m * #id #a * #m' #C
944lapply (pm_choose_some A m id a m' ?)
945[ whd in C:(??%?); cases (pm_choose A m) in C ⊢ %; normalize [ #E destruct | * * #x #y #z #E destruct % ] ]
946* * * #L1 #L2 #L3 #_
947% [ % [ @L1 | @L2 ] | * #id' cases (L3 id') [ /2/ | #L4 %2 @L4 ] ]
948qed.
949
950lemma choose_some_subset : ∀tag,A,m,id,a,m'.
951  choose tag A m = Some ? 〈〈id,a〉,m'〉 →
952  m' ⊆ m.
953#tag #A #m #id #a #m' #C
954cases (choose_some … m' C) * #L1 #L2 #L3
955#id' whd in ⊢ (?% → ?%);
956cases (L3 id')
957[ #E destruct >L2 *
958| #L4 >L4 //
959] qed.
960
961lemma choose_some_card : ∀tag,A,m,id,a,m'.
962  choose tag A m = Some ? 〈〈id,a〉,m'〉 →
963  |m| = S (|m'|).
964#tag #A * #m * #id #a * #m' #C
965lapply (pm_choose_some A m id a m' ?)
966[ whd in C:(??%?); cases (pm_choose A m) in C ⊢ %; normalize [ #E destruct | * * #x #y #z #E destruct % ] ]
967* #_ #H @H
968qed.
969
970(* Remove an element from a map/set, returning the element and a new map/set. *)
971
972definition try_remove : ∀tag,A. identifier_map tag A → identifier tag → option (A × (identifier_map tag A)) ≝
973λtag,A,m,id.
974  match pm_try_remove A (match id with [ an_identifier id' ⇒ id']) (match m with [ an_id_map m' ⇒ m' ]) with
975  [ None ⇒ None ?
976  | Some x ⇒ Some ? 〈\fst x, an_id_map tag A (\snd x)〉
977  ].
978
979lemma try_remove_empty : ∀tag,A,m,id.
980  try_remove tag A m id = None ? ↔ lookup tag A m id = None ?.
981#tag #A * #m * #id lapply (pm_try_remove_none A id m) * #H1 #H2 %
982[ normalize #C @H1 cases (pm_try_remove A id m) in C ⊢ %; [ // | normalize #x #E destruct ]
983| normalize #L >H2 //
984] qed.
985
986lemma try_remove_some : ∀tag,A,m,id,a,m'.
987  try_remove tag A m id = Some ? 〈a,m'〉 →
988  lookup tag A m id = Some A a ∧
989  lookup tag A m' id = None A ∧
990  (∀id'. id = id' ∨ lookup tag A m id' = lookup tag A m' id').
991#tag #A * #m * #id #a * #m' #C
992lapply (pm_try_remove_some A id m a m' ?)
993[ whd in C:(??%?); cases (pm_try_remove A id m) in C ⊢ %; normalize [ #E destruct | * #x #y #E destruct % ] ]
994* * * #L1 #L2 #L3 #_
995% [ % [ @L1 | @L2 ] | * #id' cases (L3 id') [ /2/ | #L4 %2 @L4 ] ]
996qed.
997
998lemma try_remove_some_card : ∀tag,A,m,id,a,m'.
999  try_remove tag A m id = Some ? 〈a,m'〉 →
1000  |m| = S (|m'|).
1001#tag #A * #m * #id #a * #m' #C
1002lapply (pm_try_remove_some A id m a m' ?)
1003[ whd in C:(??%?); cases (pm_try_remove A id m) in C ⊢ %; normalize [ #E destruct | * #x #y #E destruct % ] ]
1004* #_ #H @H
1005qed.
1006
1007lemma try_remove_this : ∀tag,A,m,id,a.
1008  lookup tag A m id = Some A a →
1009  ∃m'. try_remove tag A m id = Some ? 〈a,m'〉.
1010#tag #A * #m * #id #a #L
1011cases (pm_try_remove_some' A id m a L)
1012#m' #R %{(an_id_map tag A m')} whd in ⊢ (??%?); >R %
1013qed.
1014 
1015(* Link a map with the set consisting of its domain. *)
1016
1017definition id_set_of_map : ∀tag,A. identifier_map tag A → identifier_set tag ≝
1018λtag,A,m. an_id_map tag unit (map … (λ_. it) (match m with [ an_id_map m' ⇒ m'])).
1019
1020lemma id_set_of_map_subset : ∀tag,A,m.
1021  id_set_of_map tag A m ⊆ m.
1022#tag #A * #m * #id normalize
1023>lookup_opt_map normalize cases (lookup_opt ???) //
1024qed.
1025
1026lemma id_set_of_map_present : ∀tag,A,m,id.
1027  present tag A m id ↔ present tag unit (id_set_of_map … m) id.
1028#tag #A * #m * #id %
1029normalize @not_to_not
1030>lookup_opt_map cases (lookup_opt ???) normalize //
1031#a #E destruct
1032qed.
1033
1034lemma id_set_of_map_card : ∀tag,A,m.
1035  |m| = |id_set_of_map tag A m|.
1036#tag #A * #m whd in ⊢ (??%%); >map_size //
1037qed.
1038
1039
1040(* Transforming a list into a set. *)
1041
1042definition set_of_list : ∀tag. list (identifier tag) → identifier_set tag ≝
1043λtag,l. foldl ?? (λs,id. add_set tag s id) ∅ l.
1044
1045lemma fold_add_set_monotone : ∀tag,l,s,id.
1046  present tag unit s id →
1047  present tag unit (foldl ?? (λs,id. add_set tag s id) s l) id.
1048#tag #l elim l
1049[ //
1050| #h #t #IH #s #id #PR
1051  whd in ⊢ (???%?); @IH
1052  @lookup_add_oblivious
1053  @PR
1054] qed.
1055
1056lemma in_set_of_list : ∀tag,l,id.
1057  Exists ? (λid'. id' = id) l →
1058  present ?? (set_of_list tag l) id.
1059#tag #l #id whd in match (set_of_list ??); generalize in match ∅; elim l
1060[ #s *
1061| #id' #tl #IH #s *
1062  [ #E whd in ⊢ (???%?); destruct
1063    @fold_add_set_monotone //
1064  | @IH
1065  ]
1066] qed.
1067
1068lemma in_set_of_list' : ∀tag,l,id.
1069  present ?? (set_of_list tag l) id →
1070  Exists ? (λid'. id = id') l.
1071#tag #l #id whd in match (set_of_list ??);
1072cut (¬present ?? ∅ id) [ /3/ ]
1073generalize in match ∅;
1074elim l
1075[ #s #F #T @⊥ @(absurd … T F)
1076| #id' #tl #IH #s #F #PR whd in PR:(???%?);
1077  cases (identifier_eq … id id')
1078  [ #E destruct /2/
1079  | #NE %2 @(IH … PR)
1080    @(not_to_not … F) /2/
1081  ]
1082] qed.
1083
1084
1085
Note: See TracBrowser for help on using the repository browser.