2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department of the University of Bologna, Italy.
8 \ / This file is distributed under the terms of the
9 \ / GNU General Public License Version 2
10 V_______________________________________________________________ *)
12 include "basics/lists/listb.ma".
14 (****** DeqSet: a set with a decidable equality ******)
16 record FinSet : Type[1] ≝
17 { FinSetcarr:> DeqSet;
18 enum: list FinSetcarr;
19 enum_unique: uniqueb FinSetcarr enum = true
23 lemma bool_enum_unique: uniqueb ? [true;false] = true.
26 definition BoolFS ≝ mk_FinSet DeqBool [true;false] bool_enum_unique.
28 unification hint 0 ≔ ;
30 (* ---------------------------------------- *) ⊢
35 lemma eqbnat_true : ∀n,m. eqb n m = true ↔ n = m.
36 #n #m % [@eqb_true_to_eq | @eq_to_eqb_true]
39 definition DeqNat ≝ mk_DeqSet nat eqb eqbnat_true.
42 match n with [ O ⇒ [ ] | S p ⇒ p::enumn p ].
44 lemma memb_enumn: ∀m,n. n ≤ m → (¬ (memb DeqNat m (enumn n))) = true.
45 #m #n elim n // #n1 #Hind #ltm @sym_eq @noteq_to_eqnot @sym_not_eq
46 % #H cases (orb_true_l … H)
47 [#H1 @(absurd … (\P H1)) @sym_not_eq /2/
48 |<(notb_notb (memb …)) >Hind normalize /2/
52 lemma enumn_unique: ∀n. uniqueb DeqNat (enumn n) = true.
53 #n elim n // #m #Hind @true_to_andb_true /2/
56 definition initN ≝ λn.mk_FinSet DeqNat (enumn n) (enumn_unique n).
58 example tipa: ∀n.∃x: initN (S n). x = n.
59 #n @(ex_intro … n) // qed.
62 definition enum_sum ≝ λA,B:DeqSet.λl1.λl2.
63 (map ?? (inl A B) l1) @ (map ?? (inr A B) l2).
65 lemma enumAB_def : ∀A,B:FinSet.∀l1,l2. enum_sum A B l1 l2 =
66 (map ?? (inl A B) l1) @ (map ?? (inr A B) l2).
69 lemma enumAB_unique: ∀A,B:DeqSet.∀l1,l2.
70 uniqueb A l1 = true → uniqueb B l2 = true →
71 uniqueb ? (enum_sum A B l1 l2) = true.
73 [#_ #ul2 @unique_map_inj // #b1 #b2 #Hinr destruct //
74 |#a #tl #Hind #uA #uB @true_to_andb_true
75 [@sym_eq @noteq_to_eqnot % #H
76 cases (memb_append … (sym_eq … H))
77 [#H1 @(absurd (memb ? a tl = true))
78 [@(memb_map_inj …H1) #a1 #a2 #Hinl destruct //
79 |<(andb_true_l … uA) @eqnot_to_noteq //
82 [normalize #H destruct
83 |#b #tlB #Hind #membH cases (orb_true_l … membH)
84 [#H lapply (\P H) #H1 destruct |@Hind]
87 |@Hind // @(andb_true_r … uA)
92 definition FinSum ≝ λA,B:FinSet.
93 mk_FinSet (DeqSum A B)
94 (enum_sum A B (enum A) (enum B))
95 (enumAB_unique … (enum_unique A) (enum_unique B)).
97 unification hint 0 ≔ C1,C2;
101 (* ---------------------------------------- *) ⊢
102 T1+T2 ≡ FinSetcarr X.
106 unification hint 0 ≔ ;
107 X ≟ mk_DeqSet bool beqb beqb_true
108 (* ---------------------------------------- *) ⊢
111 unification hint 0 ≔ b1,b2:bool;
112 X ≟ mk_DeqSet bool beqb beqb_true
113 (* ---------------------------------------- *) ⊢
114 beqb b1 b2 ≡ eqb X b1 b2.
116 example exhint: ∀b:bool. (b == false) = true → b = false.
121 definition eq_pairs ≝
122 λA,B:DeqSet.λp1,p2:A×B.(\fst p1 == \fst p2) ∧ (\snd p1 == \snd p2).
124 lemma eq_pairs_true: ∀A,B:DeqSet.∀p1,p2:A×B.
125 eq_pairs A B p1 p2 = true ↔ p1 = p2.
126 #A #B * #a1 #b1 * #a2 #b2 %
127 [#H cases (andb_true …H) #eqa #eqb >(\P eqa) >(\P eqb) //
128 |#H destruct normalize >(\b (refl … a2)) >(\b (refl … b2)) //
132 definition DeqProd ≝ λA,B:DeqSet.
133 mk_DeqSet (A×B) (eq_pairs A B) (eq_pairs_true A B).
136 example hint2: ∀b1,b2.
137 〈b1,true〉==〈false,b2〉=true → 〈b1,true〉=〈false,b2〉.