-
Notifications
You must be signed in to change notification settings - Fork 0
/
ring.rs
31 lines (29 loc) · 856 Bytes
/
ring.rs
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
use num_bigint::BigInt;
use num_traits::{One, Zero};
use std::fmt;
use std::ops::{Add, Mul, Neg, Sub};
pub trait Ring:
Sized
+ Clone
+ PartialEq
+ fmt::Display
+ Add<Output = Self>
+ for<'a> Add<&'a Self, Output = Self>
+ Sub<Output = Self>
+ for<'a> Sub<&'a Self, Output = Self>
+ Mul<Output = Self>
+ for<'a> Mul<&'a Self, Output = Self>
+ Neg<Output = Self>
+ One
+ Zero
{
// A ring is an algebraic structure with addition and multiplication
fn add_ref(&self, rhs: &Self) -> Self;
fn sub_ref(&self, rhs: &Self) -> Self;
fn mul_ref(&self, rhs: &Self) -> Self;
// Utility functions
fn pow<M: Into<BigInt>>(&self, n: M) -> Self;
fn get_value(&self) -> BigInt;
fn from_value<M: Into<BigInt>>(value: M) -> Self;
fn random_element(exclude_elements: &[Self]) -> Self;
}