7 #ifndef SYMENGINE_NTHEORY_H
8 #define SYMENGINE_NTHEORY_H
17 SYMENGINE_EXPORT
int probab_prime_p(
const Integer &a,
unsigned reps = 25);
19 SYMENGINE_EXPORT RCP<const Integer>
nextprime(
const Integer &a);
23 SYMENGINE_EXPORT RCP<const Integer>
gcd(
const Integer &a,
const Integer &b);
25 SYMENGINE_EXPORT RCP<const Integer>
lcm(
const Integer &a,
const Integer &b);
28 void gcd_ext(
const Ptr<RCP<const Integer>> &g,
const Ptr<RCP<const Integer>> &s,
29 const Ptr<RCP<const Integer>> &t,
const Integer &a,
32 SYMENGINE_EXPORT RCP<const Integer>
mod(
const Integer &n,
const Integer &d);
34 SYMENGINE_EXPORT RCP<const Integer>
quotient(
const Integer &n,
39 const Ptr<RCP<const Integer>> &r,
const Integer &a,
42 SYMENGINE_EXPORT RCP<const Integer>
mod_f(
const Integer &n,
const Integer &d);
44 SYMENGINE_EXPORT RCP<const Integer>
quotient_f(
const Integer &n,
49 const Ptr<RCP<const Integer>> &r,
const Integer &a,
53 int mod_inverse(
const Ptr<RCP<const Integer>> &b,
const Integer &a,
58 bool crt(
const Ptr<RCP<const Integer>> &R,
59 const std::vector<RCP<const Integer>> &rem,
60 const std::vector<RCP<const Integer>> &
mod);
63 SYMENGINE_EXPORT RCP<const Integer>
fibonacci(
unsigned long n);
67 void fibonacci2(
const Ptr<RCP<const Integer>> &g,
68 const Ptr<RCP<const Integer>> &s,
unsigned long n);
71 SYMENGINE_EXPORT RCP<const Integer>
lucas(
unsigned long n);
75 void lucas2(
const Ptr<RCP<const Integer>> &g,
const Ptr<RCP<const Integer>> &s,
79 SYMENGINE_EXPORT RCP<const Integer>
binomial(
const Integer &n,
unsigned long k);
82 SYMENGINE_EXPORT RCP<const Integer>
factorial(
unsigned long n);
85 SYMENGINE_EXPORT
bool divides(
const Integer &a,
const Integer &b);
89 SYMENGINE_EXPORT
int factor(
const Ptr<RCP<const Integer>> &f,
const Integer &n,
105 unsigned retries = 5);
110 unsigned retries = 5);
113 SYMENGINE_EXPORT
void prime_factors(std::vector<RCP<const Integer>> &primes,
121 SYMENGINE_EXPORT RCP<const Number>
bernoulli(
unsigned long n);
123 SYMENGINE_EXPORT RCP<const Number>
harmonic(
unsigned long n,
long m = 1);
126 SYMENGINE_EXPORT
bool primitive_root(
const Ptr<RCP<const Integer>> &g,
130 SYMENGINE_EXPORT
void
133 SYMENGINE_EXPORT RCP<const Integer>
totient(
const RCP<const Integer> &n);
136 RCP<const Integer>
carmichael(
const RCP<const Integer> &n);
140 const RCP<const Integer> &a,
141 const RCP<const Integer> &n);
143 SYMENGINE_EXPORT
int legendre(
const Integer &a,
const Integer &n);
145 SYMENGINE_EXPORT
int jacobi(
const Integer &a,
const Integer &n);
147 SYMENGINE_EXPORT
int kronecker(
const Integer &a,
const Integer &n);
151 const RCP<const Integer> &a,
const RCP<const Integer> &n,
152 const RCP<const Integer> &m);
155 bool nthroot_mod(
const Ptr<RCP<const Integer>> &root,
156 const RCP<const Integer> &a,
const RCP<const Integer> &n,
157 const RCP<const Integer> &m);
161 bool powermod(
const Ptr<RCP<const Integer>> &powm,
const RCP<const Integer> &a,
162 const RCP<const Number> &b,
const RCP<const Integer> &m);
167 const RCP<const Integer> &a,
const RCP<const Number> &b,
168 const RCP<const Integer> &m);
174 SYMENGINE_EXPORT
bool is_quad_residue(
const Integer &a,
const Integer &p);
176 SYMENGINE_EXPORT
bool is_nth_residue(
const Integer &a,
const Integer &n,
184 SYMENGINE_EXPORT
int mobius(
const Integer &a);
187 SYMENGINE_EXPORT
long mertens(
const unsigned long a);
191 const integer_class &n);
194 const integer_class &x);
207 std::pair<integer_class, integer_class>
209 bool lowest_exponent =
false);
Main namespace for SymEngine package.
RCP< const Integer > gcd(const Integer &a, const Integer &b)
Greatest Common Divisor.
void fibonacci2(const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, unsigned long n)
Fibonacci n and n-1.
RCP< const Integer > quotient_f(const Integer &n, const Integer &d)
integer_class mp_principal_polygonal_root(const integer_class &s, const integer_class &x)
Numeric calculation of the principal s-gonal root of x.
bool nthroot_mod(const Ptr< RCP< const Integer >> &root, const RCP< const Integer > &a, const RCP< const Integer > &n, const RCP< const Integer > &mod)
A solution to x**n == a mod m. Return false if none exists.
RCP< const Integer > mod_f(const Integer &n, const Integer &d)
modulo round toward -inf
int factor(const Ptr< RCP< const Integer >> &f, const Integer &n, double B1)
RCP< const Number > bernoulli(unsigned long n)
RCP< const Integer > binomial(const Integer &n, unsigned long k)
Binomial Coefficient.
bool primitive_root(const Ptr< RCP< const Integer >> &g, const Integer &n)
Computes a primitive root. Returns false if no primitive root exists.
RCP< const Integer > nextprime(const Integer &a)
RCP< const Integer > quotient(const Integer &n, const Integer &d)
void powermod_list(std::vector< RCP< const Integer >> &pows, const RCP< const Integer > &a, const RCP< const Number > &b, const RCP< const Integer > &m)
vec_integer_class quadratic_residues(const Integer &a)
Finds all Quadratic Residues of a Positive Integer.
integer_class mp_polygonal_number(const integer_class &s, const integer_class &n)
Numeric calculation of the n:th s-gonal number.
void quotient_mod(const Ptr< RCP< const Integer >> &q, const Ptr< RCP< const Integer >> &r, const Integer &n, const Integer &d)
int factor_pollard_rho_method(const Ptr< RCP< const Integer >> &f, const Integer &n, unsigned retries)
Factor using Pollard's rho methods.
std::pair< integer_class, integer_class > mp_perfect_power_decomposition(const integer_class &n, bool lowest_exponent)
Decompose a positive integer into perfect powers.
int factor_pollard_pm1_method(const Ptr< RCP< const Integer >> &f, const Integer &n, unsigned B, unsigned retries)
Factor using Pollard's p-1 method.
int factor_trial_division(const Ptr< RCP< const Integer >> &f, const Integer &n)
RCP< const Integer > fibonacci(unsigned long n)
Fibonacci number.
void nthroot_mod_list(std::vector< RCP< const Integer >> &roots, const RCP< const Integer > &a, const RCP< const Integer > &n, const RCP< const Integer > &m)
All Solutions to x**n == a mod m. Return false if none exists.
RCP< const Integer > carmichael(const RCP< const Integer > &n)
Carmichael function.
bool crt(const Ptr< RCP< const Integer >> &R, const std::vector< RCP< const Integer >> &rem, const std::vector< RCP< const Integer >> &mod)
Chinese remainder function. Return true when a solution exists.
RCP< const Integer > lucas(unsigned long n)
Lucas number.
RCP< const Number > harmonic(unsigned long n, long m)
Computes the sum of the inverses of the first perfect mth powers.
void quotient_mod_f(const Ptr< RCP< const Integer >> &q, const Ptr< RCP< const Integer >> &r, const Integer &n, const Integer &d)
RCP< const Integer > factorial(unsigned long n)
Factorial.
int kronecker(const Integer &a, const Integer &n)
Kronecker Function.
bool multiplicative_order(const Ptr< RCP< const Integer >> &o, const RCP< const Integer > &a, const RCP< const Integer > &n)
Multiplicative order. Return false if order does not exist.
bool divides(const Integer &a, const Integer &b)
void gcd_ext(const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, const Ptr< RCP< const Integer >> &t, const Integer &a, const Integer &b)
Extended GCD.
void lucas2(const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, unsigned long n)
Lucas number n and n-1.
void prime_factor_multiplicities(map_integer_uint &primes_mul, const Integer &n)
Find multiplicities of prime factors of n
void prime_factors(std::vector< RCP< const Integer >> &prime_list, const Integer &n)
Find prime factors of n
RCP< const Integer > totient(const RCP< const Integer > &n)
Euler's totient function.
bool is_nth_residue(const Integer &a, const Integer &n, const Integer &mod)
Returns true if 'a' is a nth power residue of 'mod'.
int factor_lehman_method(const Ptr< RCP< const Integer >> &f, const Integer &n)
Factor using lehman's methods.
void primitive_root_list(std::vector< RCP< const Integer >> &roots, const Integer &n)
bool is_quad_residue(const Integer &a, const Integer &p)
Returns true if 'a' is a quadratic residue of 'p'.
int mobius(const Integer &a)
Mobius Function.
bool powermod(const Ptr< RCP< const Integer >> &powm, const RCP< const Integer > &a, const RCP< const Number > &b, const RCP< const Integer > &m)
int legendre(const Integer &a, const Integer &n)
Legendre Function.
RCP< const Integer > mod(const Integer &n, const Integer &d)
modulo round toward zero
int probab_prime_p(const Integer &a, unsigned reps)
Probabilistic Prime.
int mod_inverse(const Ptr< RCP< const Integer >> &b, const Integer &a, const Integer &m)
inverse modulo
int jacobi(const Integer &a, const Integer &n)
Jacobi Function.
RCP< const Integer > lcm(const Integer &a, const Integer &b)
Least Common Multiple.