My Project
Loading...
Searching...
No Matches
numbers.cc
Go to the documentation of this file.
1/*****************************************
2* Computer Algebra System SINGULAR *
3*****************************************/
4
5/*
6* ABSTRACT: interface to coefficient aritmetics
7*/
8
9#include <string.h>
10#include <stdlib.h>
11
12#include "misc/auxiliary.h"
13#include "misc/mylimits.h"
14#include "factory/factory.h"
15
16#include "reporter/reporter.h"
17
18#include "coeffs/coeffs.h"
19#include "coeffs/numbers.h"
20
21#include "coeffs/longrat.h"
22#include "coeffs/modulop.h"
23#include "coeffs/gnumpfl.h"
24#include "coeffs/gnumpc.h"
25#include "coeffs/ffields.h"
26#include "coeffs/shortfl.h"
27#include "coeffs/ntupel.h"
28#include "coeffs/flintcf_Qrat.h"
29
30#ifdef HAVE_RINGS
31#include "coeffs/rmodulo2m.h"
32#include "coeffs/rmodulon.h"
33#include "coeffs/rintegers.h"
34#endif
35
36#ifdef HAVE_POLYEXTENSIONS
39#endif
40
41
42//static int characteristic = 0;
43//extern int IsPrime(int p);
44
46
47static void ndDelete(number* d, const coeffs) { *d=NULL; }
48static number ndAnn(number, const coeffs cf) { WarnS("cfAnn undefined"); return n_Init(0,cf); }
49static char* ndCoeffString(const coeffs r)
50{
51 return omStrDup(r->cfCoeffName(r));
52}
53static void ndCoeffWrite(const coeffs r,BOOLEAN)
54{
55 PrintS(r->cfCoeffName(r));
56}
57static char* ndCoeffName(const coeffs r)
58{
59 STATIC_VAR char s[20];
60 snprintf(s,11,"Coeffs(%d)",r->type);
61 return s;
62}
63static void ndInpMult(number &a, number b, const coeffs r)
64{
65 number n=r->cfMult(a,b,r);
66 r->cfDelete(&a,r);
67 a=n;
68}
69static void ndInpAdd(number &a, number b, const coeffs r)
70{
71 number n=r->cfAdd(a,b,r);
72 r->cfDelete(&a,r);
73 a=n;
74}
75
76static void ndPower(number a, int i, number * res, const coeffs r)
77{
78 if (i==0)
79 {
80 *res = r->cfInit(1, r);
81 }
82 else if (i==1)
83 {
84 *res = r->cfCopy(a, r);
85 }
86 else if (i==2)
87 {
88 *res = r->cfMult(a, a, r);
89 }
90 else if (i<0)
91 {
92 number b = r->cfInvers(a, r);
93 ndPower(b, -i, res, r);
94 r->cfDelete(&b, r);
95 }
96 else
97 {
98 ndPower(a, i/2, res, r);
99 r->cfInpMult(*res, *res, r);
100 if (i&1)
101 {
102 r->cfInpMult(*res, a, r);
103 }
104 }
105}
106static number ndInvers(number a, const coeffs r)
107{
108 number one=r->cfInit(1,r);
109 number res=r->cfDiv(one,a,r);
110 r->cfDelete(&one,r);
111 return res;
112}
114{
115 if (!r->cfIsUnit(a,r)) Print("ndInvers_Ring used with non-unit\n");
116 number one=r->cfInit(1,r);
117 number res=r->cfDiv(one,a,r);
118 r->cfDelete(&one,r);
119 return res;
120}
121
123{ return r->cfIsOne(a,r)|| r->cfIsMOne(a,r); }
125{ return !r->cfIsZero(a,r); }
127{ return r->cfInit(1,r); }
129{ return cf->cfInit(p(),cf); }
131{ return cf->cfInit(cf->cfSize(a,cf),cf); }
132#ifdef LDEBUG
133// static void nDBDummy1(number* d,char *, int) { *d=NULL; }
134static BOOLEAN ndDBTest(number, const char *, const int, const coeffs){ return TRUE; }
135#endif
136
138{
139 Werror("farey not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
140 return n_Init(0,r);
141}
143{
144 Werror("XExtGcd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
145 return n_Init(0,r);
146}
148{
149 Werror("ChineseRemainder not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
150 return r->cfInit(0,r);
151}
152number ndReadFd( const ssiInfo *, const coeffs r)
153{
154 Warn("ReadFd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
155 return n_Init(0,r);
156}
157
158static void ndWriteFd(number, const ssiInfo *, const coeffs r)
159{
160 Warn("WriteFd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
161}
162
163static int ndParDeg(number n, const coeffs r)
164{
165 return (-r->cfIsZero(n,r));
166}
167
168static number ndParameter(const int, const coeffs r)
169{
170 return r->cfInit(1,r);
171}
172
174{
175 BOOLEAN ret = n_IsZero(a, r);
176 int c = n_GetChar(r);
177 if (ret || (c==0) || (r->is_field))
178 return ret; /*n_IsZero(a, r)*/
179 number ch = n_Init( c, r );
180 number g = n_Gcd( ch, a, r );
181 ret = !n_IsOne (g, r);
182 n_Delete(&ch, r);
183 n_Delete(&g, r);
184 return ret;
185}
186
187void ndNormalize(number&, const coeffs) { }
188static number ndReturn0(number, const coeffs r) { return r->cfInit(0,r); }
189number ndGcd(number, number, const coeffs r) { return r->cfInit(1,r); }
191{
192 if (R->is_field)
193 return R->cfInit(0,R);
194 else // implementation for a non-field:
195 {
196 number d=n_Div(a,b,R);
197 number p=n_Mult(b,d,R);
198 number r=n_Sub(a,p,R);
199 n_Delete(&p,R);
200 n_Delete(&d,R);
201 return r;
202 }
203}
204static number ndGetDenom(number &, const coeffs r) { return r->cfInit(1,r); }
205static number ndGetNumerator(number &a,const coeffs r) { return r->cfCopy(a,r); }
206static int ndSize(number a, const coeffs r) { return (int)r->cfIsZero(a,r)==FALSE; }
207
209{
210 assume(r != NULL);
211
212 // no fractions
213 assume(!( nCoeff_is_Q(r) ));
214 // all coeffs are given by integers!!!
215
217
218 if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
219 {
220 c = n_Init(1, r);
221 return;
222 }
223
224 number &curr = numberCollectionEnumerator.Current();
225
226#ifdef HAVE_RINGS
227 /// TODO: move to a separate implementation
228 if (nCoeff_is_Ring(r))
229 {
230 if (nCoeff_has_Units(r))
231 {
232 c = n_GetUnit(curr, r);
233
234 if (!n_IsOne(c, r))
235 {
236 number inv = n_Invers(c, r);
237
238 n_InpMult(curr, inv, r);
239
240 while( numberCollectionEnumerator.MoveNext() )
241 {
242 number &n = numberCollectionEnumerator.Current();
243 n_Normalize(n, r); // ?
244 n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
245 }
246
247 n_Delete(&inv, r);
248 }
249 } else c = n_Init(1, r);
250
251 return;
252 }
253#endif
254
257
258 n_Normalize(curr, r); // Q: good/bad/ugly??
259
260 if (!n_IsOne(curr, r))
261 {
262 number t = curr; // takes over the curr! note: not a reference!!!
263
264 curr = n_Init(1, r); // ???
265
266 number inv = n_Invers(t, r);
267
268 while( numberCollectionEnumerator.MoveNext() )
269 {
270 number &n = numberCollectionEnumerator.Current();
271 n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
272// n_Normalize(n, r); // ?
273 }
274
275 n_Delete(&inv, r);
276
277 c = t;
278 } else
279 c = n_Copy(curr, r); // c == 1 and nothing else to do...
280}
281
282static void ndClearDenominators(ICoeffsEnumerator& /*numberCollectionEnumerator*/, number& d, const coeffs r)
283{
284 assume( r != NULL );
287
288 d = n_Init(1, r);
289}
290
292{
293 // aRing and r need not be the same, but must be the same representation
294 assume(aRing->rep==r->rep);
296 return a;
297 else
298 return r->cfCopy(a, r);
299}
300
301static void ndKillChar(coeffs) {}
302static void ndSetChar(const coeffs) {}
303
304static number ndCopy(number a, const coeffs) { return a; }
305number nd_Copy(number a, const coeffs r) { return r->cfCopy(a, r); }
306
307#ifdef HAVE_RINGS
308static BOOLEAN ndDivBy(number, number, const coeffs) { return TRUE; } // assume a,b !=0
309static int ndDivComp(number, number, const coeffs) { return 2; }
310static number ndExtGcd (number, number, number *, number *, const coeffs r) { return r->cfInit(1,r); }
311#endif
312
314{
316 WerrorS("no conversion to factory");
317 return term;
318}
319
321{
322 WerrorS("no conversion from factory");
323 return n_Init(0,r);
324}
325
326/**< [in, out] a bigint number >= 0 */
327/**< [out] the GMP equivalent */
328/// Converts a non-negative bigint number into a GMP number.
329static void ndMPZ(mpz_t result, number &n, const coeffs r)
330{
331 mpz_init_set_si( result, r->cfInt(n, r) );
332}
334static number ndInitMPZ(mpz_t m, const coeffs r)
335{
336 return r->cfInit( mpz_get_si(m), r);
337}
339static const char *ndRead(const char * s, number *n, const coeffs r)
340{
341 *n=n_Init(1,r);
342 return s;
344static nMapFunc ndSetMap(const coeffs src, const coeffs dst)
345{
346 if (src==dst) return ndCopyMap;
347 Werror("cfSetMap is undefined for %s",nCoeffString(dst));
348 return ndCopyMap;
349}
351static BOOLEAN ndCoeffIsEqual(const coeffs r, n_coeffType n, void *d)
352{
353 /* test, if r is an instance of nInitCoeffs(n,parameter) */
354 return (n==r->type) &&(r->data==d);
355}
357number ndQuotRem (number a, number b, number * r, const coeffs R)
358{
359 // implementation for a field: r: 0, result: n_Div
360 if(R->is_field)
361 {
362 *r=n_Init(0,R);
363 return n_Div(a,b,R);
364 }
365 else
366 // implementation for a non-field:
367 {
368 number d=n_Div(a,b,R);
369 number p=n_Mult(b,d,R);
370 *r=n_Sub(a,p,R);
371 n_Delete(&p,R);
372 return d;
373 }
377{ NULL, /*n_unknown */
378 npInitChar, /* n_Zp */
379 nlInitChar, /* n_Q */
380 nrInitChar, /* n_R */
381 nfInitChar, /* n_GF */
382 ngfInitChar, /* n_long_R */
383 #ifdef HAVE_POLYEXTENSIONS
384 n2pInitChar, /* n_polyExt */
385 naInitChar, /* n_algExt */
386 ntInitChar, /* n_transExt */
387 #else
388 NULL, /* n_polyExt */
389 NULL, /* n_algExt */
390 NULL, /* n_transExt */
391 #endif
392 ngcInitChar, /* n_long_C */
393 nnInitChar, /* n_nTupel */
394 #ifdef HAVE_RINGS
395 nrzInitChar, /* n_Z */
396 nrnInitChar, /* n_Zn */
397 nrnInitChar, /* n_Znm */
398 nr2mInitChar, /* n_Z2m */
399 #else
400 NULL, /* n_Z */
401 NULL, /* n_Zn */
402 NULL, /* n_Znm */
403 NULL, /* n_Z2m */
404 #endif
405 flintQrat_InitChar, /* n_FlintQrat */
406 NULL, /* n_CF */
407 NULL, /* n_Nemo_AnticNumberField */
408 NULL, /* n_Nemo_QQField */
409 NULL, /* n_Nemo_ZZRing */
410 NULL, /* n_Nemo_FqPolyRepField */
411 NULL, /* n_Nemo_fqPolyRepField */
412 NULL, /* n_Nemo_Field */
413 NULL /* n_Nemo_Ring */
414};
417/*2
418* init operations for coeffs r
421{
423
424 while((n!=NULL) && (n->nCoeffIsEqual!=NULL) && (!n->nCoeffIsEqual(n,t,parameter)))
425 n=n->next;
426
427 if (n==NULL)
428 {
429 n=(n_Procs_s*)omAlloc0(sizeof(n_Procs_s));
430 n->next=cf_root;
431 n->ref=1;
432 n->type=t;
433
434 // default entries (different from NULL) for some routines:
436 n->cfSize = ndSize;
440 n->cfDelete= ndDelete;
441 n->cfAnn = ndAnn;
444 n->cfCoeffName = ndCoeffName; // should alway be changed!
447 n->cfCopy = ndCopy;
448 n->cfIntMod=ndIntMod; /* dummy !! */
450 n->cfGcd = ndGcd;
451 n->cfNormalizeHelper = ndGcd; /* tricky, isn't it ?*/
452 n->cfLcm = ndGcd; /* tricky, isn't it ?*/
453 n->cfInitMPZ = ndInitMPZ;
454 n->cfMPZ = ndMPZ;
455 n->cfPower = ndPower;
456 n->cfQuotRem = ndQuotRem;
457 n->cfInvers = ndInvers;
458 n->cfRandom = ndRandom;
459
460 n->cfKillChar = ndKillChar; /* dummy */
461 n->cfSetChar = ndSetChar; /* dummy */
462 // temp. removed to catch all the coeffs which miss to implement this!
463
464 n->cfChineseRemainder = ndChineseRemainder; /* not implemented */
465 n->cfFarey = ndFarey; /* not implemented */
466 n->cfParDeg = ndParDeg; /* not implemented */
467 n->cfReadFd = ndReadFd; /* not implemented */
468 n->cfWriteFd = ndWriteFd; /* not implemented */
469
471
474
475 n->cfEucNorm = ndEucNorm;
476#ifdef HAVE_RINGS
477 n->cfDivComp = ndDivComp;
478 n->cfDivBy = ndDivBy;
479 n->cfExtGcd = ndExtGcd;
480 n->cfXExtGcd = ndXExtGcd;
481 //n->cfGetUnit = ndGetUnit_Ring;// set afterwards
482#endif
483
484 // report error, if not redefined
485 n->cfRead=ndRead;
487
488#ifdef LDEBUG
490#endif
491
494
496 // init
497 if ((t<=nLastCoeffs) && (nInitCharTable[t]!=NULL))
498 nOK = (nInitCharTable[t])(n,parameter);
499 else
500 Werror("Sorry: the coeff type [%d] was not registered: it is missing in nInitCharTable", (int)t);
501 if (nOK)
502 {
503 omFreeSize(n,sizeof(*n));
504 return NULL;
505 }
506 cf_root=n;
507 // post init settings:
508 if (n->cfRePart==NULL) n->cfRePart=n->cfCopy;
509 if (n->cfExactDiv==NULL) n->cfExactDiv=n->cfDiv;
510 if (n->cfSubringGcd==NULL) n->cfSubringGcd=n->cfGcd;
511 if (n->cfWriteShort==NULL) n->cfWriteShort = n->cfWriteLong;
512 if (n->cfIsUnit==NULL)
513 {
515 else n->cfIsUnit=ndIsUnit_Ring;
516 }
517 #ifdef HAVE_RINGS
518 if (n->cfGetUnit==NULL)
519 {
520 if (n->is_field) n->cfGetUnit=n->cfCopy;
522 }
523 if ((n->cfInvers==ndInvers)&&(n->is_field))
524 {
526 }
527 #endif
528
529
530 if(n->cfMult==NULL) PrintS("cfMult missing\n");
531 if(n->cfSub==NULL) PrintS("cfSub missing\n");
532 if(n->cfAdd==NULL) PrintS("cfAdd missing\n");
533 if(n->cfDiv==NULL) PrintS("cfDiv missing\n");
534 if(n->cfExactDiv==NULL) PrintS("cfExactDiv missing\n");
535 if(n->cfInit==NULL) PrintS("cfInit missing\n");
536 if(n->cfInt==NULL) PrintS("cfInt missing\n");
537 if(n->cfIsUnit==NULL) PrintS("cfIsUnit missing\n");
538 if(n->cfGetUnit==NULL) PrintS("cfGetUnit missing\n");
539 if(n->cfInpNeg==NULL) PrintS("cfInpNeg missing\n");
540 if(n->cfXExtGcd==NULL) PrintS("cfXExtGcd missing\n");
541 if(n->cfAnn==NULL) PrintS("cfAnn missing\n");
542 if(n->cfWriteLong==NULL) PrintS("cfWriteLong missing\n");
543
545
546 assume( (n->iNumberOfParameters == 0 && n->pParameterNames == NULL) ||
547 (n->iNumberOfParameters > 0 && n->pParameterNames != NULL) );
548
549
550 if(n->cfGreater==NULL) PrintS("cfGreater missing\n");
551 if(n->cfEqual==NULL) PrintS("cfEqual missing\n");
552 if(n->cfIsZero==NULL) PrintS("cfIsZero missing\n");
553 if(n->cfIsOne==NULL) PrintS("cfIsOne missing\n");
554 if(n->cfIsMOne==NULL) PrintS("cfIsMOne missing\n");
555 if(n->cfGreaterZero==NULL) PrintS("cfGreaterZero missing\n");
556 /* error reporter:
557 if(n->cfRead==ndRead) PrintS("cfRead missing\n");
558 if(n->cfSetMap==ndSetMap) PrintS("cfSetMap missing\n");
559 */
560
561 assume(n->type==t);
562
563#ifndef SING_NDEBUG
564 if(n->cfWriteLong==NULL) Warn("cfWrite is NULL for coeff %d",t);
565 if(n->cfWriteShort==NULL) Warn("cfWriteShort is NULL for coeff %d",t);
566#endif
567 }
568 else
569 {
570 n->ref++;
571 }
572 return n;
573}
575void nKillChar(coeffs r)
576{
577 if (r!=NULL)
578 {
579 r->ref--;
580 if (r->ref<=0)
581 {
583 n_Procs_s* n=&tmp;
584 tmp.next=cf_root;
585 while((n->next!=NULL) && (n->next!=r)) n=n->next;
586 if (n->next==r)
587 {
588 n->next=n->next->next;
589 if (cf_root==r) cf_root=n->next;
590 assume (r->cfKillChar!=NULL); r->cfKillChar(r);
591 omFreeSize((void *)r, sizeof(n_Procs_s));
592 r=NULL;
593 }
594 else
595 {
596 WarnS("cf_root list destroyed");
597 }
598 }
599 }
600}
603{
604 if (n==n_unknown)
605 {
608 {
610 ((int)nLastCoeffs+1)*sizeof(cfInitCharProc));
612 ((int)nLastCoeffs)*sizeof(cfInitCharProc));
613 }
614 else
615 {
617 ((int)nLastCoeffs)*sizeof(cfInitCharProc),
618 (((int)nLastCoeffs)+1)*sizeof(cfInitCharProc));
619 }
620
622 return nLastCoeffs;
623 }
624 else
625 {
626 //if (nInitCharTable[n]!=NULL) Print("coeff %d already initialized\n",n);
627 nInitCharTable[n]=p;
628 return n;
629 }
630}
631
632struct nFindCoeffByName_s;
640};
650}
653{
655 // try existings coeffs:
656 while(n!=NULL)
657 {
658 if ((n->cfCoeffName!=NULL)
659 && (strcmp(cf_name,n->cfCoeffName(n))==0)) return n;
660 n=n->next;
661 }
662 // TODO: parametrized cf, e.g. flint:Z/26[a]
663 // try existing types:
665 while(p!=NULL)
666 {
667 coeffs cf=p->p(cf_name,p->n);
668 if (cf!=NULL) return cf;
669 p=p->next;
670 }
671 return NULL;
672}
674void n_Print(number& a, const coeffs r)
675{
676 assume(r != NULL);
677 n_Test(a,r);
678
679 StringSetS("");
680 n_Write(a, r);
681 { char* s = StringEndS(); Print("%s", s); omFree(s); }
682}
684char* nEati(char *s, int *i, int m)
685{
686
687 if (((*s) >= '0') && ((*s) <= '9'))
688 {
689 unsigned long ii=0L;
690 do
691 {
692 ii *= 10;
693 ii += *s++ - '0';
694 if ((m!=0) && (ii > (MAX_INT_VAL / 10))) ii = ii % m;
695 }
696 while (((*s) >= '0') && ((*s) <= '9'));
697 if ((m!=0) && (ii>=(unsigned)m)) ii=ii%m;
698 *i=(int)ii;
699 }
700 else (*i) = 1;
701 return s;
702}
704char* nEati(char *s, long *i, int m)
705{
706
707 if (((*s) >= '0') && ((*s) <= '9'))
708 {
709 unsigned long ii=0L;
710 do
711 {
712 ii *= 10;
713 ii += *s++ - '0';
714 if ((m!=0) && (ii > (LONG_MAX / 10))) ii = ii % m;
715 }
716 while (((*s) >= '0') && ((*s) <= '9'));
717 if ((m!=0) && (ii>=(long)m)) ii=ii%m;
718 *i=ii;
719 }
720 else (*i) = 1;
721 return s;
722}
723
724/// extracts a long integer from s, returns the rest
725char * nEatLong(char *s, mpz_ptr i)
726{
727 const char * start=s;
728
729 while (*s >= '0' && *s <= '9') s++;
730 if (*s=='\0')
731 {
732 mpz_set_str(i,start,10);
733 }
734 else
735 {
736 char c=*s;
737 *s='\0';
738 mpz_set_str(i,start,10);
739 *s=c;
740 }
741 return s;
742}
743
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition algext.cc:1388
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
Definition algext.cc:1642
All the auxiliary stuff.
int BOOLEAN
Definition auxiliary.h:87
#define TRUE
Definition auxiliary.h:100
#define FALSE
Definition auxiliary.h:96
int m
Definition cfEzgcd.cc:128
int i
Definition cfEzgcd.cc:132
int p
Definition cfModGcd.cc:4086
g
Definition cfModGcd.cc:4098
CanonicalForm cf
Definition cfModGcd.cc:4091
CanonicalForm b
Definition cfModGcd.cc:4111
factory's main class
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition coeffs.h:640
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:455
static FORCE_INLINE BOOLEAN nCoeff_has_Units(const coeffs r)
returns TRUE, if r is not a field and r has non-trivial units
Definition coeffs.h:801
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
Definition coeffs.h:843
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition coeffs.h:716
n_coeffType
Definition coeffs.h:27
@ n_Nemo_Ring
Definition coeffs.h:55
@ n_unknown
Definition coeffs.h:28
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition coeffs.h:668
static FORCE_INLINE number n_Invers(number a, const coeffs r)
return the multiplicative inverse of 'a'; raise an error if 'a' is not invertible
Definition coeffs.h:568
static FORCE_INLINE BOOLEAN nCoeff_is_numeric(const coeffs r)
Definition coeffs.h:836
static FORCE_INLINE char * nCoeffString(const coeffs cf)
TODO: make it a virtual method of coeffs, together with: Decompose & Compose, rParameter & rPar.
Definition coeffs.h:963
static FORCE_INLINE BOOLEAN nCoeff_is_Zp_a(const coeffs r)
Definition coeffs.h:863
static FORCE_INLINE BOOLEAN nCoeff_is_Q_algext(const coeffs r)
is it an alg. ext. of Q?
Definition coeffs.h:918
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:619
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition coeffs.h:810
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition coeffs.h:468
static FORCE_INLINE number n_GetUnit(number n, const coeffs r)
in Z: 1 in Z/kZ (where k is not a prime): largest divisor of n (taken in Z) that is co-prime with k i...
Definition coeffs.h:536
static FORCE_INLINE BOOLEAN nCoeff_has_simple_Alloc(const coeffs r)
TRUE if n_Delete is empty operation.
Definition coeffs.h:910
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition coeffs.h:659
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
Definition coeffs.h:734
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:429
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition coeffs.h:448
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:459
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition coeffs.h:595
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition coeffs.h:804
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:542
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
Definition coeffs.h:914
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:645
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition coeffs.h:582
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition coeffs.h:472
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition coeffs.h:922
#define Print
Definition emacs.cc:80
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
return result
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
void WerrorS(const char *s)
Definition feFopen.cc:24
BOOLEAN nfInitChar(coeffs r, void *parameter)
Definition ffields.cc:855
BOOLEAN flintQrat_InitChar(coeffs cf, void *infoStruct)
#define STATIC_VAR
Definition globaldefs.h:7
#define VAR
Definition globaldefs.h:5
BOOLEAN ngcInitChar(coeffs n, void *parameter)
Initialize r (n_long_C)
Definition gnumpc.cc:560
BOOLEAN ngfInitChar(coeffs n, void *parameter)
Initialize r.
Definition gnumpfl.cc:511
STATIC_VAR Poly * h
Definition janet.cc:971
BOOLEAN nlInitChar(coeffs r, void *p)
Definition longrat.cc:3477
#define assume(x)
Definition mod2.h:387
BOOLEAN npInitChar(coeffs r, void *p)
Definition modulop.cc:338
const int MAX_INT_VAL
Definition mylimits.h:12
The main handler for Singular numbers which are suitable for Singular polynomials.
BOOLEAN nnInitChar(coeffs n, void *p)
Initialize r.
Definition ntupel.cc:616
static void ndPower(number a, int i, number *res, const coeffs r)
Definition numbers.cc:76
static BOOLEAN ndIsUnit_Field(number a, const coeffs r)
Definition numbers.cc:124
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition numbers.cc:642
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition numbers.cc:313
number ndReadFd(const ssiInfo *, const coeffs r)
Definition numbers.cc:152
static int ndDivComp(number, number, const coeffs)
Definition numbers.cc:309
static number ndEucNorm(number a, const coeffs cf)
Definition numbers.cc:130
VAR nFindCoeffByName_p nFindCoeffByName_Root
Definition numbers.cc:641
static number ndGetUnit_Ring(number, const coeffs r)
Definition numbers.cc:126
static BOOLEAN ndCoeffIsEqual(const coeffs r, n_coeffType n, void *d)
Definition numbers.cc:350
static BOOLEAN ndDBTest(number, const char *, const int, const coeffs)
Definition numbers.cc:134
number ndGcd(number, number, const coeffs r)
Definition numbers.cc:189
static void ndKillChar(coeffs)
Definition numbers.cc:301
static void ndClearDenominators(ICoeffsEnumerator &, number &d, const coeffs r)
Definition numbers.cc:282
static void ndClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
Definition numbers.cc:208
static int ndParDeg(number n, const coeffs r)
Definition numbers.cc:163
VAR n_Procs_s * cf_root
Definition numbers.cc:45
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition numbers.cc:291
static BOOLEAN ndIsUnit_Ring(number a, const coeffs r)
Definition numbers.cc:122
void ndNormalize(number &, const coeffs)
Definition numbers.cc:187
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
Definition numbers.cc:673
nFindCoeffByName_p next
Definition numbers.cc:638
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition numbers.cc:683
static int ndSize(number a, const coeffs r)
Definition numbers.cc:206
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:419
static number ndFarey(number, number, const coeffs r)
Definition numbers.cc:137
static number ndRandom(siRandProc p, number, number, const coeffs cf)
Definition numbers.cc:128
static void ndMPZ(mpz_t result, number &n, const coeffs r)
Converts a non-negative bigint number into a GMP number.
Definition numbers.cc:328
STATIC_VAR n_coeffType nLastCoeffs
Definition numbers.cc:374
static number ndGetDenom(number &, const coeffs r)
Definition numbers.cc:204
static void ndDelete(number *d, const coeffs)
Definition numbers.cc:47
STATIC_VAR cfInitCharProc * nInitCharTable
Definition numbers.cc:415
n_coeffType n
Definition numbers.cc:636
static number ndInvers_Ring(number a, const coeffs r)
Definition numbers.cc:113
static number ndParameter(const int, const coeffs r)
Definition numbers.cc:168
static number ndCopy(number a, const coeffs)
Definition numbers.cc:304
static void ndInpMult(number &a, number b, const coeffs r)
Definition numbers.cc:63
VAR cfInitCharProc nInitCharTableDefault[]
Definition numbers.cc:375
static void ndWriteFd(number, const ssiInfo *, const coeffs r)
Definition numbers.cc:158
static number ndChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs r)
Definition numbers.cc:147
static char * ndCoeffString(const coeffs r)
Definition numbers.cc:49
coeffs nFindCoeffByName(char *cf_name)
find an existing coeff by its "CoeffName"
Definition numbers.cc:651
static number ndGetNumerator(number &a, const coeffs r)
Definition numbers.cc:205
static BOOLEAN ndDivBy(number, number, const coeffs)
Definition numbers.cc:308
static number ndInitMPZ(mpz_t m, const coeffs r)
Definition numbers.cc:333
cfInitCfByNameProc p
Definition numbers.cc:637
static void ndInpAdd(number &a, number b, const coeffs r)
Definition numbers.cc:69
number nd_Copy(number a, const coeffs r)
Definition numbers.cc:305
static nMapFunc ndSetMap(const coeffs src, const coeffs dst)
Definition numbers.cc:343
static number ndAnn(number, const coeffs cf)
Definition numbers.cc:48
static number ndInvers(number a, const coeffs r)
Definition numbers.cc:106
BOOLEAN n_IsZeroDivisor(number a, const coeffs r)
Test whether a is a zero divisor in r i.e. not coprime with char. of r very inefficient implementatio...
Definition numbers.cc:173
static number ndIntMod(number a, number b, const coeffs R)
Definition numbers.cc:190
static void ndCoeffWrite(const coeffs r, BOOLEAN)
Definition numbers.cc:53
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition numbers.cc:601
static number ndConvFactoryNSingN(const CanonicalForm, const coeffs r)
[in, out] a bigint number >= 0
Definition numbers.cc:320
static number ndReturn0(number, const coeffs r)
Definition numbers.cc:188
static number ndExtGcd(number, number, number *, number *, const coeffs r)
Definition numbers.cc:310
static const char * ndRead(const char *s, number *n, const coeffs r)
Definition numbers.cc:338
static char * ndCoeffName(const coeffs r)
Definition numbers.cc:57
static void ndSetChar(const coeffs)
Definition numbers.cc:302
void nKillChar(coeffs r)
undo all initialisations
Definition numbers.cc:574
static number ndXExtGcd(number, number, number *, number *, number *, number *, const coeffs r)
Definition numbers.cc:142
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
Definition numbers.cc:724
number ndQuotRem(number a, number b, number *r, const coeffs R)
Definition numbers.cc:356
coeffs(* cfInitCfByNameProc)(char *s, n_coeffType n)
initialize an object of type coeffs by its name, return NULL otherwise
Definition numbers.h:99
BOOLEAN(* cfInitCharProc)(coeffs, void *)
initialize an object of type coeff, return FALSE in case of success
Definition numbers.h:95
#define omStrDup(s)
#define omFreeSize(addr, size)
#define omReallocSize(addr, o_size, size)
#define omFree(addr)
#define omAlloc0(size)
#define NULL
Definition omList.c:12
void StringSetS(const char *st)
Definition reporter.cc:128
void PrintS(const char *s)
Definition reporter.cc:284
char * StringEndS()
Definition reporter.cc:151
void Werror(const char *fmt,...)
Definition reporter.cc:189
BOOLEAN nrzInitChar(coeffs r, void *parameter)
BOOLEAN nr2mInitChar(coeffs r, void *p)
Definition rmodulo2m.cc:797
BOOLEAN nrnInitChar(coeffs r, void *p)
Definition rmodulon.cc:993
BOOLEAN nrInitChar(coeffs n, void *p)
Initialize r.
Definition shortfl.cc:658
#define R
Definition sirandom.c:27
int(* siRandProc)(void)
Definition sirandom.h:9
BOOLEAN(* cfIsUnit)(number a, const coeffs r)
Definition coeffs.h:385
number(* cfChineseRemainder)(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs)
chinese remainder returns X with X mod q[i]=x[i], i=0..rl-1
Definition coeffs.h:304
number(* cfNormalizeHelper)(number a, number b, const coeffs r)
Definition coeffs.h:278
int(* cfDivComp)(number a, number b, const coeffs r)
Definition coeffs.h:384
BOOLEAN(*)(*)(*)(*)(*)(*) cfGreaterZero(number a, const coeffs r)
Definition coeffs.h:244
number(* cfExtGcd)(number a, number b, number *s, number *t, const coeffs r)
Definition coeffs.h:255
number(* cfGetUnit)(number a, const coeffs r)
Definition coeffs.h:386
number(* cfLcm)(number a, number b, const coeffs r)
Definition coeffs.h:277
number(* cfGetNumerator)(number &n, const coeffs r)
Definition coeffs.h:248
number(* cfInvers)(number a, const coeffs r)
return 1/a
Definition coeffs.h:204
number(* cfInit)(long i, const coeffs r)
init with an integer
Definition coeffs.h:185
int iNumberOfParameters
Number of Parameters in the coeffs (default 0)
Definition coeffs.h:326
number(* cfInpNeg)(number a, const coeffs r)
changes argument inline: a:= -a return -a! (no copy is returned) the result should be assigned to the...
Definition coeffs.h:202
number(* cfInitMPZ)(mpz_t i, const coeffs r)
init with a GMP integer
Definition coeffs.h:188
BOOLEAN is_field
TRUE, if cf is a field.
Definition coeffs.h:147
nMapFunc(* cfSetMap)(const coeffs src, const coeffs dst)
Definition coeffs.h:282
number(* cfParameter)(const int i, const coeffs r)
create i^th parameter or NULL if not possible
Definition coeffs.h:310
void(* cfSetChar)(const coeffs r)
Definition coeffs.h:168
number(* convFactoryNSingN)(const CanonicalForm n, const coeffs r)
conversion to CanonicalForm(factory) to number
Definition coeffs.h:322
number(* cfGcd)(number a, number b, const coeffs r)
Definition coeffs.h:253
number(* cfImPart)(number a, const coeffs r)
Definition coeffs.h:208
number(* cfFarey)(number p, number n, const coeffs)
rational reconstruction: "best" rational a/b with a/b = p mod n
Definition coeffs.h:298
coeffs next
Definition coeffs.h:132
number(* cfCopy)(number a, const coeffs r)
return a copy of a
Definition coeffs.h:206
int ref
Definition coeffs.h:133
BOOLEAN(*)(*)(*) cfIsZero(number a, const coeffs r)
Definition coeffs.h:235
void(* cfKillChar)(coeffs r)
Definition coeffs.h:166
BOOLEAN(*)(*) cfEqual(number a, number b, const coeffs r)
tests
Definition coeffs.h:234
numberfunc cfIntMod
Definition coeffs.h:182
numberfunc cfExactDiv
Definition coeffs.h:182
void(* cfMPZ)(mpz_t result, number &n, const coeffs r)
Converts a (integer) number n into a GMP number, 0 if impossible.
Definition coeffs.h:197
BOOLEAN(* nCoeffIsEqual)(const coeffs r, n_coeffType n, void *parameter)
Definition coeffs.h:152
number(* cfXExtGcd)(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition coeffs.h:263
void(* cfWriteShort)(number a, const coeffs r)
print a given number in a shorter way, if possible e.g. in K(a): a2 instead of a^2
Definition coeffs.h:215
number(* cfRePart)(number a, const coeffs r)
Definition coeffs.h:207
void(* cfNormalize)(number &a, const coeffs r)
Definition coeffs.h:230
numberfunc cfMult
Definition coeffs.h:182
number(* cfGetDenom)(number &n, const coeffs r)
Definition coeffs.h:247
void(* cfWriteLong)(number a, const coeffs r)
print a given number (long format)
Definition coeffs.h:211
number(* cfSubringGcd)(number a, number b, const coeffs r)
Definition coeffs.h:254
BOOLEAN(*)(*)(*)(*) cfIsOne(number a, const coeffs r)
Definition coeffs.h:236
number(* cfEucNorm)(number a, const coeffs r)
Definition coeffs.h:265
number(* cfAnn)(number a, const coeffs r)
Definition coeffs.h:268
char *(* cfCoeffString)(const coeffs r)
string output of coeff description
Definition coeffs.h:158
number(* cfReadFd)(const ssiInfo *f, const coeffs r)
Definition coeffs.h:285
void(* cfPower)(number a, int i, number *result, const coeffs r)
Definition coeffs.h:246
CanonicalForm(* convSingNFactoryN)(number n, BOOLEAN setChar, const coeffs r)
Definition coeffs.h:323
long(* cfInt)(number &n, const coeffs r)
convertion to long, 0 if impossible
Definition coeffs.h:194
BOOLEAN(* cfGreater)(number a, number b, const coeffs r)
Definition coeffs.h:232
number(* cfQuotRem)(number a, number b, number *rem, const coeffs r)
Definition coeffs.h:276
void(* cfCoeffWrite)(const coeffs r, BOOLEAN details)
output of coeff description via Print
Definition coeffs.h:155
void(* cfDelete)(number *a, const coeffs r)
Definition coeffs.h:279
numberfunc cfSub
Definition coeffs.h:182
BOOLEAN(* cfDBTest)(number a, const char *f, const int l, const coeffs r)
Test: is "a" a correct number?
Definition coeffs.h:423
void(* cfWriteFd)(number a, const ssiInfo *f, const coeffs r)
Definition coeffs.h:284
n_coeffType type
Definition coeffs.h:135
numberfunc cfAdd
Definition coeffs.h:182
number(* cfRandom)(siRandProc p, number p1, number p2, const coeffs cf)
a function returning random elements
Definition coeffs.h:313
BOOLEAN(*)(*)(*)(*)(*) cfIsMOne(number a, const coeffs r)
Definition coeffs.h:239
numberfunc cfDiv
Definition coeffs.h:182
char const ** pParameterNames
array containing the names of Parameters (default NULL)
Definition coeffs.h:329
char *(* cfCoeffName)(const coeffs r)
default name of cf, should substitue cfCoeffWrite, cfCoeffString
Definition coeffs.h:161
int(* cfParDeg)(number x, const coeffs r)
degree for coeffcients: -1 for 0, 0 for "constants", ...
Definition coeffs.h:307
void(* cfInpMult)(number &a, number b, const coeffs r)
Inplace: a *= b.
Definition coeffs.h:288
int(* cfSize)(number n, const coeffs r)
how complicated, (0) => 0, or positive
Definition coeffs.h:191
void(* cfInpAdd)(number &a, number b, const coeffs r)
Inplace: a += b.
Definition coeffs.h:291
BOOLEAN(* cfDivBy)(number a, number b, const coeffs r)
test if b divides a cfDivBy(zero,b,r) is true, if b is a zero divisor
Definition coeffs.h:389
nCoeffsEnumeratorFunc cfClearContent
function pointer behind n_ClearContent
Definition coeffs.h:316
nCoeffsEnumeratorFunc cfClearDenominators
function pointer behind n_ClearDenominators
Definition coeffs.h:319
const char *(* cfRead)(const char *s, number *a, const coeffs r)
Definition coeffs.h:228
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition transext.cc:2636