Changeset 8446:f935df1e363c
- Timestamp:
- 01/27/08 18:10:31 (5 years ago)
- Branch:
- default
- Files:
-
- 2 added
- 7 edited
-
c_lib/include/ntl_wrap.h (modified) (1 diff)
-
c_lib/src/ntl_wrap.cpp (modified) (2 diffs)
-
sage/libs/ntl/decl.pxi (modified) (3 diffs)
-
sage/rings/padics/eisenstein_capped_relative_element.pyx (added)
-
sage/rings/padics/eisenstein_fixed_mod_element.pyx (modified) (1 diff)
-
sage/rings/padics/padic_ZZ_pX_CR_element.pyx (modified) (2 diffs)
-
sage/rings/padics/padic_capped_relative_element.pyx (modified) (5 diffs)
-
sage/rings/padics/unramified_capped_relative_element.pyx (added)
-
setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
c_lib/include/ntl_wrap.h
r8423 r8446 200 200 EXTERN void ZZ_pX_right_pshift(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ &pn, const struct ZZ_pContext &c); 201 201 EXTERN void ZZ_pX_InvMod_newton(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ_pXModulus &F, const struct ZZ_pContext &cpn, const struct ZZ_pContext &cp); 202 EXTERN void ZZ_pX_eis_shift(struct ZZ_pX &x, const struct ZZ_pX &a, long n, const struct ZZ_pXMultiplier* low_shifter, const struct ZZ_pXMultiplier* high_shifter, const struct ZZ_pXModulus &modulus, const struct ZZ &p, const struct ZZ_pContext &cupper, const struct ZZ_pContext &clower); 202 EXTERN void ZZ_pX_eis_shift(struct ZZ_pX &x, const struct ZZ_pX &a, long n, const struct ZZ_pXMultiplier* low_shifter, const struct ZZ_pXMultiplier* high_shifter, const struct ZZ_pXModulus &modulus, const struct ZZ &p, const struct ZZ_pContext &clower); 203 203 204 #endif 204 205 -
c_lib/src/ntl_wrap.cpp
r8423 r8446 1117 1117 { 1118 1118 ctx->restore(); 1119 } 1120 1121 // Functions for using ZZ_pX's for p-adic extensions 1122 1123 void ZZ_pX_conv_modulus(ZZ_pX &fout, const ZZ_pX &fin, const ZZ_pContext &modout) 1124 { 1125 // Changes the modulus of fin to modout, and puts the result in fout. 1126 long i, n; 1127 1128 n = fin.rep.length(); 1129 fout.rep.SetLength(n); 1130 1131 ZZ_p* xp = fout.rep.elts(); 1132 const ZZ_p* ap = fin.rep.elts(); 1133 1134 // I think it's enough to just restore modout once. 1135 // This should be true as long as the function rep taking a ZZ_p as an argument 1136 // and returning a ZZ works when the ZZ_p::modulus is incorrect. 1137 modout.restore(); 1138 1139 for (i = 0; i < n; i++) 1140 { 1141 conv(xp[i], rep(ap[i])); 1142 } 1143 1144 // We may have set a leading coefficient to 0, so we have to normalize 1145 fout.normalize(); 1146 } 1147 1148 void ZZ_pEX_conv_modulus(ZZ_pEX &fout, const ZZ_pEX &fin, const ZZ_pContext &modout) 1149 { 1150 // Changes the modulus of fin to modout, and puts the result in fout. 1151 long i, n, j, m; 1152 1153 n = fin.rep.length(); 1154 fout.rep.SetLength(n); 1155 1156 ZZ_pE* outpe = fout.rep.elts(); 1157 const ZZ_pE* inpe = fin.rep.elts(); 1158 1159 ZZ_p* xp; 1160 const ZZ_p* ap; 1161 // I think it's enough to just restore modout once 1162 // This should be true as long as Loophole() offers access to 1163 // the underlying ZZ_pX representations of ZZ_pEs, 1164 // and rep of a ZZ_p (giving a ZZ) works even if the ZZ_p::modulus is 1165 // incorrect 1166 modout.restore(); 1167 1168 for (i = 0; i < n; i++) 1169 { 1170 m = rep(inpe[i]).rep.length(); 1171 outpe[i]._ZZ_pE__rep.rep.SetLength(m); 1172 1173 xp = outpe[i]._ZZ_pE__rep.rep.elts(); 1174 ap = rep(inpe[i]).rep.elts(); 1175 1176 for (j = 0; j < m; j++) 1177 conv(xp[j], rep(ap[j])); 1178 1179 // We may have set a leading coefficient to 0, so we have to normalize 1180 outpe[i]._ZZ_pE__rep.normalize(); 1181 } 1182 // We may have set a leading coefficient to 0, so we have to normalize 1183 fout.normalize(); 1184 } 1185 1186 void ZZ_pX_min_val_coeff(long & valuation, long &index, const struct ZZ_pX &f, const struct ZZ &p) 1187 { 1188 // Sets index, where the indexth coefficient of f has the minimum p-adic valuation. 1189 // Sets valuation to be this valuation. 1190 // If there are ties, index will be the lowest of the tied indices 1191 // This only makes mathematical sense when p divides the modulus of f. 1192 long i, n, v; 1193 1194 n = f.rep.length(); 1195 if (n == 0) 1196 { 1197 index = -1; 1198 return; 1199 } 1200 1201 const ZZ_p* fp = f.rep.elts(); 1202 ZZ *u = new ZZ(); 1203 1204 valuation = -1; 1205 i = 0; 1206 1207 while (valuation == -1) 1208 { 1209 if (rep(fp[i]) != 0) 1210 { 1211 index = i; 1212 valuation = ZZ_remove(*u, rep(fp[i]), p); 1213 } 1214 i++; 1215 } 1216 for (; i < n; i++) 1217 { 1218 if (rep(fp[i]) != 0) 1219 { 1220 v = ZZ_remove(*u, rep(fp[i]), p); 1221 if (v < valuation) 1222 { 1223 valuation = v; 1224 index = i; 1225 } 1226 } 1227 } 1228 delete u; 1229 } 1230 1231 long ZZ_pX_get_val_coeff(const struct ZZ_pX &f, const struct ZZ &p, long i) 1232 { 1233 // Gets the p-adic valuation of the ith coefficient of f. 1234 ZZ *u = new ZZ(); 1235 long ans = ZZ_remove(*u, rep(coeff(f, i)), p); 1236 delete u; 1237 } 1238 1239 void ZZ_pX_left_pshift(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ &pn, const struct ZZ_pContext &c) 1240 { 1241 // Multiplies each coefficient by pn, and sets the context of the answer to c. 1242 1243 long i, n; 1244 1245 n = a.rep.length(); 1246 x.rep.SetLength(n); 1247 1248 ZZ_p* xp = x.rep.elts(); 1249 const ZZ_p* ap = a.rep.elts(); 1250 1251 // I think it's enough to just restore modout once. 1252 // This should be true as long as the function rep taking a ZZ_p as an argument 1253 // and returning a ZZ works when the ZZ_p::modulus is incorrect. 1254 c.restore(); 1255 1256 for (i = 0; i < n; i++) 1257 { 1258 conv(xp[i], rep(ap[i]) * pn); 1259 } 1260 1261 // We may have set a leading coefficient to 0, so we have to normalize 1262 x.normalize(); 1263 } 1264 1265 void ZZ_pX_right_pshift(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ &pn, const struct ZZ_pContext &c) 1266 { 1267 // Divides each coefficient by pn, and sets the context of the answer to c. 1268 1269 long i, n; 1270 1271 n = a.rep.length(); 1272 x.rep.SetLength(n); 1273 1274 ZZ_p* xp = x.rep.elts(); 1275 const ZZ_p* ap = a.rep.elts(); 1276 1277 // I think it's enough to just restore modout once. 1278 // This should be true as long as the function rep taking a ZZ_p as an argument 1279 // and returning a ZZ works when the ZZ_p::modulus is incorrect. 1280 c.restore(); 1281 1282 for (i = 0; i < n; i++) 1283 { 1284 conv(xp[i], rep(ap[i]) / pn); 1285 } 1286 1287 // We may have set a leading coefficient to 0, so we have to normalize 1288 x.normalize(); 1289 } 1290 1291 void ZZ_pX_InvMod_newton(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ_pXModulus &F, const struct ZZ_pContext &cpn, const struct ZZ_pContext &cp) 1292 { 1293 int j; 1294 cp.restore(); 1295 ZZ_pX *amodp = new ZZ_pX(); 1296 ZZ_pX *xmodp = new ZZ_pX(); 1297 ZZ_pX *fmodp = new ZZ_pX(); 1298 ZZ_pX_conv_modulus(*amodp, a, cp); 1299 ZZ_pX_conv_modulus(*fmodp, F.val(), cp); 1300 InvMod(*xmodp, *amodp, *fmodp); 1301 //cout << "xmodp: " << *xmodp << "\namodp: " << *amodp << "\nfmodp: " << *fmodp << "\n"; 1302 cpn.restore(); 1303 ZZ_pX *minusa = new ZZ_pX(); 1304 ZZ_pX *xn = new ZZ_pX(); 1305 ZZ_pX_conv_modulus(*xn, *xmodp, cpn); 1306 negate(*minusa, a); 1307 do 1308 { 1309 *xn = x; 1310 // x_n = 2*x_{n-1} - a*x_{n-1}^2 = (2 - a*x_{n-1})*x_{n-1} 1311 MulMod(x, *minusa, *xn, F); 1312 SetCoeff(x, 0, ConstTerm(x) + 2); 1313 MulMod(x, x, *xn, F); 1314 //cout << "x: " << x << "\nxn: " << *xn << "\n"; 1315 //cin >> j; 1316 } while (x != (*xn)); 1317 delete amodp; 1318 delete xmodp; 1319 delete fmodp; 1320 delete minusa; 1321 delete xn; 1322 } 1323 1324 void ZZ_pX_eis_shift(struct ZZ_pX &x, const struct ZZ_pX &a, long n, const struct ZZ_pXMultiplier* low_shifter, const struct ZZ_pXMultiplier* high_shifter, const struct ZZ_pXModulus &modulus, const struct ZZ &p, const struct ZZ_pContext &clower) 1325 { 1326 long degree = deg(modulus); 1327 long pshift = n / degree; 1328 long eis_part = n % degree; 1329 long two_shift = 1; 1330 int i; 1331 1332 //cout << "eis_part: " << eis_part << "\n"; 1333 //cout << "pshift: " << pshift << "\n"; 1334 ZZ_pX low_part; // = new ZZ_pX(); 1335 ZZ_pX shifted_high_part; // = new ZZ_pX(); 1336 x = a; 1337 //cout << "beginning: a = " << a << "\n"; 1338 if (pshift) 1339 { 1340 i = 0; 1341 two_shift = 1; 1342 ZZ *pn = new ZZ(); 1343 power(*pn, p, pshift); 1344 ZZ_pX_right_pshift(x, x, *pn, clower); 1345 delete pn; 1346 while (pshift > 0) 1347 { 1348 if (pshift & 1) 1349 { 1350 MulMod(x, x, high_shifter[i], modulus); 1351 } 1352 i++; 1353 two_shift <<= 1; 1354 pshift >>= 1; 1355 } 1356 } 1357 i = 0; 1358 two_shift = 1; 1359 while (eis_part > 0) 1360 { 1361 //cout << "eis_part = " << eis_part << "\n"; 1362 if (eis_part & 1) 1363 { 1364 //cout << "i = " << i << "\n"; 1365 //cout << "two_shift = " << two_shift << "\n"; 1366 shifted_high_part = x >> two_shift; 1367 //cout << "shifted_high_part = " << shifted_high_part << "\n"; 1368 low_part = x - (shifted_high_part << two_shift); 1369 //cout << "low_part = " << low_part << "\n"; 1370 ZZ_pX_right_pshift(low_part, low_part, p, clower); 1371 //cout << "low_part = " << low_part << "\n"; 1372 MulMod(low_part, low_part, low_shifter[i], modulus); 1373 //cout << "low_part = " << low_part << "\n"; 1374 x = low_part + shifted_high_part; 1375 //cout << "x = " << x << "\n"; 1376 } 1377 i++; 1378 two_shift <<= 1; 1379 eis_part >>= 1; 1380 } 1381 //delete low_part; 1382 //delete shifted_high_part; 1119 1383 } 1120 1384 … … 1384 1648 } 1385 1649 1386 // Functions for using ZZ_pX's for p-adic extensions1387 1388 void ZZ_pX_conv_modulus(ZZ_pX &fout, const ZZ_pX &fin, const ZZ_pContext &modout)1389 {1390 // Changes the modulus of fin to modout, and puts the result in fout.1391 long i, n;1392 1393 n = fin.rep.length();1394 fout.rep.SetLength(n);1395 1396 ZZ_p* xp = fout.rep.elts();1397 const ZZ_p* ap = fin.rep.elts();1398 1399 // I think it's enough to just restore modout once.1400 // This should be true as long as the function rep taking a ZZ_p as an argument1401 // and returning a ZZ works when the ZZ_p::modulus is incorrect.1402 modout.restore();1403 1404 for (i = 0; i < n; i++)1405 {1406 conv(xp[i], rep(ap[i]));1407 }1408 1409 // We may have set a leading coefficient to 0, so we have to normalize1410 fout.normalize();1411 }1412 1413 void ZZ_pEX_conv_modulus(ZZ_pEX &fout, const ZZ_pEX &fin, const ZZ_pContext &modout)1414 {1415 // Changes the modulus of fin to modout, and puts the result in fout.1416 long i, n, j, m;1417 1418 n = fin.rep.length();1419 fout.rep.SetLength(n);1420 1421 ZZ_pE* outpe = fout.rep.elts();1422 const ZZ_pE* inpe = fin.rep.elts();1423 1424 ZZ_p* xp;1425 const ZZ_p* ap;1426 // I think it's enough to just restore modout once1427 // This should be true as long as Loophole() offers access to1428 // the underlying ZZ_pX representations of ZZ_pEs,1429 // and rep of a ZZ_p (giving a ZZ) works even if the ZZ_p::modulus is1430 // incorrect1431 modout.restore();1432 1433 for (i = 0; i < n; i++)1434 {1435 m = rep(inpe[i]).rep.length();1436 outpe[i]._ZZ_pE__rep.rep.SetLength(m);1437 1438 xp = outpe[i]._ZZ_pE__rep.rep.elts();1439 ap = rep(inpe[i]).rep.elts();1440 1441 for (j = 0; j < m; j++)1442 conv(xp[j], rep(ap[j]));1443 1444 // We may have set a leading coefficient to 0, so we have to normalize1445 outpe[i]._ZZ_pE__rep.normalize();1446 }1447 // We may have set a leading coefficient to 0, so we have to normalize1448 fout.normalize();1449 }1450 1451 void ZZ_pX_min_val_coeff(long & valuation, long &index, const struct ZZ_pX &f, const struct ZZ &p)1452 {1453 // Sets index, where the indexth coefficient of f has the minimum p-adic valuation.1454 // Sets valuation to be this valuation.1455 // If there are ties, index will be the lowest of the tied indices1456 // This only makes mathematical sense when p divides the modulus of f.1457 long i, n, v;1458 1459 n = f.rep.length();1460 if (n == 0)1461 {1462 index = -1;1463 return;1464 }1465 1466 const ZZ_p* fp = f.rep.elts();1467 ZZ *u = new ZZ();1468 1469 valuation = -1;1470 i = 0;1471 1472 while (valuation == -1)1473 {1474 if (rep(fp[i]) != 0)1475 {1476 index = i;1477 valuation = ZZ_remove(*u, rep(fp[i]), p);1478 }1479 i++;1480 }1481 for (; i < n; i++)1482 {1483 if (rep(fp[i]) != 0)1484 {1485 v = ZZ_remove(*u, rep(fp[i]), p);1486 if (v < valuation)1487 {1488 valuation = v;1489 index = i;1490 }1491 }1492 }1493 delete u;1494 }1495 1496 long ZZ_pX_get_val_coeff(const struct ZZ_pX &f, const struct ZZ &p, long i)1497 {1498 // Gets the p-adic valuation of the ith coefficient of f.1499 ZZ *u = new ZZ();1500 long ans = ZZ_remove(*u, rep(coeff(f, i)), p);1501 delete u;1502 }1503 1504 void ZZ_pX_left_pshift(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ &pn, const struct ZZ_pContext &c)1505 {1506 // Multiplies each coefficient by pn, and sets the context of the answer to c.1507 1508 long i, n;1509 1510 n = a.rep.length();1511 x.rep.SetLength(n);1512 1513 ZZ_p* xp = x.rep.elts();1514 const ZZ_p* ap = a.rep.elts();1515 1516 // I think it's enough to just restore modout once.1517 // This should be true as long as the function rep taking a ZZ_p as an argument1518 // and returning a ZZ works when the ZZ_p::modulus is incorrect.1519 c.restore();1520 1521 for (i = 0; i < n; i++)1522 {1523 conv(xp[i], rep(ap[i]) * pn);1524 }1525 1526 // We may have set a leading coefficient to 0, so we have to normalize1527 x.normalize();1528 }1529 1530 void ZZ_pX_right_pshift(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ &pn, const struct ZZ_pContext &c)1531 {1532 // Divides each coefficient by pn, and sets the context of the answer to c.1533 1534 long i, n;1535 1536 n = a.rep.length();1537 x.rep.SetLength(n);1538 1539 ZZ_p* xp = x.rep.elts();1540 const ZZ_p* ap = a.rep.elts();1541 1542 // I think it's enough to just restore modout once.1543 // This should be true as long as the function rep taking a ZZ_p as an argument1544 // and returning a ZZ works when the ZZ_p::modulus is incorrect.1545 c.restore();1546 1547 for (i = 0; i < n; i++)1548 {1549 conv(xp[i], rep(ap[i]) / pn);1550 }1551 1552 // We may have set a leading coefficient to 0, so we have to normalize1553 x.normalize();1554 }1555 1556 void ZZ_pX_InvMod_newton(struct ZZ_pX &x, const struct ZZ_pX &a, const struct ZZ_pXModulus &F, const struct ZZ_pContext &cpn, const struct ZZ_pContext &cp)1557 {1558 int j;1559 cp.restore();1560 ZZ_pX *amodp = new ZZ_pX();1561 ZZ_pX *xmodp = new ZZ_pX();1562 ZZ_pX *fmodp = new ZZ_pX();1563 ZZ_pX_conv_modulus(*amodp, a, cp);1564 ZZ_pX_conv_modulus(*fmodp, F.val(), cp);1565 InvMod(*xmodp, *amodp, *fmodp);1566 //cout << "xmodp: " << *xmodp << "\namodp: " << *amodp << "\nfmodp: " << *fmodp << "\n";1567 cpn.restore();1568 ZZ_pX *minusa = new ZZ_pX();1569 ZZ_pX *xn = new ZZ_pX();1570 ZZ_pX_conv_modulus(*xn, *xmodp, cpn);1571 negate(*minusa, a);1572 do1573 {1574 *xn = x;1575 // x_n = 2*x_{n-1} - a*x_{n-1}^2 = (2 - a*x_{n-1})*x_{n-1}1576 MulMod(x, *minusa, *xn, F);1577 SetCoeff(x, 0, ConstTerm(x) + 2);1578 MulMod(x, x, *xn, F);1579 //cout << "x: " << x << "\nxn: " << *xn << "\n";1580 //cin >> j;1581 } while (x != (*xn));1582 delete amodp;1583 delete xmodp;1584 delete fmodp;1585 delete minusa;1586 delete xn;1587 }1588 1589 void ZZ_pX_eis_shift(struct ZZ_pX &x, const struct ZZ_pX &a, long n, const struct ZZ_pXMultiplier* low_shifter, const struct ZZ_pXMultiplier* high_shifter, const struct ZZ_pXModulus &modulus, const struct ZZ &p, const struct ZZ_pContext &cupper, const struct ZZ_pContext &clower)1590 {1591 long degree = deg(modulus);1592 long pshift = n / degree;1593 long eis_part = n % degree;1594 long two_shift = 1;1595 int i;1596 1597 cupper.restore();1598 //cout << "eis_part: " << eis_part << "\n";1599 //cout << "pshift: " << pshift << "\n";1600 ZZ_pX low_part; // = new ZZ_pX();1601 ZZ_pX shifted_high_part; // = new ZZ_pX();1602 x = a;1603 //cout << "beginning: a = " << a << "\n";1604 if (pshift)1605 {1606 i = 0;1607 two_shift = 1;1608 ZZ *pn = new ZZ();1609 power(*pn, p, pshift);1610 ZZ_pX_right_pshift(x, x, *pn, clower);1611 delete pn;1612 while (pshift > 0)1613 {1614 if (pshift & 1)1615 {1616 MulMod(x, x, high_shifter[i], modulus);1617 }1618 i++;1619 two_shift <<= 1;1620 pshift >>= 1;1621 }1622 }1623 i = 0;1624 two_shift = 1;1625 while (eis_part > 0)1626 {1627 //cout << "eis_part = " << eis_part << "\n";1628 if (eis_part & 1)1629 {1630 //cout << "i = " << i << "\n";1631 //cout << "two_shift = " << two_shift << "\n";1632 shifted_high_part = x >> two_shift;1633 //cout << "shifted_high_part = " << shifted_high_part << "\n";1634 low_part = x - (shifted_high_part << two_shift);1635 //cout << "low_part = " << low_part << "\n";1636 ZZ_pX_right_pshift(low_part, low_part, p, cupper);1637 //cout << "low_part = " << low_part << "\n";1638 MulMod(low_part, low_part, low_shifter[i], modulus);1639 //cout << "low_part = " << low_part << "\n";1640 x = low_part + shifted_high_part;1641 //cout << "x = " << x << "\n";1642 }1643 i++;1644 two_shift <<= 1;1645 eis_part >>= 1;1646 }1647 //delete low_part;1648 //delete shifted_high_part;1649 }1650 1651 1650 ZZ_pEContext* ZZ_pEContext_new(ZZ_pX *f) 1652 1651 { -
sage/libs/ntl/decl.pxi
r8445 r8446 149 149 void ZZ_p_mul "mul"( ZZ_p_c x, ZZ_p_c a, ZZ_p_c b) 150 150 void ZZ_p_mul_long "mul"( ZZ_p_c x, ZZ_p_c a, long b) 151 void ZZ_p_div "div"( ZZ_p_c x, ZZ_p_c a, ZZ_p_c b) 151 152 void ZZ_p_negate "negate"(ZZ_p_c x, ZZ_p_c a) 152 153 void ZZ_p_power "power"(ZZ_p_c t, ZZ_p_c x, long e) … … 424 425 void ZZ_pX_right_pshift(ZZ_pX_c x, ZZ_pX_c a, ZZ_c pn, ZZ_pContext_c c) 425 426 void ZZ_pX_InvMod_newton(ZZ_pX_c x, ZZ_pX_c a, ZZ_pX_Modulus_c F, ZZ_pContext_c cpn, ZZ_pContext_c cp) 426 void ZZ_pX_eis_shift(ZZ_pX_c x, ZZ_pX_c a, long n, ZZ_pX_Multiplier_c* low_shifter, ZZ_pX_Multiplier_c* high_shifter, ZZ_pX_Modulus_c modulus, ZZ_c p, ZZ_pContext_c c upper, ZZ_pContext_c clower)427 void ZZ_pX_eis_shift(ZZ_pX_c x, ZZ_pX_c a, long n, ZZ_pX_Multiplier_c* low_shifter, ZZ_pX_Multiplier_c* high_shifter, ZZ_pX_Modulus_c modulus, ZZ_c p, ZZ_pContext_c clower) 427 428 428 429 # The following are ZZ_pX functions written in ntl_wrap, used for padics. … … 823 824 GF2EContext_c* GF2EContext_construct "Construct<GF2EContext>"(void *mem) 824 825 GF2EContext_c* GF2EContext_new_GF2X "GF2EContext_new"(GF2X_c* p) 825 GF2EContext_c* GF2EContext_construct_GF2X " GF2EContext_construct"(void *mem, GF2X_c* p)826 GF2EContext_c* GF2EContext_construct_GF2X "Construct<GF2EContext>"(void *mem, GF2X_c* p) 826 827 void GF2EContext_destruct "Destruct<GF2EContext>"(GF2EContext_c *mem) 827 828 void GF2EContext_delete "Delete<GF2EContext>"(GF2EContext_c *mem) -
sage/rings/padics/eisenstein_fixed_mod_element.pyx
r8437 r8446 76 76 self.prime_pow.get_top_modulus()[0], \ 77 77 self.prime_pow.small_powers[1], \ 78 self.prime_pow.get_top_context().x, \79 78 self.prime_pow.get_top_context().x) 80 79 if top_zeros: -
sage/rings/padics/padic_ZZ_pX_CR_element.pyx
r8439 r8446 9 9 from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class 10 10 from sage.libs.ntl.ntl_ZZ_pContext import ntl_ZZ_pContext 11 12 from sage.rings.padics.pow_computer_ext cimport PowComputer_ZZ_pX 13 from sage.rings.padics.pow_computer_ext cimport PowComputer_ZZ_pX_small_Eis 14 from sage.rings.padics.pow_computer_ext cimport PowComputer_ZZ_pX_big_Eis 11 15 12 16 cdef object infinity … … 82 86 self._set_from_ZZ_pX_c(poly.x, poly.c) 83 87 84 cdef int _set_from_mpz_rel(self, mpz_t x, unsigned long relprec) except -1: 85 self.prime_pow.restore_top_context() 86 cdef ZZ_c tmp 87 ZZ_construct(&tmp) 88 mpz_to_ZZ(&tmp, &x) 89 ZZ_pX_SetCoeff(self.value, 0, ZZ_to_ZZ_p(tmp)) 90 ZZ_destruct(&tmp) 91 92 cdef int _set_from_mpz_both(self, mpz_t x, long absprec, unsigned long relprec) except -1: 88 cdef int _set_inexact_zero(self, long absprec) except -1: 89 # self.unit should already have been set to zero 90 self.ordp = absprec 91 self.relprec = 0 92 self._normalized = 1 93 94 cdef int _set_exact_zero(self) except -1: 95 cdef long maxlong 96 if sizeof(long) == 4: 97 maxlong = 2147483647 98 elif sizeof(long) == 8: 99 maxlong = 9223372036854775807 100 else: 101 raise RuntimeError 102 self.ordp = maxlong 103 self._normalized = 1 104 105 cdef bint _is_exact_zero(self) except -2: 106 cdef long maxlong 107 if sizeof(long) == 4: 108 maxlong = 2147483647 109 elif sizeof(long) == 8: 110 maxlong = 9223372036854775807 111 else: 112 raise RuntimeError 113 if self.ordp == maxlong: 114 return 1 115 else: 116 return 0 93 117 94 95 cdef int _set_from_ZZ_pX_c(self, ZZ_pX_c poly) except -1: 96 self.prime_pow.restore_top_context() 97 ZZ_pX_conv_modulus(self.value, poly, (<ntl_ZZ_pContext_class>self.prime_pow.get_top_context()).x) 118 cdef int _set_from_ZZX_rel(self, ZZX_c poly, unsigned long relprec) except -1: 119 """ 120 self.prime_pow must already be set. 121 relprec should be in range 0 <= relprec <= self.prime_pow.ram_prec_cap 122 """ 123 if ZZX_IsZero(poly): 124 self._set_exact_zero() 125 return 126 cdef long i = 0 127 cdef long deg = ZZX_deg(poly) 128 cdef long mini = -1 129 cdef long minval 130 cdef long curval 131 cdef ZZ_c tmp_z 132 cdef ZZ_c *ppow 133 cdef ZZ_pX tmp_p 134 ZZ_construct(&tmp_z) 135 while mini == -1: 136 if not ZZ_IsZero(ZZX_coeff(poly,i)): 137 minval = ZZ_remove(tmp_z, ZZX_coeff(poly, i), self.prime_pow.pow_ZZ_tmp(1)[0]) 138 mini = i 139 i += 1 140 while i <= deg: 141 if not ZZ_IsZero(ZZX_coeff(poly,i)): 142 curval = ZZ_remove(tmp_z, ZZX_coeff(poly, i), self.prime_pow.pow_ZZ_tmp(1)[0]) 143 if curval < minval: 144 minval = curval 145 mini = i 146 i += 1 147 148 self.relprec = relprec 149 if self.prime_pow.e == 1: # unramified 150 self.prime_pow.restore_context(relprec) 151 self.ordp = minval 152 ppow = self.prime_pow.pow_ZZ_tmp(minval) 153 for i from 0 <= i <= deg: 154 ZZ_div(tmp_z, ZZX_coeff(poly, i), ppow[0]) 155 ZZ_pX_SetCoeff(self.unit, i, ZZ_to_ZZ_p(tmp_z)) 156 else: # eisenstein 157 self.ordp = minval * self.prime_pow.e + mini 158 self.prime_pow.restore_context(minval + cap_div(relprec + mini, self.prime_pow.e)) 159 ZZ_pX_construct(&tmp_p) 160 ZZX_to_ZZ_pX(tmp_p, poly) 161 if PY_TYPE_CHECK(self.prime_pow, PowComputer_ZZ_pX_small_Eis): 162 ZZ_pX_eis_shift(self.unit, tmp_p, self.ordp, (<PowComputer_ZZ_pX_small_Eis>self.prime_pow).low_shifter, \ 163 (<PowComputer_ZZ_pX_small_Eis>self.prime_pow).high_shifter, \ 164 self.prime_pow.get_modulus(cap_div(relprec, self.prime_pow.e)), \ 165 self.prime_pow.pow_ZZ_tmp(1)[0], \ 166 self.prime_pow.get_context(cap_div(relprec, self.prime_pow.e))) 167 elif PY_TYPE_CHECK(self.prime_pow, PowComputer_ZZ_pX_big_Eis): 168 ZZ_pX_eis_shift(self.unit, tmp_p, self.ordp, (<PowComputer_ZZ_pX_big_Eis>self.prime_pow).low_shifter, \ 169 (<PowComputer_ZZ_pX_big_Eis>self.prime_pow).high_shifter, \ 170 self.prime_pow.get_modulus(cap_div(relprec, self.prime_pow.e)), \ 171 self.prime_pow.pow_ZZ_tmp(1)[0], \ 172 self.prime_pow.get_context(cap_div(relprec, self.prime_pow.e))) 173 else: 174 raise RuntimeError, "prime_pow is of inconsistent type" 175 ZZ_pX_destruct(&tmp_p) 176 ZZ_destruct(&tmp_z) 177 self._normalized = 1 178 179 180 cdef int _set_from_ZZ_pX_both(self, ZZ_pX_c poly, long absprec, unsigned long relprec) except -1: 181 """ 182 self.prime_pow must already be set. 183 relprec should be in range 0 <= relprec <= self.prime_pow.ram_prec_cap 184 """ 185 if ZZ_pX_IsZero(poly): 186 self._set_inexact_zero(absprec) 187 return 188 cdef long i = 0 189 cdef long deg = ZZ_pX_deg(poly) 190 cdef long mini = -1 191 cdef long minval 192 cdef long curval 193 cdef ZZ_c tmp_z 194 cdef ZZ_c *ppow 195 cdef ZZ_pX tmp_p 196 ZZ_construct(&tmp_z) 197 while mini == -1: 198 if not ZZ_p_IsZero(ZZ_pX_coeff(poly,i)): 199 minval = ZZ_remove(tmp_z, ZZ_p_rep(ZZ_pX_coeff(poly, i)), self.prime_pow.pow_ZZ_tmp(1)[0]) 200 mini = i 201 i += 1 202 while i <= deg: 203 if not ZZ_p_IsZero(ZZ_pX_coeff(poly,i)): 204 curval = ZZ_remove(tmp_z, ZZ_p_rep(ZZ_pX_coeff(poly, i)), self.prime_pow.pow_ZZ_tmp(1)[0]) 205 if curval < minval: 206 minval = curval 207 mini = i 208 i += 1 209 if self.prime_pow.e == 1: # unramified 210 self.ordp = minval 211 self.relprec = absprec - self.ordp 212 if relprec < self.relprec: 213 self.relprec = relprec 214 elif self.relprec < 0: 215 self.set_inexact_zero(absprec) 216 return 217 self.prime_pow.restore_context(relprec) 218 ppow = self.prime_pow.pow_ZZ_tmp(minval) 219 for i from 0 <= i <= deg: 220 ZZ_div(tmp_z, ZZ_p_rep(ZZ_pX_coeff(poly, i)), ppow[0]) 221 ZZ_pX_SetCoeff(self.unit, i, ZZ_to_ZZ_p(tmp_z)) 222 else: # eisenstein 223 self.ordp = minval * self.prime_pow.e + mini 224 self.relprec = absprec - self.ordp 225 if relprec < self.relprec: 226 self.relprec = relprec 227 elif self.relprec < 0: 228 self.set_inexact_zero(absprec) 229 return 230 self.prime_pow.restore_context(minval + cap_div(relprec + mini, self.prime_pow.e)) 231 if PY_TYPE_CHECK(self.prime_pow, PowComputer_ZZ_pX_small_Eis): 232 ZZ_pX_eis_shift(self.unit, poly, self.ordp, (<PowComputer_ZZ_pX_small_Eis>self.prime_pow).low_shifter, \ 233 (<PowComputer_ZZ_pX_small_Eis>self.prime_pow).high_shifter, \ 234 self.prime_pow.get_modulus(cap_div(relprec, self.prime_pow.e)), \ 235 self.prime_pow.pow_ZZ_tmp(1)[0], \ 236 self.prime_pow.get_context(cap_div(relprec, self.prime_pow.e))) 237 elif PY_TYPE_CHECK(self.prime_pow, PowComputer_ZZ_pX_big_Eis): 238 ZZ_pX_eis_shift(self.unit, poly, self.ordp, (<PowComputer_ZZ_pX_big_Eis>self.prime_pow).low_shifter, \ 239 (<PowComputer_ZZ_pX_big_Eis>self.prime_pow).high_shifter, \ 240 self.prime_pow.get_modulus(cap_div(relprec, self.prime_pow.e)), \ 241 self.prime_pow.pow_ZZ_tmp(1)[0], \ 242 self.prime_pow.get_context(cap_div(relprec, self.prime_pow.e))) 243 else: 244 raise RuntimeError, "prime_pow is of inconsistent type" 245 ZZ_destruct(&tmp_z) 246 self._normalized = 1 247 248 cdef _normalize(self): 98 249 99 250 def __dealloc__(self): -
sage/rings/padics/padic_capped_relative_element.pyx
r8427 r8446 425 425 mpz_invert(self.unit, den_unit, self.prime_pow.pow_mpz_t_tmp(self.relprec)[0]) 426 426 mpz_mul(self.unit, self.unit, num_unit) 427 mpz_mod(self.unit, self.unit, self.prime_pow.pow_mpz_t_tmp( relprec)[0])427 mpz_mod(self.unit, self.unit, self.prime_pow.pow_mpz_t_tmp(self.relprec)[0]) 428 428 mpz_clear(num_unit) 429 429 mpz_clear(den_unit) … … 534 534 self.ordp = self.ordp + self.relprec 535 535 self.relprec = 0 536 self._normalized = 1536 self._normalized = 1 537 537 538 538 def __dealloc__(pAdicCappedRelativeElement self): … … 1564 1564 elif sizeof(long) == 8: 1565 1565 maxlong = 9223372036854775807 1566 else: 1567 raise RuntimeError 1566 1568 if v == maxlong: 1567 1569 return infinity … … 1573 1575 cdef Integer ans 1574 1576 cdef long maxlong 1577 self._normalize() 1575 1578 if mpz_sgn(self.unit) == -1: 1576 1579 if sizeof(long) == 4: … … 1578 1581 elif sizeof(long) == 8: 1579 1582 maxlong = 9223372036854775807 1583 else: 1584 raise RuntimeError 1580 1585 return maxlong 1581 1586 else: -
setup.py
r8426 r8446 207 207 libraries = ["csage", "ntl", "gmp", "gmpxx", "m", "stdc++"], 208 208 language='c++') 209 210 ntl_GF2EContext = Extension('sage.libs.ntl.ntl_GF2EContext', 211 sources = ["sage/libs/ntl/ntl_GF2EContext.pyx"], 212 libraries = ["csage", "ntl", "gmp", "gmpxx", "m", "stdc++"], 213 language = "c++") 209 214 210 215 mwrank = Extension("sage.libs.mwrank.mwrank",
Note: See TracChangeset
for help on using the changeset viewer.
