/usr/share/singular/LIB/realrad.lib is in singular-data 1:4.1.0-p3+ds-2build1.
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 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 | ////////////////////////////////////////////////////////////////////////////
version="version realrad.lib 4.0.0.0 Jun_2013 "; // $Id: b275d949fd627253e5d17a85b63c4ebd815a42ed $
category="real algebra";
info="
LIBRARY: realrad.lib Computation of real radicals
AUTHOR : Silke Spang
OVERVIEW:
Algorithms about the computation of the real
radical of an arbitary ideal over the rational numbers
and transcendetal extensions thereof
PROCEDURES:
realpoly(f); Computes the real part of the univariate polynomial f
realzero(j); Computes the real radical of the zerodimensional ideal j
realrad(j); Computes the real radical of an arbitary ideal over
transcendental extension of the rational numbers
";
LIB "inout.lib";
LIB "poly.lib";
LIB "matrix.lib";
LIB "general.lib";
LIB "rootsur.lib";
LIB "algebra.lib";
LIB "standard.lib";
LIB "primdec.lib";
LIB "elim.lib";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//// the main procedure //////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
proc realrad(ideal id)
"USAGE: realrad(id), id an ideal of arbitary dimension
RETURN: the real radical of id
EXAMPE: example realrad; shows an example"
{
def r=basering;
int n=nvars(basering);
// for faster Groebner basis and dimension compuations
string neuring ="ring schnell=("+charstr(r)+"),("+varstr(r)+"),dp;";
execute(neuring);
def ri=basering;
list reddim;//reduct dimension to 0
list lpar,lvar,sub;//for the ringchange
string pari,vari;
int i,siz,l,j;
string less="list lessvar="+varstr(r)+";";
execute(less);
ideal id=imap(r,id);
l=size(id);
for (i=1;i<=l;i++)
{
id[i]=simplify_gen(id[i]);
}
id=groebner(id);
if (dim(id)<=0)
{
id=realzero(id);
setring r;
id=imap(ri,id);
return(id);
}
//sub are the subsets of {x_1,...,x_n}
sub=subsets(n);
siz=size(sub)-1;//we dont want to localize on all variables
//for the empty set
reddim[1]=zeroreduct(id);
reddim[1]=realzero(reddim[1]);
for (i=1;i<=siz;i++)
{
lvar=lessvar;
lpar=list();
l=size(sub[i]);
for (j=1;j<=l;j++)
{
lpar=lpar+list(lvar[sub[i][j]-j+1]);
lvar=delete(lvar,sub[i][j]-j+1);
}
for(j=1;j<=l;j++)//there are l entries in lpar
{
pari=pari+","+string(lpar[j]);
}
l=n-l;//there are the remaining n-l entries in lvar
for(j=1;j<=l;j++)//there are l entries in lpar
{
vari=vari+","+string(lvar[j]);
}
vari=vari[2..size(vari)];
neuring="ring neu=("+charstr(r)+pari+"),("+vari+"),dp;";
execute(neuring);
ideal id=imap(r,id);
ideal buffer=zeroreduct(id);
buffer=realzero(buffer);
setring ri;
reddim[i+1]=imap(neu,buffer);
kill neu;
//compute the intersection of buffer with r
reddim[i+1]=contnonloc(reddim[i+1],pari,vari);
vari="";
pari="";
}
id=intersect(reddim[1..(siz+1)]);
//id=timeStd(id,301);//simplify the output
id=interred(id); // timeStd does not work yet
setring r;
id=imap(ri,id);
return(id);
}
example
{ "EXAMPLE:"; echo = 2;
ring r1=0,(x,y,z),lp;
//dimension 0
ideal i0=(x2+1)*(x3-2),(y3-2)*(y2+y+1),z3+2;
//dimension 1
ideal i1=(y3+3y2+y+1)*(y2+4y+4)*(x2+1),(x2+y)*(x2-y2)*(x2+2xy+y2)*(y2+y+1);
ideal i=intersect(i0,i1);
realrad(i);
}
/*static*/ proc zeroreduct(ideal i)
"USAGE:zeroreduct(i), i an arbitary ideal
RETURN: an ideal j of dimension <=0 s.th. i is contained in
j and j is contained in i_{Iso} which is the zariski closure
of all real isolated points of i
"
{
list equi;
int d,n,di;
n=nvars(basering);
def r=basering;
//chance ring to get faster groebner bases computation for dimensions
string rneu="ring neu=("+charstr(r)+"),("+varstr(r)+"),dp;";
execute(rneu);
ideal i=imap(r,i);
i=groebner(i);
while (dim(i)> 0)
{
equi=equidim(i);
d=size(equi);
equi[d]=radical(equi[d]);
di=dim(std(equi[d]));
equi[d]=equi[d],minor(jacob(equi[d]),n-di);
equi[d]=radical(equi[d]);
i=intersect(equi[1..d]);
i=groebner(i);
}
setring r;
i=imap(neu,i);
//i=timeStd(i,301);
i=interred(i); // timeStd does not work yet
return(i);
}
//////////////////////////////////////////////////////////////////////////////
///////the zero-dimensional case /////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
proc realzero(ideal j)
"USAGE: realzero(j); a zero-dimensional ideal j
RETURN: j: a zero dimensional ideal, which is the real radical
of i, if dim(i)=0
0: otherwise
this acts via
primary decomposition (i=1)
listdecomp (i=2) or facstd (i=3)
EXAMPLE: example realzero; shows an example"
{
list prim,prepared,nonshape,realu;
int r;//counter
int l;//number of first polynomial with degree >1 or even
l=size(j);
for (r=1;r<=l;r++)
{
j[r]=simplify_gen(j[r]);
if (j[r]==1)
{
return(ideal(1));
}
}
option(redSB);
//j=groebner(j);
//special case
//if (j==1)
//{
// return(j);
//}
if (nvars(basering)==1)
{
j=groebner(j);
j=realpoly(j[1]);
return(j);
}
//if (dim(j)>0) {return(0);}
def r_alt=basering;
//store the ring
//for a ring chance to the ordering lp;
execute("ring r_neu =("+charstr(basering)+"),("+varstr(basering)+"),lp;");
setring r_neu;
ideal boeser,max;
prepared[1]=ideal(1);
ideal j=imap(r_alt,j);
//ideal j=fglm(r_alt,j);
prim=primdecGTZ(j);
for (r=1;r<=size(prim);r++)
{
max=prim[r][2];
max=groebner(max);
realu=prepare_max(max);
max=realu[1];
if (max!=1)
{
if (realu[2]==1)
{
prepared=insert(prepared,max);
}
else
{
nonshape=insert(nonshape,max);
}
}
}
j=intersect(prepared[1..size(prepared)]);
//use a variable change into general position to obtain
//the shape via radzero
if (size(nonshape)>0)
{
boeser=GeneralPos(nonshape);
j=intersect(j,boeser);
}
//j=timeStd(j,301);
j=interred(j); // timeStd does not work yet
setring r_alt;
j=fetch(r_neu,j);
return(j);
}
example
{ "EXAMPLE:"; echo = 2;
//in non parametric fields
ring r=0,(x,y),dp;
ideal i=(y3+3y2+y+1)*(y2+4y+4)*(x2+1),(x2+y)*(x2-y2)*(x2+2xy+y2)*(y2+y+1);
realzero(i);
ideal j=(y3+3y2+y+1)*(y2-2y+1),(x2+y)*(x2-y2);
realzero(j);
//to get every path
ring r1=(0,t),(x,y),lp;
ideal m1=x2+1-t,y3+t2;
ideal m2=x2+t2+1,y2+t;
ideal m3=x2+1-t,y2-t;
ideal m4=x^2+1+t,y2-t;
ideal i=intersect(m1,m2,m3,m4);
realzero(i);
}
static proc GeneralPos(list buffer)
"USAGE: GeneralPos(buffer);
buffer a list of maximal ideals which failed the prepare_max-test
RETURN: j: the intersection of their realradicals
EXAMPLE: example radzero; shows no example"
{
def r=basering;
int n,ll;
//for the mapping in general position
map phi,psi;
ideal j;
ideal jmap=randomLast(20);
string ri;
intvec @hilb;
ideal trans,transprep;// the transformation ideals
int nva=nvars(r);
int zz,k,l;//counter
poly randp;
for (zz=1;zz<nva;zz++)
{
if (npars(basering)>0)
{
randp=randp+(random(0,5)*par(1)+random(0,5)*par(1)^2+random(0,5))*var(zz);
}
else
{
randp=randp+random(0,5)*var(zz);
}
}
randp=randp+var(nva);
//now they are all irreducible in the non univariate case and
//real in the univariate case
int m=size(buffer);
for (l=1;l<=m;l++)
{
//searching first non univariate polynomial with an even degree
//for odd degree we could use the fundamental theorem of algebra and
//get real zeros
//this will act via a coordinate chance into general position
//denote that this random chance doesn't work allways
//the ideas for the transformation into general position are
//used from the primdec.lib
transprep=buffer[l];
if (voice>=10)
{
jmap[size(jmap)]=randp;
}
for (k=2;k<=n;k++)
{
if (ord(buffer[l][k])==1)
{
for (zz=1;zz<=nva;zz++)
{
if (lead(buffer[l][k])/var(zz)!=0)
{
transprep[k]=var(zz);
}
}
jmap[nva]=subst(jmap[nva],lead(buffer[l][k]),0);
}
}
phi =r,jmap;
for (k=1;k<=nva;k++)
{
jmap[k]=-(jmap[k]-2*var(k));
}
psi =r,jmap;
//coordinate chance
trans=phi(transprep);
//acting with the chanced ideal
trans=groebner(trans);
trans[1]=realpoly(trans[1]);
//special case
if (trans==1)
{
buffer[l]=trans;
}
else
{
ri="ring rhelp=("+charstr(r)+ "),(" +varstr(r)+ ",@t),dp;";
execute(ri);
ideal trans=homog(imap(r,trans),@t);
ideal trans1=std(trans);
@hilb=hilb(trans1,1);
ri= "ring rhelp1=("
+charstr(r)+ "),(" +varstr(rhelp)+ "),lp;";
execute(ri);
ideal trans=homog(imap(r,trans),@t);
kill rhelp;
trans=std(trans,@hilb);
trans=subst(trans,@t,1);//dehomogenising
setring r;
trans=imap(rhelp1,trans);
kill rhelp1;
trans=std(trans);
attrib(trans,"isSB",1);
trans=realzero(trans);
//going back
buffer[l]=psi(trans);
//buffer[l]=timeStd(buffer[l],301);//timelimit for std computation
buffer[l]=interred(buffer[l]);//timeStd does not work yet
}
}
//option(returnSB);
j=intersect(buffer[1..m]);
return(j);
}
/*proc minAssReal(ideal i, int erg)
{
int l,m,d,e,r,fac;
ideal buffer,factor;
list minreal;
l=size(i);
for (r=1;r<=l;r++)
{
i[r]=simplify_gen(i[r]);
}
list pr=primdecGTZ(i);
m=size(pr);
for (l=1;l<=m;l++)
{
d=dim(std(pr[l][2]));
buffer=realrad(pr[l][2]);
buffer=std(buffer);
e=dim(buffer);
if (d==e)
{
minreal=minreal+list(pr[l]);
}
}
if (erg==0)
{
return(minreal);
}
else
{
pr=list();
m=size(minreal);
for (l=1;l<=m;l++)
{
pr=insert(pr,minreal[l][2]);
}
i=intersect(pr[1..m]);
//i=timeStd(i,301);
i=interred(i);//timeStd does not work yet
list realmin=minreal+list(i);
return(realmin);
}
}*/
//////////////////////////////////////////////////////////////////////////////
///////the univariate case ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
proc realpoly(poly f)
"USAGE: realpoly(f); a univariate polynomial f;
RETURN: poly f, where f is the real part of the input f
EXAMPLE: example realpoly; shows an example"
{
def r=basering;
int tester;
if (size(parstr(r))!=0)
{
string changering="ring rneu=0,("+parstr(r)+","+varstr(r)+"),lp";
execute(changering);
poly f=imap(r,f);
tester=1;
}
f=simplify(f,1);//wlog f is monic
if (f==1)
{
setring r;
return(f);
}
ideal j=factorize(f,1);//for getting the squarefree factorization
poly erg=1;
for (int i=1;i<=size(j);i=i+1)
{
if (is_real(j[i])==1) {erg=erg*j[i];}
//we only need real primes
}
if (tester==1)
{
setring(r);
poly erg=imap(rneu,erg);
}
return(erg);
}
example
{ "EXAMPLE:"; echo = 2;
ring r1 = 0,x,dp;
poly f=x5+16x2+x+1;
realpoly(f);
realpoly(f*(x4+2));
ring r2=0,(x,y),dp;
poly f=x6-3x4y2 + y6 + x2y2 -6y+5;
realpoly(f);
ring r3=0,(x,y,z),dp;
poly f=x4y4-2x5y3z2+x6y2z4+2x2y3z-4x3y2z3+2x4yz5+z2y2-2z4yx+z6x2;
realpoly(f);
realpoly(f*(x2+y2+1));
}
///////////////////////////////////////////////////////////////////////////////
//// for semi-definiteness/////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
proc decision(poly f)
" USAGE: decission(f); a multivariate polynomial f in Q[x_1,..,x_n] and lc f=0
RETURN: assume that the basering has a lexicographical ordering,
1 if f is positive semidefinite 0 if f is indefinite
EXAMPLE: decision shows an example
{
string ri,lessvar,parvar,perm;
ideal jac;
list varlist,buffer,isol,@s,lhelp,lhelp1,lfac,worklist;
poly p,g;
def rbuffer;
def r=basering;
//diverse zaehler
int @z,zz,count,tester;
int n=nvars(r);
//specialcases
if (leadcoef(f)<0)
{
return(0);
}
lfac=factorize(f,2);
ideal factor=lfac[1];
intvec @ex=lfac[2];
factor=factor[1];
zz=size(factor);
f=1;
for (@z=1;@z<=zz;@z++)
{
if ((@ex[@z] mod 2)==1)
{
f=f*factor[@z];
}
}
if (deg(f)<=0)
{
if (leadcoef(f)>=0)
{
return(1);
}
return(0);
}
//for recursion
if (n==1)
{
if (sturm(f,-length(f),length(f))==0)
{
return(1);
}
return(0);
}
//search for a p in Q[x_n] such that f is pos. sem. definite
//if and only if for every isolating setting S={a_1,...,a_r} holds that
//every f(x_1,..,x_n-1, a_i) is positiv semidefinite
//recursion of variables
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
ideal II = maxideal(1);
varlist = II[1..n-1];
lessvar=string(varlist);
parvar=string(var(n));
ri="ring r_neu="+charstr(r)+",(@t,"+parvar+","+lessvar+"),dp;";
execute(ri);
poly f=imap(r,f);
list varlist=imap(r,varlist);
ideal jac=jacob(@t+f);
jac=jac[3..(n+1)];
ideal eins=std(jac);
ideal i=@t+f,jac;
//use Wu method
if (eins==1)
{
zz=0;
}
else
{
matrix m=char_series(i);
zz=nrows(m);//number of rows
}
poly p=1;
for (@z=1;@z<=zz;@z++)
{
p=p*m[@z,1];
}
//trailing coefficient of p
p=subst(p,@t,0);
p=realpoly(p);
@s=subsets(n-1);
ideal jacs;
for (@z=1;@z<=size(@s);@z++)
{
perm="";
lhelp=list();
worklist=varlist;
buffer=jac[1..(n-1)];
//vorbereitungen fuer den Ringwechsel
//setze worklist=x_1,..,x_(n-1)
for (zz=1;zz<=size(@s[@z]);zz++)
{
buffer =delete(buffer ,@s[@z][zz]-zz+1);
worklist=delete(worklist,@s[@z][zz]-zz+1);
lhelp=lhelp+list(string(var(@s[@z][zz]+2)));
lhelp1=insert(lhelp,string(var(@s[@z][zz]+2)));
}
//worklist=(x_1,...,x_n-1)\(x_i1,...,x_ik)
//lhelp =(x_i1,...,x_ik)
//buffer=diff(f,x_i) i not in (i1,..,ik);
worklist=list("@t",string(var(2)))+lhelp+worklist;
for (zz=1;zz<=n+1;zz++)
{
perm=perm+","+string(worklist[zz]);
}
perm=perm[2..size(perm)];
if (size(buffer)!=0)
{
jacs=buffer[1..size(buffer)];
jacs=@t+f,jacs;
}
else
{
jacs=@t+f;
}
rbuffer=basering;
//perm=@t,x_n,x_1,..,x_ik,x\(x_i1,..,x_ik)
ri="ring rh=0,("+perm+"),dp;";
execute(ri);
ideal jacs=imap(rbuffer,jacs);
poly p=imap(rbuffer,p);
matrix m=char_series(jacs);
poly e=1;
for (count=1;count<=nrows(m);count++)
{
e=e*m[count,1];
}
//search for the leading coefficient of e in
//Q(@t,x_n)[x_@s[@z][1],..,x_@s[@z][size(@s[@z])]
intmat l[n-1][n-1];
for (zz=1;zz<n;zz++)
{
l[zz,n-zz]=1;
}
ri="ring rcoef="+"(0,@t,"+parvar+"),
("+lessvar+"),M(l);";
execute(ri);
kill l;
poly e=imap(rh,e);
e=leadcoef(e);
setring rh;
e=imap(rcoef,e);
e=subst(e,@t,0);
e=realpoly(e);
p=p*e;
setring r_neu;
p=imap(rh,p);
kill rh,rcoef;
}
setring r;
p=imap(r_neu,p);
///////////////////////////////////////////////////////////////////////////
///////////found polynomial p /////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//Compute an isolating set for p
ri="ring iso="+charstr(r)+","+parvar+",lp;";
execute(ri);
poly p=imap(r,p);
isol=isolset(p);
setring r;
list isol=imap(iso,isol);
tester=1;
for (@z=1;@z<=size(isol);@z++)
{
ri="ring rless="+charstr(r)+",("+lessvar+"),lp;";
g=subst(f,var(n),isol[@z]);
execute(ri);
poly g=imap(r,g);
tester=tester*decision(g);
setring r;
kill rless;
}
return(tester);
}
proc isolset(poly f)
"USAGE: isolset(f); f a univariate polynomial over the rational numbers
RETURN: An isolating set of f
NOTE: algorithm can be found in M-F. Roy,R: Pollack, S. Basu page 373
EXAMPLE: example isolset; shows an example"
{
int i,case;
number m;
list buffer;
//only real roots count
f=realpoly(f);
poly seppart=f;
seppart=simplify(seppart,1);
//int N=binlog(length(seppart));
//number zweihochN=exp(2,N+1);
number zweihochN=length(f);
//a special case
if (deg(seppart)==0)
{
return(list(number(0)));
}
if (sturm(seppart,-zweihochN,zweihochN)==1)
{
return(list(-zweihochN,zweihochN));
}
//getting bernstein coeffs
ideal id=isuni(f)-zweihochN;
map jmap=basering,id;
seppart=jmap(seppart);
id=2*zweihochN*var(1);
jmap=basering,id;
seppart=jmap(seppart);
matrix c=coeffs(seppart,var(1));
int s=size(c);
poly recproc;
//Reciprocal polynomial
for (i=1;i<=s;i++)
{
recproc=recproc+c[s+1-i,1]*(var(1)^(i-1));
}
jmap=basering,var(1)+1;
seppart=jmap(recproc);
list bernsteincoeffs,bern;
c=coeffs(seppart,var(1));
for (i=1;i<=s;i++)
{
bern[i]=number(c[s+1-i,1])/binomial(s-1,i-1);
}
bernsteincoeffs=bern,list(-zweihochN,zweihochN);
list POS;
POS[1]=bernsteincoeffs;
list L;
while (size(POS)!=0)
{
if (varsigns(POS[1][1])<2)
{
case=varsigns(POS[1][1]);
}
else
{
case=2;
}
//case Anweisung
buffer=POS[1];
POS=delete(POS,1);
while(1)
{
if (case==1)
{
L=L+buffer[2];
break;
}
if (case==2)
{
m=number(buffer[2][1]+buffer[2][2])/2;
bern=BernsteinCoefficients(buffer[1],buffer[2],m);
POS=bern+POS;
if (leadcoef(sign(leadcoef(subst(f,isuni(f),m))))==0)
{
number epsilon=1/10;
while (sturm(f,m-epsilon,m+epsilon)!=1)
{
epsilon=epsilon/10;
}
L=L+list(m-epsilon,m+epsilon);
}
break;
}
break;
}
}
i=1;
while (i<size(L))
{
if (L[i]==L[i+1])
{
L=delete(L,i);
}
else
{
i=i+1;
}
}
return(L);
}
static proc BernsteinCoefficients(list bern,list lr,number m)
"USAGE :BernsteinCoefficients(bern,lr,m);
a list bern=b_0,...,b_p representing a polynomial P of degree <=p
in the Bernstein basis pf lr=(l,r) an a number m in Q
RETURN:a list erg=erg1,erg2 s.th. erg1=erg1[1],erg[2] and erg1[1] are
the bernstein coefficients of P w.r.t. to erg1[2]=(l,m) and erg2[1]
is one for erg2[2]=(m,r)
EXAMPLE: Bernsteincoefficients shows no example
"
{
//Zaehler
int i,j;
list erg,erg1,erg2;
number a=(lr[2]-m)/(lr[2]-lr[1]);
number b=(m-lr[1])/(lr[2]-lr[1]);
int p=size(bern);
list berns,buffer,buffer2;
berns[1]=bern;
for (i=2;i<=p;i++)
{
for (j=1;j<=p+1-i;j++)
{
buffer[j]=a*berns[i-1][j]+b*berns[i-1][j+1];
}
berns[i]=buffer;
buffer=list();
}
for (i=1;i<=p;i++)
{
buffer[i]=berns[i][1];
buffer2[i]=berns[p+1-i][i];
}
erg1=buffer,list(lr[1],m);
erg2=buffer2,list(m,lr[2]);
erg=erg1,erg2;
return(erg);
}
static proc binlog(number i)
{
int erg;
if (i<2) {return(0);}
else
{
erg=1+binlog(i/2);
return(erg);
}
}
//////////////////////////////////////////////////////////////////////////////
///////diverse Hilfsprozeduren ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////wichtig fuers Verstaendnis//////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
static proc is_real(poly f)
"USAGE: is_real(f);a univariate irreducible polynomial f;
RETURN: 1: if f is real
0: is f is not real
EXAMPLE: example is_real; shows an example"
{
int d,anz,i;
def r=basering;
if (f==1) {return(1);}
if (isuniv(f)==0)
{
for (i=1;i<=nvars(r);i++)
{
d=size(coeffs(f,var(i)))+1;
if ((d mod 2)==1)
{
return(1);
}
}
d=1-decision(f);
return(d);
}
d=deg(f) mod 2;
if (d==1)
{
return(1);//because of fundamental theorem of algebra
}
else
{
f=simplify(f,1);//wlog we can assume that f is monic
number a=leadcoef(sign(leadcoef(subst(f,isuni(f),-length(f)))));
number b=leadcoef(sign(leadcoef(subst(f,isuni(f),length(f)))));
if
(a*b!=1)
//polynomials are contineous so the image is an interval
//referres to analysis
{
return(1);
}
else
{
anz=sturm(f,-length(f),length(f));
if (anz==0) {return(0);}
else {return(1);}
}
}
}
example
{ "EXAMPLE:"; echo = 2;
ring r1 = 0,x,dp;
poly f=x2+1;
is_real(f);
}
static proc prepare_max(ideal m)
"USAGE: prepare_max(m); m a maximal ideal in Q(y_1,...,y_m)[x_1,...,x_n]
RETURN: a list erg=(id,j); where id is the real radical of m if j=1 (i.e. m
satisfies the shape lemma in one variable x_i) else id=m and j=0;
EXAMPLE: is_in_shape shows an exmaple;
"
{
int j,k,i,l,fakul;
def r=basering;
int n=nvars(r);
list erg,varlist,perm;
string wechsler,vari;
//option(redSB);
for (i=1;i<=n;i++)
{
varlist=varlist+list(var(i));
}
perm=permutation(varlist);
fakul=size(perm);
for (i=1;i<=fakul;i++)
{
for (j=1;j<=n;j++)
{
vari=vari+","+string(perm[i][j]);
}
vari=vari[2..size(vari)];
wechsler="ring r_neu=("+charstr(r)+"),("+vari+"),lp;";
execute(wechsler);
ideal id=imap(r,m);
id=groebner(id);
k=search_first(id,2,2);
setring r;
m=imap(r_neu,id);
m[1]=realpoly(m[1]);
if (m[1]==1)
{
erg[1]=ideal(1);
erg[2]=1;
return(erg);
}
if (k>n)
{
erg[1]=m;
erg[2]=1;
return(erg);
}
else
{
for (l=k;l<=n;l++)
{
if (realpoly(m[l])==1)
{
erg[1]=ideal(1);
erg[2]=1;
return(erg);
}
}
}
vari="";
kill r_neu;
}
if (size(parstr(r))==0)
{
erg[1]=m;
j=1;
for (i=1;i<=n;i++)
{
j=j*isuniv(m[i]);
}
erg[2]=j;
return(erg);
}
erg[1]=m;
erg[2]=0;
return(erg);
}
static proc length(poly f)
"USAGE: length(f); poly f;
RETURN: sum of the absolute Value of all coeffients of an irreducible
poly nomial f
EXAMPLE: example length; shows an example"
{
number erg,buffer;
f=simplify(f,1);//wlog f is monic
int n=size(f);
for (int i=1;i<=n;i=i+1)
{
buffer= leadcoef(f[i]);
erg=erg + absValue(buffer);
}
return(erg);
}
example
{ "EXAMPLE:"; echo = 2;
ring r1 = 0,x,dp;
poly f=x4-6x3+x2+1;
norm(f);
ring r2=0,(x,y),dp;
poly g=x2-y3;
length(g);
}
//////////////////////////////////////////////////////////////////////////////
//////////////weniger wichtig fuers Verstaendnis//////////////////////////////
//////////////////////////////////////////////////////////////////////////////
static proc isuniv(poly f)
{
int erg;
if (f==0)
{
erg=1;
}
else
{
erg=(isuni(f)!=0);
}
return(erg);
}
static proc search_first(ideal j,int start, int i)
"USAGE: searchfirst(j, start, i);
id a reduced groebner basis w.r.t. lex
RETURN: if i=1 then turns the number of the first non univariate entry
with order >1 in its leading term after start
else the first non univariate of even order
EXAMPLE: example norm; shows no example"
{
int n=size(j);
int k=start;//counter
j=j,0;
if (i==1)
{
while
((k<=n)&&(ord(j[k])==1))
{
k=k+1;
}
}
else
{
while
((k<=n)&&(ord(j[k]) mod 2==1))
{
k=k+1;
}
}
return(k);
}
static proc subsets(int n)
"USAGE :subsets(n); n>=0 in Z
RETURN :l a list of all non-empty subsets of {1,..,n}
EXAMPLE:subsets(n) shows an example;
"
{
list l,buffer;
int i,j,binzahl;
if (n<=0)
{
return(l);
}
int grenze=2**n-1;
for (i=1;i<=grenze;i++)
{
binzahl=i;
for (j=1;j<=n;j++)
{
if ((binzahl mod 2)==1)
{
buffer=buffer+list(j);
}
binzahl=binzahl div 2;
}
l[i]=buffer;
buffer=list();
}
return(l);
}
example
{ "EXAMPLE:"; echo = 2;
subsets(3);
subsets(4);
}
proc permutation(list L)
" USAGE: permutation(L); L a list
OUTPUT: a list of all permutation lists of L
EXAMPLE: permutation(L) gives an example"
{
list erg,buffer,permi,einfueger;
int i,j,l;
int n=size(L);
if (n==0)
{
return(erg);
}
if (n==1)
{
erg=list(L);
return(erg);
}
for (i=1;i<=n;i++)
{
buffer=delete(L,i);
einfueger=permutation(buffer);
l=size(einfueger);
for (j=1;j<=l;j++)
{
permi=list(L[i])+einfueger[j];
erg=insert(erg,permi);
}
}
return(erg);
}
example
{ "EXAMPLE:"; echo = 2;
list L1="Just","an","example";
permutation(L1);
list L2=1,2,3,4;
permutation(L2);
}
static proc simplify_gen(poly f)
"USAGE : simplify_gen(f); f a polymimial in Q(y_1,..,y_m)[x_1,..,x_n]
RETURN : a polynomial g such that g is the square-free part of f and
every real univariate factor of f is cancelled out
EXAMPLE:simplify_gen gives no example"
{
int i,l;
ideal factor;
poly g=1;
factor=factorize(f,2)[1];
l=size(factor);
for (i=1;i<=l;i++)
{
if (isuniv(factor[i]))
{
g=g*realpoly(factor[i]);
}
else
{
g=g*factor[i];
}
}
return(g);
}
static proc contnonloc(ideal id,string pari, string vari)
"INPUT : a radical ideal id in in F[pari+vari] which is radical in
F(pari)[vari), pari and vari strings of variables
OUTPUT : the contraction ideal of id, i.e. idF(pari)[vari]\cap F[pari+vari]
EXAMPLE: contnonloc shows an example
"
{
list pr;
list contractpr;
int i,l,tester;
ideal primcomp;
def r=basering;
string neu="ring r_neu=("+charstr(r)+pari+"),("+vari+"),dp;";
execute(neu);
def r1=basering;
ideal buffer;
setring r;
pr=primdecGTZ(id);
l=size(pr);
contractpr[1]=ideal(1);
for (i=1;i<=l;i++)
{
primcomp=pr[i][2];
setring r1;
buffer=imap(r,primcomp);
buffer=groebner(buffer);
if (buffer==1)
{
tester=0;
}
else
{
tester=1;
}
setring r;
//id only consits of non units in F(pari)
if (tester==1)
{
contractpr=insert(contractpr,primcomp);
}
}
l=size(contractpr);
id=intersect(contractpr[1..l]);
return(id);
}
example
{ "EXAMPLE:"; echo = 2;
ring r = 0,(a,b,c),lp;
ideal i=b3+c5,ab2+c3;
ideal j=contnonloc(i,",b","a,c");
j;
}
|