Changeset 661c214 in git for kernel


Ignore:
Timestamp:
Feb 28, 2011, 5:36:07 PM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'c5facdfddea2addfd91babd8b9019161dea4b695')
Children:
0d6970109b48f04bc456f5aee530b7c06be12c64
Parents:
a33266f6b0236cbf3b512cbd4edad959fd94d6c3
Message:
further separation of alg/transc ext code

git-svn-id: file:///usr/local/Singular/svn/trunk@13903 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
kernel
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • kernel/clapconv.cc

    ra33266 r661c214  
    1818#include <kernel/modulop.h>
    1919#include <kernel/longalg.h>
     20#include <kernel/longtrans.h>
    2021#include <kernel/polys.h>
    2122#include <kernel/febase.h>
     
    398399      lnumber l=(lnumber)r->minpoly;
    399400      if (p_GetExp(a,1,r->algring) >= p_GetExp(l->z,1,r->algring))
    400         a = napRemainder( a, l->z);
     401        a = naRemainder( a, l->z);
    401402    }
    402403  }
  • kernel/clapconv.h

    ra33266 r661c214  
    1313
    1414#include <kernel/structs.h>
    15 #include <kernel/longalg.h>
     15#include <kernel/longtrans.h>
    1616#include <kernel/ring.h>
    1717#ifdef HAVE_FACTORY
  • kernel/clapsing.cc

    ra33266 r661c214  
    602602      {
    603603        lnumber c=(lnumber)pGetCoeff(p);
    604         p_Delete(&c->z,nacRing);
     604        p_Delete(&c->z,currRing->algring); // 2nd arg used to be nacRing
    605605        c->z=convFactoryPSingP( i.getItem() / g, currRing->algring );
    606606        //nTest((number)c);
  • kernel/clapsing.h

    ra33266 r661c214  
    1717#include <kernel/intvec.h>
    1818#include <kernel/matpol.h>
    19 #include <kernel/longalg.h>
     19#include <kernel/longtrans.h>
    2020
    2121poly singclap_gcd ( poly f, poly g );
  • kernel/longalg.cc

    ra33266 r661c214  
    2626#endif
    2727#include <kernel/longalg.h>
    28 
    29 struct snaIdeal
    30 {
    31   int anz;
    32   napoly *liste;
    33 };
    34 typedef struct snaIdeal * naIdeal;
    35 
    36 naIdeal naI=NULL;
    37 
    38 omBin snaIdeal_bin = omGetSpecBin(sizeof(snaIdeal));
    39 
    40 int naNumbOfPar;
    41 napoly naMinimalPoly;
    42 #define naParNames (currRing->parameter)
    43 static int naIsChar0;
    44 static ring naMapRing;
     28#include <kernel/longtrans.h>
    4529
    4630#ifdef LDEBUG
     
    5135#endif
    5236
     37naIdeal naI = NULL;
     38napoly naMinimalPoly;
     39omBin snaIdeal_bin = omGetSpecBin(sizeof(snaIdeal));
    5340number (*naMap)(number from);
    54 /* procedure variables */
    55 static numberfunc
    56                 nacMult, nacSub, nacAdd, nacDiv, nacIntDiv;
    57 static number   (*nacGcd)(number a, number b, const ring r);
    58 static number   (*nacLcm)(number a, number b, const ring r);
    59 static number   (*nacInit)(int i, const ring r);
    60 static int      (*nacInt)(number &n, const ring r);
    61 static void     (*nacDelete)(number *a, const ring r);
    62 #undef n_Delete
    63 #define n_Delete(A,R) nacDelete(A,R)
    64        void     (*nacNormalize)(number &a);
    65 static number   (*nacNeg)(number a);
    66        number   (*nacCopy)(number a);
    67 static number   (*nacInvers)(number a);
    68        BOOLEAN  (*nacIsZero)(number a);
    69 static BOOLEAN  (*nacIsOne)(number a);
    70 static BOOLEAN  (*nacIsMOne)(number a);
    71 static BOOLEAN  (*nacGreaterZero)(number a);
    72 static const char   * (*nacRead) (const char *s, number *a);
    73 static napoly napRedp(napoly q);
    74 static napoly napTailred(napoly q);
    75 static BOOLEAN napDivPoly(napoly p, napoly q);
    76 static int napExpi(int i, napoly a, napoly b);
    77        ring nacRing;
    78 
    79 void naCoefNormalize(number pp);
    80 
    81 #define napCopy(p)       p_Copy(p,nacRing)
    82 
    83 static number nadGcd( number a, number b, const ring r) { return nacInit(1,r); }
     41
     42static number nadGcd( number a, number b, const ring r) { return ntcInit(1,r); }
    8443/*2
    8544*  sets the appropriate operators
     
    12079  }
    12180
    122   naNumbOfPar=rPar(r);
     81  ntNumbOfPar=rPar(r);
    12382  if (i == 1)
    12483  {
    125     naIsChar0 = 1;
     84    ntIsChar0 = 1;
    12685  }
    12786  else if (i < 0)
    12887  {
    129     naIsChar0 = 0;
     88    ntIsChar0 = 0;
    13089    npSetChar(-i, r->algring); // to be changed HS
    13190  }
     
    13796#endif
    13897  nacRing        = r->algring;
    139   nacInit        = nacRing->cf->cfInit;
    140   nacInt         = nacRing->cf->n_Int;
    141   nacCopy        = nacRing->cf->nCopy;
    142   nacAdd         = nacRing->cf->nAdd;
    143   nacSub         = nacRing->cf->nSub;
    144   nacNormalize   = nacRing->cf->nNormalize;
    145   nacNeg         = nacRing->cf->nNeg;
    146   nacIsZero      = nacRing->cf->nIsZero;
    147   nacRead        = nacRing->cf->nRead;
    148   nacGreaterZero = nacRing->cf->nGreaterZero;
    149   nacIsOne       = nacRing->cf->nIsOne;
    150   nacIsMOne      = nacRing->cf->nIsMOne;
    151   nacGcd         = nacRing->cf->nGcd;
    152   nacLcm         = nacRing->cf->nLcm;
    153   nacMult        = nacRing->cf->nMult;
    154   nacDiv         = nacRing->cf->nDiv;
    155   nacIntDiv      = nacRing->cf->nIntDiv;
    156   nacInvers      = nacRing->cf->nInvers;
    157   nacDelete      = nacRing->cf->cfDelete;
    158 }
    159 
    160 /*============= procedure for polynomials: napXXXX =======================*/
    161 
    162 
    163 
    164 #ifdef LDEBUG
    165 static void napTest(napoly p)
    166 {
    167   while (p != NULL)
    168   {
    169     if (naIsChar0)
    170       nlDBTest(pGetCoeff(p), "", 0);
    171     pIter(p);
    172   }
    173 }
    174 #else
    175 #define napTest(p) ((void) 0)
    176 #endif
    177 
    178 #define napSetCoeff(p,n) {n_Delete(&pGetCoeff(p),nacRing);pGetCoeff(p)=n;}
    179 #define napComp(p,q)     p_LmCmp((poly)p,(poly)q, nacRing)
    180 #define napMultT(A,E)    A=(napoly)p_Mult_mm((poly)A,(poly)E,nacRing)
    181 #define napDeg(p)        (int)p_Totaldegree(p, nacRing)
    182 
    183 /*3
    184 * creates  an napoly
    185 */
    186 napoly napInitz(number z)
    187 {
    188   napoly a = (napoly)p_Init(nacRing);
    189   pGetCoeff(a) = z;
    190   return a;
    191 }
    192 
    193 /*3
    194 * copy a napoly. poly
    195 */
    196 static napoly napCopyNeg(napoly p)
    197 {
    198   napoly r=napCopy(p);
    199   r=(napoly)p_Neg((poly)r, nacRing);
    200   return r;
    201 }
    202 
    203 /*3
    204 * returns ph * z
    205 */
    206 static void napMultN(napoly p, number z)
    207 {
    208   number t;
    209 
    210   while (p!=NULL)
    211   {
    212     t = nacMult(pGetCoeff(p), z);
    213     nacNormalize(t);
    214     n_Delete(&pGetCoeff(p),nacRing);
    215     pGetCoeff(p) = t;
    216     pIter(p);
    217   }
    218 }
    219 
    220 /*3
    221 *  division with remainder: f = g*q + r,
    222 *  returns r and destroys f
    223 */
    224 napoly napRemainder(napoly f, const napoly g)
    225 {
    226   napoly a, h, qq;
    227 
    228   qq = (napoly)p_Init(nacRing);
    229   pNext(qq) = NULL;
    230   p_Normalize(g, nacRing);
    231   p_Normalize(f, nacRing);
    232   a = f;
    233   do
    234   {
    235     napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing));
    236     napSetm(qq);
    237     pGetCoeff(qq) = nacDiv(pGetCoeff(a), pGetCoeff(g));
    238     pGetCoeff(qq) = nacNeg(pGetCoeff(qq));
    239     nacNormalize(pGetCoeff(qq));
    240     h = napCopy(g);
    241     napMultT(h, qq);
    242     p_Normalize(h,nacRing);
    243     n_Delete(&pGetCoeff(qq),nacRing);
    244     a = napAdd(a, h);
    245   }
    246   while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing)));
    247   omFreeBinAddr(qq);
    248   return a;
    249 }
    250 
    251 /*3
    252 *  division with rest; f = g*q + r,  destroy f
    253 */
    254 static void napDivMod(napoly f, napoly  g, napoly *q, napoly *r)
    255 {
    256   napoly a, h, b, qq;
    257 
    258   qq = (napoly)p_Init(nacRing);
    259   pNext(qq) = b = NULL;
    260   p_Normalize(g,nacRing);
    261   p_Normalize(f,nacRing);
    262   a = f;
    263   do
    264   {
    265     napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing));
    266     p_Setm(qq,nacRing);
    267     pGetCoeff(qq) = nacDiv(pGetCoeff(a), pGetCoeff(g));
    268     nacNormalize(pGetCoeff(qq));
    269     b = napAdd(b, napCopy(qq));
    270     pGetCoeff(qq) = nacNeg(pGetCoeff(qq));
    271     h = napCopy(g);
    272     napMultT(h, qq);
    273     p_Normalize(h,nacRing);
    274     n_Delete(&pGetCoeff(qq),nacRing);
    275     a = napAdd(a, h);
    276   }
    277   while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing)));
    278   omFreeBinAddr(qq);
    279   *q = b;
    280   *r = a;
    281 }
    282 
    283 /*3
    284 *  returns z with z*x mod c = 1
    285 */
    286 static napoly napInvers(napoly x, const napoly c)
    287 {
    288   napoly y, r, qa, qn, q;
    289   number t, h;
    290 
    291   if (p_GetExp(x,1,nacRing) >= p_GetExp(c,1,nacRing))
    292     x = napRemainder(x, c);
    293   if (x==NULL)
    294   {
    295     goto zero_divisor;
    296   }
    297   if (p_GetExp(x,1,nacRing)==0)
    298   {
    299     if (!nacIsOne(pGetCoeff(x)))
    300     {
    301       nacNormalize(pGetCoeff(x));
    302       t = nacInvers(pGetCoeff(x));
    303       nacNormalize(t);
    304       n_Delete(&pGetCoeff(x),nacRing);
    305       pGetCoeff(x) = t;
    306     }
    307     return x;
    308   }
    309   y = napCopy(c);
    310   napDivMod(y, x, &qa, &r);
    311   if (r==NULL)
    312   {
    313     goto zero_divisor;
    314   }
    315   if (p_GetExp(r,1,nacRing)==0)
    316   {
    317     nacNormalize(pGetCoeff(r));
    318     t = nacInvers(pGetCoeff(r));
    319     nacNormalize(t);
    320     t = nacNeg(t);
    321     napMultN(qa, t);
    322     n_Delete(&t,nacRing);
    323     p_Normalize(qa,nacRing);
    324     p_Delete(&x,nacRing);
    325     p_Delete(&r,nacRing);
    326     return qa;
    327   }
    328   y = x;
    329   x = r;
    330   napDivMod(y, x, &q, &r);
    331   if (r==NULL)
    332   {
    333     goto zero_divisor;
    334   }
    335   if (p_GetExp(r,1,nacRing)==0)
    336   {
    337     q = p_Mult_q(q, qa,nacRing);
    338     q = napAdd(q, p_ISet(1,nacRing));
    339     nacNormalize(pGetCoeff(r));
    340     t = nacInvers(pGetCoeff(r));
    341     napMultN(q, t);
    342     p_Normalize(q,nacRing);
    343     n_Delete(&t,nacRing);
    344     p_Delete(&x,nacRing);
    345     p_Delete(&r,nacRing);
    346     if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing))
    347       q = napRemainder(q, c);
    348     return q;
    349   }
    350   q = p_Mult_q(q, napCopy(qa),nacRing);
    351   q = napAdd(q, p_ISet(1,nacRing));
    352   qa = napNeg(qa);
    353   loop
    354   {
    355     y = x;
    356     x = r;
    357     napDivMod(y, x, &qn, &r);
    358     if (r==NULL)
    359     {
    360       break;
    361     }
    362     if (p_GetExp(r,1,nacRing)==0)
    363     {
    364       q = p_Mult_q(q, qn,nacRing);
    365       q = napNeg(q);
    366       q = napAdd(q, qa);
    367       nacNormalize(pGetCoeff(r));
    368       t = nacInvers(pGetCoeff(r));
    369       //nacNormalize(t);
    370       napMultN(q, t);
    371       p_Normalize(q,nacRing);
    372       n_Delete(&t,nacRing);
    373       p_Delete(&x,nacRing);
    374       p_Delete(&r,nacRing);
    375       if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing))
    376         q = napRemainder(q, c);
    377       return q;
    378     }
    379     y = q;
    380     q = p_Mult_q(napCopy(q), qn, nacRing);
    381     q = napNeg(q);
    382     q = napAdd(q, qa);
    383     qa = y;
    384   }
    385 // zero divisor found:
    386 zero_divisor:
    387   Werror("zero divisor found - your minpoly is not irreducible");
    388   return x;
    389 }
    390 
    391 /*3
    392 * the max degree of an napoly poly (used for test of "simple" et al.)
    393 */
    394 static int  napMaxDeg(napoly p)
    395 {
    396   int  d = 0;
    397   while(p!=NULL)
    398   {
    399     d=si_max(d,napDeg(p));
    400     pIter(p);
    401   }
    402   return d;
    403 }
    404 
    405 /*3
    406 * the max degree of an napoly poly (used for test of "simple" et al.)
    407 */
    408 static int  napMaxDegLen(napoly p, int &l)
    409 {
    410   int  d = 0;
    411   int ll=0;
    412   while(p!=NULL)
    413   {
    414     d=si_max(d,napDeg(p));
    415     pIter(p);
    416     ll++;
    417   }
    418   l=ll;
    419   return d;
    420 }
    421 
    422 
    423 /*3
    424 *writes a polynomial number
    425 */
    426 void napWrite(napoly p,const BOOLEAN has_denom, const ring r)
    427 {
    428   ring nacring=r->algring;
    429   if (p==NULL)
    430     StringAppendS("0");
    431   else if (p_LmIsConstant(p,nacring))
    432   {
    433     BOOLEAN kl=FALSE;
    434     if (has_denom)
    435     {
    436       number den=nacring->cf->cfGetDenom(pGetCoeff(p),nacring );
    437       kl=!n_IsOne(den,nacring);
    438       n_Delete(&den, nacring);
    439     }
    440     if (kl) StringAppendS("(");
    441     //StringAppendS("-1");
    442     n_Write(pGetCoeff(p),nacring);
    443     if (kl) StringAppendS(")");
    444   }
    445   else
    446   {
    447     StringAppendS("(");
    448     loop
    449     {
    450       BOOLEAN wroteCoeff=FALSE;
    451       if ((p_LmIsConstant(p,nacring))
    452       || ((!n_IsOne(pGetCoeff(p),nacring))
    453         && (!n_IsMOne(pGetCoeff(p),nacring))))
    454       {
    455         n_Write(pGetCoeff(p),nacring);
    456         wroteCoeff=(r->ShortOut==0);
    457       }
    458       else if (n_IsMOne(pGetCoeff(p),nacring))
    459       {
    460         StringAppendS("-");
    461       }
    462       int  i;
    463       for (i = 0; i < r->P; i++)
    464       {
    465         int e=p_GetExp(p,i+1,nacring);
    466         if (e > 0)
    467         {
    468           if (wroteCoeff)
    469             StringAppendS("*");
    470           else
    471             wroteCoeff=(r->ShortOut==0);
    472           StringAppendS(r->parameter[i]);
    473           if (e > 1)
    474           {
    475             if (r->ShortOut == 0)
    476               StringAppendS("^");
    477             StringAppend("%d", e);
    478           }
    479         }
    480       } /*for*/
    481       pIter(p);
    482       if (p==NULL)
    483         break;
    484       if (n_GreaterZero(pGetCoeff(p),nacring))
    485         StringAppendS("+");
    486     }
    487     StringAppendS(")");
    488   }
    489 }
    490 
    491 
    492 static const char *napHandleMons(const char *s, int i, napoly ex)
    493 {
    494   int  j;
    495   if (strncmp(s,naParNames[i],strlen(naParNames[i]))==0)
    496   {
    497     s+=strlen(naParNames[i]);
    498     if ((*s >= '0') && (*s <= '9'))
    499     {
    500       s = eati(s, &j);
    501       napAddExp(ex,i+1,j);
    502     }
    503     else
    504       napAddExp(ex,i+1,1);
    505   }
    506   return s;
    507 }
    508 static const char *napHandlePars(const char *s, int i, napoly ex)
    509 {
    510   int  j;
    511   if (strcmp(s,naParNames[i])==0)
    512   {
    513     s+=strlen(naParNames[i]);
    514     napSetExp(ex,i+1,1);
    515   }
    516   return s;
    517 }
    518 
    519 /*3  reads a monomial  */
    520 static const char  *napRead(const char *s, napoly *b)
    521 {
    522   napoly a;
    523   int  i;
    524   a = (napoly)p_Init(nacRing);
    525   if ((*s >= '0') && (*s <= '9'))
    526   {
    527     s = nacRead(s, &pGetCoeff(a));
    528     if (nacIsZero(pGetCoeff(a)))
    529     {
    530       p_LmDelete(&a,nacRing);
    531       *b = NULL;
    532       return s;
    533     }
    534   }
    535   else
    536     pGetCoeff(a) = nacInit(1,nacRing);
    537   i = 0;
    538   const char  *olds=s;
    539   loop
    540   {
    541     s = napHandlePars(s, i, a);
    542     if (olds == s)
    543       i++;
    544     else if (*s == '\0')
    545     {
    546       *b = a;
    547       return s;
    548     }
    549     if (i >= naNumbOfPar)
    550       break;
    551   }
    552   i=0;
    553   loop
    554   {
    555     olds = s;
    556     s = napHandleMons(s, i, a);
    557     if (olds == s)
    558       i++;
    559     else
    560       i = 0;
    561     if ((*s == '\0') || (i >= naNumbOfPar))
    562       break;
    563   }
    564   *b = a;
    565   return s;
    566 }
    567 
    568 static int napExp(napoly a, napoly b)
    569 {
    570   while (pNext(a)!=NULL) pIter(a);
    571   int m = p_GetExp(a,1,nacRing);
    572   if (m==0) return 0;
    573   while (pNext(b)!=NULL) pIter(b);
    574   int mm=p_GetExp(b,1,nacRing);
    575   if (m > mm) m = mm;
    576   return m;
    577 }
    578 
    579 /*
    580 * finds the smallest i-th exponent in a and b
    581 * used to find it in a fraction
    582 */
    583 static int napExpi(int i, napoly a, napoly b)
    584 {
    585   if (a==NULL || b==NULL) return 0;
    586   int m = p_GetExp(a,i+1,nacRing);
    587   if (m==0) return 0;
    588   while (pNext(a) != NULL)
    589   {
    590     pIter(a);
    591     if (m > p_GetExp(a,i+1,nacRing))
    592     {
    593       m = p_GetExp(a,i+1,nacRing);
    594       if (m==0) return 0;
    595     }
    596   }
    597   do
    598   {
    599     if (m > p_GetExp(b,i+1,nacRing))
    600     {
    601       m = p_GetExp(b,i+1,nacRing);
    602       if (m==0) return 0;
    603     }
    604     pIter(b);
    605   }
    606   while (b != NULL);
    607   return m;
    608 }
    609 
    610 static void napContent(napoly ph)
    611 {
    612   number h,d;
    613   napoly p;
    614 
    615   p = ph;
    616   if (nacIsOne(pGetCoeff(p)))
    617     return;
    618   h = nacCopy(pGetCoeff(p));
    619   pIter(p);
    620   do
    621   {
    622     d=nacGcd(pGetCoeff(p), h, nacRing);
    623     if(nacIsOne(d))
    624     {
    625       n_Delete(&h,nacRing);
    626       n_Delete(&d,nacRing);
    627       return;
    628     }
    629     n_Delete(&h,nacRing);
    630     h = d;
    631     pIter(p);
    632   }
    633   while (p!=NULL);
    634   h = nacInvers(d);
    635   n_Delete(&d,nacRing);
    636   p = ph;
    637   while (p!=NULL)
    638   {
    639     d = nacMult(pGetCoeff(p), h);
    640     n_Delete(&pGetCoeff(p),nacRing);
    641     pGetCoeff(p) = d;
    642     pIter(p);
    643   }
    644   n_Delete(&h,nacRing);
    645 }
    646 
    647 static void napCleardenom(napoly ph)
    648 {
    649   number d, h;
    650   napoly p;
    651 
    652   if (!naIsChar0)
    653     return;
    654   p = ph;
    655   h = nacInit(1,nacRing);
    656   while (p!=NULL)
    657   {
    658     d = nacLcm(h, pGetCoeff(p), nacRing);
    659     n_Delete(&h,nacRing);
    660     h = d;
    661     pIter(p);
    662   }
    663   if(!nacIsOne(h))
    664   {
    665     p = ph;
    666     while (p!=NULL)
    667     {
    668       d=nacMult(h, pGetCoeff(p));
    669       n_Delete(&pGetCoeff(p),nacRing);
    670       nacNormalize(d);
    671       pGetCoeff(p) = d;
    672       pIter(p);
    673     }
    674     n_Delete(&h,nacRing);
    675   }
    676   napContent(ph);
    677 }
    678 
    679 static napoly napGcd0(napoly a, napoly b)
    680 {
    681   number x, y;
    682   if (!naIsChar0)
    683     return p_ISet(1,nacRing);
    684   x = nacCopy(pGetCoeff(a));
    685   if (nacIsOne(x))
    686     return napInitz(x);
    687   while (pNext(a)!=NULL)
    688   {
    689     pIter(a);
    690     y = nacGcd(x, pGetCoeff(a), nacRing);
    691     n_Delete(&x,nacRing);
    692     x = y;
    693     if (nacIsOne(x))
    694       return napInitz(x);
    695   }
    696   do
    697   {
    698     y = nacGcd(x, pGetCoeff(b), nacRing);
    699     n_Delete(&x,nacRing);
    700     x = y;
    701     if (nacIsOne(x))
    702       return napInitz(x);
    703     pIter(b);
    704   }
    705   while (b!=NULL);
    706   return napInitz(x);
    707 }
    708 
    709 /*3
    710 * result =gcd(a,b)
    711 */
    712 static napoly napGcd(napoly a, napoly b)
    713 {
    714   int i;
    715   napoly g, x, y, h;
    716   if ((a==NULL)
    717   || ((pNext(a)==NULL)&&(nacIsZero(pGetCoeff(a)))))
    718   {
    719     if ((b==NULL)
    720     || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b)))))
    721     {
    722       return p_ISet(1,nacRing);
    723     }
    724     return napCopy(b);
    725   }
    726   else
    727   if ((b==NULL)
    728   || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b)))))
    729   {
    730     return napCopy(a);
    731   }
    732   if (naMinimalPoly != NULL)
    733   {
    734     if (p_GetExp(a,1,nacRing) >= p_GetExp(b,1,nacRing))
    735     {
    736       x = a;
    737       y = b;
    738     }
    739     else
    740     {
    741       x = b;
    742       y = a;
    743     }
    744     if (!naIsChar0) g = p_ISet(1,nacRing);
    745     else            g = napGcd0(x, y);
    746     if (pNext(y)==NULL)
    747     {
    748       napSetExp(g,1, napExp(x, y));
    749       p_Setm(g,nacRing);
    750       return g;
    751     }
    752     x = napCopy(x);
    753     y = napCopy(y);
    754     loop
    755     {
    756       h = napRemainder(x, y);
    757       if (h==NULL)
    758       {
    759         napCleardenom(y);
    760         if (!nacIsOne(pGetCoeff(g)))
    761           napMultN(y, pGetCoeff(g));
    762         p_LmDelete(&g,nacRing);
    763         return y;
    764       }
    765       else if (pNext(h)==NULL)
    766         break;
    767       x = y;
    768       y = h;
    769     }
    770     p_Delete(&y,nacRing);
    771     p_LmDelete(&h,nacRing);
    772     napSetExp(g,1, napExp(a, b));
    773     p_Setm(g,nacRing);
    774     return g;
    775   }
    776   // Hmm ... this is a memory leak
    777   // x = (napoly)p_Init(nacRing);
    778   g=a;
    779   h=b;
    780   if (!naIsChar0) x = p_ISet(1,nacRing);
    781   else            x = napGcd0(g,h);
    782   for (i=(naNumbOfPar-1); i>=0; i--)
    783   {
    784     napSetExp(x,i+1, napExpi(i,a,b));
    785     p_Setm(x,nacRing);
    786   }
    787   return x;
    788 }
    789 
    790 
    791 number napLcm(napoly a)
    792 {
    793   number h = nacInit(1,nacRing);
    794 
    795   if (naIsChar0)
    796   {
    797     number d;
    798     napoly b = a;
    799 
    800     while (b!=NULL)
    801     {
    802       d = nacLcm(h, pGetCoeff(b), nacRing);
    803       n_Delete(&h,nacRing);
    804       h = d;
    805       pIter(b);
    806     }
    807   }
    808   return h;
    809 }
    810 
    811 
    812 /*2
    813 * meins  (for reduction in algebraic extension)
    814 * checks if head of p divides head of q
    815 * doesn't delete p and q
    816 */
    817 static BOOLEAN napDivPoly (napoly p, napoly q)
    818 {
    819   int j=1;   /* evtl. von naNumber.. -1 abwaerts zaehlen */
    820 
    821   while (p_GetExp(p,j,nacRing) <= p_GetExp(q,j,nacRing))
    822   {
    823     j++;
    824     if (j > naNumbOfPar)
    825       return 1;
    826   }
    827   return 0;
    828 }
    829 
    830 
    831 /*2
    832 * meins  (for reduction in algebraic extension)
    833 * Normalform of poly with naI
    834 * changes q and returns it
    835 */
    836 napoly napRedp (napoly q)
    837 {
    838   napoly h = (napoly)p_Init(nacRing);
    839   int i=0,j;
    840 
    841   loop
    842   {
    843     if (napDivPoly (naI->liste[i], q))
    844     {
    845       /* h = lt(q)/lt(naI->liste[i])*/
    846       pGetCoeff(h) = nacCopy(pGetCoeff(q));
    847       for (j=naNumbOfPar; j>0; j--)
    848         napSetExp(h,j, p_GetExp(q,j,nacRing) - p_GetExp(naI->liste[i],j,nacRing));
    849       p_Setm(h,nacRing);
    850       h = p_Mult_q(h, napCopy(naI->liste[i]),nacRing);
    851       h = napNeg (h);
    852       q = napAdd (q, napCopy(h));
    853       p_Delete (&pNext(h),nacRing);
    854       if (q == NULL)
    855       {
    856         p_Delete(&h,nacRing);
    857         return q;
    858       }
    859       /* try to reduce further */
    860       i = 0;
    861     }
    862     else
    863     {
    864       i++;
    865       if (i >= naI->anz)
    866       {
    867         p_Delete(&h,nacRing);
    868         return q;
    869       }
    870     }
    871   }
    872 }
    873 
    874 
    875 /*2
    876 * meins  (for reduction in algebraic extension)
    877 * reduces the tail of Poly q
    878 * needs q != NULL
    879 * changes q and returns it
    880 */
    881 napoly napTailred (napoly q)
    882 {
    883   napoly h;
    884 
    885   h = pNext(q);
    886   while (h != NULL)
    887   {
    888      h = napRedp (h);
    889      if (h == NULL)
    890         return q;
    891      pIter(h);
    892   }
    893   return q;
    894 }
    895 
     98  ntcInit        = nacRing->cf->cfInit;
     99  ntcInt         = nacRing->cf->n_Int;
     100  ntcCopy        = nacRing->cf->nCopy;
     101  ntcAdd         = nacRing->cf->nAdd;
     102  ntcSub         = nacRing->cf->nSub;
     103  ntcNormalize   = nacRing->cf->nNormalize;
     104  ntcNeg         = nacRing->cf->nNeg;
     105  ntcIsZero      = nacRing->cf->nIsZero;
     106  ntcRead        = nacRing->cf->nRead;
     107  ntcGreaterZero = nacRing->cf->nGreaterZero;
     108  ntcIsOne       = nacRing->cf->nIsOne;
     109  ntcIsMOne      = nacRing->cf->nIsMOne;
     110  ntcGcd         = nacRing->cf->nGcd;
     111  ntcLcm         = nacRing->cf->nLcm;
     112  ntcMult        = nacRing->cf->nMult;
     113  ntcDiv         = nacRing->cf->nDiv;
     114  ntcIntDiv      = nacRing->cf->nIntDiv;
     115  ntcInvers      = nacRing->cf->nInvers;
     116  ntcDelete      = nacRing->cf->cfDelete;
     117}
    896118
    897119/*================ procedure for rational functions: naXXXX =================*/
     
    963185  if ((l!=NULL)&&(l->n==NULL)&&(p_IsConstant(l->z,r->algring)))
    964186  {
    965     return nacInt(pGetCoeff(l->z),r->algring);
     187    return ntcInt(pGetCoeff(l->z),r->algring);
    966188  }
    967189  return 0;
     
    1052274  //  if (p_LmIsConstant(x,nacRing))
    1053275  //  {
    1054   //    number inv=nacInvers(pGetCoeff(x));
     276  //    number inv=ntcInvers(pGetCoeff(x));
    1055277  //    napMultN(lu->z,inv);
    1056278  //    n_Delete(&inv,nacRing);
     
    1177399  {
    1178400    if (p_GetExp(lo->z,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))
    1179       lo->z = napRemainder(lo->z, naMinimalPoly);
     401      lo->z = naRemainder(lo->z, naMinimalPoly);
    1180402    if ((x!=NULL) && (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)))
    1181       x = napRemainder(x, naMinimalPoly);
     403      x = naRemainder(x, naMinimalPoly);
    1182404  }
    1183405  if (naI!=NULL)
     
    1193415    }
    1194416  }
    1195   if ((x!=NULL) && (p_LmIsConstant(x,nacRing)) && nacIsOne(pGetCoeff(x)))
     417  if ((x!=NULL) && (p_LmIsConstant(x,nacRing)) && ntcIsOne(pGetCoeff(x)))
    1196418    p_Delete(&x,nacRing);
    1197419  lo->n = x;
     
    1277499  {
    1278500    if (p_GetExp(lo->z,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))
    1279       lo->z = napRemainder(lo->z, naMinimalPoly);
     501      lo->z = naRemainder(lo->z, naMinimalPoly);
    1280502    if (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))
    1281       x = napRemainder(x, naMinimalPoly);
     503      x = naRemainder(x, naMinimalPoly);
    1282504  }
    1283505  if (naI!=NULL)
     
    1293515    }
    1294516  }
    1295   if ((p_LmIsConstant(x,nacRing)) && nacIsOne(pGetCoeff(x)))
     517  if ((p_LmIsConstant(x,nacRing)) && ntcIsOne(pGetCoeff(x)))
    1296518    p_Delete(&x,nacRing);
    1297519  lo->n = x;
     
    1348570    lo->z = p_ISet(1,nacRing);
    1349571  x = b->z;
    1350   if ((!p_LmIsConstant(x,nacRing)) || !nacIsOne(pGetCoeff(x)))
     572  if ((!p_LmIsConstant(x,nacRing)) || !ntcIsOne(pGetCoeff(x)))
    1351573    x = napCopy(x);
    1352574  else
     
    1361583    x = p_Mult_q(x, lo->z,nacRing);
    1362584    if (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))
    1363       x = napRemainder(x, naMinimalPoly);
     585      x = naRemainder(x, naMinimalPoly);
    1364586    lo->z = x;
    1365587    lo->n = NULL;
    1366588    while (x!=NULL)
    1367589    {
    1368       nacNormalize(pGetCoeff(x));
     590      ntcNormalize(pGetCoeff(x));
    1369591      pIter(x);
    1370592    }
     
    1405627  if (zb!=NULL)
    1406628  {
    1407     return (nacGreaterZero(pGetCoeff(zb->z))||(!p_LmIsConstant(zb->z,nacRing)));
     629    return (ntcGreaterZero(pGetCoeff(zb->z))||(!p_LmIsConstant(zb->z,nacRing)));
    1408630  }
    1409631  /* else */ return FALSE;
     
    1474696  if ((naMinimalPoly!=NULL)
    1475697  && (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)))
    1476     a->z = napRemainder(x, naMinimalPoly);
     698    a->z = naRemainder(x, naMinimalPoly);
    1477699  else if (naI!=NULL)
    1478700  {
     
    1506728    return NULL;
    1507729  int i;
    1508   char *s=(char *)omAlloc(4* naNumbOfPar);
     730  char *s=(char *)omAlloc(4* ntNumbOfPar);
    1509731  char *t=(char *)omAlloc(8);
    1510732  s[0]='\0';
    1511   for (i = 0; i <= naNumbOfPar - 1; i++)
     733  for (i = 0; i <= ntNumbOfPar - 1; i++)
    1512734  {
    1513735    int e=p_GetExp(ph->z,i+1,nacRing);
     
    1576798    if (p_LmIsConstant(a->z,nacRing))
    1577799    {
    1578       return nacIsOne(pGetCoeff(a->z));
     800      return ntcIsOne(pGetCoeff(a->z));
    1579801    }
    1580802    else                 return FALSE;
     
    1589811    else
    1590812    {
    1591       t = nacSub(pGetCoeff(x), pGetCoeff(y));
    1592       if (!nacIsZero(t))
     813      t = ntcSub(pGetCoeff(x), pGetCoeff(y));
     814      if (!ntcIsZero(t))
    1593815      {
    1594816        n_Delete(&t,nacRing);
     
    1632854  if (a->n==NULL)
    1633855  {
    1634     if (p_LmIsConstant(a->z,nacRing)) return nacIsMOne(pGetCoeff(a->z));
     856    if (p_LmIsConstant(a->z,nacRing)) return ntcIsMOne(pGetCoeff(a->z));
    1635857    /*else                   return FALSE;*/
    1636858  }
     
    1666888  x = (lnumber)a;
    1667889  y = (lnumber)b;
    1668   if ((naNumbOfPar == 1) && (naMinimalPoly!=NULL))
     890  if ((ntNumbOfPar == 1) && (naMinimalPoly!=NULL))
    1669891  {
    1670892    if (pNext(x->z)!=NULL)
     
    1706928
    1707929/*2
    1708 * naNumbOfPar = 1:
     930* ntNumbOfPar = 1:
    1709931* clears denominator         algebraic case;
    1710932* tries to simplify ratio    transcendental case;
     
    1712934* cancels monomials
    1713935* occuring in denominator
    1714 * and enumerator  ?          naNumbOfPar != 1;
     936* and enumerator  ?          ntNumbOfPar != 1;
    1715937*
    1716938* #defines for Factory:
     
    18101032  if (p->n!=NULL)
    18111033  {
    1812     if(!nacGreaterZero(pGetCoeff(p->n)))
     1034    if(!ntcGreaterZero(pGetCoeff(p->n)))
    18131035    {
    18141036      p->z=napNeg(p->z);
     
    18461068    x = p_Mult_q(x, y,nacRing);
    18471069    if (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))
    1848       x = napRemainder(x, naMinimalPoly);
     1070      x = naRemainder(x, naMinimalPoly);
    18491071    p->z = x;
    18501072    p->n = y = NULL;
    1851     norm=naIsChar0;
     1073    norm=ntIsChar0;
    18521074  }
    18531075
     
    18571079  // DO NOT REDUCE naMinimalPoly with itself
    18581080  {
    1859     x = napRemainder(x, naMinimalPoly);
     1081    x = naRemainder(x, naMinimalPoly);
    18601082    p->z = x;
    1861     norm=naIsChar0;
     1083    norm=ntIsChar0;
    18621084  }
    18631085  /* normalize all coefficients in n and z (if in Q) */
     
    18731095  {
    18741096    int i;
    1875     for (i=naNumbOfPar-1; i>=0; i--)
     1097    for (i=ntNumbOfPar-1; i>=0; i--)
    18761098    {
    18771099      napoly xx=x;
     
    18951117  if (p_LmIsConstant(y,nacRing)) /* i.e. => simplify to (1/c)*z / monom */
    18961118  {
    1897     if (nacIsOne(pGetCoeff(y)))
     1119    if (ntcIsOne(pGetCoeff(y)))
    18981120    {
    18991121      p_LmDelete(&y,nacRing);
     
    19021124      return;
    19031125    }
    1904     number h1 = nacInvers(pGetCoeff(y));
    1905     nacNormalize(h1);
     1126    number h1 = ntcInvers(pGetCoeff(y));
     1127    ntcNormalize(h1);
    19061128    napMultN(x, h1);
    19071129    n_Delete(&h1,nacRing);
     
    19121134  }
    19131135#ifndef FACTORY_GCD_TEST
    1914   if (naNumbOfPar == 1) /* apply built-in gcd */
     1136  if (ntNumbOfPar == 1) /* apply built-in gcd */
    19151137  {
    19161138    napoly x1,y1;
     
    19281150    loop
    19291151    {
    1930       r = napRemainder(x1, y1);
     1152      r = naRemainder(x1, y1);
    19311153      if ((r==NULL) || (pNext(r)==NULL)) break;
    19321154      x1 = y1;
     
    19471169    y = p->n;
    19481170    /* collect all denoms from y and multiply x and y by it */
    1949     if (naIsChar0)
     1171    if (ntIsChar0)
    19501172    {
    19511173      number n=napLcm(y);
     
    19551177      while(x!=NULL)
    19561178      {
    1957         nacNormalize(pGetCoeff(x));
     1179        ntcNormalize(pGetCoeff(x));
    19581180        pIter(x);
    19591181      }
     
    19611183      while(y!=NULL)
    19621184      {
    1963         nacNormalize(pGetCoeff(y));
     1185        ntcNormalize(pGetCoeff(y));
    19641186        pIter(y);
    19651187      }
     
    19681190    if (pNext(y)==NULL)
    19691191    {
    1970       if (nacIsOne(pGetCoeff(y)))
     1192      if (ntcIsOne(pGetCoeff(y)))
    19711193      {
    19721194        if (p_GetExp(y,1,nacRing)==0)
     
    20001222  x=p->z;
    20011223  y=p->n;
    2002   if(!nacGreaterZero(pGetCoeff(y)))
     1224  if(!ntcGreaterZero(pGetCoeff(y)))
    20031225  {
    20041226    x=napNeg(x);
    20051227    y=napNeg(y);
    20061228  }
    2007   number g=nacCopy(pGetCoeff(x));
     1229  number g=ntcCopy(pGetCoeff(x));
    20081230  pIter(x);
    20091231  while (x!=NULL)
    20101232  {
    2011     number d=nacGcd(g,pGetCoeff(x), nacRing);
    2012     if(nacIsOne(d))
     1233    number d=ntcGcd(g,pGetCoeff(x), nacRing);
     1234    if(ntcIsOne(d))
    20131235    {
    20141236      n_Delete(&g,nacRing);
     
    20231245  while (y!=NULL)
    20241246  {
    2025     number d=nacGcd(g,pGetCoeff(y), nacRing);
    2026     if(nacIsOne(d))
     1247    number d=ntcGcd(g,pGetCoeff(y), nacRing);
     1248    if(ntcIsOne(d))
    20271249    {
    20281250      n_Delete(&g,nacRing);
     
    20391261  while (x!=NULL)
    20401262  {
    2041     number d = nacIntDiv(pGetCoeff(x),g);
     1263    number d = ntcIntDiv(pGetCoeff(x),g);
    20421264    napSetCoeff(x,d);
    20431265    pIter(x);
     
    20451267  while (y!=NULL)
    20461268  {
    2047     number d = nacIntDiv(pGetCoeff(y),g);
     1269    number d = ntcIntDiv(pGetCoeff(y),g);
    20481270    napSetCoeff(y,d);
    20491271    pIter(y);
     
    20631285  lnumber b = (lnumber)lb;
    20641286  result = (lnumber)omAlloc0Bin(rnumber_bin);
    2065   //if (((naMinimalPoly==NULL) && (naI==NULL)) || !naIsChar0)
     1287  //if (((naMinimalPoly==NULL) && (naI==NULL)) || !ntIsChar0)
    20661288  //{
    20671289  //  result->z = p_ISet(1,nacRing);
     
    20731295  napoly x = p_Copy(a->z, r->algring);
    20741296  number t = napLcm(b->z); // get all denom of b->z
    2075   if (!nacIsOne(t))
     1297  if (!ntcIsOne(t))
    20761298  {
    20771299    number bt, rr;
     
    20791301    while (xx!=NULL)
    20801302    {
    2081       bt = nacGcd(t, pGetCoeff(xx), r->algring);
    2082       rr = nacMult(t, pGetCoeff(xx));
     1303      bt = ntcGcd(t, pGetCoeff(xx), r->algring);
     1304      rr = ntcMult(t, pGetCoeff(xx));
    20831305      n_Delete(&pGetCoeff(xx),r->algring);
    2084       pGetCoeff(xx) = nacDiv(rr, bt);
    2085       nacNormalize(pGetCoeff(xx));
     1306      pGetCoeff(xx) = ntcDiv(rr, bt);
     1307      ntcNormalize(pGetCoeff(xx));
    20861308      n_Delete(&bt,r->algring);
    20871309      n_Delete(&rr,r->algring);
     
    21341356      naI->liste[i]=napCopy(h->z);
    21351357      /* If it isn't normalized (lc = 1) do this */
    2136       if (!nacIsOne(pGetCoeff(naI->liste[i])))
     1358      if (!ntcIsOne(pGetCoeff(naI->liste[i])))
    21371359      {
    21381360        x=naI->liste[i];
    2139         nacNormalize(pGetCoeff(x));
    2140         a=nacCopy(pGetCoeff(x));
    2141         number aa=nacInvers(a);
     1361        ntcNormalize(pGetCoeff(x));
     1362        a=ntcCopy(pGetCoeff(x));
     1363        number aa=ntcInvers(a);
    21421364        n_Delete(&a,nacRing);
    21431365        napMultN(x,aa);
     
    21581380  l->z=(napoly)p_Init(nacRing);
    21591381  int i=(int)((long)c);
    2160   if (i>((long)naMapRing->ch>>2)) i-=(long)naMapRing->ch;
     1382  if (i>((long)ntMapRing->ch>>2)) i-=(long)ntMapRing->ch;
    21611383  pGetCoeff(l->z)=nlInit(i, nacRing);
    21621384  l->n=NULL;
     
    21991421  if (npIsZero(c)) return NULL;
    22001422  int i=(int)((long)c);
    2201   if (i>(long)naMapRing->ch) i-=(long)naMapRing->ch;
    2202   number n=npInit(i,naMapRing);
     1423  if (i>(long)ntMapRing->ch) i-=(long)ntMapRing->ch;
     1424  number n=npInit(i,ntMapRing);
    22031425  if (npIsZero(n)) return NULL;
    22041426  lnumber l=(lnumber)omAllocBin(rnumber_bin);
     
    22271449}
    22281450
    2229 static number (*nacMap)(number);
    2230 static int naParsToCopy;
    2231 static napoly napMap(napoly p)
    2232 {
    2233   napoly w, a;
    2234 
    2235   if (p==NULL) return NULL;
    2236   a = w = (napoly)p_Init(nacRing);
    2237   int i;
    2238   for(i=1;i<=naParsToCopy;i++)
    2239     napSetExp(a,i,napGetExpFrom(p,i,naMapRing));
    2240   p_Setm(a,nacRing);
    2241   pGetCoeff(w) = nacMap(pGetCoeff(p));
    2242   loop
    2243   {
    2244     pIter(p);
    2245     if (p==NULL) break;
    2246     pNext(a) = (napoly)p_Init(nacRing);
    2247     pIter(a);
    2248     for(i=1;i<=naParsToCopy;i++)
    2249       napSetExp(a,i,napGetExpFrom(p,i,naMapRing));
    2250     p_Setm(a,nacRing);
    2251     pGetCoeff(a) = nacMap(pGetCoeff(p));
    2252   }
    2253   pNext(a) = NULL;
    2254   return w;
    2255 }
    2256 
    2257 static napoly napPerm(napoly p,const int *par_perm,const ring src_ring,const nMapFunc nMap)
    2258 {
    2259   napoly w, a;
    2260 
    2261   if (p==NULL) return NULL;
    2262   w = (napoly)p_Init(nacRing);
    2263   int i;
    2264   BOOLEAN not_null=TRUE;
    2265   loop
    2266   {
    2267     for(i=1;i<=rPar(src_ring);i++)
    2268     {
    2269       int e;
    2270       if (par_perm!=NULL) e=par_perm[i-1];
    2271       else                e=-i;
    2272       int ee=napGetExpFrom(p,i,src_ring);
    2273       if (e<0)
    2274         napSetExp(w,-e,ee);
    2275       else if (ee>0)
    2276         not_null=FALSE;
    2277     }
    2278     pGetCoeff(w) = nMap(pGetCoeff(p));
    2279     p_Setm(w,nacRing);
    2280     pIter(p);
    2281     if (!not_null)
    2282     {
    2283       if (p==NULL)
    2284       {
    2285         p_Delete(&w,nacRing);
    2286         return NULL;
    2287       }
    2288       /* else continue*/
    2289       n_Delete(&(pGetCoeff(w)),nacRing);
    2290     }
    2291     else
    2292     {
    2293       if (p==NULL) return w;
    2294       else
    2295       {
    2296         pNext(w)=napPerm(p,par_perm,src_ring,nMap);
    2297         return w;
    2298       }
    2299     }
    2300   }
    2301 }
    2302 
    23031451/*2
    23041452* map _(a) -> _(b)
     
    23161464    if (p_GetExp(erg->z,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))
    23171465    {
    2318       erg->z = napRemainder(erg->z, naMinimalPoly);
     1466      erg->z = naRemainder(erg->z, naMinimalPoly);
    23191467      if (erg->z==NULL)
    23201468      {
     
    23271475    {
    23281476      if (p_GetExp(erg->n,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))
    2329         erg->n = napRemainder(erg->n, naMinimalPoly);
    2330       if ((p_IsConstant(erg->n,nacRing)) && nacIsOne(pGetCoeff(erg->n)))
     1477        erg->n = naRemainder(erg->n, naMinimalPoly);
     1478      if ((p_IsConstant(erg->n,nacRing)) && ntcIsOne(pGetCoeff(erg->n)))
    23311479        p_Delete(&(erg->n),nacRing);
    23321480    }
     
    23371485nMapFunc naSetMap(const ring src, const ring dst)
    23381486{
    2339   naMapRing=src;
     1487  ntMapRing=src;
    23401488  if (rField_is_Q_a(dst)) /* -> Q(a) */
    23411489  {
     
    23511499    {
    23521500      int i;
    2353       naParsToCopy=0;
     1501      ntParsToCopy=0;
    23541502      for(i=0;i<rPar(src);i++)
    23551503      {
     
    23571505        ||(strcmp(src->parameter[i],dst->parameter[i])!=0))
    23581506           return NULL;
    2359         naParsToCopy++;
     1507        ntParsToCopy++;
    23601508      }
    2361       nacMap=nacCopy;
    2362       if ((naParsToCopy==rPar(dst))&&(naParsToCopy==rPar(src)))
     1509      ntcMap=ntcCopy;
     1510      if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src)))
    23631511        return naCopy;    /* Q(a) -> Q(a) */
    23641512      return naMapQaQb;   /* Q(a..) -> Q(a..) */
     
    23871535      if (rChar(src)==rChar(dst))
    23881536      {
    2389         nacMap=nacCopy;
     1537        ntcMap=ntcCopy;
    23901538      }
    23911539      else
    23921540      {
    2393         nacMap = npMapP;
     1541        ntcMap = npMapP;
    23941542      }
    23951543      int i;
    2396       naParsToCopy=0;
     1544      ntParsToCopy=0;
    23971545      for(i=0;i<rPar(src);i++)
    23981546      {
     
    24001548        ||(strcmp(src->parameter[i],dst->parameter[i])!=0))
    24011549           return NULL;
    2402         naParsToCopy++;
     1550        ntParsToCopy++;
    24031551      }
    2404       if ((naParsToCopy==rPar(dst))&&(naParsToCopy==rPar(src))
    2405       && (nacMap==nacCopy))
     1552      if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src))
     1553      && (ntcMap==ntcCopy))
    24061554        return naCopy;    /* Z/p(a) -> Z/p(a) */
    24071555      return naMapQaQb;   /* Z/p(a),Z/p'(a) -> Z/p(b)*/
     
    24091557  }
    24101558  return NULL;      /* default */
    2411 }
    2412 
    2413 /*2
    2414 * convert a napoly number into a poly
    2415 */
    2416 poly naPermNumber(number z, int * par_perm, int P, ring oldRing)
    2417 {
    2418   if (z==NULL) return NULL;
    2419   poly res=NULL;
    2420   poly p;
    2421   napoly za=((lnumber)z)->z;
    2422   napoly zb=((lnumber)z)->n;
    2423   nMapFunc nMap=naSetMap(oldRing,currRing);
    2424   if (currRing->parameter!=NULL)
    2425     nMap=currRing->algring->cf->cfSetMap(oldRing->algring, nacRing);
    2426   else
    2427     nMap=currRing->cf->cfSetMap(oldRing->algring, currRing);
    2428   if (nMap==NULL) return NULL; /* emergency exit only */
    2429   do
    2430   {
    2431     p = pInit();
    2432     pNext(p)=NULL;
    2433     nNew(&pGetCoeff(p));
    2434     int i;
    2435     for(i=pVariables;i;i--)
    2436        pSetExp(p,i, 0);
    2437     if (rRing_has_Comp(currRing)) pSetComp(p, 0);
    2438     napoly pa=NULL;
    2439     lnumber pan;
    2440     if (currRing->parameter!=NULL)
    2441     {
    2442       assume(oldRing->algring!=NULL);
    2443       pGetCoeff(p)=(number)omAlloc0Bin(rnumber_bin);
    2444       pan=(lnumber)pGetCoeff(p);
    2445       pan->s=2;
    2446       pan->z=napInitz(nMap(pGetCoeff(za)));
    2447       pa=pan->z;
    2448     }
    2449     else
    2450     {
    2451       pGetCoeff(p)=nMap(pGetCoeff(za));
    2452     }
    2453     for(i=0;i<P;i++)
    2454     {
    2455       if(napGetExpFrom(za,i+1,oldRing)!=0)
    2456       {
    2457         if(par_perm==NULL)
    2458         {
    2459           if ((rPar(currRing)>=i) && (pa!=NULL))
    2460           {
    2461             napSetExp(pa,i+1,napGetExpFrom(za,i+1,oldRing));
    2462             p_Setm(pa,nacRing);
    2463           }
    2464           else
    2465           {
    2466             pDelete(&p);
    2467             break;
    2468           }
    2469         }
    2470         else if(par_perm[i]>0)
    2471           pSetExp(p,par_perm[i],napGetExpFrom(za,i+1,oldRing));
    2472         else if((par_perm[i]<0)&&(pa!=NULL))
    2473         {
    2474           napSetExp(pa,-par_perm[i], napGetExpFrom(za,i+1,oldRing));
    2475           p_Setm(pa,nacRing);
    2476         }
    2477         else
    2478         {
    2479           pDelete(&p);
    2480           break;
    2481         }
    2482       }
    2483     }
    2484     if (p!=NULL)
    2485     {
    2486       pSetm(p);
    2487       if (zb!=NULL)
    2488       {
    2489         if  (currRing->P>0)
    2490         {
    2491           pan->n=napPerm(zb,par_perm,oldRing,nMap);
    2492           if(pan->n==NULL) /* error in mapping or mapping to variable */
    2493             pDelete(&p);
    2494         }
    2495         else
    2496           pDelete(&p);
    2497       }
    2498       pTest(p);
    2499       res=pAdd(res,p);
    2500     }
    2501     pIter(za);
    2502   }
    2503   while (za!=NULL);
    2504   pTest(res);
    2505   return res;
    2506 }
    2507 
    2508 number   naGetDenom(number &n, const ring r)
    2509 {
    2510   lnumber x=(lnumber)n;
    2511   if (x->n!=NULL)
    2512   {
    2513     lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin);
    2514     rr->z=p_Copy(x->n,r->algring);
    2515     rr->s = 2;
    2516     return (number)rr;
    2517   }
    2518   return n_Init(1,r);
    2519 }
    2520 
    2521 number   naGetNumerator(number &n, const ring r)
    2522 {
    2523   lnumber x=(lnumber)n;
    2524   lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin);
    2525   rr->z=p_Copy(x->z,r->algring);
    2526   rr->s = 2;
    2527   return (number)rr;
    25281559}
    25291560
     
    25451576  while(p!=NULL)
    25461577  {
    2547     if ((naIsChar0 && nlIsZero(pGetCoeff(p)))
    2548     || ((!naIsChar0) && npIsZero(pGetCoeff(p))))
     1578    if ((ntIsChar0 && nlIsZero(pGetCoeff(p)))
     1579    || ((!ntIsChar0) && npIsZero(pGetCoeff(p))))
    25491580    {
    25501581      Print("coeff 0 in %s:%d\n",f,l);
     
    25581589      return FALSE;
    25591590    }
    2560     //if (naIsChar0 && (((int)p->ko &3) == 0) && (p->ko->s==0) && (x->s==2))
     1591    //if (ntIsChar0 && (((int)p->ko &3) == 0) && (p->ko->s==0) && (x->s==2))
    25611592    //{
    25621593    //  Print("normalized with non-normal coeffs in %s:%d\n",f,l);
    25631594    //  return FALSE;
    25641595    //}
    2565     if (naIsChar0 && !(nlDBTest(pGetCoeff(p),f,l)))
     1596    if (ntIsChar0 && !(nlDBTest(pGetCoeff(p),f,l)))
    25661597      return FALSE;
    25671598    pIter(p);
     
    25701601  while(p!=NULL)
    25711602  {
    2572     if (naIsChar0 && !(nlDBTest(pGetCoeff(p),f,l)))
     1603    if (ntIsChar0 && !(nlDBTest(pGetCoeff(p),f,l)))
    25731604      return FALSE;
    25741605    pIter(p);
  • kernel/longalg.h

    ra33266 r661c214  
    1111#include <kernel/longrat.h>
    1212#include <kernel/polys-impl.h>
     13#include <kernel/longtrans.h>
    1314
    14 typedef polyrec *   napoly;
     15struct snaIdeal
     16{
     17  int anz;
     18  napoly *liste;
     19};
     20typedef struct snaIdeal * naIdeal;
     21extern omBin snaIdeal_bin;
     22extern naIdeal naI;
     23extern napoly naMinimalPoly;
    1524
    16 struct slnumber;
    17 typedef struct slnumber * lnumber;
    18 
    19 struct slnumber
    20 {
    21   napoly z;
    22   napoly n;
    23   BOOLEAN s;
    24 };
    25 
    26 extern napoly naMinimalPoly;
    27 extern ring nacRing;
    28 extern int naNumbOfPar;
    29 
    30 void naSetChar(int p, ring r);
     25void    naSetChar(int p, ring r);
    3126void    naDelete (number *p, const ring r);
    3227number  naInit(int i, const ring r);                /* z := i */
     
    6459BOOLEAN naDBTest(number a, const char *f,const int l);
    6560#endif
     61napoly naRemainder(napoly f, const napoly  g);
     62void    naSetIdeal(ideal I);
     63extern number (*naMap)(number from);
     64void naCoefNormalize(number pp);
    6665
    67 void    naSetIdeal(ideal I);
    68 
    69 // external access to the interna
    70 poly naPermNumber(number z, int * par_perm, int P, ring r);
    71 #define napAddExp(p,i,e)       (p_AddExp(p,i,e,currRing->algring))
    72 #define napLength(p)           pLength(p)
    73 #define napNeg(p)              (p_Neg(p,currRing->algring))
    74 #define napVariables           naNumbOfPar
    75 #define napGetCoeff(p)         pGetCoeff(p)
    76 #define napGetExpFrom(p,i,r)   (p_GetExp(p,i,r->algring))
    77 #define napSetExp(p,i,e)       (p_SetExp(p,i,e,currRing->algring))
    78 #define napNew()               (p_Init(currRing->algring))
    79 #define napAdd(p1,p2)          (p_Add_q(p1,p2,currRing->algring))
    80 #define napSetm(p)             p_Setm(p,currRing->algring)
    81 // #define nanumber               lnumber
    82 napoly napRemainder(napoly f, const napoly  g);
    83 number naGetDenom(number &n, const ring r);
    84 number naGetNumerator(number &n, const ring r);
    8566#endif
    8667
  • kernel/longtrans.cc

    ra33266 r661c214  
    2626#include <kernel/clapconv.h>
    2727#endif
     28#include <kernel/longtrans.h>
    2829#include <kernel/longalg.h>
    29 #include <kernel/longtrans.h>
    30 
    31 struct sntIdeal
    32 {
    33   int anz;
    34   napoly *liste;
    35 };
    36 typedef struct sntIdeal * ntIdeal;
    37 
    38 ntIdeal ntI=NULL;
    39 
    40 omBin sntIdeal_bin = omGetSpecBin(sizeof(sntIdeal));
    41 
    42 #define ntParNames (currRing->parameter)
    43 static int ntIsChar0;
    44 static ring ntMapRing;
     30
     31ring nacRing;
     32int ntIsChar0;
     33ring ntMapRing;
     34int ntParsToCopy;
     35int ntNumbOfPar;
     36
     37number (*ntMap)(number from);
     38numberfunc ntcMult, ntcSub, ntcAdd, ntcDiv, ntcIntDiv;
     39number   (*ntcGcd)(number a, number b, const ring r);
     40number   (*ntcLcm)(number a, number b, const ring r);
     41number   (*ntcInit)(int i, const ring r);
     42int      (*ntcInt)(number &n, const ring r);
     43void     (*ntcDelete)(number *a, const ring r);
     44void     (*ntcNormalize)(number &a);
     45number   (*ntcNeg)(number a);
     46number   (*ntcCopy)(number a);
     47number   (*ntcInvers)(number a);
     48BOOLEAN  (*ntcIsZero)(number a);
     49BOOLEAN  (*ntcIsOne)(number a);
     50BOOLEAN  (*ntcIsMOne)(number a);
     51BOOLEAN  (*ntcGreaterZero)(number a);
     52const char   * (*ntcRead) (const char *s, number *a);
     53number (*ntcMap)(number);
    4554
    4655#ifdef LDEBUG
     
    5160#endif
    5261
    53 number (*ntMap)(number from);
    54 /* procedure variables */
    55 static numberfunc
    56                 ntcMult, ntcSub, ntcAdd, ntcDiv, ntcIntDiv;
    57 static number   (*ntcGcd)(number a, number b, const ring r);
    58 static number   (*ntcLcm)(number a, number b, const ring r);
    59 static number   (*ntcInit)(int i, const ring r);
    60 static int      (*ntcInt)(number &n, const ring r);
    61 static void     (*ntcDelete)(number *a, const ring r);
    62 #undef n_Delete
    63 #define n_Delete(A,R) ntcDelete(A,R)
    64        void     (*ntcNormalize)(number &a);
    65 static number   (*ntcNeg)(number a);
    66        number   (*ntcCopy)(number a);
    67 static number   (*ntcInvers)(number a);
    68        BOOLEAN  (*ntcIsZero)(number a);
    69 static BOOLEAN  (*ntcIsOne)(number a);
    70 static BOOLEAN  (*ntcIsMOne)(number a);
    71 static BOOLEAN  (*ntcGreaterZero)(number a);
    72 static const char   * (*ntcRead) (const char *s, number *a);
    73 static napoly ntpRedp(napoly q);
    74 static napoly ntpTailred(napoly q);
    75 static BOOLEAN ntpDivPoly(napoly p, napoly q);
    76 static int ntpExpi(int i, napoly a, napoly b);
    77        ring ntcRing;
    78 
    79 void ntCoefNormalize(number pp);
    80 
    81 #define ntpCopy(p)       p_Copy(p,ntcRing)
    82 
    8362static number ntdGcd( number a, number b, const ring r) { return ntcInit(1,r); }
    8463/*2
     
    8766void ntSetChar(int i, ring r)
    8867{
    89   if (ntI!=NULL)
     68  if (naI!=NULL)
    9069  {
    9170    int j;
    92     for (j=ntI->anz-1; j>=0; j--)
    93        p_Delete (&ntI->liste[j],ntcRing);
    94     omFreeSize((ADDRESS)ntI->liste,ntI->anz*sizeof(napoly));
    95     omFreeBin((ADDRESS)ntI, sntIdeal_bin);
    96     ntI=NULL;
     71    for (j=naI->anz-1; j>=0; j--)
     72       p_Delete (&naI->liste[j],nacRing);
     73    omFreeSize((ADDRESS)naI->liste,naI->anz*sizeof(napoly));
     74    omFreeBin((ADDRESS)naI, snaIdeal_bin);
     75    naI=NULL;
    9776  }
    9877  ntMap = ntCopy;
     78 
     79  naMinimalPoly = NULL;
    9980
    10081  if (r->minideal!=NULL)
    10182  {
    102     ntI=(ntIdeal)omAllocBin(sntIdeal_bin);
    103     ntI->anz=IDELEMS(r->minideal);
    104     ntI->liste=(napoly*)omAlloc(ntI->anz*sizeof(napoly));
     83    naI=(naIdeal)omAllocBin(snaIdeal_bin);
     84    naI->anz=IDELEMS(r->minideal);
     85    naI->liste=(napoly*)omAlloc(naI->anz*sizeof(napoly));
    10586    int j;
    106     for (j=ntI->anz-1; j>=0; j--)
     87    for (j=naI->anz-1; j>=0; j--)
    10788    {
    10889      lnumber a = (lnumber)pGetCoeff(r->minideal->m[j]);
    109       ntI->liste[j]=ntpCopy(a->z);
    110     }
    111   }
    112 
    113   naNumbOfPar=rPar(r);
     90      naI->liste[j]=napCopy(a->z);
     91    }
     92  }
     93
     94  ntNumbOfPar=rPar(r);
    11495  if (i == 1)
    11596  {
     
    127108  }
    128109#endif
    129   ntcRing        = r->algring;
    130   ntcInit        = ntcRing->cf->cfInit;
    131   ntcInt         = ntcRing->cf->n_Int;
    132   ntcCopy        = ntcRing->cf->nCopy;
    133   ntcAdd         = ntcRing->cf->nAdd;
    134   ntcSub         = ntcRing->cf->nSub;
    135   ntcNormalize   = ntcRing->cf->nNormalize;
    136   ntcNeg         = ntcRing->cf->nNeg;
    137   ntcIsZero      = ntcRing->cf->nIsZero;
    138   ntcRead        = ntcRing->cf->nRead;
    139   ntcGreaterZero = ntcRing->cf->nGreaterZero;
    140   ntcIsOne       = ntcRing->cf->nIsOne;
    141   ntcIsMOne      = ntcRing->cf->nIsMOne;
    142   ntcGcd         = ntcRing->cf->nGcd;
    143   ntcLcm         = ntcRing->cf->nLcm;
    144   ntcMult        = ntcRing->cf->nMult;
    145   ntcDiv         = ntcRing->cf->nDiv;
    146   ntcIntDiv      = ntcRing->cf->nIntDiv;
    147   ntcInvers      = ntcRing->cf->nInvers;
    148   ntcDelete      = ntcRing->cf->cfDelete;
    149 }
    150 
    151 /*============= procedure for polynomials: ntpXXXX =======================*/
    152 
    153 
     110  nacRing        = r->algring;
     111  ntcInit        = nacRing->cf->cfInit;
     112  ntcInt         = nacRing->cf->n_Int;
     113  ntcCopy        = nacRing->cf->nCopy;
     114  ntcAdd         = nacRing->cf->nAdd;
     115  ntcSub         = nacRing->cf->nSub;
     116  ntcNormalize   = nacRing->cf->nNormalize;
     117  ntcNeg         = nacRing->cf->nNeg;
     118  ntcIsZero      = nacRing->cf->nIsZero;
     119  ntcRead        = nacRing->cf->nRead;
     120  ntcGreaterZero = nacRing->cf->nGreaterZero;
     121  ntcIsOne       = nacRing->cf->nIsOne;
     122  ntcIsMOne      = nacRing->cf->nIsMOne;
     123  ntcGcd         = nacRing->cf->nGcd;
     124  ntcLcm         = nacRing->cf->nLcm;
     125  ntcMult        = nacRing->cf->nMult;
     126  ntcDiv         = nacRing->cf->nDiv;
     127  ntcIntDiv      = nacRing->cf->nIntDiv;
     128  ntcInvers      = nacRing->cf->nInvers;
     129  ntcDelete      = nacRing->cf->cfDelete;
     130}
     131
     132/*============= procedure for polynomials: napXXXX =======================*/
    154133
    155134#ifdef LDEBUG
    156 static void ntpTest(napoly p)
     135void napTest(napoly p)
    157136{
    158137  while (p != NULL)
     
    164143}
    165144#else
    166 #define ntpTest(p) ((void) 0)
     145#define napTest(p) ((void) 0)
    167146#endif
    168147
    169 #define ntpSetCoeff(p,n) {n_Delete(&pGetCoeff(p),ntcRing);pGetCoeff(p)=n;}
    170 #define ntpComp(p,q)     p_LmCmp((poly)p,(poly)q, ntcRing)
    171 #define ntpMultT(A,E)    A=(napoly)p_Mult_mm((poly)A,(poly)E,ntcRing)
    172 #define ntpDeg(p)        (int)p_Totaldegree(p, ntcRing)
    173 
    174148/*3
    175 * creates an napoly
    176 */
    177 napoly ntpInitz(number z)
    178 {
    179   napoly a = (napoly)p_Init(ntcRing);
     149* creates  an napoly
     150*/
     151napoly napInitz(number z)
     152{
     153  napoly a = (napoly)p_Init(nacRing);
    180154  pGetCoeff(a) = z;
    181155  return a;
     
    185159* copy a napoly. poly
    186160*/
    187 static napoly ntpCopyNeg(napoly p)
    188 {
    189   napoly r=ntpCopy(p);
    190   r=(napoly)p_Neg((poly)r, ntcRing);
     161napoly napCopyNeg(napoly p)
     162{
     163  napoly r=napCopy(p);
     164  r=(napoly)p_Neg((poly)r, nacRing);
    191165  return r;
    192166}
     
    195169* returns ph * z
    196170*/
    197 static void ntpMultN(napoly p, number z)
     171void napMultN(napoly p, number z)
    198172{
    199173  number t;
     
    203177    t = ntcMult(pGetCoeff(p), z);
    204178    ntcNormalize(t);
    205     n_Delete(&pGetCoeff(p),ntcRing);
     179    n_Delete(&pGetCoeff(p),nacRing);
    206180    pGetCoeff(p) = t;
    207181    pIter(p);
     
    210184
    211185/*3
    212 *  division with rest; f = g*q + r,  destroy f
    213 */
    214 static void ntpDivMod(napoly f, napoly  g, napoly *q, napoly *r)
    215 {
    216   napoly a, h, b, qq;
    217 
    218   qq = (napoly)p_Init(ntcRing);
    219   pNext(qq) = b = NULL;
    220   p_Normalize(g,ntcRing);
    221   p_Normalize(f,ntcRing);
     186*  division with remainder: f = g*q + r,
     187*  returns r and destroys f
     188*/
     189napoly naRemainder(napoly f, const napoly g)
     190{
     191  napoly a, h, qq;
     192
     193  qq = (napoly)p_Init(nacRing);
     194  pNext(qq) = NULL;
     195  p_Normalize(g, nacRing);
     196  p_Normalize(f, nacRing);
    222197  a = f;
    223198  do
    224199  {
    225     napSetExp(qq,1, p_GetExp(a,1,ntcRing) - p_GetExp(g,1,ntcRing));
    226     p_Setm(qq,ntcRing);
     200    napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing));
     201    napSetm(qq);
     202    pGetCoeff(qq) = ntcDiv(pGetCoeff(a), pGetCoeff(g));
     203    pGetCoeff(qq) = ntcNeg(pGetCoeff(qq));
     204    ntcNormalize(pGetCoeff(qq));
     205    h = napCopy(g);
     206    napMultT(h, qq);
     207    p_Normalize(h,nacRing);
     208    n_Delete(&pGetCoeff(qq),nacRing);
     209    a = napAdd(a, h);
     210  }
     211  while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing)));
     212  omFreeBinAddr(qq);
     213  return a;
     214}
     215
     216/*3
     217*  division with rest; f = g*q + r,  destroy f
     218*/
     219void napDivMod(napoly f, napoly  g, napoly *q, napoly *r)
     220{
     221  napoly a, h, b, qq;
     222
     223  qq = (napoly)p_Init(nacRing);
     224  pNext(qq) = b = NULL;
     225  p_Normalize(g,nacRing);
     226  p_Normalize(f,nacRing);
     227  a = f;
     228  do
     229  {
     230    napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing));
     231    p_Setm(qq,nacRing);
    227232    pGetCoeff(qq) = ntcDiv(pGetCoeff(a), pGetCoeff(g));
    228233    ntcNormalize(pGetCoeff(qq));
    229     b = napAdd(b, ntpCopy(qq));
     234    b = napAdd(b, napCopy(qq));
    230235    pGetCoeff(qq) = ntcNeg(pGetCoeff(qq));
    231     h = ntpCopy(g);
    232     ntpMultT(h, qq);
    233     p_Normalize(h,ntcRing);
    234     n_Delete(&pGetCoeff(qq),ntcRing);
     236    h = napCopy(g);
     237    napMultT(h, qq);
     238    p_Normalize(h,nacRing);
     239    n_Delete(&pGetCoeff(qq),nacRing);
    235240    a = napAdd(a, h);
    236241  }
    237   while ((a!=NULL) && (p_GetExp(a,1,ntcRing) >= p_GetExp(g,1,ntcRing)));
     242  while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing)));
    238243  omFreeBinAddr(qq);
    239244  *q = b;
     
    244249*  returns z with z*x mod c = 1
    245250*/
    246 static napoly ntpInvers(napoly x, const napoly c)
     251napoly napInvers(napoly x, const napoly c)
    247252{
    248253  napoly y, r, qa, qn, q;
    249254  number t, h;
    250255
    251   if (p_GetExp(x,1,ntcRing) >= p_GetExp(c,1,ntcRing))
    252     x = napRemainder(x, c);
     256  if (p_GetExp(x,1,nacRing) >= p_GetExp(c,1,nacRing))
     257    x = naRemainder(x, c);
    253258  if (x==NULL)
    254259  {
    255260    goto zero_divisor;
    256261  }
    257   if (p_GetExp(x,1,ntcRing)==0)
     262  if (p_GetExp(x,1,nacRing)==0)
    258263  {
    259264    if (!ntcIsOne(pGetCoeff(x)))
     
    262267      t = ntcInvers(pGetCoeff(x));
    263268      ntcNormalize(t);
    264       n_Delete(&pGetCoeff(x),ntcRing);
     269      n_Delete(&pGetCoeff(x),nacRing);
    265270      pGetCoeff(x) = t;
    266271    }
    267272    return x;
    268273  }
    269   y = ntpCopy(c);
    270   ntpDivMod(y, x, &qa, &r);
     274  y = napCopy(c);
     275  napDivMod(y, x, &qa, &r);
    271276  if (r==NULL)
    272277  {
    273278    goto zero_divisor;
    274279  }
    275   if (p_GetExp(r,1,ntcRing)==0)
     280  if (p_GetExp(r,1,nacRing)==0)
    276281  {
    277282    ntcNormalize(pGetCoeff(r));
     
    279284    ntcNormalize(t);
    280285    t = ntcNeg(t);
    281     ntpMultN(qa, t);
    282     n_Delete(&t,ntcRing);
    283     p_Normalize(qa,ntcRing);
    284     p_Delete(&x,ntcRing);
    285     p_Delete(&r,ntcRing);
     286    napMultN(qa, t);
     287    n_Delete(&t,nacRing);
     288    p_Normalize(qa,nacRing);
     289    p_Delete(&x,nacRing);
     290    p_Delete(&r,nacRing);
    286291    return qa;
    287292  }
    288293  y = x;
    289294  x = r;
    290   ntpDivMod(y, x, &q, &r);
     295  napDivMod(y, x, &q, &r);
    291296  if (r==NULL)
    292297  {
    293298    goto zero_divisor;
    294299  }
    295   if (p_GetExp(r,1,ntcRing)==0)
    296   {
    297     q = p_Mult_q(q, qa,ntcRing);
    298     q = napAdd(q, p_ISet(1,ntcRing));
     300  if (p_GetExp(r,1,nacRing)==0)
     301  {
     302    q = p_Mult_q(q, qa,nacRing);
     303    q = napAdd(q, p_ISet(1,nacRing));
    299304    ntcNormalize(pGetCoeff(r));
    300305    t = ntcInvers(pGetCoeff(r));
    301     ntpMultN(q, t);
    302     p_Normalize(q,ntcRing);
    303     n_Delete(&t,ntcRing);
    304     p_Delete(&x,ntcRing);
    305     p_Delete(&r,ntcRing);
    306     if (p_GetExp(q,1,ntcRing) >= p_GetExp(c,1,ntcRing))
    307       q = napRemainder(q, c);
     306    napMultN(q, t);
     307    p_Normalize(q,nacRing);
     308    n_Delete(&t,nacRing);
     309    p_Delete(&x,nacRing);
     310    p_Delete(&r,nacRing);
     311    if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing))
     312      q = naRemainder(q, c);
    308313    return q;
    309314  }
    310   q = p_Mult_q(q, ntpCopy(qa),ntcRing);
    311   q = napAdd(q, p_ISet(1,ntcRing));
     315  q = p_Mult_q(q, napCopy(qa),nacRing);
     316  q = napAdd(q, p_ISet(1,nacRing));
    312317  qa = napNeg(qa);
    313318  loop
     
    315320    y = x;
    316321    x = r;
    317     ntpDivMod(y, x, &qn, &r);
     322    napDivMod(y, x, &qn, &r);
    318323    if (r==NULL)
    319324    {
    320325      break;
    321326    }
    322     if (p_GetExp(r,1,ntcRing)==0)
    323     {
    324       q = p_Mult_q(q, qn,ntcRing);
     327    if (p_GetExp(r,1,nacRing)==0)
     328    {
     329      q = p_Mult_q(q, qn,nacRing);
    325330      q = napNeg(q);
    326331      q = napAdd(q, qa);
     
    328333      t = ntcInvers(pGetCoeff(r));
    329334      //ntcNormalize(t);
    330       ntpMultN(q, t);
    331       p_Normalize(q,ntcRing);
    332       n_Delete(&t,ntcRing);
    333       p_Delete(&x,ntcRing);
    334       p_Delete(&r,ntcRing);
    335       if (p_GetExp(q,1,ntcRing) >= p_GetExp(c,1,ntcRing))
    336         q = napRemainder(q, c);
     335      napMultN(q, t);
     336      p_Normalize(q,nacRing);
     337      n_Delete(&t,nacRing);
     338      p_Delete(&x,nacRing);
     339      p_Delete(&r,nacRing);
     340      if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing))
     341        q = naRemainder(q, c);
    337342      return q;
    338343    }
    339344    y = q;
    340     q = p_Mult_q(ntpCopy(q), qn, ntcRing);
     345    q = p_Mult_q(napCopy(q), qn, nacRing);
    341346    q = napNeg(q);
    342347    q = napAdd(q, qa);
     
    352357* the max degree of an napoly poly (used for test of "simple" et al.)
    353358*/
    354 static int  ntpMaxDeg(napoly p)
     359int  napMaxDeg(napoly p)
    355360{
    356361  int  d = 0;
    357362  while(p!=NULL)
    358363  {
    359     d=si_max(d,ntpDeg(p));
     364    d=si_max(d,napDeg(p));
    360365    pIter(p);
    361366  }
     
    366371* the max degree of an napoly poly (used for test of "simple" et al.)
    367372*/
    368 static int  ntpMaxDegLen(napoly p, int &l)
     373int  napMaxDegLen(napoly p, int &l)
    369374{
    370375  int  d = 0;
     
    372377  while(p!=NULL)
    373378  {
    374     d=si_max(d,ntpDeg(p));
     379    d=si_max(d,napDeg(p));
    375380    pIter(p);
    376381    ll++;
     
    384389*writes a polynomial number
    385390*/
    386 void ntpWrite(napoly p,const BOOLEAN has_denom, const ring r)
    387 {
    388   ring ntcring=r->algring;
     391void napWrite(napoly p,const BOOLEAN has_denom, const ring r)
     392{
     393  ring nacring=r->algring;
    389394  if (p==NULL)
    390395    StringAppendS("0");
    391   else if (p_LmIsConstant(p,ntcring))
     396  else if (p_LmIsConstant(p,nacring))
    392397  {
    393398    BOOLEAN kl=FALSE;
    394399    if (has_denom)
    395400    {
    396       number den=ntcring->cf->cfGetDenom(pGetCoeff(p),ntcring );
    397       kl=!n_IsOne(den,ntcring);
    398       n_Delete(&den, ntcring);
     401      number den=nacring->cf->cfGetDenom(pGetCoeff(p),nacring );
     402      kl=!n_IsOne(den,nacring);
     403      n_Delete(&den, nacring);
    399404    }
    400405    if (kl) StringAppendS("(");
    401406    //StringAppendS("-1");
    402     n_Write(pGetCoeff(p),ntcring);
     407    n_Write(pGetCoeff(p),nacring);
    403408    if (kl) StringAppendS(")");
    404409  }
     
    409414    {
    410415      BOOLEAN wroteCoeff=FALSE;
    411       if ((p_LmIsConstant(p,ntcring))
    412       || ((!n_IsOne(pGetCoeff(p),ntcring))
    413         && (!n_IsMOne(pGetCoeff(p),ntcring))))
    414       {
    415         n_Write(pGetCoeff(p),ntcring);
     416      if ((p_LmIsConstant(p,nacring))
     417      || ((!n_IsOne(pGetCoeff(p),nacring))
     418        && (!n_IsMOne(pGetCoeff(p),nacring))))
     419      {
     420        n_Write(pGetCoeff(p),nacring);
    416421        wroteCoeff=(r->ShortOut==0);
    417422      }
    418       else if (n_IsMOne(pGetCoeff(p),ntcring))
     423      else if (n_IsMOne(pGetCoeff(p),nacring))
    419424      {
    420425        StringAppendS("-");
     
    423428      for (i = 0; i < r->P; i++)
    424429      {
    425         int e=p_GetExp(p,i+1,ntcring);
     430        int e=p_GetExp(p,i+1,nacring);
    426431        if (e > 0)
    427432        {
     
    442447      if (p==NULL)
    443448        break;
    444       if (n_GreaterZero(pGetCoeff(p),ntcring))
     449      if (n_GreaterZero(pGetCoeff(p),nacring))
    445450        StringAppendS("+");
    446451    }
     
    450455
    451456
    452 static const char *ntpHandleMons(const char *s, int i, napoly ex)
     457const char *napHandleMons(const char *s, int i, napoly ex)
    453458{
    454459  int  j;
    455   if (strncmp(s,ntParNames[i],strlen(ntParNames[i]))==0)
    456   {
    457     s+=strlen(ntParNames[i]);
     460  if (strncmp(s,naParNames[i],strlen(naParNames[i]))==0)
     461  {
     462    s+=strlen(naParNames[i]);
    458463    if ((*s >= '0') && (*s <= '9'))
    459464    {
     
    466471  return s;
    467472}
    468 static const char *ntpHandlePars(const char *s, int i, napoly ex)
     473const char *napHandlePars(const char *s, int i, napoly ex)
    469474{
    470475  int  j;
    471   if (strcmp(s,ntParNames[i])==0)
    472   {
    473     s+=strlen(ntParNames[i]);
     476  if (strcmp(s,naParNames[i])==0)
     477  {
     478    s+=strlen(naParNames[i]);
    474479    napSetExp(ex,i+1,1);
    475480  }
     
    478483
    479484/*3  reads a monomial  */
    480 static const char  *ntpRead(const char *s, napoly *b)
     485const char  *napRead(const char *s, napoly *b)
    481486{
    482487  napoly a;
    483488  int  i;
    484   a = (napoly)p_Init(ntcRing);
     489  a = (napoly)p_Init(nacRing);
    485490  if ((*s >= '0') && (*s <= '9'))
    486491  {
     
    488493    if (ntcIsZero(pGetCoeff(a)))
    489494    {
    490       p_LmDelete(&a,ntcRing);
     495      p_LmDelete(&a,nacRing);
    491496      *b = NULL;
    492497      return s;
     
    494499  }
    495500  else
    496     pGetCoeff(a) = ntcInit(1,ntcRing);
     501    pGetCoeff(a) = ntcInit(1,nacRing);
    497502  i = 0;
    498503  const char  *olds=s;
    499504  loop
    500505  {
    501     s = ntpHandlePars(s, i, a);
     506    s = napHandlePars(s, i, a);
    502507    if (olds == s)
    503508      i++;
     
    507512      return s;
    508513    }
    509     if (i >= naNumbOfPar)
     514    if (i >= ntNumbOfPar)
    510515      break;
    511516  }
     
    514519  {
    515520    olds = s;
    516     s = ntpHandleMons(s, i, a);
     521    s = napHandleMons(s, i, a);
    517522    if (olds == s)
    518523      i++;
    519524    else
    520525      i = 0;
    521     if ((*s == '\0') || (i >= naNumbOfPar))
     526    if ((*s == '\0') || (i >= ntNumbOfPar))
    522527      break;
    523528  }
     
    526531}
    527532
    528 static int ntpExp(napoly a, napoly b)
     533int napExp(napoly a, napoly b)
    529534{
    530535  while (pNext(a)!=NULL) pIter(a);
    531   int m = p_GetExp(a,1,ntcRing);
     536  int m = p_GetExp(a,1,nacRing);
    532537  if (m==0) return 0;
    533538  while (pNext(b)!=NULL) pIter(b);
    534   int mm=p_GetExp(b,1,ntcRing);
     539  int mm=p_GetExp(b,1,nacRing);
    535540  if (m > mm) m = mm;
    536541  return m;
     
    541546* used to find it in a fraction
    542547*/
    543 static int ntpExpi(int i, napoly a, napoly b)
     548int napExpi(int i, napoly a, napoly b)
    544549{
    545550  if (a==NULL || b==NULL) return 0;
    546   int m = p_GetExp(a,i+1,ntcRing);
     551  int m = p_GetExp(a,i+1,nacRing);
    547552  if (m==0) return 0;
    548553  while (pNext(a) != NULL)
    549554  {
    550555    pIter(a);
    551     if (m > p_GetExp(a,i+1,ntcRing))
    552     {
    553       m = p_GetExp(a,i+1,ntcRing);
     556    if (m > p_GetExp(a,i+1,nacRing))
     557    {
     558      m = p_GetExp(a,i+1,nacRing);
    554559      if (m==0) return 0;
    555560    }
     
    557562  do
    558563  {
    559     if (m > p_GetExp(b,i+1,ntcRing))
    560     {
    561       m = p_GetExp(b,i+1,ntcRing);
     564    if (m > p_GetExp(b,i+1,nacRing))
     565    {
     566      m = p_GetExp(b,i+1,nacRing);
    562567      if (m==0) return 0;
    563568    }
     
    568573}
    569574
    570 static void ntpContent(napoly ph)
     575void napContent(napoly ph)
    571576{
    572577  number h,d;
     
    580585  do
    581586  {
    582     d=ntcGcd(pGetCoeff(p), h, ntcRing);
     587    d=ntcGcd(pGetCoeff(p), h, nacRing);
    583588    if(ntcIsOne(d))
    584589    {
    585       n_Delete(&h,ntcRing);
    586       n_Delete(&d,ntcRing);
     590      n_Delete(&h,nacRing);
     591      n_Delete(&d,nacRing);
    587592      return;
    588593    }
    589     n_Delete(&h,ntcRing);
     594    n_Delete(&h,nacRing);
    590595    h = d;
    591596    pIter(p);
     
    593598  while (p!=NULL);
    594599  h = ntcInvers(d);
    595   n_Delete(&d,ntcRing);
     600  n_Delete(&d,nacRing);
    596601  p = ph;
    597602  while (p!=NULL)
    598603  {
    599604    d = ntcMult(pGetCoeff(p), h);
    600     n_Delete(&pGetCoeff(p),ntcRing);
     605    n_Delete(&pGetCoeff(p),nacRing);
    601606    pGetCoeff(p) = d;
    602607    pIter(p);
    603608  }
    604   n_Delete(&h,ntcRing);
    605 }
    606 
    607 static void ntpCleardenom(napoly ph)
     609  n_Delete(&h,nacRing);
     610}
     611
     612void napCleardenom(napoly ph)
    608613{
    609614  number d, h;
     
    613618    return;
    614619  p = ph;
    615   h = ntcInit(1,ntcRing);
     620  h = ntcInit(1,nacRing);
    616621  while (p!=NULL)
    617622  {
    618     d = ntcLcm(h, pGetCoeff(p), ntcRing);
    619     n_Delete(&h,ntcRing);
     623    d = ntcLcm(h, pGetCoeff(p), nacRing);
     624    n_Delete(&h,nacRing);
    620625    h = d;
    621626    pIter(p);
     
    627632    {
    628633      d=ntcMult(h, pGetCoeff(p));
    629       n_Delete(&pGetCoeff(p),ntcRing);
     634      n_Delete(&pGetCoeff(p),nacRing);
    630635      ntcNormalize(d);
    631636      pGetCoeff(p) = d;
    632637      pIter(p);
    633638    }
    634     n_Delete(&h,ntcRing);
    635   }
    636   ntpContent(ph);
    637 }
    638 
    639 static napoly ntpGcd0(napoly a, napoly b)
     639    n_Delete(&h,nacRing);
     640  }
     641  napContent(ph);
     642}
     643
     644napoly napGcd0(napoly a, napoly b)
    640645{
    641646  number x, y;
    642647  if (!ntIsChar0)
    643     return p_ISet(1,ntcRing);
     648    return p_ISet(1,nacRing);
    644649  x = ntcCopy(pGetCoeff(a));
    645650  if (ntcIsOne(x))
    646     return ntpInitz(x);
     651    return napInitz(x);
    647652  while (pNext(a)!=NULL)
    648653  {
    649654    pIter(a);
    650     y = ntcGcd(x, pGetCoeff(a), ntcRing);
    651     n_Delete(&x,ntcRing);
     655    y = ntcGcd(x, pGetCoeff(a), nacRing);
     656    n_Delete(&x,nacRing);
    652657    x = y;
    653658    if (ntcIsOne(x))
    654       return ntpInitz(x);
     659      return napInitz(x);
    655660  }
    656661  do
    657662  {
    658     y = ntcGcd(x, pGetCoeff(b), ntcRing);
    659     n_Delete(&x,ntcRing);
     663    y = ntcGcd(x, pGetCoeff(b), nacRing);
     664    n_Delete(&x,nacRing);
    660665    x = y;
    661666    if (ntcIsOne(x))
    662       return ntpInitz(x);
     667      return napInitz(x);
    663668    pIter(b);
    664669  }
    665670  while (b!=NULL);
    666   return ntpInitz(x);
     671  return napInitz(x);
    667672}
    668673
     
    670675* result =gcd(a,b)
    671676*/
    672 static napoly ntpGcd(napoly a, napoly b)
     677napoly napGcd(napoly a, napoly b)
    673678{
    674679  int i;
     
    680685    || ((pNext(b)==NULL)&&(ntcIsZero(pGetCoeff(b)))))
    681686    {
    682       return p_ISet(1,ntcRing);
    683     }
    684     return ntpCopy(b);
     687      return p_ISet(1,nacRing);
     688    }
     689    return napCopy(b);
    685690  }
    686691  else
     
    688693  || ((pNext(b)==NULL)&&(ntcIsZero(pGetCoeff(b)))))
    689694  {
    690     return ntpCopy(a);
     695    return napCopy(a);
     696  }
     697  if (naMinimalPoly != NULL)
     698  {
     699    if (p_GetExp(a,1,nacRing) >= p_GetExp(b,1,nacRing))
     700    {
     701      x = a;
     702      y = b;
     703    }
     704    else
     705    {
     706      x = b;
     707      y = a;
     708    }
     709    if (!ntIsChar0) g = p_ISet(1,nacRing);
     710    else            g = napGcd0(x, y);
     711    if (pNext(y)==NULL)
     712    {
     713      napSetExp(g,1, napExp(x, y));
     714      p_Setm(g,nacRing);
     715      return g;
     716    }
     717    x = napCopy(x);
     718    y = napCopy(y);
     719    loop
     720    {
     721      h = naRemainder(x, y);
     722      if (h==NULL)
     723      {
     724        napCleardenom(y);
     725        if (!ntcIsOne(pGetCoeff(g)))
     726          napMultN(y, pGetCoeff(g));
     727        p_LmDelete(&g,nacRing);
     728        return y;
     729      }
     730      else if (pNext(h)==NULL)
     731        break;
     732      x = y;
     733      y = h;
     734    }
     735    p_Delete(&y,nacRing);
     736    p_LmDelete(&h,nacRing);
     737    napSetExp(g,1, napExp(a, b));
     738    p_Setm(g,nacRing);
     739    return g;
    691740  }
    692741  // Hmm ... this is a memory leak
    693   // x = (napoly)p_Init(ntcRing);
     742  // x = (napoly)p_Init(nacRing);
    694743  g=a;
    695744  h=b;
    696   if (!ntIsChar0) x = p_ISet(1,ntcRing);
    697   else            x = ntpGcd0(g,h);
    698   for (i=(naNumbOfPar-1); i>=0; i--)
    699   {
    700     napSetExp(x,i+1, ntpExpi(i,a,b));
    701     p_Setm(x,ntcRing);
     745  if (!ntIsChar0) x = p_ISet(1,nacRing);
     746  else            x = napGcd0(g,h);
     747  for (i=(ntNumbOfPar-1); i>=0; i--)
     748  {
     749    napSetExp(x,i+1, napExpi(i,a,b));
     750    p_Setm(x,nacRing);
    702751  }
    703752  return x;
     
    705754
    706755
    707 number ntpLcm(napoly a)
    708 {
    709   number h = ntcInit(1,ntcRing);
     756number napLcm(napoly a)
     757{
     758  number h = ntcInit(1,nacRing);
    710759
    711760  if (ntIsChar0)
     
    716765    while (b!=NULL)
    717766    {
    718       d = ntcLcm(h, pGetCoeff(b), ntcRing);
    719       n_Delete(&h,ntcRing);
     767      d = ntcLcm(h, pGetCoeff(b), nacRing);
     768      n_Delete(&h,nacRing);
    720769      h = d;
    721770      pIter(b);
     
    731780* doesn't delete p and q
    732781*/
    733 static BOOLEAN ntpDivPoly (napoly p, napoly q)
    734 {
    735   int j=1;   /* evtl. von ntNumber.. -1 abwaerts zaehlen */
    736 
    737   while (p_GetExp(p,j,ntcRing) <= p_GetExp(q,j,ntcRing))
     782BOOLEAN napDivPoly (napoly p, napoly q)
     783{
     784  int j=1;   /* evtl. von naNumber.. -1 abwaerts zaehlen */
     785
     786  while (p_GetExp(p,j,nacRing) <= p_GetExp(q,j,nacRing))
    738787  {
    739788    j++;
    740     if (j > naNumbOfPar)
     789    if (j > ntNumbOfPar)
    741790      return 1;
    742791  }
     
    747796/*2
    748797* meins  (for reduction in algebraic extension)
    749 * Normalform of poly with ntI
     798* Normalform of poly with naI
    750799* changes q and returns it
    751800*/
    752 napoly ntpRedp (napoly q)
    753 {
    754   napoly h = (napoly)p_Init(ntcRing);
     801napoly napRedp (napoly q)
     802{
     803  napoly h = (napoly)p_Init(nacRing);
    755804  int i=0,j;
    756805
    757806  loop
    758807  {
    759     if (ntpDivPoly (ntI->liste[i], q))
    760     {
    761       /* h = lt(q)/lt(ntI->liste[i])*/
     808    if (napDivPoly (naI->liste[i], q))
     809    {
     810      /* h = lt(q)/lt(naI->liste[i])*/
    762811      pGetCoeff(h) = ntcCopy(pGetCoeff(q));
    763       for (j=naNumbOfPar; j>0; j--)
    764         napSetExp(h,j, p_GetExp(q,j,ntcRing) - p_GetExp(ntI->liste[i],j,ntcRing));
    765       p_Setm(h,ntcRing);
    766       h = p_Mult_q(h, ntpCopy(ntI->liste[i]),ntcRing);
     812      for (j=ntNumbOfPar; j>0; j--)
     813        napSetExp(h,j, p_GetExp(q,j,nacRing) - p_GetExp(naI->liste[i],j,nacRing));
     814      p_Setm(h,nacRing);
     815      h = p_Mult_q(h, napCopy(naI->liste[i]),nacRing);
    767816      h = napNeg (h);
    768       q = napAdd (q, ntpCopy(h));
    769       p_Delete (&pNext(h),ntcRing);
     817      q = napAdd (q, napCopy(h));
     818      p_Delete (&pNext(h),nacRing);
    770819      if (q == NULL)
    771820      {
    772         p_Delete(&h,ntcRing);
     821        p_Delete(&h,nacRing);
    773822        return q;
    774823      }
     
    779828    {
    780829      i++;
    781       if (i >= ntI->anz)
    782       {
    783         p_Delete(&h,ntcRing);
     830      if (i >= naI->anz)
     831      {
     832        p_Delete(&h,nacRing);
    784833        return q;
    785834      }
     
    795844* changes q and returns it
    796845*/
    797 napoly ntpTailred (napoly q)
     846napoly napTailred (napoly q)
    798847{
    799848  napoly h;
     
    802851  while (h != NULL)
    803852  {
    804      h = ntpRedp (h);
     853     h = napRedp (h);
    805854     if (h == NULL)
    806855        return q;
     
    810859}
    811860
    812 
    813 /*================ procedure for rational functions: ntXXXX =================*/
    814 
    815 /*2
    816 *  z:= i
    817 */
    818 number ntInit(int i, const ring r)
    819 {
    820   if (i!=0)
    821   {
    822     number c=n_Init(i,r->algring);
    823     if (!n_IsZero(c,r->algring))
    824     {
    825       poly z=p_Init(r->algring);
    826       pSetCoeff0(z,c);
    827       lnumber l = (lnumber)omAllocBin(rnumber_bin);
    828       l->z = z;
    829       l->s = 2;
    830       l->n = NULL;
    831       return (number)l;
    832     }
    833   }
    834   /*else*/
    835   return NULL;
    836 }
    837 
    838 number  ntPar(int i)
    839 {
    840   lnumber l = (lnumber)omAllocBin(rnumber_bin);
    841   l->s = 2;
    842   l->z = p_ISet(1,ntcRing);
    843   napSetExp(l->z,i,1);
    844   p_Setm(l->z,ntcRing);
    845   l->n = NULL;
    846   return (number)l;
    847 }
    848 
    849 int     ntParDeg(number n)     /* i := deg(n) */
    850 {
    851   lnumber l = (lnumber)n;
    852   if (l==NULL) return -1;
    853   return ntpDeg(l->z);
    854 }
    855 
    856 //int     ntParDeg(number n)     /* i := deg(n) */
    857 //{
    858 //  lnumber l = (lnumber)n;
    859 //  if (l==NULL) return -1;
    860 //  return ntpMaxDeg(l->z)+ntpMaxDeg(l->n);
    861 //}
    862 
    863 int     ntSize(number n)     /* size desc. */
    864 {
    865   lnumber l = (lnumber)n;
    866   if (l==NULL) return -1;
    867   int len_z;
    868   int len_n;
    869   int o=ntpMaxDegLen(l->z,len_z)+ntpMaxDegLen(l->n,len_n);
    870   return (len_z+len_n)+o;
    871 }
    872 
    873 /*2
    874 * convert a number to int (if possible)
    875 */
    876 int ntInt(number &n, const ring r)
    877 {
    878   lnumber l=(lnumber)n;
    879   if ((l!=NULL)&&(l->n==NULL)&&(p_IsConstant(l->z,r->algring)))
    880   {
    881     return ntcInt(pGetCoeff(l->z),r->algring);
    882   }
    883   return 0;
    884 }
    885 
    886 /*2
    887 *  deletes p
    888 */
    889 void ntDelete(number *p, const ring r)
    890 {
    891   if ((*p)!=NULL)
    892   {
    893     lnumber l = (lnumber) * p;
    894     if (l==NULL) return;
    895     p_Delete(&(l->z),r->algring);
    896     p_Delete(&(l->n),r->algring);
    897     omFreeBin((ADDRESS)l,  rnumber_bin);
    898   }
    899   *p = NULL;
    900 }
    901 
    902 /*2
    903 * copy p to erg
    904 */
    905 number ntCopy(number p)
    906 {
     861napoly napMap(napoly p)
     862{
     863  napoly w, a;
     864
    907865  if (p==NULL) return NULL;
    908   ntTest(p);
    909   lnumber erg;
    910   lnumber src = (lnumber)p;
    911   erg = (lnumber)omAlloc0Bin(rnumber_bin);
    912   erg->z = p_Copy(src->z, ntcRing);
    913   erg->n = p_Copy(src->n, ntcRing);
    914   erg->s = src->s;
    915   return (number)erg;
    916 }
    917 number nt_Copy(number p, const ring r)
    918 {
    919   if (p==NULL) return NULL;
    920   lnumber erg;
    921   lnumber src = (lnumber)p;
    922   erg = (lnumber)omAlloc0Bin(rnumber_bin);
    923   erg->z = p_Copy(src->z,r->algring);
    924   erg->n = p_Copy(src->n,r->algring);
    925   erg->s = src->s;
    926   return (number)erg;
    927 }
    928 
    929 /*2
    930 *  addition; lu:= la + lb
    931 */
    932 number ntAdd(number la, number lb)
    933 {
    934   if (la==NULL) return ntCopy(lb);
    935   if (lb==NULL) return ntCopy(la);
    936 
    937   napoly x, y;
    938   lnumber lu;
    939   lnumber a = (lnumber)la;
    940   lnumber b = (lnumber)lb;
    941   #ifdef LDEBUG
    942   omCheckAddrSize(a,sizeof(snumber));
    943   omCheckAddrSize(b,sizeof(snumber));
    944   #endif
    945   if (b->n!=NULL) x = pp_Mult_qq(a->z, b->n,ntcRing);
    946   else            x = ntpCopy(a->z);
    947   if (a->n!=NULL) y = pp_Mult_qq(b->z, a->n,ntcRing);
    948   else            y = ntpCopy(b->z);
    949   napoly res = napAdd(x, y);
    950   if (res==NULL)
    951   {
    952     return (number)NULL;
    953   }
    954   lu = (lnumber)omAllocBin(rnumber_bin);
    955   lu->z=res;
    956   if (a->n!=NULL)
    957   {
    958     if (b->n!=NULL) x = pp_Mult_qq(a->n, b->n,ntcRing);
    959     else            x = ntpCopy(a->n);
    960   }
    961   else
    962   {
    963     if (b->n!=NULL) x = ntpCopy(b->n);
    964     else            x = NULL;
    965   }
    966   //if (x!=NULL)
    967   //{
    968   //  if (p_LmIsConstant(x,ntcRing))
    969   //  {
    970   //    number inv=ntcInvers(pGetCoeff(x));
    971   //    ntpMultN(lu->z,inv);
    972   //    n_Delete(&inv,ntcRing);
    973   //    ntpDelete(&x);
    974   //  }
    975   //}
    976   lu->n = x;
    977   lu->s = FALSE;
    978   if (/*lu->n*/ x!=NULL)
    979   {
    980      number luu=(number)lu;
    981      //if (p_IsConstant(lu->n,ntcRing)) ntCoefNormalize(luu);
    982      //else
    983                 ntNormalize(luu);
    984      lu=(lnumber)luu;
    985   }
    986   //else lu->s=2;
    987   ntTest((number)lu);
    988   return (number)lu;
    989 }
    990 
    991 /*2
    992 *  subtraction; r:= la - lb
    993 */
    994 number ntSub(number la, number lb)
    995 {
    996   lnumber lu;
    997 
    998   if (lb==NULL) return ntCopy(la);
    999   if (la==NULL)
    1000   {
    1001     lu = (lnumber)ntCopy(lb);
    1002     lu->z = napNeg(lu->z);
    1003     return (number)lu;
    1004   }
    1005 
    1006   lnumber a = (lnumber)la;
    1007   lnumber b = (lnumber)lb;
    1008 
    1009   #ifdef LDEBUG
    1010   omCheckAddrSize(a,sizeof(snumber));
    1011   omCheckAddrSize(b,sizeof(snumber));
    1012   #endif
    1013 
    1014   napoly x, y;
    1015   if (b->n!=NULL) x = pp_Mult_qq(a->z, b->n,ntcRing);
    1016   else            x = ntpCopy(a->z);
    1017   if (a->n!=NULL) y = p_Mult_q(ntpCopy(b->z), ntpCopyNeg(a->n),ntcRing);
    1018   else            y = ntpCopyNeg(b->z);
    1019   napoly res = napAdd(x, y);
    1020   if (res==NULL)
    1021   {
    1022     return (number)NULL;
    1023   }
    1024   lu = (lnumber)omAllocBin(rnumber_bin);
    1025   lu->z=res;
    1026   if (a->n!=NULL)
    1027   {
    1028     if (b->n!=NULL) x = pp_Mult_qq(a->n, b->n,ntcRing);
    1029     else            x = ntpCopy(a->n);
    1030   }
    1031   else
    1032   {
    1033     if (b->n!=NULL) x = ntpCopy(b->n);
    1034     else            x = NULL;
    1035   }
    1036   lu->n = x;
    1037   lu->s = FALSE;
    1038   if (/*lu->n*/ x!=NULL)
    1039   {
    1040      number luu=(number)lu;
    1041      //if (p_IsConstant(lu->n,ntcRing)) ntCoefNormalize(luu);
    1042      //else
    1043                          ntNormalize(luu);
    1044      lu=(lnumber)luu;
    1045   }
    1046   //else lu->s=2;
    1047   ntTest((number)lu);
    1048   return (number)lu;
    1049 }
    1050 
    1051 /*2
    1052 *  multiplication; r:= la * lb
    1053 */
    1054 number ntMult(number la, number lb)
    1055 {
    1056   if ((la==NULL) || (lb==NULL))
    1057     return NULL;
    1058 
    1059   lnumber a = (lnumber)la;
    1060   lnumber b = (lnumber)lb;
    1061   lnumber lo;
    1062   napoly x;
    1063 
    1064   #ifdef LDEBUG
    1065   omCheckAddrSize(a,sizeof(snumber));
    1066   omCheckAddrSize(b,sizeof(snumber));
    1067   #endif
    1068   ntTest(la);
    1069   ntTest(lb);
    1070 
    1071   lo = (lnumber)omAllocBin(rnumber_bin);
    1072   lo->z = pp_Mult_qq(a->z, b->z,ntcRing);
    1073 
    1074   if (a->n==NULL)
    1075   {
    1076     if (b->n==NULL)
    1077       x = NULL;
    1078     else
    1079       x = ntpCopy(b->n);
    1080   }
    1081   else
    1082   {
    1083     if (b->n==NULL)
    1084     {
    1085       x = ntpCopy(a->n);
    1086     }
    1087     else
    1088     {
    1089       x = pp_Mult_qq(b->n, a->n, ntcRing);
    1090     }
    1091   }
    1092   if (ntI!=NULL)
    1093   {
    1094     lo->z = ntpRedp (lo->z);
    1095     if (lo->z != NULL)
    1096        lo->z = ntpTailred (lo->z);
    1097     if (x!=NULL)
    1098     {
    1099       x = ntpRedp (x);
    1100       if (x!=NULL)
    1101         x = ntpTailred (x);
    1102     }
    1103   }
    1104   if ((x!=NULL) && (p_LmIsConstant(x,ntcRing)) && ntcIsOne(pGetCoeff(x)))
    1105     p_Delete(&x,ntcRing);
    1106   lo->n = x;
    1107   lo->s = 0;
    1108   if(lo->z==NULL)
    1109   {
    1110     omFreeBin((ADDRESS)lo, rnumber_bin);
    1111     lo=NULL;
    1112   }
    1113   else if (lo->n!=NULL)
    1114   {
    1115     number luu=(number)lo;
    1116     // if (p_IsConstant(lo->n,ntcRing)) ntCoefNormalize(luu);
    1117     // else
    1118                       ntNormalize(luu);
    1119     lo=(lnumber)luu;
    1120   }
    1121   //if (naMinimalPoly==NULL) lo->s=2;
    1122   ntTest((number)lo);
    1123   return (number)lo;
    1124 }
    1125 
    1126 number ntIntDiv(number la, number lb)
    1127 {
    1128   lnumber res;
    1129   lnumber a = (lnumber)la;
    1130   lnumber b = (lnumber)lb;
    1131   if (a==NULL)
    1132   {
    1133     return NULL;
    1134   }
    1135   if (b==NULL)
    1136   {
    1137     WerrorS(nDivBy0);
    1138     return NULL;
    1139   }
    1140   assume(a->z!=NULL && b->z!=NULL);
    1141   assume(a->n==NULL && b->n==NULL);
    1142   res = (lnumber)omAllocBin(rnumber_bin);
    1143   res->z = ntpCopy(a->z);
    1144   res->n = ntpCopy(b->z);
    1145   res->s = 0;
    1146   number nres=(number)res;
    1147   ntNormalize(nres);
    1148 
    1149   //ntpDelete(&res->n);
    1150   ntTest(nres);
    1151   return nres;
    1152 }
    1153 
    1154 /*2
    1155 *  division; lo:= la / lb
    1156 */
    1157 number ntDiv(number la, number lb)
    1158 {
    1159   lnumber lo;
    1160   lnumber a = (lnumber)la;
    1161   lnumber b = (lnumber)lb;
    1162   napoly x;
    1163 
    1164   if (a==NULL)
    1165     return NULL;
    1166 
    1167   if (b==NULL)
    1168   {
    1169     WerrorS(nDivBy0);
    1170     return NULL;
    1171   }
    1172   #ifdef LDEBUG
    1173   omCheckAddrSize(a,sizeof(snumber));
    1174   omCheckAddrSize(b,sizeof(snumber));
    1175   #endif
    1176   lo = (lnumber)omAllocBin(rnumber_bin);
    1177   if (b->n!=NULL)
    1178     lo->z = pp_Mult_qq(a->z, b->n,ntcRing);
    1179   else
    1180     lo->z = ntpCopy(a->z);
    1181   if (a->n!=NULL)
    1182     x = pp_Mult_qq(b->z, a->n, ntcRing);
    1183   else
    1184     x = ntpCopy(b->z);
    1185   if (ntI!=NULL)
    1186   {
    1187     lo->z = ntpRedp (lo->z);
    1188     if (lo->z != NULL)
    1189        lo->z = ntpTailred (lo->z);
    1190     if (x!=NULL)
    1191     {
    1192       x = ntpRedp (x);
    1193       if (x!=NULL)
    1194         x = ntpTailred (x);
    1195     }
    1196   }
    1197   if ((p_LmIsConstant(x,ntcRing)) && ntcIsOne(pGetCoeff(x)))
    1198     p_Delete(&x,ntcRing);
    1199   lo->n = x;
    1200   lo->s = 0;
    1201   if (lo->n!=NULL)
    1202   {
    1203     number luu=(number)lo;
    1204      //if (p_IsConstant(lo->n,ntcRing)) ntCoefNormalize(luu);
    1205      //else
    1206                          ntNormalize(luu);
    1207     lo=(lnumber)luu;
    1208   }
    1209   //else lo->s=2;
    1210   ntTest((number)lo);
    1211   return (number)lo;
    1212 }
    1213 
    1214 /*2
    1215 *  za:= - za, inplace
    1216 */
    1217 number ntNeg(number za)
    1218 {
    1219   if (za!=NULL)
    1220   {
    1221     lnumber e = (lnumber)za;
    1222     ntTest(za);
    1223     e->z = napNeg(e->z);
    1224   }
    1225   return za;
    1226 }
    1227 
    1228 /*2
    1229 * 1/a
    1230 */
    1231 number ntInvers(number a)
    1232 {
    1233   lnumber lo;
    1234   lnumber b = (lnumber)a;
    1235   napoly x;
    1236 
    1237   if (b==NULL)
    1238   {
    1239     WerrorS(nDivBy0);
    1240     return NULL;
    1241   }
    1242   #ifdef LDEBUG
    1243   omCheckAddrSize(b,sizeof(snumber));
    1244   #endif
    1245   lo = (lnumber)omAlloc0Bin(rnumber_bin);
    1246   lo->s = b->s;
    1247   if (b->n!=NULL)
    1248     lo->z = ntpCopy(b->n);
    1249   else
    1250     lo->z = p_ISet(1,ntcRing);
    1251   x = b->z;
    1252   if ((!p_LmIsConstant(x,ntcRing)) || !ntcIsOne(pGetCoeff(x)))
    1253     x = ntpCopy(x);
    1254   else
    1255   {
    1256     lo->n = NULL;
    1257     ntTest((number)lo);
    1258     return (number)lo;
    1259   }
    1260   lo->n = x;
    1261   if (lo->n!=NULL)
    1262   {
    1263      number luu=(number)lo;
    1264      //if (p_IsConstant(lo->n,ntcRing)) ntCoefNormalize(luu);
    1265      //else
    1266                            ntNormalize(luu);
    1267      lo=(lnumber)luu;
    1268   }
    1269   ntTest((number)lo);
    1270   return (number)lo;
    1271 }
    1272 
    1273 
    1274 BOOLEAN ntIsZero(number za)
    1275 {
    1276   lnumber zb = (lnumber)za;
    1277   ntTest(za);
    1278 #ifdef LDEBUG
    1279   if ((zb!=NULL) && (zb->z==NULL)) WerrorS("internal zero error(2)");
    1280 #endif
    1281   return (zb==NULL);
    1282 }
    1283 
    1284 
    1285 BOOLEAN ntGreaterZero(number za)
    1286 {
    1287   lnumber zb = (lnumber)za;
    1288 #ifdef LDEBUG
    1289   if ((zb!=NULL) && (zb->z==NULL)) WerrorS("internal zero error(3)");
    1290 #endif
    1291   ntTest(za);
    1292   if (zb!=NULL)
    1293   {
    1294     return (ntcGreaterZero(pGetCoeff(zb->z))||(!p_LmIsConstant(zb->z,ntcRing)));
    1295   }
    1296   /* else */ return FALSE;
    1297 }
    1298 
    1299 
    1300 /*2
    1301 * a = b ?
    1302 */
    1303 BOOLEAN ntEqual (number a, number b)
    1304 {
    1305   if(a==b) return TRUE;
    1306   if((a==NULL)&&(b!=NULL)) return FALSE;
    1307   if((b==NULL)&&(a!=NULL)) return FALSE;
    1308 
    1309   lnumber aa=(lnumber)a;
    1310   lnumber bb=(lnumber)b;
    1311 
    1312   int an_deg=0;
    1313   if(aa->n!=NULL)
    1314     an_deg=ntpDeg(aa->n);
    1315   int bn_deg=0;
    1316   if(bb->n!=NULL)
    1317     bn_deg=ntpDeg(bb->n);
    1318   if(an_deg+ntpDeg(bb->z)!=bn_deg+ntpDeg(aa->z))
    1319     return FALSE;
    1320 #if 0
    1321   ntNormalize(a);
    1322   aa=(lnumber)a;
    1323   ntNormalize(b);
    1324   bb=(lnumber)b;
    1325   if((aa->n==NULL)&&(bb->n!=NULL)) return FALSE;
    1326   if((bb->n==NULL)&&(aa->n!=NULL)) return FALSE;
    1327   if(ntpComp(aa->z,bb->z)!=0) return FALSE;
    1328   if((aa->n!=NULL) && (ntpComp(aa->n,bb->n))) return FALSE;
    1329 #endif
    1330   number h = ntSub(a, b);
    1331   BOOLEAN bo = ntIsZero(h);
    1332   ntDelete(&h,currRing);
    1333   return bo;
    1334 }
    1335 
    1336 
    1337 BOOLEAN ntGreater (number a, number b)
    1338 {
    1339   if (ntIsZero(a))
    1340     return FALSE;
    1341   if (ntIsZero(b))
    1342     return TRUE; /* a!= 0)*/
    1343   return ntpDeg(((lnumber)a)->z)>ntpDeg(((lnumber)b)->z);
    1344 }
    1345 
    1346 /*2
    1347 * reads a number
    1348 */
    1349 const char  *ntRead(const char *s, number *p)
    1350 {
    1351   napoly x;
    1352   lnumber a;
    1353   s = ntpRead(s, &x);
    1354   if (x==NULL)
    1355   {
    1356     *p = NULL;
    1357     return s;
    1358   }
    1359   *p = (number)omAlloc0Bin(rnumber_bin);
    1360   a = (lnumber)*p;
    1361   if (ntI!=NULL)
    1362   {
    1363     a->z = ntpRedp(x);
    1364     if (a->z != NULL)
    1365       a->z = ntpTailred (a->z);
    1366   }
    1367   else
    1368     a->z = x;
    1369   if(a->z==NULL)
    1370   {
    1371     omFreeBin((ADDRESS)*p, rnumber_bin);
    1372     *p=NULL;
    1373   }
    1374   else
    1375   {
    1376     a->n = NULL;
    1377     a->s = 0;
    1378     ntTest(*p);
    1379   }
    1380   return s;
    1381 }
    1382 
    1383 /*2
    1384 * tries to convert a number to a name
    1385 */
    1386 char * ntName(number n)
    1387 {
    1388   lnumber ph = (lnumber)n;
    1389   if (ph==NULL)
    1390     return NULL;
    1391   int i;
    1392   char *s=(char *)omAlloc(4* naNumbOfPar);
    1393   char *t=(char *)omAlloc(8);
    1394   s[0]='\0';
    1395   for (i = 0; i <= naNumbOfPar - 1; i++)
    1396   {
    1397     int e=p_GetExp(ph->z,i+1,ntcRing);
    1398     if (e > 0)
    1399     {
    1400       if (e >1)
    1401       {
    1402         sprintf(t,"%s%d",ntParNames[i],e);
    1403         strcat(s,t);
    1404       }
    1405       else
    1406       {
    1407         strcat(s,ntParNames[i]);
    1408       }
    1409     }
    1410   }
    1411   omFreeSize((ADDRESS)t,8);
    1412   if (s[0]=='\0')
    1413   {
    1414     omFree((ADDRESS)s);
    1415     return NULL;
    1416   }
    1417   return s;
    1418 }
    1419 
    1420 /*2
    1421 *  writes a number
    1422 */
    1423 void ntWrite(number &phn, const ring r)
    1424 {
    1425   lnumber ph = (lnumber)phn;
    1426   if (ph==NULL)
    1427     StringAppendS("0");
    1428   else
    1429   {
    1430     phn->s = 0;
    1431     BOOLEAN has_denom=(ph->n!=NULL);
    1432     ntpWrite(ph->z,has_denom/*(ph->n!=NULL)*/,r);
    1433     if (has_denom/*(ph->n!=NULL)*/)
    1434     {
    1435       StringAppendS("/");
    1436       ntpWrite(ph->n,TRUE,r);
    1437     }
    1438   }
    1439 }
    1440 
    1441 /*2
    1442 * za == 1 ?
    1443 */
    1444 BOOLEAN ntIsOne(number za)
    1445 {
    1446   lnumber a = (lnumber)za;
    1447   napoly x, y;
    1448   number t;
    1449   if (a==NULL) return FALSE;
    1450 #ifdef LDEBUG
    1451   omCheckAddrSize(a,sizeof(snumber));
    1452   if (a->z==NULL)
    1453   {
    1454     WerrorS("internal zero error(4)");
    1455     return FALSE;
    1456   }
    1457 #endif
    1458   if (a->n==NULL)
    1459   {
    1460     if (p_LmIsConstant(a->z,ntcRing))
    1461     {
    1462       return ntcIsOne(pGetCoeff(a->z));
    1463     }
    1464     else                 return FALSE;
    1465   }
    1466 #if 0
    1467   x = a->z;
    1468   y = a->n;
    1469   do
    1470   {
    1471     if (ntpComp(x, y))
    1472       return FALSE;
    1473     else
    1474     {
    1475       t = ntcSub(pGetCoeff(x), pGetCoeff(y));
    1476       if (!ntcIsZero(t))
    1477       {
    1478         n_Delete(&t,ntcRing);
    1479         return FALSE;
    1480       }
    1481       else
    1482         n_Delete(&t,ntcRing);
    1483     }
    1484     pIter(x);
    1485     pIter(y);
    1486   }
    1487   while ((x!=NULL) && (y!=NULL));
    1488   if ((x!=NULL) || (y!=NULL)) return FALSE;
    1489   p_Delete(&a->z,ntcRing);
    1490   p_Delete(&a->n,ntcRing);
    1491   a->z = p_ISet(1,ntcRing);
    1492   a->n = NULL;
    1493   return TRUE;
    1494 #else
    1495   return FALSE;
    1496 #endif
    1497 }
    1498 
    1499 /*2
    1500 * za == -1 ?
    1501 */
    1502 BOOLEAN ntIsMOne(number za)
    1503 {
    1504   lnumber a = (lnumber)za;
    1505   napoly x, y;
    1506   number t;
    1507   if (a==NULL) return FALSE;
    1508 #ifdef LDEBUG
    1509   omCheckAddrSize(a,sizeof(snumber));
    1510   if (a->z==NULL)
    1511   {
    1512     WerrorS("internal zero error(5)");
    1513     return FALSE;
    1514   }
    1515 #endif
    1516   if (a->n==NULL)
    1517   {
    1518     if (p_LmIsConstant(a->z,ntcRing)) return ntcIsMOne(pGetCoeff(a->z));
    1519     /*else                   return FALSE;*/
    1520   }
    1521   return FALSE;
    1522 }
    1523 
    1524 /*2
    1525 * returns the i-th power of p (i>=0)
    1526 */
    1527 void ntPower(number p, int i, number *rc)
    1528 {
    1529   number x;
    1530   *rc = ntInit(1,currRing);
    1531   for (; i > 0; i--)
    1532   {
    1533     x = ntMult(*rc, p);
    1534     ntDelete(rc,currRing);
    1535     *rc = x;
    1536   }
    1537 }
    1538 
    1539 /*2
    1540 * result =gcd(a,b)
    1541 */
    1542 number ntGcd(number a, number b, const ring r)
    1543 {
    1544   if (a==NULL)  return ntCopy(b);
    1545   if (b==NULL)  return ntCopy(a);
    1546 
    1547   lnumber x, y;
    1548   lnumber result = (lnumber)omAlloc0Bin(rnumber_bin);
    1549 
    1550   x = (lnumber)a;
    1551   y = (lnumber)b;
    1552 #ifndef HAVE_FACTORY
    1553   result->z = ntpGcd(x->z, y->z); // change from ntpGcd0
    1554 #else
    1555   int c=ABS(nGetChar());
    1556   if (c==1) c=0;
    1557   setCharacteristic( c );
    1558 
    1559   napoly rz=ntpGcd(x->z, y->z);
    1560   CanonicalForm F, G, R;
    1561   R=convSingPFactoryP(rz,r->algring);
    1562   p_Normalize(x->z,ntcRing);
    1563   F=convSingPFactoryP(x->z,r->algring)/R;
    1564   p_Normalize(y->z,ntcRing);
    1565   G=convSingPFactoryP(y->z,r->algring)/R;
    1566   F = gcd( F, G );
    1567   if (F.isOne())
    1568     result->z= rz;
    1569   else
    1570   {
    1571     p_Delete(&rz,r->algring);
    1572     result->z=convFactoryPSingP( F*R,r->algring );
    1573     p_Normalize(result->z,ntcRing);
    1574   }
    1575 #endif
    1576   ntTest((number)result);
    1577   return (number)result;
    1578 }
    1579 
    1580 
    1581 /*2
    1582 * naNumbOfPar = 1:
    1583 * clears denominator         algebraic case;
    1584 * tries to simplify ratio    transcendental case;
    1585 *
    1586 * cancels monomials
    1587 * occuring in denominator
    1588 * and enumerator  ?          naNumbOfPar != 1;
    1589 *
    1590 * #defines for Factory:
    1591 * FACTORY_GCD_TEST: do not apply built in gcd for
    1592 *   univariate polynomials, always use Factory
    1593 */
    1594 //#define FACTORY_GCD_TEST
    1595 void ntCoefNormalize(number pp)
    1596 {
    1597   if (pp==NULL) return;
    1598   lnumber p = (lnumber)pp;
    1599   number nz; // all denom. of the numerator
    1600   nz=p_GetAllDenom(p->z,ntcRing);
    1601   BOOLEAN norm=FALSE;
    1602   if (!n_IsOne(nz,ntcRing))
    1603   {
    1604     norm=TRUE;
    1605     p->z=p_Mult_nn(p->z,nz,ntcRing);
    1606     if (p->n==NULL)
    1607     {
    1608       p->n=p_NSet(nz,ntcRing);
    1609     }
    1610     else
    1611     {
    1612       p->n=p_Mult_nn(p->n,nz,ntcRing);
    1613       n_Delete(&nz, ntcRing);
    1614     }
    1615   }
    1616   else
    1617   {
    1618     n_Delete(&nz, ntcRing);
    1619   }
    1620   if (norm)
    1621   {
    1622     norm=FALSE;
    1623     p_Normalize(p->z,ntcRing);
    1624     p_Normalize(p->n,ntcRing);
    1625   }
    1626   number nn;
    1627   nn=p_GetAllDenom(p->n,ntcRing);
    1628   if (!n_IsOne(nn,ntcRing))
    1629   {
    1630     norm=TRUE;
    1631     p->n=p_Mult_nn(p->n,nn,ntcRing);
    1632     p->z=p_Mult_nn(p->z,nn,ntcRing);
    1633     n_Delete(&nn, ntcRing);
    1634   }
    1635   else
    1636   {
    1637     n_Delete(&nn, ntcRing);
    1638   }
    1639   if (norm)
    1640   {
    1641     p_Normalize(p->z,ntcRing);
    1642     p_Normalize(p->n,ntcRing);
    1643   }
    1644   // remove common factors in n, z:
    1645   if (p->n!=NULL)
    1646   {
    1647     poly pp=p->z;
    1648     nz=n_Copy(pGetCoeff(pp),ntcRing);
    1649     pIter(pp);
    1650     while(pp!=NULL)
    1651     {
    1652       if (n_IsOne(nz,ntcRing)) break;
    1653       number d=n_Gcd(nz,pGetCoeff(pp),ntcRing);
    1654       n_Delete(&nz,ntcRing); nz=d;
    1655       pIter(pp);
    1656     }
    1657     if (!n_IsOne(nz,ntcRing))
    1658     {
    1659       pp=p->n;
    1660       nn=n_Copy(pGetCoeff(pp),ntcRing);
    1661       pIter(pp);
    1662       while(pp!=NULL)
    1663       {
    1664         if (n_IsOne(nn,ntcRing)) break;
    1665         number d=n_Gcd(nn,pGetCoeff(pp),ntcRing);
    1666         n_Delete(&nn,ntcRing); nn=d;
    1667         pIter(pp);
    1668       }
    1669       number ng=n_Gcd(nz,nn,ntcRing);
    1670       n_Delete(&nn,ntcRing);
    1671       if (!n_IsOne(ng,ntcRing))
    1672       {
    1673         number ni=n_Invers(ng,ntcRing);
    1674         p->z=p_Mult_nn(p->z,ni,ntcRing);
    1675         p->n=p_Mult_nn(p->n,ni,ntcRing);
    1676         p_Normalize(p->z,ntcRing);
    1677         p_Normalize(p->n,ntcRing);
    1678         n_Delete(&ni,ntcRing);
    1679       }
    1680       n_Delete(&ng,ntcRing);
    1681     }
    1682     n_Delete(&nz,ntcRing);
    1683   }
    1684   if (p->n!=NULL)
    1685   {
    1686     if(!ntcGreaterZero(pGetCoeff(p->n)))
    1687     {
    1688       p->z=napNeg(p->z);
    1689       p->n=napNeg(p->n);
    1690     }
    1691 
    1692     if (/*(p->n!=NULL) && */
    1693     (p_IsConstant(p->n,ntcRing))
    1694     && (n_IsOne(pGetCoeff(p->n),ntcRing)))
    1695     {
    1696       p_Delete(&(p->n), ntcRing);
    1697       p->n = NULL;
    1698     }
    1699   }
    1700 }
    1701 
    1702 void ntNormalize(number &pp)
    1703 {
    1704 
    1705   //ntTest(pp); // input may not be "normal"
    1706   lnumber p = (lnumber)pp;
    1707 
    1708   if (p==NULL)
    1709     return;
    1710   ntCoefNormalize(pp);
    1711   p->s = 2;
    1712   napoly x = p->z;
    1713   napoly y = p->n;
    1714 
    1715   BOOLEAN norm=FALSE;
    1716 
    1717   if (y==NULL) return;
    1718 
    1719   if ((x!=NULL) && (y!=NULL))
    1720   {
    1721     int i;
    1722     for (i=naNumbOfPar-1; i>=0; i--)
    1723     {
    1724       napoly xx=x;
    1725       napoly yy=y;
    1726       int m = ntpExpi(i, yy, xx);
    1727       if (m != 0)          // in this case xx!=NULL!=yy
    1728       {
    1729         while (xx != NULL)
    1730         {
    1731           napAddExp(xx,i+1, -m);
    1732           pIter(xx);
    1733         }
    1734         while (yy != NULL)
    1735         {
    1736           napAddExp(yy,i+1, -m);
    1737           pIter(yy);
    1738         }
    1739       }
    1740     }
    1741   }
    1742   if (p_LmIsConstant(y,ntcRing)) /* i.e. => simplify to (1/c)*z / monom */
    1743   {
    1744     if (ntcIsOne(pGetCoeff(y)))
    1745     {
    1746       p_LmDelete(&y,ntcRing);
    1747       p->n = NULL;
    1748       ntTest(pp);
    1749       return;
    1750     }
    1751     number h1 = ntcInvers(pGetCoeff(y));
    1752     ntcNormalize(h1);
    1753     ntpMultN(x, h1);
    1754     n_Delete(&h1,ntcRing);
    1755     p_LmDelete(&y,ntcRing);
    1756     p->n = NULL;
    1757     ntTest(pp);
    1758     return;
    1759   }
    1760 #ifndef FACTORY_GCD_TEST
    1761   if (naNumbOfPar == 1) /* apply built-in gcd */
    1762   {
    1763     napoly x1,y1;
    1764     if (p_GetExp(x,1,ntcRing) >= p_GetExp(y,1,ntcRing))
    1765     {
    1766       x1 = ntpCopy(x);
    1767       y1 = ntpCopy(y);
    1768     }
    1769     else
    1770     {
    1771       x1 = ntpCopy(y);
    1772       y1 = ntpCopy(x);
    1773     }
    1774     napoly r;
    1775     loop
    1776     {
    1777       r = napRemainder(x1, y1);
    1778       if ((r==NULL) || (pNext(r)==NULL)) break;
    1779       x1 = y1;
    1780       y1 = r;
    1781     }
    1782     if (r!=NULL)
    1783     {
    1784       p_Delete(&r,ntcRing);
    1785       p_Delete(&y1,ntcRing);
    1786     }
    1787     else
    1788     {
    1789       ntpDivMod(x, y1, &(p->z), &r);
    1790       ntpDivMod(y, y1, &(p->n), &r);
    1791       p_Delete(&y1,ntcRing);
    1792     }
    1793     x = p->z;
    1794     y = p->n;
    1795     /* collect all denoms from y and multiply x and y by it */
    1796     if (ntIsChar0)
    1797     {
    1798       number n=ntpLcm(y);
    1799       ntpMultN(x,n);
    1800       ntpMultN(y,n);
    1801       n_Delete(&n,ntcRing);
    1802       while(x!=NULL)
    1803       {
    1804         ntcNormalize(pGetCoeff(x));
    1805         pIter(x);
    1806       }
    1807       x = p->z;
    1808       while(y!=NULL)
    1809       {
    1810         ntcNormalize(pGetCoeff(y));
    1811         pIter(y);
    1812       }
    1813       y = p->n;
    1814     }
    1815     if (pNext(y)==NULL)
    1816     {
    1817       if (ntcIsOne(pGetCoeff(y)))
    1818       {
    1819         if (p_GetExp(y,1,ntcRing)==0)
    1820         {
    1821           p_LmDelete(&y,ntcRing);
    1822           p->n = NULL;
    1823         }
    1824         ntTest(pp);
    1825         return;
    1826       }
    1827     }
    1828   }
    1829 #endif /* FACTORY_GCD_TEST */
    1830 #ifdef HAVE_FACTORY
    1831 #ifndef FACTORY_GCD_TEST
    1832   else
    1833 #endif
    1834   {
    1835     napoly xx,yy;
    1836     singclap_algdividecontent(x,y,xx,yy);
    1837     if (xx!=NULL)
    1838     {
    1839       p->z=xx;
    1840       p->n=yy;
    1841       p_Delete(&x,ntcRing);
    1842       p_Delete(&y,ntcRing);
    1843     }
    1844   }
    1845 #endif
    1846   /* remove common factors from z and n */
    1847   x=p->z;
    1848   y=p->n;
    1849   if(!ntcGreaterZero(pGetCoeff(y)))
    1850   {
    1851     x=napNeg(x);
    1852     y=napNeg(y);
    1853   }
    1854   number g=ntcCopy(pGetCoeff(x));
    1855   pIter(x);
    1856   while (x!=NULL)
    1857   {
    1858     number d=ntcGcd(g,pGetCoeff(x), ntcRing);
    1859     if(ntcIsOne(d))
    1860     {
    1861       n_Delete(&g,ntcRing);
    1862       n_Delete(&d,ntcRing);
    1863       ntTest(pp);
    1864       return;
    1865     }
    1866     n_Delete(&g,ntcRing);
    1867     g = d;
    1868     pIter(x);
    1869   }
    1870   while (y!=NULL)
    1871   {
    1872     number d=ntcGcd(g,pGetCoeff(y), ntcRing);
    1873     if(ntcIsOne(d))
    1874     {
    1875       n_Delete(&g,ntcRing);
    1876       n_Delete(&d,ntcRing);
    1877       ntTest(pp);
    1878       return;
    1879     }
    1880     n_Delete(&g,ntcRing);
    1881     g = d;
    1882     pIter(y);
    1883   }
    1884   x=p->z;
    1885   y=p->n;
    1886   while (x!=NULL)
    1887   {
    1888     number d = ntcIntDiv(pGetCoeff(x),g);
    1889     ntpSetCoeff(x,d);
    1890     pIter(x);
    1891   }
    1892   while (y!=NULL)
    1893   {
    1894     number d = ntcIntDiv(pGetCoeff(y),g);
    1895     ntpSetCoeff(y,d);
    1896     pIter(y);
    1897   }
    1898   n_Delete(&g,ntcRing);
    1899   ntTest(pp);
    1900 }
    1901 
    1902 /*2
    1903 * returns in result->n 1
    1904 * and in     result->z the lcm(a->z,b->n)
    1905 */
    1906 number ntLcm(number la, number lb, const ring r)
    1907 {
    1908   lnumber result;
    1909   lnumber a = (lnumber)la;
    1910   lnumber b = (lnumber)lb;
    1911   result = (lnumber)omAlloc0Bin(rnumber_bin);
    1912   //if (((naMinimalPoly==NULL) && (ntI==NULL)) || !ntIsChar0)
    1913   //{
    1914   //  result->z = p_ISet(1,ntcRing);
    1915   //  return (number)result;
    1916   //}
    1917   //ntNormalize(lb);
    1918   ntTest(la);
    1919   ntTest(lb);
    1920   napoly x = p_Copy(a->z, r->algring);
    1921   number t = ntpLcm(b->z); // get all denom of b->z
    1922   if (!ntcIsOne(t))
    1923   {
    1924     number bt, rr;
    1925     napoly xx=x;
    1926     while (xx!=NULL)
    1927     {
    1928       bt = ntcGcd(t, pGetCoeff(xx), r->algring);
    1929       rr = ntcMult(t, pGetCoeff(xx));
    1930       n_Delete(&pGetCoeff(xx),r->algring);
    1931       pGetCoeff(xx) = ntcDiv(rr, bt);
    1932       ntcNormalize(pGetCoeff(xx));
    1933       n_Delete(&bt,r->algring);
    1934       n_Delete(&rr,r->algring);
    1935       pIter(xx);
    1936     }
    1937   }
    1938   n_Delete(&t,r->algring);
    1939   result->z = x;
    1940 #ifdef HAVE_FACTORY
    1941   if (b->n!=NULL)
    1942   {
    1943     result->z=singclap_alglcm(result->z,b->n);
    1944     p_Delete(&x,r->algring);
    1945   }
    1946 #endif
    1947   ntTest(la);
    1948   ntTest(lb);
    1949   ntTest((number)result);
    1950   return ((number)result);
    1951 }
    1952 
    1953 /*2
    1954 * input: a set of constant polynomials
    1955 * sets the global variable ntI
    1956 */
    1957 void ntSetIdeal(ideal I)
    1958 {
    1959   int i;
    1960 
    1961   if (idIs0(I))
    1962   {
    1963     for (i=ntI->anz-1; i>=0; i--)
    1964       p_Delete(&ntI->liste[i],ntcRing);
    1965     omFreeBin((ADDRESS)ntI, sntIdeal_bin);
    1966     ntI=NULL;
    1967   }
    1968   else
    1969   {
    1970     lnumber h;
    1971     number a;
    1972     napoly x;
    1973 
    1974     ntI=(ntIdeal)omAllocBin(sntIdeal_bin);
    1975     ntI->anz=IDELEMS(I);
    1976     ntI->liste=(napoly*)omAlloc(ntI->anz*sizeof(napoly));
    1977     for (i=IDELEMS(I)-1; i>=0; i--)
    1978     {
    1979       h=(lnumber)pGetCoeff(I->m[i]);
    1980       /* We only need the enumerator of h, as we expect it to be a polynomial */
    1981       ntI->liste[i]=ntpCopy(h->z);
    1982       /* If it isn't normalized (lc = 1) do this */
    1983       if (!ntcIsOne(pGetCoeff(ntI->liste[i])))
    1984       {
    1985         x=ntI->liste[i];
    1986         ntcNormalize(pGetCoeff(x));
    1987         a=ntcCopy(pGetCoeff(x));
    1988         number aa=ntcInvers(a);
    1989         n_Delete(&a,ntcRing);
    1990         ntpMultN(x,aa);
    1991         n_Delete(&aa,ntcRing);
    1992       }
    1993     }
    1994   }
    1995 }
    1996 
    1997 /*2
    1998 * map Z/p -> Q(a)
    1999 */
    2000 number ntMapP0(number c)
    2001 {
    2002   if (npIsZero(c)) return NULL;
    2003   lnumber l=(lnumber)omAllocBin(rnumber_bin);
    2004   l->s=2;
    2005   l->z=(napoly)p_Init(ntcRing);
    2006   int i=(int)((long)c);
    2007   if (i>((long)ntMapRing->ch>>2)) i-=(long)ntMapRing->ch;
    2008   pGetCoeff(l->z)=nlInit(i, ntcRing);
    2009   l->n=NULL;
    2010   return (number)l;
    2011 }
    2012 
    2013 /*2
    2014 * map Q -> Q(a)
    2015 */
    2016 number ntMap00(number c)
    2017 {
    2018   if (nlIsZero(c)) return NULL;
    2019   lnumber l=(lnumber)omAllocBin(rnumber_bin);
    2020   l->s=0;
    2021   l->z=(napoly)p_Init(ntcRing);
    2022   pGetCoeff(l->z)=nlCopy(c);
    2023   l->n=NULL;
    2024   return (number)l;
    2025 }
    2026 
    2027 /*2
    2028 * map Z/p -> Z/p(a)
    2029 */
    2030 number ntMapPP(number c)
    2031 {
    2032   if (npIsZero(c)) return NULL;
    2033   lnumber l=(lnumber)omAllocBin(rnumber_bin);
    2034   l->s=2;
    2035   l->z=(napoly)p_Init(ntcRing);
    2036   pGetCoeff(l->z)=c; /* omit npCopy, because npCopy is a no-op */
    2037   l->n=NULL;
    2038   return (number)l;
    2039 }
    2040 
    2041 /*2
    2042 * map Z/p' -> Z/p(a)
    2043 */
    2044 number ntMapPP1(number c)
    2045 {
    2046   if (npIsZero(c)) return NULL;
    2047   int i=(int)((long)c);
    2048   if (i>(long)ntMapRing->ch) i-=(long)ntMapRing->ch;
    2049   number n=npInit(i,ntMapRing);
    2050   if (npIsZero(n)) return NULL;
    2051   lnumber l=(lnumber)omAllocBin(rnumber_bin);
    2052   l->s=2;
    2053   l->z=(napoly)p_Init(ntcRing);
    2054   pGetCoeff(l->z)=n;
    2055   l->n=NULL;
    2056   return (number)l;
    2057 }
    2058 
    2059 /*2
    2060 * map Q -> Z/p(a)
    2061 */
    2062 number ntMap0P(number c)
    2063 {
    2064   if (nlIsZero(c)) return NULL;
    2065   number n=npInit(nlModP(c,npPrimeM),ntcRing);
    2066   if (npIsZero(n)) return NULL;
    2067   npTest(n);
    2068   lnumber l=(lnumber)omAllocBin(rnumber_bin);
    2069   l->s=2;
    2070   l->z=(napoly)p_Init(ntcRing);
    2071   pGetCoeff(l->z)=n;
    2072   l->n=NULL;
    2073   return (number)l;
    2074 }
    2075 
    2076 static number (*ntcMap)(number);
    2077 static int ntParsToCopy;
    2078 static napoly ntpMap(napoly p)
    2079 {
    2080   napoly w, a;
    2081 
    2082   if (p==NULL) return NULL;
    2083   a = w = (napoly)p_Init(ntcRing);
     866  a = w = (napoly)p_Init(nacRing);
    2084867  int i;
    2085868  for(i=1;i<=ntParsToCopy;i++)
    2086869    napSetExp(a,i,napGetExpFrom(p,i,ntMapRing));
    2087   p_Setm(a,ntcRing);
     870  p_Setm(a,nacRing);
    2088871  pGetCoeff(w) = ntcMap(pGetCoeff(p));
    2089872  loop
     
    2091874    pIter(p);
    2092875    if (p==NULL) break;
    2093     pNext(a) = (napoly)p_Init(ntcRing);
     876    pNext(a) = (napoly)p_Init(nacRing);
    2094877    pIter(a);
    2095878    for(i=1;i<=ntParsToCopy;i++)
    2096879      napSetExp(a,i,napGetExpFrom(p,i,ntMapRing));
    2097     p_Setm(a,ntcRing);
     880    p_Setm(a,nacRing);
    2098881    pGetCoeff(a) = ntcMap(pGetCoeff(p));
    2099882  }
     
    2102885}
    2103886
    2104 static napoly ntpPerm(napoly p,const int *par_perm,const ring src_ring,const nMapFunc nMap)
     887napoly napPerm(napoly p,const int *par_perm,const ring src_ring,const nMapFunc nMap)
    2105888{
    2106889  napoly w, a;
    2107890
    2108891  if (p==NULL) return NULL;
    2109   w = (napoly)p_Init(ntcRing);
     892  w = (napoly)p_Init(nacRing);
    2110893  int i;
    2111894  BOOLEAN not_null=TRUE;
     
    2124907    }
    2125908    pGetCoeff(w) = nMap(pGetCoeff(p));
    2126     p_Setm(w,ntcRing);
     909    p_Setm(w,nacRing);
    2127910    pIter(p);
    2128911    if (!not_null)
     
    2130913      if (p==NULL)
    2131914      {
    2132         p_Delete(&w,ntcRing);
     915        p_Delete(&w,nacRing);
    2133916        return NULL;
    2134917      }
    2135918      /* else continue*/
    2136       n_Delete(&(pGetCoeff(w)),ntcRing);
     919      n_Delete(&(pGetCoeff(w)),nacRing);
    2137920    }
    2138921    else
     
    2141924      else
    2142925      {
    2143         pNext(w)=ntpPerm(p,par_perm,src_ring,nMap);
     926        pNext(w)=napPerm(p,par_perm,src_ring,nMap);
    2144927        return w;
    2145928      }
     
    2149932
    2150933/*2
    2151 * map _(a) -> _(b)
    2152 */
    2153 number ntMapQaQb(number c)
    2154 {
    2155   if (c==NULL) return NULL;
    2156   lnumber erg= (lnumber)omAlloc0Bin(rnumber_bin);
    2157   lnumber src =(lnumber)c;
    2158   erg->s=src->s;
    2159   erg->z=ntpMap(src->z);
    2160   erg->n=ntpMap(src->n);
    2161   return (number)erg;
    2162 }
    2163 
    2164 nMapFunc ntSetMap(const ring src, const ring dst)
    2165 {
    2166   ntMapRing=src;
    2167   if (rField_is_Q_a(dst)) /* -> Q(a) */
    2168   {
    2169     if (rField_is_Q(src))
    2170     {
    2171       return ntMap00;   /*Q -> Q(a)*/
    2172     }
    2173     if (rField_is_Zp(src))
    2174     {
    2175       return ntMapP0;  /* Z/p -> Q(a)*/
    2176     }
    2177     if (rField_is_Q_a(src))
    2178     {
    2179       int i;
    2180       ntParsToCopy=0;
    2181       for(i=0;i<rPar(src);i++)
    2182       {
    2183         if ((i>=rPar(dst))
    2184         ||(strcmp(src->parameter[i],dst->parameter[i])!=0))
    2185            return NULL;
    2186         ntParsToCopy++;
    2187       }
    2188       ntcMap=ntcCopy;
    2189       if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src)))
    2190         return ntCopy;    /* Q(a) -> Q(a) */
    2191       return ntMapQaQb;   /* Q(a..) -> Q(a..) */
    2192     }
    2193   }
    2194   /*-----------------------------------------------------*/
    2195   if (rField_is_Zp_a(dst)) /* -> Z/p(a) */
    2196   {
    2197     if (rField_is_Q(src))
    2198     {
    2199       return ntMap0P;   /*Q -> Z/p(a)*/
    2200     }
    2201     if (rField_is_Zp(src))
    2202     {
    2203       if (src->ch==dst->ch)
    2204       {
    2205         return ntMapPP;  /* Z/p -> Z/p(a)*/
    2206       }
    2207       else
    2208       {
    2209         return ntMapPP1;  /* Z/p' -> Z/p(a)*/
    2210       }
    2211     }
    2212     if (rField_is_Zp_a(src))
    2213     {
    2214       if (rChar(src)==rChar(dst))
    2215       {
    2216         ntcMap=ntcCopy;
    2217       }
    2218       else
    2219       {
    2220         ntcMap = npMapP;
    2221       }
    2222       int i;
    2223       ntParsToCopy=0;
    2224       for(i=0;i<rPar(src);i++)
    2225       {
    2226         if ((i>=rPar(dst))
    2227         ||(strcmp(src->parameter[i],dst->parameter[i])!=0))
    2228            return NULL;
    2229         ntParsToCopy++;
    2230       }
    2231       if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src))
    2232       && (ntcMap==ntcCopy))
    2233         return ntCopy;    /* Z/p(a) -> Z/p(a) */
    2234       return ntMapQaQb;   /* Z/p(a),Z/p'(a) -> Z/p(b)*/
    2235     }
    2236   }
    2237   return NULL;      /* default */
    2238 }
    2239 
    2240 /*2
    2241934* convert a napoly number into a poly
    2242935*/
    2243 poly ntPermNumber(number z, int * par_perm, int P, ring oldRing)
     936poly napPermNumber(number z, int * par_perm, int P, ring oldRing)
    2244937{
    2245938  if (z==NULL) return NULL;
     
    2248941  napoly za=((lnumber)z)->z;
    2249942  napoly zb=((lnumber)z)->n;
    2250   nMapFunc nMap=ntSetMap(oldRing,currRing);
     943  nMapFunc nMap=naSetMap(oldRing,currRing);
    2251944  if (currRing->parameter!=NULL)
    2252     nMap=currRing->algring->cf->cfSetMap(oldRing->algring, ntcRing);
     945    nMap=currRing->algring->cf->cfSetMap(oldRing->algring, nacRing);
    2253946  else
    2254947    nMap=currRing->cf->cfSetMap(oldRing->algring, currRing);
     
    2271964      pan=(lnumber)pGetCoeff(p);
    2272965      pan->s=2;
    2273       pan->z=ntpInitz(nMap(pGetCoeff(za)));
     966      pan->z=napInitz(nMap(pGetCoeff(za)));
    2274967      pa=pan->z;
    2275968    }
     
    2287980          {
    2288981            napSetExp(pa,i+1,napGetExpFrom(za,i+1,oldRing));
    2289             p_Setm(pa,ntcRing);
     982            p_Setm(pa,nacRing);
    2290983          }
    2291984          else
     
    2300993        {
    2301994          napSetExp(pa,-par_perm[i], napGetExpFrom(za,i+1,oldRing));
    2302           p_Setm(pa,ntcRing);
     995          p_Setm(pa,nacRing);
    2303996        }
    2304997        else
     
    23161009        if  (currRing->P>0)
    23171010        {
    2318           pan->n=ntpPerm(zb,par_perm,oldRing,nMap);
     1011          pan->n=napPerm(zb,par_perm,oldRing,nMap);
    23191012          if(pan->n==NULL) /* error in mapping or mapping to variable */
    23201013            pDelete(&p);
     
    23331026}
    23341027
     1028number   napGetDenom(number &n, const ring r)
     1029{
     1030  lnumber x=(lnumber)n;
     1031  if (x->n!=NULL)
     1032  {
     1033    lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin);
     1034    rr->z=p_Copy(x->n,r->algring);
     1035    rr->s = 2;
     1036    return (number)rr;
     1037  }
     1038  return n_Init(1,r);
     1039}
     1040
     1041number   napGetNumerator(number &n, const ring r)
     1042{
     1043  lnumber x=(lnumber)n;
     1044  lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin);
     1045  rr->z=p_Copy(x->z,r->algring);
     1046  rr->s = 2;
     1047  return (number)rr;
     1048}
     1049
     1050/*================ procedure for rational functions: ntXXXX =================*/
     1051
     1052/*2
     1053*  z:= i
     1054*/
     1055number ntInit(int i, const ring r)
     1056{
     1057  if (i!=0)
     1058  {
     1059    number c=n_Init(i,r->algring);
     1060    if (!n_IsZero(c,r->algring))
     1061    {
     1062      poly z=p_Init(r->algring);
     1063      pSetCoeff0(z,c);
     1064      lnumber l = (lnumber)omAllocBin(rnumber_bin);
     1065      l->z = z;
     1066      l->s = 2;
     1067      l->n = NULL;
     1068      return (number)l;
     1069    }
     1070  }
     1071  /*else*/
     1072  return NULL;
     1073}
     1074
     1075/*3
     1076*  division with remainder: f = g*q + r,
     1077*  returns r and destroys f
     1078*/
     1079napoly ntRemainder(napoly f, const napoly g)
     1080{
     1081  napoly a, h, qq;
     1082
     1083  qq = (napoly)p_Init(nacRing);
     1084  pNext(qq) = NULL;
     1085  p_Normalize(g, nacRing);
     1086  p_Normalize(f, nacRing);
     1087  a = f;
     1088  do
     1089  {
     1090    napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing));
     1091    napSetm(qq);
     1092    pGetCoeff(qq) = ntcDiv(pGetCoeff(a), pGetCoeff(g));
     1093    pGetCoeff(qq) = ntcNeg(pGetCoeff(qq));
     1094    ntcNormalize(pGetCoeff(qq));
     1095    h = napCopy(g);
     1096    napMultT(h, qq);
     1097    p_Normalize(h,nacRing);
     1098    n_Delete(&pGetCoeff(qq),nacRing);
     1099    a = napAdd(a, h);
     1100  }
     1101  while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing)));
     1102  omFreeBinAddr(qq);
     1103  return a;
     1104}
     1105
     1106number  ntPar(int i)
     1107{
     1108  lnumber l = (lnumber)omAllocBin(rnumber_bin);
     1109  l->s = 2;
     1110  l->z = p_ISet(1,nacRing);
     1111  napSetExp(l->z,i,1);
     1112  p_Setm(l->z,nacRing);
     1113  l->n = NULL;
     1114  return (number)l;
     1115}
     1116
     1117int     ntParDeg(number n)     /* i := deg(n) */
     1118{
     1119  lnumber l = (lnumber)n;
     1120  if (l==NULL) return -1;
     1121  return napDeg(l->z);
     1122}
     1123
     1124//int     ntParDeg(number n)     /* i := deg(n) */
     1125//{
     1126//  lnumber l = (lnumber)n;
     1127//  if (l==NULL) return -1;
     1128//  return napMaxDeg(l->z)+napMaxDeg(l->n);
     1129//}
     1130
     1131int     ntSize(number n)     /* size desc. */
     1132{
     1133  lnumber l = (lnumber)n;
     1134  if (l==NULL) return -1;
     1135  int len_z;
     1136  int len_n;
     1137  int o=napMaxDegLen(l->z,len_z)+napMaxDegLen(l->n,len_n);
     1138  return (len_z+len_n)+o;
     1139}
     1140
     1141/*2
     1142* convert a number to int (if possible)
     1143*/
     1144int ntInt(number &n, const ring r)
     1145{
     1146  lnumber l=(lnumber)n;
     1147  if ((l!=NULL)&&(l->n==NULL)&&(p_IsConstant(l->z,r->algring)))
     1148  {
     1149    return ntcInt(pGetCoeff(l->z),r->algring);
     1150  }
     1151  return 0;
     1152}
     1153
     1154/*2
     1155*  deletes p
     1156*/
     1157void ntDelete(number *p, const ring r)
     1158{
     1159  if ((*p)!=NULL)
     1160  {
     1161    lnumber l = (lnumber) * p;
     1162    if (l==NULL) return;
     1163    p_Delete(&(l->z),r->algring);
     1164    p_Delete(&(l->n),r->algring);
     1165    omFreeBin((ADDRESS)l,  rnumber_bin);
     1166  }
     1167  *p = NULL;
     1168}
     1169
     1170/*2
     1171* copy p to erg
     1172*/
     1173number ntCopy(number p)
     1174{
     1175  if (p==NULL) return NULL;
     1176  ntTest(p);
     1177  lnumber erg;
     1178  lnumber src = (lnumber)p;
     1179  erg = (lnumber)omAlloc0Bin(rnumber_bin);
     1180  erg->z = p_Copy(src->z, nacRing);
     1181  erg->n = p_Copy(src->n, nacRing);
     1182  erg->s = src->s;
     1183  return (number)erg;
     1184}
     1185number nt_Copy(number p, const ring r)
     1186{
     1187  if (p==NULL) return NULL;
     1188  lnumber erg;
     1189  lnumber src = (lnumber)p;
     1190  erg = (lnumber)omAlloc0Bin(rnumber_bin);
     1191  erg->z = p_Copy(src->z,r->algring);
     1192  erg->n = p_Copy(src->n,r->algring);
     1193  erg->s = src->s;
     1194  return (number)erg;
     1195}
     1196
     1197/*2
     1198*  addition; lu:= la + lb
     1199*/
     1200number ntAdd(number la, number lb)
     1201{
     1202  if (la==NULL) return ntCopy(lb);
     1203  if (lb==NULL) return ntCopy(la);
     1204
     1205  napoly x, y;
     1206  lnumber lu;
     1207  lnumber a = (lnumber)la;
     1208  lnumber b = (lnumber)lb;
     1209  #ifdef LDEBUG
     1210  omCheckAddrSize(a,sizeof(snumber));
     1211  omCheckAddrSize(b,sizeof(snumber));
     1212  #endif
     1213  if (b->n!=NULL) x = pp_Mult_qq(a->z, b->n,nacRing);
     1214  else            x = napCopy(a->z);
     1215  if (a->n!=NULL) y = pp_Mult_qq(b->z, a->n,nacRing);
     1216  else            y = napCopy(b->z);
     1217  napoly res = napAdd(x, y);
     1218  if (res==NULL)
     1219  {
     1220    return (number)NULL;
     1221  }
     1222  lu = (lnumber)omAllocBin(rnumber_bin);
     1223  lu->z=res;
     1224  if (a->n!=NULL)
     1225  {
     1226    if (b->n!=NULL) x = pp_Mult_qq(a->n, b->n,nacRing);
     1227    else            x = napCopy(a->n);
     1228  }
     1229  else
     1230  {
     1231    if (b->n!=NULL) x = napCopy(b->n);
     1232    else            x = NULL;
     1233  }
     1234  //if (x!=NULL)
     1235  //{
     1236  //  if (p_LmIsConstant(x,nacRing))
     1237  //  {
     1238  //    number inv=ntcInvers(pGetCoeff(x));
     1239  //    napMultN(lu->z,inv);
     1240  //    n_Delete(&inv,nacRing);
     1241  //    napDelete(&x);
     1242  //  }
     1243  //}
     1244  lu->n = x;
     1245  lu->s = FALSE;
     1246  if (/*lu->n*/ x!=NULL)
     1247  {
     1248     number luu=(number)lu;
     1249     //if (p_IsConstant(lu->n,nacRing)) ntCoefNormalize(luu);
     1250     //else
     1251                ntNormalize(luu);
     1252     lu=(lnumber)luu;
     1253  }
     1254  //else lu->s=2;
     1255  ntTest((number)lu);
     1256  return (number)lu;
     1257}
     1258
     1259/*2
     1260*  subtraction; r:= la - lb
     1261*/
     1262number ntSub(number la, number lb)
     1263{
     1264  lnumber lu;
     1265
     1266  if (lb==NULL) return ntCopy(la);
     1267  if (la==NULL)
     1268  {
     1269    lu = (lnumber)ntCopy(lb);
     1270    lu->z = napNeg(lu->z);
     1271    return (number)lu;
     1272  }
     1273
     1274  lnumber a = (lnumber)la;
     1275  lnumber b = (lnumber)lb;
     1276
     1277  #ifdef LDEBUG
     1278  omCheckAddrSize(a,sizeof(snumber));
     1279  omCheckAddrSize(b,sizeof(snumber));
     1280  #endif
     1281
     1282  napoly x, y;
     1283  if (b->n!=NULL) x = pp_Mult_qq(a->z, b->n,nacRing);
     1284  else            x = napCopy(a->z);
     1285  if (a->n!=NULL) y = p_Mult_q(napCopy(b->z), napCopyNeg(a->n),nacRing);
     1286  else            y = napCopyNeg(b->z);
     1287  napoly res = napAdd(x, y);
     1288  if (res==NULL)
     1289  {
     1290    return (number)NULL;
     1291  }
     1292  lu = (lnumber)omAllocBin(rnumber_bin);
     1293  lu->z=res;
     1294  if (a->n!=NULL)
     1295  {
     1296    if (b->n!=NULL) x = pp_Mult_qq(a->n, b->n,nacRing);
     1297    else            x = napCopy(a->n);
     1298  }
     1299  else
     1300  {
     1301    if (b->n!=NULL) x = napCopy(b->n);
     1302    else            x = NULL;
     1303  }
     1304  lu->n = x;
     1305  lu->s = FALSE;
     1306  if (/*lu->n*/ x!=NULL)
     1307  {
     1308     number luu=(number)lu;
     1309     //if (p_IsConstant(lu->n,nacRing)) ntCoefNormalize(luu);
     1310     //else
     1311                         ntNormalize(luu);
     1312     lu=(lnumber)luu;
     1313  }
     1314  //else lu->s=2;
     1315  ntTest((number)lu);
     1316  return (number)lu;
     1317}
     1318
     1319/*2
     1320*  multiplication; r:= la * lb
     1321*/
     1322number ntMult(number la, number lb)
     1323{
     1324  if ((la==NULL) || (lb==NULL))
     1325    return NULL;
     1326
     1327  lnumber a = (lnumber)la;
     1328  lnumber b = (lnumber)lb;
     1329  lnumber lo;
     1330  napoly x;
     1331
     1332  #ifdef LDEBUG
     1333  omCheckAddrSize(a,sizeof(snumber));
     1334  omCheckAddrSize(b,sizeof(snumber));
     1335  #endif
     1336  ntTest(la);
     1337  ntTest(lb);
     1338
     1339  lo = (lnumber)omAllocBin(rnumber_bin);
     1340  lo->z = pp_Mult_qq(a->z, b->z,nacRing);
     1341
     1342  if (a->n==NULL)
     1343  {
     1344    if (b->n==NULL)
     1345      x = NULL;
     1346    else
     1347      x = napCopy(b->n);
     1348  }
     1349  else
     1350  {
     1351    if (b->n==NULL)
     1352    {
     1353      x = napCopy(a->n);
     1354    }
     1355    else
     1356    {
     1357      x = pp_Mult_qq(b->n, a->n, nacRing);
     1358    }
     1359  }
     1360  if (naI!=NULL)
     1361  {
     1362    lo->z = napRedp (lo->z);
     1363    if (lo->z != NULL)
     1364       lo->z = napTailred (lo->z);
     1365    if (x!=NULL)
     1366    {
     1367      x = napRedp (x);
     1368      if (x!=NULL)
     1369        x = napTailred (x);
     1370    }
     1371  }
     1372  if ((x!=NULL) && (p_LmIsConstant(x,nacRing)) && ntcIsOne(pGetCoeff(x)))
     1373    p_Delete(&x,nacRing);
     1374  lo->n = x;
     1375  lo->s = 0;
     1376  if(lo->z==NULL)
     1377  {
     1378    omFreeBin((ADDRESS)lo, rnumber_bin);
     1379    lo=NULL;
     1380  }
     1381  else if (lo->n!=NULL)
     1382  {
     1383    number luu=(number)lo;
     1384    // if (p_IsConstant(lo->n,nacRing)) ntCoefNormalize(luu);
     1385    // else
     1386                      ntNormalize(luu);
     1387    lo=(lnumber)luu;
     1388  }
     1389  //if (naMinimalPoly==NULL) lo->s=2;
     1390  ntTest((number)lo);
     1391  return (number)lo;
     1392}
     1393
     1394number ntIntDiv(number la, number lb)
     1395{
     1396  lnumber res;
     1397  lnumber a = (lnumber)la;
     1398  lnumber b = (lnumber)lb;
     1399  if (a==NULL)
     1400  {
     1401    return NULL;
     1402  }
     1403  if (b==NULL)
     1404  {
     1405    WerrorS(nDivBy0);
     1406    return NULL;
     1407  }
     1408  assume(a->z!=NULL && b->z!=NULL);
     1409  assume(a->n==NULL && b->n==NULL);
     1410  res = (lnumber)omAllocBin(rnumber_bin);
     1411  res->z = napCopy(a->z);
     1412  res->n = napCopy(b->z);
     1413  res->s = 0;
     1414  number nres=(number)res;
     1415  ntNormalize(nres);
     1416
     1417  //napDelete(&res->n);
     1418  ntTest(nres);
     1419  return nres;
     1420}
     1421
     1422/*2
     1423*  division; lo:= la / lb
     1424*/
     1425number ntDiv(number la, number lb)
     1426{
     1427  lnumber lo;
     1428  lnumber a = (lnumber)la;
     1429  lnumber b = (lnumber)lb;
     1430  napoly x;
     1431
     1432  if (a==NULL)
     1433    return NULL;
     1434
     1435  if (b==NULL)
     1436  {
     1437    WerrorS(nDivBy0);
     1438    return NULL;
     1439  }
     1440  #ifdef LDEBUG
     1441  omCheckAddrSize(a,sizeof(snumber));
     1442  omCheckAddrSize(b,sizeof(snumber));
     1443  #endif
     1444  lo = (lnumber)omAllocBin(rnumber_bin);
     1445  if (b->n!=NULL)
     1446    lo->z = pp_Mult_qq(a->z, b->n,nacRing);
     1447  else
     1448    lo->z = napCopy(a->z);
     1449  if (a->n!=NULL)
     1450    x = pp_Mult_qq(b->z, a->n, nacRing);
     1451  else
     1452    x = napCopy(b->z);
     1453  if (naI!=NULL)
     1454  {
     1455    lo->z = napRedp (lo->z);
     1456    if (lo->z != NULL)
     1457       lo->z = napTailred (lo->z);
     1458    if (x!=NULL)
     1459    {
     1460      x = napRedp (x);
     1461      if (x!=NULL)
     1462        x = napTailred (x);
     1463    }
     1464  }
     1465  if ((p_LmIsConstant(x,nacRing)) && ntcIsOne(pGetCoeff(x)))
     1466    p_Delete(&x,nacRing);
     1467  lo->n = x;
     1468  lo->s = 0;
     1469  if (lo->n!=NULL)
     1470  {
     1471    number luu=(number)lo;
     1472     //if (p_IsConstant(lo->n,nacRing)) ntCoefNormalize(luu);
     1473     //else
     1474                         ntNormalize(luu);
     1475    lo=(lnumber)luu;
     1476  }
     1477  //else lo->s=2;
     1478  ntTest((number)lo);
     1479  return (number)lo;
     1480}
     1481
     1482/*2
     1483*  za:= - za, inplace
     1484*/
     1485number ntNeg(number za)
     1486{
     1487  if (za!=NULL)
     1488  {
     1489    lnumber e = (lnumber)za;
     1490    ntTest(za);
     1491    e->z = napNeg(e->z);
     1492  }
     1493  return za;
     1494}
     1495
     1496/*2
     1497* 1/a
     1498*/
     1499number ntInvers(number a)
     1500{
     1501  lnumber lo;
     1502  lnumber b = (lnumber)a;
     1503  napoly x;
     1504
     1505  if (b==NULL)
     1506  {
     1507    WerrorS(nDivBy0);
     1508    return NULL;
     1509  }
     1510  #ifdef LDEBUG
     1511  omCheckAddrSize(b,sizeof(snumber));
     1512  #endif
     1513  lo = (lnumber)omAlloc0Bin(rnumber_bin);
     1514  lo->s = b->s;
     1515  if (b->n!=NULL)
     1516    lo->z = napCopy(b->n);
     1517  else
     1518    lo->z = p_ISet(1,nacRing);
     1519  x = b->z;
     1520  if ((!p_LmIsConstant(x,nacRing)) || !ntcIsOne(pGetCoeff(x)))
     1521    x = napCopy(x);
     1522  else
     1523  {
     1524    lo->n = NULL;
     1525    ntTest((number)lo);
     1526    return (number)lo;
     1527  }
     1528  lo->n = x;
     1529  if (lo->n!=NULL)
     1530  {
     1531     number luu=(number)lo;
     1532     //if (p_IsConstant(lo->n,nacRing)) ntCoefNormalize(luu);
     1533     //else
     1534                           ntNormalize(luu);
     1535     lo=(lnumber)luu;
     1536  }
     1537  ntTest((number)lo);
     1538  return (number)lo;
     1539}
     1540
     1541
     1542BOOLEAN ntIsZero(number za)
     1543{
     1544  lnumber zb = (lnumber)za;
     1545  ntTest(za);
     1546#ifdef LDEBUG
     1547  if ((zb!=NULL) && (zb->z==NULL)) WerrorS("internal zero error(2)");
     1548#endif
     1549  return (zb==NULL);
     1550}
     1551
     1552
     1553BOOLEAN ntGreaterZero(number za)
     1554{
     1555  lnumber zb = (lnumber)za;
     1556#ifdef LDEBUG
     1557  if ((zb!=NULL) && (zb->z==NULL)) WerrorS("internal zero error(3)");
     1558#endif
     1559  ntTest(za);
     1560  if (zb!=NULL)
     1561  {
     1562    return (ntcGreaterZero(pGetCoeff(zb->z))||(!p_LmIsConstant(zb->z,nacRing)));
     1563  }
     1564  /* else */ return FALSE;
     1565}
     1566
     1567
     1568/*2
     1569* a = b ?
     1570*/
     1571BOOLEAN ntEqual (number a, number b)
     1572{
     1573  if(a==b) return TRUE;
     1574  if((a==NULL)&&(b!=NULL)) return FALSE;
     1575  if((b==NULL)&&(a!=NULL)) return FALSE;
     1576
     1577  lnumber aa=(lnumber)a;
     1578  lnumber bb=(lnumber)b;
     1579
     1580  int an_deg=0;
     1581  if(aa->n!=NULL)
     1582    an_deg=napDeg(aa->n);
     1583  int bn_deg=0;
     1584  if(bb->n!=NULL)
     1585    bn_deg=napDeg(bb->n);
     1586  if(an_deg+napDeg(bb->z)!=bn_deg+napDeg(aa->z))
     1587    return FALSE;
     1588#if 0
     1589  ntNormalize(a);
     1590  aa=(lnumber)a;
     1591  ntNormalize(b);
     1592  bb=(lnumber)b;
     1593  if((aa->n==NULL)&&(bb->n!=NULL)) return FALSE;
     1594  if((bb->n==NULL)&&(aa->n!=NULL)) return FALSE;
     1595  if(napComp(aa->z,bb->z)!=0) return FALSE;
     1596  if((aa->n!=NULL) && (napComp(aa->n,bb->n))) return FALSE;
     1597#endif
     1598  number h = ntSub(a, b);
     1599  BOOLEAN bo = ntIsZero(h);
     1600  ntDelete(&h,currRing);
     1601  return bo;
     1602}
     1603
     1604
     1605BOOLEAN ntGreater (number a, number b)
     1606{
     1607  if (ntIsZero(a))
     1608    return FALSE;
     1609  if (ntIsZero(b))
     1610    return TRUE; /* a!= 0)*/
     1611  return napDeg(((lnumber)a)->z)>napDeg(((lnumber)b)->z);
     1612}
     1613
     1614/*2
     1615* reads a number
     1616*/
     1617const char  *ntRead(const char *s, number *p)
     1618{
     1619  napoly x;
     1620  lnumber a;
     1621  s = napRead(s, &x);
     1622  if (x==NULL)
     1623  {
     1624    *p = NULL;
     1625    return s;
     1626  }
     1627  *p = (number)omAlloc0Bin(rnumber_bin);
     1628  a = (lnumber)*p;
     1629  if (naI!=NULL)
     1630  {
     1631    a->z = napRedp(x);
     1632    if (a->z != NULL)
     1633      a->z = napTailred (a->z);
     1634  }
     1635  else
     1636    a->z = x;
     1637  if(a->z==NULL)
     1638  {
     1639    omFreeBin((ADDRESS)*p, rnumber_bin);
     1640    *p=NULL;
     1641  }
     1642  else
     1643  {
     1644    a->n = NULL;
     1645    a->s = 0;
     1646    ntTest(*p);
     1647  }
     1648  return s;
     1649}
     1650
     1651/*2
     1652* tries to convert a number to a name
     1653*/
     1654char * ntName(number n)
     1655{
     1656  lnumber ph = (lnumber)n;
     1657  if (ph==NULL)
     1658    return NULL;
     1659  int i;
     1660  char *s=(char *)omAlloc(4* ntNumbOfPar);
     1661  char *t=(char *)omAlloc(8);
     1662  s[0]='\0';
     1663  for (i = 0; i <= ntNumbOfPar - 1; i++)
     1664  {
     1665    int e=p_GetExp(ph->z,i+1,nacRing);
     1666    if (e > 0)
     1667    {
     1668      if (e >1)
     1669      {
     1670        sprintf(t,"%s%d",naParNames[i],e);
     1671        strcat(s,t);
     1672      }
     1673      else
     1674      {
     1675        strcat(s,naParNames[i]);
     1676      }
     1677    }
     1678  }
     1679  omFreeSize((ADDRESS)t,8);
     1680  if (s[0]=='\0')
     1681  {
     1682    omFree((ADDRESS)s);
     1683    return NULL;
     1684  }
     1685  return s;
     1686}
     1687
     1688/*2
     1689*  writes a number
     1690*/
     1691void ntWrite(number &phn, const ring r)
     1692{
     1693  lnumber ph = (lnumber)phn;
     1694  if (ph==NULL)
     1695    StringAppendS("0");
     1696  else
     1697  {
     1698    phn->s = 0;
     1699    BOOLEAN has_denom=(ph->n!=NULL);
     1700    napWrite(ph->z,has_denom/*(ph->n!=NULL)*/,r);
     1701    if (has_denom/*(ph->n!=NULL)*/)
     1702    {
     1703      StringAppendS("/");
     1704      napWrite(ph->n,TRUE,r);
     1705    }
     1706  }
     1707}
     1708
     1709/*2
     1710* za == 1 ?
     1711*/
     1712BOOLEAN ntIsOne(number za)
     1713{
     1714  lnumber a = (lnumber)za;
     1715  napoly x, y;
     1716  number t;
     1717  if (a==NULL) return FALSE;
     1718#ifdef LDEBUG
     1719  omCheckAddrSize(a,sizeof(snumber));
     1720  if (a->z==NULL)
     1721  {
     1722    WerrorS("internal zero error(4)");
     1723    return FALSE;
     1724  }
     1725#endif
     1726  if (a->n==NULL)
     1727  {
     1728    if (p_LmIsConstant(a->z,nacRing))
     1729    {
     1730      return ntcIsOne(pGetCoeff(a->z));
     1731    }
     1732    else                 return FALSE;
     1733  }
     1734#if 0
     1735  x = a->z;
     1736  y = a->n;
     1737  do
     1738  {
     1739    if (napComp(x, y))
     1740      return FALSE;
     1741    else
     1742    {
     1743      t = ntcSub(pGetCoeff(x), pGetCoeff(y));
     1744      if (!ntcIsZero(t))
     1745      {
     1746        n_Delete(&t,nacRing);
     1747        return FALSE;
     1748      }
     1749      else
     1750        n_Delete(&t,nacRing);
     1751    }
     1752    pIter(x);
     1753    pIter(y);
     1754  }
     1755  while ((x!=NULL) && (y!=NULL));
     1756  if ((x!=NULL) || (y!=NULL)) return FALSE;
     1757  p_Delete(&a->z,nacRing);
     1758  p_Delete(&a->n,nacRing);
     1759  a->z = p_ISet(1,nacRing);
     1760  a->n = NULL;
     1761  return TRUE;
     1762#else
     1763  return FALSE;
     1764#endif
     1765}
     1766
     1767/*2
     1768* za == -1 ?
     1769*/
     1770BOOLEAN ntIsMOne(number za)
     1771{
     1772  lnumber a = (lnumber)za;
     1773  napoly x, y;
     1774  number t;
     1775  if (a==NULL) return FALSE;
     1776#ifdef LDEBUG
     1777  omCheckAddrSize(a,sizeof(snumber));
     1778  if (a->z==NULL)
     1779  {
     1780    WerrorS("internal zero error(5)");
     1781    return FALSE;
     1782  }
     1783#endif
     1784  if (a->n==NULL)
     1785  {
     1786    if (p_LmIsConstant(a->z,nacRing)) return ntcIsMOne(pGetCoeff(a->z));
     1787    /*else                   return FALSE;*/
     1788  }
     1789  return FALSE;
     1790}
     1791
     1792/*2
     1793* returns the i-th power of p (i>=0)
     1794*/
     1795void ntPower(number p, int i, number *rc)
     1796{
     1797  number x;
     1798  *rc = ntInit(1,currRing);
     1799  for (; i > 0; i--)
     1800  {
     1801    x = ntMult(*rc, p);
     1802    ntDelete(rc,currRing);
     1803    *rc = x;
     1804  }
     1805}
     1806
     1807/*2
     1808* result =gcd(a,b)
     1809*/
     1810number ntGcd(number a, number b, const ring r)
     1811{
     1812  if (a==NULL)  return ntCopy(b);
     1813  if (b==NULL)  return ntCopy(a);
     1814
     1815  lnumber x, y;
     1816  lnumber result = (lnumber)omAlloc0Bin(rnumber_bin);
     1817
     1818  x = (lnumber)a;
     1819  y = (lnumber)b;
     1820#ifndef HAVE_FACTORY
     1821  result->z = napGcd(x->z, y->z); // change from napGcd0
     1822#else
     1823  int c=ABS(nGetChar());
     1824  if (c==1) c=0;
     1825  setCharacteristic( c );
     1826
     1827  napoly rz=napGcd(x->z, y->z);
     1828  CanonicalForm F, G, R;
     1829  R=convSingPFactoryP(rz,r->algring);
     1830  p_Normalize(x->z,nacRing);
     1831  F=convSingPFactoryP(x->z,r->algring)/R;
     1832  p_Normalize(y->z,nacRing);
     1833  G=convSingPFactoryP(y->z,r->algring)/R;
     1834  F = gcd( F, G );
     1835  if (F.isOne())
     1836    result->z= rz;
     1837  else
     1838  {
     1839    p_Delete(&rz,r->algring);
     1840    result->z=convFactoryPSingP( F*R,r->algring );
     1841    p_Normalize(result->z,nacRing);
     1842  }
     1843#endif
     1844  ntTest((number)result);
     1845  return (number)result;
     1846}
     1847
     1848
     1849/*2
     1850* ntNumbOfPar = 1:
     1851* clears denominator         algebraic case;
     1852* tries to simplify ratio    transcendental case;
     1853*
     1854* cancels monomials
     1855* occuring in denominator
     1856* and enumerator  ?          ntNumbOfPar != 1;
     1857*
     1858* #defines for Factory:
     1859* FACTORY_GCD_TEST: do not apply built in gcd for
     1860*   univariate polynomials, always use Factory
     1861*/
     1862//#define FACTORY_GCD_TEST
     1863void ntCoefNormalize(number pp)
     1864{
     1865  if (pp==NULL) return;
     1866  lnumber p = (lnumber)pp;
     1867  number nz; // all denom. of the numerator
     1868  nz=p_GetAllDenom(p->z,nacRing);
     1869  BOOLEAN norm=FALSE;
     1870  if (!n_IsOne(nz,nacRing))
     1871  {
     1872    norm=TRUE;
     1873    p->z=p_Mult_nn(p->z,nz,nacRing);
     1874    if (p->n==NULL)
     1875    {
     1876      p->n=p_NSet(nz,nacRing);
     1877    }
     1878    else
     1879    {
     1880      p->n=p_Mult_nn(p->n,nz,nacRing);
     1881      n_Delete(&nz, nacRing);
     1882    }
     1883  }
     1884  else
     1885  {
     1886    n_Delete(&nz, nacRing);
     1887  }
     1888  if (norm)
     1889  {
     1890    norm=FALSE;
     1891    p_Normalize(p->z,nacRing);
     1892    p_Normalize(p->n,nacRing);
     1893  }
     1894  number nn;
     1895  nn=p_GetAllDenom(p->n,nacRing);
     1896  if (!n_IsOne(nn,nacRing))
     1897  {
     1898    norm=TRUE;
     1899    p->n=p_Mult_nn(p->n,nn,nacRing);
     1900    p->z=p_Mult_nn(p->z,nn,nacRing);
     1901    n_Delete(&nn, nacRing);
     1902  }
     1903  else
     1904  {
     1905    n_Delete(&nn, nacRing);
     1906  }
     1907  if (norm)
     1908  {
     1909    p_Normalize(p->z,nacRing);
     1910    p_Normalize(p->n,nacRing);
     1911  }
     1912  // remove common factors in n, z:
     1913  if (p->n!=NULL)
     1914  {
     1915    poly pp=p->z;
     1916    nz=n_Copy(pGetCoeff(pp),nacRing);
     1917    pIter(pp);
     1918    while(pp!=NULL)
     1919    {
     1920      if (n_IsOne(nz,nacRing)) break;
     1921      number d=n_Gcd(nz,pGetCoeff(pp),nacRing);
     1922      n_Delete(&nz,nacRing); nz=d;
     1923      pIter(pp);
     1924    }
     1925    if (!n_IsOne(nz,nacRing))
     1926    {
     1927      pp=p->n;
     1928      nn=n_Copy(pGetCoeff(pp),nacRing);
     1929      pIter(pp);
     1930      while(pp!=NULL)
     1931      {
     1932        if (n_IsOne(nn,nacRing)) break;
     1933        number d=n_Gcd(nn,pGetCoeff(pp),nacRing);
     1934        n_Delete(&nn,nacRing); nn=d;
     1935        pIter(pp);
     1936      }
     1937      number ng=n_Gcd(nz,nn,nacRing);
     1938      n_Delete(&nn,nacRing);
     1939      if (!n_IsOne(ng,nacRing))
     1940      {
     1941        number ni=n_Invers(ng,nacRing);
     1942        p->z=p_Mult_nn(p->z,ni,nacRing);
     1943        p->n=p_Mult_nn(p->n,ni,nacRing);
     1944        p_Normalize(p->z,nacRing);
     1945        p_Normalize(p->n,nacRing);
     1946        n_Delete(&ni,nacRing);
     1947      }
     1948      n_Delete(&ng,nacRing);
     1949    }
     1950    n_Delete(&nz,nacRing);
     1951  }
     1952  if (p->n!=NULL)
     1953  {
     1954    if(!ntcGreaterZero(pGetCoeff(p->n)))
     1955    {
     1956      p->z=napNeg(p->z);
     1957      p->n=napNeg(p->n);
     1958    }
     1959
     1960    if (/*(p->n!=NULL) && */
     1961    (p_IsConstant(p->n,nacRing))
     1962    && (n_IsOne(pGetCoeff(p->n),nacRing)))
     1963    {
     1964      p_Delete(&(p->n), nacRing);
     1965      p->n = NULL;
     1966    }
     1967  }
     1968}
     1969
     1970void ntNormalize(number &pp)
     1971{
     1972
     1973  //ntTest(pp); // input may not be "normal"
     1974  lnumber p = (lnumber)pp;
     1975
     1976  if (p==NULL)
     1977    return;
     1978  ntCoefNormalize(pp);
     1979  p->s = 2;
     1980  napoly x = p->z;
     1981  napoly y = p->n;
     1982
     1983  BOOLEAN norm=FALSE;
     1984
     1985  if (y==NULL) return;
     1986
     1987  if ((x!=NULL) && (y!=NULL))
     1988  {
     1989    int i;
     1990    for (i=ntNumbOfPar-1; i>=0; i--)
     1991    {
     1992      napoly xx=x;
     1993      napoly yy=y;
     1994      int m = napExpi(i, yy, xx);
     1995      if (m != 0)          // in this case xx!=NULL!=yy
     1996      {
     1997        while (xx != NULL)
     1998        {
     1999          napAddExp(xx,i+1, -m);
     2000          pIter(xx);
     2001        }
     2002        while (yy != NULL)
     2003        {
     2004          napAddExp(yy,i+1, -m);
     2005          pIter(yy);
     2006        }
     2007      }
     2008    }
     2009  }
     2010  if (p_LmIsConstant(y,nacRing)) /* i.e. => simplify to (1/c)*z / monom */
     2011  {
     2012    if (ntcIsOne(pGetCoeff(y)))
     2013    {
     2014      p_LmDelete(&y,nacRing);
     2015      p->n = NULL;
     2016      ntTest(pp);
     2017      return;
     2018    }
     2019    number h1 = ntcInvers(pGetCoeff(y));
     2020    ntcNormalize(h1);
     2021    napMultN(x, h1);
     2022    n_Delete(&h1,nacRing);
     2023    p_LmDelete(&y,nacRing);
     2024    p->n = NULL;
     2025    ntTest(pp);
     2026    return;
     2027  }
     2028#ifndef FACTORY_GCD_TEST
     2029  if (ntNumbOfPar == 1) /* apply built-in gcd */
     2030  {
     2031    napoly x1,y1;
     2032    if (p_GetExp(x,1,nacRing) >= p_GetExp(y,1,nacRing))
     2033    {
     2034      x1 = napCopy(x);
     2035      y1 = napCopy(y);
     2036    }
     2037    else
     2038    {
     2039      x1 = napCopy(y);
     2040      y1 = napCopy(x);
     2041    }
     2042    napoly r;
     2043    loop
     2044    {
     2045      r = ntRemainder(x1, y1);
     2046      if ((r==NULL) || (pNext(r)==NULL)) break;
     2047      x1 = y1;
     2048      y1 = r;
     2049    }
     2050    if (r!=NULL)
     2051    {
     2052      p_Delete(&r,nacRing);
     2053      p_Delete(&y1,nacRing);
     2054    }
     2055    else
     2056    {
     2057      napDivMod(x, y1, &(p->z), &r);
     2058      napDivMod(y, y1, &(p->n), &r);
     2059      p_Delete(&y1,nacRing);
     2060    }
     2061    x = p->z;
     2062    y = p->n;
     2063    /* collect all denoms from y and multiply x and y by it */
     2064    if (ntIsChar0)
     2065    {
     2066      number n=napLcm(y);
     2067      napMultN(x,n);
     2068      napMultN(y,n);
     2069      n_Delete(&n,nacRing);
     2070      while(x!=NULL)
     2071      {
     2072        ntcNormalize(pGetCoeff(x));
     2073        pIter(x);
     2074      }
     2075      x = p->z;
     2076      while(y!=NULL)
     2077      {
     2078        ntcNormalize(pGetCoeff(y));
     2079        pIter(y);
     2080      }
     2081      y = p->n;
     2082    }
     2083    if (pNext(y)==NULL)
     2084    {
     2085      if (ntcIsOne(pGetCoeff(y)))
     2086      {
     2087        if (p_GetExp(y,1,nacRing)==0)
     2088        {
     2089          p_LmDelete(&y,nacRing);
     2090          p->n = NULL;
     2091        }
     2092        ntTest(pp);
     2093        return;
     2094      }
     2095    }
     2096  }
     2097#endif /* FACTORY_GCD_TEST */
     2098#ifdef HAVE_FACTORY
     2099#ifndef FACTORY_GCD_TEST
     2100  else
     2101#endif
     2102  {
     2103    napoly xx,yy;
     2104    singclap_algdividecontent(x,y,xx,yy);
     2105    if (xx!=NULL)
     2106    {
     2107      p->z=xx;
     2108      p->n=yy;
     2109      p_Delete(&x,nacRing);
     2110      p_Delete(&y,nacRing);
     2111    }
     2112  }
     2113#endif
     2114  /* remove common factors from z and n */
     2115  x=p->z;
     2116  y=p->n;
     2117  if(!ntcGreaterZero(pGetCoeff(y)))
     2118  {
     2119    x=napNeg(x);
     2120    y=napNeg(y);
     2121  }
     2122  number g=ntcCopy(pGetCoeff(x));
     2123  pIter(x);
     2124  while (x!=NULL)
     2125  {
     2126    number d=ntcGcd(g,pGetCoeff(x), nacRing);
     2127    if(ntcIsOne(d))
     2128    {
     2129      n_Delete(&g,nacRing);
     2130      n_Delete(&d,nacRing);
     2131      ntTest(pp);
     2132      return;
     2133    }
     2134    n_Delete(&g,nacRing);
     2135    g = d;
     2136    pIter(x);
     2137  }
     2138  while (y!=NULL)
     2139  {
     2140    number d=ntcGcd(g,pGetCoeff(y), nacRing);
     2141    if(ntcIsOne(d))
     2142    {
     2143      n_Delete(&g,nacRing);
     2144      n_Delete(&d,nacRing);
     2145      ntTest(pp);
     2146      return;
     2147    }
     2148    n_Delete(&g,nacRing);
     2149    g = d;
     2150    pIter(y);
     2151  }
     2152  x=p->z;
     2153  y=p->n;
     2154  while (x!=NULL)
     2155  {
     2156    number d = ntcIntDiv(pGetCoeff(x),g);
     2157    napSetCoeff(x,d);
     2158    pIter(x);
     2159  }
     2160  while (y!=NULL)
     2161  {
     2162    number d = ntcIntDiv(pGetCoeff(y),g);
     2163    napSetCoeff(y,d);
     2164    pIter(y);
     2165  }
     2166  n_Delete(&g,nacRing);
     2167  ntTest(pp);
     2168}
     2169
     2170/*2
     2171* returns in result->n 1
     2172* and in     result->z the lcm(a->z,b->n)
     2173*/
     2174number ntLcm(number la, number lb, const ring r)
     2175{
     2176  lnumber result;
     2177  lnumber a = (lnumber)la;
     2178  lnumber b = (lnumber)lb;
     2179  result = (lnumber)omAlloc0Bin(rnumber_bin);
     2180  //if (((naMinimalPoly==NULL) && (naI==NULL)) || !ntIsChar0)
     2181  //{
     2182  //  result->z = p_ISet(1,nacRing);
     2183  //  return (number)result;
     2184  //}
     2185  //ntNormalize(lb);
     2186  ntTest(la);
     2187  ntTest(lb);
     2188  napoly x = p_Copy(a->z, r->algring);
     2189  number t = napLcm(b->z); // get all denom of b->z
     2190  if (!ntcIsOne(t))
     2191  {
     2192    number bt, rr;
     2193    napoly xx=x;
     2194    while (xx!=NULL)
     2195    {
     2196      bt = ntcGcd(t, pGetCoeff(xx), r->algring);
     2197      rr = ntcMult(t, pGetCoeff(xx));
     2198      n_Delete(&pGetCoeff(xx),r->algring);
     2199      pGetCoeff(xx) = ntcDiv(rr, bt);
     2200      ntcNormalize(pGetCoeff(xx));
     2201      n_Delete(&bt,r->algring);
     2202      n_Delete(&rr,r->algring);
     2203      pIter(xx);
     2204    }
     2205  }
     2206  n_Delete(&t,r->algring);
     2207  result->z = x;
     2208#ifdef HAVE_FACTORY
     2209  if (b->n!=NULL)
     2210  {
     2211    result->z=singclap_alglcm(result->z,b->n);
     2212    p_Delete(&x,r->algring);
     2213  }
     2214#endif
     2215  ntTest(la);
     2216  ntTest(lb);
     2217  ntTest((number)result);
     2218  return ((number)result);
     2219}
     2220
     2221/*2
     2222* map Z/p -> Q(a)
     2223*/
     2224number ntMapP0(number c)
     2225{
     2226  if (npIsZero(c)) return NULL;
     2227  lnumber l=(lnumber)omAllocBin(rnumber_bin);
     2228  l->s=2;
     2229  l->z=(napoly)p_Init(nacRing);
     2230  int i=(int)((long)c);
     2231  if (i>((long)ntMapRing->ch>>2)) i-=(long)ntMapRing->ch;
     2232  pGetCoeff(l->z)=nlInit(i, nacRing);
     2233  l->n=NULL;
     2234  return (number)l;
     2235}
     2236
     2237/*2
     2238* map Q -> Q(a)
     2239*/
     2240number ntMap00(number c)
     2241{
     2242  if (nlIsZero(c)) return NULL;
     2243  lnumber l=(lnumber)omAllocBin(rnumber_bin);
     2244  l->s=0;
     2245  l->z=(napoly)p_Init(nacRing);
     2246  pGetCoeff(l->z)=nlCopy(c);
     2247  l->n=NULL;
     2248  return (number)l;
     2249}
     2250
     2251/*2
     2252* map Z/p -> Z/p(a)
     2253*/
     2254number ntMapPP(number c)
     2255{
     2256  if (npIsZero(c)) return NULL;
     2257  lnumber l=(lnumber)omAllocBin(rnumber_bin);
     2258  l->s=2;
     2259  l->z=(napoly)p_Init(nacRing);
     2260  pGetCoeff(l->z)=c; /* omit npCopy, because npCopy is a no-op */
     2261  l->n=NULL;
     2262  return (number)l;
     2263}
     2264
     2265/*2
     2266* map Z/p' -> Z/p(a)
     2267*/
     2268number ntMapPP1(number c)
     2269{
     2270  if (npIsZero(c)) return NULL;
     2271  int i=(int)((long)c);
     2272  if (i>(long)ntMapRing->ch) i-=(long)ntMapRing->ch;
     2273  number n=npInit(i,ntMapRing);
     2274  if (npIsZero(n)) return NULL;
     2275  lnumber l=(lnumber)omAllocBin(rnumber_bin);
     2276  l->s=2;
     2277  l->z=(napoly)p_Init(nacRing);
     2278  pGetCoeff(l->z)=n;
     2279  l->n=NULL;
     2280  return (number)l;
     2281}
     2282
     2283/*2
     2284* map Q -> Z/p(a)
     2285*/
     2286number ntMap0P(number c)
     2287{
     2288  if (nlIsZero(c)) return NULL;
     2289  number n=npInit(nlModP(c,npPrimeM),nacRing);
     2290  if (npIsZero(n)) return NULL;
     2291  npTest(n);
     2292  lnumber l=(lnumber)omAllocBin(rnumber_bin);
     2293  l->s=2;
     2294  l->z=(napoly)p_Init(nacRing);
     2295  pGetCoeff(l->z)=n;
     2296  l->n=NULL;
     2297  return (number)l;
     2298}
     2299
     2300/*2
     2301* map _(a) -> _(b)
     2302*/
     2303number ntMapQaQb(number c)
     2304{
     2305  if (c==NULL) return NULL;
     2306  lnumber erg= (lnumber)omAlloc0Bin(rnumber_bin);
     2307  lnumber src =(lnumber)c;
     2308  erg->s=src->s;
     2309  erg->z=napMap(src->z);
     2310  erg->n=napMap(src->n);
     2311  return (number)erg;
     2312}
     2313
     2314nMapFunc ntSetMap(const ring src, const ring dst)
     2315{
     2316  ntMapRing=src;
     2317  if (rField_is_Q_a(dst)) /* -> Q(a) */
     2318  {
     2319    if (rField_is_Q(src))
     2320    {
     2321      return ntMap00;   /*Q -> Q(a)*/
     2322    }
     2323    if (rField_is_Zp(src))
     2324    {
     2325      return ntMapP0;  /* Z/p -> Q(a)*/
     2326    }
     2327    if (rField_is_Q_a(src))
     2328    {
     2329      int i;
     2330      ntParsToCopy=0;
     2331      for(i=0;i<rPar(src);i++)
     2332      {
     2333        if ((i>=rPar(dst))
     2334        ||(strcmp(src->parameter[i],dst->parameter[i])!=0))
     2335           return NULL;
     2336        ntParsToCopy++;
     2337      }
     2338      ntcMap=ntcCopy;
     2339      if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src)))
     2340        return ntCopy;    /* Q(a) -> Q(a) */
     2341      return ntMapQaQb;   /* Q(a..) -> Q(a..) */
     2342    }
     2343  }
     2344  /*-----------------------------------------------------*/
     2345  if (rField_is_Zp_a(dst)) /* -> Z/p(a) */
     2346  {
     2347    if (rField_is_Q(src))
     2348    {
     2349      return ntMap0P;   /*Q -> Z/p(a)*/
     2350    }
     2351    if (rField_is_Zp(src))
     2352    {
     2353      if (src->ch==dst->ch)
     2354      {
     2355        return ntMapPP;  /* Z/p -> Z/p(a)*/
     2356      }
     2357      else
     2358      {
     2359        return ntMapPP1;  /* Z/p' -> Z/p(a)*/
     2360      }
     2361    }
     2362    if (rField_is_Zp_a(src))
     2363    {
     2364      if (rChar(src)==rChar(dst))
     2365      {
     2366        ntcMap=ntcCopy;
     2367      }
     2368      else
     2369      {
     2370        ntcMap = npMapP;
     2371      }
     2372      int i;
     2373      ntParsToCopy=0;
     2374      for(i=0;i<rPar(src);i++)
     2375      {
     2376        if ((i>=rPar(dst))
     2377        ||(strcmp(src->parameter[i],dst->parameter[i])!=0))
     2378           return NULL;
     2379        ntParsToCopy++;
     2380      }
     2381      if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src))
     2382      && (ntcMap==ntcCopy))
     2383        return ntCopy;    /* Z/p(a) -> Z/p(a) */
     2384      return ntMapQaQb;   /* Z/p(a),Z/p'(a) -> Z/p(b)*/
     2385    }
     2386  }
     2387  return NULL;      /* default */
     2388}
     2389
     2390/*2
     2391* convert a napoly number into a poly
     2392*/
     2393poly ntPermNumber(number z, int * par_perm, int P, ring oldRing)
     2394{
     2395  if (z==NULL) return NULL;
     2396  poly res=NULL;
     2397  poly p;
     2398  napoly za=((lnumber)z)->z;
     2399  napoly zb=((lnumber)z)->n;
     2400  nMapFunc nMap=ntSetMap(oldRing,currRing);
     2401  if (currRing->parameter!=NULL)
     2402    nMap=currRing->algring->cf->cfSetMap(oldRing->algring, nacRing);
     2403  else
     2404    nMap=currRing->cf->cfSetMap(oldRing->algring, currRing);
     2405  if (nMap==NULL) return NULL; /* emergency exit only */
     2406  do
     2407  {
     2408    p = pInit();
     2409    pNext(p)=NULL;
     2410    nNew(&pGetCoeff(p));
     2411    int i;
     2412    for(i=pVariables;i;i--)
     2413       pSetExp(p,i, 0);
     2414    if (rRing_has_Comp(currRing)) pSetComp(p, 0);
     2415    napoly pa=NULL;
     2416    lnumber pan;
     2417    if (currRing->parameter!=NULL)
     2418    {
     2419      assume(oldRing->algring!=NULL);
     2420      pGetCoeff(p)=(number)omAlloc0Bin(rnumber_bin);
     2421      pan=(lnumber)pGetCoeff(p);
     2422      pan->s=2;
     2423      pan->z=napInitz(nMap(pGetCoeff(za)));
     2424      pa=pan->z;
     2425    }
     2426    else
     2427    {
     2428      pGetCoeff(p)=nMap(pGetCoeff(za));
     2429    }
     2430    for(i=0;i<P;i++)
     2431    {
     2432      if(napGetExpFrom(za,i+1,oldRing)!=0)
     2433      {
     2434        if(par_perm==NULL)
     2435        {
     2436          if ((rPar(currRing)>=i) && (pa!=NULL))
     2437          {
     2438            napSetExp(pa,i+1,napGetExpFrom(za,i+1,oldRing));
     2439            p_Setm(pa,nacRing);
     2440          }
     2441          else
     2442          {
     2443            pDelete(&p);
     2444            break;
     2445          }
     2446        }
     2447        else if(par_perm[i]>0)
     2448          pSetExp(p,par_perm[i],napGetExpFrom(za,i+1,oldRing));
     2449        else if((par_perm[i]<0)&&(pa!=NULL))
     2450        {
     2451          napSetExp(pa,-par_perm[i], napGetExpFrom(za,i+1,oldRing));
     2452          p_Setm(pa,nacRing);
     2453        }
     2454        else
     2455        {
     2456          pDelete(&p);
     2457          break;
     2458        }
     2459      }
     2460    }
     2461    if (p!=NULL)
     2462    {
     2463      pSetm(p);
     2464      if (zb!=NULL)
     2465      {
     2466        if  (currRing->P>0)
     2467        {
     2468          pan->n=napPerm(zb,par_perm,oldRing,nMap);
     2469          if(pan->n==NULL) /* error in mapping or mapping to variable */
     2470            pDelete(&p);
     2471        }
     2472        else
     2473          pDelete(&p);
     2474      }
     2475      pTest(p);
     2476      res=pAdd(res,p);
     2477    }
     2478    pIter(za);
     2479  }
     2480  while (za!=NULL);
     2481  pTest(res);
     2482  return res;
     2483}
     2484
    23352485number   ntGetDenom(number &n, const ring r)
    23362486{
  • kernel/longtrans.h

    ra33266 r661c214  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: longtrans.cc 12469 2011-02-25 13:38:49Z seelisch $ */
     6/* $Id: longtrans.h 12469 2011-02-25 13:38:49Z seelisch $ */
    77/*
    88* ABSTRACT:   numbers in transcendental field extensions, i.e.,
     
    1212#include <kernel/longrat.h>
    1313#include <kernel/polys-impl.h>
    14 #include <kernel/longalg.h>
    1514
    16 extern ring ntcRing;
     15typedef polyrec * napoly;
    1716
     17struct slnumber;
     18typedef struct slnumber * lnumber;
    1819
    19 void ntSetChar(int p, ring r);
     20struct slnumber
     21{
     22  napoly z;
     23  napoly n;
     24  BOOLEAN s;
     25};
     26
     27extern int ntNumbOfPar;
     28#define naParNames (currRing->parameter)
     29extern ring nacRing;
     30extern int ntIsChar0;
     31extern ring ntMapRing;
     32extern int ntParsToCopy;
     33
     34void    ntSetChar(int p, ring r);
    2035void    ntDelete (number *p, const ring r);
    2136number  ntInit(int i, const ring r);                /* z := i */
     
    5368BOOLEAN ntDBTest(number a, const char *f,const int l);
    5469#endif
     70napoly ntRemainder(napoly f, const napoly  g);
     71void    ntSetIdeal(ideal I);
     72extern number (*ntMap)(number from);
     73void ntCoefNormalize(number pp);
    5574
    56 void    ntSetIdeal(ideal I);
     75/* procedure variables for operations in coefficient field/ring */
     76extern numberfunc ntcMult, ntcSub, ntcAdd, ntcDiv, ntcIntDiv;
     77extern number   (*ntcGcd)(number a, number b, const ring r);
     78extern number   (*ntcLcm)(number a, number b, const ring r);
     79extern number   (*ntcInit)(int i, const ring r);
     80extern int      (*ntcInt)(number &n, const ring r);
     81extern void     (*ntcDelete)(number *a, const ring r);
     82#undef n_Delete
     83#define n_Delete(A,R) ntcDelete(A,R)
     84extern void     (*ntcNormalize)(number &a);
     85extern number   (*ntcNeg)(number a);
     86extern number   (*ntcCopy)(number a);
     87extern number   (*ntcInvers)(number a);
     88extern BOOLEAN  (*ntcIsZero)(number a);
     89extern BOOLEAN  (*ntcIsOne)(number a);
     90extern BOOLEAN  (*ntcIsMOne)(number a);
     91extern BOOLEAN  (*ntcGreaterZero)(number a);
     92extern const char   * (*ntcRead) (const char *s, number *a);
     93extern number (*ntcMap)(number);
     94
     95// external access to the interna
     96poly napPermNumber(number z, int * par_perm, int P, ring r);
     97#define napAddExp(p,i,e)       (p_AddExp(p,i,e,currRing->algring))
     98#define napLength(p)           pLength(p)
     99#define napNeg(p)              (p_Neg(p,currRing->algring))
     100#define napVariables           naNumbOfPar
     101#define napGetCoeff(p)         pGetCoeff(p)
     102#define napGetExpFrom(p,i,r)   (p_GetExp(p,i,r->algring))
     103#define napSetExp(p,i,e)       (p_SetExp(p,i,e,currRing->algring))
     104#define napNew()               (p_Init(currRing->algring))
     105#define napAdd(p1,p2)          (p_Add_q(p1,p2,currRing->algring))
     106#define napSetm(p)             p_Setm(p,currRing->algring)
     107#define napCopy(p)             p_Copy(p,nacRing)
     108#define napSetCoeff(p,n)       {n_Delete(&pGetCoeff(p),nacRing);pGetCoeff(p)=n;}
     109#define napComp(p,q)           p_LmCmp((poly)p,(poly)q, nacRing)
     110#define napMultT(A,E)          A=(napoly)p_Mult_mm((poly)A,(poly)E,nacRing)
     111#define napDeg(p)              (int)p_Totaldegree(p, nacRing)
     112number napGetDenom(number &n, const ring r);
     113number napGetNumerator(number &n, const ring r);
     114void napTest(napoly p);
     115napoly napInitz(number z);
     116napoly napCopyNeg(napoly p);
     117void napMultN(napoly p, number z);
     118void napDivMod(napoly f, napoly  g, napoly *q, napoly *r);
     119napoly napInvers(napoly x, const napoly c);
     120int  napMaxDeg(napoly p);
     121int  napMaxDegLen(napoly p, int &l);
     122void napWrite(napoly p,const BOOLEAN has_denom, const ring r);
     123const char *napHandleMons(const char *s, int i, napoly ex);
     124const char *napHandlePars(const char *s, int i, napoly ex);
     125const char  *napRead(const char *s, napoly *b);
     126int napExp(napoly a, napoly b);
     127int napExpi(int i, napoly a, napoly b);
     128void napContent(napoly ph);
     129void napCleardenom(napoly ph);
     130napoly napGcd0(napoly a, napoly b);
     131napoly napGcd(napoly a, napoly b);
     132number napLcm(napoly a);
     133BOOLEAN napDivPoly (napoly p, napoly q);
     134napoly napRedp (napoly q);
     135napoly napTailred (napoly q);
     136napoly napMap(napoly p);
     137napoly napPerm(napoly p,const int *par_perm,const ring src_ring,const nMapFunc nMap);
    57138
    58139#endif
  • kernel/maps.cc

    ra33266 r661c214  
    1717#include <omalloc/omalloc.h>
    1818#include <kernel/kstd1.h>
    19 #include <kernel/longalg.h>
     19#include <kernel/longtrans.h>
    2020#include <kernel/maps.h>
    2121#include <kernel/prCopy.h>
  • kernel/numbers.cc

    ra33266 r661c214  
    140140  else if (rField_is_Extension(r))
    141141  {
    142     if (r->minpoly == NULL)
     142    if (r->minpoly != NULL)
    143143    {
    144144      naSetChar(c,r);
     
    321321  if (rField_is_Extension(r))
    322322  {
    323     //naInitChar(c,TRUE,r);
    324     n->cfDelete       = naDelete;
    325     n-> nNormalize    = naNormalize;
    326     n->cfInit         = naInit;
    327     n->nPar           = naPar;
    328     n->nParDeg        = naParDeg;
    329     n->n_Int          = naInt;
    330     n->nAdd           = naAdd;
    331     n->nSub           = naSub;
    332     n->nMult          = naMult;
    333     n->nDiv           = naDiv;
    334     n->nExactDiv      = naDiv;
    335     n->nIntDiv        = naIntDiv;
    336     n->nNeg           = naNeg;
    337     n->nInvers        = naInvers;
    338     n->nCopy          = naCopy;
    339     n->cfCopy         = na_Copy;
    340     n->nGreater       = naGreater;
    341     n->nEqual         = naEqual;
    342     n->nIsZero        = naIsZero;
    343     n->nIsOne         = naIsOne;
    344     n->nIsMOne        = naIsMOne;
    345     n->nGreaterZero   = naGreaterZero;
    346     n->cfWrite        = naWrite;
    347     n->nRead          = naRead;
    348     n->nPower         = naPower;
    349     n->nGcd           = naGcd;
    350     n->nLcm           = naLcm;
    351     n->cfSetMap       = naSetMap;
    352     n->nName          = naName;
    353     n->nSize          = naSize;
    354     n->cfGetDenom     = naGetDenom;
    355     n->cfGetNumerator = naGetNumerator;
    356 #ifdef LDEBUG
    357     n->nDBTest        = naDBTest;
     323    //ntInitChar(c,TRUE,r);
     324    n->cfDelete       = ntDelete;
     325    n->nNormalize     = ntNormalize;
     326    n->cfInit         = ntInit;
     327    n->nPar           = ntPar;
     328    n->nParDeg        = ntParDeg;
     329    n->n_Int          = ntInt;
     330    n->nAdd           = ntAdd;
     331    n->nSub           = ntSub;
     332    n->nMult          = ntMult;
     333    n->nDiv           = ntDiv;
     334    n->nExactDiv      = ntDiv;
     335    n->nIntDiv        = ntIntDiv;
     336    n->nNeg           = ntNeg;
     337    n->nInvers        = ntInvers;
     338    n->nCopy          = ntCopy;
     339    n->cfCopy         = nt_Copy;
     340    n->nGreater       = ntGreater;
     341    n->nEqual         = ntEqual;
     342    n->nIsZero        = ntIsZero;
     343    n->nIsOne         = ntIsOne;
     344    n->nIsMOne        = ntIsMOne;
     345    n->nGreaterZero   = ntGreaterZero;
     346    n->cfWrite        = ntWrite;
     347    n->nRead          = ntRead;
     348    n->nPower         = ntPower;
     349    n->nGcd           = ntGcd;
     350    n->nLcm           = ntLcm;
     351    n->cfSetMap       = ntSetMap;
     352    n->nName          = ntName;
     353    n->nSize          = ntSize;
     354    n->cfGetDenom     = napGetDenom;
     355    n->cfGetNumerator = napGetNumerator;
     356#ifdef LDEBUG
     357    n->nDBTest        = ntDBTest;
    358358#endif
    359359  }
  • kernel/polys1.cc

    ra33266 r661c214  
    2020#include <kernel/intvec.h>
    2121#include <kernel/longalg.h>
     22#include <kernel/longtrans.h>
    2223#include <kernel/ring.h>
    2324#include <kernel/ideals.h>
     
    12371238    {
    12381239      qq=pOne();
    1239       aq=naPermNumber(pGetCoeff(p),par_perm,OldPar, oldRing);
     1240      aq=napPermNumber(pGetCoeff(p),par_perm,OldPar, oldRing);
    12401241      if ((currRing->minpoly!=NULL)
    12411242      && ((rField_is_Zp_a()) || (rField_is_Q_a())))
  • kernel/ring.cc

    ra33266 r661c214  
    1818#include <kernel/febase.h>
    1919#include <kernel/intvec.h>
    20 #include <kernel/longalg.h>
     20#include <kernel/longtrans.h>
    2121#include <kernel/ffields.h>
    2222#include <kernel/ideals.h>
Note: See TracChangeset for help on using the changeset viewer.