feanor_math/
lib.rs

1#![allow(non_snake_case)]
2#![allow(non_camel_case_types)]
3#![allow(rustdoc::private_intra_doc_links)]
4
5#![warn(
6    // missing_debug_implementations,
7    unused_extern_crates,
8    unused_import_braces,
9    // unused_qualifications,
10    unused_results,
11    // missing_docs
12)]
13
14#![feature(associated_type_defaults)]
15#![feature(btree_cursors)]
16#![feature(test)]
17#![feature(min_specialization)]
18#![feature(maybe_uninit_slice)]
19#![feature(allocator_api)]
20#![feature(fn_traits)]
21#![feature(iter_advance_by)]
22#![feature(mapped_lock_guards)]
23#![feature(unboxed_closures)]
24#![feature(ptr_alignment_type)]
25#![feature(never_type)]
26#![feature(array_chunks)]
27#![feature(doc_cfg)]
28#![feature(int_roundings)]
29
30#![doc = include_str!("../Readme.md")]
31
32#[cfg(test)]
33extern crate test;
34
35const MAX_PROBABILISTIC_REPETITIONS: usize = 30;
36const DEFAULT_PROBABILISTIC_REPETITIONS: usize = 30;
37
38#[cfg(test)]
39const RANDOM_TEST_INSTANCE_COUNT: usize = 10;
40
41macro_rules! static_assert_impls {
42    ($type:ty: $trait:tt) => {
43        {
44            fn assert_impls<T>() where T: ?Sized + $trait {}
45            assert_impls::<$type>();
46        }
47    };
48}
49
50///
51/// Contains [`unstable_sealed::UnstableSealed`] to mark a trait "sealed" on stable.
52/// 
53#[stability::unstable(feature = "enable")]
54pub mod unstable_sealed {
55
56    ///
57    /// Marks a trait as "sealed" on stable. In other words, using this trait
58    /// as supertrait for another trait within `feanor-math` means that implementing
59    /// the subtrait for new types is unstable, and only available when `unstable-enable`
60    /// is active.
61    /// 
62    pub trait UnstableSealed {}
63}
64
65mod unsafe_any;
66mod lazy;
67
68///
69/// Contains [`computation::ComputationController`] to observe long-running computations.
70/// 
71#[macro_use]
72pub mod computation;
73///
74/// Contains the core traits of the library - [`ring::RingBase`] and [`ring::RingStore`].
75/// 
76#[macro_use]
77pub mod ring;
78///
79/// Contains the trait [`delegate::DelegateRing`] that simplifies implementing the 
80/// newtype-pattern for rings.
81/// 
82pub mod delegate;
83///
84/// Contains different traits for sequences of elements, namely [`seq::VectorView`] and [`seq::VectorFn`]. 
85/// They all have some functional overlap with [`ExactSizeIterator`], but differ in how they allow
86/// access to the elements of the sequence.
87/// 
88pub mod seq;
89///
90/// Contains the trait [`divisibility::DivisibilityRing`] for rings that provide information
91/// about divisibility of their elements.
92/// 
93pub mod divisibility;
94///
95/// Contains the trait [`field::Field`] for rings that are fields.
96/// 
97pub mod field;
98///
99/// Contains the trait [`pid::PrincipalIdealRing`] for rings in whom every ideal is principal.
100/// Also contains [`pid::EuclideanRing`], which is the simplest way how a ring can become a
101/// principal idea ring.
102/// 
103pub mod pid;
104///
105/// Contains the core of `feanor-math`'s (currently) minimalistic approach to matrices. In particular,
106/// we use [`matrix::Submatrix`] and [`matrix::SubmatrixMut`] for matrices that don't own their data.
107/// 
108pub mod matrix;
109///
110/// Contains the trait [`ordered::OrderedRing`] for rings with a total ordering that is compatible
111/// with the ring operations.
112/// 
113pub mod ordered;
114///
115/// Provides the ring implementation [`primitive_int::StaticRing`] that represents the integer ring
116/// with arithmetic given by the primitive integer types ``i8` to `i128`.
117/// 
118pub mod primitive_int;
119///
120/// Contains the trait [`integer::IntegerRing`] for rings that represent the ring of integers `Z`.
121/// 
122pub mod integer;
123///
124/// A collection of all number-theoretic algorithms that are currently implemented in
125/// this crate.
126/// 
127pub mod algorithms;
128///
129/// A collection of various more complicated ring traits and implementations, in particular
130/// arbitrary-precision integer rings, the integer quotients `Z/nZ` or polynomial rings.
131/// 
132pub mod rings;
133///
134/// Ccontains the struct [`wrapper::RingElementWrapper`] that contains an element together with its ring,
135/// and thus can provide ring operations without explicit access to the ring.
136/// 
137/// Using this is for example necessary if you want to use elements of a [`crate::ring::HashableElRing`]-ring
138/// as elements in a [`std::collections::HashSet`].
139/// ```
140/// # use feanor_math::ring::*;
141/// # use feanor_math::homomorphism::*;
142/// # use feanor_math::wrapper::*;
143/// # use feanor_math::integer::*;
144/// # use std::collections::HashSet;
145/// 
146/// let mut set = HashSet::new();
147/// set.insert(RingElementWrapper::new(BigIntRing::RING, BigIntRing::RING.int_hom().map(3)));
148/// assert!(set.contains(&RingElementWrapper::new(BigIntRing::RING, BigIntRing::RING.int_hom().map(3))));
149/// ```
150/// 
151pub mod wrapper;
152///
153/// Contains the trait [`homomorphism::Homomorphism`], [`homomorphism::CanHomFrom`] and
154/// others that are the foundation of the homomorphism framework, that enables mapping
155/// elements between different rings.
156/// 
157pub mod homomorphism;
158///
159/// Contains implementations of various iterators and combinators, like [`iters::powerset()`]
160/// or [`iters::multi_cartesian_product`].
161/// 
162pub mod iters;
163///
164/// Contains the trait [`local::PrincipalLocalRing`] for principal ideal rings that additionally are local,
165/// i.e. they have a unique maximal ideal (which then is generated by a single element).
166/// 
167pub mod local;
168///
169/// Contains the trait [`serialization::SerializableElementRing`] for rings whose elements can be serialized
170/// by using `serde`. 
171/// 
172/// It also contains some utilities to simplify this, since it is usually not possible to use 
173/// `#[derive(Serialize, Deserialize)]` to implement serialization - the reason is that serialization and
174/// deserialization usually require access to the ring. Hence, we need to use [`serde::de::DeserializeSeed`],
175/// but this is incompatible with `#[derive]`
176/// 
177pub mod serialization;
178///
179/// Contains a workaround for specialization.
180/// 
181pub mod specialization;
182///
183/// Contains the trait [`compute_locally::EvaluatePolyLocallyRing`] and related traits for computing
184/// the evaluation of a polynomial over a ring via its evaluations modulo different prime ideals.
185/// 
186/// Note that here (and in `feanor-math` generally), the term "local" is used to refer to algorithms
187/// that work modulo prime ideals (or their powers), which is different from the mathematical concept
188/// of localization.
189/// 
190pub mod compute_locally;