]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/sets/setoids.ma
b66f4d457e9a12ed8dcc2ef1b732541467509048
[helm.git] / helm / software / matita / nlibrary / sets / setoids.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "logic/connectives.ma".
16 include "properties/relations.ma".
17 include "hints_declaration.ma".
18
19 nrecord setoid : Type[1] ≝
20  { carr:> Type[0];
21    eq0: equivalence_relation carr
22  }.
23
24 interpretation "setoid eq" 'eq t x y = (eq_rel ? (eq0 t) x y).
25
26 notation > "hvbox(a break =_0 b)" non associative with precedence 45
27 for @{ eq_rel ? (eq0 ?) $a $b }.
28
29 interpretation "setoid symmetry" 'invert r = (sym ???? r).
30 notation ".= r" with precedence 50 for @{'trans $r}.
31 interpretation "trans" 'trans r = (trans ????? r).
32 notation > ".=_0 r" with precedence 50 for @{'trans_x0 $r}.
33 interpretation "trans_x0" 'trans_x0 r = (trans ????? r).
34
35 nrecord unary_morphism (A,B: setoid) : Type[0] ≝
36  { fun1:1> A → B;
37    prop1: ∀a,a'. a = a' → fun1 a = fun1 a'
38  }.
39
40 notation "† c" with precedence 90 for @{'prop1 $c }.
41 notation "l ‡ r" with precedence 90 for @{'prop2 $l $r }.
42 notation "#" with precedence 90 for @{'refl}.
43 interpretation "prop1" 'prop1 c  = (prop1 ????? c).
44 interpretation "refl" 'refl = (refl ???).
45 notation "┼_0 c" with precedence 89 for @{'prop1_x0 $c }.
46 notation "l ╪_0 r" with precedence 89 for @{'prop2_x0 $l $r }.
47 interpretation "prop1_x0" 'prop1_x0 c  = (prop1 ????? c).
48
49 ndefinition unary_morph_setoid : setoid → setoid → setoid.
50 #S1; #S2; @ (unary_morphism S1 S2); @;
51 ##[ #f; #g; napply (∀x,x'. x=x' → f x = g x');
52 ##| #f; #x; #x'; #Hx; napply (.= †Hx); napply #;
53 ##| #f; #g; #H; #x; #x'; #Hx; napply ((H … Hx^-1)^-1);
54 ##| #f; #g; #h; #H1; #H2; #x; #x'; #Hx; napply (trans … (H1 …) (H2 …)); //; ##]
55 nqed.
56
57 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
58 unification hint 0 ≔ o1,o2 ; 
59      X ≟ unary_morph_setoid o1 o2
60   (* ------------------------------ *) ⊢ 
61      carr X ≡ unary_morphism o1 o2.
62
63 interpretation "prop2" 'prop2 l r = (prop1 ? (unary_morph_setoid ??) ? ?? l ?? r).
64 interpretation "prop2_x0" 'prop2_x0 l r = (prop1 ? (unary_morph_setoid ??) ? ?? l ?? r).
65
66 nlemma unary_morph_eq: ∀A,B.∀f,g: unary_morphism A B. (∀x. f x = g x) → f=g.
67 #A B f g H x1 x2 E; napply (.= †E); napply H; nqed.
68
69 nlemma mk_binary_morphism:
70  ∀A,B,C: setoid. ∀f: A → B → C. (∀a,a',b,b'. a=a' → b=b' → f a b = f a' b') →
71   unary_morphism A (unary_morph_setoid B C).
72  #A; #B; #C; #f; #H; @ [ #x; @ (f x) ] #a; #a'; #Ha [##2: napply unary_morph_eq; #y]
73  /2/.
74 nqed.
75
76 ndefinition composition ≝
77  λo1,o2,o3:Type[0].λf:o2 → o3.λg: o1 → o2.λx.f (g x).
78  
79 interpretation "function composition" 'compose f g = (composition ??? f g).
80
81 ndefinition comp_unary_morphisms:
82  ∀o1,o2,o3:setoid.
83   unary_morphism o2 o3 → unary_morphism o1 o2 →
84    unary_morphism o1 o3.
85 #o1; #o2; #o3; #f; #g; @ (f ∘ g);
86  #a; #a'; #e; nnormalize; napply (.= †(†e)); napply #.
87 nqed.
88
89 unification hint 0 ≔ o1,o2,o3:setoid,f:unary_morphism o2 o3,g:unary_morphism o1 o2;
90    R ≟ mk_unary_morphism ?? (composition … f g)
91         (prop1 ?? (comp_unary_morphisms o1 o2 o3 f g))
92  (* -------------------------------------------------------------------- *) ⊢
93                               fun1 ?? R ≡ (composition … f g).
94
95 ndefinition comp_binary_morphisms:
96  ∀o1,o2,o3.
97   unary_morphism (unary_morph_setoid o2 o3)
98    (unary_morph_setoid (unary_morph_setoid o1 o2) (unary_morph_setoid o1 o3)).
99 #o1; #o2; #o3; napply mk_binary_morphism
100  [ #f; #g; napply (comp_unary_morphisms … f g) (*CSC: why not ∘?*)
101  | #a; #a'; #b; #b'; #ea; #eb; #x; #x'; #Hx; nnormalize; /3/ ]
102 nqed.