Changeset 90d772 in git for Singular/LIB/general.lib
- Timestamp:
- May 2, 2005, 3:28:15 PM (18 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- c4e65ede88881de04fe2115143cd0fb9a0e67317
- Parents:
- 17695492ed27b2e174eb4ae917d029b1027d83a9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/general.lib
r176954 r90d772 3 3 //eric, added absValue 11.04.2002 4 4 /////////////////////////////////////////////////////////////////////////////// 5 version="$Id: general.lib,v 1.4 4 2004-08-13 14:09:21Singular Exp $";5 version="$Id: general.lib,v 1.45 2005-05-02 13:28:15 Singular Exp $"; 6 6 category="General purpose"; 7 7 info=" … … 27 27 which(command); search for command and return absolute path, if found 28 28 primecoeffs(J[,q]); primefactors <= min(p,32003) of coeffs of J 29 primefactors(n [,p]); primefactors <= min(p,32003) of n 29 primefactors(n[,p]); primefactors <= min(p,32003) of n 30 timeStd(i,d) std(i) if the standard basis computation finished 31 after d-1 seconds and i otherwhise 32 timeFactorize(p,d) factorize(p) if the factorization finished after d-1 33 seconds otherwhise f is considered to be irreducible 34 factorH(p) changes variables to become the last variable the 35 principal one in the multivariate factorization and 36 factorizes then the polynomial 37 30 38 (parameters in square brackets [] are optional) 31 39 "; … … 1506 1514 } 1507 1515 /////////////////////////////////////////////////////////////////////////////// 1516 proc timeFactorize(poly i,list #) 1517 "USAGE: timeFactorize(p,d) poly p , integer d 1518 RETURN: factorize(p) if the factorization finished after d-1 1519 seconds otherwhise f is considered to be irreducible 1520 EXAMPLE: example timeFactorize; shows an example 1521 " 1522 { 1523 def P=basering; 1524 if (size(#) > 0) 1525 { 1526 if (system("with", "MP")) 1527 { 1528 if ((typeof(#[1]) == "int")&&(#[1])) 1529 { 1530 int wait = #[1]; 1531 int j = 10; 1532 1533 string bs = nameof(basering); 1534 link l_fork = "MPtcp:fork"; 1535 open(l_fork); 1536 write(l_fork, quote(system("pid"))); 1537 int pid = read(l_fork); 1538 write(l_fork, quote(timeFactorize(eval(i)))); 1539 1540 // sleep in small intervalls for appr. one second 1541 if (wait > 0) 1542 { 1543 while(j < 1000000) 1544 { 1545 if (status(l_fork, "read", "ready", j)) {break;} 1546 j = j + j; 1547 } 1548 } 1549 1550 // sleep in intervalls of one second from now on 1551 j = 1; 1552 while (j < wait) 1553 { 1554 if (status(l_fork, "read", "ready", 1000000)) {break;} 1555 j = j + 1; 1556 } 1557 1558 if (status(l_fork, "read", "ready")) 1559 { 1560 def result = read(l_fork); 1561 if (bs != nameof(basering)) 1562 { 1563 def PP = basering; 1564 setring P; 1565 def result = imap(PP, result); 1566 kill PP; 1567 } 1568 kill (l_fork); 1569 } 1570 else 1571 { 1572 list result; 1573 intvec v=1,1; 1574 result[1]=list(1,i); 1575 result[2]=v; 1576 j = system("sh", "kill " + string(pid)); 1577 } 1578 return (result); 1579 } 1580 } 1581 } 1582 return(factorH(i)); 1583 } 1584 example 1585 { "EXAMPLE:"; echo = 2; 1586 ring r=0,(x,y),dp; 1587 poly p=((x2+y3)^2+xy6)*((x3+y2)^2+x10y); 1588 p=p^2; 1589 //timeFactorize(p,2); 1590 //timeFactorize(p,20); 1591 } 1592 1593 proc timeStd(ideal i,list #) 1594 "USAGE: timeStd(i,d), i ideal, d integer 1595 RETURN: std(i) if the standard basis computation finished after 1596 d-1 seconds and i otherwhise 1597 EXAMPLE: example timeStd; shows an example 1598 " 1599 { 1600 def P=basering; 1601 if (size(#) > 0) 1602 { 1603 if (system("with", "MP")) 1604 { 1605 if ((typeof(#[1]) == "int")&&(#[1])) 1606 { 1607 int wait = #[1]; 1608 int j = 10; 1609 1610 string bs = nameof(basering); 1611 link l_fork = "MPtcp:fork"; 1612 open(l_fork); 1613 write(l_fork, quote(system("pid"))); 1614 int pid = read(l_fork); 1615 write(l_fork, quote(timeStd(eval(i)))); 1616 1617 // sleep in small intervalls for appr. one second 1618 if (wait > 0) 1619 { 1620 while(j < 1000000) 1621 { 1622 if (status(l_fork, "read", "ready", j)) {break;} 1623 j = j + j; 1624 } 1625 } 1626 j = 1; 1627 while (j < wait) 1628 { 1629 if (status(l_fork, "read", "ready", 1000000)) {break;} 1630 j = j + 1; 1631 } 1632 if (status(l_fork, "read", "ready")) 1633 { 1634 def result = read(l_fork); 1635 if (bs != nameof(basering)) 1636 { 1637 def PP = basering; 1638 setring P; 1639 def result = imap(PP, result); 1640 kill PP; 1641 } 1642 kill (l_fork); 1643 } 1644 else 1645 { 1646 ideal result=i; 1647 j = system("sh", "kill " + string(pid)); 1648 } 1649 return (result); 1650 } 1651 } 1652 } 1653 return(std(i)); 1654 } 1655 example 1656 { "EXAMPLE:"; echo = 2; 1657 ring r=32003,(a,b,c,d,e),dp; 1658 int n=6; 1659 ideal i= 1660 a^n-b^n, 1661 b^n-c^n, 1662 c^n-d^n, 1663 d^n-e^n, 1664 a^(n-1)*b+b^(n-1)*c+c^(n-1)*d+d^(n-1)*e+e^(n-1)*a; 1665 timeStd(i,2); 1666 timeStd(i,20); 1667 } 1668 1669 proc factorH(poly p) 1670 "USAGE: factorH(p) p poly 1671 RETURN: factorize(p) 1672 NOTE: changes variables to become the last variable the principal 1673 one in the multivariate factorization and factorizes then 1674 the polynomial 1675 EXAMPLE: example factorH; shows an example 1676 " 1677 { 1678 def R=basering; 1679 int i,j; 1680 int n=1; 1681 int d=nrows(coeffs(p,var(1))); 1682 for(i=1;i<=nvars(R);i++) 1683 { 1684 j=nrows(coeffs(p,var(i))); 1685 if(d>j) 1686 { 1687 n=i; 1688 d=j; 1689 } 1690 } 1691 ideal ma=maxideal(1); //die letzte Variable ist die Hauptvariable 1692 ma[nvars(R)]=var(n); 1693 ma[n]=var(nvars(R)); 1694 map phi=R,ma; 1695 list fac=factorize(phi(p)); 1696 list re=phi(fac); 1697 return(re); 1698 } 1699 example 1700 { "EXAMPLE:"; echo = 2; 1701 system("random",992851144); 1702 ring r=32003,(x,y,z,w,t),lp; 1703 poly p=y2w9+yz7t-yz5w4-z2w4t4-w8t3; 1704 factorize(p); //fast 1705 system("random",992851262); 1706 //factorize(p); //slow 1707 system("random",992851262); 1708 factorH(p); 1709 }
Note: See TracChangeset
for help on using the changeset viewer.