]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/sets/partitions.ma
93172d6174c206dc3a4abb4012c25e97db32e990
[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 alias symbol "eq" = "setoid1 eq".
24 nrecord partition (A: setoid) : Type[1] ≝ 
25  { support: setoid;
26    indexes: qpowerclass support;
27    class: unary_morphism1 (setoid1_of_setoid support) (qpowerclass_setoid A);
28    inhabited: ∀i. i ∈ indexes → class i ≬ class i;
29    disjoint: ∀i,j. i ∈ indexes → j ∈ indexes → class i ≬ class j → i=j;
30    covers: big_union support ? ? (λx.class x) = full_set A
31  }. napply indexes; nqed.
32
33 naxiom daemon: False.
34
35 nlet rec partition_splits_card_map
36  A (P:partition A) n s (f:isomorphism ?? (Nat_ n) (indexes ? P))
37  (fi: ∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) m index
38  on index : A ≝
39  match ltb m (s index) with
40   [ or_introl _ ⇒ iso_f ???? (fi index) m
41   | or_intror _ ⇒
42      match index with
43       [ O ⇒ (* dummy value: it could be an elim False: *) iso_f ???? (fi O) O
44       | S index' ⇒
45          partition_splits_card_map A P n s f fi (minus m (s index)) index']].  
46
47 naxiom big_union_preserves_iso:
48  ∀A,A',B,T,T',f.
49   ∀g: isomorphism A' A T' T.
50    big_union A B T f = big_union A' B T' (λx.f (iso_f ???? g x)).
51
52 nlemma partition_splits_card:
53  ∀A. ∀P:partition A. ∀n,s.
54   ∀f:isomorphism ?? (Nat_ n) (indexes ? P).
55    (∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) →
56     (isomorphism ?? (Nat_ (big_plus n (λi.λ_.s i))) (Full_set A)).
57  #A; #P; #Sn; ncases Sn
58   [ #s; #f; #fi;
59     ngeneralize in match (covers ? P) in ⊢ ?; *; #_; #H;
60     ngeneralize in match
61      (big_union_preserves_iso ??? (indexes A P) (Nat_ O) (λx.class ? P x) f) in ⊢ ?;
62      *; #K; #_; nwhd in K: (? → ? → %);
63     nelim daemon (* impossibile *)
64   | #n; #s; #f; #fi; napply mk_isomorphism
65   [ napply mk_unary_morphism
66      [ napply (λm.partition_splits_card_map A P (S n) s f fi m n)
67      | #a; #a'; #H; nrewrite < H; napply refl ]
68 ##| #y; #_;
69     ngeneralize in match (covers ? P) in ⊢ ?; *; #_; #Hc;
70     ngeneralize in match (Hc y I) in ⊢ ?; *; #index; *; #Hi1; #Hi2;
71     ngeneralize in match (f_sur ???? f ? Hi1) in ⊢ ?; *; #nindex; *; #Hni1; #Hni2;
72     ngeneralize in match (f_sur ???? (fi nindex) y ?) in ⊢ ?
73      [##2: napply (. #‡(†?));##[##3: napply Hni2 |##2: ##skip | nassumption]##]
74     *; #nindex2; *; #Hni21; #Hni22;
75     nletin xxx ≝ (plus match nindex return λ_.nat with [ O ⇒ O | S nn ⇒ big_plus nn (λi.λ_.s i)] nindex2);
76     napply (ex_intro … xxx); napply conj
77      [ nwhd in Hni1; nelim daemon
78      | nwhd in ⊢ (???%?);
79        (* BEL POSTO DOVE FARE UN LEMMA *)
80        (* invariante: Hni1; altre premesse: Hni1, Hni22 *)
81        nchange in Hni1 with (nindex < S n); ngeneralize in match Hni1 in ⊢ ?;
82        nelim n in ⊢ (% → ??? (????????%) ?)
83         [ #A (* decompose *)
84         | #index'; #Hrec; #K; nwhd in ⊢ (???%?);
85           nelim (ltb xxx (s (S index')));
86           #K1; nwhd in ⊢ (???%?)
87            [
88            
89            nindex < S index' + 1
90            +^{nindex} (s i) w < s (S index') 
91            S index' == nindex
92            
93            |
94            ]
95         ]
96      ]
97   | #x; #x'; nnormalize in ⊢ (? → ? → %);
98     nelim daemon
99   ]
100 nqed.
101
102 (************** equivalence relations vs partitions **********************)
103
104 ndefinition partition_of_compatible_equivalence_relation:
105  ∀A:setoid. compatible_equivalence_relation A → partition A.
106  #A; #R; napply mk_partition
107   [ napply (quotient ? R)
108   | napply Full_set
109   | #a; napply mk_qpowerclass
110      [ napply {x | R x a}
111      | #x; #x'; #H; nnormalize; napply mk_iff; #K; nelim daemon]
112 ##| #x; #_; nnormalize; napply (ex_intro … x); napply conj; napply refl
113   | #x; #x'; #_; #_; nnormalize; *; #x''; *; #H1; #H2; napply (trans ?????? H2);
114     napply sym; nassumption
115   | nnormalize; napply conj
116      [ #a; #_; napply I | #a; #_; napply (ex_intro … a); napply conj [ napply I | napply refl]##]
117 nqed.