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