inertia_algebra/structures/
ringlike.rs

1use crate::*;
2
3/// A **ring** is the combination of an Abelian group and a multiplicative monoid 
4/// structure.
5///
6/// A ring is equipped with:
7///
8/// * An abstract operator (usually the addition, "+") that fulfills the constraints 
9/// of an Abelian group.
10///
11///     *An Abelian group is a set with a closed commutative and associative addition 
12///     with the divisibility property and an identity element.*
13/// * A second abstract operator (usually the multiplication, "×") that fulfills the 
14/// constraints of a monoid.
15///
16///     *A set equipped with a closed associative multiplication with the divisibility 
17///     property and an identity element.*
18///
19/// The multiplication is distributive over the addition:
20///
21/// # Distributivity
22///
23/// ~~~notrust
24/// a, b, c ∈ Self, a × (b + c) = a × b + a × c.
25/// ~~~
26pub trait AbstractNCRing<A: Operator = Additive, M: Operator = Multiplicative>:
27    AbstractGroupAbelian<A, Element=<Self as AbstractNCRing<A, M>>::Element> 
28    + AbstractMonoid<M, Element=<Self as AbstractNCRing<A, M>>::Element>
29    + Distributive<A, M>
30{
31    type Element: AbstractNCRingElement<A, M, Parent=Self>;
32    fn is_abstract_ncring(&self, _: A, _: M) -> bool { true }
33}
34
35pub trait AbstractNCRingElement<A: Operator = Additive, M: Operator = Multiplicative>:
36    AbstractGroupAbelianElement<A, Parent=<Self as AbstractNCRingElement<A, M>>::Parent> 
37    + AbstractMonoidElement<M, Parent=<Self as AbstractNCRingElement<A, M>>::Parent>
38{
39    type Parent: AbstractNCRing<A, M, Element=Self>;
40}
41
42impl<Par, Elem, A: Operator, M: Operator> AbstractNCRing<A, M> for Par
43where
44    Par: AbstractGroupAbelian<A, Element=Elem>
45    + AbstractMonoid<M, Element=Elem>
46    + Distributive<A, M>,
47    Elem: AbstractGroupAbelianElement<A, Parent=Par>
48    + AbstractMonoidElement<M, Parent=Par>
49{
50    type Element = Elem;
51}
52
53impl<Par, Elem, A: Operator, M: Operator> AbstractNCRingElement<A, M> for Elem
54where
55    Elem: AbstractGroupAbelianElement<A, Parent=Par>
56    + AbstractMonoidElement<M, Parent=Par>,
57    Par: AbstractGroupAbelian<A, Element=Elem>
58    + AbstractMonoid<M, Element=Elem>
59    + Distributive<A, M>
60{
61    type Parent = Par;
62}
63
64/// A ring with a commutative multiplication.
65///
66/// *A **commutative ring** is a set with two binary operations: a closed commutative and associative with the divisibility property and an identity element,
67/// and another closed associative and **commutative** with the divisibility property and an identity element.*
68///
69/// # Commutativity
70///
71/// ```notrust
72/// ∀ a, b ∈ Self, a × b = b × a
73/// ```
74pub trait AbstractRing<A: Operator = Additive, M: Operator = Multiplicative>:
75    AbstractNCRing<A, M, Element=<Self as AbstractRing<A, M>>::Element>
76    + Commutative<M>
77{
78    type Element: AbstractRingElement<A, M, Parent=Self>;
79    fn is_abstract_ring(&self, _: A, _: M) -> bool { true }
80}
81
82pub trait AbstractRingElement<A: Operator = Additive, M: Operator = Multiplicative>:
83    AbstractNCRingElement<A, M, Parent=<Self as AbstractRingElement<A, M>>::Parent>
84{
85    type Parent: AbstractRing<A, M, Element=Self>;
86}
87
88impl<Par, Elem, A: Operator, M: Operator> AbstractRing<A, M> for Par
89where
90    Par: AbstractNCRing<A, M, Element=Elem> + Commutative<M>,
91    Elem: AbstractNCRingElement<A, M, Parent=Par>
92{
93    type Element = Elem;
94}
95
96impl<Par, Elem, A: Operator, M: Operator> AbstractRingElement<A, M> for Elem
97where
98    Elem: AbstractNCRingElement<A, M, Parent=Par>,
99    Par: AbstractNCRing<A, M, Element=Elem> + Commutative<M>
100{
101    type Parent = Par;
102}
103
104/// A field is a commutative ring, and an Abelian group under both operators.
105///
106/// *A **field** is a set with two binary operations, an addition and a multiplication, which are both closed, commutative, associative
107/// possess the divisibility property and an identity element, noted 0 and 1 respectively. Furthermore the multiplication is distributive
108/// over the addition.*
109pub trait AbstractField<A: Operator = Additive, M: Operator = Multiplicative>:
110    AbstractRing<A, M, Element=<Self as AbstractField<A, M>>::Element>
111    + Divisible<M>
112{
113    type Element: AbstractFieldElement<A, M, Parent=Self>;
114    fn is_abstract_field(&self, _: A, _: M) -> bool { true }
115}
116
117pub trait AbstractFieldElement<A: Operator = Additive, M: Operator = Multiplicative>:
118    AbstractRingElement<A, M, Parent=<Self as AbstractFieldElement<A, M>>::Parent> 
119    + TwoSidedInverse<M>
120{
121    type Parent: AbstractField<A, M, Element=Self>;
122}
123
124impl<Par, Elem, A: Operator, M: Operator> AbstractField<A, M> for Par
125where
126    Par: AbstractRing<A, M, Element=Elem> 
127    + Divisible<M>,
128    Elem: AbstractRingElement<A, M, Parent=Par> 
129    + TwoSidedInverse<M>
130{
131    type Element = Elem;
132}
133
134impl<Par, Elem, A: Operator, M: Operator> AbstractFieldElement<A, M> for Elem
135where
136    Elem: AbstractRingElement<A, M, Parent=Par> 
137    + TwoSidedInverse<M>,
138    Par: AbstractRing<A, M, Element=Elem>
139    + Divisible<M>
140{
141    type Parent = Par;
142}