ZZ eval(const ZZX& f, const ZZ& x) { static ZZ y,z; static ZZ t; long i; GetCoeff(t, f, deg(f)); y=t; for (i = deg(f)-1; i >= 0; i--) { GetCoeff(t, f, i); mul(z, y, x); add(y, z, t); } return y; }
zz_pE eval(const zz_pX& f, const zz_pE& x) { static zz_pE y,z; static zz_p t; long i; GetCoeff(t, f,deg(f)); y=t; for (i = deg(f)-1; i >= 0; i--) { GetCoeff(t, f, i); mul(z, y, x); add(y, z, t); } return y; }
void SplineSeg<D> :: PrintCoeff (ostream & ost) const { Vector u(6); GetCoeff(u); for ( int i=0; i<6; i++) ost << u[i] << " "; ost << endl; }
unsigned long to_ulong(const zz_pX& x) { unsigned long u; int i; static zz_p c; c = LeadCoeff(x); static long p; p = c.modulus(); for (u = 0, i = deg(x); i >= 0; i--) { GetCoeff(c, x,i); u = u * p + rep(c); } return u; }
void mul(zz_pX& U, zz_pX& V, const zz_pXMatrix& M) // (U, V)^T = M*(U, V)^T { long d = deg(U) - deg(M(1,1)); long k = NextPowerOfTwo(d - 1); // When the GCD algorithm is run on polynomials of degree n, n-1, // where n is a power of two, then d-1 is likely to be a power of two. // It would be more natural to set k = NextPowerOfTwo(d+1), but this // would be much less efficient in this case. long n = (1L << k); long xx; zz_p a0, a1, b0, b1, c0, d0, u0, u1, v0, v1, nu0, nu1, nv0; zz_p t1, t2; if (n == d-1) xx = 1; else if (n == d) xx = 2; else xx = 3; switch (xx) { case 1: GetCoeff(a0, M(0,0), 0); GetCoeff(a1, M(0,0), 1); GetCoeff(b0, M(0,1), 0); GetCoeff(b1, M(0,1), 1); GetCoeff(c0, M(1,0), 0); GetCoeff(d0, M(1,1), 0); GetCoeff(u0, U, 0); GetCoeff(u1, U, 1); GetCoeff(v0, V, 0); GetCoeff(v1, V, 1); mul(t1, (a0), (u0)); mul(t2, (b0), (v0)); add(t1, t1, t2); nu0 = t1; mul(t1, (a1), (u0)); mul(t2, (a0), (u1)); add(t1, t1, t2); mul(t2, (b1), (v0)); add(t1, t1, t2); mul(t2, (b0), (v1)); add(t1, t1, t2); nu1 = t1; mul(t1, (c0), (u0)); mul(t2, (d0), (v0)); add (t1, t1, t2); nv0 = t1; break; case 2: GetCoeff(a0, M(0,0), 0); GetCoeff(b0, M(0,1), 0); GetCoeff(u0, U, 0); GetCoeff(v0, V, 0); mul(t1, (a0), (u0)); mul(t2, (b0), (v0)); add(t1, t1, t2); nu0 = t1; break; case 3: break; } fftRep RU(INIT_SIZE, k), RV(INIT_SIZE, k), R1(INIT_SIZE, k), R2(INIT_SIZE, k); TofftRep(RU, U, k); TofftRep(RV, V, k); TofftRep(R1, M(0,0), k); mul(R1, R1, RU); TofftRep(R2, M(0,1), k); mul(R2, R2, RV); add(R1, R1, R2); FromfftRep(U, R1, 0, d); TofftRep(R1, M(1,0), k); mul(R1, R1, RU); TofftRep(R2, M(1,1), k); mul(R2, R2, RV); add(R1, R1, R2); FromfftRep(V, R1, 0, d-1); // now fix-up results switch (xx) { case 1: GetCoeff(u0, U, 0); sub(u0, u0, nu0); SetCoeff(U, d-1, u0); SetCoeff(U, 0, nu0); GetCoeff(u1, U, 1); sub(u1, u1, nu1); SetCoeff(U, d, u1); SetCoeff(U, 1, nu1); GetCoeff(v0, V, 0); sub(v0, v0, nv0); SetCoeff(V, d-1, v0); SetCoeff(V, 0, nv0); break; case 2: GetCoeff(u0, U, 0); sub(u0, u0, nu0); SetCoeff(U, d, u0); SetCoeff(U, 0, nu0); break; } }
void CTransform::setValue( const unsigned char * byte ) { G[0][0] = GetCoeff( byte + 0 ) / FV; G[0][1] = GetCoeff( byte + 2 ) / FM; G[0][2] = GetCoeff( byte + 4 ) / FM; G[0][3] = GetCoeff( byte + 6 ) / FM; G[1][0] = GetCoeff( byte + 8 ) / FV; G[1][1] = GetCoeff( byte +10 ) / FM; G[1][2] = GetCoeff( byte +12 ) / FM; G[1][3] = GetCoeff( byte +14 ) / FM; G[2][0] = GetCoeff( byte +16 ) / FV; G[2][1] = GetCoeff( byte +18 ) / FM; G[2][2] = GetCoeff( byte +20 ) / FM; G[2][3] = GetCoeff( byte +22 ) / FM; M[0][0] = GetCoeff( byte +24 ) / FV; M[0][1] = GetCoeff( byte +26 ) / FM; M[0][2] = GetCoeff( byte +28 ) / FM; M[0][3] = GetCoeff( byte +30 ) / FM; M[1][0] = GetCoeff( byte +32 ) / FV; M[1][1] = GetCoeff( byte +34 ) / FM; M[1][2] = GetCoeff( byte +36 ) / FM; M[1][3] = GetCoeff( byte +38 ) / FM; M[2][0] = GetCoeff( byte +40 ) / FV; M[2][1] = GetCoeff( byte +42 ) / FM; M[2][2] = GetCoeff( byte +44 ) / FM; M[2][3] = GetCoeff( byte +46 ) / FM; }
void mul(ZZ_pX& U, ZZ_pX& V, const ZZ_pXMatrix& M) // (U, V)^T = M*(U, V)^T { long d = deg(U) - deg(M(1,1)); long k = NextPowerOfTwo(d - 1); // When the GCD algorithm is run on polynomials of degree n, n-1, // where n is a power of two, then d-1 is likely to be a power of two. // It would be more natural to set k = NextPowerOfTwo(d+1), but this // would be much less efficient in this case. // We optimize this case, as it does sometimes arise naturally // in some situations. long n = (1L << k); long xx; ZZ_p a0, a1, b0, b1, c0, d0, u0, u1, v0, v1, nu0, nu1, nv0; NTL_ZZRegister(t1); NTL_ZZRegister(t2); if (n == d-1) xx = 1; else if (n == d) xx = 2; else xx = 3; switch (xx) { case 1: GetCoeff(a0, M(0,0), 0); GetCoeff(a1, M(0,0), 1); GetCoeff(b0, M(0,1), 0); GetCoeff(b1, M(0,1), 1); GetCoeff(c0, M(1,0), 0); GetCoeff(d0, M(1,1), 0); GetCoeff(u0, U, 0); GetCoeff(u1, U, 1); GetCoeff(v0, V, 0); GetCoeff(v1, V, 1); mul(t1, rep(a0), rep(u0)); mul(t2, rep(b0), rep(v0)); add(t1, t1, t2); conv(nu0, t1); mul(t1, rep(a1), rep(u0)); mul(t2, rep(a0), rep(u1)); add(t1, t1, t2); mul(t2, rep(b1), rep(v0)); add(t1, t1, t2); mul(t2, rep(b0), rep(v1)); add(t1, t1, t2); conv(nu1, t1); mul(t1, rep(c0), rep(u0)); mul(t2, rep(d0), rep(v0)); add (t1, t1, t2); conv(nv0, t1); break; case 2: GetCoeff(a0, M(0,0), 0); GetCoeff(b0, M(0,1), 0); GetCoeff(u0, U, 0); GetCoeff(v0, V, 0); mul(t1, rep(a0), rep(u0)); mul(t2, rep(b0), rep(v0)); add(t1, t1, t2); conv(nu0, t1); break; case 3: break; } FFTRep RU(INIT_SIZE, k), RV(INIT_SIZE, k), R1(INIT_SIZE, k), R2(INIT_SIZE, k); ToFFTRep(RU, U, k); ToFFTRep(RV, V, k); ToFFTRep(R1, M(0,0), k); mul(R1, R1, RU); ToFFTRep(R2, M(0,1), k); mul(R2, R2, RV); add(R1, R1, R2); FromFFTRep(U, R1, 0, d); ToFFTRep(R1, M(1,0), k); mul(R1, R1, RU); ToFFTRep(R2, M(1,1), k); mul(R2, R2, RV); add(R1, R1, R2); FromFFTRep(V, R1, 0, d-1); // now fix-up results switch (xx) { case 1: GetCoeff(u0, U, 0); sub(u0, u0, nu0); SetCoeff(U, d-1, u0); SetCoeff(U, 0, nu0); GetCoeff(u1, U, 1); sub(u1, u1, nu1); SetCoeff(U, d, u1); SetCoeff(U, 1, nu1); GetCoeff(v0, V, 0); sub(v0, v0, nv0); SetCoeff(V, d-1, v0); SetCoeff(V, 0, nv0); break; case 2: GetCoeff(u0, U, 0); sub(u0, u0, nu0); SetCoeff(U, d, u0); SetCoeff(U, 0, nu0); break; } }