2 #ifndef _BPAS_INTEGER_H_ 3 #define _BPAS_INTEGER_H_ 5 #include "BPASEuclideanDomain.hpp" 120 template <
class Ring>
123 inline mpz_class& get_mpz_ref() {
127 inline const mpz_class& get_mpz_ref()
const {
131 inline mpz_class get_mpz ()
const {
135 inline mpz_ptr get_mpz_t() {
136 return _m.get_mpz_t();
139 inline mpz_srcptr get_mpz_t()
const {
140 return _m.get_mpz_t();
144 inline double get_d()
const {
148 inline long int get_si()
const {
152 inline unsigned long int get_ui()
const {
272 mpz_neg(ret._m.get_mpz_t(), _m.get_mpz_t());
298 mpz_pow_ui(r._m.get_mpz_t(), _m.get_mpz_t(), (
unsigned long int) e);
316 return (mpz_cmp(_m.get_mpz_t(), i._m.get_mpz_t()) == 0);
325 return (mpz_cmp(_m.get_mpz_t(), i._m.get_mpz_t()) != 0);
328 inline bool operator< (
const Integer& r)
const {
332 inline bool operator<= (
const Integer& r)
const {
336 inline bool operator> (
const Integer& r)
const {
340 inline bool operator>= (
const Integer& r)
const {
368 if (mpz_divisible_p(_m.get_mpz_t(), i._m.get_mpz_t())) {
369 mpz_divexact(_m.get_mpz_t(), _m.get_mpz_t(), i._m.get_mpz_t());
371 std::cerr <<
"BPAS ERROR: Non-exact division in Integer: " << _m <<
" / " << i._m << std::endl;
377 inline bool divisible(
unsigned long int i) {
378 return mpz_divisible_ui_p(_m.get_mpz_t(), i);
396 mpz_gcd(c._m.get_mpz_t(), _m.get_mpz_t(), other._m.get_mpz_t());
403 std::vector<Integer> ret;
404 ret.push_back(*
this);
442 return Integer(mpz_class(a) + r._m);
446 return Integer(mpz_class(a) - r._m);
450 return Integer(mpz_class(a) * r._m);
454 return Integer(mpz_class(a) / r._m);
457 inline friend bool operator<(
int a,
const Integer& r) {
461 inline friend bool operator<=(
int a,
const Integer& r) {
465 inline friend bool operator>(
int a,
const Integer& r) {
469 inline friend bool operator>=(
int a,
const Integer& r) {
474 return Integer(mpz_class(a) + r._m);
478 return Integer(mpz_class(a) - r._m);
482 return Integer(mpz_class(a) * r._m);
486 return Integer(mpz_class(a) / r._m);
493 inline friend bool operator<(
long int a,
const Integer& r) {
497 inline friend bool operator<=(
long int a,
const Integer& r) {
501 inline friend bool operator>(
long int a,
const Integer& r) {
505 inline friend bool operator>=(
long int a,
const Integer& r) {
Integer operator-() const
Negation.
Definition: Integer.hpp:270
Integer & operator-=(const Integer &i)
Subtraction assignment.
Definition: Integer.hpp:262
Integer extendedEuclidean(const Integer &b, Integer *s=NULL, Integer *t=NULL) const
Perform the extended euclidean division on *this and b.
A sparsely represented univariate polynomial over an arbitrary ring.
Definition: BigPrimeField.hpp:21
void negativeOne()
Assign to negative one.
Definition: Integer.hpp:206
Integer operator/(const Integer &i) const
Exact division.
Definition: Integer.hpp:357
Integer quotient(const Integer &b) const
Get the quotient of *this and b.
Integer()
Get a zero integer.
An arbitrary-precision complex rational number.
Definition: ComplexRationalNumber.hpp:23
Integer operator+(const Integer &i) const
Addition.
Definition: Integer.hpp:236
Integer & operator/=(const Integer &i)
Exact division assignment.
Definition: Integer.hpp:367
An ExpressionTree encompasses various forms of data that can be expressed generically as a binary tre...
Definition: ExpressionTree.hpp:17
Integer euclideanSize() const
Get the euclidean size of *this.
Definition: Integer.hpp:411
A finite field whose prime should be a generalized fermat number.
Definition: GeneralizedFermatPrimeField.hpp:36
Integer unitCanonical(Integer *u=NULL, Integer *v=NULL) const
Obtain the unit normal (a.k.a canonical associate) of an element.
A prime field whose prime is 32 bits or less.
Definition: SmallPrimeField.hpp:450
A univariate polynomial with Integer coefficients using a dense representation.
Definition: uzpolynomial.h:14
bool operator!=(const Integer &i) const
Inequality test,.
Definition: Integer.hpp:324
Integer & operator*=(const Integer &i)
Multiplication assignment.
Definition: Integer.hpp:288
A univariate polynomial with RationalNumber coefficients represented densely.
Definition: urpolynomial.h:16
bool operator==(const Integer &i) const
Equality test,.
Definition: Integer.hpp:315
Integer remainder(const Integer &b) const
Get the remainder of *this and b.
A prime field whose prime can be arbitrarily large.
Definition: BigPrimeField.hpp:27
bool isNegativeOne() const
Is a -1.
Definition: Integer.hpp:197
int isConstant() const
Is a constant.
Definition: Integer.hpp:215
Integer gcd(const Integer &other) const
Get GCD of *this and other.
Definition: Integer.hpp:394
Integer & operator^=(long long int e)
Exponentiation assignment.
Definition: Integer.hpp:305
A simple data structure for encapsulating a collection of Factor elements.
Definition: Factors.hpp:95
ExpressionTree convertToExpressionTree() const
Convert this to an expression tree.
Definition: Integer.hpp:349
Integer & operator%=(const Integer &r)
Assign *this to be the remainder of *this and b.
Definition: Integer.hpp:386
An arbitrary-precision Integer.
Definition: Integer.hpp:22
Integer & operator=(const Integer &a)
Copy assignment.
Integer operator%(const Integer &r) const
Get the remainder of *this and b;.
Definition: Integer.hpp:381
Integer & operator+=(const Integer &i)
Addition assignment.
Definition: Integer.hpp:245
An abstract class defining the interface of a Euclidean domain.
Definition: BPASEuclideanDomain.hpp:14
An arbitrary-precision rational number.
Definition: RationalNumber.hpp:24
Factors< Integer > squareFree() const
Compute squarefree factorization of *this.
Definition: Integer.hpp:402
Integer operator^(long long int e) const
Exponentiation.
Definition: Integer.hpp:296
void zero()
Assign to zero.
Definition: Integer.hpp:170
Integer euclideanDivision(const Integer &b, Integer *q=NULL) const
Perform the eucldiean division of *this and b.
ExprTreeNode is a single node in the bianry tree of an ExpressionTree.
Definition: ExprTreeNode.hpp:76
bool isZero() const
Is a zero.
Definition: Integer.hpp:161
Integer operator*(const Integer &i) const
Multiplication.
Definition: Integer.hpp:279
bool isOne() const
Is a 1.
Definition: Integer.hpp:179
void one()
Assign to one.
Definition: Integer.hpp:188