1
+ (** This file defines what an [Algebra] is and provides some
2
+ elementary results. *)
3
+
1
4
Require Export
5
+ Coq.Unicode.Utf8
2
6
HoTTClasses.implementations.ne_list
3
7
HoTTClasses.implementations.family_prod.
4
8
@@ -25,69 +29,128 @@ Open Scope Algebra_scope.
25
29
26
30
Local Notation SymbolType_internal := @ne_list.
27
31
28
- Record Signature : Type := Build
32
+ (** A [Signature] is used to characterise [Algebra]s. It consists of
33
+ - A type of [Sort]s, which represent the "objects" (types) an
34
+ algebra for the signature must provide.
35
+ - A type of Function [Symbol]s, which represent operations an
36
+ algebra for the signature must provide.
37
+ - For each symbol [u:Symbol], a [SymbolType] specifying the
38
+ required type of the operation corresponding to [u] provided by
39
+ the algebra for the signature. *)
40
+
41
+ Record Signature : Type := BuildSignature
29
42
{ Sort : Type
30
43
; Symbol : Type
31
44
; symbol_types : Symbol → SymbolType_internal Sort }.
32
45
46
+ (** Notice we have this implicit coercion allowing us to use a
47
+ signature [σ:Signature] as a map [Symbol σ → SymbolType σ]
48
+ (see [SymbolType] below). *)
49
+
33
50
Global Coercion symbol_types : Signature >-> Funclass.
34
51
35
- Definition BuildSingleSortedSignature {Op : Type } (arities : Op → nat)
52
+ (** A single sorted [Signature] is a singuture with [Sort = Unit].
53
+ Then it suffices to provide an arity for each Function [Symbol]. *)
54
+
55
+ Definition BuildSingleSortedSignature {sym : Type } (arities : sym → nat)
36
56
: Signature
37
- := Build Unit Op (ne_list.replicate_Sn tt ∘ arities).
57
+ := BuildSignature Unit sym (ne_list.replicate_Sn tt ∘ arities).
58
+
59
+ (** Let [σ:Signature]. For each symbol [u : Symbol σ], [σ u] is
60
+ associates [u] to a [SymbolType σ]. This represents the required
61
+ type of the algebra operation corresponding to [u]. *)
62
+
63
+ Definition SymbolType (σ : Signature) : Type
64
+ := SymbolType_internal (Sort σ).
65
+
66
+ (** For [s : SymbolType σ], [cod_symboltype σ] is the codomain of the
67
+ symbol type [s]. *)
68
+
69
+ Definition cod_symboltype {σ} : SymbolType σ → Sort σ
70
+ := ne_list.last.
38
71
39
- Definition SymbolType (σ : Signature) : Type := SymbolType_internal (Sort σ).
72
+ (** For [s : SymbolType σ], [cod_symboltype σ] is the domain of the
73
+ symbol type [s]. *)
40
74
41
- Definition cod_symboltype {σ} : SymbolType σ → Sort σ := ne_list.last.
75
+ Definition dom_symboltype {σ} : SymbolType σ → list (Sort σ)
76
+ := ne_list.front.
42
77
43
- Definition dom_symboltype {σ} : SymbolType σ → list (Sort σ) := ne_list.front.
78
+ (** For [s : SymbolType σ], [cod_symboltype σ] is the arity of the
79
+ symbol type [s]. That is the number [n:nat] of arguments of the
80
+ [SymbolType σ]. *)
44
81
45
- Definition arity_symboltype {σ} : SymbolType σ → nat := length ∘ dom_symboltype.
82
+ Definition arity_symboltype {σ} : SymbolType σ → nat
83
+ := length ∘ dom_symboltype.
84
+
85
+ (** An [Algebra] must provide a family of [Carriers σ] indexed by
86
+ [Sort σ]. These carriers are the "objects" (types) of the algebra. *)
87
+
88
+ (* [Carriers] is a notation because it will be used for an implicit
89
+ coercion [Algebra >-> Funclass] below. *)
46
90
47
91
Notation Carriers := (λ (σ : Signature), Sort σ → Type ).
48
92
49
- Fixpoint Operation {σ : Signature} (A : Carriers σ) (u : SymbolType σ) : Type
50
- := match u with
93
+ (** The function [Operation] maps a family of carriers [A : Carriers σ]
94
+ and [w : SymbolType σ] to the corresponding function type. For
95
+ example
96
+ <<
97
+ Operation A [:s1; s2; r:] = A s1 → A s2 → A r
98
+ >> *)
99
+
100
+ Fixpoint Operation {σ : Signature} (A : Carriers σ) (w : SymbolType σ)
101
+ : Type
102
+ := match w with
51
103
| [:s:] => A s
52
- | s ::: u ' => A s → Operation A u '
104
+ | s ::: w ' => A s → Operation A w '
53
105
end .
54
106
55
- Global Instance trunc_operation `{Funext} {σ : Signature} (A : Carriers σ)
56
- {n} `{!∀ s, IsTrunc n (A s)} (w : SymbolType σ)
57
- : IsTrunc n (Operation A w).
107
+ Global Instance trunc_operation `{Funext} {σ : Signature}
108
+ (A : Carriers σ) {n} `{!∀ s, IsTrunc n (A s)} (w : SymbolType σ)
109
+ : IsTrunc n (Operation A w).
58
110
Proof .
59
111
induction w; apply (istrunc_trunctype_type (BuildTruncType n _)).
60
112
Defined .
61
113
62
- (** Uncurry of [Operation], such that
63
-
64
- [ap_operation f (x1,x2,...,xn) = f x1 x2 ... xn]. *)
114
+ (** Uncurry of an [Operation A w], such that
115
+ <<
116
+ ap_operation f (x1,x2,...,xn) = f x1 x2 ... xn
117
+ >> *)
65
118
66
119
Fixpoint ap_operation {σ} {A : Carriers σ} {w : SymbolType σ}
67
- : Operation A w → FamilyProd A (dom_symboltype w) → A (cod_symboltype w)
120
+ : Operation A w →
121
+ FamilyProd A (dom_symboltype w) →
122
+ A (cod_symboltype w)
68
123
:= match w with
69
124
| [:s:] => λ f _, f
70
125
| s ::: w' => λ f '(x, l), ap_operation (f x) l
71
126
end .
72
127
73
- (** Funext for uncurried [Operation]s. If
128
+ (** Funext for uncurried [Operation A w]. If
129
+ <<
130
+ ap_operation f (x1,x2,...,xn) = ap_operation g (x1,x2,...,xn)
131
+ >>
132
+ for all [(x1,x2,...,xn) : A s1 * A s2 * ... * A sn], then [f = g]. *)
74
133
75
- [ap_operation f (x1,x2,...,xn) = ap_operation g (x1,x2,...,xn)],
76
-
77
- for all [(x1,x2,...,xn) : A s1 * A s2 * ... A sn], then [f = g].
78
- *)
79
-
80
- Fixpoint path_forall_ap_operation `{Funext} {σ} {A : Carriers σ} {w : SymbolType σ}
134
+ Fixpoint path_forall_ap_operation `{Funext} {σ : Signature}
135
+ {A : Carriers σ} {w : SymbolType σ}
81
136
: ∀ (f g : Operation A w),
82
- (∀ a : FamilyProd A (dom_symboltype w), ap_operation f a = ap_operation g a)
137
+ (∀ a : FamilyProd A (dom_symboltype w),
138
+ ap_operation f a = ap_operation g a)
83
139
-> f = g
84
140
:= match w with
85
- | [:s:] => λ f g h, h tt
141
+ | [:s:] => λ ( f g : A s) p, p tt
86
142
| s ::: w' =>
87
- λ f g h, path_forall f g
88
- (λ x, path_forall_ap_operation (f x) (g x) (λ a, h (x,a)))
143
+ λ (f g : A s → Operation A w') p,
144
+ path_forall f g
145
+ (λ x, path_forall_ap_operation (f x) (g x) (λ a, p (x,a)))
89
146
end .
90
147
148
+ (** An [Algebra σ] for a signature [σ] consists of a family [carriers :
149
+ Carriers σ] indexed by the sorts [s : Sort σ], and for each symbol
150
+ [u : Symbol σ], an operation of type [Operation carriers (σ u)],
151
+ where [σ u : SymbolType σ] is the symbol type of [u]. For each
152
+ sort [s : Sort σ], [carriers s] is required to be a set. *)
153
+
91
154
Record Algebra {σ : Signature} : Type := BuildAlgebra
92
155
{ carriers : Carriers σ
93
156
; operations : ∀ (u : Symbol σ), Operation carriers (σ u)
@@ -97,6 +160,8 @@ Arguments Algebra : clear implicits.
97
160
98
161
Arguments BuildAlgebra {σ} carriers operations {hset_carriers_algebra}.
99
162
163
+ (** We have a convenient implicit coercion from an algebra to the
164
+ family of carriers. *)
100
165
Global Coercion carriers : Algebra >-> Funclass.
101
166
102
167
Global Existing Instance hset_carriers_algebra.
@@ -119,9 +184,13 @@ Ltac change_issig_algebra A :=
119
184
change (operations A) with (issig_algebra A).2.1 in *;
120
185
change (carriers A) with (issig_algebra A).1 in *.
121
186
187
+ (** To find a path between two algebras [A B : Algebra σ] it suffices
188
+ to find a path between the carrier families and the operations. *)
189
+
122
190
Lemma path_algebra `{Funext} {σ} (A B : Algebra σ)
123
191
: (∃ (p : carriers A = carriers B),
124
- transport (λ X, ∀ u, Operation X (σ u)) p (operations A) = operations B)
192
+ transport (λ X, ∀ u, Operation X (σ u)) p (operations A)
193
+ = operations B)
125
194
→ A = B.
126
195
Proof .
127
196
intros [p q].
0 commit comments