1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "sets/sets.ma".
16 include "nat/plus.ma".
17 include "nat/compare.ma".
18 include "nat/minus.ma".
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 alias symbol "eq" = "setoid eq".
27 alias symbol "eq" = "setoid1 eq".
28 alias symbol "eq" = "setoid eq".
29 alias symbol "eq" = "setoid1 eq".
30 alias symbol "eq" = "setoid eq".
31 nrecord partition (A: setoid) : Type[1] ≝
33 indexes: qpowerclass support;
34 class: unary_morphism1 (setoid1_of_setoid support) (qpowerclass_setoid A);
35 inhabited: ∀i. i ∈ indexes → class i ≬ class i;
36 disjoint: ∀i,j. i ∈ indexes → j ∈ indexes → class i ≬ class j → i=j;
37 covers: big_union support ? ? (λx.class x) = full_set A
38 }. napply indexes; nqed.
42 nlet rec partition_splits_card_map
43 A (P:partition A) n s (f:isomorphism ?? (Nat_ n) (indexes ? P))
44 (fi: ∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) m index
46 match ltb m (s index) with
47 [ true ⇒ iso_f ???? (fi index) m
50 [ O ⇒ (* dummy value: it could be an elim False: *) iso_f ???? (fi O) O
52 partition_splits_card_map A P n s f fi (minus m (s index)) index']].
54 naxiom big_union_preserves_iso:
56 ∀g: isomorphism A' A T' T.
57 big_union A B T f = big_union A' B T' (λx.f (iso_f ???? g x)).
59 naxiom le_to_lt_or_eq: ∀n,m. n ≤ m → n < m ∨ n = m.
60 alias symbol "eq" = "leibnitz's equality".
61 naxiom minus_canc: ∀n. O = minus n n.
62 naxiom lt_to_ltb_t: ∀n,m. ∀P: bool → CProp[0]. P true → n < m → P (ltb n m).
63 naxiom lt_to_ltb_f: ∀n,m. ∀P: bool → CProp[0]. P false → ¬ (n < m) → P (ltb n m).
64 naxiom lt_to_minus: ∀n,m. n < m → S (minus (minus m n) (S O)) = minus m n.
65 naxiom not_lt_O: ∀n. ¬ (n < O).
66 naxiom minus_S: ∀n,m. m ≤ n → minus (S n) m = S (minus n m).
67 naxiom minus_lt_to_lt: ∀n,m,p. n < p → minus n m < p.
68 naxiom minus_O_n: ∀n. O = minus O n.
69 naxiom le_O_to_eq: ∀n. n ≤ O → n=O.
70 naxiom lt_to_minus_to_S: ∀n,m. m < n → ∃k. minus n m = S k.
71 naxiom ltb_t: ∀n,m. n < m → ltb n m = true.
72 naxiom ltb_f: ∀n,m. ¬ (n < m) → ltb n m = false.
73 naxiom plus_n_O: ∀n. plus n O = n.
74 naxiom not_lt_plus: ∀n,m. ¬ (plus n m < n).
75 naxiom lt_to_lt_plus: ∀n,m,l. n < m → n < m + l.
76 naxiom S_plus: ∀n,m. S (n + m) = n + S m.
77 naxiom big_plus_ext: ∀n,f,f'. (∀i,p. f i p = f' i p) → big_plus n f = big_plus n f'.
78 naxiom ad_hoc1: ∀n,m,l. n + (m + l) = l + (n + m).
79 naxiom assoc: ∀n,m,l. n + m + l = n + (m + l).
80 naxiom lt_canc: ∀n,m,p. n < m → p + n < p + m.
81 naxiom ad_hoc2: ∀a,b. a < b → b - a - (b - S a) = S O.
82 naxiom ad_hoc3: ∀a,b. b < a → S (O + (a - S b) + b) = a.
83 naxiom ad_hoc4: ∀a,b. a - S b ≤ a - b.
84 naxiom ad_hoc5: ∀a. S a - a = S O.
85 naxiom ad_hoc6: ∀a,b. b ≤ a → a - b + b = a.
86 naxiom ad_hoc7: ∀a,b,c. a + (b + O) + c - b = a + c.
87 naxiom ad_hoc8: ∀a,b,c. ¬ (a + (b + O) + c < b).
90 naxiom split_big_plus:
92 big_plus n f = big_plus m (λi,p.f i ?) + big_plus (n - m) (λi.λp.f (i + m) ?).
96 nlemma partition_splits_card:
97 ∀A. ∀P:partition A. ∀n,s.
98 ∀f:isomorphism ?? (Nat_ n) (indexes ? P).
99 (∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) →
100 (isomorphism ?? (Nat_ (big_plus n (λi.λ_.s i))) (Full_set A)).
101 #A; #P; #Sn; ncases Sn
103 ngeneralize in match (covers ? P) in ⊢ ?; *; #_; #H;
105 (big_union_preserves_iso ??? (indexes A P) (Nat_ O) (λx.class ? P x) f) in ⊢ ?;
106 *; #K; #_; nwhd in K: (? → ? → %);
107 nelim daemon (* impossibile *)
108 | #n; #s; #f; #fi; napply mk_isomorphism
109 [ napply mk_unary_morphism
110 [ napply (λm.partition_splits_card_map A P (S n) s f fi m n)
111 | #a; #a'; #H; nrewrite < H; napply refl ]
113 ngeneralize in match (covers ? P) in ⊢ ?; *; #_; #Hc;
114 ngeneralize in match (Hc y I) in ⊢ ?; *; #index; *; #Hi1; #Hi2;
115 ngeneralize in match (f_sur ???? f ? Hi1) in ⊢ ?; *; #nindex; *; #Hni1; #Hni2;
116 ngeneralize in match (f_sur ???? (fi nindex) y ?) in ⊢ ?
117 [##2: napply (. #‡(†?));##[##3: napply Hni2 |##2: ##skip | nassumption]##]
118 *; #nindex2; *; #Hni21; #Hni22;
119 nletin xxx ≝ (plus (big_plus (minus n nindex) (λi.λ_.s (S (plus i nindex)))) nindex2);
120 napply (ex_intro … xxx); napply conj
121 [ nwhd in Hni1; nwhd; nwhd in ⊢ (?(? %)%);
122 nchange with (? < plus (s n) (big_plus n ?));
123 nelim (le_to_lt_or_eq … (le_S_S_to_le … Hni1))
124 [##2: #E; nrewrite < E; nrewrite < (minus_canc nindex);
125 nwhd in ⊢ (?%?); nrewrite < E; napply lt_to_lt_plus; nassumption
126 | #L; nrewrite > (split_big_plus n (S nindex) (λm.λ_.s m) L);
127 nrewrite > (split_big_plus (n - nindex) (n - S nindex) (λi.λ_.s (S (i+nindex))) ?)
128 [ ngeneralize in match (big_plus_ext (n - S nindex)
129 (λi,p.s (S (i+nindex))) (λi,p.s (i + S nindex)) ?) in ⊢ ?
131 napply (eq_rect_CProp0_r ??
132 (λx:nat.λ_. x + big_plus (n - nindex - (n - S nindex))
133 (λi,p.s (S (i + (n - S nindex)+nindex))) + nindex2 <
134 s n + (big_plus (S nindex) (λi,p.s i) +
135 big_plus (n - S nindex) (λi,p. s (i + S nindex)))) ? ? E);
136 nrewrite > (ad_hoc1 (s n) (big_plus (S nindex) (λi,p.s i))
137 (big_plus (n - S nindex) (λi,p. s (i + S nindex))));
138 napply (eq_rect_CProp0_r
139 ?? (λx.λ_.x < ?) ?? (assoc
140 (big_plus (n - S nindex) (λi,p.s (i + S nindex)))
141 (big_plus (n - nindex - (n - S nindex))
142 (λi,p.s (S (i + (n - S nindex)+nindex))))
145 nrewrite > (ad_hoc2 … L); nwhd in ⊢ (?(?%?)?);
146 nrewrite > (ad_hoc3 … L);
147 napply (eq_rect_CProp0_r ?? (λx.λ_.x < ?) ?? (assoc …));
148 napply lt_canc; nnormalize in ⊢ (?%?); nwhd in ⊢ (??%);
149 napply lt_to_lt_plus; nassumption
150 ##|##2: #i; #_; nrewrite > (S_plus i nindex); napply refl]
151 ##| napply ad_hoc4]##]
152 ##| nwhd in ⊢ (???%?);
153 nchange in Hni1 with (nindex < S n);
154 ngeneralize in match (le_S_S_to_le … Hni1) in ⊢ ?;
155 nwhd in ⊢ (? → ???(???????%?)?);
156 napply (nat_rect_CProp0
158 eq_rel (carr A) (eq A)
159 (partition_splits_card_map A P (S n) s f fi
161 (big_plus (minus x nindex) (λi.λ_:i < minus x nindex.s (S (plus i nindex))))
163 [ #K; nrewrite < (minus_O_n nindex); nwhd in ⊢ (???(???????%?)?);
164 nwhd in ⊢ (???%?); nchange in Hni21 with (nindex2 < s nindex);
165 ngeneralize in match (le_O_to_eq … K) in ⊢ ?; #K';
166 ngeneralize in match Hni21 in ⊢ ?;
167 ngeneralize in match Hni22 in ⊢ ?;
168 nrewrite > K' in ⊢ (% → % → ?); #K1; #K2;
169 nrewrite > (ltb_t … K2);
170 nwhd in ⊢ (???%?); nassumption
171 | #n'; #Hrec; #HH; nelim (le_to_lt_or_eq … HH)
172 [##2: #K; nrewrite < K; nrewrite < (minus_canc nindex);
173 nwhd in ⊢ (???(???????%?)?);
175 nwhd in ⊢ (???%?); nrewrite < K; nrewrite > (ltb_t … Hni21);
176 nwhd in ⊢ (???%?); nassumption
177 ##| #K; ngeneralize in match (le_S_S_to_le … K) in ⊢ ?; #K';
179 ngeneralize in match (?:
180 ¬ (big_plus (S n' - nindex) (λi,p.s (S (i+nindex))) + nindex2 < s (S n'))) in ⊢ ?
181 [ #N; nrewrite > (ltb_f … N); nwhd in ⊢ (???%?);
182 ngeneralize in match (Hrec K') in ⊢ ?; #Hrec';
183 napply (eq_rect_CProp0_r ??
184 (λx,p. eq_rel (carr A) (eq A) (partition_splits_card_map A P (S n) s f fi
185 (big_plus x ? + ? - ?) n') y) ?? (minus_S n' nindex K'));
186 nrewrite > (split_big_plus (S (n' - nindex)) (n' - nindex)
187 (λi,p.s (S (i+nindex))) (le_S ?? (le_n ?)));
188 nrewrite > (ad_hoc5 (n' - nindex));
189 nnormalize in ⊢ (???(???????(?(?(??%)?)?)?)?);
190 nrewrite > (ad_hoc6 … K');
191 nrewrite > (ad_hoc7 (big_plus (n' - nindex) (λi,p.s (S (i+nindex))))
194 | nrewrite > (minus_S … K');
195 nrewrite > (split_big_plus (S (n' - nindex)) (n' - nindex)
196 (λi,p.s (S (i+nindex))) (le_S ?? (le_n ?)));
197 nrewrite > (ad_hoc5 (n' - nindex));
198 nnormalize in ⊢ (?(?(?(??%)?)?));
199 nrewrite > (ad_hoc6 … K');
200 napply ad_hoc8]##]##]##]
201 ##| #x; #x'; nnormalize in ⊢ (? → ? → %);
206 (************** equivalence relations vs partitions **********************)
208 ndefinition partition_of_compatible_equivalence_relation:
209 ∀A:setoid. compatible_equivalence_relation A → partition A.
210 #A; #R; napply mk_partition
211 [ napply (quotient ? R)
213 | napply mk_unary_morphism1
214 [ #a; napply mk_qpowerclass
216 | #x; #x'; #H; nnormalize; napply mk_iff; #K; nelim daemon]
217 ##| #a; #a'; #H; napply conj; #x; nnormalize; #K [ nelim daemon | nelim daemon]##]
218 ##| #x; #_; nnormalize; napply (ex_intro … x); napply conj; napply refl
219 | #x; #x'; #_; #_; nnormalize; *; #x''; *; #H1; #H2; napply (trans ?????? H2);
220 napply sym; nassumption
221 | nnormalize; napply conj
222 [ #a; #_; napply I | #a; #_; napply (ex_intro … a); napply conj [ napply I | napply refl]##]