Changeset 298d0a in git
- Timestamp:
- Aug 13, 2004, 4:09:21 PM (19 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- c3b42bd22345d6bc9ce1a7e84df4e0c62e0173bf
- Parents:
- cbcc6f60e9762c35407e5f53eca609495277d48c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/general.lib
rcbcc6f6 r298d0a 3 3 //eric, added absValue 11.04.2002 4 4 /////////////////////////////////////////////////////////////////////////////// 5 version="$Id: general.lib,v 1.4 3 2004-08-13 12:52:37Singular Exp $";5 version="$Id: general.lib,v 1.44 2004-08-13 14:09:21 Singular Exp $"; 6 6 category="General purpose"; 7 7 info=" … … 26 26 watchdog(i,cmd); only wait for result of command cmd for i seconds 27 27 which(command); search for command and return absolute path, if found 28 primecoeffs(J[,q]); primefactors <= min(p,32003) of coeffs of J 28 primecoeffs(J[,q]); primefactors <= min(p,32003) of coeffs of J 29 29 primefactors(n [,p]); primefactors <= min(p,32003) of n 30 30 (parameters in square brackets [] are optional) … … 141 141 142 142 proc absValue(def c) 143 "USAGE: absValue(c); c int, number or poly 143 "USAGE: absValue(c); c int, number or poly 144 144 RETURN: absValue(c); the absolute value of c 145 145 NOTE: absValue(c)=c if c>=0; absValue=-c if c<=0. 146 146 @* So the function can be applied to any type, for which comparison 147 @* operators are defined. 147 @* operators are defined. 148 148 SEE ALSO: boolean expressions 149 149 EXAMPLE: example absValue; shows an example … … 492 492 for ( @joni=size(@marie); @joni>0; @joni-- ) 493 493 { 494 if( (@marie[@joni]!="General")494 if( (@marie[@joni]!="General") 495 495 and (@marie[@joni]!="Top") 496 496 and (@marie[@joni]!="killall") 497 and (@marie[@joni]=="LIB" or 498 typeof(`@marie[@joni]`)=="package" or 499 typeof(`@marie[@joni]`)=="proc")) 500 { kill `@marie[@joni]`; 501 if (defined(`@marie[@joni]`)) {kill `@marie[@joni]`;}} 497 and (@marie[@joni]!="LIB") and 498 ((typeof(`@marie[@joni]`)=="package") or 499 (typeof(`@marie[@joni]`)=="proc"))) 500 { 501 if (defined(`@marie[@joni]`)) {kill `@marie[@joni]`;} 502 } 503 if (!defined(@joni)) break; 502 504 } 503 if ( system("with","Namespaces"))505 if ((system("with","Namespaces")) && defined(General)) 504 506 { 507 505 508 @marie=names(General); 506 509 for ( @joni=size(@marie); @joni>0; @joni-- ) … … 546 549 } 547 550 } 551 if (!defined(@joni)) break; 548 552 } 549 553 } … … 1244 1248 "USAGE: primefactors(n [,p]); n = int or number, p = integer 1245 1249 COMPUTE: primefactors <= min(p,32003) of n (default p = 32003) 1246 RETURN: a list, say l, 1247 l[1] : primefactors <= min(p,32003) of n 1250 RETURN: a list, say l, 1251 l[1] : primefactors <= min(p,32003) of n 1248 1252 l[2] : l[2][i] = multiplicity of l[1][i] 1249 1253 l[3] : remaining factor ( n=product{ (l[1][i]^l[2][i])*l[3]} ) … … 1260 1264 intvec w1,w2,v; 1261 1265 list l; 1262 if (size(#) == 0) 1263 { 1264 p=32003; 1265 } 1266 else 1266 if (size(#) == 0) 1267 { 1268 p=32003; 1269 } 1270 else 1267 1271 { 1268 1272 if( typeof(#[1]) != "int") … … 1274 1278 if( n<0) { n=-n;}; 1275 1279 1276 // ----------------- case: 1st parameter is a number -------------------- 1280 // ----------------- case: 1st parameter is a number -------------------- 1277 1281 if (typeof(n) =="number") 1278 1282 { … … 1284 1288 number m; 1285 1289 for( ii=1; ii<=size(v); ii++) 1286 { 1290 { 1287 1291 jj=0; 1288 1292 while(1) 1289 { 1293 { 1290 1294 q = v[ii]; 1291 jj = jj+1; 1295 jj = jj+1; 1292 1296 m = n/q; //divide n as often as possible 1293 1297 if (denominator(m)!=1) { break; } 1294 1298 n=m; 1295 1299 } 1296 if( jj>1 ) 1300 if( jj>1 ) 1297 1301 { 1298 1302 w1 = w1,v[ii]; //primes … … 1309 1313 w1 = w1[2..size(w1)]; 1310 1314 w2 = w2[2..size(w2)]; 1311 } 1315 } 1312 1316 else //no primefactor was found 1313 1317 { 1314 1318 w1 = 1; w2 = 1; 1315 } 1319 } 1316 1320 l = w1,w2,n; 1317 1321 return(l); … … 1325 1329 } 1326 1330 } 1327 1331 1328 1332 // --------------------------- trivial cases -------------------- 1329 if( n==0 ) 1330 { 1333 if( n==0 ) 1334 { 1331 1335 w1=1; w2=1; w3=0; l=w1,w2,w3; 1332 1336 return(l); 1333 1337 } 1334 1335 if( n==1 ) 1336 { 1338 1339 if( n==1 ) 1340 { 1337 1341 w3=1; 1338 1342 if( size(w1) >1 ) //at least 1 primefactor was found … … 1340 1344 w1 = w1[2..size(w1)]; 1341 1345 w2 = w2[2..size(w2)]; 1342 } 1346 } 1343 1347 else //no primefactor was found 1344 1348 { 1345 1349 w1 = 1; w2 = 1; 1346 } 1350 } 1347 1351 l=w1,w2,w3; 1348 1352 return(l); … … 1351 1355 { //case n is a prime 1352 1356 if (p > n) 1353 { 1357 { 1354 1358 w1=w1,n; w2=w2,1; w3=1; 1355 1359 w1 = w1[2..size(w1)]; … … 1365 1369 w1 = w1[2..size(w1)]; 1366 1370 w2 = w2[2..size(w2)]; 1367 } 1371 } 1368 1372 else //no primefactor was found 1369 1373 { 1370 1374 w1 = 1; w2 = 1; 1371 } 1375 } 1372 1376 l=w1,w2,w3; 1373 1377 return(l); 1374 } 1375 } 1376 else 1378 } 1379 } 1380 else 1377 1381 { 1378 1382 if ( p >= n) … … 1384 1388 v = primes(q,p); 1385 1389 } 1386 //------------- search for primfactors <= last entry of v ------------ 1390 //------------- search for primfactors <= last entry of v ------------ 1387 1391 for(ii=1; ii<=size(v); ii++) 1388 1392 { 1389 1393 z=0; 1390 1394 while( (n mod v[ii]) == 0 ) 1391 { 1395 { 1392 1396 z=z+1; 1393 1397 n = n div v[ii]; 1394 1398 } 1395 1399 if (z!=0) 1396 { 1400 { 1397 1401 w1 = w1,v[ii]; //primes 1398 1402 w2 = w2,z; //multiplicities … … 1405 1409 w1 = w1[2..size(w1)]; 1406 1410 w2 = w2[2..size(w2)]; 1407 } 1411 } 1408 1412 else //no primefactor was found 1409 1413 { 1410 1414 w1 = 1; w2 = 1; 1411 } 1415 } 1412 1416 w3 = n; 1413 1417 l = w1,w2,w3; … … 1419 1423 ring r = 0,x,dp; 1420 1424 primefactors(123456789100); 1421 } 1425 } 1422 1426 1423 1427 /////////////////////////////////////////////////////////////////////////////// … … 1436 1440 { 1437 1441 int q,ii,n,mark;; 1438 if (size(#) == 0) 1439 { 1440 q=32003; 1441 } 1442 else 1442 if (size(#) == 0) 1443 { 1444 q=32003; 1445 } 1446 else 1443 1447 { 1444 1448 if( typeof(#[1]) != "int") … … 1456 1460 def I = ideal(matrix(J)); 1457 1461 poly p = product(maxideal(1)); 1458 matrix Coef=coef(I[1],p); 1462 matrix Coef=coef(I[1],p); 1459 1463 ideal id, jd, rest; 1460 1464 intvec v,re; … … 1466 1470 id = Coef[2,1..ncols(Coef)]; 1467 1471 id = simplify(id,6); 1468 for (ii=1; ii<=size(id); ii++) 1469 { 1470 l = primefactors(number(id[ii]),q); 1472 for (ii=1; ii<=size(id); ii++) 1473 { 1474 l = primefactors(number(id[ii]),q); 1471 1475 jd = jd,l[1]; 1472 1476 rest = rest,l[3]; 1473 } 1477 } 1474 1478 jd = simplify(jd,6); 1475 for (ii=1; ii<=size(jd); ii++) 1476 { 1479 for (ii=1; ii<=size(jd); ii++) 1480 { 1477 1481 v[ii]=int(jd[ii]); 1478 1482 } … … 1490 1494 else 1491 1495 { 1492 result = v,rest; 1496 result = v,rest; 1493 1497 } 1494 1498 return(result); … … 1500 1504 ideal I = -13b6c3t+4b5c4t,-10b4c2t-5b4ct2; 1501 1505 primecoeffs(I); 1502 } 1503 /////////////////////////////////////////////////////////////////////////////// 1506 } 1507 ///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.