My Project  UNKNOWN_GIT_VERSION
Functions | Variables
polys.cc File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "misc/options.h"
#include "polys.h"
#include "kernel/ideals.h"
#include "polys/clapsing.h"

Go to the source code of this file.

Functions

void rChangeCurrRing (ring r)
 
poly p_Divide (poly p, poly q, const ring r)
 polynomial division, ignoring the rest via singclap_pdivide resp. idLift destroyes a,b More...
 
poly singclap_gcd (poly f, poly g, const ring r)
 polynomial gcd via singclap_gcd_r resp. idSyzygies destroys f and g More...
 

Variables

ring currRing = NULL
 Widely used global variable which specifies the current polynomial ring for Singular interpreter and legacy implementatins. @Note: one should avoid using it in newer designs, for example due to possible problems in parallelization with threads. More...
 

Function Documentation

◆ p_Divide()

poly p_Divide ( poly  p,
poly  q,
const ring  r 
)

polynomial division, ignoring the rest via singclap_pdivide resp. idLift destroyes a,b

Definition at line 31 of file polys.cc.

32 {
33  assume(q!=NULL);
34  if (q==NULL)
35  {
36  WerrorS("div. by 0");
37  return NULL;
38  }
39  if (p==NULL)
40  {
41  p_Delete(&q,r);
42  return NULL;
43  }
44  if (pNext(q)!=NULL)
45  { /* This means that q != 0 consists of at least two terms*/
46  if(p_GetComp(p,r)==0)
47  {
48  if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
49  &&(!rField_is_Ring(r)))
50  {
51  poly res=singclap_pdivide(p, q, r);
52  p_Delete(&p,r);
53  p_Delete(&q,r);
54  return res;
55  }
56  else
57  {
58  ideal vi=idInit(1,1); vi->m[0]=q;
59  ideal ui=idInit(1,1); ui->m[0]=p;
60  ideal R; matrix U;
61  ring save_ring=currRing;
62  if (r!=currRing) rChangeCurrRing(r);
63  int save_opt;
64  SI_SAVE_OPT1(save_opt);
65  si_opt_1 &= ~(Sy_bit(OPT_PROT));
66  ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
67  SI_RESTORE_OPT1(save_opt);
68  if (r!=save_ring) rChangeCurrRing(save_ring);
69  if (idIs0(R))
70  {
72  p=MATELEM(T,1,1); MATELEM(T,1,1)=NULL;
73  id_Delete((ideal *)&T,r);
74  }
75  else p=NULL;
76  id_Delete((ideal *)&U,r);
77  id_Delete(&R,r);
78  //vi->m[0]=NULL; ui->m[0]=NULL;
79  id_Delete(&vi,r);
80  id_Delete(&ui,r);
81  return p;
82  }
83  }
84  else
85  {
86  int comps=p_MaxComp(p,r);
87  ideal I=idInit(comps,1);
88  poly h;
89  int i;
90  // conversion to a list of polys:
91  while (p!=NULL)
92  {
93  i=p_GetComp(p,r)-1;
94  h=pNext(p);
95  pNext(p)=NULL;
96  p_SetComp(p,0,r);
97  I->m[i]=p_Add_q(I->m[i],p,r);
98  p=h;
99  }
100  // division and conversion to vector:
101  h=NULL;
102  p=NULL;
103  for(i=comps-1;i>=0;i--)
104  {
105  if (I->m[i]!=NULL)
106  {
107  if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
108  &&(!rField_is_Ring(r)))
109  h=singclap_pdivide(I->m[i],q,r);
110  else
111  {
112  ideal vi=idInit(1,1); vi->m[0]=q;
113  ideal ui=idInit(1,1); ui->m[0]=I->m[i];
114  ideal R; matrix U;
115  ring save_ring=currRing;
116  if (r!=currRing) rChangeCurrRing(r);
117  int save_opt;
118  SI_SAVE_OPT1(save_opt);
119  si_opt_1 &= ~(Sy_bit(OPT_PROT));
120  ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
121  SI_RESTORE_OPT1(save_opt);
122  if (r!=save_ring) rChangeCurrRing(save_ring);
123  if (idIs0(R))
124  {
126  p=MATELEM(T,1,1); MATELEM(T,1,1)=NULL;
127  id_Delete((ideal *)&T,r);
128  }
129  else p=NULL;
130  id_Delete((ideal*)&U,r);
131  id_Delete(&R,r);
132  vi->m[0]=NULL; ui->m[0]=NULL;
133  id_Delete(&vi,r);
134  id_Delete(&ui,r);
135  }
136  p_SetCompP(h,i+1,r);
137  p=p_Add_q(p,h,r);
138  }
139  }
140  id_Delete(&I,r);
141  p_Delete(&q,r);
142  return p;
143  }
144  }
145  else
146  { /* This means that q != 0 consists of just one term,
147  or that r is over a coefficient ring. */
148 #ifdef HAVE_RINGS
149  if (!rField_is_Domain(r))
150  {
151  WerrorS("division only defined over coefficient domains");
152  return NULL;
153  }
154  if (pNext(q)!=NULL)
155  {
156  WerrorS("division over a coefficient domain only implemented for terms");
157  return NULL;
158  }
159 #endif
160  return p_DivideM(p,q,r);
161  }
162  return FALSE;
163 }

◆ rChangeCurrRing()

void rChangeCurrRing ( ring  r)

Definition at line 15 of file polys.cc.

16 {
17  //------------ set global ring vars --------------------------------
18  currRing = r;
19  if( r != NULL )
20  {
21  rTest(r);
22  //------------ global variables related to coefficients ------------
23  assume( r->cf!= NULL );
24  nSetChar(r->cf);
25  //------------ global variables related to polys
26  p_SetGlobals(r); // also setting TEST_RINGDEP_OPTS
27  //------------ global variables related to factory -----------------
28  }
29 }

◆ singclap_gcd()

poly singclap_gcd ( poly  f,
poly  g,
const ring  r 
)

polynomial gcd via singclap_gcd_r resp. idSyzygies destroys f and g

Definition at line 165 of file polys.cc.

166 {
167  poly res=NULL;
168 
169  if (f!=NULL)
170  {
171  //if (r->cf->has_simple_Inverse) p_Norm(f,r);
172  if (rField_is_Zp(r)) p_Norm(f,r);
173  else p_Cleardenom(f, r);
174  }
175  if (g!=NULL)
176  {
177  //if (r->cf->has_simple_Inverse) p_Norm(g,r);
178  if (rField_is_Zp(r)) p_Norm(g,r);
179  else p_Cleardenom(g, r);
180  }
181  else return f; // g==0 => gcd=f (but do a p_Cleardenom/pNorm)
182  if (f==NULL) return g; // f==0 => gcd=g (but do a p_Cleardenom/pNorm)
185  {
186  res=p_One(currRing);
187  }
188  else if (r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
189  {
190  res=singclap_gcd_r(f,g,r);
191  }
192  else
193  {
194  ideal I=idInit(2,1);
195  I->m[0]=f;
196  I->m[1]=p_Copy(g,r);
197  intvec *w=NULL;
198  ring save_ring=currRing;
199  if (r!=currRing) rChangeCurrRing(r);
200  int save_opt;
201  SI_SAVE_OPT1(save_opt);
202  si_opt_1 &= ~(Sy_bit(OPT_PROT));
203  ideal S1=idSyzygies(I,testHomog,&w);
204  if (w!=NULL) delete w;
205  // expect S1->m[0]=(-g/gcd,f/gcd)
206  if (IDELEMS(S1)!=1) WarnS("error in syzygy computation for GCD");
207  int lp;
208  p_TakeOutComp(&S1->m[0],1,&res,&lp,r);
209  p_Delete(&S1->m[0],r);
210  // GCD is g divided iby (-g/gcd):
211  res=p_Divide(g,res,r);
212  // restore, r, opt:
213  SI_RESTORE_OPT1(save_opt);
214  if (r!=save_ring) rChangeCurrRing(save_ring);
215  // clean the result
216  res=p_Cleardenom(res,r);
217  p_Content(res,r);
218  return res;
219  }
220  p_Delete(&f, r);
221  p_Delete(&g, r);
222  return res;
223 }

Variable Documentation

◆ currRing

ring currRing = NULL

Widely used global variable which specifies the current polynomial ring for Singular interpreter and legacy implementatins. @Note: one should avoid using it in newer designs, for example due to possible problems in parallelization with threads.

Definition at line 13 of file polys.cc.

FALSE
#define FALSE
Definition: auxiliary.h:94
p_Divide
poly p_Divide(poly p, poly q, const ring r)
polynomial division, ignoring the rest via singclap_pdivide resp. idLift destroyes a,...
Definition: polys.cc:31
idLift
ideal idLift(ideal mod, ideal submod, ideal *rest, BOOLEAN goodShape, BOOLEAN isSB, BOOLEAN divide, matrix *unit, GbVariant alg)
Definition: ideals.cc:1113
p_GetComp
#define p_GetComp(p, r)
Definition: monomials.h:62
ip_smatrix
Definition: matpol.h:13
nSetChar
static FORCE_INLINE void nSetChar(const coeffs r)
initialisations after each ring change
Definition: coeffs.h:435
f
FILE * f
Definition: checklibs.c:9
MATELEM
#define MATELEM(mat, i, j)
Definition: matpol.h:28
rField_is_Domain
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:477
rChangeCurrRing
void rChangeCurrRing(ring r)
Definition: polys.cc:15
p_SetCompP
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:246
singclap_pdivide
poly singclap_pdivide(poly f, poly g, const ring r)
Definition: clapsing.cc:556
SI_SAVE_OPT1
#define SI_SAVE_OPT1(A)
Definition: options.h:21
g
g
Definition: cfModGcd.cc:4031
rTest
#define rTest(r)
Definition: ring.h:775
testHomog
Definition: structs.h:40
idIs0
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
Definition: simpleideals.cc:767
w
const CanonicalForm & w
Definition: facAbsFact.cc:55
p_Copy
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:798
currRing
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
id_Delete
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
Definition: simpleideals.cc:113
res
CanonicalForm res
Definition: facAbsFact.cc:64
Sy_bit
#define Sy_bit(x)
Definition: options.h:31
p_SetGlobals
void p_SetGlobals(const ring r, BOOLEAN complete)
set all properties of a new ring - also called by rComplete
Definition: ring.cc:3333
T
static jList * T
Definition: janet.cc:31
rField_is_Ring
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:474
p_DivideM
poly p_DivideM(poly a, poly b, const ring r)
Definition: p_polys.cc:1537
h
static Poly * h
Definition: janet.cc:972
intvec
Definition: intvec.h:16
p_Cleardenom
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2779
p_Content
void p_Content(poly ph, const ring r)
Definition: p_polys.cc:2235
p_Delete
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
p_Add_q
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:878
p_One
poly p_One(const ring r)
Definition: p_polys.cc:1302
singclap_gcd_r
poly singclap_gcd_r(poly f, poly g, const ring r)
Definition: clapsing.cc:42
idInit
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:36
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
m
int m
Definition: cfEzgcd.cc:121
WarnS
#define WarnS
Definition: emacs.cc:77
assume
#define assume(x)
Definition: mod2.h:384
NULL
#define NULL
Definition: omList.c:9
p_TakeOutComp
void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r)
Definition: p_polys.cc:3443
idSyzygies
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition: ideals.cc:730
p_SetComp
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:239
R
#define R
Definition: sirandom.c:26
p
int p
Definition: cfModGcd.cc:4019
p_IsConstant
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition: p_polys.h:1907
ndConvSingNFactoryN
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition: numbers.cc:273
SI_RESTORE_OPT1
#define SI_RESTORE_OPT1(A)
Definition: options.h:24
IDELEMS
#define IDELEMS(i)
Definition: simpleideals.h:24
p_Norm
void p_Norm(poly p1, const ring r)
Definition: p_polys.cc:3667
id_Module2formatedMatrix
matrix id_Module2formatedMatrix(ideal mod, int rows, int cols, const ring R)
Definition: simpleideals.cc:1246
rField_is_Zp
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:490
p_MaxComp
static long p_MaxComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:284
pNext
#define pNext(p)
Definition: monomials.h:34
OPT_PROT
#define OPT_PROT
Definition: options.h:73
si_opt_1
unsigned si_opt_1
Definition: options.c:5