Changeset bcbdc40 in git


Ignore:
Timestamp:
Dec 5, 2016, 3:03:48 PM (7 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '82fc009ea2b0098c1a4896c841bb70860976bdfc')
Children:
665dab88a13186ce5e6abca704e42280baad6b91
Parents:
8d1432ec89236ac387a78cc9cc8071a2127d8f1e
Message:
static in rmodulon.cc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/rmodulon.cc

    r8d1432e rbcbdc40  
    2424#ifdef HAVE_RINGS
    2525
    26 number  nrnCopy        (number a, const coeffs r);
    27 int     nrnSize        (number a, const coeffs r);
    28 void    nrnDelete      (number *a, const coeffs r);
    29 BOOLEAN nrnGreaterZero (number k, const coeffs r);
    30 number  nrnMult        (number a, number b, const coeffs r);
    31 number  nrnInit        (long i, const coeffs r);
    32 long    nrnInt         (number &n, const coeffs r);
    33 number  nrnAdd         (number a, number b, const coeffs r);
    34 number  nrnSub         (number a, number b, const coeffs r);
    35 void    nrnPower       (number a, int i, number * result, const coeffs r);
    36 BOOLEAN nrnIsZero      (number a, const coeffs r);
    37 BOOLEAN nrnIsOne       (number a, const coeffs r);
    38 BOOLEAN nrnIsMOne      (number a, const coeffs r);
    39 BOOLEAN nrnIsUnit      (number a, const coeffs r);
    40 number  nrnGetUnit     (number a, const coeffs r);
    41 number  nrnAnn         (number a, const coeffs r);
    42 number  nrnDiv         (number a, number b, const coeffs r);
    43 number  nrnMod         (number a,number b, const coeffs r);
    44 number  nrnIntDiv      (number a,number b, const coeffs r);
    45 number  nrnNeg         (number c, const coeffs r);
    46 number  nrnInvers      (number c, const coeffs r);
    47 BOOLEAN nrnGreater     (number a, number b, const coeffs r);
    48 BOOLEAN nrnDivBy       (number a, number b, const coeffs r);
    49 int     nrnDivComp     (number a, number b, const coeffs r);
    50 BOOLEAN nrnEqual       (number a, number b, const coeffs r);
    51 number  nrnLcm         (number a,number b, const coeffs r);
    52 number  nrnGcd         (number a,number b, const coeffs r);
    53 number  nrnExtGcd      (number a, number b, number *s, number *t, const coeffs r);
    54 number  nrnXExtGcd      (number a, number b, number *s, number *t, number *u, number *v, const coeffs r);
    55 number  nrnQuotRem      (number a, number b, number *s, const coeffs r);
    56 nMapFunc nrnSetMap     (const coeffs src, const coeffs dst);
    5726#if SI_INTEGER_VARIANT==2
    5827// FIXME? TODO? // extern void    nrzWrite       (number &a, const coeffs r); // FIXME
     
    6130void nrnWrite (number a, const coeffs);
    6231#endif
    63 const char *  nrnRead  (const char *s, number *a, const coeffs r);
    64 void     nrnCoeffWrite (const coeffs r, BOOLEAN details);
    6532#ifdef LDEBUG
    6633BOOLEAN nrnDBTest      (number a, const char *f, const int l, const coeffs r);
    6734#endif
    68 void    nrnSetExp(unsigned long c, const coeffs r);
    69 void    nrnInitExp(unsigned long c, const coeffs r);
    70 coeffs  nrnQuot1(number c, const coeffs r);
    71 
    72 number nrnMapQ(number from, const coeffs src, const coeffs dst);
    73 
    7435
    7536extern omBin gmp_nrz_bin;
    7637
    77 void    nrnCoeffWrite  (const coeffs r, BOOLEAN /*details*/)
     38static void nrnCoeffWrite  (const coeffs r, BOOLEAN /*details*/)
    7839{
    7940  size_t l = (size_t)mpz_sizeinbase(r->modBase, 10) + 2;
     
    13091}
    13192
    132 coeffs nrnQuot1(number c, const coeffs r)
     93static coeffs nrnQuot1(number c, const coeffs r)
    13394{
    13495    coeffs rr;
     
    175136}
    176137
    177 /* for initializing function pointers */
    178 BOOLEAN nrnInitChar (coeffs r, void* p)
    179 {
    180   assume( (getCoeffType(r) == n_Zn) || (getCoeffType (r) == n_Znm) );
    181   ZnmInfo * info= (ZnmInfo *) p;
    182   r->modBase= (mpz_ptr)nrnCopy((number)info->base, r); //this circumvents the problem
    183   //in bigintmat.cc where we cannot create a "legal" nrn that can be freed.
    184   //If we take a copy, we can do whatever we want.
    185 
    186   nrnInitExp (info->exp, r);
    187 
    188   /* next computation may yield wrong characteristic as r->modNumber
    189      is a GMP number */
    190   r->ch = mpz_get_ui(r->modNumber);
    191 
    192   r->is_field=FALSE;
    193   r->is_domain=FALSE;
    194   r->rep=n_rep_gmp;
    195 
    196 
    197   r->cfCoeffString = nrnCoeffString;
    198 
    199   r->cfInit        = nrnInit;
    200   r->cfDelete      = nrnDelete;
    201   r->cfCopy        = nrnCopy;
    202   r->cfSize        = nrnSize;
    203   r->cfInt         = nrnInt;
    204   r->cfAdd         = nrnAdd;
    205   r->cfSub         = nrnSub;
    206   r->cfMult        = nrnMult;
    207   r->cfDiv         = nrnDiv;
    208   r->cfAnn         = nrnAnn;
    209   r->cfIntMod      = nrnMod;
    210   r->cfExactDiv    = nrnDiv;
    211   r->cfInpNeg         = nrnNeg;
    212   r->cfInvers      = nrnInvers;
    213   r->cfDivBy       = nrnDivBy;
    214   r->cfDivComp     = nrnDivComp;
    215   r->cfGreater     = nrnGreater;
    216   r->cfEqual       = nrnEqual;
    217   r->cfIsZero      = nrnIsZero;
    218   r->cfIsOne       = nrnIsOne;
    219   r->cfIsMOne      = nrnIsMOne;
    220   r->cfGreaterZero = nrnGreaterZero;
    221   r->cfWriteLong   = nrnWrite;
    222   r->cfRead        = nrnRead;
    223   r->cfPower       = nrnPower;
    224   r->cfSetMap      = nrnSetMap;
    225   //r->cfNormalize   = ndNormalize;
    226   r->cfLcm         = nrnLcm;
    227   r->cfGcd         = nrnGcd;
    228   r->cfIsUnit      = nrnIsUnit;
    229   r->cfGetUnit     = nrnGetUnit;
    230   r->cfExtGcd      = nrnExtGcd;
    231   r->cfXExtGcd     = nrnXExtGcd;
    232   r->cfQuotRem     = nrnQuotRem;
    233   r->cfCoeffName   = nrnCoeffName;
    234   r->cfCoeffWrite  = nrnCoeffWrite;
    235   r->nCoeffIsEqual = nrnCoeffsEqual;
    236   r->cfKillChar    = nrnKillChar;
    237   r->cfQuot1       = nrnQuot1;
    238 #ifdef LDEBUG
    239   r->cfDBTest      = nrnDBTest;
    240 #endif
    241   return FALSE;
     138static number nrnCopy(number a, const coeffs)
     139{
     140  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
     141  mpz_init_set(erg, (mpz_ptr) a);
     142  return (number) erg;
    242143}
    243144
     
    245146 * create a number from int
    246147 */
    247 number nrnInit(long i, const coeffs r)
     148static number nrnInit(long i, const coeffs r)
    248149{
    249150  mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
     
    253154}
    254155
    255 void nrnDelete(number *a, const coeffs)
     156static void nrnDelete(number *a, const coeffs)
    256157{
    257158  if (*a == NULL) return;
     
    261162}
    262163
    263 number nrnCopy(number a, const coeffs)
    264 {
    265   mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
    266   mpz_init_set(erg, (mpz_ptr) a);
    267   return (number) erg;
    268 }
    269 
    270 int nrnSize(number a, const coeffs)
     164static int nrnSize(number a, const coeffs)
    271165{
    272166  if (a == NULL) return 0;
     
    277171 * convert a number to int
    278172 */
    279 long nrnInt(number &n, const coeffs)
     173static long nrnInt(number &n, const coeffs)
    280174{
    281175  return mpz_get_si((mpz_ptr) n);
     
    285179 * Multiply two numbers
    286180 */
    287 number nrnMult(number a, number b, const coeffs r)
     181static number nrnMult(number a, number b, const coeffs r)
    288182{
    289183  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    294188}
    295189
    296 void nrnPower(number a, int i, number * result, const coeffs r)
     190static void nrnPower(number a, int i, number * result, const coeffs r)
    297191{
    298192  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    302196}
    303197
    304 number nrnAdd(number a, number b, const coeffs r)
     198static number nrnAdd(number a, number b, const coeffs r)
    305199{
    306200  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    311205}
    312206
    313 number nrnSub(number a, number b, const coeffs r)
     207static number nrnSub(number a, number b, const coeffs r)
    314208{
    315209  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    320214}
    321215
    322 number nrnNeg(number c, const coeffs r)
     216static BOOLEAN nrnIsZero(number a, const coeffs)
     217{
     218#ifdef LDEBUG
     219  if (a == NULL) return FALSE;
     220#endif
     221  return 0 == mpz_cmpabs_ui((mpz_ptr)a, 0);
     222}
     223
     224static number nrnNeg(number c, const coeffs r)
    323225{
    324226  if( !nrnIsZero(c, r) )
     
    328230}
    329231
    330 number nrnInvers(number c, const coeffs r)
     232static number nrnInvers(number c, const coeffs r)
    331233{
    332234  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    334236  mpz_invert(erg, (mpz_ptr)c, r->modNumber);
    335237  return (number) erg;
     238}
     239
     240/*
     241 * Give the largest k, such that a = x * k, b = y * k has
     242 * a solution.
     243 */
     244static number nrnGcd(number a, number b, const coeffs r)
     245{
     246  if ((a == NULL) && (b == NULL)) return nrnInit(0,r);
     247  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     248  mpz_init_set(erg, r->modNumber);
     249  if (a != NULL) mpz_gcd(erg, erg, (mpz_ptr)a);
     250  if (b != NULL) mpz_gcd(erg, erg, (mpz_ptr)b);
     251  if(mpz_cmp(erg,r->modNumber)==0)
     252  {
     253    mpz_clear(erg);
     254    omFreeBin((ADDRESS)erg,gmp_nrz_bin);
     255    return nrnInit(0,r);
     256  }
     257  return (number)erg;
    336258}
    337259
     
    340262 * TODO: lcm(gcd,gcd) better than gcd(lcm) ?
    341263 */
    342 number nrnLcm(number a, number b, const coeffs r)
     264static number nrnLcm(number a, number b, const coeffs r)
    343265{
    344266  number erg = nrnGcd(NULL, a, r);
     
    346268  mpz_lcm((mpz_ptr)erg, (mpz_ptr)erg, (mpz_ptr)tmp);
    347269  nrnDelete(&tmp, r);
    348   return (number)erg;
    349 }
    350 
    351 /*
    352  * Give the largest k, such that a = x * k, b = y * k has
    353  * a solution.
    354  */
    355 number nrnGcd(number a, number b, const coeffs r)
    356 {
    357   if ((a == NULL) && (b == NULL)) return nrnInit(0,r);
    358   mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
    359   mpz_init_set(erg, r->modNumber);
    360   if (a != NULL) mpz_gcd(erg, erg, (mpz_ptr)a);
    361   if (b != NULL) mpz_gcd(erg, erg, (mpz_ptr)b);
    362   if(mpz_cmp(erg,r->modNumber)==0)
    363   {
    364     mpz_clear(erg);
    365     omFreeBin((ADDRESS)erg,gmp_nrz_bin);
    366     return nrnInit(0,r);
    367   }
    368270  return (number)erg;
    369271}
     
    393295 * however, mod 12, the gcd should be 1
    394296 */
    395 number nrnExtGcd(number a, number b, number *s, number *t, const coeffs r)
     297static number nrnExtGcd(number a, number b, number *s, number *t, const coeffs r)
    396298{
    397299  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    408310  return (number)erg;
    409311}
    410 /* XExtGcd  returns a unimodular matrix ((s,t)(u,v)) sth.
    411  * (a,b)^t ((st)(uv)) = (g,0)^t
    412  * Beware, the ExtGcd will not necessaairly do this.
    413  * Problem: if g = as+bt then (in Z/nZ) it follows NOT that
    414  *             1 = (a/g)s + (b/g) t
    415  * due to the zero divisors.
    416  */
    417 
    418 //#define CF_DEB;
    419 number nrnXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
    420 {
    421   number xx;
    422 #ifdef CF_DEB
    423   StringSetS("XExtGcd of ");
    424   nrnWrite(a, r);
    425   StringAppendS("\t");
    426   nrnWrite(b, r);
    427   StringAppendS(" modulo ");
    428   nrnWrite(xx = (number)r->modNumber, r);
    429   Print("%s\n", StringEndS());
    430 #endif
    431 
    432   mpz_ptr one = (mpz_ptr)omAllocBin(gmp_nrz_bin);
    433   mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
    434   mpz_ptr bs  = (mpz_ptr)omAllocBin(gmp_nrz_bin);
    435   mpz_ptr bt  = (mpz_ptr)omAllocBin(gmp_nrz_bin);
    436   mpz_ptr bu  = (mpz_ptr)omAllocBin(gmp_nrz_bin);
    437   mpz_ptr bv  = (mpz_ptr)omAllocBin(gmp_nrz_bin);
    438   mpz_init(erg);
    439   mpz_init(one);
    440   mpz_init_set(bs, (mpz_ptr) a);
    441   mpz_init_set(bt, (mpz_ptr) b);
    442   mpz_init(bu);
    443   mpz_init(bv);
    444   mpz_gcd(erg, bs, bt);
    445 
    446 #ifdef CF_DEB
    447   StringSetS("1st gcd:");
    448   nrnWrite(xx= (number)erg, r);
    449 #endif
    450 
    451   mpz_gcd(erg, erg, r->modNumber);
    452 
    453   mpz_div(bs, bs, erg);
    454   mpz_div(bt, bt, erg);
    455 
    456 #ifdef CF_DEB
    457   Print("%s\n", StringEndS());
    458   StringSetS("xgcd: ");
    459 #endif
    460 
    461   mpz_gcdext(one, bu, bv, bs, bt);
    462   number ui = nrnGetUnit(xx = (number) one, r);
    463 #ifdef CF_DEB
    464   n_Write(xx, r);
    465   StringAppendS("\t");
    466   n_Write(ui, r);
    467   Print("%s\n", StringEndS());
    468 #endif
    469   nrnDelete(&xx, r);
    470   if (!nrnIsOne(ui, r))
    471   {
    472 #ifdef CF_DEB
    473     PrintS("Scaling\n");
    474 #endif
    475     number uii = nrnInvers(ui, r);
    476     nrnDelete(&ui, r);
    477     ui = uii;
    478     mpz_ptr uu = (mpz_ptr)omAllocBin(gmp_nrz_bin);
    479     mpz_init_set(uu, (mpz_ptr)ui);
    480     mpz_mul(bu, bu, uu);
    481     mpz_mul(bv, bv, uu);
    482     mpz_clear(uu);
    483     omFreeBin(uu, gmp_nrz_bin);
    484   }
    485   nrnDelete(&ui, r);
    486 #ifdef CF_DEB
    487   StringSetS("xgcd");
    488   nrnWrite(xx= (number)bs, r);
    489   StringAppendS("*");
    490   nrnWrite(xx= (number)bu, r);
    491   StringAppendS(" + ");
    492   nrnWrite(xx= (number)bt, r);
    493   StringAppendS("*");
    494   nrnWrite(xx= (number)bv, r);
    495   Print("%s\n", StringEndS());
    496 #endif
    497 
    498   mpz_mod(bs, bs, r->modNumber);
    499   mpz_mod(bt, bt, r->modNumber);
    500   mpz_mod(bu, bu, r->modNumber);
    501   mpz_mod(bv, bv, r->modNumber);
    502   *s = (number)bu;
    503   *t = (number)bv;
    504   *u = (number)bt;
    505   *u = nrnNeg(*u, r);
    506   *v = (number)bs;
    507   return (number)erg;
    508 }
    509 
    510 
    511 BOOLEAN nrnIsZero(number a, const coeffs)
     312
     313static BOOLEAN nrnIsOne(number a, const coeffs)
    512314{
    513315#ifdef LDEBUG
    514316  if (a == NULL) return FALSE;
    515317#endif
    516   return 0 == mpz_cmpabs_ui((mpz_ptr)a, 0);
    517 }
    518 
    519 BOOLEAN nrnIsOne(number a, const coeffs)
    520 {
    521 #ifdef LDEBUG
    522   if (a == NULL) return FALSE;
    523 #endif
    524318  return 0 == mpz_cmp_si((mpz_ptr)a, 1);
    525319}
    526320
    527 BOOLEAN nrnIsMOne(number a, const coeffs r)
    528 {
    529 #ifdef LDEBUG
    530   if (a == NULL) return FALSE;
    531 #endif
    532   if(nrnIsOne(a,r)) return FALSE; // for char 2
    533   mpz_t t; mpz_init_set(t, (mpz_ptr)a);
    534   mpz_add_ui(t, t, 1);
    535   bool erg = (0 == mpz_cmp(t, r->modNumber));
    536   mpz_clear(t);
    537   return erg;
    538 }
    539 
    540 BOOLEAN nrnEqual(number a, number b, const coeffs)
     321static BOOLEAN nrnEqual(number a, number b, const coeffs)
    541322{
    542323  return 0 == mpz_cmp((mpz_ptr)a, (mpz_ptr)b);
    543324}
    544325
    545 BOOLEAN nrnGreater(number a, number b, const coeffs)
    546 {
    547   return 0 < mpz_cmp((mpz_ptr)a, (mpz_ptr)b);
    548 }
    549 
    550 BOOLEAN nrnGreaterZero(number k, const coeffs)
    551 {
    552   return 0 < mpz_cmp_si((mpz_ptr)k, 0);
    553 }
    554 
    555 BOOLEAN nrnIsUnit(number a, const coeffs r)
    556 {
    557   number tmp = nrnGcd(a, (number)r->modNumber, r);
    558   bool res = nrnIsOne(tmp, r);
    559   nrnDelete(&tmp, NULL);
    560   return res;
    561 }
    562 
    563 number nrnGetUnit(number k, const coeffs r)
     326static number nrnGetUnit(number k, const coeffs r)
    564327{
    565328  if (mpz_divisible_p(r->modNumber, (mpz_ptr)k)) return nrnInit(1,r);
     
    598361}
    599362
    600 number nrnAnn(number k, const coeffs r)
     363/* XExtGcd  returns a unimodular matrix ((s,t)(u,v)) sth.
     364 * (a,b)^t ((st)(uv)) = (g,0)^t
     365 * Beware, the ExtGcd will not necessaairly do this.
     366 * Problem: if g = as+bt then (in Z/nZ) it follows NOT that
     367 *             1 = (a/g)s + (b/g) t
     368 * due to the zero divisors.
     369 */
     370
     371//#define CF_DEB;
     372static number nrnXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
     373{
     374  number xx;
     375#ifdef CF_DEB
     376  StringSetS("XExtGcd of ");
     377  nrnWrite(a, r);
     378  StringAppendS("\t");
     379  nrnWrite(b, r);
     380  StringAppendS(" modulo ");
     381  nrnWrite(xx = (number)r->modNumber, r);
     382  Print("%s\n", StringEndS());
     383#endif
     384
     385  mpz_ptr one = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     386  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     387  mpz_ptr bs  = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     388  mpz_ptr bt  = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     389  mpz_ptr bu  = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     390  mpz_ptr bv  = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     391  mpz_init(erg);
     392  mpz_init(one);
     393  mpz_init_set(bs, (mpz_ptr) a);
     394  mpz_init_set(bt, (mpz_ptr) b);
     395  mpz_init(bu);
     396  mpz_init(bv);
     397  mpz_gcd(erg, bs, bt);
     398
     399#ifdef CF_DEB
     400  StringSetS("1st gcd:");
     401  nrnWrite(xx= (number)erg, r);
     402#endif
     403
     404  mpz_gcd(erg, erg, r->modNumber);
     405
     406  mpz_div(bs, bs, erg);
     407  mpz_div(bt, bt, erg);
     408
     409#ifdef CF_DEB
     410  Print("%s\n", StringEndS());
     411  StringSetS("xgcd: ");
     412#endif
     413
     414  mpz_gcdext(one, bu, bv, bs, bt);
     415  number ui = nrnGetUnit(xx = (number) one, r);
     416#ifdef CF_DEB
     417  n_Write(xx, r);
     418  StringAppendS("\t");
     419  n_Write(ui, r);
     420  Print("%s\n", StringEndS());
     421#endif
     422  nrnDelete(&xx, r);
     423  if (!nrnIsOne(ui, r))
     424  {
     425#ifdef CF_DEB
     426    PrintS("Scaling\n");
     427#endif
     428    number uii = nrnInvers(ui, r);
     429    nrnDelete(&ui, r);
     430    ui = uii;
     431    mpz_ptr uu = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     432    mpz_init_set(uu, (mpz_ptr)ui);
     433    mpz_mul(bu, bu, uu);
     434    mpz_mul(bv, bv, uu);
     435    mpz_clear(uu);
     436    omFreeBin(uu, gmp_nrz_bin);
     437  }
     438  nrnDelete(&ui, r);
     439#ifdef CF_DEB
     440  StringSetS("xgcd");
     441  nrnWrite(xx= (number)bs, r);
     442  StringAppendS("*");
     443  nrnWrite(xx= (number)bu, r);
     444  StringAppendS(" + ");
     445  nrnWrite(xx= (number)bt, r);
     446  StringAppendS("*");
     447  nrnWrite(xx= (number)bv, r);
     448  Print("%s\n", StringEndS());
     449#endif
     450
     451  mpz_mod(bs, bs, r->modNumber);
     452  mpz_mod(bt, bt, r->modNumber);
     453  mpz_mod(bu, bu, r->modNumber);
     454  mpz_mod(bv, bv, r->modNumber);
     455  *s = (number)bu;
     456  *t = (number)bv;
     457  *u = (number)bt;
     458  *u = nrnNeg(*u, r);
     459  *v = (number)bs;
     460  return (number)erg;
     461}
     462
     463static BOOLEAN nrnIsMOne(number a, const coeffs r)
     464{
     465#ifdef LDEBUG
     466  if (a == NULL) return FALSE;
     467#endif
     468  if(nrnIsOne(a,r)) return FALSE; // for char 2
     469  mpz_t t; mpz_init_set(t, (mpz_ptr)a);
     470  mpz_add_ui(t, t, 1);
     471  bool erg = (0 == mpz_cmp(t, r->modNumber));
     472  mpz_clear(t);
     473  return erg;
     474}
     475
     476static BOOLEAN nrnGreater(number a, number b, const coeffs)
     477{
     478  return 0 < mpz_cmp((mpz_ptr)a, (mpz_ptr)b);
     479}
     480
     481static BOOLEAN nrnGreaterZero(number k, const coeffs)
     482{
     483  return 0 < mpz_cmp_si((mpz_ptr)k, 0);
     484}
     485
     486static BOOLEAN nrnIsUnit(number a, const coeffs r)
     487{
     488  number tmp = nrnGcd(a, (number)r->modNumber, r);
     489  bool res = nrnIsOne(tmp, r);
     490  nrnDelete(&tmp, NULL);
     491  return res;
     492}
     493
     494static number nrnAnn(number k, const coeffs r)
    601495{
    602496  mpz_ptr tmp = (mpz_ptr) omAllocBin(gmp_nrz_bin);
     
    611505}
    612506
    613 BOOLEAN nrnDivBy(number a, number b, const coeffs r)
     507static BOOLEAN nrnDivBy(number a, number b, const coeffs r)
    614508{
    615509  if (a == NULL)
     
    625519}
    626520
    627 int nrnDivComp(number a, number b, const coeffs r)
     521static int nrnDivComp(number a, number b, const coeffs r)
    628522{
    629523  if (nrnEqual(a, b,r)) return 2;
     
    633527}
    634528
    635 number nrnDiv(number a, number b, const coeffs r)
     529static number nrnDiv(number a, number b, const coeffs r)
    636530{
    637531  if (a == NULL) a = (number)r->modNumber;
     
    666560}
    667561
    668 number nrnMod(number a, number b, const coeffs r)
     562static number nrnMod(number a, number b, const coeffs r)
    669563{
    670564  /*
     
    698592}
    699593
    700 number nrnIntDiv(number a, number b, const coeffs r)
     594static number nrnIntDiv(number a, number b, const coeffs r)
    701595{
    702596  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    722616 * the exact quotient.
    723617 */
    724 number nrnQuotRem(number a, number b, number  * rem, const coeffs r)
     618static number nrnQuotRem(number a, number b, number  * rem, const coeffs r)
    725619{
    726620  mpz_t g, aa, bb;
     
    758652 */
    759653
    760 mpz_ptr nrnMapCoef = NULL;
    761 
    762 number nrnMapModN(number from, const coeffs /*src*/, const coeffs dst)
     654static mpz_ptr nrnMapCoef = NULL;
     655
     656static number nrnMapModN(number from, const coeffs /*src*/, const coeffs dst)
    763657{
    764658  return nrnMult(from, (number) nrnMapCoef, dst);
    765659}
    766660
    767 number nrnMap2toM(number from, const coeffs /*src*/, const coeffs dst)
     661static number nrnMap2toM(number from, const coeffs /*src*/, const coeffs dst)
    768662{
    769663  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    774668}
    775669
    776 number nrnMapZp(number from, const coeffs /*src*/, const coeffs dst)
     670static number nrnMapZp(number from, const coeffs /*src*/, const coeffs dst)
    777671{
    778672  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    793687
    794688#if SI_INTEGER_VARIANT==3
    795 number nrnMapZ(number from, const coeffs /*src*/, const coeffs dst)
     689static number nrnMapZ(number from, const coeffs /*src*/, const coeffs dst)
    796690{
    797691  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    805699#elif SI_INTEGER_VARIANT==2
    806700
    807 number nrnMapZ(number from, const coeffs src, const coeffs dst)
     701static number nrnMapZ(number from, const coeffs src, const coeffs dst)
    808702{
    809703  if (SR_HDL(from) & SR_INT)
     
    815709}
    816710#elif SI_INTEGER_VARIANT==1
    817 number nrnMapZ(number from, const coeffs src, const coeffs dst)
     711static number nrnMapZ(number from, const coeffs src, const coeffs dst)
    818712{
    819713  return nrnMapQ(from,src,dst);
     
    821715#endif
    822716#if SI_INTEGER_VARIANT!=2
    823 void nrnWrite (number a, const coeffs)
     717static void nrnWrite (number a, const coeffs)
    824718{
    825719  char *s,*z;
     
    839733#endif
    840734
    841 number nrnMapQ(number from, const coeffs src, const coeffs dst)
     735static number nrnMapQ(number from, const coeffs src, const coeffs dst)
    842736{
    843737  mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
     
    933827 */
    934828
    935 void nrnSetExp(unsigned long m, coeffs r)
     829static void nrnSetExp(unsigned long m, coeffs r)
    936830{
    937831  /* clean up former stuff */
     
    945839
    946840/* We expect this ring to be Z/n^m for some m > 0 and for some n > 2 which is not a prime. */
    947 void nrnInitExp(unsigned long m, coeffs r)
     841static void nrnInitExp(unsigned long m, coeffs r)
    948842{
    949843  nrnSetExp(m, r);
     
    994888}
    995889
    996 const char * nrnRead (const char *s, number *a, const coeffs r)
     890static const char * nrnRead (const char *s, number *a, const coeffs r)
    997891{
    998892  mpz_ptr z = (mpz_ptr) omAllocBin(gmp_nrz_bin);
     
    1004898  return s;
    1005899}
     900
     901/* for initializing function pointers */
     902BOOLEAN nrnInitChar (coeffs r, void* p)
     903{
     904  assume( (getCoeffType(r) == n_Zn) || (getCoeffType (r) == n_Znm) );
     905  ZnmInfo * info= (ZnmInfo *) p;
     906  r->modBase= (mpz_ptr)nrnCopy((number)info->base, r); //this circumvents the problem
     907  //in bigintmat.cc where we cannot create a "legal" nrn that can be freed.
     908  //If we take a copy, we can do whatever we want.
     909
     910  nrnInitExp (info->exp, r);
     911
     912  /* next computation may yield wrong characteristic as r->modNumber
     913     is a GMP number */
     914  r->ch = mpz_get_ui(r->modNumber);
     915
     916  r->is_field=FALSE;
     917  r->is_domain=FALSE;
     918  r->rep=n_rep_gmp;
     919
     920
     921  r->cfCoeffString = nrnCoeffString;
     922
     923  r->cfInit        = nrnInit;
     924  r->cfDelete      = nrnDelete;
     925  r->cfCopy        = nrnCopy;
     926  r->cfSize        = nrnSize;
     927  r->cfInt         = nrnInt;
     928  r->cfAdd         = nrnAdd;
     929  r->cfSub         = nrnSub;
     930  r->cfMult        = nrnMult;
     931  r->cfDiv         = nrnDiv;
     932  r->cfAnn         = nrnAnn;
     933  r->cfIntMod      = nrnMod;
     934  r->cfExactDiv    = nrnDiv;
     935  r->cfInpNeg         = nrnNeg;
     936  r->cfInvers      = nrnInvers;
     937  r->cfDivBy       = nrnDivBy;
     938  r->cfDivComp     = nrnDivComp;
     939  r->cfGreater     = nrnGreater;
     940  r->cfEqual       = nrnEqual;
     941  r->cfIsZero      = nrnIsZero;
     942  r->cfIsOne       = nrnIsOne;
     943  r->cfIsMOne      = nrnIsMOne;
     944  r->cfGreaterZero = nrnGreaterZero;
     945  r->cfWriteLong   = nrnWrite;
     946  r->cfRead        = nrnRead;
     947  r->cfPower       = nrnPower;
     948  r->cfSetMap      = nrnSetMap;
     949  //r->cfNormalize   = ndNormalize;
     950  r->cfLcm         = nrnLcm;
     951  r->cfGcd         = nrnGcd;
     952  r->cfIsUnit      = nrnIsUnit;
     953  r->cfGetUnit     = nrnGetUnit;
     954  r->cfExtGcd      = nrnExtGcd;
     955  r->cfXExtGcd     = nrnXExtGcd;
     956  r->cfQuotRem     = nrnQuotRem;
     957  r->cfCoeffName   = nrnCoeffName;
     958  r->cfCoeffWrite  = nrnCoeffWrite;
     959  r->nCoeffIsEqual = nrnCoeffsEqual;
     960  r->cfKillChar    = nrnKillChar;
     961  r->cfQuot1       = nrnQuot1;
     962#ifdef LDEBUG
     963  r->cfDBTest      = nrnDBTest;
     964#endif
     965  return FALSE;
     966}
     967
    1006968#endif
    1007969/* #ifdef HAVE_RINGS */
Note: See TracChangeset for help on using the changeset viewer.