Changeset 2a2e43 in git
- Timestamp:
- Jul 17, 2014, 3:09:51 PM (9 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- e243f1d19971923717babbc0dc13cd49ed4840cf
- Parents:
- 3169ca78b60cbcbd96901fbd89cf164a5ed0b62d88355ebe9326d86d566d6c175b82b315be5b63ed
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/canonicalform.h
r3169ca r2a2e43 271 271 272 272 bool hasFirstAlgVar( const CanonicalForm & f, Variable & a); 273 274 CanonicalForm leftShift (const CanonicalForm& F, int n); 273 275 //}}} 274 276 -
factory/cfEzgcd.cc
r3169ca r2a2e43 1135 1135 degF = degree( F, x ); degG = degree( G, x ); 1136 1136 1137 if (hasFirstAlgVar(G,a))1137 if (algExtension) 1138 1138 b = REvaluation( 2, tmax(F.level(), G.level()), AlgExtRandomF( a ) ); 1139 1139 else … … 1166 1166 Variable alpha= rootOf (mipo.mapinto()); 1167 1167 result= GF2FalphaRep (result, alpha); 1168 prune (alpha); 1168 1169 } 1169 1170 if (k > 1) … … 1173 1174 } 1174 1175 if (extOfExt) 1176 { 1175 1177 result= mapDown (result, primElem, imPrimElem, oldA, dest, source); 1178 prune1 (oldA); 1179 } 1176 1180 return N (d*result); 1177 1181 } … … 1188 1192 Variable alpha= rootOf (mipo.mapinto()); 1189 1193 F= GF2FalphaRep (F, alpha); 1194 prune (alpha); 1190 1195 } 1191 1196 if (k > 1) … … 1195 1200 } 1196 1201 if (extOfExt) 1202 { 1197 1203 F= mapDown (F, primElem, imPrimElem, oldA, dest, source); 1204 prune1 (oldA); 1205 } 1198 1206 return N (d*F); 1199 1207 } … … 1211 1219 Variable alpha= rootOf (mipo.mapinto()); 1212 1220 G= GF2FalphaRep (G, alpha); 1221 prune (alpha); 1213 1222 } 1214 1223 if (k > 1) … … 1218 1227 } 1219 1228 if (extOfExt) 1229 { 1220 1230 G= mapDown (G, primElem, imPrimElem, oldA, dest, source); 1231 prune1 (oldA); 1232 } 1221 1233 return N (d*G); 1222 1234 } … … 1248 1260 Variable alpha= rootOf (mipo.mapinto()); 1249 1261 result= GF2FalphaRep (result, alpha); 1262 prune (alpha); 1250 1263 } 1251 1264 if (k > 1) … … 1255 1268 } 1256 1269 if (extOfExt) 1270 { 1257 1271 result= mapDown (result, primElem, imPrimElem, oldA, dest, source); 1272 prune1 (oldA); 1273 } 1258 1274 return N (d*result); 1259 1275 } … … 1291 1307 Variable alpha= rootOf (mipo.mapinto()); 1292 1308 F= GF2FalphaRep (F, alpha); 1309 prune (alpha); 1293 1310 } 1294 1311 if (k > 1) … … 1298 1315 } 1299 1316 if (extOfExt) 1317 { 1300 1318 F= mapDown (F, primElem, imPrimElem, oldA, dest, source); 1319 prune1 (oldA); 1320 } 1301 1321 return N (d*F); 1302 1322 } … … 1314 1334 Variable alpha= rootOf (mipo.mapinto()); 1315 1335 G= GF2FalphaRep (G, alpha); 1336 prune (alpha); 1316 1337 } 1317 1338 if (k > 1) … … 1321 1342 } 1322 1343 if (extOfExt) 1344 { 1323 1345 G= mapDown (G, primElem, imPrimElem, oldA, dest, source); 1346 prune1 (oldA); 1347 } 1324 1348 return N (d*G); 1325 1349 } … … 1377 1401 Variable alpha= rootOf (mipo.mapinto()); 1378 1402 result= GF2FalphaRep (result, alpha); 1403 prune (alpha); 1379 1404 } 1380 1405 if (k > 1) … … 1384 1409 } 1385 1410 if (extOfExt) 1411 { 1386 1412 result= mapDown (result, primElem, imPrimElem, oldA, dest, source); 1413 prune1 (oldA); 1414 } 1387 1415 return N (d*result); 1388 1416 } … … 1396 1424 result= modGCDFq (F, G, a); 1397 1425 if (extOfExt) 1426 { 1398 1427 result= mapDown (result, primElem, imPrimElem, oldA, dest, source); 1428 prune1 (oldA); 1429 } 1399 1430 return N (d*result); 1400 1431 } … … 1408 1439 Variable alpha= rootOf (mipo.mapinto()); 1409 1440 result= GF2FalphaRep (result, alpha); 1441 prune (alpha); 1410 1442 } 1411 1443 if (k > 1) … … 1430 1462 result= modGCDFq (F, G, a); 1431 1463 if (extOfExt) 1464 { 1432 1465 result= mapDown (result, primElem, imPrimElem, oldA, dest, source); 1466 prune1 (oldA); 1467 } 1433 1468 return N (d*result); 1434 1469 } … … 1442 1477 Variable alpha= rootOf (mipo.mapinto()); 1443 1478 result= GF2FalphaRep (result, alpha); 1479 prune (alpha); 1444 1480 } 1445 1481 if (k > 1) … … 1477 1513 Variable alpha= rootOf (mipo.mapinto()); 1478 1514 cand= GF2FalphaRep (cand, alpha); 1515 prune (alpha); 1479 1516 } 1480 1517 if (k > 1 && gcdfound) … … 1484 1521 } 1485 1522 if (extOfExt && gcdfound) 1523 { 1486 1524 cand= mapDown (cand, primElem, imPrimElem, oldA, dest, source); 1525 prune1 (oldA); 1526 } 1487 1527 } 1488 1528 } -
factory/cfGcdAlgExt.cc
r3169ca r2a2e43 859 859 && f.level() == tmp.level() && tmp.level() == g.level()) 860 860 { 861 CanonicalForm Q, R, sf, sg, stmp; 862 Variable x= Variable (1); 863 sf= swapvar (f, f.mvar(), x); 864 sg= swapvar (g, f.mvar(), x); 865 stmp= swapvar (tmp, f.mvar(), x); 866 newtonDivrem (sf, stmp, Q, R); 861 CanonicalForm Q, R; 862 newtonDivrem (f, tmp, Q, R); 867 863 if (R.isZero()) 868 864 { 869 newtonDivrem ( sg, stmp, Q, R);865 newtonDivrem (g, tmp, Q, R); 870 866 if (R.isZero()) 871 867 { -
factory/cfGcdUtil.cc
r3169ca r2a2e43 52 52 bool passToGF= false; 53 53 int k= 1; 54 bool extOfExt= false; 55 Variable v3; 54 56 if (p > 0 && p < TEST_ONE_MAX && CFFactory::gettype() != GaloisFieldDomain && !algExtension) 55 57 { … … 78 80 else if (p > 0 && p < TEST_ONE_MAX && algExtension) 79 81 { 80 bool extOfExt= false;81 82 #ifdef HAVE_NTL 82 83 int d= degree (getMipo (v)); … … 132 133 if (extOfExt) 133 134 { 135 v3= v; 134 136 F= mapUp (F, v, v2, primElem, imPrimElem, source, dest); 135 137 G= mapUp (G, v, v2, primElem, imPrimElem, source, dest); … … 181 183 if (k > 1) 182 184 setCharacteristic (p, k, gf_name); 185 if (extOfExt) 186 prune1 (v3); 183 187 return false; 184 188 } … … 208 212 if (k > 1) 209 213 setCharacteristic (p, k, gf_name); 214 if (extOfExt) 215 prune1 (v3); 210 216 return result; 211 217 } -
factory/cfModGcd.cc
r3169ca r2a2e43 695 695 ppA= mapDown (ppA, prim_elem_alpha, im_prim_elem_alpha, alpha, u, v); 696 696 ppB= mapDown (ppB, prim_elem_alpha, im_prim_elem_alpha, alpha, u, v); 697 prune1 (alpha); 697 698 } 698 699 coF= N (ppA*(cA/gcdcAcB)); … … 770 771 TIMING_END_AND_PRINT (termination_test, 771 772 "time for successful termination test Fq: "); 773 prune1 (alpha); 772 774 return N(gcdcAcB*ppH); 773 775 } … … 1319 1321 coG= 0; 1320 1322 G_m= 0; 1321 Variable alpha, V_buf ;1323 Variable alpha, V_buf, cleanUp; 1322 1324 bool fail= false; 1323 1325 bool inextension= false; … … 1364 1366 CanonicalForm mipo; 1365 1367 int deg= 2; 1366 do { 1368 bool initialized= false; 1369 do 1370 { 1367 1371 mipo= randomIrredpoly (deg, x); 1368 alpha= rootOf (mipo); 1372 if (initialized) 1373 setMipo (alpha, mipo); 1374 else 1375 alpha= rootOf (mipo); 1369 1376 inextension= true; 1377 initialized= true; 1370 1378 fail= false; 1371 1379 random_element= randomElement (m*lcA*lcB, alpha, l, fail); … … 1374 1382 list= CFList(); 1375 1383 V_buf= alpha; 1384 cleanUp= alpha; 1376 1385 TIMING_START (gcd_recursion); 1377 1386 G_random_element= … … 1461 1470 if (d0 == 0) 1462 1471 { 1472 if (inextension) 1473 prune (cleanUp); 1463 1474 coF= N (ppA*(cA/gcdcAcB)); 1464 1475 coG= N (ppB*(cB/gcdcAcB)); … … 1525 1536 (fdivides (ppH, ppA, ppCoF) && fdivides (ppH, ppB, ppCoG))) 1526 1537 { 1538 if (inextension) 1539 prune (cleanUp); 1527 1540 coF= N ((cA/gcdcAcB)*ppCoF); 1528 1541 coG= N ((cB/gcdcAcB)*ppCoG); … … 2277 2290 CanonicalForm mipo; 2278 2291 int deg= 2; 2279 do { 2292 bool initialized= false; 2293 do 2294 { 2280 2295 mipo= randomIrredpoly (deg, x); 2281 V_buf= rootOf (mipo); 2296 if (initialized) 2297 setMipo (V_buf, mipo); 2298 else 2299 V_buf= rootOf (mipo); 2282 2300 evalFail= false; 2301 initialized= true; 2283 2302 evalPoints= evaluationPoints (A, B, Aeval, Beval, LCA, GF, V_buf, 2284 2303 evalFail, list); … … 2296 2315 delete[] pEvalPoints; 2297 2316 fail= true; 2317 if (alpha.level() != 1 && V_buf != alpha) 2318 prune1 (alpha); 2298 2319 return 0; 2299 2320 } … … 2305 2326 delete[] pEvalPoints; 2306 2327 fail= true; 2328 if (alpha.level() != 1 && V_buf != alpha) 2329 prune1 (alpha); 2307 2330 return 0; 2308 2331 } … … 2367 2390 delete[] coeffMonoms; 2368 2391 fail= true; 2392 if (alpha.level() != 1 && V_buf != alpha) 2393 prune1 (alpha); 2369 2394 return 0; 2370 2395 } … … 2383 2408 CFList u, v; 2384 2409 result= mapDown (result, prim_elem_alpha, im_prim_elem_alpha, alpha, u, v); 2410 prune1 (alpha); 2385 2411 } 2386 2412 … … 2551 2577 CanonicalForm mipo; 2552 2578 int deg= 2; 2553 do { 2579 bool initialized= false; 2580 do 2581 { 2554 2582 mipo= randomIrredpoly (deg, x); 2555 V_buf= rootOf (mipo); 2583 if (initialized) 2584 setMipo (V_buf, mipo); 2585 else 2586 V_buf= rootOf (mipo); 2556 2587 evalFail= false; 2588 initialized= true; 2557 2589 evalPoints= evaluationPoints (A, B, Aeval, Beval, LCA, GF, V_buf, 2558 2590 evalFail, list); … … 2576 2608 delete[] pEvalPoints; 2577 2609 fail= true; 2610 if (alpha.level() != 1 && V_buf != alpha) 2611 prune1 (alpha); 2578 2612 return 0; 2579 2613 } … … 2585 2619 delete[] pEvalPoints; 2586 2620 fail= true; 2621 if (alpha.level() != 1 && V_buf != alpha) 2622 prune1 (alpha); 2587 2623 return 0; 2588 2624 } … … 2745 2781 delete [] bufpEvalPoints; 2746 2782 fail= true; 2783 if (alpha.level() != 1 && V_buf != alpha) 2784 prune1 (alpha); 2747 2785 return 0; 2748 2786 } … … 2760 2798 delete [] bufpEvalPoints; 2761 2799 fail= true; 2800 if (alpha.level() != 1 && V_buf != alpha) 2801 prune1 (alpha); 2762 2802 return 0; 2763 2803 } … … 2848 2888 delete [] bufpEvalPoints; 2849 2889 fail= true; 2890 if (alpha.level() != 1 && V_buf != alpha) 2891 prune1 (alpha); 2850 2892 return 0; 2851 2893 } … … 2870 2912 delete [] bufpEvalPoints; 2871 2913 fail= true; 2914 if (alpha.level() != 1 && V_buf != alpha) 2915 prune1 (alpha); 2872 2916 return 0; 2873 2917 } … … 2906 2950 delete [] bufpEvalPoints; 2907 2951 fail= true; 2952 if (alpha.level() != 1 && V_buf != alpha) 2953 prune1 (alpha); 2908 2954 return 0; 2909 2955 } … … 2922 2968 CFList u, v; 2923 2969 result= mapDown (result,prim_elem_alpha, im_prim_elem_alpha, alpha, u, v); 2970 prune1 (alpha); 2924 2971 } 2925 2972 result= N(result); … … 2987 3034 delete[] pM; 2988 3035 fail= true; 3036 if (alpha.level() != 1 && V_buf != alpha) 3037 prune1 (alpha); 2989 3038 return 0; 2990 3039 } … … 3007 3056 CFList u, v; 3008 3057 result= mapDown (result, prim_elem, im_prim_elem, alpha, u, v); 3058 prune1 (alpha); 3009 3059 } 3010 3060 result= N(result); … … 3195 3245 3196 3246 if (d0 == 0) 3247 { 3248 if (inextension) 3249 prune1 (alpha); 3197 3250 return N(gcdcAcB); 3251 } 3198 3252 if (d0 > d) 3199 3253 { … … 3238 3292 ppH /= Lc(ppH); 3239 3293 DEBOUTLN (cerr, "ppH after mapDown= " << ppH); 3294 prune1 (alpha); 3240 3295 return N(gcdcAcB*ppH); 3241 3296 } … … 3374 3429 3375 3430 if (d0 == 0) 3431 { 3432 if (inextension) 3433 prune1 (alpha); 3376 3434 return N(gcdcAcB); 3435 } 3377 3436 if (d0 > d) 3378 3437 { … … 3421 3480 ppH /= Lc(ppH); 3422 3481 DEBOUTLN (cerr, "ppH after mapDown= " << ppH); 3482 prune1 (alpha); 3423 3483 return N(gcdcAcB*ppH); 3424 3484 } … … 3518 3578 topLevel= false; 3519 3579 bool inextension= false; 3520 Variable V_buf, alpha ;3580 Variable V_buf, alpha, cleanUp; 3521 3581 CanonicalForm prim_elem, im_prim_elem; 3522 3582 CFList source, dest; … … 3563 3623 CanonicalForm mipo; 3564 3624 int deg= 2; 3625 bool initialized= false; 3565 3626 do 3566 3627 { 3567 3628 mipo= randomIrredpoly (deg, x); 3568 alpha= rootOf (mipo); 3629 if (initialized) 3630 setMipo (alpha, mipo); 3631 else 3632 alpha= rootOf (mipo); 3569 3633 inextension= true; 3570 3634 fail= false; 3635 initialized= true; 3571 3636 random_element= randomElement (m, alpha, l, fail); 3572 3637 deg++; 3573 3638 } while (fail); 3639 cleanUp= alpha; 3574 3640 V_buf= alpha; 3575 3641 list= CFList(); … … 3650 3716 3651 3717 if (d0 == 0) 3718 { 3719 if (inextension) 3720 prune (cleanUp); 3652 3721 return N(gcdcAcB); 3722 } 3653 3723 if (d0 > d) 3654 3724 { … … 3688 3758 3689 3759 if (fdivides (ppH, ppA) && fdivides (ppH, ppB)) 3760 { 3761 if (inextension) 3762 prune (cleanUp); 3690 3763 return N(gcdcAcB*ppH); 3764 } 3691 3765 } 3692 3766 G_m= H; … … 3758 3832 CanonicalForm mipo; 3759 3833 int deg= 2; 3834 bool initialized= false; 3760 3835 do 3761 3836 { 3762 3837 mipo= randomIrredpoly (deg, x); 3763 alpha= rootOf (mipo); 3838 if (initialized) 3839 setMipo (alpha, mipo); 3840 else 3841 alpha= rootOf (mipo); 3764 3842 inextension= true; 3765 3843 fail= false; 3844 initialized= true; 3766 3845 random_element= randomElement (m, alpha, l, fail); 3767 3846 deg++; 3768 3847 } while (fail); 3848 cleanUp= alpha; 3769 3849 V_buf= alpha; 3770 3850 list= CFList(); … … 3862 3942 3863 3943 if (d0 == 0) 3944 { 3945 if (inextension) 3946 prune (cleanUp); 3864 3947 return N(gcdcAcB); 3948 } 3865 3949 if (d0 > d) 3866 3950 { … … 3901 3985 DEBOUTLN (cerr, "ppH= " << ppH); 3902 3986 if (fdivides (ppH, ppA) && fdivides (ppH, ppB)) 3987 { 3988 if (inextension) 3989 prune (cleanUp); 3903 3990 return N(gcdcAcB*ppH); 3991 } 3904 3992 } 3905 3993 … … 3913 4001 } 3914 4002 else 4003 { 4004 if (inextension) 4005 prune (cleanUp); 3915 4006 return N(gcdcAcB*modGCDFp (ppA, ppB)); 4007 } 3916 4008 } while (1); //end of first do 3917 4009 } -
factory/cfModResultant.cc
r3169ca r2a2e43 24 24 #include "cf_algorithm.h" 25 25 #include "cf_iter.h" 26 #include "cf_irred.h" 27 #include "cf_generator.h" 28 #include "cf_random.h" 29 #include "cf_map_ext.h" 30 #include "facFqBivarUtil.h" 26 31 27 32 #ifdef HAVE_NTL … … 253 258 if (F.isZero() || G.isZero()) 254 259 return 0; 260 Variable alpha; 255 261 256 262 #ifdef HAVE_FLINT 257 nmod_poly_t FLINTF, FLINTG; 258 convertFacCF2nmod_poly_t (FLINTF, F); 259 convertFacCF2nmod_poly_t (FLINTG, G); 260 mp_limb_t FLINTresult= nmod_poly_resultant (FLINTF, FLINTG); 261 nmod_poly_clear (FLINTF); 262 nmod_poly_clear (FLINTG); 263 return CanonicalForm ((long) FLINTresult); 263 if (!hasFirstAlgVar (F, alpha) && !hasFirstAlgVar (G,alpha)) 264 { 265 nmod_poly_t FLINTF, FLINTG; 266 convertFacCF2nmod_poly_t (FLINTF, F); 267 convertFacCF2nmod_poly_t (FLINTG, G); 268 mp_limb_t FLINTresult= nmod_poly_resultant (FLINTF, FLINTG); 269 nmod_poly_clear (FLINTF); 270 nmod_poly_clear (FLINTG); 271 return CanonicalForm ((long) FLINTresult); 272 } 264 273 #else 274 if (!hasFirstAlgVar (F, alpha) && !hasFirstAlgVar (G,alpha)) 275 { 276 if (fac_NTL_char != getCharacteristic()) 277 { 278 fac_NTL_char= getCharacteristic(); 279 zz_p::init (getCharacteristic()); 280 } 281 zz_pX NTLF= convertFacCF2NTLzzpX (F); 282 zz_pX NTLG= convertFacCF2NTLzzpX (G); 283 284 zz_p NTLResult= resultant (NTLF, NTLG); 285 286 return CanonicalForm (to_long (rep (NTLResult))); 287 } 288 #endif 289 //at this point F or G has an algebraic var. 265 290 if (fac_NTL_char != getCharacteristic()) 266 291 { … … 268 293 zz_p::init (getCharacteristic()); 269 294 } 270 zz_pX NTL F= convertFacCF2NTLzzpX (F);271 zz_p X NTLG= convertFacCF2NTLzzpX (G);272 273 zz_p NTLResult= resultant (NTLF, NTLG);274 275 return CanonicalForm (to_long (rep (NTLResult))); 276 #endif 295 zz_pX NTLMipo= convertFacCF2NTLzzpX (getMipo (alpha)); 296 zz_pE::init (NTLMipo); 297 zz_pEX NTLF= convertFacCF2NTLzz_pEX (F, NTLMipo); 298 zz_pEX NTLG= convertFacCF2NTLzz_pEX (G, NTLMipo); 299 zz_pE NTLResult= resultant (NTLF, NTLG); 300 301 return convertNTLzzpE2CF (NTLResult, alpha); 277 302 #else 278 303 return resultant (F, G, F.mvar()); … … 282 307 static inline 283 308 void evalPoint (const CanonicalForm& F, const CanonicalForm& G, 284 CanonicalForm& FEval, CanonicalForm& GEval, int& evalPoint) 309 CanonicalForm& FEval, CanonicalForm& GEval, 310 CFGenerator& evalPoint) 285 311 { 286 312 int degF, degG; … … 290 316 do 291 317 { 292 evalPoint++; 293 if (evalPoint >= getCharacteristic()) 318 if (!evalPoint.hasItems()) 294 319 break; 295 FEval= F (evalPoint , 2);296 GEval= G (evalPoint , 2);320 FEval= F (evalPoint.item(), 2); 321 GEval= G (evalPoint.item(), 2); 297 322 if (degree (FEval, 1) < degF || degree (GEval, 1) < degG) 323 { 324 evalPoint.next(); 298 325 continue; 326 } 299 327 else 300 328 return; 301 329 } 302 while (evalPoint < getCharacteristic());330 while (evalPoint.hasItems()); 303 331 } 304 332 … … 350 378 Variable y= Variable (2); 351 379 352 int i= -1;353 380 CanonicalForm GEval, FEval, recResult, H; 354 381 CanonicalForm newtonPoly= 1; … … 358 385 int bound= degAx*degree (G, 2) + degree (F, 2)*degBx; 359 386 387 int p= getCharacteristic(); 388 CanonicalForm minpoly; 389 Variable alpha= Variable (tmax (F.level(), G.level()) + 1); 390 bool algExt= hasFirstAlgVar (F, alpha) || hasFirstAlgVar (G, alpha); 391 CFGenerator * gen; 392 bool extOfExt= false; 393 Variable v= alpha; 394 CanonicalForm primElemAlpha, imPrimElemAlpha; 395 CFList source,dest; 396 if (!algExt && (p < (1 << 28))) 397 { 398 // pass to an extension of size at least 2^29 399 // for very very large input that is maybe too small though 400 int deg= ceil (29.0*((double) log (2)/log (p)))+1; 401 minpoly= randomIrredpoly (deg, z); 402 alpha= rootOf (minpoly); 403 AlgExtGenerator AlgExtGen (alpha); 404 gen= AlgExtGen.clone(); 405 for (int i= 0; i < p; i++) // skip values from the prime field 406 (*gen).next(); 407 } 408 else if (!algExt) 409 { 410 FFGenerator FFGen; 411 gen= FFGen.clone(); 412 } 413 else 414 { 415 int deg= ceil (29.0*((double) log (2)/log (p))); 416 if (degree (getMipo (alpha)) < deg) 417 { 418 mpz_t field_size; 419 mpz_init (field_size); 420 mpz_ui_pow_ui (field_size, p, 421 deg + degree (getMipo (alpha)) - deg%degree (getMipo (alpha))); 422 423 // field_size needs to fit in an int because of mapUp, mapDown, length of lists etc. 424 if (mpz_fits_sint_p (field_size)) 425 { 426 minpoly= randomIrredpoly (deg + degree (getMipo (alpha)) 427 - deg%degree (getMipo (alpha)), z); 428 v= rootOf (minpoly); 429 Variable V_buf2; 430 bool primFail= false; 431 extOfExt= true; 432 primElemAlpha= primitiveElement (alpha, V_buf2, primFail); 433 ASSERT (!primFail, "failure in integer factorizer"); 434 if (primFail) 435 ; //ERROR 436 else 437 imPrimElemAlpha= mapPrimElem (primElemAlpha, alpha, v); 438 F= mapUp (F, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest); 439 G= mapUp (G, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest); 440 } 441 else 442 { 443 deg= deg - deg % degree (getMipo (alpha)); 444 mpz_ui_pow_ui (field_size, p, deg); 445 while (deg / degree (getMipo (alpha)) >= 2 && !mpz_fits_sint_p (field_size)) 446 { 447 deg -= degree (getMipo (alpha)); 448 mpz_ui_pow_ui (field_size, p, deg); 449 } 450 if (deg != degree (getMipo (alpha))) 451 { 452 minpoly= randomIrredpoly (deg, z); 453 v= rootOf (minpoly); 454 Variable V_buf2; 455 bool primFail= false; 456 extOfExt= true; 457 primElemAlpha= primitiveElement (alpha, V_buf2, primFail); 458 ASSERT (!primFail, "failure in integer factorizer"); 459 if (primFail) 460 ; //ERROR 461 else 462 imPrimElemAlpha= mapPrimElem (primElemAlpha, alpha, v); 463 F= mapUp (F, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest); 464 G= mapUp (G, alpha, v, primElemAlpha, imPrimElemAlpha, source, dest); 465 } 466 } 467 mpz_clear (field_size); 468 } 469 AlgExtGenerator AlgExtGen (v); 470 gen= AlgExtGen.clone(); 471 for (int i= 0; i < p; i++) 472 (*gen).next(); 473 } 360 474 int count= 0; 361 475 int equalCount= 0; 476 CanonicalForm point; 362 477 do 363 478 { 364 evalPoint (F, G, FEval, GEval, i); 365 366 ASSERT (i < getCharacteristic(), "ran out of points"); 367 368 recResult= resultantFp (FEval, GEval, z); 369 370 H= newtonInterp (i, recResult, newtonPoly, modResult, y); 479 evalPoint (F, G, FEval, GEval, *gen); 480 481 recResult= resultantFp (FEval, GEval, z, prob); 482 483 H= newtonInterp ((*gen).item(), recResult, newtonPoly, modResult, y); 371 484 372 485 if (H == modResult) … … 377 490 count++; 378 491 if (count > bound || (prob && equalCount == 2)) 379 break; 492 { 493 if (!algExt && degree (H, alpha) <= 0) 494 break; 495 else if (algExt) 496 { 497 if (extOfExt && !isInExtension (H, imPrimElemAlpha, 1, primElemAlpha, 498 dest, source)) 499 { 500 H= mapDown (H, primElemAlpha, imPrimElemAlpha, alpha, dest, source); 501 prune (v); 502 break; 503 } 504 else if (!extOfExt) 505 break; 506 } 507 } 380 508 381 509 modResult= H; 382 newtonPoly *= (y - i); 510 newtonPoly *= (y - (*gen).item()); 511 if ((*gen).hasItems()) 512 (*gen).next(); 513 else 514 STICKYASSERT (0, "out of evaluation points"); 383 515 } while (1); 516 517 delete gen; 384 518 385 519 return N (H); -
factory/cf_cyclo.cc
r3169ca r2a2e43 131 131 for (int i= 0; i < distinct_factors_length; i++) 132 132 { 133 result= result (power (x, distinct_factors[i]), x)/result;133 result= leftShift (result, distinct_factors[i])/result; 134 134 prod *= distinct_factors[i]; 135 135 } 136 return result (power (x, n/prod), x);136 return leftShift (result, n/prod); 137 137 } 138 138 -
factory/cf_map_ext.cc
r3169ca r2a2e43 165 165 { 166 166 Variable beta= rootOf (gf_mipo); 167 return GF2FalphaHelper (F, beta) (alpha, beta); 167 CanonicalForm result= GF2FalphaHelper (F, beta) (alpha, beta); 168 prune (beta); 169 return result; 168 170 } 169 171 … … 339 341 primitive= false; 340 342 fail= false; 343 bool initialized= false; 341 344 do 342 345 { 343 346 BuildIrred (NTL_mipo, d); 344 347 mipo2= convertNTLzzpX2CF (NTL_mipo, Variable (1)); 345 beta= rootOf (mipo2); 348 if (!initialized) 349 beta= rootOf (mipo2); 350 else 351 setMipo (beta, mipo2); 346 352 primitive= isPrimitive (beta, fail); 347 353 if (primitive) -
factory/cf_ops.cc
r3169ca r2a2e43 677 677 return false; 678 678 } 679 680 /** left shift the main variable of F by n 681 * @return if x is the main variable of F the result is F(x^n) 682 **/ 683 CanonicalForm leftShift (const CanonicalForm& F, int n) 684 { 685 ASSERT (n >= 0, "cannot left shift by negative number"); 686 if (F.inBaseDomain()) 687 return F; 688 if (n == 0) 689 return F; 690 Variable x=F.mvar(); 691 CanonicalForm result= 0; 692 for (CFIterator i= F; i.hasTerms(); i++) 693 result += i.coeff()*power (x, i.exp()*n); 694 return result; 695 } -
factory/facAlgFunc.cc
r3169ca r2a2e43 367 367 j.getItem()= j.getItem() (rb, i.getItem().mvar()); 368 368 } 369 prune (alpha); 369 370 } 370 371 else … … 463 464 if (!isRat && getCharacteristic() == 0) 464 465 Off (SW_RATIONAL); 466 prune (alpha); 465 467 return L; 466 468 } … … 1000 1002 } 1001 1003 Factorlist= Trager(f, Astar, vminpoly, as, isFunctionField); 1004 if (extdeg > 1) 1005 prune (vminpoly); 1002 1006 return Factorlist; 1003 1007 } … … 1015 1019 } 1016 1020 Factorlist= Trager (f, Astar, vminpoly, as, isFunctionField); 1021 if (extdeg > 1) 1022 prune (vminpoly); 1017 1023 return Factorlist; 1018 1024 } -
factory/facBivar.cc
r3169ca r2a2e43 578 578 for (CFListIterator iter= uniFactors; iter.hasItem(); iter++) 579 579 iter.getItem()= replacevar (iter.getItem(), vv, v); 580 prune (vv); 580 581 } 581 582 -
factory/facFqBivar.cc
r3169ca r2a2e43 233 233 i.getItem()= CFFactor (buf, i.getItem().exp()); 234 234 } 235 prune (beta); 235 236 } 236 237 else if (alpha.level() != 1) … … 8850 8851 for (CFListIterator j= factors; j.hasItem(); j++) 8851 8852 j.getItem()= GF2FalphaRep (j.getItem(), vBuf); 8853 prune (vBuf); 8852 8854 } 8853 8855 else // not able to pass to GF, pass to F_p(\alpha) … … 8857 8859 ExtensionInfo info2= ExtensionInfo (v); 8858 8860 factors= biFactorize (A, info2); 8861 prune (v); 8859 8862 } 8860 8863 return factors; … … 8870 8873 ExtensionInfo info2= ExtensionInfo (v); 8871 8874 factors= biFactorize (A, info2); 8875 prune (v); 8872 8876 } 8873 8877 else … … 8891 8895 ExtensionInfo info2= ExtensionInfo (v, alpha, imPrimElem, primElem); 8892 8896 factors= biFactorize (bufA, info2); 8897 prune (v); 8893 8898 } 8894 8899 else … … 8911 8916 ExtensionInfo info2= ExtensionInfo (v, beta, imPrimElem, delta); 8912 8917 factors= biFactorize (bufA, info2); 8918 prune (v); 8913 8919 } 8914 8920 } … … 8933 8939 ExtensionInfo info2= ExtensionInfo (extension); 8934 8940 factors= biFactorize (A.mapinto(), info2); 8941 prune (vBuf); 8935 8942 } 8936 8943 else // not able to pass to another GF, pass to F_p(\alpha) … … 8943 8950 ExtensionInfo info2= ExtensionInfo (v, extension); 8944 8951 factors= biFactorize (A, info2); 8952 prune (vBuf); 8945 8953 } 8946 8954 } … … 8980 8988 for (CFListIterator i= factors; i.hasItem(); i++) 8981 8989 i.getItem()= Falpha2GFRep (i.getItem()); 8990 prune (v1); 8982 8991 } 8983 8992 } -
factory/facFqFactorize.cc
r3169ca r2a2e43 2044 2044 tmp= iter.getItem() (evalPoint, x); 2045 2045 tmp /= Lc (tmp); 2046 if ( pos= findItem (factors2, tmp))2046 if ((pos= findItem (factors2, tmp))) 2047 2047 { 2048 2048 result2.append (getItem (factors3, pos)); … … 3647 3647 for (CFListIterator j= factors; j.hasItem(); j++) 3648 3648 j.getItem()= GF2FalphaRep (j.getItem(), vBuf); 3649 prune (vBuf); 3649 3650 } 3650 3651 else if (p >= 7 && p*p < (1<<16)) // pass to GF if possible … … 3660 3661 for (CFListIterator j= factors; j.hasItem(); j++) 3661 3662 j.getItem()= GF2FalphaRep (j.getItem(), vBuf); 3663 prune (vBuf); 3662 3664 } 3663 3665 else // not able to pass to GF, pass to F_p(\alpha) … … 3667 3669 ExtensionInfo info= ExtensionInfo (v); 3668 3670 factors= multiFactorize (A, info); 3671 prune (v); 3669 3672 } 3670 3673 return factors; … … 3680 3683 ExtensionInfo info= ExtensionInfo (v); 3681 3684 factors= multiFactorize (A, info); 3685 prune (v); 3682 3686 } 3683 3687 else … … 3701 3705 ExtensionInfo info= ExtensionInfo (v, alpha, imPrimElem, primElem); 3702 3706 factors= multiFactorize (bufA, info); 3707 prune (v); 3703 3708 } 3704 3709 else … … 3721 3726 ExtensionInfo info= ExtensionInfo (v, beta, imPrimElem, delta); 3722 3727 factors= multiFactorize (bufA, info); 3728 prune (v); 3723 3729 } 3724 3730 } … … 3743 3749 ExtensionInfo info= ExtensionInfo (extension); 3744 3750 factors= multiFactorize (A.mapinto(), info); 3751 prune (vBuf); 3745 3752 } 3746 3753 else // not able to pass to another GF, pass to F_p(\alpha) … … 3753 3760 ExtensionInfo info= ExtensionInfo (v, extension); 3754 3761 factors= multiFactorize (A, info); 3762 prune (vBuf); 3755 3763 } 3756 3764 } … … 3788 3796 for (CFListIterator i= factors; i.hasItem(); i++) 3789 3797 i.getItem()= Falpha2GFRep (i.getItem()); 3798 prune (v1); 3790 3799 } 3791 3800 } -
factory/facMul.cc
r3169ca r2a2e43 230 230 mulFLINTQTrunc (const CanonicalForm& F, const CanonicalForm& G, int m) 231 231 { 232 if (F.inCoeffDomain() || G.inCoeffDomain()) 233 return mod (F*G, power (Variable (1), m)); 232 if (F.inCoeffDomain() && G.inCoeffDomain()) 233 return F*G; 234 if (F.inCoeffDomain()) 235 return mod (F*G, power (G.mvar(), m)); 236 if (G.inCoeffDomain()) 237 return mod (F*G, power (F.mvar(), m)); 234 238 Variable alpha; 235 239 if (hasFirstAlgVar (F, alpha) || hasFirstAlgVar (G, alpha)) … … 257 261 } 258 262 259 CanonicalForm uniReverse (const CanonicalForm& F, int d )263 CanonicalForm uniReverse (const CanonicalForm& F, int d, const Variable& x) 260 264 { 261 265 if (d == 0) 262 266 return F; 263 267 if (F.inCoeffDomain()) 264 return F*power (Variable (1),d); 265 Variable x= Variable (1); 268 return F*power (x,d); 266 269 CanonicalForm result= 0; 267 270 CFIterator i= F; … … 275 278 276 279 CanonicalForm 277 newtonInverse (const CanonicalForm& F, const int n )280 newtonInverse (const CanonicalForm& F, const int n, const Variable& x) 278 281 { 279 282 int l= ilog2(n); 280 283 281 CanonicalForm g= F [0]; 282 284 CanonicalForm g; 285 if (F.inCoeffDomain()) 286 g= F; 287 else 288 g= F [0]; 289 290 if (!F.inCoeffDomain()) 291 ASSERT (F.mvar() == x, "main variable of F and x differ"); 283 292 ASSERT (!g.isZero(), "expected a unit"); 284 293 285 294 if (!g.isOne()) 286 295 g = 1/g; 287 Variable x= Variable (1);288 296 CanonicalForm result; 289 297 int exp= 0; … … 328 336 CanonicalForm& R) 329 337 { 338 ASSERT (F.level() == G.level(), "F and G have different level"); 330 339 CanonicalForm A= F; 331 340 CanonicalForm B= G; 332 Variable x= Variable (1);333 int degA= degree (A , x);334 int degB= degree (B , x);341 Variable x= A.mvar(); 342 int degA= degree (A); 343 int degB= degree (B); 335 344 int m= degA - degB; 336 345 … … 346 355 else 347 356 { 348 R= uniReverse (A, degA); 349 350 CanonicalForm revB= uniReverse (B, degB); 351 CanonicalForm buf= revB; 352 revB= newtonInverse (revB, m + 1); 357 R= uniReverse (A, degA, x); 358 359 CanonicalForm revB= uniReverse (B, degB, x); 360 revB= newtonInverse (revB, m + 1, x); 353 361 Q= mulFLINTQTrunc (R, revB, m + 1); 354 Q= uniReverse (Q, m );362 Q= uniReverse (Q, m, x); 355 363 356 364 R= A - mulNTL (Q, B); … … 361 369 newtonDiv (const CanonicalForm& F, const CanonicalForm& G, CanonicalForm& Q) 362 370 { 371 ASSERT (F.level() == G.level(), "F and G have different level"); 363 372 CanonicalForm A= F; 364 373 CanonicalForm B= G; 365 Variable x= Variable (1);366 int degA= degree (A , x);367 int degB= degree (B , x);374 Variable x= A.mvar(); 375 int degA= degree (A); 376 int degB= degree (B); 368 377 int m= degA - degB; 369 378 … … 378 387 else 379 388 { 380 CanonicalForm R= uniReverse (A, degA); 381 382 CanonicalForm revB= uniReverse (B, degB); 383 revB= newtonInverse (revB, m + 1); 389 CanonicalForm R= uniReverse (A, degA, x); 390 CanonicalForm revB= uniReverse (B, degB, x); 391 revB= newtonInverse (revB, m + 1, x); 384 392 Q= mulFLINTQTrunc (R, revB, m + 1); 385 Q= uniReverse (Q, m );393 Q= uniReverse (Q, m, x); 386 394 } 387 395 } … … 3695 3703 } 3696 3704 CanonicalForm Q, R; 3697 Variable x= Variable (1); 3698 Variable y= Variable (2); 3699 newtonDivrem (swapvar (B, y, x), swapvar (A, y, x), Q, R); 3705 newtonDivrem (B, A, Q, R); 3700 3706 if (!isRat) 3701 3707 Off (SW_RATIONAL); -
factory/variable.cc
r3169ca r2a2e43 220 220 { 221 221 ASSERT( alpha.level() < 0 && alpha.level() != LEVELBASE, "illegal extension" ); 222 algextensions[-alpha.level()]= ext_entry( 0, false ); 222 223 algextensions[-alpha.level()]= ext_entry((InternalPoly*)(conv2mipo( mipo, alpha ).getval()), true ); 223 224 } … … 256 257 return 0; 257 258 return strlen( var_names_ext )-1; 259 } 260 261 void prune (Variable& alpha) 262 { 263 int i, n = strlen( var_names_ext ); 264 ASSERT (n+1 >= -alpha.level(), "wrong variable"); 265 if (-alpha.level() == 1) 266 { 267 delete [] var_names_ext; 268 delete [] algextensions; 269 var_names_ext= 0; 270 algextensions= 0; 271 alpha= Variable(); 272 return; 273 } 274 char * newvarnames = new char [-alpha.level() + 1]; 275 for ( i = 0; i < -alpha.level(); i++ ) 276 newvarnames[i] = var_names_ext[i]; 277 newvarnames[-alpha.level()] = 0; 278 delete [] var_names_ext; 279 var_names_ext = newvarnames; 280 ext_entry * newalgext = new ext_entry [-alpha.level()]; 281 for ( i = 0; i < -alpha.level(); i++ ) 282 newalgext[i] = algextensions[i]; 283 delete [] algextensions; 284 algextensions = newalgext; 285 alpha= Variable(); 286 } 287 288 void prune1 (const Variable& alpha) 289 { 290 int i, n = strlen( var_names_ext ); 291 ASSERT (n+1 >= -alpha.level(), "wrong variable"); 292 293 char * newvarnames = new char [-alpha.level() + 2]; 294 for ( i = 0; i <= -alpha.level(); i++ ) 295 newvarnames[i] = var_names_ext[i]; 296 newvarnames[-alpha.level()+1] = 0; 297 delete [] var_names_ext; 298 var_names_ext = newvarnames; 299 ext_entry * newalgext = new ext_entry [-alpha.level()+1]; 300 for ( i = 0; i <= -alpha.level(); i++ ) 301 newalgext[i] = algextensions[i]; 302 delete [] algextensions; 303 algextensions = newalgext; 258 304 } 259 305 -
factory/variable.h
r3169ca r2a2e43 103 103 char getDefaultExtName(); 104 104 105 void prune (Variable& alpha); 106 void prune1 (const Variable& alpha); 105 107 int ExtensionLevel(); 106 108 -
libpolys/polys/clapsing.cc
r3169ca r2a2e43 124 124 G( convSingAPFactoryAP( g,a,r ) ); 125 125 res= convFactoryAPSingAP( gcd( F, G ),r ); 126 prune (a); 126 127 if (!b1) Off(SW_USE_QGCD); 127 128 } … … 235 236 } 236 237 res= convFactoryAPSingAP( GCD,r ); 238 prune (a); 237 239 if (!b1) Off(SW_USE_QGCD); 238 240 } … … 343 345 G( convSingAPFactoryAP( g,a,r ) ); 344 346 res= convFactoryAPSingAP( resultant( F, G, X ),r ); 347 prune (a); 345 348 } 346 349 else … … 497 500 pa=convFactoryAPSingAP(Fa,r); 498 501 pb=convFactoryAPSingAP(Gb,r); 502 prune (a); 499 503 } 500 504 else … … 556 560 G( convSingAPFactoryAP( g,a,r ) ); 557 561 res= convFactoryAPSingAP( F / G, r ); 562 prune (a); 558 563 } 559 564 else … … 745 750 } 746 751 } 752 if (r->cf->extRing!=NULL) 753 if (r->cf->extRing->qideal!=NULL) 754 prune (a); 747 755 if (e==0) 748 756 { … … 841 849 number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf); 842 850 851 Variable a; 843 852 if (!rField_is_Zp(r) && !rField_is_Zp_a(r)) /* Q, Q(a) */ 844 853 { … … 894 903 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0], 895 904 r->cf->extRing); 896 Variablea=rootOf(mipo);905 a=rootOf(mipo); 897 906 CanonicalForm F( convSingAPFactoryAP( f, a, r ) ); 898 907 if (rField_is_Zp_a(r)) … … 982 991 } 983 992 } 993 if (r->cf->extRing!=NULL) 994 if (r->cf->extRing->qideal!=NULL) 995 prune (a); 984 996 #ifndef SING_NDEBUG 985 997 if ((r->cf->extRing!=NULL) && (!p_IsConstantPoly(ff,r))) … … 1210 1222 number NN=NULL; 1211 1223 number old_lead_coeff=n_Copy(pGetCoeff(f), r->cf); 1224 Variable a; 1212 1225 1213 1226 if (!rField_is_Zp(r) && !rField_is_Zp_a(r)) /* Q, Q(a) */ … … 1261 1274 CanonicalForm mipo=convSingPFactoryP(r->cf->extRing->qideal->m[0], 1262 1275 r->cf->extRing); 1263 Variablea=rootOf(mipo);1276 a=rootOf(mipo); 1264 1277 CanonicalForm F( convSingAPFactoryAP( f, a, r ) ); 1265 1278 L= sqrFree (F); … … 1336 1349 } 1337 1350 } 1351 if (r->cf->extRing!=NULL) 1352 if (r->cf->extRing->qideal!=NULL) 1353 prune (a); 1338 1354 if (rField_is_Q_a(r) && (r->cf->extRing->qideal!=NULL)) 1339 1355 { … … 1794 1810 mipos->m[i]= convFactoryPSingTrP (replacevar (iter.getItem().minpoly(), alpha, x), r); 1795 1811 } 1812 if (!iter.getItem().minpoly().isOne()) 1813 prune (alpha); 1796 1814 numFactors += count; 1797 1815 }
Note: See TracChangeset
for help on using the changeset viewer.