📄 lzz_pex.txt
字号:
NOTE: A zz_pEX may be used wherever a zz_pEXModulus is required,and a zz_pEXModulus may be used wherever a zz_pEX is required.\**************************************************************************/class zz_pEXModulus {public: zz_pEXModulus(); // initially in an unusable state zz_pEXModulus(const zz_pEX& f); // initialize with f, deg(f) > 0 zz_pEXModulus(const zz_pEXModulus&); // copy zz_pEXModulus& operator=(const zz_pEXModulus&); // assignment ~zz_pEXModulus(); // destructor operator const zz_pEX& () const; // implicit read-only access to f const zz_pEX& val() const; // explicit read-only access to f};void build(zz_pEXModulus& F, const zz_pEX& f);// pre-computes information about f and stores it in F. Must have// deg(f) > 0. Note that the declaration zz_pEXModulus F(f) is// equivalent to zz_pEXModulus F; build(F, f).// In the following, f refers to the polynomial f supplied to the// build routine, and n = deg(f).long deg(const zz_pEXModulus& F); // return n=deg(f)void MulMod(zz_pEX& x, const zz_pEX& a, const zz_pEX& b, const zz_pEXModulus& F);zz_pEX MulMod(const zz_pEX& a, const zz_pEX& b, const zz_pEXModulus& F);// x = (a * b) % f; deg(a), deg(b) < nvoid SqrMod(zz_pEX& x, const zz_pEX& a, const zz_pEXModulus& F);zz_pEX SqrMod(const zz_pEX& a, const zz_pEXModulus& F);// x = a^2 % f; deg(a) < nvoid PowerMod(zz_pEX& x, const zz_pEX& a, const ZZ& e, const zz_pEXModulus& F);zz_pEX PowerMod(const zz_pEX& a, const ZZ& e, const zz_pEXModulus& F);void PowerMod(zz_pEX& x, const zz_pEX& a, long e, const zz_pEXModulus& F);zz_pEX PowerMod(const zz_pEX& a, long e, const zz_pEXModulus& F);// x = a^e % f; e >= 0, deg(a) < n. Uses a sliding window algorithm.// (e may be negative)void PowerXMod(zz_pEX& x, const ZZ& e, const zz_pEXModulus& F);zz_pEX PowerXMod(const ZZ& e, const zz_pEXModulus& F);void PowerXMod(zz_pEX& x, long e, const zz_pEXModulus& F);zz_pEX PowerXMod(long e, const zz_pEXModulus& F);// x = X^e % f (e may be negative)void rem(zz_pEX& x, const zz_pEX& a, const zz_pEXModulus& F);// x = a % fvoid DivRem(zz_pEX& q, zz_pEX& r, const zz_pEX& a, const zz_pEXModulus& F);// q = a/f, r = a%fvoid div(zz_pEX& q, const zz_pEX& a, const zz_pEXModulus& F);// q = a/f// operator notation:zz_pEX operator/(const zz_pEX& a, const zz_pEXModulus& F);zz_pEX operator%(const zz_pEX& a, const zz_pEXModulus& F);zz_pEX& operator/=(zz_pEX& x, const zz_pEXModulus& F);zz_pEX& operator%=(zz_pEX& x, const zz_pEXModulus& F);/**************************************************************************\ vectors of zz_pEX's\**************************************************************************/NTL_vector_decl(zz_pEX,vec_zz_pEX)// vec_zz_pEXNTL_eq_vector_decl(zz_pEX,vec_zz_pEX)// == and !=NTL_io_vector_decl(zz_pEX,vec_zz_pEX)// I/O operators/**************************************************************************\ Modular CompositionModular composition is the problem of computing g(h) mod f forpolynomials f, g, and h.The algorithm employed is that of Brent & Kung (Fast algorithms formanipulating formal power series, JACM 25:581-595, 1978), which usesO(n^{1/2}) modular polynomial multiplications, and O(n^2) scalaroperations.\**************************************************************************/void CompMod(zz_pEX& x, const zz_pEX& g, const zz_pEX& h, const zz_pEXModulus& F);zz_pEX CompMod(const zz_pEX& g, const zz_pEX& h, const zz_pEXModulus& F);// x = g(h) mod f; deg(h) < nvoid Comp2Mod(zz_pEX& x1, zz_pEX& x2, const zz_pEX& g1, const zz_pEX& g2, const zz_pEX& h, const zz_pEXModulus& F);// xi = gi(h) mod f (i=1,2); deg(h) < n.void Comp3Mod(zz_pEX& x1, zz_pEX& x2, zz_pEX& x3, const zz_pEX& g1, const zz_pEX& g2, const zz_pEX& g3, const zz_pEX& h, const zz_pEXModulus& F);// xi = gi(h) mod f (i=1..3); deg(h) < n./**************************************************************************\ Composition with Pre-ConditioningIf a single h is going to be used with many g's then you should builda zz_pEXArgument for h, and then use the compose routine below. Theroutine build computes and stores h, h^2, ..., h^m mod f. After thispre-computation, composing a polynomial of degree roughly n with htakes n/m multiplies mod f, plus n^2 scalar multiplies. Thus,increasing m increases the space requirement and the pre-computationtime, but reduces the composition time.\**************************************************************************/struct zz_pEXArgument { vec_zz_pEX H;};void build(zz_pEXArgument& H, const zz_pEX& h, const zz_pEXModulus& F, long m);// Pre-Computes information about h. m > 0, deg(h) < n.void CompMod(zz_pEX& x, const zz_pEX& g, const zz_pEXArgument& H, const zz_pEXModulus& F);zz_pEX CompMod(const zz_pEX& g, const zz_pEXArgument& H, const zz_pEXModulus& F);extern long zz_pEXArgBound;// Initially 0. If this is set to a value greater than zero, then// composition routines will allocate a table of no than about// zz_pEXArgBound KB. Setting this value affects all compose routines// and the power projection and minimal polynomial routines below, // and indirectly affects many routines in zz_pEXFactoring./**************************************************************************\ power projection routines\**************************************************************************/void project(zz_pE& x, const zz_pEVector& a, const zz_pEX& b);zz_pE project(const zz_pEVector& a, const zz_pEX& b);// x = inner product of a with coefficient vector of bvoid ProjectPowers(vec_zz_pE& x, const vec_zz_pE& a, long k, const zz_pEX& h, const zz_pEXModulus& F);vec_zz_pE ProjectPowers(const vec_zz_pE& a, long k, const zz_pEX& h, const zz_pEXModulus& F);// Computes the vector// project(a, 1), project(a, h), ..., project(a, h^{k-1} % f). // This operation is the "transpose" of the modular composition operation.void ProjectPowers(vec_zz_pE& x, const vec_zz_pE& a, long k, const zz_pEXArgument& H, const zz_pEXModulus& F);vec_zz_pE ProjectPowers(const vec_zz_pE& a, long k, const zz_pEXArgument& H, const zz_pEXModulus& F);// same as above, but uses a pre-computed zz_pEXArgumentclass zz_pEXTransMultiplier { /* ... */ };void build(zz_pEXTransMultiplier& B, const zz_pEX& b, const zz_pEXModulus& F);void UpdateMap(vec_zz_pE& x, const vec_zz_pE& a, const zz_pEXMultiplier& B, const zz_pEXModulus& F);vec_zz_pE UpdateMap(const vec_zz_pE& a, const zz_pEXMultiplier& B, const zz_pEXModulus& F);// Computes the vector// project(a, b), project(a, (b*X)%f), ..., project(a, (b*X^{n-1})%f)// Required: a.length() <= deg(F), deg(b) < deg(F).// This is "transposed" MulMod by B.// Input may have "high order" zeroes stripped.// Output always has high order zeroes stripped./**************************************************************************\ Minimum PolynomialsThese routines should be used only when zz_pE is a field.All of these routines implement the algorithm from [Shoup, J. SymbolicComp. 17:371-391, 1994] and [Shoup, J. Symbolic Comp. 20:363-397,1995], based on transposed modular composition and theBerlekamp/Massey algorithm.\**************************************************************************/void MinPolySeq(zz_pEX& h, const vec_zz_pE& a, long m);zz_pEX MinPolySeq(const vec_zz_pE& a, long m);// computes the minimum polynomial of a linealy generated sequence; m// is a bound on the degree of the polynomial; required: a.length() >=// 2*mvoid ProbMinPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);zz_pEX ProbMinPolyMod(const zz_pEX& g, const zz_pEXModulus& F, long m);void ProbMinPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F);zz_pEX ProbMinPolyMod(const zz_pEX& g, const zz_pEXModulus& F);// computes the monic minimal polynomial if (g mod f). m = a bound on// the degree of the minimal polynomial; in the second version, this// argument defaults to n. The algorithm is probabilistic, always// returns a divisor of the minimal polynomial, and returns a proper// divisor with probability at most m/2^{zz_pE::degree()}.void MinPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);zz_pEX MinPolyMod(const zz_pEX& g, const zz_pEXModulus& F, long m);void MinPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F);zz_pEX MinPolyMod(const zz_pEX& g, const zz_pEXModulus& F);// same as above, but guarantees that result is correctvoid IrredPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);zz_pEX IrredPolyMod(const zz_pEX& g, const zz_pEXModulus& F, long m);void IrredPolyMod(zz_pEX& h, const zz_pEX& g, const zz_pEXModulus& F);zz_pEX IrredPolyMod(const zz_pEX& g, const zz_pEXModulus& F);// same as above, but assumes that f is irreducible, or at least that// the minimal poly of g is itself irreducible. The algorithm is// deterministic (and is always correct)./**************************************************************************\ Composition and Minimal Polynomials in towersThese are implementations of algorithms that will be describedand analyzed in a forthcoming paper.The routines require that p is prime, but zz_pE need not be a field.\**************************************************************************/void CompTower(zz_pEX& x, const zz_pX& g, const zz_pEXArgument& h, const zz_pEXModulus& F);zz_pEX CompTower(const zz_pX& g, const zz_pEXArgument& h, const zz_pEXModulus& F);void CompTower(zz_pEX& x, const zz_pX& g, const zz_pEX& h, const zz_pEXModulus& F);zz_pEX CompTower(const zz_pX& g, const zz_pEX& h, const zz_pEXModulus& F);// x = g(h) mod fvoid ProbMinPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);zz_pX ProbMinPolyTower(const zz_pEX& g, const zz_pEXModulus& F, long m);void ProbMinPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F);zz_pX ProbMinPolyTower(const zz_pEX& g, const zz_pEXModulus& F);// Uses a probabilistic algorithm to compute the minimal// polynomial of (g mod f) over zz_p.// The parameter m is a bound on the degree of the minimal polynomial// (default = deg(f)*zz_pE::degree()).// In general, the result will be a divisor of the true minimimal// polynomial. For correct results, use the MinPoly routines below.void MinPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);zz_pX MinPolyTower(const zz_pEX& g, const zz_pEXModulus& F, long m);void MinPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F);zz_pX MinPolyTower(const zz_pEX& g, const zz_pEXModulus& F);// Same as above, but result is always correct.void IrredPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F, long m);zz_pX IrredPolyTower(const zz_pEX& g, const zz_pEXModulus& F, long m);void IrredPolyTower(zz_pX& h, const zz_pEX& g, const zz_pEXModulus& F);zz_pX IrredPolyTower(const zz_pEX& g, const zz_pEXModulus& F);// Same as above, but assumes the minimal polynomial is// irreducible, and uses a slightly faster, deterministic algorithm./**************************************************************************\ Traces, norms, resultants\**************************************************************************/void TraceMod(zz_pE& x, const zz_pEX& a, const zz_pEXModulus& F);zz_pE TraceMod(const zz_pEX& a, const zz_pEXModulus& F);void TraceMod(zz_pE& x, const zz_pEX& a, const zz_pEX& f);zz_pE TraceMod(const zz_pEX& a, const zz_pEXModulus& f);// x = Trace(a mod f); deg(a) < deg(f)void TraceVec(vec_zz_pE& S, const zz_pEX& f);vec_zz_pE TraceVec(const zz_pEX& f);// S[i] = Trace(X^i mod f), i = 0..deg(f)-1; 0 < deg(f)// The above trace routines implement the asymptotically fast trace// algorithm from [von zur Gathen and Shoup, Computational Complexity,// 1992].void NormMod(zz_pE& x, const zz_pEX& a, const zz_pEX& f);zz_pE NormMod(const zz_pEX& a, const zz_pEX& f);// x = Norm(a mod f); 0 < deg(f), deg(a) < deg(f)void resultant(zz_pE& x, const zz_pEX& a, const zz_pEX& b);zz_pE resultant(const zz_pEX& a, const zz_pEX& b);// x = resultant(a, b)// NormMod and resultant require that zz_pE is a field./**************************************************************************\ MiscellanyA zz_pEX f is represented as a vec_zz_pE, which can be accessed asf.rep. The constant term is f.rep[0] and the leading coefficient isf.rep[f.rep.length()-1], except if f is zero, in which casef.rep.length() == 0. Note that the leading coefficient is alwaysnonzero (unless f is zero). One can freely access and modify f.rep,but one should always ensure that the leading coefficient is nonzero,which can be done by invoking f.normalize().\**************************************************************************/void clear(zz_pEX& x) // x = 0void set(zz_pEX& x); // x = 1void zz_pEX::normalize(); // f.normalize() strips leading zeros from f.rep.void zz_pEX::SetMaxLength(long n);// f.SetMaxLength(n) pre-allocate spaces for n coefficients. The// polynomial that f represents is unchanged.void zz_pEX::kill();// f.kill() sets f to 0 and frees all memory held by f. Equivalent to// f.rep.kill().zz_pEX::zz_pEX(INIT_SIZE_TYPE, long n);// zz_pEX(INIT_SIZE, n) initializes to zero, but space is pre-allocated// for n coefficientsstatic const zz_pEX& zero();// zz_pEX::zero() is a read-only reference to 0void swap(zz_pEX& x, zz_pEX& y); // swap x and y (via "pointer swapping")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -