X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fmatita%2Flibrary%2Fformal_topology%2Frelations.ma;h=f81e19eeccb87b438dc2215b5f2b3b8744322618;hb=c96d1f2066d37b84a34412f7c49fb3e4f54bd9a2;hp=e67b2ce7c5ea8792fd4b715efb3befe79dcaa2c5;hpb=7fad6f9727bb6f054c0198cf10354be4b355baef;p=helm.git diff --git a/helm/software/matita/library/formal_topology/relations.ma b/helm/software/matita/library/formal_topology/relations.ma index e67b2ce7c..f81e19eec 100644 --- a/helm/software/matita/library/formal_topology/relations.ma +++ b/helm/software/matita/library/formal_topology/relations.ma @@ -14,132 +14,234 @@ include "datatypes/subsets.ma". -record ssigma (A:Type) (S: powerset A) : Type ≝ - { witness:> A; - proof:> witness ∈ S - }. - -coercion ssigma. - -record binary_relation (A,B: Type) (U: Ω \sup A) (V: Ω \sup B) : Type ≝ - { satisfy:2> U → V → CProp }. +record binary_relation (A,B: setoid) : Type ≝ + { satisfy:> binary_morphism1 A B CPROP }. notation < "hvbox (x \nbsp \natur term 90 r \nbsp y)" with precedence 45 for @{'satisfy $r $x $y}. notation > "hvbox (x \natur term 90 r y)" with precedence 45 for @{'satisfy $r $x $y}. -interpretation "relation applied" 'satisfy r x y = (satisfy ____ r x y). +interpretation "relation applied" 'satisfy r x y = (fun1 ___ (satisfy __ r) x y). + +definition binary_relation_setoid: setoid → setoid → setoid1. + intros (A B); + constructor 1; + [ apply (binary_relation A B) + | constructor 1; + [ apply (λA,B.λr,r': binary_relation A B. ∀x,y. r x y ↔ r' x y) + | simplify; intros 3; split; intro; assumption + | simplify; intros 5; split; intro; + [ apply (fi ?? (H ??)) | apply (if ?? (H ??))] assumption + | simplify; intros 7; split; intro; + [ apply (if ?? (H1 ??)) | apply (fi ?? (H ??)) ] + [ apply (if ?? (H ??)) | apply (fi ?? (H1 ??)) ] + assumption]] +qed. definition composition: - ∀A,B,C.∀U1: Ω \sup A.∀U2: Ω \sup B.∀U3: Ω \sup C. - binary_relation ?? U1 U2 → binary_relation ?? U2 U3 → - binary_relation ?? U1 U3. - intros (A B C U1 U2 U3 R12 R23); + ∀A,B,C. + binary_morphism1 (binary_relation_setoid A B) (binary_relation_setoid B C) (binary_relation_setoid A C). + intros; constructor 1; - intros (s1 s3); - apply (∃s2. s1 ♮R12 s2 ∧ s2 ♮R23 s3); + [ intros (R12 R23); + constructor 1; + constructor 1; + [ apply (λs1:A.λs3:C.∃s2:B. s1 ♮R12 s2 ∧ s2 ♮R23 s3); + | intros; + split; intro; cases H2 (w H3); clear H2; exists; [1,3: apply w ] + [ apply (. (H‡#)‡(#‡H1)); assumption + | apply (. ((H \sup -1)‡#)‡(#‡(H1 \sup -1))); assumption]] + | intros 8; split; intro H2; simplify in H2 ⊢ %; + cases H2 (w H3); clear H2; exists [1,3: apply w] cases H3 (H2 H4); clear H3; + [ lapply (if ?? (H x w) H2) | lapply (fi ?? (H x w) H2) ] + [ lapply (if ?? (H1 w y) H4)| lapply (fi ?? (H1 w y) H4) ] + exists; try assumption; + split; assumption] +qed. + +definition REL: category1. + constructor 1; + [ apply setoid + | intros (T T1); apply (binary_relation_setoid T T1) + | intros; constructor 1; + constructor 1; unfold setoid1_of_setoid; simplify; + [ intros; apply (c = c1) + | intros; split; intro; + [ apply (trans ????? (H \sup -1)); + apply (trans ????? H2); + apply H1 + | apply (trans ????? H); + apply (trans ????? H2); + apply (H1 \sup -1)]] + | apply composition + | intros 9; + split; intro; + cases f (w H); clear f; cases H; clear H; + [cases f (w1 H); clear f | cases f1 (w1 H); clear f1] + cases H; clear H; + exists; try assumption; + split; try assumption; + exists; try assumption; + split; assumption + |6,7: intros 5; unfold composition; simplify; split; intro; + unfold setoid1_of_setoid in x y; simplify in x y; + [1,3: cases H (w H1); clear H; cases H1; clear H1; unfold; + [ apply (. (H \sup -1 : eq1 ? w x)‡#); assumption + | apply (. #‡(H : eq1 ? w y)); assumption] + |2,4: exists; try assumption; split; first [apply refl | assumption]]] +qed. + +definition full_subset: ∀s:REL. Ω \sup s. + apply (λs.{x | True}); + intros; simplify; split; intro; assumption. qed. -interpretation "binary relation composition" 'compose x y = (composition ______ x y). +coercion full_subset. -definition equal_relations ≝ - λA,B,U,V.λr,r': binary_relation A B U V. - ∀x,y. r x y ↔ r' x y. +definition setoid1_of_REL: REL → setoid ≝ λS. S. -interpretation "equal relation" 'eq x y = (equal_relations ____ x y). +coercion setoid1_of_REL. -lemma refl_equal_relations: ∀A,B,U,V. reflexive ? (equal_relations A B U V). - intros 5; intros 2; split; intro; assumption. +definition comprehension: ∀b:REL. (b ⇒ CPROP) → Ω \sup b. + apply (λb:REL. λP: b ⇒ CPROP. {x | x ∈ b ∧ P x}); + intros; simplify; apply (.= (H‡#)‡(†H)); apply refl1. qed. -lemma sym_equal_relations: ∀A,B,U,V. symmetric ? (equal_relations A B U V). - intros 7; intros 2; split; intro; - [ apply (fi ?? (H ??)) | apply (if ?? (H ??))] assumption. +interpretation "subset comprehension" 'comprehension s p = + (comprehension s (mk_unary_morphism __ p _)). + +definition ext: ∀X,S:REL. binary_morphism1 (arrows1 ? X S) S (Ω \sup X). + apply (λX,S.mk_binary_morphism1 ??? (λr:arrows1 ? X S.λf:S.{x ∈ X | x ♮r f}) ?); + [ intros; simplify; apply (.= (H‡#)); apply refl1 + | intros; simplify; split; intros; simplify; intros; cases f; split; try assumption; + [ apply (. (#‡H1)); whd in H; apply (if ?? (H ??)); assumption + | apply (. (#‡H1\sup -1)); whd in H; apply (fi ?? (H ??));assumption]] qed. -lemma trans_equal_relations: ∀A,B,U,V. transitive ? (equal_relations A B U V). - intros 9; intros 2; split; intro; - [ apply (if ?? (H1 ??)) | apply (fi ?? (H ??)) ] - [ apply (if ?? (H ??)) | apply (fi ?? (H1 ??)) ] - assumption. +definition extS: ∀X,S:REL. ∀r: arrows1 ? X S. Ω \sup S ⇒ Ω \sup X. + (* ∃ is not yet a morphism apply (λX,S,r,F.{x ∈ X | ∃a. a ∈ F ∧ x ♮r a});*) + intros (X S r); constructor 1; + [ intro F; constructor 1; constructor 1; + [ apply (λx. x ∈ X ∧ ∃a:S. a ∈ F ∧ x ♮r a); + | intros; split; intro; cases f (H1 H2); clear f; split; + [ apply (. (H‡#)); assumption + |3: apply (. (H\sup -1‡#)); assumption + |2,4: cases H2 (w H3); exists; [1,3: apply w] + [ apply (. (#‡(H‡#))); assumption + | apply (. (#‡(H \sup -1‡#))); assumption]]] + | intros; split; simplify; intros; cases f; cases H1; split; + [1,3: assumption + |2,4: exists; [1,3: apply w] + [ apply (. (#‡H)‡#); assumption + | apply (. (#‡H\sup -1)‡#); assumption]]] qed. -lemma associative_composition: - ∀A,B,C,D.∀U1,U2,U3,U4. - ∀r1:binary_relation A B U1 U2. - ∀r2:binary_relation B C U2 U3. - ∀r3:binary_relation C D U3 U4. - (r1 ∘ r2) ∘ r3 = r1 ∘ (r2 ∘ r3). - intros 13; - split; intro; - cases H; clear H; cases H1; clear H1; - [cases H; clear H | cases H2; clear H2] - cases H1; clear H1; - exists; try assumption; - split; try assumption; - exists; try assumption; - split; assumption. +lemma equalset_extS_id_X_X: ∀o:REL.∀X.extS ?? (id1 ? o) X = X. + intros; + unfold extS; simplify; + split; simplify; + [ intros 2; change with (a ∈ X); + cases f; clear f; + cases H; clear H; + cases x; clear x; + change in f2 with (eq1 ? a w); + apply (. (f2\sup -1‡#)); + assumption + | intros 2; change in f with (a ∈ X); + split; + [ whd; exact I + | exists; [ apply a ] + split; + [ assumption + | change with (a = a); apply refl]]] qed. -lemma composition_morphism: - ∀A,B,C.∀U1,U2,U3. - ∀r1,r1':binary_relation A B U1 U2. - ∀r2,r2':binary_relation B C U2 U3. - r1 = r1' → r2 = r2' → r1 ∘ r2 = r1' ∘ r2'. - intros 14; split; intro; - cases H2; clear H2; cases H3; clear H3; - [ lapply (if ?? (H x w) H2) | lapply (fi ?? (H x w) H2) ] - [ lapply (if ?? (H1 w y) H4)| lapply (fi ?? (H1 w y) H4) ] - exists; try assumption; - split; assumption. +lemma extS_com: ∀o1,o2,o3,c1,c2,S. extS o1 o3 (c2 ∘ c1) S = extS o1 o2 c1 (extS o2 o3 c2 S). + intros; unfold extS; simplify; split; intros; simplify; intros; + [ cases f (H1 H2); cases H2 (w H3); clear f H2; split; [assumption] + cases H3 (H4 H5); cases H5 (w1 H6); clear H3 H5; cases H6 (H7 H8); clear H6; + exists; [apply w1] split [2: assumption] constructor 1; [assumption] + exists; [apply w] split; assumption + | cases f (H1 H2); cases H2 (w H3); clear f H2; split; [assumption] + cases H3 (H4 H5); cases H4 (w1 H6); clear H3 H4; cases H6 (w2 H7); clear H6; + cases H7; clear H7; exists; [apply w2] split; [assumption] exists [apply w] split; + assumption] qed. -definition binary_relation_setoid: ∀A,B. Ω \sup A → Ω \sup B → setoid. - intros (A B U V); - constructor 1; - [ apply (binary_relation ?? U V) - | constructor 1; - [ apply equal_relations - | apply refl_equal_relations - | apply sym_equal_relations - | apply trans_equal_relations - ]] +(* the same as ⋄ for a basic pair *) +definition image: ∀U,V:REL. binary_morphism1 (arrows1 ? U V) (Ω \sup U) (Ω \sup V). + intros; constructor 1; + [ apply (λr: arrows1 ? U V.λS: Ω \sup U. {y | ∃x:U. x ♮r y ∧ x ∈ S}); + intros; simplify; split; intro; cases H1; exists [1,3: apply w] + [ apply (. (#‡H)‡#); assumption + | apply (. (#‡H \sup -1)‡#); assumption] + | intros; split; simplify; intros; cases H2; exists [1,3: apply w] + [ apply (. #‡(#‡H1)); cases x; split; try assumption; + apply (if ?? (H ??)); assumption + | apply (. #‡(#‡H1 \sup -1)); cases x; split; try assumption; + apply (if ?? (H \sup -1 ??)); assumption]] qed. -record sigma (A:Type) (P: A → Type) : Type ≝ - { s_witness:> A; - s_proof:> P s_witness - }. +(* the same as □ for a basic pair *) +definition minus_star_image: ∀U,V:REL. binary_morphism1 (arrows1 ? U V) (Ω \sup U) (Ω \sup V). + intros; constructor 1; + [ apply (λr: arrows1 ? U V.λS: Ω \sup U. {y | ∀x:U. x ♮r y → x ∈ S}); + intros; simplify; split; intros; apply H1; + [ apply (. #‡H \sup -1); assumption + | apply (. #‡H); assumption] + | intros; split; simplify; intros; [ apply (. #‡H1); | apply (. #‡H1 \sup -1)] + apply H2; [ apply (if ?? (H \sup -1 ??)); | apply (if ?? (H ??)) ] assumption] +qed. -interpretation "sigma" 'sigma \eta.x = (sigma _ x). +(* minus_image is the same as ext *) -definition REL: category. - constructor 1; - [ apply (ΣA:Type.Ω \sup A) - | intros; apply (binary_relation_setoid ?? (s_proof ?? s) (s_proof ?? s1)) - | intros; constructor 1; intros; apply (s=s1) - | intros; constructor 1; - [ apply composition - | apply composition_morphism - ] - | intros; unfold mk_binary_morphism; simplify; - apply associative_composition - |6,7: intros 5; simplify; split; intro; - [1,3: cases H; clear H; cases H1; clear H1; - [ rewrite > H | rewrite < H2 ] - assumption - |*: exists; try assumption; split; first [ reflexivity | assumption ]]] +theorem image_id: ∀o,U. image o o (id1 REL o) U = U. + intros; unfold image; simplify; split; simplify; intros; + [ change with (a ∈ U); + cases H; cases x; change in f with (eq1 ? w a); apply (. f‡#); assumption + | change in f with (a ∈ U); + exists; [apply a] split; [ change with (a = a); apply refl | assumption]] qed. -definition elements: objs REL → Type ≝ - λb:ΣA.Ω\sup A.ssigma (s_witness ?? b) (s_proof ?? b). - -coercion elements. +theorem minus_star_image_id: ∀o,U. minus_star_image o o (id1 REL o) U = U. + intros; unfold minus_star_image; simplify; split; simplify; intros; + [ change with (a ∈ U); apply H; change with (a=a); apply refl + | change in f1 with (eq1 ? x a); apply (. f1 \sup -1‡#); apply f] +qed. -definition carrier: objs REL → Type ≝ - λb:ΣA.Ω\sup A.s_witness ?? b. +theorem image_comp: ∀A,B,C,r,s,X. image A C (r ∘ s) X = image B C r (image A B s X). + intros; unfold image; simplify; split; simplify; intros; cases H; clear H; cases x; + clear x; [ cases f; clear f; | cases f1; clear f1 ] + exists; try assumption; cases x; clear x; split; try assumption; + exists; try assumption; split; assumption. +qed. -interpretation "REL carrier" 'card c = (carrier c). +theorem minus_star_image_comp: + ∀A,B,C,r,s,X. + minus_star_image A C (r ∘ s) X = minus_star_image B C r (minus_star_image A B s X). + intros; unfold minus_star_image; simplify; split; simplify; intros; whd; intros; + [ apply H; exists; try assumption; split; assumption + | change with (x ∈ X); cases f; cases x1; apply H; assumption] +qed. -definition subset: ∀b:objs REL. Ω \sup (carrier b) ≝ - λb:ΣA.Ω\sup A.s_proof ?? b. +(*CSC: unused! *) +theorem ext_comp: + ∀o1,o2,o3: REL. + ∀a: arrows1 ? o1 o2. + ∀b: arrows1 ? o2 o3. + ∀x. ext ?? (b∘a) x = extS ?? a (ext ?? b x). + intros; + unfold ext; unfold extS; simplify; split; intro; simplify; intros; + cases f; clear f; split; try assumption; + [ cases f2; clear f2; cases x1; clear x1; exists; [apply w] split; + [1: split] assumption; + | cases H; clear H; cases x1; clear x1; exists [apply w]; split; + [2: cases f] assumption] +qed. -coercion subset. +theorem extS_singleton: + ∀o1,o2.∀a:arrows1 ? o1 o2.∀x.extS o1 o2 a (singleton o2 x) = ext o1 o2 a x. + intros; unfold extS; unfold ext; unfold singleton; simplify; + split; intros 2; simplify; cases f; split; try assumption; + [ cases H; cases x1; change in f2 with (eq1 ? x w); apply (. #‡f2 \sup -1); + assumption + | exists; try assumption; split; try assumption; change with (x = x); apply refl] +qed. \ No newline at end of file