/usr/share/singular/LIB/poly.lib is in singular-data 4.0.3+ds-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 | ////////////////////////////////////////////////////////////////////////////
version="version poly.lib 4.0.0.0 Jun_2013 "; // $Id: 80de7b0741561fba913feacc78e04be45e7e50fb $
category="General purpose";
info="
LIBRARY: poly.lib Procedures for Manipulating Polys, Ideals, Modules
AUTHORS: O. Bachmann, G.-M. Greuel, A. Fruehbis
PROCEDURES:
cyclic(int); ideal of cyclic n-roots
elemSymmId(int); ideal of elementary symmetric polynomials
katsura([i]); katsura [i] ideal
freerank(poly/...) rank of coker(input) if coker is free else -1
is_zero(poly/...); int, =1 resp. =0 if coker(input) is 0 resp. not
lcm(ideal); lcm of given generators of ideal
maxcoef(poly/...); maximal length of coefficient occurring in poly/...
maxdeg(poly/...); int/intmat = degree/s of terms of maximal order
maxdeg1(poly/...); int = [weighted] maximal degree of input
mindeg(poly/...); int/intmat = degree/s of terms of minimal order
mindeg1(poly/...); int = [weighted] minimal degree of input
normalize(poly/...); normalize poly/... such that leading coefficient is 1
rad_con(p,I); check radical containment of polynomial p in ideal I
content(f); content of polynomial/vector f
mod2id(M,iv); conversion of a module M to an ideal
id2mod(i,iv); conversion inverse to mod2id
substitute(I,...) substitute in I variables by polynomials
subrInterred(i1,i2,iv);interred w.r.t. a subset of variables
newtonDiag(f); Newton diagram of a polynomial
hilbPoly(I); Hilbert polynomial of basering/I
(parameters in square brackets [] are optional)
";
LIB "general.lib";
LIB "ring.lib";
///////////////////////////////////////////////////////////////////////////////
static proc bino(int a, int b)
{
//computes binomial var(1)+a over b
int i;
if(b==0){return(1);}
poly p=(var(1)+a)/b;
for(i=1;i<=b-1;i++)
{
p=p*(var(1)+a-i)/i;
}
return(p);
}
proc hilbPoly(ideal I)
"USAGE: hilbPoly(I); I a homogeneous ideal
RETURN: the Hilbert polynomial of basering/I as an intvec v=v_0,...,v_r
such that the Hilbert polynomial is (v_0+v_1*t+...v_r*t^r)/r!
EXAMPLE: example hilbPoly; shows an example
"
{
def R=basering;
if(!attrib(I,"isSB")){I=std(I);}
intvec v=hilb(I,2);
int s=dim(I);
intvec hp;
if(s==0){return(hp);}
int d=size(v)-2;
ring S=0,t,dp;
poly p=v[1+d]*bino(s-1-d,s-1);
int i;
for(i=1;i<=d;i++)
{
p=p+v[d-i+1]*bino(s-1-d+i,s-1);
}
int n=1;
for(i=2;i<=s-1;i++){n=n*i;}
p=n*p;
hp[s]=int(leadcoef(p));
for(i=2;i<=size(p);i++)
{
hp[leadexp(p[i])+1]=int(leadcoef(p[i]));
}
setring R;
return(hp);
}
example
{ "EXAMPLE:"; echo = 2;
ring r = 0,(b,c,t,h),dp;
ideal I=
bct-t2h+2th2+h3,
bt3-ct3-t4+b2th+c2th-2bt2h+2ct2h+2t3h-bch2-2bth2+2cth2+2th3,
b2c2+bt2h-ct2h-t3h+b2h2+2bch2+c2h2-2bth2+2cth2+t2h2-2bh3+2ch3+2th3+3h4,
c2t3+ct4-c3th-2c2t2h-2ct3h-t4h+bc2h2-2c2th2-bt2h2+4t3h2+2bth3-2cth3-t2h3
+bh4-6th4-2h5;
hilbPoly(I);
}
///////////////////////////////////////////////////////////////////////////////
proc substitute (def I,list #)
"USAGE: - case 1: typeof(#[1])==poly:
substitute (I,v,f[,v1,f1,v2,f2,...]); I object of basering which
can be mapped, v,v1,v2,.. ring variables, f,f1,f2,... poly
@* - case 2: typeof(#[1])==ideal:
substitute (I,v,f); I object of basering which can be mapped,
v ideal of ring variables, f ideal
RETURN: object of same type as I,
@* - case 1: ring variable v,v1,v2,... substituted by polynomials
f,f1,f2,..., in this order
@* - case 2: ring variables in v substituted by polynomials in f:
v[i] is substituted by f[i], i=1,...,i=min(size(v),ncols(f))
NOTE: this procedure extends the built-in command subst via maps
EXAMPLE: example substitute; shows an example
"
{
def bas = basering;
ideal m = maxideal(1);
int i,ii;
if(typeof(#[1])=="poly")
{
poly v = #[1];
poly f = #[2];
map phi = bas,m;
def J = I;
for (ii=1; ii<=size(#) - 1; ii=ii+2)
{
m = maxideal(1);
i=rvar(#[ii]);
m[i] = #[ii+1];
phi = bas,m;
J = phi(J);
}
return(J);
}
if(typeof(#[1])=="ideal")
{
ideal v = #[1];
ideal f = #[2];
int mi = ncols(v);
if(ncols(f)<mi)
{
mi = ncols(f);
}
def J = I;
for (ii=1; ii<=mi; ii++)
{
m[rvar(v[ii])]=f[ii];
}
map phi = bas,m;
J = phi(I);
return(J);
}
}
example
{ "EXAMPLE:"; echo = 2;
ring r = 0,(b,c,t),dp;
ideal I = -bc+4b2c2t,bc2t-5b2c;
substitute(I,c,b+c,t,0,b,b-1);
ideal v = c,t,b;
ideal f = b+c,0,b-1;
substitute(I,v,f);
}
///////////////////////////////////////////////////////////////////////////////
proc cyclic (int n)
"USAGE: cyclic(n); n integer
RETURN: ideal of cyclic n-roots from 1-st n variables of basering
EXAMPLE: example cyclic; shows examples
"
{
//----------------------------- procedure body --------------------------------
ideal m = maxideal(1);
m = m[1..n],m[1..n];
int i,j;
ideal s; poly t;
for ( j=0; j<=n-2; j++ )
{
t=0;
for( i=1;i<=n;i++ ) { t=t+product(m,i..i+j); }
s=s+t;
}
s=s,product(m,1..n)-1;
return (s);
}
//-------------------------------- examples -----------------------------------
example
{ "EXAMPLE:"; echo = 2;
ring r=0,(u,v,w,x,y,z),lp;
cyclic(nvars(basering));
homog(cyclic(5),z);
}
///////////////////////////////////////////////////////////////////////////////
proc elemSymmPoly(int d, int lindex, int hindex)
"USAGE: elemSymmPoly(d,lindex,hindex); d,lindex,hindex integers
RETURN: elementary symmetric polynomial of degree d for variables
@* var(lindex),...,var(hindex) of basering
EXAMPLE: example elemSymmPoly; shows an example
"
{
if(hindex - lindex + 1 < d)
{
int i = hindex - lindex + 1;
"========================================================";
"There is no elementary symmetric polynomial of degree "+string(d);
"for just "+string(i)+" variables.";
"========================================================";
return(poly(0));
}
if(d == 0)
{
return(poly(1));
}
else
{
int i;
poly p;
for (i = lindex; i <= hindex - d + 1; i++)
{
p = p + var(i) * elemSymmPoly(d - 1, i + 1, hindex);
}
return(p);
}
}
example
{ "EXAMPLE:"; echo = 2;
ring R = 0, (u,v,w,x,y,z), lp;
elemSymmPoly(3,2,5);
elemSymmPoly(6,1,6);
}
//////////////////////////////////////////////////////////////////////////
proc elemSymmId(int n)
"USAGE: elemSymmId(n); n integer
RETURN: ideal of elementary symmetric polynomials for 1-st n
@* variables of basering
EXAMPLE: example elemSymmId; shows an example
{
int i;
ideal symm;
for(i = 1; i <= n; i++)
{
symm = symm + elemSymmPoly(i, 1, n);
}
return(symm);
}
example
{ "EXAMPLE:"; echo = 2;
ring R = 0, (v,w,x,y,z), lp;
elemSymmId(3);
elemSymmId(nvars(basering));
}
//////////////////////////////////////////////////////////////////////////
proc katsura
"USAGE: katsura([n]); n integer
RETURN: katsura(n) : n-th katsura ideal of
(1) newly created and set ring (32003, x(0..n), dp), if
nvars(basering) < n
(2) basering, if nvars(basering) >= n
katsura() : katsura ideal of basering
EXAMPLE: example katsura; shows examples
"
{
int n;
if ( size(#) == 1 && typeof(#[1]) == "int")
{
n = #[1] - 1;
while (1)
{
if (defined(basering))
{
if (nvars(basering) >= #[1]) {break;}
}
ring katsura_ring = 32003, x(0..#[1]), dp;
keepring katsura_ring;
break;
}
}
else
{
n = nvars(basering) -1;
}
ideal s;
int i, j;
poly p;
p = -1;
for (i = -n; i <= n; i++)
{
p = p + kat_var(i, n);
}
s[1] = p;
for (i = 0; i < n; i++)
{
p = -1 * kat_var(i,n);
for (j = -n; j <= n; j++)
{
p = p + kat_var(j,n) * kat_var(i-j, n);
}
s = s,p;
}
return (s);
}
//-------------------------------- examples -----------------------------------
example
{
"EXAMPLE:"; echo = 2;
ring r; basering;
katsura();
katsura(4); basering;
}
proc kat_var(int i, int n)
{
poly p;
if (i < 0) { i = -i;}
if (i <= n) { p = var(i+1); }
return (p);
}
///////////////////////////////////////////////////////////////////////////////
proc freerank
"USAGE: freerank(M[,any]); M=poly/ideal/vector/module/matrix
COMPUTE: rank of module presented by M in case it is free.
By definition this is vdim(coker(M)/m*coker(M)) if coker(M)
is free, where m is the maximal ideal of the variables of the
basering and M is considered to be a matrix.
(the 0-module is free of rank 0)
RETURN: rank of coker(M) if coker(M) is free and -1 else;
in case of a second argument return a list:
L[1] = rank of coker(M) or -1
L[2] = minbase(M)
NOTE: freerank(syz(M)); computes the rank of M if M is free (and -1 else)
EXAMPLE: example freerank; shows examples
"
{
int rk;
def M = simplify(#[1],10);
resolution mre = res(M,2);
intmat B = betti(mre);
if ( ncols(B)>1 ) { rk = -1; }
else { rk = sum(B[1..nrows(B),1]); }
if (size(#) == 2) { list L=rk,mre[1]; return(L);}
return(rk);
}
example
{"EXAMPLE"; echo=2;
ring r;
ideal i=x;
module M=[x,0,1],[-x,0,-1];
freerank(M); // should be 2, coker(M) is not free
freerank(syz (M),"");
// [1] should be 1, coker(syz(M))=M is free of rank 1
// [2] should be gen(2)+gen(1) (minimal relation of M)
freerank(i);
freerank(syz(i)); // should be 1, coker(syz(i))=i is free of rank 1
}
///////////////////////////////////////////////////////////////////////////////
proc is_zero
"USAGE: is_zero(M[,any]); M=poly/ideal/vector/module/matrix
RETURN: integer, 1 if coker(M)=0 resp. 0 if coker(M)!=0, where M is
considered as matrix.
If a second argument is given, return a list:
L[1] = 1 if coker(M)=0 resp. 0 if coker(M)!=0
L[2] = dim(M)
EXAMPLE: example is_zero; shows examples
"
{
int d=dim(std(#[1]));
int a = ( d==-1 );
if( size(#) >1 ) { return(list(a,d)); }
return(a);
}
example
{ "EXAMPLE:"; echo=2;
ring r;
module m = [x],[y],[1,z];
is_zero(m,1);
qring q = std(ideal(x2+y3+z2));
ideal j = x2+y3+z2-37;
is_zero(j);
}
///////////////////////////////////////////////////////////////////////////////
proc maxcoef (def f)
"USAGE: maxcoef(f); f poly/ideal/vector/module/matrix
RETURN: maximal length of coefficient of f of type int (by measuring the
length of the string of each coefficient)
EXAMPLE: example maxcoef; shows examples
"
{
//----------------------------- procedure body --------------------------------
int max,s,ii,jj; string t;
ideal i = ideal(matrix(f));
i = simplify(i,6); // delete 0's and keep first of equal elements
poly m = var(1); matrix C;
for (ii=2;ii<=nvars(basering);ii++) { m = m*var(ii); }
for (ii=1; ii<=size(i); ii++)
{
C = coef(i[ii],m);
for (jj=1; jj<=ncols(C); jj++)
{
t = string(C[2,jj]); s = size(t);
if ( t[1] == "-" ) { s = s - 1; }
if ( s > max ) { max = s; }
}
}
return(max);
}
//-------------------------------- examples -----------------------------------
example
{ "EXAMPLE:"; echo = 2;
ring r= 0,(x,y,z),ds;
poly g = 345x2-1234567890y+7/4z;
maxcoef(g);
ideal i = g,10/1234567890;
maxcoef(i);
// since i[2]=1/123456789
}
///////////////////////////////////////////////////////////////////////////////
proc maxdeg (def id)
"USAGE: maxdeg(id); id poly/ideal/vector/module/matrix
RETURN: int/intmat, each component equals maximal degree of monomials in the
corresponding component of id, independent of ring ordering
(maxdeg of each var is 1).
Of type int, if id is of type poly; of type intmat otherwise
SEE ALSO: maxdeg1
EXAMPLE: example maxdeg; shows examples
"
{
//-------- subprocedure to find maximal degree of given component ----------
proc findmaxdeg
{
poly c = #[1];
if (c==0) { return(-1); }
//--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
int d = (deg(c)>=0)*deg(c)-(deg(c)<0)*deg(c);
int i = d;
while ( c-jet(c,i) != 0 ) { i = 2*(i+1); }
int o = i-1;
int u = (d != i)*((i div 2)-1);
//----------------------- "quick search" for maxdeg ------------------------
while ( (c-jet(c,i)==0)*(c-jet(c,i-1)!=0) == 0)
{
i = (o+1+u) div 2;
if (c-jet(c,i)!=0) { u = i+1; }
else { o = i-1; }
}
return(i);
}
//------------------------------ main program ---------------------------------
matrix M = matrix(id);
int r,c = nrows(M), ncols(M); int i,j;
intmat m[r][c];
for (i=r; i>0; i--)
{
for (j=c; j>0; j--) { m[i,j] = findmaxdeg(M[i,j]); }
}
if (typeof(id)=="poly") { return(m[1,1]); }
return(m);
}
//-------------------------------- examples -----------------------------------
example
{ "EXAMPLE:"; echo = 2;
ring r = 0,(x,y,z),wp(1,2,3);
poly f = x+y2+z3;
deg(f); //deg; returns weighted degree (in case of 1 block)!
maxdeg(f);
matrix m[2][2]=f+x10,1,0,f^2;
maxdeg(m);
}
///////////////////////////////////////////////////////////////////////////////
proc maxdeg1 (def id,list #)
"USAGE: maxdeg1(id[,v]); id=poly/ideal/vector/module/matrix, v=intvec
RETURN: integer, maximal [weighted] degree of monomials of id independent of
ring ordering, maxdeg1 of i-th variable is v[i] (default: v=1..1).
NOTE: This proc returns one integer while maxdeg returns, in general,
a matrix of integers. For one polynomial and if no intvec v is given
maxdeg is faster
EXAMPLE: example maxdeg1; shows examples
"
{
//-------- subprocedure to find maximal degree of given component ----------
proc findmaxdeg
{
poly c = #[1];
if (c==0) { return(-1); }
intvec v = #[2];
//--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
int d = (deg(c)>=0)*deg(c)-(deg(c)<0)*deg(c);
int i = d;
if ( c == jet(c,-1,v)) //case: maxdeg is negative
{
i = -d;
while ( c == jet(c,i,v) ) { i = 2*(i-1); }
int o = (d != -i)*((i div 2)+2) - 1;
int u = i+1;
int e = -1;
}
else //case: maxdeg is nonnegative
{
while ( c != jet(c,i,v) ) { i = 2*(i+1); }
int o = i-1;
int u = (d != i)*((i div 2)-1);
int e = 1;
}
//----------------------- "quick search" for maxdeg ------------------------
while ( ( c==jet(c,i,v) )*( c!=jet(c,i-1,v) ) == 0 )
{
i = (o+e+u) div 2;
if ( c!=jet(c,i,v) ) { u = i+1; }
else { o = i-1; }
}
return(i);
}
//------------------------------ main program ---------------------------------
ideal M = simplify(ideal(matrix(id)),8); //delete scalar multiples from id
int c = ncols(M);
int i,n;
if( size(#)==0 )
{
int m = maxdeg(M[c]);
for (i=c-1; i>0; i--)
{
n = maxdeg(M[i]);
m = (m>=n)*m + (m<n)*n; //let m be the maximum of m and n
}
}
else
{
intvec v=#[1]; //weight vector for the variables
int m = findmaxdeg(M[c],v);
for (i=c-1; i>0; i--)
{
n = findmaxdeg(M[i],v);
if( n>m ) { m=n; }
}
}
return(m);
}
//-------------------------------- examples -----------------------------------
example
{ "EXAMPLE:"; echo = 2;
ring r = 0,(x,y,z),wp(1,2,3);
poly f = x+y2+z3;
deg(f); //deg returns weighted degree (in case of 1 block)!
maxdeg1(f);
intvec v = ringweights(r);
maxdeg1(f,v); //weighted maximal degree
matrix m[2][2]=f+x10,1,0,f^2;
maxdeg1(m,v); //absolute weighted maximal degree
}
///////////////////////////////////////////////////////////////////////////////
proc mindeg (def id)
"USAGE: mindeg(id); id poly/ideal/vector/module/matrix
RETURN: minimal degree/s of monomials of id, independent of ring ordering
(mindeg of each variable is 1) of type int if id of type poly, else
of type intmat.
SEE ALSO: mindeg1
EXAMPLE: example mindeg; shows examples
"
{
//--------- subprocedure to find minimal degree of given component ---------
proc findmindeg
{
poly c = #[1];
if (c==0) { return(-1); }
//--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
int d = (ord(c)>=0)*ord(c)-(ord(c)<0)*ord(c);
int i = d;
while ( jet(c,i) == 0 ) { i = 2*(i+1); }
int o = i-1;
int u = (d != i)*((i div 2)-1);
//----------------------- "quick search" for mindeg ------------------------
while ( (jet(c,u)==0)*(jet(c,o)!=0) )
{
i = (o+u) div 2;
if (jet(c,i)==0) { u = i+1; }
else { o = i-1; }
}
if (jet(c,u)!=0) { return(u); }
else { return(o+1); }
}
//------------------------------ main program ---------------------------------
matrix M = matrix(id);
int r,c = nrows(M), ncols(M); int i,j;
intmat m[r][c];
for (i=r; i>0; i--)
{
for (j=c; j>0; j--) { m[i,j] = findmindeg(M[i,j]); }
}
if (typeof(id)=="poly") { return(m[1,1]); }
return(m);
}
//-------------------------------- examples -----------------------------------
example
{ "EXAMPLE:"; echo = 2;
ring r = 0,(x,y,z),ls;
poly f = x5+y2+z3;
ord(f); // ord returns weighted order of leading term!
mindeg(f); // computes minimal degree
matrix m[2][2]=x10,1,0,f^2;
mindeg(m); // computes matrix of minimum degrees
}
///////////////////////////////////////////////////////////////////////////////
proc mindeg1 (def id, list #)
"USAGE: mindeg1(id[,v]); id=poly/ideal/vector/module/matrix, v=intvec
RETURN: integer, minimal [weighted] degree of monomials of id independent of
ring ordering, mindeg1 of i-th variable is v[i] (default v=1..1).
NOTE: This proc returns one integer while mindeg returns, in general,
a matrix of integers. For one polynomial and if no intvec v is given
mindeg is faster.
EXAMPLE: example mindeg1; shows examples
"
{
//--------- subprocedure to find minimal degree of given component ---------
proc findmindeg
{
poly c = #[1];
intvec v = #[2];
if (c==0) { return(-1); }
//--- guess upper 'o' and lower 'u' bound, in case of negative weights -----
int d = (ord(c)>=0)*ord(c)-(ord(c)<0)*ord(c);
int i = d;
if ( jet(c,-1,v) !=0 ) //case: mindeg is negative
{
i = -d;
while ( jet(c,i,v) != 0 ) { i = 2*(i-1); }
int o = (d != -i)*((i div 2)+2) - 1;
int u = i+1;
int e = -1; i=u;
}
else //case: inded is nonnegative
{
while ( jet(c,i,v) == 0 ) { i = 2*(i+1); }
int o = i-1;
int u = (d != i)*((i div 2)-1);
int e = 1; i=u;
}
//----------------------- "quick search" for mindeg ------------------------
while ( (jet(c,i-1,v)==0)*(jet(c,i,v)!=0) == 0 )
{
i = (o+e+u) div 2;
if (jet(c,i,v)==0) { u = i+1; }
else { o = i-1; }
}
return(i);
}
//------------------------------ main program ---------------------------------
ideal M = simplify(ideal(matrix(id)),8); //delete scalar multiples from id
int c = ncols(M);
int i,n;
if( size(#)==0 )
{
int m = mindeg(M[c]);
for (i=c-1; i>0; i--)
{
n = mindeg(M[i]);
m = (m<=n)*m + (m>n)*n; //let m be the maximum of m and n
}
}
else
{
intvec v=#[1]; //weight vector for the variables
int m = findmindeg(M[c],v);
for (i=c-1; i>0; i--)
{
n = findmindeg(M[i],v);
m = (m<=n)*m + (m>n)*n; //let m be the maximum of m and n
}
}
return(m);
}
//-------------------------------- examples -----------------------------------
example
{ "EXAMPLE:"; echo = 2;
ring r = 0,(x,y,z),ls;
poly f = x5+y2+z3;
ord(f); // ord returns weighted order of leading term!
intvec v = 1,-3,2;
mindeg1(f,v); // computes minimal weighted degree
matrix m[2][2]=x10,1,0,f^2;
mindeg1(m,1..3); // computes absolute minimum of weighted degrees
}
///////////////////////////////////////////////////////////////////////////////
proc normalize (def id)
"USAGE: normalize(id); id=poly/vector/ideal/module
RETURN: object of same type
each element is normalized with leading coefficient equal to 1
EXAMPLE: example normalize; shows an example
"
{
return(simplify(id,1));
}
//-------------------------------- examples -----------------------------------
example
{ "EXAMPLE:"; echo = 2;
ring r = 0,(x,y,z),ls;
poly f = 2x5+3y2+4z3;
normalize(f);
module m=[9xy,0,3z3],[4z,6y,2x];
normalize(m);
ring s = 0,(x,y,z),(c,ls);
module m=[9xy,0,3z3],[4z,6y,2x];
normalize(m);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Input: <ideal>=<f1,f2,...,fm> and <polynomial> g
// Question: Does g lie in the radical of <ideal>?
// Solution: Compute a standard basis G for <f1,f2,...,fm,gz-1> where z is a
// new variable. Then g is contained in the radical of <ideal> <=>
// 1 is generator in G.
///////////////////////////////////////////////////////////////////////////////
proc rad_con (poly g,ideal I)
"USAGE: rad_con(g,I); g polynomial, I ideal
RETURN: 1 (TRUE) (type int) if g is contained in the radical of I
@* 0 (FALSE) (type int) otherwise
EXAMPLE: example rad_con; shows an example
"
{ def br=basering;
int n=nvars(br);
int dB=degBound;
degBound=0;
string mp=string(minpoly);
if (attrib(br,"global")==1)
{
execute("ring R=("+charstr(br)+"),(@x(1..n),@z),dp;");
}
else
{
execute("ring R=("+charstr(br)+"),(@z,@x(1..n)),(dp(1),"+ordstr(br)+");");
}
if (mp!="0")
{
execute("minpoly=number("+mp+");");
}
ideal irrel=@x(1..n);
map f=br,irrel;
poly p=f(g);
ideal J=f(I),ideal(p*@z-1);
J=std(J);
degBound=dB;
if (J[1]==1)
{
setring br;
return(1);
}
else
{
setring br;
return(0);
}
}
example
{ "EXAMPLE:"; echo=2;
ring R=0,(x,y,z),dp;
ideal I=x2+y2,z2;
poly f=x4+y4;
rad_con(f,I);
ideal J=x2+y2,z2,x4+y4;
poly g=z;
rad_con(g,I);
}
///////////////////////////////////////////////////////////////////////////////
proc lcm (def id, list #)
"USAGE: lcm(p[,q]); p int/intvec q a list of integers or
p poly/ideal q a list of polynomials
RETURN: the least common multiple of p and q:
@* - of type int if p is an int/intvec
@* - of type poly if p is a poly/ideal
EXAMPLE: example lcm; shows an example
"
{
int k,j;
//------------------------------ integer case --------------------------------
if( typeof(id) == "int" or typeof(id) == "intvec" )
{
intvec i = id;
if (size(#)!=0)
{
for (j = 1; j<=size(#); j++)
{
if (typeof(#[j]) !="int" and typeof(#[j]) !="intvec")
{ ERROR("// ** list element must be an integer");}
else
{ i = i,#[j]; }
}
}
int p,q;
if( i == 0 )
{
return(0);
}
for(j=1;j<=size(i);j++)
{
if( i[j] != 0 )
{
p=i[j];
break;
}
}
for (k=j+1;k<=size(i);k++)
{
if( i[k] !=0)
{
q=gcd(p,i[k]);
p=p div q;
p=p*i[k];
}
}
if(p <0 )
{return(-p);}
return(p);
}
//----------------------------- polynomial case ------------------------------
if( typeof(id) == "poly" or typeof(id) == "ideal" )
{
ideal i = id;
if (size(#)!=0)
{
for (j = 1; j<=size(#); j++)
{
if (typeof(#[j]) !="poly" and typeof(#[j]) !="ideal"
and typeof(#[j]) !="int" and typeof(#[j]) !="intvec")
{ ERROR("// ** list element must be a polynomial");}
else
{ i = i,#[j]; }
}
}
poly p,q;
i=simplify(i,10);
if(size(i) == 0)
{
return(0);
}
for(j=1;j<=size(i);j++)
{
if(maxdeg(i[j])!= 0)
{
p=i[j];
break;
}
}
if(p==0)
{
return(1);
}
for (k=j+1;k<=size(i);k++)
{
if(maxdeg(i[k])!=0)
{
q=gcd(p,i[k]);
if(maxdeg(q)==0)
{
p=p*i[k];
}
else
{
p=p/q;
p=p*i[k];
}
}
}
return(p);
}
}
example
{ "EXAMPLE:"; echo = 2;
ring r = 0,(x,y,z),lp;
poly p = (x+y)*(y+z);
poly q = (z4+2)*(y+z);
lcm(p,q);
ideal i=p,q,y+z;
lcm(i,p);
lcm(2,3,6);
lcm(2..6);
}
///////////////////////////////////////////////////////////////////////////////
proc content(def f)
"USAGE: content(f); f polynomial/vector
RETURN: number, the content (greatest common factor of coefficients)
of the polynomial/vector f
SEE ALSO: cleardenom
EXAMPLE: example content; shows an example
"
{
if (f==0) { return(number(1)); }
if (attrib(basering,"ring_cf")
&& ((typeof(f)=="poly")||(typeof(f)=="vector")))
{
number c=leadcoef(f);
while((c!=1)&&(f!=0))
{
c=gcd(c,leadcoef(f));
f=f-lead(f);
}
return(c);
}
else
{
return(leadcoef(f)/leadcoef(cleardenom(f)));
}
}
example
{ "EXAMPLE:"; echo = 2;
ring r=0,(x,y,z),(c,lp);
content(3x2+18xy-27xyz);
vector v=[3x2+18xy-27xyz,15x2+12y4,3];
content(v);
}
///////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// The idea of the procedures mod2id, id2mod and subrInterred is, to
// perform standard basis computation or interreduction of a submodule
// of a free module with generators gen(1),...,gen(n) over a ring R
// in a ring R[t1,...,tn]/<ti*tj> with gen(i) maped to ti
////////////////////////////////////////////////////////////////////////
proc mod2id(matrix M,intvec vpos)
"USAGE: mod2id(M,vpos); M matrix, vpos intvec
ASSUME: vpos is an integer vector such that gen(i) corresponds
to var(vpos[i]).
The basering contains variables var(vpos[i]) which do not occur
in M.
RETURN: ideal I in which each gen(i) from the module is replaced by
var(vpos[i]) and all monomials var(vpos[i])*var(vpos[j]) have
been added to the generating set of I.
NOTE: This procedure should be used in the following situation:
one wants to pass to a ring with new variables, say e(1),..,e(s),
which correspond to the components gen(1),..,gen(s) of the
module M such that e(i)*e(j)=0 for all i,j.
The new ring should already exist and be the current ring
EXAMPLE: example mod2id; shows an example"
{
int p = printlevel-voice+3; // p=printlevel+1 (default: p=1)
//----------------------------------------------------------------------
// define the ideal generated by the var(vpos[i]) and set up the matrix
// for the multiplication
//----------------------------------------------------------------------
ideal vars=var(vpos[1]);
for(int i=2;i<=size(vpos);i++)
{
vars=vars,var(vpos[i]);
}
matrix varm[1][size(vpos)]=vars;
if (size(vpos) > nrows(M))
{
matrix Mt[size(vpos)][ncols(M)];
Mt[1..nrows(M),1..ncols(M)]=M;
kill M;
matrix M=Mt;
}
//----------------------------------------------------------------------
// define the desired ideal
//----------------------------------------------------------------------
ideal ret=vars^2,varm*M;
return(ret);
}
example
{ "EXAMPLE:"; echo=2;
ring r=0,(e(1),e(2),x,y,z),(dp(2),ds(3));
module mo=x*gen(1)+y*gen(2);
intvec iv=2,1;
mod2id(mo,iv);
}
////////////////////////////////////////////////////////////////////////
proc id2mod(ideal i,intvec vpos)
"USAGE: id2mod(I,vpos); I ideal, vpos intvec
RETURN: module corresponding to the ideal by replacing var(vpos[i]) by
gen(i) and omitting all generators var(vpos[i])*var(vpos[j])
NOTE: * This procedure only makes sense if the ideal contains
all var(vpos[i])*var(vpos[j]) as monomial generators and
all other generators of I are linear combinations of the
var(vpos[i]) over the ring in the other variables.
* This is the inverse procedure to mod2id and should be applied
only to ideals created by mod2id using the same intvec vpos
(possibly after a standard basis computation)
EXAMPLE: example id2mod; shows an example"
{
int p = printlevel-voice+3; // p=printlevel+1 (default: p=1)
//---------------------------------------------------------------------
// Initialization
//---------------------------------------------------------------------
int n=size(i);
int v=size(vpos);
matrix tempmat;
matrix mm[v][n];
//---------------------------------------------------------------------
// Conversion
//---------------------------------------------------------------------
for(int j=1;j<=v;j++)
{
tempmat=coeffs(i,var(vpos[j]));
mm[j,1..n]=tempmat[2,1..n];
}
for(j=1;j<=v;j++)
{
mm=subst(mm,var(vpos[j]),0);
}
module ret=simplify(mm,10);
return(ret);
}
example
{ "EXAMPLE:"; echo=2;
ring r=0,(e(1),e(2),x,y,z),(dp(2),ds(3));
ideal i=e(2)^2,e(1)*e(2),e(1)^2,e(1)*y+e(2)*x;
intvec iv=2,1;
id2mod(i,iv);
}
///////////////////////////////////////////////////////////////////////
proc subrInterred(ideal mon, ideal sm, intvec iv)
"USAGE: subrInterred(mon,sm,iv);
sm: ideal in a ring r with n + s variables,
e.g. x_1,..,x_n and t_1,..,t_s
mon: ideal with monomial generators (not divisible by
any of the t_i) such that sm is contained in the module
k[t_1,..,t_s]*mon[1]+..+k[t_1,..,t_s]*mon[size(mon)]
iv: intvec listing the variables which are supposed to be used
as x_i
RETURN: list l:
l[1]=the monomials from mon in the order used
l[2]=their coefficients after interreduction
l[3]=l[1]*l[2]
PURPOSE: Do interred only w.r.t. a subset of variables.
The procedure returns an interreduced system of generators of
sm considered as a k[t_1,..,t_s]-submodule of the free module
k[t_1,..,t_s]*mon[1]+..+k[t_1,..,t_s]*mon[size(mon)]).
EXAMPLE: example subrInterred; shows an example
"
{
int p = printlevel-voice+3; // p=printlevel+1 (default: p=1)
//-----------------------------------------------------------------------
// check that mon is really generated by monomials
// and sort its generators with respect to the monomial ordering
//-----------------------------------------------------------------------
int err;
for(int i=1;i<=ncols(mon);i++)
{
if ( size(mon[i]) > 1 )
{
err=1;
}
}
if (err==1)
{
ERROR("mon has to be generated by monomials");
}
intvec sv=sortvec(mon);
ideal mons;
for(i=1;i<=size(sv);i++)
{
mons[i]=mon[sv[i]];
}
ideal itemp=maxideal(1);
for(i=1;i<=size(iv);i++)
{
itemp=subst(itemp,var(iv[i]),0);
}
itemp=simplify(itemp,10);
def r=basering;
string tempstr="ring rtemp=" + charstr(basering) + ",(" + string(itemp)
+ "),(C,dp);";
//-----------------------------------------------------------------------
// express m in terms of the generators of mon and check whether m
// can be considered as a submodule of k[t_1,..,t_n]*mon
//-----------------------------------------------------------------------
module motemp;
motemp[ncols(sm)]=0;
poly ptemp;
int j;
for(i=1;i<=ncols(mons);i++)
{
for(j=1;j<=ncols(sm);j++)
{
ptemp=sm[j]/mons[i];
motemp[j]=motemp[j]+ptemp*gen(i);
}
}
for(i=1;i<=size(iv);i++)
{
motemp=subst(motemp,var(iv[i]),0);
}
matrix monmat[1][ncols(mons)]=mons;
ideal dummy=monmat*motemp;
for(i=1;i<=size(sm);i++)
{
if(sm[i]-dummy[i]!=0)
{
ERROR("the second argument is not a submodule of the assumed structure");
}
}
//----------------------------------------------------------------------
// do the interreduction and convert back
//----------------------------------------------------------------------
execute(tempstr);
def motemp=imap(r,motemp);
intvec save=option(get);
option(redSB);
motemp=interred(motemp);
option(set,save);
setring r;
kill motemp;
def motemp=imap(rtemp,motemp);
//list ret=monmat,motemp,monmat*motemp;
module motemp2=motemp;
for(i=1;i<=ncols(motemp2);i++)
{
motemp2[i]=cleardenom(motemp2[i]);
}
module motemp3=monmat*motemp;
for(i=1;i<=ncols(motemp3);i++)
{
motemp3[i]=cleardenom(motemp3[i]);
}
list ret=monmat,motemp2,matrix(motemp3);
return(ret);
}
example
{ "EXAMPLE:"; echo=2;
ring r=0,(x,y,z),dp;
ideal i=x^2+x*y^2,x*y+x^2*y,z;
ideal j=x^2+x*y^2,x*y,z;
ideal mon=x^2,z,x*y;
intvec iv=1,3;
subrInterred(mon,i,iv);
subrInterred(mon,j,iv);
}
///////////////////////////////////////////////////////////////////////////////
// moved here from nctools.lib
// This procedure calculates the Newton diagram of the polynomial f
// The output is a intmat M, each row of M is the exp of a monomial in f
////////////////////////////////////////////////////////////////////////
proc newtonDiag(poly f)
"USAGE: newtonDiag(f); f a poly
RETURN: intmat
PURPOSE: compute the Newton diagram of f
NOTE: each row is the exponent of a monomial of f
EXAMPLE: example newtonDiag; shows examples
"{
int n = nvars(basering);
intvec N=0;
if ( f != 0 )
{
while ( f != 0 )
{
N = N, leadexp(f);
f = f-lead(f);
}
}
else
{
N=N, leadexp(f);
}
N = N[2..size(N)]; // Deletes the zero added in the definition of T
intmat M=intmat(N,(size(N) div n),n); // Conversion from vector to matrix
return (M);
}
example
{
"EXAMPLE:";echo=2;
ring r = 0,(x,y,z),lp;
poly f = x2y+3xz-5y+3;
newtonDiag(f);
}
////////////////////////////////////////////////////////////////////////
|