]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/sets/partitions.ma
6b81ce60bf5b0d4e33280cd4cb3f7b596de045de
[helm.git] / helm / software / matita / nlibrary / sets / partitions.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "sets/sets.ma".
16 include "nat/plus.ma".
17 include "nat/compare.ma".
18 include "nat/minus.ma".
19
20 alias symbol "eq" = "setoid eq".
21 alias symbol "eq" = "setoid1 eq".
22 alias symbol "eq" = "setoid eq".
23 nrecord partition (A: setoid) : Type[1] ≝ 
24  { support: setoid;
25    indexes: qpowerclass support;
26    class: support → qpowerclass A;
27    inhabited: ∀i. i ∈ indexes → class i ≬ class i;
28    disjoint: ∀i,j. i ∈ indexes → j ∈ indexes → class i ≬ class j → i=j;
29    covers: big_union support ? ? (λx.class x) = full_set A
30  }. napply indexes; nqed.
31
32 naxiom daemon: False.
33
34 nlet rec partition_splits_card_map
35  A (P:partition A) n s (f:isomorphism ?? (Nat_ n) (indexes ? P))
36  (fi: ∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) m index
37  on index : A ≝
38  match ltb m (s index) with
39   [ or_introl _ ⇒ iso_f ???? (fi index) m
40   | or_intror _ ⇒
41      match index with
42       [ O ⇒ (* dummy value: it could be an elim False: *) iso_f ???? (fi O) O
43       | S index' ⇒
44          partition_splits_card_map A P n s f fi (minus m (s index)) index']].  
45
46 nlemma partition_splits_card:
47  ∀A. ∀P:partition A. ∀n,s.
48   ∀f:isomorphism ?? (Nat_ n) (indexes ? P).
49    (∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) →
50     (isomorphism ?? (Nat_ (big_plus n (λi.λ_.s i))) (Full_set A)).
51  #A; #P; #n; #s; #f; #fi; napply mk_isomorphism
52   [ napply mk_unary_morphism
53      [ napply (λm.partition_splits_card_map A P n s f fi m n)
54      | #a; #a'; #H; nrewrite < H; napply refl ]
55 ##| #y; #_;
56     ngeneralize in match (covers ? P) in ⊢ ?; *; #_; #Hc;
57     ngeneralize in match (Hc y I) in ⊢ ?; *; #index; *; #Hi1; #Hi2;
58     nelim daemon
59   | #x; #x'; nnormalize in ⊢ (? → ? → %);
60     nelim daemon
61   ]
62 nqed.
63
64 (************** equivalence relations vs partitions **********************)
65
66 ndefinition partition_of_compatible_equivalence_relation:
67  ∀A:setoid. compatible_equivalence_relation A → partition A.
68  #A; #R; napply mk_partition
69   [ napply (quotient ? R)
70   | napply Full_set
71   | #a; napply mk_qpowerclass
72      [ napply {x | R x a}
73      | #x; #x'; #H; nnormalize; napply mk_iff; #K; nelim daemon]
74 ##| #x; #_; nnormalize; napply (ex_intro … x); napply conj; napply refl
75   | #x; #x'; #_; #_; nnormalize; *; #x''; *; #H1; #H2; napply (trans ?????? H2);
76     napply sym; nassumption
77   | nnormalize; napply conj
78      [ #a; #_; napply I | #a; #_; napply (ex_intro … a); napply conj [ napply I | napply refl]##]
79 nqed.