feanor_math/
lib.rs

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