From: Claudio Sacerdoti Coen Date: Mon, 24 Aug 2009 09:08:59 +0000 (+0000) Subject: Nicer proof "finished" (up to arithmetical facts). X-Git-Tag: make_still_working~3523 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=56b3e8606a00dbe15266bb36d832174103202366;p=helm.git Nicer proof "finished" (up to arithmetical facts). --- diff --git a/helm/software/matita/nlibrary/sets/partitions.ma b/helm/software/matita/nlibrary/sets/partitions.ma index d87ccd3a9..c5771028d 100644 --- a/helm/software/matita/nlibrary/sets/partitions.ma +++ b/helm/software/matita/nlibrary/sets/partitions.ma @@ -31,6 +31,8 @@ alias symbol "eq" = "setoid1 eq". alias symbol "eq" = "setoid eq". alias symbol "eq" = "setoid1 eq". alias symbol "eq" = "setoid eq". +alias symbol "eq" = "setoid1 eq". +alias symbol "eq" = "setoid eq". nrecord partition (A: setoid) : Type[1] ≝ { support: setoid; indexes: qpowerclass support; @@ -51,7 +53,8 @@ nlet rec iso_nat_nat_union (s: nat → nat) m index on index : pair nat nat ≝ | S index' ⇒ iso_nat_nat_union s (minus m (s index)) index']]. alias symbol "eq" = "leibnitz's equality". -naxiom plus_n_O: ∀n. plus n O = n. +naxiom plus_n_O: ∀n. n + O = n. +naxiom plus_n_S: ∀n,m. n + S m = S (n + m). naxiom ltb_t: ∀n,m. n < m → ltb n m = true. naxiom ltb_f: ∀n,m. ¬ (n < m) → ltb n m = false. naxiom ltb_cases: ∀n,m. (n < m ∧ ltb n m = true) ∨ (¬ (n < m) ∧ ltb n m = false). @@ -62,12 +65,20 @@ naxiom ad_hoc11: ∀a,b. a - b ≤ S a - b. naxiom ad_hoc12: ∀a,b. b ≤ a → S a - b - (a - b) = S O. naxiom ad_hoc13: ∀a,b. b ≤ a → (O + (a - b)) + b = a. naxiom ad_hoc14: ∀a,b,c,d,e. c ≤ a → a - c = b + d + e → a = b + (c + d) + e. +naxiom ad_hoc15: ∀a,a',b,c. a=a' → b < c → a + b < c + a'. +naxiom ad_hoc16: ∀a,b,c. a < c → a < b + c. naxiom not_lt_to_le: ∀a,b. ¬ (a < b) → b ≤ a. +naxiom le_to_le_S_S: ∀a,b. a ≤ b → S a ≤ S b. +naxiom minus_S_S: ∀a,b. S a - S b = a - b. +naxiom minus_S: ∀n. S n - n = S O. +naxiom ad_hoc17: ∀a,b,c,d,d'. a+c+d=b+c+d' → a+d=b+d'. naxiom split_big_plus: ∀n,m,f. m ≤ n → big_plus n f = big_plus m (λi,p.f i ?) + big_plus (n - m) (λi.λp.f (i + m) ?). nelim daemon. nqed. +naxiom big_plus_preserves_ext: + ∀n,f,f'. (∀i,p. f i p = f' i p) → big_plus n f = big_plus n f'. ntheorem iso_nat_nat_union_char: ∀n:nat. ∀s: nat → nat. ∀m:nat. m < big_plus (S n) (λi.λ_.s i) → @@ -111,67 +122,28 @@ ntheorem iso_nat_nat_union_char: | napply le_S; nassumption ]##]##]##] nqed. - -nlet rec partition_splits_card_map - A (P:partition A) n s (f:isomorphism ?? (Nat_ n) (indexes ? P)) - (fi: ∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i))) m index - on index : A ≝ - match ltb m (s index) with - [ true ⇒ iso_f ???? (fi index) m - | false ⇒ - match index with - [ O ⇒ (* dummy value: it could be an elim False: *) iso_f ???? (fi O) O - | S index' ⇒ - partition_splits_card_map A P n s f fi (minus m (s index)) index']]. - -naxiom big_union_preserves_iso: - ∀A,A',B,T,T',f. - ∀g: isomorphism A' A T' T. - big_union A B T f = big_union A' B T' (λx.f (iso_f ???? g x)). - -naxiom le_to_lt_or_eq: ∀n,m. n ≤ m → n < m ∨ n = m. -alias symbol "eq" = "leibnitz's equality". -naxiom lt_to_ltb_t: ∀n,m. ∀P: bool → CProp[0]. P true → n < m → P (ltb n m). -naxiom lt_to_ltb_f: ∀n,m. ∀P: bool → CProp[0]. P false → ¬ (n < m) → P (ltb n m). -naxiom lt_to_minus: ∀n,m. n < m → S (minus (minus m n) (S O)) = minus m n. -naxiom not_lt_O: ∀n. ¬ (n < O). -naxiom minus_S: ∀n,m. m ≤ n → minus (S n) m = S (minus n m). -naxiom minus_lt_to_lt: ∀n,m,p. n < p → minus n m < p. -naxiom minus_O_n: ∀n. O = minus O n. -naxiom le_O_to_eq: ∀n. n ≤ O → n=O. -naxiom lt_to_minus_to_S: ∀n,m. m < n → ∃k. minus n m = S k. -naxiom not_lt_plus: ∀n,m. ¬ (plus n m < n). -naxiom lt_to_lt_plus: ∀n,m,l. n < m → n < m + l. -naxiom S_plus: ∀n,m. S (n + m) = n + S m. -naxiom big_plus_ext: ∀n,f,f'. (∀i,p. f i p = f' i p) → big_plus n f = big_plus n f'. -naxiom ad_hoc1: ∀n,m,l. n + (m + l) = l + (n + m). -naxiom assoc: ∀n,m,l. n + m + l = n + (m + l). -naxiom lt_canc: ∀n,m,p. n < m → p + n < p + m. -naxiom ad_hoc2: ∀a,b. a < b → b - a - (b - S a) = S O. -naxiom ad_hoc3: ∀a,b. b < a → S (O + (a - S b) + b) = a. -naxiom ad_hoc4: ∀a,b. a - S b ≤ a - b. -naxiom ad_hoc5: ∀a. S a - a = S O. -naxiom ad_hoc6: ∀a,b. b ≤ a → a - b + b = a. -naxiom ad_hoc7: ∀a,b,c. a + (b + O) + c - b = a + c. -naxiom ad_hoc8: ∀a,b,c. ¬ (a + (b + O) + c < b). -naxiom ltb_elim_CProp0: ∀n,m. ∀P: bool → CProp[0]. (n < m → P true) → (¬ (n < m) → P false) → P (ltb n m). - -nlemma partition_splits_card_output: - ∀A. ∀P:partition A. ∀n,s. - ∀f:isomorphism ?? (Nat_ (S n)) (indexes ? P). - ∀fi:∀i. isomorphism ?? (Nat_ (s i)) (class ? P (iso_f ???? f i)). - ∀x. x ∈ Nat_ (big_plus (S n) (λi.λ_.s i)) → - ∃i1.∃i2. partition_splits_card_map A P (S n) s f fi x n = iso_f ???? (fi i1) i2. - #A; #P; #n; #s; #f; #fi; - nelim n in ⊢ (? → % → ??(λ_.??(λ_.???(????????%)?))) - [ #x; nnormalize in ⊢ (% → ?); nrewrite > (plus_n_O (s O)); nchange in ⊢ (% → ?) with (x < s O); - #H; napply (ex_intro … O); napply (ex_intro … x); nwhd in ⊢ (???%?); - nrewrite > (ltb_t … H); nwhd in ⊢ (???%?); napply refl - | #n'; #Hrec; #x; #Hx; nwhd in ⊢ (??(λ_.??(λ_.???%?))); nwhd in Hx; nwhd in Hx: (??%); - nelim (ltb_cases x (s (S n'))); *; #K1; #K2; nrewrite > K2; nwhd in ⊢ (??(λ_.??(λ_.???%?))) - [ napply (ex_intro … (S n')); napply (ex_intro … x); napply refl - | napply (Hrec (x - s (S n')) ?); nwhd; nrewrite < (minus_S x (s (S n')) ?) - [ napply ad_hoc9; nassumption | napply not_lt_to_le; nassumption ]##] +ntheorem iso_nat_nat_union_pre: + ∀n:nat. ∀s: nat → nat. + ∀i1,i2. i1 ≤ n → i2 < s i1 → + big_plus (n - i1) (λi.λ_.s (S (i + i1))) + i2 < big_plus (S n) (λi.λ_.s i). + #n; #s; #i1; #i2; #H1; #H2; + nrewrite > (split_big_plus (S n) (S i1) (λi.λ_.s i) ?) + [##2: napply le_to_le_S_S; nassumption] + napply ad_hoc15 + [ nrewrite > (minus_S_S n i1 …); napply big_plus_preserves_ext; #i; #_; + nrewrite > (plus_n_S i i1); napply refl + | nrewrite > (split_big_plus (S i1) i1 (λi.λ_.s i) ?) [##2: napply le_S; napply le_n] + napply ad_hoc16; nrewrite > (minus_S i1); nnormalize; nrewrite > (plus_n_O (s i1) …); + nassumption ] +nqed. + +ntheorem iso_nat_nat_union_uniq: + ∀n:nat. ∀s: nat → nat. + ∀i1,i1',i2,i2'. i1 ≤ n → i1' ≤ n → i2 < s i1 → i2' < s i1' → + big_plus (n - i1) (λi.λ_.s (S (i + i1))) + i2 = big_plus (n - i1') (λi.λ_.s (S (i + i1'))) + i2' → + i1 = i1' ∧ i2 = i2'. + #n; #s; #i1; #i1'; #i2; #i2'; #H1; #H1'; #H2; #H2'; #E; + nelim daemon. nqed. nlemma partition_splits_card: @@ -182,14 +154,16 @@ nlemma partition_splits_card: #A; #P; #Sn; ncases Sn [ #s; #f; #fi; ngeneralize in match (covers ? P) in ⊢ ?; *; #_; #H; + (* ngeneralize in match (big_union_preserves_iso ??? (indexes A P) (Nat_ O) (λx.class ? P x) f) in ⊢ ?; - *; #K; #_; nwhd in K: (? → ? → %); + *; #K; #_; nwhd in K: (? → ? → %);*) nelim daemon (* impossibile *) | #n; #s; #f; #fi; napply mk_isomorphism [ napply mk_unary_morphism - [ napply (λm.partition_splits_card_map A P (S n) s f fi m n) + [ napply (λm.let p ≝ iso_nat_nat_union s m n in iso_f ???? (fi (fst … p)) (snd … p)) | #a; #a'; #H; nrewrite < H; napply refl ] +##| #x; #Hx; nwhd; napply I ##| #y; #_; ngeneralize in match (covers ? P) in ⊢ ?; *; #_; #Hc; ngeneralize in match (Hc y I) in ⊢ ?; *; #index; *; #Hi1; #Hi2; @@ -199,102 +173,40 @@ nlemma partition_splits_card: *; #nindex2; *; #Hni21; #Hni22; nletin xxx ≝ (plus (big_plus (minus n nindex) (λi.λ_.s (S (plus i nindex)))) nindex2); napply (ex_intro … xxx); napply conj - [ nwhd in Hni1; nwhd; nwhd in ⊢ (?(? %)%); - nchange with (? < plus (s n) (big_plus n ?)); - nelim (le_to_lt_or_eq … (le_S_S_to_le … Hni1)) - [##2: #E; nrewrite < E; nrewrite < (minus_canc nindex); - nwhd in ⊢ (?%?); nrewrite < E; napply lt_to_lt_plus; nassumption - | #L; nrewrite > (split_big_plus n (S nindex) (λm.λ_.s m) L); - nrewrite > (split_big_plus (n - nindex) (n - S nindex) (λi.λ_.s (S (i+nindex))) ?) - [ ngeneralize in match (big_plus_ext (n - S nindex) - (λi,p.s (S (i+nindex))) (λi,p.s (i + S nindex)) ?) in ⊢ ? - [ #E; - napply (eq_rect_CProp0_r ?? - (λx:nat.λ_. x + big_plus (n - nindex - (n - S nindex)) - (λi,p.s (S (i + (n - S nindex)+nindex))) + nindex2 < - s n + (big_plus (S nindex) (λi,p.s i) + - big_plus (n - S nindex) (λi,p. s (i + S nindex)))) ? ? E); - nrewrite > (ad_hoc1 (s n) (big_plus (S nindex) (λi,p.s i)) - (big_plus (n - S nindex) (λi,p. s (i + S nindex)))); - napply (eq_rect_CProp0_r - ?? (λx.λ_.x < ?) ?? (assoc - (big_plus (n - S nindex) (λi,p.s (i + S nindex))) - (big_plus (n - nindex - (n - S nindex)) - (λi,p.s (S (i + (n - S nindex)+nindex)))) - nindex2)); - napply lt_canc; - nrewrite > (ad_hoc2 … L); nwhd in ⊢ (?(?%?)?); - nrewrite > (ad_hoc3 … L); - napply (eq_rect_CProp0_r ?? (λx.λ_.x < ?) ?? (assoc …)); - napply lt_canc; nnormalize in ⊢ (?%?); nwhd in ⊢ (??%); - napply lt_to_lt_plus; nassumption - ##|##2: #i; #_; nrewrite > (S_plus i nindex); napply refl] - ##| napply ad_hoc4]##] - ##| nwhd in ⊢ (???%?); - nchange in Hni1 with (nindex < S n); - ngeneralize in match (le_S_S_to_le … Hni1) in ⊢ ?; - nwhd in ⊢ (? → ???(???????%?)?); - napply (nat_rect_CProp0 - (λx. nindex ≤ x → - eq_rel (carr A) (eq A) - (partition_splits_card_map A P (S n) s f fi - (plus - (big_plus (minus x nindex) (λi.λ_:i < minus x nindex.s (S (plus i nindex)))) - nindex2) x) y) ?? n) - [ #K; nrewrite < (minus_O_n nindex); nwhd in ⊢ (???(???????%?)?); - nwhd in ⊢ (???%?); nchange in Hni21 with (nindex2 < s nindex); - ngeneralize in match (le_O_to_eq … K) in ⊢ ?; #K'; - ngeneralize in match Hni21 in ⊢ ?; - ngeneralize in match Hni22 in ⊢ ?; - nrewrite > K' in ⊢ (% → % → ?); #K1; #K2; - nrewrite > (ltb_t … K2); - nwhd in ⊢ (???%?); nassumption - | #n'; #Hrec; #HH; nelim (le_to_lt_or_eq … HH) - [##2: #K; nrewrite < K; nrewrite < (minus_canc nindex); - nwhd in ⊢ (???(???????%?)?); - nrewrite > K; - nwhd in ⊢ (???%?); nrewrite < K; nrewrite > (ltb_t … Hni21); - nwhd in ⊢ (???%?); nassumption - ##| #K; ngeneralize in match (le_S_S_to_le … K) in ⊢ ?; #K'; - nwhd in ⊢ (???%?); - ngeneralize in match (?: - ¬ (big_plus (S n' - nindex) (λi,p.s (S (i+nindex))) + nindex2 < s (S n'))) in ⊢ ? - [ #N; nrewrite > (ltb_f … N); nwhd in ⊢ (???%?); - ngeneralize in match (Hrec K') in ⊢ ?; #Hrec'; - napply (eq_rect_CProp0_r ?? - (λx,p. eq_rel (carr A) (eq A) (partition_splits_card_map A P (S n) s f fi - (big_plus x ? + ? - ?) n') y) ?? (minus_S n' nindex K')); - nrewrite > (split_big_plus (S (n' - nindex)) (n' - nindex) - (λi,p.s (S (i+nindex))) (le_S ?? (le_n ?))); - nrewrite > (ad_hoc5 (n' - nindex)); - nnormalize in ⊢ (???(???????(?(?(??%)?)?)?)?); - nrewrite > (ad_hoc6 … K'); - nrewrite > (ad_hoc7 (big_plus (n' - nindex) (λi,p.s (S (i+nindex)))) - (s (S n')) nindex2); - nassumption - | nrewrite > (minus_S … K'); - nrewrite > (split_big_plus (S (n' - nindex)) (n' - nindex) - (λi,p.s (S (i+nindex))) (le_S ?? (le_n ?))); - nrewrite > (ad_hoc5 (n' - nindex)); - nnormalize in ⊢ (?(?(?(??%)?)?)); - nrewrite > (ad_hoc6 … K'); - napply ad_hoc8]##]##]##] -##| #x; #x'; nnormalize in ⊢ (? → ? → %); #Hx; #Hx'; - nelim (partition_splits_card_output A P n s f fi x Hx); #i1x; *; #i2x; #Ex; - nelim (partition_splits_card_output A P n s f fi x' Hx'); #i1x'; *; #i2x'; #Ex'; - ngeneralize in match (? : - iso_f ???? fi i1x(* ≬ iso_f ???? (fi i1x'))*)) in ⊢ ?; - #E; napply (f_inj ???? (fi i1x)); - - nelim n in ⊢ (% → % → (???(????????%)(????????%)) → ?) - [ nnormalize in ⊢ (% → % → ?); nrewrite > (plus_n_O (s O)); - nchange in ⊢ (% → ?) with (x < s O); - nchange in ⊢ (? → % → ?) with (x' < s O); - #H1; #H2; nwhd in ⊢ (???%% → ?); - nrewrite > (ltb_t … H1); nrewrite > (ltb_t … H2); nwhd in ⊢ (???%% → ?); - napply f_inj; nassumption - | #n'; #Hrec; #Hx; #Hx'; nwhd in ⊢ (???%% → ?); - ] + [ napply iso_nat_nat_union_pre [ napply le_S_S_to_le; nassumption | nassumption ] + ##| nwhd in ⊢ (???%%); napply (.= ?) [ nassumption|##skip] + ngeneralize in match (iso_nat_nat_union_char n s xxx ?) in ⊢ ? + [##2: napply iso_nat_nat_union_pre [ napply le_S_S_to_le; nassumption | nassumption]##] + *; *; #K1; #K2; #K3; + ngeneralize in match + (iso_nat_nat_union_uniq n s nindex (fst … (iso_nat_nat_union s xxx n)) + nindex2 (snd … (iso_nat_nat_union s xxx n)) ?????) in ⊢ ? + [ *; #E1; #E2; nrewrite > E1; nrewrite > E2; napply refl + | napply le_S_S_to_le; nassumption + |##*: nassumption]##] +##| #x; #x'; nnormalize in ⊢ (? → ? → %); #Hx; #Hx'; #E; + ngeneralize in match (? : ∀i1,i2,i1',i2'. i1 ∈ Nat_ (S n) → i1' ∈ Nat_ (S n) → i2 ∈ pc ? (Nat_ (s i1)) → i2' ∈ pc ? (Nat_ (s i1')) → eq_rel (carr A) (eq A) (iso_f ???? (fi i1) i2) (iso_f ???? (fi i1') i2') → i1=i1' ∧ i2=i2') in ⊢ ? + [##2: #i1; #i2; #i1'; #i2'; #Hi1; #Hi1'; #Hi2; #Hi2'; #E; + ngeneralize in match (disjoint ? P (iso_f ???? f i1) (iso_f ???? f i1') ???) in ⊢ ? + [##2,3: napply f_closed; nassumption + |##4: napply ex_intro [ napply (iso_f ???? (fi i1) i2) ] napply conj + [ napply f_closed; nassumption ##| napply (. ?‡#) [##2: nassumption | ##3: ##skip] + nwhd; napply f_closed; nassumption]##] + #E'; ngeneralize in match (? : i1=i1') in ⊢ ? + [##2: napply (f_inj … E'); nassumption + | #E''; nrewrite < E''; napply conj + [ napply refl | nrewrite < E'' in E; #E'''; napply (f_inj … E''') + [ nassumption | nrewrite > E''; nassumption ]##]##] + ##] #K; + nelim (iso_nat_nat_union_char n s x Hx); *; #i1x; #i2x; #i3x; + nelim (iso_nat_nat_union_char n s x' Hx'); *; #i1x'; #i2x'; #i3x'; + ngeneralize in match (K … E) in ⊢ ? + [##2,3: napply le_to_le_S_S; nassumption + |##4,5: nassumption] + *; #K1; #K2; + napply (eq_rect_CProp0_r ?? (λX.λ_.? = X) ?? i1x'); + napply (eq_rect_CProp0_r ?? (λX.λ_.X = ?) ?? i1x); + nrewrite > K1; nrewrite > K2; napply refl ] nqed. (************** equivalence relations vs partitions **********************) diff --git a/helm/software/matita/nlibrary/sets/sets.ma b/helm/software/matita/nlibrary/sets/sets.ma index 3e63bf8f2..4579054c5 100644 --- a/helm/software/matita/nlibrary/sets/sets.ma +++ b/helm/software/matita/nlibrary/sets/sets.ma @@ -226,6 +226,7 @@ nqed. nrecord isomorphism (A) (B) (S: qpowerclass A) (T: qpowerclass B) : CProp[0] ≝ { iso_f:> unary_morphism A B; + f_closed: ∀x. x ∈ S → iso_f x ∈ T; f_sur: surjective ?? S T iso_f; f_inj: injective ?? S iso_f }.