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
use std::fmt::Debug;
use std::ops::{Add, Mul, Sub};

/// Represents an associative ring with identity
pub trait RingElement:
    Copy
    + Send
    + Sized
    + Sync
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + Eq
    + Debug
{
    // multiplicative identity
    const ONE: Self;

    // additive identity
    const ZERO: Self;
}

/// Represents a module over a ring:
///
/// The elements of the module is M = R^n
/// The scalar ring is R^n
///
/// We additionally require component-wise multiplication between elements in the module.
pub trait RingModule<S: RingElement>: RingElement {
    const DIMENSION: usize;

    // action of the scalar ring upon the module:
    // s * (r_1, r_2, ..., r_dimension) = (s * r_1, s * r_2, ..., s * r_dimension)
    fn action(&self, s: S) -> Self;

    fn set(&mut self, i: usize, s: S);

    fn get(&self, i: usize) -> S;
}