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" = "setoid eq".
22 alias symbol "eq" = "setoid1 eq".
23 alias symbol "eq" = "setoid eq".
24 alias symbol "eq" = "setoid1 eq".
25 nrecord partition (A: setoid) : Type[1] ≝
27 indexes: ext_powerclass support;
28 class: unary_morphism1 (setoid1_of_setoid support) (ext_powerclass_setoid A);
29 inhabited: ∀i. i ∈ indexes → class i ≬ class i;
30 disjoint: ∀i,j. i ∈ indexes → j ∈ indexes → class i ≬ class j → i = j;
31 covers: big_union support ? indexes (λx.class x) = full_set A
36 nlet rec iso_nat_nat_union (s: nat → nat) m index on index : pair nat nat ≝
37 match ltb m (s index) with
38 [ true ⇒ mk_pair … index m
41 [ O ⇒ (* dummy value: it could be an elim False: *) mk_pair … O O
42 | S index' ⇒ iso_nat_nat_union s (minus m (s index)) index']].
44 alias symbol "eq" = "leibnitz's equality".
45 naxiom plus_n_O: ∀n. n + O = n.
46 naxiom plus_n_S: ∀n,m. n + S m = S (n + m).
47 naxiom ltb_t: ∀n,m. n < m → ltb n m = true.
48 naxiom ltb_f: ∀n,m. ¬ (n < m) → ltb n m = false.
49 naxiom ltb_cases: ∀n,m. (n < m ∧ ltb n m = true) ∨ (¬ (n < m) ∧ ltb n m = false).
50 naxiom minus_canc: ∀n. minus n n = O.
51 naxiom ad_hoc9: ∀a,b,c. a < b + c → a - b < c.
52 naxiom ad_hoc10: ∀a,b,c. a - b = c → a = b + c.
53 naxiom ad_hoc11: ∀a,b. a - b ≤ S a - b.
54 naxiom ad_hoc12: ∀a,b. b ≤ a → S a - b - (a - b) = S O.
55 naxiom ad_hoc13: ∀a,b. b ≤ a → (O + (a - b)) + b = a.
56 naxiom ad_hoc14: ∀a,b,c,d,e. c ≤ a → a - c = b + d + e → a = b + (c + d) + e.
57 naxiom ad_hoc15: ∀a,a',b,c. a=a' → b < c → a + b < c + a'.
58 naxiom ad_hoc16: ∀a,b,c. a < c → a < b + c.
59 naxiom not_lt_to_le: ∀a,b. ¬ (a < b) → b ≤ a.
60 naxiom le_to_le_S_S: ∀a,b. a ≤ b → S a ≤ S b.
61 naxiom minus_S: ∀n. S n - n = S O.
62 naxiom ad_hoc17: ∀a,b,c,d,d'. a+c+d=b+c+d' → a+d=b+d'.
63 naxiom split_big_plus:
65 big_plus n f = big_plus m (λi,p.f i ?) + big_plus (n - m) (λi.λp.f (i + m) ?).
68 naxiom big_plus_preserves_ext:
69 ∀n,f,f'. (∀i,p. f i p = f' i p) → big_plus n f = big_plus n f'.
71 ntheorem iso_nat_nat_union_char:
72 ∀n:nat. ∀s: nat → nat. ∀m:nat. m < big_plus (S n) (λi.λ_.s i) →
73 let p ≝ iso_nat_nat_union s m n in
74 m = big_plus (n - fst … p) (λi.λ_.s (S (i + fst … p))) + snd … p ∧
75 fst … p ≤ n ∧ snd … p < s (fst … p).
77 [ #m; nwhd in ⊢ (??% → let p ≝ % in ?); nwhd in ⊢ (??(??%) → ?);
78 nrewrite > (plus_n_O (s O)); #H; nrewrite > (ltb_t … H); nnormalize; @
79 [ @ [ napply refl | napply le_n ] ##| nassumption ]
80 ##| #n'; #Hrec; #m; nwhd in ⊢ (??% → let p ≝ % in ?); #H;
81 ncases (ltb_cases m (s (S n'))); *; #H1; #H2; nrewrite > H2;
82 nwhd in ⊢ (let p ≝ % in ?); nwhd
83 [ napply conj [napply conj
84 [ nwhd in ⊢ (????(?(?%(λ_.λ_:(??%).?))%)); nrewrite > (minus_canc n'); napply refl
85 | nnormalize; napply le_n]
86 ##| nnormalize; nassumption ]
87 ##| nchange in H with (m < s (S n') + big_plus (S n') (λi.λ_.s i));
88 nlapply (Hrec (m - s (S n')) ?)
89 [ napply ad_hoc9; nassumption] *; *; #Hrec1; #Hrec2; #Hrec3; @
92 [nrewrite > (split_big_plus …); ##[##2:napply ad_hoc11;##|##3:##skip]
93 nrewrite > (ad_hoc12 …); ##[##2: nassumption]
94 nwhd in ⊢ (????(?(??%)?));
95 nrewrite > (ad_hoc13 …);##[##2: nassumption]
96 napply ad_hoc14 [ napply not_lt_to_le; nassumption ]
97 nwhd in ⊢ (???(?(??%)?));
98 nrewrite > (plus_n_O …);
100 ##| napply le_S; nassumption ]##]##]##]
103 ntheorem iso_nat_nat_union_pre:
104 ∀n:nat. ∀s: nat → nat.
105 ∀i1,i2. i1 ≤ n → i2 < s i1 →
106 big_plus (n - i1) (λi.λ_.s (S (i + i1))) + i2 < big_plus (S n) (λi.λ_.s i).
107 #n; #s; #i1; #i2; #H1; #H2;
108 nrewrite > (split_big_plus (S n) (S i1) (λi.λ_.s i) ?)
109 [##2: napply le_to_le_S_S; nassumption]
111 [ nwhd in ⊢ (???(?%?));
112 napply big_plus_preserves_ext; #i; #_;
113 nrewrite > (plus_n_S i i1); napply refl
114 | nrewrite > (split_big_plus (S i1) i1 (λi.λ_.s i) ?) [##2: napply le_S; napply le_n]
115 napply ad_hoc16; nrewrite > (minus_S i1); nnormalize; nrewrite > (plus_n_O (s i1) …);
119 ntheorem iso_nat_nat_union_uniq:
120 ∀n:nat. ∀s: nat → nat.
121 ∀i1,i1',i2,i2'. i1 ≤ n → i1' ≤ n → i2 < s i1 → i2' < s i1' →
122 big_plus (n - i1) (λi.λ_.s (S (i + i1))) + i2 = big_plus (n - i1') (λi.λ_.s (S (i + i1'))) + i2' →
124 #n; #s; #i1; #i1'; #i2; #i2'; #H1; #H1'; #H2; #H2'; #E;
128 nlemma partition_splits_card:
129 ∀A. ∀P:partition A. ∀n,s.
130 ∀f:isomorphism ?? (Nat_ n) (indexes ? P).
131 (∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) →
132 (isomorphism ?? (Nat_ (big_plus n (λi.λ_.s i))) (Full_set A)).
133 #A; #P; #Sn; ncases Sn
135 nlapply (covers ? P); *; #_; #H;
138 (big_union_preserves_iso ??? (indexes A P) (Nat_ O) (λx.class ? P x) f);
139 *; #K; #_; nwhd in K: (? → ? → %);*)
140 nelim daemon (* impossibile *)
143 [ napply (λm.let p ≝ (iso_nat_nat_union s m n) in iso_f ???? (fi (fst … p)) (snd … p))
144 | #a; #a'; #H; nrewrite < H; napply refl ]
145 ##| #x; #Hx; nwhd; napply I
147 nlapply (covers ? P); *; #_; #Hc;
148 nlapply (Hc y I); *; #index; *; #Hi1; #Hi2;
149 nlapply (f_sur ???? f ? Hi1); *; #nindex; *; #Hni1; #Hni2;
150 nlapply (f_sur ???? (fi nindex) y ?)
151 [ alias symbol "refl" = "refl".
152 alias symbol "prop1" = "prop11".
153 alias symbol "prop2" = "prop21 mem".
154 napply (. #‡(†?));##[##2: napply Hni2 |##1: ##skip | nassumption]##]
155 *; #nindex2; *; #Hni21; #Hni22;
156 nletin xxx ≝ (plus (big_plus (minus n nindex) (λi.λ_.s (S (plus i nindex)))) nindex2);
158 [ napply iso_nat_nat_union_pre [ napply le_S_S_to_le; nassumption | nassumption ]
159 ##| nwhd in ⊢ (???%%); napply (.= ?) [##3: nassumption|##skip]
160 nlapply (iso_nat_nat_union_char n s xxx ?)
161 [napply iso_nat_nat_union_pre [ napply le_S_S_to_le; nassumption | nassumption]##]
164 (iso_nat_nat_union_uniq n s nindex (fst … (iso_nat_nat_union s xxx n))
165 nindex2 (snd … (iso_nat_nat_union s xxx n)) ?????)
166 [##6: *; #E1; #E2; nrewrite > E1; nrewrite > E2; napply refl
167 |##5: napply le_S_S_to_le; nassumption
168 |##*: nassumption]##]
169 ##| #x; #x'; nnormalize in ⊢ (? → ? → %); #Hx; #Hx'; #E;
170 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');
171 ##[ #i1; #i2; #i1'; #i2'; #Hi1; #Hi1'; #Hi2; #Hi2'; #E;
172 nlapply(disjoint … P (f i1) (f i1') ???)
173 [##2,3: napply f_closed; nassumption
174 |##1: @ (fi i1 i2); @;
175 ##[ napply f_closed; nassumption ##| alias symbol "refl" = "refl1".
177 nwhd; napply f_closed; nassumption]##]
178 #E'; ncut(i1 = i1'); ##[ napply (f_inj … E'); nassumption; ##]
179 #E''; nrewrite < E''; @;
181 ##| nrewrite < E'' in E; #E'''; napply (f_inj … E''')
182 [ nassumption | nrewrite > E''; nassumption ]##]##]
184 nelim (iso_nat_nat_union_char n s x Hx); *; #i1x; #i2x; #i3x;
185 nelim (iso_nat_nat_union_char n s x' Hx'); *; #i1x'; #i2x'; #i3x';
188 ##|##3,4:napply le_to_le_S_S; nassumption; ##]
190 napply (eq_rect_CProp0_r ?? (λX.λ_.? = X) ?? i1x');
191 napply (eq_rect_CProp0_r ?? (λX.λ_.X = ?) ?? i1x);
192 nrewrite > K1; nrewrite > K2; napply refl ]
195 (************** equivalence relations vs partitions **********************)
197 ndefinition partition_of_compatible_equivalence_relation:
198 ∀A:setoid. compatible_equivalence_relation A → partition A.
199 #A; #R; napply mk_partition
200 [ napply (quotient ? R)
202 | napply mk_unary_morphism1
203 [ #a; napply mk_ext_powerclass
205 | #x; #x'; #H; nnormalize; napply mk_iff; #K; nelim daemon]
206 ##| #a; #a'; #H; napply conj; #x; nnormalize; #K [ nelim daemon | nelim daemon]##]
207 ##| #x; #_; nnormalize; napply (ex_intro … x); napply conj; napply refl
208 | #x; #x'; #_; #_; nnormalize; *; #x''; *; #H1; #H2; napply (trans ?????? H2);
209 napply sym; nassumption
210 | nnormalize; napply conj
211 [ #a; #_; napply I | #a; #_; napply (ex_intro … a); napply conj [ napply I | napply refl]##]