2 #ifndef _GENERALIZED_FERMAT_PRIMT_FIELD_H_ 3 #define _GENERALIZED_FERMAT_PRIMT_FIELD_H_ 5 #include "BPASFiniteField.hpp" 8 typedef unsigned long long int usfixn64;
11 #define ULMAX 18446744073709551615ULL 12 #define SQRTR 3037000502 13 #define RC 9223372019674906624ULL 39 static mpz_class& prime;
44 static mpz_class characteristic;
89 static void setPrime (mpz_class p,usfixn64 R,
int K){
97 return characteristic;
100 void setX (mpz_class a);
102 mpz_class Prime()
const;
104 mpz_class number()
const;
108 static mpz_class power(mpz_class xi, mpz_class yi) {
117 res = (res*xi) % prime;
123 xi = (xi*xi) % prime;
129 return GeneralizedFermatPrimeField::findPrimitiveRootofUnity(n);
132 static mpz_class findPrimitiveRootofUnity_plain(mpz_class n){
133 if ( ((prime - 1) % n != 0)){
134 cout <<
"ERROR: n does not divide prime - 1." << endl;
138 mpz_class q = (prime - 1) / n;
139 mpz_class p1 = prime - 1;
142 mpz_class test = q * n / 2;
151 if (power(c,test) == p1) {
159 cout <<
"No primitive root found!"<< endl;
169 throw std::invalid_argument(
"findPrimitiveRootofUnity error: N is less than 2k");
171 mpz_class g = findPrimitiveRootofUnity_plain(n);
172 mpz_class n2k = n / (2 * k);
173 mpz_class a = power(g, n2k);
175 std::stringstream str;
177 mpz_class r_mpz (str.str());
194 for (
int i = 0; i < k; i++) {
203 memset(x, 0x00, (k) *
sizeof(usfixn64));
207 for (
int i = k - 1;i > 0; i --){
220 for (
int i = k - 1;i > 0; i --){
227 inline bool isNegativeOne()
const {
228 for (
int i = 0; i < (k - 1);i ++){
239 inline void negativeOne() {
240 for (
int i = 0; i < (k - 1); i ++){
246 inline int isConstant()
const {
251 for (
int i = 0; i < k; i++) {
252 if (x[i] != c.x[i]) {
260 inline bool operator== (
const mpz_class& c)
const {
262 for (
int i = 0; i < k; i++) {
263 if (x[i] != b.x[i]) {
272 for (
int i = 0; i < k; i++) {
273 if (x[i] != c.x[i]) {
280 inline bool operator!= (
const mpz_class& c)
const {
282 for (
int i = 0; i < k; i++) {
283 if (x[i] != b.x[i]) {
367 void smallAdd2 (usfixn64 *xm, usfixn64* ym,
short & c);
369 void oneShiftRight (usfixn64 * xs);
372 void mulLong_2 (usfixn64 x, usfixn64 y, usfixn64 &s0,usfixn64 &s1, usfixn64 &s2);
375 void mulLong_3 (usfixn64
const &x, usfixn64
const &y, usfixn64 &s0,
376 usfixn64 &s1, usfixn64 &s2);
378 void multiplication (usfixn64* __restrict__ xs,
const usfixn64* __restrict__ ys,
379 usfixn64 permutationStride, usfixn64* lVector,
380 usfixn64 *hVector, usfixn64* cVector,
381 usfixn64* lVectorSub,
382 usfixn64 *hVectorSub, usfixn64* cVectorSub );
384 void multiplication_step2 (usfixn64* __restrict__ xs, usfixn64 permutationStride,
385 usfixn64* __restrict__ lVector,
386 usfixn64 * __restrict__ hVector,
387 usfixn64* __restrict__ cVector);
420 mpz_class xi = number();
421 mpz_class yi = c.number();
436 void egcd (
const mpz_class& x,
const mpz_class& y, mpz_class *ao, mpz_class *bo, mpz_class *vo, mpz_class P);
439 mpz_class a, n, b, v;
442 egcd (a, prime, &n, &b, &v, prime);
451 mpz_class b (std::to_string(c), 10);
518 std::cout <<
"BPAS: error, dividend is zero from GeneralizedFermatPrimeField."<< std::endl;
548 std::cerr <<
"GeneralizedFermatPrimeField::gcd NOT YET IMPLEMENTED" << std::endl;
557 std::vector<GeneralizedFermatPrimeField> ret;
558 ret.push_back(*
this);
GeneralizedFermatPrimeField & operator^=(long long int c)
Exponentiation assignment.
Definition: GeneralizedFermatPrimeField.hpp:485
GeneralizedFermatPrimeField remainder(const GeneralizedFermatPrimeField &b) const
Get the remainder of *this and b.
A sparsely represented univariate polynomial over an arbitrary ring.
Definition: BigPrimeField.hpp:21
GeneralizedFermatPrimeField operator+(const GeneralizedFermatPrimeField &c) const
Addition.
Definition: GeneralizedFermatPrimeField.hpp:291
An arbitrary-precision complex rational number.
Definition: ComplexRationalNumber.hpp:23
ExpressionTree convertToExpressionTree() const
Convert this to an expression tree.
Definition: GeneralizedFermatPrimeField.hpp:495
GeneralizedFermatPrimeField operator-() const
Negation.
Definition: GeneralizedFermatPrimeField.hpp:361
An ExpressionTree encompasses various forms of data that can be expressed generically as a binary tre...
Definition: ExpressionTree.hpp:17
GeneralizedFermatPrimeField gcd(const GeneralizedFermatPrimeField &a) const
Get GCD of *this and other.
Definition: GeneralizedFermatPrimeField.hpp:547
void zero()
Make *this ring element zero.
Definition: GeneralizedFermatPrimeField.hpp:202
A finite field whose prime should be a generalized fermat number.
Definition: GeneralizedFermatPrimeField.hpp:36
GeneralizedFermatPrimeField quotient(const GeneralizedFermatPrimeField &b) const
Get the quotient of *this and b.
GeneralizedFermatPrimeField operator%(const GeneralizedFermatPrimeField &c) const
Get the remainder of *this and b;.
Definition: GeneralizedFermatPrimeField.hpp:538
GeneralizedFermatPrimeField & operator%=(const GeneralizedFermatPrimeField &c)
Assign *this to be the remainder of *this and b.
Definition: GeneralizedFermatPrimeField.hpp:542
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
GeneralizedFermatPrimeField operator^(long long int c) const
Exponentiation.
Definition: GeneralizedFermatPrimeField.hpp:449
Integer euclideanSize() const
Get the euclidean size of *this.
Definition: GeneralizedFermatPrimeField.hpp:565
bool operator!=(const GeneralizedFermatPrimeField &c) const
Inequality test,.
Definition: GeneralizedFermatPrimeField.hpp:271
bool isZero() const
Determine if *this ring element is zero, that is the additive identity.
Definition: GeneralizedFermatPrimeField.hpp:193
A univariate polynomial with RationalNumber coefficients represented densely.
Definition: urpolynomial.h:16
GeneralizedFermatPrimeField & operator=(const GeneralizedFermatPrimeField &c)
Copy assignment.
A prime field whose prime can be arbitrarily large.
Definition: BigPrimeField.hpp:27
mpz_class getCharacteristic() const override
The characteristic of this ring class.
Definition: GeneralizedFermatPrimeField.hpp:96
A simple data structure for encapsulating a collection of Factor elements.
Definition: Factors.hpp:95
An arbitrary-precision Integer.
Definition: Integer.hpp:22
GeneralizedFermatPrimeField extendedEuclidean(const GeneralizedFermatPrimeField &b, GeneralizedFermatPrimeField *s=NULL, GeneralizedFermatPrimeField *t=NULL) const
Perform the extended euclidean division on *this and b.
bool operator==(const GeneralizedFermatPrimeField &c) const
Equality test,.
Definition: GeneralizedFermatPrimeField.hpp:250
GeneralizedFermatPrimeField inverse() const
Get the inverse of *this.
GeneralizedFermatPrimeField operator*(const GeneralizedFermatPrimeField &c) const
Multiplication.
Definition: GeneralizedFermatPrimeField.hpp:389
GeneralizedFermatPrimeField & operator/=(const GeneralizedFermatPrimeField &c)
Exact division assignment.
Definition: GeneralizedFermatPrimeField.hpp:516
GeneralizedFermatPrimeField unitCanonical(GeneralizedFermatPrimeField *u=NULL, GeneralizedFermatPrimeField *v=NULL) const
Obtain the unit normal (a.k.a canonical associate) of an element.
An arbitrary-precision rational number.
Definition: RationalNumber.hpp:24
Factors< GeneralizedFermatPrimeField > squareFree() const
Compute squarefree factorization of *this.
Definition: GeneralizedFermatPrimeField.hpp:556
bool isOne() const
Determine if *this ring element is one, that is the multiplication identity.
Definition: GeneralizedFermatPrimeField.hpp:206
GeneralizedFermatPrimeField euclideanDivision(const GeneralizedFermatPrimeField &b, GeneralizedFermatPrimeField *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
An abstract class defining the interface of a prime field.
Definition: BPASFiniteField.hpp:12
GeneralizedFermatPrimeField operator/(const GeneralizedFermatPrimeField &c) const
Exact division.
Definition: GeneralizedFermatPrimeField.hpp:499
void one()
Make *this ring element one.
Definition: GeneralizedFermatPrimeField.hpp:219