⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zz_pex.h

📁 密码大家Shoup写的数论算法c语言实现
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef NTL_ZZ_pEX__H#define NTL_ZZ_pEX__H#include <NTL/vec_ZZ_pE.h>NTL_OPEN_NNSclass ZZ_pEX {public:vec_ZZ_pE rep;/***************************************************************          Constructors, Destructors, and Assignment****************************************************************/ZZ_pEX()//  initial value 0   { }ZZ_pEX(INIT_SIZE_TYPE, long n) { rep.SetMaxLength(n); }~ZZ_pEX() { }void normalize();// strip leading zerosvoid SetMaxLength(long n) // pre-allocate space for n coefficients.// Value is unchanged   { rep.SetMaxLength(n); }void kill() // free space held by this polynomial.  Value becomes 0.   { rep.kill(); }static const ZZ_pEX& zero();inline ZZ_pEX(long i, const ZZ_pE& c);inline ZZ_pEX(long i, const ZZ_p& c);inline ZZ_pEX(long i, long c);inline ZZ_pEX& operator=(long a);inline ZZ_pEX& operator=(const ZZ_p& a);inline ZZ_pEX& operator=(const ZZ_pE& a);ZZ_pEX(ZZ_pEX& x, INIT_TRANS_TYPE) : rep(x.rep, INIT_TRANS) { }};NTL_SNS istream& operator>>(NTL_SNS istream& s, ZZ_pEX& x);NTL_SNS ostream& operator<<(NTL_SNS ostream& s, const ZZ_pEX& a);/**********************************************************                   Some utility routines***********************************************************/inline long deg(const ZZ_pEX& a) { return a.rep.length() - 1; }// degree of a polynomial.// note that the zero polynomial has degree -1.const ZZ_pE& coeff(const ZZ_pEX& a, long i);// zero if i not in rangeconst ZZ_pE& LeadCoeff(const ZZ_pEX& a);// zero if a == 0const ZZ_pE& ConstTerm(const ZZ_pEX& a);// zero if a == 0void SetCoeff(ZZ_pEX& x, long i, const ZZ_pE& a);void SetCoeff(ZZ_pEX& x, long i, const ZZ_p& a);void SetCoeff(ZZ_pEX& x, long i, long a);// x[i] = a, error is raised if i < 0inline ZZ_pEX::ZZ_pEX(long i, const ZZ_pE& a)   { SetCoeff(*this, i, a); }inline ZZ_pEX::ZZ_pEX(long i, const ZZ_p& a)   { SetCoeff(*this, i, a); }inline ZZ_pEX::ZZ_pEX(long i, long a)   { SetCoeff(*this, i, a); }void SetCoeff(ZZ_pEX& x, long i);// x[i] = 1, error is raised if i < 0void SetX(ZZ_pEX& x);// x is set to the monomial Xlong IsX(const ZZ_pEX& a);// test if x = Xinline void clear(ZZ_pEX& x) // x = 0   { x.rep.SetLength(0); }inline void set(ZZ_pEX& x)// x = 1   { x.rep.SetLength(1); set(x.rep[0]); }inline void swap(ZZ_pEX& x, ZZ_pEX& y)// swap x & y (only pointers are swapped)   { swap(x.rep, y.rep); }void random(ZZ_pEX& x, long n);inline ZZ_pEX random_ZZ_pEX(long n)   { ZZ_pEX x; random(x, n); NTL_OPT_RETURN(ZZ_pEX, x); }// generate a random polynomial of degree < n void trunc(ZZ_pEX& x, const ZZ_pEX& a, long m);inline ZZ_pEX trunc(const ZZ_pEX& a, long m)   { ZZ_pEX x; trunc(x, a, m);  NTL_OPT_RETURN(ZZ_pEX, x); }// x = a % X^mvoid RightShift(ZZ_pEX& x, const ZZ_pEX& a, long n);inline ZZ_pEX RightShift(const ZZ_pEX& a, long n)   { ZZ_pEX x; RightShift(x, a, n);  NTL_OPT_RETURN(ZZ_pEX, x); }// x = a/X^nvoid LeftShift(ZZ_pEX& x, const ZZ_pEX& a, long n);inline ZZ_pEX LeftShift(const ZZ_pEX& a, long n)   { ZZ_pEX x; LeftShift(x, a, n);  NTL_OPT_RETURN(ZZ_pEX, x); }// x = a*X^n#ifndef NTL_TRANSITIONinline ZZ_pEX operator>>(const ZZ_pEX& a, long n)   { ZZ_pEX x; RightShift(x, a, n); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator<<(const ZZ_pEX& a, long n)   { ZZ_pEX x; LeftShift(x, a, n); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX& operator<<=(ZZ_pEX& x, long n)   { LeftShift(x, x, n); return x; }inline ZZ_pEX& operator>>=(ZZ_pEX& x, long n)   { RightShift(x, x, n); return x; }#endifvoid diff(ZZ_pEX& x, const ZZ_pEX& a);inline ZZ_pEX diff(const ZZ_pEX& a)   { ZZ_pEX x; diff(x, a);  NTL_OPT_RETURN(ZZ_pEX, x); }// x = derivative of avoid MakeMonic(ZZ_pEX& x);void reverse(ZZ_pEX& c, const ZZ_pEX& a, long hi);inline ZZ_pEX reverse(const ZZ_pEX& a, long hi)   { ZZ_pEX x; reverse(x, a, hi); NTL_OPT_RETURN(ZZ_pEX, x); }inline void reverse(ZZ_pEX& c, const ZZ_pEX& a){  reverse(c, a, deg(a)); }inline ZZ_pEX reverse(const ZZ_pEX& a)   { ZZ_pEX x; reverse(x, a); NTL_OPT_RETURN(ZZ_pEX, x); }inline void VectorCopy(vec_ZZ_pE& x, const ZZ_pEX& a, long n)   { VectorCopy(x, a.rep, n); }inline vec_ZZ_pE VectorCopy(const ZZ_pEX& a, long n)   { return VectorCopy(a.rep, n); }/*******************************************************************                        conversion routines********************************************************************/void conv(ZZ_pEX& x, long a);void conv(ZZ_pEX& x, const ZZ& a);void conv(ZZ_pEX& x, const ZZ_p& a);void conv(ZZ_pEX& x, const ZZ_pX& a);void conv(ZZ_pEX& x, const ZZ_pE& a);void conv(ZZ_pEX& x, const vec_ZZ_pE& a);inline ZZ_pEX to_ZZ_pEX(long a)   { ZZ_pEX x; conv(x, a); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX to_ZZ_pEX(const ZZ& a)   { ZZ_pEX x; conv(x, a); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX to_ZZ_pEX(const ZZ_p& a)   { ZZ_pEX x; conv(x, a); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX to_ZZ_pEX(const ZZ_pX& a)   { ZZ_pEX x; conv(x, a); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX to_ZZ_pEX(const ZZ_pE& a)   { ZZ_pEX x; conv(x, a); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX to_ZZ_pEX(const vec_ZZ_pE& a)   { ZZ_pEX x; conv(x, a); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX& ZZ_pEX::operator=(long a)   { conv(*this, a); return *this; }inline ZZ_pEX& ZZ_pEX::operator=(const ZZ_p& a)   { conv(*this, a); return *this; }inline ZZ_pEX& ZZ_pEX::operator=(const ZZ_pE& a)   { conv(*this, a); return *this; }/*************************************************************                        Comparison**************************************************************/long IsZero(const ZZ_pEX& a); long IsOne(const ZZ_pEX& a);inline long operator==(const ZZ_pEX& a, const ZZ_pEX& b){ return a.rep == b.rep; }long operator==(const ZZ_pEX& a, long b);long operator==(const ZZ_pEX& a, const ZZ_p& b);long operator==(const ZZ_pEX& a, const ZZ_pE& b);inline long operator==(long a, const ZZ_pEX& b)   { return (b == a); }inline long operator==(const ZZ_p& a, const ZZ_pEX& b)   { return (b == a); }inline long operator==(const ZZ_pE& a, const ZZ_pEX& b)   { return (b == a); }inline long operator!=(const ZZ_pEX& a, const ZZ_pEX& b)   { return !(a == b); }inline long operator!=(const ZZ_pEX& a, long b)   { return !(a == b); }inline long operator!=(const ZZ_pEX& a, const ZZ_p& b)   { return !(a == b); }inline long operator!=(const ZZ_pEX& a, const ZZ_pE& b)   { return !(a == b); }inline long operator!=(const long a, const ZZ_pEX& b)   { return !(a == b); }inline long operator!=(const ZZ_p& a, const ZZ_pEX& b)   { return !(a == b); }inline long operator!=(const ZZ_pE& a, const ZZ_pEX& b)   { return !(a == b); }/***************************************************************                         Addition****************************************************************/void add(ZZ_pEX& x, const ZZ_pEX& a, const ZZ_pEX& b);void sub(ZZ_pEX& x, const ZZ_pEX& a, const ZZ_pEX& b);void negate(ZZ_pEX& x, const ZZ_pEX& a);// scalar versionsvoid add(ZZ_pEX & x, const ZZ_pEX& a, long b); void add(ZZ_pEX & x, const ZZ_pEX& a, const ZZ_p& b); void add(ZZ_pEX & x, const ZZ_pEX& a, const ZZ_pE& b); inline void add(ZZ_pEX& x, const ZZ_pE& a, const ZZ_pEX& b)   { add(x, b, a); }inline void add(ZZ_pEX& x, const ZZ_p& a, const ZZ_pEX& b)   { add(x, b, a); }inline void add(ZZ_pEX& x, long a, const ZZ_pEX& b)   { add(x, b, a); }void sub(ZZ_pEX & x, const ZZ_pEX& a, long b); void sub(ZZ_pEX & x, const ZZ_pEX& a, const ZZ_p& b); void sub(ZZ_pEX & x, const ZZ_pEX& a, const ZZ_pE& b); void sub(ZZ_pEX& x, const ZZ_pE& a, const ZZ_pEX& b);void sub(ZZ_pEX& x, const ZZ_p& a, const ZZ_pEX& b);void sub(ZZ_pEX& x, long a, const ZZ_pEX& b);inline ZZ_pEX operator+(const ZZ_pEX& a, const ZZ_pEX& b)   { ZZ_pEX x; add(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator+(const ZZ_pEX& a, const ZZ_pE& b)   { ZZ_pEX x; add(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator+(const ZZ_pEX& a, const ZZ_p& b)   { ZZ_pEX x; add(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator+(const ZZ_pEX& a, long b)   { ZZ_pEX x; add(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator+(const ZZ_pE& a, const ZZ_pEX& b)   { ZZ_pEX x; add(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator+(const ZZ_p& a, const ZZ_pEX& b)   { ZZ_pEX x; add(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator+(long a, const ZZ_pEX& b)   { ZZ_pEX x; add(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator-(const ZZ_pEX& a, const ZZ_pEX& b)   { ZZ_pEX x; sub(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator-(const ZZ_pEX& a, const ZZ_pE& b)   { ZZ_pEX x; sub(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator-(const ZZ_pEX& a, const ZZ_p& b)   { ZZ_pEX x; sub(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator-(const ZZ_pEX& a, long b)   { ZZ_pEX x; sub(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator-(const ZZ_pE& a, const ZZ_pEX& b)   { ZZ_pEX x; sub(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator-(const ZZ_p& a, const ZZ_pEX& b)   { ZZ_pEX x; sub(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator-(long a, const ZZ_pEX& b)   { ZZ_pEX x; sub(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX& operator+=(ZZ_pEX& x, const ZZ_pEX& b)   { add(x, x, b); return x; }inline ZZ_pEX& operator+=(ZZ_pEX& x, const ZZ_pE& b)   { add(x, x, b); return x; }inline ZZ_pEX& operator+=(ZZ_pEX& x, const ZZ_p& b)   { add(x, x, b); return x; }inline ZZ_pEX& operator+=(ZZ_pEX& x, long b)   { add(x, x, b); return x; }inline ZZ_pEX& operator-=(ZZ_pEX& x, const ZZ_pEX& b)   { sub(x, x, b); return x; }inline ZZ_pEX& operator-=(ZZ_pEX& x, const ZZ_pE& b)   { sub(x, x, b); return x; }inline ZZ_pEX& operator-=(ZZ_pEX& x, const ZZ_p& b)   { sub(x, x, b); return x; }inline ZZ_pEX& operator-=(ZZ_pEX& x, long b)   { sub(x, x, b); return x; }inline ZZ_pEX operator-(const ZZ_pEX& a)    { ZZ_pEX x; negate(x, a); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX& operator++(ZZ_pEX& x) { add(x, x, 1); return x; }inline void operator++(ZZ_pEX& x, int) { add(x, x, 1); }inline ZZ_pEX& operator--(ZZ_pEX& x) { sub(x, x, 1); return x; }inline void operator--(ZZ_pEX& x, int) { sub(x, x, 1); }/*****************************************************************                        Multiplication******************************************************************/void mul(ZZ_pEX& x, const ZZ_pEX& a, const ZZ_pEX& b);// x = a * bvoid sqr(ZZ_pEX& x, const ZZ_pEX& a);inline ZZ_pEX sqr(const ZZ_pEX& a)    { ZZ_pEX x; sqr(x, a); NTL_OPT_RETURN(ZZ_pEX, x); }// x = a^2void mul(ZZ_pEX & x, const ZZ_pEX& a, long b); void mul(ZZ_pEX & x, const ZZ_pEX& a, const ZZ_p& b); void mul(ZZ_pEX & x, const ZZ_pEX& a, const ZZ_pE& b); inline void mul(ZZ_pEX& x, long a, const ZZ_pEX& b)   { mul(x, b, a); }inline void mul(ZZ_pEX& x, const ZZ_p& a, const ZZ_pEX& b)   { mul(x, b, a); }inline void mul(ZZ_pEX& x, const ZZ_pE& a, const ZZ_pEX& b)   { mul(x, b, a); }void MulTrunc(ZZ_pEX& x, const ZZ_pEX& a, const ZZ_pEX& b, long n);inline ZZ_pEX MulTrunc(const ZZ_pEX& a, const ZZ_pEX& b, long n)   { ZZ_pEX x; MulTrunc(x, a, b, n); NTL_OPT_RETURN(ZZ_pEX, x); }// x = a * b % X^nvoid SqrTrunc(ZZ_pEX& x, const ZZ_pEX& a, long n);inline ZZ_pEX SqrTrunc(const ZZ_pEX& a, long n)   { ZZ_pEX x; SqrTrunc(x, a, n); NTL_OPT_RETURN(ZZ_pEX, x); }// x = a*a % X^ninline ZZ_pEX operator*(const ZZ_pEX& a, const ZZ_pEX& b)   { ZZ_pEX x; mul(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator*(const ZZ_pEX& a, const ZZ_pE& b)   { ZZ_pEX x; mul(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator*(const ZZ_pEX& a, const ZZ_p& b)   { ZZ_pEX x; mul(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator*(const ZZ_pEX& a, long b)   { ZZ_pEX x; mul(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator*(const ZZ_pE& a, const ZZ_pEX& b)   { ZZ_pEX x; mul(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator*(const ZZ_p& a, const ZZ_pEX& b)   { ZZ_pEX x; mul(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX operator*(long a, const ZZ_pEX& b)   { ZZ_pEX x; mul(x, a, b); NTL_OPT_RETURN(ZZ_pEX, x); }inline ZZ_pEX& operator*=(ZZ_pEX& x, const ZZ_pEX& b)   { mul(x, x, b); return x; }inline ZZ_pEX& operator*=(ZZ_pEX& x, const ZZ_pE& b)   { mul(x, x, b); return x; }inline ZZ_pEX& operator*=(ZZ_pEX& x, const ZZ_p& b)   { mul(x, x, b); return x; }inline ZZ_pEX& operator*=(ZZ_pEX& x, long b)   { mul(x, x, b); return x; }void power(ZZ_pEX& x, const ZZ_pEX& a, long e);inline ZZ_pEX power(const ZZ_pEX& a, long e)   { ZZ_pEX x; power(x, a, e); NTL_OPT_RETURN(ZZ_pEX, x); }/*************************************************************                      Division**************************************************************/void DivRem(ZZ_pEX& q, ZZ_pEX& r, const ZZ_pEX& a, const ZZ_pEX& b);// q = a/b, r = a%bvoid div(ZZ_pEX& q, const ZZ_pEX& a, const ZZ_pEX& b);void div(ZZ_pEX& q, const ZZ_pEX& a, const ZZ_pE& b);void div(ZZ_pEX& q, const ZZ_pEX& a, const ZZ_p& b);void div(ZZ_pEX& q, const ZZ_pEX& a, long b);// q = a/bvoid rem(ZZ_pEX& r, const ZZ_pEX& a, const ZZ_pEX& b);// r = a%blong divide(ZZ_pEX& q, const ZZ_pEX& a, const ZZ_pEX& b);// if b | a, sets q = a/b and returns 1; otherwise returns 0long divide(const ZZ_pEX& a, const ZZ_pEX& b);// if b | a, sets q = a/b and returns 1; otherwise returns 0void InvTrunc(ZZ_pEX& x, const ZZ_pEX& a, long m);inline ZZ_pEX InvTrunc(const ZZ_pEX& a, long m)   { ZZ_pEX x; InvTrunc(x, a, m); NTL_OPT_RETURN(ZZ_pEX, x); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -