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".
19 include "datatypes/pairs.ma".
21 alias symbol "eq" (instance 7) = "setoid1 eq".
22 nrecord partition (A: setoid) : Type[1] ≝
24 indexes: ext_powerclass support;
25 class: unary_morphism1 (setoid1_of_setoid support) (ext_powerclass_setoid A);
26 inhabited: ∀i. i ∈ indexes → class i ≬ class i;
27 disjoint: ∀i,j. i ∈ indexes → j ∈ indexes → class i ≬ class j → i = j;
28 covers: big_union support ? indexes (λx.class x) = full_set A
33 nlet rec iso_nat_nat_union (s: nat → nat) m index on index : pair nat nat ≝
34 match ltb m (s index) with
35 [ true ⇒ mk_pair … index m
38 [ O ⇒ (* dummy value: it could be an elim False: *) mk_pair … O O
39 | S index' ⇒ iso_nat_nat_union s (minus m (s index)) index']].
41 alias symbol "eq" = "leibnitz's equality".
42 naxiom plus_n_O: ∀n. n + O = n.
43 naxiom plus_n_S: ∀n,m. n + S m = S (n + m).
44 naxiom ltb_t: ∀n,m. n < m → ltb n m = true.
45 naxiom ltb_f: ∀n,m. ¬ (n < m) → ltb n m = false.
46 naxiom ltb_cases: ∀n,m. (n < m ∧ ltb n m = true) ∨ (¬ (n < m) ∧ ltb n m = false).
47 naxiom minus_canc: ∀n. minus n n = O.
48 naxiom ad_hoc9: ∀a,b,c. a < b + c → a - b < c.
49 naxiom ad_hoc10: ∀a,b,c. a - b = c → a = b + c.
50 naxiom ad_hoc11: ∀a,b. a - b ≤ S a - b.
51 naxiom ad_hoc12: ∀a,b. b ≤ a → S a - b - (a - b) = S O.
52 naxiom ad_hoc13: ∀a,b. b ≤ a → (O + (a - b)) + b = a.
53 naxiom ad_hoc14: ∀a,b,c,d,e. c ≤ a → a - c = b + d + e → a = b + (c + d) + e.
54 naxiom ad_hoc15: ∀a,a',b,c. a=a' → b < c → a + b < c + a'.
55 naxiom ad_hoc16: ∀a,b,c. a < c → a < b + c.
56 naxiom not_lt_to_le: ∀a,b. ¬ (a < b) → b ≤ a.
57 naxiom le_to_le_S_S: ∀a,b. a ≤ b → S a ≤ S b.
58 naxiom minus_S: ∀n. S n - n = S O.
59 naxiom ad_hoc17: ∀a,b,c,d,d'. a+c+d=b+c+d' → a+d=b+d'.
60 naxiom split_big_plus:
62 big_plus n f = big_plus m (λi,p.f i ?) + big_plus (n - m) (λi.λp.f (i + m) ?).
65 naxiom big_plus_preserves_ext:
66 ∀n,f,f'. (∀i,p. f i p = f' i p) → big_plus n f = big_plus n f'.
68 ntheorem iso_nat_nat_union_char:
69 ∀n:nat. ∀s: nat → nat. ∀m:nat. m < big_plus (S n) (λi.λ_.s i) →
70 let p ≝ iso_nat_nat_union s m n in
71 m = big_plus (n - fst … p) (λi.λ_.s (S (i + fst … p))) + snd … p ∧
72 fst … p ≤ n ∧ snd … p < s (fst … p).
74 [ #m; nwhd in ⊢ (??% → let p ≝ % in ?); nwhd in ⊢ (??(??%) → ?);
75 nrewrite > (plus_n_O (s O)); #H; nrewrite > (ltb_t … H); nnormalize; @; /2/
76 ##| #n'; #Hrec; #m; nwhd in ⊢ (??% → let p ≝ % in ?); #H;
77 ncases (ltb_cases m (s (S n'))); *; #H1; #H2; nrewrite > H2;
78 nwhd in ⊢ (let p ≝ % in ?); nwhd
79 [ napply conj [napply conj; //;
80 nwhd in ⊢ (???(?(?%(λ_.λ_:(??%).?))%)); nrewrite > (minus_canc n'); //
82 ##| nchange in H with (m < s (S n') + big_plus (S n') (λi.λ_.s i));
83 nlapply (Hrec (m - s (S n')) ?); /2/; *; *; #Hrec1; #Hrec2; #Hrec3; @; //; @; /2/;
84 nrewrite > (split_big_plus …); ##[##2:napply ad_hoc11;##|##3:##skip]
85 nrewrite > (ad_hoc12 …); //;
86 nwhd in ⊢ (???(?(??%)?));
87 nrewrite > (ad_hoc13 …); //;
89 nwhd in ⊢ (???(?(??%)?));
90 nrewrite > (plus_n_O …); // ##]##]
93 ntheorem iso_nat_nat_union_pre:
94 ∀n:nat. ∀s: nat → nat.
95 ∀i1,i2. i1 ≤ n → i2 < s i1 →
96 big_plus (n - i1) (λi.λ_.s (S (i + i1))) + i2 < big_plus (S n) (λi.λ_.s i).
99 ntheorem iso_nat_nat_union_uniq:
100 ∀n:nat. ∀s: nat → nat.
101 ∀i1,i1',i2,i2'. i1 ≤ n → i1' ≤ n → i2 < s i1 → i2' < s i1' →
102 big_plus (n - i1) (λi.λ_.s (S (i + i1))) + i2 = big_plus (n - i1') (λi.λ_.s (S (i + i1'))) + i2' →
104 #n; #s; #i1; #i1'; #i2; #i2'; #H1; #H1'; #H2; #H2'; #E;
108 nlemma partition_splits_card:
109 ∀A. ∀P:partition A. ∀n,s.
110 ∀f:isomorphism ?? (Nat_ n) (indexes ? P).
111 (∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) →
112 (isomorphism ?? (Nat_ (big_plus n (λi.λ_.s i))) (Full_set A)).
113 #A; #P; #Sn; ncases Sn
115 nlapply (covers ? P); *; #_; #H;
118 (big_union_preserves_iso ??? (indexes A P) (Nat_ O) (λx.class ? P x) f);
119 *; #K; #_; nwhd in K: (? → ? → %);*)
120 nelim daemon (* impossibile *)
123 [ napply (λm.let p ≝ (iso_nat_nat_union s m n) in iso_f ???? (fi (fst … p)) (snd … p))
124 | #a; #a'; #H; nrewrite < H; napply refl ]
125 ##| #x; #Hx; nwhd; napply I
127 nlapply (covers ? P); *; #_; #Hc;
128 nlapply (Hc y I); *; #index; *; #Hi1; #Hi2;
129 nlapply (f_sur ???? f ? Hi1); *; #nindex; *; #Hni1; #Hni2;
130 nlapply (f_sur ???? (fi nindex) y ?)
131 [ alias symbol "refl" (instance 3) = "refl".
132 alias symbol "prop2" (instance 2) = "prop21".
133 alias symbol "prop1" (instance 4) = "prop11".
134 napply (. #‡(†?));##[##2: napply Hni2 |##1: ##skip | nassumption]##]
135 *; #nindex2; *; #Hni21; #Hni22;
136 nletin xxx ≝ (plus (big_plus (minus n nindex) (λi.λ_.s (S (plus i nindex)))) nindex2);
138 [ napply iso_nat_nat_union_pre [ napply le_S_S_to_le; nassumption | nassumption ]
139 ##| nwhd in ⊢ (???%%); napply (.= ?) [##3: nassumption|##skip]
140 nlapply (iso_nat_nat_union_char n s xxx ?)
141 [napply iso_nat_nat_union_pre [ napply le_S_S_to_le; nassumption | nassumption]##]
144 (iso_nat_nat_union_uniq n s nindex (fst … (iso_nat_nat_union s xxx n))
145 nindex2 (snd … (iso_nat_nat_union s xxx n)) ?????); /2/
146 [##2: *; #E1; #E2; nrewrite > E1; nrewrite > E2; //
148 ##| #x; #x'; nnormalize in ⊢ (? → ? → %); #Hx; #Hx'; #E;
149 ncut(∀i1,i2,i1',i2'. i1 ∈ Nat_ (S n) → i1' ∈ Nat_ (S n) → i2 ∈ Nat_ (s i1) → i2' ∈ Nat_ (s i1') → eq_rel (carr A) (eq A) (fi i1 i2) (fi i1' i2') → i1=i1' ∧ i2=i2');
150 ##[ #i1; #i2; #i1'; #i2'; #Hi1; #Hi1'; #Hi2; #Hi2'; #E;
151 nlapply(disjoint … P (f i1) (f i1') ???)
152 [##2,3: napply f_closed; //
153 |##1: @ (fi i1 i2); @;
154 ##[ napply f_closed; // ##| alias symbol "refl" = "refl1".
156 nwhd; napply f_closed; //]##]
157 #E'; ncut(i1 = i1'); ##[ napply (f_inj … E'); // ##]
158 #E''; nrewrite < E''; @; //;
159 nrewrite < E'' in E; #E'''; napply (f_inj … E'''); //;
160 nrewrite > E''; // ]##]
162 nelim (iso_nat_nat_union_char n s x Hx); *; #i1x; #i2x; #i3x;
163 nelim (iso_nat_nat_union_char n s x' Hx'); *; #i1x'; #i2x'; #i3x';
166 ##|##3,4:napply le_to_le_S_S; nassumption; ##]
168 napply (eq_rect_CProp0_r ?? (λX.λ_.? = X) ?? i1x');
169 napply (eq_rect_CProp0_r ?? (λX.λ_.X = ?) ?? i1x);
170 nrewrite > K1; nrewrite > K2; napply refl.
173 (************** equivalence relations vs partitions **********************)
175 ndefinition partition_of_compatible_equivalence_relation:
176 ∀A:setoid. compatible_equivalence_relation A → partition A.
177 #A; #R; napply mk_partition
178 [ napply (quotient ? R)
180 | napply mk_unary_morphism1
181 [ #a; napply mk_ext_powerclass
183 | #x; #x'; #H; nnormalize; napply mk_iff; #K; nelim daemon]
184 ##| #a; #a'; #H; napply conj; #x; nnormalize; #K [ nelim daemon | nelim daemon]##]
185 ##| #x; #_; nnormalize; /3/
186 | #x; #x'; #_; #_; nnormalize; *; #x''; *; /3/
187 | nnormalize; napply conj; /4/ ]