Changeset 5812c69 in git for Singular/fglmhom.cc
- Timestamp:
- Sep 24, 1998, 11:59:51 AM (26 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 56c52a7879fbc6de62cefba1da86b2edf2aadd4c
- Parents:
- 073d2edeb03013a5c6ed0913687b024305a1427d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/fglmhom.cc
r073d2e r5812c69 1 1 // emacs edit mode for this file is -*- C++ -*- 2 // $Id: fglmhom.cc,v 1.1 0 1998-06-15 14:30:06Singular Exp $2 // $Id: fglmhom.cc,v 1.11 1998-09-24 09:59:39 Singular Exp $ 3 3 4 4 /**************************************** 5 5 * Computer Algebra System SINGULAR * 6 6 ****************************************/ 7 /* 7 /* 8 8 * ABSTRACT - The FGLM-Algorithm extended for homogeneous ideals. 9 9 * Calculates via the hilbert-function a groebner basis. … … 18 18 #include "tok.h" 19 19 #include "structs.h" 20 #include "subexpr.h" 20 #include "subexpr.h" 21 21 #include "polys.h" 22 22 #include "ideals.h" … … 62 62 homogElem() : v(), dv(), basis(0), destbasis(0), inDest(FALSE) {} 63 63 homogElem( poly m, int b, BOOLEAN ind ) : 64 basis(b), inDest(ind) 64 basis(b), inDest(ind) 65 65 { 66 67 66 mon.dm= m; 67 mon.sm= NULL; 68 68 } 69 69 }; 70 70 71 struct homogData 71 struct homogData 72 72 { 73 73 ideal sourceIdeal; … … 83 83 int overall; // nur zum testen. 84 84 int numberofdestbasismonoms; 85 // homogData() : sourceHeads(NULL), numSourceHeads(0), monlist(NULL), 86 // 85 // homogData() : sourceHeads(NULL), numSourceHeads(0), monlist(NULL), 86 // numMonoms(0), basisSize(0) {} 87 87 }; 88 88 89 89 int 90 hfglmNextdegree( intvec * source, ideal current, int & deg ) 90 hfglmNextdegree( intvec * source, ideal current, int & deg ) 91 91 { 92 92 int numelems; 93 93 intvec * newhilb = hHstdSeries( current, NULL, currQuotient ); 94 94 95 loop 95 loop 96 96 { 97 if ( deg < newhilb->length() ) 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 if (numelems != 0) 115 116 117 } 97 if ( deg < newhilb->length() ) 98 { 99 if ( deg < source->length() ) 100 numelems= (*newhilb)[deg]-(*source)[deg]; 101 else 102 numelems= (*newhilb)[deg]; 103 } 104 else 105 { 106 if (deg < source->length()) 107 numelems= -(*source)[deg]; 108 else 109 { 110 deg= 0; 111 return 0; 112 } 113 } 114 if (numelems != 0) 115 return numelems; 116 deg++; 117 } 118 118 delete newhilb; 119 119 } 120 120 121 void 121 void 122 122 generateMonoms( poly m, int var, int deg, homogData * dat ) 123 123 { 124 124 if ( var == pVariables ) { 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 if ( !inDest ) 147 148 149 150 151 for ( k= dat->monlistmax; k < (dat->monlistmax+dat->monlistblock); k++ ) 152 153 154 155 156 157 158 159 160 161 162 163 164 125 BOOLEAN inSource = FALSE; 126 BOOLEAN inDest = FALSE; 127 poly mon = pCopy( m ); 128 pSetExp( mon, var, deg ); 129 pSetm( mon ); 130 ++dat->overall; 131 int i; 132 for ( i= dat->numSourceHeads - 1; (i >= 0) && (inSource==FALSE); i-- ) { 133 if ( pDivisibleBy( dat->sourceHeads[i].dm, mon ) ) { 134 inSource= TRUE; 135 } 136 } 137 for ( i= dat->numDestPolys - 1; (i >= 0) && (inDest==FALSE); i-- ) { 138 if ( pDivisibleBy( (dat->destIdeal->m)[i], mon ) ) { 139 inDest= TRUE; 140 } 141 } 142 if ( (!inSource) || (!inDest) ) { 143 int basis = 0; 144 if ( !inSource ) 145 basis= ++(dat->basisSize); 146 if ( !inDest ) 147 ++dat->numberofdestbasismonoms; 148 if ( dat->numMonoms == dat->monlistmax ) { 149 dat->monlist= (homogElem * )ReAlloc( dat->monlist, (dat->monlistmax)*sizeof( homogElem ), (dat->monlistmax+dat->monlistblock) * sizeof( homogElem ) ); 150 int k; 151 for ( k= dat->monlistmax; k < (dat->monlistmax+dat->monlistblock); k++ ) 152 dat->monlist[k].homogElem(); 153 dat->monlistmax+= dat->monlistblock; 154 } 155 dat->monlist[dat->numMonoms]= homogElem( mon, basis, inDest ); 156 dat->numMonoms++; 157 if ( inSource && ! inDest ) PROT( "\\" ); 158 if ( ! inSource && inDest ) PROT( "/" ); 159 if ( ! inSource && ! inDest ) PROT( "." ); 160 } 161 else { 162 pDelete( & mon ); 163 } 164 return; 165 165 } 166 166 else { 167 168 169 170 171 172 173 174 167 poly newm = pCopy( m ); 168 while ( deg >= 0 ) { 169 generateMonoms( newm, var+1, deg, dat ); 170 pIncrExp( newm, var ); 171 pSetm( newm ); 172 deg--; 173 } 174 pDelete( & newm ); 175 175 } 176 176 return; … … 178 178 179 179 void 180 mapMonoms( ring oldRing, homogData & dat ) 180 mapMonoms( ring oldRing, homogData & dat ) 181 181 { 182 182 int * vperm = (int *)Alloc( (currRing->N + 1)*sizeof(int) ); … … 185 185 int s; 186 186 for ( s= dat.numMonoms - 1; s >= 0; s-- ) { 187 // 187 // dat.monlist[s].mon.sm= pPermPoly( dat.monlist[s].mon.dm, vperm, currRing->N, NULL, 0 ); 188 188 // obachman: changed the folowing to reflect the new calling interface of 189 189 // pPermPoly -- Tim please check whether this is correct! 190 dat.monlist[s].mon.sm= pPermPoly( dat.monlist[s].mon.dm, vperm, oldRing, NULL, 0 ); 190 dat.monlist[s].mon.sm= pPermPoly( dat.monlist[s].mon.dm, vperm, oldRing, NULL, 0 ); 191 191 } 192 192 } 193 193 194 194 void 195 getVectorRep( homogData & dat ) 195 getVectorRep( homogData & dat ) 196 196 { 197 197 // Calculate the NormalForms 198 198 int s; 199 199 for ( s= 0; s < dat.numMonoms; s++ ) { 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 200 if ( dat.monlist[s].inDest == FALSE ) { 201 fglmVector v; 202 if ( dat.monlist[s].basis == 0 ) { 203 v= fglmVector( dat.basisSize ); 204 // now the monom is in L(source) 205 PROT( "(" ); 206 poly nf = kNF( dat.sourceIdeal, NULL, dat.monlist[s].mon.sm ); 207 PROT( ")" ); 208 poly temp = nf; 209 while (temp != NULL ) { 210 int t; 211 for ( t= dat.numMonoms - 1; t >= 0; t-- ) { 212 if ( dat.monlist[t].basis > 0 ) { 213 if ( pEqual( dat.monlist[t].mon.sm, temp ) ) { 214 number coeff= nCopy( pGetCoeff( temp ) ); 215 v.setelem( dat.monlist[t].basis, coeff ); 216 } 217 } 218 } 219 pIter(temp); 220 } 221 pDelete( & nf ); 222 } 223 else { 224 PROT( "." ); 225 v= fglmVector( dat.basisSize, dat.monlist[s].basis ); 226 } 227 dat.monlist[s].v= v; 228 } 229 229 } 230 230 } 231 231 232 232 void 233 remapVectors( ring oldring, homogData & dat ) 233 remapVectors( ring oldring, homogData & dat ) 234 234 { 235 235 nSetMap( oldring->ch, oldring->parameter, oldring->P, oldring->minpoly ); 236 236 int s; 237 237 for ( s= dat.numMonoms - 1; s >= 0; s-- ) { 238 239 240 241 242 243 244 245 246 238 if ( dat.monlist[s].inDest == FALSE ) { 239 int k; 240 fglmVector newv( dat.basisSize ); 241 for ( k= dat.basisSize; k > 0; k-- ){ 242 number newnum= nMap( dat.monlist[s].v.getelem( k ) ); 243 newv.setelem( k, newnum ); 244 } 245 dat.monlist[s].dv= newv; 246 } 247 247 } 248 248 } 249 249 250 250 void 251 gaussreduce( homogData & dat, int maxnum, int BS ) 251 gaussreduce( homogData & dat, int maxnum, int BS ) 252 252 { 253 253 int s; … … 256 256 int destbasisSize = 0; 257 257 gaussReducer gauss( dat.basisSize ); 258 258 259 259 for ( s= 0; (s < dat.numMonoms) && (found < maxnum); s++ ) { 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 while ( dat.monlist[l].destbasis != k ) 276 277 278 279 280 281 282 283 // 284 285 286 287 288 289 290 291 292 293 294 295 260 if ( dat.monlist[s].inDest == FALSE ) { 261 if ( gauss.reduce( dat.monlist[s].dv ) == FALSE ) { 262 destbasisSize++; 263 dat.monlist[s].destbasis= destbasisSize; 264 gauss.store(); 265 PROT( "." ); 266 } 267 else { 268 fglmVector p= gauss.getDependence(); 269 poly result = pCopy( dat.monlist[s].mon.dm ); 270 pSetCoeff( result, nCopy( p.getconstelem( p.size() ) ) ); 271 int l = 0; 272 int k; 273 for ( k= 1; k < p.size(); k++ ) { 274 if ( ! p.elemIsZero( k ) ) { 275 while ( dat.monlist[l].destbasis != k ) 276 l++; 277 poly temp = pCopy( dat.monlist[l].mon.dm ); 278 pSetCoeff( temp, nCopy( p.getconstelem( k ) ) ); 279 result= pAdd( result, temp ); 280 } 281 } 282 if ( ! nGreaterZero( pGetCoeff( result ) ) ) result= pNeg( result ); 283 // PROT2( "(%s)", pString( result ) ); 284 PROT( "+" ); 285 found++; 286 (dat.destIdeal->m)[dat.numDestPolys]= result; 287 dat.numDestPolys++; 288 if ( IDELEMS(dat.destIdeal) == dat.numDestPolys ) { 289 pEnlargeSet( & dat.destIdeal->m, IDELEMS( dat.destIdeal ), BS ); 290 IDELEMS( dat.destIdeal )+= BS; 291 } 292 293 } 294 295 } 296 296 } 297 297 PROT2( "(%i", s ); … … 313 313 ring sourceRing = currRing; 314 314 315 intvec * hilb = hHstdSeries( sourceIdeal, NULL, currQuotient ); 315 intvec * hilb = hHstdSeries( sourceIdeal, NULL, currQuotient ); 316 316 int s; 317 317 dat.sourceIdeal= sourceIdeal; 318 318 dat.sourceHeads= (doublepoly *)Alloc( IDELEMS( sourceIdeal ) * sizeof( doublepoly ) ); 319 319 for ( s= IDELEMS( sourceIdeal ) - 1; s >= 0; s-- ) { 320 320 dat.sourceHeads[s].sm= pHead( (sourceIdeal->m)[s] ); 321 321 } 322 322 dat.numSourceHeads= IDELEMS( sourceIdeal ); … … 329 329 nSetMap( sourceRing->ch, sourceRing->parameter, sourceRing->P, sourceRing->minpoly ); 330 330 for ( s= IDELEMS( sourceIdeal ) - 1; s >= 0; s-- ) { 331 331 dat.sourceHeads[s].dm= pPermPoly( dat.sourceHeads[s].sm, vperm, sourceRing, NULL, 0 ); 332 332 } 333 333 … … 336 336 337 337 while ( (numGBelems= hfglmNextdegree( hilb, dat.destIdeal, deg )) != 0 ) { 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 338 int num = 0; // the number of monoms of degree deg 339 PROT2( "deg= %i ", deg ); 340 PROT2( "num= %i\ngen>", numGBelems ); 341 dat.monlistblock= 512; 342 dat.monlistmax= dat.monlistblock; 343 dat.monlist= (homogElem *)Alloc( dat.monlistmax*sizeof( homogElem ) ); 344 int j; 345 for ( j= dat.monlistmax - 1; j >= 0; j-- ) dat.monlist[j].homogElem(); 346 dat.numMonoms= 0; 347 dat.basisSize= 0; 348 dat.overall= 0; 349 dat.numberofdestbasismonoms= 0; 350 351 poly start= pOne(); 352 generateMonoms( start, 1, deg, &dat ); 353 pDelete( & start ); 354 355 PROT2( "(%i/", dat.basisSize ); 356 PROT2( "%i)\nvec>", dat.overall ); 357 // switch to sourceRing and map monoms 358 rSetHdl( sourceRingHdl, TRUE ); 359 mapMonoms( destRing, dat ); 360 getVectorRep( dat ); 361 362 // switch to destination Ring and remap the vectors 363 rSetHdl( destRingHdl, TRUE ); 364 remapVectors( sourceRing, dat ); 365 366 PROT( "<\nred>" ); 367 // now do gaussian reduction 368 gaussreduce( dat, numGBelems, groebnerBS ); 369 370 Free( (ADDRESS)dat.monlist, dat.monlistmax*sizeof( homogElem ) ); 371 PROT( "<\n" ); 372 372 } 373 373 PROT( "\n" );
Note: See TracChangeset
for help on using the changeset viewer.