Skip to main content

feanor_math/
lib.rs

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