My Project  UNKNOWN_GIT_VERSION
Data Structures | Macros | Functions
fglm.h File Reference
#include "kernel/polys.h"
#include "kernel/structs.h"
#include "kernel/fglm/fglmvec.h"

Go to the source code of this file.

Data Structures

class  fglmSelem
 
class  fglmDelem
 

Macros

#define PROT(msg)
 
#define STICKYPROT(msg)   if (BTEST1(OPT_PROT)) Print(msg)
 
#define PROT2(msg, arg)
 
#define STICKYPROT2(msg, arg)   if (BTEST1(OPT_PROT)) Print(msg,arg)
 
#define fglmASSERT(ignore1, ignore2)
 

Functions

BOOLEAN fglmzero (ring sourceRing, ideal &sourceIdeal, ring destRing, ideal &destideal, BOOLEAN switchBack=TRUE, BOOLEAN deleteIdeal=FALSE)
 
BOOLEAN fglmquot (ideal sourceIdeal, poly quot, ideal &destIdeal)
 
poly fglmLinearCombination (ideal source, poly monset)
 
poly fglmNewLinearCombination (ideal source, poly monset)
 

Macro Definition Documentation

◆ fglmASSERT

#define fglmASSERT (   ignore1,
  ignore2 
)

Definition at line 23 of file fglm.h.

◆ PROT

#define PROT (   msg)

Definition at line 19 of file fglm.h.

◆ PROT2

#define PROT2 (   msg,
  arg 
)

Definition at line 21 of file fglm.h.

◆ STICKYPROT

#define STICKYPROT (   msg)    if (BTEST1(OPT_PROT)) Print(msg)

Definition at line 20 of file fglm.h.

◆ STICKYPROT2

#define STICKYPROT2 (   msg,
  arg 
)    if (BTEST1(OPT_PROT)) Print(msg,arg)

Definition at line 22 of file fglm.h.

Function Documentation

◆ fglmLinearCombination()

poly fglmLinearCombination ( ideal  source,
poly  monset 
)

Definition at line 416 of file fglmcomb.cc.

417 {
418  int k;
419  poly temp;
420 
421  polyset m;
422  polyset nf;
423  fglmVector * v;
424 
425  polyset basis;
426  int basisSize = 0;
427  int basisBS = 16;
428  int basisMax;
429  // get number of monomials in monset
430  int numMonoms = 0;
431  temp = monset;
432  while ( temp != NULL ) {
433  numMonoms++;
434  pIter( temp );
435  }
436  // Allocate Memory
437  m= (polyset)omAlloc( numMonoms * sizeof( poly ) );
438  nf= (polyset)omAlloc( numMonoms * sizeof( poly ) );
439  // Warning: The fglmVectors in v are yet not initialized
440  v= (fglmVector *)omAlloc( numMonoms * sizeof( fglmVector ) );
441  basisMax= basisBS;
442  basis= (polyset)omAlloc( basisMax * sizeof( poly ) );
443 
444  // get the NormalForm and the basis monomials
445  temp= monset;
446  for ( k= 0; k < numMonoms; k++ ) {
447  poly mon= pHead( temp );
448  if ( ! nIsOne( pGetCoeff( mon ) ) ) {
449  nDelete( & pGetCoeff( mon ) );
450  pSetCoeff( mon, nInit( 1 ) );
451  }
452  STICKYPROT( "(" );
453  nf[k]= kNF( source, currRing->qideal, mon );
454  STICKYPROT( ")" );
455 
456  // search through basis
457  STICKYPROT( "[" );
458  poly sm = nf[k];
459  while ( sm != NULL ) {
460  BOOLEAN found = FALSE;
461  int b;
462  for ( b= 0; (b < basisSize) && (found == FALSE); b++ )
463  if ( pLmEqual( sm, basis[b] ) ) found= TRUE;
464  if ( found == FALSE ) {
465  // Expand the basis
466  if ( basisSize == basisMax ) {
467  basis= (polyset)omReallocSize( basis, basisMax * sizeof( poly ), (basisMax + basisBS ) * sizeof( poly ) );
468  basisMax+= basisBS;
469  }
470  basis[basisSize]= pHead( sm );
471  nDelete( & pGetCoeff( basis[basisSize] ) );
472  pSetCoeff( basis[basisSize], nInit( 1 ) );
473  basisSize++;
474  }
475  pIter( sm );
476  }
477  STICKYPROT( "]" );
478  m[k]= mon;
479  pIter( temp );
480  }
481  // get the vector representation
482  STICKYPROT2( "(%i)", basisSize );
483  for ( k= 0; k < numMonoms; k++ ) {
484 #ifndef HAVE_EXPLICIT_CONSTR
485  v[k].mac_constr_i( basisSize );
486 #else
487  v[k].fglmVector( basisSize );
488 #endif
489  STICKYPROT( "(+" );
490  poly mon= nf[k];
491  while ( mon != NULL ) {
492  BOOLEAN found = FALSE;
493  int b= 0;
494  while ( found == FALSE ) {
495  if ( pLmEqual( mon, basis[b] ) )
496  found= TRUE;
497  else
498  b++;
499  }
500  number coeff = nCopy( pGetCoeff( mon ) );
501  v[k].setelem( b+1, coeff );
502  pIter( mon );
503  }
504  STICKYPROT( ")" );
505  }
506  // gauss reduce
507  gaussReducer gauss( basisSize );
508  BOOLEAN isZero = FALSE;
509  fglmVector p;
510  for ( k= 0; (k < numMonoms) && (isZero == FALSE); k++ ) {
511  STICKYPROT( "(-" );
512  if ( ( isZero= gauss.reduce( v[k] )) == TRUE )
513  p= gauss.getDependence();
514  else
515  gauss.store();
516  STICKYPROT( ")" );
517  }
518  poly comb = NULL;
519  if ( isZero == TRUE ) {
520  number gcd = p.gcd();
521  if ( ! nIsZero( gcd ) && ! ( nIsOne( gcd ) ) )
522  p/= gcd;
523  nDelete( & gcd );
524  for ( k= 1; k <= p.size(); k++ ) {
525  if ( ! p.elemIsZero( k ) ) {
526  poly temp = pCopy( m[k-1] );
527  pSetCoeff( temp, nCopy( p.getconstelem( k ) ) );
528  comb= pAdd( comb, temp );
529  }
530  }
531  if ( ! nGreaterZero( pGetCoeff( comb ) ) ) comb= pNeg( comb );
532  }
533 
534  // Free Memory
535  for ( k= 0; k < numMonoms; k++ ) {
536  pDelete( m + k );
537  pDelete( nf + k );
538  }
539  omFreeSize( (ADDRESS)m, numMonoms * sizeof( poly ) );
540  omFreeSize( (ADDRESS)nf, numMonoms * sizeof( poly ) );
541  // Warning: At this point all Vectors in v have to be initialized
542  for ( k= numMonoms - 1; k >= 0; k-- ) v[k].~fglmVector();
543  omFreeSize( (ADDRESS)v, numMonoms * sizeof( fglmVector ) );
544  for ( k= 0; k < basisSize; k++ )
545  pDelete( basis + k );
546  omFreeSize( (ADDRESS)basis, basisMax * sizeof( poly ) );
547  STICKYPROT( "\n" );
548  return comb;
549 }

◆ fglmNewLinearCombination()

poly fglmNewLinearCombination ( ideal  source,
poly  monset 
)

Definition at line 154 of file fglmcomb.cc.

155 {
156  polyset m = NULL;
157  polyset nf = NULL;
158  fglmVector * mv = NULL;
159 
160  fglmVector * v = NULL;
161  polyset basis = NULL;
162  int basisSize = 0;
163  int basisBS = 16;
164  int basisMax = basisBS;
165 
166  int * weights = NULL;
167  int * lengthes = NULL;
168  int * order = NULL;
169 
170  int numMonoms = 0;
171  int k;
172 
173  // get number of monoms
174  numMonoms= pLength( monset );
175  STICKYPROT2( "%i monoms\n", numMonoms );
176 
177  // Allcoate Memory and initialize sets
178  m= (polyset)omAlloc( numMonoms * sizeof( poly ) );
179  poly temp= monset;
180  for ( k= 0; k < numMonoms; k++ ) {
181 // m[k]= pOne();
182 // pSetExpV( m[k], temp->exp );
183 // pSetm( m[k] );
184  m[k]=pLmInit(temp);
185  pSetCoeff( m[k], nInit(1) );
186  pIter( temp );
187  }
188 
189  nf= (polyset)omAlloc( numMonoms * sizeof( poly ) );
190 
191 #ifndef HAVE_EXPLICIT_CONSTR
192  mv= new fglmVector[ numMonoms ];
193 #else
194  mv= (fglmVector *)omAlloc( numMonoms * sizeof( fglmVector ) );
195 #endif
196 
197 #ifndef HAVE_EXPLICIT_CONSTR
198  v= new fglmVector[ numMonoms ];
199 #else
200  v= (fglmVector *)omAlloc( numMonoms * sizeof( fglmVector ) );
201 #endif
202 
203  basisMax= basisBS;
204  basis= (polyset)omAlloc( basisMax * sizeof( poly ) );
205 
206  weights= (int *)omAlloc( IDELEMS( source ) * sizeof( int ) );
207  STICKYPROT( "weights: " );
208  for ( k= 0; k < IDELEMS( source ); k++ ) {
209  poly temp= (source->m)[k];
210  int w = 0;
211  while ( temp != NULL ) {
212  w+= nSize( pGetCoeff( temp ) );
213  pIter( temp );
214  }
215  weights[k]= w;
216  STICKYPROT2( "%i ", w );
217  }
218  STICKYPROT( "\n" );
219  lengthes= (int *)omAlloc( numMonoms * sizeof( int ) );
220  order= (int *)omAlloc( numMonoms * sizeof( int ) );
221 
222  // calculate the NormalForm in a special way
223  for ( k= 0; k < numMonoms; k++ )
224  {
225  STICKYPROT( "#" );
226  poly current = pCopy( m[k] );
227  fglmVector currV( numMonoms, k+1 );
228 
229  fglmReduce( & current, currV, m, numMonoms, source, weights );
230  poly temp = current;
231  int b;
232  while ( temp != NULL )
233  {
234  BOOLEAN found = FALSE;
235  for ( b= 0; (b < basisSize) && (found == FALSE); b++ )
236  {
237  if ( pLmEqual( temp, basis[b] ) )
238  {
239  found= TRUE;
240  }
241  }
242  if ( found == FALSE )
243  {
244  if ( basisSize == basisMax )
245  {
246  // Expand the basis
247  basis= (polyset)omReallocSize( basis, basisMax * sizeof( poly ), (basisMax + basisBS ) * sizeof( poly ) );
248  basisMax+= basisBS;
249  }
250 // basis[basisSize]= pOne();
251 // pSetExpV( basis[basisSize], temp->exp );
252 // pSetm( basis[basisSize] );
253  basis[basisSize]=pLmInit(temp);
254  pSetCoeff( basis[basisSize], nInit(1) );
255  basisSize++;
256  }
257  pIter( temp );
258  }
259  nf[k]= current;
260 #ifndef HAVE_EXPLICIT_CONSTR
261  mv[k].mac_constr( currV );
262 #else
263  mv[k].fglmVector( currV );
264 #endif
265  STICKYPROT( "\n" );
266  }
267  // get the vector representation
268  for ( k= 0; k < numMonoms; k++ ) {
269  STICKYPROT( "." );
270 
271 #ifndef HAVE_EXPLICIT_CONSTR
272  v[k].mac_constr_i( basisSize );
273 #else
274  v[k].fglmVector( basisSize );
275 #endif
276  poly mon= nf[k];
277  while ( mon != NULL ) {
278  BOOLEAN found = FALSE;
279  int b= 0;
280  while ( found == FALSE ) {
281  if ( pLmEqual( mon, basis[b] ) ) {
282  found= TRUE;
283  }
284  else {
285  b++;
286  }
287  }
288  number coeff = nCopy( pGetCoeff( mon ) );
289  v[k].setelem( b+1, coeff );
290  pIter( mon );
291  }
292  pDelete( nf + k );
293  }
294  // Free Memory not needed anymore
295  omFreeSize( (ADDRESS)nf, numMonoms * sizeof( poly ) );
296  omFreeSize( (ADDRESS)weights, IDELEMS( source ) * sizeof( int ) );
297 
298  STICKYPROT2( "\nbasis size: %i\n", basisSize );
299  STICKYPROT( "(clear basis" );
300  for ( k= 0; k < basisSize; k++ )
301  pDelete( basis + k );
302  STICKYPROT( ")\n" );
303  // gauss reduce
304  gaussReducer gauss( basisSize );
305  BOOLEAN isZero = FALSE;
306  fglmVector p;
307 
308  STICKYPROT( "sizes: " );
309  for ( k= 0; k < numMonoms; k++ ) {
310  lengthes[k]= v[k].numNonZeroElems();
311  STICKYPROT2( "%i ", lengthes[k] );
312  }
313  STICKYPROT( "\n" );
314 
315  int act = 0;
316  while ( (isZero == FALSE) && (act < numMonoms) ) {
317  int best = 0;
318  for ( k= numMonoms - 1; k >= 0; k-- ) {
319  if ( lengthes[k] > 0 ) {
320  if ( best == 0 ) {
321  best= k+1;
322  }
323  else {
324  if ( lengthes[k] < lengthes[best-1] ) {
325  best= k+1;
326  }
327  }
328  }
329  }
330  lengthes[best-1]= 0;
331  order[act]= best-1;
332  STICKYPROT2( " (%i) ", best );
333  if ( ( isZero= gauss.reduce( v[best-1] )) == TRUE ) {
334  p= gauss.getDependence();
335  }
336  else {
337  STICKYPROT( "+" );
338  gauss.store();
339  act++;
340  }
341 #ifndef HAVE_EXPLICIT_CONSTR
342  v[best-1].clearelems();
343 #else
344  v[best-1].~fglmVector();
345 #endif
346  }
347  poly result = NULL;
348  if ( isZero == TRUE ) {
349  number gcd = p.gcd();
350  if ( ! nIsZero( gcd ) && ! ( nIsOne( gcd ) ) ) {
351  p/= gcd;
352  }
353  nDelete( & gcd );
354  fglmVector temp( numMonoms );
355  for ( k= 0; k < p.size(); k++ ) {
356  if ( ! p.elemIsZero( k+1 ) ) {
357  temp+= p.getconstelem( k+1 ) * mv[order[k]];
358  }
359  }
360  number denom = temp.clearDenom();
361  nDelete( & denom );
362  gcd = temp.gcd();
363  if ( ! nIsZero( gcd ) && ! nIsOne( gcd ) ) {
364  temp/= gcd;
365  }
366  nDelete( & gcd );
367 
368  poly sum = NULL;
369  for ( k= 1; k <= numMonoms; k++ ) {
370  if ( ! temp.elemIsZero( k ) ) {
371  if ( result == NULL ) {
372  result= pCopy( m[k-1] );
373  sum= result;
374  }
375  else {
376  sum->next= pCopy( m[k-1] );
377  pIter( sum );
378  }
379  pSetCoeff( sum, nCopy( temp.getconstelem( k ) ) );
380  }
381  }
383  }
384  // Free Memory
385  omFreeSize( (ADDRESS)lengthes, numMonoms * sizeof( int ) );
386  omFreeSize( (ADDRESS)order, numMonoms * sizeof( int ) );
387 // for ( k= 0; k < numMonoms; k++ )
388 // v[k].~fglmVector();
389 #ifndef HAVE_EXPLICIT_CONSTR
390  delete [] v;
391 #else
392  omFreeSize( (ADDRESS)v, numMonoms * sizeof( fglmVector ) );
393 #endif
394 
395  for ( k= 0; k < basisSize; k++ )
396  pDelete( basis + k );
397  omFreeSize( (ADDRESS)basis, basisMax * sizeof( poly ) );
398 
399 #ifndef HAVE_EXPLICIT_CONSTR
400  delete [] mv;
401 #else
402  for ( k= 0; k < numMonoms; k++ )
403  mv[k].~fglmVector();
404  omFreeSize( (ADDRESS)mv, numMonoms * sizeof( fglmVector ) );
405 #endif
406 
407  for ( k= 0; k < numMonoms; k++ )
408  pDelete( m + k );
409  omFreeSize( (ADDRESS)m, numMonoms * sizeof( poly ) );
410 
411  STICKYPROT( "\n" );
412  return result;
413 }

◆ fglmquot()

BOOLEAN fglmquot ( ideal  sourceIdeal,
poly  quot,
ideal &  destIdeal 
)

Definition at line 1220 of file fglmzero.cc.

1221 {
1222  BOOLEAN fglmok;
1223  fglmVector v;
1224 
1225  idealFunctionals L( 100, (currRing->N) );
1226  // STICKYPROT("calculating normal form\n");
1227  // poly p = kNF( sourceIdeal, currRing->qideal, quot );
1228  // STICKYPROT("calculating functionals\n");
1229  fglmok = CalculateFunctionals( sourceIdeal, L, quot, v );
1230  if ( fglmok == TRUE ) {
1231  // STICKYPROT("calculating groebner basis\n");
1232  destIdeal= GroebnerViaFunctionals( L, v );
1233  }
1234  return fglmok;
1235 }

◆ fglmzero()

BOOLEAN fglmzero ( ring  sourceRing,
ideal &  sourceIdeal,
ring  destRing,
ideal &  destideal,
BOOLEAN  switchBack = TRUE,
BOOLEAN  deleteIdeal = FALSE 
)

Definition at line 1195 of file fglmzero.cc.

1196 {
1197  ring initialRing = currRing;
1198  BOOLEAN fglmok;
1199 
1200  if ( currRing != sourceRing )
1201  {
1202  rChangeCurrRing( sourceRing );
1203  }
1204  idealFunctionals L( 100, rVar(currRing) );
1205  fglmok = CalculateFunctionals( sourceIdeal, L );
1206  if ( deleteIdeal == TRUE )
1207  idDelete( & sourceIdeal );
1208  rChangeCurrRing( destRing );
1209  if ( fglmok == TRUE )
1210  {
1211  L.map( sourceRing );
1212  destIdeal= GroebnerViaFunctionals( L );
1213  }
1214  if ( (switchBack) && (currRing != initialRing) )
1215  rChangeCurrRing( initialRing );
1216  return fglmok;
1217 }
FALSE
#define FALSE
Definition: auxiliary.h:94
pLmEqual
#define pLmEqual(p1, p2)
Definition: polys.h:111
fglmVector::clearDenom
number clearDenom()
Definition: fglmvec.cc:503
isZero
bool isZero(const CFArray &A)
checks if entries of A are zero
Definition: facSparseHensel.h:468
k
int k
Definition: cfEzgcd.cc:92
idDelete
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
rChangeCurrRing
void rChangeCurrRing(ring r)
Definition: polys.cc:15
result
return result
Definition: facAbsBiFact.cc:76
polyset
poly * polyset
Definition: polys.h:254
ADDRESS
void * ADDRESS
Definition: auxiliary.h:133
pNeg
#define pNeg(p)
Definition: polys.h:193
pDelete
#define pDelete(p_ptr)
Definition: polys.h:181
fglmVector
Definition: fglmvec.h:19
fglmVector::fglmVector
fglmVector(fglmVectorRep *rep)
Definition: fglmvec.cc:153
w
const CanonicalForm & w
Definition: facAbsFact.cc:55
b
CanonicalForm b
Definition: cfModGcd.cc:4044
nf
Definition: gnumpfl.cc:28
found
bool found
Definition: facFactorize.cc:56
nGreaterZero
#define nGreaterZero(n)
Definition: numbers.h:28
pLength
static unsigned pLength(poly a)
Definition: p_polys.h:193
currRing
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
rVar
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:582
TRUE
#define TRUE
Definition: auxiliary.h:98
nIsOne
#define nIsOne(n)
Definition: numbers.h:26
act
static scmon act
Definition: hdegree.cc:1078
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
gaussReducer
Definition: fglmgauss.h:19
pIter
#define pIter(p)
Definition: monomials.h:38
p_Cleardenom
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2782
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
STICKYPROT
#define STICKYPROT(msg)
Definition: fglm.h:20
fglmReduce
static void fglmReduce(poly *pptr, fglmVector &v, polyset m, int numMonoms, ideal source, int *w)
Definition: fglmcomb.cc:129
kNF
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2822
pAdd
#define pAdd(p, q)
Definition: polys.h:198
pLmInit
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
pSetCoeff
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
nIsZero
#define nIsZero(n)
Definition: numbers.h:20
m
int m
Definition: cfEzgcd.cc:121
NULL
#define NULL
Definition: omList.c:10
idealFunctionals
Definition: fglmzero.cc:77
nDelete
#define nDelete(n)
Definition: numbers.h:17
STICKYPROT2
#define STICKYPROT2(msg, arg)
Definition: fglm.h:22
gcd
int gcd(int a, int b)
Definition: walkSupport.cc:836
GroebnerViaFunctionals
static ideal GroebnerViaFunctionals(const idealFunctionals &l, fglmVector iv=fglmVector())
Definition: fglmzero.cc:1048
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
p
int p
Definition: cfModGcd.cc:4019
CalculateFunctionals
static BOOLEAN CalculateFunctionals(const ideal &theIdeal, idealFunctionals &l)
Definition: fglmzero.cc:675
nInit
#define nInit(i)
Definition: numbers.h:25
pCopy
#define pCopy(p)
return a copy of the poly
Definition: polys.h:180
IDELEMS
#define IDELEMS(i)
Definition: simpleideals.h:24
pHead
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL
Definition: polys.h:67
pGetCoeff
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:45
nCopy
#define nCopy(n)
Definition: numbers.h:16
nSize
#define nSize(n)
Definition: numbers.h:40
omReallocSize
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220