Changeset 17e473 in git


Ignore:
Timestamp:
Apr 20, 2011, 9:43:24 PM (12 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
03bf555de3ab718b020a7fd0a086b5c2e493dbd0
Parents:
1ddd044275ba5d4433a597ff9edee1abfce81a0e
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-04-20 21:43:24+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:31:23+01:00
Message:
FIX: we can link against libpolys
FIX: rField_*(r...) all should call corresponding nCoeff_*(r->cf...)
ADD: first tests of polynomial rings

TODO for Frank: change ring.* wrt ring-related variables (moved to coeffs &&& renamed!)
TODO: poly. algs. over rings are UNusable at the moment
Location:
libpolys
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/coeffs.h

    r1ddd04 r17e473  
    207207static inline n_coeffType getCoeffType(const coeffs r)
    208208{
     209  assume(r != NULL);
    209210  return r->type;
    210211}
    211212
    212 /// returns true for coeffs being a domain
    213 static inline bool nField_is_Domain(const coeffs r)
    214 {
    215 #ifdef HAVE_RINGS
    216   return (r->ringtype == 4 || r->ringtype == 0);
    217 #else
    218   return true;
    219 #endif
    220 }
    221 
    222 
    223213static inline int nInternalChar(const coeffs r)
    224214{
     215  assume(r != NULL);
    225216  return r->ch;
    226217}
     
    248239/// return a copy of a
    249240static inline number n_Copy(number n,    const coeffs r)
    250 { return r->cfCopy(n, r); }
     241{   assume(r != NULL); return r->cfCopy(n, r); }
    251242
    252243static inline void   n_Delete(number* p, const coeffs r)
    253 { r->cfDelete(p, r); }
     244{   assume(r != NULL); r->cfDelete(p, r); }
    254245
    255246static inline BOOLEAN n_Equal(number a, number b, const coeffs r)
    256 { return r->cfEqual(a, b, r); }
     247{ assume(r != NULL); return r->cfEqual(a, b, r); }
    257248
    258249static inline BOOLEAN n_IsZero(number n, const coeffs r)
    259 { return r->cfIsZero(n,r); }
     250{ assume(r != NULL); return r->cfIsZero(n,r); }
    260251
    261252static inline BOOLEAN n_IsOne(number n,  const coeffs r)
    262 { return r->cfIsOne(n,r); }
     253{ assume(r != NULL); return r->cfIsOne(n,r); }
    263254
    264255static inline BOOLEAN n_IsMOne(number n, const coeffs r)
    265 { return r->cfIsMOne(n,r); }
     256{ assume(r != NULL); return r->cfIsMOne(n,r); }
    266257
    267258static inline BOOLEAN n_GreaterZero(number n, const coeffs r)
    268 { return r->cfGreaterZero(n,r); }
     259{ assume(r != NULL); return r->cfGreaterZero(n,r); }
    269260// cfGreater?
    270261
    271262#ifdef HAVE_RINGS
    272263static inline BOOLEAN n_IsUnit(number n, const coeffs r)
    273 { return r->cfIsUnit(n,r); }
     264{ assume(r != NULL); return r->cfIsUnit(n,r); }
    274265
    275266static inline number n_GetUnit(number n, const coeffs r)
    276 { return r->cfGetUnit(n,r); }
     267{ assume(r != NULL); return r->cfGetUnit(n,r); }
    277268
    278269static inline BOOLEAN n_DivBy(number a, number b, const coeffs r)
    279 { return r->cfDivBy(a,b,r); }
     270{ assume(r != NULL); return r->cfDivBy(a,b,r); }
    280271#endif
    281272
    282273/// init with an integer
    283274static inline number n_Init(int i,       const coeffs r)
    284 { return r->cfInit(i,r); }
     275{ assume(r != NULL); return r->cfInit(i,r); }
    285276
    286277/// changes argument  inline: a:= -a
    287278static inline number n_Neg(number n,     const coeffs r)
    288 { return r->cfNeg(n,r); }
     279{ assume(r != NULL); return r->cfNeg(n,r); }
    289280
    290281/// return 1/a
    291282static inline number n_Invers(number a,  const coeffs r)
    292 { return r->cfInvers(a,r); }
     283{ assume(r != NULL); return r->cfInvers(a,r); }
    293284
    294285/// use for pivot strategies, (0) => 0, otherwise positive
    295286static inline int    n_Size(number n,    const coeffs r)
    296 { return r->cfSize(n,r); }
     287{ assume(r != NULL); return r->cfSize(n,r); }
    297288
    298289/// normalize the number. i.e. go to some canonnical representation (inplace)
    299290static inline void   n_Normalize(number& n, const coeffs r)
    300 { return r->cfNormalize(n,r); }
     291{ assume(r != NULL); return r->cfNormalize(n,r); }
    301292
    302293/// Normalize and Write to the output buffer of reporter
    303294static inline void   n_Write(number& n,  const coeffs r)
    304 { return r->cfWrite(n,r); }
     295{ assume(r != NULL); return r->cfWrite(n,r); }
    305296
    306297/// Normalize and get denomerator
    307298static inline number n_GetDenom(number& n, const coeffs r)
    308 { return r->cfGetDenom(n, r); }
     299{ assume(r != NULL); return r->cfGetDenom(n, r); }
    309300
    310301/// Normalize and get numerator
    311302static inline number n_GetNumerator(number& n, const coeffs r)
    312 { return r->cfGetNumerator(n, r); }
     303{ assume(r != NULL); return r->cfGetNumerator(n, r); }
    313304
    314305static inline void   n_Power(number a, int b, number *res, const coeffs r)
    315 { r->cfPower(a,b,res,r); }
     306{ assume(r != NULL); r->cfPower(a,b,res,r); }
    316307
    317308static inline number n_Mult(number a, number b, const coeffs r)
    318 { return r->cfMult(a, b, r); }
     309{ assume(r != NULL); return r->cfMult(a, b, r); }
    319310
    320311/// Inplace multiplication: a := a * b
    321312static inline void n_InpMult(number &a, number b, const coeffs r)
    322 { r->cfInpMult(a,b,r); }
     313{ assume(r != NULL); r->cfInpMult(a,b,r); }
    323314
    324315static inline number n_Sub(number a, number b, const coeffs r)
    325 { return r->cfSub(a, b, r); }
     316{ assume(r != NULL); return r->cfSub(a, b, r); }
    326317
    327318static inline number n_Add(number a, number b, const coeffs r)
    328 { return r->cfAdd(a, b, r); }
     319{ assume(r != NULL); return r->cfAdd(a, b, r); }
    329320
    330321static inline number n_Div(number a, number b, const coeffs r)
    331 { return r->cfDiv(a,b,r); }
     322{ assume(r != NULL); return r->cfDiv(a,b,r); }
    332323
    333324static inline number n_IntDiv(number a, number b, const coeffs r)
    334 { return r->cfIntDiv(a,b,r); }
     325{ assume(r != NULL); return r->cfIntDiv(a,b,r); }
    335326
    336327static inline number n_ExactDiv(number a, number b, const coeffs r)
    337 { return r->cfExactDiv(a,b,r); }
     328{ assume(r != NULL); return r->cfExactDiv(a,b,r); }
    338329
    339330static inline number n_Gcd(number a, number b, const coeffs r)
    340 { return r->cfGcd(a,b,r); }
     331{ assume(r != NULL); return r->cfGcd(a,b,r); }
    341332
    342333static inline number n_Lcm(number a, number b, const coeffs r)
    343 { return r->cfLcm(a,b,r); }
     334{ assume(r != NULL); return r->cfLcm(a,b,r); }
    344335
    345336static inline nMapFunc n_SetMap(const coeffs src, const coeffs dst)
    346 { return dst->cfSetMap(src,dst); }
     337{ assume(src != NULL && dst != NULL); return dst->cfSetMap(src,dst); }
    347338
    348339static inline number n_Par(int n, const coeffs r)
    349 { return r->cfPar(n,r); }
     340{ assume(r != NULL); return r->cfPar(n,r); }
    350341
    351342static inline int n_ParDeg(number n, const coeffs r)
    352 { return r->cfParDeg(n,r); }
     343{ assume(r != NULL); return r->cfParDeg(n,r); }
    353344
    354345/// Tests whether n is a correct number: only used if LDEBUG is defined
    355346static inline BOOLEAN n_DBTest(number n, const char *filename, const int linenumber, const coeffs r)
    356347{
     348  assume(r != NULL);
    357349#ifdef LDEBUG
    358350  return (r)->cfDBTest(n, filename, linenumber, r);
     
    364356// Tests:
    365357static inline BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
    366 { return (r->ringtype == 1); }
     358{ assume(r != NULL); return (r->ringtype == 1); }
    367359
    368360static inline BOOLEAN nCoeff_is_Ring_ModN(const coeffs r)
    369 { return (r->ringtype == 2); }
     361{ assume(r != NULL); return (r->ringtype == 2); }
    370362
    371363static inline BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
    372 { return (r->ringtype == 3); }
     364{ assume(r != NULL); return (r->ringtype == 3); }
    373365
    374366static inline BOOLEAN nCoeff_is_Ring_Z(const coeffs r)
    375 { return (r->ringtype == 4); }
     367{ assume(r != NULL); return (r->ringtype == 4); }
    376368
    377369static inline BOOLEAN nCoeff_is_Ring(const coeffs r)
    378 { return (r->ringtype != 0); }
     370{ assume(r != NULL); return (r->ringtype != 0); }
    379371
    380372/// returns TRUE, if r is not a field and r has no zero divisors (i.e is a domain)
    381373static inline BOOLEAN nCoeff_is_Domain(const coeffs r)
    382 { return (r->ringtype == 4 || r->ringtype == 0); }
     374{
     375  assume(r != NULL);
     376#ifdef HAVE_RINGS
     377  return (r->ringtype == 4 || r->ringtype == 0);
     378#else
     379  return TRUE;
     380#endif
     381}
    383382
    384383/// returns TRUE, if r is not a field and r has non-trivial units
    385384static inline BOOLEAN nCoeff_has_Units(const coeffs r)
    386 { return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); }
     385{ assume(r != NULL); return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); }
    387386
    388387static inline BOOLEAN nCoeff_is_Zp(const coeffs r)
    389 { return getCoeffType(r)==n_Zp; }
     388{ assume(r != NULL); return getCoeffType(r)==n_Zp; }
    390389
    391390static inline BOOLEAN nCoeff_is_Zp(const coeffs r, int p)
    392 { return (getCoeffType(r)  && (r->ch == ABS(p))); }
     391{ assume(r != NULL); return (getCoeffType(r)  && (r->ch == ABS(p))); }
    393392
    394393static inline BOOLEAN nCoeff_is_Q(const coeffs r)
    395 { return getCoeffType(r)==n_Q; }
     394{ assume(r != NULL); return getCoeffType(r)==n_Q; }
    396395
    397396static inline BOOLEAN nCoeff_is_numeric(const coeffs r) /* R, long R, long C */
    398 {  return (getCoeffType(r)==n_R) || (getCoeffType(r)==n_long_R) || (getCoeffType(r)==n_long_C); }
     397{ assume(r != NULL);  return (getCoeffType(r)==n_R) || (getCoeffType(r)==n_long_R) || (getCoeffType(r)==n_long_C); }
     398// (r->ringtype == 0) && (r->ch ==  -1); ??
     399
    399400
    400401static inline BOOLEAN nCoeff_is_R(const coeffs r)
    401 { return getCoeffType(r)==n_R; }
     402{ assume(r != NULL); return getCoeffType(r)==n_R; }
    402403
    403404static inline BOOLEAN nCoeff_is_GF(const coeffs r)
    404 { return getCoeffType(r)==n_GF; }
     405{ assume(r != NULL); return getCoeffType(r)==n_GF; }
    405406
    406407static inline BOOLEAN nCoeff_is_GF(const coeffs r, int q)
    407 { return (getCoeffType(r)==n_GF) && (r->ch == q); }
     408{ assume(r != NULL); return (getCoeffType(r)==n_GF) && (r->ch == q); }
    408409
    409410static inline BOOLEAN nCoeff_is_Zp_a(const coeffs r)
    410 { return (r->ringtype == 0) && (r->ch < -1); }
     411{ assume(r != NULL); return (r->ringtype == 0) && (r->ch < -1); }
    411412
    412413static inline BOOLEAN nCoeff_is_Zp_a(const coeffs r, int p)
    413 { return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
     414{ assume(r != NULL); return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
    414415
    415416static inline BOOLEAN nCoeff_is_Q_a(const coeffs r)
    416 { return (r->ringtype == 0) && (r->ch == 1); }
     417{ assume(r != NULL); return (r->ringtype == 0) && (r->ch == 1); }
    417418
    418419static inline BOOLEAN nCoeff_is_long_R(const coeffs r)
    419 { return getCoeffType(r)==n_long_R; }
     420{ assume(r != NULL); return getCoeffType(r)==n_long_R; }
    420421
    421422static inline BOOLEAN nCoeff_is_long_C(const coeffs r)
    422 { return getCoeffType(r)==n_long_C; }
     423{ assume(r != NULL); return getCoeffType(r)==n_long_C; }
    423424
    424425static inline BOOLEAN nCoeff_is_CF(const coeffs r)
    425 { return getCoeffType(r)==n_CF; }
     426{ assume(r != NULL); return getCoeffType(r)==n_CF; }
    426427
    427428/// TRUE, if the computation of the inverse is fast (i.e. prefer leading coeff. 1 over content)
    428429static inline BOOLEAN nCoeff_has_simple_inverse(const coeffs r)
    429 { return r->has_simple_Inverse; }
     430{ assume(r != NULL); return r->has_simple_Inverse; }
    430431/* Z/2^n, Z/p, GF(p,n), R, long_R, long_C*/
     432// /* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/
     433// #ifdef HAVE_RINGS
     434// { return (r->ringtype > 0) || (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/2^n, Z/p, GF(p,n), R, long_R, long_C*/
     435// #else
     436// { return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/
     437// #endif
     438
     439
    431440
    432441/// TRUE if n_Delete/n_New are empty operations
    433442static inline BOOLEAN nCoeff_has_simple_Alloc(const coeffs r)
    434 { return r->has_simple_Alloc; }
     443{ assume(r != NULL); return r->has_simple_Alloc; }
    435444/* Z/p, GF(p,n), R, Ring_2toM: nCopy, nNew, nDelete are dummies*/
     445// return (rField_is_Zp(r)
     446//         || rField_is_GF(r)
     447// #ifdef HAVE_RINGS
     448//             || rField_is_Ring_2toM(r)
     449// #endif
     450//             || rField_is_R(r)); }
     451
    436452
    437453static inline BOOLEAN nCoeff_is_Extension(const coeffs r)
    438 { return (nCoeff_is_Q_a(r)) || (nCoeff_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/
     454{ assume(r != NULL); return (nCoeff_is_Q_a(r)) || (nCoeff_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/
    439455
    440456/// BOOLEAN n_Test(number a, const coeffs r)
     
    448464// Deprecated:
    449465static inline int n_GetChar(const coeffs r)
    450 { return nInternalChar(r); }
    451 
    452 
    453 
    454 #endif
    455 
     466{ assume(r != NULL); return nInternalChar(r); }
     467
     468
     469
     470#endif
     471
  • libpolys/polys/monomials/ring.cc

    r1ddd04 r17e473  
    138138ring rDefault(coeffs cf, int N, char **n,int ord_size, int *ord, int *block0, int *block1)
    139139{
     140  assume( cf != NULL);
    140141  ring r=(ring) omAlloc0Bin(sip_sring_bin);
    141142  r->ch    = n_GetChar(cf);
     
    167168  if (ch==0) cf=nInitChar(n_Q,NULL);
    168169  else       cf=nInitChar(n_Zp,(void*)(long)ch);
     170  assume( cf != NULL);
    169171  return rDefault(cf,N,n,ord_size,ord,block0,block1);
    170172}
    171173ring   rDefault(coeffs cf, int N, char **n)
    172174
     175  assume( cf != NULL);
    173176  /*order: lp,0*/
    174177  int *order = (int *) omAlloc(2* sizeof(int));
     
    190193  if (ch==0) cf=nInitChar(n_Q,NULL);
    191194  else       cf=nInitChar(n_Zp,(void*)(long)ch);
     195  assume( cf != NULL);
    192196  return rDefault(cf,N,n);
    193197}
     
    286290  else if (rField_is_Ring(r))
    287291  {
     292    TODO(Frank, "Please consider addapting the variable names...");
     293   
    288294    PrintS("//   coeff. ring is : ");
    289295    if (rField_is_Ring_Z(r)) PrintS("Integers\n");
     296/*
    290297    long l = (long)mpz_sizeinbase(r->ringflaga, 10) + 2;
    291298    char* s = (char*) omAlloc(l);
     
    295302    if (rField_is_Ring_PtoM(r)) Print("Z/%s^%lu\n", s, r->ringflagb);
    296303    omFreeSize((ADDRESS)s, l);
     304*/ 
    297305  }
    298306#endif
     
    521529  }
    522530#ifdef HAVE_RINGS
     531  TODO(Frank, "Please consider addapting the variable names...");
     532/*
    523533  if (r->ringflaga != NULL)
    524534  {
     
    531541    omFree((ADDRESS)r->nrnModul);
    532542  }
     543*/
    533544#endif
    534545  omFreeBin(r, sip_sring_bin);
     
    649660
    650661#ifdef HAVE_RINGS
     662  TODO(Frank, "Please consider addapting the variable names...");
     663/*
    651664  if (rField_is_Ring_Z(r))
    652665  {
    653     s=omStrDup("integer");                   /* Z */
     666    s=omStrDup("integer");                   // Z
    654667    return s;
    655668  }
     
    674687    return s;
    675688  }
     689*/
    676690#endif
    677691  if (r->parameter==NULL)
     
    777791{
    778792#ifdef HAVE_RINGS
     793  TODO(Frank, "Please consider addapting the variable names...");
     794/*
    779795  if (rField_is_Ring_2toM(r))
    780796    return binaryPower(2, (int)(unsigned long)r->ringflagb);
     
    784800    return binaryPower((int)mpz_get_ui(r->ringflaga),
    785801                       (int)(unsigned long)r->ringflagb);
     802*/
    786803#endif
    787804  if (rField_is_numeric(r))
     
    15971614ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
    15981615{
     1616  TODO(Hans, "Please consider the change to '->cf'...");
     1617 
    15991618  if (r == NULL) return NULL;
    16001619  int i,j;
     
    16151634  res->ch=r->ch;     /* characteristic */
    16161635#ifdef HAVE_RINGS
    1617   res->ringtype=r->ringtype;  /* cring = 0 => coefficient field, cring = 1 => coeffs from Z/2^m */
     1636  TODO(Frank, "Please consider addapting the variable names...");
     1637/*
     1638  res->ringtype=r->ringtype;  // cring = 0 => coefficient field, cring = 1 => coeffs from Z/2^m
    16181639  if (r->ringflaga!=NULL)
    16191640  {
     
    16271648    mpz_init_set(res->nrnModul,r->nrnModul);
    16281649  }
     1650*/
    16291651#endif
    16301652  //memset: res->ref=0; /* reference counter to the ring */
     
    16821704  //memset: res->cf=NULL;
    16831705  res->options=r->options;
    1684   #ifdef HAVE_RINGS
    1685   res->ringtype=r->ringtype;
    1686   #endif
     1706#ifdef HAVE_RINGS
     1707  TODO(Frank, "Please consider addapting the variable names...");
     1708//  res->ringtype=r->ringtype;
     1709#endif
    16871710  //
    16881711  if (r->algring!=NULL)
     
    34733496  // set intStrategy
    34743497#ifdef HAVE_RINGS
    3475   if (rField_is_Extension(r) || rField_is_Q(r) || rField_is_Ring(r))
     3498  if (
     3499         rField_is_Extension(r)
     3500      || rField_is_Q(r)
     3501      || rField_is_Ring(r))
    34763502#else
    34773503  if (rField_is_Extension(r) || rField_is_Q(r))
  • libpolys/polys/monomials/ring.h

    r1ddd04 r17e473  
    222222  intvec * pModW;   /* std: module weights */
    223223  poly      ppNoether; /*  variables, set by procedures from hecke/kstd1:
     224
    224225                            the highest monomial below pHEdge */
    225 #ifdef HAVE_RINGS
    226   unsigned int  ringtype;  /* cring = 0 => coefficient field, cring = 1 => coeffs from Z/2^m */
    227   int_number    ringflaga; /* Z/(ringflag^ringflagb)=Z/nrnModul*/
    228   unsigned long ringflagb;
    229   unsigned long nr2mModul;  /* Z/nr2mModul */
    230   int_number    nrnModul;
    231 #endif
     226// #ifdef HAVE_RINGS
     227//   unsigned int  ringtype;  /* cring = 0 => coefficient field, cring = 1 => coeffs from Z/2^m */
     228//   int_number    ringflaga; /* Z/(ringflag^ringflagb)=Z/nrnModul*/
     229//   unsigned long ringflagb;
     230//   unsigned long nr2mModul;  /* Z/nr2mModul */
     231//   int_number    nrnModul;
     232// #endif
     233 
    232234  unsigned long options; /* ring dependent options */
    233235
     
    347349static inline bool rIsPluralRing(const ring r)
    348350{
     351  assume(r != NULL);   
    349352#ifdef HAVE_PLURAL
    350353  nc_struct *n;
     
    357360static inline bool rIsRatGRing(const ring r)
    358361{
     362  assume(r != NULL);
    359363#ifdef HAVE_PLURAL
    360364  /* nc_struct *n; */
     
    413417
    414418#ifdef HAVE_RINGS
    415 static inline BOOLEAN rField_is_Ring_2toM(ring r)
    416 { return (getCoeffType(r->cf) == n_Z2m); }
    417 
    418 static inline BOOLEAN rField_is_Ring_ModN(ring r)
    419 { return (getCoeffType(r->cf) == n_Zn); }
    420 
    421 static inline BOOLEAN rField_is_Ring_PtoM(ring r)
    422 { return (getCoeffType(r->cf) == n_Zpn); }
    423 
    424 static inline BOOLEAN rField_is_Ring_Z(ring r)
    425 { return (getCoeffType(r->cf) == n_Z); }
    426 
    427 static inline BOOLEAN rField_is_Ring(ring r)
    428 { return (r->ringtype != 0); }
    429 
    430 static inline BOOLEAN rField_is_Domain(ring r)
    431 { return (r->ringtype == 4 || r->ringtype == 0); }
    432 
    433 static inline BOOLEAN rField_has_Units(ring r)
    434 { return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); }
     419static inline BOOLEAN rField_is_Ring_2toM(const ring r)
     420{ assume(r != NULL); return ( getCoeffType(r->cf) == n_Z2m && nCoeff_is_Ring_2toM(r->cf) ); }
     421
     422static inline BOOLEAN rField_is_Ring_ModN(const ring r)
     423{ assume(r != NULL); return ( getCoeffType(r->cf) == n_Zn && nCoeff_is_Ring_ModN(r->cf) ); }
     424
     425static inline BOOLEAN rField_is_Ring_PtoM(const ring r)
     426{ assume(r != NULL); return (getCoeffType(r->cf) == n_Zpn && nCoeff_is_Ring_PtoM(r->cf) ); }
     427
     428static inline BOOLEAN rField_is_Ring_Z(const ring r)
     429{ assume(r != NULL); return (getCoeffType(r->cf) == n_Z && nCoeff_is_Ring_Z(r->cf) ); }
     430
     431static inline BOOLEAN rField_is_Ring(const ring r)
     432{ assume(r != NULL); return nCoeff_is_Ring(r->cf); }
     433
     434static inline BOOLEAN rField_is_Domain(const ring r)
     435{ assume(r != NULL); return nCoeff_is_Domain(r->cf); }
     436
     437static inline BOOLEAN rField_has_Units(const ring r)
     438{ assume(r != NULL); return nCoeff_has_Units(r->cf); }
    435439#else
    436440#define rField_is_Ring(A) (0)
     
    443447#endif
    444448
    445 static inline BOOLEAN rField_is_Zp(ring r)
    446 { return (getCoeffType(r->cf) == n_Zp); }
    447 
    448 static inline BOOLEAN rField_is_Zp(ring r, int p)
    449 { return (getCoeffType(r->cf) == n_Zp) && (r->ch == p); }
    450 
    451 static inline BOOLEAN rField_is_Q(ring r)
    452 { return (getCoeffType(r->cf) == n_Q); }
    453 
    454 static inline BOOLEAN rField_is_numeric(ring r) /* R, long R, long C */
    455 { return (r->ringtype == 0) && (r->ch ==  -1); }
    456 
    457 static inline BOOLEAN rField_is_R(ring r)
    458 { return (getCoeffType(r->cf) == n_R); }
    459 
    460 static inline BOOLEAN rField_is_GF(ring r)
    461 { return (getCoeffType(r->cf) == n_GF); }
    462 
    463 static inline BOOLEAN rField_is_GF(ring r, int q)
    464 { return (getCoeffType(r->cf) == n_GF) && (r->ch == q); }
    465 
    466 static inline BOOLEAN rField_is_Zp_a(ring r)
    467 { return (r->ringtype == 0) && (r->ch < -1); }
    468 
    469 static inline BOOLEAN rField_is_Zp_a(ring r, int p)
    470 { return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
    471 
    472 static inline BOOLEAN rField_is_Q_a(ring r)
    473 { return (r->ringtype == 0) && (r->ch == 1); }
    474 
    475 static inline BOOLEAN rField_is_long_R(ring r)
    476 { return (getCoeffType(r->cf) == n_long_R); }
    477 
    478 static inline BOOLEAN rField_is_long_C(ring r)
    479 { return (getCoeffType(r->cf) == n_long_C); }
    480 
    481 static inline BOOLEAN rField_has_simple_inverse(ring r)
    482 /* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/
    483 #ifdef HAVE_RINGS
    484 { return (r->ringtype > 0) || (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/2^n, Z/p, GF(p,n), R, long_R, long_C*/
    485 #else
    486 { return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/
    487 #endif
    488 
    489 static inline BOOLEAN rField_has_simple_Alloc(ring r)
    490 { return (rField_is_Zp(r)
    491        || rField_is_GF(r)
    492 #ifdef HAVE_RINGS
    493        || rField_is_Ring_2toM(r)
    494 #endif
    495        || rField_is_R(r)); }
     449static inline BOOLEAN rField_is_Zp(const ring r)
     450{ assume(r != NULL); return (getCoeffType(r->cf) == n_Zp); }
     451
     452static inline BOOLEAN rField_is_Zp(const ring r, int p)
     453{ assume(r != NULL); return (getCoeffType(r->cf) == n_Zp) && (r->ch == p); }
     454
     455static inline BOOLEAN rField_is_Q(const ring r)
     456{ assume(r != NULL); return nCoeff_is_Q(r->cf); }
     457
     458static inline BOOLEAN rField_is_numeric(const ring r) /* R, long R, long C */
     459{ assume(r != NULL); return nCoeff_is_numeric(r->cf); }
     460
     461static inline BOOLEAN rField_is_R(const ring r)
     462{ assume(r != NULL); return nCoeff_is_R(r->cf); }
     463
     464static inline BOOLEAN rField_is_GF(const ring r)
     465{ assume(r != NULL); return nCoeff_is_GF(r->cf); }
     466
     467static inline BOOLEAN rField_is_GF(const ring r, int q)
     468{ assume(r != NULL); return nCoeff_is_GF(r->cf, q); }
     469
     470static inline BOOLEAN rField_is_Zp_a(const ring r)
     471{ assume(r != NULL); return nCoeff_is_Zp_a(r->cf); }
     472
     473static inline BOOLEAN rField_is_Zp_a(const ring r, int p)
     474{ assume(r != NULL); return nCoeff_is_Zp_a(r->cf, p); }
     475
     476static inline BOOLEAN rField_is_Q_a(const ring r)
     477{ assume(r != NULL); return nCoeff_is_Q_a(r->cf); }
     478   
     479static inline BOOLEAN rField_is_long_R(const ring r)
     480{ assume(r != NULL); return nCoeff_is_long_R(r->cf); }
     481
     482static inline BOOLEAN rField_is_long_C(const ring r)
     483{ assume(r != NULL); return nCoeff_is_long_C(r->cf); }
     484
     485static inline BOOLEAN rField_has_simple_inverse(const ring r)
     486{ assume(r != NULL); return nCoeff_has_simple_inverse(r->cf); }
     487
     488static inline BOOLEAN rField_has_simple_Alloc(const ring r)
     489{ assume(r != NULL); return nCoeff_has_simple_Alloc(r->cf); }
    496490
    497491/* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/
    498 static inline BOOLEAN rField_is_Extension(ring r)
    499 { return (rField_is_Q_a(r)) || (rField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/
    500 
    501 n_coeffType rFieldType(ring r);
     492static inline BOOLEAN rField_is_Extension(const ring r)
     493{ assume(r != NULL); return nCoeff_is_Extension(r->cf); } /* Z/p(a) and Q(a)*/
     494
     495n_coeffType rFieldType(const ring r);
    502496
    503497/// this needs to be called whenever a new ring is created: new fields
     
    510504static inline int rBlocks(ring r)
    511505{
     506  assume(r != NULL);
    512507  int i=0;
    513508  while (r->order[i]!=0) i++;
     
    518513static inline char* rRingVar(short i, const ring r)
    519514{
    520   return r->names[i];
     515  assume(r != NULL); return r->names[i];
    521516}
    522517static inline BOOLEAN rShortOut(const ring r)
    523518{
    524   return (r->ShortOut);
     519  assume(r != NULL); return (r->ShortOut);
    525520}
    526521
     
    571566
    572567static inline BOOLEAN rIsSyzIndexRing(const ring r)
    573 { return r->order[0] == ringorder_s;}
     568{ assume(r != NULL); return r->order[0] == ringorder_s;}
    574569
    575570static inline int rGetCurrSyzLimit(const ring r)
    576 { return (rIsSyzIndexRing(r)? r->typ[0].data.syz.limit : 0);}
     571{ assume(r != NULL); return (rIsSyzIndexRing(r)? r->typ[0].data.syz.limit : 0);}
    577572
    578573// Ring Manipulations
     
    619614static inline BOOLEAN rOrd_is_Comp_dp(ring r)
    620615{
     616  assume(r != NULL);
    621617  return ((r->order[0] == ringorder_c || r->order[0] == ringorder_C) &&
    622618          r->order[1] == ringorder_dp &&
  • libpolys/polys/operations/p_Mult_q.cc

    r1ddd04 r17e473  
    191191static poly _p_Mult_q_Normal(poly p, poly q, const int copy, const ring r)
    192192{
     193  assume(r != NULL);
    193194  assume(p != NULL && pNext(p) != NULL && q != NULL && pNext(q) != NULL);
    194195#ifdef HAVE_RINGS
    195   assume(nField_is_Domain(r->cf));
    196 #endif
    197   pAssume1(! pHaveCommonMonoms(p, q));
     196  assume(nCoeff_is_Domain(r->cf));
     197#endif
     198  pAssume1(! p_HaveCommonMonoms(p, q, r));
    198199  p_Test(p, r);
    199200  p_Test(q, r);
     
    269270poly _p_Mult_q(poly p, poly q, const int copy, const ring r)
    270271{
    271 #ifdef HAVE_RINGS
    272   if (!nField_is_Domain(r->cf))
     272  assume(r != NULL);
     273#ifdef HAVE_RINGS
     274  if (!nCoeff_is_Domain(r->cf))
    273275    return _p_Mult_q_Normal_ZeroDiv(p, q, copy, r);
    274276#endif
  • libpolys/tests/polys_test.h

    r1ddd04 r17e473  
     1#include <cxxtest/TestSuite.h>
     2#include <cxxtest/GlobalFixture.h>
    13
    24#include "config.h"
     
    1012
    1113
     14// the following headers are private...
     15#include <coeffs/longrat.h>
     16#include <coeffs/gnumpfl.h>
     17#include <coeffs/gnumpc.h>
     18#include <coeffs/shortfl.h>
     19#include <coeffs/ffields.h>
     20#include <coeffs/modulop.h>
     21#include <coeffs/rmodulon.h>
     22#include <coeffs/rmodulo2m.h>
     23#include <coeffs/rintegers.h>
     24
     25
    1226#include <polys/monomials/ring.h>
    1327
     
    1630
    1731
     32
     33class GlobalPrintingFixture : public CxxTest::GlobalFixture
     34{
     35  public:
     36    bool setUpWorld() {
     37      clog << ( "<world>" ) << endl;
     38      TS_ASSERT_EQUALS( nRegister( n_Zp, npInitChar), n_Zp );
     39      TS_ASSERT_EQUALS( nRegister( n_GF, nfInitChar), n_GF );
     40      TS_ASSERT_EQUALS( nRegister( n_R, nrInitChar), n_R );
     41      TS_ASSERT_EQUALS( nRegister( n_Q, nlInitChar), n_Q );
     42      TS_ASSERT_EQUALS( nRegister( n_R, nrInitChar), n_R );
     43     
     44#ifdef HAVE_RINGS
     45      TS_ASSERT_EQUALS( nRegister( n_Z, nrzInitChar), n_Z ); // these are UNusable at the moment!
     46#endif
     47     
     48      return true;
     49    }
     50    bool tearDownWorld() { clog <<( "</world>" )  << endl; return true; }
     51    bool setUp() { clog <<( "<test>" )  << endl; return true; }
     52    bool tearDown() { clog <<( "</test>" )  << endl; return true; }
     53};
     54
     55
     56//
     57// We can rely on this file being included exactly once
     58// and declare this global variable in the header file.
     59//
     60static GlobalPrintingFixture globalPrintingFixture;
     61
     62
     63namespace
     64{
     65  void PrintRing(const ring r)
     66  {
     67    rWrite(r); PrintLn();
     68  #ifdef  RDEBUG
     69    rDebugPrint(r); PrintLn();
     70  #endif
     71  }
     72}
    1873
    1974class PolysTestSuite : public CxxTest::TestSuite
    2075{
    2176public:
    22    void test_1()
     77  void test_Z13_t()
     78  {
     79    clog << "Creating  Z/13[t]: " << endl;
     80
     81    char* n[] = {"t"};
     82    ring r = rDefault( 13, 1, n);     
     83    TS_ASSERT_DIFFERS( r, NULLp );
     84
     85    PrintRing(r);
     86
     87    TS_ASSERT( rField_is_Domain(r) );
     88    TS_ASSERT( !rField_is_Q(r) );
     89
     90    TS_ASSERT( rField_is_Zp(r) );
     91    TS_ASSERT( !rField_is_Zp(r, 11) );
     92    TS_ASSERT( rField_is_Zp(r, 13) );
     93
     94    TS_ASSERT_EQUALS( rVar(r), 1);
     95
     96    rDelete(r);
     97  }
     98
     99  void test_QQ_t()
     100  {
     101    clog << "Creating  Q[s]: " << endl;
     102
     103    char* n[] = {"s"};
     104    ring r = rDefault( 0, 1, n);     
     105    TS_ASSERT_DIFFERS( r, NULLp );
     106
     107    PrintRing(r);
     108
     109    TS_ASSERT( rField_is_Domain(r) );
     110    TS_ASSERT( rField_is_Q(r) );
     111   
     112    TS_ASSERT( !rField_is_Zp(r) );
     113    TS_ASSERT( !rField_is_Zp(r, 11) );
     114
     115    TS_ASSERT_EQUALS( rVar(r), 1);
     116
     117    rDelete(r);
     118  }
     119 
     120  void test_Z11_x_y_z()
     121  {
     122     clog << "Creating  Z/11[x, y, z]: " << endl;
     123     
     124     char* n[] = {"x", "y", "z"};
     125     ring r = rDefault( 11, 3, n);     
     126     TS_ASSERT_DIFFERS( r, NULLp );
     127
     128     PrintRing(r);
     129     
     130     TS_ASSERT( rField_is_Domain(r) );
     131     TS_ASSERT( !rField_is_Q(r) );
     132
     133     TS_ASSERT( rField_is_Zp(r) );
     134     TS_ASSERT( rField_is_Zp(r, 11) );
     135     TS_ASSERT( !rField_is_Zp(r, 13) );
     136
     137     TS_ASSERT_EQUALS( rVar(r), 3);
     138
     139     rDelete(r);
     140  }
     141   void test_QQ_x_y_z()
    23142   {
    24      char* n = "x";
    25      ring r = rDefault( 11, 1, &n);
     143     clog << "Creating  QQ[x, y, z, u]: " << endl;
     144
     145     char* n[] = {"x", "y", "z", "u"};
     146     ring r = rDefault( 0, 4, n);     
    26147     TS_ASSERT_DIFFERS( r, NULLp );
    27148
    28      clog << "RING: Z/11 [x]: " << endl;
    29      rWrite(r);
    30 #ifdef  RDEBUG
    31      rDebugPrint(r);
    32 #endif
    33      
     149     PrintRing(r);
     150
     151     TS_ASSERT( rField_is_Domain(r) );
     152     TS_ASSERT( rField_is_Q(r) );
     153
     154     TS_ASSERT( !rField_is_Zp(r) );
     155     TS_ASSERT( !rField_is_Zp(r, 11) );
     156
     157     TS_ASSERT_EQUALS( rVar(r), 4);
     158
    34159     rDelete(r);
    35160   }
     161
     162
     163   void test_Z13_t_GF()
     164   {
     165     clog << "Creating  GF[t]: " << endl;
     166
     167     char* n[] = {"t"};
     168
     169     GFInfo param;
     170
     171     param.GFChar= 5;
     172     param.GFDegree= 2;
     173     param.GFPar_name= (const char*)"Q";
     174
     175     const coeffs cf = nInitChar( n_GF, &param );
     176
     177     TS_ASSERT_DIFFERS( cf, NULLp );
     178
     179     ring r = rDefault( cf, 1, n);  // now cf belongs to r!
     180     TS_ASSERT_DIFFERS( r, NULLp );
     181
     182     PrintRing(r);
     183
     184     TS_ASSERT( rField_is_Domain(r) );
     185     TS_ASSERT( !rField_is_Q(r) );
     186
     187     TS_ASSERT( !rField_is_Zp(r) );
     188     TS_ASSERT( !rField_is_Zp(r, 11) );
     189     TS_ASSERT( !rField_is_Zp(r, 13) );
     190     TS_ASSERT( rField_is_GF(r) );
     191
     192     TS_ASSERT( !rField_is_GF(r, 5) );
     193     TS_ASSERT( rField_is_GF(r, 25) );
     194
     195     TS_ASSERT_EQUALS( rVar(r), 1);
     196
     197     rDelete(r); // kills 'cf' as well!
     198   }
     199
    36200};
    37201
Note: See TracChangeset for help on using the changeset viewer.