]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/sets/setoids.ma
e593ea7d52be439e22b776a8c5d81aa334547f3f
[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 (* 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 interpretation "setoid eq" 'eq t x y = (eq_rel ? (eq0 t) x y).
32
33 notation > "hvbox(a break =_0 b)" non associative with precedence 45
34 for @{ eq_rel ? (eq0 ?) $a $b }.
35
36 interpretation "setoid symmetry" 'invert r = (sym ???? r).
37 notation ".= r" with precedence 50 for @{'trans $r}.
38 interpretation "trans" 'trans r = (trans ????? r).
39 notation > ".=_0 r" with precedence 50 for @{'trans_x0 $r}.
40 interpretation "trans_x0" 'trans_x0 r = (trans ????? r).
41
42 nrecord unary_morphism (A,B: setoid) : Type[0] ≝ { 
43   fun1:1> A → B;
44   prop1: ∀a,a'. a = a' → fun1 a = fun1 a'
45 }.
46
47 notation > "B ⇒_0 C" right associative with precedence 72 for @{'umorph0 $B $C}.
48 notation "hvbox(B break ⇒\sub 0 C)" right associative with precedence 72 for @{'umorph0 $B $C}.
49 interpretation "unary morphism 0" 'umorph0 A B = (unary_morphism A B).
50
51 notation "† c" with precedence 90 for @{'prop1 $c }.
52 notation "l ‡ r" with precedence 90 for @{'prop2 $l $r }.
53 notation "#" with precedence 90 for @{'refl}.
54 interpretation "prop1" 'prop1 c  = (prop1 ????? c).
55 interpretation "refl" 'refl = (refl ???).
56 notation "┼_0 c" with precedence 89 for @{'prop1_x0 $c }.
57 notation "l ╪_0 r" with precedence 89 for @{'prop2_x0 $l $r }.
58 interpretation "prop1_x0" 'prop1_x0 c  = (prop1 ????? c).
59
60 ndefinition unary_morph_setoid : setoid → setoid → setoid.
61 #S1; #S2; @ (S1 ⇒_0 S2); @;
62 ##[ #f; #g; napply (∀x,x'. x=x' → f x = g x');
63 ##| #f; #x; #x'; #Hx; napply (.= †Hx); napply #;
64 ##| #f; #g; #H; #x; #x'; #Hx; napply ((H … Hx^-1)^-1);
65 ##| #f; #g; #h; #H1; #H2; #x; #x'; #Hx; napply (trans … (H1 …) (H2 …)); //; ##]
66 nqed.
67
68 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
69 unification hint 0 ≔ o1,o2 ; 
70      X ≟ unary_morph_setoid o1 o2
71   (* ----------------------------- *) ⊢ 
72      carr X ≡ o1 ⇒_0 o2.
73
74 interpretation "prop2" 'prop2 l r = (prop1 ? (unary_morph_setoid ??) ? ?? l ?? r).
75 interpretation "prop2_x0" 'prop2_x0 l r = (prop1 ? (unary_morph_setoid ??) ? ?? l ?? r).
76
77 nlemma unary_morph_eq: ∀A,B.∀f,g:A ⇒_0 B. (∀x. f x = g x) → f = g.
78 #A B f g H x1 x2 E; napply (.= †E); napply H; nqed.
79
80 nlemma mk_binary_morphism:
81  ∀A,B,C: setoid. ∀f: A → B → C. (∀a,a',b,b'. a=a' → b=b' → f a b = f a' b') →
82   A ⇒_0 (unary_morph_setoid B C).
83  #A; #B; #C; #f; #H; @ [ #x; @ (f x) ] #a; #a'; #Ha [##2: napply unary_morph_eq; #y]
84  /2/.
85 nqed.
86
87 ndefinition composition ≝
88  λo1,o2,o3:Type[0].λf:o2 → o3.λg: o1 → o2.λx.f (g x).
89  
90 interpretation "function composition" 'compose f g = (composition ??? f g).
91
92 ndefinition comp_unary_morphisms:
93  ∀o1,o2,o3:setoid.o2 ⇒_0 o3 → o1 ⇒_0 o2 → o1 ⇒_0  o3.
94 #o1; #o2; #o3; #f; #g; @ (f ∘ g);
95  #a; #a'; #e; nnormalize; napply (.= †(†e)); napply #.
96 nqed.
97
98 unification hint 0 ≔ o1,o2,o3:setoid,f:o2 ⇒_0 o3,g:o1 ⇒_0 o2;
99    R ≟ mk_unary_morphism ?? (composition … f g)
100         (prop1 ?? (comp_unary_morphisms o1 o2 o3 f g))
101  (* -------------------------------------------------------------------- *) ⊢
102                               fun1 ?? R ≡ (composition … f g).
103
104 ndefinition comp_binary_morphisms: 
105   ∀o1,o2,o3.(o2 ⇒_0 o3) ⇒_0 ((o1 ⇒_0 o2) ⇒_0 (o1 ⇒_0 o3)).
106 #o1; #o2; #o3; napply mk_binary_morphism
107  [ #f; #g; napply (comp_unary_morphisms ??? f g) 
108          (* CSC: why not ∘? 
109             GARES: because the coercion to FunClass is not triggered if there
110                    are no "extra" arguments. We could fix that in the refiner
111          *)
112  | #a; #a'; #b; #b'; #ea; #eb; #x; #x'; #Hx; nnormalize; /3/ ]
113 nqed.