My Project
rintegers3.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT: numbers (integers)
6 */
7 #ifdef HAVE_RINGS
8 #if SI_INTEGER_VARIANT == 3
9 
10 //make sure that a small number is an immediate integer
11 //bascially copied from longrat.cc nlShort3
12 //TODO: is there any point in checking 0 first???
13 //TODO: it is not clear that this works in 32/64 bit everywhere.
14 // too many hacks.
15 #ifdef LDEBUG
16 #define nrzTest(A) nrzDBTest(A,__FILE__,__LINE__,NULL)
17 BOOLEAN nrzDBTest (number x, const char *f, const int l, const coeffs);
18 #else
19 #define nrzTest(A)
20 #endif
21 
22 #undef CF_DEBUG
23 static inline number nrz_short(number x)
24 {
25 #if CF_DEBUG
26  StringAppendS("short(");
27  nrzWrite(x, NULL);
28 #endif
29  if (mpz_sgn1((mpz_ptr) x)==0)
30  {
31  mpz_clear((mpz_ptr)x);
33 #if CF_DEBUG
34  StringAppendS(")=0");
35 #endif
36  return INT_TO_SR(0);
37  }
38  if (mpz_size1((mpz_ptr)x)<=MP_SMALL)
39  {
40  long ui=mpz_get_si((mpz_ptr)x);
41  if ((((ui<<3)>>3)==ui)
42  && (mpz_cmp_si((mpz_ptr)x,ui)==0))
43  {
44  mpz_clear((mpz_ptr)x);
46 #if CF_DEBUG
47  StringAppendS(")=imm");
48 #endif
49  return INT_TO_SR(ui);
50  }
51  }
52 #if CF_DEBUG
53  StringAppendS(")");
54 #endif
55  return x;
56 }
57 
58 
59 static int nrzSize(number a, const coeffs)
60 {
61  if (a==INT_TO_SR(0)) return 0;
62  if (n_Z_IS_SMALL(a)) return 1;
63  return ((mpz_ptr)a)->_mp_alloc;
64 }
65 
66 
67 /*
68  * Multiply two numbers
69  * check for 0, 1, -1 maybe
70  */
71 #if CF_DEBUG
72 number _nrzMult(number, number, const coeffs);
73 number nrzMult(number a, number b, const coeffs R)
74 {
75  StringSetS("Mult: ");
76  nrzWrite(a, R);
77  StringAppendS(" by ");
78  nrzWrite(b, R);
79  number c = _nrzMult(a, b, R);
80  StringAppendS(" is ");
81  nrzWrite(c, R);
82  char * s = StringEndS();
83  Print("%s\n", s);
84  omFree(s);
85  return c;
86 }
87 number _nrzMult (number a, number b, const coeffs R)
88 #else
89 number nrzMult (number a, number b, const coeffs R)
90 #endif
91 {
92  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
93  {
94  //from longrat.cc
95  if (SR_TO_INT(a)==0)
96  return a;
97  if (SR_TO_INT(b)==0)
98  return b;
99  long r=(long)((unsigned long)(SR_HDL(a)-1L))*((unsigned long)(SR_HDL(b)>>1));
100  if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1L))
101  {
102  number u=((number) ((r>>1)+SR_INT));
103  // if (((((long)SR_HDL(u))<<1)>>1)==SR_HDL(u)) return (u);
104  return nrzInit(SR_HDL(u)>>2, R);
105  }
106  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
107  mpz_init(erg);
108  mpz_set_si(erg, SR_TO_INT(a));
109  mpz_mul_si(erg, erg, SR_TO_INT(b));
110  nrzTest((number)erg);
111  return (number) erg;
112  }
113  else if (n_Z_IS_SMALL(a))
114  {
115  if (SR_TO_INT(a)==0)
116  return a;
117  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
118  mpz_init_set(erg, (mpz_ptr) b);
119  mpz_mul_si(erg, erg, SR_TO_INT(a));
120  nrzTest((number)erg);
121  return (number) erg;
122  }
123  else if (n_Z_IS_SMALL(b))
124  {
125  if (SR_TO_INT(b)==0)
126  return b;
127  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
128  mpz_init_set(erg, (mpz_ptr) a);
129  mpz_mul_si(erg, erg, SR_TO_INT(b));
130  nrzTest((number)erg);
131  return (number) erg;
132  }
133  else
134  {
135  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
136  mpz_init(erg);
137  mpz_mul(erg, (mpz_ptr) a, (mpz_ptr) b);
138  nrzTest((number)erg);
139  return (number) erg;
140  }
141 }
142 
143 
144 static long int_gcd(long a, long b)
145 {
146  long r;
147  a = ABS(a);
148  b = ABS(b);
149  if (!a) return b;
150  if (!b) return a;
151  do
152  {
153  r = a % b;
154  a = b;
155  b = r;
156  } while (b);
157  return ABS(a); // % in c doeas not imply a signn
158  // it would be unlikely to see a negative here
159  // but who knows
160 }
161 
162 /*
163  * Give the smallest non unit k, such that a * x = k = b * y has a solution
164  */
165 static number nrzLcm (number a, number b, const coeffs R)
166 {
167  #ifdef CF_DEBUG
168  PrintS("nrzLcm\n");
169  #endif
170  mpz_ptr erg;
171  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
172  {
173  long g = int_gcd(SR_TO_INT(a), SR_TO_INT(b));
174  return nrzMult(a, INT_TO_SR(SR_TO_INT(b)/g), R);
175  }
176  else
177  {
178  erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
179  if (n_Z_IS_SMALL(a))
180  {
181  mpz_init_set(erg, (mpz_ptr) b);
182  unsigned long g = mpz_gcd_ui(NULL, erg, (unsigned long) ABS(SR_TO_INT(a)));
183  mpz_mul_si(erg, erg, SR_TO_INT(a)/g);
184  }
185  else if (n_Z_IS_SMALL(b))
186  {
187  mpz_init_set(erg, (mpz_ptr) a);
188  unsigned long g = mpz_gcd_ui(NULL, erg, (unsigned long) ABS(SR_TO_INT(b)));
189  mpz_mul_si(erg, erg, SR_TO_INT(b)/g);
190  }
191  else
192  {
193  mpz_init(erg);
194  mpz_lcm(erg, (mpz_ptr) a, (mpz_ptr) b);
195  }
196  }
197  return (number) erg;
198 }
199 
200 static number nrzCopy(number a, const coeffs)
201 {
202  if (n_Z_IS_SMALL(a)) return a;
203  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
204  mpz_init_set(erg, (mpz_ptr) a);
205  return (number) erg;
206 }
207 
208 /*
209  * Give the largest non unit k, such that a = x * k, b = y * k has
210  * a solution.
211  */
212 static number nrzGcd (number a,number b,const coeffs R)
213 {
214  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
215  {
216  long g = int_gcd(SR_TO_INT(a), SR_TO_INT(b));
217  return INT_TO_SR(g);
218  }
219  else if (n_Z_IS_SMALL(a))
220  {
221  if (a==INT_TO_SR(0))
222  return nrzCopy(b, R);
223  unsigned long g = mpz_gcd_ui(NULL, (mpz_ptr)b, (unsigned long) ABS(SR_TO_INT(a)));
224  return INT_TO_SR( g);
225  }
226  else if (n_Z_IS_SMALL(b))
227  {
228  if (b==INT_TO_SR(0))
229  return nrzCopy(a, R);
230  unsigned long g = mpz_gcd_ui(NULL, (mpz_ptr)a, (unsigned long) ABS(SR_TO_INT(b)));
231  return INT_TO_SR(g);
232  }
233  else
234  {
235  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
236  mpz_init(erg);
237  mpz_gcd(erg, (mpz_ptr) a, (mpz_ptr) b);
238  return (number) erg;
239  }
240 }
241 
242 /*
243  * Give the largest non unit k, such that a = x * k, b = y * k has
244  * a solution and r, s, s.t. k = s*a + t*b
245  */
246 static long int_extgcd(long a, long b, long * u, long* x, long * v, long* y)
247 {
248  long q, r;
249  if (!a)
250  {
251  *u = 0;
252  *v = 1;
253  *x = -1;
254  *y = 0;
255  return b;
256  }
257  if (!b)
258  {
259  *u = 1;
260  *v = 0;
261  *x = 0;
262  *y = 1;
263  return a;
264  }
265  *u=1;
266  *v=0;
267  *x=0;
268  *y=1;
269  do
270  {
271  q = a/b;
272  r = a%b;
273  assume (q*b+r == a);
274  a = b;
275  b = r;
276 
277  r = -(*v)*q+(*u);
278  (*u) =(*v);
279  (*v) = r;
280 
281  r = -(*y)*q+(*x);
282  (*x) = (*y);
283  (*y) = r;
284  } while (b);
285 
286  return a;
287 }
288 
289 static number nrzExtGcd (number a, number b, number *s, number *t, const coeffs)
290 {
291  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
292  {
293  long u, v, x, y;
294  long g = int_extgcd(SR_TO_INT(a), SR_TO_INT(b), &u, &v, &x, &y);
295  *s = INT_TO_SR(u);
296  *t = INT_TO_SR(v);
297  return INT_TO_SR(g);
298  }
299  else
300  {
301  mpz_t aa, bb;
302  if (n_Z_IS_SMALL(a))
303  {
304  mpz_init_set_si(aa, SR_TO_INT(a));
305  }
306  else
307  {
308  mpz_init_set(aa, (mpz_ptr) a);
309  }
310  if (n_Z_IS_SMALL(b))
311  {
312  mpz_init_set_si(bb, SR_TO_INT(b));
313  }
314  else
315  {
316  mpz_init_set(bb, (mpz_ptr) b);
317  }
318  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
319  mpz_ptr bs = (mpz_ptr) omAllocBin(gmp_nrz_bin);
320  mpz_ptr bt = (mpz_ptr) omAllocBin(gmp_nrz_bin);
321  mpz_init(erg);
322  mpz_init(bs);
323  mpz_init(bt);
324  mpz_gcdext(erg, bs, bt, aa, bb);
325  *s = nrz_short((number) bs);
326  *t = nrz_short((number) bt);
327  mpz_clear(aa);
328  mpz_clear(bb);
329  return nrz_short((number) erg);
330  }
331 }
332 #if CF_DEBUG
333 static number _nrzXExtGcd(number, number, number *, number *, number *, number *, const coeffs);
334 static number nrzXExtGcd(number a, number b, number *x, number * y, number * u, number * v, const coeffs R)
335 {
336  char * s;
337  StringSetS("XExtGcd: ");
338  nrzWrite(a, R);
339  StringAppendS(" by ");
340  nrzWrite(b, R);
341  number c = _nrzXExtGcd(a, b, x, y, u, v, R);
342  StringAppendS(" is ");
343  nrzWrite(c, R);
344  StringAppendS("[[");
345  nrzWrite(*x, R);
346  StringAppendS(", ");
347  nrzWrite(*y, R);
348  StringAppendS("], ");
349  nrzWrite(*u, R);
350  StringAppendS(", ");
351  nrzWrite(*v, R);
352  s=StringEndS();
353  Print("%s]]\n", s);
354  omFree(s);
355  return c;
356 }
357 static number _nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v, const coeffs )
358 #else
359 static number nrzXExtGcd (number a, number b, number *s, number *t, number *u, number *v, const coeffs )
360 #endif
361 {
362  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
363  {
364  long uu, vv, x, y;
365  long g = int_extgcd(SR_TO_INT(a), SR_TO_INT(b), &uu, &vv, &x, &y);
366  *s = INT_TO_SR(uu);
367  *t = INT_TO_SR(vv);
368  *u = INT_TO_SR(x);
369  *v = INT_TO_SR(y);
370  return INT_TO_SR(g);
371  }
372  else
373  {
374  mpz_t aa, bb;
375  if (n_Z_IS_SMALL(a))
376  {
377  mpz_init_set_si(aa, SR_TO_INT(a));
378  }
379  else
380  {
381  mpz_init_set(aa, (mpz_ptr) a);
382  }
383  if (n_Z_IS_SMALL(b))
384  {
385  mpz_init_set_si(bb, SR_TO_INT(b));
386  }
387  else
388  {
389  mpz_init_set(bb, (mpz_ptr) b);
390  }
391  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
392  mpz_ptr bs = (mpz_ptr) omAllocBin(gmp_nrz_bin);
393  mpz_ptr bt = (mpz_ptr) omAllocBin(gmp_nrz_bin);
394  mpz_init(erg);
395  mpz_init(bs);
396  mpz_init(bt);
397 
398  mpz_gcdext(erg, bs, bt, aa, bb);
399 
400  mpz_ptr bu = (mpz_ptr) omAllocBin(gmp_nrz_bin);
401  mpz_ptr bv = (mpz_ptr) omAllocBin(gmp_nrz_bin);
402 
403  mpz_init_set(bu, (mpz_ptr) bb);
404  mpz_init_set(bv, (mpz_ptr) aa);
405 
406  mpz_clear(aa);
407  mpz_clear(bb);
408  assume(mpz_cmp_si(erg, 0));
409 
410  mpz_div(bu, bu, erg);
411  mpz_div(bv, bv, erg);
412 
413  mpz_mul_si(bu, bu, -1);
414  *u = nrz_short((number) bu);
415  *v = nrz_short((number) bv);
416 
417  *s = nrz_short((number) bs);
418  *t = nrz_short((number) bt);
419  return nrz_short((number) erg);
420  }
421 }
422 #if CF_DEBUG
423 static number _nrzQuotRem(number, number, number *, const coeffs);
424 static number nrzQuotRem(number a, number b, number * r, const coeffs R)
425 {
426  StringSetS("QuotRem: ");
427  nrzWrite(a, R);
428  StringAppendS(" by ");
429  nrzWrite(b, R);
430  number c = _nrzQuotRem(a, b, r, R);
431  StringAppendS(" is ");
432  nrzWrite(c, R);
433  if (r) {
434  StringAppendS("+R(");
435  nrzWrite(*r, R);
436  StringAppendS(")");
437  }
438  char * s = StringEndS();
439  Print("%s\n", s);
440  omFree(s);
441  return c;
442 }
443 static number _nrzQuotRem (number a, number b, number * r, const coeffs )
444 #else
445 static number nrzQuotRem (number a, number b, number * r, const coeffs )
446 #endif
447 {
448  assume(SR_TO_INT(b));
449  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
450  {
451  if (r)
452  *r = INT_TO_SR(SR_TO_INT(a) % SR_TO_INT(b));
453  return INT_TO_SR(SR_TO_INT(a)/SR_TO_INT(b));
454  }
455  else if (n_Z_IS_SMALL(a))
456  {
457  //a is small, b is not, so q=0, r=a
458  if (r)
459  *r = a;
460  return INT_TO_SR(0);
461  }
462  else if (n_Z_IS_SMALL(b))
463  {
464  unsigned long rr;
465  mpz_ptr qq = (mpz_ptr) omAllocBin(gmp_nrz_bin);
466  mpz_init(qq);
467  mpz_t rrr;
468  mpz_init(rrr);
469  rr = mpz_divmod_ui(qq, rrr, (mpz_ptr) a, (unsigned long)ABS(SR_TO_INT(b)));
470  mpz_clear(rrr);
471 
472  if (r)
473  *r = INT_TO_SR(rr);
474  if (SR_TO_INT(b)<0)
475  {
476  mpz_mul_si(qq, qq, -1);
477  }
478  return nrz_short((number)qq);
479  }
480  mpz_ptr qq = (mpz_ptr) omAllocBin(gmp_nrz_bin),
481  rr = (mpz_ptr) omAllocBin(gmp_nrz_bin);
482  mpz_init(qq);
483  mpz_init(rr);
484  mpz_divmod(qq, rr, (mpz_ptr)a, (mpz_ptr)b);
485  if (r)
486  *r = (number) rr;
487  else
488  {
489  mpz_clear(rr);
490  }
491  nrzTest((number)qq);
492  return (number) qq;
493 }
494 
495 static void nrzPower (number a, int i, number * result, const coeffs)
496 {
497  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
498  mpz_init(erg);
499  mpz_t aa;
500  if (n_Z_IS_SMALL(a))
501  mpz_init_set_si(aa, SR_TO_INT(a));
502  else
503  mpz_init_set(aa, (mpz_ptr) a);
504  mpz_pow_ui(erg, aa, i);
505  *result = nrz_short((number) erg);
506 }
507 
508 /*
509  * create a number from int
510  * TODO: do not create an mpz if not necessary
511  */
512 number nrzInit (long i, const coeffs)
513 {
514  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
515  mpz_init_set_si(erg, i);
516  return nrz_short((number) erg);
517 }
518 
519 static number nrzInitMPZ(mpz_t m, const coeffs)
520 {
521  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
522  mpz_init_set(erg, m);
523  return nrz_short((number) erg);
524 }
525 
526 
527 static void nrzDelete(number *a, const coeffs)
528 {
529  if (*a == NULL) return;
530  if (n_Z_IS_SMALL(*a)==0)
531  {
532  mpz_clear((mpz_ptr) *a);
534  }
535  *a = NULL;
536 }
537 
538 /*
539  * convert a number to int
540  */
541 static long nrzInt(number &n, const coeffs)
542 {
543  if (n_Z_IS_SMALL(n)) return SR_TO_INT(n);
544  return mpz_get_si( (mpz_ptr)n);
545 }
546 #if CF_DEBUG
547 static number _nrzAdd(number, number, const coeffs);
548 static number nrzAdd(number a, number b, const coeffs R)
549 {
550  StringSetS("Add: ");
551  nrzWrite(a, R);
552  StringAppendS(" to ");
553  nrzWrite(b, R);
554  number c = _nrzAdd(a, b, R);
555  StringAppendS(" is ");
556  nrzWrite(c, R);
557  char * s = StringEndS();
558  Print("%s\n", s);
559  omFree(s);
560  return c;
561 }
562 static number _nrzAdd (number a, number b, const coeffs )
563 #else
564 static number nrzAdd (number a, number b, const coeffs )
565 #endif
566 {
567  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
568  {
569  long c = SR_TO_INT(a) + SR_TO_INT(b);
570  if (INT_IS_SMALL(c))
571  return INT_TO_SR(c);
572  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
573  mpz_init_set_si(erg, c);
574 
575  nrzTest((number)erg);
576  return (number) erg;
577  }
578  else if (n_Z_IS_SMALL(a))
579  {
580  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
581  mpz_init(erg);
582  if (SR_TO_INT(a)>0)
583  mpz_add_ui(erg, (mpz_ptr) b, (unsigned long)SR_TO_INT(a));
584  else
585  mpz_sub_ui(erg, (mpz_ptr) b, (unsigned long)-(SR_TO_INT(a)));
586  return nrz_short((number) erg);
587  }
588  else if (n_Z_IS_SMALL(b))
589  {
590  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
591  mpz_init(erg);
592  if (SR_TO_INT(b)>0)
593  mpz_add_ui(erg, (mpz_ptr) a, (unsigned long)SR_TO_INT(b));
594  else
595  mpz_sub_ui(erg, (mpz_ptr) a, (unsigned long)-(SR_TO_INT(b)));
596  return nrz_short((number) erg);
597  }
598  else
599  {
600  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
601  mpz_init(erg);
602  mpz_add(erg, (mpz_ptr) a, (mpz_ptr) b);
603  return nrz_short((number) erg);
604  }
605 }
606 
607 static number nrzSub (number a, number b, const coeffs )
608 {
609  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
610  {
611  long c = SR_TO_INT(a) - SR_TO_INT(b);
612  if (INT_IS_SMALL(c))
613  return INT_TO_SR(c);
614  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
615  mpz_init_set_si(erg, c);
616  nrzTest((number)erg);
617  return (number) erg;
618  }
619  else if (n_Z_IS_SMALL(a))
620  {
621  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
622  mpz_init(erg);
623 
624  if (SR_TO_INT(a)>0)
625  mpz_ui_sub(erg, (unsigned long)SR_TO_INT(a), (mpz_ptr) b);
626  else
627  {
628  mpz_add_ui(erg, (mpz_ptr) b, (unsigned long)-SR_TO_INT(a));
629  mpz_neg(erg, erg);
630  }
631  return nrz_short((number) erg);
632  }
633  else if (n_Z_IS_SMALL(b))
634  {
635  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
636  mpz_init(erg);
637  if (SR_TO_INT(b)>0)
638  mpz_sub_ui(erg, (mpz_ptr) a, (unsigned long)SR_TO_INT(b));
639  else
640  mpz_add_ui(erg, (mpz_ptr) a, (unsigned long)-SR_TO_INT(b));
641  return nrz_short((number) erg);
642  }
643  else
644  {
645  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
646  mpz_init(erg);
647  mpz_sub(erg, (mpz_ptr) a, (mpz_ptr) b);
648  return nrz_short((number) erg);
649  }
650 }
651 
652 static BOOLEAN nrzGreater (number a,number b, const coeffs)
653 {
654  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
655  return ((long)a)>((long)b);
656  else if (n_Z_IS_SMALL(a))
657  return 0 > mpz_cmp_si((mpz_ptr)b,SR_TO_INT(a));
658  else if (n_Z_IS_SMALL(b))
659  return 0 < mpz_cmp_si((mpz_ptr)a,SR_TO_INT(b));
660  return 0 < mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
661 }
662 
663 static BOOLEAN nrzGreaterZero (number k, const coeffs C)
664 {
665  return nrzGreater(k, INT_TO_SR(0), C);
666 }
667 
668 static number nrzGetUnit (number n, const coeffs r)
669 {
670  if (nrzGreaterZero(n, r))
671  return INT_TO_SR(1);
672  /*else*/
673  return INT_TO_SR(-1);
674 }
675 
676 static number nrzAnn(number n, const coeffs)
677 {
678  if (SR_TO_INT(n)) // in Z: the annihilator of !=0 is 0
679  return INT_TO_SR(0);
680  else
681  return INT_TO_SR(1);
682 }
683 
684 static BOOLEAN nrzIsUnit (number a, const coeffs)
685 {
686  return ABS(SR_TO_INT(a))==1;
687 }
688 
689 static BOOLEAN nrzIsZero (number a, const coeffs)
690 {
691  return (a==INT_TO_SR(0));
692 }
693 
694 static BOOLEAN nrzIsOne (number a, const coeffs)
695 {
696  return a==INT_TO_SR(1);
697 }
698 
699 static BOOLEAN nrzIsMOne (number a, const coeffs)
700 {
701  return a==INT_TO_SR(-1);
702 }
703 
704 static BOOLEAN nrzEqual (number a,number b, const coeffs)
705 {
706  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
707  return a==b;
708  else if (n_Z_IS_SMALL(a) || n_Z_IS_SMALL(b))
709  return FALSE;
710  else
711  return 0 == mpz_cmp((mpz_ptr) a, (mpz_ptr) b);
712 }
713 
714 static BOOLEAN nrzDivBy (number a,number b, const coeffs)
715 {
716  if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
717  {
718  return SR_TO_INT(a) %SR_TO_INT(b) ==0;
719  }
720  else if (n_Z_IS_SMALL(a))
721  {
722  return a==INT_TO_SR(0);
723  }
724  else if (n_Z_IS_SMALL(b))
725  {
726  return mpz_divisible_ui_p((mpz_ptr)a, (unsigned long)ABS(SR_TO_INT(b))) != 0;
727  }
728  else
729  return mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b) != 0;
730 }
731 
732 static int nrzDivComp(number a, number b, const coeffs r)
733 {
734  if (nrzDivBy(a, b, r))
735  {
736  if (nrzDivBy(b, a, r)) return 2;
737  return -1;
738  }
739  if (nrzDivBy(b, a, r)) return 1;
740  return 0;
741 }
742 
743 static number nrzDiv (number a,number b, const coeffs)
744 {
745  assume(SR_TO_INT(b));
746  if (nrzIsZero(b))
747  {
748  WerrorS(nDivBy0);
749  return INT_TO_SR(0);
750  }
751  else if (n_Z_IS_SMALL(a) && n_Z_IS_SMALL(b))
752  {
753  //if (SR_TO_INT(a) % SR_TO_INT(b))
754  //{
755  // WerrorS("1:Division by non divisible element.");
756  // WerrorS("Result is without remainder.");
757  //}
758  return INT_TO_SR(SR_TO_INT(a)/SR_TO_INT(b));
759  }
760  else if (n_Z_IS_SMALL(a))
761  {
762  //if (SR_TO_INT(a))
763  //{
764  // WerrorS("2:Division by non divisible element.");
765  // WerrorS("Result is without remainder.");
766  //}
767  return INT_TO_SR(0);
768  }
769  else if (n_Z_IS_SMALL(b))
770  {
771  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
772  mpz_t r;
773  mpz_init(r);
774  mpz_init(erg);
775  if (mpz_divmod_ui(erg, r, (mpz_ptr) a, (unsigned long)ABS(SR_TO_INT(b)))) {
776  // WerrorS("3:Division by non divisible element.");
777  // WerrorS("Result is without remainder.");
778  }
779  mpz_clear(r);
780  if (SR_TO_INT(b)<0)
781  mpz_neg(erg, erg);
782  return nrz_short((number) erg);
783  }
784  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
785  mpz_init(erg);
786  mpz_t r;
787  mpz_init(r);
788  mpz_tdiv_qr(erg, r, (mpz_ptr) a, (mpz_ptr) b);
789 #if CF_DEBUG
790  StringSetS("division of");
791  nrzWrite(a, R);
792  StringAppendS(" by ");
793  nrzWrite(b, R);
794  StringAppendS(" is ");
795  number du;
796  nrzWrite(du = (number)erg, R);
797  StringAppendS(" rest ");
798  nrzWrite(du = (number)r, R);
799  char * s = StringEndS();
800  Print("%s\n", s);
801  omFree(s);
802 #endif
803 
804  if (mpz_sgn1(r)!=0)
805  {
806  //WerrorS("4:Division by non divisible element.");
807  //WerrorS("Result is without remainder.");
808  }
809  mpz_clear(r);
810  return nrz_short((number) erg);
811 }
812 
813 static number nrzExactDiv (number a,number b, const coeffs)
814 {
815  assume(SR_TO_INT(b));
816  mpz_t aa, bb;
817  if (nrzIsZero(b))
818  {
819  WerrorS(nDivBy0);
820  return INT_TO_SR(0);
821  }
822  else if (n_Z_IS_SMALL(a))
823  mpz_init_set_si(aa, SR_TO_INT(a));
824  else
825  mpz_init_set(aa, (mpz_ptr) a);
826  if (n_Z_IS_SMALL(b))
827  mpz_init_set_si(bb, SR_TO_INT(b));
828  else
829  mpz_init_set(bb, (mpz_ptr) b);
830  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
831  mpz_init(erg);
832  mpz_tdiv_q(erg, (mpz_ptr) aa, (mpz_ptr) bb);
833  mpz_clear(aa);
834  mpz_clear(bb);
835  nrzTest((number)erg);
836  return (number) erg;
837 }
838 
839 static number nrzIntMod (number a,number b, const coeffs)
840 {
841  mpz_t aa, bb;
842  assume(SR_TO_INT(b));
843  if (n_Z_IS_SMALL(a))
844  mpz_init_set_si(aa, SR_TO_INT(a));
845  else
846  mpz_init_set(aa, (mpz_ptr) a);
847  if (n_Z_IS_SMALL(b))
848  mpz_init_set_si(bb, SR_TO_INT(b));
849  else
850  mpz_init_set(bb, (mpz_ptr) b);
851 
852  mpz_t erg;
853  mpz_init(erg);
854  mpz_ptr r = (mpz_ptr) omAllocBin(gmp_nrz_bin);
855  mpz_init(r);
856  mpz_tdiv_qr(erg, r, (mpz_ptr) aa, (mpz_ptr) bb);
857  mpz_clear(erg);
858  mpz_clear(aa);
859  mpz_clear(bb);
860 
861  return nrz_short((number) r);
862 }
863 
864 static number nrzInvers (number c, const coeffs r)
865 {
866  if (!nrzIsUnit((number) c, r))
867  {
868  WerrorS("Non invertible element.");
869  return nrzInit(0,r);
870  }
871  return c; // has to be 1 or -1....
872 }
873 
874 static number nrzNeg (number c, const coeffs)
875 {
876 // nNeg inplace !!!
877  if (n_Z_IS_SMALL(c))
878  return INT_TO_SR(-SR_TO_INT(c));
879  mpz_mul_si((mpz_ptr) c, (mpz_ptr) c, -1);
880  return c;
881 }
882 
883 static number nrzFarey(number r, number N, const coeffs R)
884 {
885  number a0 = nrzCopy(N, R);
886  number b0 = nrzInit(0, R);
887  number a1 = nrzCopy(r, R);
888  number b1 = nrzInit(1, R);
889  number two = nrzInit(2, R);
890 #if 0
891  PrintS("Farey start with ");
892  n_Print(r, R);
893  PrintS(" mod ");
894  n_Print(N, R);
895  PrintLn();
896 #endif
897  while (1)
898  {
899  number as = nrzMult(a1, a1, R);
900  n_InpMult(as, two, R);
901  if (nrzGreater(N, as, R))
902  {
903  nrzDelete(&as, R);
904  break;
905  }
906  nrzDelete(&as, R);
907  number q = nrzDiv(a0, a1, R);
908  number t = nrzMult(a1, q, R),
909  s = nrzSub(a0, t, R);
910  nrzDelete(&a0, R);
911  a0 = a1;
912  a1 = s;
913  nrzDelete(&t, R);
914 
915  t = nrzMult(b1, q, R);
916  s = nrzSub(b0, t, R);
917  nrzDelete(&b0, R);
918  b0 = b1;
919  b1 = s;
920  nrzDelete(&t, R);
921  nrzDelete(&q, R);
922  }
923  number as = nrzMult(b1, b1, R);
924  n_InpMult(as, two, R);
925  nrzDelete(&two, R);
926  if (nrzGreater(as, N, R))
927  {
928  nrzDelete(&a0, R);
929  nrzDelete(&a1, R);
930  nrzDelete(&b0, R);
931  nrzDelete(&b1, R);
932  nrzDelete(&as, R);
933  return NULL;
934  }
935  nrzDelete(&as, R);
936  nrzDelete(&a0, R);
937  nrzDelete(&b0, R);
938 
939  number a, b, ab;
940  coeffs Q = nInitChar(n_Q, 0);
941  nMapFunc f = n_SetMap(R, Q);
942  a = f(a1, R, Q);
943  b = f(b1, R, Q);
944  ab = n_Div(a, b, Q);
945  n_Delete(&a, Q);
946  n_Delete(&b, Q);
947  nKillChar(Q);
948 
949  nrzDelete(&a1, R);
950  nrzDelete(&b1, R);
951  return ab;
952 }
953 
954 static number nrzMapMachineInt(number from, const coeffs /*src*/, const coeffs /*dst*/)
955 {
956  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
957  mpz_init_set_ui(erg, (unsigned long) from);
958  return nrz_short((number) erg);
959 }
960 
961 static number nrzMapZp(number from, const coeffs /*src*/, const coeffs /*dst*/)
962 {
963  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
964  mpz_init_set_si(erg, (long) from);
965  return nrz_short((number) erg);
966 }
967 
968 static number nrzModNMap(number from, const coeffs /* src */, const coeffs /*dst*/)
969 {
970  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
971  mpz_init_set(erg, (mpz_ptr) from);
972  return nrz_short((number) erg);
973 }
974 
975 static number nrzMapQ(number from, const coeffs /* src */, const coeffs dst)
976 {
977  if (SR_HDL(from) & SR_INT)
978  return nrzInit(SR_TO_INT(from),dst);
979  if (from->s!=3)
980  {
981  WerrorS("rational in map to integer");
982  return NULL;
983  }
984  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
985  mpz_init_set(erg, from->z);
986  return nrz_short((number) erg);
987 }
988 
989 static nMapFunc nrzSetMap(const coeffs src, const coeffs /*dst*/)
990 {
991  /* dst = rintegers */
992  if (src->rep==n_rep_gmp) //nCoeff_is_Zn(src) || nCoeff_is_Ring_PtoM(src))
993  return nrzModNMap;
994 
995  if ((src->rep==n_rep_gap_gmp) && nCoeff_is_Z(src))
996  {
997  return ndCopyMap; //nrzCopyMap;
998  }
999  if (src->rep==n_rep_gap_rat) /*&& nCoeff_is_Z(src)) Q, bigint*/
1000  {
1001  return nrzMapQ;
1002  }
1003  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
1004  {
1005  return nrzMapMachineInt;
1006  }
1007  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
1008  {
1009  return nrzMapZp;
1010  }
1011  return NULL; // default
1012 }
1013 
1014 
1015 /*
1016  * set the exponent (allocate and init tables) (TODO)
1017  */
1018 
1019 void nrzSetExp(int, coeffs)
1020 {
1021 }
1022 
1023 void nrzInitExp(int, coeffs)
1024 {
1025 }
1026 
1027 #ifdef LDEBUG
1028 BOOLEAN nrzDBTest (number x, const char *f, const int l, const coeffs)
1029 {
1030  if (SR_HDL(x) & SR_INT) return TRUE;
1031  if (mpz_sgn1((mpz_ptr) x)==0)
1032  {
1033  Print("gmp-0 %s:%d\n",f,l);
1034  return FALSE;
1035  }
1036  if (mpz_size1((mpz_ptr)x)<=MP_SMALL)
1037  {
1038  long ui=mpz_get_si((mpz_ptr)x);
1039  if ((((ui<<3)>>3)==ui)
1040  && (mpz_cmp_si((mpz_ptr)x,ui)==0))
1041  {
1042  Print("gmp-small %s:%d\n",f,l);
1043  return FALSE;
1044  }
1045  }
1046  return TRUE;
1047 }
1048 #endif
1049 
1050 void nrzWrite (number a, const coeffs)
1051 {
1052  char *s,*z;
1053  if (a==NULL)
1054  {
1055  StringAppendS("o");
1056  }
1057  else
1058  {
1059  if (n_Z_IS_SMALL(a))
1060  {
1061  StringAppend("%d", SR_TO_INT(a));
1062  }
1063  else
1064  {
1065  int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
1066  s=(char*)omAlloc(l);
1067  z=mpz_get_str(s,10,(mpz_ptr) a);
1068  StringAppendS(z);
1069  omFreeSize((ADDRESS)s,l);
1070  }
1071  }
1072 }
1073 
1074 /*2
1075 * extracts a long integer from s, returns the rest (COPY FROM longrat0.cc)
1076 */
1077 static const char * nlEatLongC(char *s, mpz_ptr i)
1078 {
1079  const char * start=s;
1080 
1081  if (*s<'0' || *s>'9')
1082  {
1083  mpz_set_ui(i,1);
1084  return s;
1085  }
1086  while (*s >= '0' && *s <= '9') s++;
1087  if (*s=='\0')
1088  {
1089  mpz_set_str(i,start,10);
1090  }
1091  else
1092  {
1093  char c=*s;
1094  *s='\0';
1095  mpz_set_str(i,start,10);
1096  *s=c;
1097  }
1098  return s;
1099 }
1100 
1101 static const char * nrzRead (const char *s, number *a, const coeffs)
1102 {
1103  mpz_ptr z = (mpz_ptr) omAllocBin(gmp_nrz_bin);
1104  {
1105  mpz_init(z);
1106  s = nlEatLongC((char *) s, z);
1107  }
1108  *a = nrz_short((number) z);
1109  return s;
1110 }
1111 
1112 static CanonicalForm nrzConvSingNFactoryN( number n, BOOLEAN setChar, const coeffs /*r*/ )
1113 {
1114  if (setChar) setCharacteristic( 0 );
1115 
1117  if ( n_Z_IS_SMALL(n))
1118  {
1119  term = SR_TO_INT(n);
1120  }
1121  else
1122  {
1123  mpz_t dummy;
1124  mpz_init_set( dummy,n->z );
1125  term = make_cf( dummy );
1126  }
1127  return term;
1128 }
1129 
1130 static number nrzConvFactoryNSingN( const CanonicalForm n, const coeffs r)
1131 {
1132  if (n.isImm())
1133  {
1134  return nrzInit(n.intval(),r);
1135  }
1136  else
1137  {
1138  if ( !n.den().isOne() )
1139  {
1140  WerrorS("rational in conversion to integer");
1141  return NULL;
1142  }
1143  mpz_ptr z = (mpz_ptr) omAlloc0Bin(gmp_nrz_bin);
1144  gmp_numerator( n,z);
1145  return nrz_short((number)z);
1146  }
1147 }
1148 
1149 static void nrzMPZ(mpz_t res, number &a, const coeffs)
1150 {
1151  if (n_Z_IS_SMALL(a))
1152  mpz_init_set_si(res, SR_TO_INT(a));
1153  else
1154  mpz_init_set(res, (mpz_ptr) a);
1155 }
1156 
1157 static coeffs nrzQuot1(number c, const coeffs r)
1158 {
1159  mpz_t dummy;
1160  if(n_Z_IS_SMALL(c))
1161  {
1162  long ch = r->cfInt(c, r);
1163  mpz_init_set_ui(dummy, ch);
1164  }
1165  else
1166  {
1167  mpz_init_set(dummy, (mpz_ptr)c);
1168  }
1169  ZnmInfo info;
1170  info.base = dummy;
1171  info.exp = (unsigned long) 1;
1172  coeffs rr = nInitChar(n_Zn, (void*)&info);
1173  mpz_clear(dummy);
1174  return(rr);
1175 }
1176 
1177 number nlReadFd(const ssiInfo *d, const coeffs);
1178 void nlWriteFd(number n, const ssiInfo* d, const coeffs);
1179 
1180 BOOLEAN nrzInitChar(coeffs r, void *)
1181 {
1182  assume( getCoeffType(r) == n_Z );
1183 
1184  r->is_field=FALSE;
1185  r->is_domain=TRUE;
1186  r->rep=n_rep_gap_gmp;
1187 
1188  //r->nCoeffIsEqual = ndCoeffIsEqual;
1189  r->cfCoeffName = nrzCoeffName;
1190  //r->cfKillChar = ndKillChar;
1191  r->cfMult = nrzMult;
1192  r->cfSub = nrzSub;
1193  r->cfAdd = nrzAdd;
1194  r->cfDiv = nrzDiv;
1195  r->cfIntMod= nrzIntMod;
1196  r->cfExactDiv= nrzExactDiv;
1197  r->cfInit = nrzInit;
1198  r->cfInitMPZ = nrzInitMPZ;
1199  r->cfSize = nrzSize;
1200  r->cfInt = nrzInt;
1201  //#ifdef HAVE_RINGS
1202  r->cfDivComp = nrzDivComp; // only for ring stuff
1203  r->cfIsUnit = nrzIsUnit; // only for ring stuff
1204  r->cfGetUnit = nrzGetUnit; // only for ring stuff
1205  r->cfAnn = nrzAnn;
1206  r->cfExtGcd = nrzExtGcd; // only for ring stuff
1207  r->cfXExtGcd = nrzXExtGcd; // only for ring stuff
1208  r->cfEucNorm = nrzEucNorm;
1209  r->cfQuotRem = nrzSmallestQuotRem;
1210  r->cfDivBy = nrzDivBy; // only for ring stuff
1211  //#endif
1212  r->cfInpNeg = nrzNeg;
1213  r->cfInvers= nrzInvers;
1214  r->cfCopy = nrzCopy;
1215  r->cfWriteLong = nrzWrite;
1216  r->cfRead = nrzRead;
1217  r->cfGreater = nrzGreater;
1218  r->cfEqual = nrzEqual;
1219  r->cfIsZero = nrzIsZero;
1220  r->cfIsOne = nrzIsOne;
1221  r->cfIsMOne = nrzIsMOne;
1222  r->cfGreaterZero = nrzGreaterZero;
1223  r->cfPower = nrzPower;
1224  r->cfGcd = nrzGcd;
1225  r->cfLcm = nrzLcm;
1226  r->cfDelete= nrzDelete;
1227  r->cfSetMap = nrzSetMap;
1228  r->convSingNFactoryN = nrzConvSingNFactoryN;
1229  r->convFactoryNSingN = nrzConvFactoryNSingN;
1230  r->cfMPZ = nrzMPZ;
1231  r->cfFarey = nrzFarey;
1232  r->cfWriteFd=nlWriteFd;
1233  r->cfReadFd=nlReadFd;
1234 
1235  r->cfQuot1 = nrzQuot1;
1236  // requires conversion to factory:
1237  r->cfChineseRemainder=nlChineseRemainderSym;
1238  // debug stuff
1239 
1240 #ifdef LDEBUG
1241  r->cfDBTest=nrzDBTest;
1242 #endif
1243 
1244  r->ch = 0;
1245  r->has_simple_Alloc=FALSE;
1246  r->has_simple_Inverse=FALSE;
1247  return FALSE;
1248 }
1249 #endif
1250 #endif
static int ABS(int v)
Definition: auxiliary.h:112
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
void * ADDRESS
Definition: auxiliary.h:119
void FACTORY_PUBLIC setCharacteristic(int c)
Definition: cf_char.cc:28
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:56
int l
Definition: cfEzgcd.cc:100
int m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
Variable x
Definition: cfModGcd.cc:4082
g
Definition: cfModGcd.cc:4090
CanonicalForm b
Definition: cfModGcd.cc:4103
FILE * f
Definition: checklibs.c:9
factory's main class
Definition: canonicalform.h:86
CanonicalForm den() const
den() returns the denominator of CO if CO is a rational number, 1 (from the current domain!...
CF_NO_INLINE bool isOne() const
long intval() const
conversion functions
bool isImm() const
Definition: int_poly.h:33
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:816
number ndCopyMap(number a, const coeffs src, const coeffs dst)
Definition: numbers.cc:282
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:30
@ n_Zn
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
@ n_Z
only used if HAVE_RINGS is defined
Definition: coeffs.h:43
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
Definition: numbers.cc:646
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:700
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:615
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:392
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:800
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:724
static FORCE_INLINE void n_InpMult(number &a, number b, const coeffs r)
multiplication of 'a' and 'b'; replacement of 'a' by the product a*b
Definition: coeffs.h:641
@ n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition: coeffs.h:112
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:547
#define Print
Definition: emacs.cc:80
#define StringAppend
Definition: emacs.cc:79
return result
Definition: facAbsBiFact.cc:75
const CanonicalForm int s
Definition: facAbsFact.cc:51
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:53
CanonicalForm res
Definition: facAbsFact.cc:60
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
const ExtensionInfo & info
< [in] sqrfree poly
CanonicalForm FACTORY_PUBLIC make_cf(const mpz_ptr n)
Definition: singext.cc:66
void FACTORY_PUBLIC gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20
void WerrorS(const char *s)
Definition: feFopen.cc:24
STATIC_VAR jList * Q
Definition: janet.cc:30
void nlWriteFd(number n, const ssiInfo *d, const coeffs)
Definition: longrat.cc:3330
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:177
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:3095
number nlReadFd(const ssiInfo *d, const coeffs)
Definition: longrat.cc:3376
#define MP_SMALL
Definition: longrat.cc:144
static int int_extgcd(int a, int b, int *u, int *x, int *v, int *y)
Definition: longrat.cc:1415
#define SR_INT
Definition: longrat.h:67
#define INT_TO_SR(INT)
Definition: longrat.h:68
#define SR_TO_INT(SR)
Definition: longrat.h:69
#define assume(x)
Definition: mod2.h:389
The main handler for Singular numbers which are suitable for Singular polynomials.
const char *const nDivBy0
Definition: numbers.h:88
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define omFree(addr)
Definition: omAllocDecl.h:261
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
#define NULL
Definition: omList.c:12
void StringSetS(const char *st)
Definition: reporter.cc:128
void StringAppendS(const char *st)
Definition: reporter.cc:107
void PrintS(const char *s)
Definition: reporter.cc:284
char * StringEndS()
Definition: reporter.cc:151
void PrintLn()
Definition: reporter.cc:310
static char * nrzCoeffName(const coeffs)
Definition: rintegers.cc:26
VAR omBin gmp_nrz_bin
Definition: rintegers.cc:24
void nrzWrite(number a, const coeffs r)
void nrzDelete(number *a, const coeffs)
int nrzSize(number a, const coeffs)
BOOLEAN nrzInitChar(coeffs r, void *parameter)
number nrzInit(long i, const coeffs r)
Definition: s_buff.h:21
#define mpz_size1(A)
Definition: si_gmp.h:17
#define mpz_sgn1(A)
Definition: si_gmp.h:18
#define R
Definition: sirandom.c:27
#define SR_HDL(A)
Definition: tgb.cc:35