]> matita.cs.unibo.it Git - helm.git/blob - matitaB/matita/nlibrary/sets/setoids.ma
Keeping track of locations of disambiguated ids and symbols.
[helm.git] / matitaB / 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 record setoid : Type[1] ≝ { 
20   carr:> Type[0];
21   eq0: equivalence_relation carr
22 }.
23
24 (* activate non uniform coercions on: Type → setoid *)
25 unification hint 0 ≔ R : setoid;
26    MR ≟ carr R, 
27    lock ≟ mk_lock1 Type[0] MR setoid R 
28 (* ---------------------------------------- *) ⊢ 
29    setoid ≡ force1 ? MR lock.
30
31 notation < "[\setoid\ensp\of term 19 x]" non associative with precedence 90 for @{'mk_setoid $x}.
32 interpretation "mk_setoid" 'mk_setoid x = (mk_setoid x ?).
33
34 interpretation "setoid eq" 'eq t x y = (eq_rel ? (eq0 t) x y).
35 (* single = is for the abstract equality of setoids, == is for concrete 
36    equalities (that may be lifted to the setoid level when needed *)
37 notation < "hvbox(a break mpadded width -50% (=)= b)" non associative with precedence 45 for @{ 'eq_low $a $b }.
38 notation > "a == b" non associative with precedence 45 for @{ 'eq_low $a $b }.
39
40 notation > "hvbox(a break =_0 b)" non associative with precedence 45
41 for @{ eq_rel ? (eq0 ?) $a $b }.
42
43 interpretation "setoid symmetry" 'invert r = (sym ???? r).
44 notation ".= r" with precedence 50 for @{'trans $r}.
45 interpretation "trans" 'trans r = (trans ????? r).
46 notation > ".=_0 r" with precedence 50 for @{'trans_x0 $r}.
47 interpretation "trans_x0" 'trans_x0 r = (trans ????? r).
48
49 record unary_morphism (A,B: setoid) : Type[0] ≝ { 
50   fun1:1> A → B;
51   prop1: ∀a,a'. a = a' → fun1 a = fun1 a'
52 }.
53
54 notation > "B ⇒_0 C" right associative with precedence 72 for @{'umorph0 $B $C}.
55 notation "hvbox(B break ⇒\sub 0 C)" right associative with precedence 72 for @{'umorph0 $B $C}.
56 interpretation "unary morphism 0" 'umorph0 A B = (unary_morphism A B).
57
58 notation "† c" with precedence 90 for @{'prop1 $c }.
59 notation "l ‡ r" with precedence 90 for @{'prop2 $l $r }.
60 notation "#" with precedence 90 for @{'refl}.
61 interpretation "prop1" 'prop1 c  = (prop1 ????? c).
62 interpretation "refl" 'refl = (refl ???).
63 notation "┼_0 c" with precedence 89 for @{'prop1_x0 $c }.
64 notation "l ╪_0 r" with precedence 89 for @{'prop2_x0 $l $r }.
65 interpretation "prop1_x0" 'prop1_x0 c  = (prop1 ????? c).
66
67 definition unary_morph_setoid : setoid → setoid → setoid.
68 #S1 #S2 @(mk_setoid … (S1 ⇒_0 S2)) %
69 [ #f #g @(∀x,x'. x=x' → f x = g x')
70 | #f #x #x' #Hx @(.= †Hx) @#
71 | #f #g #H #x #x' #Hx @((H … Hx^-1)^-1)
72 | #f #g #h #H1 #H2 #x #x' #Hx @(trans … (H1 …) (H2 …)) // ]
73 qed.
74
75 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
76 unification hint 0 ≔ o1,o2 ; 
77      X ≟ unary_morph_setoid o1 o2
78   (* ----------------------------- *) ⊢ 
79      carr X ≡ o1 ⇒_0 o2.
80
81 interpretation "prop2" 'prop2 l r = (prop1 ? (unary_morph_setoid ??) ? ?? l ?? r).
82 interpretation "prop2_x0" 'prop2_x0 l r = (prop1 ? (unary_morph_setoid ??) ? ?? l ?? r).
83
84 lemma unary_morph_eq: ∀A,B.∀f,g:A ⇒_0 B. (∀x. f x = g x) → f = g.
85 #A #B #f #g #H #x1 #x2 #E @(.= †E) @H
86 qed.
87
88 lemma mk_binary_morphism:
89  ∀A,B,C: setoid. ∀f: A → B → C. (∀a,a',b,b'. a=a' → b=b' → f a b = f a' b') →
90   A ⇒_0 (unary_morph_setoid B C).
91  #A #B #C #f #H % [ #x % [@(f x)|/2/] |#a #a' #Ha @unary_morph_eq #y]
92  /2/
93 qed.
94
95 definition composition ≝
96  λo1,o2,o3:Type[0].λf:o2 → o3.λg: o1 → o2.λx.f (g x).
97  
98 interpretation "function composition" 'compose f g = (composition ??? f g).
99
100 definition comp_unary_morphisms:
101  ∀o1,o2,o3:setoid.o2 ⇒_0 o3 → o1 ⇒_0 o2 → o1 ⇒_0  o3.
102 #o1 #o2 #o3 #f #g % [@(f ∘ g)]
103  #a #a' #e normalize @(.= †(†e)) @#
104 qed.
105
106 unification hint 0 ≔ o1,o2,o3:setoid,f:o2 ⇒_0 o3,g:o1 ⇒_0 o2;
107    R ≟ mk_unary_morphism o1 o3 
108         (composition ??? (fun1 o2 o3 f) (fun1 o1 o2 g))
109         (prop1 o1 o3 (comp_unary_morphisms o1 o2 o3 f g))
110  (* -------------------------------------------------------------------- *) ⊢
111     fun1 o1 o3 R ≡ composition ??? (fun1 o2 o3 f) (fun1 o1 o2 g).
112
113 definition comp_binary_morphisms: 
114   ∀o1,o2,o3.(o2 ⇒_0 o3) ⇒_0 ((o1 ⇒_0 o2) ⇒_0 (o1 ⇒_0 o3)).
115 #o1 #o2 #o3 @mk_binary_morphism
116  [ #f #g @(comp_unary_morphisms ??? f g) 
117          (* CSC: why not ∘? 
118             GARES: because the coercion to FunClass is not triggered if there
119                    are no "extra" arguments. We could fix that in the refiner
120          *)
121  | #a #a' #b #b' #ea #eb #x #x' #Hx normalize /3/ ]
122 qed.