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