]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/sets/partitions.ma
f1f64f8812d7ef427376482856e8fc88795f47da
[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 nlemma partition_splits_card:
48  ∀A. ∀P:partition A. ∀n,s.
49   ∀f:isomorphism ?? (Nat_ n) (indexes ? P).
50    (∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) →
51     (isomorphism ?? (Nat_ (big_plus n (λi.λ_.s i))) (Full_set A)).
52  #A; #P; #n; #s; #f; #fi; napply mk_isomorphism
53   [ napply mk_unary_morphism
54      [ napply (λm.partition_splits_card_map A P n s f fi m n)
55      | #a; #a'; #H; nrewrite < H; napply refl ]
56 ##| #y; #_;
57     ngeneralize in match (covers ? P) in ⊢ ?; *; #_; #Hc;
58     ngeneralize in match (Hc y I) in ⊢ ?; *; #index; *; #Hi1; #Hi2;
59     ngeneralize in match (f_sur ???? f ? Hi1) in ⊢ ?; *; #nindex; *; #Hni1; #Hni2;
60     ngeneralize in match (f_sur ???? (fi nindex) y ?) in ⊢ ?
61      [##2: napply (. #‡(†?));##[##3: napply Hni2 |##2: ##skip | nassumption]##]
62     *; #nindex2; *; #Hni21; #Hni22;
63     napply (ex_intro … (plus (big_plus nindex (λi.λ_.s i)) nindex2)); napply conj
64      [ nwhd in Hni1; nelim daemon
65      | nwhd in ⊢ (???%?);
66        (* BEL POSTO DOVE FARE UN LEMMA *)
67        (* invariante: Hni1; altre premesse: Hni1, Hni22 *)
68        nchange in Hni1 with (nindex < n); ngeneralize in match Hni1 in ⊢ ?;
69        nelim n
70         [ #A (* decompose *)
71         | #index'; #Hrec; 
72         ]
73      ]
74   | #x; #x'; nnormalize in ⊢ (? → ? → %);
75     nelim daemon
76   ]
77 nqed.
78
79 (************** equivalence relations vs partitions **********************)
80
81 ndefinition partition_of_compatible_equivalence_relation:
82  ∀A:setoid. compatible_equivalence_relation A → partition A.
83  #A; #R; napply mk_partition
84   [ napply (quotient ? R)
85   | napply Full_set
86   | #a; napply mk_qpowerclass
87      [ napply {x | R x a}
88      | #x; #x'; #H; nnormalize; napply mk_iff; #K; nelim daemon]
89 ##| #x; #_; nnormalize; napply (ex_intro … x); napply conj; napply refl
90   | #x; #x'; #_; #_; nnormalize; *; #x''; *; #H1; #H2; napply (trans ?????? H2);
91     napply sym; nassumption
92   | nnormalize; napply conj
93      [ #a; #_; napply I | #a; #_; napply (ex_intro … a); napply conj [ napply I | napply refl]##]
94 nqed.