[71f6706] | 1 | // $Id: standard.lib,v 1.29 1999-04-22 08:35:12 obachman Exp $ |
---|
[6149f4f] | 2 | ////////////////////////////////////////////////////////////////////////////// |
---|
[2f2af5] | 3 | |
---|
[71f6706] | 4 | version="$Id: standard.lib,v 1.29 1999-04-22 08:35:12 obachman Exp $"; |
---|
[5480da] | 5 | info=" |
---|
[82716e] | 6 | LIBRARY: standard.lib PROCEDURES WHICH ARE ALWAYS LOADED AT START-UP |
---|
[2f2af5] | 7 | |
---|
| 8 | stdfglm(ideal[,ord]) standard basis of the ideal via fglm [and ordering ord] |
---|
[78388a] | 9 | stdhilb(ideal) standard basis of the ideal using the Hilbert function |
---|
[3939bc] | 10 | groebner(ideal/module) standard basis of ideal or module using a |
---|
| 11 | heuristically choosen method |
---|
[ef25c3] | 12 | quot(any,any[,n]) a general quotient procedure calling several algorithms |
---|
[aa6e78] | 13 | allows module/module, ideal/ideal, module/ideal and a |
---|
| 14 | pre-definition of the algorithm by the parameter n |
---|
| 15 | quotient1(m1,m2) computes quotients by every vector of m2 and intersects them |
---|
| 16 | quotient2(m1,m2) a heuristic variant: the quotient is just defined by a |
---|
| 17 | (not really) general element of m2 which has to be proved |
---|
| 18 | quotient3(m1,m2) the homogeneous variant of quotient5(m1,m2) |
---|
| 19 | quotient4(m1,m2) the same as quotient5(m1,m2) using the modulo-command |
---|
| 20 | instead of the quotient-command from the kernel |
---|
| 21 | quotient5(m1,m2) computes with a real general element of m2 by adjoining |
---|
| 22 | a new variable |
---|
[2dbaece] | 23 | sprintf(fmt,...) returns fomatted string |
---|
| 24 | fprintf(link,fmt,..) writes formatted string to link |
---|
| 25 | printf(fmt,...) displays formatted string |
---|
[5480da] | 26 | "; |
---|
| 27 | |
---|
[6149f4f] | 28 | ////////////////////////////////////////////////////////////////////////////// |
---|
[2f2af5] | 29 | |
---|
| 30 | proc stdfglm (ideal i, list #) |
---|
[d2b2a7] | 31 | "USAGE: stdfglm(i[,s]); i ideal, s string (any allowed ordstr of a ring) |
---|
[0fbdd1] | 32 | RETURN: stdfglm(i): standard basis of i in the basering, calculated via fglm |
---|
[d2b2a7] | 33 | from ordering \"dp\" to the ordering of the basering. |
---|
[0fbdd1] | 34 | stdfglm(i,s): standard basis of i in the basering, calculated via |
---|
| 35 | fglm from ordering s to the ordering of the basering. |
---|
[5011fd] | 36 | EXAMPLE: example stdfglm; shows an example" |
---|
[2f2af5] | 37 | { |
---|
| 38 | string os; |
---|
| 39 | def dr= basering; |
---|
[f2ae935] | 40 | if( (size(#)==0) or (typeof(#[1]) != "string") ) |
---|
[2f2af5] | 41 | { |
---|
| 42 | os = "dp(" + string( nvars(dr) ) + ")"; |
---|
[f2ae935] | 43 | if ( (find( ordstr(dr), os ) != 0) and (find( ordstr(dr), "a") == 0) ) |
---|
[2f2af5] | 44 | { |
---|
| 45 | os= "Dp"; |
---|
[f2ae935] | 46 | } |
---|
| 47 | else |
---|
[2f2af5] | 48 | { |
---|
| 49 | os= "dp"; |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | else { os = #[1]; } |
---|
[283282f] | 53 | execute "ring sr=("+charstr(dr)+"),("+varstr(dr)+"),"+os+";"; |
---|
[2f2af5] | 54 | ideal i= fetch(dr,i); |
---|
| 55 | intvec opt= option(get); |
---|
| 56 | option(redSB); |
---|
| 57 | i=std(i); |
---|
| 58 | option(set,opt); |
---|
| 59 | setring dr; |
---|
| 60 | return (fglm(sr,i)); |
---|
| 61 | } |
---|
| 62 | example |
---|
| 63 | { "EXAMPLE:"; echo = 2; |
---|
[f2ae935] | 64 | ring r = 0,(x,y,z),lp; |
---|
[0fbdd1] | 65 | ideal i = y3+x2, x2y+x2, x3-x2, z4-x2-y; |
---|
| 66 | ideal i1= stdfglm(i); //uses fglm from "dp" to "lp" |
---|
[f2ae935] | 67 | i1; |
---|
[0fbdd1] | 68 | ideal i2= stdfglm(i,"Dp"); //uses fglm from "Dp" to "lp" |
---|
| 69 | i2; |
---|
[2f2af5] | 70 | } |
---|
[6149f4f] | 71 | ///////////////////////////////////////////////////////////////////////////// |
---|
[bb0968] | 72 | |
---|
[78388a] | 73 | proc stdhilb(ideal i,list #) |
---|
| 74 | "USAGE: stdhilb(i); i ideal |
---|
| 75 | stdhilb(i,v); i homogeneous ideal, v intvec (the Hilbert function) |
---|
| 76 | RETURN: stdhilb(i): a standard basis of i (computing v internally) |
---|
| 77 | stdhilb(i,v): standard basis of i, using the given Hilbert function |
---|
| 78 | EXAMPLE: example stdhilb; shows an example" |
---|
[bb0968] | 79 | { |
---|
| 80 | def R=basering; |
---|
| 81 | |
---|
| 82 | if((homog(i)==1)||(ordstr(basering)[1]=="d")) |
---|
| 83 | { |
---|
| 84 | if ((size(#)!=0)&&(homog(i)==1)) |
---|
| 85 | { |
---|
| 86 | return(std(i,#[1])); |
---|
| 87 | } |
---|
| 88 | return(std(i)); |
---|
| 89 | } |
---|
[f2ae935] | 90 | |
---|
[bb0968] | 91 | execute "ring S = ("+charstr(R)+"),("+varstr(R)+",@t),dp;"; |
---|
| 92 | ideal i=homog(imap(R,i),@t); |
---|
| 93 | intvec v=hilb(std(i),1); |
---|
| 94 | execute "ring T = ("+charstr(R)+"),("+varstr(R)+",@t),("+ordstr(R)+");"; |
---|
| 95 | ideal i=fetch(S,i); |
---|
| 96 | ideal a=std(i,v); |
---|
| 97 | setring R; |
---|
| 98 | map phi=T,maxideal(1),1; |
---|
| 99 | ideal a=phi(a); |
---|
| 100 | |
---|
| 101 | int k,j; |
---|
| 102 | poly m; |
---|
| 103 | int c=size(i); |
---|
| 104 | |
---|
| 105 | for(j=1;j<c;j++) |
---|
| 106 | { |
---|
| 107 | if(deg(a[j])==0) |
---|
| 108 | { |
---|
| 109 | a=ideal(1); |
---|
[f2ae935] | 110 | attrib(a,"isSB",1); |
---|
[bb0968] | 111 | return(a); |
---|
| 112 | } |
---|
| 113 | if(deg(a[j])>0) |
---|
| 114 | { |
---|
| 115 | m=lead(a[j]); |
---|
| 116 | for(k=j+1;k<=c;k++) |
---|
| 117 | { |
---|
| 118 | if(size(lead(a[k])/m)>0) |
---|
| 119 | { |
---|
| 120 | a[k]=0; |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | } |
---|
[f2ae935] | 125 | a=simplify(a,2); |
---|
| 126 | attrib(a,"isSB",1); |
---|
| 127 | return(a); |
---|
[bb0968] | 128 | } |
---|
| 129 | example |
---|
| 130 | { "EXAMPLE:"; echo = 2; |
---|
[f2ae935] | 131 | ring r = 0,(x,y,z),lp; |
---|
[0fbdd1] | 132 | ideal i = y3+x2, x2y+x2, x3-x2, z4-x2-y; |
---|
[78388a] | 133 | ideal i1= stdhilb(i); i1; |
---|
[0fbdd1] | 134 | // is in this case equivalent to: |
---|
| 135 | intvec v=1,0,0,-3,0,1,0,3,-1,-1; |
---|
[78388a] | 136 | ideal i2=stdhilb(i,v); |
---|
[bb0968] | 137 | } |
---|
[6149f4f] | 138 | ////////////////////////////////////////////////////////////////////////// |
---|
[bb0968] | 139 | |
---|
[45f7bf] | 140 | proc groebner(def i, list #) |
---|
[6149f4f] | 141 | "USAGE: groebner(i[, wait]) i -- ideal/module; wait -- int |
---|
[3939bc] | 142 | RETURNS: Standard basis of ideal or module which is computed using a |
---|
| 143 | heuristically choosen method: |
---|
[6149f4f] | 144 | If the ordering of the current ring is a local ordering, or |
---|
[45f7bf] | 145 | if it is a non-block ordering and the current ring has no |
---|
[3939bc] | 146 | parameters, then std(i) is returned. |
---|
[45f7bf] | 147 | Otherwise, i is mapped into a ring with no parameters and |
---|
| 148 | ordering dp, where its Hilbert series is computed. This is |
---|
| 149 | followed by a Hilbert-series based std computation in the |
---|
| 150 | original ring. |
---|
[6149f4f] | 151 | NOTE: If a 2nd argument 'wait' is given, then the computation proceeds |
---|
[3939bc] | 152 | at most 'wait' seconds. That is, if no result could be computed in |
---|
| 153 | 'wait' seconds, then the computation is interrupted, 0 is returned, |
---|
| 154 | a warning message is displayed, and the global variable |
---|
| 155 | 'groebner_error' is defined. |
---|
[45f7bf] | 156 | EXAMPLE: example groebner; shows an example" |
---|
| 157 | { |
---|
| 158 | def P=basering; |
---|
[6149f4f] | 159 | |
---|
| 160 | // we have two arguments -- try to use MPfork links |
---|
[45f7bf] | 161 | if (size(#) > 0) |
---|
| 162 | { |
---|
| 163 | if (system("with", "MP")) |
---|
| 164 | { |
---|
| 165 | if (typeof(#[1]) == "int") |
---|
| 166 | { |
---|
[e665360] | 167 | int wait = #[1]; |
---|
| 168 | int j = 10; |
---|
[3939bc] | 169 | |
---|
[45f7bf] | 170 | string bs = nameof(basering); |
---|
| 171 | link l_fork = "MPtcp:fork"; |
---|
| 172 | open(l_fork); |
---|
| 173 | write(l_fork, quote(system("pid"))); |
---|
[6149f4f] | 174 | int pid = read(l_fork); |
---|
[45f7bf] | 175 | write(l_fork, quote(groebner(eval(i)))); |
---|
[3939bc] | 176 | |
---|
[e665360] | 177 | // sleep in small intervalls for appr. one second |
---|
| 178 | if (wait > 0) |
---|
[45f7bf] | 179 | { |
---|
[e665360] | 180 | while(j < 1000000) |
---|
| 181 | { |
---|
| 182 | if (status(l_fork, "read", "ready", j)) {break;} |
---|
| 183 | j = j + j; |
---|
| 184 | } |
---|
[45f7bf] | 185 | } |
---|
[3939bc] | 186 | |
---|
[e665360] | 187 | // sleep in intervalls of one second from now on |
---|
| 188 | j = 1; |
---|
| 189 | while (j < wait) |
---|
| 190 | { |
---|
| 191 | if (status(l_fork, "read", "ready", 1000000)) {break;} |
---|
| 192 | j = j + 1; |
---|
| 193 | } |
---|
[3939bc] | 194 | |
---|
[45f7bf] | 195 | if (status(l_fork, "read", "ready")) |
---|
| 196 | { |
---|
| 197 | def result = read(l_fork); |
---|
| 198 | if (bs != nameof(basering)) |
---|
| 199 | { |
---|
| 200 | def PP = basering; |
---|
| 201 | setring P; |
---|
| 202 | def result = imap(PP, result); |
---|
| 203 | kill PP; |
---|
| 204 | } |
---|
[6149f4f] | 205 | if (defined(groebner_error)) |
---|
| 206 | { |
---|
| 207 | kill(groebner_error); |
---|
| 208 | } |
---|
[45f7bf] | 209 | kill (l_fork); |
---|
| 210 | } |
---|
| 211 | else |
---|
| 212 | { |
---|
| 213 | ideal result; |
---|
| 214 | if (! defined(groebner_error)) |
---|
| 215 | { |
---|
[6149f4f] | 216 | int groebner_error = 1; |
---|
[45f7bf] | 217 | export groebner_error; |
---|
| 218 | } |
---|
| 219 | "// ** groebner did not finish"; |
---|
| 220 | j = system("sh", "kill " + string(pid)); |
---|
| 221 | } |
---|
| 222 | return (result); |
---|
| 223 | } |
---|
| 224 | else |
---|
| 225 | { |
---|
| 226 | "// ** groebner needs int as 2nd arg"; |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | else |
---|
| 230 | { |
---|
[6fa72f7] | 231 | "// ** groebner with two args is not supported in this configuration"; |
---|
[45f7bf] | 232 | } |
---|
| 233 | } |
---|
| 234 | |
---|
[6149f4f] | 235 | // we are still here -- do the actual computation |
---|
| 236 | string ordstr_P = ordstr(P); |
---|
| 237 | if (find(ordstr_P,"s") > 0) |
---|
| 238 | { |
---|
| 239 | //spaeter den lokalen fall ueber lp oder aehnlich behandeln |
---|
| 240 | return(std(i)); |
---|
| 241 | } |
---|
[3939bc] | 242 | |
---|
[6149f4f] | 243 | int IsSimple_P; |
---|
| 244 | if (system("nblocks") <= 2) |
---|
| 245 | { |
---|
| 246 | if (find(ordstr_P, "M") <= 0) |
---|
| 247 | { |
---|
| 248 | IsSimple_P = 1; |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | int npars_P = npars(P); |
---|
[45f7bf] | 252 | |
---|
[6149f4f] | 253 | // return std if no parameters and (dp or wp) |
---|
[6fa72f7] | 254 | if ((npars_P <= 1) && IsSimple_P) |
---|
[6149f4f] | 255 | { |
---|
| 256 | if (find(ordstr_P, "d") > 0) |
---|
| 257 | { |
---|
| 258 | return (std(i)); |
---|
| 259 | } |
---|
| 260 | if (find(ordstr_P,"w") > 0) |
---|
| 261 | { |
---|
| 262 | return (std(i)); |
---|
| 263 | } |
---|
| 264 | } |
---|
[45f7bf] | 265 | |
---|
[6149f4f] | 266 | // reset options |
---|
| 267 | intvec opt=option(get); |
---|
| 268 | int p_opt; |
---|
| 269 | string s_opt = option(); |
---|
| 270 | option(none); |
---|
| 271 | // turn on option(prot) and/or option(mem), if previously set |
---|
| 272 | if (find(s_opt, "prot")) |
---|
| 273 | { |
---|
| 274 | option(prot); |
---|
| 275 | p_opt = 1; |
---|
| 276 | } |
---|
| 277 | if (find(s_opt, "mem")) |
---|
| 278 | { |
---|
| 279 | option(mem); |
---|
| 280 | } |
---|
[3939bc] | 281 | |
---|
[6149f4f] | 282 | // construct ring in which first std computation is done |
---|
| 283 | string varstr_P = varstr(P); |
---|
| 284 | string parstr_P = parstr(P); |
---|
[6fa72f7] | 285 | int is_homog = (homog(i) && (npars_P <= 1)); |
---|
| 286 | int add_vars = 0; |
---|
| 287 | string ri = "ring Phelp ="; |
---|
[bcd557] | 288 | |
---|
[6fa72f7] | 289 | // more than one parameters are converted to ring variables |
---|
| 290 | if (npars_P > 1) |
---|
[6149f4f] | 291 | { |
---|
[6fa72f7] | 292 | ri = ri + string(char(P)) + ",(" + varstr_P + "," + parstr_P; |
---|
| 293 | add_vars = npars_P; |
---|
[6149f4f] | 294 | } |
---|
[6fa72f7] | 295 | else |
---|
| 296 | { |
---|
| 297 | ri = ri + "(" + charstr(P) + "),(" + varstr_P; |
---|
| 298 | } |
---|
| 299 | |
---|
[6149f4f] | 300 | // a homogenizing variable is added, if necessary |
---|
| 301 | if (! is_homog) |
---|
| 302 | { |
---|
| 303 | ri = ri + ",@t"; |
---|
[6fa72f7] | 304 | add_vars = add_vars + 1; |
---|
[6149f4f] | 305 | } |
---|
| 306 | // ordering is set to (dp, C) |
---|
| 307 | ri = ri + "),(dp,C);"; |
---|
[45f7bf] | 308 | |
---|
[6149f4f] | 309 | // change the ring |
---|
| 310 | execute(ri); |
---|
[3939bc] | 311 | |
---|
[6149f4f] | 312 | // get ideal from previous ring |
---|
| 313 | if (is_homog) |
---|
| 314 | { |
---|
| 315 | ideal qh = imap(P, i); |
---|
| 316 | } |
---|
| 317 | else |
---|
| 318 | { |
---|
| 319 | // and homogenize |
---|
| 320 | ideal qh=homog(imap(P,i),@t); |
---|
| 321 | } |
---|
[3939bc] | 322 | |
---|
[6149f4f] | 323 | // compute std and hilbert series |
---|
| 324 | if (p_opt) |
---|
| 325 | { |
---|
| 326 | "std in " + ri[13, size(ri) - 13]; |
---|
| 327 | } |
---|
| 328 | ideal qh1=std(qh); |
---|
| 329 | intvec hi=hilb(qh1,1); |
---|
[45f7bf] | 330 | |
---|
[6fa72f7] | 331 | if (add_vars == 0) |
---|
[6149f4f] | 332 | { |
---|
| 333 | // no additional variables were introduced |
---|
| 334 | setring P; // can immediately change to original ring |
---|
| 335 | // simply compute std with hilbert series in original ring |
---|
| 336 | if (p_opt) |
---|
| 337 | { |
---|
| 338 | "std with hilb in basering"; |
---|
| 339 | } |
---|
[12310e] | 340 | i = std(i, hi); |
---|
[6149f4f] | 341 | } |
---|
| 342 | else |
---|
| 343 | { |
---|
| 344 | // additional variables were introduced |
---|
| 345 | // need another intermediate ring |
---|
[bcd557] | 346 | ri = "ring Phelp1 = (" + charstr(Phelp) |
---|
[6fa72f7] | 347 | + "),(" + varstr(Phelp) + "),(" + ordstr_P; |
---|
[3939bc] | 348 | |
---|
[6fa72f7] | 349 | // for lp wit at most one parameter, we do not need a block ordering |
---|
| 350 | if ( ! (IsSimple_P && (add_vars <2) && find(ordstr_P, "l"))) |
---|
[6149f4f] | 351 | { |
---|
| 352 | // need block ordering |
---|
[6fa72f7] | 353 | ri = ri + ", dp(" + string(add_vars) + ")"; |
---|
[6149f4f] | 354 | } |
---|
| 355 | ri = ri + ");"; |
---|
[3939bc] | 356 | |
---|
[6149f4f] | 357 | // change to intermediate ring |
---|
| 358 | execute(ri); |
---|
| 359 | ideal qh = imap(Phelp, qh); |
---|
| 360 | kill Phelp; |
---|
| 361 | if (p_opt) |
---|
| 362 | { |
---|
| 363 | "std with hilb in " + ri[14,size(ri)-14]; |
---|
| 364 | } |
---|
| 365 | // compute std with Hilbert series |
---|
| 366 | qh = std(qh, hi); |
---|
| 367 | // subst 1 for homogenizing var |
---|
| 368 | if (!is_homog) |
---|
| 369 | { |
---|
| 370 | qh = subst(qh, @t, 1); |
---|
| 371 | } |
---|
[3939bc] | 372 | |
---|
[6149f4f] | 373 | // go back to original ring |
---|
| 374 | setring P; |
---|
| 375 | // get ideal, delete zeros and clean SB |
---|
| 376 | i = imap(Phelp1,qh); |
---|
| 377 | i = simplify(i, 34); |
---|
| 378 | kill Phelp1; |
---|
| 379 | } |
---|
[45f7bf] | 380 | |
---|
[6149f4f] | 381 | // clean-up time |
---|
| 382 | option(set, opt); |
---|
| 383 | if (find(s_opt, "redSB") > 0) |
---|
| 384 | { |
---|
| 385 | i=interred(i); |
---|
| 386 | } |
---|
| 387 | attrib(i, "isSB", 1); |
---|
| 388 | return (i); |
---|
[45f7bf] | 389 | } |
---|
| 390 | example |
---|
| 391 | { |
---|
| 392 | "EXAMPLE: "; echo = 2; |
---|
| 393 | ring r = 0, (a,b,c,d), lp; |
---|
[3939bc] | 394 | option(prot); |
---|
[45f7bf] | 395 | ideal i = a+b+c+d, ab+ad+bc+cd, abc+abd+acd+bcd, abcd-1; // cyclic 4 |
---|
| 396 | groebner(i); |
---|
| 397 | ring rp = (0, a, b), (c,d), lp; |
---|
| 398 | ideal i = imap(r, i); |
---|
| 399 | ideal j = groebner(i); |
---|
| 400 | option(noprot); |
---|
| 401 | j; simplify(j, 1); std(i); |
---|
[6149f4f] | 402 | if (system("with", "MP")) {groebner(i, 0);} |
---|
| 403 | defined(groebner_error); |
---|
[45f7bf] | 404 | } |
---|
| 405 | |
---|
[6149f4f] | 406 | |
---|
| 407 | ////////////////////////////////////////////////////////////////////////// |
---|
[3939bc] | 408 | proc res(list #) |
---|
[6149f4f] | 409 | { |
---|
| 410 | def P=basering; |
---|
| 411 | def m=#[1]; //the ideal or module |
---|
[3939bc] | 412 | |
---|
[6149f4f] | 413 | int i=#[2]; //the length of the resolution |
---|
| 414 | //if size(#)>2 a minimal resolution is computed |
---|
| 415 | |
---|
| 416 | //LaScala for the homogeneous case |
---|
| 417 | if(homog(m)==1) |
---|
| 418 | { |
---|
[b5b60f] | 419 | resolution re; |
---|
| 420 | if ((i==0) or (i>=nvars(basering))) |
---|
[6149f4f] | 421 | { |
---|
[b5b60f] | 422 | re=lres(m,i); |
---|
| 423 | if(size(#)>2) |
---|
| 424 | { |
---|
| 425 | re=minres(re); |
---|
| 426 | } |
---|
| 427 | } |
---|
| 428 | else |
---|
| 429 | { |
---|
| 430 | if(size(#)>2) |
---|
| 431 | { |
---|
| 432 | re=mres(m,i); |
---|
| 433 | } |
---|
| 434 | else |
---|
| 435 | { |
---|
| 436 | re=sres(std(m),i); |
---|
| 437 | } |
---|
[6149f4f] | 438 | } |
---|
| 439 | return(re); |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | //mres for the global non homogeneous case |
---|
| 443 | if(find(ordstr(P),"s")==0) |
---|
| 444 | { |
---|
| 445 | string ri= "ring Phelp =" |
---|
| 446 | +string(char(P))+",("+varstr_P+"),(dp,C);"; |
---|
| 447 | execute(ri); |
---|
| 448 | def m=imap(P,m); |
---|
| 449 | list re=mres(m,i); |
---|
| 450 | setring P; |
---|
[64c6d1] | 451 | resolution result=imap(Phelp,re); |
---|
[3939bc] | 452 | return(result); |
---|
[6149f4f] | 453 | } |
---|
| 454 | |
---|
| 455 | //sres for the local case and not minimal resolution |
---|
| 456 | if(size(#)<=2) |
---|
| 457 | { |
---|
| 458 | string ri= "ring Phelp =" |
---|
| 459 | +string(char(P))+",("+varstr_P+"),(ls,c);"; |
---|
| 460 | execute(ri); |
---|
| 461 | def m=imap(P,m); |
---|
| 462 | m=std(m); |
---|
| 463 | list re=sres(m,i); |
---|
| 464 | setring P; |
---|
[64c6d1] | 465 | resolution result=imap(Phelp,re); |
---|
[6149f4f] | 466 | return(result); |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | //mres for the local case and minimal resolution |
---|
| 470 | string ri= "ring Phelp =" |
---|
| 471 | +string(char(P))+",("+varstr_P+"),(ls,C);"; |
---|
| 472 | execute(ri); |
---|
| 473 | def m=imap(P,m); |
---|
| 474 | list re=mres(m,i); |
---|
| 475 | setring P; |
---|
[64c6d1] | 476 | resolution result=imap(Phelp,re); |
---|
[3939bc] | 477 | return(result); |
---|
[6149f4f] | 478 | } |
---|
| 479 | |
---|
[ef25c3] | 480 | proc quot (m1,m2,list #) |
---|
| 481 | "USAGE: quot(m1, m2[, n]); m1, m2 two submodules of k^s, |
---|
[aa6e78] | 482 | n (optional) integer (1<= n <=5) |
---|
| 483 | RETURN: the quotient of m1 and m2 |
---|
[300a34] | 484 | EXAMPLE: example quot; shows an example" |
---|
[aa6e78] | 485 | { |
---|
| 486 | if (((typeof(m1)!="ideal") and (typeof(m1)!="module")) |
---|
| 487 | or ((typeof(m2)!="ideal") and (typeof(m2)!="module"))) |
---|
| 488 | { |
---|
[ef25c3] | 489 | "USAGE: quot(m1, m2[, n]); m1, m2 two submodules of k^s,"; |
---|
[aa6e78] | 490 | " n (optional) integer (1<= n <=5)"; |
---|
| 491 | "RETURN: the quotient of m1 and m2"; |
---|
| 492 | "EXAMPLE: example quot; shows an example"; |
---|
| 493 | return(); |
---|
| 494 | } |
---|
| 495 | if (typeof(m1)!=typeof(m2)) |
---|
| 496 | { |
---|
[ef25c3] | 497 | return(quotient(m1,m2)); |
---|
[aa6e78] | 498 | } |
---|
[f22a08] | 499 | if (size(#)>0) |
---|
[aa6e78] | 500 | { |
---|
[f22a08] | 501 | if (typeof(#[1])=="int" ) |
---|
[aa6e78] | 502 | { |
---|
[f7bdb8] | 503 | return(quot1(m1,m2,#[1])); |
---|
[aa6e78] | 504 | } |
---|
| 505 | } |
---|
| 506 | else |
---|
| 507 | { |
---|
[f7bdb8] | 508 | return(quot1(m1,m2,2)); |
---|
[aa6e78] | 509 | } |
---|
| 510 | } |
---|
| 511 | example |
---|
| 512 | { "EXAMPLE:"; echo = 2; |
---|
| 513 | ring r=181,(x,y,z),(c,ls); |
---|
| 514 | ideal id1=maxideal(4); |
---|
| 515 | ideal id2=x2+xyz,y2-z3y,z3+y5xz; |
---|
| 516 | option(prot); |
---|
[ef25c3] | 517 | ideal id6=quotient(id1,id2); |
---|
[aa6e78] | 518 | id6; |
---|
[ef25c3] | 519 | ideal id7=quot(id1,id2,1); |
---|
[aa6e78] | 520 | id7; |
---|
[ef25c3] | 521 | ideal id8=quot(id1,id2,2); |
---|
[aa6e78] | 522 | id8; |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | static proc quot1 (module m1, module m2,int n) |
---|
[300a34] | 526 | "USAGE: quot1(m1, m2, n); m1, m2 two submodules of k^s, |
---|
[aa6e78] | 527 | n integer (1<= n <=5) |
---|
| 528 | RETURN: the quotient of m1 and m2 |
---|
[ef25c3] | 529 | EXAMPLE: example quot1; shows an example" |
---|
[aa6e78] | 530 | { |
---|
| 531 | if (n==1) |
---|
| 532 | { |
---|
| 533 | return(quotient1(m1,m2)); |
---|
| 534 | } |
---|
[300a34] | 535 | else |
---|
| 536 | { |
---|
[aa6e78] | 537 | if (n==2) |
---|
| 538 | { |
---|
| 539 | return(quotient2(m1,m2)); |
---|
| 540 | } |
---|
[300a34] | 541 | else |
---|
| 542 | { |
---|
[aa6e78] | 543 | if (n==3) |
---|
| 544 | { |
---|
| 545 | return(quotient3(m1,m2)); |
---|
| 546 | } |
---|
[300a34] | 547 | else |
---|
| 548 | { |
---|
[aa6e78] | 549 | if (n==4) |
---|
| 550 | { |
---|
| 551 | return(quotient4(m1,m2)); |
---|
| 552 | } |
---|
[300a34] | 553 | else |
---|
| 554 | { |
---|
[aa6e78] | 555 | if (n==5) |
---|
| 556 | { |
---|
| 557 | return(quotient5(m1,m2)); |
---|
| 558 | } |
---|
| 559 | else |
---|
| 560 | { |
---|
| 561 | return(quotient(m1,m2)); |
---|
| 562 | } |
---|
| 563 | } |
---|
| 564 | } |
---|
| 565 | } |
---|
[300a34] | 566 | } |
---|
[aa6e78] | 567 | } |
---|
| 568 | example |
---|
| 569 | { "EXAMPLE:"; echo = 2; |
---|
| 570 | ring r=181,(x,y,z),(c,ls); |
---|
| 571 | ideal id1=maxideal(4); |
---|
| 572 | ideal id2=x2+xyz,y2-z3y,z3+y5xz; |
---|
| 573 | option(prot); |
---|
[ef25c3] | 574 | ideal id6=quotient(id1,id2); |
---|
[aa6e78] | 575 | id6; |
---|
| 576 | ideal id7=quot1(id1,id2,1); |
---|
| 577 | id7; |
---|
| 578 | ideal id8=quot1(id1,id2,2); |
---|
| 579 | id8; |
---|
| 580 | } |
---|
| 581 | |
---|
[300a34] | 582 | static proc quotient0(module a,module b) |
---|
[aa6e78] | 583 | { |
---|
| 584 | module mm=b+a; |
---|
[ef25c3] | 585 | resolution rs=lres(mm,0); |
---|
[aa6e78] | 586 | list I=list(rs); |
---|
| 587 | matrix M=I[2]; |
---|
| 588 | matrix A[1][nrows(M)]=M[1..nrows(M),1]; |
---|
| 589 | ideal i=A; |
---|
| 590 | return (i); |
---|
| 591 | } |
---|
| 592 | proc quotient1(module a,module b) //17sec |
---|
[300a34] | 593 | "USAGE: quotient1(m1, m2); m1, m2 two submodules of k^s, |
---|
| 594 | RETURN: the quotient of m1 and m2" |
---|
[aa6e78] | 595 | { |
---|
| 596 | int i; |
---|
| 597 | a=std(a); |
---|
| 598 | module dummy; |
---|
| 599 | module B=NF(b,a)+dummy; |
---|
[ef25c3] | 600 | ideal re=quotient(a,module(B[1])); |
---|
[aa6e78] | 601 | for(i=2;i<=size(B);i++) |
---|
| 602 | { |
---|
[ef25c3] | 603 | re=intersect1(re,quotient(a,module(B[i]))); |
---|
[aa6e78] | 604 | } |
---|
[300a34] | 605 | return(re); |
---|
[aa6e78] | 606 | } |
---|
| 607 | proc quotient2(module a,module b) //13sec |
---|
[300a34] | 608 | "USAGE: quotient2(m1, m2); m1, m2 two submodules of k^s, |
---|
| 609 | RETURN: the quotient of m1 and m2" |
---|
[aa6e78] | 610 | { |
---|
| 611 | a=std(a); |
---|
| 612 | module dummy; |
---|
| 613 | module bb=NF(b,a)+dummy; |
---|
| 614 | int i=size(bb); |
---|
[ef25c3] | 615 | ideal re=quotient(a,module(bb[i])); |
---|
[aa6e78] | 616 | bb[i]=0; |
---|
| 617 | module temp; |
---|
| 618 | module temp1; |
---|
| 619 | module bbb; |
---|
| 620 | int mx; |
---|
| 621 | i=i-1; |
---|
| 622 | while (1) |
---|
| 623 | { |
---|
| 624 | if (i==0) break; |
---|
| 625 | temp = a+bb*re; |
---|
| 626 | temp1 = lead(interred(temp)); |
---|
| 627 | mx=ncols(a); |
---|
| 628 | if (ncols(temp1)>ncols(a)) |
---|
| 629 | { |
---|
| 630 | mx=ncols(temp1); |
---|
| 631 | } |
---|
| 632 | temp1 = matrix(temp1,1,mx)-matrix(lead(a),1,mx); |
---|
| 633 | temp1 = dummy+temp1; |
---|
| 634 | if (deg(temp1[1])<0) break; |
---|
[ef25c3] | 635 | re=intersect1(re,quotient(a,module(bb[i]))); |
---|
[aa6e78] | 636 | bb[i]=0; |
---|
| 637 | i = i-1; |
---|
| 638 | } |
---|
[300a34] | 639 | return(re); |
---|
[aa6e78] | 640 | } |
---|
| 641 | proc quotient3(module a,module b) //89sec |
---|
[300a34] | 642 | "USAGE: quotient3(m1, m2); m1, m2 two submodules of k^s, |
---|
[aa6e78] | 643 | only for global rings |
---|
[300a34] | 644 | RETURN: the quotient of m1 and m2" |
---|
[aa6e78] | 645 | { |
---|
| 646 | string s="ring @newr=("+charstr(basering)+ |
---|
| 647 | "),("+varstr(basering)+",@t,@w),dp;"; |
---|
| 648 | def @newP=basering; |
---|
| 649 | execute s; |
---|
| 650 | module b=imap(@newP,b); |
---|
| 651 | module a=imap(@newP,a); |
---|
| 652 | int i; |
---|
| 653 | int j=size(b); |
---|
| 654 | vector @b; |
---|
| 655 | for(i=1;i<=j;i++) |
---|
| 656 | { |
---|
| 657 | @b=@b+@t^(i-1)*@w^(j-i+1)*b[i]; |
---|
| 658 | } |
---|
[ef25c3] | 659 | ideal re=quotient(a,module(@b)); |
---|
[aa6e78] | 660 | setring @newP; |
---|
| 661 | ideal re=imap(@newr,re); |
---|
[300a34] | 662 | return(re); |
---|
[aa6e78] | 663 | } |
---|
| 664 | proc quotient5(module a,module b) //89sec |
---|
[300a34] | 665 | "USAGE: quotient5(m1, m2); m1, m2 two submodules of k^s, |
---|
[aa6e78] | 666 | only for global rings |
---|
[300a34] | 667 | RETURN: the quotient of m1 and m2" |
---|
[aa6e78] | 668 | { |
---|
| 669 | string s="ring @newr=("+charstr(basering)+ |
---|
| 670 | "),("+varstr(basering)+",@t),dp;"; |
---|
| 671 | def @newP=basering; |
---|
| 672 | execute s; |
---|
| 673 | module b=imap(@newP,b); |
---|
| 674 | module a=imap(@newP,a); |
---|
| 675 | int i; |
---|
| 676 | int j=size(b); |
---|
| 677 | vector @b; |
---|
| 678 | for(i=1;i<=j;i++) |
---|
| 679 | { |
---|
| 680 | @b=@b+@t^(i-1)*b[i]; |
---|
| 681 | } |
---|
| 682 | @b=homog(@b,@w); |
---|
[ef25c3] | 683 | ideal re=quotient(a,module(@b)); |
---|
[aa6e78] | 684 | setring @newP; |
---|
| 685 | ideal re=imap(@newr,re); |
---|
[300a34] | 686 | return(re); |
---|
[aa6e78] | 687 | } |
---|
| 688 | proc quotient4(module a,module b) //95sec |
---|
[300a34] | 689 | "USAGE: quotient4(m1, m2); m1, m2 two submodules of k^s, |
---|
[aa6e78] | 690 | only for global rings |
---|
[300a34] | 691 | RETURN: the quotient of m1 and m2" |
---|
[aa6e78] | 692 | { |
---|
| 693 | string s="ring @newr=("+charstr(basering)+ |
---|
| 694 | "),("+varstr(basering)+",@t),dp;"; |
---|
| 695 | def @newP=basering; |
---|
| 696 | execute s; |
---|
| 697 | module b=imap(@newP,b); |
---|
| 698 | module a=imap(@newP,a); |
---|
| 699 | int i; |
---|
| 700 | vector @b=b[1]; |
---|
| 701 | for(i=2;i<=size(b);i++) |
---|
| 702 | { |
---|
| 703 | @b=@b+@t^(i-1)*b[i]; |
---|
| 704 | } |
---|
| 705 | matrix sy=modulo(@b,a); |
---|
| 706 | ideal re=sy; |
---|
| 707 | setring @newP; |
---|
| 708 | ideal re=imap(@newr,re); |
---|
[300a34] | 709 | return(re); |
---|
[aa6e78] | 710 | } |
---|
| 711 | static proc intersect1(ideal i,ideal j) |
---|
| 712 | { |
---|
| 713 | def R=basering; |
---|
| 714 | execute "ring gnir = ("+charstr(basering)+"), |
---|
| 715 | ("+varstr(basering)+",@t),(C,dp);"; |
---|
| 716 | ideal i=var(nvars(basering))*imap(R,i)+(var(nvars(basering))-1)*imap(R,j); |
---|
| 717 | ideal j=eliminate(i,var(nvars(basering))); |
---|
| 718 | setring R; |
---|
| 719 | map phi=gnir,maxideal(1); |
---|
| 720 | return(phi(j)); |
---|
| 721 | } |
---|
[300a34] | 722 | |
---|
[2dbaece] | 723 | ////////////////////////////////////////////////////////////////// |
---|
| 724 | /// |
---|
| 725 | /// sprintf, fprintf printf |
---|
| 726 | /// |
---|
| 727 | proc sprintf(string fmt, list #) |
---|
| 728 | "USAGE: sprintf(fmt, ...) fmt string |
---|
| 729 | RETURN: string |
---|
| 730 | PURPOSE: sprintf performs output formatting. The first argument is a format |
---|
| 731 | control string. Additional arguments may be required, depending on |
---|
| 732 | the contents of the control string. A series of output characters is |
---|
| 733 | generated as directed by the control string; these characters are |
---|
| 734 | returned as a string. The control string is simply text to be copied, |
---|
| 735 | except that the string may contain conversion specifications. Do |
---|
| 736 | 'help print:' for a listing of valid conversion specifications. |
---|
[71f6706] | 737 | As an addition to the conversions of 'print', the '%n' and '%2' |
---|
| 738 | conversion specification does not consume an additional argument, |
---|
| 739 | but simply generates a newline character. |
---|
[2dbaece] | 740 | NOTE: If one of the additional arguments is a list, then it should be |
---|
| 741 | enclosed once more into a list() command, since passing a list |
---|
| 742 | as an argument flattens the list by one level. |
---|
| 743 | SEE ALSO: fprintf, printf, print, string |
---|
| 744 | EXAMPLE : example sprintf; shows an example |
---|
| 745 | " |
---|
| 746 | { |
---|
| 747 | if (size(fmt) <= 1) |
---|
| 748 | { |
---|
| 749 | return (fmt); |
---|
| 750 | } |
---|
| 751 | int next, l, nnext; |
---|
| 752 | string ret; |
---|
[71f6706] | 753 | list formats = "%l", "%s", "%2l", "%2s", "%t", "%;", "%p", "%b", "%n", "%2"; |
---|
[2dbaece] | 754 | while (1) |
---|
| 755 | { |
---|
| 756 | if (size(#) <= 0) |
---|
| 757 | { |
---|
| 758 | return (ret + fmt); |
---|
| 759 | } |
---|
| 760 | nnext = 0; |
---|
| 761 | while (1) |
---|
| 762 | { |
---|
| 763 | nnext = find(fmt, "%", nnext + 1); |
---|
| 764 | if (nnext == 0) |
---|
| 765 | { |
---|
| 766 | next = 0; |
---|
| 767 | break; |
---|
| 768 | } |
---|
| 769 | l = 1; |
---|
| 770 | while (l <= size(formats)) |
---|
| 771 | { |
---|
| 772 | next = find(fmt, formats[l], nnext); |
---|
| 773 | if (next == nnext) break; |
---|
| 774 | l++; |
---|
| 775 | } |
---|
| 776 | if (next == nnext) break; |
---|
| 777 | } |
---|
| 778 | if (next == 0) |
---|
| 779 | { |
---|
| 780 | return (ret + fmt); |
---|
| 781 | } |
---|
[71f6706] | 782 | if (formats[l] != "%2" && formats[l] != "%n") |
---|
| 783 | { |
---|
| 784 | ret = ret + fmt[1, next - 1] + print(#[1], formats[l]); |
---|
| 785 | # = delete(#, 1); |
---|
| 786 | } |
---|
| 787 | else |
---|
| 788 | { |
---|
| 789 | ret = ret + fmt[1, next - 1] + print("", "%2s"); |
---|
| 790 | } |
---|
[2dbaece] | 791 | if (size(fmt) <= (next + size(formats[l]) - 1)) |
---|
| 792 | { |
---|
| 793 | return (ret); |
---|
| 794 | } |
---|
| 795 | fmt = fmt[next + size(formats[l]), size(fmt)-next-size(formats[l]) + 1]; |
---|
| 796 | } |
---|
| 797 | } |
---|
| 798 | example |
---|
| 799 | { |
---|
| 800 | ring r=0,(x,y,z),dp; |
---|
| 801 | module m=[1,y],[0,x+z]; |
---|
| 802 | intmat M=betti(mres(m,0)); |
---|
| 803 | list l = r, m, M; |
---|
[71f6706] | 804 | string s = sprintf("s:%s,%n l:%l", 1, 2); s; |
---|
| 805 | s = sprintf("s:%n%s", l); s; |
---|
| 806 | s = sprintf("s:%2%s", list(l)); s; |
---|
| 807 | s = sprintf("2l:%n%2l", list(l)); s; |
---|
[2dbaece] | 808 | s = sprintf("%p", list(l)); s; |
---|
| 809 | s = sprintf("%;", list(l)); s; |
---|
| 810 | s = sprintf("%b", M); s; |
---|
| 811 | } |
---|
| 812 | |
---|
| 813 | proc printf(string fmt, list #) |
---|
| 814 | "USAGE: printf(fmt, ...) fmt string |
---|
| 815 | RETURN: none |
---|
| 816 | PURPOSE: printf performs output formatting. The first argument is a format |
---|
| 817 | control string. Additional arguments may be required, depending on |
---|
| 818 | the contents of the control string. A series of output characters is |
---|
| 819 | generated as directed by the control string; these characters are |
---|
| 820 | displayed (i.e. printed to standard out). |
---|
| 821 | The control string is simply text to be copied, except that the |
---|
| 822 | string may contain conversion specifications. |
---|
| 823 | Do 'help print:' for a listing of valid conversion specifications. |
---|
[71f6706] | 824 | As an addition to the conversions of 'print', the '%n' and '%2' |
---|
| 825 | conversion specification does not consume an additional argument, |
---|
| 826 | but simply generates a newline character. |
---|
[2dbaece] | 827 | |
---|
| 828 | NOTE: If one of the additional arguments is a list, then it should be |
---|
| 829 | enclosed once more into a list() command, since passing a list |
---|
| 830 | as an argument flattens the list by one level. |
---|
| 831 | SEE ALSO: sprintf, fprintf, print, string |
---|
| 832 | EXAMPLE : example printf; shows an example |
---|
| 833 | " |
---|
| 834 | { |
---|
| 835 | write("", sprintf(fmt, #)); |
---|
| 836 | } |
---|
| 837 | example |
---|
| 838 | { |
---|
| 839 | ring r=0,(x,y,z),dp; |
---|
| 840 | module m=[1,y],[0,x+z]; |
---|
| 841 | intmat M=betti(mres(m,0)); |
---|
| 842 | list l = r, m, M; |
---|
| 843 | printf("s:%s, l:%l", 1, 2); |
---|
| 844 | printf("s:%s", l); |
---|
| 845 | printf("s:%s", list(l)); |
---|
| 846 | printf("2l:%2l", list(l)); |
---|
| 847 | printf("%p", list(l)); |
---|
| 848 | printf("%;", list(l)); |
---|
| 849 | printf("%b", M); |
---|
| 850 | } |
---|
| 851 | |
---|
| 852 | |
---|
| 853 | proc fprintf(link l, string fmt, list #) |
---|
| 854 | "USAGE: fprintf(l, fmt, ...) l link; fmt string |
---|
| 855 | RETURN: none |
---|
| 856 | PURPOSE: fprintf performs output formatting. The second argument is a format |
---|
| 857 | control string. Additional arguments may be required, depending on |
---|
| 858 | the contents of the control string. A series of output characters is |
---|
| 859 | generated as directed by the control string; these characters are |
---|
| 860 | written to the link l. |
---|
| 861 | The control string is simply text to be copied, except that the |
---|
| 862 | string may contain conversion specifications. |
---|
| 863 | Do 'help print:' for a listing of valid conversion specifications. |
---|
[71f6706] | 864 | As an addition to the conversions of 'print', the '%n' and '%2' |
---|
| 865 | conversion specification does not consume an additional argument, |
---|
| 866 | but simply generates a newline character. |
---|
[2dbaece] | 867 | |
---|
| 868 | NOTE: If one of the additional arguments is a list, then it should be |
---|
| 869 | enclosed once more into a list() command, since passing a list |
---|
| 870 | as an argument flattens the list by one level. |
---|
| 871 | SEE ALSO: sprintf, printf, print, string |
---|
| 872 | EXAMPLE : example fprintf; shows an example |
---|
| 873 | " |
---|
| 874 | { |
---|
| 875 | write(l, sprintf(fmt, #)); |
---|
| 876 | } |
---|
| 877 | example |
---|
| 878 | { |
---|
| 879 | ring r=0,(x,y,z),dp; |
---|
| 880 | module m=[1,y],[0,x+z]; |
---|
| 881 | intmat M=betti(mres(m,0)); |
---|
| 882 | list l = r, m, M; |
---|
| 883 | link li = ""; // link to stdout |
---|
| 884 | fprintf(li, "s:%s, l:%l", 1, 2); |
---|
| 885 | fprintf(li, "s:%s", l); |
---|
| 886 | fprintf(li, "s:%s", list(l)); |
---|
| 887 | fprintf(li, "2l:%2l", list(l)); |
---|
| 888 | fprintf(li, "%p", list(l)); |
---|
| 889 | fprintf(li, "%;", list(l)); |
---|
| 890 | fprintf(li, "%b", M); |
---|
| 891 | } |
---|
| 892 | |
---|
| 893 | |
---|
| 894 | |
---|
| 895 | |
---|
| 896 | |
---|
| 897 | |
---|
[64c6d1] | 898 | /* |
---|
| 899 | proc minres(list #) |
---|
[6149f4f] | 900 | { |
---|
[64c6d1] | 901 | if (size(#) == 2) |
---|
| 902 | { |
---|
| 903 | if (typeof(#[1]) == "ideal" || typeof(#[1]) == "module") |
---|
| 904 | { |
---|
| 905 | if (typeof(#[2] == "int")) |
---|
| 906 | { |
---|
| 907 | return (res(#[1],#[2],1)); |
---|
| 908 | } |
---|
| 909 | } |
---|
| 910 | } |
---|
[bcd557] | 911 | |
---|
[64c6d1] | 912 | if (typeof(#[1]) == "resolution") |
---|
| 913 | { |
---|
| 914 | return minimizeres(#[1]); |
---|
| 915 | } |
---|
| 916 | else |
---|
| 917 | { |
---|
| 918 | return minimizeres(#); |
---|
| 919 | } |
---|
[bcd557] | 920 | |
---|
[6149f4f] | 921 | } |
---|
[64c6d1] | 922 | |
---|
| 923 | */ |
---|