[e83e84] | 1 | /////////////////////////////////////////////////////////////////////////////// |
---|
[341696] | 2 | version="$Id$"; |
---|
[e83e84] | 3 | category="real algebra"; |
---|
| 4 | info=" |
---|
| 5 | LIBRARY: realrad.lib Computation of real radicals |
---|
| 6 | AUTHOR : Silke Spang |
---|
| 7 | |
---|
| 8 | OVERVIEW: |
---|
| 9 | Algorithms about the computation of the real |
---|
| 10 | radical of an arbitary ideal over the rational numbers |
---|
| 11 | and transcendetal extensions thereof |
---|
| 12 | |
---|
| 13 | PROCEDURES: |
---|
| 14 | realpoly(f); Computes the real part of the univariate polynomial f |
---|
| 15 | realzero(j); Computes the real radical of the zerodimensional ideal j |
---|
| 16 | realrad(j); Computes the real radical of an arbitary ideal over |
---|
| 17 | transcendental extension of the rational numbers |
---|
| 18 | "; |
---|
| 19 | |
---|
| 20 | LIB "inout.lib"; |
---|
| 21 | LIB "poly.lib"; |
---|
| 22 | LIB "matrix.lib"; |
---|
| 23 | LIB "general.lib"; |
---|
| 24 | LIB "rootsur.lib"; |
---|
| 25 | LIB "algebra.lib"; |
---|
| 26 | LIB "standard.lib"; |
---|
| 27 | LIB "primdec.lib"; |
---|
| 28 | LIB "elim.lib"; |
---|
| 29 | |
---|
| 30 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 31 | |
---|
| 32 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 33 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 34 | //// the main procedure ////////////////////////////////////////////////////// |
---|
| 35 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 36 | proc realrad(ideal id) |
---|
| 37 | "USAGE: realrad(id), id an ideal of arbitary dimension |
---|
| 38 | RETURN: the real radical of id |
---|
| 39 | EXAMPE: example realrad; shows an example" |
---|
| 40 | { |
---|
| 41 | |
---|
| 42 | def r=basering; |
---|
| 43 | int n=nvars(basering); |
---|
| 44 | // for faster Groebner basis and dimension compuations |
---|
| 45 | string neuring ="ring schnell=("+charstr(r)+"),("+varstr(r)+"),dp;"; |
---|
| 46 | execute(neuring); |
---|
| 47 | def ri=basering; |
---|
| 48 | |
---|
| 49 | list reddim;//reduct dimension to 0 |
---|
| 50 | list lpar,lvar,sub;//for the ringchange |
---|
| 51 | string pari,vari; |
---|
| 52 | int i,siz,l,j; |
---|
| 53 | string less="list lessvar="+varstr(r)+";"; |
---|
| 54 | execute(less); |
---|
| 55 | ideal id=imap(r,id); |
---|
| 56 | l=size(id); |
---|
| 57 | for (i=1;i<=l;i++) |
---|
| 58 | { |
---|
| 59 | id[i]=simplify_gen(id[i]); |
---|
| 60 | } |
---|
| 61 | id=groebner(id); |
---|
| 62 | if (dim(id)<=0) |
---|
| 63 | { |
---|
| 64 | id=realzero(id); |
---|
| 65 | setring r; |
---|
| 66 | id=imap(ri,id); |
---|
| 67 | return(id); |
---|
| 68 | } |
---|
| 69 | //sub are the subsets of {x_1,...,x_n} |
---|
[224420b] | 70 | sub=subsets(n); |
---|
[e83e84] | 71 | siz=size(sub)-1;//we dont want to localize on all variables |
---|
| 72 | |
---|
| 73 | //for the empty set |
---|
| 74 | reddim[1]=zeroreduct(id); |
---|
| 75 | reddim[1]=realzero(reddim[1]); |
---|
| 76 | for (i=1;i<=siz;i++) |
---|
| 77 | { |
---|
| 78 | |
---|
| 79 | lvar=lessvar; |
---|
| 80 | lpar=list(); |
---|
| 81 | l=size(sub[i]); |
---|
| 82 | for (j=1;j<=l;j++) |
---|
| 83 | { |
---|
| 84 | lpar=lpar+list(lvar[sub[i][j]-j+1]); |
---|
| 85 | lvar=delete(lvar,sub[i][j]-j+1); |
---|
| 86 | } |
---|
| 87 | for(j=1;j<=l;j++)//there are l entries in lpar |
---|
| 88 | { |
---|
| 89 | pari=pari+","+string(lpar[j]); |
---|
| 90 | } |
---|
| 91 | l=n-l;//there are the remaining n-l entries in lvar |
---|
| 92 | for(j=1;j<=l;j++)//there are l entries in lpar |
---|
| 93 | { |
---|
| 94 | vari=vari+","+string(lvar[j]); |
---|
| 95 | } |
---|
| 96 | vari=vari[2..size(vari)]; |
---|
| 97 | neuring="ring neu=("+charstr(r)+pari+"),("+vari+"),dp;"; |
---|
| 98 | execute(neuring); |
---|
| 99 | ideal id=imap(r,id); |
---|
| 100 | ideal buffer=zeroreduct(id); |
---|
| 101 | buffer=realzero(buffer); |
---|
| 102 | setring ri; |
---|
| 103 | reddim[i+1]=imap(neu,buffer); |
---|
| 104 | kill neu; |
---|
| 105 | //compute the intersection of buffer with r |
---|
| 106 | reddim[i+1]=contnonloc(reddim[i+1],pari,vari); |
---|
| 107 | vari=""; |
---|
| 108 | pari=""; |
---|
| 109 | } |
---|
| 110 | id=intersect(reddim[1..(siz+1)]); |
---|
| 111 | id=timeStd(id,301);//simplify the output |
---|
| 112 | setring r; |
---|
| 113 | id=imap(ri,id); |
---|
| 114 | return(id); |
---|
| 115 | |
---|
| 116 | } |
---|
| 117 | example |
---|
| 118 | { "EXAMPLE:"; echo = 2; |
---|
[7ba9fe] | 119 | ring r1=0,(x,y,z),lp; |
---|
| 120 | //dimension 0 |
---|
| 121 | ideal i0=(x2+1)*(x3-2),(y3-2)*(y2+y+1),z3+2; |
---|
| 122 | //dimension 1 |
---|
[a1c745] | 123 | ideal i1=(y3+3y2+y+1)*(y2+4y+4)*(x2+1),(x2+y)*(x2-y2)*(x2+2xy+y2)*(y2+y+1); |
---|
[7ba9fe] | 124 | ideal i=intersect(i0,i1); |
---|
[a1c745] | 125 | realrad(i); |
---|
[e83e84] | 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
[7ba9fe] | 129 | /*static*/ proc zeroreduct(ideal i) |
---|
[e83e84] | 130 | "USAGE:zeroreduct(i), i an arbitary ideal |
---|
| 131 | RETURN: an ideal j of dimension <=0 s.th. i is contained in |
---|
| 132 | j and j is contained in i_{Iso} which is the zariski closure |
---|
| 133 | of all real isolated points of i |
---|
| 134 | " |
---|
| 135 | { |
---|
| 136 | list equi; |
---|
| 137 | int d,n,di; |
---|
| 138 | n=nvars(basering); |
---|
| 139 | def r=basering; |
---|
| 140 | |
---|
| 141 | //chance ring to get faster groebner bases computation for dimensions |
---|
| 142 | |
---|
| 143 | string rneu="ring neu=("+charstr(r)+"),("+varstr(r)+"),dp;"; |
---|
| 144 | execute(rneu); |
---|
| 145 | ideal i=imap(r,i); |
---|
| 146 | |
---|
| 147 | i=groebner(i); |
---|
| 148 | while (dim(i)> 0) |
---|
| 149 | { |
---|
| 150 | equi=equidim(i); |
---|
| 151 | d=size(equi); |
---|
| 152 | equi[d]=radical(equi[d]); |
---|
[7ba9fe] | 153 | di=dim(std(equi[d])); |
---|
[e83e84] | 154 | equi[d]=equi[d],minor(jacob(equi[d]),n-di); |
---|
| 155 | equi[d]=radical(equi[d]); |
---|
| 156 | i=intersect(equi[1..d]); |
---|
| 157 | i=groebner(i); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | setring r; |
---|
| 161 | i=imap(neu,i); |
---|
| 162 | i=timeStd(i,301); |
---|
| 163 | return(i); |
---|
| 164 | } |
---|
| 165 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 166 | ///////the zero-dimensional case ///////////////////////////////////////////// |
---|
| 167 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 168 | proc realzero(ideal j) |
---|
| 169 | "USAGE: realzero(j); a zero-dimensional ideal j |
---|
| 170 | RETURN: j: a zero dimensional ideal, which is the real radical |
---|
| 171 | of i, if dim(i)=0 |
---|
| 172 | 0: otherwise |
---|
| 173 | this acts via |
---|
| 174 | primary decomposition (i=1) |
---|
| 175 | listdecomp (i=2) or facstd (i=3) |
---|
| 176 | EXAMPLE: example realzero; shows an example" |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | { |
---|
| 180 | list prim,prepared,nonshape,realu; |
---|
| 181 | int r;//counter |
---|
[3754ca] | 182 | int l;//number of first polynomial with degree >1 or even |
---|
[e83e84] | 183 | l=size(j); |
---|
| 184 | for (r=1;r<=l;r++) |
---|
| 185 | { |
---|
| 186 | j[r]=simplify_gen(j[r]); |
---|
| 187 | if (j[r]==1) |
---|
| 188 | { |
---|
| 189 | return(ideal(1)); |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | option(redSB); |
---|
| 193 | //j=groebner(j); |
---|
| 194 | //special case |
---|
| 195 | //if (j==1) |
---|
| 196 | //{ |
---|
| 197 | // return(j); |
---|
| 198 | //} |
---|
| 199 | if (nvars(basering)==1) |
---|
| 200 | { |
---|
| 201 | j=groebner(j); |
---|
| 202 | j=realpoly(j[1]); |
---|
| 203 | return(j); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | //if (dim(j)>0) {return(0);} |
---|
| 208 | |
---|
| 209 | def r_alt=basering; |
---|
| 210 | //store the ring |
---|
| 211 | //for a ring chance to the ordering lp; |
---|
| 212 | execute("ring r_neu =("+charstr(basering)+"),("+varstr(basering)+"),lp;"); |
---|
| 213 | setring r_neu; |
---|
| 214 | ideal boeser,max; |
---|
| 215 | prepared[1]=ideal(1); |
---|
| 216 | ideal j=imap(r_alt,j); |
---|
| 217 | //ideal j=fglm(r_alt,j); |
---|
| 218 | prim=primdecGTZ(j); |
---|
| 219 | for (r=1;r<=size(prim);r++) |
---|
| 220 | { |
---|
| 221 | max=prim[r][2]; |
---|
| 222 | max=groebner(max); |
---|
| 223 | realu=prepare_max(max); |
---|
| 224 | max=realu[1]; |
---|
| 225 | if (max!=1) |
---|
| 226 | { |
---|
| 227 | if (realu[2]==1) |
---|
| 228 | { |
---|
| 229 | prepared=insert(prepared,max); |
---|
| 230 | } |
---|
| 231 | else |
---|
| 232 | { |
---|
| 233 | nonshape=insert(nonshape,max); |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | j=intersect(prepared[1..size(prepared)]); |
---|
| 238 | |
---|
| 239 | //use a variable change into general position to obtain |
---|
| 240 | //the shape via radzero |
---|
| 241 | if (size(nonshape)>0) |
---|
| 242 | { |
---|
| 243 | boeser=GeneralPos(nonshape); |
---|
| 244 | j=intersect(j,boeser); |
---|
| 245 | } |
---|
| 246 | j=timeStd(j,301); |
---|
| 247 | setring r_alt; |
---|
| 248 | j=fetch(r_neu,j); |
---|
| 249 | return(j); |
---|
| 250 | } |
---|
| 251 | example |
---|
| 252 | { "EXAMPLE:"; echo = 2; |
---|
| 253 | //in non parametric fields |
---|
| 254 | ring r=0,(x,y),dp; |
---|
| 255 | ideal i=(y3+3y2+y+1)*(y2+4y+4)*(x2+1),(x2+y)*(x2-y2)*(x2+2xy+y2)*(y2+y+1); |
---|
| 256 | realzero(i); |
---|
| 257 | ideal j=(y3+3y2+y+1)*(y2-2y+1),(x2+y)*(x2-y2); |
---|
| 258 | realzero(j); |
---|
| 259 | |
---|
| 260 | //to get every path |
---|
| 261 | ring r1=(0,t),(x,y),lp; |
---|
| 262 | ideal m1=x2+1-t,y3+t2; |
---|
| 263 | ideal m2=x2+t2+1,y2+t; |
---|
| 264 | ideal m3=x2+1-t,y2-t; |
---|
| 265 | ideal m4=x^2+1+t,y2-t; |
---|
| 266 | ideal i=intersect(m1,m2,m3,m4); |
---|
| 267 | realzero(i); |
---|
| 268 | |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | static proc GeneralPos(list buffer) |
---|
| 272 | "USAGE: GeneralPos(buffer); |
---|
| 273 | buffer a list of maximal ideals which failed the prepare_max-test |
---|
| 274 | RETURN: j: the intersection of their realradicals |
---|
| 275 | EXAMPLE: example radzero; shows no example" |
---|
| 276 | { |
---|
| 277 | def r=basering; |
---|
| 278 | int n,ll; |
---|
| 279 | //for the mapping in general position |
---|
| 280 | map phi,psi; |
---|
| 281 | ideal j; |
---|
| 282 | ideal jmap=randomLast(20); |
---|
| 283 | string ri; |
---|
| 284 | intvec @hilb; |
---|
| 285 | ideal trans,transprep;// the transformation ideals |
---|
| 286 | int nva=nvars(r); |
---|
| 287 | int zz,k,l;//counter |
---|
| 288 | poly randp; |
---|
| 289 | for (zz=1;zz<nva;zz++) |
---|
| 290 | { |
---|
| 291 | if (npars(basering)>0) |
---|
| 292 | { |
---|
| 293 | randp=randp+(random(0,5)*par(1)+random(0,5)*par(1)^2+random(0,5))*var(zz); |
---|
| 294 | } |
---|
| 295 | else |
---|
| 296 | { |
---|
| 297 | randp=randp+random(0,5)*var(zz); |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | randp=randp+var(nva); |
---|
| 301 | |
---|
| 302 | //now they are all irreducible in the non univariate case and |
---|
| 303 | //real in the univariate case |
---|
| 304 | |
---|
| 305 | int m=size(buffer); |
---|
| 306 | for (l=1;l<=m;l++) |
---|
| 307 | { |
---|
| 308 | //searching first non univariate polynomial with an even degree |
---|
| 309 | //for odd degree we could use the fundamental theorem of algebra and |
---|
| 310 | //get real zeros |
---|
| 311 | |
---|
| 312 | //this will act via a coordinate chance into general position |
---|
| 313 | //denote that this random chance doesn't work allways |
---|
| 314 | //the ideas for the transformation into general position are |
---|
| 315 | //used from the primdec.lib |
---|
| 316 | transprep=buffer[l]; |
---|
| 317 | if (voice>=10) |
---|
| 318 | { |
---|
| 319 | jmap[size(jmap)]=randp; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | |
---|
| 323 | for (k=2;k<=n;k++) |
---|
| 324 | { |
---|
| 325 | if (ord(buffer[l][k])==1) |
---|
| 326 | { |
---|
| 327 | for (zz=1;zz<=nva;zz++) |
---|
| 328 | { |
---|
| 329 | if (lead(buffer[l][k])/var(zz)!=0) |
---|
| 330 | { |
---|
| 331 | transprep[k]=var(zz); |
---|
| 332 | } |
---|
| 333 | } |
---|
| 334 | jmap[nva]=subst(jmap[nva],lead(buffer[l][k]),0); |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | phi =r,jmap; |
---|
| 338 | for (k=1;k<=nva;k++) |
---|
| 339 | { |
---|
| 340 | jmap[k]=-(jmap[k]-2*var(k)); |
---|
| 341 | } |
---|
| 342 | psi =r,jmap; |
---|
| 343 | |
---|
| 344 | //coordinate chance |
---|
| 345 | trans=phi(transprep); |
---|
| 346 | |
---|
| 347 | //acting with the chanced ideal |
---|
| 348 | |
---|
| 349 | trans=groebner(trans); |
---|
| 350 | trans[1]=realpoly(trans[1]); |
---|
| 351 | |
---|
| 352 | //special case |
---|
| 353 | if (trans==1) |
---|
| 354 | { |
---|
| 355 | buffer[l]=trans; |
---|
| 356 | } |
---|
| 357 | else |
---|
| 358 | { |
---|
| 359 | ri="ring rhelp=("+charstr(r)+ "),(" +varstr(r)+ ",@t),dp;"; |
---|
| 360 | execute(ri); |
---|
| 361 | ideal trans=homog(imap(r,trans),@t); |
---|
| 362 | |
---|
| 363 | ideal trans1=std(trans); |
---|
| 364 | @hilb=hilb(trans1,1); |
---|
| 365 | ri= "ring rhelp1=(" |
---|
| 366 | +charstr(r)+ "),(" +varstr(rhelp)+ "),lp;"; |
---|
| 367 | execute(ri); |
---|
| 368 | ideal trans=homog(imap(r,trans),@t); |
---|
| 369 | kill rhelp; |
---|
| 370 | trans=std(trans,@hilb); |
---|
| 371 | trans=subst(trans,@t,1);//dehomogenising |
---|
| 372 | setring r; |
---|
| 373 | trans=imap(rhelp1,trans); |
---|
| 374 | kill rhelp1; |
---|
| 375 | trans=std(trans); |
---|
| 376 | attrib(trans,"isSB",1); |
---|
| 377 | |
---|
| 378 | trans=realzero(trans); |
---|
| 379 | |
---|
| 380 | //going back |
---|
| 381 | buffer[l]=psi(trans); |
---|
| 382 | buffer[l]=timeStd(buffer[l],301);//timelimit for std computation |
---|
| 383 | } |
---|
| 384 | } |
---|
| 385 | //option(returnSB); |
---|
| 386 | j=intersect(buffer[1..m]); |
---|
| 387 | return(j); |
---|
| 388 | |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | /*proc minAssReal(ideal i, int erg) |
---|
| 392 | { |
---|
| 393 | int l,m,d,e,r,fac; |
---|
| 394 | ideal buffer,factor; |
---|
| 395 | list minreal; |
---|
| 396 | l=size(i); |
---|
| 397 | for (r=1;r<=l;r++) |
---|
| 398 | { |
---|
| 399 | i[r]=simplify_gen(i[r]); |
---|
| 400 | |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | list pr=primdecGTZ(i); |
---|
| 404 | m=size(pr); |
---|
| 405 | for (l=1;l<=m;l++) |
---|
| 406 | { |
---|
| 407 | d=dim(std(pr[l][2])); |
---|
| 408 | buffer=realrad(pr[l][2]); |
---|
| 409 | buffer=std(buffer); |
---|
| 410 | e=dim(buffer); |
---|
| 411 | if (d==e) |
---|
| 412 | { |
---|
| 413 | minreal=minreal+list(pr[l]); |
---|
| 414 | } |
---|
| 415 | } |
---|
| 416 | if (erg==0) |
---|
| 417 | { |
---|
| 418 | return(minreal); |
---|
| 419 | } |
---|
| 420 | else |
---|
| 421 | { |
---|
| 422 | pr=list(); |
---|
| 423 | m=size(minreal); |
---|
| 424 | for (l=1;l<=m;l++) |
---|
| 425 | { |
---|
| 426 | pr=insert(pr,minreal[l][2]); |
---|
| 427 | } |
---|
| 428 | i=intersect(pr[1..m]); |
---|
| 429 | i=timeStd(i,301); |
---|
| 430 | list realmin=minreal+list(i); |
---|
| 431 | return(realmin); |
---|
| 432 | } |
---|
| 433 | }*/ |
---|
| 434 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 435 | ///////the univariate case /////////////////////////////////////////////////// |
---|
| 436 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 437 | proc realpoly(poly f) |
---|
[3754ca] | 438 | "USAGE: realpoly(f); a univariate polynomial f; |
---|
[e83e84] | 439 | RETURN: poly f, where f is the real part of the input f |
---|
| 440 | EXAMPLE: example realpoly; shows an example" |
---|
| 441 | { |
---|
| 442 | def r=basering; |
---|
| 443 | int tester; |
---|
| 444 | if (size(parstr(r))!=0) |
---|
| 445 | { |
---|
| 446 | string changering="ring rneu=0,("+parstr(r)+","+varstr(r)+"),lp"; |
---|
| 447 | execute(changering); |
---|
| 448 | poly f=imap(r,f); |
---|
| 449 | tester=1; |
---|
| 450 | } |
---|
| 451 | f=simplify(f,1);//wlog f is monic |
---|
| 452 | if (f==1) |
---|
| 453 | { |
---|
| 454 | setring r; |
---|
| 455 | return(f); |
---|
| 456 | } |
---|
| 457 | ideal j=factorize(f,1);//for getting the squarefree factorization |
---|
| 458 | poly erg=1; |
---|
| 459 | for (int i=1;i<=size(j);i=i+1) |
---|
| 460 | { |
---|
| 461 | if (is_real(j[i])==1) {erg=erg*j[i];} |
---|
| 462 | //we only need real primes |
---|
| 463 | } |
---|
| 464 | if (tester==1) |
---|
| 465 | { |
---|
| 466 | setring(r); |
---|
| 467 | poly erg=imap(rneu,erg); |
---|
| 468 | } |
---|
| 469 | return(erg); |
---|
| 470 | } |
---|
| 471 | example |
---|
| 472 | { "EXAMPLE:"; echo = 2; |
---|
| 473 | ring r1 = 0,x,dp; |
---|
| 474 | poly f=x5+16x2+x+1; |
---|
| 475 | realpoly(f); |
---|
| 476 | realpoly(f*(x4+2)); |
---|
| 477 | ring r2=0,(x,y),dp; |
---|
| 478 | poly f=x6-3x4y2 + y6 + x2y2 -6y+5; |
---|
| 479 | realpoly(f); |
---|
| 480 | ring r3=0,(x,y,z),dp; |
---|
| 481 | poly f=x4y4-2x5y3z2+x6y2z4+2x2y3z-4x3y2z3+2x4yz5+z2y2-2z4yx+z6x2; |
---|
| 482 | realpoly(f); |
---|
| 483 | realpoly(f*(x2+y2+1)); |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | |
---|
| 487 | |
---|
| 488 | |
---|
| 489 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 490 | //// for semi-definiteness///////////////////////////////////////////////////// |
---|
| 491 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 492 | proc decision(poly f) |
---|
| 493 | " USAGE: decission(f); a multivariate polynomial f in Q[x_1,..,x_n] and lc f=0 |
---|
| 494 | RETURN: assume that the basering has a lexicographical ordering, |
---|
| 495 | 1 if f is positive semidefinite 0 if f is indefinite |
---|
| 496 | EXAMPLE: decision shows an example |
---|
| 497 | { |
---|
[3fd4df] | 498 | string ri,lessvar,parvar,perm; |
---|
[e83e84] | 499 | ideal jac; |
---|
| 500 | list varlist,buffer,isol,@s,lhelp,lhelp1,lfac,worklist; |
---|
| 501 | poly p,g; |
---|
| 502 | def rbuffer; |
---|
| 503 | def r=basering; |
---|
| 504 | //diverse zaehler |
---|
| 505 | int @z,zz,count,tester; |
---|
| 506 | int n=nvars(r); |
---|
| 507 | //specialcases |
---|
| 508 | |
---|
| 509 | if (leadcoef(f)<0) |
---|
| 510 | { |
---|
| 511 | return(0); |
---|
| 512 | } |
---|
| 513 | lfac=factorize(f,2); |
---|
| 514 | ideal factor=lfac[1]; |
---|
[4c346c] | 515 | intvec @ex=lfac[2]; |
---|
[e83e84] | 516 | factor=factor[1]; |
---|
| 517 | zz=size(factor); |
---|
| 518 | f=1; |
---|
| 519 | for (@z=1;@z<=zz;@z++) |
---|
| 520 | { |
---|
[4c346c] | 521 | if ((@ex[@z] mod 2)==1) |
---|
[e83e84] | 522 | { |
---|
| 523 | f=f*factor[@z]; |
---|
| 524 | } |
---|
| 525 | } |
---|
| 526 | if (deg(f)<=0) |
---|
| 527 | { |
---|
| 528 | if (leadcoef(f)>=0) |
---|
| 529 | { |
---|
| 530 | return(1); |
---|
| 531 | } |
---|
| 532 | return(0); |
---|
| 533 | } |
---|
| 534 | //for recursion |
---|
| 535 | if (n==1) |
---|
| 536 | { |
---|
| 537 | if (sturm(f,-length(f),length(f))==0) |
---|
| 538 | { |
---|
| 539 | return(1); |
---|
| 540 | } |
---|
| 541 | return(0); |
---|
| 542 | } |
---|
| 543 | //search for a p in Q[x_n] such that f is pos. sem. definite |
---|
[3754ca] | 544 | //if and only if for every isolating setting S={a_1,...,a_r} holds that |
---|
[e83e84] | 545 | //every f(x_1,..,x_n-1, a_i) is positiv semidefinite |
---|
| 546 | //recursion of variables |
---|
| 547 | /////////////////////////////////////////////////////////////////////////// |
---|
| 548 | /////////////////////////////////////////////////////////////////////////// |
---|
[bee06d] | 549 | ideal II = maxideal(1); |
---|
| 550 | varlist = II[1..n-1]; |
---|
| 551 | lessvar=string(varlist); |
---|
| 552 | |
---|
[3fd4df] | 553 | parvar=string(var(n)); |
---|
| 554 | ri="ring r_neu="+charstr(r)+",(@t,"+parvar+","+lessvar+"),dp;"; |
---|
[e83e84] | 555 | execute(ri); |
---|
| 556 | poly f=imap(r,f); |
---|
| 557 | list varlist=imap(r,varlist); |
---|
| 558 | ideal jac=jacob(@t+f); |
---|
| 559 | jac=jac[3..(n+1)]; |
---|
| 560 | ideal eins=std(jac); |
---|
| 561 | ideal i=@t+f,jac; |
---|
| 562 | //use Wu method |
---|
| 563 | if (eins==1) |
---|
| 564 | { |
---|
| 565 | zz=0; |
---|
| 566 | } |
---|
| 567 | else |
---|
| 568 | { |
---|
| 569 | matrix m=char_series(i); |
---|
| 570 | zz=nrows(m);//number of rows |
---|
| 571 | } |
---|
| 572 | poly p=1; |
---|
| 573 | for (@z=1;@z<=zz;@z++) |
---|
| 574 | { |
---|
| 575 | p=p*m[@z,1]; |
---|
| 576 | } |
---|
| 577 | //trailing coefficient of p |
---|
| 578 | p=subst(p,@t,0); |
---|
| 579 | p=realpoly(p); |
---|
[224420b] | 580 | @s=subsets(n-1); |
---|
[e83e84] | 581 | ideal jacs; |
---|
| 582 | for (@z=1;@z<=size(@s);@z++) |
---|
| 583 | { |
---|
| 584 | perm=""; |
---|
| 585 | lhelp=list(); |
---|
| 586 | |
---|
| 587 | worklist=varlist; |
---|
| 588 | buffer=jac[1..(n-1)]; |
---|
| 589 | //vorbereitungen fuer den Ringwechsel |
---|
| 590 | //setze worklist=x_1,..,x_(n-1) |
---|
| 591 | |
---|
| 592 | for (zz=1;zz<=size(@s[@z]);zz++) |
---|
| 593 | { |
---|
| 594 | buffer =delete(buffer ,@s[@z][zz]-zz+1); |
---|
| 595 | worklist=delete(worklist,@s[@z][zz]-zz+1); |
---|
| 596 | lhelp=lhelp+list(string(var(@s[@z][zz]+2))); |
---|
| 597 | lhelp1=insert(lhelp,string(var(@s[@z][zz]+2))); |
---|
| 598 | } |
---|
| 599 | //worklist=(x_1,...,x_n-1)\(x_i1,...,x_ik) |
---|
| 600 | //lhelp =(x_i1,...,x_ik) |
---|
| 601 | //buffer=diff(f,x_i) i not in (i1,..,ik); |
---|
| 602 | |
---|
| 603 | worklist=list("@t",string(var(2)))+lhelp+worklist; |
---|
| 604 | for (zz=1;zz<=n+1;zz++) |
---|
| 605 | { |
---|
| 606 | perm=perm+","+string(worklist[zz]); |
---|
| 607 | } |
---|
| 608 | perm=perm[2..size(perm)]; |
---|
| 609 | if (size(buffer)!=0) |
---|
| 610 | { |
---|
| 611 | jacs=buffer[1..size(buffer)]; |
---|
| 612 | jacs=@t+f,jacs; |
---|
| 613 | } |
---|
| 614 | else |
---|
| 615 | { |
---|
| 616 | jacs=@t+f; |
---|
| 617 | } |
---|
| 618 | rbuffer=basering; |
---|
| 619 | //perm=@t,x_n,x_1,..,x_ik,x\(x_i1,..,x_ik) |
---|
| 620 | ri="ring rh=0,("+perm+"),dp;"; |
---|
| 621 | execute(ri); |
---|
| 622 | ideal jacs=imap(rbuffer,jacs); |
---|
| 623 | poly p=imap(rbuffer,p); |
---|
| 624 | matrix m=char_series(jacs); |
---|
| 625 | poly e=1; |
---|
| 626 | for (count=1;count<=nrows(m);count++) |
---|
| 627 | { |
---|
| 628 | e=e*m[count,1]; |
---|
| 629 | } |
---|
| 630 | //search for the leading coefficient of e in |
---|
| 631 | //Q(@t,x_n)[x_@s[@z][1],..,x_@s[@z][size(@s[@z])] |
---|
| 632 | intmat l[n-1][n-1]; |
---|
| 633 | for (zz=1;zz<n;zz++) |
---|
| 634 | { |
---|
| 635 | l[zz,n-zz]=1; |
---|
| 636 | } |
---|
[3fd4df] | 637 | ri="ring rcoef="+"(0,@t,"+parvar+"), |
---|
[e83e84] | 638 | ("+lessvar+"),M(l);"; |
---|
| 639 | execute(ri); |
---|
| 640 | kill l; |
---|
| 641 | poly e=imap(rh,e); |
---|
| 642 | e=leadcoef(e); |
---|
| 643 | setring rh; |
---|
| 644 | e=imap(rcoef,e); |
---|
| 645 | e=subst(e,@t,0); |
---|
| 646 | e=realpoly(e); |
---|
| 647 | p=p*e; |
---|
| 648 | setring r_neu; |
---|
| 649 | p=imap(rh,p); |
---|
| 650 | kill rh,rcoef; |
---|
| 651 | } |
---|
| 652 | setring r; |
---|
| 653 | p=imap(r_neu,p); |
---|
| 654 | /////////////////////////////////////////////////////////////////////////// |
---|
| 655 | ///////////found polynomial p ///////////////////////////////////////////// |
---|
| 656 | /////////////////////////////////////////////////////////////////////////// |
---|
| 657 | //Compute an isolating set for p |
---|
[3fd4df] | 658 | ri="ring iso="+charstr(r)+","+parvar+",lp;"; |
---|
[e83e84] | 659 | execute(ri); |
---|
| 660 | poly p=imap(r,p); |
---|
| 661 | isol=isolset(p); |
---|
| 662 | setring r; |
---|
| 663 | list isol=imap(iso,isol); |
---|
| 664 | tester=1; |
---|
| 665 | for (@z=1;@z<=size(isol);@z++) |
---|
| 666 | { |
---|
| 667 | ri="ring rless="+charstr(r)+",("+lessvar+"),lp;"; |
---|
| 668 | g=subst(f,var(n),isol[@z]); |
---|
| 669 | execute(ri); |
---|
| 670 | poly g=imap(r,g); |
---|
| 671 | tester=tester*decision(g); |
---|
| 672 | setring r; |
---|
| 673 | kill rless; |
---|
| 674 | } |
---|
| 675 | return(tester); |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | |
---|
| 679 | proc isolset(poly f) |
---|
| 680 | "USAGE: isolset(f); f a univariate polynomial over the rational numbers |
---|
| 681 | RETURN: An isolating set of f |
---|
| 682 | NOTE: algorithm can be found in M-F. Roy,R: Pollack, S. Basu page 373 |
---|
| 683 | EXAMPLE: example isolset; shows an example" |
---|
| 684 | { |
---|
| 685 | int i,case; |
---|
| 686 | number m; |
---|
| 687 | list buffer; |
---|
| 688 | //only real roots count |
---|
| 689 | f=realpoly(f); |
---|
| 690 | poly seppart=f; |
---|
| 691 | seppart=simplify(seppart,1); |
---|
| 692 | //int N=binlog(length(seppart)); |
---|
| 693 | //number zweihochN=exp(2,N+1); |
---|
| 694 | number zweihochN=length(f); |
---|
| 695 | //a special case |
---|
| 696 | if (deg(seppart)==0) |
---|
| 697 | { |
---|
| 698 | return(list(number(0))); |
---|
| 699 | } |
---|
| 700 | if (sturm(seppart,-zweihochN,zweihochN)==1) |
---|
| 701 | { |
---|
| 702 | return(list(-zweihochN,zweihochN)); |
---|
| 703 | } |
---|
| 704 | //getting bernstein coeffs |
---|
| 705 | ideal id=isuni(f)-zweihochN; |
---|
| 706 | map jmap=basering,id; |
---|
| 707 | seppart=jmap(seppart); |
---|
| 708 | |
---|
| 709 | id=2*zweihochN*var(1); |
---|
| 710 | jmap=basering,id; |
---|
| 711 | seppart=jmap(seppart); |
---|
| 712 | |
---|
| 713 | matrix c=coeffs(seppart,var(1)); |
---|
| 714 | int s=size(c); |
---|
| 715 | poly recproc; |
---|
| 716 | //Reciprocal polynomial |
---|
| 717 | for (i=1;i<=s;i++) |
---|
| 718 | { |
---|
| 719 | recproc=recproc+c[s+1-i,1]*(var(1)^(i-1)); |
---|
| 720 | } |
---|
| 721 | jmap=basering,var(1)+1; |
---|
| 722 | seppart=jmap(recproc); |
---|
| 723 | list bernsteincoeffs,bern; |
---|
| 724 | c=coeffs(seppart,var(1)); |
---|
| 725 | for (i=1;i<=s;i++) |
---|
| 726 | { |
---|
[966787] | 727 | bern[i]=number(c[s+1-i,1])/binomial(s-1,i-1); |
---|
[e83e84] | 728 | } |
---|
| 729 | bernsteincoeffs=bern,list(-zweihochN,zweihochN); |
---|
| 730 | list POS; |
---|
| 731 | POS[1]=bernsteincoeffs; |
---|
| 732 | list L; |
---|
| 733 | while (size(POS)!=0) |
---|
| 734 | { |
---|
| 735 | if (varsigns(POS[1][1])<2) |
---|
| 736 | { |
---|
| 737 | case=varsigns(POS[1][1]); |
---|
| 738 | } |
---|
| 739 | else |
---|
| 740 | { |
---|
| 741 | case=2; |
---|
| 742 | } |
---|
| 743 | //case Anweisung |
---|
| 744 | buffer=POS[1]; |
---|
| 745 | POS=delete(POS,1); |
---|
| 746 | while(1) |
---|
| 747 | { |
---|
| 748 | if (case==1) |
---|
| 749 | { |
---|
| 750 | L=L+buffer[2]; |
---|
| 751 | break; |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | if (case==2) |
---|
| 755 | { |
---|
| 756 | m=number(buffer[2][1]+buffer[2][2])/2; |
---|
| 757 | bern=BernsteinCoefficients(buffer[1],buffer[2],m); |
---|
| 758 | POS=bern+POS; |
---|
| 759 | if (leadcoef(sign(leadcoef(subst(f,isuni(f),m))))==0) |
---|
| 760 | { |
---|
| 761 | number epsilon=1/10; |
---|
| 762 | while (sturm(f,m-epsilon,m+epsilon)!=1) |
---|
| 763 | { |
---|
| 764 | epsilon=epsilon/10; |
---|
| 765 | } |
---|
| 766 | L=L+list(m-epsilon,m+epsilon); |
---|
| 767 | } |
---|
| 768 | break; |
---|
| 769 | } |
---|
| 770 | break; |
---|
| 771 | } |
---|
| 772 | } |
---|
| 773 | i=1; |
---|
| 774 | while (i<size(L)) |
---|
| 775 | { |
---|
| 776 | if (L[i]==L[i+1]) |
---|
| 777 | { |
---|
| 778 | L=delete(L,i); |
---|
| 779 | } |
---|
| 780 | else |
---|
| 781 | { |
---|
| 782 | i=i+1; |
---|
| 783 | } |
---|
| 784 | } |
---|
| 785 | return(L); |
---|
| 786 | } |
---|
| 787 | |
---|
| 788 | static proc BernsteinCoefficients(list bern,list lr,number m) |
---|
| 789 | "USAGE :BernsteinCoefficients(bern,lr,m); |
---|
| 790 | a list bern=b_0,...,b_p representing a polynomial P of degree <=p |
---|
| 791 | in the Bernstein basis pf lr=(l,r) an a number m in Q |
---|
| 792 | RETURN:a list erg=erg1,erg2 s.th. erg1=erg1[1],erg[2] and erg1[1] are |
---|
[3754ca] | 793 | the bernstein coefficients of P w.r.t. to erg1[2]=(l,m) and erg2[1] |
---|
[e83e84] | 794 | is one for erg2[2]=(m,r) |
---|
| 795 | EXAMPLE: Bernsteincoefficients shows no example |
---|
| 796 | " |
---|
| 797 | { |
---|
| 798 | //Zaehler |
---|
| 799 | int i,j; |
---|
| 800 | list erg,erg1,erg2; |
---|
| 801 | number a=(lr[2]-m)/(lr[2]-lr[1]); |
---|
| 802 | number b=(m-lr[1])/(lr[2]-lr[1]); |
---|
| 803 | int p=size(bern); |
---|
| 804 | list berns,buffer,buffer2; |
---|
| 805 | berns[1]=bern; |
---|
| 806 | for (i=2;i<=p;i++) |
---|
| 807 | { |
---|
| 808 | for (j=1;j<=p+1-i;j++) |
---|
| 809 | { |
---|
| 810 | buffer[j]=a*berns[i-1][j]+b*berns[i-1][j+1]; |
---|
| 811 | } |
---|
| 812 | berns[i]=buffer; |
---|
| 813 | buffer=list(); |
---|
| 814 | } |
---|
| 815 | |
---|
| 816 | for (i=1;i<=p;i++) |
---|
| 817 | { |
---|
| 818 | buffer[i]=berns[i][1]; |
---|
| 819 | buffer2[i]=berns[p+1-i][i]; |
---|
| 820 | } |
---|
| 821 | erg1=buffer,list(lr[1],m); |
---|
| 822 | erg2=buffer2,list(m,lr[2]); |
---|
| 823 | erg=erg1,erg2; |
---|
| 824 | return(erg); |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | static proc binlog(number i) |
---|
| 828 | { |
---|
| 829 | int erg; |
---|
| 830 | if (i<2) {return(0);} |
---|
| 831 | else |
---|
| 832 | { |
---|
| 833 | erg=1+binlog(i/2); |
---|
| 834 | return(erg); |
---|
| 835 | } |
---|
| 836 | } |
---|
| 837 | |
---|
| 838 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 839 | ///////diverse Hilfsprozeduren /////////////////////////////////////////////// |
---|
| 840 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 841 | |
---|
| 842 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 843 | /////wichtig fuers Verstaendnis////////////////////////////////////////////// |
---|
| 844 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 845 | static proc is_real(poly f) |
---|
| 846 | "USAGE: is_real(f);a univariate irreducible polynomial f; |
---|
| 847 | RETURN: 1: if f is real |
---|
| 848 | 0: is f is not real |
---|
| 849 | EXAMPLE: example is_real; shows an example" |
---|
| 850 | |
---|
| 851 | { |
---|
| 852 | int d,anz,i; |
---|
| 853 | def r=basering; |
---|
| 854 | |
---|
| 855 | if (f==1) {return(1);} |
---|
| 856 | if (isuniv(f)==0) |
---|
| 857 | { |
---|
| 858 | for (i=1;i<=nvars(r);i++) |
---|
| 859 | { |
---|
| 860 | d=size(coeffs(f,var(i)))+1; |
---|
| 861 | if ((d mod 2)==1) |
---|
| 862 | { |
---|
| 863 | return(1); |
---|
| 864 | } |
---|
| 865 | } |
---|
| 866 | d=1-decision(f); |
---|
| 867 | return(d); |
---|
| 868 | } |
---|
| 869 | d=deg(f) mod 2; |
---|
| 870 | if (d==1) |
---|
| 871 | { |
---|
| 872 | return(1);//because of fundamental theorem of algebra |
---|
| 873 | } |
---|
| 874 | else |
---|
| 875 | { |
---|
| 876 | f=simplify(f,1);//wlog we can assume that f is monic |
---|
| 877 | number a=leadcoef(sign(leadcoef(subst(f,isuni(f),-length(f))))); |
---|
| 878 | number b=leadcoef(sign(leadcoef(subst(f,isuni(f),length(f))))); |
---|
| 879 | if |
---|
| 880 | (a*b!=1) |
---|
| 881 | //polynomials are contineous so the image is an interval |
---|
| 882 | //referres to analysis |
---|
| 883 | { |
---|
| 884 | return(1); |
---|
| 885 | } |
---|
| 886 | else |
---|
| 887 | { |
---|
| 888 | anz=sturm(f,-length(f),length(f)); |
---|
| 889 | if (anz==0) {return(0);} |
---|
| 890 | else {return(1);} |
---|
| 891 | } |
---|
| 892 | } |
---|
| 893 | } |
---|
| 894 | example |
---|
| 895 | { "EXAMPLE:"; echo = 2; |
---|
| 896 | ring r1 = 0,x,dp; |
---|
| 897 | poly f=x2+1; |
---|
| 898 | is_real(f); |
---|
| 899 | |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | |
---|
| 903 | static proc prepare_max(ideal m) |
---|
| 904 | "USAGE: prepare_max(m); m a maximal ideal in Q(y_1,...,y_m)[x_1,...,x_n] |
---|
| 905 | RETURN: a list erg=(id,j); where id is the real radical of m if j=1 (i.e. m |
---|
| 906 | satisfies the shape lemma in one variable x_i) else id=m and j=0; |
---|
| 907 | EXAMPLE: is_in_shape shows an exmaple; |
---|
| 908 | " |
---|
| 909 | |
---|
| 910 | { |
---|
| 911 | int j,k,i,l,fakul; |
---|
| 912 | def r=basering; |
---|
| 913 | int n=nvars(r); |
---|
| 914 | list erg,varlist,perm; |
---|
| 915 | string wechsler,vari; |
---|
| 916 | //option(redSB); |
---|
| 917 | |
---|
| 918 | for (i=1;i<=n;i++) |
---|
| 919 | { |
---|
| 920 | varlist=varlist+list(var(i)); |
---|
| 921 | } |
---|
| 922 | perm=permutation(varlist); |
---|
| 923 | fakul=size(perm); |
---|
| 924 | for (i=1;i<=fakul;i++) |
---|
| 925 | { |
---|
| 926 | for (j=1;j<=n;j++) |
---|
| 927 | { |
---|
| 928 | vari=vari+","+string(perm[i][j]); |
---|
| 929 | } |
---|
| 930 | vari=vari[2..size(vari)]; |
---|
| 931 | wechsler="ring r_neu=("+charstr(r)+"),("+vari+"),lp;"; |
---|
| 932 | execute(wechsler); |
---|
| 933 | ideal id=imap(r,m); |
---|
| 934 | id=groebner(id); |
---|
| 935 | k=search_first(id,2,2); |
---|
| 936 | setring r; |
---|
| 937 | m=imap(r_neu,id); |
---|
| 938 | m[1]=realpoly(m[1]); |
---|
| 939 | if (m[1]==1) |
---|
| 940 | { |
---|
| 941 | erg[1]=ideal(1); |
---|
| 942 | erg[2]=1; |
---|
| 943 | return(erg); |
---|
| 944 | } |
---|
| 945 | if (k>n) |
---|
| 946 | { |
---|
| 947 | erg[1]=m; |
---|
| 948 | erg[2]=1; |
---|
| 949 | return(erg); |
---|
| 950 | } |
---|
| 951 | else |
---|
| 952 | { |
---|
| 953 | for (l=k;l<=n;l++) |
---|
| 954 | { |
---|
| 955 | if (realpoly(m[l])==1) |
---|
| 956 | { |
---|
| 957 | erg[1]=ideal(1); |
---|
| 958 | erg[2]=1; |
---|
| 959 | return(erg); |
---|
| 960 | } |
---|
| 961 | } |
---|
| 962 | } |
---|
| 963 | vari=""; |
---|
| 964 | kill r_neu; |
---|
| 965 | } |
---|
| 966 | if (size(parstr(r))==0) |
---|
| 967 | { |
---|
| 968 | erg[1]=m; |
---|
| 969 | j=1; |
---|
| 970 | for (i=1;i<=n;i++) |
---|
| 971 | { |
---|
| 972 | j=j*isuniv(m[i]); |
---|
| 973 | } |
---|
| 974 | erg[2]=j; |
---|
| 975 | return(erg); |
---|
| 976 | } |
---|
| 977 | erg[1]=m; |
---|
| 978 | erg[2]=0; |
---|
| 979 | return(erg); |
---|
| 980 | } |
---|
| 981 | |
---|
| 982 | static proc length(poly f) |
---|
| 983 | "USAGE: length(f); poly f; |
---|
| 984 | RETURN: sum of the absolute Value of all coeffients of an irreducible |
---|
| 985 | poly nomial f |
---|
| 986 | EXAMPLE: example length; shows an example" |
---|
| 987 | |
---|
| 988 | { |
---|
| 989 | number erg,buffer; |
---|
| 990 | f=simplify(f,1);//wlog f is monic |
---|
| 991 | int n=size(f); |
---|
| 992 | for (int i=1;i<=n;i=i+1) |
---|
| 993 | { |
---|
| 994 | buffer= leadcoef(f[i]); |
---|
| 995 | erg=erg + absValue(buffer); |
---|
| 996 | } |
---|
| 997 | |
---|
| 998 | return(erg); |
---|
| 999 | } |
---|
| 1000 | example |
---|
| 1001 | { "EXAMPLE:"; echo = 2; |
---|
| 1002 | ring r1 = 0,x,dp; |
---|
| 1003 | poly f=x4-6x3+x2+1; |
---|
| 1004 | norm(f); |
---|
| 1005 | |
---|
| 1006 | ring r2=0,(x,y),dp; |
---|
| 1007 | poly g=x2-y3; |
---|
| 1008 | length(g); |
---|
| 1009 | |
---|
| 1010 | } |
---|
| 1011 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 1012 | //////////////weniger wichtig fuers Verstaendnis////////////////////////////// |
---|
| 1013 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 1014 | static proc isuniv(poly f) |
---|
| 1015 | { |
---|
| 1016 | int erg; |
---|
| 1017 | if (f==0) |
---|
| 1018 | { |
---|
| 1019 | erg=1; |
---|
| 1020 | } |
---|
| 1021 | else |
---|
| 1022 | { |
---|
| 1023 | erg=(isuni(f)!=0); |
---|
| 1024 | } |
---|
| 1025 | return(erg); |
---|
| 1026 | } |
---|
| 1027 | static proc search_first(ideal j,int start, int i) |
---|
| 1028 | "USAGE: searchfirst(j, start, i); |
---|
[3754ca] | 1029 | id a reduced groebner basis w.r.t. lex |
---|
[e83e84] | 1030 | RETURN: if i=1 then turns the number of the first non univariate entry |
---|
| 1031 | with order >1 in its leading term after start |
---|
| 1032 | else the first non univariate of even order |
---|
| 1033 | EXAMPLE: example norm; shows no example" |
---|
| 1034 | { |
---|
| 1035 | int n=size(j); |
---|
| 1036 | int k=start;//counter |
---|
| 1037 | j=j,0; |
---|
| 1038 | if (i==1) |
---|
| 1039 | { |
---|
| 1040 | while |
---|
| 1041 | ((k<=n)&&(ord(j[k])==1)) |
---|
| 1042 | { |
---|
| 1043 | k=k+1; |
---|
| 1044 | } |
---|
| 1045 | } |
---|
| 1046 | else |
---|
| 1047 | { |
---|
| 1048 | while |
---|
| 1049 | ((k<=n)&&(ord(j[k]) mod 2==1)) |
---|
| 1050 | { |
---|
| 1051 | k=k+1; |
---|
| 1052 | } |
---|
| 1053 | |
---|
| 1054 | } |
---|
| 1055 | return(k); |
---|
| 1056 | } |
---|
| 1057 | |
---|
[224420b] | 1058 | static proc subsets(int n) |
---|
| 1059 | "USAGE :subsets(n); n>=0 in Z |
---|
[e83e84] | 1060 | RETURN :l a list of all non-empty subsets of {1,..,n} |
---|
[224420b] | 1061 | EXAMPLE:subsets(n) shows an example; |
---|
[e83e84] | 1062 | " |
---|
| 1063 | { |
---|
| 1064 | list l,buffer; |
---|
| 1065 | int i,j,binzahl; |
---|
| 1066 | if (n<=0) |
---|
| 1067 | { |
---|
| 1068 | return(l); |
---|
| 1069 | } |
---|
[183572] | 1070 | int grenze=2**n-1; |
---|
[e83e84] | 1071 | for (i=1;i<=grenze;i++) |
---|
| 1072 | { |
---|
| 1073 | binzahl=i; |
---|
| 1074 | for (j=1;j<=n;j++) |
---|
| 1075 | { |
---|
| 1076 | if ((binzahl mod 2)==1) |
---|
| 1077 | { |
---|
| 1078 | buffer=buffer+list(j); |
---|
| 1079 | } |
---|
| 1080 | binzahl=binzahl div 2; |
---|
| 1081 | } |
---|
| 1082 | l[i]=buffer; |
---|
| 1083 | buffer=list(); |
---|
| 1084 | } |
---|
| 1085 | return(l); |
---|
| 1086 | } |
---|
| 1087 | example |
---|
| 1088 | { "EXAMPLE:"; echo = 2; |
---|
[224420b] | 1089 | subsets(3); |
---|
| 1090 | subsets(4); |
---|
[e83e84] | 1091 | } |
---|
| 1092 | |
---|
| 1093 | proc permutation(list L) |
---|
| 1094 | " USAGE: permutation(L); L a list |
---|
| 1095 | OUTPUT: a list of all permutation lists of L |
---|
| 1096 | EXAMPLE: permutation(L) gives an example" |
---|
| 1097 | { |
---|
| 1098 | list erg,buffer,permi,einfueger; |
---|
| 1099 | int i,j,l; |
---|
| 1100 | int n=size(L); |
---|
| 1101 | if (n==0) |
---|
| 1102 | { |
---|
| 1103 | return(erg); |
---|
| 1104 | } |
---|
| 1105 | if (n==1) |
---|
| 1106 | { |
---|
| 1107 | erg=list(L); |
---|
| 1108 | return(erg); |
---|
| 1109 | } |
---|
| 1110 | for (i=1;i<=n;i++) |
---|
| 1111 | { |
---|
| 1112 | buffer=delete(L,i); |
---|
| 1113 | einfueger=permutation(buffer); |
---|
| 1114 | l=size(einfueger); |
---|
| 1115 | for (j=1;j<=l;j++) |
---|
| 1116 | { |
---|
| 1117 | permi=list(L[i])+einfueger[j]; |
---|
| 1118 | erg=insert(erg,permi); |
---|
| 1119 | } |
---|
| 1120 | } |
---|
| 1121 | return(erg); |
---|
| 1122 | } |
---|
| 1123 | example |
---|
| 1124 | { "EXAMPLE:"; echo = 2; |
---|
[c60d60] | 1125 | list L1="Just","an","example"; |
---|
| 1126 | permutation(L1); |
---|
[e83e84] | 1127 | list L2=1,2,3,4; |
---|
[c60d60] | 1128 | permutation(L2); |
---|
[e83e84] | 1129 | } |
---|
| 1130 | static proc simplify_gen(poly f) |
---|
| 1131 | "USAGE : simplify_gen(f); f a polymimial in Q(y_1,..,y_m)[x_1,..,x_n] |
---|
| 1132 | RETURN : a polynomial g such that g is the square-free part of f and |
---|
| 1133 | every real univariate factor of f is cancelled out |
---|
| 1134 | EXAMPLE:simplify_gen gives no example" |
---|
| 1135 | { |
---|
| 1136 | int i,l; |
---|
| 1137 | ideal factor; |
---|
| 1138 | poly g=1; |
---|
| 1139 | factor=factorize(f,2)[1]; |
---|
| 1140 | l=size(factor); |
---|
| 1141 | for (i=1;i<=l;i++) |
---|
| 1142 | { |
---|
| 1143 | if (isuniv(factor[i])) |
---|
| 1144 | { |
---|
| 1145 | g=g*realpoly(factor[i]); |
---|
| 1146 | } |
---|
| 1147 | else |
---|
| 1148 | { |
---|
| 1149 | g=g*factor[i]; |
---|
| 1150 | } |
---|
| 1151 | } |
---|
| 1152 | return(g); |
---|
| 1153 | } |
---|
| 1154 | static proc contnonloc(ideal id,string pari, string vari) |
---|
| 1155 | "INPUT : a radical ideal id in in F[pari+vari] which is radical in |
---|
| 1156 | F(pari)[vari), pari and vari strings of variables |
---|
| 1157 | OUTPUT : the contraction ideal of id, i.e. idF(pari)[vari]\cap F[pari+vari] |
---|
| 1158 | EXAMPLE: contnonloc shows an example |
---|
| 1159 | " |
---|
| 1160 | { |
---|
| 1161 | list pr; |
---|
| 1162 | list contractpr; |
---|
| 1163 | int i,l,tester; |
---|
| 1164 | ideal primcomp; |
---|
| 1165 | def r=basering; |
---|
| 1166 | string neu="ring r_neu=("+charstr(r)+pari+"),("+vari+"),dp;"; |
---|
| 1167 | execute(neu); |
---|
| 1168 | def r1=basering; |
---|
| 1169 | ideal buffer; |
---|
| 1170 | setring r; |
---|
| 1171 | pr=primdecGTZ(id); |
---|
| 1172 | l=size(pr); |
---|
| 1173 | contractpr[1]=ideal(1); |
---|
| 1174 | for (i=1;i<=l;i++) |
---|
| 1175 | { |
---|
| 1176 | primcomp=pr[i][2]; |
---|
| 1177 | setring r1; |
---|
| 1178 | buffer=imap(r,primcomp); |
---|
| 1179 | buffer=groebner(buffer); |
---|
| 1180 | if (buffer==1) |
---|
| 1181 | { |
---|
| 1182 | tester=0; |
---|
| 1183 | } |
---|
| 1184 | else |
---|
| 1185 | { |
---|
| 1186 | tester=1; |
---|
| 1187 | } |
---|
| 1188 | setring r; |
---|
| 1189 | |
---|
| 1190 | //id only consits of non units in F(pari) |
---|
| 1191 | if (tester==1) |
---|
| 1192 | { |
---|
| 1193 | contractpr=insert(contractpr,primcomp); |
---|
| 1194 | } |
---|
| 1195 | } |
---|
| 1196 | l=size(contractpr); |
---|
| 1197 | id=intersect(contractpr[1..l]); |
---|
| 1198 | return(id); |
---|
| 1199 | } |
---|
| 1200 | example |
---|
| 1201 | { "EXAMPLE:"; echo = 2; |
---|
| 1202 | ring r = 0,(a,b,c),lp; |
---|
| 1203 | ideal i=b3+c5,ab2+c3; |
---|
| 1204 | ideal j=contnonloc(i,",b","a,c"); |
---|
| 1205 | j; |
---|
| 1206 | } |
---|