/////////////////////////////////////////////////////////////// // $Id: grwalk.lib,v 1.3 2005-06-06 11:26:46 Singular Exp $ // /////////////////////////////////////////////////////////////// version="$Id: grwalk.lib,v 1.3 2005-06-06 11:26:46 Singular Exp $"; category="Commutative Algebra"; info=" LIBRARY: grwalk.lib Groebner Walk Conversion Algorithms AUTHOR: I Made Sulandra PROCEDURES: fwalk(ideal[,intvec]); standard basis of ideal via fractalwalk alg twalk(ideal[,intvec]); standard basis of ideal via Tran's alg awalk1(ideal[,intvec]); standard basis of ideal via the first alt. alg awalk2(ideal[,intvec]); standard basis of ideal via the second alt. alg pwalk(ideal[,intvec]); standard basis of ideal via perturbation walk alg gwalk(ideal[,intvec]); standard basis of ideal via groebnerwalk alg "; ////////////////////////////////////////////////////////////////////////////// static proc OrderStringalp(string Wpal,list #) { int n= nvars(basering); string order_str; intvec curr_weight, target_weight; curr_weight = system("Mivdp",n); target_weight = system("Mivlp",n); if(size(#) != 0) { if(size(#) == 1) { if(typeof(#[1]) == "intvec") { if(Wpal == "al"){ order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; } else { order_str = "(Wp("+string(#[1])+"),C)"; } curr_weight = #[1]; } else { if(typeof(#[1]) == "string") { if(#[1] == "Dp") { order_str = "Dp"; } else { order_str = "dp"; } } else { order_str = "dp"; } } } else { if(size(#) == 2) { if(typeof(#[2]) == "intvec") { target_weight = #[2]; } if(typeof(#[1]) == "intvec") { if(Wpal == "al"){ order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; } else { order_str = "(Wp("+string(#[1])+"),C)"; } curr_weight = #[1]; } else { if(typeof(#[1]) == "string") { if(#[1] == "Dp") { order_str = "Dp"; } else { order_str = "dp"; } } else { order_str = "dp"; } } } } } else { order_str = "dp"; } list result; result[1] = order_str; result[2] = curr_weight; result[3] = target_weight; return(result); } static proc OrderStringalp_NP(string Wpal,list #) { int n= nvars(basering); string order_str = "dp"; //string order_str = "Dp"; int nP = 1;// call LatsGB to compute the wanted GB by pwalk //Default: // if size(#)=0, the Gröbnerwalk algorithm and its developments compute // a Groebner basis from "dp" to "lp" intvec curr_weight = system("Mivdp",n); //define (1,1,...,1) intvec target_weight = system("Mivlp",n); //define (1,0,...,0) if(size(#) != 0) { if(size(#) == 1) { if(typeof(#[1]) == "intvec") { curr_weight = #[1]; if(Wpal == "al"){ order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; } else { order_str = "(Wp("+string(#[1])+"),C)"; } } else { if(typeof(#[1]) == "int"){ nP = #[1]; } else { print("// ** the input must be \"(ideal, int)\" or "); print("// ** \"(ideal, intvec)\""); print("// ** a lex. GB will be computed from \"dp\" to \"lp\""); } } } else { if(size(#) == 2) { if(typeof(#[1]) == "intvec" and typeof(#[2]) == "int"){ curr_weight = #[1]; if(Wpal == "al"){ order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; } else { order_str = "(Wp("+string(#[1])+"),C)"; } } else{ if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec"){ curr_weight = #[1]; target_weight = #[2]; if(Wpal == "al"){ order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; } else { order_str = "(Wp("+string(#[1])+"),C)"; } } else{ print("// ** the input must be \"(ideal,intvec,int)\" or "); print("// ** \"(ideal,intvec,intvec)\""); print("// ** and a lex. GB will be computed from \"dp\" to \"lp\""); } } } else { if(size(#) == 3) { if(typeof(#[1]) == "intvec" and typeof(#[2]) == "intvec" and typeof(#[3]) == "int") { curr_weight = #[1]; target_weight = #[2]; nP = #[3]; if(Wpal == "al"){ order_str = "(a("+string(#[1])+"),lp("+string(n) + "),C)"; } else { order_str = "(Wp("+string(#[1])+"),C)"; } } else{ print("// ** the input must be \"(ideal,intvec,intvec,int)\""); print("// ** and a lex. GB will be computed from \"dp\" to \"lp\""); } } else{ print("// ** The given input is wrong"); print("// ** and a lex. GB will be computed from \"dp\" to \"lp\""); } } } } list result; result[1] = nP; result[2] = order_str; result[3] = curr_weight; result[4] = target_weight; return(result); } proc gwalk(ideal Go, list #) "SYNTAX: gwalk(ideal i); gwalk(ideal i, intvec v, intvec w); TYPE: ideal PURPOSE: compute the standard basis of the ideal, calculated via the improved Groebner walk algorithm from the ordering \"(a(v),lp)\", \"dp\" or \"Dp\" to the ordering \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\". SEE ALSO: std, stdfglm, groebner, pwalk, fwalk, twalk, awalk1, awalk2 KEYWORDS: Groebner walk EXAMPLE: example gwalk; shows an example" { /* we use ring with ordering (a(...),lp,C) */ list OSCTW = OrderStringalp_NP("al", #);//"dp" //list OSCTW = OrderStringalp("al", "Dp");//Dp string ord_str = OSCTW[2]; intvec curr_weight = OSCTW[3]; /* original weight vector */ intvec target_weight = OSCTW[4]; /* terget weight vector */ kill OSCTW; option(redSB); def xR = basering; execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";"); def old_ring = basering; //print("//** help ring = " + string(basering)); ideal G = fetch(xR, Go); G = system("Mwalk", G, curr_weight, target_weight); setring xR; //kill Go; keepring basering; ideal result = fetch(old_ring, G); attrib(result,"isSB",1); return (result); } example { "EXAMPLE:"; echo = 2; //** compute a Gröbner basis of I w.r.t. lp. ring r = 32003,(z,y,x), lp; ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z; gwalk(I); } /* 16 Mai 2003 */ proc awalk1(ideal G, list #) "SYNTAX: awalk1(ideal i); awalk1(ideal i, int n); awalk1(ideal i, int n, intvec v, intvec w); awalk1(ideal i, intvec v, intvec w); TYPE: ideal PURPOSE: compute the standard basis of the ideal, calculated via the first alternative algorithm from an ordering \"(a(v),lp)\", \"dp\" or \"Dp\" to the ordering \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\" with a perturbation degree n for the weight vector w. SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk2 KEYWORDS: the first alternative algorithm EXAMPLE: example awalk1; shows an example" { if (size(#) == 0) { return (awalk1_tmp(G, nvars(basering)-1)); } else { if(typeof(#[1]) == "int") { return (awalk1_tmp(G, #[1])); } else { return (awalk1_tmp(G, nvars(basering)-1, #)); } } } example { "EXAMPLE:"; echo = 2; ring r = 32003,(z,y,x), lp; ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z; awalk1(I,3); } proc awalk1_tmp(ideal Go, int n2, list #) //proc awalk1(ideal Go, int n1, int n2, list #) { int nV = nvars(basering); int n1 = 1; //assume(n1 >= 1 && n1 <= nV && n2 >= 1 && n2 <= nV); if(n1 < 1 || n1 > nV || n2 < 1 || n2 > nV) { print("//Erorr: The perturbed degree is wrong!!"); print("// It must be between 1 and " + string(nV)); return(); } /* we use ring with ordering (a(...),lp,C) */ list OSCTW = OrderStringalp_NP("al", #); //list OSCTW = OrderStringalp("al", "Dp"); string ord_str = OSCTW[2]; intvec curr_weight = OSCTW[3]; /* original weight vector */ intvec target_weight = OSCTW[4]; /* terget weight vector */ kill OSCTW; option(redSB); def xR = basering; execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";"); def old_ring = basering; //print("//** help ring = " + string(basering)); ideal G = fetch(xR, Go); G = system("MAltwalk1", G, n1, n2, curr_weight, target_weight); setring xR; //kill Go; keepring basering; ideal result = fetch(old_ring, G); attrib(result,"isSB",1); return (result); } proc fwalk(ideal Go, list #) "SYNTAX: fwalk(ideal i); fwalk(ideal i, intvec v, intvec w); TYPE: ideal PURPOSE: compute the standard basis of the ideal w.r.t. the lexicographical ordering or a weighted-lex ordering, calculated via the fractal walk algorithm. SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, twalk, awalk1, awalk2 KEYWORDS: The fractal walk algorithm EXAMPLE: example fwalk; shows an example" { /* we use ring with ordering (a(...),lp,C) */ list OSCTW = OrderStringalp_NP("al", #); string ord_str = OSCTW[2]; intvec curr_weight = OSCTW[3]; /* original weight vector */ intvec target_weight = OSCTW[4]; /* terget weight vector */ kill OSCTW; option(redSB); def xR = basering; execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";"); def old_ring = basering; //print("//** help ring = " + string(basering)); ideal G = fetch(xR, Go); G = system("Mfwalk", G, curr_weight, target_weight); setring xR; //kill Go; keepring basering; ideal result = fetch(old_ring, G); attrib(result,"isSB",1); return (result); } example { "EXAMPLE:"; echo = 2; ring r = 32003,(z,y,x), lp; ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z; fwalk(I); } proc awalk2(ideal Go, list #) "SYNTAX: awalk2(ideal i); awalk2(ideal i, intvec v, intvec w); TYPE: ideal PURPOSE: compute the standard basis of the ideal, calculated via the second alternative algorithm from the ordering \"(a(v),lp)\", \"dp\" or \"Dp\" to the ordering \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\". SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, twalk, awalk1 KEYWORDS: Groebner walk EXAMPLE: example awalk2; shows an example" { /* we use ring with ordering (a(...),lp,C) */ list OSCTW = OrderStringalp_NP("al", #);//"dp" //list OSCTW = OrderStringalp("al", "Dp");//Dp string ord_str = OSCTW[2]; intvec curr_weight = OSCTW[3]; /* original weight vector */ intvec target_weight = OSCTW[4]; /* terget weight vector */ kill OSCTW; option(redSB); def xR = basering; execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";"); def old_ring = basering; //print("//** help ring = " + string(basering)); ideal G = fetch(xR, Go); G = system("MAltwalk2", G, curr_weight, target_weight); setring xR; //kill Go; keepring basering; ideal result = fetch(old_ring, G); attrib(result,"isSB",1); return (result); } example { "EXAMPLE:"; echo = 2; ring r = 32003,(z,y,x), lp; ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z; awalk2(I); } proc pwalk(ideal Go, int n1, int n2, list #) "SYNTAX: pwalk(int d, ideal i, int n1, int n2); pwalk(int d, ideal i, int n1, int n2, intvec v, intvec w); TYPE: ideal PURPOSE: compute the standard basis of the ideal, calculated via the perturbation walk algorithm from the ordering \"(a(v),lp)\", \"dp\" or \"Dp\" to the ordering \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\" with a perturbation degree n, m for v and w, resp. SEE ALSO: std, stdfglm, groebner, gwalk, fwalk, twalk, awalk1, awalk2 KEYWORDS: Perturbation walk EXAMPLE: example pwalk; shows an example" { int nV = nvars(basering); //assume(n1 >= 1 && n1 <= nV && n2 >= 1 && n2 <= nV); if(n1 < 1 || n1 > nV || n2 < 1 || n2 > nV) { print("//Erorr: The perturbed degree is wrong!!"); print("// It must be between 1 and " + string(nV)); return(); } /* we use ring with ordering (a(...),lp,C) */ list OSCTW = OrderStringalp_NP("al", #); //list OSCTW = OrderStringalp("al", "Dp");//Dp int nP = OSCTW[1]; string ord_str = OSCTW[2]; intvec curr_weight = OSCTW[3]; /* original weight vector */ intvec target_weight = OSCTW[4]; /* terget weight vector */ kill OSCTW; option(redSB); def xR = basering; execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";"); def old_ring = basering; ideal G = fetch(xR, Go); G = system("Mpwalk", G, n1, n2, curr_weight, target_weight,nP); setring xR; //kill Go; keepring basering; ideal result = fetch(old_ring, G); attrib(result,"isSB",1); return (result); } example { "EXAMPLE:"; echo = 2; ring r = 32003,(z,y,x), lp; ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z; pwalk(I,2,3); } proc twalk(ideal Go, list #) "SYNTAX: twalk(ideal i); twalk(ideal i, intvec v, intvec w); TYPE: ideal PURPOSE: compute the standard basis of the ideal w.r.t. the ordering \"(a(w),lp)\" or \"(a(1,0,...,0),lp)\", calculated via the Tran algorithm. SEE ALSO: std, stdfglm, groebner, gwalk, pwalk, fwalk, awalk1, awalk2 KEYWORDS: The Tran algorithm EXAMPLE: example twalk; shows an example" { list L = OrderStringalp_NP("al", #); int nP = L[1]; /* we use ring with ordering (a(...),lp,C) */ string ord_str = L[2]; intvec curr_weight = L[3]; intvec target_weight = L[4]; kill L; option(redSB); def xR = basering; execute("ring ostR = ("+charstr(xR)+"),("+varstr(xR)+"),"+ord_str+";"); def old_ring = basering; //print("//** help ring = " + string(basering)); ideal G = fetch(xR, Go); G = system("TranMImprovwalk", G, curr_weight, target_weight, nP); setring xR; //kill Go; keepring basering; ideal result = fetch(old_ring, G); attrib(result,"isSB",1); return (result); } example { "EXAMPLE:"; echo = 2; ring r = 32003,(z,y,x), lp; ideal I = y3+xyz+y2z+xz3, 3+xy+x2y+y2z; twalk(I); }