-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStructures.v
More file actions
143 lines (102 loc) · 4.49 KB
/
Copy pathStructures.v
File metadata and controls
143 lines (102 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
(** * Algebraic Structures via Hierarchy Builder
Follows the Wikipedia definition of a semiring:
https://en.wikipedia.org/wiki/Semiring
Hierarchy:
- CommutativeMonoid (additive, reused for both R and V)
- Semiring = CommutativeMonoid + multiplicative + distrib
- IdempotentSemiring = Semiring + idempotence
- BoundedSemiring = Semiring + boundedness
- IsSemimodule (two-sorted typeclass over the above)
Key design choice: IsSemiring extends CommutativeMonoid, so the additive
commutative monoid is defined once and shared by both the semiring (R)
and the vector space (V). Operations are disambiguated by type. *)
From HB Require Import structures.
From Stdlib Require Import Utf8 List.
(** * 1. Commutative Monoid — additive structure, shared by R and V *)
HB.mixin Record IsCommutativeMonoid V := {
zero : V;
add : V -> V -> V;
addA : forall x y z : V, add (add x y) z = add x (add y z);
addC : forall x y : V, add x y = add y x;
add0r : forall x : V, add zero x = x;
addr0 : forall x : V, add x zero = x;
}.
HB.structure Definition CommutativeMonoid := { V of IsCommutativeMonoid V }.
Module CMonoidNotations.
Notation "x ⊕ y" := (add x y) (at level 50, left associativity).
Notation "0V" := zero.
End CMonoidNotations.
(** * 2. Semiring = CommutativeMonoid (additive) + multiplicative + distrib *)
HB.mixin Record IsSemiring R of CommutativeMonoid R := {
one : R;
mul : R -> R -> R;
mulA : forall a b c : R, mul (mul a b) c = mul a (mul b c);
mul1r : forall a : R, mul one a = a;
mulr1 : forall a : R, mul a one = a;
mulDr : forall a b c : R, mul (add a b) c = add (mul a c) (mul b c);
mulDl : forall a b c : R, mul a (add b c) = add (mul a b) (mul a c);
mul0r : forall a : R, mul zero a = zero;
mulr0 : forall a : R, mul a zero = zero;
}.
HB.structure Definition Semiring :=
{ R of IsSemiring R & CommutativeMonoid R }.
Module SemiringNotations.
Notation "a + b" := (add a b) (at level 50, left associativity).
Notation "a * b" := (mul a b) (at level 40, left associativity).
Notation "0" := zero.
Notation "1" := one.
End SemiringNotations.
(** * 3. Commutative Semiring (extends Semiring) *)
HB.mixin Record IsCommutativeSemiring R of Semiring R := {
mulC : forall a b : R, mul a b = mul b a;
}.
HB.structure Definition CommutativeSemiring :=
{ R of IsCommutativeSemiring R & Semiring R }.
(** * 4. Idempotent Semiring (extends Semiring) *)
HB.mixin Record IsIdempotentSemiring R of Semiring R := {
add_idem : forall a : R, add a a = a;
}.
HB.structure Definition IdempotentSemiring :=
{ R of IsIdempotentSemiring R & Semiring R }.
(** * 5. Bounded Semiring (extends Semiring) *)
HB.mixin Record IsBoundedSemiring R of Semiring R := {
add_bound : forall a : R, add one a = one;
}.
HB.structure Definition BoundedSemiring :=
{ R of IsBoundedSemiring R & Semiring R }.
(** 5b. Bounded Commutative Semiring
Combines BoundedSemiring + CommutativeSemiring.
Since both share the Semiring ancestor, mulC and add_bound live
in the same HB sort, so [rewrite mulC] works on bounded semiring
terms directly. *)
HB.structure Definition BoundedCommutativeSemiring :=
{ R of IsBoundedSemiring R & IsCommutativeSemiring R & Semiring R }.
(** * 6. Semimodule (two-sorted, parameterized HB structure) *)
HB.mixin Record IsSemimodule {R : Semiring.type} V
of CommutativeMonoid V := {
scale : R -> V -> V;
scale_distr_v : forall (a : R) (x y : V),
scale a (add x y) = add (scale a x) (scale a y);
scale_distr_r : forall (a b : R) (x : V),
scale (add a b) x = add (scale a x) (scale b x);
scale_assoc : forall (a b : R) (x : V),
scale a (scale b x) = scale (mul a b) x;
scale_one : forall (x : V), scale one x = x;
scale_zero_r : forall (x : V), scale zero x = zero;
scale_zero_v : forall (a : R), scale a zero = zero;
}.
HB.structure Definition Semimodule (R : Semiring.type) :=
{ V of IsSemimodule R V & CommutativeMonoid V }.
Module SemimoduleNotations.
Notation "a ⊙ v" := (scale a v) (at level 40).
End SemimoduleNotations.
(** 7. Finite Type — a type with a decidable, complete, duplicate-free
enumeration of all its elements. *)
HB.mixin Record IsFinType T := {
elements : list T;
elements_nodup : NoDup elements;
elements_complete : forall x : T, In x elements;
elements_two_or_more : (2 <= List.length elements)%nat;
fin_eq_dec : forall x y : T, {x = y} + {x <> y};
}.
HB.structure Definition FinType := { T of IsFinType T }.