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 finding the prime factorization of a number.
15pub trait Factor {
16    type FACTORS;
17
18    fn factor(&self) -> Self::FACTORS;
19}
20
21/// A trait for producing iterators of primes.
22pub trait Primes {
23    type I: Iterator<Item = Self>;
24    type LI: Iterator<Item = Self>;
25
26    fn primes_less_than(n: &Self) -> Self::LI;
27
28    fn primes_less_than_or_equal_to(n: &Self) -> Self::LI;
29
30    fn primes() -> Self::I;
31}
32
33/// A trait for finding a primitive root modulo a prime.
34pub trait PrimitiveRootPrime {
35    type Output;
36
37    fn primitive_root_prime(&self) -> Self::Output;
38}