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