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#include "coeffs/rmodulo2m.h"
31#include "coeffs/rmodulon.h"
32#include "coeffs/rintegers.h"
33
34#ifdef HAVE_POLYEXTENSIONS
37#endif
38
39
40//static int characteristic = 0;
41//extern int IsPrime(int p);
42
44
45static void ndDelete(number* d, const coeffs) { *d=NULL; }
46static number ndAnn(number, const coeffs cf) { WarnS("cfAnn undefined"); return n_Init(0,cf); }
47static char* ndCoeffString(const coeffs r)
48{
49 return omStrDup(r->cfCoeffName(r));
50}
51static void ndCoeffWrite(const coeffs r,BOOLEAN)
52{
53 PrintS(r->cfCoeffName(r));
54}
55static char* ndCoeffName(const coeffs r)
56{
57 STATIC_VAR char s[20];
58 snprintf(s,11,"Coeffs(%d)",r->type);
59 return s;
60}
61static void ndInpMult(number &a, number b, const coeffs r)
62{
63 number n=r->cfMult(a,b,r);
64 r->cfDelete(&a,r);
65 a=n;
66}
67static void ndInpAdd(number &a, number b, const coeffs r)
68{
69 number n=r->cfAdd(a,b,r);
70 r->cfDelete(&a,r);
71 a=n;
72}
73
74static void ndPower(number a, int i, number * res, const coeffs r)
75{
76 if (i==0)
77 {
78 *res = r->cfInit(1, r);
79 }
80 else if (i==1)
81 {
82 *res = r->cfCopy(a, r);
83 }
84 else if (i==2)
85 {
86 *res = r->cfMult(a, a, r);
87 }
88 else if (i<0)
89 {
90 number b = r->cfInvers(a, r);
91 ndPower(b, -i, res, r);
92 r->cfDelete(&b, r);
93 }
94 else
95 {
96 ndPower(a, i/2, res, r);
97 r->cfInpMult(*res, *res, r);
98 if (i&1)
99 {
100 r->cfInpMult(*res, a, r);
101 }
102 }
103}
104static number ndInvers(number a, const coeffs r)
105{
106 number one=r->cfInit(1,r);
107 number res=r->cfDiv(one,a,r);
108 r->cfDelete(&one,r);
109 return res;
110}
111static number ndInvers_Ring(number a, const coeffs r)
112{
113 if (!r->cfIsUnit(a,r)) Print("ndInvers_Ring used with non-unit\n");
114 number one=r->cfInit(1,r);
115 number res=r->cfDiv(one,a,r);
116 r->cfDelete(&one,r);
117 return res;
118}
119
120static BOOLEAN ndIsUnit_Ring(number a, const coeffs r)
121{ return r->cfIsOne(a,r)|| r->cfIsMOne(a,r); }
122static BOOLEAN ndIsUnit_Field(number a, const coeffs r)
123{ return !r->cfIsZero(a,r); }
124static number ndGetUnit_Ring(number, const coeffs r)
125{ return r->cfInit(1,r); }
126static number ndRandom(siRandProc p, number, number, const coeffs cf)
127{ return cf->cfInit(p(),cf); }
128static number ndEucNorm(number a, const coeffs cf)
129{ return cf->cfInit(cf->cfSize(a,cf),cf); }
130#ifdef LDEBUG
131// static void nDBDummy1(number* d,char *, int) { *d=NULL; }
132static BOOLEAN ndDBTest(number, const char *, const int, const coeffs){ return TRUE; }
133#endif
134
135static number ndFarey(number,number,const coeffs r)
136{
137 Werror("farey not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
138 return n_Init(0,r);
139}
140static number ndXExtGcd(number, number, number *, number *, number *, number *, const coeffs r)
141{
142 Werror("XExtGcd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
143 return n_Init(0,r);
144}
145static number ndChineseRemainder(number *,number *,int,BOOLEAN,CFArray&,const coeffs r)
146{
147 Werror("ChineseRemainder not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
148 return r->cfInit(0,r);
149}
150number ndReadFd( const ssiInfo *, const coeffs r)
151{
152 Warn("ReadFd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
153 return n_Init(0,r);
154}
155
156number ndReadFd_S( char**, const coeffs r)
157{
158 Warn("ReadFd_S not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
159 return n_Init(0,r);
160}
161
162static void ndWriteFd(number, const ssiInfo *, const coeffs r)
163{
164 Warn("WriteFd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
165}
166
167static int ndParDeg(number n, const coeffs r)
168{
169 return (-r->cfIsZero(n,r));
170}
171
172static number ndParameter(const int, const coeffs r)
173{
174 return r->cfInit(1,r);
175}
176
177BOOLEAN n_IsZeroDivisor( number a, const coeffs r)
178{
179 BOOLEAN ret = n_IsZero(a, r);
180 int c = n_GetChar(r);
181 if (ret || (c==0) || (r->is_field))
182 return ret; /*n_IsZero(a, r)*/
183 number ch = n_Init( c, r );
184 number g = n_Gcd( ch, a, r );
185 ret = !n_IsOne (g, r);
186 n_Delete(&ch, r);
187 n_Delete(&g, r);
188 return ret;
189}
190
191void ndNormalize(number&, const coeffs) { }
192static number ndReturn0(number, const coeffs r) { return r->cfInit(0,r); }
193number ndGcd(number, number, const coeffs r) { return r->cfInit(1,r); }
194static number ndIntMod(number a, number b, const coeffs R)
195{
196 if (R->is_field)
197 return R->cfInit(0,R);
198 else // implementation for a non-field:
199 {
200 number d=n_Div(a,b,R);
201 number p=n_Mult(b,d,R);
202 number r=n_Sub(a,p,R);
203 n_Delete(&p,R);
204 n_Delete(&d,R);
205 return r;
206 }
207}
208static number ndGetDenom(number &, const coeffs r) { return r->cfInit(1,r); }
209static number ndGetNumerator(number &a,const coeffs r) { return r->cfCopy(a,r); }
210static int ndSize(number a, const coeffs r) { return (int)r->cfIsZero(a,r)==FALSE; }
211
212static void ndClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs r)
213{
214 assume(r != NULL);
215
216 // no fractions
217 assume(!( nCoeff_is_Q(r) ));
218 // all coeffs are given by integers!!!
219
220 numberCollectionEnumerator.Reset();
221
222 if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
223 {
224 c = n_Init(1, r);
225 return;
226 }
227
228 number &curr = numberCollectionEnumerator.Current();
229
230 /// TODO: move to a separate implementation
231 if (nCoeff_is_Ring(r))
232 {
233 if (nCoeff_has_Units(r))
234 {
235 c = n_GetUnit(curr, r);
236
237 if (!n_IsOne(c, r))
238 {
239 number inv = n_Invers(c, r);
240
241 n_InpMult(curr, inv, r);
242
243 while( numberCollectionEnumerator.MoveNext() )
244 {
245 number &n = numberCollectionEnumerator.Current();
246 n_Normalize(n, r); // ?
247 n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
248 }
249
250 n_Delete(&inv, r);
251 }
252 } else c = n_Init(1, r);
253
254 return;
255 }
256
259
260 n_Normalize(curr, r); // Q: good/bad/ugly??
261
262 if (!n_IsOne(curr, r))
263 {
264 number t = curr; // takes over the curr! note: not a reference!!!
265
266 curr = n_Init(1, r); // ???
267
268 number inv = n_Invers(t, r);
269
270 while( numberCollectionEnumerator.MoveNext() )
271 {
272 number &n = numberCollectionEnumerator.Current();
273 n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
274// n_Normalize(n, r); // ?
275 }
276
277 n_Delete(&inv, r);
278
279 c = t;
280 } else
281 c = n_Copy(curr, r); // c == 1 and nothing else to do...
282}
283
284static void ndClearDenominators(ICoeffsEnumerator& /*numberCollectionEnumerator*/, number& d, const coeffs r)
285{
286 assume( r != NULL );
289
290 d = n_Init(1, r);
291}
292
293number ndCopyMap(number a, const coeffs aRing, const coeffs r)
294{
295 // aRing and r need not be the same, but must be the same representation
296 assume(aRing->rep==r->rep);
298 return a;
299 else
300 return r->cfCopy(a, r);
301}
302
303static void ndKillChar(coeffs) {}
304static void ndSetChar(const coeffs) {}
305
306static number ndCopy(number a, const coeffs) { return a; }
307number nd_Copy(number a, const coeffs r) { return r->cfCopy(a, r); }
308
309static BOOLEAN ndDivBy(number, number, const coeffs) { return TRUE; } // assume a,b !=0
310static int ndDivComp(number, number, const coeffs) { return 2; }
311static number ndExtGcd (number, number, number *, number *, const coeffs r) { return r->cfInit(1,r); }
312
314{
316 WerrorS("no conversion to factory");
317 return term;
318}
319
320static number ndConvFactoryNSingN( const CanonicalForm, const coeffs r)
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 nrzInitChar, /* n_Z */
395 nrnInitChar, /* n_Zn */
396 nrnInitChar, /* n_Znm */
397 nr2mInitChar, /* n_Z2m */
398 flintQrat_InitChar, /* n_FlintQrat */
399 NULL, /* n_CF */
400 NULL, /* n_Nemo_AnticNumberField */
401 NULL, /* n_Nemo_QQField */
402 NULL, /* n_Nemo_ZZRing */
403 NULL, /* n_Nemo_FqPolyRepField */
404 NULL, /* n_Nemo_fqPolyRepField */
405 NULL, /* n_Nemo_Field */
406 NULL /* n_Nemo_Ring */
407};
410/*2
411* init operations for coeffs r
413coeffs nInitChar(n_coeffType t, void * parameter)
414{
416
417 while((n!=NULL) && (n->nCoeffIsEqual!=NULL) && (!n->nCoeffIsEqual(n,t,parameter)))
418 n=n->next;
419
420 if (n==NULL)
421 {
422 n=(n_Procs_s*)omAlloc0(sizeof(n_Procs_s));
423 n->next=cf_root;
424 n->ref=1;
425 n->type=t;
426
427 // default entries (different from NULL) for some routines:
429 n->cfSize = ndSize;
433 n->cfDelete= ndDelete;
434 n->cfAnn = ndAnn;
437 n->cfCoeffName = ndCoeffName; // should always be changed!
440 n->cfCopy = ndCopy;
441 n->cfIntMod=ndIntMod; /* dummy !! */
443 n->cfGcd = ndGcd;
444 n->cfNormalizeHelper = ndGcd; /* tricky, isn't it ?*/
445 n->cfLcm = ndGcd; /* tricky, isn't it ?*/
446 n->cfInitMPZ = ndInitMPZ;
447 n->cfMPZ = ndMPZ;
448 n->cfPower = ndPower;
449 n->cfQuotRem = ndQuotRem;
450 n->cfInvers = ndInvers;
451 n->cfRandom = ndRandom;
452
453 n->cfKillChar = ndKillChar; /* dummy */
454 n->cfSetChar = ndSetChar; /* dummy */
455 // temp. removed to catch all the coeffs which miss to implement this!
456
457 n->cfChineseRemainder = ndChineseRemainder; /* not implemented */
458 n->cfFarey = ndFarey; /* not implemented */
459 n->cfParDeg = ndParDeg; /* not implemented */
460 n->cfReadFd = ndReadFd; /* not implemented */
461 n->cfReadFd_S = ndReadFd_S; /* not implemented */
462 n->cfWriteFd = ndWriteFd; /* not implemented */
463
465
468
469 n->cfEucNorm = ndEucNorm;
470 n->cfDivComp = ndDivComp;
471 n->cfDivBy = ndDivBy;
472 n->cfExtGcd = ndExtGcd;
473 n->cfXExtGcd = ndXExtGcd;
474 //n->cfGetUnit = ndGetUnit_Ring;// set afterwards
475
476 // report error, if not redefined
477 n->cfRead=ndRead;
479
480#ifdef LDEBUG
482#endif
483
486
487 BOOLEAN nOK=TRUE;
488 // init
489 if ((t<=nLastCoeffs) && (nInitCharTable[t]!=NULL))
490 nOK = (nInitCharTable[t])(n,parameter);
491 else
492 Werror("Sorry: the coeff type [%d] was not registered: it is missing in nInitCharTable", (int)t);
493 if (nOK)
494 {
495 omFreeSize(n,sizeof(*n));
496 return NULL;
497 }
498 cf_root=n;
499 // post init settings:
500 if (n->cfRePart==NULL) n->cfRePart=n->cfCopy;
501 if (n->cfExactDiv==NULL) n->cfExactDiv=n->cfDiv;
502 if (n->cfSubringGcd==NULL) n->cfSubringGcd=n->cfGcd;
503 if (n->cfWriteShort==NULL) n->cfWriteShort = n->cfWriteLong;
504 if (n->cfIsUnit==NULL)
505 {
507 else n->cfIsUnit=ndIsUnit_Ring;
508 }
509 if (n->cfGetUnit==NULL)
510 {
511 if (n->is_field) n->cfGetUnit=n->cfCopy;
513 }
514 if ((n->cfInvers==ndInvers)&&(n->is_field))
515 {
517 }
518
519 if(n->cfMult==NULL) PrintS("cfMult missing\n");
520 if(n->cfSub==NULL) PrintS("cfSub missing\n");
521 if(n->cfAdd==NULL) PrintS("cfAdd missing\n");
522 if(n->cfDiv==NULL) PrintS("cfDiv missing\n");
523 if(n->cfExactDiv==NULL) PrintS("cfExactDiv missing\n");
524 if(n->cfInit==NULL) PrintS("cfInit missing\n");
525 if(n->cfInt==NULL) PrintS("cfInt missing\n");
526 if(n->cfIsUnit==NULL) PrintS("cfIsUnit missing\n");
527 if(n->cfGetUnit==NULL) PrintS("cfGetUnit missing\n");
528 if(n->cfInpNeg==NULL) PrintS("cfInpNeg missing\n");
529 if(n->cfXExtGcd==NULL) PrintS("cfXExtGcd missing\n");
530 if(n->cfAnn==NULL) PrintS("cfAnn missing\n");
531 if(n->cfWriteLong==NULL) PrintS("cfWriteLong missing\n");
532
534
535 assume( (n->iNumberOfParameters == 0 && n->pParameterNames == NULL) ||
536 (n->iNumberOfParameters > 0 && n->pParameterNames != NULL) );
537
538
539 if(n->cfGreater==NULL) PrintS("cfGreater missing\n");
540 if(n->cfEqual==NULL) PrintS("cfEqual missing\n");
541 if(n->cfIsZero==NULL) PrintS("cfIsZero missing\n");
542 if(n->cfIsOne==NULL) PrintS("cfIsOne missing\n");
543 if(n->cfIsMOne==NULL) PrintS("cfIsMOne missing\n");
544 if(n->cfGreaterZero==NULL) PrintS("cfGreaterZero missing\n");
545 /* error reporter:
546 if(n->cfRead==ndRead) PrintS("cfRead missing\n");
547 if(n->cfSetMap==ndSetMap) PrintS("cfSetMap missing\n");
548 */
549
550 assume(n->type==t);
551
552#ifndef SING_NDEBUG
553 if(n->cfWriteLong==NULL) Warn("cfWrite is NULL for coeff %d",t);
554 if(n->cfWriteShort==NULL) Warn("cfWriteShort is NULL for coeff %d",t);
555#endif
556 }
557 else
558 {
559 n->ref++;
560 }
561 return n;
562}
564void nKillChar(coeffs r)
565{
566 if (r!=NULL)
567 {
568 r->ref--;
569 if (r->ref<=0)
570 {
571 n_Procs_s tmp;
572 n_Procs_s* n=&tmp;
573 tmp.next=cf_root;
574 while((n->next!=NULL) && (n->next!=r)) n=n->next;
575 if (n->next==r)
576 {
577 n->next=n->next->next;
578 if (cf_root==r) cf_root=n->next;
579 assume (r->cfKillChar!=NULL); r->cfKillChar(r);
580 omFreeSize((void *)r, sizeof(n_Procs_s));
581 r=NULL;
582 }
583 else
584 {
585 WarnS("cf_root list destroyed");
586 }
587 }
588 }
589}
592{
593 if (n==n_unknown)
594 {
597 {
599 ((int)nLastCoeffs+1)*sizeof(cfInitCharProc));
601 ((int)nLastCoeffs)*sizeof(cfInitCharProc));
602 }
603 else
604 {
606 ((int)nLastCoeffs)*sizeof(cfInitCharProc),
607 (((int)nLastCoeffs)+1)*sizeof(cfInitCharProc));
608 }
609
611 return nLastCoeffs;
612 }
613 else
614 {
615 //if (nInitCharTable[n]!=NULL) Print("coeff %d already initialized\n",n);
616 nInitCharTable[n]=p;
617 return n;
618 }
619}
620
621struct nFindCoeffByName_s;
622typedef struct nFindCoeffByName_s* nFindCoeffByName_p;
629};
631VAR nFindCoeffByName_p nFindCoeffByName_Root=NULL;
633{
634 nFindCoeffByName_p h=(nFindCoeffByName_p)omAlloc0(sizeof(*h));
635 h->p=p;
636 h->n=n;
639}
641coeffs nFindCoeffByName(char *cf_name)
642{
644 // try existings coeffs:
645 while(n!=NULL)
646 {
647 if ((n->cfCoeffName!=NULL)
648 && (strcmp(cf_name,n->cfCoeffName(n))==0)) return n;
649 n=n->next;
650 }
651 // TODO: parametrized cf, e.g. flint:Z/26[a]
652 // try existing types:
653 nFindCoeffByName_p p=nFindCoeffByName_Root;
654 while(p!=NULL)
655 {
656 coeffs cf=p->p(cf_name,p->n);
657 if (cf!=NULL) return cf;
658 p=p->next;
659 }
660 return NULL;
661}
663void n_Print(number& a, const coeffs r)
664{
665 assume(r != NULL);
666 n_Test(a,r);
667
668 StringSetS("");
669 n_Write(a, r);
670 { char* s = StringEndS(); Print("%s", s); omFree(s); }
671}
673char* nEati(char *s, int *i, int m)
674{
675
676 if (((*s) >= '0') && ((*s) <= '9'))
677 {
678 unsigned long ii=0L;
679 do
680 {
681 ii *= 10;
682 ii += *s++ - '0';
683 if ((m!=0) && (ii > (MAX_INT_VAL / 10))) ii = ii % m;
684 }
685 while (((*s) >= '0') && ((*s) <= '9'));
686 if ((m!=0) && (ii>=(unsigned)m)) ii=ii%m;
687 *i=(int)ii;
688 }
689 else (*i) = 1;
690 return s;
691}
693char* nEati(char *s, long *i, int m)
694{
695
696 if (((*s) >= '0') && ((*s) <= '9'))
697 {
698 unsigned long ii=0L;
699 do
700 {
701 ii *= 10;
702 ii += *s++ - '0';
703 if ((m!=0) && (ii > (LONG_MAX / 10))) ii = ii % m;
704 }
705 while (((*s) >= '0') && ((*s) <= '9'));
706 if ((m!=0) && (ii>=(unsigned long)m)) ii=ii%(unsigned long)m;
707 *i=ii;
708 }
709 else (*i) = 1L;
710 return s;
711}
712
713/// extracts a long integer from s, returns the rest
714char * nEatLong(char *s, mpz_ptr i)
715{
716 const char * start=s;
717
718 while (*s >= '0' && *s <= '9') s++;
719 if (*s=='\0')
720 {
721 mpz_set_str(i,start,10);
722 }
723 else
724 {
725 char c=*s;
726 *s='\0';
727 mpz_set_str(i,start,10);
728 *s=c;
729 }
730 return s;
731}
732
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition algext.cc:1433
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
Definition algext.cc:1687
All the auxiliary stuff.
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
Array< CanonicalForm > CFArray
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
virtual reference Current()=0
Gets the current element in the collection (read and write).
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection.
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
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:639
IEnumerator< number > ICoeffsEnumerator
Abstract interface for an enumerator of number coefficients for an object, e.g. a polynomial.
Definition coeffs.h:85
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:457
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:789
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
Definition coeffs.h:837
number ndCopyMap(number a, const coeffs src, const coeffs dst)
Definition numbers.cc:293
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r).
Definition coeffs.h:715
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:667
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:567
static FORCE_INLINE BOOLEAN nCoeff_is_numeric(const coeffs r)
Definition coeffs.h:830
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:961
static FORCE_INLINE BOOLEAN nCoeff_is_Zp_a(const coeffs r)
Definition coeffs.h:857
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:618
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition coeffs.h:804
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition coeffs.h:470
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:537
static FORCE_INLINE BOOLEAN nCoeff_has_simple_Alloc(const coeffs r)
TRUE if n_Delete is empty operation.
Definition coeffs.h:904
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:658
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
Definition coeffs.h:732
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:431
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition coeffs.h:450
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition coeffs.h:594
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition coeffs.h:794
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:541
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
Definition coeffs.h:908
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:644
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:581
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition coeffs.h:474
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition coeffs.h:916
static FORCE_INLINE BOOLEAN nCoeff_is_Q_algExt(const coeffs r)
is it an alg. ext. of Q?
Definition coeffs.h:912
#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
factory.h' is the user interface to Factory.
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:3560
#define assume(x)
Definition mod2.h:389
BOOLEAN npInitChar(coeffs r, void *p)
Definition modulop.cc:351
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:74
static BOOLEAN ndIsUnit_Field(number a, const coeffs r)
Definition numbers.cc:122
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition numbers.cc:631
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition numbers.cc:313
number ndReadFd(const ssiInfo *, const coeffs r)
Definition numbers.cc:150
static int ndDivComp(number, number, const coeffs)
Definition numbers.cc:310
static number ndEucNorm(number a, const coeffs cf)
Definition numbers.cc:128
VAR nFindCoeffByName_p nFindCoeffByName_Root
Definition numbers.cc:630
static number ndGetUnit_Ring(number, const coeffs r)
Definition numbers.cc:124
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:132
number ndGcd(number, number, const coeffs r)
Definition numbers.cc:193
static void ndKillChar(coeffs)
Definition numbers.cc:303
static void ndClearDenominators(ICoeffsEnumerator &, number &d, const coeffs r)
Definition numbers.cc:284
static void ndClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
Definition numbers.cc:212
static int ndParDeg(number n, const coeffs r)
Definition numbers.cc:167
VAR n_Procs_s * cf_root
Definition numbers.cc:43
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition numbers.cc:293
static BOOLEAN ndIsUnit_Ring(number a, const coeffs r)
Definition numbers.cc:120
void ndNormalize(number &, const coeffs)
Definition numbers.cc:191
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
Definition numbers.cc:662
nFindCoeffByName_p next
Definition numbers.cc:627
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition numbers.cc:672
static int ndSize(number a, const coeffs r)
Definition numbers.cc:210
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:412
static number ndFarey(number, number, const coeffs r)
Definition numbers.cc:135
static number ndRandom(siRandProc p, number, number, const coeffs cf)
Definition numbers.cc:126
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:208
static void ndDelete(number *d, const coeffs)
Definition numbers.cc:45
STATIC_VAR cfInitCharProc * nInitCharTable
Definition numbers.cc:408
n_coeffType n
Definition numbers.cc:625
static number ndInvers_Ring(number a, const coeffs r)
Definition numbers.cc:111
static number ndParameter(const int, const coeffs r)
Definition numbers.cc:172
number ndReadFd_S(char **, const coeffs r)
Definition numbers.cc:156
static number ndCopy(number a, const coeffs)
Definition numbers.cc:306
static void ndInpMult(number &a, number b, const coeffs r)
Definition numbers.cc:61
VAR cfInitCharProc nInitCharTableDefault[]
Definition numbers.cc:375
static void ndWriteFd(number, const ssiInfo *, const coeffs r)
Definition numbers.cc:162
static number ndChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs r)
Definition numbers.cc:145
static char * ndCoeffString(const coeffs r)
Definition numbers.cc:47
coeffs nFindCoeffByName(char *cf_name)
find an existing coeff by its "CoeffName"
Definition numbers.cc:640
static number ndGetNumerator(number &a, const coeffs r)
Definition numbers.cc:209
static BOOLEAN ndDivBy(number, number, const coeffs)
Definition numbers.cc:309
static number ndInitMPZ(mpz_t m, const coeffs r)
Definition numbers.cc:333
cfInitCfByNameProc p
Definition numbers.cc:626
static void ndInpAdd(number &a, number b, const coeffs r)
Definition numbers.cc:67
number nd_Copy(number a, const coeffs r)
Definition numbers.cc:307
static nMapFunc ndSetMap(const coeffs src, const coeffs dst)
Definition numbers.cc:343
static number ndAnn(number, const coeffs cf)
Definition numbers.cc:46
static number ndInvers(number a, const coeffs r)
Definition numbers.cc:104
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:177
static number ndIntMod(number a, number b, const coeffs R)
Definition numbers.cc:194
static void ndCoeffWrite(const coeffs r, BOOLEAN)
Definition numbers.cc:51
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition numbers.cc:590
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:192
static number ndExtGcd(number, number, number *, number *, const coeffs r)
Definition numbers.cc:311
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:55
static void ndSetChar(const coeffs)
Definition numbers.cc:304
void nKillChar(coeffs r)
undo all initialisations
Definition numbers.cc:563
static number ndXExtGcd(number, number, number *, number *, number *, number *, const coeffs r)
Definition numbers.cc:140
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
Definition numbers.cc:713
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:100
BOOLEAN(* cfInitCharProc)(coeffs, void *)
initialize an object of type coeff, return FALSE in case of success
Definition numbers.h:96
#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:288
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:801
BOOLEAN nrnInitChar(coeffs r, void *p)
Definition rmodulon.cc:999
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
number(* cfReadFd_S)(char **s, const coeffs r)
Definition coeffs.h:419
CanonicalForm(* convSingNFactoryN)(number n, BOOLEAN setChar, const coeffs r)
Definition coeffs.h:323
number(* cfInitMPZ)(mpz_t i, const coeffs r)
init with a GMP integer
Definition coeffs.h:188
number(* cfImPart)(number a, const coeffs r)
Definition coeffs.h:208
char *(* cfCoeffString)(const coeffs r)
string output of coeff description
Definition coeffs.h:158
number(* cfLcm)(number a, number b, const coeffs r)
Definition coeffs.h:277
int iNumberOfParameters
Number of Parameters in the coeffs (default 0).
Definition coeffs.h:326
number(* cfSubringGcd)(number a, number b, const coeffs r)
Definition coeffs.h:254
BOOLEAN(* cfIsMOne)(number a, const coeffs r)
Definition coeffs.h:239
void(* cfWriteFd)(number a, const ssiInfo *f, const coeffs r)
Definition coeffs.h:284
BOOLEAN(* cfIsZero)(number a, const coeffs r)
Definition coeffs.h:235
number(* cfInvers)(number a, const coeffs r)
return 1/a
Definition coeffs.h:204
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
number(* cfAnn)(number a, const coeffs r)
Definition coeffs.h:268
numberfunc cfSub
Definition coeffs.h:182
numberfunc cfDiv
Definition coeffs.h:182
number(* cfQuotRem)(number a, number b, number *rem, const coeffs r)
Definition coeffs.h:276
number(* cfParameter)(const int i, const coeffs r)
create i^th parameter or NULL if not possible
Definition coeffs.h:310
BOOLEAN(* cfIsUnit)(number a, const coeffs r)
Definition coeffs.h:385
number(* cfNormalizeHelper)(number a, number b, const coeffs r)
Definition coeffs.h:278
number(* cfRandom)(siRandProc p, number p1, number p2, const coeffs cf)
a function returning random elements
Definition coeffs.h:313
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
void(* cfCoeffWrite)(const coeffs r, BOOLEAN details)
output of coeff description via Print
Definition coeffs.h:155
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(* cfGcd)(number a, number b, const coeffs r)
Definition coeffs.h:253
n_coeffType type
Definition coeffs.h:135
void(* cfSetChar)(const coeffs r)
Definition coeffs.h:168
numberfunc cfAdd
Definition coeffs.h:182
nCoeffsEnumeratorFunc cfClearContent
function pointer behind n_ClearContent
Definition coeffs.h:316
int(* cfDivComp)(number a, number b, const coeffs r)
Definition coeffs.h:384
number(* cfReadFd)(const ssiInfo *f, const coeffs r)
Definition coeffs.h:285
const char *(* cfRead)(const char *s, number *a, const coeffs r)
Definition coeffs.h:228
number(* convFactoryNSingN)(const CanonicalForm n, const coeffs r)
conversion to CanonicalForm(factory) to number
Definition coeffs.h:322
BOOLEAN(* cfEqual)(number a, number b, const coeffs r)
tests
Definition coeffs.h:234
void(* cfWriteLong)(number a, const coeffs r)
print a given number (long format)
Definition coeffs.h:211
void(* cfDelete)(number *a, const coeffs r)
Definition coeffs.h:279
BOOLEAN(* nCoeffIsEqual)(const coeffs r, n_coeffType n, void *parameter)
Definition coeffs.h:152
nCoeffsEnumeratorFunc cfClearDenominators
function pointer behind n_ClearDenominators
Definition coeffs.h:319
numberfunc cfExactDiv
Definition coeffs.h:182
char const ** pParameterNames
array containing the names of Parameters (default NULL)
Definition coeffs.h:329
number(* cfEucNorm)(number a, const coeffs r)
Definition coeffs.h:265
BOOLEAN(* cfGreaterZero)(number a, const coeffs r)
Definition coeffs.h:244
void(* cfInpAdd)(number &a, number b, const coeffs r)
Inplace: a += b.
Definition coeffs.h:291
number(* cfExtGcd)(number a, number b, number *s, number *t, const coeffs r)
Definition coeffs.h:255
number(* cfFarey)(number p, number n, const coeffs)
rational reconstruction: "best" rational a/b with a/b = p mod n
Definition coeffs.h:298
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
nMapFunc(* cfSetMap)(const coeffs src, const coeffs dst)
Definition coeffs.h:282
int(* cfParDeg)(number x, const coeffs r)
degree for coefficients: -1 for 0, 0 for "constants", ...
Definition coeffs.h:307
number(* cfInit)(long i, const coeffs r)
init with an integer
Definition coeffs.h:185
void(* cfInpMult)(number &a, number b, const coeffs r)
Inplace: a *= b.
Definition coeffs.h:288
void(* cfKillChar)(coeffs r)
Definition coeffs.h:166
BOOLEAN is_field
TRUE, if cf is a field.
Definition coeffs.h:147
coeffs next
Definition coeffs.h:132
long(* cfInt)(number &n, const coeffs r)
conversion to long, 0 if impossible
Definition coeffs.h:194
void(* cfPower)(number a, int i, number *result, const coeffs r)
Definition coeffs.h:246
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
BOOLEAN(* cfGreater)(number a, number b, const coeffs r)
Definition coeffs.h:232
BOOLEAN(* cfDBTest)(number a, const char *f, const int l, const coeffs r)
Test: is "a" a correct number?
Definition coeffs.h:425
number(* cfRePart)(number a, const coeffs r)
Definition coeffs.h:207
int ref
Definition coeffs.h:133
numberfunc cfMult
Definition coeffs.h:182
number(* cfGetUnit)(number a, const coeffs r)
Definition coeffs.h:386
number(* cfCopy)(number a, const coeffs r)
return a copy of a
Definition coeffs.h:206
void(* cfNormalize)(number &a, const coeffs r)
Definition coeffs.h:230
char *(* cfCoeffName)(const coeffs r)
default name of cf, should substitute cfCoeffWrite, cfCoeffString
Definition coeffs.h:161
numberfunc cfIntMod
Definition coeffs.h:182
number(* cfGetDenom)(number &n, const coeffs r)
Definition coeffs.h:247
BOOLEAN(* cfIsOne)(number a, const coeffs r)
Definition coeffs.h:236
number(* cfXExtGcd)(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition coeffs.h:263
number(* cfGetNumerator)(number &n, const coeffs r)
Definition coeffs.h:248
int(* cfSize)(number n, const coeffs r)
how complicated, (0) => 0, or positive
Definition coeffs.h:191
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition transext.cc:2636