Changeset f63d2e8 in git for factory/facMul.cc
- Timestamp:
- Jan 7, 2014, 2:40:44 PM (10 years ago)
- Branches:
- (u'spielwiese', 'e7cc1ebecb61be8b9ca6c18016352af89940b21a')
- Children:
- 9fbf02f68394ff576e8b5825b51326cca02d8cdd
- Parents:
- 7ed4f6c34d2b1133b547efc14dffe495b47b317e
- git-author:
- Martin Lee <martinlee84@web.de>2014-01-07 14:40:44+01:00
- git-committer:
- Martin Lee <martinlee84@web.de>2014-01-20 16:45:04+01:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/facMul.cc
r7ed4f6c rf63d2e8 63 63 int k= 0; 64 64 int degfSubK; 65 int repLength, j; 66 CanonicalForm coeff, ff; 67 fmpz* tmp; 65 int repLength; 66 fmpq_poly_t buf; 67 fmpq_poly_t mipo; 68 convertFacCF2Fmpq_poly_t (mipo, getMipo(alpha)); 68 69 while (degf >= k) 69 70 { 70 coeff= 0;71 71 degfSubK= degf - k; 72 72 if (degfSubK >= d) … … 75 75 repLength= degfSubK + 1; 76 76 77 for (j= 0; j < repLength; j++) 78 { 79 tmp= fmpz_poly_get_coeff_ptr (F, j+k); 80 if (!fmpz_is_zero (tmp)) 81 { 82 ff= convertFmpz2CF (tmp); 83 coeff += ff*power (alpha, j); //TODO faster reduction mod alpha 84 } 85 } 86 result += coeff*power (x, i); 77 fmpq_poly_init2 (buf, repLength); 78 _fmpq_poly_set_length (buf, repLength); 79 _fmpz_vec_set (buf->coeffs, F->coeffs + k, repLength); 80 _fmpq_poly_normalise (buf); 81 fmpq_poly_rem (buf, buf, mipo); 82 83 result += convertFmpq_poly_t2FacCF (buf, alpha)*power (x, i); 84 fmpq_poly_clear (buf); 87 85 i++; 88 86 k= d*i; 89 87 } 88 fmpq_poly_clear (mipo); 90 89 result /= den; 91 90 return result; … … 1154 1153 #endif 1155 1154 1156 void kronSubQa (fmpq_poly_t result, const CanonicalForm& A, int d1, int d2)1155 /*void kronSubQa (fmpq_poly_t result, const CanonicalForm& A, int d1, int d2) 1157 1156 { 1158 1157 int degAy= degree (A); … … 1197 1196 fmpq_clear (coeff); 1198 1197 _fmpq_poly_normalise (result); 1198 }*/ 1199 1200 void kronSubQa (fmpz_poly_t result, const CanonicalForm& A, int d1, int d2) 1201 { 1202 int degAy= degree (A); 1203 fmpz_poly_init2 (result, d1*(degAy + 1)); 1204 _fmpz_poly_set_length (result, d1*(degAy + 1)); 1205 1206 fmpz_poly_t buf; 1207 1208 int k; 1209 CFIterator j; 1210 for (CFIterator i= A; i.hasTerms(); i++) 1211 { 1212 if (i.coeff().inCoeffDomain()) 1213 { 1214 k= d1*i.exp(); 1215 convertFacCF2Fmpz_poly_t (buf, i.coeff()); 1216 _fmpz_vec_set (result->coeffs + k, buf->coeffs, buf->length); 1217 fmpz_poly_clear (buf); 1218 } 1219 else 1220 { 1221 for (j= i.coeff(); j.hasTerms(); j++) 1222 { 1223 k= d1*i.exp(); 1224 k += d2*j.exp(); 1225 convertFacCF2Fmpz_poly_t (buf, j.coeff()); 1226 _fmpz_vec_set (result->coeffs + k, buf->coeffs, buf->length); 1227 fmpz_poly_clear (buf); 1228 } 1229 } 1230 } 1231 _fmpz_poly_normalise (result); 1199 1232 } 1200 1233 … … 1294 1327 1295 1328 fmpz_poly_t buf; 1296 fmpz_t coeff1, coeff2; 1297 1298 int k, kk, j, bufRepLength; 1329 1330 int k, kk; 1299 1331 for (CFIterator i= A; i.hasTerms(); i++) 1300 1332 { … … 1303 1335 k= i.exp()*d; 1304 1336 kk= (degAy - i.exp())*d; 1305 bufRepLength= (int) fmpz_poly_length (buf); 1306 for (j= 0; j < bufRepLength; j++) 1307 { 1308 fmpz_poly_get_coeff_fmpz (coeff1, subA1, j+k); 1309 fmpz_poly_get_coeff_fmpz (coeff2, buf, j); 1310 fmpz_add (coeff1, coeff1, coeff2); 1311 fmpz_poly_set_coeff_fmpz (subA1, j + k, coeff1); 1312 fmpz_poly_get_coeff_fmpz (coeff1, subA2, j + kk); 1313 fmpz_add (coeff1, coeff1, coeff2); 1314 fmpz_poly_set_coeff_fmpz (subA2, j + kk, coeff1); 1315 } 1337 _fmpz_vec_add (subA1->coeffs+k, subA1->coeffs + k, buf->coeffs, buf->length); 1338 _fmpz_vec_add (subA2->coeffs+kk, subA2->coeffs + kk, buf->coeffs, buf->length); 1316 1339 fmpz_poly_clear (buf); 1317 1340 } 1318 fmpz_clear (coeff1); 1319 fmpz_clear (coeff2); 1341 1320 1342 _fmpz_poly_normalise (subA1); 1321 1343 _fmpz_poly_normalise (subA2); … … 1326 1348 Variable y= Variable (2); 1327 1349 Variable x= Variable (1); 1328 1329 fmpz_poly_t f;1330 fmpz_poly_init (f);1331 fmpz_poly_set (f, F);1332 1350 1333 1351 fmpz_poly_t buf; 1334 1352 CanonicalForm result= 0; 1335 1353 int i= 0; 1336 int degf= fmpz_poly_degree( f);1354 int degf= fmpz_poly_degree(F); 1337 1355 int k= 0; 1338 int degfSubK, repLength, j; 1339 fmpz_t coeff; 1356 int degfSubK, repLength; 1340 1357 while (degf >= k) 1341 1358 { … … 1347 1364 1348 1365 fmpz_poly_init2 (buf, repLength); 1349 fmpz_init (coeff); 1350 for (j= 0; j < repLength; j++) 1351 { 1352 fmpz_poly_get_coeff_fmpz (coeff, f, j + k); 1353 fmpz_poly_set_coeff_fmpz (buf, j, coeff); 1354 } 1366 _fmpz_poly_set_length (buf, repLength); 1367 _fmpz_vec_set (buf->coeffs, F->coeffs+k, repLength); 1355 1368 _fmpz_poly_normalise (buf); 1356 1369 … … 1359 1372 k= d*i; 1360 1373 fmpz_poly_clear (buf); 1361 fmpz_clear (coeff); 1362 } 1363 fmpz_poly_clear (f); 1374 } 1364 1375 1365 1376 return result; 1366 1377 } 1367 1378 1368 CanonicalForm1379 /*CanonicalForm 1369 1380 reverseSubstQa (const fmpq_poly_t F, int d1, int d2, const Variable& alpha, 1370 1381 const fmpq_poly_t mipo) … … 1436 1447 fmpq_poly_clear (f); 1437 1448 return result; 1449 }*/ 1450 1451 CanonicalForm 1452 reverseSubstQa (const fmpz_poly_t F, int d1, int d2, const Variable& alpha, 1453 const fmpq_poly_t mipo) 1454 { 1455 Variable y= Variable (2); 1456 Variable x= Variable (1); 1457 1458 fmpq_poly_t buf; 1459 CanonicalForm result= 0, result2; 1460 int i= 0; 1461 int degf= fmpz_poly_degree(F); 1462 int k= 0; 1463 int degfSubK; 1464 int repLength; 1465 while (degf >= k) 1466 { 1467 degfSubK= degf - k; 1468 if (degfSubK >= d1) 1469 repLength= d1; 1470 else 1471 repLength= degfSubK + 1; 1472 1473 int j= 0; 1474 result2= 0; 1475 while (j*d2 < repLength) 1476 { 1477 fmpq_poly_init2 (buf, d2); 1478 _fmpq_poly_set_length (buf, d2); 1479 _fmpz_vec_set (buf->coeffs, F->coeffs + k*j*d2, d2); 1480 _fmpq_poly_normalise (buf); 1481 fmpq_poly_rem (buf, buf, mipo); 1482 result2 += convertFmpq_poly_t2FacCF (buf, alpha)*power (x, j); 1483 j++; 1484 fmpq_poly_clear (buf); 1485 } 1486 if (repLength - j*d2 != 0 && j*d2 - repLength < d2) 1487 { 1488 j--; 1489 repLength -= j*d2; 1490 fmpq_poly_init2 (buf, repLength); 1491 _fmpq_poly_set_length (buf, repLength); 1492 j++; 1493 _fmpz_vec_set (buf->coeffs, F->coeffs + k + j*d2, repLength); 1494 _fmpq_poly_normalise (buf); 1495 fmpq_poly_rem (buf, buf, mipo); 1496 result2 += convertFmpq_poly_t2FacCF (buf, alpha)*power (x, j); 1497 fmpq_poly_clear (buf); 1498 } 1499 1500 result += result2*power (y, i); 1501 i++; 1502 k= d1*i; 1503 } 1504 1505 return result; 1438 1506 } 1439 1507 … … 1675 1743 int degg= fmpz_poly_degree(g); 1676 1744 1677 1678 1745 fmpz_poly_t buf1,buf2, buf3; 1679 1746 … … 2078 2145 } 2079 2146 2080 CanonicalForm2147 /*CanonicalForm 2081 2148 mulMod2FLINTQa (const CanonicalForm& F, const CanonicalForm& G, 2082 2149 const CanonicalForm& M) … … 2108 2175 fmpq_poly_clear (FLINTG); 2109 2176 return result; 2177 }*/ 2178 2179 CanonicalForm 2180 mulMod2FLINTQa (const CanonicalForm& F, const CanonicalForm& G, 2181 const CanonicalForm& M) 2182 { 2183 Variable a; 2184 if (!hasFirstAlgVar (F,a) && !hasFirstAlgVar (G, a)) 2185 return mulMod2FLINTQ (F, G, M); 2186 CanonicalForm A= F, B= G; 2187 2188 int degFx= degree (F, 1); 2189 int degFa= degree (F, a); 2190 int degGx= degree (G, 1); 2191 int degGa= degree (G, a); 2192 2193 int d2= degFa+degGa+1; 2194 int d1= degFx + 1 + degGx; 2195 d1 *= d2; 2196 2197 CanonicalForm f= bCommonDen (F); 2198 CanonicalForm g= bCommonDen (G); 2199 A *= f; 2200 B *= g; 2201 2202 fmpz_poly_t FLINTF, FLINTG; 2203 kronSubQa (FLINTF, A, d1, d2); 2204 kronSubQa (FLINTG, B, d1, d2); 2205 2206 fmpz_poly_mullow (FLINTF, FLINTF, FLINTG, d1*degree (M)); 2207 2208 fmpq_poly_t mipo; 2209 convertFacCF2Fmpq_poly_t (mipo, getMipo (a)); 2210 A= reverseSubstQa (FLINTF, d1, d2, a, mipo); 2211 fmpz_poly_clear (FLINTF); 2212 fmpz_poly_clear (FLINTG); 2213 return A/(f*g); 2110 2214 } 2111 2215
Note: See TracChangeset
for help on using the changeset viewer.