My Project
Loading...
Searching...
No Matches
Functions | Variables
polys.cc File Reference
#include "kernel/mod2.h"
#include "misc/options.h"
#include "polys.h"
#include "kernel/ideals.h"
#include "polys/clapsing.h"
#include "polys/clapconv.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 a/b, ignoring the rest via singclap_pdivide resp. idLift destroys a,b
 
poly pp_Divide (poly p, poly q, const ring r)
 polynomial division a/b, ignoring the rest via singclap_pdivide resp. idLift does not destroy a,b
 
poly p_DivRem (poly p, poly q, poly &rest, const ring r)
 
poly singclap_gcd (poly f, poly g, const ring r)
 polynomial gcd via singclap_gcd_r resp. idSyzygies destroys f and g
 

Variables

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

Function Documentation

◆ p_Divide()

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

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

Definition at line 33 of file polys.cc.

34{
35 assume(q!=NULL);
36 if (q==NULL)
37 {
38 WerrorS("div. by 0");
39 return NULL;
40 }
41 if (p==NULL)
42 {
43 p_Delete(&q,r);
44 return NULL;
45 }
46 if ((pNext(q)!=NULL)||rIsPluralRing(r))
47 { /* This means that q != 0 consists of at least two terms*/
48 if(p_GetComp(p,r)==0)
49 {
50 if((rFieldType(r)==n_transExt)
51 &&(convSingTrP(p,r))
52 &&(convSingTrP(q,r))
53 &&(!rIsNCRing(r)))
54 {
55 poly res=singclap_pdivide(p, q, r);
56 p_Delete(&p,r);
57 p_Delete(&q,r);
58 return res;
59 }
60 else if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
61 &&(!rField_is_Ring(r))
62 &&(!rIsNCRing(r)))
63 {
64 poly res=singclap_pdivide(p, q, r);
65 p_Delete(&p,r);
66 p_Delete(&q,r);
67 return res;
68 }
69 else
70 {
71 ideal vi=idInit(1,1); vi->m[0]=q;
72 ideal ui=idInit(1,1); ui->m[0]=p;
73 ideal R; matrix U;
75 if (r!=currRing) rChangeCurrRing(r);
82 p=m->m[0]; m->m[0]=NULL;
83 id_Delete(&m,r);
84 p_SetCompP(p,0,r);
85 id_Delete((ideal *)&U,r);
86 id_Delete(&R,r);
87 //vi->m[0]=NULL; ui->m[0]=NULL;
88 id_Delete(&vi,r);
89 id_Delete(&ui,r);
90 return p;
91 }
92 }
93 else
94 {
95 int comps=p_MaxComp(p,r);
97 poly h;
98 int i;
99 // conversion to a list of polys:
100 while (p!=NULL)
101 {
102 i=p_GetComp(p,r)-1;
103 h=pNext(p);
104 pNext(p)=NULL;
105 p_SetComp(p,0,r);
106 I->m[i]=p_Add_q(I->m[i],p,r);
107 p=h;
108 }
109 // division and conversion to vector:
110 h=NULL;
111 p=NULL;
112 for(i=comps-1;i>=0;i--)
113 {
114 if (I->m[i]!=NULL)
115 {
116 if((rFieldType(r)==n_transExt)
117 &&(convSingTrP(I->m[i],r))
118 &&(convSingTrP(q,r))
119 &&(!rIsNCRing(r)))
120 {
121 h=singclap_pdivide(I->m[i],q,r);
122 }
123 else if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
124 &&(!rField_is_Ring(r))
125 &&(!rIsNCRing(r)))
126 h=singclap_pdivide(I->m[i],q,r);
127 else
128 {
129 ideal vi=idInit(1,1); vi->m[0]=q;
130 ideal ui=idInit(1,1); ui->m[0]=I->m[i];
131 ideal R; matrix U;
133 if (r!=currRing) rChangeCurrRing(r);
136 si_opt_1 &= ~(Sy_bit(OPT_PROT));
137 ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
140 if (idIs0(R))
141 {
143 p=MATELEM(T,1,1); MATELEM(T,1,1)=NULL;
144 id_Delete((ideal *)&T,r);
145 }
146 else p=NULL;
147 id_Delete((ideal*)&U,r);
148 id_Delete(&R,r);
149 vi->m[0]=NULL; ui->m[0]=NULL;
150 id_Delete(&vi,r);
151 id_Delete(&ui,r);
152 }
153 p_SetCompP(h,i+1,r);
154 p=p_Add_q(p,h,r);
155 }
156 }
157 id_Delete(&I,r);
158 p_Delete(&q,r);
159 return p;
160 }
161 }
162 else
163 { /* This means that q != 0 consists of just one term, or LetterPlace */
164#ifdef HAVE_RINGS
165 if (pNext(q)!=NULL)
166 {
167 WerrorS("division over a coefficient domain only implemented for terms");
168 return NULL;
169 }
170#endif
171 return p_DivideM(p,q,r);
172 }
173 return NULL;
174}
#define BITSET
Definition auxiliary.h:85
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
int m
Definition cfEzgcd.cc:128
int i
Definition cfEzgcd.cc:132
int p
Definition cfModGcd.cc:4086
BOOLEAN convSingTrP(poly p, const ring r)
Definition clapconv.cc:375
poly singclap_pdivide(poly f, poly g, const ring r)
Definition clapsing.cc:624
@ n_transExt
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition coeffs.h:38
CanonicalForm res
Definition facAbsFact.cc:60
void WerrorS(const char *s)
Definition feFopen.cc:24
ideal idLift(ideal mod, ideal submod, ideal *rest, BOOLEAN goodShape, BOOLEAN isSB, BOOLEAN divide, matrix *unit, GbVariant alg)
represents the generators of submod in terms of the generators of mod (Matrix(SM)*U-Matrix(rest)) = M...
Definition ideals.cc:1105
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
STATIC_VAR jList * T
Definition janet.cc:30
STATIC_VAR Poly * h
Definition janet.cc:971
#define MATELEM(mat, i, j)
1-based access to matrix
Definition matpol.h:29
#define assume(x)
Definition mod2.h:389
#define p_GetComp(p, r)
Definition monomials.h:64
#define pNext(p)
Definition monomials.h:36
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition numbers.cc:307
#define NULL
Definition omList.c:12
VAR unsigned si_opt_1
Definition options.c:5
#define OPT_PROT
Definition options.h:76
#define SI_SAVE_OPT1(A)
Definition options.h:21
#define SI_RESTORE_OPT1(A)
Definition options.h:24
#define Sy_bit(x)
Definition options.h:31
poly p_DivideM(poly a, poly b, const ring r)
Definition p_polys.cc:1582
static poly p_Add_q(poly p, poly q, const ring r)
Definition p_polys.h:937
static void p_SetCompP(poly p, int i, ring r)
Definition p_polys.h:255
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition p_polys.h:248
static long p_MaxComp(poly p, ring lmRing, ring tailRing)
Definition p_polys.h:293
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:902
void rChangeCurrRing(ring r)
Definition polys.cc:15
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
static n_coeffType rFieldType(const ring r)
the type of the coefficient filed of r (n_Zp, n_Q, etc)
Definition ring.h:561
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition ring.h:405
static BOOLEAN rIsNCRing(const ring r)
Definition ring.h:426
#define rField_is_Ring(R)
Definition ring.h:490
ideal idInit(int idsize, int rank)
initialise an ideal / module
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
matrix id_Module2formatedMatrix(ideal mod, int rows, int cols, const ring R)
#define R
Definition sirandom.c:27

◆ p_DivRem()

poly p_DivRem ( poly  p,
poly  q,
poly &  rest,
const ring  r 
)

Definition at line 316 of file polys.cc.

317{
318 assume(q!=NULL);
319 rest=NULL;
320 if (q==NULL)
321 {
322 WerrorS("div. by 0");
323 return NULL;
324 }
325 if (p==NULL)
326 {
327 p_Delete(&q,r);
328 return NULL;
329 }
330 if(p_GetComp(p,r)==0)
331 {
332 if((rFieldType(r)==n_transExt)
333 &&(convSingTrP(p,r))
334 &&(convSingTrP(q,r))
335 &&(!rIsNCRing(r)))
336 {
337 poly res=singclap_pdivide(p, q, r);
338 rest=singclap_pmod(p,q,r);
339 p_Delete(&p,r);
340 p_Delete(&q,r);
341 return res;
342 }
343 else if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
344 &&(!rField_is_Ring(r))
345 &&(!rIsNCRing(r)))
346 {
347 poly res=singclap_pdivide(p, q, r);
348 rest=singclap_pmod(p,q,r);
349 p_Delete(&p,r);
350 p_Delete(&q,r);
351 return res;
352 }
353 else
354 {
355 ideal vi=idInit(1,1); vi->m[0]=q;
356 ideal ui=idInit(1,1); ui->m[0]=p;
357 ideal R; matrix U;
359 if (r!=currRing) rChangeCurrRing(r);
362 si_opt_1 &= ~(Sy_bit(OPT_PROT));
363 ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
366 p=m->m[0]; m->m[0]=NULL;
367 id_Delete(&m,r);
368 p_SetCompP(p,0,r);
369 rest=R->m[0]; R->m[0]=NULL;
370 id_Delete(&R,r);
371 p_SetCompP(rest,0,r);
372 id_Delete((ideal *)&U,r);
373 //vi->m[0]=NULL; ui->m[0]=NULL;
374 id_Delete(&vi,r);
375 id_Delete(&ui,r);
376 return p;
377 }
378 }
379 return NULL;
380}
poly singclap_pmod(poly f, poly g, const ring r)
Definition clapsing.cc:702

◆ pp_Divide()

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

polynomial division a/b, ignoring the rest via singclap_pdivide resp. idLift does not destroy a,b

Definition at line 176 of file polys.cc.

177{
178 if (q==NULL)
179 {
180 WerrorS("div. by 0");
181 return NULL;
182 }
183 if (p==NULL)
184 {
185 return NULL;
186 }
187 if ((pNext(q)!=NULL)||rIsPluralRing(r))
188 { /* This means that q != 0 consists of at least two terms*/
189 if(p_GetComp(p,r)==0)
190 {
191 if((rFieldType(r)==n_transExt)
192 &&(convSingTrP(p,r))
193 &&(convSingTrP(q,r))
194 &&(!rIsNCRing(r)))
195 {
196 poly res=singclap_pdivide(p, q, r);
197 return res;
198 }
199 else if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
200 &&(!rField_is_Ring(r))
201 &&(!rIsNCRing(r)))
202 {
203 poly res=singclap_pdivide(p, q, r);
204 return res;
205 }
206 else
207 {
208 ideal vi=idInit(1,1); vi->m[0]=p_Copy(q,r);
209 ideal ui=idInit(1,1); ui->m[0]=p_Copy(p,r);
210 ideal R; matrix U;
212 if (r!=currRing) rChangeCurrRing(r);
215 si_opt_1 &= ~(Sy_bit(OPT_PROT));
216 ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
220 p=MATELEM(T,1,1); MATELEM(T,1,1)=NULL;
221 id_Delete((ideal *)&T,r);
222 id_Delete((ideal *)&U,r);
223 id_Delete(&R,r);
224 //vi->m[0]=NULL; ui->m[0]=NULL;
225 id_Delete(&vi,r);
226 id_Delete(&ui,r);
227 return p;
228 }
229 }
230 else
231 {
232 p=p_Copy(p,r);
233 int comps=p_MaxComp(p,r);
234 ideal I=idInit(comps,1);
235 poly h;
236 int i;
237 // conversion to a list of polys:
238 while (p!=NULL)
239 {
240 i=p_GetComp(p,r)-1;
241 h=pNext(p);
242 pNext(p)=NULL;
243 p_SetComp(p,0,r);
244 I->m[i]=p_Add_q(I->m[i],p,r);
245 p=h;
246 }
247 // division and conversion to vector:
248 h=NULL;
249 p=NULL;
250 q=p_Copy(q,r);
251 for(i=comps-1;i>=0;i--)
252 {
253 if (I->m[i]!=NULL)
254 {
255 if((rFieldType(r)==n_transExt)
256 &&(convSingTrP(I->m[i],r))
257 &&(convSingTrP(q,r))
258 &&(!rIsNCRing(r)))
259 {
260 h=singclap_pdivide(I->m[i],q,r);
261 }
262 else if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
263 &&(!rField_is_Ring(r))
264 &&(!rIsNCRing(r)))
265 h=singclap_pdivide(I->m[i],q,r);
266 else
267 {
268 ideal vi=idInit(1,1); vi->m[0]=q;
269 ideal ui=idInit(1,1); ui->m[0]=I->m[i];
270 ideal R; matrix U;
272 if (r!=currRing) rChangeCurrRing(r);
275 si_opt_1 &= ~(Sy_bit(OPT_PROT));
276 ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
279 if (idIs0(R))
280 {
282 p=MATELEM(T,1,1); MATELEM(T,1,1)=NULL;
283 id_Delete((ideal *)&T,r);
284 }
285 else p=NULL;
286 id_Delete((ideal*)&U,r);
287 id_Delete(&R,r);
288 vi->m[0]=NULL; ui->m[0]=NULL;
289 id_Delete(&vi,r);
290 id_Delete(&ui,r);
291 }
292 p_SetCompP(h,i+1,r);
293 p=p_Add_q(p,h,r);
294 }
295 }
296 id_Delete(&I,r);
297 p_Delete(&q,r);
298 return p;
299 }
300 }
301 else
302 { /* This means that q != 0 consists of just one term,
303 or that r is over a coefficient ring. */
304#ifdef HAVE_RINGS
305 if (pNext(q)!=NULL)
306 {
307 WerrorS("division over a coefficient domain only implemented for terms");
308 return NULL;
309 }
310#endif
311 return pp_DivideM(p,q,r);
312 }
313 return NULL;
314}
poly pp_DivideM(poly a, poly b, const ring r)
Definition p_polys.cc:1637
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition p_polys.h:847

◆ rChangeCurrRing()

void rChangeCurrRing ( ring  r)

Definition at line 15 of file polys.cc.

16{
17 if (currRing!=NULL)
19 //------------ set global ring vars --------------------------------
20 currRing = r;
21 if( r != NULL )
22 {
23 rTest(r);
24 //------------ global variables related to coefficients ------------
25 assume( r->cf!= NULL );
26 nSetChar(r->cf);
27 //------------ global variables related to polys
28 p_SetGlobals(r); // also setting TEST_RINGDEP_OPTS
29 //------------ global variables related to factory -----------------
30 }
31}
static FORCE_INLINE void nSetChar(const coeffs r)
initialisations after each ring change
Definition coeffs.h:444
#define TEST_RINGDEP_OPTS
Definition options.h:101
void p_SetGlobals(const ring r, BOOLEAN complete)
set all properties of a new ring - also called by rComplete
Definition ring.cc:3448
#define rTest(r)
Definition ring.h:792

◆ 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 382 of file polys.cc.

383{
384 poly res=NULL;
385
386 if (f!=NULL)
387 {
388 //if (r->cf->has_simple_Inverse) p_Norm(f,r);
389 if (rField_is_Zp(r)) p_Norm(f,r);
390 else if (!rField_is_Ring(r)) p_Cleardenom(f, r);
391 }
392 if (g!=NULL)
393 {
394 //if (r->cf->has_simple_Inverse) p_Norm(g,r);
395 if (rField_is_Zp(r)) p_Norm(g,r);
396 else if (!rField_is_Ring(r)) p_Cleardenom(g, r);
397 }
398 else return f; // g==0 => gcd=f (but do a p_Cleardenom/pNorm)
399 if (f==NULL) return g; // f==0 => gcd=g (but do a p_Cleardenom/pNorm)
400 if(!rField_is_Ring(r)
401 && (p_IsConstant(f,r)
402 ||p_IsConstant(g,r)))
403 {
404 res=p_One(r);
405 }
406 else if (r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
407 {
409 }
410 else
411 {
412 ideal I=idInit(2,1);
413 I->m[0]=f;
414 I->m[1]=p_Copy(g,r);
415 intvec *w=NULL;
417 if (r!=currRing) rChangeCurrRing(r);
420 si_opt_1 &= ~(Sy_bit(OPT_PROT));
422 if (w!=NULL) delete w;
423 // expect S1->m[0]=(-g/gcd,f/gcd)
424 if (IDELEMS(S1)!=1) WarnS("error in syzygy computation for GCD");
425 int lp;
426 p_TakeOutComp(&S1->m[0],1,&res,&lp,r);
427 p_Delete(&S1->m[0],r);
428 // GCD is g divided iby (-g/gcd):
429 res=p_Divide(g,res,r);
430 // restore, r, opt:
433 // clean the result
435 if (nCoeff_is_Ring(r->cf)) p_Content(res,r);
436 return res;
437 }
438 p_Delete(&f, r);
439 p_Delete(&g, r);
440 return res;
441}
g
Definition cfModGcd.cc:4098
FILE * f
Definition checklibs.c:9
poly singclap_gcd_r(poly f, poly g, const ring r)
Definition clapsing.cc:68
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
Definition coeffs.h:730
#define WarnS
Definition emacs.cc:78
const CanonicalForm & w
Definition facAbsFact.cc:51
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition ideals.cc:830
void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r)
Definition p_polys.cc:3535
void p_Content(poly ph, const ring r)
Definition p_polys.cc:2299
void p_Norm(poly p1, const ring r)
Definition p_polys.cc:3759
poly p_Cleardenom(poly p, const ring r)
Definition p_polys.cc:2849
poly p_One(const ring r)
Definition p_polys.cc:1314
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition p_polys.h:1979
poly p_Divide(poly p, poly q, const ring r)
polynomial division a/b, ignoring the rest via singclap_pdivide resp. idLift destroys a,...
Definition polys.cc:33
static BOOLEAN rField_is_Zp(const ring r)
Definition ring.h:505
#define IDELEMS(i)
@ testHomog
Definition structs.h:34

Variable Documentation

◆ currRing

VAR ring currRing = NULL

Widely used global variable which specifies the current polynomial ring for Singular interpreter and legacy implementations. @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.