algebraeon_rings/integer/
modulo.rs1use super::*;
2
3impl<
4 B: BorrowedStructure<IntegerCanonicalStructure>,
5 BE: BorrowedStructure<EuclideanRemainderQuotientStructure<IntegerCanonicalStructure, B, true>>,
6> CountableSetSignature
7 for MultiplicativeMonoidUnitsStructure<
8 EuclideanRemainderQuotientStructure<IntegerCanonicalStructure, B, true>,
9 BE,
10 >
11{
12 fn generate_all_elements(&self) -> impl Iterator<Item = Self::Set> + Clone {
13 self.list_all_elements().into_iter()
14 }
15}
16
17impl<
18 B: BorrowedStructure<IntegerCanonicalStructure>,
19 BE: BorrowedStructure<EuclideanRemainderQuotientStructure<IntegerCanonicalStructure, B, true>>,
20> FiniteSetSignature
21 for MultiplicativeMonoidUnitsStructure<
22 EuclideanRemainderQuotientStructure<IntegerCanonicalStructure, B, true>,
23 BE,
24 >
25{
26 fn list_all_elements(&self) -> Vec<Self::Set> {
27 let mut units = vec![];
28 let mut u = Integer::from(1);
29 while u < Abs::abs(self.monoid().modulus()) {
30 units.push(u.clone());
31 u += Integer::ONE;
32 }
33 units
34 }
35}
36
37impl<B: BorrowedStructure<IntegerCanonicalStructure>> FiniteFieldSignature
38 for EuclideanRemainderQuotientStructure<IntegerCanonicalStructure, B, true>
39{
40 fn characteristic_and_power(&self) -> (Natural, Natural) {
41 (Abs::abs(self.modulus()), Natural::ONE)
42 }
43}
44
45impl<B: BorrowedStructure<IntegerCanonicalStructure>, const IS_FIELD: bool> CountableSetSignature
46 for EuclideanRemainderQuotientStructure<IntegerCanonicalStructure, B, IS_FIELD>
47{
48 fn generate_all_elements(&self) -> impl Iterator<Item = Self::Set> + Clone {
49 (0usize..)
50 .map(Integer::from)
51 .take_while(|n| n < self.modulus())
52 }
53}
54
55impl<B: BorrowedStructure<IntegerCanonicalStructure>, const IS_FIELD: bool> FiniteSetSignature
56 for EuclideanRemainderQuotientStructure<IntegerCanonicalStructure, B, IS_FIELD>
57{
58 fn size(&self) -> usize {
59 Abs::abs(self.modulus()).try_into().unwrap()
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn count_elements() {
69 assert_eq!(
70 Integer::structure()
71 .into_quotient_ring(26.into())
72 .list_all_elements()
73 .len(),
74 26
75 );
76 }
77}