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