modulop.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT: numbers modulo p (<=32749)
6 */
7 
8 #include "misc/auxiliary.h"
9 
10 #include "factory/factory.h"
11 
12 #include "misc/mylimits.h"
13 #include "misc/sirandom.h"
14 
15 #include "reporter/reporter.h"
16 
17 #include "coeffs/coeffs.h"
18 #include "coeffs/numbers.h"
19 #include "coeffs/mpr_complex.h"
20 
21 #include "coeffs/longrat.h"
22 #include "coeffs/modulop.h"
23 
24 #include <string.h>
25 
26 BOOLEAN npGreaterZero (number k, const coeffs r);
27 number npMult (number a, number b, const coeffs r);
28 number npInit (long i, const coeffs r);
29 long npInt (number &n, const coeffs r);
30 void npPower (number a, int i, number * result,const coeffs r);
31 BOOLEAN npIsZero (number a,const coeffs r);
32 BOOLEAN npIsOne (number a,const coeffs r);
33 BOOLEAN npIsMOne (number a,const coeffs r);
34 number npDiv (number a, number b,const coeffs r);
35 number npNeg (number c,const coeffs r);
36 number npInvers (number c,const coeffs r);
37 BOOLEAN npGreater (number a, number b,const coeffs r);
38 BOOLEAN npEqual (number a, number b,const coeffs r);
39 void npWrite (number a, const coeffs r);
40 void npCoeffWrite (const coeffs r, BOOLEAN details);
41 const char * npRead (const char *s, number *a,const coeffs r);
42 void nvInpMult(number &a, number b, const coeffs r);
43 
44 #ifdef LDEBUG
45 BOOLEAN npDBTest (number a, const char *f, const int l, const coeffs r);
46 #endif
47 
48 nMapFunc npSetMap(const coeffs src, const coeffs dst);
49 
50 #ifdef NV_OPS
51 #pragma GCC diagnostic ignored "-Wlong-long"
52 static inline number nvMultM(number a, number b, const coeffs r)
53 {
54  assume( getCoeffType(r) == n_Zp );
55 
56 #if SIZEOF_LONG == 4
57 #define ULONG64 (unsigned long long)(unsigned long)
58 #else
59 #define ULONG64 (unsigned long)
60 #endif
61  return (number)
62  (unsigned long)((ULONG64 a)*(ULONG64 b) % (ULONG64 r->ch));
63 }
64 number nvMult (number a, number b, const coeffs r);
65 number nvDiv (number a, number b, const coeffs r);
66 number nvInvers (number c, const coeffs r);
67 //void nvPower (number a, int i, number * result, const coeffs r);
68 #endif
69 
70 BOOLEAN npGreaterZero (number k, const coeffs r)
71 {
72  n_Test(k, r);
73 
74  int h = (int)((long) k);
75  return ((int)h !=0) && (h <= (r->ch>>1));
76 }
77 
78 //unsigned long npMultMod(unsigned long a, unsigned long b, int npPrimeM)
79 //{
80 // unsigned long c = a*b;
81 // c = c % npPrimeM;
82 // assume(c == (unsigned long) npMultM((number) a, (number) b, npPrimeM));
83 // return c;
84 //}
85 
86 number npMult (number a,number b, const coeffs r)
87 {
88  n_Test(a, r);
89  n_Test(b, r);
90 
91  if (((long)a == 0) || ((long)b == 0))
92  return (number)0;
93  number c = npMultM(a,b, r);
94  n_Test(c, r);
95  return c;
96 }
97 
98 void npInpMult (number &a,number b, const coeffs r)
99 {
100  n_Test(a, r);
101  n_Test(b, r);
102 
103  if (((long)a == 0) || ((long)b == 0))
104  a=(number)0;
105  else
106  a = npMultM(a,b, r);
107  n_Test(a, r);
108 }
109 
110 /*2
111 * create a number from int
112 */
113 number npInit (long i, const coeffs r)
114 {
115  long ii=i % (long)r->ch;
116  if (ii < 0L) ii += (long)r->ch;
117 
118  number c = (number)ii;
119  n_Test(c, r);
120  return c;
121 }
122 
123 
124 /*2
125  * convert a number to an int in (-p/2 .. p/2]
126  */
127 long npInt(number &n, const coeffs r)
128 {
129  n_Test(n, r);
130 
131  if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
132  else return ((long)n);
133 }
134 
135 BOOLEAN npIsZero (number a, const coeffs r)
136 {
137  n_Test(a, r);
138 
139  return 0 == (long)a;
140 }
141 
142 BOOLEAN npIsMOne (number a, const coeffs r)
143 {
144  n_Test(a, r);
145 
146  return ((r->npPminus1M == (long)a) &&(1L!=(long)a))/*for char 2*/;
147 }
148 
149 number npDiv (number a,number b, const coeffs r)
150 {
151  n_Test(a, r);
152  n_Test(b, r);
153 
154  if ((long)b==0L)
155  {
156  WerrorS(nDivBy0);
157  return (number)0L;
158  }
159  if ((long)a==0) return (number)0L;
160 
161  number d;
162 #ifndef HAVE_GENERIC_MULT
163  int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
164  #ifdef HAVE_GENERIC_ADD
165  if (s < 0)
166  s += r->npPminus1M;
167  #else
168  #if SIZEOF_LONG == 8
169  s += ((long)s >> 63) & r->npPminus1M;
170  #else
171  s += ((long)s >> 31) & r->npPminus1M;
172  #endif
173  #endif
174  d = (number)(long)r->npExpTable[s];
175 #else
176  number inv=npInversM(b,r);
177  d = npMultM(a,inv,r);
178 #endif
179 
180  n_Test(d, r);
181  return d;
182 
183 }
184 number npInvers (number c, const coeffs r)
185 {
186  n_Test(c, r);
187 
188  if ((long)c==0L)
189  {
190  WerrorS("1/0");
191  return (number)0L;
192  }
193  number d = npInversM(c,r);
194 
195  n_Test(d, r);
196  return d;
197 }
198 
199 number npNeg (number c, const coeffs r)
200 {
201  n_Test(c, r);
202 
203  if ((long)c==0L) return c;
204 
205 #if 0
206  number d = npNegM(c,r);
207  n_Test(d, r);
208  return d;
209 #else
210  c = npNegM(c,r);
211  n_Test(c, r);
212  return c;
213 #endif
214 }
215 
216 BOOLEAN npGreater (number a,number b, const coeffs r)
217 {
218  n_Test(a, r);
219  n_Test(b, r);
220 
221  //return (long)a != (long)b;
222  return ((long)a) > ((long)b);
223 }
224 
225 BOOLEAN npEqual (number a,number b, const coeffs r)
226 {
227  n_Test(a, r);
228  n_Test(b, r);
229 
230 // return (long)a == (long)b;
231 
232  return npEqualM(a,b,r);
233 }
234 
235 void npWrite (number a, const coeffs r)
236 {
237  n_Test(a, r);
238 
239  if ((long)a>(((long)r->ch) >>1)) StringAppend("-%d",(int)(((long)r->ch)-((long)a)));
240  else StringAppend("%d",(int)((long)a));
241 }
242 
243 #if 0
244 void npPower (number a, int i, number * result, const coeffs r)
245 {
246  n_Test(a, r);
247 
248  if (i==0)
249  {
250  //npInit(1,result);
251  *(long *)result = 1;
252  }
253  else if (i==1)
254  {
255  *result = a;
256  }
257  else
258  {
259  npPower(a,i-1,result,r);
260  *result = npMultM(a,*result,r);
261  }
262 }
263 #endif
264 
265 static inline const char* npEati(const char *s, int *i, const coeffs r)
266 {
267  return nEati((char *)s,i,(int)r->ch);
268 }
269 
270 const char * npRead (const char *s, number *a, const coeffs r)
271 {
272  int z;
273  int n=1;
274 
275  s = npEati(s, &z, r);
276  if ((*s) == '/')
277  {
278  s++;
279  s = npEati(s, &n, r);
280  }
281  if (n == 1)
282  *a = (number)(long)z;
283  else
284  {
285  if ((z==0)&&(n==0)) WerrorS(nDivBy0);
286  else
287  {
288 #ifdef NV_OPS
289  if (r->ch>NV_MAX_PRIME)
290  *a = nvDiv((number)(long)z,(number)(long)n,r);
291  else
292 #endif
293  *a = npDiv((number)(long)z,(number)(long)n,r);
294  }
295  }
296  n_Test(*a, r);
297  return s;
298 }
299 
300 /*2
301 * set the charcteristic (allocate and init tables)
302 */
303 
305 {
306  #ifdef HAVE_INVTABLE
307  if (r->npInvTable!=NULL)
308  {
309  omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) );
310  r->npInvTable=NULL;
311  }
312  #endif
313  #ifndef HAVE_GENERIC_MULT
314  if (r->npExpTable!=NULL)
315  {
316  omFreeSize( (void *)r->npExpTable, r->ch*sizeof(unsigned short) );
317  omFreeSize( (void *)r->npLogTable, r->ch*sizeof(unsigned short) );
318  r->npExpTable=NULL; r->npLogTable=NULL;
319  }
320  #endif
321 }
322 
323 static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void * parameter)
324 {
325  /* test, if r is an instance of nInitCoeffs(n,parameter) */
326  return (n==n_Zp) && (r->ch==(int)(long)parameter);
327 }
328 CanonicalForm npConvSingNFactoryN( number n, BOOLEAN setChar, const coeffs r )
329 {
330  if (setChar) setCharacteristic( r->ch );
331  return CanonicalForm(npInt( n,r ));
332 }
333 
334 number npConvFactoryNSingN( const CanonicalForm n, const coeffs r)
335 {
336  if (n.isImm())
337  {
338  return npInit(n.intval(),r);
339  }
340  else
341  {
342  assume(0);
343  return NULL;
344  }
345 }
346 
347 static char* npCoeffName(const coeffs cf)
348 {
349  STATIC_VAR char npCoeffName_buf[15];
350  snprintf(npCoeffName_buf,14,"ZZ/%d",cf->ch);
351  return npCoeffName_buf;
352 }
353 
354 static char* npCoeffString(const coeffs cf)
355 {
356  return omStrDup(npCoeffName(cf));
357 }
358 
359 static void npWriteFd(number n, const ssiInfo* d, const coeffs)
360 {
361  fprintf(d->f_write,"%d ",(int)(long)n);
362 }
363 
364 static number npReadFd(const ssiInfo *d, const coeffs)
365 {
366  // read int
367  int dd;
368  dd=s_readint(d->f_read);
369  return (number)(long)dd;
370 }
371 
372 static number npRandom(siRandProc p, number, number, const coeffs cf)
373 {
374  return npInit(p(),cf);
375 }
376 
378 {
379  assume( getCoeffType(r) == n_Zp );
380  const int c = (int) (long) p;
381 
382  assume( c > 0 );
383 
384  int i, w;
385 
386  r->is_field=TRUE;
387  r->is_domain=TRUE;
388  r->rep=n_rep_int;
389 
390  r->ch = c;
391  r->npPminus1M = c /*r->ch*/ - 1;
392 
393  //r->cfInitChar=npInitChar;
394  r->cfKillChar=npKillChar;
395  r->nCoeffIsEqual=npCoeffsEqual;
396  r->cfCoeffString=npCoeffString;
397  r->cfCoeffName=npCoeffName;
398  r->cfCoeffWrite=npCoeffWrite;
399 
400  r->cfMult = npMult;
401  r->cfInpMult = npInpMult;
402  r->cfSub = npSubM;
403  r->cfAdd = npAddM;
404  r->cfInpAdd = npInpAddM;
405  r->cfDiv = npDiv;
406  r->cfInit = npInit;
407  //r->cfSize = ndSize;
408  r->cfInt = npInt;
409  #ifdef HAVE_RINGS
410  //r->cfDivComp = NULL; // only for ring stuff
411  //r->cfIsUnit = NULL; // only for ring stuff
412  //r->cfGetUnit = NULL; // only for ring stuff
413  //r->cfExtGcd = NULL; // only for ring stuff
414  // r->cfDivBy = NULL; // only for ring stuff
415  #endif
416  r->cfInpNeg = npNeg;
417  r->cfInvers= npInvers;
418  //r->cfCopy = ndCopy;
419  //r->cfRePart = ndCopy;
420  //r->cfImPart = ndReturn0;
421  r->cfWriteLong = npWrite;
422  r->cfRead = npRead;
423  //r->cfNormalize=ndNormalize;
424  r->cfGreater = npGreater;
425  r->cfEqual = npEqual;
426  r->cfIsZero = npIsZero;
427  r->cfIsOne = npIsOne;
428  r->cfIsMOne = npIsMOne;
429  r->cfGreaterZero = npGreaterZero;
430  //r->cfPower = npPower;
431  //r->cfGetDenom = ndGetDenom;
432  //r->cfGetNumerator = ndGetNumerator;
433  //r->cfGcd = ndGcd;
434  //r->cfLcm = ndGcd;
435  //r->cfDelete= ndDelete;
436  r->cfSetMap = npSetMap;
437  //r->cfName = ndName;
438  //r->cfInpMult=ndInpMult;
439  r->convSingNFactoryN=npConvSingNFactoryN;
440  r->convFactoryNSingN=npConvFactoryNSingN;
441  r->cfRandom=npRandom;
442 #ifdef LDEBUG
443  // debug stuff
444  r->cfDBTest=npDBTest;
445 #endif
446 
447  // io via ssi
448  r->cfWriteFd=npWriteFd;
449  r->cfReadFd=npReadFd;
450 
451  // the variables:
452  r->type = n_Zp;
453  r->has_simple_Alloc=TRUE;
454  r->has_simple_Inverse=TRUE;
455 
456  // the tables
457 #ifdef NV_OPS
458  if (r->ch <=NV_MAX_PRIME)
459 #endif
460  {
461 #ifdef HAVE_INVTABLE
462  r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
463 #endif
464 #ifndef HAVE_GENERIC_MULT
465  r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
466  r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
467  r->npExpTable[0] = 1;
468  r->npLogTable[0] = 0;
469  if (r->ch > 2)
470  {
471  w = 1;
472  loop
473  {
474  r->npLogTable[1] = 0;
475  w++;
476  i = 0;
477  loop
478  {
479  i++;
480  r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
481  r->npLogTable[r->npExpTable[i]] = i;
482  if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
483  break;
484  }
485  if (i == r->ch - 1)
486  break;
487  }
488  }
489  else
490  {
491  r->npExpTable[1] = 1;
492  r->npLogTable[1] = 0;
493  }
494 #endif
495  }
496 #ifdef NV_OPS
497  else /*if (c>NV_MAX_PRIME)*/
498  {
499  r->cfMult = nvMult;
500  r->cfDiv = nvDiv;
501  r->cfExactDiv = nvDiv;
502  r->cfInvers = nvInvers;
503  r->cfInpMult = nvInpMult;
504  //r->cfPower= nvPower;
505  //if (c>FACTORY_MAX_PRIME) // factory will catch this error
506  //{
507  // r->convSingNFactoryN=ndConvSingNFactoryN;
508  //}
509  }
510 #endif
511  return FALSE;
512 }
513 
514 #ifdef LDEBUG
515 BOOLEAN npDBTest (number a, const char *f, const int l, const coeffs r)
516 {
517  if (((long)a<0L) || ((long)a>(long)r->ch))
518  {
519  Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
520  return FALSE;
521  }
522  return TRUE;
523 }
524 #endif
525 
526 static number npMapP(number from, const coeffs src, const coeffs dst_r)
527 {
528  long i = (long)from;
529  if (i>src->ch/2)
530  {
531  i-=src->ch;
532  while (i < 0) i+=dst_r->ch;
533  }
534  i%=dst_r->ch;
535  return (number)i;
536 }
537 
538 static number npMapLongR(number from, const coeffs /*src*/, const coeffs dst_r)
539 {
540  gmp_float *ff=(gmp_float*)from;
541  mpf_t *f=ff->_mpfp();
542  number res;
543  mpz_ptr dest,ndest;
544  int size,i;
545  int e,al,bl;
546  long iz;
547  mp_ptr qp,dd,nn;
548 
549  size = (*f)[0]._mp_size;
550  if (size == 0)
551  return npInit(0,dst_r);
552  if(size<0)
553  size = -size;
554 
555  qp = (*f)[0]._mp_d;
556  while(qp[0]==0)
557  {
558  qp++;
559  size--;
560  }
561 
562  if(dst_r->ch>2)
563  e=(*f)[0]._mp_exp-size;
564  else
565  e=0;
566  res = ALLOC_RNUMBER();
567 #if defined(LDEBUG)
568  res->debug=123456;
569 #endif
570  dest = res->z;
571 
572  long in=0;
573  if (e<0)
574  {
575  al = dest->_mp_size = size;
576  if (al<2) al = 2;
577  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
578  for (i=0;i<size;i++) dd[i] = qp[i];
579  bl = 1-e;
580  nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
581  nn[bl-1] = 1;
582  for (i=bl-2;i>=0;i--) nn[i] = 0;
583  ndest = res->n;
584  ndest->_mp_d = nn;
585  ndest->_mp_alloc = ndest->_mp_size = bl;
586  res->s = 0;
587  in=mpz_fdiv_ui(ndest,dst_r->ch);
588  mpz_clear(ndest);
589  }
590  else
591  {
592  al = dest->_mp_size = size+e;
593  if (al<2) al = 2;
594  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
595  for (i=0;i<size;i++) dd[i+e] = qp[i];
596  for (i=0;i<e;i++) dd[i] = 0;
597  res->s = 3;
598  }
599 
600  dest->_mp_d = dd;
601  dest->_mp_alloc = al;
602  iz=mpz_fdiv_ui(dest,dst_r->ch);
603  mpz_clear(dest);
604  if(res->s==0)
605  iz=(long)npDiv((number)iz,(number)in,dst_r);
606  FREE_RNUMBER(res); // Q!?
607  return (number)iz;
608 }
609 
610 #ifdef HAVE_RINGS
611 /*2
612 * convert from a GMP integer
613 */
614 static number npMapGMP(number from, const coeffs /*src*/, const coeffs dst)
615 {
616  mpz_ptr erg = (mpz_ptr) omAlloc(sizeof(mpz_t)); // evtl. spaeter mit bin
617  mpz_init(erg);
618 
619  mpz_mod_ui(erg, (mpz_ptr) from, dst->ch);
620  number r = (number) mpz_get_si(erg);
621 
622  mpz_clear(erg);
623  omFree((void *) erg);
624  return (number) r;
625 }
626 
627 static number npMapZ(number from, const coeffs src, const coeffs dst)
628 {
629  if (SR_HDL(from) & SR_INT)
630  {
631  long f_i=SR_TO_INT(from);
632  return npInit(f_i,dst);
633  }
634  return npMapGMP(from,src,dst);
635 }
636 
637 /*2
638 * convert from an machine long
639 */
640 static number npMapMachineInt(number from, const coeffs /*src*/,const coeffs dst)
641 {
642  long i = (long) (((unsigned long) from) % dst->ch);
643  return (number) i;
644 }
645 #endif
646 
647 static number npMapCanonicalForm (number a, const coeffs /*src*/, const coeffs dst)
648 {
649  setCharacteristic (dst ->ch);
651  return (number) (f.intval());
652 }
653 
654 nMapFunc npSetMap(const coeffs src, const coeffs dst)
655 {
656 #ifdef HAVE_RINGS
657  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
658  {
659  return npMapMachineInt;
660  }
661  if (src->rep==n_rep_gmp) //nCoeff_is_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Zn(src))
662  {
663  return npMapGMP;
664  }
665  if (src->rep==n_rep_gap_gmp) //nCoeff_is_Z(src)
666  {
667  return npMapZ;
668  }
669 #endif
670  if (src->rep==n_rep_gap_rat) /* Q, Z */
671  {
672  return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
673  }
674  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
675  {
676  if (n_GetChar(src) == n_GetChar(dst))
677  {
678  return ndCopyMap;
679  }
680  else
681  {
682  return npMapP;
683  }
684  }
685  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
686  {
687  return npMapLongR;
688  }
689  if (nCoeff_is_CF (src))
690  {
691  return npMapCanonicalForm;
692  }
693  return NULL; /* default */
694 }
695 
696 // -----------------------------------------------------------
697 // operation for very large primes (32749< p < 2^31-1)
698 // ----------------------------------------------------------
699 #ifdef NV_OPS
700 
701 number nvMult (number a,number b, const coeffs r)
702 {
703  //if (((long)a == 0) || ((long)b == 0))
704  // return (number)0;
705  //else
706  return nvMultM(a,b,r);
707 }
708 
709 void nvInpMult(number &a, number b, const coeffs r)
710 {
711  number n=nvMultM(a,b,r);
712  a=n;
713 }
714 
715 static inline number nvInversM (number c, const coeffs r)
716 {
717  long inv=npInvMod((long)c,r);
718  return (number)inv;
719 }
720 
721 number nvDiv (number a,number b, const coeffs r)
722 {
723  if ((long)a==0L)
724  return (number)0L;
725  else if ((long)b==0L)
726  {
727  WerrorS(nDivBy0);
728  return (number)0L;
729  }
730  else
731  {
732  number inv=nvInversM(b,r);
733  return nvMultM(a,inv,r);
734  }
735 }
736 number nvInvers (number c, const coeffs r)
737 {
738  if ((long)c==0L)
739  {
740  WerrorS(nDivBy0);
741  return (number)0L;
742  }
743  return nvInversM(c,r);
744 }
745 #if 0
746 void nvPower (number a, int i, number * result, const coeffs r)
747 {
748  if (i==0)
749  {
750  //npInit(1,result);
751  *(long *)result = 1;
752  }
753  else if (i==1)
754  {
755  *result = a;
756  }
757  else
758  {
759  nvPower(a,i-1,result,r);
760  *result = nvMultM(a,*result,r);
761  }
762 }
763 #endif
764 #endif
765 
766 void npCoeffWrite (const coeffs r, BOOLEAN /*details*/)
767 {
768  Print("ZZ/%d",r->ch);
769 }
770 
long intval() const
conversion functions
Definition: s_buff.h:20
const CanonicalForm int s
Definition: facAbsFact.cc:55
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:640
static number npInversM(number c, const coeffs r)
Definition: modulop.h:230
#define Print
Definition: emacs.cc:80
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:822
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:68
number npInit(long i, const coeffs r)
Definition: modulop.cc:113
long npInt(number &n, const coeffs r)
Definition: modulop.cc:127
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1435
#define FALSE
Definition: auxiliary.h:96
mpf_t * _mpfp()
Definition: mpr_complex.h:134
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:736
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251
bool isImm() const
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:913
void npPower(number a, int i, number *result, const coeffs r)
number npInvers(number c, const coeffs r)
Definition: modulop.cc:184
#define npEqualM(A, B, r)
Definition: modulop.h:271
static number npMapP(number from, const coeffs src, const coeffs dst_r)
Definition: modulop.cc:526
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:347
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:701
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
static number nvInversM(number c, const coeffs r)
Definition: modulop.cc:715
{p < 2^31}
Definition: coeffs.h:30
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition: numbers.cc:630
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:746
(), see rinteger.h, new impl.
Definition: coeffs.h:112
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:709
void npWrite(number a, const coeffs r)
Definition: modulop.cc:235
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
factory&#39;s main class
Definition: canonicalform.h:77
#define TRUE
Definition: auxiliary.h:100
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:149
#define FREE_RNUMBER(x)
Definition: coeffs.h:86
void WerrorS(const char *s)
Definition: feFopen.cc:24
int k
Definition: cfEzgcd.cc:92
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:225
#define loop
Definition: structs.h:80
BOOLEAN npInitChar(coeffs r, void *p)
Definition: modulop.cc:377
#define omAlloc(size)
Definition: omAllocDecl.h:210
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:515
void setCharacteristic(int c)
Definition: cf_char.cc:23
virtual class for internal CanonicalForm&#39;s
Definition: int_cf.h:41
static number npNegM(number a, const coeffs r)
Definition: modulop.h:171
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:131
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:372
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:216
CanonicalForm b
Definition: cfModGcd.cc:4044
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:721
s_buff f_read
Definition: s_buff.h:22
if(yy_init)
Definition: libparse.cc:1420
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:142
Coefficient rings, fields and other domains suitable for Singular polynomials.
void npCoeffWrite(const coeffs r, BOOLEAN details)
Definition: modulop.cc:766
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:919
CanonicalForm res
Definition: facAbsFact.cc:64
int s_readint(s_buff F)
Definition: s_buff.cc:112
#define omFree(addr)
Definition: omAllocDecl.h:261
#define assume(x)
Definition: mod2.h:390
The main handler for Singular numbers which are suitable for Singular polynomials.
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:70
static const char * npEati(const char *s, int *i, const coeffs r)
Definition: modulop.cc:265
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:738
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:121
static number npReadFd(const ssiInfo *d, const coeffs)
Definition: modulop.cc:364
All the auxiliary stuff.
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition: modulop.cc:359
const char *const nDivBy0
Definition: numbers.h:88
#define STATIC_VAR
Definition: globaldefs.h:7
#define StringAppend
Definition: emacs.cc:79
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:654
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
static long npInvMod(long a, const coeffs R)
Definition: modulop.h:185
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:538
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
int(* siRandProc)()
Definition: sirandom.h:9
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:334
#define NV_MAX_PRIME
Definition: modulop.h:29
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define SR_TO_INT(SR)
Definition: longrat.h:68
(number), see longrat.h
Definition: coeffs.h:111
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:126
void npInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:98
STATIC_VAR Poly * h
Definition: janet.cc:971
static char * npCoeffString(const coeffs cf)
Definition: modulop.cc:354
n_coeffType
Definition: coeffs.h:27
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define NULL
Definition: omList.c:12
FILE * f_write
Definition: s_buff.h:23
#define ULONG64
(gmp_float), see
Definition: coeffs.h:117
number npNeg(number c, const coeffs r)
Definition: modulop.cc:199
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:647
#define SR_INT
Definition: longrat.h:66
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:627
const CanonicalForm & w
Definition: facAbsFact.cc:55
#define ALLOC_RNUMBER()
Definition: coeffs.h:87
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:86
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:328
static number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:614
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:323
(int), see modulop.h
Definition: coeffs.h:110
#define SR_HDL(A)
Definition: tgb.cc:35
int p
Definition: cfModGcd.cc:4019
void npKillChar(coeffs r)
Definition: modulop.cc:304
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:270
int BOOLEAN
Definition: auxiliary.h:87
BOOLEAN npIsOne(number a, const coeffs r)
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:135
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93
return result
Definition: facAbsBiFact.cc:76
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:52
#define omStrDup(s)
Definition: omAllocDecl.h:263