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
#[macro_export]
macro_rules! ring_operation {
($field:ident, $p:ident, $g:ident, $r:ident, $r2:ident, $r3:ident, $inv:ident) => {
group_operation!($field, $p, $g, $r, $r2, $r3, $inv);
impl Ring for $field {
const MULTIPLICATIVE_IDENTITY: $field = $field::one();
fn one() -> Self {
Self::MULTIPLICATIVE_IDENTITY
}
}
impl Default for $field {
fn default() -> Self {
$field::one()
}
}
impl PartialOrd for $field {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
fn lt(&self, other: &Self) -> bool {
for (a, b) in self.0.iter().rev().zip(other.0.iter().rev()) {
if a != b {
return a < b;
}
}
false
}
fn le(&self, other: &Self) -> bool {
for (a, b) in self.0.iter().rev().zip(other.0.iter().rev()) {
if a != b {
return a < b;
}
}
true
}
fn gt(&self, other: &Self) -> bool {
for (a, b) in self.0.iter().rev().zip(other.0.iter().rev()) {
if a != b {
return a > b;
}
}
false
}
fn ge(&self, other: &Self) -> bool {
for (a, b) in self.0.iter().rev().zip(other.0.iter().rev()) {
if a != b {
return a > b;
}
}
true
}
}
impl Ord for $field {
fn cmp(&self, other: &Self) -> Ordering {
for (a, b) in self.0.iter().rev().zip(other.0.iter().rev()) {
if a < b {
return Ordering::Less;
} else if a > b {
return Ordering::Greater;
}
}
Ordering::Equal
}
}
};
}
pub use ring_operation;