2 #ifndef _SMALL_PRIME_FIELD_H     3 #define _SMALL_PRIME_FIELD_H     5 #include "BPASFiniteField.hpp"    32     static long int prime;
    37     static mpz_class characteristic;
    38     static bool isPrimeField;
    39     static bool isSmallPrimeField;
    40     static bool isComplexField;
    69         std::cout << 
"BPAS error, try to cast pointer to Rational Number to pointer to SmallPrimeField" << std::endl;
    73         std::cout << 
"BPAS error, try to cast pointer to BigPrimeField to pointer to SmallPrimeField" << std::endl;
    77         std::cout << 
"BPAS error, try to cast pointer to GeneralizedFermatPrimeField to pointer to SmallPrimeField" << std::endl;
    81     static void setPrime(
long int p){
    85         std::ostringstream ss;
    87         std::string sp = ss.str();
   102     void whichprimefield(){
   103         cout << 
"SmallPrimeField" << endl;
   106     long long int number(){
   112         if ( ((prime - 1) % n != 0)){
   113             cout << 
"ERROR: n does not divide prime - 1." << endl;
   117         long int  q = (prime - 1) / n;
   121         long int test = q * n / 2;
   125             if ((c^test) == p1) {
   132             cout << 
"No primitive root found!"<< endl;
   158     inline bool isOne() {
   165     inline bool isNegativeOne() {
   166         return (a == (prime - 1));
   168     inline void negativeOne() {
   172     inline int isConstant() {
   303   void egcd (
long long int x, 
long long int y, 
long long int *ao, 
long long int *bo, 
long long int *vo, 
long long int P){
   304         long long int t, A, B, C, D, u, v, q;
   334     long long int n, b, v;
   335     egcd (a, prime, &n, &b, &v, prime);
   347     long long int v = prime;
   348     long long int x1 = 1;
   349     long long int x2 = 0;
   357                 x1 = (x1 + prime) >> 1;
   364                 x2 = (x2 + prime) >> 1;
   398       std::cout << 
"BPAS: error, dividend is zero from SmallPrimeField."<< std::endl;
   455     static long long int prime;
   457     static unsigned long long int Pp;
   467     static mpz_class characteristic;
   499     template <
class Ring>
   511     long long int number() 
const;
   513     void whichprimefield();
   515     static void setPrime(
long long int p){
   519         std::ostringstream ss;
   521         std::string sp = ss.str();
   528         SmallPrimeField::characteristic = w;
   539       long long int t, A, B, C, D, u, v,q;
   542         "xor %%rax,%%rax\n\t"   548         : 
"=&d" (v),
"=&a" (q)
   581       Pp = (
unsigned long long int)C;
   586         "xor %%rax,%%rax\n\t"   592         "movq %%rax,%%rdx\n\t"   594         : 
"b"((
unsigned long long int)C)
   601     return characteristic;
   604     long long int Prime();
   611         return SmallPrimeField::findPrimitiveRootofUnity(n);
   616         if ( ((prime - 1) % n != 0)){
   617             cout << 
"ERROR: n does not divide prime - 1." << endl;
   621         long long int  q = (prime - 1) / n;
   625         long long int test = q * n / 2;
   629             if ((c^test) == p1) {
   636             cout << 
"No primitive root found!"<< endl;
   661     inline bool isNegativeOne() {
   665     inline void negativeOne() {
   670     inline int isConstant() {
   704     a += (a >> 63) & prime;
   733     a += (a >> 63) & prime;
   767     long long int _a = a;
   770       "movq %%rax,%%rsi\n\t"   771       "movq %%rdx,%%rdi\n\t"   774       "add %%rsi,%%rax\n\t"   775       "adc %%rdi,%%rdx\n\t"   777       "mov %%rdx,%%rax\n\t"   780       "addq %%rax,%%rdx\n\t"   782       : 
"a"(_a),
"rm"(c.a),
"b"((
unsigned long long int)Pp),
"c"(prime)
   789     long long int* pinverse();
   793     static long long int Mont(
long long int b, 
long long int c);
   794   static long long int getRsquare();
   799      long long int rsquare = getRsquare();
   812         printf(
"Not invertible!\n");
   816     long long int* result = r.pinverse();
   818       result[0] = Mont(result[0], rsquare);
   821     result[0] = Mont(result[0], rsquare);
   824       r.a = 1L << (128 - result[1]);
   825       result[0] = Mont(result[0], r.a);
   870         if ((*this).number() == c.number())
   875     inline bool operator== (
long long int k)
 const {
   878         if (b.number() == r.number()){
   887         if ((*this).number() == c.number())
   893     inline bool operator!= (
long long int k)
 const {
   896         if (b.number() == r.number()){
   922             std::cout << 
"BPAS: error, dividend is zero from SmallPrimeField."<< std::endl;
   938     (*this).a  = (*this).a % c.a;
   963         std::vector<SmallPrimeField> ret;
   964         ret.push_back(*
this);
   999 #endif //montgomery switch  1001 #endif //include guard Factors< SmallPrimeField > squareFree() const
Compute squarefree factorization of *this. 
Definition: SmallPrimeField.hpp:962
SmallPrimeField & operator=(const SmallPrimeField &c)
Copy assignment. 
A sparsely represented univariate polynomial over an arbitrary ring. 
Definition: BigPrimeField.hpp:21
SmallPrimeField operator*(const SmallPrimeField &c) const
Multiplication. 
Definition: SmallPrimeField.hpp:742
bool isOne() const
Determine if *this ring element is one, that is the multiplication identity. 
Definition: SmallPrimeField.hpp:651
SmallPrimeField operator/(const SmallPrimeField &c) const
Exact division. 
Definition: SmallPrimeField.hpp:908
SmallPrimeField inverse() const
Get the inverse of *this. 
Definition: SmallPrimeField.hpp:796
SmallPrimeField & operator*=(const SmallPrimeField &c)
Multiplication assignment. 
Definition: SmallPrimeField.hpp:757
void zero()
Make *this ring element zero. 
Definition: SmallPrimeField.hpp:647
An arbitrary-precision complex rational number. 
Definition: ComplexRationalNumber.hpp:23
SmallPrimeField operator^(long long int e) const
Exponentiation. 
Definition: SmallPrimeField.hpp:835
SmallPrimeField euclideanDivision(const SmallPrimeField &b, SmallPrimeField *q=NULL) const
Perform the eucldiean division of *this and b. 
SmallPrimeField operator-() const
Negation. 
Definition: SmallPrimeField.hpp:736
An ExpressionTree encompasses various forms of data that can be expressed generically as a binary tre...
Definition: ExpressionTree.hpp:17
A finite field whose prime should be a generalized fermat number. 
Definition: GeneralizedFermatPrimeField.hpp:36
friend std::ostream & operator<<(std::ostream &ostream, const SmallPrimeField &d)
Output operator. 
Definition: BPASRing.hpp:155
ExpressionTree convertToExpressionTree() const
Convert this to an expression tree. 
Definition: SmallPrimeField.hpp:904
void one()
Make *this ring element one. 
Definition: SmallPrimeField.hpp:656
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
SmallPrimeField gcd(const SmallPrimeField &other) const
Get GCD of *this and other. 
Definition: SmallPrimeField.hpp:942
A univariate polynomial with RationalNumber coefficients represented densely. 
Definition: urpolynomial.h:16
A prime field whose prime can be arbitrarily large. 
Definition: BigPrimeField.hpp:27
bool isZero() const
Determine if *this ring element is zero, that is the additive identity. 
Definition: SmallPrimeField.hpp:643
A simple data structure for encapsulating a collection of Factor elements. 
Definition: Factors.hpp:95
bool operator!=(const SmallPrimeField &c) const
Inequality test,. 
Definition: SmallPrimeField.hpp:886
SmallPrimeField operator%(const SmallPrimeField &c) const
Get the remainder of *this and b;. 
Definition: SmallPrimeField.hpp:933
An arbitrary-precision Integer. 
Definition: Integer.hpp:22
SmallPrimeField & operator^=(long long int e)
Exponentiation assignment. 
Definition: SmallPrimeField.hpp:864
mpz_class getCharacteristic() const override
The characteristic of this ring class. 
Definition: SmallPrimeField.hpp:600
An arbitrary-precision rational number. 
Definition: RationalNumber.hpp:24
SmallPrimeField unitCanonical(SmallPrimeField *u=NULL, SmallPrimeField *v=NULL) const
Obtain the unit normal (a.k.a canonical associate) of an element. 
SmallPrimeField remainder(const SmallPrimeField &b) const
Get the remainder of *this and b. 
An abstract class defining the interface of a field. 
Definition: BPASField.hpp:11
SmallPrimeField & operator/=(const SmallPrimeField &c)
Exact division assignment. 
Definition: SmallPrimeField.hpp:920
SmallPrimeField quotient(const SmallPrimeField &b) const
Get the quotient of *this and b. 
ExprTreeNode is a single node in the bianry tree of an ExpressionTree. 
Definition: ExprTreeNode.hpp:76
An abstract class defining the interface of a prime field. 
Definition: BPASFiniteField.hpp:12
Integer euclideanSize() const
Get the euclidean size of *this. 
Definition: SmallPrimeField.hpp:971
SmallPrimeField operator+(const SmallPrimeField &c) const
Addition. 
Definition: SmallPrimeField.hpp:678
bool operator==(const SmallPrimeField &c) const
Equality test,. 
Definition: SmallPrimeField.hpp:869
SmallPrimeField extendedEuclidean(const SmallPrimeField &b, SmallPrimeField *s=NULL, SmallPrimeField *t=NULL) const
Perform the extended euclidean division on *this and b. 
SmallPrimeField & operator%=(const SmallPrimeField &c)
Assign *this to be the remainder of *this and b. 
Definition: SmallPrimeField.hpp:937