Changeset 287cc8 in git for ntl/src/ZZ_pEX.c
- Timestamp:
- Jan 5, 2010, 5:51:13 PM (14 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 3c38b3810fd61108b01f123f5a91e13ccff52b20
- Parents:
- 1d43d184dd871d77c1ba8e095d768f22a0fbe92f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ntl/src/ZZ_pEX.c
r1d43d18 r287cc8 97 97 long j, m; 98 98 99 if (i < 0) 99 if (i < 0) 100 100 Error("SetCoeff: negative index"); 101 101 … … 174 174 long j, m; 175 175 176 if (i < 0) 176 if (i < 0) 177 177 Error("coefficient index out of range"); 178 178 … … 203 203 return deg(a) == 1 && IsOne(LeadCoeff(a)) && IsZero(ConstTerm(a)); 204 204 } 205 206 205 206 207 207 208 208 const ZZ_pE& coeff(const ZZ_pEX& a, long i) … … 245 245 void conv(ZZ_pEX& x, long a) 246 246 { 247 if (a == 0) 247 if (a == 0) 248 248 clear(x); 249 249 else if (a == 1) … … 265 265 void conv(ZZ_pEX& x, const ZZ_p& a) 266 266 { 267 if (IsZero(a)) 267 if (IsZero(a)) 268 268 clear(x); 269 269 else if (IsOne(a)) … … 305 305 306 306 long i; 307 const ZZ_pE *ap, *bp; 307 const ZZ_pE *ap, *bp; 308 308 ZZ_pE* xp; 309 309 … … 406 406 407 407 long i; 408 const ZZ_pE *ap, *bp; 408 const ZZ_pE *ap, *bp; 409 409 ZZ_pE* xp; 410 410 … … 537 537 void sub(ZZ_pEX& x, long a, const ZZ_pEX& b) 538 538 { 539 NTL_ZZ_pRegister(T); 539 NTL_ZZ_pRegister(T); 540 540 T = a; 541 541 negate(x, b); … … 558 558 mul(c, b, ConstTerm(a)); 559 559 return; 560 } 560 } 561 561 562 562 if (deg(b) == 0) { … … 586 586 long dcoeff = deg(coeff); 587 587 for (j = 0; j <= dcoeff; j++) 588 A.rep[n2*i + j] = coeff.rep[j]; 588 A.rep[n2*i + j] = coeff.rep[j]; 589 589 } 590 590 … … 597 597 long dcoeff = deg(coeff); 598 598 for (j = 0; j <= dcoeff; j++) 599 B.rep[n2*i + j] = coeff.rep[j]; 599 B.rep[n2*i + j] = coeff.rep[j]; 600 600 } 601 601 … … 611 611 612 612 ZZ_pX tmp; 613 613 614 614 for (i = 0; i <= dc; i++) { 615 615 tmp.rep.SetLength(n2); … … 621 621 conv(c.rep[i], tmp); 622 622 } 623 623 624 624 c.normalize(); 625 625 } … … 700 700 conv(c, res); 701 701 return; 702 } 702 } 703 703 704 704 // general case...Kronecker subst … … 722 722 long dcoeff = deg(coeff); 723 723 for (j = 0; j <= dcoeff; j++) 724 A.rep[n2*i + j] = coeff.rep[j]; 724 A.rep[n2*i + j] = coeff.rep[j]; 725 725 } 726 726 … … 736 736 737 737 ZZ_pX tmp; 738 738 739 739 for (i = 0; i <= dc; i++) { 740 740 tmp.rep.SetLength(n2); … … 746 746 conv(c.rep[i], tmp); 747 747 } 748 749 748 749 750 750 c.normalize(); 751 751 } … … 796 796 797 797 x.normalize(); 798 } 798 } 799 799 800 800 801 801 void trunc(ZZ_pEX& x, const ZZ_pEX& a, long m) 802 802 803 // x = a % X^m, output may alias input 803 // x = a % X^m, output may alias input 804 804 805 805 { … … 931 931 const ZZ_pE *ap, *bp; 932 932 ZZ_pE *xp; 933 933 934 934 ZZ_pEX la, lb; 935 935 … … 1020 1020 SetSize(x, da+1, 2*ZZ_pE::degree()); 1021 1021 1022 for (i = 0; i <= da; i++) 1022 for (i = 0; i <= da; i++) 1023 1023 x[i] = rep(a.rep[i]); 1024 1024 … … 1104 1104 1105 1105 1106 void PlainDivRem(ZZ_pEX& q, ZZ_pEX& r, const ZZ_pEX& a, const ZZ_pEX& b, 1106 void PlainDivRem(ZZ_pEX& q, ZZ_pEX& r, const ZZ_pEX& a, const ZZ_pEX& b, 1107 1107 vec_ZZ_pX& x) 1108 1108 { … … 1311 1311 long da = deg(a); 1312 1312 long i; 1313 1313 1314 1314 if (da < n) { 1315 1315 clear(x); … … 1337 1337 1338 1338 if (n < 0) { 1339 if (n < -NTL_MAX_LONG) 1339 if (n < -NTL_MAX_LONG) 1340 1340 clear(x); 1341 1341 else … … 1445 1445 if (NTL_OVERFLOW(n, ZZ_pE::degree(), 0)) 1446 1446 Error("build(ZZ_pEXModulus,ZZ_pEX): overflow"); 1447 1447 1448 1448 1449 1449 F.tracevec.SetLength(0); … … 1478 1478 1479 1479 1480 ZZ_pEXModulus::~ZZ_pEXModulus() 1481 { 1480 ZZ_pEXModulus::~ZZ_pEXModulus() 1481 { 1482 1482 } 1483 1483 … … 1739 1739 mul(P1, P2, b); 1740 1740 sub(P1, a, P1); 1741 1741 1742 1742 r = P1; 1743 1743 } … … 1760 1760 mul(P1, P2, b); 1761 1761 sub(P1, a, P1); 1762 1762 1763 1763 r = P1; 1764 1764 q = P2; … … 1780 1780 mul(P2, P1, P2); 1781 1781 RightShift(P2, P2, da-db); 1782 1782 1783 1783 q = P2; 1784 1784 } … … 1887 1887 1888 1888 1889 inv(t, LeadCoeff(x)); 1890 mul(x, x, t); 1891 } 1892 1893 1894 1895 1889 inv(t, LeadCoeff(x)); 1890 mul(x, x, t); 1891 } 1892 1893 1894 1895 1896 1896 1897 1897 void XGCD(ZZ_pEX& d, ZZ_pEX& s, ZZ_pEX& t, const ZZ_pEX& a, const ZZ_pEX& b) … … 1913 1913 long e = max(deg(a), deg(b)) + 1; 1914 1914 1915 ZZ_pEX temp(INIT_SIZE, e), u(INIT_SIZE, e), v(INIT_SIZE, e), 1916 u0(INIT_SIZE, e), v0(INIT_SIZE, e), 1917 u1(INIT_SIZE, e), v1(INIT_SIZE, e), 1915 ZZ_pEX temp(INIT_SIZE, e), u(INIT_SIZE, e), v(INIT_SIZE, e), 1916 u0(INIT_SIZE, e), v0(INIT_SIZE, e), 1917 u1(INIT_SIZE, e), v1(INIT_SIZE, e), 1918 1918 u2(INIT_SIZE, e), v2(INIT_SIZE, e), q(INIT_SIZE, e); 1919 1919 … … 2092 2092 f.rep = res; 2093 2093 } 2094 2095 void InnerProduct(ZZ_pEX& x, const vec_ZZ_pE& v, long low, long high, 2094 2095 void InnerProduct(ZZ_pEX& x, const vec_ZZ_pE& v, long low, long high, 2096 2096 const vec_ZZ_pEX& H, long n, vec_ZZ_pX& t) 2097 2097 { … … 2122 2122 2123 2123 2124 void CompMod(ZZ_pEX& x, const ZZ_pEX& g, const ZZ_pEXArgument& A, 2124 void CompMod(ZZ_pEX& x, const ZZ_pEX& g, const ZZ_pEXArgument& A, 2125 2125 const ZZ_pEXModulus& F) 2126 2126 { … … 2230 2230 } 2231 2231 2232 void Comp3Mod(ZZ_pEX& x1, ZZ_pEX& x2, ZZ_pEX& x3, 2232 void Comp3Mod(ZZ_pEX& x1, ZZ_pEX& x2, ZZ_pEX& x3, 2233 2233 const ZZ_pEX& g1, const ZZ_pEX& g2, const ZZ_pEX& g3, 2234 2234 const ZZ_pEX& h, const ZZ_pEXModulus& F) … … 2278 2278 B.shamt_fbi = 0; 2279 2279 else 2280 B.shamt_fbi = F.n-2 - d; 2280 B.shamt_fbi = F.n-2 - d; 2281 2281 2282 2282 CopyReverse(B.fbi, t, d); 2283 2283 2284 // The following code optimizes the case when 2284 // The following code optimizes the case when 2285 2285 // f = X^n + low degree poly 2286 2286 … … 2358 2358 2359 2359 static 2360 void ProjectPowers(vec_ZZ_pE& x, const ZZ_pEX& a, long k, 2360 void ProjectPowers(vec_ZZ_pE& x, const ZZ_pEX& a, long k, 2361 2361 const ZZ_pEXArgument& H, const ZZ_pEXModulus& F) 2362 2362 { 2363 if (k < 0 || NTL_OVERFLOW(k, 1, 0) || deg(a) >= F.n) 2363 if (k < 0 || NTL_OVERFLOW(k, 1, 0) || deg(a) >= F.n) 2364 2364 Error("ProjectPowers: bad args"); 2365 2365 … … 2387 2387 2388 2388 static 2389 void ProjectPowers(vec_ZZ_pE& x, const ZZ_pEX& a, long k, const ZZ_pEX& h, 2389 void ProjectPowers(vec_ZZ_pE& x, const ZZ_pEX& a, long k, const ZZ_pEX& h, 2390 2390 const ZZ_pEXModulus& F) 2391 2391 { … … 2474 2474 } 2475 2475 2476 // cerr << "finished: " << L << " " << deg(Lambda) << "\n"; 2476 // cerr << "finished: " << L << " " << deg(Lambda) << "\n"; 2477 2477 2478 2478 dl = deg(Lambda); … … 2498 2498 2499 2499 2500 void DoMinPolyMod(ZZ_pEX& h, const ZZ_pEX& g, const ZZ_pEXModulus& F, long m, 2500 void DoMinPolyMod(ZZ_pEX& h, const ZZ_pEX& g, const ZZ_pEXModulus& F, long m, 2501 2501 const ZZ_pEX& R) 2502 2502 { … … 2541 2541 ZZ_pEX R; 2542 2542 ZZ_pEXTransMultiplier H1; 2543 2543 2544 2544 2545 2545 for (;;) { … … 2634 2634 ZZ_pEX lq, r; 2635 2635 DivRem(lq, r, a, b); 2636 if (!IsZero(r)) return 0; 2636 if (!IsZero(r)) return 0; 2637 2637 q = lq; 2638 2638 return 1; … … 2644 2644 ZZ_pEX lq, r; 2645 2645 DivRem(lq, r, a, b); 2646 if (!IsZero(r)) return 0; 2646 if (!IsZero(r)) return 0; 2647 2647 return 1; 2648 2648 } … … 2671 2671 return k; 2672 2672 } 2673 2673 2674 2674 2675 2675 … … 2737 2737 2738 2738 v[0] = g; 2739 2739 2740 2740 if (k > 1) { 2741 2741 ZZ_pEX t; … … 2753 2753 val = 0; 2754 2754 for (i = n-1; i >= 0; i--) { 2755 val = (val << 1) | bit(e, i); 2755 val = (val << 1) | bit(e, i); 2756 2756 if (val == 0) 2757 2757 SqrMod(res, res, F); … … 2907 2907 res.SetMaxLength(da*e + 1); 2908 2908 res = 1; 2909 2909 2910 2910 long k = NumBits(e); 2911 2911 long i; … … 3005 3005 Error("trace: bad args"); 3006 3006 3007 if (F.tracevec.length() == 0) 3007 if (F.tracevec.length() == 0) 3008 3008 ComputeTraceVec(F); 3009 3009 … … 3023 3023 { 3024 3024 ZZ_pE res; 3025 3025 3026 3026 if (IsZero(a) || IsZero(b)) 3027 3027 clear(res); 3028 else if (deg(a) == 0 && deg(b) == 0) 3028 else if (deg(a) == 0 && deg(b) == 0) 3029 3029 set(res); 3030 3030 else { … … 3062 3062 else 3063 3063 clear(res); 3064 3064 3065 3065 break; 3066 3066 } … … 3073 3073 void resultant(ZZ_pE& rres, const ZZ_pEX& a, const ZZ_pEX& b) 3074 3074 { 3075 PlainResultant(rres, a, b); 3075 PlainResultant(rres, a, b); 3076 3076 } 3077 3077 … … 3079 3079 void NormMod(ZZ_pE& x, const ZZ_pEX& a, const ZZ_pEX& f) 3080 3080 { 3081 if (deg(f) <= 0 || deg(a) >= deg(f)) 3081 if (deg(f) <= 0 || deg(a) >= deg(f)) 3082 3082 Error("norm: bad args"); 3083 3083 … … 3163 3163 3164 3164 3165 void CompTower(ZZ_pEX& x, const ZZ_pX& g, const ZZ_pEX& h, 3165 void CompTower(ZZ_pEX& x, const ZZ_pX& g, const ZZ_pEX& h, 3166 3166 const ZZ_pEXModulus& F) 3167 3167 // x = g(h) mod f … … 3197 3197 } 3198 3198 3199 void ProjectedInnerProduct(ZZ_p& x, const vec_ZZ_pE& a, 3199 void ProjectedInnerProduct(ZZ_p& x, const vec_ZZ_pE& a, 3200 3200 const vec_vec_ZZ_p& b) 3201 3201 { … … 3232 3232 } 3233 3233 } 3234 3234 3235 3235 3236 3236 … … 3242 3242 long n = F.n; 3243 3243 3244 if (a.length() > n || k < 0 || NTL_OVERFLOW(k, 1, 0)) 3244 if (a.length() > n || k < 0 || NTL_OVERFLOW(k, 1, 0)) 3245 3245 Error("ProjectPowers: bad args"); 3246 3246 … … 3301 3301 3302 3302 ProjectPowersTower(x, R, 2*m, g, F, proj); 3303 3303 3304 3304 MinPolySeq(h, x, m); 3305 3305 } 3306 3306 3307 3307 3308 void ProbMinPolyTower(ZZ_pX& h, const ZZ_pEX& g, const ZZ_pEXModulus& F, 3308 void ProbMinPolyTower(ZZ_pX& h, const ZZ_pEX& g, const ZZ_pEXModulus& F, 3309 3309 long m) 3310 3310 { … … 3326 3326 3327 3327 3328 void ProbMinPolyTower(ZZ_pX& h, const ZZ_pEX& g, const ZZ_pEXModulus& F, 3328 void ProbMinPolyTower(ZZ_pX& h, const ZZ_pEX& g, const ZZ_pEXModulus& F, 3329 3329 long m, const vec_ZZ_p& proj) 3330 3330 { … … 3369 3369 vec_ZZ_pE R; 3370 3370 ZZ_pEXTransMultiplier H1; 3371 3371 3372 3372 3373 3373 for (;;) {
Note: See TracChangeset
for help on using the changeset viewer.