My Project
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
47void nNew(number* d) { *d=NULL; }
48
49
50static void ndDelete(number* d, const coeffs) { *d=NULL; }
51static number ndAnn(number, const coeffs) { return NULL;}
52static char* ndCoeffString(const coeffs r)
53{
54 return omStrDup(r->cfCoeffName(r));
55}
56static void ndCoeffWrite(const coeffs r,BOOLEAN)
57{
58 PrintS(r->cfCoeffName(r));
59}
60static char* ndCoeffName(const coeffs r)
61{
62 STATIC_VAR char s[20];
63 snprintf(s,11,"Coeffs(%d)",r->type);
64 return s;
65}
66static void ndInpMult(number &a, number b, const coeffs r)
67{
68 number n=r->cfMult(a,b,r);
69 r->cfDelete(&a,r);
70 a=n;
71}
72static void ndInpAdd(number &a, number b, const coeffs r)
73{
74 number n=r->cfAdd(a,b,r);
75 r->cfDelete(&a,r);
76 a=n;
77}
78
79static void ndPower(number a, int i, number * res, const coeffs r)
80{
81 if (i==0)
82 {
83 *res = r->cfInit(1, r);
84 }
85 else if (i==1)
86 {
87 *res = r->cfCopy(a, r);
88 }
89 else if (i==2)
90 {
91 *res = r->cfMult(a, a, r);
92 }
93 else if (i<0)
94 {
95 number b = r->cfInvers(a, r);
96 ndPower(b, -i, res, r);
97 r->cfDelete(&b, r);
98 }
99 else
100 {
101 ndPower(a, i/2, res, r);
102 r->cfInpMult(*res, *res, r);
103 if (i&1)
104 {
105 r->cfInpMult(*res, a, r);
106 }
107 }
108}
109static number ndInvers(number a, const coeffs r)
110{
111 number one=r->cfInit(1,r);
112 number res=r->cfDiv(one,a,r);
113 r->cfDelete(&one,r);
114 return res;
115}
116
117static BOOLEAN ndIsUnit_Ring(number a, const coeffs r)
118{ return r->cfIsOne(a,r)|| r->cfIsMOne(a,r); }
119static BOOLEAN ndIsUnit_Field(number a, const coeffs r)
120{ return !r->cfIsZero(a,r); }
121static number ndGetUnit_Ring(number, const coeffs r)
122{ return r->cfInit(1,r); }
123#ifdef LDEBUG
124// static void nDBDummy1(number* d,char *, int) { *d=NULL; }
125static BOOLEAN ndDBTest(number, const char *, const int, const coeffs){ return TRUE; }
126#endif
127
128static number ndFarey(number,number,const coeffs r)
129{
130 Werror("farey not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
131 return NULL;
132}
133static number ndChineseRemainder(number *,number *,int,BOOLEAN,CFArray&,const coeffs r)
134{
135 Werror("ChineseRemainder not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
136 return r->cfInit(0,r);
137}
138
139static int ndParDeg(number n, const coeffs r)
140{
141 return (-r->cfIsZero(n,r));
142}
143
144static number ndParameter(const int, const coeffs r)
145{
146 return r->cfInit(1,r);
147}
148
149BOOLEAN n_IsZeroDivisor( number a, const coeffs r)
150{
151 BOOLEAN ret = n_IsZero(a, r);
152 int c = n_GetChar(r);
153 if (ret || (c==0) || (r->is_field))
154 return ret; /*n_IsZero(a, r)*/
155 number ch = n_Init( c, r );
156 number g = n_Gcd( ch, a, r );
157 ret = !n_IsOne (g, r);
158 n_Delete(&ch, r);
159 n_Delete(&g, r);
160 return ret;
161}
162
163void ndNormalize(number&, const coeffs) { }
164static number ndReturn0(number, const coeffs r) { return r->cfInit(0,r); }
165number ndGcd(number, number, const coeffs r) { return r->cfInit(1,r); }
166static number ndIntMod(number, number, const coeffs r) { return r->cfInit(0,r); }
167static number ndGetDenom(number &, const coeffs r) { return r->cfInit(1,r); }
168static number ndGetNumerator(number &a,const coeffs r) { return r->cfCopy(a,r); }
169static int ndSize(number a, const coeffs r) { return (int)r->cfIsZero(a,r)==FALSE; }
170
171static void ndClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs r)
172{
173 assume(r != NULL);
174
175 // no fractions
176 assume(!( nCoeff_is_Q(r) ));
177 // all coeffs are given by integers!!!
178
179 numberCollectionEnumerator.Reset();
180
181 if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
182 {
183 c = n_Init(1, r);
184 return;
185 }
186
187 number &curr = numberCollectionEnumerator.Current();
188
189#ifdef HAVE_RINGS
190 /// TODO: move to a separate implementation
191 if (nCoeff_is_Ring(r))
192 {
193 if (nCoeff_has_Units(r))
194 {
195 c = n_GetUnit(curr, r);
196
197 if (!n_IsOne(c, r))
198 {
199 number inv = n_Invers(c, r);
200
201 n_InpMult(curr, inv, r);
202
203 while( numberCollectionEnumerator.MoveNext() )
204 {
205 number &n = numberCollectionEnumerator.Current();
206 n_Normalize(n, r); // ?
207 n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
208 }
209
210 n_Delete(&inv, r);
211 }
212 } else c = n_Init(1, r);
213
214 return;
215 }
216#endif
217
220
221 n_Normalize(curr, r); // Q: good/bad/ugly??
222
223 if (!n_IsOne(curr, r))
224 {
225 number t = curr; // takes over the curr! note: not a reference!!!
226
227 curr = n_Init(1, r); // ???
228
229 number inv = n_Invers(t, r);
230
231 while( numberCollectionEnumerator.MoveNext() )
232 {
233 number &n = numberCollectionEnumerator.Current();
234 n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
235// n_Normalize(n, r); // ?
236 }
237
238 n_Delete(&inv, r);
239
240 c = t;
241 } else
242 c = n_Copy(curr, r); // c == 1 and nothing else to do...
243}
244
245static void ndClearDenominators(ICoeffsEnumerator& /*numberCollectionEnumerator*/, number& d, const coeffs r)
246{
247 assume( r != NULL );
250
251 d = n_Init(1, r);
252}
253
254static number ndCopy(number a, const coeffs) { return a; }
255number ndCopyMap(number a, const coeffs aRing, const coeffs r)
256{
257 // aRing and r need not be the same, but must be the same representation
258 assume(aRing->rep==r->rep);
260 return a;
261 else
262 return r->cfCopy(a, r);
263}
264
265static void ndKillChar(coeffs) {}
266static void ndSetChar(const coeffs) {}
267
268number nd_Copy(number a, const coeffs r) { return r->cfCopy(a, r); }
269
270#ifdef HAVE_RINGS
271static BOOLEAN ndDivBy(number, number, const coeffs) { return TRUE; } // assume a,b !=0
272static int ndDivComp(number, number, const coeffs) { return 2; }
273static number ndExtGcd (number, number, number *, number *, const coeffs r) { return r->cfInit(1,r); }
274#endif
275
277{
279 WerrorS("no conversion to factory");
280 return term;
281}
282
283static number ndConvFactoryNSingN( const CanonicalForm, const coeffs)
284{
285 WerrorS("no conversion from factory");
286 return NULL;
287}
288
289/**< [in, out] a bigint number >= 0 */
290/**< [out] the GMP equivalent */
291/// Converts a non-negative bigint number into a GMP number.
292static void ndMPZ(mpz_t result, number &n, const coeffs r)
293{
294 mpz_init_set_si( result, r->cfInt(n, r) );
295}
297static number ndInitMPZ(mpz_t m, const coeffs r)
298{
299 return r->cfInit( mpz_get_si(m), r);
300}
301
303static BOOLEAN ndCoeffIsEqual(const coeffs r, n_coeffType n, void *)
304{
305 /* test, if r is an instance of nInitCoeffs(n,parameter) */
306 /* if parameter is not needed */
307 return (n==r->type);
308}
310static number ndQuotRem (number a, number b, number * r, const coeffs R)
311{
312 // implementation for a field: r: 0, result: n_Div
313 assume(R->is_field);
314 *r=n_Init(0,R);
315 return n_Div(a,b,R);
319{ NULL, /*n_unknown */
320 npInitChar, /* n_Zp */
321 nlInitChar, /* n_Q */
322 nrInitChar, /* n_R */
323 nfInitChar, /* n_GF */
324 ngfInitChar, /* n_long_R */
325 #ifdef HAVE_POLYEXTENSIONS
326 n2pInitChar, /* n_polyExt */
327 naInitChar, /* n_algExt */
328 ntInitChar, /* n_transExt */
329 #else
330 NULL, /* n_polyExt */
331 NULL, /* n_algExt */
332 NULL, /* n_transExt */
333 #endif
334 ngcInitChar, /* n_long_C */
335 nnInitChar, /* n_nTupel */
336 #ifdef HAVE_RINGS
337 nrzInitChar, /* n_Z */
338 nrnInitChar, /* n_Zn */
339 nrnInitChar, /* n_Znm */
340 nr2mInitChar, /* n_Z2m */
341 #else
342 NULL, /* n_Z */
343 NULL, /* n_Zn */
344 NULL, /* n_Znm */
345 NULL, /* n_Z2m */
346 #endif
347 flintQrat_InitChar, /* n_FlintQrat */
348 NULL /* n_CF */
349};
352/*2
353* init operations for coeffs r
355coeffs nInitChar(n_coeffType t, void * parameter)
356{
358
359 while((n!=NULL) && (n->nCoeffIsEqual!=NULL) && (!n->nCoeffIsEqual(n,t,parameter)))
360 n=n->next;
361
362 if (n==NULL)
363 {
364 n=(n_Procs_s*)omAlloc0(sizeof(n_Procs_s));
365 n->next=cf_root;
366 n->ref=1;
367 n->type=t;
368
369 // default entries (different from NULL) for some routines:
371 n->cfSize = ndSize;
375 n->cfDelete= ndDelete;
376 n->cfAnn = ndAnn;
379 n->cfCoeffName = ndCoeffName; // should alway be changed!
382 n->cfCopy = ndCopy;
383 n->cfIntMod=ndIntMod; /* dummy !! */
385 n->cfGcd = ndGcd;
386 n->cfNormalizeHelper = ndGcd; /* tricky, isn't it ?*/
387 n->cfLcm = ndGcd; /* tricky, isn't it ?*/
388 n->cfInitMPZ = ndInitMPZ;
389 n->cfMPZ = ndMPZ;
390 n->cfPower = ndPower;
391 n->cfQuotRem = ndQuotRem;
392 n->cfInvers = ndInvers;
393
394 n->cfKillChar = ndKillChar; /* dummy */
395 n->cfSetChar = ndSetChar; /* dummy */
396 // temp. removed to catch all the coeffs which miss to implement this!
397
399 n->cfFarey = ndFarey;
400 n->cfParDeg = ndParDeg;
401
403
406
407 //n->cfIsUnit = ndIsUnit;
408#ifdef HAVE_RINGS
409 n->cfDivComp = ndDivComp;
410 n->cfDivBy = ndDivBy;
411 n->cfExtGcd = ndExtGcd;
412 //n->cfGetUnit = ndGetUnit_Ring;// set afterwards
413#endif
414
415#ifdef LDEBUG
417#endif
418
421
422 BOOLEAN nOK=TRUE;
423 // init
424 if ((t<=nLastCoeffs) && (nInitCharTable[t]!=NULL))
425 nOK = (nInitCharTable[t])(n,parameter);
426 else
427 Werror("Sorry: the coeff type [%d] was not registered: it is missing in nInitCharTable", (int)t);
428 if (nOK)
429 {
430 omFreeSize(n,sizeof(*n));
431 return NULL;
432 }
433 cf_root=n;
434 // post init settings:
435 if (n->cfRePart==NULL) n->cfRePart=n->cfCopy;
436 if (n->cfExactDiv==NULL) n->cfExactDiv=n->cfDiv;
437 if (n->cfSubringGcd==NULL) n->cfSubringGcd=n->cfGcd;
438 if (n->cfIsUnit==NULL)
439 {
441 else n->cfIsUnit=ndIsUnit_Ring;
442 }
443 #ifdef HAVE_RINGS
444 if (n->cfGetUnit==NULL)
445 {
446 if (n->is_field) n->cfGetUnit=n->cfCopy;
448 }
449 #endif
450
451 if(n->cfWriteShort==NULL)
453
455 assume(n->cfSetChar!=NULL);
457 assume(n->cfMult!=NULL);
458 assume(n->cfSub!=NULL);
459 assume(n->cfAdd!=NULL);
460 assume(n->cfDiv!=NULL);
461 assume(n->cfIntMod!=NULL);
463 assume(n->cfInit!=NULL);
464 assume(n->cfInitMPZ!=NULL);
465 assume(n->cfSize!=NULL);
466 assume(n->cfInt!=NULL);
467 assume(n->cfMPZ!=NULL);
468 //assume(n->n->cfDivComp!=NULL);
469 //assume(n->cfIsUnit!=NULL);
470 //assume(n->cfGetUnit!=NULL);
471 //assume(n->cfExtGcd!=NULL);
472 assume(n->cfInpNeg!=NULL);
473 assume(n->cfCopy!=NULL);
474
477
479
480 assume( (n->iNumberOfParameters == 0 && n->pParameterNames == NULL) ||
481 (n->iNumberOfParameters > 0 && n->pParameterNames != NULL) );
482
484 assume(n->cfParDeg!=NULL);
485
486 assume(n->cfRead!=NULL);
488 assume(n->cfGreater!=NULL);
489 //assume(n->cfDivBy!=NULL);
490 assume(n->cfEqual!=NULL);
491 assume(n->cfIsZero!=NULL);
492 assume(n->cfIsOne!=NULL);
493 assume(n->cfIsMOne!=NULL);
497 assume(n->cfGcd!=NULL);
499 assume(n->cfDelete!=NULL);
500 assume(n->cfSetMap!=NULL);
501 assume(n->cfInpMult!=NULL);
502// assume(n->cfInit_bigint!=NULL);
503 assume(n->cfCoeffWrite != NULL);
504
507
508 assume(n->type==t);
509
510#ifndef SING_NDEBUG
511 if(n->cfKillChar==NULL) Warn("cfKillChar is NULL for coeff %d",t);
512 if(n->cfWriteLong==NULL) Warn("cfWrite is NULL for coeff %d",t);
513 if(n->cfWriteShort==NULL) Warn("cfWriteShort is NULL for coeff %d",t);
514#endif
515 }
516 else
517 {
518 n->ref++;
519 }
520 return n;
521}
523void nKillChar(coeffs r)
524{
525 if (r!=NULL)
526 {
527 r->ref--;
528 if (r->ref<=0)
529 {
530 n_Procs_s tmp;
531 n_Procs_s* n=&tmp;
532 tmp.next=cf_root;
533 while((n->next!=NULL) && (n->next!=r)) n=n->next;
534 if (n->next==r)
535 {
536 n->next=n->next->next;
537 if (cf_root==r) cf_root=n->next;
538 assume (r->cfKillChar!=NULL); r->cfKillChar(r);
539 omFreeSize((void *)r, sizeof(n_Procs_s));
540 r=NULL;
541 }
542 else
543 {
544 WarnS("cf_root list destroyed");
545 }
546 }
547 }
548}
551{
552 if (n==n_unknown)
553 {
556 {
558 ((int)nLastCoeffs+1)*sizeof(cfInitCharProc));
560 ((int)nLastCoeffs)*sizeof(cfInitCharProc));
561 }
562 else
563 {
565 ((int)nLastCoeffs)*sizeof(cfInitCharProc),
566 (((int)nLastCoeffs)+1)*sizeof(cfInitCharProc));
567 }
568
570 return nLastCoeffs;
571 }
572 else
573 {
574 if (nInitCharTable[n]!=NULL) Print("coeff %d already initialized\n",n);
575 nInitCharTable[n]=p;
576 return n;
577 }
578}
579
580struct nFindCoeffByName_s;
581typedef struct nFindCoeffByName_s* nFindCoeffByName_p;
587 nFindCoeffByName_p next;
588};
590VAR nFindCoeffByName_p nFindCoeffByName_Root=NULL;
592{
593 nFindCoeffByName_p h=(nFindCoeffByName_p)omAlloc0(sizeof(*h));
594 h->p=p;
595 h->n=n;
598}
600coeffs nFindCoeffByName(char *cf_name)
601{
603 // try existings coeffs:
604 while(n!=NULL)
605 {
606 if ((n->cfCoeffName!=NULL)
607 && (strcmp(cf_name,n->cfCoeffName(n))==0)) return n;
608 n=n->next;
609 }
610 // TODO: parametrized cf, e.g. flint:Z/26[a]
611 // try existing types:
612 nFindCoeffByName_p p=nFindCoeffByName_Root;
613 while(p!=NULL)
614 {
615 coeffs cf=p->p(cf_name,p->n);
616 if (cf!=NULL) return cf;
617 p=p->next;
618 }
619 return NULL;
620}
622void n_Print(number& a, const coeffs r)
623{
624 assume(r != NULL);
625 n_Test(a,r);
626
627 StringSetS("");
628 n_Write(a, r);
629 { char* s = StringEndS(); Print("%s", s); omFree(s); }
630}
632char* nEati(char *s, int *i, int m)
633{
634
635 if (((*s) >= '0') && ((*s) <= '9'))
636 {
637 unsigned long ii=0L;
638 do
639 {
640 ii *= 10;
641 ii += *s++ - '0';
642 if ((m!=0) && (ii > (MAX_INT_VAL / 10))) ii = ii % m;
643 }
644 while (((*s) >= '0') && ((*s) <= '9'));
645 if ((m!=0) && (ii>=(unsigned)m)) ii=ii%m;
646 *i=(int)ii;
647 }
648 else (*i) = 1;
649 return s;
650}
651
652/// extracts a long integer from s, returns the rest
653char * nEatLong(char *s, mpz_ptr i)
654{
655 const char * start=s;
656
657 while (*s >= '0' && *s <= '9') s++;
658 if (*s=='\0')
659 {
660 mpz_set_str(i,start,10);
661 }
662 else
663 {
664 char c=*s;
665 *s='\0';
666 mpz_set_str(i,start,10);
667 *s=c;
668 }
669 return s;
670}
671
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: algext.cc:1378
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
Definition: algext.cc:1633
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:4078
g
Definition: cfModGcd.cc:4090
CanonicalForm cf
Definition: cfModGcd.cc:4083
CanonicalForm b
Definition: cfModGcd.cc:4103
factory's main class
Definition: canonicalform.h:86
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...
Templated enumerator interface for simple iteration over a generic collection of T's.
Definition: Enumerator.h:125
Definition: int_poly.h:33
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:451
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:797
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
Definition: coeffs.h:839
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:712
n_coeffType
Definition: coeffs.h:27
@ n_CF
?
Definition: coeffs.h:48
@ 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:664
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:564
static FORCE_INLINE BOOLEAN nCoeff_is_numeric(const coeffs r)
Definition: coeffs.h:832
static FORCE_INLINE BOOLEAN nCoeff_is_Zp_a(const coeffs r)
Definition: coeffs.h:859
static FORCE_INLINE BOOLEAN nCoeff_is_Q_algext(const coeffs r)
is it an alg. ext. of Q?
Definition: coeffs.h:914
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:615
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:806
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:464
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:532
static FORCE_INLINE BOOLEAN nCoeff_has_simple_Alloc(const coeffs r)
TRUE if n_Delete/n_New are empty operations.
Definition: coeffs.h:906
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
Definition: coeffs.h:730
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:591
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:800
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:538
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
Definition: coeffs.h:910
static FORCE_INLINE void n_InpMult(number &a, number b, const coeffs r)
multiplication of 'a' and 'b'; replacement of 'a' by the product a*b
Definition: coeffs.h:641
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:578
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:468
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition: coeffs.h:918
#define Print
Definition: emacs.cc:80
#define Warn
Definition: emacs.cc:77
#define WarnS
Definition: emacs.cc:78
return result
Definition: facAbsBiFact.cc:75
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:858
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:554
BOOLEAN ngfInitChar(coeffs n, void *parameter)
Initialize r.
Definition: gnumpfl.cc:499
STATIC_VAR Poly * h
Definition: janet.cc:971
BOOLEAN nlInitChar(coeffs r, void *p)
Definition: longrat.cc:3475
#define assume(x)
Definition: mod2.h:387
BOOLEAN npInitChar(coeffs r, void *p)
Definition: modulop.cc:340
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:588
static void ndPower(number a, int i, number *res, const coeffs r)
Definition: numbers.cc:79
static BOOLEAN ndIsUnit_Field(number a, const coeffs r)
Definition: numbers.cc:119
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition: numbers.cc:590
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition: numbers.cc:276
static int ndDivComp(number, number, const coeffs)
Definition: numbers.cc:272
VAR nFindCoeffByName_p nFindCoeffByName_Root
Definition: numbers.cc:589
static number ndGetUnit_Ring(number, const coeffs r)
Definition: numbers.cc:121
static BOOLEAN ndDBTest(number, const char *, const int, const coeffs)
Definition: numbers.cc:125
number ndGcd(number, number, const coeffs r)
Definition: numbers.cc:165
static void ndKillChar(coeffs)
Definition: numbers.cc:265
static number ndConvFactoryNSingN(const CanonicalForm, const coeffs)
[in, out] a bigint number >= 0
Definition: numbers.cc:283
static void ndClearDenominators(ICoeffsEnumerator &, number &d, const coeffs r)
Definition: numbers.cc:245
static void ndClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
Definition: numbers.cc:171
static int ndParDeg(number n, const coeffs r)
Definition: numbers.cc:139
static BOOLEAN ndCoeffIsEqual(const coeffs r, n_coeffType n, void *)
Definition: numbers.cc:302
VAR n_Procs_s * cf_root
Definition: numbers.cc:45
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:255
static BOOLEAN ndIsUnit_Ring(number a, const coeffs r)
Definition: numbers.cc:117
void ndNormalize(number &, const coeffs)
Definition: numbers.cc:163
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
Definition: numbers.cc:621
nFindCoeffByName_p next
Definition: numbers.cc:586
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition: numbers.cc:631
static int ndSize(number a, const coeffs r)
Definition: numbers.cc:169
static number ndIntMod(number, number, const coeffs r)
Definition: numbers.cc:166
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:354
static number ndFarey(number, number, const coeffs r)
Definition: numbers.cc:128
void nNew(number *d)
Definition: numbers.cc:47
static void ndMPZ(mpz_t result, number &n, const coeffs r)
Converts a non-negative bigint number into a GMP number.
Definition: numbers.cc:291
STATIC_VAR n_coeffType nLastCoeffs
Definition: numbers.cc:316
static number ndAnn(number, const coeffs)
Definition: numbers.cc:51
static number ndGetDenom(number &, const coeffs r)
Definition: numbers.cc:167
static void ndDelete(number *d, const coeffs)
Definition: numbers.cc:50
STATIC_VAR cfInitCharProc * nInitCharTable
Definition: numbers.cc:350
n_coeffType n
Definition: numbers.cc:584
static number ndParameter(const int, const coeffs r)
Definition: numbers.cc:144
static number ndCopy(number a, const coeffs)
Definition: numbers.cc:254
static void ndInpMult(number &a, number b, const coeffs r)
Definition: numbers.cc:66
VAR cfInitCharProc nInitCharTableDefault[]
Definition: numbers.cc:317
static number ndChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs r)
Definition: numbers.cc:133
static char * ndCoeffString(const coeffs r)
Definition: numbers.cc:52
coeffs nFindCoeffByName(char *cf_name)
find an existing coeff by its "CoeffName"
Definition: numbers.cc:599
static number ndGetNumerator(number &a, const coeffs r)
Definition: numbers.cc:168
static BOOLEAN ndDivBy(number, number, const coeffs)
Definition: numbers.cc:271
static number ndInitMPZ(mpz_t m, const coeffs r)
Definition: numbers.cc:296
cfInitCfByNameProc p
Definition: numbers.cc:585
static void ndInpAdd(number &a, number b, const coeffs r)
Definition: numbers.cc:72
number nd_Copy(number a, const coeffs r)
Definition: numbers.cc:268
static number ndInvers(number a, const coeffs r)
Definition: numbers.cc:109
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:149
static void ndCoeffWrite(const coeffs r, BOOLEAN)
Definition: numbers.cc:56
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition: numbers.cc:549
static number ndReturn0(number, const coeffs r)
Definition: numbers.cc:164
static number ndExtGcd(number, number, number *, number *, const coeffs r)
Definition: numbers.cc:273
static number ndQuotRem(number a, number b, number *r, const coeffs R)
Definition: numbers.cc:309
static char * ndCoeffName(const coeffs r)
Definition: numbers.cc:60
static void ndSetChar(const coeffs)
Definition: numbers.cc:266
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:522
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
Definition: numbers.cc:652
coeffs(* cfInitCfByNameProc)(char *s, n_coeffType n)
initialize an object of type coeffs by its name, return NULL otherwise
Definition: numbers.h:97
BOOLEAN(* cfInitCharProc)(coeffs, void *)
initialize an object of type coeff, return FALSE in case of success
Definition: numbers.h:93
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
#define omFree(addr)
Definition: omAllocDecl.h:261
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#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:770
BOOLEAN nrnInitChar(coeffs r, void *p)
Definition: rmodulon.cc:984
BOOLEAN nrInitChar(coeffs n, void *p)
Initialize r.
Definition: shortfl.cc:658
#define R
Definition: sirandom.c:27
BOOLEAN(* cfIsUnit)(number a, const coeffs r)
Definition: coeffs.h:378
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:297
number(* cfNormalizeHelper)(number a, number b, const coeffs r)
Definition: coeffs.h:271
int(* cfDivComp)(number a, number b, const coeffs r)
Definition: coeffs.h:377
BOOLEAN(*)(*)(*)(*)(*)(*) cfGreaterZero(number a, const coeffs r)
Definition: coeffs.h:237
number(* cfExtGcd)(number a, number b, number *s, number *t, const coeffs r)
Definition: coeffs.h:248
number(* cfGetUnit)(number a, const coeffs r)
Definition: coeffs.h:379
number(* cfLcm)(number a, number b, const coeffs r)
Definition: coeffs.h:270
number(* cfGetNumerator)(number &n, const coeffs r)
Definition: coeffs.h:241
number(* cfInvers)(number a, const coeffs r)
return 1/a
Definition: coeffs.h:197
number(* cfInit)(long i, const coeffs r)
init with an integer
Definition: coeffs.h:178
int iNumberOfParameters
Number of Parameters in the coeffs (default 0)
Definition: coeffs.h:319
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:195
number(* cfInitMPZ)(mpz_t i, const coeffs r)
init with a GMP integer
Definition: coeffs.h:181
BOOLEAN is_field
TRUE, if cf is a field.
Definition: coeffs.h:140
nMapFunc(* cfSetMap)(const coeffs src, const coeffs dst)
Definition: coeffs.h:275
number(* cfParameter)(const int i, const coeffs r)
create i^th parameter or NULL if not possible
Definition: coeffs.h:303
void(* cfSetChar)(const coeffs r)
Definition: coeffs.h:161
number(* convFactoryNSingN)(const CanonicalForm n, const coeffs r)
conversion to CanonicalForm(factory) to number
Definition: coeffs.h:315
number(* cfGcd)(number a, number b, const coeffs r)
Definition: coeffs.h:246
number(* cfImPart)(number a, const coeffs r)
Definition: coeffs.h:201
number(* cfFarey)(number p, number n, const coeffs)
rational reconstruction: "best" rational a/b with a/b = p mod n
Definition: coeffs.h:291
coeffs next
Definition: coeffs.h:125
number(* cfCopy)(number a, const coeffs r)
return a copy of a
Definition: coeffs.h:199
int ref
Definition: coeffs.h:126
BOOLEAN(*)(*)(*) cfIsZero(number a, const coeffs r)
Definition: coeffs.h:228
void(* cfKillChar)(coeffs r)
Definition: coeffs.h:159
BOOLEAN(*)(*) cfEqual(number a, number b, const coeffs r)
tests
Definition: coeffs.h:227
numberfunc cfIntMod
Definition: coeffs.h:175
numberfunc cfExactDiv
Definition: coeffs.h:175
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:190
BOOLEAN(* nCoeffIsEqual)(const coeffs r, n_coeffType n, void *parameter)
Definition: coeffs.h:145
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:208
number(* cfRePart)(number a, const coeffs r)
Definition: coeffs.h:200
void(* cfNormalize)(number &a, const coeffs r)
Definition: coeffs.h:223
numberfunc cfMult
Definition: coeffs.h:175
number(* cfGetDenom)(number &n, const coeffs r)
Definition: coeffs.h:240
void(* cfWriteLong)(number a, const coeffs r)
print a given number (long format)
Definition: coeffs.h:204
number(* cfSubringGcd)(number a, number b, const coeffs r)
Definition: coeffs.h:247
BOOLEAN(*)(*)(*)(*) cfIsOne(number a, const coeffs r)
Definition: coeffs.h:229
number(* cfAnn)(number a, const coeffs r)
Definition: coeffs.h:261
char *(* cfCoeffString)(const coeffs r)
string output of coeff description
Definition: coeffs.h:151
void(* cfPower)(number a, int i, number *result, const coeffs r)
Definition: coeffs.h:239
CanonicalForm(* convSingNFactoryN)(number n, BOOLEAN setChar, const coeffs r)
Definition: coeffs.h:316
long(* cfInt)(number &n, const coeffs r)
convertion to long, 0 if impossible
Definition: coeffs.h:187
BOOLEAN(* cfGreater)(number a, number b, const coeffs r)
Definition: coeffs.h:225
number(* cfQuotRem)(number a, number b, number *rem, const coeffs r)
Definition: coeffs.h:269
void(* cfCoeffWrite)(const coeffs r, BOOLEAN details)
output of coeff description via Print
Definition: coeffs.h:148
void(* cfDelete)(number *a, const coeffs r)
Definition: coeffs.h:272
numberfunc cfSub
Definition: coeffs.h:175
BOOLEAN(* cfDBTest)(number a, const char *f, const int l, const coeffs r)
Test: is "a" a correct number?
Definition: coeffs.h:415
n_coeffType type
Definition: coeffs.h:128
numberfunc cfAdd
Definition: coeffs.h:175
BOOLEAN(*)(*)(*)(*)(*) cfIsMOne(number a, const coeffs r)
Definition: coeffs.h:232
numberfunc cfDiv
Definition: coeffs.h:175
char const ** pParameterNames
array containing the names of Parameters (default NULL)
Definition: coeffs.h:322
char *(* cfCoeffName)(const coeffs r)
default name of cf, should substitue cfCoeffWrite, cfCoeffString
Definition: coeffs.h:154
int(* cfParDeg)(number x, const coeffs r)
degree for coeffcients: -1 for 0, 0 for "constants", ...
Definition: coeffs.h:300
void(* cfInpMult)(number &a, number b, const coeffs r)
Inplace: a *= b.
Definition: coeffs.h:281
int(* cfSize)(number n, const coeffs r)
how complicated, (0) => 0, or positive
Definition: coeffs.h:184
void(* cfInpAdd)(number &a, number b, const coeffs r)
Inplace: a += b.
Definition: coeffs.h:284
BOOLEAN(* cfDivBy)(number a, number b, const coeffs r)
Definition: coeffs.h:381
nCoeffsEnumeratorFunc cfClearContent
function pointer behind n_ClearContent
Definition: coeffs.h:309
nCoeffsEnumeratorFunc cfClearDenominators
function pointer behind n_ClearDenominators
Definition: coeffs.h:312
const char *(* cfRead)(const char *s, number *a, const coeffs r)
Definition: coeffs.h:221
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: transext.cc:2544