Changeset 7d90aa in git


Ignore:
Timestamp:
Mar 8, 2011, 7:29:56 PM (13 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '45e267b9942dec9429fe249ce3e5e44ab80a6a3a')
Children:
655a2976d656bc7749e136dea00a5bb75c14a0b4
Parents:
634d93b52f3d7540be44b7c941a206dc38b1b1be
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2011-03-08 19:29:56+01:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 11:49:00+01:00
Message:
initial changes to 'coeffs' + first build system
Location:
coeffs
Files:
6 added
23 edited

Legend:

Unmodified
Added
Removed
  • coeffs/ffields.h

    r634d93b r7d90aa  
    88* ABSTRACT: finite fields with a none-prime number of elements (via tables)
    99*/
    10 #include <kernel/structs.h>
     10#include "coeffs.h"
    1111
    1212
    13 BOOLEAN nfGreaterZero (number k);
    14 number  nfMult        (number a, number b);
    15 number  nfInit        (int i, const ring r);
    16 number  nfPar         (int i);
    17 int     nfParDeg      (number n);
    18 int     nfInt         (number &n, const ring r);
    19 number  nfAdd         (number a, number b);
    20 number  nfSub         (number a, number b);
    21 void    nfPower       (number a, int i, number * result);
    22 BOOLEAN nfIsZero      (number a);
    23 BOOLEAN nfIsOne       (number a);
    24 BOOLEAN nfIsMOne      (number a);
    25 number  nfDiv         (number a, number b);
    26 number  nfNeg         (number c);
    27 number  nfInvers      (number c);
    28 BOOLEAN nfGreater     (number a, number b);
    29 BOOLEAN nfEqual       (number a, number b);
    30 void    nfWrite       (number &a, const ring r);
    31 const char *  nfRead  (const char *s, number *a);
     13BOOLEAN nfGreaterZero (number k, const coeffs r);
     14number  nfMult        (number a, number b, const coeffs r);
     15number  nfInit        (int i, const coeffs r);
     16number  nfPar         (int i, const coeffs r);
     17int     nfParDeg      (number n, const coeffs r);
     18int     nfInt         (number &n, const coeffs r);
     19number  nfAdd         (number a, number b, const coeffs r);
     20number  nfSub         (number a, number b, const coeffs r);
     21void    nfPower       (number a, int i, number * result, const coeffs r);
     22BOOLEAN nfIsZero      (number a, const coeffs r);
     23BOOLEAN nfIsOne       (number a, const coeffs r);
     24BOOLEAN nfIsMOne      (number a, const coeffs r);
     25number  nfDiv         (number a, number b, const coeffs r);
     26number  nfNeg         (number c, const coeffs r);
     27number  nfInvers      (number c, const coeffs r);
     28BOOLEAN nfGreater     (number a, number b, const coeffs r);
     29BOOLEAN nfEqual       (number a, number b, const coeffs r);
     30void    nfWrite       (number &a, const coeffs r);
     31const char *  nfRead  (const char *s, number *a, const coeffs r);
    3232#ifdef LDEBUG
    3333BOOLEAN nfDBTest      (number a, const char *f, const int l);
     
    3535void    nfSetChar     (int c, char ** param);
    3636
    37 nMapFunc nfSetMap     (const ring src, const ring dst);
    38 char *  nfName        (number n);
     37nMapFunc nfSetMap     (const coeffs src, const coeffs dst);
     38char *  nfName        (number n, const coeffs r);
    3939extern  int nfMinPoly[];
    4040extern  int nfCharP;  /* the characteristic: p*/
  • coeffs/gnumpc.cc

    r634d93b r7d90aa  
    99*/
    1010
    11 #include <kernel/mod2.h>
    12 #include <kernel/structs.h>
    13 #include <kernel/febase.h>
    14 #include <omalloc/omalloc.h>
    15 #include <kernel/numbers.h>
    16 #include <kernel/longrat.h>
    17 #include <kernel/modulop.h>
    18 #include <kernel/gnumpc.h>
    19 #include <kernel/gnumpfl.h>
    20 #include <kernel/mpr_complex.h>
     11#include "coeffs.h"
     12#include "numbers.h"
     13#include "longrat.h"
     14#include "modulop.h"
     15#include "gnumpc.h"
     16#include "gnumpfl.h"
     17#include "mpr_complex.h"
    2118
    2219extern size_t gmp_output_digits;
     
    7168}
    7269
    73 nMapFunc ngcSetMap(const ring src,const ring dst)
     70nMapFunc ngcSetMap(const coeffs src,const coeffs dst)
    7471{
    7572  if(rField_is_Q(src))
     
    106103* n := i
    107104*/
    108 number ngcInit (int i, const ring r)
     105number ngcInit (int i, const coeffs r)
    109106{
    110107  gmp_complex* n= new gmp_complex( (long)i, (long)0 );
     
    115112* convert number to int
    116113*/
    117 int ngcInt(number &i, const ring r)
     114int ngcInt(number &i, const coeffs r)
    118115{
    119116  return (int)((gmp_complex*)i)->real();
     
    138135* delete a
    139136*/
    140 void ngcDelete (number * a, const ring r)
     137void ngcDelete (number * a, const coeffs r)
    141138{
    142139  if ( *a != NULL )
     
    155152  return (number)b;
    156153}
    157 number ngc_Copy(number a, ring r)
     154number ngc_Copy(number a, const coeffs r)
    158155{
    159156  gmp_complex* b=new gmp_complex( *(gmp_complex*)a );
     
    373370* write a floating point number
    374371*/
    375 void ngcWrite (number &a, const ring r)
     372void ngcWrite (number &a, const coeffs r)
    376373{
    377374  if (a==NULL)
     
    382379    out= complexToStr(*(gmp_complex*)a,gmp_output_digits);
    383380    StringAppendS(out);
    384     //    omFreeSize((ADDRESS)out, (strlen(out)+1)* sizeof(char) );
    385     omFree( (ADDRESS)out );
     381    //    omFreeSize((void *)out, (strlen(out)+1)* sizeof(char) );
     382    omFree( (void *)out );
    386383  }
    387384}
  • coeffs/gnumpc.h

    r634d93b r7d90aa  
    88* ABSTRACT: computations with GMP floating-point numbers
    99*/
    10 #include <kernel/structs.h>
     10#include "coeffs.h"
    1111
    12 BOOLEAN  ngcGreaterZero(number za);      // !!! MAY NOT WORK AS EXPECTED !!!
    13 BOOLEAN  ngcGreater(number a, number b);
    14 BOOLEAN  ngcEqual(number a, number b);
    15 BOOLEAN  ngcIsOne(number a);
    16 BOOLEAN  ngcIsMOne(number a);
    17 BOOLEAN  ngcIsZero(number za);
    18 number   ngcInit(int i, const ring r);
    19 int      ngcInt(number &n, const ring r);
    20 number   ngcNeg(number za);
    21 number   ngcInvers(number a);
    22 number   ngcPar(int i);
    23 number   ngcAdd(number la, number li);
    24 number   ngcSub(number la, number li);
    25 number   ngcMult(number a, number b);
    26 number   ngcDiv(number a, number b);
    27 int      ngcSize(number n);
    28 void     ngcPower(number x, int exp, number *lu);
     12BOOLEAN  ngcGreaterZero(number za, const coeffs r); // !!! MAY NOT WORK AS EXPECTED !!!
     13BOOLEAN  ngcGreater(number a, number b, const coeffs r);
     14BOOLEAN  ngcEqual(number a, number b, const coeffs r);
     15BOOLEAN  ngcIsOne(number a, const coeffs r);
     16BOOLEAN  ngcIsMOne(number a, const coeffs r);
     17BOOLEAN  ngcIsZero(number za, const coeffs r);
     18number   ngcInit(int i, const coeffs r);
     19int      ngcInt(number &n, const coeffs r);
     20number   ngcNeg(number za, const coeffs r);
     21number   ngcInvers(number a, const coeffs r);
     22number   ngcPar(int i, const coeffs r);
     23number   ngcAdd(number la, number li, const coeffs r);
     24number   ngcSub(number la, number li, const coeffs r);
     25number   ngcMult(number a, number b, const coeffs r);
     26number   ngcDiv(number a, number b, const coeffs r);
     27void     ngcPower(number x, int exp, number *lu, const coeffs r);
    2928number   ngcCopy(number a);
    30 number   ngc_Copy(number a, ring r);
    31 const char * ngcRead (const char *s, number *a);
    32 void     ngcWrite(number &a, const ring r);
    33 number   ngcRePart(number a);
    34 number   ngcImPart(number a);
     29number   ngc_Copy(number a, coeffs r);
     30const char * ngcRead (const char *s, number *a, const coeffs r);
     31void     ngcWrite(number &a, const coeffs r);
     32number   ngcRePart(number a, const coeffs r);
     33number   ngcImPart(number a, const coeffs r);
    3534
    3635
     
    3837BOOLEAN  ngcDBTest(number a, const char *f, const int l);
    3938#endif
    40 void     ngcDelete(number *a, const ring r);
     39void     ngcDelete(number *a, const coeffs r);
    4140
    42 nMapFunc  ngcSetMap(const ring src, const ring dst);
     41nMapFunc  ngcSetMap(const coeffs src, const coeffs dst);
    4342
    44 number ngcMapQ(number from);
     43number ngcMapQ(number from, const coeffs r);
    4544#endif
    4645
  • coeffs/gnumpfl.cc

    r634d93b r7d90aa  
    382382    out= floatToStr(*(gmp_float*)a,gmp_output_digits);
    383383    StringAppendS(out);
    384     //omFreeSize((ADDRESS)out, (strlen(out)+1)* sizeof(char) );
    385     omFree( (ADDRESS)out );
     384    //omFreeSize((void *)out, (strlen(out)+1)* sizeof(char) );
     385    omFree( (void *)out );
    386386  }
    387387  else
  • coeffs/gnumpfl.h

    r634d93b r7d90aa  
    88* ABSTRACT: computations with GMP floating-point numbers
    99*/
    10 #include <kernel/structs.h>
     10#include "coeffs.h"
    1111
    12 BOOLEAN  ngfGreaterZero(number za);
    13 BOOLEAN  ngfGreater(number a, number b);
    14 BOOLEAN  ngfEqual(number a, number b);
    15 BOOLEAN  ngfIsOne(number a);
    16 BOOLEAN  ngfIsMOne(number a);
    17 BOOLEAN  ngfIsZero(number za);
    18 number   ngfInit(int i, const ring r);
    19 int      ngfInt(number &n, const ring r);
    20 number   ngfNeg(number za);
    21 number   ngfInvers(number a);
    22 number   ngfAdd(number la, number li);
    23 number   ngfSub(number la, number li);
    24 number   ngfMult(number a, number b);
    25 int      ngfSize(number n);
    26 number   ngfDiv(number a, number b);
    27 void     ngfPower(number x, int exp, number *lu);
     12BOOLEAN  ngfGreaterZero(number za, const coeffs r);
     13BOOLEAN  ngfGreater(number a, number b, const coeffs r);
     14BOOLEAN  ngfEqual(number a, number b, const coeffs r);
     15BOOLEAN  ngfIsOne(number a, const coeffs r);
     16BOOLEAN  ngfIsMOne(number a, const coeffs r);
     17BOOLEAN  ngfIsZero(number za, const coeffs r);
     18number   ngfInit(int i, const coeffs r);
     19int      ngfInt(number &n, const coeffs r);
     20number   ngfNeg(number za, const coeffs r);
     21number   ngfInvers(number a, const coeffs r);
     22number   ngfAdd(number la, number li, const coeffs r);
     23number   ngfSub(number la, number li, const coeffs r);
     24number   ngfMult(number a, number b, const coeffs r);
     25number   ngfDiv(number a, number b, const coeffs r);
     26void     ngfPower(number x, int exp, number *lu, const coeffs r);
    2827number   ngfCopy(number a);
    29 number   ngf_Copy(number a, ring r);
    30 const char *   ngfRead (const char *s, number *a);
    31 void     ngfWrite(number &a, const ring r);
     28number   ngf_Copy(number a, coeffs r);
     29const char *   ngfRead (const char *s, number *a, const coeffs r);
     30void     ngfWrite(number &a, const coeffs r);
    3231
    3332#ifdef LDEBUG
    3433BOOLEAN  ngfDBTest(number a, const char *f, const int l);
    3534#endif
    36 void     ngfDelete(number *a, const ring r);
     35void     ngfDelete(number *a, const coeffs r);
    3736
    38 nMapFunc  ngfSetMap(const ring src, const ring dst);
     37nMapFunc  ngfSetMap(const coeffs src, const coeffs dst);
    3938
    4039void setGMPFloatDigits( size_t digits, size_t rest );
    41 number ngfMapQ(number from);
     40number ngfMapQ(number from, const coeffs r);
    4241#endif
  • coeffs/longalg.cc

    r634d93b r7d90aa  
    9292    for (j=naI->anz-1; j>=0; j--)
    9393       p_Delete (&naI->liste[j],nacRing);
    94     omFreeSize((ADDRESS)naI->liste,naI->anz*sizeof(napoly));
    95     omFreeBin((ADDRESS)naI, snaIdeal_bin);
     94    omFreeSize((void *)naI->liste,naI->anz*sizeof(napoly));
     95    omFreeBin((void *)naI, snaIdeal_bin);
    9696    naI=NULL;
    9797  }
     
    978978    p_Delete(&(l->z),r->algring);
    979979    p_Delete(&(l->n),r->algring);
    980     omFreeBin((ADDRESS)l,  rnumber_bin);
     980    omFreeBin((void *)l,  rnumber_bin);
    981981  }
    982982  *p = NULL;
     
    11981198  if(lo->z==NULL)
    11991199  {
    1200     omFreeBin((ADDRESS)lo, rnumber_bin);
     1200    omFreeBin((void *)lo, rnumber_bin);
    12011201    lo=NULL;
    12021202  }
     
    14841484  if(a->z==NULL)
    14851485  {
    1486     omFreeBin((ADDRESS)*p, rnumber_bin);
     1486    omFreeBin((void *)*p, rnumber_bin);
    14871487    *p=NULL;
    14881488  }
     
    15241524    }
    15251525  }
    1526   omFreeSize((ADDRESS)t,8);
     1526  omFreeSize((void *)t,8);
    15271527  if (s[0]=='\0')
    15281528  {
    1529     omFree((ADDRESS)s);
     1529    omFree((void *)s);
    15301530    return NULL;
    15311531  }
     
    21152115    for (i=naI->anz-1; i>=0; i--)
    21162116      p_Delete(&naI->liste[i],nacRing);
    2117     omFreeBin((ADDRESS)naI, snaIdeal_bin);
     2117    omFreeBin((void *)naI, snaIdeal_bin);
    21182118    naI=NULL;
    21192119  }
  • coeffs/longrat.cc

    r634d93b r7d90aa  
    4545#include <string.h>
    4646#include <float.h>
    47 #include <omalloc/omalloc.h>
    48 #include <kernel/febase.h>
    49 #include <kernel/numbers.h>
    50 #include <kernel/modulop.h>
    51 #include <kernel/ring.h>
    52 #include <kernel/shortfl.h>
    53 #include <kernel/mpr_complex.h>
     47#include "coeffs.h"
     48#include "omalloc.h"
     49#include "numbers.h"
     50#include "modulop.h"
     51#include "shortfl.h"
     52#include "mpr_complex.h"
     53#include "longrat.h"
    5454
    5555
     
    660660    bb->debug=654324;
    661661#endif
    662     FREE_RNUMBER(bb);
     662    omFreeBin((void *)bb, rnumber_bin);
    663663  }
    664664  u=nlShort3(u);
     
    726726    bb->debug=654324;
    727727#endif
    728     FREE_RNUMBER(bb);
     728    omFreeBin((void *)bb, rnumber_bin);
    729729  }
    730730  u=nlShort3(u);
     
    803803    bb->debug=654324;
    804804#endif
    805     FREE_RNUMBER(bb);
     805    omFreeBin((void *)bb, rnumber_bin);
    806806  }
    807807  if (mpz_isNeg(u->z))
     
    846846    if (r==0)
    847847    {
    848       FREE_RNUMBER(u);
     848      omFreeBin((void *)u, rnumber_bin);
    849849      return INT_TO_SR(i/j);
    850850    }
     
    13961396#endif
    13971397    }
    1398     FREE_RNUMBER(*a);
     1398    omFreeBin((void *) *a, rnumber_bin);
    13991399  }
    14001400}
     
    24622462    {
    24632463      mpz_clear(&r->z);
    2464       FREE_RNUMBER(r);
     2464      omFreeBin((void *)r, rnumber_bin);
    24652465      r=INT_TO_SR(ui);
    24662466    }
  • coeffs/longrat.h

    r634d93b r7d90aa  
    88* ABSTRACT: computation with long rational numbers
    99*/
    10 #include <kernel/structs.h>
     10#include "coeffs.h"
    1111
    12 #include <kernel/si_gmp.h>
     12#include "si_gmp.h"
     13
     14typedef MP_INT lint;
    1315
    1416#define SR_HDL(A) ((long)(A))
    1517
    1618#define SR_INT    1L
    17 #define INT_TO_SR(INT)  ((number) ((((long)INT) << 2) + SR_INT))
     19#define INT_TO_SR(INT)  ((number) (((long)INT << 2) + SR_INT))
    1820#define SR_TO_INT(SR)   (((long)SR) >> 2)
    19 
    2021
    2122#define MP_SMALL 1
     
    2829struct snumber
    2930{
    30   mpz_t z;
    31   mpz_t n;
     31  lint z;
     32  lint n;
    3233#if defined(LDEBUG)
    3334  int debug;
     
    4546#endif // DO_LINLINE
    4647
    47 LINLINE BOOLEAN  nlEqual(number a, number b);
    48 LINLINE number   nlInit(int i, const ring r);
    49 number nlRInit (long i);
    50 LINLINE BOOLEAN  nlIsOne(number a);
    51 LINLINE BOOLEAN  nlIsZero(number za);
     48LINLINE BOOLEAN  nlEqual(number a, number b, const coeffs r);
     49LINLINE number   nlInit(int i, const coeffs r);
     50number nlRInit (int i);
     51LINLINE BOOLEAN  nlIsOne(number a, const coeffs r);
     52LINLINE BOOLEAN  nlIsZero(number za, const coeffs r);
    5253LINLINE number   nlCopy(number a);
    53 LINLINE void     nlDelete(number *a, const ring r);
    54 LINLINE number   nlNeg(number za);
    55 LINLINE number   nlAdd(number la, number li);
    56 LINLINE number   nlSub(number la, number li);
    57 LINLINE number   nlMult(number a, number b);
     54LINLINE number   nl_Copy(number a, const coeffs r);
     55LINLINE void     nlDelete(number *a, const coeffs r);
     56LINLINE number   nlNeg(number za, const coeffs r);
     57LINLINE number   nlAdd(number la, number li, const coeffs r);
     58LINLINE number   nlSub(number la, number li, const coeffs r);
     59LINLINE number   nlMult(number a, number b, const coeffs r);
    5860
    5961number   nlInit2 (int i, int j);
    6062number   nlInit2gmp (mpz_t i, mpz_t j);
    61 number   nlGcd(number a, number b, const ring r);
    62 number   nlLcm(number a, number b, const ring r);   /*special routine !*/
    63 BOOLEAN  nlGreater(number a, number b);
    64 BOOLEAN  nlIsMOne(number a);
    65 int      nlInt(number &n, const ring r);
     63number   nlGcd(number a, number b, const coeffs r);
     64number   nlLcm(number a, number b, const coeffs r);   /*special routine !*/
     65BOOLEAN  nlGreater(number a, number b, const coeffs r);
     66BOOLEAN  nlIsMOne(number a, const coeffs r);
     67int      nlInt(number &n, const coeffs r);
    6668number   nlBigInt(number &n);
    6769#ifdef HAVE_RINGS
    6870void     nlGMP(number &i, number n);
    6971#endif
    70 BOOLEAN  nlGreaterZero(number za);
    71 number   nlInvers(number a);
    72 void     nlNormalize(number &x);
    73 number   nlDiv(number a, number b);
    74 number   nlExactDiv(number a, number b);
    75 number   nlIntDiv(number a, number b);
    76 number   nlIntMod(number a, number b);
    77 void     nlPower(number x, int exp, number *lu);
    78 const char *   nlRead (const char *s, number *a);
    79 void     nlWrite(number &a, const ring r);
     72BOOLEAN  nlGreaterZero(number za, const coeffs r);
     73number   nlInvers(number a, const coeffs r);
     74void     nlNormalize(number &x, const coeffs r);
     75number   nlDiv(number a, number b, const coeffs r);
     76number   nlExactDiv(number a, number b, const coeffs r);
     77number   nlIntDiv(number a, number b, const coeffs r);
     78number   nlIntMod(number a, number b, const coeffs r);
     79void     nlPower(number x, int exp, number *lu, const coeffs r);
     80const char *   nlRead (const char *s, number *a, const coeffs r);
     81void     nlWrite(number &a, const coeffs r);
    8082int      nlModP(number n, int p);
    81 int      nlSize(number n);
    82 number   nlGetDenom(number &n, const ring r);
    83 number   nlGetNumerator(number &n, const ring r);
     83int      nlSize(number n, const coeffs r);
     84number   nlGetDenom(number &n, const coeffs r);
     85number   nlGetNumerator(number &n, const coeffs r);
    8486number   nlChineseRemainder(number *x, number *q,int rl);
    8587#ifdef LDEBUG
     
    8890extern number nlOne;
    8991
    90 nMapFunc nlSetMap(const ring src, const ring dst);
     92nMapFunc nlSetMap(const coeffs src, const coeffs dst);
    9193#ifdef HAVE_RINGS
    9294number nlMapGMP(number from);
    9395#endif
    9496
    95 //#define SI_THREADS 1
    96 #ifdef SI_THREADS
    97 #define ALLOC_RNUMBER() (number)malloc(sizeof(snumber));
    98 static inline number ALLOC0_RNUMBER() { number n=(number)malloc(sizeof(snumber));memset(n,0,sizeof(snumber));return n; }
    99 #define FREE_RNUMBER(x) free(x)
    100 #else
    101 extern omBin rnumber_bin;
     97#ifndef OM_ALLOC_H
     98struct omBin_s;
     99#endif
     100extern omBin_s* rnumber_bin;
     101
     102
     103#define FREE_RNUMBER(x) omFreeBin((void *)x, rnumber_bin)
    102104#define ALLOC_RNUMBER() (number)omAllocBin(rnumber_bin)
    103105#define ALLOC0_RNUMBER() (number)omAlloc0Bin(rnumber_bin)
    104 #define FREE_RNUMBER(x) omFreeBin((ADDRESS)x, rnumber_bin)
    105 #endif
    106106
    107107// in-place operations
    108 void nlInpGcd(number &a, number b, const ring r);
    109 void nlInpIntDiv(number &a, number b, const ring r);
    110 LINLINE number   nlInpAdd(number la, number li, const ring r);
    111 LINLINE void nlInpMult(number &a, number b, ring r);
     108void nlInpGcd(number &a, number b, const coeffs r);
     109void nlInpIntDiv(number &a, number b, const coeffs r);
     110LINLINE number nlInpAdd(number la, number li, const coeffs r);
     111LINLINE void nlInpMult(number &a, number b, const coeffs r);
    112112
    113113number nlFarey(number nP, number nN);
     
    117117BOOLEAN nlDBTest(number a, char *f,int l);
    118118#else
    119 #define nlTest(a) ((void)1)
     119#define nlTest(a) ((void)0)
    120120#endif
    121121
  • coeffs/longrat0.cc

    r634d93b r7d90aa  
    139139      StringAppendS(z);
    140140    }
    141     omFreeSize((ADDRESS)s,l);
     141    omFreeSize((void *)s,l);
    142142  }
    143143}
  • coeffs/modulop.cc

    r634d93b r7d90aa  
    88
    99#include <string.h>
    10 #include <kernel/mod2.h>
    11 #include <omalloc/mylimits.h>
    12 #include <kernel/structs.h>
    13 #include <kernel/febase.h>
    14 #include <omalloc/omalloc.h>
    15 #include <kernel/numbers.h>
    16 #include <kernel/longrat.h>
    17 #include <kernel/mpr_complex.h>
    18 #include <kernel/ring.h>
    19 #ifdef HAVE_RINGS
    20 #include <si_gmp.h>
    21 #endif
    22 #include <kernel/modulop.h>
    23 
    24 long npPrimeM=0;
     10#include "coeffs.h"
     11#include "numbers.h"
     12#include "longrat.h"
     13#include "mpr_complex.h"
     14#include "modulop.h"
     15
    2516int npGen=0;
    26 long npPminus1M=0;
    2717long npMapPrime;
    2818
     
    3727
    3828
    39 BOOLEAN npGreaterZero (number k)
     29BOOLEAN npGreaterZero (number k, const coeffs r)
    4030{
    4131  int h = (int)((long) k);
    42   return ((int)h !=0) && (h <= (npPrimeM>>1));
     32  return ((int)h !=0) && (h <= (r->npPrimeM>>1));
    4333}
    4434
     
    5141//}
    5242
    53 number npMult (number a,number b)
     43number npMult (number a,number b, const coeffs r)
    5444{
    5545  if (((long)a == 0) || ((long)b == 0))
    5646    return (number)0;
    5747  else
    58     return npMultM(a,b);
     48    return npMultM(a,b, r);
    5949}
    6050
     
    6252* create a number from int
    6353*/
    64 number npInit (int i, const ring r)
     54number npInit (int i, const coeffs r)
    6555{
    6656  long ii=i;
     
    7464* convert a number to int (-p/2 .. p/2)
    7565*/
    76 int npInt(number &n, const ring r)
     66int npInt(number &n, const coeffs r)
    7767{
    7868  if ((long)n > (((long)r->ch) >>1)) return (int)((long)n -((long)r->ch));
     
    8070}
    8171
    82 number npAdd (number a, number b)
    83 {
    84   return npAddM(a,b);
    85 }
    86 
    87 number npSub (number a, number b)
    88 {
    89   return npSubM(a,b);
    90 }
    91 
    92 BOOLEAN npIsZero (number  a)
     72number npAdd (number a, number b, const coeffs r)
     73{
     74  return npAddM(a,b, r);
     75}
     76
     77number npSub (number a, number b, const coeffs r)
     78{
     79  return npSubM(a,b,r);
     80}
     81
     82BOOLEAN npIsZero (number  a, const coeffs r)
    9383{
    9484  return 0 == (long)a;
    9585}
    9686
    97 BOOLEAN npIsOne (number a)
     87BOOLEAN npIsOne (number a, const coeffs r)
    9888{
    9989  return 1 == (long)a;
    10090}
    10191
    102 BOOLEAN npIsMOne (number a)
    103 {
    104   return ((npPminus1M == (long)a)&&((long)1!=(long)a));
     92BOOLEAN npIsMOne (number a, const coeffs r)
     93{
     94  return ((r->npPminus1M == (long)a)&&((long)1!=(long)a));
    10595}
    10696
     
    115105#endif
    116106
    117 long InvMod(long a)
     107long InvMod(long a, const coeffs R)
    118108{
    119109   long d, s, t;
    120110
    121111#ifdef USE_NTL_XGCD
    122    XGCD(d, s, t, a, npPrimeM);
     112   XGCD(d, s, t, a, R->npPrimeM);
    123113   assume (d == 1);
    124114#else
     
    127117   assume(a>0);
    128118   u1=1; u2=0;
    129    u = a; v = npPrimeM;
     119   u = a; v = R->npPrimeM;
    130120
    131121   while (v != 0)
     
    144134#endif
    145135   if (s < 0)
    146       return s + npPrimeM;
     136      return s + R->npPrimeM;
    147137   else
    148138      return s;
     
    150140#endif
    151141
    152 static inline number npInversM (number c)
     142inline number npInversM (number c, const coeffs r)
    153143{
    154144#ifndef HAVE_DIV_MOD
    155   return (number)(long)npExpTable[npPminus1M - npLogTable[(long)c]];
     145  return (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
    156146#else
    157   long inv=(long)npInvTable[(long)c];
     147  long inv=(long)r->npInvTable[(long)c];
    158148  if (inv==0)
    159149  {
    160     inv=InvMod((long)c);
    161     npInvTable[(long)c]=inv;
     150    inv=InvMod((long)c,r);
     151    r->npInvTable[(long)c]=inv;
    162152  }
    163153  return (number)inv;
     
    165155}
    166156
    167 number npDiv (number a,number b)
     157number npDiv (number a,number b, const coeffs r)
    168158{
    169159//#ifdef NV_OPS
     
    181171  else
    182172  {
    183     int s = npLogTable[(long)a] - npLogTable[(long)b];
     173    int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
    184174    if (s < 0)
    185       s += npPminus1M;
    186     return (number)(long)npExpTable[s];
     175      s += r->npPminus1M;
     176    return (number)(long)r->npExpTable[s];
    187177  }
    188178#else
    189   number inv=npInversM(b);
    190   return npMultM(a,inv);
    191 #endif
    192 }
    193 number  npInvers (number c)
     179  number inv=npInversM(b,r);
     180  return npMultM(a,inv,r);
     181#endif
     182}
     183number  npInvers (number c, const coeffs r)
    194184{
    195185  if ((long)c==0)
     
    198188    return (number)0;
    199189  }
    200   return npInversM(c);
    201 }
    202 
    203 number npNeg (number c)
     190  return npInversM(c,r);
     191}
     192
     193number npNeg (number c, const coeffs r)
    204194{
    205195  if ((long)c==0) return c;
    206   return npNegM(c);
    207 }
    208 
    209 BOOLEAN npGreater (number a,number b)
     196  return npNegM(c,r);
     197}
     198
     199BOOLEAN npGreater (number a,number b, const coeffs r)
    210200{
    211201  //return (long)a != (long)b;
     
    213203}
    214204
    215 BOOLEAN npEqual (number a,number b)
     205BOOLEAN npEqual (number a,number b, const coeffs r)
    216206{
    217207//  return (long)a == (long)b;
    218   return npEqualM(a,b);
    219 }
    220 
    221 void npWrite (number &a, const ring r)
     208  return npEqualM(a,b,r);
     209}
     210
     211void npWrite (number &a, const coeffs r)
    222212{
    223213  if ((long)a>(((long)r->ch) >>1)) StringAppend("-%d",(int)(((long)r->ch)-((long)a)));
     
    225215}
    226216
    227 void npPower (number a, int i, number * result)
     217void npPower (number a, int i, number * result, const coeffs r)
    228218{
    229219  if (i==0)
     
    238228  else
    239229  {
    240     npPower(a,i-1,result);
    241     *result = npMultM(a,*result);
    242   }
    243 }
    244 
    245 static const char* npEati(const char *s, int *i)
     230    npPower(a,i-1,result,r);
     231    *result = npMultM(a,*result,r);
     232  }
     233}
     234
     235static const char* npEati(const char *s, int *i, const coeffs r)
    246236{
    247237
     
    253243      ii *= 10;
    254244      ii += *s++ - '0';
    255       if (ii >= (MAX_INT_VAL / 10)) ii = ii % npPrimeM;
     245      if (ii >= (MAX_INT_VAL / 10)) ii = ii % r->npPrimeM;
    256246    }
    257247    while (((*s) >= '0') && ((*s) <= '9'));
    258     if (ii >= npPrimeM) ii = ii % npPrimeM;
     248    if (ii >= npPrimeM) ii = ii % r->npPrimeM;
    259249    *i=(int)ii;
    260250  }
     
    263253}
    264254
    265 const char * npRead (const char *s, number *a)
     255const char * npRead (const char *s, number *a, const coeffs r)
    266256{
    267257  int z;
    268258  int n=1;
    269259
    270   s = npEati(s, &z);
     260  s = npEati(s, &z, r);
    271261  if ((*s) == '/')
    272262  {
    273263    s++;
    274     s = npEati(s, &n);
     264    s = npEati(s, &n, r);
    275265  }
    276266  if (n == 1)
     
    282272    {
    283273#ifdef NV_OPS
    284       if (npPrimeM>NV_MAX_PRIME)
    285         *a = nvDiv((number)z,(number)n);
     274      if (r->npPrimeM>NV_MAX_PRIME)
     275        *a = nvDiv((number)z,(number)n,r);
    286276      else
    287277#endif
    288         *a = npDiv((number)z,(number)n);
     278        *a = npDiv((number)z,(number)n,r);
    289279    }
    290280  }
    291281  return s;
    292282}
    293 
    294 /*2
    295 * the last used charcteristic
    296 */
    297 //int npGetChar()
    298 //{
    299 //  return npPrimeM;
    300 //}
    301283
    302284/*2
     
    304286*/
    305287
    306 void npSetChar(int c, ring r)
     288void npSetChar(int c, coeffs r)
    307289{
    308290
     
    310292  if ((c>1) || (c<(-1)))
    311293  {
    312     if (c>1) npPrimeM = c;
    313     else     npPrimeM = -c;
    314     npPminus1M = npPrimeM - 1;
     294    if (c>1) r->npPrimeM = c;
     295    else     r->npPrimeM = -c;
     296    r->npPminus1M = r->npPrimeM - 1;
    315297#ifdef NV_OPS
    316     if (r->cf->npPrimeM >NV_MAX_PRIME) return;
    317 #endif
    318 #ifdef HAVE_DIV_MOD
    319     npInvTable=r->cf->npInvTable;
     298    if (r->npPrimeM >NV_MAX_PRIME) return;
    320299#endif
    321300#if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
    322     npExpTable=r->cf->npExpTable;
    323     npLogTable=r->cf->npLogTable;
    324301    npGen = npExpTable[1];
    325302#endif
    326303  }
    327   else
    328   {
    329     npPrimeM=0;
    330 #ifdef HAVE_DIV_MOD
    331     npInvTable=NULL;
    332 #endif
    333 #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
    334     npExpTable=NULL;
    335     npLogTable=NULL;
    336 #endif
    337   }
    338 }
    339 
    340 void npInitChar(int c, ring r)
     304}
     305
     306void npInitChar(int c, coeffs r)
    341307{
    342308  int i, w;
     
    344310  if ((c>1) || (c<(-1)))
    345311  {
    346     if (c>1) r->cf->npPrimeM = c;
    347     else     r->cf->npPrimeM = -c;
    348     r->cf->npPminus1M = r->cf->npPrimeM - 1;
     312    if (c>1) r->npPrimeM = c;
     313    else     r->npPrimeM = -c;
     314    r->npPminus1M = r->npPrimeM - 1;
    349315#ifdef NV_OPS
    350     if (r->cf->npPrimeM <=NV_MAX_PRIME)
     316    if (r->npPrimeM <=NV_MAX_PRIME)
    351317#endif
    352318    {
    353319#if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
    354       r->cf->npExpTable=(unsigned short *)omAlloc( r->cf->npPrimeM*sizeof(unsigned short) );
    355       r->cf->npLogTable=(unsigned short *)omAlloc( r->cf->npPrimeM*sizeof(unsigned short) );
    356       r->cf->npExpTable[0] = 1;
    357       r->cf->npLogTable[0] = 0;
    358       if (r->cf->npPrimeM > 2)
     320      r->npExpTable=(unsigned short *)omAlloc( r->npPrimeM*sizeof(unsigned short) );
     321      r->npLogTable=(unsigned short *)omAlloc( r->npPrimeM*sizeof(unsigned short) );
     322      r->npExpTable[0] = 1;
     323      r->npLogTable[0] = 0;
     324      if (r->npPrimeM > 2)
    359325      {
    360326        w = 1;
    361327        loop
    362328        {
    363           r->cf->npLogTable[1] = 0;
     329          r->npLogTable[1] = 0;
    364330          w++;
    365331          i = 0;
     
    367333          {
    368334            i++;
    369             r->cf->npExpTable[i] =(int)(((long)w * (long)r->cf->npExpTable[i-1])
    370                                  % r->cf->npPrimeM);
    371             r->cf->npLogTable[r->cf->npExpTable[i]] = i;
    372             if (/*(i == npPrimeM - 1 ) ||*/ (r->cf->npExpTable[i] == 1))
     335            r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1])
     336                                 % r->npPrimeM);
     337            r->npLogTable[r->npExpTable[i]] = i;
     338            if (/*(i == npPrimeM - 1 ) ||*/ (r->npExpTable[i] == 1))
    373339              break;
    374340          }
    375           if (i == r->cf->npPrimeM - 1)
     341          if (i == r->npPrimeM - 1)
    376342            break;
    377343        }
     
    379345      else
    380346      {
    381         r->cf->npExpTable[1] = 1;
    382         r->cf->npLogTable[1] = 0;
     347        r->npExpTable[1] = 1;
     348        r->npLogTable[1] = 0;
    383349      }
    384350#endif
    385351#ifdef HAVE_DIV_MOD
    386       r->cf->npInvTable=(unsigned short*)omAlloc0( r->cf->npPrimeM*sizeof(unsigned short) );
     352      r->npInvTable=(unsigned short*)omAlloc0( r->npPrimeM*sizeof(unsigned short) );
    387353#endif
    388354    }
     
    395361
    396362#ifdef LDEBUG
    397 BOOLEAN npDBTest (number a, const char *f, const int l)
    398 {
    399   if (((long)a<0) || ((long)a>npPrimeM))
     363BOOLEAN npDBTest (number a, const coeffs r, const char *f, const int l)
     364{
     365  if (((long)a<0) || ((long)a>r->npPrimeM))
    400366  {
    401367    Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
     
    406372#endif
    407373
    408 number npMap0(number from)
    409 {
    410   return npInit(nlModP(from,npPrimeM),currRing);
    411 }
    412 
    413 number npMapP(number from)
     374number npMap0(number from, const coeffs dst_r)
     375{
     376  return npInit(nlModP(from,dst_r->npPrimeM),dst_r);
     377}
     378
     379number npMapP(number from, const coeffs dst_r)
    414380{
    415381  long i = (long)from;
     
    417383  {
    418384    i-=npMapPrime;
    419     while (i < 0) i+=npPrimeM;
    420   }
    421   i%=npPrimeM;
     385    while (i < 0) i+=dst_r->npPrimeM;
     386  }
     387  i%=dst_r->npPrimeM;
    422388  return (number)i;
    423389}
    424390
    425 static number npMapLongR(number from)
     391static number npMapLongR(number from, const coeffs dst_r)
    426392{
    427393  gmp_float *ff=(gmp_float*)from;
     
    436402  size = (*f)[0]._mp_size;
    437403  if (size == 0)
    438     return npInit(0,currRing);
     404    return npInit(0,dst_r);
    439405  if(size<0)
    440406    size = -size;
     
    447413  }
    448414
    449   if(npPrimeM>2)
     415  if(dst_r->npPrimeM>2)
    450416    e=(*f)[0]._mp_exp-size;
    451417  else
     
    490456  if(res->s==0)
    491457    iz=(long)npDiv((number)iz,(number)in);
    492   FREE_RNUMBER(res);
     458  omFreeBin((void *)res, rnumber_bin);
    493459  return (number)iz;
    494460}
     
    507473
    508474  mpz_clear(erg);
    509   omFree((ADDRESS) erg);
     475  omFree((void *) erg);
    510476  return (number) r;
    511477}
     
    521487#endif
    522488
    523 nMapFunc npSetMap(const ring src, const ring dst)
     489nMapFunc npSetMap(const coeffs src, const coeffs dst)
    524490{
    525491#ifdef HAVE_RINGS
    526   if (rField_is_Ring_2toM(src))
     492  if (nField_is_Ring_2toM(src))
    527493  {
    528494    return npMapMachineInt;
    529495  }
    530   if (rField_is_Ring_Z(src) || rField_is_Ring_PtoM(src) || rField_is_Ring_ModN(src))
     496  if (nField_is_Ring_Z(src) || nField_is_Ring_PtoM(src) || nField_is_Ring_ModN(src))
    531497  {
    532498    return npMapGMP;
    533499  }
    534500#endif
    535   if (rField_is_Q(src))
     501  if (nField_is_Q(src))
    536502  {
    537503    return npMap0;
    538504  }
    539   if ( rField_is_Zp(src) )
    540   {
    541     if (rChar(src) == rChar(dst))
     505  if ( nField_is_Zp(src) )
     506  {
     507    if (n_GetChar(src) == n_GetChar(dst))
    542508    {
    543509      return ndCopy;
     
    545511    else
    546512    {
    547       npMapPrime=rChar(src);
     513      npMapPrime=n_GetChar(src);
    548514      return npMapP;
    549515    }
    550516  }
    551   if (rField_is_long_R(src))
     517  if (nField_is_long_R(src))
    552518  {
    553519    return npMapLongR;
     
    561527#ifdef NV_OPS
    562528
    563 number nvMult (number a,number b)
     529number nvMult (number a,number b, const coeffs r)
    564530{
    565531  //if (((long)a == 0) || ((long)b == 0))
     
    584550   u1=1; v1=0;
    585551   u2=0; v2=1;
    586    u = a; v = npPrimeM;
     552   u = a; v = R->npPrimeM;
    587553
    588554   while (v != 0)
     
    603569   //t = v1;
    604570   if (s < 0)
    605       return s + npPrimeM;
     571      return s + R->npPrimeM;
    606572   else
    607573      return s;
    608574}
    609575
    610 static inline number nvInversM (number c)
    611 {
    612   long inv=nvInvMod((long)c);
     576inline number nvInversM (number c, const coeffs r)
     577{
     578  long inv=nvInvMod((long)c,r);
    613579  return (number)inv;
    614580}
    615581
    616 number nvDiv (number a,number b)
     582number nvDiv (number a,number b, const coeffs r)
    617583{
    618584  if ((long)a==0)
     
    625591  else
    626592  {
    627     number inv=nvInversM(b);
    628     return nvMultM(a,inv);
    629   }
    630 }
    631 number  nvInvers (number c)
     593    number inv=nvInversM(b,r);
     594    return nvMultM(a,inv,r);
     595  }
     596}
     597number  nvInvers (number c, const coeffs r)
    632598{
    633599  if ((long)c==0)
     
    636602    return (number)0;
    637603  }
    638   return nvInversM(c);
    639 }
    640 void nvPower (number a, int i, number * result)
     604  return nvInversM(c,r);
     605}
     606void nvPower (number a, int i, number * result, const coeffs r)
    641607{
    642608  if (i==0)
     
    651617  else
    652618  {
    653     nvPower(a,i-1,result);
    654     *result = nvMultM(a,*result);
    655   }
    656 }
    657 #endif
     619    nvPower(a,i-1,result,r);
     620    *result = nvMultM(a,*result,r);
     621  }
     622}
     623#endif
  • coeffs/modulop.h

    r634d93b r7d90aa  
    88* ABSTRACT: numbers modulo p (<=32003)
    99*/
    10 #include <kernel/structs.h>
     10#include "coeffs.h"
    1111
    1212// defines are in struct.h
     
    2222#define NV_MAX_PRIME 32003
    2323
    24 extern long npPrimeM;
    2524extern int npGen;
    2625extern long npMapPrime;
    2726
    28 BOOLEAN npGreaterZero (number k);
    29 number  npMult        (number a, number b);
    30 number  npInit        (int i, const ring r);
    31 int     npInt         (number &n, const ring r);
    32 number  npAdd         (number a, number b);
    33 number  npSub         (number a, number b);
    34 void    npPower       (number a, int i, number * result);
    35 BOOLEAN npIsZero      (number a);
    36 BOOLEAN npIsOne       (number a);
    37 BOOLEAN npIsMOne       (number a);
    38 number  npDiv         (number a, number b);
    39 number  npNeg         (number c);
    40 number  npInvers      (number c);
    41 BOOLEAN npGreater     (number a, number b);
    42 BOOLEAN npEqual       (number a, number b);
    43 void    npWrite       (number &a, const ring r);
    44 const char *  npRead  (const char *s, number *a);
     27BOOLEAN npGreaterZero (number k, const coeffs r);
     28number  npMult        (number a, number b, const coeffs r);
     29number  npInit        (int i, const coeffs r);
     30int     npInt         (number &n, const coeffs r);
     31number  npAdd         (number a, number b,const coeffs r);
     32number  npSub         (number a, number b,const coeffs r);
     33void    npPower       (number a, int i, number * result,const coeffs r);
     34BOOLEAN npIsZero      (number a,const coeffs r);
     35BOOLEAN npIsOne       (number a,const coeffs r);
     36BOOLEAN npIsMOne       (number a,const coeffs r);
     37number  npDiv         (number a, number b,const coeffs r);
     38number  npNeg         (number c,const coeffs r);
     39number  npInvers      (number c,const coeffs r);
     40BOOLEAN npGreater     (number a, number b,const coeffs r);
     41BOOLEAN npEqual       (number a, number b,const coeffs r);
     42void    npWrite       (number &a, const coeffs r);
     43const char *  npRead  (const char *s, number *a,const coeffs r);
    4544#ifdef LDEBUG
    46 BOOLEAN npDBTest      (number a, const char *f, const int l);
    47 #define npTest(A)     npDBTest(A,__FILE__,__LINE__)
     45BOOLEAN npDBTest      (number a,const coeffs r, const char *f, const int l);
     46#define npTest(A,r)     npDBTest(A,r,__FILE__,__LINE__)
    4847#else
    49 #define npTest(A)     (0)
     48#define npTest(A,r)     (0)
    5049#endif
    51 void    npSetChar(int c, ring r);
    52 void    npInitChar(int c, ring r);
     50void    npSetChar(int c, coeffs r);
     51void    npInitChar(int c, coeffs r);
    5352
    5453//int     npGetChar();
    5554
    56 nMapFunc npSetMap(const ring src, const ring dst);
    57 number  npMapP(number from);
    58 number  npMap0(number from);
     55nMapFunc npSetMap(const coeffs src, const coeffs dst);
     56number  npMapP(number from, const coeffs r);
     57number  npMap0(number from, const coeffs r);
    5958/*-------specials for spolys, do NOT use otherwise--------------------------*/
    6059/* for npMultM, npSubM, npNegM, npEqualM : */
     
    8685#endif
    8786#ifdef HAVE_MULT_MOD
    88 static inline number npMultM(number a, number b)
     87static inline number npMultM(number a, number b, const coeffs r)
    8988{
    9089  return (number)
    91     ((((unsigned long) a)*((unsigned long) b)) % ((unsigned long) npPrimeM));
     90    ((((unsigned long) a)*((unsigned long) b)) % ((unsigned long) r->npPrimeM));
    9291}
    9392#else
    94 static inline number npMultM(number a, number b)
     93static inline number npMultM(number a, number b, const coeffs r)
    9594{
    96   long x = (long)npLogTable[(long)a]+npLogTable[(long)b];
    97   return (number)(long)npExpTable[x<npPminus1M ? x : x-npPminus1M];
     95  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
     96  return (number)(long)r->npExpTable[x<r->npPminus1M ? x : x- r->npPminus1M];
    9897}
    9998#endif
     
    120119#endif
    121120#ifdef HAVE_GENERIC_ADD
    122 static inline number npAddM(number a, number b)
     121static inline number npAddM(number a, number b, const coeffs r)
    123122{
    124   long r = (long)a + (long)b;
    125   return (number)(r >= npPrimeM ? r - npPrimeM : r);
     123  long R = (long)a + (long)b;
     124  return (number)(R >= r->npPrimeM ? R - r->npPrimeM : R);
    126125}
    127 static inline number npSubM(number a, number b)
     126static inline number npSubM(number a, number b, const coeffs r)
    128127{
    129128  return (number)((long)a<(long)b ?
    130                        npPrimeM-(long)b+(long)a : (long)a-(long)b);
     129                       r->npPrimeM-(long)b+(long)a : (long)a-(long)b);
    131130}
    132131#else
    133 static inline number npAddM(number a, number b)
     132static inline number npAddM(number a, number b, const coeffs r)
    134133{
    135134   long res = ((long)a + (long)b);
    136    res -= npPrimeM;
     135   res -= r->npPrimeM;
    137136#if SIZEOF_LONG == 8
    138    res += (res >> 63) & npPrimeM;
     137   res += (res >> 63) & r->npPrimeM;
    139138#else
    140    res += (res >> 31) & npPrimeM;
     139   res += (res >> 31) & r->npPrimeM;
    141140#endif
    142141   return (number)res;
    143142}
    144 static inline number npSubM(number a, number b)
     143static inline number npSubM(number a, number b, const coeffs r)
    145144{
    146145   long res = ((long)a - (long)b);
    147146#if SIZEOF_LONG == 8
    148    res += (res >> 63) & npPrimeM;
     147   res += (res >> 63) & r->npPrimeM;
    149148#else
    150    res += (res >> 31) & npPrimeM;
     149   res += (res >> 31) & r->npPrimeM;
    151150#endif
    152151   return (number)res;
     
    154153#endif
    155154
    156 static inline BOOLEAN npIsZeroM (number  a)
     155static inline BOOLEAN npIsZeroM (number  a, const coeffs r)
    157156{
    158157  return 0 == (long)a;
     
    166165*/
    167166
    168 #define npNegM(A)      (number)(npPrimeM-(long)(A))
    169 #define npEqualM(A,B)  ((A)==(B))
     167#define npNegM(A,r)      (number)(r->npPrimeM-(long)(A))
     168#define npEqualM(A,B,r)  ((A)==(B))
    170169
    171170
    172171#ifdef NV_OPS
    173 static inline number nvMultM(number a, number b)
     172static inline number nvMultM(number a, number b, const coeffs r)
    174173{
    175174#if SIZEOF_LONG == 4
     
    179178#endif
    180179  return (number)
    181     (unsigned long)((ULONG64 a)*(ULONG64 b) % (ULONG64 npPrimeM));
     180    (unsigned long)((ULONG64 a)*(ULONG64 b) % (ULONG64 r->npPrimeM));
    182181}
    183 number  nvMult        (number a, number b);
    184 number  nvDiv         (number a, number b);
    185 number  nvInvers      (number c);
    186 void    nvPower       (number a, int i, number * result);
    187 void    nvInpMult     (number &a, number b, const ring r);
     182number  nvMult        (number a, number b, const coeffs r);
     183number  nvDiv         (number a, number b, const coeffs r);
     184number  nvInvers      (number c, const coeffs r);
     185void    nvPower       (number a, int i, number * result, const coeffs r);
    188186#endif
    189187
  • coeffs/mpr_base.cc

    r634d93b r7d90aa  
    429429  for ( i= 0; i <= max; i++ )
    430430  {
    431     omFreeSize( (ADDRESS) points[i]->point, fdim * sizeof(Coord_t) );
    432     omFreeSize( (ADDRESS) points[i], sizeof(onePoint) );
    433   }
    434   omFreeSize( (ADDRESS) points, (max+1) * sizeof(onePointP) );
     431    omFreeSize( (void *) points[i]->point, fdim * sizeof(Coord_t) );
     432    omFreeSize( (void *) points[i], sizeof(onePoint) );
     433  }
     434  omFreeSize( (void *) points, (max+1) * sizeof(onePointP) );
    435435}
    436436
     
    573573    pIter( piter );
    574574  }
    575   omFreeSize( (ADDRESS) vert, (dim+1) * sizeof(int) );
     575  omFreeSize( (void *) vert, (dim+1) * sizeof(int) );
    576576}
    577577
     
    591591    if ( j > dim ) break;
    592592  }
    593   omFreeSize( (ADDRESS) vert, (dim+1) * sizeof(int) );
     593  omFreeSize( (void *) vert, (dim+1) * sizeof(int) );
    594594
    595595  if ( i > num ) return 0;
     
    712712  lifted= true;
    713713
    714   if ( !outerL ) omFreeSize( (ADDRESS) l, (dim+1) * sizeof(int) );
     714  if ( !outerL ) omFreeSize( (void *) l, (dim+1) * sizeof(int) );
    715715}
    716716//<-
     
    811811  } // i
    812812
    813   omFreeSize( (ADDRESS) vert, (idelem+1) * sizeof(int) );
     813  omFreeSize( (void *) vert, (idelem+1) * sizeof(int) );
    814814
    815815#ifdef mprDEBUG_PROT
     
    875875  } // i
    876876
    877   omFreeSize( (ADDRESS) vert, (idelem+1) * sizeof(int) );
     877  omFreeSize( (void *) vert, (idelem+1) * sizeof(int) );
    878878
    879879#ifdef mprDEBUG_PROT
     
    13991399
    14001400  // clean up
    1401   omFreeSize( (ADDRESS) optSum, (LP->m) * sizeof(struct setID) );
     1401  omFreeSize( (void *) optSum, (LP->m) * sizeof(struct setID) );
    14021402
    14031403  mprSTICKYPROT(ST_SPARSE_RC);
     
    14791479
    14801480  pDelete( &epp );
    1481   omFreeSize( (ADDRESS) epp_mon, (n+2) * sizeof(int) );
    1482   omFreeSize( (ADDRESS) eexp, (pVariables+1)*sizeof(int));
     1481  omFreeSize( (void *) epp_mon, (n+2) * sizeof(int) );
     1482  omFreeSize( (void *) eexp, (pVariables+1)*sizeof(int));
    14831483
    14841484#ifdef mprDEBUG_ALL
     
    15421542  }
    15431543
    1544   omFreeSize( (ADDRESS) vert.point, (pVariables+2) * sizeof(Coord_t) );
     1544  omFreeSize( (void *) vert.point, (pVariables+2) * sizeof(Coord_t) );
    15451545
    15461546  return vs;
     
    17171717    delete Qi[i];
    17181718  }
    1719   omFreeSize( (ADDRESS) Qi, idelem * sizeof(pointSet*) );
     1719  omFreeSize( (void *) Qi, idelem * sizeof(pointSet*) );
    17201720
    17211721  delete E;
     
    20972097    }
    20982098    // OB: ????? (solve_s.tst)
    2099     omfreeSize( (ADDRESS)resVectorList[i].numColVector,
     2099    omfreeSize( (void *)resVectorList[i].numColVector,
    21002100                numVectors * sizeof( number ) );
    2101     omfreeSize( (ADDRESS)resVectorList[i].numColParNr,
     2101    omfreeSize( (void *)resVectorList[i].numColParNr,
    21022102                (pVariables+1) * sizeof(int) );
    21032103  }
    21042104
    2105   omFreeSize( (ADDRESS)resVectorList, veclistmax*sizeof( resVector ) );
     2105  omFreeSize( (void *)resVectorList, veclistmax*sizeof( resVector ) );
    21062106
    21072107  // free matrix m
     
    30553055  // free some stuff: pev, presult
    30563056  for ( i=0; i < n; i++ ) nDelete( pev + i );
    3057   omFreeSize( (ADDRESS)pev, n * sizeof( number ) );
     3057  omFreeSize( (void *)pev, n * sizeof( number ) );
    30583058
    30593059  for ( i=0; i <= tdg; i++ ) nDelete( presults+i );
    3060   omFreeSize( (ADDRESS)presults, (tdg + 1) * sizeof( number ) );
     3060  omFreeSize( (void *)presults, (tdg + 1) * sizeof( number ) );
    30613061
    30623062  return roots;
     
    31723172  // free some stuff: pev, presult
    31733173  for ( i=0; i < n; i++ ) nDelete( pevpoint + i );
    3174   omFreeSize( (ADDRESS)pevpoint, n * sizeof( number ) );
     3174  omFreeSize( (void *)pevpoint, n * sizeof( number ) );
    31753175
    31763176  return roots;
  • coeffs/mpr_complex.cc

    r634d93b r7d90aa  
    598598  && (strlen(in)-(in[0]=='-'?1:0) == oprec) )
    599599  {
    600     omFree( (ADDRESS) in );
     600    omFree( (void *) in );
    601601    insize= (exponent+oprec+2) * sizeof(char) + 10;
    602602    in= (char*)omAlloc( insize );
     
    605605  }
    606606  nout= nicifyFloatStr( in, exponent, oprec, &size, SIGN_EMPTY );
    607   omFree( (ADDRESS) in );
     607  omFree( (void *) in );
    608608  out= (char*)omAlloc( (strlen(nout)+1) * sizeof(char) );
    609609  strcpy( out, nout );
    610   omFree( (ADDRESS) nout );
     610  omFree( (void *) nout );
    611611
    612612  return out;
     
    740740        sprintf(out,"(%s%s)",c.imag().sign()>=0?"I*":"-I*",in_imag);
    741741    }
    742     omFree( (ADDRESS) in_real );
    743     omFree( (ADDRESS) in_imag );
     742    omFree( (void *) in_real );
     743    omFree( (void *) in_imag );
    744744  }
    745745  else
  • coeffs/mpr_complex.h

    r634d93b r7d90aa  
    1414//-> include & define stuff
    1515// must have gmp version >= 2
    16 #include <kernel/si_gmp.h>
    17 #include <kernel/numbers.h>
    18 #include <kernel/ring.h>
    19 #include <kernel/mpr_global.h>
     16#include "si_gmp.h"
     17#include "numbers.h"
     18#include "mpr_global.h"
    2019
    2120#define ZTOF 1
     
    302301gmp_complex sqrt( const gmp_complex & x );
    303302
    304 inline gmp_complex numberToComplex( number num )
    305 {
    306   if (rField_is_long_C()) {
     303inline gmp_complex numberToComplex( number num, const coeffs r )
     304{
     305  if (nField_is_long_C(r))
     306  {
    307307    return *(gmp_complex*)num;
    308   } else {
     308  }
     309  else
     310  {
    309311    return gmp_complex( numberToFloat(num) );
    310312  }
  • coeffs/mpr_numeric.cc

    r634d93b r7d90aa  
    5555  int j;
    5656  for ( j= 0; j < cn; j++ ) nDelete( x+j );
    57   omFreeSize( (ADDRESS)x, cn * sizeof( number ) );
     57  omFreeSize( (void *)x, cn * sizeof( number ) );
    5858}
    5959
     
    145145  }
    146146
    147   omFreeSize( (ADDRESS) exp, (n+1) * sizeof(int) );
     147  omFreeSize( (void *) exp, (n+1) * sizeof(int) );
    148148
    149149  pSortAdd(pit);
     
    242242  // free mem
    243243  for ( j= 0; j < cn; j++ ) nDelete( c+j );
    244   omFreeSize( (ADDRESS)c, cn * sizeof( number ) );
     244  omFreeSize( (void *)c, cn * sizeof( number ) );
    245245
    246246  nDelete( &tmp1 );
     
    289289  {
    290290    for ( i=0; i < anz+2; i++ ) nDelete( ievpoint + i );
    291     omFreeSize( (ADDRESS)ievpoint, (anz+2) * sizeof( number ) );
     291    omFreeSize( (void *)ievpoint, (anz+2) * sizeof( number ) );
    292292  }
    293293
    294294  for ( i=0; i <= tdg; i++ ) nDelete( coeffs + i );
    295   omFreeSize( (ADDRESS)coeffs, (tdg+1) * sizeof( number ) );
     295  omFreeSize( (void *)coeffs, (tdg+1) * sizeof( number ) );
    296296
    297297  // theroots löschen
    298298  for ( i=0; i < tdg; i++ ) delete theroots[i];
    299   omFreeSize( (ADDRESS) theroots, (tdg)*sizeof(gmp_complex*) );
     299  omFreeSize( (void *) theroots, (tdg)*sizeof(gmp_complex*) );
    300300
    301301  //mprPROTnl("~rootContainer()");
     
    464464  // free memory
    465465  for ( i=0; i <= tdg; i++ ) delete ad[i];
    466   omFreeSize( (ADDRESS) ad, (tdg+1)*sizeof(gmp_complex*) );
     466  omFreeSize( (void *) ad, (tdg+1)*sizeof(gmp_complex*) );
    467467
    468468  return found_roots;
     
    547547  mprSTICKYPROT("\n");
    548548  for ( i=0; i <= tdg; i++ ) delete ad[i];
    549   omFreeSize( (ADDRESS) ad, (tdg+1)*sizeof( gmp_complex* ));
     549  omFreeSize( (void *) ad, (tdg+1)*sizeof( gmp_complex* ));
    550550
    551551  return ret;
     
    10071007  for( i= 0; i < LiPM_rows; i++ )
    10081008  {
    1009     omFreeSize( (ADDRESS) LiPM[i], LiPM_cols * sizeof(mprfloat) );
    1010   }
    1011   omFreeSize( (ADDRESS) LiPM, LiPM_rows * sizeof(mprfloat *) );
    1012 
    1013   omFreeSize( (ADDRESS) iposv, 2*LiPM_rows*sizeof(int) );
    1014   omFreeSize( (ADDRESS) izrov, 2*LiPM_rows*sizeof(int) );
     1009    omFreeSize( (void *) LiPM[i], LiPM_cols * sizeof(mprfloat) );
     1010  }
     1011  omFreeSize( (void *) LiPM, LiPM_rows * sizeof(mprfloat *) );
     1012
     1013  omFreeSize( (void *) iposv, 2*LiPM_rows*sizeof(int) );
     1014  omFreeSize( (void *) izrov, 2*LiPM_rows*sizeof(int) );
    10151015}
    10161016
     
    11291129      icase=-2;
    11301130      // free mem l1,l2,l3;
    1131       omFreeSize( (ADDRESS) l3, (m+1) * sizeof(int) );
    1132       omFreeSize( (ADDRESS) l2, (m+1) * sizeof(int) );
    1133       omFreeSize( (ADDRESS) l1, (n+1) * sizeof(int) );
     1131      omFreeSize( (void *) l3, (m+1) * sizeof(int) );
     1132      omFreeSize( (void *) l2, (m+1) * sizeof(int) );
     1133      omFreeSize( (void *) l1, (n+1) * sizeof(int) );
    11341134      return;
    11351135    }
     
    11561156        icase= -1; // no solution found
    11571157        // free mem l1,l2,l3;
    1158         omFreeSize( (ADDRESS) l3, (m+1) * sizeof(int) );
    1159         omFreeSize( (ADDRESS) l2, (m+1) * sizeof(int) );
    1160         omFreeSize( (ADDRESS) l1, (n+1) * sizeof(int) );
     1158        omFreeSize( (void *) l3, (m+1) * sizeof(int) );
     1159        omFreeSize( (void *) l2, (m+1) * sizeof(int) );
     1160        omFreeSize( (void *) l1, (n+1) * sizeof(int) );
    11611161        return;
    11621162      }
     
    11931193        icase = -1; // no solution found
    11941194        // free mem l1,l2,l3;
    1195         omFreeSize( (ADDRESS) l3, (m+1) * sizeof(int) );
    1196         omFreeSize( (ADDRESS) l2, (m+1) * sizeof(int) );
    1197         omFreeSize( (ADDRESS) l1, (n+1) * sizeof(int) );
     1195        omFreeSize( (void *) l3, (m+1) * sizeof(int) );
     1196        omFreeSize( (void *) l2, (m+1) * sizeof(int) );
     1197        omFreeSize( (void *) l1, (n+1) * sizeof(int) );
    11981198        return;
    11991199      }
     
    12411241      icase=0; // finite solution found
    12421242      // free mem l1,l2,l3
    1243       omFreeSize( (ADDRESS) l3, (m+1) * sizeof(int) );
    1244       omFreeSize( (ADDRESS) l2, (m+1) * sizeof(int) );
    1245       omFreeSize( (ADDRESS) l1, (n+1) * sizeof(int) );
     1243      omFreeSize( (void *) l3, (m+1) * sizeof(int) );
     1244      omFreeSize( (void *) l2, (m+1) * sizeof(int) );
     1245      omFreeSize( (void *) l1, (n+1) * sizeof(int) );
    12461246      return;
    12471247    }
     
    12551255      icase=1;                /* unbounded */
    12561256      // free mem
    1257       omFreeSize( (ADDRESS) l3, (m+1) * sizeof(int) );
    1258       omFreeSize( (ADDRESS) l2, (m+1) * sizeof(int) );
    1259       omFreeSize( (ADDRESS) l1, (n+1) * sizeof(int) );
     1257      omFreeSize( (void *) l3, (m+1) * sizeof(int) );
     1258      omFreeSize( (void *) l2, (m+1) * sizeof(int) );
     1259      omFreeSize( (void *) l1, (n+1) * sizeof(int) );
    12601260      return;
    12611261    }
  • coeffs/numbers.cc

    r634d93b r7d90aa  
    1010#include <string.h>
    1111#include <stdlib.h>
    12 #include <kernel/mod2.h>
    13 #include <kernel/structs.h>
    14 #include <kernel/febase.h>
    15 #include <kernel/kstd1.h>
    16 #include <kernel/numbers.h>
    17 #include <kernel/longrat.h>
    18 #include <kernel/longalg.h>
    19 #include <kernel/longtrans.h>
    20 #include <kernel/modulop.h>
    21 #include <kernel/gnumpfl.h>
    22 #include <kernel/gnumpc.h>
    23 #include <kernel/ring.h>
    24 #include <kernel/ffields.h>
    25 #include <kernel/shortfl.h>
     12#include "coeffs.h"
     13#include "numbers.h"
     14#include "longrat.h"
     15#include "longalg.h"
     16#include "modulop.h"
     17#include "gnumpfl.h"
     18#include "gnumpc.h"
     19#include "ffields.h"
     20#include "shortfl.h"
     21#include "longtrans.h"
    2622#ifdef HAVE_RINGS
    2723#include <kernel/rmodulo2m.h>
     
    3531extern int IsPrime(int p);
    3632
    37 number  (*nInit_bigint)(number i);
    38 number (*nPar)(int i);
    39 int    (*nParDeg)(number n);
    40 int    (*nSize)(number n);
    41 int    (*n_Int)(number &n, const ring r);
    42 numberfunc nMult, nSub, nAdd, nDiv, nIntDiv, nIntMod, nExactDiv;
    43 number (*nNeg)(number a);
    44 number (*nInvers)(number a);
    45 void   (*nNormalize)(number &a);
    46 number (*nCopy)(number a);
    47 number (*nRePart)(number a);
    48 number (*nImPart)(number a);
    49 #ifdef HAVE_RINGS
    50 BOOLEAN (*nDivBy)(number a,number b);
    51 int     (*nDivComp)(number a,number b);
    52 BOOLEAN (*nIsUnit)(number a);
    53 number  (*nGetUnit)(number a);
    54 number  (*nExtGcd)(number a, number b, number *s, number *t);
    55 #endif
    56 BOOLEAN (*nGreater)(number a,number b);
    57 BOOLEAN (*nEqual)(number a,number b);
    58 BOOLEAN (*nIsZero)(number a);
    59 BOOLEAN (*nIsOne)(number a);
    60 BOOLEAN (*nIsMOne)(number a);
    61 BOOLEAN (*nGreaterZero)(number a);
    62 const char* (*nRead)(const char *s,number *a);
    63 void    (*nPower)(number a, int i, number * result);
    64 number  (*nGcd)(number a, number b, const ring r);
    65 number  (*nLcm)(number a, number b, const ring r);
    66 char * (*nName)(number n);
    67 
    6833/*0 implementation*/
    6934number nNULL; /* the 0 as constant */
     
    7237
    7338void   nNew(number* d) { *d=NULL; }
    74 void   ndDelete(number* d, const ring r) { *d=NULL; }
    75 void   ndInpMult(number &a, number b, const ring r)
     39void   ndDelete(number* d, const coeffs r) { *d=NULL; }
     40void   ndInpMult(number &a, number b, const coeffs r)
    7641{
    7742  number n=n_Mult(a,b,r);
     
    7944  a=n;
    8045}
    81 number ndInpAdd(number &a, number b, const ring r)
     46number ndInpAdd(number &a, number b, const coeffs r)
    8247{
    8348  number n=n_Add(a,b,r);
     
    9560#endif
    9661
    97 void   nDummy2(number& d) { }
    98 
    99 char * ndName(number n) { return NULL; }
    100 
    101 number ndPar(int i) { return nInit(0); }
    102 
    103 number ndReturn0(number n) { return nInit(0); }
    104 
    105 int    ndParDeg(number n) { return 0; }
    106 
    107 number ndGcd(number a, number b, const ring r) { return n_Init(1,r); }
    108 
    109 number ndIntMod(number a, number b) { return nInit(0); }
    110 
    111 number ndGetDenom(number &n, const ring r) { return n_Init(1,r); }
    112 number ndGetNumerator(number &a,const ring r) { return r->cf->nCopy(a); }
    113 
    114 int ndSize(number a) { return (int)nIsZero(a)==FALSE; }
     62void   nDummy2(number& d, const coeffs r) { }
     63
     64char * ndName(number n, const coeffs r) { return NULL; }
     65
     66number ndPar(int i, const coeffs r) { return n_Init(0,r); }
     67
     68number ndReturn0(number n, const coeffs r) { return n_Init(0,r); }
     69
     70int    ndParDeg(number n, const coeffs r) { return 0; }
     71
     72number ndGcd(number a, number b, const coeffs r) { return n_Init(1,r); }
     73
     74number ndIntMod(number a, number b, const coeffs r) { return n_Init(0,r); }
     75
     76number ndGetDenom(number &n, const coeffs r) { return n_Init(1,r); }
     77number ndGetNumerator(number &a,const coeffs r) { return n_Copy(a,r); }
     78
     79int ndSize(number a, const coeffs r) { return (int)n_IsZero(a,r)==FALSE; }
    11580
    11681number ndCopy(number a) { return a; }
    117 number nd_Copy(number a,const ring r) { return r->cf->nCopy(a); }
     82number nd_Copy(number a,const coeffs r) { return r->nCopy(a); }
    11883
    11984#ifdef HAVE_RINGS
     
    12893* init nDelete    for characteristic c (complete==FALSE)
    12994*/
    130 void nSetChar(ring r)
     95void nSetChar(coeffs r)
    13196{
    13297  int c=rInternalChar(r);
    13398
    13499  /*--------------------- Q -----------------*/
    135   if (rField_is_Q(r))
    136   {
    137     nInit_bigint=nlCopy;
     100  if (nField_is_Q(r))
     101  {
     102    r->nInit_bigint=nl_Copy;
    138103  }
    139104  /*--------------------- Q_a/ Zp_a -----------------*/
    140   else if (rField_is_Extension(r))
    141   {
     105  else if (nField_is_Extension(r))
     106  {
     107    if (r->minpoly != NULL)
     108    {
    142109      naSetChar(c,r);
    143       if (rField_is_Q_a()) nInit_bigint=naMap00;
    144       if (rField_is_Zp_a()) nInit_bigint=naMap0P;
     110      if (rField_is_Q_a(r)) r->nInit_bigint=naMap00;
     111      if (rField_is_Zp_a(r)) r->nInit_bigint=naMap0P;
     112    }
     113    else
     114    {
     115      ntSetChar(c,r);
     116      if (rField_is_Q_a(r)) r->nInit_bigint=ntMap00;
     117      if (rField_is_Zp_a(r)) r->nInit_bigint=ntMap0P;
     118    }
    145119  }
    146120#ifdef HAVE_RINGS
    147121  /*----------------------ring Z / 2^m----------------*/
    148   else if (rField_is_Ring_2toM(r))
     122  else if (nField_is_Ring_2toM(r))
    149123  {
    150124    nr2mSetExp(c, r);
    151     nInit_bigint=nr2mMapQ;
     125    r->nInit_bigint=nr2mMapQ;
    152126  }
    153127  /*----------------------ring Z ----------------*/
    154   else if (rField_is_Ring_Z(r))
     128  else if (nField_is_Ring_Z(r))
    155129  {
    156130    nrzSetExp(c, r);
    157     nInit_bigint=nrzMapQ;
     131    r->nInit_bigint=nrzMapQ;
    158132  }
    159133  /*----------------------ring Z / n----------------*/
    160   else if (rField_is_Ring_ModN(r))
     134  else if (nField_is_Ring_ModN(r))
    161135  {
    162136    nrnSetExp(c, r);
    163     nInit_bigint=nrnMapQ;
     137    r->nInit_bigint=nrnMapQ;
    164138  }
    165139  /*----------------------ring Z / n----------------*/
    166   else if (rField_is_Ring_PtoM(r))
     140  else if (nField_is_Ring_PtoM(r))
    167141  {
    168142    nrnSetExp(c, r);
    169     nInit_bigint=nrnMapQ;
    170   }
    171 #endif
    172   else if (rField_is_Zp(r))
     143    r->nInit_bigint=nrnMapQ;
     144  }
     145#endif
     146  else if (nField_is_Zp(r))
    173147  /*----------------------char. p----------------*/
    174148  {
    175149    npSetChar(c, r);
    176     nInit_bigint=npMap0;
     150    r->nInit_bigint=npMap0;
    177151  }
    178152  /* -------------- GF(p^m) -----------------------*/
    179   else if (rField_is_GF(r))
     153  else if (nField_is_GF(r))
    180154  {
    181155    nfSetChar(c,r->parameter);
    182     nInit_bigint=ndReturn0; // not impl.
     156    r->nInit_bigint=ndReturn0; // not impl.
    183157  }
    184158  /* -------------- R -----------------------*/
    185159  //if (c==(-1))
    186   else if (rField_is_R(r))
    187   {
    188     nInit_bigint=nrMapQ;
     160  else if (nField_is_R(r))
     161  {
     162    r->nInit_bigint=nrMapQ;
    189163  }
    190164  /* -------------- long R -----------------------*/
    191165  /* -------------- long C -----------------------*/
    192   else if ((rField_is_long_R(r))
    193   || (rField_is_long_C(r)))
     166  else if ((nField_is_long_R(r))
     167  || (nField_is_long_C(r)))
    194168  {
    195169    setGMPFloatDigits(r->float_len,r->float_len2);
    196     if (rField_is_long_R(r)) nInit_bigint=ngfMapQ;
    197     else                     nInit_bigint=ngcMapQ;
     170    if (nField_is_long_R(r)) r->nInit_bigint=ngfMapQ;
     171    else                     r->nInit_bigint=ngcMapQ;
    198172  }
    199173#ifdef TEST
    200174  /* -------------- R -----------------------*/
    201175  //if (c==(-1))
    202   else if (!rField_is_R(r) && !rField_is_Q(r))
     176  else if (!nField_is_R(r) && !nField_is_Q(r))
    203177  {
    204178    WerrorS("unknown field");
    205179  }
    206180#endif
    207   nNormalize=r->cf->nNormalize;
    208   nPar   = r->cf->nPar;
    209   nParDeg= r->cf->nParDeg;
    210   n_Int  = r->cf->n_Int;
    211   nAdd   = r->cf->nAdd;
    212   nSub   = r->cf->nSub;
    213   nMult  = r->cf->nMult;
    214   nDiv   = r->cf->nDiv;
    215   nExactDiv= r->cf->nExactDiv;
    216   nIntDiv= r->cf->nIntDiv;
    217   nIntMod= r->cf->nIntMod;
    218   nNeg   = r->cf->nNeg;
    219   nInvers= r->cf->nInvers;
    220   nCopy  = r->cf->nCopy;
    221 #ifdef HAVE_RINGS
    222   nDivComp  = r->cf->nDivComp;
    223   nDivBy = r->cf->nDivBy;
    224   nIsUnit = r->cf->nIsUnit;
    225   nGetUnit = r->cf->nGetUnit;
    226   nExtGcd = r->cf->nExtGcd;
    227 #endif
    228   nGreater = r->cf->nGreater;
    229   nEqual = r->cf->nEqual;
    230   nIsZero = r->cf->nIsZero;
    231   nIsOne = r->cf->nIsOne;
    232   nIsMOne = r->cf->nIsMOne;
    233   nGreaterZero = r->cf->nGreaterZero;
    234   nRead = r->cf->nRead;
    235   nPower = r->cf->nPower;
    236   nGcd  = r->cf->nGcd;
    237   nLcm  = r->cf->nLcm;
    238   nName= r->cf->nName;
    239   nSize  = r->cf->nSize;
    240   nRePart = r->cf->nRePart;
    241   nImPart = r->cf->nImPart;
    242   nNULL=r->cf->nNULL;
    243181}
    244182
    245183/*2
    246 * init operations for ring r
     184* init operations for coeffs r
    247185*/
    248 void nInitChar(ring r)
     186void nInitChar(coeffs r)
    249187{
    250   int c=rInternalChar(r);
    251 
    252   if (rField_is_Extension(r))
     188  int c=nInternalChar(r);
     189  n_coeffType t=nFieldType(r);
     190
     191  if (nField_is_Extension(r))
    253192  {
    254193    if (r->algring==NULL)
     
    282221  {
    283222    n->ref++;
    284     r->cf=n;
     223    r=n;
    285224    return;
    286225  }
     
    290229    return;
    291230  }
    292   r->cf=n;
     231  r=n;
    293232  n->nChar = c;
    294233  n->nPar  = ndPar;
     
    313252  n->nGetUnit = (nMapFunc)NULL;
    314253#endif
    315   if (rField_is_Extension(r))
     254  if (nField_is_Extension(r))
    316255  {
    317256    //naInitChar(c,TRUE,r);
     
    354293#ifdef HAVE_RINGS
    355294  /* -------------- Z/2^m ----------------------- */
    356   else if (rField_is_Ring_2toM(r))
     295  else if (nField_is_Ring_2toM(r))
    357296  {
    358297     nr2mInitExp(c,r);
     
    393332  }
    394333  /* -------------- Z/n ----------------------- */
    395   else if (rField_is_Ring_ModN(r) || rField_is_Ring_PtoM(r)
     334  else if (nField_is_Ring_ModN(r) || nField_is_Ring_PtoM(r)
    396335  )
    397336  {
     
    436375  }
    437376  /* -------------- Z ----------------------- */
    438   else if (rField_is_Ring_Z(r))
     377  else if (nField_is_Ring_Z(r))
    439378  {
    440379     n->cfInit  = nrzInit;
     
    477416  }
    478417#endif
    479   else if (rField_is_Q(r))
     418  else if (nField_is_Q(r))
    480419  {
    481420    n->cfDelete= nlDelete;
     
    513452#endif
    514453  }
    515   else if (rField_is_Zp(r))
     454  else if (nField_is_Zp(r))
    516455  /*----------------------char. p----------------*/
    517456  {
     
    555494  }
    556495  /* -------------- GF(p^m) -----------------------*/
    557   else if (rField_is_GF(r))
     496  else if (nField_is_GF(r))
    558497  {
    559498    //nfSetChar(c,r->parameter);
     
    588527  /* -------------- R -----------------------*/
    589528  //if (c==(-1))
    590   else if (rField_is_R(r))
     529  else if (nField_is_R(r))
    591530  {
    592531    n->cfInit = nrInit;
     
    617556  }
    618557  /* -------------- long R -----------------------*/
    619   else if (rField_is_long_R(r))
     558  else if (nField_is_long_R(r))
    620559  {
    621560    n->cfDelete= ngfDelete;
     
    647586  }
    648587  /* -------------- long C -----------------------*/
    649   else if (rField_is_long_C(r))
     588  else if (nField_is_long_C(r))
    650589  {
    651590    n->cfDelete= ngcDelete;
     
    692631    n->nNULL=n->cfInit(0,r);
    693632    if (n->nRePart==NULL)
    694       n->nRePart=n->nCopy;
     633      n->nRePart=n->cfCopy;
    695634    if (n->nIntDiv==NULL)
    696635      n->nIntDiv=n->nDiv;
     
    698637}
    699638
    700 void nKillChar(ring r)
     639void nKillChar(coeffs r)
    701640{
    702641  if (r!=NULL)
    703642  {
    704     if (r->cf!=NULL)
     643    r->ref--;
     644    if (r->ref<=0)
    705645    {
    706       r->cf->ref--;
    707       if (r->cf->ref<=0)
     646      n_Procs_s tmp;
     647      n_Procs_s* n=&tmp;
     648      tmp.next=cf_root;
     649      while((n->next!=NULL) && (n->next!=r)) n=n->next;
     650      if (n->next==r)
    708651      {
    709         n_Procs_s tmp;
    710         n_Procs_s* n=&tmp;
    711         tmp.next=cf_root;
    712         while((n->next!=NULL) && (n->next!=r->cf)) n=n->next;
    713         if (n->next==r->cf)
     652        n->next=n->next->next;
     653        if (cf_root==r) cf_root=n->next;
     654        r->cfDelete(&(r->nNULL),r);
     655        switch(r->type)
    714656        {
    715           n->next=n->next->next;
    716           if (cf_root==r->cf) cf_root=n->next;
    717           r->cf->cfDelete(&(r->cf->nNULL),r);
    718           switch(r->cf->type)
    719           {
    720             case n_Zp:
    721                  #ifdef HAVE_DIV_MOD
    722                  if (r->cf->npInvTable!=NULL)
    723                  omFreeSize( (ADDRESS)r->cf->npInvTable,
    724                              r->cf->npPrimeM*sizeof(unsigned short) );
    725                  #else
    726                  if (r->cf->npExpTable!=NULL)
     657          case n_Zp:
     658               #ifdef HAVE_DIV_MOD
     659               if (r->npInvTable!=NULL)
     660               omFreeSize( (void *)r->npInvTable,
     661                           r->npPrimeM*sizeof(unsigned short) );
     662               #else
     663               if (r->npExpTable!=NULL)
     664               {
     665                 omFreeSize( (void *)r->npExpTable,
     666                             r->npPrimeM*sizeof(unsigned short) );
     667                 omFreeSize( (void *)r->npLogTable,
     668                             r->npPrimeM*sizeof(unsigned short) );
     669               }
     670               #endif
     671               break;
     672          case n_Zp_a:
     673          case n_Q_a:
     674               {
     675                 number n=r->minpoly;
     676                 if (n!=NULL)
    727677                 {
    728                    omFreeSize( (ADDRESS)r->cf->npExpTable,
    729                                r->cf->npPrimeM*sizeof(unsigned short) );
    730                    omFreeSize( (ADDRESS)r->cf->npLogTable,
    731                                r->cf->npPrimeM*sizeof(unsigned short) );
     678                   r->minpoly=NULL;
     679                   naDelete(&n,r);
    732680                 }
    733                  #endif
    734                  break;
    735             case n_Zp_a:
    736             case n_Q_a:
    737                  {
    738                    number n=r->minpoly;
    739                    if (n!=NULL)
    740                    {
    741                      r->minpoly=NULL;
    742                      if (r==currRing) naMinimalPoly=NULL;
    743                      naDelete(&n,r);
    744                    }
    745                  }
    746                  break;
     681               }
     682               break;
    747683
    748684            default:
    749685                 break;
    750686          }
    751           omFreeSize((ADDRESS)r->cf, sizeof(n_Procs_s));
    752           r->cf=NULL;
     687          omFreeSize((void *)r, sizeof(n_Procs_s));
     688          r=NULL;
    753689        }
    754690        else
     
    759695      r->cf=NULL;
    760696    }
    761     if (r->algring!=NULL)
    762     {
    763       rKill(r->algring);
    764       r->algring=NULL;
    765     }
     697    //if (r->algring!=NULL)
     698    //{
     699    //  rKill(r->algring);
     700    //  r->algring=NULL;
     701    //}
    766702  }
    767703}
  • coeffs/numbers.h

    r634d93b r7d90aa  
    88* ABSTRACT: interface to coefficient aritmetics
    99*/
    10 #include <kernel/structs.h>
    11 
    12 #define n_Copy(n, r)          (r)->cf->cfCopy(n,r)
    13 #define n_Delete(n, r)        (r)->cf->cfDelete(n,r)
    14 #define n_Mult(n1, n2, r)     (r)->cf->nMult(n1, n2)
    15 #define n_Add(n1, n2, r)      (r)->cf->nAdd(n1, n2)
    16 #define n_IsZero(n, r)        (r)->cf->nIsZero(n)
    17 #define n_Equal(n1, n2, r)    (r)->cf->nEqual(n1, n2)
    18 #define n_Neg(n, r)           (r)->cf->nNeg(n)
    19 #define n_Sub(n1, n2, r)      (r)->cf->nSub(n1, n2)
    20 //#define n_GetChar(r)          ((r)->cf->nChar)
     10#include "coeffs.h"
     11
     12#define SHORT_REAL_LENGTH 6 // use short reals for real <= 6 digits
     13
     14#define n_Copy(n, r)          (r)->cfCopy(n,r)
     15#define n_Delete(n, r)        (r)->cfDelete(n,r)
     16#define n_Mult(n1, n2, r)     (r)->nMult(n1, n2,r)
     17#define n_Add(n1, n2, r)      (r)->nAdd(n1, n2,r)
     18#define n_IsZero(n, r)        (r)->nIsZero(n,r)
     19#define n_Equal(n1, n2, r)    (r)->nEqual(n1, n2,r)
     20#define n_Neg(n, r)           (r)->nNeg(n,r)
     21#define n_Sub(n1, n2, r)      (r)->nSub(n1, n2,r)
    2122#define n_GetChar(r)          ((r)->ch)
    22 #define n_Init(i, r)          (r)->cf->cfInit(i,r)
    23 #define n_IsOne(n, r)         (r)->cf->nIsOne(n)
    24 #define n_IsMOne(n, r)        (r)->cf->nIsMOne(n)
    25 #define n_GreaterZero(n, r)   (r)->cf->nGreaterZero(n)
    26 #define n_Write(n, r)         (r)->cf->cfWrite(n,r)
    27 #define n_Normalize(n, r)     (r)->cf->nNormalize(n)
    28 #define n_Gcd(a, b, r)        (r)->cf->nGcd(a,b,r)
    29 #define n_IntDiv(a, b, r)     (r)->cf->nIntDiv(a,b)
    30 #define n_Div(a, b, r)        (r)->cf->nDiv(a,b)
    31 #define n_Invers(a, r)     (r)->cf->nInvers(a)
    32 #define n_ExactDiv(a, b, r)   (r)->cf->nExactDiv(a,b)
    33 #define n_Test(a,r)           (r)->cf->nDBTest(a,__FILE__,__LINE__)
    34 
    35 #define n_InpMult(a, b, r)    (r)->cf->nInpMult(a,b,r)
    36 #define n_Power(a, b, res, r) (r)->cf->nPower(a,b,res)
    37 #define n_Size(n,r)           (r)->cf->nSize(n)
    38 #define n_GetDenom(N,r)       (r)->cf->cfGetDenom((N),r)
    39 #define n_GetNumerator(N,r)   (r)->cf->cfGetNumerator((N),r)
     23#define n_Init(i, r)          (r)->cfInit(i,r)
     24#define n_IsOne(n, r)         (r)->nIsOne(n,r)
     25#define n_IsMOne(n, r)        (r)->nIsMOne(n,r)
     26#define n_GreaterZero(n, r)   (r)->nGreaterZero(n,r)
     27#define n_Write(n, r)         (r)->cfWrite(n,r)
     28#define n_Normalize(n, r)     (r)->nNormalize(n,r)
     29#define n_Gcd(a, b, r)        (r)->nGcd(a,b,r)
     30#define n_IntDiv(a, b, r)     (r)->nIntDiv(a,b,r)
     31#define n_Div(a, b, r)        (r)->nDiv(a,b,r)
     32#define n_Invers(a, r)        (r)->nInvers(a,r)
     33#define n_ExactDiv(a, b, r)   (r)->nExactDiv(a,b,r)
     34#define n_Test(a,r)           (r)->nDBTest(a,r,__FILE__,__LINE__)
     35
     36#define n_InpMult(a, b, r)    (r)->nInpMult(a,b,r)
     37#define n_Power(a, b, res, r) (r)->nPower(a,b,res,r)
     38#define n_Size(n,r)           (r)->nSize(n,r)
     39#define n_GetDenom(N,r)       (r)->cfGetDenom((N),r)
     40#define n_GetNumerator(N,r)   (r)->cfGetNumerator((N),r)
    4041
    4142#define n_New(n, r)           nNew(n)
     
    4546
    4647/* prototypes */
    47 extern numberfunc nMult, nSub ,nAdd ,nDiv, nIntDiv, nIntMod, nExactDiv;
    4848void           nNew(number * a);
    49 extern number  (*nInit_bigint)(number i);
    5049#define        nInit(i) n_Init(i,currRing)
    51 extern number  (*nPar)(int i);
    52 extern int     (*nParDeg)(number n);
    53 /* size: a measure for the complexity of the represented number n;
    54          zero should have size zero; larger size means more complex */
    55 extern int     (*nSize)(number n);
    56 extern int     (*n_Int)(number &n, const ring r);
    57 #ifdef HAVE_RINGS
    58 extern int     (*nDivComp)(number a,number b);
    59 extern BOOLEAN (*nIsUnit)(number a);
    60 extern number  (*nGetUnit)(number a);
    61 extern number  (*nExtGcd)(number a, number b, number *s, number *t);
    62 #endif
    63 // always use in the form    n=nNeg(n) !
    64 extern number  (*nNeg)(number a);
    65 extern number  (*nInvers)(number a);
    66 extern number  (*nCopy)(number a);
    67 extern number  (*nRePart)(number a);
    68 extern number  (*nImPart)(number a);
    6950#define nWrite(A) n_Write(A,currRing)
    70 extern const char *  (*nRead)(const char * s, number * a);
    71 extern void    (*nNormalize)(number &a);
    72 extern BOOLEAN (*nGreater)(number a,number b),
    73 #ifdef HAVE_RINGS
    74                (*nDivBy)(number a,number b),
    75 #endif
    76                (*nEqual)(number a,number b),
    77                (*nIsZero)(number a),
    78                (*nIsOne)(number a),
    79                (*nIsMOne)(number a),
    80                (*nGreaterZero)(number a);
    81 extern void    (*nPower)(number a, int i, number * result);
    82 extern number (*nGcd)(number a, number b, const ring r);
    83 extern number (*nLcm)(number a, number b, const ring r);
    84 
    85 extern number nNULL; /* the 0 as constant */
    8651
    8752#define nTest(a) (1)
     
    9156
    9257#define nSetMap(R) (currRing->cf->cfSetMap(R,currRing))
    93 extern char *  (*nName)(number n);
    9458
    9559void nDummy1(number* d);
    96 void ndDelete(number* d, const ring r);
     60void ndDelete(number* d, const coeffs r);
    9761void nDummy2(number &d);
    98 number ndGcd(number a, number b, const ring);
    99 number ndCopy(number a);
    100 void   ndInpMult(number &a, number b, const ring r);
    101 number ndInpAdd(number &a, number b, const ring r);
     62number ndGcd(number a, number b, const coeffs);
     63number ndCopy(number a, const coeffs r);
     64void   ndInpMult(number &a, number b, const coeffs r);
     65number ndInpAdd(number &a, number b, const coeffs r);
    10266
    10367#ifdef LDEBUG
     
    10670#define nGetChar() n_GetChar(currRing)
    10771
    108 void nInitChar(ring r);
    109 void nKillChar(ring r);
    110 void nSetChar(ring r);
     72void nInitChar(coeffs r);
     73void nKillChar(coeffs r);
     74void nSetChar(coeffs r);
    11175
    11276#define nDivBy0 "div by 0"
     
    11478// dummy routines
    11579void   nDummy2(number& d); // nNormalize...
    116 #endif
     80
     81// Tests:
     82#ifdef HAVE_RINGS
     83static inline BOOLEAN nField_is_Ring_2toM(const coeffs r)
     84{ return (r->ringtype == 1); }
     85
     86static inline BOOLEAN nField_is_Ring_ModN(const coeffs r)
     87{ return (r->ringtype == 2); }
     88
     89static inline BOOLEAN nField_is_Ring_PtoM(const coeffs r)
     90{ return (r->ringtype == 3); }
     91
     92static inline BOOLEAN nField_is_Ring_Z(const coeffs r)
     93{ return (r->ringtype == 4); }
     94
     95static inline BOOLEAN nField_is_Ring(const coeffs r)
     96{ return (r->ringtype != 0); }
     97
     98static inline BOOLEAN nField_is_Domain(const coeffs r)
     99{ return (r->ringtype == 4 || r->ringtype == 0); }
     100
     101static inline BOOLEAN nField_has_Units(const coeffs r)
     102{ return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); }
     103#else
     104#define nField_is_Ring(A) (0)
     105#endif
     106
     107#ifdef HAVE_RINGS
     108static inline BOOLEAN nField_is_Zp(const coeffs r)
     109{ return (r->ringtype == 0) && (r->ch > 1) && (r->parameter==NULL); }
     110
     111static inline BOOLEAN nField_is_Zp(const coeffs r, int p)
     112{ return (r->ringtype == 0) && (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); }
     113
     114static inline BOOLEAN nField_is_Q(const coeffs r)
     115{ return (r->ringtype == 0) && (r->ch == 0) && (r->parameter==NULL); }
     116
     117static inline BOOLEAN nField_is_numeric(const coeffs r) /* R, long R, long C */
     118{ return (r->ringtype == 0) && (r->ch ==  -1); }
     119
     120static inline BOOLEAN nField_is_R(const coeffs r)
     121{
     122  if (nField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH))
     123      return (r->ringtype == 0) && (r->parameter==NULL);
     124  return FALSE;
     125}
     126
     127static inline BOOLEAN nField_is_GF(const coeffs r)
     128{ return (r->ringtype == 0) && (r->ch > 1) && (r->parameter!=NULL); }
     129
     130static inline BOOLEAN nField_is_GF(const coeffs r, int q)
     131{ return (r->ringtype == 0) && (r->ch == q); }
     132
     133static inline BOOLEAN nField_is_Zp_a(const coeffs r)
     134{ return (r->ringtype == 0) && (r->ch < -1); }
     135
     136static inline BOOLEAN nField_is_Zp_a(const coeffs r, int p)
     137{ return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
     138
     139static inline BOOLEAN nField_is_Q_a(const coeffs r)
     140{ return (r->ringtype == 0) && (r->ch == 1); }
     141
     142static inline BOOLEAN nField_is_long_R(const coeffs r)
     143{
     144  if (nField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH))
     145    return (r->ringtype == 0) && (r->parameter==NULL);
     146  return FALSE;
     147}
     148
     149static inline BOOLEAN nField_is_long_C(const coeffs r)
     150{
     151  if (nField_is_numeric(r))
     152    return (r->ringtype == 0) && (r->parameter!=NULL);
     153  return FALSE;
     154}
     155#else
     156static inline BOOLEAN nField_is_Zp(const coeffs r)
     157{ return (r->ch > 1) && (r->parameter==NULL); }
     158
     159static inline BOOLEAN nField_is_Zp(const coeffs r, int p)
     160{ return (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); }
     161
     162static inline BOOLEAN nField_is_Q(const coeffs r)
     163{ return (r->ch == 0) && (r->parameter==NULL); }
     164
     165static inline BOOLEAN nField_is_numeric(const coeffs r) /* R, long R, long C */
     166{ return (r->ch ==  -1); }
     167
     168static inline BOOLEAN nField_is_R(const coeffs r)
     169{
     170  if (nField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH))
     171    return (r->parameter==NULL);
     172  return FALSE;
     173}
     174
     175static inline BOOLEAN nField_is_GF(const coeffs r)
     176{ return (r->ch > 1) && (r->parameter!=NULL); }
     177
     178static inline BOOLEAN nField_is_GF(const coeffs r, int q)
     179{ return (r->ch == q); }
     180
     181static inline BOOLEAN nField_is_Zp_a(const coeffs r)
     182{ return (r->ch < -1); }
     183
     184static inline BOOLEAN nField_is_Zp_a(const coeffs r, int p)
     185{ return (r->ch < -1 ) && (-(r->ch) == ABS(p)); }
     186
     187static inline BOOLEAN nField_is_Q_a(const coeffs r)
     188{ return (r->ch == 1); }
     189
     190static inline BOOLEAN nField_is_long_R(const coeffs r)
     191{
     192  if (nField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH))
     193    return (r->parameter==NULL);
     194  return FALSE;
     195}
     196
     197static inline BOOLEAN nField_is_long_C(const coeffs r)
     198{
     199  if (nField_is_numeric(r))
     200    return (r->parameter!=NULL);
     201  return FALSE;
     202}
     203#endif
     204
     205static inline BOOLEAN nField_has_simple_inverse(const coeffs r)
     206/* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/
     207#ifdef HAVE_RINGS
     208{ 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*/
     209#else
     210{ return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/
     211#endif
     212
     213static inline BOOLEAN nField_has_simple_Alloc(const coeffs r)
     214{ return (nField_is_Zp(r)
     215       || nField_is_GF(r)
     216#ifdef HAVE_RINGS
     217       || nField_is_Ring_2toM(r)
     218#endif
     219       || nField_is_R(r));
     220}
     221/* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/
     222
     223static inline BOOLEAN nField_is_Extension(const coeffs r)
     224{ return (nField_is_Q_a(r)) || (nField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/
     225
     226#endif
  • coeffs/rmodulo2m.cc

    r634d93b r7d90aa  
    556556    {
    557557      mpz_clear(modul);
    558       omFree((ADDRESS) modul);
     558      omFree((void *) modul);
    559559      return nr2mMapGMP;
    560560    }
    561561    mpz_clear(modul);
    562     omFree((ADDRESS) modul);
     562    omFree((void *) modul);
    563563  }
    564564  return NULL;      // default
  • coeffs/rmodulo2m.h

    r634d93b r7d90aa  
    99*/
    1010#ifdef HAVE_RINGS
    11 #include <kernel/structs.h>
     11#include "coeffs.h"
    1212
    1313extern int nr2mExp;
  • coeffs/rmodulon.cc

    r634d93b r7d90aa  
    4141  if (*a == NULL) return;
    4242  mpz_clear((int_number) *a);
    43   omFreeBin((ADDRESS) *a, gmp_nrz_bin);
     43  omFreeBin((void *) *a, gmp_nrz_bin);
    4444  *a = NULL;
    4545}
  • coeffs/rmodulon.h

    r634d93b r7d90aa  
    99*/
    1010#ifdef HAVE_RINGS
    11 #include <kernel/structs.h>
     11#include "coeffs.h"
    1212
    1313#ifndef NATNUMBER
  • coeffs/shortfl.cc

    r634d93b r7d90aa  
    99
    1010#include <string.h>
    11 #include <kernel/mod2.h>
    12 #include <omalloc/mylimits.h>
    13 #include <kernel/structs.h>
    14 #include <kernel/febase.h>
    15 #include <kernel/numbers.h>
    16 #include <kernel/longrat.h>
    17 #include <kernel/mpr_complex.h>
    18 #include <kernel/ring.h>
    19 #include <kernel/shortfl.h>
     11#include "coeffs.h"
     12#include <mylimits.h>
     13#include "febase.h"
     14#include "numbers.h"
     15#include "longrat.h"
     16#include "mpr_complex.h"
     17#include "shortfl.h"
    2018
    2119static float nrEps = 1.0e-3;
     
    3533}
    3634
    37 BOOLEAN nrGreaterZero (number k)
     35BOOLEAN nrGreaterZero (number k, const coeffs r)
    3836{
    3937  return nf(k).F() >= 0.0;
    4038}
    4139
    42 number nrMult (number a,number b)
     40number nrMult (number a,number b, const coeffs r)
    4341{
    4442  return nf(nf(a).F() * nf(b).F()).N();
     
    4846* create a number from int
    4947*/
    50 number nrInit (int i, const ring R)
     48number nrInit (int i, const coeffs R)
    5149{
    5250  float r = (float)i;
     
    5755* convert a number to int
    5856*/
    59 int nrInt(number &n, const ring R)
     57int nrInt(number &n, const coeffs R)
    6058{
    6159  int i;
     
    6866}
    6967
    70 int nrSize(number n)
     68int nrSize(number n, const coeffs R)
    7169{
    7270  float f = nf(n).F();
     
    8078}
    8179
    82 number nrAdd (number a, number b)
     80number nrAdd (number a, number b, const coeffs R)
    8381{
    8482  float x = nf(a).F();
     
    110108}
    111109
    112 number nrSub (number a, number b)
     110number nrSub (number a, number b, const coeffs R)
    113111{
    114112  float x = nf(a).F();
     
    140138}
    141139
    142 BOOLEAN nrIsZero (number  a)
     140BOOLEAN nrIsZero (number  a, const coeffs r)
    143141{
    144142  return (0.0 == nf(a).F());
    145143}
    146144
    147 BOOLEAN nrIsOne (number a)
     145BOOLEAN nrIsOne (number a, const coeffs r)
    148146{
    149147  float aa=nf(a).F()-1.0;
     
    152150}
    153151
    154 BOOLEAN nrIsMOne (number a)
     152BOOLEAN nrIsMOne (number a, const coeffs r)
    155153{
    156154  float aa=nf(a).F()+1.0;
     
    159157}
    160158
    161 number nrDiv (number a,number b)
     159number nrDiv (number a,number b, const coeffs r)
    162160{
    163161  float n = nf(b).F();
     
    171169}
    172170
    173 number  nrInvers (number c)
     171number  nrInvers (number c, const coeffs r)
    174172{
    175173  float n = nf(c).F();
     
    182180}
    183181
    184 number nrNeg (number c)
     182number nrNeg (number c, const coeffs r)
    185183{
    186184  return nf(-nf(c).F()).N();
    187185}
    188186
    189 BOOLEAN nrGreater (number a,number b)
     187BOOLEAN nrGreater (number a,number b, const coeffs r)
    190188{
    191189  return nf(a).F() > nf(b).F();
    192190}
    193191
    194 BOOLEAN nrEqual (number a,number b)
    195 {
    196   number x = nrSub(a,b);
     192BOOLEAN nrEqual (number a,number b, const coeffs r)
     193{
     194  number x = nrSub(a,b,r);
    197195  return nf(x).F() == nf((float)0.0).F();
    198196}
    199197
    200 void nrWrite (number &a, const ring r)
     198void nrWrite (number &a, const coeffs r)
    201199{
    202200  StringAppend("%9.3e", nf(a).F());
    203201}
    204202
    205 void nrPower (number a, int i, number * result)
     203void nrPower (number a, int i, number * result, const coeffs r)
    206204{
    207205  if (i==0)
     
    215213    return;
    216214  }
    217   nrPower(a,i-1,result);
     215  nrPower(a,i-1,result,r);
    218216  *result = nf(nf(a).F() * nf(*result).F()).N();
    219217}
     
    240238const char *nIllegalChar="illegal character in number";
    241239
    242 const char * nrRead (const char *s, number *a)
     240const char * nrRead (const char *s, number *a, const coeffs r)
    243241{
    244242  const char *t;
     
    425423}
    426424
    427 static number nrMapP(number from)
     425static number nrMapP(number from, const coeffs R)
    428426{
    429427  int i = (int)((long)from);
     
    432430}
    433431
    434 static number nrMapLongR(number from)
     432static number nrMapLongR(number from, const coeffs R)
    435433{
    436434  float t =(float)mpf_get_d((mpf_srcptr)from);
    437435  return nf(t).N();
    438436}
    439 static number nrMapC(number from)
     437static number nrMapC(number from, const coeffs r)
    440438{
    441439  gmp_float h = ((gmp_complex*)from)->real();
     
    444442}
    445443
    446 nMapFunc nrSetMap(const ring src, const ring dst)
    447 {
    448   if (rField_is_Q(src))
     444nMapFunc nrSetMap(const coeffs src, const coeffs dst)
     445{
     446  if (nField_is_Q(src))
    449447  {
    450448    return nrMapQ;
    451449  }
    452   if (rField_is_long_R(src))
     450  if (nField_is_long_R(src))
    453451  {
    454452    return nrMapLongR;
    455453  }
    456   if (rField_is_R(src))
     454  if (nField_is_R(src))
    457455  {
    458456    return ndCopy;
    459457  }
    460   if(rField_is_Zp(src))
     458  if(nField_is_Zp(src))
    461459  {
    462460    return nrMapP;
    463461  }
    464   if (rField_is_long_C(src))
     462  if (nField_is_long_C(src))
    465463  {
    466464    return nrMapC;
  • coeffs/shortfl.h

    r634d93b r7d90aa  
    88*/
    99/* $Id$ */
    10 #include <kernel/structs.h>
     10#include "coeffs.h"
    1111
    12 BOOLEAN nrGreaterZero (number k);
    13 number  nrMult        (number a, number b);
    14 number  nrInit        (int i, const ring r);
    15 int     nrInt         (number &n, const ring r);
    16 number  nrAdd         (number a, number b);
    17 number  nrSub         (number a, number b);
    18 void    nrPower       (number a, int i, number * result);
    19 BOOLEAN nrIsZero      (number a);
    20 BOOLEAN nrIsOne       (number a);
    21 BOOLEAN nrIsMOne      (number a);
    22 number  nrDiv         (number a, number b);
    23 number  nrNeg         (number c);
    24 number  nrInvers      (number c);
    25 int     nrSize        (number n);
    26 BOOLEAN nrGreater     (number a, number b);
    27 BOOLEAN nrEqual       (number a, number b);
    28 void    nrWrite       (number &a, const ring r);
    29 const char *  nrRead  (const char *s, number *a);
     12BOOLEAN nrGreaterZero (number k, const coeffs r);
     13number  nrMult        (number a, number b, const coeffs r);
     14number  nrInit        (int i, const coeffs r);
     15int     nrInt         (number &n, const coeffs r);
     16number  nrAdd         (number a, number b, const coeffs r);
     17number  nrSub         (number a, number b, const coeffs r);
     18void    nrPower       (number a, int i, number * result, const coeffs r);
     19BOOLEAN nrIsZero      (number a, const coeffs r);
     20BOOLEAN nrIsOne       (number a, const coeffs r);
     21BOOLEAN nrIsMOne      (number a, const coeffs r);
     22number  nrDiv         (number a, number b, const coeffs r);
     23number  nrNeg         (number c, const coeffs r);
     24number  nrInvers      (number c, const coeffs r);
     25BOOLEAN nrGreater     (number a, number b, const coeffs r);
     26BOOLEAN nrEqual       (number a, number b, const coeffs r);
     27void    nrWrite       (number &a, const coeffs r);
     28const char *  nrRead  (const char *s, number *a, const coeffs r);
    3029int     nrGetChar();
    3130#ifdef LDEBUG
    32 BOOLEAN nrDBTest(number a, const char *f, const int l);
     31BOOLEAN nrDBTest(number a, const coeffs, rconst char *f, const int l);
    3332#endif
    3433
    35 nMapFunc nrSetMap(const ring src, const ring dst);
     34nMapFunc nrSetMap(const coeffs src, const coeffs dst);
    3635
    3736float   nrFloat(number n);
    38 number nrMapQ(number from);
     37number nrMapQ(number from, const coeffs r);
    3938#endif
    4039
Note: See TracChangeset for help on using the changeset viewer.