Changeset 1e6de6 in git for factory/int_poly.cc
- Timestamp:
- Jan 7, 2008, 2:33:11 PM (16 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- aa7480c120ef293aaf5a185ec38a2440c23fc879
- Parents:
- 6840b2040b65b549b02b0e852339ab1a0a791484
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/int_poly.cc
r6840b2 r1e6de6 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: int_poly.cc,v 1. 19 2006-09-15 10:15:48Singular Exp $ */2 /* $Id: int_poly.cc,v 1.20 2008-01-07 13:33:10 Singular Exp $ */ 3 3 4 4 #include <config.h> … … 1140 1140 if ( aTermList == 0 ) 1141 1141 return 0; 1142 else if ( negate ) { 1142 else if ( negate ) 1143 { 1143 1144 termList sourceCursor = aTermList; 1144 1145 termList dummy = new term; 1145 1146 termList targetCursor = dummy; 1146 1147 1147 while ( sourceCursor ) { 1148 while ( sourceCursor ) 1149 { 1148 1150 targetCursor->next = new term( 0, -sourceCursor->coeff, sourceCursor->exp ); 1149 1151 targetCursor = targetCursor->next; … … 1156 1158 return targetCursor; 1157 1159 } 1158 else { 1160 else 1161 { 1159 1162 termList sourceCursor = aTermList; 1160 1163 termList dummy = new term; 1161 1164 termList targetCursor = dummy; 1162 1165 1163 while ( sourceCursor ) { 1166 while ( sourceCursor ) 1167 { 1164 1168 targetCursor->next = new term( 0, sourceCursor->coeff, sourceCursor->exp ); 1165 1169 targetCursor = targetCursor->next; … … 1179 1183 if ( aTermList == 0 ) 1180 1184 return 0; 1181 else { 1185 else 1186 { 1182 1187 termList sourceCursor = aTermList; 1183 1188 termList dummy = new term; 1184 1189 termList targetCursor = dummy; 1185 1190 1186 while ( sourceCursor ) { 1191 while ( sourceCursor ) 1192 { 1187 1193 targetCursor->next = new term( 0, sourceCursor->coeff.deepCopy(), sourceCursor->exp ); 1188 1194 targetCursor = targetCursor->next; … … 1202 1208 termList cursor = aTermList; 1203 1209 1204 while ( cursor ) { 1210 while ( cursor ) 1211 { 1205 1212 cursor = cursor->next; 1206 1213 delete aTermList; … … 1213 1220 { 1214 1221 termList cursor = terms; 1215 while ( cursor ) { 1222 while ( cursor ) 1223 { 1216 1224 cursor->coeff = -cursor->coeff; 1217 1225 cursor = cursor->next; … … 1226 1234 termList predCursor = 0; 1227 1235 1228 while ( theCursor && aCursor ) { 1229 if ( theCursor->exp == aCursor->exp ) { 1236 while ( theCursor && aCursor ) 1237 { 1238 if ( theCursor->exp == aCursor->exp ) 1239 { 1230 1240 if ( negate ) 1231 1241 theCursor->coeff -= aCursor->coeff; 1232 1242 else 1233 1243 theCursor->coeff += aCursor->coeff; 1234 if ( theCursor->coeff.isZero() ) { 1235 if ( predCursor ) { 1244 if ( theCursor->coeff.isZero() ) 1245 { 1246 if ( predCursor ) 1247 { 1236 1248 predCursor->next = theCursor->next; 1237 1249 delete theCursor; 1238 1250 theCursor = predCursor->next; 1239 1251 } 1240 else { 1252 else 1253 { 1241 1254 theList = theList->next; 1242 1255 delete theCursor; … … 1244 1257 } 1245 1258 } 1246 else { 1259 else 1260 { 1247 1261 predCursor = theCursor; 1248 1262 theCursor = theCursor->next; … … 1250 1264 aCursor = aCursor->next; 1251 1265 } 1252 else if ( theCursor->exp < aCursor->exp ) { 1266 else if ( theCursor->exp < aCursor->exp ) 1267 { 1253 1268 if ( negate ) 1254 if ( predCursor ) { 1269 if ( predCursor ) 1270 { 1255 1271 predCursor->next = new term( theCursor, -aCursor->coeff, aCursor->exp ); 1256 1272 predCursor = predCursor->next; 1257 1273 } 1258 else { 1274 else 1275 { 1259 1276 theList = new term( theCursor, -aCursor->coeff, aCursor->exp ); 1260 1277 predCursor = theList; 1261 1278 } 1262 1279 else 1263 if ( predCursor ) { 1280 if ( predCursor ) 1281 { 1264 1282 predCursor->next = new term( theCursor, aCursor->coeff, aCursor->exp ); 1265 1283 predCursor = predCursor->next; 1266 1284 } 1267 else { 1285 else 1286 { 1268 1287 theList = new term( theCursor, aCursor->coeff, aCursor->exp ); 1269 1288 predCursor = theList; … … 1271 1290 aCursor = aCursor->next; 1272 1291 } 1273 else { 1292 else 1293 { 1274 1294 predCursor = theCursor; 1275 1295 theCursor = theCursor->next; 1276 1296 } 1277 1297 } 1278 if ( aCursor ) { 1298 if ( aCursor ) 1299 { 1279 1300 if ( predCursor ) 1280 1301 predCursor->next = copyTermList( aCursor, lastTerm, negate ); … … 1291 1312 InternalPoly::mulTermList ( termList theCursor, const CanonicalForm& coeff, const int exp ) 1292 1313 { 1293 while ( theCursor ) { 1314 while ( theCursor ) 1315 { 1294 1316 theCursor->coeff *= coeff; 1295 1317 theCursor->exp += exp; … … 1305 1327 termList dummy; 1306 1328 1307 while ( theCursor ) { 1329 while ( theCursor ) 1330 { 1308 1331 theCursor->coeff /= coeff; 1309 if ( theCursor->coeff.isZero() ) { 1332 if ( theCursor->coeff.isZero() ) 1333 { 1310 1334 if ( theCursor == firstTerm ) 1311 1335 firstTerm = theCursor->next; … … 1316 1340 delete dummy; 1317 1341 } 1318 else { 1342 else 1343 { 1319 1344 lastTerm = theCursor; 1320 1345 theCursor = theCursor->next; … … 1331 1356 termList dummy; 1332 1357 1333 while ( theCursor ) { 1358 while ( theCursor ) 1359 { 1334 1360 theCursor->coeff.div( coeff ); 1335 if ( theCursor->coeff.isZero() ) { 1361 if ( theCursor->coeff.isZero() ) 1362 { 1336 1363 if ( theCursor == firstTerm ) 1337 1364 firstTerm = theCursor->next; … … 1342 1369 delete dummy; 1343 1370 } 1344 else { 1371 else 1372 { 1345 1373 lastTerm = theCursor; 1346 1374 theCursor = theCursor->next; … … 1357 1385 termList dummy; 1358 1386 1359 while ( theCursor ) { 1387 while ( theCursor ) 1388 { 1360 1389 theCursor->coeff.mod( coeff ); 1361 if ( theCursor->coeff.isZero() ) { 1390 if ( theCursor->coeff.isZero() ) 1391 { 1362 1392 if ( theCursor == firstTerm ) 1363 1393 firstTerm = theCursor->next; … … 1368 1398 delete dummy; 1369 1399 } 1370 else { 1400 else 1401 { 1371 1402 lastTerm = theCursor; 1372 1403 theCursor = theCursor->next; … … 1379 1410 InternalPoly::appendTermList ( termList& first, termList& last, const CanonicalForm& coeff, const int exp ) 1380 1411 { 1381 if ( last ) { 1412 if ( last ) 1413 { 1382 1414 last->next = new term( 0, coeff, exp ); 1383 1415 last = last->next; 1384 1416 } 1385 else { 1417 else 1418 { 1386 1419 first = new term( 0, coeff, exp ); 1387 1420 last = first; … … 1402 1435 coeff = c; 1403 1436 1404 while ( theCursor && aCursor ) { 1405 if ( theCursor->exp == aCursor->exp + exp ) { 1437 while ( theCursor && aCursor ) 1438 { 1439 if ( theCursor->exp == aCursor->exp + exp ) 1440 { 1406 1441 theCursor->coeff += aCursor->coeff * coeff; 1407 if ( theCursor->coeff.isZero() ) { 1408 if ( predCursor ) { 1442 if ( theCursor->coeff.isZero() ) 1443 { 1444 if ( predCursor ) 1445 { 1409 1446 predCursor->next = theCursor->next; 1410 1447 delete theCursor; 1411 1448 theCursor = predCursor->next; 1412 1449 } 1413 else { 1450 else 1451 { 1414 1452 theList = theList->next; 1415 1453 delete theCursor; … … 1417 1455 } 1418 1456 } 1419 else { 1457 else 1458 { 1420 1459 predCursor = theCursor; 1421 1460 theCursor = theCursor->next; … … 1423 1462 aCursor = aCursor->next; 1424 1463 } 1425 else if ( theCursor->exp < aCursor->exp + exp ) { 1426 if ( predCursor ) { 1464 else if ( theCursor->exp < aCursor->exp + exp ) 1465 { 1466 if ( predCursor ) 1467 { 1427 1468 predCursor->next = new term( theCursor, aCursor->coeff * coeff, aCursor->exp + exp ); 1428 1469 predCursor = predCursor->next; 1429 1470 } 1430 else { 1471 else 1472 { 1431 1473 theList = new term( theCursor, aCursor->coeff * coeff, aCursor->exp + exp ); 1432 1474 predCursor = theList; … … 1434 1476 aCursor = aCursor->next; 1435 1477 } 1436 else { 1478 else 1479 { 1437 1480 predCursor = theCursor; 1438 1481 theCursor = theCursor->next; 1439 1482 } 1440 1483 } 1441 if ( aCursor ) { 1442 if ( predCursor ) { 1484 if ( aCursor ) 1485 { 1486 if ( predCursor ) 1487 { 1443 1488 predCursor->next = copyTermList( aCursor, lastTerm ); 1444 1489 predCursor = predCursor->next; 1445 1490 } 1446 else { 1491 else 1492 { 1447 1493 theList = copyTermList( aCursor, lastTerm ); 1448 1494 predCursor = theList; 1449 1495 } 1450 while ( predCursor ) { 1496 while ( predCursor ) 1497 { 1451 1498 predCursor->exp += exp; 1452 1499 predCursor->coeff *= coeff; … … 1467 1514 int exp = redterms->exp; 1468 1515 termList dummy; 1469 while ( first && ( first->exp >= exp ) ) { 1516 while ( first && ( first->exp >= exp ) ) 1517 { 1470 1518 newcoeff = first->coeff / coeff; 1471 1519 newexp = first->exp - exp;
Note: See TracChangeset
for help on using the changeset viewer.