- Timestamp:
- Apr 23, 2004, 4:14:48 PM (20 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'd08f5f0bb3329b8ca19f23b74cb1473686415c3a')
- Children:
- 979aa58e6eda64d0f268299c491c22335ba45afd
- Parents:
- 941bf901a04bf88f372b9d507a2d244f2733e050
- Location:
- Singular
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/standard.lib
r941bf9 r5a66d0 1 1 ////////////////////////////////////////////////////////////////////////////// 2 version="$Id: standard.lib,v 1.6 4 2003-10-17 16:03:18 levandovExp $";2 version="$Id: standard.lib,v 1.65 2004-04-23 14:12:24 Singular Exp $"; 3 3 category="Miscellaneous"; 4 4 info=" … … 6 6 7 7 PROCEDURES: 8 stdjanet(ideal/module) Groebner basis using Janet basis computation9 8 stdfglm(ideal[,ord]) standard basis of ideal via fglm [and ordering ord] 10 9 stdhilb(ideal[,h]) standard basis of ideal using the Hilbert function … … 12 11 quot(any,any[,n]) quotient using heuristically chosen method 13 12 res(ideal/module,[i]) free resolution of ideal or module 14 janet(ideal/module) Janet basis of the ideal/module15 13 sprintf(fmt,...) returns fomatted string 16 14 fprintf(link,fmt,..) writes formatted string to link … … 1109 1107 p=p^2; 1110 1108 timeFactorize(p,2); 1111 timeFactorize(p,20); 1109 "ERROR: will not run currently:"; 1110 //timeFactorize(p,20); 1112 1111 } 1113 1112 … … 1229 1228 factorH(p); 1230 1229 } 1231 1232 proc janet(def @i)1233 "SYNTAX: @code{janet (} ideal_expression @code{)} @*1234 @code{janet (} module_expression @code{)}1235 TYPE: type of the first argument1236 PURPOSE: computes the Janet basis of the argument @code{I}1237 (ideal or module).1238 ASSUME: well-ordering on current ring. Computations with modules1239 are still under development1240 NOTE: Janet basis is an involutive basis with respect to1241 the involutive Janet division. It is indeed a non-reduced Groebner basis.1242 SEE ALSO: stdjanet, std1243 KEYWORDS: involutive basis computations1244 EXAMPLE: example janet; shows an example"1245 {1246 return(system("janet",@i,1));1247 }1248 example1249 { "EXAMPLE: "; echo=2;1250 ring r=0,(x,y,z),dp;1251 ideal i=x*y*z-1,x+y+z,x*y+x*z+y*z; // cyclic 31252 janet(i);1253 }1254 //////////////////////////////////////////////////////////////////////////1255 1256 proc stdjanet(def @i)1257 "SYNTAX: @code{groebner (} ideal_expression @code{)} @*1258 @code{groebner (} module_expression @code{)}1259 TYPE: type of the first argument1260 PURPOSE: computes the reduced Groebner basis of the argument @code{I} (ideal or module) via the computation of Janet basis and interreduction.1261 ASSUME: well-ordering on current ring. Computations with modules are1262 still under development.1263 NOTE: In order to compare the result with the one, produced by @code{std},1264 be sure that @code{option(prot)} is activated in the latter computation.1265 SEE ALSO: janet, std1266 KEYWORDS: involutive basis computations, groebner basis computations1267 EXAMPLE: example stdjanet; shows an example"1268 {1269 return(system("janet",@i,0));1270 }1271 example1272 { "EXAMPLE: "; echo=2;1273 ring r=0,(x,y,z),dp;1274 ideal i=x*y*z-1,x+y+z,x*y+x*z+y*z; // cyclic 31275 stdjanet(i);1276 option(redSB);1277 std(i);1278 }1279 1230 ////////////////////////////////////////////////////////////////////////// 1280 1231 -
Singular/extra.cc
r941bf9 r5a66d0 2 2 * Computer Algebra System SINGULAR * 3 3 *****************************************/ 4 /* $Id: extra.cc,v 1.20 3 2004-04-03 17:25:02 levandovExp $ */4 /* $Id: extra.cc,v 1.204 2004-04-23 14:10:50 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: general interface to internals of Singular ("system" command) … … 592 592 } 593 593 else 594 /*==================== janet =============================*/595 if(strcmp(sys_cmd,"janet") == 0)596 {597 if ((h!=NULL) && ((h->Typ() == IDEAL_CMD) || (h->Typ()== MODUL_CMD)))598 {599 return jjJanetBasis(res,h);600 }601 else602 {603 WerrorS("ideal or module expected");604 return TRUE;605 }606 }607 else608 594 /*==================== spectrum =============================*/ 609 595 #ifdef HAVE_SPECTRUM -
Singular/iparith.cc
r941bf9 r5a66d0 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: iparith.cc,v 1.31 6 2004-04-19 10:40:40Singular Exp $ */4 /* $Id: iparith.cc,v 1.317 2004-04-23 14:10:13 Singular Exp $ */ 5 5 6 6 /* … … 45 45 #include "algmap.h" 46 46 #include "units.h" 47 #include "janet.h" 47 48 #include "../kernel/GMPrat.h" 48 49 #ifdef HAVE_FACTORY … … 220 221 { "intvec", 0, INTVEC_CMD , ROOT_DECL_LIST}, 221 222 { "jacob", 0, JACOB_CMD , CMD_1}, 223 { "janet", 0, JANET_CMD , CMD_12}, 222 224 { "jet", 0, JET_CMD , CMD_M}, 223 225 { "kbase", 0, KBASE_CMD , CMD_12}, … … 1896 1898 setFlag(res,FLAG_STD); 1897 1899 return FALSE; 1900 } 1901 static BOOLEAN jjJanetBasis2(leftv res, leftv u, leftv v) 1902 { 1903 return jjStdJanetBasis(res,u,(int)v->Data()); 1898 1904 } 1899 1905 static BOOLEAN jjJET_P(leftv res, leftv u, leftv v) … … 2575 2581 ,{jjINTERSECT, INTERSECT_CMD, IDEAL_CMD, IDEAL_CMD, IDEAL_CMD ALLOW_PLURAL} 2576 2582 ,{jjINTERSECT, INTERSECT_CMD, MODUL_CMD, MODUL_CMD, MODUL_CMD ALLOW_PLURAL} 2583 ,{jjJanetBasis2, JANET_CMD, IDEAL_CMD, IDEAL_CMD, INT_CMD ALLOW_PLURAL} 2577 2584 ,{jjJET_P, JET_CMD, POLY_CMD, POLY_CMD, INT_CMD ALLOW_PLURAL} 2578 2585 ,{jjJET_ID, JET_CMD, IDEAL_CMD, IDEAL_CMD, INT_CMD ALLOW_PLURAL} … … 3936 3943 ,{jjJACOB_P, JACOB_CMD, IDEAL_CMD, POLY_CMD ALLOW_PLURAL} 3937 3944 ,{mpJacobi, JACOB_CMD, MATRIX_CMD, IDEAL_CMD ALLOW_PLURAL} 3945 ,{jjJanetBasis, JANET_CMD, IDEAL_CMD, IDEAL_CMD ALLOW_PLURAL} 3938 3946 ,{jjKBASE, KBASE_CMD, IDEAL_CMD, IDEAL_CMD ALLOW_PLURAL} 3939 3947 ,{jjKBASE, KBASE_CMD, MODUL_CMD, MODUL_CMD ALLOW_PLURAL} … … 4864 4872 ,{jjHILBERT3, HILBERT_CMD,INTVEC_CMD, MODUL_CMD, INT_CMD, INTVEC_CMD NO_PLURAL} 4865 4873 ,{jjCALL3MANY, IDEAL_CMD, IDEAL_CMD, DEF_CMD, DEF_CMD, DEF_CMD ALLOW_PLURAL} 4874 ,{lInsert3, INSERT_CMD, LIST_CMD, LIST_CMD, DEF_CMD, INT_CMD ALLOW_PLURAL} 4866 4875 //,{jjCALL3MANY, INTERSECT_CMD, NONE, DEF_CMD, DEF_CMD, DEF_CMD ALLOW_PLURAL} 4867 ,{lInsert3, INSERT_CMD, LIST_CMD, LIST_CMD, DEF_CMD, INT_CMD ALLOW_PLURAL}4868 4876 ,{jjINTMAT3, INTMAT_CMD, INTMAT_CMD, INTMAT_CMD, INT_CMD, INT_CMD ALLOW_PLURAL} 4869 4877 ,{jjCALL3MANY, INTVEC_CMD, INTVEC_CMD, DEF_CMD, DEF_CMD, DEF_CMD ALLOW_PLURAL} -
Singular/janet.cc
r941bf9 r5a66d0 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <time.h> 5 1 6 #include "mod2.h" 2 #include "febase.h" 3 #include "janet.h" 7 #include <omalloc.h> 4 8 #include "polys.h" 5 9 #include "numbers.h" … … 7 11 #include "ideals.h" 8 12 #include "subexpr.h" 13 #include "kbuckets.h" 9 14 #include "longrat.h" 15 16 #if (defined(__CYGWIN__)) 17 #include <ctype.h> 18 #endif 19 #include <stdarg.h> 20 21 #include "febase.h" 22 #include "janet.h" 10 23 #include "kutil.h" 11 24 25 //------GLOBALS------- 26 static int m_s,v_s,vectorized,VarN1,offset; 27 static jList *T,*Q; 28 static TreeM *G; 29 static Poly *phD; 30 static NodeM *FreeNodes; 31 static int degree_compatible; 32 static int (*ListGreatMove)(jList *,jList *,poly); 33 static int Mask[8]={0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1}; 34 12 35 //#define DebugPrint 13 36 14 #define pow_(x) pTotaldegree((x)) 15 16 static int ProdCrit, ChainCrit; 37 //#define pow_(x) pTotaldegree((x)) 38 //#define pow_(x) pDeg((x)) 39 pFDegProc jDeg; 40 #define pow_(x) jDeg((x)) 17 41 18 42 void Debug() 19 43 { 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 LCI it=T->root; 45 46 Print("T==================================\n"); 47 while (it) 48 { 49 pWrite(it->info->root); 50 it=it->next; 51 } 52 53 it=Q->root; 54 55 Print("Q==================================\n"); 56 while (it) 57 { 58 if (it->info->root) pWrite(it->info->root); 59 else 60 { 61 Print("%d.........",it->info->prolonged); 62 pWrite(it->info->history); 63 } 64 it=it->next; 65 } 66 Print("===================================\n"); 43 67 } 44 68 45 69 int ReducePolyLead(Poly *x,Poly *y) 46 70 { 47 if (!x->root || !y->root) 48 return 0; 49 50 /* poly b1=pDivide(x->root,y->root); 51 52 number gcd=nGcd(pGetCoeff(x->root),pGetCoeff(y->root),currRing); 53 54 number a1=nDiv(pGetCoeff(y->root),gcd); 55 pGetCoeff(b1)=nDiv(pGetCoeff(x->root),gcd); 56 57 x->root=pMult_nn(x->root,a1); 58 nDelete(&a1); 59 60 x->root=pMinus_mm_Mult_qq(x->root,b1,y->root); 61 62 pDelete(&b1);*/ 63 64 x->root=ksOldSpolyRed(y->root,x->root,NULL); 65 66 // if (x->root) pContent(x->root); 67 68 return 1; 71 if (!x->root || !y->root) 72 return 0; 73 74 /* poly b1=pDivide(x->root,y->root); 75 76 number gcd=nGcd(pGetCoeff(x->root),pGetCoeff(y->root),currRing); 77 78 number a1=nDiv(pGetCoeff(y->root),gcd); 79 pGetCoeff(b1)=nDiv(pGetCoeff(x->root),gcd); 80 81 x->root=pMult_nn(x->root,a1); 82 nDelete(&a1); 83 84 x->root=pMinus_mm_Mult_qq(x->root,b1,y->root); 85 86 pDelete(&b1); 87 */ 88 #if 1 89 if (x->root_b==NULL) 90 { 91 if (x->root_l<=0) x->root_l=pLength(x->root); 92 x->root_b=kBucketCreate(currRing); 93 kBucketInit(x->root_b,x->root,x->root_l); 94 } 95 number coef; 96 if (y->root_l<=0) y->root_l=pLength(y->root); 97 coef=kBucketPolyRed(x->root_b,y->root,y->root_l,NULL); 98 nDelete(&coef); 99 x->root=kBucketGetLm(x->root_b); 100 if (x->root==NULL) 101 { 102 kBucketDestroy(&x->root_b); 103 x->root_b=NULL; 104 x->root_l=0; 105 } 106 #else 107 x->root=ksOldSpolyRed(y->root,x->root,NULL); 108 #endif 109 // if (x->root) pContent(x->root); 110 // if (x->root) pSimpleContent(x->root,5); 111 112 return 1; 69 113 } 70 114 71 115 int ReducePoly(Poly *x,poly from,Poly *y) 72 116 { 73 if (!x->root || !y->root) 74 return 0; 75 76 /* poly b1=pDivide(from,y->root); 77 78 number gcd=nGcd(pGetCoeff(from),pGetCoeff(y->root),currRing); 79 80 number a1=nDiv(pGetCoeff(y->root),gcd); 81 pGetCoeff(b1)=nDiv(pGetCoeff(from),gcd); 82 83 x->root=pMult_nn(x->root,a1); 84 nDelete(&a1);*/ 85 86 // x->root=pMinus_mm_Mult_qq(x->root,b1,y->root); 87 // pDelete(&b1); 88 89 ksOldSpolyTail(y->root,x->root,from,NULL,currRing); 90 91 return 1; 117 if (!x->root || !y->root) 118 return 0; 119 120 /* poly b1=pDivide(from,y->root); 121 122 number gcd=nGcd(pGetCoeff(from),pGetCoeff(y->root),currRing); 123 124 number a1=nDiv(pGetCoeff(y->root),gcd); 125 pGetCoeff(b1)=nDiv(pGetCoeff(from),gcd); 126 127 x->root=pMult_nn(x->root,a1); 128 nDelete(&a1);*/ 129 130 // x->root=pMinus_mm_Mult_qq(x->root,b1,y->root); 131 // pDelete(&b1); 132 133 ksOldSpolyTail(y->root,x->root,from,NULL,currRing); 134 y->root_l=0; 135 136 return 1; 92 137 } 93 138 94 139 void PNF(Poly *p, TreeM *F) 95 140 { 96 Poly *f; 97 98 if (!p->root) return; 99 100 poly temp=p->root; 101 102 while(temp->next) 103 { 104 f=is_div_(F,temp->next); 105 if (f) 106 { 107 if (ReducePoly(p,temp,f)) //temp->next 108 { 109 ; 110 } 111 } 112 else 113 temp=temp->next; 114 }; 115 116 // pCleardenom(p->root); 117 pContent(p->root); 118 pTest(p->root); 141 if (p->root==NULL) return; 142 143 Poly *f; 144 BOOLEAN done=FALSE; 145 poly temp=p->root; 146 147 // if (TEST_OPT_PROT) { PrintS("r"); mflush(); } 148 int count=0; 149 poly pp=p->root; 150 int old_size=nSize(pGetCoeff(pp)); 151 p->root_l=0; 152 while(temp->next) 153 { 154 f=is_div_(F,temp->next); 155 if (f) 156 { 157 if (ReducePoly(p,temp,f)) //temp->next 158 { 159 count++; 160 //if (TEST_OPT_PROT) { PrintS("-"); mflush(); } 161 if ((f!=NULL) 162 && (count>20) 163 && (nSize(pGetCoeff(pp))>old_size) 164 ) 165 { 166 //pSimpleContent(pp,2); 167 pContent(pp); 168 count=0; 169 // old_size=nSize(pGetCoeff(pp)); 170 } 171 } 172 done=TRUE; 173 } 174 else 175 temp=temp->next; 176 } 177 178 if (done) pContent(p->root); 179 //if (done) pSimpleContent(p->root,-1); 180 pTest(p->root); 119 181 } 120 182 121 183 void NFL(Poly *p, TreeM *F) 122 184 { 123 Poly *f; 124 int g1,f1,gg; 125 126 127 if ((f=is_div_(F,p->lead))==NULL) return; 128 129 int pX=pow_(p->lead); 130 int phX=pow_(p->history); 131 132 if (pX!=phX) 133 { 134 int phF=pow_(f->history); 135 if (!rIsPluralRing(currRing)) 136 { 137 /* Product Criterion */ 138 if (pX >= (phX+phF)) 139 { 140 // Print("ProdCrit Works!"); 141 ProdCrit++; 142 pDelete(&p->root); 143 p->root=NULL; 144 return; 145 } 146 } 147 148 int gg=0; int i=0; 149 for(i=0; i<currRing->N;i++) 150 { 151 g1=pGetExp(p->history,i+1); 152 f1=pGetExp(f->history,i+1); 153 if (g1 > f1) { gg=gg+g1; } 154 else { gg=gg+f1; } 155 } 156 if (pX > gg) 157 { 158 // Print("ChainCrit Works!"); 159 ChainCrit++; 160 pDelete(&p->root); 161 //x->root=NULL; 162 return; 163 } 164 int pF=pow_(f->lead); 165 166 if ((pX == pF) && (pF == phF)) 167 { 168 pLmDelete(&f->history); 169 f->history=pCopy(p->history); 170 } 171 } 172 173 while(f && p->root) 174 { 175 // Print("R"); 176 if (ReducePolyLead(p,f) == 0) break; 177 if (p->root) f=is_div_(F,p->root); 178 } 179 180 if (!p->root) 181 return; 182 183 InitHistory(p); 184 InitProl(p); 185 InitLead(p); 186 p->changed=1; 187 188 // pCleardenom(p->root); 189 pContent(p->root); 190 pTest(p->root); 185 Poly *f; 186 int g1,f1,gg; 187 188 if ((f=is_div_(F,p->lead))==NULL) return; 189 190 int pX=pow_(p->lead); 191 int phX=pow_(p->history); 192 193 if (pX!=phX) 194 { 195 int phF=pow_(f->history); 196 if (pX >= (phX+phF)) 197 { 198 pDelete(&p->root); 199 //p->root=NULL; 200 return; 201 } 202 203 /* poly p2=pInit(); 204 pLcm(p->history,f->history,p2); 205 pSetm(p2); 206 207 if (pLmCmp(p->root,p2) > 0) 208 { 209 pLmDelete(&p2); 210 pDelete(&p->root); 211 //p->root=NULL; 212 return; 213 } 214 215 pLmDelete(&p2); 216 */ 217 /* for(int i=0, gg=0 ; i<currRing->N;i++) 218 if ((g1=pGetExp(p->history,i+1)) > (f1=pGetExp(f->history,i+1))) 219 gg+=g1; 220 else gg+=f1; 221 222 if (pX > gg) 223 { 224 pDelete(&p->root); 225 //x->root=NULL; 226 return; 227 } 228 */ 229 int pF=pow_(f->lead); 230 231 if ((pX == pF) && (pF == phF)) 232 { 233 pLmDelete(&f->history); 234 f->history=pCopy(p->history); 235 } 236 } 237 238 //if (TEST_OPT_PROT) { PrintS("R"); mflush(); } 239 int old_size, count; 240 count=0; 241 while(f && p->root) 242 { 243 // Print("R"); 244 // if (TEST_OPT_PROT) { PrintS("R"); mflush(); } 245 #if 0 246 old_size=nSize(pGetCoeff(p->root)); 247 #endif 248 if (ReducePolyLead(p,f) == 0) break; 249 if (p->root!=NULL) 250 { 251 count++; 252 #if 0 253 if ((count>4) && (3<nSize(pGetCoeff(p->root))) 254 && (nSize(pGetCoeff(p->root))>old_size)) 255 { 256 pSimpleContent(p->root,old_size); 257 count=0; 258 } 259 #else 260 if (count>500) 261 { 262 kBucketClear(p->root_b,&p->root,&p->root_l); 263 pSimpleContent(p->root,2); 264 kBucketInit(p->root_b,p->root,p->root_l); 265 count=0; 266 //Print("."); 267 } 268 #endif 269 f=is_div_(F,p->root); 270 } 271 } 272 #if 1 273 if (p->root_b!=NULL) 274 { 275 kBucketClear(p->root_b,&p->root,&p->root_l); 276 kBucketDestroy(&p->root_b); 277 p->root_b=NULL; 278 } 279 #endif 280 281 if (!p->root) 282 return; 283 284 InitHistory(p); 285 InitProl(p); 286 InitLead(p); 287 p->changed=1; 288 289 pContent(p->root); 290 //pSimpleContent(p->root,-1); 291 pTest(p->root); 191 292 } 192 293 193 294 int ValidatePoly(Poly *x, TreeM *F) 194 295 { 195 Poly *f,*g; 196 int g1,f1; 197 198 if (x->root) return 1; 199 200 g=is_present(T,x->history); //it's a prolongation - do we have a parent ? 201 202 if (!g) return 0; //if not - kill him ! 203 204 poly lmX=pDivide(x->lead,g->root); 205 pSetCoeff(lmX,nInit(1)); 206 207 /* if ((f=is_div_(F,lmX)) != NULL) 208 { 209 int pX=pow_(lmX); 210 int phX=pow_(x->history); 211 212 if (pX!=phX) 213 { 214 int phF=pow_(f->history); 215 if (pX >= (phX+phF)) 216 { 217 pLmDelete(&lmX); 218 //x->root=NULL; 219 return 0; 220 } 221 222 for(int i=0, gg=0 ; i<currRing->N;i++) 223 if ((g1=pGetExp(x->history,i+1)) > (f1=pGetExp(f->history,i+1))) 224 gg+=g1; 225 else gg+=f1; 226 227 if (pX > gg) 228 { 229 pLmDelete(&lmX); 230 //x->root=NULL; 231 return 0; 232 } 233 int pF=pow_(f->root); 234 235 if ((pX == pF) && (pF == phF)) 236 f->history=x->history; 237 } 238 } 239 240 pLmDelete(&lmX); 241 242 */ x->root=pCopy(g->root); 243 244 x->root=pMult(lmX,x->root); 245 246 pTest(x->root); 247 248 x->prolonged=-1; 249 250 return 1; 296 Poly *f,*g; 297 int g1,f1; 298 299 if (x->root) return 1; 300 301 g=is_present(T,x->history); //it's a prolongation - do we have a parent ? 302 303 if (!g) return 0; //if not - kill him ! 304 305 poly lmX=pDivide(x->lead,g->root); 306 pGetCoeff(lmX)=nInit(1); 307 308 /* if ((f=is_div_(F,lmX)) != NULL) 309 { 310 int pX=pow_(lmX); 311 int phX=pow_(x->history); 312 313 if (pX!=phX) 314 { 315 int phF=pow_(f->history); 316 if (pX >= (phX+phF)) 317 { 318 pLmDelete(&lmX); 319 //x->root=NULL; 320 return 0; 321 } 322 323 for(int i=0, gg=0 ; i<currRing->N;i++) 324 if ((g1=pGetExp(x->history,i+1)) > (f1=pGetExp(f->history,i+1))) 325 gg+=g1; 326 else 327 gg+=f1; 328 329 if (pX > gg) 330 { 331 pLmDelete(&lmX); 332 return 0; 333 } 334 int pF=pow_(f->root); 335 336 if ((pX == pF) && (pF == phF)) 337 f->history=x->history; 338 } 339 } 340 341 pLmDelete(&lmX); 342 343 */ 344 x->root=pCopy(g->root); 345 x->root_l=g->root_l; 346 347 x->root=pMult(x->root,lmX); 348 349 pTest(x->root); 350 351 x->prolonged=-1; 352 353 return 1; 251 354 } 252 355 253 356 Poly *NewPoly(poly p) 254 357 { 255 Poly *beg=(Poly *)GCM(sizeof(Poly)); 256 257 beg->root=p;//(p == NULL ? pInit() : p); 258 beg->history=NULL;//pInit(); 259 beg->lead=NULL; 260 beg->mult=(char *)GCMA(sizeof(char)*2*offset); 261 262 for (int i=0; i < currRing->N; i++) 263 { 264 ClearMult(beg,i); 265 ClearProl(beg,i); 266 }; 267 268 beg->prolonged=-1; 269 270 return beg; 358 Poly *beg=(Poly *)GCM(sizeof(Poly)); 359 360 beg->root=p;//(p == NULL ? pInit() : p); 361 beg->root_b=NULL; 362 beg->root_l=0; 363 beg->history=NULL;//pInit(); 364 beg->lead=NULL; 365 beg->mult=(char *)GCMA(sizeof(char)*2*offset); 366 367 for (int i=0; i < currRing->N; i++) 368 { 369 ClearMult(beg,i); 370 ClearProl(beg,i); 371 }; 372 373 beg->prolonged=-1; 374 375 return beg; 271 376 } 272 377 273 378 void DestroyPoly(Poly *x) 274 379 { 275 276 277 278 279 380 pDelete(&x->root); 381 pDelete(&x->history); 382 if (x->lead) pDelete(&x->lead); 383 GCF(x->mult); 384 GCF(x); 280 385 } 281 386 282 387 void ControlProlong(Poly *x) 283 388 { 284 285 286 287 // 288 // 289 389 for (int i = 0; i< offset; i++) 390 { 391 (x->mult+offset)[i]&=~((x->mult)[i]); 392 // if (!GetMult(x,i) && !GetProl(x,i)) 393 // ProlVar(x,i); 394 } 290 395 } 291 396 292 397 void InitHistory(Poly *p) 293 398 { 294 if (p->history) pDelete(&p->history);295 296 399 if (p->history) pLmDelete(&p->history); 400 p->history=pLmInit(p->root); 401 p->changed=0; 297 402 } 298 403 299 404 void InitLead(Poly *p) 300 405 { 301 if (p->lead) pDelete(&p->lead);302 303 406 if (p->lead) pLmDelete(&p->lead); 407 p->lead=pLmInit(p->root); 408 p->prolonged=-1; 304 409 } 305 410 306 411 void InitProl(Poly *p) 307 412 { 308 413 memset(p->mult+offset,0,sizeof(char)*offset); 309 414 } 310 415 311 416 int GetMult(Poly *x,int i) 312 417 { 313 418 return x->mult[i/8] & Mask[i%8]; 314 419 } 315 420 316 421 void SetMult(Poly *x,int i) 317 422 { 318 423 x->mult[i/8] |= Mask[i%8]; 319 424 } 320 425 321 426 void ClearMult(Poly *x,int i) 322 427 { 323 428 x->mult[i/8] &= ~Mask[i%8]; 324 429 } 325 430 326 431 int GetProl(Poly *x, int i) 327 432 { 328 433 return (x->mult+offset)[i/8] & Mask[i%8]; 329 434 } 330 435 331 436 void SetProl(Poly *x, int i) 332 437 { 333 438 (x->mult+offset)[i/8] |= Mask[i%8]; 334 439 } 335 440 336 441 void ClearProl(Poly *x, int i) 337 442 { 338 443 (x->mult+offset)[i/8] &= ~Mask[i%8]; 339 444 } 340 445 341 446 int LengthCompare(poly p1,poly p2) 342 447 { 343 344 345 346 347 348 349 350 448 do 449 { 450 if (p1 == NULL) return 1; 451 if (p2 == NULL) return 0; 452 pIter(p1); 453 pIter(p2); 454 }while(p1 && p2); 455 return 1; 351 456 } 352 457 353 458 int ProlCompare(Poly *item1, Poly *item2) 354 459 { 355 switch(pLmCmp(item1->lead,item2->lead)) 356 { 357 case -1: 358 return 1; 359 360 case 1: 361 return 0; 362 363 default: 364 return LengthCompare(item1->root,item2->root); 365 } 460 switch(pLmCmp(item1->lead,item2->lead)) 461 { 462 case -1: 463 return 1; 464 465 case 1: 466 return 0; 467 468 default: 469 if ((item1->root_l<=0)||(item2->root_l<=0)) 470 return LengthCompare(item1->root,item2->root); 471 return item1->root_l<=item2->root_l; 472 } 366 473 } 367 474 368 475 void ProlVar(Poly *temp,int i) 369 476 { 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 // 386 387 477 Poly *Pr; 478 479 if (!GetProl(temp,i) && !GetMult(temp,i)) 480 { 481 Pr=NewPoly(); 482 SetProl(temp,i); 483 484 Pr->prolonged=i; 485 Pr->history=pLmInit(temp->history); 486 Pr->lead=pLmInit(temp->lead); 487 pIncrExp(Pr->lead,i+1); 488 pSetm(Pr->lead); 489 InitProl(temp); 490 491 Pr->changed=0; 492 // pTest(Pr->root); 493 InsertInCount(Q,Pr); 494 } 388 495 } 389 496 390 497 void DestroyListNode(ListNode *x) 391 498 { 392 393 499 DestroyPoly(x->info); 500 GCF(x); 394 501 } 395 502 396 503 ListNode* CreateListNode(Poly *x) 397 504 { 398 399 400 401 505 ListNode* ret=(ListNode *)GCM(sizeof(ListNode)); 506 ret->info=x; 507 ret->next=NULL; 508 return ret; 402 509 } 403 510 … … 405 512 Poly *FindMinList(jList *L) 406 513 { 407 408 409 410 411 412 413 414 415 min=&((*min)->next); 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 514 LI min=&(L->root); 515 LI l; 516 LCI xl; 517 Poly *x; 518 519 if (degree_compatible) 520 { 521 while ((*min) && ((*min)->info->root == NULL)) 522 min=&((*min)->next); 523 } 524 525 if (!(*min)) return NULL; 526 527 l=&((*min)->next); 528 529 while (*l) 530 { 531 if ((*l)->info->root != NULL) 532 { 533 if (ProlCompare((*l)->info,(*min)->info)) 534 min=l; 535 } 536 537 l=&((*l)->next); 538 } 539 x=(*min)->info; 540 xl=*min; 541 *min=(*min)->next; 542 GCF(xl); 543 544 return x; 438 545 } 439 546 440 547 void InsertInList(jList *x,Poly *y) 441 548 { 442 443 444 445 446 447 if (pLmCmp(y->lead,(*ix)->info->lead) == -1) 448 449 else 450 451 452 453 454 455 456 549 ListNode *ins; 550 LI ix=&(x->root); 551 552 while (*ix) 553 { 554 if (pLmCmp(y->lead,(*ix)->info->lead) == -1) 555 ix=(ListNode **)&((*ix)->next); 556 else 557 break; 558 } 559 560 ins=CreateListNode(y); 561 ins->next=(ListNode *)(*ix); 562 *ix=ins; 563 return; 457 564 } 458 565 459 566 void InsertInCount(jList *x,Poly *y) 460 567 { 461 462 463 464 465 466 467 568 ListNode *ins; 569 LI ix=&(x->root); 570 571 ins=CreateListNode(y); 572 ins->next=(ListNode *)(*ix); 573 *ix=ins; 574 return; 468 575 } 469 576 470 577 int ListGreatMoveOrder(jList *A,jList *B,poly x) 471 578 { 472 473 474 475 476 477 478 479 480 481 482 483 484 579 LCI y=A->root; 580 581 if (!y || pLmCmp(y->info->lead,x) < 0) return 0; 582 583 while(y && pLmCmp(y->info->lead,x) >= 0) 584 { 585 InsertInCount(B,y->info); 586 A->root=y->next; 587 GCF(y); 588 y=A->root; 589 } 590 591 return 1; 485 592 } 486 593 487 594 int ListGreatMoveDegree(jList *A,jList *B,poly x) 488 595 { 489 490 491 492 493 494 495 496 497 498 499 500 501 502 596 LCI y=A->root; 597 int pow_x=pow_(x); 598 599 if (!y || pow_(y->info->lead) <= pow_x) return 0; 600 601 while(y && pow_(y->info->lead) > pow_x) 602 { 603 InsertInCount(B,y->info); 604 A->root=y->next; 605 GCF(y); 606 y=A->root; 607 } 608 609 return 1; 503 610 } 504 611 505 612 int CountList(jList *Q) 506 613 { 507 508 509 510 511 512 513 514 515 516 614 int i=0; 615 LCI y=Q->root; 616 617 while(y) 618 { 619 i++; 620 y=y->next; 621 } 622 623 return i; 517 624 } 518 625 519 626 void NFListQ() 520 627 { 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 { 546 // 547 548 549 550 551 552 553 554 555 556 557 558 559 560 // 561 628 LCI ll; 629 int p,p1; 630 LI l; 631 632 do 633 { 634 if (!Q->root) break; 635 636 ll=Q->root; 637 638 p=pow_(Q->root->info->lead); 639 640 while (ll) 641 { 642 int ploc=pow_(ll->info->lead); 643 if (ploc < p) p=ploc; 644 ll=ll->next; 645 } 646 647 p1=1; 648 649 l=&(Q->root); 650 651 while (*l) 652 { 653 // Print("*"); 654 int ploc=pow_((*l)->info->lead); 655 656 if (ploc == p) 657 { 658 if (!ValidatePoly((*l)->info,G)) 659 { 660 ll=(*l); 661 *l=(*l)->next; 662 DestroyListNode(ll); 663 continue; 664 }; 665 666 (*l)->info->changed=0; 667 // Print("!"); 668 NFL((*l)->info,G); 562 669 // Print("$"); 563 564 565 566 567 568 569 570 571 572 573 574 575 576 // 670 if (!(*l)->info->root) 671 { 672 ll=(*l); 673 *l=(*l)->next; 674 DestroyListNode(ll); 675 continue; 676 }; 677 p1=0; 678 } 679 680 l=&((*l)->next); 681 } 682 }while(p1); 683 // Print("\n"); 577 684 } 578 685 … … 580 687 void ForEachPNF(jList *x,int i) 581 688 { 582 583 584 585 586 587 588 689 LCI y=x->root; 690 691 while(y) 692 { 693 if (pow_(y->info->root) == i) PNF(y->info,G); 694 y=y->next; 695 } 589 696 } 590 697 591 698 void ForEachControlProlong(jList *x) 592 699 { 593 594 595 596 597 598 599 700 LCI y=x->root; 701 702 while(y) 703 { 704 ControlProlong(y->info); 705 y=y->next; 706 } 600 707 } 601 708 602 709 void DestroyList(jList *x) 603 710 { 604 605 606 607 608 609 610 611 612 613 614 711 LCI y=x->root,z; 712 713 while(y) 714 { 715 z=y->next; 716 DestroyPoly(y->info); 717 GCF(y); 718 y=z; 719 } 720 721 GCF(x); 615 722 } 616 723 617 724 Poly* is_present(jList *F,poly x) 618 725 { 619 620 621 622 623 624 625 726 LCI iF=F->root; 727 while(iF) 728 if (pLmCmp(iF->info->root,x) == 0) 729 return iF->info; 730 else iF=iF->next; 731 732 return NULL; 626 733 } 627 734 628 735 int GB_length() 629 736 { 630 631 632 633 while(iT) 634 635 636 637 638 639 640 737 LCI iT=T->root; 738 int l=0; 739 740 while(iT) 741 { 742 if (pow_(iT->info->lead) == pow_(iT->info->history)) 743 ++l; 744 iT=iT->next; 745 } 746 747 return l; 641 748 } 642 749 … … 645 752 NodeM* create() 646 753 { 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 754 NodeM *y; 755 756 if (FreeNodes == NULL) 757 { 758 y=(NodeM *)GCM(sizeof(NodeM)); 759 } 760 else 761 { 762 y=FreeNodes; 763 FreeNodes=FreeNodes->left; 764 } 765 766 y->left=y->right=NULL; 767 y->ended=NULL; 768 return y; 662 769 } 663 770 664 771 void DestroyFreeNodes() 665 772 { 666 667 668 669 670 671 672 773 NodeM *y; 774 775 while((y=FreeNodes)!=NULL) 776 { 777 FreeNodes=FreeNodes->left; 778 GCF(y); 779 } 673 780 } 674 781 675 782 static void go_right(NodeM *current,poly_function disp) 676 783 { 677 678 679 680 681 682 784 if (current) 785 { 786 go_right(current->left,disp); 787 if (current->ended) disp(current->ended); 788 go_right(current->right,disp); 789 } 683 790 } 684 791 685 792 void ForEach(TreeM *t,poly_function disp) 686 793 { 687 794 go_right(t->root,disp); 688 795 } 689 796 690 797 void DestroyTree(NodeM *G) 691 798 { 692 693 694 695 696 697 698 799 if (G) 800 { 801 DestroyTree(G->left); 802 DestroyTree(G->right); 803 G->left=FreeNodes; 804 FreeNodes=G; 805 } 699 806 } 700 807 701 808 void Define(TreeM **G) 702 809 { 703 704 810 *G=(TreeM *)GCM(sizeof(TreeM)); 811 (*G)->root=create(); 705 812 } 706 813 … … 708 815 { 709 816 710 711 712 713 714 715 817 if (pow_(m2) == 0 && pow_(m1)) return 0; 818 819 for(int k=from; k < currRing->N; k++) 820 if (pGetExp(m1,k+1) < pGetExp(m2,k+1)) return 0; 821 822 return 1; 716 823 } 717 824 718 825 void div_l(poly item, NodeM *x,int from) 719 826 { 720 721 { 722 723 724 725 726 727 728 729 827 if (x && !temp_l) 828 { 829 div_l(item,x->left,from); 830 if ((x->ended) && sp_div(item,x->ended->root,from)) 831 { 832 temp_l=x->ended; 833 return; 834 }; 835 div_l(item,x->right,from); 836 } 730 837 } 731 838 732 839 Poly* is_div_upper(poly item, NodeM *x,int from) 733 840 { 734 735 736 841 temp_l=NULL; 842 div_l(item,x,from); 843 return temp_l; 737 844 } 738 845 739 846 Poly* is_div_(TreeM *tree, poly item) 740 847 { 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 if (!curr->left) 759 760 if (curr->right) 761 762 763 };764 765 766 767 }; 768 769 770 771 772 773 774 775 776 777 848 int power_tmp,i,i_con=currRing->N-1; 849 NodeM *curr=tree->root; 850 851 if (!curr) return NULL; 852 if (pow_(item) == 0) return NULL; 853 854 for ( ; i_con>=0 && !pGetExp(item,i_con+1) ; i_con--) 855 ; 856 857 for (i=0; i <= i_con ; i++) 858 { 859 power_tmp=pGetExp(item,i+1); 860 861 while (power_tmp) 862 { 863 if (curr->ended) return curr->ended; 864 865 if (!curr->left) 866 { 867 if (curr->right) 868 return is_div_upper(item,curr->right,i); //?????? 869 return NULL; 870 } 871 872 curr=curr->left; 873 power_tmp--; 874 } 875 876 if (curr->ended) return curr->ended; 877 878 if (!curr->right) return NULL; 879 880 curr=curr->right; 881 } 882 883 if (curr->ended) return curr->ended; 884 else return NULL; 778 885 } 779 886 780 887 static void ClearMultiplicative(NodeM *xx,int i) 781 888 { 782 783 784 while (xx->left) 785 786 787 788 789 790 791 792 793 794 795 889 if (!xx) return; 890 891 while (xx->left) 892 { 893 ClearMultiplicative(xx->right, i); 894 xx = xx->left; 895 } 896 if ((xx->ended) && (GetMult(xx->ended,i))) 897 { 898 ClearMult(xx->ended,i); 899 ProlVar(xx->ended,i); 900 } 901 else 902 ClearMultiplicative(xx->right,i); 796 903 } 797 904 //====================================================== … … 800 907 int power_tmp,i,i_con=currRing->N-1; 801 908 NodeM *curr=(*tree)->root; 802 909 803 910 for ( ; (i_con>=0) && !pGetExp(item->root,i_con+1) ; i_con--) 804 911 SetMult(item,i_con); 805 912 806 913 for (i = 0; i<= i_con; i++) 807 914 //<= … … 814 921 { 815 922 if (!curr->left) 816 { 923 { 817 924 SetMult(item,i); 818 925 ClearMultiplicative(curr->right,i); … … 838 945 void Initialization(char *Ord) 839 946 { 840 ProdCrit=0;841 ChainCrit=0;842 947 offset=(currRing->N % 8 == 0) ? (currRing->N/8)*8 : (currRing->N/8+1)*8; 843 948 if (strstr(Ord,"dp\0") || strstr(Ord,"Dp\0")) 844 949 { 845 950 degree_compatible=1; 951 jDeg=pDeg; 846 952 ListGreatMove=ListGreatMoveDegree; 847 953 } … … 849 955 { 850 956 degree_compatible=0; 957 jDeg=pTotaldegree; 851 958 ListGreatMove=ListGreatMoveOrder; 852 959 } 853 960 854 961 Define(&G); 855 962 }; … … 866 973 void Q2TG() 867 974 { 868 LCI t; 869 Poly *x; 870 871 while (Q->root) 975 LCI t; 976 Poly *x; 977 978 while (Q->root) 979 { 980 t=Q->root; 981 x=t->info; 982 insert_(&G,x); 983 InsertInList(T,x); 984 Q->root=t->next; 985 GCF(t); 986 } 987 } 988 989 int ComputeBasis(jList *_T,jList *_Q) 990 { 991 int gb_l,i,ret_value=1; 992 993 T=_T; Q=_Q; 994 995 // Debug(); 996 997 while((h=FindMinList(Q))!=NULL) 998 { 999 // Print("New element\n"); 1000 // Debug(); 1001 1002 if (!degree_compatible) 872 1003 { 873 t=Q->root; 874 x=t->info; 875 insert_(&G,x); 876 InsertInList(T,x); 877 Q->root=t->next; 878 GCF(t); 1004 if (!ValidatePoly(h,G)) 1005 { 1006 DestroyPoly(h); 1007 continue; 1008 } 1009 1010 h->changed=0; 1011 1012 NFL(h,G); 1013 1014 if (!h->root) 1015 { 1016 DestroyPoly(h); 1017 continue; 1018 } 879 1019 } 880 } 881 882 int ComputeBasis(jList *_T, jList *_Q) 883 { 884 int gb_l,i,ret_value=1; 885 886 T=_T; Q=_Q; 887 888 // Debug(); 889 890 while( (h=FindMinList(Q)) != NULL ) 891 { 892 893 // Print("New element\n"); 894 // Debug(); 895 896 if (!degree_compatible) 897 { 898 if (!ValidatePoly(h,G)) 899 { 900 DestroyPoly(h); 901 continue; 902 }; 903 904 h->changed=0; 905 906 NFL(h,G); 907 908 if (!h->root) 909 { 910 DestroyPoly(h); 911 continue; 912 }; 913 } 914 915 if (h->root) 916 { 917 if (pIsConstant(h->root)) 918 { 919 // WarnS("Constant in basis\n"); 920 return 0; 921 } 922 923 if (h->changed && ListGreatMove(T,Q,h->root)) 924 { 925 // Print("<-\n"); 926 DestroyTree(G->root); 927 G->root=create(); 928 T2G(); 929 } 930 } 931 932 // Print("PNF\n"); 933 PNF(h,G); 934 if (TEST_OPT_PROT) 935 { 936 Print("s%d",pow_(h->root)); 937 } 938 insert_(&G,h); 939 InsertInList(T,h); 940 941 // Print("For each PNF\n"); 942 if (degree_compatible) 943 ForEachPNF(T,pow_(h->root)); 944 945 // Print("Control of prolongations\n"); 946 if (h->changed) 947 ForEachControlProlong(T); 948 else 949 ControlProlong(h); 950 951 // Debug(); 952 953 // Print("NFListQ\n"); 954 if (degree_compatible) 955 NFListQ(); 956 //Debug(); 957 } 958 959 // gb_l=GB_length(); 960 961 if (TEST_OPT_PROT) 962 { 963 Print("\nLength of Janet basis: %d", CountList(T)); 964 Print("\nproduct criterion:%d chain criterion:%d\n", ProdCrit, ChainCrit); 965 // Print("Length of Groebner basis: %d\n",gb_l); 966 } 967 968 DestroyTree(G->root); 969 GCF(G); 970 DestroyFreeNodes(); 971 972 return 1; 1020 1021 if (h->root) 1022 { 1023 if (pIsConstant(h->root)) 1024 { 1025 WarnS("Constant in basis\n"); 1026 return 0; 1027 } 1028 1029 if (h->changed && ListGreatMove(T,Q,h->root)) 1030 { 1031 // Print("<-\n"); 1032 DestroyTree(G->root); 1033 G->root=create(); 1034 T2G(); 1035 } 1036 } 1037 1038 // Print("PNF\n"); 1039 PNF(h,G); 1040 // Print("{%d}\n",pow_(h->root)); 1041 insert_(&G,h); 1042 InsertInList(T,h); 1043 1044 // Print("For each PNF\n"); 1045 if (degree_compatible) 1046 ForEachPNF(T,pow_(h->root)); 1047 1048 // Print("Control of prolongations\n"); 1049 if (h->changed) 1050 ForEachControlProlong(T); 1051 else 1052 ControlProlong(h); 1053 1054 // Debug(); 1055 1056 // Print("NFListQ\n"); 1057 if (degree_compatible) 1058 NFListQ(); 1059 //Debug(); 1060 } 1061 1062 // gb_l=GB_length(); 1063 1064 Print("Length of Janet basis: %d\n",CountList(T)); 1065 // Print("Length of Groebner basis: %d\n",gb_l); 1066 1067 DestroyTree(G->root); 1068 GCF(G); 1069 DestroyFreeNodes(); 1070 1071 return 1; 973 1072 } 974 1073 -
Singular/janet.h
r941bf9 r5a66d0 2 2 #define __JANET_INTERFACE__ 3 3 4 #include "febase.h" 5 #include "polys.h" 6 #include "numbers.h" 7 #include "ring.h" 8 #include "ideals.h" 9 #include "subexpr.h" 10 #include "longrat.h" 11 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 #include <time.h> 16 #include <omalloc.h> 4 #include "structs.h" 17 5 18 6 #define GCM(sz) omAlloc((sz)) 19 7 #define GCMA(sz) omAlloc((sz)) 20 #define GCR(x,y) omRealloc((x),(y))21 8 #define GCF(x) omFree((x)) 22 23 #if (defined(__CYGWIN__))24 #include <ctype.h>25 #endif26 #include <stdarg.h>27 9 28 10 #define ListNode struct LISTNODE … … 30 12 #define NodeM struct NODEM 31 13 32 static int Mask[8]={0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};33 34 14 typedef struct 35 15 { 36 poly root; //poly for parent, NULL for prol 37 poly history; //parent 38 poly lead; //leading monomial for prolongation 39 char *mult; //[multi].[prol] 40 int changed; 41 int prolonged; //number of prolonged variable for prolongation, otherwise = -1; 16 poly root; //poly for parent, NULL for prol 17 kBucket_pt root_b; 18 int root_l; 19 poly history; //parent 20 poly lead; //leading monomial for prolongation 21 char *mult; //[multi].[prol] 22 int changed; 23 int prolonged; //number of prolonged variable for prolongation, otherwise = -1; 42 24 } Poly; 43 25 … … 69 51 typedef ListNode** LI; 70 52 71 //------GLOBALS-------72 static int m_s,v_s,vectorized,VarN1,offset;73 static jList *T,*Q;74 75 static TreeM *G;76 77 static Poly *phD;78 static NodeM *FreeNodes;79 80 53 //-------FUNCS---------- 81 54 Poly* FindMinList(jList *); … … 88 61 Poly* NewPoly(poly p=NULL); 89 62 void DestroyPoly(); 90 91 static int degree_compatible;92 63 93 64 void NFL(Poly *,TreeM *); … … 111 82 int ProlCompare(Poly *, Poly *); 112 83 int ValidatePoly(Poly *,TreeM *); 113 static int (*ListGreatMove)(jList *,jList *,poly);114 84 int ListGreatMoveDegree(jList *,jList *,poly); 115 85 int ListGreatMoveOrder(jList *,jList *,poly); … … 125 95 void DestroyListNode(ListNode *x); 126 96 void DestroyFreeNodes(); 97 127 98 BOOLEAN jjJanetBasis(leftv res, leftv v); 99 BOOLEAN jjStdJanetBasis(leftv res, leftv v,int flag); // 0: JB, 1: SB 100 128 101 #endif //JANET_INTERFACE -
Singular/wrapper.cc
r941bf9 r5a66d0 1 #include <string.h> 1 2 #include "mod2.h" 3 #include "febase.h" 4 #include "polys.h" 5 #include "kstd1.h" 6 #include "subexpr.h" 7 #include "ideals.h" 8 #include "ring.h" 2 9 #include "janet.h" 3 #include "kstd1.h"4 #include "ipid.h"5 10 6 11 #define pow_(x) pTotaldegree((x)) … … 10 15 extern void Initialization(char *); 11 16 17 BOOLEAN jInitBasis(ideal v, jList **TT,jList **QQ) 18 { 19 if (pOrdSgn==-1) 20 { 21 WerrorS("janet only for well-orderings"); 22 return TRUE; 23 } 24 25 Initialization(rOrdStr(currRing)); 26 27 jList *Q=(jList *)GCM(sizeof(jList)); 28 Q->root=NULL; 29 30 jList *T=(jList *)GCM(sizeof(jList)); 31 T->root=NULL; 32 33 for (int i=0; i < v->idelems(); i++) 34 { 35 if (v->m[i]!=NULL) 36 { 37 Poly *beg=NewPoly(pCopy(v->m[i])); 38 39 InitHistory(beg); 40 InitProl(beg); 41 InitLead(beg); 42 43 InsertInCount(Q,beg); 44 } 45 } 46 47 BOOLEAN r= !(ComputeBasis(T,Q)); 48 *TT=T; 49 *QQ=Q; 50 return r; 51 } 52 53 BOOLEAN jjStdJanetBasis(leftv res, leftv v, int flag) 54 { 55 ideal result; 56 int dpO; 57 58 jList *T; 59 jList *Q; 60 ideal I=(ideal)v->Data(); 61 BOOLEAN is_zero=TRUE; 62 for (int i=0; i < I->idelems(); i++) 63 { 64 if ((I->m[i]!=NULL)&& (pIsConstant(I->m[i]))) 65 { 66 goto zero; 67 } 68 else 69 is_zero=FALSE; 70 } 71 if (is_zero) 72 goto zero; 73 if (!jInitBasis(I,&T,&Q)) 74 { 75 dpO=(strstr(rOrdStr(currRing),"dp")!=NULL); 76 int ideal_length; 77 if (flag==1) 78 ideal_length= dpO ? GB_length() : CountList(T); 79 else 80 ideal_length=CountList(T); 81 82 result=idInit(ideal_length,1); 83 84 int ideal_index=0; 85 86 LCI iT=T->root; 87 88 while(iT) 89 { 90 pTest(iT->info->root); 91 if ((flag==1) && dpO) 92 { 93 //if (pow_(iT->info->lead) == pow_(iT->info->history)) 94 if (pDeg(iT->info->lead) == pDeg(iT->info->history)) 95 { 96 result->m[ideal_length-ideal_index-1]=pCopy(iT->info->root); 97 if (!nGreaterZero(pGetCoeff(iT->info->root))) 98 result->m[ideal_length-ideal_index-1] 99 =pNeg(result->m[ideal_length-ideal_index-1]); 100 101 ideal_index++; 102 } 103 } 104 else 105 { 106 result->m[ideal_length-ideal_index-1]=pCopy(iT->info->root); 107 if (!nGreaterZero(pGetCoeff(iT->info->root))) 108 result->m[ideal_length-ideal_index-1] 109 =pNeg(result->m[ideal_length-ideal_index-1]); 110 111 ideal_index++; 112 } 113 iT=iT->next; 114 } 115 } 116 117 if ((flag==1) && (!dpO)) 118 { 119 //Print ("interred\n"); 120 result=kInterRed(result); 121 idSkipZeroes(result); 122 } 123 res->data = (char *)result; 124 res->rtyp = IDEAL_CMD; 125 126 DestroyList(Q); 127 DestroyList(T); 128 129 return FALSE; 130 131 zero: 132 result=idInit(1,1); 133 if (!is_zero) result->m[0]=pOne(); 134 res->data = (char *)result; 135 res->rtyp = IDEAL_CMD; 136 return FALSE; 137 } 138 12 139 BOOLEAN jjJanetBasis(leftv res, leftv v) 13 140 { 14 Initialization(rOrdStr(currRing)); 15 16 jList *Q=(jList *)GCM(sizeof(jList)); 17 Q->root=NULL; 18 19 jList *T=(jList *)GCM(sizeof(jList)); 20 T->root=NULL; 21 22 ideal input = (ideal)(v->Data()); 23 /* the second arg is an integer, defining what to return: 24 0 (default case) = Groebner basis, 25 1 = Janet basis. 26 */ 27 int doJanet; 28 if ((v->next!=NULL) && (v->next->Typ() == INT_CMD)) 29 { 30 doJanet = (int)v->next->CopyD(); 31 // Print("doJanet:%d\n",doJanet); 32 } 33 else 34 { 35 doJanet = 0; 36 } 37 ideal result; 38 int dpO = !doJanet; /* compatibility */ 39 40 for (int i=0; i < input->idelems(); i++) 41 { 42 /* nonzero constant check */ 43 if (pIsConstant(input->m[i])) { goto zero; } 44 Poly *beg=NewPoly(pCopy(input->m[i])); 45 InitHistory(beg); 46 InitProl(beg); 47 InitLead(beg); 48 InsertInCount(Q,beg); 49 } 50 51 if (ComputeBasis(T,Q)) 52 { 53 // dpO=(strstr(rOrdStr(currRing),"dp")!=NULL); 54 int ideal_length= dpO ? GB_length() : CountList(T); 55 result=idInit(ideal_length,1); 56 int ideal_index=0; 57 58 LCI iT=T->root; 59 60 while (iT) 61 { 62 #ifdef PDEBUG 63 pTest(iT->info->root); 64 #endif 65 if (!(dpO && (pow_(iT->info->lead) != pow_(iT->info->history)))) 66 { 67 result->m[ideal_length-ideal_index-1]=pCopy(iT->info->root); 68 if (!nGreaterZero(pGetCoeff(iT->info->root))) 69 { 70 result->m[ideal_length-ideal_index-1]=pNeg(result->m[ideal_length-ideal_index-1]); 71 } 72 ideal_index++; 73 } 74 iT=iT->next; 75 } 76 } 77 else 78 { 79 zero: 80 result=idInit(1,1); 81 result->m[0]=pOne(); 82 } 83 84 /* now we make the basis shorter... getting Groebner */ 85 if (!doJanet) /* if (!dpO) */ 86 { 87 if (TEST_OPT_PROT) 88 { 89 Print ("interred\n"); 90 } 91 result=kInterRed(result); 92 idSkipZeroes(result); 93 } 94 res->data = (char *)result; 95 res->rtyp = v->Typ(); 96 if (!doJanet) setFlag(res,FLAG_STD); 97 98 DestroyList(Q); 99 DestroyList(T); 100 101 return FALSE; 141 return jjStdJanetBasis(res,v,0); 102 142 }
Note: See TracChangeset
for help on using the changeset viewer.