longrat.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT: computation with long rational numbers (Hubert Grassmann)
6 */
7 
8 #include <misc/auxiliary.h>
9 #include <omalloc/omalloc.h>
10 
11 #include <factory/factory.h>
12 
13 #include <misc/sirandom.h>
14 #include <misc/prime.h>
15 #include <reporter/reporter.h>
16 
17 #include "rmodulon.h" // ZnmInfo
18 #include "longrat.h"
19 #include "shortfl.h"
20 #include "modulop.h"
21 
22 // allow inlining only from p_Numbers.h and if ! LDEBUG
23 #if defined(DO_LINLINE) && defined(P_NUMBERS_H) && !defined(LDEBUG)
24 #define LINLINE static FORCE_INLINE
25 #else
26 #define LINLINE
27 #undef DO_LINLINE
28 #endif // DO_LINLINE
29 
30 LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r);
31 LINLINE number nlInit(long i, const coeffs r);
32 LINLINE BOOLEAN nlIsOne(number a, const coeffs r);
33 LINLINE BOOLEAN nlIsZero(number za, const coeffs r);
34 LINLINE number nlCopy(number a, const coeffs r);
35 LINLINE number nl_Copy(number a, const coeffs r);
36 LINLINE void nlDelete(number *a, const coeffs r);
37 LINLINE number nlNeg(number za, const coeffs r);
38 LINLINE number nlAdd(number la, number li, const coeffs r);
39 LINLINE number nlSub(number la, number li, const coeffs r);
40 LINLINE number nlMult(number a, number b, const coeffs r);
41 LINLINE void nlInpAdd(number &a, number b, const coeffs r);
42 LINLINE void nlInpMult(number &a, number b, const coeffs r);
43 
44 number nlRInit (long i);
45 
46 
47 // number nlInitMPZ(mpz_t m, const coeffs r);
48 // void nlMPZ(mpz_t m, number &n, const coeffs r);
49 
50 void nlNormalize(number &x, const coeffs r);
51 
52 number nlGcd(number a, number b, const coeffs r);
53 number nlExtGcd(number a, number b, number *s, number *t, const coeffs);
54 number nlNormalizeHelper(number a, number b, const coeffs r); /*special routine !*/
55 BOOLEAN nlGreater(number a, number b, const coeffs r);
56 BOOLEAN nlIsMOne(number a, const coeffs r);
57 long nlInt(number &n, const coeffs r);
58 number nlBigInt(number &n);
59 
60 #ifdef HAVE_RINGS
61 number nlMapGMP(number from, const coeffs src, const coeffs dst);
62 #endif
63 
64 BOOLEAN nlGreaterZero(number za, const coeffs r);
65 number nlInvers(number a, const coeffs r);
66 number nlDiv(number a, number b, const coeffs r);
67 number nlExactDiv(number a, number b, const coeffs r);
68 number nlIntDiv(number a, number b, const coeffs r);
69 number nlIntMod(number a, number b, const coeffs r);
70 void nlPower(number x, int exp, number *lu, const coeffs r);
71 const char * nlRead (const char *s, number *a, const coeffs r);
72 void nlWrite(number a, const coeffs r);
73 
74 number nlGetDenom(number &n, const coeffs r);
75 number nlGetNumerator(number &n, const coeffs r);
76 void nlCoeffWrite(const coeffs r, BOOLEAN details);
77 number nlChineseRemainder(number *x, number *q,int rl, const coeffs C);
78 number nlFarey(number nN, number nP, const coeffs CF);
79 
80 #ifdef LDEBUG
81 BOOLEAN nlDBTest(number a, const char *f, const int l);
82 #endif
83 
84 nMapFunc nlSetMap(const coeffs src, const coeffs dst);
85 
86 // in-place operations
87 void nlInpIntDiv(number &a, number b, const coeffs r);
88 
89 #ifdef LDEBUG
90 #define nlTest(a, r) nlDBTest(a,__FILE__,__LINE__, r)
91 BOOLEAN nlDBTest(number a, char *f,int l, const coeffs r);
92 #else
93 #define nlTest(a, r) do {} while (0)
94 #endif
95 
96 
97 // 64 bit version:
98 //#if SIZEOF_LONG == 8
99 #if 0
100 #define MAX_NUM_SIZE 60
101 #define POW_2_28 (1L<<60)
102 #define POW_2_28_32 (1L<<28)
103 #define LONG long
104 #else
105 #define MAX_NUM_SIZE 28
106 #define POW_2_28 (1L<<28)
107 #define POW_2_28_32 (1L<<28)
108 #define LONG int
109 #endif
110 
111 
112 static inline number nlShort3(number x) // assume x->s==3
113 {
114  assume(x->s==3);
115  if (mpz_cmp_ui(x->z,(long)0)==0)
116  {
117  mpz_clear(x->z);
118  FREE_RNUMBER(x);
119  return INT_TO_SR(0);
120  }
121  if (mpz_size1(x->z)<=MP_SMALL)
122  {
123  LONG ui=mpz_get_si(x->z);
124  if ((((ui<<3)>>3)==ui)
125  && (mpz_cmp_si(x->z,(long)ui)==0))
126  {
127  mpz_clear(x->z);
128  FREE_RNUMBER(x);
129  return INT_TO_SR(ui);
130  }
131  }
132  return x;
133 }
134 
135 #ifndef LONGRAT_CC
136 #define LONGRAT_CC
137 
138 #include <string.h>
139 #include <float.h>
140 
141 #include <coeffs/coeffs.h>
142 #include <reporter/reporter.h>
143 #include <omalloc/omalloc.h>
144 
145 #include <coeffs/numbers.h>
146 #include <coeffs/mpr_complex.h>
147 
148 #ifndef BYTES_PER_MP_LIMB
149 #define BYTES_PER_MP_LIMB sizeof(mp_limb_t)
150 #endif
151 
152 //#define SR_HDL(A) ((long)(A))
153 /*#define SR_INT 1L*/
154 /*#define INT_TO_SR(INT) ((number) (((long)INT << 2) + SR_INT))*/
155 // #define SR_TO_INT(SR) (((long)SR) >> 2)
156 
157 #define MP_SMALL 1
158 //#define mpz_isNeg(A) (mpz_cmp_si(A,(long)0)<0)
159 #define mpz_isNeg(A) ((A)->_mp_size<0)
160 #define mpz_limb_size(A) ((A)->_mp_size)
161 #define mpz_limb_d(A) ((A)->_mp_d)
162 #define MPZ_DIV(A,B,C) mpz_tdiv_q((A),(B),(C))
163 #define MPZ_EXACTDIV(A,B,C) mpz_divexact((A),(B),(C))
164 
165 void _nlDelete_NoImm(number *a);
166 
167 /***************************************************************
168  *
169  * Routines which are never inlined by p_Numbers.h
170  *
171  *******************************************************************/
172 #ifndef P_NUMBERS_H
173 
174 number nlShort3_noinline(number x) // assume x->s==3
175 {
176  return nlShort3(x);
177 }
178 
179 
180 #if (__GNU_MP_VERSION*10+__GNU_MP_VERSION_MINOR < 31)
181 void mpz_mul_si (mpz_ptr r, mpz_srcptr s, long int si)
182 {
183  if (si>=0)
184  mpz_mul_ui(r,s,si);
185  else
186  {
187  mpz_mul_ui(r,s,-si);
188  mpz_neg(r,r);
189  }
190 }
191 #endif
192 
193 static number nlMapP(number from, const coeffs src, const coeffs dst)
194 {
195  assume( getCoeffType(src) == n_Zp );
196 
197  number to = nlInit(npInt(from,src), dst); // FIXME? TODO? // extern long npInt (number &n, const coeffs r);
198 
199  return to;
200 }
201 
202 static number nlMapLongR(number from, const coeffs src, const coeffs dst);
203 static number nlMapR(number from, const coeffs src, const coeffs dst);
204 
205 
206 #ifdef HAVE_RINGS
207 /*2
208 * convert from a GMP integer
209 */
210 number nlMapGMP(number from, const coeffs /*src*/, const coeffs /*dst*/)
211 {
212  number z=ALLOC_RNUMBER();
213 #if defined(LDEBUG)
214  z->debug=123456;
215 #endif
216  mpz_init_set(z->z,(mpz_ptr) from);
217  //mpz_init_set_ui(&z->n,1);
218  z->s = 3;
219  z=nlShort3(z);
220  return z;
221 }
222 
223 number nlMapZ(number from, const coeffs src, const coeffs dst)
224 {
225  if (SR_HDL(from) & SR_INT)
226  {
227  return from;
228  }
229  return nlMapGMP(from,src,dst);
230 }
231 
232 /*2
233 * convert from an machine long
234 */
235 number nlMapMachineInt(number from, const coeffs /*src*/, const coeffs /*dst*/)
236 {
237  number z=ALLOC_RNUMBER();
238 #if defined(LDEBUG)
239  z->debug=123456;
240 #endif
241  mpz_init_set_ui(z->z,(unsigned long) from);
242  z->s = 3;
243  z=nlShort3(z);
244  return z;
245 }
246 #endif
247 
248 
249 #ifdef LDEBUG
250 BOOLEAN nlDBTest(number a, const char *f,const int l, const coeffs /*r*/)
251 {
252  if (a==NULL)
253  {
254  Print("!!longrat: NULL in %s:%d\n",f,l);
255  return FALSE;
256  }
257  //if ((int)a==1) Print("!! 0x1 as number ? %s %d\n",f,l);
258  if ((((long)a)&3L)==3L)
259  {
260  Print(" !!longrat:ptr(3) in %s:%d\n",f,l);
261  return FALSE;
262  }
263  if ((((long)a)&3L)==1L)
264  {
265  if (((((LONG)(long)a)<<1)>>1)!=((LONG)(long)a))
266  {
267  Print(" !!longrat:arith:%lx in %s:%d\n",(long)a, f,l);
268  return FALSE;
269  }
270  return TRUE;
271  }
272  /* TODO: If next line is active, then computations in algebraic field
273  extensions over Q will throw a lot of assume violations although
274  everything is computed correctly and no seg fault appears.
275  Maybe the test is not appropriate in this case. */
276  omCheckIf(omCheckAddrSize(a,sizeof(*a)), return FALSE);
277  if (a->debug!=123456)
278  {
279  Print("!!longrat:debug:%d in %s:%d\n",a->debug,f,l);
280  a->debug=123456;
281  return FALSE;
282  }
283  if ((a->s<0)||(a->s>4))
284  {
285  Print("!!longrat:s=%d in %s:%d\n",a->s,f,l);
286  return FALSE;
287  }
288  /* TODO: If next line is active, then computations in algebraic field
289  extensions over Q will throw a lot of assume violations although
290  everything is computed correctly and no seg fault appears.
291  Maybe the test is not appropriate in this case. */
292  //omCheckAddrSize(a->z[0]._mp_d,a->z[0]._mp_alloc*BYTES_PER_MP_LIMB);
293  if (a->z[0]._mp_alloc==0)
294  Print("!!longrat:z->alloc=0 in %s:%d\n",f,l);
295 
296  if (a->s<2)
297  {
298  if ((a->n[0]._mp_d[0]==0)&&(a->n[0]._mp_alloc<=1))
299  {
300  Print("!!longrat: n==0 in %s:%d\n",f,l);
301  return FALSE;
302  }
303  /* TODO: If next line is active, then computations in algebraic field
304  extensions over Q will throw a lot of assume violations although
305  everything is computed correctly and no seg fault appears.
306  Maybe the test is not appropriate in this case. */
307  //omCheckIf(omCheckAddrSize(a->n[0]._mp_d,a->n[0]._mp_alloc*BYTES_PER_MP_LIMB), return FALSE);
308  if (a->z[0]._mp_alloc==0)
309  Print("!!longrat:n->alloc=0 in %s:%d\n",f,l);
310  if ((mpz_size1(a->n) ==1) && (mpz_cmp_si(a->n,(long)1)==0))
311  {
312  Print("!!longrat:integer as rational in %s:%d\n",f,l);
313  mpz_clear(a->n); a->s=3;
314  return FALSE;
315  }
316  else if (mpz_isNeg(a->n))
317  {
318  Print("!!longrat:div. by negative in %s:%d\n",f,l);
319  mpz_neg(a->z,a->z);
320  mpz_neg(a->n,a->n);
321  return FALSE;
322  }
323  return TRUE;
324  }
325  //if (a->s==2)
326  //{
327  // Print("!!longrat:s=2 in %s:%d\n",f,l);
328  // return FALSE;
329  //}
330  if (mpz_size1(a->z)>MP_SMALL) return TRUE;
331  LONG ui=(LONG)mpz_get_si(a->z);
332  if ((((ui<<3)>>3)==ui)
333  && (mpz_cmp_si(a->z,(long)ui)==0))
334  {
335  Print("!!longrat:im int %d in %s:%d\n",ui,f,l);
336  return FALSE;
337  }
338  return TRUE;
339 }
340 #endif
341 
342 static CanonicalForm nlConvSingNFactoryN( number n, const BOOLEAN setChar, const coeffs /*r*/ )
343 {
344  if (setChar) setCharacteristic( 0 );
345 
347  if ( SR_HDL(n) & SR_INT )
348  {
349  long nn=SR_TO_INT(n);
350  term = nn;
351  }
352  else
353  {
354  if ( n->s == 3 )
355  {
356  mpz_t dummy;
357  long lz=mpz_get_si(n->z);
358  if (mpz_cmp_si(n->z,lz)==0) term=lz;
359  else
360  {
361  mpz_init_set( dummy,n->z );
362  term = make_cf( dummy );
363  }
364  }
365  else
366  {
367  // assume s==0 or s==1
368  mpz_t num, den;
369  On(SW_RATIONAL);
370  mpz_init_set( num, n->z );
371  mpz_init_set( den, n->n );
372  term = make_cf( num, den, ( n->s != 1 ));
373  }
374  }
375  return term;
376 }
377 
378 number nlRInit (long i);
379 
380 static number nlConvFactoryNSingN( const CanonicalForm f, const coeffs r)
381 {
382  if (f.isImm())
383  {
384  return nlInit(f.intval(),r);
385  }
386  else
387  {
388  number z = ALLOC_RNUMBER(); //Q!? // (number)omAllocBin(rnumber_bin);
389 #if defined(LDEBUG)
390  z->debug=123456;
391 #endif
392  gmp_numerator( f, z->z );
393  if ( f.den().isOne() )
394  z->s = 3;
395  else
396  {
397  gmp_denominator( f, z->n );
398  z->s = 0;
399  }
400  nlNormalize(z,r);
401  return z;
402  }
403 }
404 
405 static number nlMapR(number from, const coeffs src, const coeffs dst)
406 {
407  assume( getCoeffType(src) == n_R );
408 
409  double f=nrFloat(from); // FIXME? TODO? // extern float nrFloat(number n);
410  if (f==0.0) return INT_TO_SR(0);
411  int f_sign=1;
412  if (f<0.0)
413  {
414  f_sign=-1;
415  f=-f;
416  }
417  int i=0;
418  mpz_t h1;
419  mpz_init_set_ui(h1,1);
420  while((FLT_RADIX*f) < DBL_MAX && i<DBL_MANT_DIG)
421  {
422  f*=FLT_RADIX;
423  mpz_mul_ui(h1,h1,FLT_RADIX);
424  i++;
425  }
426  number re=nlRInit(1);
427  mpz_set_d(re->z,f);
428  memcpy(&(re->n),&h1,sizeof(h1));
429  re->s=0; /* not normalized */
430  if(f_sign==-1) re=nlNeg(re,dst);
431  nlNormalize(re,dst);
432  return re;
433 }
434 
435 static number nlMapLongR(number from, const coeffs src, const coeffs dst)
436 {
437  assume( getCoeffType(src) == n_long_R );
438 
439  gmp_float *ff=(gmp_float*)from;
440  mpf_t *f=ff->_mpfp();
441  number res;
442  mpz_ptr dest,ndest;
443  int size, i,negative;
444  int e,al,bl;
445  mp_ptr qp,dd,nn;
446 
447  size = (*f)[0]._mp_size;
448  if (size == 0)
449  return INT_TO_SR(0);
450  if(size<0)
451  {
452  negative = 1;
453  size = -size;
454  }
455  else
456  negative = 0;
457 
458  qp = (*f)[0]._mp_d;
459  while(qp[0]==0)
460  {
461  qp++;
462  size--;
463  }
464 
465  e=(*f)[0]._mp_exp-size;
466  res = ALLOC_RNUMBER();
467 #if defined(LDEBUG)
468  res->debug=123456;
469 #endif
470  dest = res->z;
471 
472  if (e<0)
473  {
474  al = dest->_mp_size = size;
475  if (al<2) al = 2;
476  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
477  for (i=0;i<size;i++) dd[i] = qp[i];
478  bl = 1-e;
479  nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
480  nn[bl-1] = 1;
481  for (i=bl-2;i>=0;i--) nn[i] = 0;
482  ndest = res->n;
483  ndest->_mp_d = nn;
484  ndest->_mp_alloc = ndest->_mp_size = bl;
485  res->s = 0;
486  }
487  else
488  {
489  al = dest->_mp_size = size+e;
490  if (al<2) al = 2;
491  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
492  for (i=0;i<size;i++) dd[i+e] = qp[i];
493  for (i=0;i<e;i++) dd[i] = 0;
494  res->s = 3;
495  }
496 
497  dest->_mp_d = dd;
498  dest->_mp_alloc = al;
499  if (negative) dest->_mp_size = -dest->_mp_size;
500 
501  if (res->s==0)
502  nlNormalize(res,dst);
503  else if (mpz_size1(res->z)<=MP_SMALL)
504  {
505  // res is new, res->ref is 1
506  res=nlShort3(res);
507  }
508  nlTest(res, dst);
509  return res;
510 }
511 
512 //static number nlMapLongR(number from)
513 //{
514 // gmp_float *ff=(gmp_float*)from;
515 // const mpf_t *f=ff->mpfp();
516 // int f_size=ABS((*f)[0]._mp_size);
517 // if (f_size==0)
518 // return nlInit(0);
519 // int f_sign=1;
520 // number work=ngcCopy(from);
521 // if (!ngcGreaterZero(work))
522 // {
523 // f_sign=-1;
524 // work=ngcNeg(work);
525 // }
526 // int i=0;
527 // mpz_t h1;
528 // mpz_init_set_ui(h1,1);
529 // while((FLT_RADIX*f) < DBL_MAX && i<DBL_MANT_DIG)
530 // {
531 // f*=FLT_RADIX;
532 // mpz_mul_ui(h1,h1,FLT_RADIX);
533 // i++;
534 // }
535 // number r=nlRInit(1);
536 // mpz_set_d(&(r->z),f);
537 // memcpy(&(r->n),&h1,sizeof(h1));
538 // r->s=0; /* not normalized */
539 // nlNormalize(r);
540 // return r;
541 //
542 //
543 // number r=nlRInit(1);
544 // int f_shift=f_size+(*f)[0]._mp_exp;
545 // if ( f_shift > 0)
546 // {
547 // r->s=0;
548 // mpz_init(&r->n);
549 // mpz_setbit(&r->n,f_shift*BYTES_PER_MP_LIMB*8);
550 // mpz_setbit(&r->z,f_size*BYTES_PER_MP_LIMB*8-1);
551 // // now r->z has enough space
552 // memcpy(mpz_limb_d(&r->z),((*f)[0]._mp_d),f_size*BYTES_PER_MP_LIMB);
553 // nlNormalize(r);
554 // }
555 // else
556 // {
557 // r->s=3;
558 // if (f_shift==0)
559 // {
560 // mpz_setbit(&r->z,f_size*BYTES_PER_MP_LIMB*8-1);
561 // // now r->z has enough space
562 // memcpy(mpz_limb_d(&r->z),((*f)[0]._mp_d),f_size*BYTES_PER_MP_LIMB);
563 // }
564 // else /* f_shift < 0 */
565 // {
566 // mpz_setbit(&r->z,(f_size-f_shift)*BYTES_PER_MP_LIMB*8-1);
567 // // now r->z has enough space
568 // memcpy(mpz_limb_d(&r->z)-f_shift,((*f)[0]._mp_d),
569 // f_size*BYTES_PER_MP_LIMB);
570 // }
571 // }
572 // if ((*f)[0]._mp_size<0);
573 // r=nlNeg(r);
574 // return r;
575 //}
576 
577 int nlSize(number a, const coeffs)
578 {
579  if (a==INT_TO_SR(0))
580  return 0; /* rational 0*/
581  if (SR_HDL(a) & SR_INT)
582  return 1; /* immidiate int */
583  int s=a->z[0]._mp_alloc;
584 // while ((s>0) &&(a->z._mp_d[s]==0L)) s--;
585 //#if SIZEOF_LONG == 8
586 // if (a->z._mp_d[s] < (unsigned long)0x100000000L) s=s*2-1;
587 // else s *=2;
588 //#endif
589 // s++;
590  if (a->s<2)
591  {
592  int d=a->n[0]._mp_alloc;
593 // while ((d>0) && (a->n._mp_d[d]==0L)) d--;
594 //#if SIZEOF_LONG == 8
595 // if (a->n._mp_d[d] < (unsigned long)0x100000000L) d=d*2-1;
596 // else d *=2;
597 //#endif
598  s+=d;
599  }
600  return s;
601 }
602 
603 /*2
604 * convert number to int
605 */
606 long nlInt(number &i, const coeffs r)
607 {
608  nlTest(i, r);
609  nlNormalize(i,r);
610  if (SR_HDL(i) & SR_INT)
611  {
612  return SR_TO_INT(i);
613  }
614  if (i->s==3)
615  {
616  if(mpz_size1(i->z)>MP_SMALL) return 0;
617  long ul=mpz_get_si(i->z);
618  if (mpz_cmp_si(i->z,ul)!=0) return 0;
619  return ul;
620  }
621  mpz_t tmp;
622  long ul;
623  mpz_init(tmp);
624  MPZ_DIV(tmp,i->z,i->n);
625  if(mpz_size1(tmp)>MP_SMALL) ul=0;
626  else
627  {
628  ul=mpz_get_si(tmp);
629  if (mpz_cmp_si(tmp,ul)!=0) ul=0;
630  }
631  mpz_clear(tmp);
632  return ul;
633 }
634 
635 /*2
636 * convert number to bigint
637 */
638 number nlBigInt(number &i, const coeffs r)
639 {
640  nlTest(i, r);
641  nlNormalize(i,r);
642  if (SR_HDL(i) & SR_INT) return (i);
643  if (i->s==3)
644  {
645  return nlCopy(i,r);
646  }
647  number tmp=nlRInit(1);
648  MPZ_DIV(tmp->z,i->z,i->n);
649  tmp=nlShort3(tmp);
650  return tmp;
651 }
652 
653 /*
654 * 1/a
655 */
656 number nlInvers(number a, const coeffs r)
657 {
658  nlTest(a, r);
659  number n;
660  if (SR_HDL(a) & SR_INT)
661  {
662  if ((a==INT_TO_SR(1L)) || (a==INT_TO_SR(-1L)))
663  {
664  return a;
665  }
666  if (nlIsZero(a,r))
667  {
668  WerrorS(nDivBy0);
669  return INT_TO_SR(0);
670  }
671  n=ALLOC_RNUMBER();
672 #if defined(LDEBUG)
673  n->debug=123456;
674 #endif
675  n->s=1;
676  if ((long)a>0L)
677  {
678  mpz_init_set_si(n->z,(long)1);
679  mpz_init_set_si(n->n,(long)SR_TO_INT(a));
680  }
681  else
682  {
683  mpz_init_set_si(n->z,(long)-1);
684  mpz_init_set_si(n->n,(long)-SR_TO_INT(a));
685  }
686  nlTest(n, r);
687  return n;
688  }
689  n=ALLOC_RNUMBER();
690 #if defined(LDEBUG)
691  n->debug=123456;
692 #endif
693  {
694  n->s=a->s;
695  mpz_init_set(n->n,a->z);
696  switch (a->s)
697  {
698  case 0:
699  case 1:
700  mpz_init_set(n->z,a->n);
701  if (mpz_isNeg(n->n)) /* && n->s<2*/
702  {
703  mpz_neg(n->z,n->z);
704  mpz_neg(n->n,n->n);
705  }
706  if (mpz_cmp_si(n->n,(long)1)==0)
707  {
708  mpz_clear(n->n);
709  n->s=3;
710  n=nlShort3(n);
711  }
712  break;
713  case 3:
714  n->s=1;
715  if (mpz_isNeg(n->n)) /* && n->s<2*/
716  {
717  mpz_neg(n->n,n->n);
718  mpz_init_set_si(n->z,(long)-1);
719  }
720  else
721  {
722  mpz_init_set_si(n->z,(long)1);
723  }
724  break;
725  }
726  }
727  nlTest(n, r);
728  return n;
729 }
730 
731 
732 /*2
733 * u := a / b in Z, if b | a (else undefined)
734 */
735 number nlExactDiv(number a, number b, const coeffs r)
736 {
737  if (b==INT_TO_SR(0))
738  {
739  WerrorS(nDivBy0);
740  return INT_TO_SR(0);
741  }
742  if (a==INT_TO_SR(0))
743  return INT_TO_SR(0);
744  number u;
745  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
746  {
747  /* the small int -(1<<28) divided by -1 is the large int (1<<28) */
748  if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
749  {
750  return nlRInit(POW_2_28);
751  }
752  long aa=SR_TO_INT(a);
753  long bb=SR_TO_INT(b);
754  return INT_TO_SR(aa/bb);
755  }
756  number bb=NULL;
757  if (SR_HDL(b) & SR_INT)
758  {
759  bb=nlRInit(SR_TO_INT(b));
760  b=bb;
761  }
762  u=ALLOC_RNUMBER();
763 #if defined(LDEBUG)
764  u->debug=123456;
765 #endif
766  mpz_init(u->z);
767  /* u=a/b */
768  u->s = 3;
769  MPZ_EXACTDIV(u->z,a->z,b->z);
770  if (bb!=NULL)
771  {
772  mpz_clear(bb->z);
773 #if defined(LDEBUG)
774  bb->debug=654324;
775 #endif
776  FREE_RNUMBER(bb); // omFreeBin((void *)bb, rnumber_bin);
777  }
778  u=nlShort3(u);
779  nlTest(u, r);
780  return u;
781 }
782 
783 /*2
784 * u := a / b in Z
785 */
786 number nlIntDiv (number a, number b, const coeffs r)
787 {
788  if (b==INT_TO_SR(0))
789  {
790  WerrorS(nDivBy0);
791  return INT_TO_SR(0);
792  }
793  if (a==INT_TO_SR(0))
794  return INT_TO_SR(0);
795  number u;
796  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
797  {
798  /* the small int -(1<<28) divided by -1 is the large int (1<<28) */
799  if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
800  {
801  return nlRInit(POW_2_28);
802  }
803  long aa=SR_TO_INT(a);
804  long bb=SR_TO_INT(b);
805  return INT_TO_SR(aa/bb);
806  }
807  if (SR_HDL(a) & SR_INT)
808  {
809  /* the small int -(1<<28) divided by 2^28 is 1 */
810  if (a==INT_TO_SR(-(POW_2_28)))
811  {
812  if(mpz_cmp_si(b->z,(POW_2_28))==0)
813  {
814  return INT_TO_SR(-1);
815  }
816  }
817  /* a is a small and b is a large int: -> 0 */
818  return INT_TO_SR(0);
819  }
820  number bb=NULL;
821  if (SR_HDL(b) & SR_INT)
822  {
823  bb=nlRInit(SR_TO_INT(b));
824  b=bb;
825  }
826  u=ALLOC_RNUMBER();
827 #if defined(LDEBUG)
828  u->debug=123456;
829 #endif
830  assume(a->s==3);
831  assume(b->s==3);
832  mpz_init_set(u->z,a->z);
833  /* u=u/b */
834  u->s = 3;
835  MPZ_DIV(u->z,u->z,b->z);
836  if (bb!=NULL)
837  {
838  mpz_clear(bb->z);
839 #if defined(LDEBUG)
840  bb->debug=654324;
841 #endif
842  FREE_RNUMBER(bb);
843  }
844  u=nlShort3(u);
845  nlTest(u,r);
846  return u;
847 }
848 
849 /*2
850 * u := a mod b in Z, u>=0
851 */
852 number nlIntMod (number a, number b, const coeffs r)
853 {
854  if (b==INT_TO_SR(0))
855  {
856  WerrorS(nDivBy0);
857  return INT_TO_SR(0);
858  }
859  if (a==INT_TO_SR(0))
860  return INT_TO_SR(0);
861  number u;
862  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
863  {
864  LONG bb=SR_TO_INT(b);
865  LONG c=SR_TO_INT(a) % bb;
866  return INT_TO_SR(c);
867  }
868  if (SR_HDL(a) & SR_INT)
869  {
870  mpz_t aa;
871  mpz_init(aa);
872  mpz_set_si(aa, SR_TO_INT(a));
873  u=ALLOC_RNUMBER();
874 #if defined(LDEBUG)
875  u->debug=123456;
876 #endif
877  u->s = 3;
878  mpz_init(u->z);
879  mpz_mod(u->z,aa,b->z);
880  mpz_clear(aa);
881  u=nlShort3(u);
882  nlTest(u,r);
883  return u;
884  }
885  number bb=NULL;
886  if (SR_HDL(b) & SR_INT)
887  {
888  bb=nlRInit(SR_TO_INT(b));
889  b=bb;
890  }
891  u=ALLOC_RNUMBER();
892 #if defined(LDEBUG)
893  u->debug=123456;
894 #endif
895  mpz_init(u->z);
896  u->s = 3;
897  mpz_mod(u->z,a->z,b->z);
898  if (bb!=NULL)
899  {
900  mpz_clear(bb->z);
901 #if defined(LDEBUG)
902  bb->debug=654324;
903 #endif
904  FREE_RNUMBER(bb);
905  }
906  u=nlShort3(u);
907  nlTest(u,r);
908  return u;
909 }
910 
911 BOOLEAN nlDivBy (number a,number b, const coeffs)
912 {
913  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
914  {
915  return ((SR_TO_INT(a) % SR_TO_INT(b))==0);
916  }
917  if (SR_HDL(b) & SR_INT)
918  {
919  return (mpz_divisible_ui_p(a->z,SR_TO_INT(b))!=0);
920  }
921  if (SR_HDL(a) & SR_INT) return FALSE;
922  return mpz_divisible_p(a->z, b->z) != 0;
923 }
924 
925 int nlDivComp(number a, number b, const coeffs r)
926 {
927  if (nlDivBy(a, b, r))
928  {
929  if (nlDivBy(b, a, r)) return 2;
930  return -1;
931  }
932  if (nlDivBy(b, a, r)) return 1;
933  return 0;
934 }
935 
936 number nlGetUnit (number n, const coeffs r)
937 {
938  if (nlGreaterZero(n, r))
939  return INT_TO_SR(1);
940  else
941  return INT_TO_SR(-1);
942 }
943 
944 coeffs nlQuot1(number c, const coeffs r)
945 {
946  long ch = r->cfInt(c, r);
947  int p=IsPrime(ch);
948  coeffs rr=NULL;
949  if ((long)p==ch)
950  {
951  rr = nInitChar(n_Zp,(void*)ch);
952  }
953  #ifdef HAVE_RINGS
954  else
955  {
956  mpz_ptr dummy;
957  dummy = (mpz_ptr) omAlloc(sizeof(mpz_t));
958  mpz_init_set_ui(dummy, ch);
959  ZnmInfo info;
960  info.base = dummy;
961  info.exp = (unsigned long) 1;
962  rr = nInitChar(n_Zn, (void*)&info);
963  }
964  #endif
965  return(rr);
966 }
967 
968 
969 BOOLEAN nlIsUnit (number a, const coeffs)
970 {
971  return ((SR_HDL(a) & SR_INT) && (ABS(SR_TO_INT(a))==1));
972 }
973 
974 
975 /*2
976 * u := a / b
977 */
978 number nlDiv (number a, number b, const coeffs r)
979 {
980  if (nlIsZero(b,r))
981  {
982  WerrorS(nDivBy0);
983  return INT_TO_SR(0);
984  }
985  number u;
986 // ---------- short / short ------------------------------------
987  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
988  {
989  LONG i=SR_TO_INT(a);
990  LONG j=SR_TO_INT(b);
991  if (j==1L) return a;
992  if ((i==-POW_2_28) && (j== -1L))
993  {
994  return nlRInit(POW_2_28);
995  }
996  LONG r=i%j;
997  if (r==0)
998  {
999  return INT_TO_SR(i/j);
1000  }
1001  u=ALLOC_RNUMBER();
1002  u->s=0;
1003  #if defined(LDEBUG)
1004  u->debug=123456;
1005  #endif
1006  mpz_init_set_si(u->z,(long)i);
1007  mpz_init_set_si(u->n,(long)j);
1008  }
1009  else
1010  {
1011  u=ALLOC_RNUMBER();
1012  u->s=0;
1013  #if defined(LDEBUG)
1014  u->debug=123456;
1015  #endif
1016  mpz_init(u->z);
1017 // ---------- short / long ------------------------------------
1018  if (SR_HDL(a) & SR_INT)
1019  {
1020  // short a / (z/n) -> (a*n)/z
1021  if (b->s<2)
1022  {
1023  mpz_mul_si(u->z,b->n,SR_TO_INT(a));
1024  }
1025  else
1026  // short a / long z -> a/z
1027  {
1028  mpz_set_si(u->z,SR_TO_INT(a));
1029  }
1030  if (mpz_cmp(u->z,b->z)==0)
1031  {
1032  mpz_clear(u->z);
1033  FREE_RNUMBER(u);
1034  return INT_TO_SR(1);
1035  }
1036  mpz_init_set(u->n,b->z);
1037  }
1038 // ---------- long / short ------------------------------------
1039  else if (SR_HDL(b) & SR_INT)
1040  {
1041  mpz_set(u->z,a->z);
1042  // (z/n) / b -> z/(n*b)
1043  if (a->s<2)
1044  {
1045  mpz_init_set(u->n,a->n);
1046  if ((long)b>0L)
1047  mpz_mul_ui(u->n,u->n,SR_TO_INT(b));
1048  else
1049  {
1050  mpz_mul_ui(u->n,u->n,-SR_TO_INT(b));
1051  mpz_neg(u->z,u->z);
1052  }
1053  }
1054  else
1055  // long z / short b -> z/b
1056  {
1057  //mpz_set(u->z,a->z);
1058  mpz_init_set_si(u->n,SR_TO_INT(b));
1059  }
1060  }
1061 // ---------- long / long ------------------------------------
1062  else
1063  {
1064  mpz_set(u->z,a->z);
1065  mpz_init_set(u->n,b->z);
1066  if (a->s<2) mpz_mul(u->n,u->n,a->n);
1067  if (b->s<2) mpz_mul(u->z,u->z,b->n);
1068  }
1069  }
1070  if (mpz_isNeg(u->n))
1071  {
1072  mpz_neg(u->z,u->z);
1073  mpz_neg(u->n,u->n);
1074  }
1075  if (mpz_cmp_si(u->n,(long)1)==0)
1076  {
1077  mpz_clear(u->n);
1078  u->s=3;
1079  u=nlShort3(u);
1080  }
1081  nlTest(u, r);
1082  return u;
1083 }
1084 
1085 /*2
1086 * u:= x ^ exp
1087 */
1088 void nlPower (number x,int exp,number * u, const coeffs r)
1089 {
1090  *u = INT_TO_SR(0); // 0^e, e!=0
1091  if (exp==0)
1092  *u= INT_TO_SR(1);
1093  else if (!nlIsZero(x,r))
1094  {
1095  nlTest(x, r);
1096  number aa=NULL;
1097  if (SR_HDL(x) & SR_INT)
1098  {
1099  aa=nlRInit(SR_TO_INT(x));
1100  x=aa;
1101  }
1102  else if (x->s==0)
1103  nlNormalize(x,r);
1104  *u=ALLOC_RNUMBER();
1105 #if defined(LDEBUG)
1106  (*u)->debug=123456;
1107 #endif
1108  mpz_init((*u)->z);
1109  mpz_pow_ui((*u)->z,x->z,(unsigned long)exp);
1110  if (x->s<2)
1111  {
1112  if (mpz_cmp_si(x->n,(long)1)==0)
1113  {
1114  x->s=3;
1115  mpz_clear(x->n);
1116  }
1117  else
1118  {
1119  mpz_init((*u)->n);
1120  mpz_pow_ui((*u)->n,x->n,(unsigned long)exp);
1121  }
1122  }
1123  (*u)->s = x->s;
1124  if ((*u)->s==3) *u=nlShort3(*u);
1125  if (aa!=NULL)
1126  {
1127  mpz_clear(aa->z);
1128  FREE_RNUMBER(aa);
1129  }
1130  }
1131 #ifdef LDEBUG
1132  if (exp<0) Print("nlPower: neg. exp. %d\n",exp);
1133  nlTest(*u, r);
1134 #endif
1135 }
1136 
1137 
1138 /*2
1139 * za >= 0 ?
1140 */
1141 BOOLEAN nlGreaterZero (number a, const coeffs r)
1142 {
1143  nlTest(a, r);
1144  if (SR_HDL(a) & SR_INT) return SR_HDL(a)>1L /* represents number(0) */;
1145  return (!mpz_isNeg(a->z));
1146 }
1147 
1148 /*2
1149 * a > b ?
1150 */
1151 BOOLEAN nlGreater (number a, number b, const coeffs r)
1152 {
1153  nlTest(a, r);
1154  nlTest(b, r);
1155  number re;
1156  BOOLEAN rr;
1157  re=nlSub(a,b,r);
1158  rr=(!nlIsZero(re,r)) && (nlGreaterZero(re,r));
1159  nlDelete(&re,r);
1160  return rr;
1161 }
1162 
1163 /*2
1164 * a == -1 ?
1165 */
1166 BOOLEAN nlIsMOne (number a, const coeffs r)
1167 {
1168 #ifdef LDEBUG
1169  if (a==NULL) return FALSE;
1170  nlTest(a, r);
1171 #endif
1172  return (a==INT_TO_SR(-1L));
1173 }
1174 
1175 /*2
1176 * result =gcd(a,b)
1177 */
1178 number nlGcd(number a, number b, const coeffs r)
1179 {
1180  number result;
1181  nlTest(a, r);
1182  nlTest(b, r);
1183  //nlNormalize(a);
1184  //nlNormalize(b);
1185  if ((a==INT_TO_SR(1L))||(a==INT_TO_SR(-1L))
1186  || (b==INT_TO_SR(1L))||(b==INT_TO_SR(-1L)))
1187  return INT_TO_SR(1L);
1188  if (a==INT_TO_SR(0)) /* gcd(0,b) ->b */
1189  return nlCopy(b,r);
1190  if (b==INT_TO_SR(0)) /* gcd(a,0) -> a */
1191  return nlCopy(a,r);
1192  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
1193  {
1194  long i=SR_TO_INT(a);
1195  long j=SR_TO_INT(b);
1196  if((i==0L)||(j==0L))
1197  return INT_TO_SR(1);
1198  long l;
1199  i=ABS(i);
1200  j=ABS(j);
1201  do
1202  {
1203  l=i%j;
1204  i=j;
1205  j=l;
1206  } while (l!=0L);
1207  if (i==POW_2_28)
1208  result=nlRInit(POW_2_28);
1209  else
1210  result=INT_TO_SR(i);
1211  nlTest(result,r);
1212  return result;
1213  }
1214  if (((!(SR_HDL(a) & SR_INT))&&(a->s<2))
1215  || ((!(SR_HDL(b) & SR_INT))&&(b->s<2))) return INT_TO_SR(1);
1216  if (SR_HDL(a) & SR_INT)
1217  {
1218  LONG aa=ABS(SR_TO_INT(a));
1219  unsigned long t=mpz_gcd_ui(NULL,b->z,(long)aa);
1220  if (t==POW_2_28)
1221  result=nlRInit(POW_2_28);
1222  else
1223  result=INT_TO_SR(t);
1224  }
1225  else
1226  if (SR_HDL(b) & SR_INT)
1227  {
1228  LONG bb=ABS(SR_TO_INT(b));
1229  unsigned long t=mpz_gcd_ui(NULL,a->z,(long)bb);
1230  if (t==POW_2_28)
1231  result=nlRInit(POW_2_28);
1232  else
1233  result=INT_TO_SR(t);
1234  }
1235  else
1236  {
1237  result=ALLOC0_RNUMBER();
1238  mpz_init(result->z);
1239  mpz_gcd(result->z,a->z,b->z);
1240  result->s = 3;
1241  #ifdef LDEBUG
1242  result->debug=123456;
1243  #endif
1244  result=nlShort3(result);
1245  }
1246  nlTest(result, r);
1247  return result;
1248 }
1249 //number nlGcd_dummy(number a, number b, const coeffs r)
1250 //{
1251 // extern char my_yylinebuf[80];
1252 // Print("nlGcd in >>%s<<\n",my_yylinebuf);
1253 // return nlGcd(a,b,r);;
1254 //}
1255 
1256 number nlShort1(number x) // assume x->s==0/1
1257 {
1258  assume(x->s<2);
1259  if (mpz_cmp_ui(x->z,(long)0)==0)
1260  {
1261  _nlDelete_NoImm(&x);
1262  return INT_TO_SR(0);
1263  }
1264  if (x->s<2)
1265  {
1266  if (mpz_cmp(x->z,x->n)==0)
1267  {
1268  _nlDelete_NoImm(&x);
1269  return INT_TO_SR(1);
1270  }
1271  }
1272  return x;
1273 }
1274 /*2
1275 * simplify x
1276 */
1277 void nlNormalize (number &x, const coeffs r)
1278 {
1279  if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1280  return;
1281  if (x->s==3)
1282  {
1283  x=nlShort3_noinline(x);
1284  nlTest(x,r);
1285  return;
1286  }
1287  else if (x->s==0)
1288  {
1289  if (mpz_cmp_si(x->n,(long)1)==0)
1290  {
1291  mpz_clear(x->n);
1292  x->s=3;
1293  x=nlShort3(x);
1294  }
1295  else
1296  {
1297  mpz_t gcd;
1298  mpz_init(gcd);
1299  mpz_gcd(gcd,x->z,x->n);
1300  x->s=1;
1301  if (mpz_cmp_si(gcd,(long)1)!=0)
1302  {
1303  MPZ_EXACTDIV(x->z,x->z,gcd);
1304  MPZ_EXACTDIV(x->n,x->n,gcd);
1305  if (mpz_cmp_si(x->n,(long)1)==0)
1306  {
1307  mpz_clear(x->n);
1308  x->s=3;
1309  x=nlShort3_noinline(x);
1310  }
1311  }
1312  mpz_clear(gcd);
1313  }
1314  }
1315  nlTest(x, r);
1316 }
1317 
1318 /*2
1319 * returns in result->z the lcm(a->z,b->n)
1320 */
1321 number nlNormalizeHelper(number a, number b, const coeffs r)
1322 {
1323  number result;
1324  nlTest(a, r);
1325  nlTest(b, r);
1326  if ((SR_HDL(b) & SR_INT)
1327  || (b->s==3))
1328  {
1329  // b is 1/(b->n) => b->n is 1 => result is a
1330  return nlCopy(a,r);
1331  }
1332  result=ALLOC_RNUMBER();
1333 #if defined(LDEBUG)
1334  result->debug=123456;
1335 #endif
1336  result->s=3;
1337  mpz_t gcd;
1338  mpz_init(gcd);
1339  mpz_init(result->z);
1340  if (SR_HDL(a) & SR_INT)
1341  mpz_gcd_ui(gcd,b->n,ABS(SR_TO_INT(a)));
1342  else
1343  mpz_gcd(gcd,a->z,b->n);
1344  if (mpz_cmp_si(gcd,(long)1)!=0)
1345  {
1346  mpz_t bt;
1347  mpz_init_set(bt,b->n);
1348  MPZ_EXACTDIV(bt,bt,gcd);
1349  if (SR_HDL(a) & SR_INT)
1350  mpz_mul_si(result->z,bt,SR_TO_INT(a));
1351  else
1352  mpz_mul(result->z,bt,a->z);
1353  mpz_clear(bt);
1354  }
1355  else
1356  if (SR_HDL(a) & SR_INT)
1357  mpz_mul_si(result->z,b->n,SR_TO_INT(a));
1358  else
1359  mpz_mul(result->z,b->n,a->z);
1360  mpz_clear(gcd);
1361  result=nlShort3(result);
1362  nlTest(result, r);
1363  return result;
1364 }
1365 
1366 // Map q \in QQ or ZZ \to Zp or an extension of it
1367 // src = Q or Z, dst = Zp (or an extension of Zp)
1368 number nlModP(number q, const coeffs Q, const coeffs Zp)
1369 {
1370  const int p = n_GetChar(Zp);
1371  assume( p > 0 );
1372 
1373  const long P = p;
1374  assume( P > 0 );
1375 
1376  // embedded long within q => only long numerator has to be converted
1377  // to int (modulo char.)
1378  if (SR_HDL(q) & SR_INT)
1379  {
1380  long i = SR_TO_INT(q);
1381  return n_Init( i, Zp );
1382  }
1383 
1384  const unsigned long PP = p;
1385 
1386  // numerator modulo char. should fit into int
1387  number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1388 
1389  // denominator != 1?
1390  if (q->s!=3)
1391  {
1392  // denominator modulo char. should fit into int
1393  number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1394 
1395  number res = n_Div( z, n, Zp );
1396 
1397  n_Delete(&z, Zp);
1398  n_Delete(&n, Zp);
1399 
1400  return res;
1401  }
1402 
1403  return z;
1404 }
1405 
1406 #ifdef HAVE_RINGS
1407 /*2
1408 * convert number i (from Q) to GMP and warn if denom != 1
1409 */
1410 void nlGMP(number &i, number n, const coeffs r)
1411 {
1412  // Hier brauche ich einfach die GMP Zahl
1413  nlTest(i, r);
1414  nlNormalize(i, r);
1415  if (SR_HDL(i) & SR_INT)
1416  {
1417  mpz_set_si((mpz_ptr) n, SR_TO_INT(i));
1418  return;
1419  }
1420  if (i->s!=3)
1421  {
1422  WarnS("Omitted denominator during coefficient mapping !");
1423  }
1424  mpz_set((mpz_ptr) n, i->z);
1425 }
1426 #endif
1427 
1428 /*2
1429 * acces to denominator, other 1 for integers
1430 */
1431 number nlGetDenom(number &n, const coeffs r)
1432 {
1433  if (!(SR_HDL(n) & SR_INT))
1434  {
1435  if (n->s==0)
1436  {
1437  nlNormalize(n,r);
1438  }
1439  if (!(SR_HDL(n) & SR_INT))
1440  {
1441  if (n->s!=3)
1442  {
1443  number u=ALLOC_RNUMBER();
1444  u->s=3;
1445 #if defined(LDEBUG)
1446  u->debug=123456;
1447 #endif
1448  mpz_init_set(u->z,n->n);
1449  u=nlShort3_noinline(u);
1450  return u;
1451  }
1452  }
1453  }
1454  return INT_TO_SR(1);
1455 }
1456 
1457 /*2
1458 * acces to Nominator, nlCopy(n) for integers
1459 */
1460 number nlGetNumerator(number &n, const coeffs r)
1461 {
1462  if (!(SR_HDL(n) & SR_INT))
1463  {
1464  if (n->s==0)
1465  {
1466  nlNormalize(n,r);
1467  }
1468  if (!(SR_HDL(n) & SR_INT))
1469  {
1470  number u=ALLOC_RNUMBER();
1471 #if defined(LDEBUG)
1472  u->debug=123456;
1473 #endif
1474  u->s=3;
1475  mpz_init_set(u->z,n->z);
1476  if (n->s!=3)
1477  {
1478  u=nlShort3_noinline(u);
1479  }
1480  return u;
1481  }
1482  }
1483  return n; // imm. int
1484 }
1485 
1486 /***************************************************************
1487  *
1488  * routines which are needed by Inline(d) routines
1489  *
1490  *******************************************************************/
1492 {
1493  assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
1494 // long - short
1495  BOOLEAN bo;
1496  if (SR_HDL(b) & SR_INT)
1497  {
1498  if (a->s!=0) return FALSE;
1499  number n=b; b=a; a=n;
1500  }
1501 // short - long
1502  if (SR_HDL(a) & SR_INT)
1503  {
1504  if (b->s!=0)
1505  return FALSE;
1506  if (((long)a > 0L) && (mpz_isNeg(b->z)))
1507  return FALSE;
1508  if (((long)a < 0L) && (!mpz_isNeg(b->z)))
1509  return FALSE;
1510  mpz_t bb;
1511  mpz_init_set(bb,b->n);
1512  mpz_mul_si(bb,bb,(long)SR_TO_INT(a));
1513  bo=(mpz_cmp(bb,b->z)==0);
1514  mpz_clear(bb);
1515  return bo;
1516  }
1517 // long - long
1518  if (((a->s==1) && (b->s==3))
1519  || ((b->s==1) && (a->s==3)))
1520  return FALSE;
1521  if (mpz_isNeg(a->z)&&(!mpz_isNeg(b->z)))
1522  return FALSE;
1523  if (mpz_isNeg(b->z)&&(!mpz_isNeg(a->z)))
1524  return FALSE;
1525  mpz_t aa;
1526  mpz_t bb;
1527  mpz_init_set(aa,a->z);
1528  mpz_init_set(bb,b->z);
1529  if (a->s<2) mpz_mul(bb,bb,a->n);
1530  if (b->s<2) mpz_mul(aa,aa,b->n);
1531  bo=(mpz_cmp(aa,bb)==0);
1532  mpz_clear(aa);
1533  mpz_clear(bb);
1534  return bo;
1535 }
1536 
1537 // copy not immediate number a
1538 number _nlCopy_NoImm(number a)
1539 {
1540  assume(!((SR_HDL(a) & SR_INT)||(a==NULL)));
1541  //nlTest(a, r);
1542  number b=ALLOC_RNUMBER();
1543 #if defined(LDEBUG)
1544  b->debug=123456;
1545 #endif
1546  switch (a->s)
1547  {
1548  case 0:
1549  case 1:
1550  mpz_init_set(b->n,a->n);
1551  case 3:
1552  mpz_init_set(b->z,a->z);
1553  break;
1554  }
1555  b->s = a->s;
1556  return b;
1557 }
1558 
1559 void _nlDelete_NoImm(number *a)
1560 {
1561  {
1562  switch ((*a)->s)
1563  {
1564  case 0:
1565  case 1:
1566  mpz_clear((*a)->n);
1567  case 3:
1568  mpz_clear((*a)->z);
1569 #ifdef LDEBUG
1570  (*a)->s=2;
1571 #endif
1572  }
1573  FREE_RNUMBER(*a); // omFreeBin((void *) *a, rnumber_bin);
1574  }
1575 }
1576 
1577 number _nlNeg_NoImm(number a)
1578 {
1579  {
1580  mpz_neg(a->z,a->z);
1581  if (a->s==3)
1582  {
1583  a=nlShort3(a);
1584  }
1585  }
1586  return a;
1587 }
1588 
1589 number _nlAdd_aNoImm_OR_bNoImm(number a, number b)
1590 {
1591  number u=ALLOC_RNUMBER();
1592 #if defined(LDEBUG)
1593  u->debug=123456;
1594 #endif
1595  mpz_init(u->z);
1596  if (SR_HDL(b) & SR_INT)
1597  {
1598  number x=a;
1599  a=b;
1600  b=x;
1601  }
1602  if (SR_HDL(a) & SR_INT)
1603  {
1604  switch (b->s)
1605  {
1606  case 0:
1607  case 1:/* a:short, b:1 */
1608  {
1609  mpz_t x;
1610  mpz_init(x);
1611  mpz_mul_si(x,b->n,SR_TO_INT(a));
1612  mpz_add(u->z,b->z,x);
1613  mpz_clear(x);
1614  if (mpz_cmp_ui(u->z,(long)0)==0)
1615  {
1616  mpz_clear(u->z);
1617  FREE_RNUMBER(u);
1618  return INT_TO_SR(0);
1619  }
1620  if (mpz_cmp(u->z,b->n)==0)
1621  {
1622  mpz_clear(u->z);
1623  FREE_RNUMBER(u);
1624  return INT_TO_SR(1);
1625  }
1626  mpz_init_set(u->n,b->n);
1627  u->s = 0;
1628  break;
1629  }
1630  case 3:
1631  {
1632  if ((long)a>0L)
1633  mpz_add_ui(u->z,b->z,SR_TO_INT(a));
1634  else
1635  mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
1636  if (mpz_cmp_ui(u->z,(long)0)==0)
1637  {
1638  mpz_clear(u->z);
1639  FREE_RNUMBER(u);
1640  return INT_TO_SR(0);
1641  }
1642  u->s = 3;
1643  u=nlShort3(u);
1644  break;
1645  }
1646  }
1647  }
1648  else
1649  {
1650  switch (a->s)
1651  {
1652  case 0:
1653  case 1:
1654  {
1655  switch(b->s)
1656  {
1657  case 0:
1658  case 1:
1659  {
1660  mpz_t x;
1661  mpz_init(x);
1662 
1663  mpz_mul(x,b->z,a->n);
1664  mpz_mul(u->z,a->z,b->n);
1665  mpz_add(u->z,u->z,x);
1666  mpz_clear(x);
1667 
1668  if (mpz_cmp_ui(u->z,(long)0)==0)
1669  {
1670  mpz_clear(u->z);
1671  FREE_RNUMBER(u);
1672  return INT_TO_SR(0);
1673  }
1674  mpz_init(u->n);
1675  mpz_mul(u->n,a->n,b->n);
1676  if (mpz_cmp(u->z,u->n)==0)
1677  {
1678  mpz_clear(u->z);
1679  mpz_clear(u->n);
1680  FREE_RNUMBER(u);
1681  return INT_TO_SR(1);
1682  }
1683  u->s = 0;
1684  break;
1685  }
1686  case 3: /* a:1 b:3 */
1687  {
1688  mpz_mul(u->z,b->z,a->n);
1689  mpz_add(u->z,u->z,a->z);
1690  if (mpz_cmp_ui(u->z,(long)0)==0)
1691  {
1692  mpz_clear(u->z);
1693  FREE_RNUMBER(u);
1694  return INT_TO_SR(0);
1695  }
1696  if (mpz_cmp(u->z,a->n)==0)
1697  {
1698  mpz_clear(u->z);
1699  FREE_RNUMBER(u);
1700  return INT_TO_SR(1);
1701  }
1702  mpz_init_set(u->n,a->n);
1703  u->s = 0;
1704  break;
1705  }
1706  } /*switch (b->s) */
1707  break;
1708  }
1709  case 3:
1710  {
1711  switch(b->s)
1712  {
1713  case 0:
1714  case 1:/* a:3, b:1 */
1715  {
1716  mpz_mul(u->z,a->z,b->n);
1717  mpz_add(u->z,u->z,b->z);
1718  if (mpz_cmp_ui(u->z,(long)0)==0)
1719  {
1720  mpz_clear(u->z);
1721  FREE_RNUMBER(u);
1722  return INT_TO_SR(0);
1723  }
1724  if (mpz_cmp(u->z,b->n)==0)
1725  {
1726  mpz_clear(u->z);
1727  FREE_RNUMBER(u);
1728  return INT_TO_SR(1);
1729  }
1730  mpz_init_set(u->n,b->n);
1731  u->s = 0;
1732  break;
1733  }
1734  case 3:
1735  {
1736  mpz_add(u->z,a->z,b->z);
1737  if (mpz_cmp_ui(u->z,(long)0)==0)
1738  {
1739  mpz_clear(u->z);
1740  FREE_RNUMBER(u);
1741  return INT_TO_SR(0);
1742  }
1743  u->s = 3;
1744  u=nlShort3(u);
1745  break;
1746  }
1747  }
1748  break;
1749  }
1750  }
1751  }
1752  return u;
1753 }
1754 
1755 void _nlInpAdd_aNoImm_OR_bNoImm(number &a, number b)
1756 {
1757  if (SR_HDL(b) & SR_INT)
1758  {
1759  switch (a->s)
1760  {
1761  case 0:
1762  case 1:/* b:short, a:1 */
1763  {
1764  mpz_t x;
1765  mpz_init(x);
1766  mpz_mul_si(x,a->n,SR_TO_INT(b));
1767  mpz_add(a->z,a->z,x);
1768  mpz_clear(x);
1769  a->s = 0;
1770  a=nlShort1(a);
1771  break;
1772  }
1773  case 3:
1774  {
1775  if ((long)b>0L)
1776  mpz_add_ui(a->z,a->z,SR_TO_INT(b));
1777  else
1778  mpz_sub_ui(a->z,a->z,-SR_TO_INT(b));
1779  a->s = 3;
1780  a=nlShort3_noinline(a);
1781  break;
1782  }
1783  }
1784  return;
1785  }
1786  else if (SR_HDL(a) & SR_INT)
1787  {
1788  number u=ALLOC_RNUMBER();
1789  #if defined(LDEBUG)
1790  u->debug=123456;
1791  #endif
1792  mpz_init(u->z);
1793  switch (b->s)
1794  {
1795  case 0:
1796  case 1:/* a:short, b:1 */
1797  {
1798  mpz_t x;
1799  mpz_init(x);
1800 
1801  mpz_mul_si(x,b->n,SR_TO_INT(a));
1802  mpz_add(u->z,b->z,x);
1803  mpz_clear(x);
1804  // result cannot be 0, if coeffs are normalized
1805  mpz_init_set(u->n,b->n);
1806  u->s = 0;
1807  u=nlShort1(u);
1808  break;
1809  }
1810  case 3:
1811  {
1812  if ((long)a>0L)
1813  mpz_add_ui(u->z,b->z,SR_TO_INT(a));
1814  else
1815  mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
1816  // result cannot be 0, if coeffs are normalized
1817  u->s = 3;
1818  u=nlShort3_noinline(u);
1819  break;
1820  }
1821  }
1822  a=u;
1823  }
1824  else
1825  {
1826  switch (a->s)
1827  {
1828  case 0:
1829  case 1:
1830  {
1831  switch(b->s)
1832  {
1833  case 0:
1834  case 1: /* a:1 b:1 */
1835  {
1836  mpz_t x;
1837  mpz_t y;
1838  mpz_init(x);
1839  mpz_init(y);
1840  mpz_mul(x,b->z,a->n);
1841  mpz_mul(y,a->z,b->n);
1842  mpz_add(a->z,x,y);
1843  mpz_clear(x);
1844  mpz_clear(y);
1845  mpz_mul(a->n,a->n,b->n);
1846  a->s = 0;
1847  break;
1848  }
1849  case 3: /* a:1 b:3 */
1850  {
1851  mpz_t x;
1852  mpz_init(x);
1853  mpz_mul(x,b->z,a->n);
1854  mpz_add(a->z,a->z,x);
1855  mpz_clear(x);
1856  a->s = 0;
1857  break;
1858  }
1859  } /*switch (b->s) */
1860  a=nlShort1(a);
1861  break;
1862  }
1863  case 3:
1864  {
1865  switch(b->s)
1866  {
1867  case 0:
1868  case 1:/* a:3, b:1 */
1869  {
1870  mpz_t x;
1871  mpz_init(x);
1872  mpz_mul(x,a->z,b->n);
1873  mpz_add(a->z,b->z,x);
1874  mpz_clear(x);
1875  mpz_init_set(a->n,b->n);
1876  a->s = 0;
1877  a=nlShort1(a);
1878  break;
1879  }
1880  case 3:
1881  {
1882  mpz_add(a->z,a->z,b->z);
1883  a->s = 3;
1884  a=nlShort3_noinline(a);
1885  break;
1886  }
1887  }
1888  break;
1889  }
1890  }
1891  }
1892 }
1893 
1894 number _nlSub_aNoImm_OR_bNoImm(number a, number b)
1895 {
1896  number u=ALLOC_RNUMBER();
1897 #if defined(LDEBUG)
1898  u->debug=123456;
1899 #endif
1900  mpz_init(u->z);
1901  if (SR_HDL(a) & SR_INT)
1902  {
1903  switch (b->s)
1904  {
1905  case 0:
1906  case 1:/* a:short, b:1 */
1907  {
1908  mpz_t x;
1909  mpz_init(x);
1910  mpz_mul_si(x,b->n,SR_TO_INT(a));
1911  mpz_sub(u->z,x,b->z);
1912  mpz_clear(x);
1913  if (mpz_cmp_ui(u->z,(long)0)==0)
1914  {
1915  mpz_clear(u->z);
1916  FREE_RNUMBER(u);
1917  return INT_TO_SR(0);
1918  }
1919  if (mpz_cmp(u->z,b->n)==0)
1920  {
1921  mpz_clear(u->z);
1922  FREE_RNUMBER(u);
1923  return INT_TO_SR(1);
1924  }
1925  mpz_init_set(u->n,b->n);
1926  u->s = 0;
1927  break;
1928  }
1929  case 3:
1930  {
1931  if ((long)a>0L)
1932  {
1933  mpz_sub_ui(u->z,b->z,SR_TO_INT(a));
1934  mpz_neg(u->z,u->z);
1935  }
1936  else
1937  {
1938  mpz_add_ui(u->z,b->z,-SR_TO_INT(a));
1939  mpz_neg(u->z,u->z);
1940  }
1941  if (mpz_cmp_ui(u->z,(long)0)==0)
1942  {
1943  mpz_clear(u->z);
1944  FREE_RNUMBER(u);
1945  return INT_TO_SR(0);
1946  }
1947  u->s = 3;
1948  u=nlShort3(u);
1949  break;
1950  }
1951  }
1952  }
1953  else if (SR_HDL(b) & SR_INT)
1954  {
1955  switch (a->s)
1956  {
1957  case 0:
1958  case 1:/* b:short, a:1 */
1959  {
1960  mpz_t x;
1961  mpz_init(x);
1962  mpz_mul_si(x,a->n,SR_TO_INT(b));
1963  mpz_sub(u->z,a->z,x);
1964  mpz_clear(x);
1965  if (mpz_cmp_ui(u->z,(long)0)==0)
1966  {
1967  mpz_clear(u->z);
1968  FREE_RNUMBER(u);
1969  return INT_TO_SR(0);
1970  }
1971  if (mpz_cmp(u->z,a->n)==0)
1972  {
1973  mpz_clear(u->z);
1974  FREE_RNUMBER(u);
1975  return INT_TO_SR(1);
1976  }
1977  mpz_init_set(u->n,a->n);
1978  u->s = 0;
1979  break;
1980  }
1981  case 3:
1982  {
1983  if ((long)b>0L)
1984  {
1985  mpz_sub_ui(u->z,a->z,SR_TO_INT(b));
1986  }
1987  else
1988  {
1989  mpz_add_ui(u->z,a->z,-SR_TO_INT(b));
1990  }
1991  if (mpz_cmp_ui(u->z,(long)0)==0)
1992  {
1993  mpz_clear(u->z);
1994  FREE_RNUMBER(u);
1995  return INT_TO_SR(0);
1996  }
1997  u->s = 3;
1998  u=nlShort3(u);
1999  break;
2000  }
2001  }
2002  }
2003  else
2004  {
2005  switch (a->s)
2006  {
2007  case 0:
2008  case 1:
2009  {
2010  switch(b->s)
2011  {
2012  case 0:
2013  case 1:
2014  {
2015  mpz_t x;
2016  mpz_t y;
2017  mpz_init(x);
2018  mpz_init(y);
2019  mpz_mul(x,b->z,a->n);
2020  mpz_mul(y,a->z,b->n);
2021  mpz_sub(u->z,y,x);
2022  mpz_clear(x);
2023  mpz_clear(y);
2024  if (mpz_cmp_ui(u->z,(long)0)==0)
2025  {
2026  mpz_clear(u->z);
2027  FREE_RNUMBER(u);
2028  return INT_TO_SR(0);
2029  }
2030  mpz_init(u->n);
2031  mpz_mul(u->n,a->n,b->n);
2032  if (mpz_cmp(u->z,u->n)==0)
2033  {
2034  mpz_clear(u->z);
2035  mpz_clear(u->n);
2036  FREE_RNUMBER(u);
2037  return INT_TO_SR(1);
2038  }
2039  u->s = 0;
2040  break;
2041  }
2042  case 3: /* a:1, b:3 */
2043  {
2044  mpz_t x;
2045  mpz_init(x);
2046  mpz_mul(x,b->z,a->n);
2047  mpz_sub(u->z,a->z,x);
2048  mpz_clear(x);
2049  if (mpz_cmp_ui(u->z,(long)0)==0)
2050  {
2051  mpz_clear(u->z);
2052  FREE_RNUMBER(u);
2053  return INT_TO_SR(0);
2054  }
2055  if (mpz_cmp(u->z,a->n)==0)
2056  {
2057  mpz_clear(u->z);
2058  FREE_RNUMBER(u);
2059  return INT_TO_SR(1);
2060  }
2061  mpz_init_set(u->n,a->n);
2062  u->s = 0;
2063  break;
2064  }
2065  }
2066  break;
2067  }
2068  case 3:
2069  {
2070  switch(b->s)
2071  {
2072  case 0:
2073  case 1: /* a:3, b:1 */
2074  {
2075  mpz_t x;
2076  mpz_init(x);
2077  mpz_mul(x,a->z,b->n);
2078  mpz_sub(u->z,x,b->z);
2079  mpz_clear(x);
2080  if (mpz_cmp_ui(u->z,(long)0)==0)
2081  {
2082  mpz_clear(u->z);
2083  FREE_RNUMBER(u);
2084  return INT_TO_SR(0);
2085  }
2086  if (mpz_cmp(u->z,b->n)==0)
2087  {
2088  mpz_clear(u->z);
2089  FREE_RNUMBER(u);
2090  return INT_TO_SR(1);
2091  }
2092  mpz_init_set(u->n,b->n);
2093  u->s = 0;
2094  break;
2095  }
2096  case 3: /* a:3 , b:3 */
2097  {
2098  mpz_sub(u->z,a->z,b->z);
2099  if (mpz_cmp_ui(u->z,(long)0)==0)
2100  {
2101  mpz_clear(u->z);
2102  FREE_RNUMBER(u);
2103  return INT_TO_SR(0);
2104  }
2105  u->s = 3;
2106  u=nlShort3(u);
2107  break;
2108  }
2109  }
2110  break;
2111  }
2112  }
2113  }
2114  return u;
2115 }
2116 
2117 // a and b are intermediate, but a*b not
2118 number _nlMult_aImm_bImm_rNoImm(number a, number b)
2119 {
2120  number u=ALLOC_RNUMBER();
2121 #if defined(LDEBUG)
2122  u->debug=123456;
2123 #endif
2124  u->s=3;
2125  mpz_init_set_si(u->z,SR_TO_INT(a));
2126  mpz_mul_si(u->z,u->z,SR_TO_INT(b));
2127  return u;
2128 }
2129 
2130 // a or b are not immediate
2131 number _nlMult_aNoImm_OR_bNoImm(number a, number b)
2132 {
2133  assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
2134  number u=ALLOC_RNUMBER();
2135 #if defined(LDEBUG)
2136  u->debug=123456;
2137 #endif
2138  mpz_init(u->z);
2139  if (SR_HDL(b) & SR_INT)
2140  {
2141  number x=a;
2142  a=b;
2143  b=x;
2144  }
2145  if (SR_HDL(a) & SR_INT)
2146  {
2147  u->s=b->s;
2148  if (u->s==1) u->s=0;
2149  if ((long)a>0L)
2150  {
2151  mpz_mul_ui(u->z,b->z,(unsigned long)SR_TO_INT(a));
2152  }
2153  else
2154  {
2155  if (a==INT_TO_SR(-1))
2156  {
2157  mpz_set(u->z,b->z);
2158  mpz_neg(u->z,u->z);
2159  u->s=b->s;
2160  }
2161  else
2162  {
2163  mpz_mul_ui(u->z,b->z,(unsigned long)-SR_TO_INT(a));
2164  mpz_neg(u->z,u->z);
2165  }
2166  }
2167  if (u->s<2)
2168  {
2169  if (mpz_cmp(u->z,b->n)==0)
2170  {
2171  mpz_clear(u->z);
2172  FREE_RNUMBER(u);
2173  return INT_TO_SR(1);
2174  }
2175  mpz_init_set(u->n,b->n);
2176  }
2177  else //u->s==3
2178  {
2179  u=nlShort3(u);
2180  }
2181  }
2182  else
2183  {
2184  mpz_mul(u->z,a->z,b->z);
2185  u->s = 0;
2186  if(a->s==3)
2187  {
2188  if(b->s==3)
2189  {
2190  u->s = 3;
2191  }
2192  else
2193  {
2194  if (mpz_cmp(u->z,b->n)==0)
2195  {
2196  mpz_clear(u->z);
2197  FREE_RNUMBER(u);
2198  return INT_TO_SR(1);
2199  }
2200  mpz_init_set(u->n,b->n);
2201  }
2202  }
2203  else
2204  {
2205  if(b->s==3)
2206  {
2207  if (mpz_cmp(u->z,a->n)==0)
2208  {
2209  mpz_clear(u->z);
2210  FREE_RNUMBER(u);
2211  return INT_TO_SR(1);
2212  }
2213  mpz_init_set(u->n,a->n);
2214  }
2215  else
2216  {
2217  mpz_init(u->n);
2218  mpz_mul(u->n,a->n,b->n);
2219  if (mpz_cmp(u->z,u->n)==0)
2220  {
2221  mpz_clear(u->z);
2222  mpz_clear(u->n);
2223  FREE_RNUMBER(u);
2224  return INT_TO_SR(1);
2225  }
2226  }
2227  }
2228  }
2229  return u;
2230 }
2231 
2232 /*2
2233 * copy a to b for mapping
2234 */
2235 number nlCopyMap(number a, const coeffs src, const coeffs dst)
2236 {
2237  if ((SR_HDL(a) & SR_INT)||(a==NULL))
2238  {
2239  return a;
2240  }
2241  return _nlCopy_NoImm(a);
2242 }
2243 
2244 nMapFunc nlSetMap(const coeffs src, const coeffs dst)
2245 {
2246  if (src->rep==n_rep_gap_rat) /*Q, coeffs_BIGINT */
2247  {
2248  return ndCopyMap;
2249  }
2250  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
2251  {
2252  return nlMapP;
2253  }
2254  if ((src->rep==n_rep_float) && nCoeff_is_R(src))
2255  {
2256  return nlMapR;
2257  }
2258  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
2259  {
2260  return nlMapLongR; /* long R -> Q */
2261  }
2262 #ifdef HAVE_RINGS
2263  if (src->rep==n_rep_gmp) // nCoeff_is_Ring_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Ring_ModN(src))
2264  {
2265  return nlMapGMP;
2266  }
2267  if (src->rep==n_rep_gap_gmp)
2268  {
2269  return nlMapZ;
2270  }
2271  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
2272  {
2273  return nlMapMachineInt;
2274  }
2275 #endif
2276  return NULL;
2277 }
2278 /*2
2279 * z := i
2280 */
2281 number nlRInit (long i)
2282 {
2283  number z=ALLOC_RNUMBER();
2284 #if defined(LDEBUG)
2285  z->debug=123456;
2286 #endif
2287  mpz_init_set_si(z->z,i);
2288  z->s = 3;
2289  return z;
2290 }
2291 
2292 /*2
2293 * z := i/j
2294 */
2295 number nlInit2 (int i, int j, const coeffs r)
2296 {
2297  number z=ALLOC_RNUMBER();
2298 #if defined(LDEBUG)
2299  z->debug=123456;
2300 #endif
2301  mpz_init_set_si(z->z,(long)i);
2302  mpz_init_set_si(z->n,(long)j);
2303  z->s = 0;
2304  nlNormalize(z,r);
2305  return z;
2306 }
2307 
2308 number nlInit2gmp (mpz_t i, mpz_t j, const coeffs r)
2309 {
2310  number z=ALLOC_RNUMBER();
2311 #if defined(LDEBUG)
2312  z->debug=123456;
2313 #endif
2314  mpz_init_set(z->z,i);
2315  mpz_init_set(z->n,j);
2316  z->s = 0;
2317  nlNormalize(z,r);
2318  return z;
2319 }
2320 
2321 #else // DO_LINLINE
2322 
2323 // declare immedate routines
2324 number nlRInit (long i);
2325 BOOLEAN _nlEqual_aNoImm_OR_bNoImm(number a, number b);
2326 number _nlCopy_NoImm(number a);
2327 number _nlNeg_NoImm(number a);
2328 number _nlAdd_aNoImm_OR_bNoImm(number a, number b);
2329 void _nlInpAdd_aNoImm_OR_bNoImm(number &a, number b);
2330 number _nlSub_aNoImm_OR_bNoImm(number a, number b);
2331 number _nlMult_aNoImm_OR_bNoImm(number a, number b);
2332 number _nlMult_aImm_bImm_rNoImm(number a, number b);
2333 
2334 #endif
2335 
2336 /***************************************************************
2337  *
2338  * Routines which might be inlined by p_Numbers.h
2339  *
2340  *******************************************************************/
2341 #if defined(DO_LINLINE) || !defined(P_NUMBERS_H)
2342 
2343 // routines which are always inlined/static
2344 
2345 /*2
2346 * a = b ?
2347 */
2348 LINLINE BOOLEAN nlEqual (number a, number b, const coeffs r)
2349 {
2350  nlTest(a, r);
2351  nlTest(b, r);
2352 // short - short
2353  if (SR_HDL(a) & SR_HDL(b) & SR_INT) return a==b;
2354  return _nlEqual_aNoImm_OR_bNoImm(a, b);
2355 }
2356 
2357 LINLINE number nlInit (long i, const coeffs r)
2358 {
2359  number n;
2360  #if MAX_NUM_SIZE == 60
2361  if (((i << 3) >> 3) == i) n=INT_TO_SR(i);
2362  else n=nlRInit(i);
2363  #else
2364  LONG ii=(LONG)i;
2365  if ( (((long)ii==i) && ((ii << 3) >> 3) == ii )) n=INT_TO_SR(ii);
2366  else n=nlRInit(i);
2367  #endif
2368  nlTest(n, r);
2369  return n;
2370 }
2371 
2372 /*2
2373 * a == 1 ?
2374 */
2375 LINLINE BOOLEAN nlIsOne (number a, const coeffs r)
2376 {
2377 #ifdef LDEBUG
2378  if (a==NULL) return FALSE;
2379  nlTest(a, r);
2380 #endif
2381  return (a==INT_TO_SR(1));
2382 }
2383 
2385 {
2386  #if 0
2387  if (a==INT_TO_SR(0)) return TRUE;
2388  if ((SR_HDL(a) & SR_INT)||(a==NULL)) return FALSE;
2389  if (mpz_cmp_si(a->z,(long)0)==0)
2390  {
2391  printf("gmp-0 in nlIsZero\n");
2392  dErrorBreak();
2393  return TRUE;
2394  }
2395  return FALSE;
2396  #else
2397  return (a==INT_TO_SR(0));
2398  #endif
2399 }
2400 
2401 /*2
2402 * copy a to b
2403 */
2404 LINLINE number nlCopy(number a, const coeffs)
2405 {
2406  if ((SR_HDL(a) & SR_INT)||(a==NULL))
2407  {
2408  return a;
2409  }
2410  return _nlCopy_NoImm(a);
2411 }
2412 
2413 
2414 /*2
2415 * delete a
2416 */
2417 LINLINE void nlDelete (number * a, const coeffs r)
2418 {
2419  if (*a!=NULL)
2420  {
2421  nlTest(*a, r);
2422  if ((SR_HDL(*a) & SR_INT)==0)
2423  {
2424  _nlDelete_NoImm(a);
2425  }
2426  *a=NULL;
2427  }
2428 }
2429 
2430 /*2
2431 * za:= - za
2432 */
2433 LINLINE number nlNeg (number a, const coeffs R)
2434 {
2435  nlTest(a, R);
2436  if(SR_HDL(a) &SR_INT)
2437  {
2438  LONG r=SR_TO_INT(a);
2439  if (r==(-(POW_2_28))) a=nlRInit(POW_2_28);
2440  else a=INT_TO_SR(-r);
2441  return a;
2442  }
2443  a = _nlNeg_NoImm(a);
2444  nlTest(a, R);
2445  return a;
2446 
2447 }
2448 
2449 /*2
2450 * u:= a + b
2451 */
2452 LINLINE number nlAdd (number a, number b, const coeffs R)
2453 {
2454  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2455  {
2456  LONG r=SR_HDL(a)+SR_HDL(b)-1L;
2457  if ( ((r << 1) >> 1) == r )
2458  return (number)(long)r;
2459  else
2460  return nlRInit(SR_TO_INT(r));
2461  }
2462  number u = _nlAdd_aNoImm_OR_bNoImm(a, b);
2463  nlTest(u, R);
2464  return u;
2465 }
2466 
2467 number nlShort1(number a);
2468 number nlShort3_noinline(number x);
2469 
2470 LINLINE void nlInpAdd(number &a, number b, const coeffs r)
2471 {
2472  // a=a+b
2473  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2474  {
2475  LONG r=SR_HDL(a)+SR_HDL(b)-1L;
2476  if ( ((r << 1) >> 1) == r )
2477  a=(number)(long)r;
2478  else
2479  a=nlRInit(SR_TO_INT(r));
2480  }
2481  else
2482  {
2484  nlTest(a,r);
2485  }
2486 }
2487 
2488 LINLINE number nlMult (number a, number b, const coeffs R)
2489 {
2490  nlTest(a, R);
2491  nlTest(b, R);
2492  if (a==INT_TO_SR(0)) return INT_TO_SR(0);
2493  if (b==INT_TO_SR(0)) return INT_TO_SR(0);
2494  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2495  {
2496  LONG r=(LONG)((unsigned LONG)(SR_HDL(a)-1L))*((unsigned LONG)(SR_HDL(b)>>1));
2497  if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1L))
2498  {
2499  number u=((number) ((r>>1)+SR_INT));
2500  if (((((LONG)SR_HDL(u))<<1)>>1)==SR_HDL(u)) return (u);
2501  return nlRInit(SR_HDL(u)>>2);
2502  }
2503  number u = _nlMult_aImm_bImm_rNoImm(a, b);
2504  nlTest(u, R);
2505  return u;
2506 
2507  }
2508  number u = _nlMult_aNoImm_OR_bNoImm(a, b);
2509  nlTest(u, R);
2510  return u;
2511 
2512 }
2513 
2514 
2515 /*2
2516 * u:= a - b
2517 */
2518 LINLINE number nlSub (number a, number b, const coeffs r)
2519 {
2520  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2521  {
2522  LONG r=SR_HDL(a)-SR_HDL(b)+1;
2523  if ( ((r << 1) >> 1) == r )
2524  {
2525  return (number)(long)r;
2526  }
2527  else
2528  return nlRInit(SR_TO_INT(r));
2529  }
2530  number u = _nlSub_aNoImm_OR_bNoImm(a, b);
2531  nlTest(u, r);
2532  return u;
2533 
2534 }
2535 
2536 LINLINE void nlInpMult(number &a, number b, const coeffs r)
2537 {
2538  number aa=a;
2539  if (((SR_HDL(b)|SR_HDL(aa))&SR_INT))
2540  {
2541  number n=nlMult(aa,b,r);
2542  nlDelete(&a,r);
2543  a=n;
2544  }
2545  else
2546  {
2547  mpz_mul(aa->z,a->z,b->z);
2548  if (aa->s==3)
2549  {
2550  if(b->s!=3)
2551  {
2552  mpz_init_set(a->n,b->n);
2553  a->s=0;
2554  }
2555  }
2556  else
2557  {
2558  if(b->s!=3)
2559  {
2560  mpz_mul(a->n,a->n,b->n);
2561  }
2562  a->s=0;
2563  }
2564  }
2565 }
2566 #endif // DO_LINLINE
2567 
2568 #ifndef P_NUMBERS_H
2569 
2570 static void nlMPZ(mpz_t m, number &n, const coeffs r)
2571 {
2572  nlTest(n, r);
2573  nlNormalize(n, r);
2574  if (SR_HDL(n) & SR_INT) mpz_init_set_si(m, SR_TO_INT(n)); /* n fits in an int */
2575  else mpz_init_set(m, (mpz_ptr)n->z);
2576 }
2577 
2578 
2579 static number nlInitMPZ(mpz_t m, const coeffs)
2580 {
2581  number z = ALLOC_RNUMBER();
2582  mpz_init_set(z->z, m);
2583  z->s = 3;
2584  return z;
2585 }
2586 
2587 
2588 void nlInpGcd(number &a, number b, const coeffs r)
2589 {
2590  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2591  {
2592  number n=nlGcd(a,b,r);
2593  nlDelete(&a,r);
2594  a=n;
2595  }
2596  else
2597  {
2598  mpz_gcd(a->z,a->z,b->z);
2599  a=nlShort3_noinline(a);
2600  }
2601 }
2602 
2603 void nlInpIntDiv(number &a, number b, const coeffs r)
2604 {
2605  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2606  {
2607  number n=nlIntDiv(a,b, r);
2608  nlDelete(&a,r);
2609  a=n;
2610  }
2611  else
2612  {
2613  if (mpz_isNeg(a->z))
2614  {
2615  if (mpz_isNeg(b->z))
2616  {
2617  mpz_add(a->z,a->z,b->z);
2618  }
2619  else
2620  {
2621  mpz_sub(a->z,a->z,b->z);
2622  }
2623  mpz_add_ui(a->z,a->z,1);
2624  }
2625  else
2626  {
2627  if (mpz_isNeg(b->z))
2628  {
2629  mpz_sub(a->z,a->z,b->z);
2630  }
2631  else
2632  {
2633  mpz_add(a->z,a->z,b->z);
2634  }
2635  mpz_sub_ui(a->z,a->z,1);
2636  }
2637  MPZ_DIV(a->z,a->z,b->z);
2638  a=nlShort3_noinline(a);
2639  }
2640 }
2641 
2642 number nlFarey(number nN, number nP, const coeffs r)
2643 {
2644  mpz_t tmp; mpz_init(tmp);
2645  mpz_t A,B,C,D,E,N,P;
2646  if (SR_HDL(nN) & SR_INT) mpz_init_set_si(N,SR_TO_INT(nN));
2647  else mpz_init_set(N,nN->z);
2648  if (SR_HDL(nP) & SR_INT) mpz_init_set_si(P,SR_TO_INT(nP));
2649  else mpz_init_set(P,nP->z);
2650  assume(!mpz_isNeg(P));
2651  if (mpz_isNeg(N)) mpz_add(N,N,P);
2652  mpz_init_set_si(A,(long)0);
2653  mpz_init_set_ui(B,(unsigned long)1);
2654  mpz_init_set_si(C,(long)0);
2655  mpz_init(D);
2656  mpz_init_set(E,P);
2657  number z=INT_TO_SR(0);
2658  while(mpz_cmp_si(N,(long)0)!=0)
2659  {
2660  mpz_mul(tmp,N,N);
2661  mpz_add(tmp,tmp,tmp);
2662  if (mpz_cmp(tmp,P)<0)
2663  {
2664  if (mpz_isNeg(B))
2665  {
2666  mpz_neg(B,B);
2667  mpz_neg(N,N);
2668  }
2669  // check for gcd(N,B)==1
2670  mpz_gcd(tmp,N,B);
2671  if (mpz_cmp_ui(tmp,1)==0)
2672  {
2673  // return N/B
2674  z=ALLOC_RNUMBER();
2675  #ifdef LDEBUG
2676  z->debug=123456;
2677  #endif
2678  mpz_init_set(z->z,N);
2679  mpz_init_set(z->n,B);
2680  z->s = 0;
2681  nlNormalize(z,r);
2682  }
2683  else
2684  {
2685  // return nN (the input) instead of "fail"
2686  z=nlCopy(nN,r);
2687  }
2688  break;
2689  }
2690  //mpz_mod(D,E,N);
2691  //mpz_div(tmp,E,N);
2692  mpz_divmod(tmp,D,E,N);
2693  mpz_mul(tmp,tmp,B);
2694  mpz_sub(C,A,tmp);
2695  mpz_set(E,N);
2696  mpz_set(N,D);
2697  mpz_set(A,B);
2698  mpz_set(B,C);
2699  }
2700  mpz_clear(tmp);
2701  mpz_clear(A);
2702  mpz_clear(B);
2703  mpz_clear(C);
2704  mpz_clear(D);
2705  mpz_clear(E);
2706  mpz_clear(N);
2707  mpz_clear(P);
2708  return z;
2709 }
2710 
2711 number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
2712 {
2713  mpz_t aa,bb;
2714  *s=ALLOC_RNUMBER();
2715  mpz_init((*s)->z); (*s)->s=3;
2716  (*t)=ALLOC_RNUMBER();
2717  mpz_init((*t)->z); (*t)->s=3;
2718  number g=ALLOC_RNUMBER();
2719  mpz_init(g->z); g->s=3;
2720  if (SR_HDL(a) & SR_INT)
2721  {
2722  mpz_init_set_si(aa,SR_TO_INT(a));
2723  }
2724  else
2725  {
2726  mpz_init_set(aa,a->z);
2727  }
2728  if (SR_HDL(b) & SR_INT)
2729  {
2730  mpz_init_set_si(bb,SR_TO_INT(b));
2731  }
2732  else
2733  {
2734  mpz_init_set(bb,b->z);
2735  }
2736  mpz_gcdext(g->z,(*s)->z,(*t)->z,aa,bb);
2737  mpz_clear(aa);
2738  mpz_clear(bb);
2739  (*s)=nlShort3((*s));
2740  (*t)=nlShort3((*t));
2741  g=nlShort3(g);
2742  return g;
2743 }
2744 
2745 void nlCoeffWrite (const coeffs r, BOOLEAN /*details*/)
2746 {
2747  if (r->is_field)
2748  PrintS("// characteristic : 0\n");
2749  else
2750  PrintS("// coeff. ring is : Integers\n");
2751 }
2752 
2754 number nlChineseRemainderSym(number *x, number *q,int rl, BOOLEAN sym, CFArray &inv_cache,const coeffs CF)
2755 // elemenst in the array are x[0..(rl-1)], q[0..(rl-1)]
2756 {
2757  setCharacteristic( 0 ); // only in char 0
2758  Off(SW_RATIONAL);
2759  CFArray X(rl), Q(rl);
2760  int i;
2761  for(i=rl-1;i>=0;i--)
2762  {
2763  X[i]=CF->convSingNFactoryN(x[i],FALSE,CF); // may be larger MAX_INT
2764  Q[i]=CF->convSingNFactoryN(q[i],FALSE,CF); // may be larger MAX_INT
2765  }
2766  CanonicalForm xnew,qnew;
2767  if (n_SwitchChinRem)
2768  chineseRemainder(X,Q,xnew,qnew);
2769  else
2770  chineseRemainderCached(X,Q,xnew,qnew,inv_cache);
2771  number n=CF->convFactoryNSingN(xnew,CF);
2772  if (sym)
2773  {
2774  number p=CF->convFactoryNSingN(qnew,CF);
2775  number p2=nlIntDiv(p,nlInit(2, CF),CF);
2776  if (nlGreater(n,p2,CF))
2777  {
2778  number n2=nlSub(n,p,CF);
2779  nlDelete(&n,CF);
2780  n=n2;
2781  }
2782  nlDelete(&p2,CF);
2783  nlDelete(&p,CF);
2784  }
2785  nlNormalize(n,CF);
2786  return n;
2787 }
2788 number nlChineseRemainder(number *x, number *q,int rl, const coeffs C)
2789 {
2790  CFArray inv(rl);
2791  return nlChineseRemainderSym(x,q,rl,TRUE,inv,C);
2792 }
2793 
2794 static void nlClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
2795 {
2796  assume(cf != NULL);
2797 
2798  numberCollectionEnumerator.Reset();
2799 
2800  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
2801  {
2802  c = nlInit(1, cf);
2803  return;
2804  }
2805 
2806  // all coeffs are given by integers!!!
2807 
2808  // part 1, find a small candidate for gcd
2809  number cand1,cand;
2810  int s1,s;
2811  s=2147483647; // max. int
2812 
2813  const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
2814 
2815  int normalcount = 0;
2816  do
2817  {
2818  number& n = numberCollectionEnumerator.Current();
2819  nlNormalize(n, cf); ++normalcount;
2820  cand1 = n;
2821 
2822  if (SR_HDL(cand1)&SR_INT) { cand=cand1; break; }
2823  assume(cand1->s==3); // all coeffs should be integers // ==0?!! after printing
2824  s1=mpz_size1(cand1->z);
2825  if (s>s1)
2826  {
2827  cand=cand1;
2828  s=s1;
2829  }
2830  } while (numberCollectionEnumerator.MoveNext() );
2831 
2832 // assume( nlGreaterZero(cand,cf) ); // cand may be a negative integer!
2833 
2834  cand=nlCopy(cand,cf);
2835  // part 2: compute gcd(cand,all coeffs)
2836 
2837  numberCollectionEnumerator.Reset();
2838 
2839  while (numberCollectionEnumerator.MoveNext() )
2840  {
2841  number& n = numberCollectionEnumerator.Current();
2842 
2843  if( (--normalcount) <= 0)
2844  nlNormalize(n, cf);
2845 
2846  nlInpGcd(cand, n, cf);
2847  assume( nlGreaterZero(cand,cf) );
2848 
2849  if(nlIsOne(cand,cf))
2850  {
2851  c = cand;
2852 
2853  if(!lc_is_pos)
2854  {
2855  // make the leading coeff positive
2856  c = nlNeg(c, cf);
2857  numberCollectionEnumerator.Reset();
2858 
2859  while (numberCollectionEnumerator.MoveNext() )
2860  {
2861  number& nn = numberCollectionEnumerator.Current();
2862  nn = nlNeg(nn, cf);
2863  }
2864  }
2865  return;
2866  }
2867  }
2868 
2869  // part3: all coeffs = all coeffs / cand
2870  if (!lc_is_pos)
2871  cand = nlNeg(cand,cf);
2872 
2873  c = cand;
2874  numberCollectionEnumerator.Reset();
2875 
2876  while (numberCollectionEnumerator.MoveNext() )
2877  {
2878  number& n = numberCollectionEnumerator.Current();
2879  number t=nlIntDiv(n, cand, cf); // simple integer exact division, no ratios to remain
2880  nlDelete(&n, cf);
2881  n = t;
2882  }
2883 }
2884 
2885 static void nlClearDenominators(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
2886 {
2887  assume(cf != NULL);
2888 
2889  numberCollectionEnumerator.Reset();
2890 
2891  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
2892  {
2893  c = nlInit(1, cf);
2894 // assume( n_GreaterZero(c, cf) );
2895  return;
2896  }
2897 
2898  // all coeffs are given by integers after returning from this routine
2899 
2900  // part 1, collect product of all denominators /gcds
2901  number cand;
2902  cand=ALLOC_RNUMBER();
2903 #if defined(LDEBUG)
2904  cand->debug=123456;
2905 #endif
2906  cand->s=3;
2907 
2908  int s=0;
2909 
2910  const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
2911 
2912  do
2913  {
2914  number& cand1 = numberCollectionEnumerator.Current();
2915 
2916  if (!(SR_HDL(cand1)&SR_INT))
2917  {
2918  nlNormalize(cand1, cf);
2919  if ((!(SR_HDL(cand1)&SR_INT)) // not a short int
2920  && (cand1->s==1)) // and is a normalised rational
2921  {
2922  if (s==0) // first denom, we meet
2923  {
2924  mpz_init_set(cand->z, cand1->n); // cand->z = cand1->n
2925  s=1;
2926  }
2927  else // we have already something
2928  {
2929  mpz_lcm(cand->z, cand->z, cand1->n);
2930  }
2931  }
2932  }
2933  }
2934  while (numberCollectionEnumerator.MoveNext() );
2935 
2936 
2937  if (s==0) // nothing to do, all coeffs are already integers
2938  {
2939 // mpz_clear(tmp);
2940  FREE_RNUMBER(cand);
2941  if (lc_is_pos)
2942  c=nlInit(1,cf);
2943  else
2944  {
2945  // make the leading coeff positive
2946  c=nlInit(-1,cf);
2947 
2948  // TODO: incorporate the following into the loop below?
2949  numberCollectionEnumerator.Reset();
2950  while (numberCollectionEnumerator.MoveNext() )
2951  {
2952  number& n = numberCollectionEnumerator.Current();
2953  n = nlNeg(n, cf);
2954  }
2955  }
2956 // assume( n_GreaterZero(c, cf) );
2957  return;
2958  }
2959 
2960  cand = nlShort3(cand);
2961 
2962  // part2: all coeffs = all coeffs * cand
2963  // make the lead coeff positive
2964  numberCollectionEnumerator.Reset();
2965 
2966  if (!lc_is_pos)
2967  cand = nlNeg(cand, cf);
2968 
2969  c = cand;
2970 
2971  while (numberCollectionEnumerator.MoveNext() )
2972  {
2973  number &n = numberCollectionEnumerator.Current();
2974  nlInpMult(n, cand, cf);
2975  }
2976 
2977 }
2978 
2979 char * nlCoeffName(const coeffs r)
2980 {
2981  if (r->cfDiv==nlDiv) return (char*)"QQ";
2982  else return (char*)"ZZ";
2983 }
2984 
2985 static char* nlCoeffString(const coeffs r)
2986 {
2987  //return omStrDup(nlCoeffName(r));
2988  if (r->cfDiv==nlDiv) return omStrDup("0");
2989  else return omStrDup("integer");
2990 }
2991 
2992 #define SSI_BASE 16
2993 
2994 static void nlWriteFd(number n,FILE* f, const coeffs)
2995 {
2996  if(SR_HDL(n) & SR_INT)
2997  {
2998  #if SIZEOF_LONG == 4
2999  fprintf(f,"4 %ld ",SR_TO_INT(n));
3000  #else
3001  long nn=SR_TO_INT(n);
3002  if ((nn<POW_2_28_32)&&(nn>= -POW_2_28_32))
3003  {
3004  int nnn=(int)nn;
3005  fprintf(f,"4 %d ",nnn);
3006  }
3007  else
3008  {
3009  mpz_t tmp;
3010  mpz_init_set_si(tmp,nn);
3011  fputs("8 ",f);
3012  mpz_out_str (f,SSI_BASE, tmp);
3013  fputc(' ',f);
3014  mpz_clear(tmp);
3015  }
3016  #endif
3017  }
3018  else if (n->s<2)
3019  {
3020  //gmp_fprintf(f,"%d %Zd %Zd ",n->s,n->z,n->n);
3021  fprintf(f,"%d ",n->s+5);
3022  mpz_out_str (f,SSI_BASE, n->z);
3023  fputc(' ',f);
3024  mpz_out_str (f,SSI_BASE, n->n);
3025  fputc(' ',f);
3026 
3027  //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: s=%d gmp/gmp \"%Zd %Zd\" ",n->s,n->z,n->n);
3028  }
3029  else /*n->s==3*/
3030  {
3031  //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
3032  fputs("8 ",f);
3033  mpz_out_str (f,SSI_BASE, n->z);
3034  fputc(' ',f);
3035 
3036  //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: gmp \"%Zd\" ",n->z);
3037  }
3038 }
3039 
3040 static number nlReadFd(s_buff f, const coeffs)
3041 {
3042  int sub_type=-1;
3043  sub_type=s_readint(f);
3044  switch(sub_type)
3045  {
3046  case 0:
3047  case 1:
3048  {// read mpz_t, mpz_t
3049  number n=nlRInit(0);
3050  mpz_init(n->n);
3051  s_readmpz(f,n->z);
3052  s_readmpz(f,n->n);
3053  n->s=sub_type;
3054  return n;
3055  }
3056 
3057  case 3:
3058  {// read mpz_t
3059  number n=nlRInit(0);
3060  s_readmpz(f,n->z);
3061  n->s=3; /*sub_type*/
3062  #if SIZEOF_LONG == 8
3063  n=nlShort3(n);
3064  #endif
3065  return n;
3066  }
3067  case 4:
3068  {
3069  LONG dd=s_readlong(f);
3070  //#if SIZEOF_LONG == 8
3071  return INT_TO_SR(dd);
3072  //#else
3073  //return nlInit(dd,NULL);
3074  //#endif
3075  }
3076  case 5:
3077  case 6:
3078  {// read raw mpz_t, mpz_t
3079  number n=nlRInit(0);
3080  mpz_init(n->n);
3081  s_readmpz_base (f,n->z, SSI_BASE);
3082  s_readmpz_base (f,n->n, SSI_BASE);
3083  n->s=sub_type-5;
3084  return n;
3085  }
3086  case 8:
3087  {// read raw mpz_t
3088  number n=nlRInit(0);
3089  s_readmpz_base (f,n->z, SSI_BASE);
3090  n->s=sub_type=3; /*subtype-5*/
3091  #if SIZEOF_LONG == 8
3092  n=nlShort3(n);
3093  #endif
3094  return n;
3095  }
3096 
3097  default: Werror("error in reading number: invalid subtype %d",sub_type);
3098  return NULL;
3099  }
3100  return NULL;
3101 }
3103 {
3104  /* test, if r is an instance of nInitCoeffs(n,parameter) */
3105  /* if parameter is not needed */
3106  if (n==r->type)
3107  {
3108  if ((p==NULL)&&(r->cfDiv==nlDiv)) return TRUE;
3109  if ((p!=NULL)&&(r->cfDiv!=nlDiv)) return TRUE;
3110  }
3111  return FALSE;
3112 }
3113 
3114 static number nlLcm(number a,number b,const coeffs r)
3115 {
3116  number g=nlGcd(a,b,r);
3117  number n1=nlMult(a,b,r);
3118  number n2=nlDiv(n1,g,r);
3119  nlDelete(&g,r);
3120  nlDelete(&n1,r);
3121  return n2;
3122 }
3123 
3124 static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
3125 {
3126  number a=nlInit(p(),cf);
3127  if (v2!=NULL)
3128  {
3129  number b=nlInit(p(),cf);
3130  number c=nlDiv(a,b,cf);
3131  nlDelete(&b,cf);
3132  nlDelete(&a,cf);
3133  a=c;
3134  }
3135  return a;
3136 }
3137 
3139 {
3140  r->is_domain=TRUE;
3141  r->rep=n_rep_gap_rat;
3142 
3143  //const int ch = (int)(long)(p);
3144 
3145  r->nCoeffIsEqual=nlCoeffIsEqual;
3146  //r->cfKillChar = ndKillChar; /* dummy */
3147  r->cfCoeffString=nlCoeffString;
3148  r->cfCoeffName=nlCoeffName;
3149 
3150  r->cfInitMPZ = nlInitMPZ;
3151  r->cfMPZ = nlMPZ;
3152 
3153  r->cfMult = nlMult;
3154  r->cfSub = nlSub;
3155  r->cfAdd = nlAdd;
3156  if (p==NULL) /* Q */
3157  {
3158  r->is_field=TRUE;
3159  r->cfDiv = nlDiv;
3160  //r->cfGcd = ndGcd_dummy;
3161  r->cfSubringGcd = nlGcd;
3162  }
3163  else /* Z: coeffs_BIGINT */
3164  {
3165  r->is_field=FALSE;
3166  r->cfDiv = nlIntDiv;
3167  r->cfIntMod= nlIntMod;
3168  r->cfGcd = nlGcd;
3169  r->cfDivBy=nlDivBy;
3170  r->cfDivComp = nlDivComp;
3171  r->cfIsUnit = nlIsUnit;
3172  r->cfGetUnit = nlGetUnit;
3173  r->cfQuot1 = nlQuot1;
3174  r->cfLcm = nlLcm;
3175  }
3176  r->cfExactDiv= nlExactDiv;
3177  r->cfInit = nlInit;
3178  r->cfSize = nlSize;
3179  r->cfInt = nlInt;
3180 
3181  r->cfChineseRemainder=nlChineseRemainderSym;
3182  r->cfFarey=nlFarey;
3183  r->cfInpNeg = nlNeg;
3184  r->cfInvers= nlInvers;
3185  r->cfCopy = nlCopy;
3186  r->cfRePart = nlCopy;
3187  //r->cfImPart = ndReturn0;
3188  r->cfWriteLong = nlWrite;
3189  r->cfRead = nlRead;
3190  r->cfNormalize=nlNormalize;
3191  r->cfGreater = nlGreater;
3192  r->cfEqual = nlEqual;
3193  r->cfIsZero = nlIsZero;
3194  r->cfIsOne = nlIsOne;
3195  r->cfIsMOne = nlIsMOne;
3196  r->cfGreaterZero = nlGreaterZero;
3197  r->cfPower = nlPower;
3198  r->cfGetDenom = nlGetDenom;
3199  r->cfGetNumerator = nlGetNumerator;
3200  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3201  r->cfNormalizeHelper = nlNormalizeHelper;
3202  r->cfDelete= nlDelete;
3203  r->cfSetMap = nlSetMap;
3204  //r->cfName = ndName;
3205  r->cfInpMult=nlInpMult;
3206  r->cfInpAdd=nlInpAdd;
3207  r->cfCoeffWrite=nlCoeffWrite;
3208 
3209  r->cfClearContent = nlClearContent;
3210  r->cfClearDenominators = nlClearDenominators;
3211 
3212 #ifdef LDEBUG
3213  // debug stuff
3214  r->cfDBTest=nlDBTest;
3215 #endif
3216  r->convSingNFactoryN=nlConvSingNFactoryN;
3217  r->convFactoryNSingN=nlConvFactoryNSingN;
3218 
3219  r->cfRandom=nlRandom;
3220 
3221  // io via ssi
3222  r->cfWriteFd=nlWriteFd;
3223  r->cfReadFd=nlReadFd;
3224 
3225  // the variables: general stuff (required)
3226  r->nNULL = INT_TO_SR(0);
3227  //r->type = n_Q;
3228  r->ch = 0;
3229  r->has_simple_Alloc=FALSE;
3230  r->has_simple_Inverse=FALSE;
3231 
3232  // variables for this type of coeffs:
3233  // (none)
3234  return FALSE;
3235 }
3236 #if 0
3237 number nlMod(number a, number b)
3238 {
3239  if (((SR_HDL(b)&SR_HDL(a))&SR_INT)
3240  {
3241  int bi=SR_TO_INT(b);
3242  int ai=SR_TO_INT(a);
3243  int bb=ABS(bi);
3244  int c=ai%bb;
3245  if (c<0) c+=bb;
3246  return (INT_TO_SR(c));
3247  }
3248  number al;
3249  number bl;
3250  if (SR_HDL(a))&SR_INT)
3251  al=nlRInit(SR_TO_INT(a));
3252  else
3253  al=nlCopy(a);
3254  if (SR_HDL(b))&SR_INT)
3255  bl=nlRInit(SR_TO_INT(b));
3256  else
3257  bl=nlCopy(b);
3258  number r=nlRInit(0);
3259  mpz_mod(r->z,al->z,bl->z);
3260  nlDelete(&al);
3261  nlDelete(&bl);
3262  if (mpz_size1(&r->z)<=MP_SMALL)
3263  {
3264  LONG ui=(int)mpz_get_si(&r->z);
3265  if ((((ui<<3)>>3)==ui)
3266  && (mpz_cmp_si(x->z,(long)ui)==0))
3267  {
3268  mpz_clear(&r->z);
3269  FREE_RNUMBER(r); // omFreeBin((void *)r, rnumber_bin);
3270  r=INT_TO_SR(ui);
3271  }
3272  }
3273  return r;
3274 }
3275 #endif
3276 #endif // not P_NUMBERS_H
3277 #endif // LONGRAT_CC
mpz_ptr base
Definition: rmodulon.h:18
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20
mpz_t z
Definition: longrat.h:48
number nlGetUnit(number n, const coeffs r)
Definition: longrat.cc:936
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2518
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2885
#define MPZ_EXACTDIV(A, B, C)
Definition: longrat.cc:163
const CanonicalForm int s
Definition: facAbsFact.cc:55
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:181
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327
#define D(A)
Definition: gentable.cc:119
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: longrat.cc:3102
#define Print
Definition: emacs.cc:83
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:43
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:818
char * nlCoeffName(const coeffs r)
Definition: longrat.cc:2979
void Off(int sw)
switches
CanonicalForm num(const CanonicalForm &f)
long npInt(number &n, const coeffs r)
Definition: modulop.cc:143
Definition: int_poly.h:36
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition: longrat.cc:380
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1141
#define FALSE
Definition: auxiliary.h:140
static void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2570
mpf_t * _mpfp()
Definition: mpr_complex.h:134
return P p
Definition: myNF.cc:203
number _nlMult_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:2131
f
Definition: cfModGcd.cc:4022
number nlShort1(number x)
Definition: longrat.cc:1256
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition: longrat.cc:1321
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:239
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:892
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2470
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1431
void nlWrite(number a, const coeffs r)
Definition: longrat0.cc:117
int nlSize(number a, const coeffs)
Definition: longrat.cc:577
int n_SwitchChinRem
Definition: longrat.cc:2753
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:539
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:834
#define omCheckIf(cond, test)
Definition: omAllocDecl.h:323
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2452
{p < 2^31}
Definition: coeffs.h:30
void nlInpGcd(number &a, number b, const coeffs r)
Definition: longrat.cc:2588
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition: longrat.cc:1166
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:741
(), see rinteger.h, new impl.
Definition: coeffs.h:111
void nlCoeffWrite(const coeffs r, BOOLEAN details)
Definition: longrat.cc:2745
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:786
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:445
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1178
factory&#39;s main class
Definition: canonicalform.h:75
#define TRUE
Definition: auxiliary.h:144
coeffs nlQuot1(number c, const coeffs r)
Definition: longrat.cc:944
#define POW_2_28
Definition: longrat.cc:106
number nlRInit(long i)
Definition: longrat.cc:2281
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
number nlInit2(int i, int j, const coeffs r)
create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode ...
Definition: longrat.cc:2295
g
Definition: cfModGcd.cc:4031
const char * nlRead(const char *s, number *a, const coeffs r)
Definition: longrat0.cc:57
void WerrorS(const char *s)
Definition: feFopen.cc:24
bool negative(N n)
Definition: ValueTraits.h:119
void s_readmpz_base(s_buff F, mpz_ptr a, int base)
Definition: s_buff.cc:217
void nlGMP(number &i, number n, const coeffs r)
Definition: longrat.cc:1410
#define Q
Definition: sirandom.c:25
number nlIntMod(number a, number b, const coeffs r)
Definition: longrat.cc:852
#define POW_2_28_32
Definition: longrat.cc:107
number nlInit2gmp(mpz_t i, mpz_t j, const coeffs r)
create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode ...
Definition: longrat.cc:2308
#define WarnS
Definition: emacs.cc:81
BOOLEAN nlInitChar(coeffs r, void *p)
Definition: longrat.cc:3138
long intval() const
conversion functions
#define omAlloc(size)
Definition: omAllocDecl.h:210
void setCharacteristic(int c)
Definition: cf_char.cc:23
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1151
LINLINE number nl_Copy(number a, const coeffs r)
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2579
CF_NO_INLINE bool isOne() const
CF_INLINE bool CanonicalForm::isOne, isZero () const.
Definition: cf_inline.cc:354
real floating point (GMP) numbers
Definition: coeffs.h:34
number nlMapZ(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:223
CanonicalForm make_cf(const mpz_ptr n)
Definition: singext.cc:67
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2375
poly res
Definition: myNF.cc:322
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection...
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define MP_SMALL
Definition: longrat.cc:157
static number nlLcm(number a, number b, const coeffs r)
Definition: longrat.cc:3114
clock_t to
Definition: walk.cc:100
mpz_t n
Definition: longrat.h:49
const ring r
Definition: syzextra.cc:208
static number nlMapP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:193
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2433
float nrFloat(number n)
Converts a n_R number into a float. Needed by Maps.
Definition: shortfl.cc:78
Coefficient rings, fields and other domains suitable for Singular polynomials.
void s_readmpz(s_buff F, mpz_t a)
Definition: s_buff.cc:192
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
int s_readint(s_buff F)
Definition: s_buff.cc:120
int j
Definition: myNF.cc:70
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:978
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2488
number nlInvers(number a, const coeffs r)
Definition: longrat.cc:656
number _nlCopy_NoImm(number a)
Definition: longrat.cc:1538
#define assume(x)
Definition: mod2.h:405
void _nlInpAdd_aNoImm_OR_bNoImm(number &a, number b)
Definition: longrat.cc:1755
The main handler for Singular numbers which are suitable for Singular polynomials.
Templated enumerator interface for simple iteration over a generic collection of T&#39;s.
Definition: Enumerator.h:124
int nlDivComp(number a, number b, const coeffs r)
Definition: longrat.cc:925
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2536
static void nlWriteFd(number n, FILE *f, const coeffs)
Definition: longrat.cc:2994
const ExtensionInfo & info
< [in] sqrfree poly
#define A
Definition: sirandom.c:23
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:72
const ring R
Definition: DebugPrint.cc:36
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1559
number nlModP(number q, const coeffs Q, const coeffs Zp)
Definition: longrat.cc:1368
virtual reference Current()=0
Gets the current element in the collection (read and write).
#define LINLINE
Definition: longrat.cc:26
static number nlMapLongR(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:435
number nlCopyMap(number a, const coeffs src, const coeffs dst)
Definition: longrat.cc:2235
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
All the auxiliary stuff.
int m
Definition: cfEzgcd.cc:119
#define mpz_isNeg(A)
Definition: longrat.cc:159
const char *const nDivBy0
Definition: numbers.h:83
void On(int sw)
switches
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2348
unsigned long exp
Definition: rmodulon.h:18
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition: longrat.cc:1088
CanonicalForm den() const
den() returns the denominator of CO if CO is a rational number, 1 (from the current domain!) otherwis...
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:294
static number nlReadFd(s_buff f, const coeffs)
Definition: longrat.cc:3040
void nlInpIntDiv(number &a, number b, const coeffs r)
Definition: longrat.cc:2603
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: longrat.cc:2711
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2384
int IsPrime(int p)
Definition: prime.cc:61
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:114
BOOLEAN _nlEqual_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:1491
number nlShort3_noinline(number x)
Definition: longrat.cc:174
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2794
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition: longrat.cc:342
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
int(* siRandProc)()
Definition: sirandom.h:9
number nlChineseRemainder(number *x, number *q, int rl, const coeffs C)
Definition: longrat.cc:2788
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
number nlBigInt(number &n)
void chineseRemainderCached(CFArray &a, CFArray &n, CanonicalForm &xnew, CanonicalForm &prod, CFArray &inv)
Definition: cf_chinese.cc:264
#define SR_TO_INT(SR)
Definition: longrat.h:67
(number), see longrat.h
Definition: coeffs.h:110
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
void chineseRemainder(const CanonicalForm &x1, const CanonicalForm &q1, const CanonicalForm &x2, const CanonicalForm &q2, CanonicalForm &xnew, CanonicalForm &qnew)
void chineseRemainder ( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2...
Definition: cf_chinese.cc:52
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2754
bool isImm() const
#define mpz_size1(A)
Definition: si_gmp.h:12
n_coeffType
Definition: coeffs.h:27
CanonicalForm cf
Definition: cfModGcd.cc:4024
number _nlNeg_NoImm(number a)
Definition: longrat.cc:1577
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition: longrat.cc:3124
void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
REvaluation E(1, terms.length(), IntRandom(25))
CanonicalForm den(const CanonicalForm &f)
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of &#39;a&#39; and &#39;b&#39;, i.e., a/b; raises an error if &#39;b&#39; is not invertible in r exceptio...
Definition: coeffs.h:615
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:911
(gmp_float), see
Definition: coeffs.h:116
b *CanonicalForm B
Definition: facBivar.cc:51
#define ABS(x)
Definition: auxiliary.h:157
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
int gcd(int a, int b)
Definition: walkSupport.cc:839
BOOLEAN nlIsUnit(number a, const coeffs)
Definition: longrat.cc:969
long nlInt(number &n, const coeffs r)
Definition: longrat.cc:606
#define SR_INT
Definition: longrat.h:65
number _nlMult_aImm_bImm_rNoImm(number a, number b)
Definition: longrat.cc:2118
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition: longrat.cc:2244
Variable x
Definition: cfModGcd.cc:4023
number _nlAdd_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:1589
long s_readlong(s_buff F)
Definition: s_buff.cc:148
number nlExactDiv(number a, number b, const coeffs r)
Definition: longrat.cc:735
number _nlSub_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:1894
number nlMapGMP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:210
BOOLEAN nlDBTest(number a, const char *f, const int l)
p exp[i]
Definition: DebugPrint.cc:39
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2357
#define MPZ_DIV(A, B, C)
Definition: longrat.cc:162
(int), see modulop.h
Definition: coeffs.h:109
#define SR_HDL(A)
Definition: tgb.cc:35
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
static char * nlCoeffString(const coeffs r)
Definition: longrat.cc:2985
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:456
number nlMapMachineInt(number from, const coeffs, const coeffs)
Definition: longrat.cc:235
kBucketDestroy & P
Definition: myNF.cc:191
int BOOLEAN
Definition: auxiliary.h:131
static number nlMapR(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:405
const poly b
Definition: syzextra.cc:213
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1460
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2404
void dErrorBreak()
Definition: dError.cc:141
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define LONG
Definition: longrat.cc:108
return result
Definition: facAbsBiFact.cc:76
int l
Definition: cfEzgcd.cc:94
#define ALLOC0_RNUMBER()
Definition: coeffs.h:87
#define SSI_BASE
Definition: longrat.cc:2992
#define nlTest(a, r)
Definition: longrat.cc:90
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
Definition: cfModGcd.cc:69
number nlFarey(number nN, number nP, const coeffs CF)
Definition: longrat.cc:2642
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:327
(float), see shortfl.h
Definition: coeffs.h:115
#define omStrDup(s)
Definition: omAllocDecl.h:263