malachite_base/num/factorization/
traits.rs

1// Copyright © 2025 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9/// A trait for testing whether a number is prime.
10pub trait IsPrime {
11    fn is_prime(&self) -> bool;
12}
13
14/// A trait for testing whether a number is a square.
15pub trait IsSquare {
16    fn is_square(&self) -> bool;
17}
18
19/// A trait for testing whether a number is a perfect power.
20pub trait IsPower {
21    fn is_power(&self) -> bool;
22}
23
24/// A trait for expessing as number as the power of some number raised to an exponent greater than
25/// 1, if such a representation exists.
26pub trait ExpressAsPower: Sized {
27    fn express_as_power(&self) -> Option<(Self, u64)>;
28}
29
30/// A trait for finding the prime factorization of a number.
31pub trait Factor {
32    type FACTORS;
33
34    fn factor(&self) -> Self::FACTORS;
35}
36
37/// A trait for producing iterators of primes.
38pub trait Primes {
39    type I: Iterator<Item = Self>;
40    type LI: Iterator<Item = Self>;
41
42    fn primes_less_than(n: &Self) -> Self::LI;
43
44    fn primes_less_than_or_equal_to(n: &Self) -> Self::LI;
45
46    fn primes() -> Self::I;
47}
48
49/// A trait for finding a primitive root modulo a prime.
50pub trait PrimitiveRootPrime {
51    type Output;
52
53    fn primitive_root_prime(&self) -> Self::Output;
54}