My Project
Data Structures | Functions | Variables
numbers.cc File Reference
#include <string.h>
#include <stdlib.h>
#include "misc/auxiliary.h"
#include "misc/mylimits.h"
#include "factory/factory.h"
#include "reporter/reporter.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/longrat.h"
#include "coeffs/modulop.h"
#include "coeffs/gnumpfl.h"
#include "coeffs/gnumpc.h"
#include "coeffs/ffields.h"
#include "coeffs/shortfl.h"
#include "coeffs/ntupel.h"
#include "coeffs/flintcf_Qrat.h"
#include "coeffs/rmodulo2m.h"
#include "coeffs/rmodulon.h"
#include "coeffs/rintegers.h"
#include "polys/ext_fields/algext.h"
#include "polys/ext_fields/transext.h"

Go to the source code of this file.

Data Structures

struct  nFindCoeffByName_p
 

Functions

void nNew (number *d)
 
static void ndDelete (number *d, const coeffs)
 
static number ndAnn (number, const coeffs)
 
static char * ndCoeffString (const coeffs r)
 
static void ndCoeffWrite (const coeffs r, BOOLEAN)
 
static char * ndCoeffName (const coeffs r)
 
static void ndInpMult (number &a, number b, const coeffs r)
 
static void ndInpAdd (number &a, number b, const coeffs r)
 
static void ndPower (number a, int i, number *res, const coeffs r)
 
static number ndInvers (number a, const coeffs r)
 
static BOOLEAN ndIsUnit (number a, const coeffs r)
 
static BOOLEAN ndDBTest (number, const char *, const int, const coeffs)
 
static number ndFarey (number, number, const coeffs r)
 
static number ndChineseRemainder (number *, number *, int, BOOLEAN, CFArray &, const coeffs r)
 
static int ndParDeg (number n, const coeffs r)
 
static number ndParameter (const int, const coeffs r)
 
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 implementation: should ONLY be used for debug stuff /tests. More...
 
static void ndNormalize (number &, const coeffs)
 
static number ndReturn0 (number, const coeffs r)
 
number ndGcd (number, number, const coeffs r)
 
static number ndIntMod (number, number, const coeffs r)
 
static number ndGetDenom (number &, const coeffs r)
 
static number ndGetNumerator (number &a, const coeffs r)
 
static int ndSize (number a, const coeffs r)
 
static void ndClearContent (ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
 
static void ndClearDenominators (ICoeffsEnumerator &, number &d, const coeffs r)
 
static number ndCopy (number a, const coeffs)
 
number ndCopyMap (number a, const coeffs aRing, const coeffs r)
 
static void ndKillChar (coeffs)
 
static void ndSetChar (const coeffs)
 
number nd_Copy (number a, const coeffs r)
 
static BOOLEAN ndDivBy (number, number, const coeffs)
 
static int ndDivComp (number, number, const coeffs)
 
static number ndExtGcd (number, number, number *, number *, const coeffs r)
 
CanonicalForm ndConvSingNFactoryN (number, BOOLEAN, const coeffs)
 
static number ndConvFactoryNSingN (const CanonicalForm, const coeffs)
 [in, out] a bigint number >= 0
More...
 
static void ndMPZ (mpz_t result, number &n, const coeffs r)
 Converts a non-negative bigint number into a GMP number. More...
 
static number ndInitMPZ (mpz_t m, const coeffs r)
 
static BOOLEAN ndCoeffIsEqual (const coeffs r, n_coeffType n, void *)
 
static number ndQuotRem (number a, number b, number *r, const coeffs R)
 
coeffs nInitChar (n_coeffType t, void *parameter)
 one-time initialisations for new coeffs in case of an error return NULL More...
 
void nKillChar (coeffs r)
 undo all initialisations More...
 
n_coeffType nRegister (n_coeffType n, cfInitCharProc p)
 
void nRegisterCfByName (cfInitCfByNameProc p, n_coeffType n)
 
coeffs nFindCoeffByName (char *cf_name)
 find an existing coeff by its "CoeffName" More...
 
void n_Print (number &a, const coeffs r)
 print a number (BEWARE of string buffers!) mostly for debugging More...
 
number n_convFactoryNSingN (const CanonicalForm n, const coeffs r)
 
CanonicalForm n_convSingNFactoryN (number n, BOOLEAN setChar, const coeffs r)
 
char * nEati (char *s, int *i, int m)
 divide by the first (leading) number and return it, i.e. make monic More...
 
char * nEatLong (char *s, mpz_ptr i)
 extracts a long integer from s, returns the rest More...
 

Variables

VAR n_Procs_scf_root =NULL
 
STATIC_VAR n_coeffType nLastCoeffs =n_CF
 
VAR cfInitCharProc nInitCharTableDefault []
 
STATIC_VAR cfInitCharProcnInitCharTable =nInitCharTableDefault
 
VAR nFindCoeffByName_p nFindCoeffByName_Root =NULL
 

Data Structure Documentation

◆ nFindCoeffByName_s

struct nFindCoeffByName_s

Definition at line 574 of file numbers.cc.

Data Fields
n_coeffType n
nFindCoeffByName_p next
cfInitCfByNameProc p

Function Documentation

◆ n_convFactoryNSingN()

number n_convFactoryNSingN ( const CanonicalForm  n,
const coeffs  r 
)

Definition at line 624 of file numbers.cc.

626 { STATISTIC(n_convFactoryNSingN); assume(r != NULL); assume(r->convFactoryNSingN != NULL); return r->convFactoryNSingN(n, r); }
#define assume(x)
Definition: mod2.h:387
number n_convFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: numbers.cc:624
#define STATISTIC(f)
Definition: numstats.h:16
#define NULL
Definition: omList.c:12

◆ n_convSingNFactoryN()

CanonicalForm n_convSingNFactoryN ( number  n,
BOOLEAN  setChar,
const coeffs  r 
)

Definition at line 629 of file numbers.cc.

631 { STATISTIC(n_convSingNFactoryN); assume(r != NULL); assume(r->convSingNFactoryN != NULL); return r->convSingNFactoryN(n, setChar, r); }
CanonicalForm n_convSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: numbers.cc:629

◆ n_IsZeroDivisor()

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 implementation: should ONLY be used for debug stuff /tests.

Definition at line 148 of file numbers.cc.

149 {
150  BOOLEAN ret = n_IsZero(a, r);
151  int c = n_GetChar(r);
152  if (ret || (c==0) || (r->is_field))
153  return ret; /*n_IsZero(a, r)*/
154  number ch = n_Init( c, r );
155  number g = n_Gcd( ch, a, r );
156  ret = !n_IsOne (g, r);
157  n_Delete(&ch, r);
158  n_Delete(&g, r);
159  return ret;
160 }
int BOOLEAN
Definition: auxiliary.h:87
g
Definition: cfModGcd.cc:4092
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:687
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:465
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:445
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:456
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:539
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:469

◆ n_Print()

void n_Print ( number &  a,
const coeffs  r 
)

print a number (BEWARE of string buffers!) mostly for debugging

Definition at line 613 of file numbers.cc.

615 {
616  assume(r != NULL);
617  n_Test(a,r);
618 
619  StringSetS("");
620  n_Write(a, r);
621  { char* s = StringEndS(); Print("%s", s); omFree(s); }
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:736
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:592
#define Print
Definition: emacs.cc:80
const CanonicalForm int s
Definition: facAbsFact.cc:51
#define omFree(addr)
Definition: omAllocDecl.h:261
void StringSetS(const char *st)
Definition: reporter.cc:128
char * StringEndS()
Definition: reporter.cc:151

◆ nd_Copy()

number nd_Copy ( number  a,
const coeffs  r 
)

Definition at line 267 of file numbers.cc.

267 { return r->cfCopy(a, r); }

◆ ndAnn()

static number ndAnn ( number  ,
const  coeffs 
)
static

Definition at line 55 of file numbers.cc.

55 { return NULL;}

◆ ndChineseRemainder()

static number ndChineseRemainder ( number *  ,
number *  ,
int  ,
BOOLEAN  ,
CFArray ,
const coeffs  r 
)
static

Definition at line 132 of file numbers.cc.

133 {
134  Werror("ChineseRemainder not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
135  return r->cfInit(0,r);
136 }
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ ndClearContent()

static void ndClearContent ( ICoeffsEnumerator numberCollectionEnumerator,
number &  c,
const coeffs  r 
)
static

TODO: move to a separate implementation

Definition at line 170 of file numbers.cc.

171 {
172  assume(r != NULL);
173 
174  // no fractions
175  assume(!( nCoeff_is_Q(r) ));
176  // all coeffs are given by integers!!!
177 
178  numberCollectionEnumerator.Reset();
179 
180  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
181  {
182  c = n_Init(1, r);
183  return;
184  }
185 
186  number &curr = numberCollectionEnumerator.Current();
187 
188 #ifdef HAVE_RINGS
189  /// TODO: move to a separate implementation
190  if (nCoeff_is_Ring(r))
191  {
192  if (nCoeff_has_Units(r))
193  {
194  c = n_GetUnit(curr, r);
195 
196  if (!n_IsOne(c, r))
197  {
198  number inv = n_Invers(c, r);
199 
200  n_InpMult(curr, inv, r);
201 
202  while( numberCollectionEnumerator.MoveNext() )
203  {
204  number &n = numberCollectionEnumerator.Current();
205  n_Normalize(n, r); // ?
206  n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
207  }
208 
209  n_Delete(&inv, r);
210  }
211  } else c = n_Init(1, r);
212 
213  return;
214  }
215 #endif
216 
217  assume(!nCoeff_is_Ring(r));
219 
220  n_Normalize(curr, r); // Q: good/bad/ugly??
221 
222  if (!n_IsOne(curr, r))
223  {
224  number t = curr; // takes over the curr! note: not a reference!!!
225 
226  curr = n_Init(1, r); // ???
227 
228  number inv = n_Invers(t, r);
229 
230  while( numberCollectionEnumerator.MoveNext() )
231  {
232  number &n = numberCollectionEnumerator.Current();
233  n_InpMult(n, inv, r); // TODO: either this or directly divide!!!?
234 // n_Normalize(n, r); // ?
235  }
236 
237  n_Delete(&inv, r);
238 
239  c = t;
240  } else
241  c = n_Copy(curr, r); // c == 1 and nothing else to do...
242 }
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...
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:452
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:821
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
Definition: coeffs.h:863
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:565
static FORCE_INLINE BOOLEAN nCoeff_is_numeric(const coeffs r)
Definition: coeffs.h:856
static FORCE_INLINE BOOLEAN nCoeff_is_Zp_a(const coeffs r)
Definition: coeffs.h:883
static FORCE_INLINE BOOLEAN nCoeff_is_Q_algext(const coeffs r)
is it an alg. ext. of Q?
Definition: coeffs.h:938
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:830
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:533
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
Definition: coeffs.h:754
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:824
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:642
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:579

◆ ndClearDenominators()

static void ndClearDenominators ( ICoeffsEnumerator ,
number &  d,
const coeffs  r 
)
static

Definition at line 244 of file numbers.cc.

245 {
246  assume( r != NULL );
249 
250  d = n_Init(1, r);
251 }
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
Definition: coeffs.h:934
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition: coeffs.h:942

◆ ndCoeffIsEqual()

static BOOLEAN ndCoeffIsEqual ( const coeffs  r,
n_coeffType  n,
void *   
)
static

Definition at line 301 of file numbers.cc.

303 {
304  /* test, if r is an instance of nInitCoeffs(n,parameter) */
305  /* if parameter is not needed */
306  return (n==r->type);

◆ ndCoeffName()

static char* ndCoeffName ( const coeffs  r)
static

Definition at line 64 of file numbers.cc.

65 {
66  STATIC_VAR char s[20];
67  snprintf(s,11,"Coeffs(%d)",r->type);
68  return s;
69 }
#define STATIC_VAR
Definition: globaldefs.h:7

◆ ndCoeffString()

static char* ndCoeffString ( const coeffs  r)
static

Definition at line 56 of file numbers.cc.

57 {
58  return omStrDup(r->cfCoeffName(r));
59 }
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ ndCoeffWrite()

static void ndCoeffWrite ( const coeffs  r,
BOOLEAN   
)
static

Definition at line 60 of file numbers.cc.

61 {
62  PrintS(r->cfCoeffName(r));
63 }
void PrintS(const char *s)
Definition: reporter.cc:284

◆ ndConvFactoryNSingN()

static number ndConvFactoryNSingN ( const  CanonicalForm,
const  coeffs 
)
static

[in, out] a bigint number >= 0

[out] the GMP equivalent

Definition at line 282 of file numbers.cc.

◆ ndConvSingNFactoryN()

CanonicalForm ndConvSingNFactoryN ( number  ,
BOOLEAN  ,
const  coeffs 
)

Definition at line 275 of file numbers.cc.

276 {
277  CanonicalForm term(0);
278  WerrorS("no conversion to factory");
279  return term;
280 }
factory's main class
Definition: canonicalform.h:86
Definition: int_poly.h:33
void WerrorS(const char *s)
Definition: feFopen.cc:24

◆ ndCopy()

static number ndCopy ( number  a,
const  coeffs 
)
static

Definition at line 253 of file numbers.cc.

253 { return a; }

◆ ndCopyMap()

number ndCopyMap ( number  a,
const coeffs  aRing,
const coeffs  r 
)

Definition at line 254 of file numbers.cc.

255 {
256  // aRing and r need not be the same, but must be the same representation
257  assume(aRing->rep==r->rep);
259  return a;
260  else
261  return r->cfCopy(a, r);
262 }
static FORCE_INLINE BOOLEAN nCoeff_has_simple_Alloc(const coeffs r)
TRUE if n_Delete/n_New are empty operations.
Definition: coeffs.h:930

◆ ndDBTest()

static BOOLEAN ndDBTest ( number  ,
const char *  ,
const int  ,
const  coeffs 
)
static

Definition at line 124 of file numbers.cc.

124 { return TRUE; }
#define TRUE
Definition: auxiliary.h:100

◆ ndDelete()

static void ndDelete ( number *  d,
const  coeffs 
)
static

Definition at line 54 of file numbers.cc.

54 { *d=NULL; }

◆ ndDivBy()

static BOOLEAN ndDivBy ( number  ,
number  ,
const  coeffs 
)
static

Definition at line 270 of file numbers.cc.

270 { return TRUE; } // assume a,b !=0

◆ ndDivComp()

static int ndDivComp ( number  ,
number  ,
const  coeffs 
)
static

Definition at line 271 of file numbers.cc.

271 { return 2; }

◆ ndExtGcd()

static number ndExtGcd ( number  ,
number  ,
number *  ,
number *  ,
const coeffs  r 
)
static

Definition at line 272 of file numbers.cc.

272 { return r->cfInit(1,r); }

◆ ndFarey()

static number ndFarey ( number  ,
number  ,
const coeffs  r 
)
static

Definition at line 127 of file numbers.cc.

128 {
129  Werror("farey not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
130  return NULL;
131 }

◆ ndGcd()

number ndGcd ( number  a,
number  b,
const coeffs  r 
)

Definition at line 164 of file numbers.cc.

164 { return r->cfInit(1,r); }

◆ ndGetDenom()

static number ndGetDenom ( number &  ,
const coeffs  r 
)
static

Definition at line 166 of file numbers.cc.

166 { return r->cfInit(1,r); }

◆ ndGetNumerator()

static number ndGetNumerator ( number &  a,
const coeffs  r 
)
static

Definition at line 167 of file numbers.cc.

167 { return r->cfCopy(a,r); }

◆ ndInitMPZ()

static number ndInitMPZ ( mpz_t  m,
const coeffs  r 
)
static

Definition at line 295 of file numbers.cc.

297 {
298  return r->cfInit( mpz_get_si(m), r);
int m
Definition: cfEzgcd.cc:128

◆ ndInpAdd()

static void ndInpAdd ( number &  a,
number  b,
const coeffs  r 
)
static

Definition at line 76 of file numbers.cc.

77 {
78  number n=r->cfAdd(a,b,r);
79  r->cfDelete(&a,r);
80  a=n;
81 }
CanonicalForm b
Definition: cfModGcd.cc:4105

◆ ndInpMult()

static void ndInpMult ( number &  a,
number  b,
const coeffs  r 
)
static

Definition at line 70 of file numbers.cc.

71 {
72  number n=r->cfMult(a,b,r);
73  r->cfDelete(&a,r);
74  a=n;
75 }

◆ ndIntMod()

static number ndIntMod ( number  ,
number  ,
const coeffs  r 
)
static

Definition at line 165 of file numbers.cc.

165 { return r->cfInit(0,r); }

◆ ndInvers()

static number ndInvers ( number  a,
const coeffs  r 
)
static

Definition at line 113 of file numbers.cc.

114 {
115  number one=r->cfInit(1,r);
116  number res=r->cfDiv(one,a,r);
117  r->cfDelete(&one,r);
118  return res;
119 }
CanonicalForm res
Definition: facAbsFact.cc:60

◆ ndIsUnit()

static BOOLEAN ndIsUnit ( number  a,
const coeffs  r 
)
static

Definition at line 121 of file numbers.cc.

121 { return !r->cfIsZero(a,r); }

◆ ndKillChar()

static void ndKillChar ( coeffs  )
static

Definition at line 264 of file numbers.cc.

264 {}

◆ ndMPZ()

static void ndMPZ ( mpz_t  result,
number &  n,
const coeffs  r 
)
static

Converts a non-negative bigint number into a GMP number.

Definition at line 290 of file numbers.cc.

292 {
293  mpz_init_set_si( result, r->cfInt(n, r) );
return result
Definition: facAbsBiFact.cc:75

◆ ndNormalize()

static void ndNormalize ( number &  ,
const  coeffs 
)
static

Definition at line 162 of file numbers.cc.

162 { }

◆ ndParameter()

static number ndParameter ( const int  ,
const coeffs  r 
)
static

Definition at line 143 of file numbers.cc.

144 {
145  return r->cfInit(1,r);
146 }

◆ ndParDeg()

static int ndParDeg ( number  n,
const coeffs  r 
)
static

Definition at line 138 of file numbers.cc.

139 {
140  return (-r->cfIsZero(n,r));
141 }

◆ ndPower()

static void ndPower ( number  a,
int  i,
number *  res,
const coeffs  r 
)
static

Definition at line 83 of file numbers.cc.

84 {
85  if (i==0)
86  {
87  *res = r->cfInit(1, r);
88  }
89  else if (i==1)
90  {
91  *res = r->cfCopy(a, r);
92  }
93  else if (i==2)
94  {
95  *res = r->cfMult(a, a, r);
96  }
97  else if (i<0)
98  {
99  number b = r->cfInvers(a, r);
100  ndPower(b, -i, res, r);
101  r->cfDelete(&b, r);
102  }
103  else
104  {
105  ndPower(a, i/2, res, r);
106  r->cfInpMult(*res, *res, r);
107  if (i&1)
108  {
109  r->cfInpMult(*res, a, r);
110  }
111  }
112 }
int i
Definition: cfEzgcd.cc:132
static void ndPower(number a, int i, number *res, const coeffs r)
Definition: numbers.cc:83

◆ ndQuotRem()

static number ndQuotRem ( number  a,
number  b,
number *  r,
const coeffs  R 
)
static

Definition at line 308 of file numbers.cc.

310 {
311  // implementation for a field: r: 0, result: n_Div
312  assume(R->is_field);
313  *r=n_Init(0,R);
314  return n_Div(a,b,R);
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:616
#define R
Definition: sirandom.c:27

◆ ndReturn0()

static number ndReturn0 ( number  ,
const coeffs  r 
)
static

Definition at line 163 of file numbers.cc.

163 { return r->cfInit(0,r); }

◆ ndSetChar()

static void ndSetChar ( const  coeffs)
static

Definition at line 265 of file numbers.cc.

265 {}

◆ ndSize()

static int ndSize ( number  a,
const coeffs  r 
)
static

Definition at line 168 of file numbers.cc.

168 { return (int)r->cfIsZero(a,r)==FALSE; }
#define FALSE
Definition: auxiliary.h:96

◆ nEati()

char* nEati ( char *  s,
int *  i,
int  m 
)

divide by the first (leading) number and return it, i.e. make monic

does nothing (just returns a dummy one number) helper routine: read an int from a string (mod m), return a pointer to the rest

Definition at line 633 of file numbers.cc.

635 {
636 
637  if (((*s) >= '0') && ((*s) <= '9'))
638  {
639  unsigned long ii=0L;
640  do
641  {
642  ii *= 10;
643  ii += *s++ - '0';
644  if ((m!=0) && (ii > (MAX_INT_VAL / 10))) ii = ii % m;
645  }
646  while (((*s) >= '0') && ((*s) <= '9'));
647  if ((m!=0) && (ii>=(unsigned)m)) ii=ii%m;
648  *i=(int)ii;
649  }
650  else (*i) = 1;
651  return s;
const int MAX_INT_VAL
Definition: mylimits.h:12

◆ nEatLong()

char* nEatLong ( char *  s,
mpz_ptr  i 
)

extracts a long integer from s, returns the rest

Definition at line 654 of file numbers.cc.

656 {
657  const char * start=s;
658 
659  while (*s >= '0' && *s <= '9') s++;
660  if (*s=='\0')
661  {
662  mpz_set_str(i,start,10);
663  }
664  else
665  {
666  char c=*s;
667  *s='\0';
668  mpz_set_str(i,start,10);
669  *s=c;
670  }
671  return s;

◆ nFindCoeffByName()

coeffs nFindCoeffByName ( char *  cf_name)

find an existing coeff by its "CoeffName"

Definition at line 591 of file numbers.cc.

593 {
594  n_Procs_s* n=cf_root;
595  // try existings coeffs:
596  while(n!=NULL)
597  {
598  if ((n->cfCoeffName!=NULL)
599  && (strcmp(cf_name,n->cfCoeffName(n))==0)) return n;
600  n=n->next;
601  }
602  // TODO: parametrized cf, e.g. flint:Z/26[a]
603  // try existing types:
604  nFindCoeffByName_p p=nFindCoeffByName_Root;
605  while(p!=NULL)
606  {
607  coeffs cf=p->p(cf_name,p->n);
608  if (cf!=NULL) return cf;
609  p=p->next;
610  }
611  return NULL;
int p
Definition: cfModGcd.cc:4080
CanonicalForm cf
Definition: cfModGcd.cc:4085
The main handler for Singular numbers which are suitable for Singular polynomials.
VAR nFindCoeffByName_p nFindCoeffByName_Root
Definition: numbers.cc:581
VAR n_Procs_s * cf_root
Definition: numbers.cc:49
char *(* cfCoeffName)(const coeffs r)
default name of cf, should substitue cfCoeffWrite, cfCoeffString
Definition: coeffs.h:155
coeffs next
Definition: coeffs.h:126

◆ nInitChar()

coeffs nInitChar ( n_coeffType  t,
void *  parameter 
)

one-time initialisations for new coeffs in case of an error return NULL

Definition at line 353 of file numbers.cc.

355 {
356  n_Procs_s *n=cf_root;
357 
358  while((n!=NULL) && (n->nCoeffIsEqual!=NULL) && (!n->nCoeffIsEqual(n,t,parameter)))
359  n=n->next;
360 
361  if (n==NULL)
362  {
363  n=(n_Procs_s*)omAlloc0(sizeof(n_Procs_s));
364  n->next=cf_root;
365  n->ref=1;
366  n->type=t;
367 
368  // default entries (different from NULL) for some routines:
370  n->cfSize = ndSize;
373  n->cfImPart=ndReturn0;
374  n->cfDelete= ndDelete;
375  n->cfAnn = ndAnn;
378  n->cfCoeffName = ndCoeffName; // should alway be changed!
379  n->cfInpMult=ndInpMult;
380  n->cfInpAdd=ndInpAdd;
381  n->cfCopy = ndCopy;
382  n->cfIntMod=ndIntMod; /* dummy !! */
384  n->cfGcd = ndGcd;
385  n->cfNormalizeHelper = ndGcd; /* tricky, isn't it ?*/
386  n->cfLcm = ndGcd; /* tricky, isn't it ?*/
387  n->cfInitMPZ = ndInitMPZ;
388  n->cfMPZ = ndMPZ;
389  n->cfPower = ndPower;
390  n->cfQuotRem = ndQuotRem;
391  n->cfInvers = ndInvers;
392 
393  n->cfKillChar = ndKillChar; /* dummy */
394  n->cfSetChar = ndSetChar; /* dummy */
395  // temp. removed to catch all the coeffs which miss to implement this!
396 
398  n->cfFarey = ndFarey;
399  n->cfParDeg = ndParDeg;
400 
402 
405 
406  n->cfIsUnit = ndIsUnit;
407 #ifdef HAVE_RINGS
408  n->cfDivComp = ndDivComp;
409  n->cfDivBy = ndDivBy;
410  n->cfExtGcd = ndExtGcd;
411  //n->cfGetUnit = (nMapFunc)NULL;
412 #endif
413 
414 #ifdef LDEBUG
415  n->cfDBTest=ndDBTest;
416 #endif
417 
420 
421  BOOLEAN nOK=TRUE;
422  // init
423  if ((t<=nLastCoeffs) && (nInitCharTable[t]!=NULL))
424  nOK = (nInitCharTable[t])(n,parameter);
425  else
426  Werror("Sorry: the coeff type [%d] was not registered: it is missing in nInitCharTable", (int)t);
427  if (nOK)
428  {
429  omFreeSize(n,sizeof(*n));
430  return NULL;
431  }
432  cf_root=n;
433  // post init settings:
434  if (n->cfRePart==NULL) n->cfRePart=n->cfCopy;
435  if (n->cfExactDiv==NULL) n->cfExactDiv=n->cfDiv;
436  if (n->cfSubringGcd==NULL) n->cfSubringGcd=n->cfGcd;
437 
438 #ifdef HAVE_RINGS
439  if (n->cfGetUnit==NULL) n->cfGetUnit=n->cfCopy;
440 #endif
441 
442  if(n->cfWriteShort==NULL)
443  n->cfWriteShort = n->cfWriteLong;
444 
446  assume(n->cfSetChar!=NULL);
448  assume(n->cfMult!=NULL);
449  assume(n->cfSub!=NULL);
450  assume(n->cfAdd!=NULL);
451  assume(n->cfDiv!=NULL);
452  assume(n->cfIntMod!=NULL);
453  assume(n->cfExactDiv!=NULL);
454  assume(n->cfInit!=NULL);
455  assume(n->cfInitMPZ!=NULL);
456  assume(n->cfSize!=NULL);
457  assume(n->cfInt!=NULL);
458  assume(n->cfMPZ!=NULL);
459  //assume(n->n->cfDivComp!=NULL);
460  //assume(n->cfIsUnit!=NULL);
461  //assume(n->cfGetUnit!=NULL);
462  //assume(n->cfExtGcd!=NULL);
463  assume(n->cfInpNeg!=NULL);
464  assume(n->cfCopy!=NULL);
465 
466  assume(n->cfWriteLong!=NULL);
467  assume(n->cfWriteShort!=NULL);
468 
469  assume(n->iNumberOfParameters>= 0);
470 
471  assume( (n->iNumberOfParameters == 0 && n->pParameterNames == NULL) ||
472  (n->iNumberOfParameters > 0 && n->pParameterNames != NULL) );
473 
474  assume(n->cfParameter!=NULL);
475  assume(n->cfParDeg!=NULL);
476 
477  assume(n->cfRead!=NULL);
478  assume(n->cfNormalize!=NULL);
479  assume(n->cfGreater!=NULL);
480  //assume(n->cfDivBy!=NULL);
481  assume(n->cfEqual!=NULL);
482  assume(n->cfIsZero!=NULL);
483  assume(n->cfIsOne!=NULL);
484  assume(n->cfIsMOne!=NULL);
486  assume(n->cfGetDenom!=NULL);
488  assume(n->cfGcd!=NULL);
490  assume(n->cfDelete!=NULL);
491  assume(n->cfSetMap!=NULL);
492  assume(n->cfInpMult!=NULL);
493 // assume(n->cfInit_bigint!=NULL);
494  assume(n->cfCoeffWrite != NULL);
495 
496  assume(n->cfClearContent != NULL);
498 
499  assume(n->type==t);
500 
501 #ifndef SING_NDEBUG
502  if(n->cfKillChar==NULL) Warn("cfKillChar is NULL for coeff %d",t);
503  if(n->cfWriteLong==NULL) Warn("cfWrite is NULL for coeff %d",t);
504  if(n->cfWriteShort==NULL) Warn("cfWriteShort is NULL for coeff %d",t);
505 #endif
506  }
507  else
508  {
509  n->ref++;
510  }
511  return n;
#define Warn
Definition: emacs.cc:77
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
Definition: numbers.cc:275
static int ndDivComp(number, number, const coeffs)
Definition: numbers.cc:271
static BOOLEAN ndDBTest(number, const char *, const int, const coeffs)
Definition: numbers.cc:124
number ndGcd(number, number, const coeffs r)
Definition: numbers.cc:164
static void ndKillChar(coeffs)
Definition: numbers.cc:264
static number ndConvFactoryNSingN(const CanonicalForm, const coeffs)
[in, out] a bigint number >= 0
Definition: numbers.cc:282
static void ndClearDenominators(ICoeffsEnumerator &, number &d, const coeffs r)
Definition: numbers.cc:244
static void ndClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
Definition: numbers.cc:170
static int ndParDeg(number n, const coeffs r)
Definition: numbers.cc:138
static BOOLEAN ndCoeffIsEqual(const coeffs r, n_coeffType n, void *)
Definition: numbers.cc:301
static char * ndCoeffString(const coeffs r)
Definition: numbers.cc:56
static char * ndCoeffName(const coeffs r)
Definition: numbers.cc:64
static void ndNormalize(number &, const coeffs)
Definition: numbers.cc:162
static int ndSize(number a, const coeffs r)
Definition: numbers.cc:168
static number ndIntMod(number, number, const coeffs r)
Definition: numbers.cc:165
static number ndFarey(number, number, const coeffs r)
Definition: numbers.cc:127
static void ndMPZ(mpz_t result, number &n, const coeffs r)
Converts a non-negative bigint number into a GMP number.
Definition: numbers.cc:290
STATIC_VAR n_coeffType nLastCoeffs
Definition: numbers.cc:315
static number ndAnn(number, const coeffs)
Definition: numbers.cc:55
static number ndGetDenom(number &, const coeffs r)
Definition: numbers.cc:166
static void ndDelete(number *d, const coeffs)
Definition: numbers.cc:54
STATIC_VAR cfInitCharProc * nInitCharTable
Definition: numbers.cc:349
static number ndParameter(const int, const coeffs r)
Definition: numbers.cc:143
static number ndCopy(number a, const coeffs)
Definition: numbers.cc:253
static void ndInpMult(number &a, number b, const coeffs r)
Definition: numbers.cc:70
static number ndChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs r)
Definition: numbers.cc:132
static number ndGetNumerator(number &a, const coeffs r)
Definition: numbers.cc:167
static BOOLEAN ndDivBy(number, number, const coeffs)
Definition: numbers.cc:270
static BOOLEAN ndIsUnit(number a, const coeffs r)
Definition: numbers.cc:121
static number ndInitMPZ(mpz_t m, const coeffs r)
Definition: numbers.cc:295
static void ndInpAdd(number &a, number b, const coeffs r)
Definition: numbers.cc:76
static number ndInvers(number a, const coeffs r)
Definition: numbers.cc:113
static void ndCoeffWrite(const coeffs r, BOOLEAN)
Definition: numbers.cc:60
static number ndReturn0(number, const coeffs r)
Definition: numbers.cc:163
static number ndExtGcd(number, number, number *, number *, const coeffs r)
Definition: numbers.cc:272
static number ndQuotRem(number a, number b, number *r, const coeffs R)
Definition: numbers.cc:308
static void ndSetChar(const coeffs)
Definition: numbers.cc:265
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc0(size)
Definition: omAllocDecl.h:211
BOOLEAN(* cfIsUnit)(number a, const coeffs r)
Definition: coeffs.h:379
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:298
number(* cfNormalizeHelper)(number a, number b, const coeffs r)
Definition: coeffs.h:272
int(* cfDivComp)(number a, number b, const coeffs r)
Definition: coeffs.h:378
BOOLEAN(*)(*)(*)(*)(*)(*) cfGreaterZero(number a, const coeffs r)
Definition: coeffs.h:238
number(* cfExtGcd)(number a, number b, number *s, number *t, const coeffs r)
Definition: coeffs.h:249
number(* cfGetUnit)(number a, const coeffs r)
Definition: coeffs.h:380
number(* cfLcm)(number a, number b, const coeffs r)
Definition: coeffs.h:271
number(* cfGetNumerator)(number &n, const coeffs r)
Definition: coeffs.h:242
number(* cfInvers)(number a, const coeffs r)
return 1/a
Definition: coeffs.h:198
number(* cfInit)(long i, const coeffs r)
init with an integer
Definition: coeffs.h:179
int iNumberOfParameters
Number of Parameters in the coeffs (default 0)
Definition: coeffs.h:320
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:196
number(* cfInitMPZ)(mpz_t i, const coeffs r)
init with a GMP integer
Definition: coeffs.h:182
nMapFunc(* cfSetMap)(const coeffs src, const coeffs dst)
Definition: coeffs.h:276
number(* cfParameter)(const int i, const coeffs r)
create i^th parameter or NULL if not possible
Definition: coeffs.h:304
void(* cfSetChar)(const coeffs r)
Definition: coeffs.h:162
number(* convFactoryNSingN)(const CanonicalForm n, const coeffs r)
conversion to CanonicalForm(factory) to number
Definition: coeffs.h:316
number(* cfGcd)(number a, number b, const coeffs r)
Definition: coeffs.h:247
number(* cfImPart)(number a, const coeffs r)
Definition: coeffs.h:202
number(* cfFarey)(number p, number n, const coeffs)
rational reconstruction: "best" rational a/b with a/b = p mod n
Definition: coeffs.h:292
number(* cfCopy)(number a, const coeffs r)
return a copy of a
Definition: coeffs.h:200
int ref
Definition: coeffs.h:127
BOOLEAN(*)(*)(*) cfIsZero(number a, const coeffs r)
Definition: coeffs.h:229
void(* cfKillChar)(coeffs r)
Definition: coeffs.h:160
BOOLEAN(*)(*) cfEqual(number a, number b, const coeffs r)
tests
Definition: coeffs.h:228
numberfunc cfIntMod
Definition: coeffs.h:176
numberfunc cfExactDiv
Definition: coeffs.h:176
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:191
BOOLEAN(* nCoeffIsEqual)(const coeffs r, n_coeffType n, void *parameter)
Definition: coeffs.h:146
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:209
number(* cfRePart)(number a, const coeffs r)
Definition: coeffs.h:201
void(* cfNormalize)(number &a, const coeffs r)
Definition: coeffs.h:224
numberfunc cfMult
Definition: coeffs.h:176
char *(* cfCoeffString)(const coeffs r)
string output of coeff description
Definition: coeffs.h:152
number(* cfGetDenom)(number &n, const coeffs r)
Definition: coeffs.h:241
void(* cfWriteLong)(number a, const coeffs r)
print a given number (long format)
Definition: coeffs.h:205
number(* cfSubringGcd)(number a, number b, const coeffs r)
Definition: coeffs.h:248
BOOLEAN(*)(*)(*)(*) cfIsOne(number a, const coeffs r)
Definition: coeffs.h:230
number(* cfAnn)(number a, const coeffs r)
Definition: coeffs.h:262
void(* cfPower)(number a, int i, number *result, const coeffs r)
Definition: coeffs.h:240
CanonicalForm(* convSingNFactoryN)(number n, BOOLEAN setChar, const coeffs r)
Definition: coeffs.h:317
long(* cfInt)(number &n, const coeffs r)
convertion to long, 0 if impossible
Definition: coeffs.h:188
BOOLEAN(* cfGreater)(number a, number b, const coeffs r)
Definition: coeffs.h:226
number(* cfQuotRem)(number a, number b, number *rem, const coeffs r)
Definition: coeffs.h:270
void(* cfCoeffWrite)(const coeffs r, BOOLEAN details)
output of coeff description via Print
Definition: coeffs.h:149
void(* cfDelete)(number *a, const coeffs r)
Definition: coeffs.h:273
numberfunc cfSub
Definition: coeffs.h:176
BOOLEAN(* cfDBTest)(number a, const char *f, const int l, const coeffs r)
Test: is "a" a correct number?
Definition: coeffs.h:416
n_coeffType type
Definition: coeffs.h:129
numberfunc cfAdd
Definition: coeffs.h:176
BOOLEAN(*)(*)(*)(*)(*) cfIsMOne(number a, const coeffs r)
Definition: coeffs.h:233
numberfunc cfDiv
Definition: coeffs.h:176
char const ** pParameterNames
array containing the names of Parameters (default NULL)
Definition: coeffs.h:323
int(* cfParDeg)(number x, const coeffs r)
degree for coeffcients: -1 for 0, 0 for "constants", ...
Definition: coeffs.h:301
void(* cfInpMult)(number &a, number b, const coeffs r)
Inplace: a *= b.
Definition: coeffs.h:282
int(* cfSize)(number n, const coeffs r)
how complicated, (0) => 0, or positive
Definition: coeffs.h:185
const char *(* cfRead)(const char *s, number *a, const coeffs r)
Definition: coeffs.h:222
void(* cfInpAdd)(number &a, number b, const coeffs r)
Inplace: a += b.
Definition: coeffs.h:285
BOOLEAN(* cfDivBy)(number a, number b, const coeffs r)
Definition: coeffs.h:382
nCoeffsEnumeratorFunc cfClearContent
function pointer behind n_ClearContent
Definition: coeffs.h:310
nCoeffsEnumeratorFunc cfClearDenominators
function pointer behind n_ClearDenominators
Definition: coeffs.h:313

◆ nKillChar()

void nKillChar ( coeffs  r)

undo all initialisations

Definition at line 513 of file numbers.cc.

515 {
517  if (r!=NULL)
518  {
519  r->ref--;
520  if (r->ref<=0)
521  {
522  n_Procs_s tmp;
523  n_Procs_s* n=&tmp;
524  tmp.next=cf_root;
525  while((n->next!=NULL) && (n->next!=r)) n=n->next;
526  if (n->next==r)
527  {
528  n->next=n->next->next;
529  if (cf_root==r) cf_root=n->next;
530  assume (r->cfKillChar!=NULL); r->cfKillChar(r); // STATISTIC(nKillChar);
531  omFreeSize((void *)r, sizeof(n_Procs_s));
532  r=NULL;
533  }
534  else
535  {
536  WarnS("cf_root list destroyed");
537  }
538  }
539  }
#define WarnS
Definition: emacs.cc:78
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:513

◆ nNew()

void nNew ( number *  d)

Definition at line 51 of file numbers.cc.

51 { *d=NULL; }

◆ nRegister()

n_coeffType nRegister ( n_coeffType  n,
cfInitCharProc  p 
)

Definition at line 541 of file numbers.cc.

543 {
544  if (n==n_unknown)
545  {
548  {
550  ((int)nLastCoeffs+1)*sizeof(cfInitCharProc));
552  ((int)nLastCoeffs)*sizeof(cfInitCharProc));
553  }
554  else
555  {
557  ((int)nLastCoeffs)*sizeof(cfInitCharProc),
558  (((int)nLastCoeffs)+1)*sizeof(cfInitCharProc));
559  }
560 
562  return nLastCoeffs;
563  }
564  else
565  {
566  if (nInitCharTable[n]!=NULL) Print("coeff %d already initialized\n",n);
567  nInitCharTable[n]=p;
568  return n;
569  }
n_coeffType
Definition: coeffs.h:28
@ n_unknown
Definition: coeffs.h:29
VAR cfInitCharProc nInitCharTableDefault[]
Definition: numbers.cc:316
BOOLEAN(* cfInitCharProc)(coeffs, void *)
initialize an object of type coeff, return FALSE in case of success
Definition: numbers.h:93
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220

◆ nRegisterCfByName()

void nRegisterCfByName ( cfInitCfByNameProc  p,
n_coeffType  n 
)

Definition at line 582 of file numbers.cc.

584 {
585  nFindCoeffByName_p h=(nFindCoeffByName_p)omAlloc0(sizeof(*h));
586  h->p=p;
587  h->n=n;
588  h->next=nFindCoeffByName_Root;
STATIC_VAR Poly * h
Definition: janet.cc:971

Variable Documentation

◆ cf_root

VAR n_Procs_s* cf_root =NULL

Definition at line 49 of file numbers.cc.

◆ nFindCoeffByName_Root

VAR nFindCoeffByName_p nFindCoeffByName_Root =NULL

Definition at line 581 of file numbers.cc.

◆ nInitCharTable

Definition at line 349 of file numbers.cc.

◆ nInitCharTableDefault

VAR cfInitCharProc nInitCharTableDefault[]

Definition at line 316 of file numbers.cc.

◆ nLastCoeffs

STATIC_VAR n_coeffType nLastCoeffs =n_CF

Definition at line 315 of file numbers.cc.