Changeset 94b759 in git


Ignore:
Timestamp:
Apr 30, 2010, 7:26:10 PM (14 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '648d28f488f6ff08f5607ff229b9ad9e4a5b93c2')
Children:
6ce7579378e276236fc3dfffd7b704449b1e306a
Parents:
97d8a41a15dadbaebb9ddaa1705f32a135ccb013
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2010-04-30 19:26:10+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 11:50:24+01:00
Message:
Finished long_C: gnumpc.*.
Note: that MapFunctions should look as follows:
number nMapFunc(number a, const coeffs r, const coeffs aRing);
and map "a" from aRing into r!!!!!!
Location:
coeffs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • coeffs/coeffs.h

    r97d8a4 r94b759  
    1515#define NULL        (0)
    1616#endif
     17
     18// #ifdef _TRY
     19#ifndef ABS
     20#define ABS(x) ((x)<0?(-(x)):(x))
     21#endif
     22// #endif
     23
     24
    1725
    1826#if (SIZEOF_LONG == 8)
     
    8391struct snumber;
    8492typedef struct snumber *   number;
    85 typedef number (*numberfunc)(number a,number b, const coeffs r);
    86 typedef number (*nMapFunc)(number a, const coeffs r);
    87 
    88 #define _TRY
     93typedef number (*numberfunc)(number a, number b, const coeffs r);
     94
     95/// maps "a" from aRing into r
     96typedef number (*nMapFunc)(number a, const coeffs r, const coeffs aRing);
     97
     98// #define _TRY
    8999
    90100#ifdef _TRY
     
    114124   #endif
    115125   // Zp_a, Q_a
     126   // ?
    116127
    117128   // general stuff
     
    192203  short      float_len; /* additional char-flags, rInit */
    193204  short      float_len2; /* additional char-flags, rInit */
    194 
    195205};
    196206
     207/// Returns the type of coeffs domain
     208static inline n_coeffType getCoeffType(const coeffs r)
     209{
     210  return r->type;
     211}
     212
    197213#define  nInternalChar(r) ((r)->ch)
    198214
  • coeffs/gnumpc.cc

    r97d8a4 r94b759  
    1919#include "omalloc.h"
    2020
    21 extern size_t gmp_output_digits;
    22 
    23 
    24 number ngcMapQ(number from, const coeffs)
    25 {
     21
     22#ifdef LDEBUG
     23// not yet implemented
     24BOOLEAN ngcDBTest(number a, const char *f, const int l, const coeffs r)
     25{
     26  assume( getCoeffType(r) == ID );
     27
     28  return TRUE;
     29}
     30#endif
     31
     32#ifndef assume
     33#  define assume(a) if(!(a)){ Werror( "Assumption: is wrong: %s\n", #a ); };
     34#endif
     35
     36const n_coeffType ID = n_long_C;
     37
     38number ngcMapQ(number from, const coeffs r, const coeffs aRing)
     39{
     40  assume( getCoeffType(r) == ID );
     41  assume( getCoeffType(aRing) == n_Q );
     42
    2643  if ( from != NULL )
    2744  {
     
    3249    return NULL;
    3350}
    34 union nf
    35 {
    36   float _f;
    37   number _n;
    38   nf(float f) {_f = f;}
    39   nf(number n) {_n = n;}
    40   float F() const {return _f;}
    41   number N() const {return _n;}
    42 };
    43 static number ngcMapLongR(number from, const coeffs)
    44 {
     51
     52static number ngcMapLongR(number from, const coeffs r, const coeffs aRing)
     53{
     54  assume( getCoeffType(r) == ID );
     55  assume( getCoeffType(aRing) == n_long_R );
     56 
    4557  if ( from != NULL )
    4658  {
     
    5163    return NULL;
    5264}
    53 static number ngcMapR(number from, const coeffs)
    54 {
     65
     66static number ngcMapR(number from, const coeffs r, const coeffs aRing)
     67{
     68  assume( getCoeffType(r) == ID );
     69  assume( getCoeffType(aRing) == n_R );
     70
     71  union nf
     72  {
     73    float _f;
     74    number _n;
     75    nf(float f) {_f = f;}
     76    nf(number n) {_n = n;}
     77    float F() const {return _f;}
     78    number N() const {return _n;}
     79  };
     80
    5581  if ( from != NULL )
    5682  {
     
    6187    return NULL;
    6288}
    63 extern ring ngfMapRing;
    64 static number ngcMapP(number from, const coeffs)
    65 {
     89
     90static number ngcMapP(number from, const coeffs r, const coeffs aRing)
     91{
     92  assume( getCoeffType(r) == ID );
     93  assume( getCoeffType(aRing) ==  n_Zp );
     94 
    6695  if ( from != NULL)
    67     return ngcInit(npInt(from,ngfMapRing), currRing);
     96    return ngcInit(npInt(from, aRing), r);
    6897  else
    6998    return NULL;
    7099}
    71100
    72 nMapFunc ngcSetMap(const coeffs src,const coeffs dst)
    73 {
    74   if(rField_is_Q(src))
     101
     102
     103static number ngcCopyMap(number from, const coeffs r, const coeffs aRing)
     104{
     105  assume( getCoeffType(r) == ID );
     106  assume( getCoeffType(aRing) ==  ID );
     107
     108  gmp_complex* b = NULL;
     109 
     110  if ( from !=  NULL )
     111  {
     112    b = new gmp_complex( *(gmp_complex*)from );
     113  }
     114  return (number)b; 
     115}
     116
     117nMapFunc ngcSetMap(const coeffs src/*, const coeffs dst */)
     118{
     119//  assume( getCoeffType(dst) == ID );
     120 
     121  if(nField_is_Q(src))
    75122  {
    76123    return ngcMapQ;
    77124  }
    78   if (rField_is_long_R(src))
     125  if (nField_is_long_R(src))
    79126  {
    80127    return ngcMapLongR;
    81128  }
    82   if (rField_is_long_C(src))
    83   {
    84     return ngcCopy;
    85   }
    86   if(rField_is_R(src))
     129  if (nField_is_long_C(src))
     130  {
     131    return ngcCopyMap;
     132  }
     133  if(nField_is_R(src))
    87134  {
    88135    return ngcMapR;
    89136  }
    90   if (rField_is_Zp(src))
    91   {
    92     ngfMapRing=src;
     137  if (nField_is_Zp(src))
     138  {
    93139    return ngcMapP;
    94140  }
     
    96142}
    97143
    98 number   ngcPar(int i)
    99 {
     144
     145
     146number   ngcPar(int i, const coeffs r)
     147{
     148  assume( getCoeffType(r) == ID );
     149
    100150  gmp_complex* n= new gmp_complex( (long)0, (long)1 );
    101151  return (number)n;
     
    107157number ngcInit (int i, const coeffs r)
    108158{
     159  assume( getCoeffType(r) == ID );
     160 
    109161  gmp_complex* n= new gmp_complex( (long)i, (long)0 );
     162 
    110163  return (number)n;
    111164}
     
    116169int ngcInt(number &i, const coeffs r)
    117170{
     171  assume( getCoeffType(r) == ID );
     172 
    118173  return (int)((gmp_complex*)i)->real();
    119174}
     
    139194void ngcDelete (number * a, const coeffs r)
    140195{
     196  assume( getCoeffType(r) == ID );
     197
    141198  if ( *a != NULL )
    142199  {
     
    149206 * copy a to b
    150207*/
    151 number ngcCopy(number a, const coeffs)
    152 {
     208number ngcCopy(number a, const coeffs r)
     209{
     210  assume( getCoeffType(r) == ID );
     211 
    153212  gmp_complex* b= new gmp_complex( *(gmp_complex*)a );
    154213  return (number)b;
    155214}
    156 number ngc_Copy(number a, const coeffs r)
    157 {
    158   gmp_complex* b=new gmp_complex( *(gmp_complex*)a );
    159   return (number)b;
    160 }
     215
    161216
    162217/*2
    163218* za:= - za
    164219*/
    165 gmp_complex ngc_m1(-1);
    166 
    167 number ngcNeg (number a, const coeffs)
    168 {
     220number ngcNeg (number a, const coeffs R)
     221{
     222  assume( getCoeffType(R) == ID );
     223
    169224  gmp_complex* r=(gmp_complex*)a;
    170225  (*r) *= ngc_m1;
     
    175230* 1/a
    176231*/
    177 number ngcInvers(number a, const coeffs)
    178 {
     232number ngcInvers(number a, const coeffs R)
     233{
     234  assume( getCoeffType(R) == ID );
     235
    179236  gmp_complex* r = NULL;
    180237  if (((gmp_complex*)a)->isZero())
     
    184241  else
    185242  {
    186     r= new gmp_complex( (gmp_complex)1 / (*(gmp_complex*)a) );
    187   }
    188   return (number)r;
     243    b = new gmp_complex( (gmp_complex)1 / (*(gmp_complex*)a) );
     244  }
     245  return (number)b;
    189246}
    190247
     
    192249* u:= a + b
    193250*/
    194 number ngcAdd (number a, number b, const coeffs)
    195 {
     251number ngcAdd (number a, number b, const coeffs R)
     252{
     253  assume( getCoeffType(R) == ID );
     254
    196255  gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) + (*(gmp_complex*)b) );
    197256  return (number)r;
     
    203262number ngcSub (number a, number b, const coeffs R)
    204263{
     264  assume( getCoeffType(R) == ID );
     265
    205266  gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) - (*(gmp_complex*)b) );
    206267  return (number)r;
     
    210271* u := a * b
    211272*/
    212 number ngcMult (number a, number b)
    213 {
     273number ngcMult (number a, number b, const coeffs R)
     274{
     275  assume( getCoeffType(R) == ID );
     276 
    214277  gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) * (*(gmp_complex*)b) );
    215278  return (number)r;
     
    219282* u := a / b
    220283*/
    221 number ngcDiv (number a, number b, const coeffs)
    222 {
     284number ngcDiv (number a, number b, const coeffs r)
     285{
     286  assume( getCoeffType(r) == ID );
     287
    223288  if (((gmp_complex*)b)->isZero())
    224289  {
     
    227292    return NULL;
    228293  }
    229   gmp_complex* r= new gmp_complex( (*(gmp_complex*)a) / (*(gmp_complex*)b) );
    230   return (number)r;
     294  gmp_complex* res = new gmp_complex( (*(gmp_complex*)a) / (*(gmp_complex*)b) );
     295  return (number)res;
    231296}
    232297
     
    234299* u:= x ^ exp
    235300*/
    236 void ngcPower ( number x, int exp, number * u, const coeffs R)
    237 {
     301void ngcPower ( number x, int exp, number * u, const coeffs r)
     302{
     303  assume( getCoeffType(r) == ID );
     304
    238305  if ( exp == 0 )
    239306  {
     
    244311  else if ( exp == 1 )
    245312  {
    246     nNew(u);
     313    n_New(u, r);
    247314    gmp_complex* n = new gmp_complex();
    248315    *n= *(gmp_complex*)x;
     
    252319  else if (exp == 2)
    253320  {
    254     nNew(u);
     321    n_New(u, r);
    255322    gmp_complex* n = new gmp_complex();
    256323    *n= *(gmp_complex*)x;
     
    261328  if (exp&1==1)
    262329  {
    263     ngcPower(x,exp-1,u, R);
    264     gmp_complex *n=new gmp_complex();
     330    ngcPower(x,exp-1,u, r);
     331    gmp_complex *n = new gmp_complex();
    265332    *n=*(gmp_complex*)x;
    266333    *(gmp_complex*)(*u) *= *(gmp_complex*)n;
     
    270337  {
    271338    number w;
    272     nNew(&w);
    273     ngcPower(x,exp/2,&w, R);
    274     ngcPower(w,2,u, R);
    275     nDelete(&w);
    276   }
    277 }
    278 
    279 BOOLEAN ngcIsZero (number a, const coeffs)
    280 {
     339    n_New(&w, r);
     340    ngcPower(x,exp/2,&w, r);
     341    ngcPower(w,2,u, r);
     342    n_Delete(&w, r);
     343  }
     344}
     345
     346BOOLEAN ngcIsZero (number a, const coeffs r)
     347{
     348  assume( getCoeffType(r) == ID );
     349
    281350  return ( ((gmp_complex*)a)->real().isZero() && ((gmp_complex*)a)->imag().isZero());
    282351}
    283352
    284 number ngcRePart(number a, const coeffs)
    285 {
     353number ngcRePart(number a, const coeffs r)
     354{
     355  assume( getCoeffType(r) == ID );
     356
    286357  gmp_complex* n = new gmp_complex(((gmp_complex*)a)->real());
    287358  return (number)n;
    288359}
    289360
    290 number ngcImPart(number a, const coeffs)
    291 {
     361number ngcImPart(number a, const coeffs r)
     362{
     363  assume( getCoeffType(r) == ID );
     364
    292365  gmp_complex* n = new gmp_complex(((gmp_complex*)a)->imag());
    293366  return (number)n;
     
    297370* za >= 0 ?
    298371*/
    299 BOOLEAN ngcGreaterZero (number a, const coeffs)
    300 {
     372BOOLEAN ngcGreaterZero (number a, const coeffs r)
     373{
     374  assume( getCoeffType(r) == ID );
     375
    301376  if ( ! ((gmp_complex*)a)->imag().isZero() )
    302377    return ( abs( *(gmp_complex*)a).sign() >= 0 );
     
    308383* a > b ?
    309384*/
    310 BOOLEAN ngcGreater (number a, number b, const coeffs)
    311 {
     385BOOLEAN ngcGreater (number a, number b, const coeffs r)
     386{
     387  assume( getCoeffType(r) == ID );
     388
    312389  gmp_complex *aa=(gmp_complex*)a;
    313390  gmp_complex *bb=(gmp_complex*)b;
     
    318395* a = b ?
    319396*/
    320 BOOLEAN ngcEqual (number a, number b, const coeffs)
    321 {
     397BOOLEAN ngcEqual (number a, number b, const coeffs r)
     398{
     399  assume( getCoeffType(r) == ID );
     400
    322401  gmp_complex *aa=(gmp_complex*)a;
    323402  gmp_complex *bb=(gmp_complex*)b;
     
    328407* a == 1 ?
    329408*/
    330 BOOLEAN ngcIsOne (number a, const coeffs)
    331 {
     409BOOLEAN ngcIsOne (number a, const coeffs r)
     410{
     411  assume( getCoeffType(r) == ID );
     412
    332413  return (((gmp_complex*)a)->real().isOne() && ((gmp_complex*)a)->imag().isZero());
    333414  //return (((gmp_complex*)a)->real().isOne());
     
    337418* a == -1 ?
    338419*/
    339 BOOLEAN ngcIsMOne (number a, const coeffs)
    340 {
     420BOOLEAN ngcIsMOne (number a, const coeffs r)
     421{
     422  assume( getCoeffType(r) == ID );
     423
    341424  return (((gmp_complex*)a)->real().isMOne() && ((gmp_complex*)a)->imag().isZero());
    342425  //return (((gmp_complex*)a)->real().isMOne());
     
    346429* extracts the number a from s, returns the rest
    347430*/
    348 const char * ngcRead (const char * s, number * a, const coeffs R)
    349 {
     431const char * ngcRead (const char * s, number * a, const coeffs r)
     432{
     433  assume( getCoeffType(r) == ID );
     434 
    350435  if ((*s >= '0') && (*s <= '9'))
    351436  {
    352437    gmp_float *re=NULL;
    353     s=ngfRead(s,(number *)&re, R);
     438    s=ngfRead(s,(number *)&re, r);
    354439    gmp_complex *aa=new gmp_complex(*re);
    355440    *a=(number)aa;
    356441    delete re;
    357442  }
    358   else if (strncmp(s,currRing->parameter[0],strlen(currRing->parameter[0]))==0)
    359   {
    360     s+=strlen(currRing->parameter[0]);
     443  else if (strncmp(s, r->parameter[0],strlen(r->parameter[0]))==0)
     444  {
     445    s+=strlen(r->parameter[0]);
    361446    gmp_complex *aa=new gmp_complex((long)0,(long)1);
    362447    *a=(number)aa;
     
    369454}
    370455
     456
     457
    371458/*2
    372459* write a floating point number
     
    374461void ngcWrite (number &a, const coeffs r)
    375462{
     463  assume( getCoeffType(r) == ID );
     464
     465  extern size_t gmp_output_digits; /// comes from mpr_complex.cc
     466
    376467  if (a==NULL)
    377468    StringAppendS("0");
     
    379470  {
    380471    char *out;
    381     out= complexToStr(*(gmp_complex*)a,gmp_output_digits);
     472    out= complexToStr(*(gmp_complex*)a, gmp_output_digits);
    382473    StringAppendS(out);
    383474    //    omFreeSize((void *)out, (strlen(out)+1)* sizeof(char) );
     
    385476  }
    386477}
    387 
    388 #ifdef LDEBUG
    389 // not yet implemented
    390 //BOOLEAN ngcDBTest(number a, const char *f, const int l)
    391 //{
    392 //  return TRUE;
    393 //}
    394 #endif
    395478
    396479// local Variables: ***
  • coeffs/gnumpc.h

    r97d8a4 r94b759  
    2626number   ngcDiv(number a, number b, const coeffs r);
    2727void     ngcPower(number x, int exp, number *lu, const coeffs r);
    28 number   ngcCopy(number a, const coeffs);
     28number   ngcCopy(number a, const coeffs r);
    2929number   ngc_Copy(number a, coeffs r);
    3030const char * ngcRead (const char *s, number *a, const coeffs r);
     
    3333number   ngcImPart(number a, const coeffs r);
    3434
     35void     ngcDelete(number *a, const coeffs r);
    3536
    3637#ifdef LDEBUG
    37 BOOLEAN  ngcDBTest(number a, const char *f, const int l, const coeffs);
     38BOOLEAN  ngcDBTest(number a, const char *f, const int l, const coeffs r);
    3839#endif
    39 void     ngcDelete(number *a, const coeffs r);
    4040
    41 nMapFunc  ngcSetMap(const coeffs src, const coeffs dst);
     41/// Get a mapping function from src into this domain: long_C
     42/// no need in dst!?
     43nMapFunc  ngcSetMap(const coeffs src/*, const coeffs dst*/);
    4244
    43 number ngcMapQ(number from, const coeffs r);
     45// Why is this here? who needs it?
     46// number ngcMapQ(number from, const coeffs r, const coeffs aRing);
    4447#endif
    4548
  • coeffs/numbers.h

    r97d8a4 r94b759  
    5151
    5252#define nTest(a) (1)
    53 #define nDelete(A) (currRing)->cf->cfDelete(A,currRing)
    54 #define nGetDenom(N) (currRing->cf->cfGetDenom((N),currRing))
    55 #define nGetNumerator(N) (currRing->cf->cfGetNumerator((N),currRing))
     53
     54// please use n_* counterparts instead!!!
     55// #define nDelete(A) (currRing)->cf->cfDelete(A,currRing)
     56// #define nGetDenom(N) (currRing->cf->cfGetDenom((N),currRing))
     57// #define nGetNumerator(N) (currRing->cf->cfGetNumerator((N),currRing))
     58
    5659
    5760#define nSetMap(R) (currRing->cf->cfSetMap(R,currRing))
     
    107110
    108111#ifdef _TRY
    109 #ifndef ABS
    110 #define ABS(x) ((x)<0?(-(x)):(x))
    111 #endif
    112 #endif
    113 
    114 
    115 
    116 #ifdef _TRY
    117112#define rField_is_Q(r) nField_is_Q(r)
    118113#define rField_is_long_R(r) nField_is_long_R(r)
Note: See TracChangeset for help on using the changeset viewer.