My Project
Loading...
Searching...
No Matches
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.
 
VAR coeffs coeffs_BIGINT
 

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

35{
36 assume(q!=NULL);
37 if (q==NULL)
38 {
39 WerrorS("div. by 0");
40 return NULL;
41 }
42 if (p==NULL)
43 {
44 p_Delete(&q,r);
45 return NULL;
46 }
47 if ((pNext(q)!=NULL)||rIsPluralRing(r))
48 { /* This means that q != 0 consists of at least two terms*/
49 if(p_GetComp(p,r)==0)
50 {
51 if((rFieldType(r)==n_transExt)
52 &&(convSingTrP(p,r))
53 &&(convSingTrP(q,r))
54 &&(!rIsNCRing(r)))
55 {
56 poly res=singclap_pdivide(p, q, r);
57 p_Delete(&p,r);
58 p_Delete(&q,r);
59 return res;
60 }
61 else if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
62 &&(!rField_is_Ring(r))
63 &&(!rIsNCRing(r)))
64 {
65 poly res=singclap_pdivide(p, q, r);
66 p_Delete(&p,r);
67 p_Delete(&q,r);
68 return res;
69 }
70 else
71 {
72 ideal vi=idInit(1,1); vi->m[0]=q;
73 ideal ui=idInit(1,1); ui->m[0]=p;
74 ideal R; matrix U;
75 ring save_ring=currRing;
76 if (r!=currRing) rChangeCurrRing(r);
77 BITSET save_opt;
78 SI_SAVE_OPT1(save_opt);
80 ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
81 SI_RESTORE_OPT1(save_opt);
82 if (r!=save_ring) rChangeCurrRing(save_ring);
83 p=m->m[0]; m->m[0]=NULL;
84 id_Delete(&m,r);
85 p_SetCompP(p,0,r);
86 id_Delete((ideal *)&U,r);
87 id_Delete(&R,r);
88 //vi->m[0]=NULL; ui->m[0]=NULL;
89 id_Delete(&vi,r);
90 id_Delete(&ui,r);
91 return p;
92 }
93 }
94 else
95 {
96 int comps=p_MaxComp(p,r);
97 ideal I=idInit(comps,1);
98 poly h;
99 int i;
100 // conversion to a list of polys:
101 while (p!=NULL)
102 {
103 i=p_GetComp(p,r)-1;
104 h=pNext(p);
105 pNext(p)=NULL;
106 p_SetComp(p,0,r);
107 I->m[i]=p_Add_q(I->m[i],p,r);
108 p=h;
109 }
110 // division and conversion to vector:
111 h=NULL;
112 p=NULL;
113 for(i=comps-1;i>=0;i--)
114 {
115 if (I->m[i]!=NULL)
116 {
117 if((rFieldType(r)==n_transExt)
118 &&(convSingTrP(I->m[i],r))
119 &&(convSingTrP(q,r))
120 &&(!rIsNCRing(r)))
121 {
122 h=singclap_pdivide(I->m[i],q,r);
123 }
124 else if ((r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
125 &&(!rField_is_Ring(r))
126 &&(!rIsNCRing(r)))
127 h=singclap_pdivide(I->m[i],q,r);
128 else
129 {
130 ideal vi=idInit(1,1); vi->m[0]=q;
131 ideal ui=idInit(1,1); ui->m[0]=I->m[i];
132 ideal R; matrix U;
133 ring save_ring=currRing;
134 if (r!=currRing) rChangeCurrRing(r);
135 BITSET save_opt;
136 SI_SAVE_OPT1(save_opt);
137 si_opt_1 &= ~(Sy_bit(OPT_PROT));
138 ideal m = idLift(vi,ui,&R, FALSE,TRUE,TRUE,&U);
139 SI_RESTORE_OPT1(save_opt);
140 if (r!=save_ring) rChangeCurrRing(save_ring);
141 if (idIs0(R))
142 {
144 p=MATELEM(T,1,1); MATELEM(T,1,1)=NULL;
145 id_Delete((ideal *)&T,r);
146 }
147 else p=NULL;
148 id_Delete((ideal*)&U,r);
149 id_Delete(&R,r);
150 vi->m[0]=NULL; ui->m[0]=NULL;
151 id_Delete(&vi,r);
152 id_Delete(&ui,r);
153 }
154 p_SetCompP(h,i+1,r);
155 p=p_Add_q(p,h,r);
156 }
157 }
158 id_Delete(&I,r);
159 p_Delete(&q,r);
160 return p;
161 }
162 }
163 else
164 { /* This means that q != 0 consists of just one term, or LetterPlace */
165#ifdef HAVE_RINGS
166 if (pNext(q)!=NULL)
167 {
168 WerrorS("division over a coefficient domain only implemented for terms");
169 return NULL;
170 }
171#endif
172 return p_DivideM(p,q,r);
173 }
174 return NULL;
175}
#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:1111
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
ip_smatrix * matrix
Definition matpol.h:43
#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:938
static void p_SetCompP(poly p, int i, ring r)
Definition p_polys.h:256
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition p_polys.h:249
static long p_MaxComp(poly p, ring lmRing, ring tailRing)
Definition p_polys.h:294
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
void rChangeCurrRing(ring r)
Definition polys.cc:16
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:562
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition ring.h:406
static BOOLEAN rIsNCRing(const ring r)
Definition ring.h:427
#define rField_is_Ring(R)
Definition ring.h:491
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 317 of file polys.cc.

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

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

◆ rChangeCurrRing()

void rChangeCurrRing ( ring r)

Definition at line 16 of file polys.cc.

17{
18 if (currRing!=NULL)
20 //------------ set global ring vars --------------------------------
21 currRing = r;
22 if( r != NULL )
23 {
24 rTest(r);
25 //------------ global variables related to coefficients ------------
26 assume( r->cf!= NULL );
27 nSetChar(r->cf);
28 //------------ global variables related to polys
29 p_SetGlobals(r); // also setting TEST_RINGDEP_OPTS
30 //------------ global variables related to factory -----------------
31 }
32}
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:3493
#define rTest(r)
Definition ring.h:794

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

384{
385 poly res=NULL;
386
387 if (f!=NULL)
388 {
389 //if (r->cf->has_simple_Inverse) p_Norm(f,r);
390 if (rField_is_Zp(r)) p_Norm(f,r);
391 else if (!rField_is_Ring(r)) p_Cleardenom(f, r);
392 }
393 if (g!=NULL)
394 {
395 //if (r->cf->has_simple_Inverse) p_Norm(g,r);
396 if (rField_is_Zp(r)) p_Norm(g,r);
397 else if (!rField_is_Ring(r)) p_Cleardenom(g, r);
398 }
399 else return f; // g==0 => gcd=f (but do a p_Cleardenom/pNorm)
400 if (f==NULL) return g; // f==0 => gcd=g (but do a p_Cleardenom/pNorm)
401 if(!rField_is_Ring(r)
402 && (p_IsConstant(f,r)
403 ||p_IsConstant(g,r)))
404 {
405 res=p_One(r);
406 }
407 else if (r->cf->convSingNFactoryN!=ndConvSingNFactoryN)
408 {
410 }
411 else
412 {
413 ideal I=idInit(2,1);
414 I->m[0]=f;
415 I->m[1]=p_Copy(g,r);
416 intvec *w=NULL;
417 ring save_ring=currRing;
418 if (r!=currRing) rChangeCurrRing(r);
419 BITSET save_opt;
420 SI_SAVE_OPT1(save_opt);
421 si_opt_1 &= ~(Sy_bit(OPT_PROT));
422 ideal S1=idSyzygies(I,testHomog,&w);
423 if (w!=NULL) delete w;
424 // expect S1->m[0]=(-g/gcd,f/gcd)
425 if (IDELEMS(S1)!=1) WarnS("error in syzygy computation for GCD");
426 int lp;
427 p_TakeOutComp(&S1->m[0],1,&res,&lp,r);
428 p_Delete(&S1->m[0],r);
429 // GCD is g divided iby (-g/gcd):
430 res=p_Divide(g,res,r);
431 // restore, r, opt:
432 SI_RESTORE_OPT1(save_opt);
433 if (r!=save_ring) rChangeCurrRing(save_ring);
434 // clean the result
436 if (nCoeff_is_Ring(r->cf)) p_Content(res,r);
437 return res;
438 }
439 p_Delete(&f, r);
440 p_Delete(&g, r);
441 return res;
442}
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:836
void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r)
Definition p_polys.cc:3575
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:3799
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:1980
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:34
static BOOLEAN rField_is_Zp(const ring r)
Definition ring.h:506
#define IDELEMS(i)
@ testHomog
Definition structs.h:34

Variable Documentation

◆ coeffs_BIGINT

VAR coeffs coeffs_BIGINT

Definition at line 14 of file polys.cc.

◆ 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.