My Project  debian-1:4.1.1-p2+ds-4build4
Enumerations | Functions
fglm.cc File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "misc/options.h"
#include "polys/monomials/ring.h"
#include "polys/monomials/maps.h"
#include "kernel/polys.h"
#include "kernel/ideals.h"
#include "kernel/GBEngine/kstd1.h"
#include "kernel/fglm/fglm.h"
#include "Singular/fglm.h"
#include "Singular/ipid.h"
#include "Singular/ipshell.h"
#include "Singular/tok.h"

Go to the source code of this file.

Enumerations

enum  FglmState {
  FglmOk , FglmHasOne , FglmNoIdeal , FglmNotReduced ,
  FglmNotZeroDim , FglmIncompatibleRings , FglmPolyIsOne , FglmPolyIsZero
}
 

Functions

ideal fglmUpdatesource (const ideal sourceIdeal)
 
void fglmUpdateresult (ideal &result)
 
FglmState fglmConsistency (idhdl sringHdl, idhdl dringHdl, int *vperm)
 
FglmState fglmIdealcheck (const ideal theIdeal)
 
BOOLEAN fglmProc (leftv result, leftv first, leftv second)
 
BOOLEAN fglmQuotProc (leftv result, leftv first, leftv second)
 
BOOLEAN findUniProc (leftv result, leftv first)
 

Enumeration Type Documentation

◆ FglmState

enum FglmState
Enumerator
FglmOk 
FglmHasOne 
FglmNoIdeal 
FglmNotReduced 
FglmNotZeroDim 
FglmIncompatibleRings 
FglmPolyIsOne 
FglmPolyIsZero 

Definition at line 43 of file fglm.cc.

43  {
44  FglmOk,
45  FglmHasOne,
50  // for fglmquot:
53 };
@ FglmOk
Definition: fglm.cc:44
@ FglmNotReduced
Definition: fglm.cc:47
@ FglmHasOne
Definition: fglm.cc:45
@ FglmNotZeroDim
Definition: fglm.cc:48
@ FglmIncompatibleRings
Definition: fglm.cc:49
@ FglmPolyIsOne
Definition: fglm.cc:51
@ FglmPolyIsZero
Definition: fglm.cc:52
@ FglmNoIdeal
Definition: fglm.cc:46

Function Documentation

◆ fglmConsistency()

FglmState fglmConsistency ( idhdl  sringHdl,
idhdl  dringHdl,
int *  vperm 
)

Definition at line 125 of file fglm.cc.

126 {
127  int k;
128  FglmState state= FglmOk;
129  ring dring = IDRING( dringHdl );
130  ring sring = IDRING( sringHdl );
131 
132  if ( rChar(sring) != rChar(dring) )
133  {
134  WerrorS( "rings must have same characteristic" );
135  state= FglmIncompatibleRings;
136  }
137  if ( (sring->OrdSgn != 1) || (dring->OrdSgn != 1) )
138  {
139  WerrorS( "only works for global orderings" );
140  state= FglmIncompatibleRings;
141  }
142  if ( sring->N != dring->N )
143  {
144  WerrorS( "rings must have same number of variables" );
145  state= FglmIncompatibleRings;
146  }
147  if ( rPar(sring) != rPar(dring) )
148  {
149  WerrorS( "rings must have same number of parameters" );
150  state= FglmIncompatibleRings;
151  }
152  if ( state != FglmOk ) return state;
153  // now the rings have the same number of variables resp. parameters.
154  // check if the names of the variables resp. parameters do agree:
155  int nvar = sring->N;
156  int npar = rPar(sring);
157  int * pperm;
158  if ( npar > 0 )
159  pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) );
160  else
161  pperm= NULL;
162  maFindPerm( sring->names, nvar, rParameter(sring), npar,
163  dring->names, nvar, rParameter(dring), npar, vperm, pperm,
164  dring->cf->type);
165  for ( k= nvar; (k > 0) && (state == FglmOk); k-- )
166  if ( vperm[k] <= 0 )
167  {
168  WerrorS( "variable names do not agree" );
169  state= FglmIncompatibleRings;
170  }
171  for ( k= npar-1; (k >= 0) && (state == FglmOk); k-- )
172  if ( pperm[k] >= 0 )
173  {
174  WerrorS( "parameter names do not agree" );
175  state= FglmIncompatibleRings;
176  }
177  if (pperm != NULL) // OB: ????
178  omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) );
179  if ( state != FglmOk ) return state;
180  // check if both rings are qrings or not
181  if ( sring->qideal != NULL )
182  {
183  if ( dring->qideal == NULL )
184  {
185  Werror( "%s is a qring, current ring not", sringHdl->id );
186  return FglmIncompatibleRings;
187  }
188  // both rings are qrings, now check if both quotients define the same ideal.
189  // check if sring->qideal is contained in dring->qideal:
190  rSetHdl( dringHdl );
191  nMapFunc nMap=n_SetMap(currRing->cf, sring->cf );
192  ideal sqind = idInit( IDELEMS( sring->qideal ), 1 );
193  for ( k= IDELEMS( sring->qideal )-1; k >= 0; k-- )
194  (sqind->m)[k]= p_PermPoly( (sring->qideal->m)[k], vperm, sring,
195  currRing, nMap);
196  ideal sqindred = kNF( dring->qideal, NULL, sqind );
197  if ( ! idIs0( sqindred ) )
198  {
199  WerrorS( "the quotients do not agree" );
200  state= FglmIncompatibleRings;
201  }
202  idDelete( & sqind );
203  idDelete( & sqindred );
204  rSetHdl( sringHdl );
205  if ( state != FglmOk ) return state;
206  // check if dring->qideal is contained in sring->qideal:
207  int * dsvperm = (int *)omAlloc0( (nvar+1)*sizeof( int ) );
208  maFindPerm( dring->names, nvar, NULL, 0, sring->names, nvar, NULL, 0,
209  dsvperm, NULL, sring->cf->type);
210  nMap=n_SetMap(currRing->cf, dring->cf);
211  ideal dqins = idInit( IDELEMS( dring->qideal ), 1 );
212  for ( k= IDELEMS( dring->qideal )-1; k >= 0; k-- )
213  (dqins->m)[k]=p_PermPoly( (dring->qideal->m)[k], dsvperm, sring,
214  currRing, nMap);
215  ideal dqinsred = kNF( sring->qideal, NULL, dqins );
216  if ( ! idIs0( dqinsred ) )
217  {
218  WerrorS( "the quotients do not agree" );
219  state= FglmIncompatibleRings;
220  }
221  idDelete( & dqins );
222  idDelete( & dqinsred );
223  omFreeSize( (ADDRESS)dsvperm, (nvar+1)*sizeof( int ) );
224  if ( state != FglmOk ) return state;
225  }
226  else
227  {
228  if ( dring->qideal != NULL )
229  {
230  Werror( "current ring is a qring, %s not", sringHdl->id );
231  return FglmIncompatibleRings;
232  }
233  }
234  return FglmOk;
235 }
void * ADDRESS
Definition: auxiliary.h:133
int k
Definition: cfEzgcd.cc:92
const char * id
Definition: idrec.h:39
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:722
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:74
void WerrorS(const char *s)
Definition: feFopen.cc:24
FglmState
Definition: fglm.cc:43
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
#define IDRING(a)
Definition: ipid.h:122
void rSetHdl(idhdl h)
Definition: ipshell.cc:5050
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2813
void maFindPerm(char const *const *const preim_names, int preim_n, char const *const *const preim_par, int preim_p, char const *const *const names, int n, char const *const *const par, int nop, int *perm, int *par_perm, n_coeffType ch)
Definition: maps.cc:165
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:10
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
Definition: p_polys.cc:4014
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int rChar(ring r)
Definition: ring.cc:688
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:616
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:590
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:37
#define IDELEMS(i)
Definition: simpleideals.h:24

◆ fglmIdealcheck()

FglmState fglmIdealcheck ( const ideal  theIdeal)

Definition at line 246 of file fglm.cc.

247 {
248  FglmState state = FglmOk;
249  int power;
250  int k;
251  BOOLEAN * purePowers = (BOOLEAN *)omAlloc0( currRing->N*sizeof( BOOLEAN ) );
252 
253  for ( k= IDELEMS( theIdeal ) - 1; (state == FglmOk) && (k >= 0); k-- )
254  {
255  poly p = (theIdeal->m)[k];
256  if (p!=NULL)
257  {
258  if( pIsConstant( p ) ) state= FglmHasOne;
259  else if ( (power= pIsPurePower( p )) > 0 )
260  {
261  fglmASSERT( 0 < power && power <= currRing->N, "illegal power" );
262  if ( purePowers[power-1] == TRUE ) state= FglmNotReduced;
263  else purePowers[power-1]= TRUE;
264  }
265  for ( int l = IDELEMS( theIdeal ) - 1; state == FglmOk && l >= 0; l-- )
266  if ( (k != l) && pDivisibleBy( p, (theIdeal->m)[l] ) )
267  state= FglmNotReduced;
268  }
269  }
270  if ( state == FglmOk )
271  {
272  for ( k= currRing->N-1 ; (state == FglmOk) && (k >= 0); k-- )
273  if ( purePowers[k] == FALSE ) state= FglmNotZeroDim;
274  }
275  omFreeSize( (ADDRESS)purePowers, currRing->N*sizeof( BOOLEAN ) );
276  return state;
277 }
int BOOLEAN
Definition: auxiliary.h:85
#define TRUE
Definition: auxiliary.h:98
#define FALSE
Definition: auxiliary.h:94
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
int l
Definition: cfEzgcd.cc:93
int p
Definition: cfModGcd.cc:4019
#define fglmASSERT(ignore1, ignore2)
Definition: fglm.h:23
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:225
#define pIsPurePower(p)
Definition: polys.h:235
#define pDivisibleBy(a, b)
returns TRUE, if leading monom of a divides leading monom of b i.e., if there exists a expvector c > ...
Definition: polys.h:138

◆ fglmProc()

BOOLEAN fglmProc ( leftv  result,
leftv  first,
leftv  second 
)

Definition at line 283 of file fglm.cc.

284 {
285  FglmState state = FglmOk;
286 
287  idhdl destRingHdl = currRingHdl;
288  // ring destRing = currRing;
289  ideal destIdeal = NULL;
290  idhdl sourceRingHdl = (idhdl)first->data;
291  rSetHdl( sourceRingHdl );
292  // ring sourceRing = currRing;
293 
294  int * vperm = (int *)omAlloc0( (currRing->N+1)*sizeof( int ) );
295  state= fglmConsistency( sourceRingHdl, destRingHdl, vperm );
296  omFreeSize( (ADDRESS)vperm, (currRing->N+1)*sizeof(int) );
297 
298  if ( state == FglmOk )
299  {
300  idhdl ih = currRing->idroot->get( second->Name(), myynest );
301  if ( (ih != NULL) && (IDTYP(ih)==IDEAL_CMD) )
302  {
303  ideal sourceIdeal;
304  if ( currRing->qideal != NULL )
305  sourceIdeal= fglmUpdatesource( IDIDEAL( ih ) );
306  else
307  sourceIdeal = IDIDEAL( ih );
308  state= fglmIdealcheck( sourceIdeal );
309  if ( state == FglmOk )
310  {
311  // Now the settings are compatible with FGLM
312  assumeStdFlag( (leftv)ih );
313  if ( fglmzero( IDRING(sourceRingHdl), sourceIdeal, IDRING(destRingHdl), destIdeal, FALSE, (currRing->qideal != NULL) ) == FALSE )
314  state= FglmNotReduced;
315  }
316  } else state= FglmNoIdeal;
317  }
318  if ( currRingHdl != destRingHdl )
319  rSetHdl( destRingHdl );
320  switch (state)
321  {
322  case FglmOk:
323  if ( currRing->qideal != NULL ) fglmUpdateresult( destIdeal );
324  break;
325  case FglmHasOne:
326  destIdeal= idInit(1,1);
327  (destIdeal->m)[0]= pOne();
328  state= FglmOk;
329  break;
331  Werror( "ring %s and current ring are incompatible", first->Name() );
332  destIdeal= NULL;
333  break;
334  case FglmNoIdeal:
335  Werror( "Can't find ideal %s in ring %s", second->Name(), first->Name() );
336  destIdeal= NULL;
337  break;
338  case FglmNotZeroDim:
339  Werror( "The ideal %s has to be 0-dimensional", second->Name() );
340  destIdeal= NULL;
341  break;
342  case FglmNotReduced:
343  Werror( "The ideal %s has to be given by a reduced SB", second->Name() );
344  destIdeal= NULL;
345  break;
346  default:
347  destIdeal= idInit(1,1);
348  }
349 
350  result->rtyp = IDEAL_CMD;
351  result->data= (void *)destIdeal;
352  setFlag( result, FLAG_STD );
353  return (state != FglmOk);
354 }
Definition: idrec.h:35
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
void * data
Definition: subexpr.h:88
const char * Name()
Definition: subexpr.h:120
return result
Definition: facAbsBiFact.cc:76
int myynest
Definition: febase.cc:41
FglmState fglmConsistency(idhdl sringHdl, idhdl dringHdl, int *vperm)
Definition: fglm.cc:125
FglmState fglmIdealcheck(const ideal theIdeal)
Definition: fglm.cc:246
ideal fglmUpdatesource(const ideal sourceIdeal)
Definition: fglm.cc:61
void fglmUpdateresult(ideal &result)
Definition: fglm.cc:93
@ IDEAL_CMD
Definition: grammar.cc:283
idhdl currRingHdl
Definition: ipid.cc:61
#define setFlag(A, F)
Definition: ipid.h:108
#define IDIDEAL(a)
Definition: ipid.h:128
#define IDTYP(a)
Definition: ipid.h:114
#define FLAG_STD
Definition: ipid.h:104
BOOLEAN fglmzero(ring sourceRing, ideal &sourceIdeal, ring destRing, ideal &destideal, BOOLEAN switchBack=TRUE, BOOLEAN deleteIdeal=FALSE)
Definition: fglmzero.cc:1195
#define pOne()
Definition: polys.h:301
idrec * idhdl
Definition: ring.h:21
BOOLEAN assumeStdFlag(leftv h)
Definition: subexpr.cc:1471

◆ fglmQuotProc()

BOOLEAN fglmQuotProc ( leftv  result,
leftv  first,
leftv  second 
)

Definition at line 360 of file fglm.cc.

361 {
362  FglmState state = FglmOk;
363 
364  // STICKYPROT("quotstart\n");
365  ideal sourceIdeal = (ideal)first->Data();
366  poly quot = (poly)second->Data();
367  ideal destIdeal = NULL;
368 
369  state = fglmIdealcheck( sourceIdeal );
370  if ( state == FglmOk )
371  {
372  if ( quot == NULL ) state= FglmPolyIsZero;
373  else if ( pIsConstant( quot ) ) state= FglmPolyIsOne;
374  }
375 
376  if ( state == FglmOk )
377  {
378  assumeStdFlag( first );
379  if ( fglmquot( sourceIdeal, quot, destIdeal ) == FALSE )
380  state= FglmNotReduced;
381  }
382 
383  switch (state)
384  {
385  case FglmOk:
386  break;
387  case FglmHasOne:
388  destIdeal= idInit(1,1);
389  (destIdeal->m)[0]= pOne();
390  state= FglmOk;
391  break;
392  case FglmNotZeroDim:
393  Werror( "The ideal %s has to be 0-dimensional", first->Name() );
394  destIdeal= NULL;
395  break;
396  case FglmNotReduced:
397  Werror( "The poly %s has to be reduced", second->Name() );
398  destIdeal= NULL;
399  break;
400  case FglmPolyIsOne:
401  int k;
402  destIdeal= idInit( IDELEMS(sourceIdeal), 1 );
403  for ( k= IDELEMS( sourceIdeal )-1; k >=0; k-- )
404  (destIdeal->m)[k]= pCopy( (sourceIdeal->m)[k] );
405  state= FglmOk;
406  break;
407  case FglmPolyIsZero:
408  destIdeal= idInit(1,1);
409  (destIdeal->m)[0]= pOne();
410  state= FglmOk;
411  break;
412  default:
413  destIdeal= idInit(1,1);
414  }
415 
416  result->rtyp = IDEAL_CMD;
417  result->data= (void *)destIdeal;
418  setFlag( result, FLAG_STD );
419  // STICKYPROT("quotend\n");
420  return (state != FglmOk);
421 } // fglmQuotProt
void * Data()
Definition: subexpr.cc:1134
BOOLEAN fglmquot(ideal sourceIdeal, poly quot, ideal &destIdeal)
Definition: fglmzero.cc:1220
#define pCopy(p)
return a copy of the poly
Definition: polys.h:172

◆ fglmUpdateresult()

void fglmUpdateresult ( ideal &  result)

Definition at line 93 of file fglm.cc.

94 {
95  int k, l;
96  BOOLEAN found;
97  for ( k= IDELEMS( result )-1; k >=0; k-- )
98  {
99  if ( (result->m)[k] != NULL )
100  {
101  found= FALSE;
102  for ( l= IDELEMS( currRing->qideal )-1; (l >= 0) && ( found == FALSE ); l-- )
103  if ( pDivisibleBy( (currRing->qideal->m)[l], (result->m)[k] ) )
104  found= TRUE;
105  if ( found ) pDelete( & ((result->m)[k]) );
106  }
107  }
108  idSkipZeroes( result );
109 }
bool found
Definition: facFactorize.cc:56
#define pDelete(p_ptr)
Definition: polys.h:173
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size

◆ fglmUpdatesource()

ideal fglmUpdatesource ( const ideal  sourceIdeal)

Definition at line 61 of file fglm.cc.

62 {
63  int k, l, offset;
64  BOOLEAN found;
65  ideal newSource= idInit( IDELEMS( sourceIdeal ) + IDELEMS( currRing->qideal ), 1 );
66  for ( k= IDELEMS( sourceIdeal )-1; k >=0; k-- )
67  (newSource->m)[k]= pCopy( (sourceIdeal->m)[k] );
68  offset= IDELEMS( sourceIdeal );
69  for ( l= IDELEMS( currRing->qideal )-1; l >= 0; l-- )
70  {
71  if ( (currRing->qideal->m)[l] != NULL )
72  {
73  found= FALSE;
74  for ( k= IDELEMS( sourceIdeal )-1; (k >= 0) && (found == FALSE); k-- )
75  if ( pDivisibleBy( (sourceIdeal->m)[k], (currRing->qideal->m)[l] ) )
76  found= TRUE;
77  if ( ! found )
78  {
79  (newSource->m)[offset]= pCopy( (currRing->qideal->m)[l] );
80  offset++;
81  }
82  }
83  }
84  idSkipZeroes( newSource );
85  return newSource;
86 }
int offset
Definition: libparse.cc:1091

◆ findUniProc()

BOOLEAN findUniProc ( leftv  result,
leftv  first 
)

Definition at line 428 of file fglm.cc.

429 {
430  ideal sourceIdeal;
431  ideal destIdeal = NULL;
432  FglmState state;
433 
434  sourceIdeal = (ideal)first->Data();
435 
436  assumeStdFlag( first );
437  state= fglmIdealcheck( sourceIdeal );
438  if ( state == FglmOk )
439  {
440  // check for special cases: if the input contains
441  // univariate polys, try to reduce the problem
442  int i,k;
443  int count=0;
444  BOOLEAN * purePowers = (BOOLEAN *)omAlloc0( currRing->N*sizeof( BOOLEAN ) );
445  for ( k= IDELEMS( sourceIdeal ) - 1; k >= 0; k-- )
446  {
447  if((i=pIsUnivariate(sourceIdeal->m[k]))>0)
448  {
449  if (purePowers[i-1]==0)
450  {
451  purePowers[i-1]=k;
452  count++;
453  if (count==currRing->N) break;
454  }
455  }
456  }
457  if (count==currRing->N)
458  {
459  destIdeal=idInit(currRing->N,1);
460  for(k=currRing->N-1; k>=0; k--) destIdeal->m[k]=pCopy(sourceIdeal->m[purePowers[k]]);
461  }
462  omFreeSize((ADDRESS)purePowers, currRing->N*sizeof( BOOLEAN ) );
463  if (destIdeal!=NULL)
464  state = FglmOk;
465  else if ( FindUnivariateWrapper( sourceIdeal, destIdeal ) == FALSE )
466  state = FglmNotReduced;
467  }
468  switch (state)
469  {
470  case FglmOk:
471  break;
472  case FglmHasOne:
473  destIdeal= idInit(1,1);
474  (destIdeal->m)[0]= pOne();
475  state= FglmOk;
476  break;
477  case FglmNotZeroDim:
478  Werror( "The ideal %s has to be 0-dimensional", first->Name() );
479  destIdeal= NULL;
480  break;
481  case FglmNotReduced:
482  Werror( "The ideal %s has to be reduced", first->Name() );
483  destIdeal= NULL;
484  break;
485  default:
486  destIdeal= idInit(1,1);
487  }
488 
489  result->rtyp = IDEAL_CMD;
490  result->data= (void *)destIdeal;
491 
492  return FALSE;
493 }
int i
Definition: cfEzgcd.cc:125
BOOLEAN FindUnivariateWrapper(ideal source, ideal &destIdeal)
Definition: fglmzero.cc:1238
#define pIsUnivariate(p)
Definition: polys.h:236
int status int void size_t count
Definition: si_signals.h:59