Index: kernel/longalg.cc
===================================================================
--- kernel/longalg.cc	(revision 43c57185bbe2457782485ecda44d8025a86ca320)
+++ kernel/longalg.cc	(revision b3af9332ce7b8a001aebc6b801c0baa452306ede)
@@ -2,10 +2,7 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: longalg.cc,v 1.47 2009-08-14 17:14:30 Singular Exp $ */
+/* $Id: longalg.cc,v 1.48 2009-08-21 10:55:46 Singular Exp $ */
 /*
 * ABSTRACT:   algebraic numbers
-* convention: A) minpoly==0: n->z, n->n are from Z[a] resp. Z/p[a],
-*                no common div., L(n->n) >0 (or n->n==NULL)
-*             B) minpoly!=NULL: n->z from k[a], n->n==NULL
 */
 
@@ -31,6 +28,8 @@
 naIdeal naI=NULL;
 
+int naNumbOfPar;
 napoly naMinimalPoly;
 #define naParNames (currRing->parameter)
+#define napNormalize(p) p_Normalize(p,nacRing)
 static int naIsChar0;
 static int naPrimeM;
@@ -49,4 +48,5 @@
 static number   (*nacGcd)(number a, number b, const ring r);
 static number   (*nacLcm)(number a, number b, const ring r);
+static void     (*nacDelete)(number *a, const ring r);
        number   (*nacInit)(int i);
 static int      (*nacInt)(number &n);
@@ -66,4 +66,12 @@
 static int napExpi(int i, napoly a, napoly b);
        ring nacRing;
+static inline void naNormalize0(number &pp)
+{
+  lnumber p = (lnumber)pp;
+  if ((p!=NULL) && (p->z!=NULL))
+  {
+      naNormalize(pp);
+  }
+}
 
 #define napCopy(p)       (napoly)p_Copy((poly)p,nacRing)
@@ -106,4 +114,5 @@
   }
 
+  naNumbOfPar=rPar(r);
   if (i == 1)
   {
@@ -137,4 +146,5 @@
   nacGcd         = nacRing->cf->nGcd;
   nacLcm         = nacRing->cf->nLcm;
+  nacDelete      = nacRing->cf->cfDelete;
   nacMult        = nacRing->cf->nMult;
   nacDiv         = nacRing->cf->nDiv;
@@ -153,5 +163,5 @@
   {
     if (naIsChar0)
-      nlDBTest(napGetCoeff(p), "", 0);
+      nlDBTest(pGetCoeff(p), "", 0);
     pIter(p);
   }
@@ -162,5 +172,5 @@
 
 #define napInit(i)       (napoly)p_ISet(i,nacRing)
-#define napSetCoeff(p,n) p_SetCoeff(p,n,nacRing);
+#define napSetCoeff(p,n) {nacDelete(&pGetCoeff(p),nacRing);pGetCoeff(p)=n;}
 #define napDelete1(p)    p_LmDelete((poly *)p, nacRing)
 #define nap_Copy(p,r)       (napoly)p_Copy((poly)p,r->algring)
@@ -178,5 +188,5 @@
 {
   napoly a = (napoly)p_Init(nacRing);
-  napGetCoeff(a) = z;
+  pGetCoeff(a) = z;
   return a;
 }
@@ -193,4 +203,21 @@
 
 /*3
+* returns ph * z
+*/
+static void napMultN(napoly p, number z)
+{
+  number t;
+
+  while (p!=NULL)
+  {
+    t = nacMult(pGetCoeff(p), z);
+    nacNormalize(t);
+    nacDelete(&pGetCoeff(p),nacRing);
+    pGetCoeff(p) = t;
+    pIter(p);
+  }
+}
+
+/*3
 *  division with rest; f = g*q + r, returns r and destroy f
 */
@@ -201,6 +228,6 @@
   qq = (napoly)p_Init(nacRing);
   pNext(qq) = NULL;
-  p_Normalize(g,nacRing);
-  p_Normalize(f,nacRing);
+  napNormalize(g);
+  napNormalize(f);
   a = f;
   do
@@ -208,11 +235,11 @@
     napSetExp(qq,1, napGetExp(a,1) - napGetExp(g,1));
     napSetm(qq);
-    napGetCoeff(qq) = nacDiv(napGetCoeff(a), napGetCoeff(g));
-    napGetCoeff(qq) = nacNeg(napGetCoeff(qq));
-    nacNormalize(napGetCoeff(qq));
+    pGetCoeff(qq) = nacDiv(pGetCoeff(a), pGetCoeff(g));
+    pGetCoeff(qq) = nacNeg(pGetCoeff(qq));
+    nacNormalize(pGetCoeff(qq));
     h = napCopy(g);
     napMultT(h, qq);
-    p_Normalize(h,nacRing);
-    n_Delete(&napGetCoeff(qq),nacRing);
+    napNormalize(h);
+    nacDelete(&pGetCoeff(qq),nacRing);
     a = napAdd(a, h);
   }
@@ -231,6 +258,6 @@
   qq = (napoly)p_Init(nacRing);
   pNext(qq) = b = NULL;
-  p_Normalize(g,nacRing);
-  p_Normalize(f,nacRing);
+  napNormalize(g);
+  napNormalize(f);
   a = f;
   do
@@ -238,12 +265,12 @@
     napSetExp(qq,1, napGetExp(a,1) - napGetExp(g,1));
     p_Setm(qq,nacRing);
-    napGetCoeff(qq) = nacDiv(napGetCoeff(a), napGetCoeff(g));
-    nacNormalize(napGetCoeff(qq));
+    pGetCoeff(qq) = nacDiv(pGetCoeff(a), pGetCoeff(g));
+    nacNormalize(pGetCoeff(qq));
     b = napAdd(b, napCopy(qq));
-    napGetCoeff(qq) = nacNeg(napGetCoeff(qq));
+    pGetCoeff(qq) = nacNeg(pGetCoeff(qq));
     h = napCopy(g);
     napMultT(h, qq);
-    p_Normalize(h,nacRing);
-    n_Delete(&napGetCoeff(qq),nacRing);
+    napNormalize(h);
+    nacDelete(&pGetCoeff(qq),nacRing);
     a = napAdd(a, h);
   }
@@ -270,11 +297,11 @@
   if (napGetExp(x,1)==0)
   {
-    if (!nacIsOne(napGetCoeff(x)))
-    {
-      nacNormalize(napGetCoeff(x));
-      t = nacInvers(napGetCoeff(x));
+    if (!nacIsOne(pGetCoeff(x)))
+    {
+      nacNormalize(pGetCoeff(x));
+      t = nacInvers(pGetCoeff(x));
       nacNormalize(t);
-      n_Delete(&napGetCoeff(x),nacRing);
-      napGetCoeff(x) = t;
+      nacDelete(&pGetCoeff(x),nacRing);
+      pGetCoeff(x) = t;
     }
     return x;
@@ -288,11 +315,11 @@
   if (napGetExp(r,1)==0)
   {
-    nacNormalize(napGetCoeff(r));
-    t = nacInvers(napGetCoeff(r));
+    nacNormalize(pGetCoeff(r));
+    t = nacInvers(pGetCoeff(r));
     nacNormalize(t);
     t = nacNeg(t);
-    qa=p_Mult_nn(qa,t,nacRing); p_Normalize(qa,nacRing);
-    n_Delete(&t,nacRing);
-    p_Normalize(qa,nacRing);
+    napMultN(qa, t);
+    nacDelete(&t,nacRing);
+    napNormalize(qa);
     p_Delete(&x,nacRing);
     p_Delete(&r,nacRing);
@@ -310,9 +337,9 @@
     q = napMult(q, qa);
     q = napAdd(q, napInit(1));
-    nacNormalize(napGetCoeff(r));
-    t = nacInvers(napGetCoeff(r));
-    q=p_Mult_nn(q,t,nacRing); p_Normalize(q,nacRing);
-    p_Normalize(q,nacRing);
-    n_Delete(&t,nacRing);
+    nacNormalize(pGetCoeff(r));
+    t = nacInvers(pGetCoeff(r));
+    napMultN(q, t);
+    napNormalize(q);
+    nacDelete(&t,nacRing);
     p_Delete(&x,nacRing);
     p_Delete(&r,nacRing);
@@ -338,10 +365,10 @@
       q = napNeg(q);
       q = napAdd(q, qa);
-      nacNormalize(napGetCoeff(r));
-      t = nacInvers(napGetCoeff(r));
+      nacNormalize(pGetCoeff(r));
+      t = nacInvers(pGetCoeff(r));
       //nacNormalize(t);
-      q=p_Mult_nn(q,t,nacRing); p_Normalize(q,nacRing);
-      p_Normalize(q,nacRing);
-      n_Delete(&t,nacRing);
+      napMultN(q, t);
+      napNormalize(q);
+      nacDelete(&t,nacRing);
       p_Delete(&x,nacRing);
       p_Delete(&r,nacRing);
@@ -406,5 +433,5 @@
     if (has_denom)
     {
-      number den=n_GetDenom(napGetCoeff(p), nacRing);
+      number den=nacRing->cf->cfGetDenom(pGetCoeff(p), nacRing);
       kl=!n_IsOne(den,nacRing);
       n_Delete(&den, nacRing);
@@ -412,5 +439,5 @@
     if (kl) StringAppendS("(");
     //StringAppendS("-1");
-    nacWrite(napGetCoeff(p));
+    nacWrite(pGetCoeff(p));
     if (kl) StringAppendS(")");
   }
@@ -422,16 +449,16 @@
       BOOLEAN wroteCoeff=FALSE;
       if ((napIsConstant(p))
-      || ((!nacIsOne(napGetCoeff(p)))
-        && (!nacIsMOne(napGetCoeff(p)))))
+      || ((!nacIsOne(pGetCoeff(p)))
+        && (!nacIsMOne(pGetCoeff(p)))))
       {
-        nacWrite(napGetCoeff(p));
+        nacWrite(pGetCoeff(p));
         wroteCoeff=(currRing->ShortOut==0);
       }
-      else if (nacIsMOne(napGetCoeff(p)))
+      else if (nacIsMOne(pGetCoeff(p)))
       {
         StringAppendS("-");
       }
       int  i;
-      for (i = 0; i < rPar(currRing); i++)
+      for (i = 0; i < naNumbOfPar; i++)
       {
         if (napGetExp(p,i+1) > 0)
@@ -453,5 +480,5 @@
       if (p==NULL)
         break;
-      if (nacGreaterZero(napGetCoeff(p)))
+      if (nacGreaterZero(pGetCoeff(p)))
         StringAppendS("+");
     }
@@ -496,6 +523,6 @@
   if ((*s >= '0') && (*s <= '9'))
   {
-    s = nacRead(s, &napGetCoeff(a));
-    if (nacIsZero(napGetCoeff(a)))
+    s = nacRead(s, &pGetCoeff(a));
+    if (nacIsZero(pGetCoeff(a)))
     {
       napDelete1(&a);
@@ -505,5 +532,5 @@
   }
   else
-    napGetCoeff(a) = nacInit(1);
+    pGetCoeff(a) = nacInit(1);
   i = 0;
   const char  *olds=s;
@@ -513,10 +540,10 @@
     if (olds == s)
       i++;
-    else if (*s == '\0')
+    else if (*s == '\0') 
     {
       *b = a;
       return s;
     }
-    if (i >= rPar(currRing))
+    if (i >= naNumbOfPar)
       break;
   }
@@ -530,5 +557,5 @@
     else
       i = 0;
-    if ((*s == '\0') || (i >= rPar(currRing)))
+    if ((*s == '\0') || (i >= naNumbOfPar))
       break;
   }
@@ -585,18 +612,18 @@
 
   p = ph;
-  if (nacIsOne(napGetCoeff(p)))
+  if (nacIsOne(pGetCoeff(p)))
     return;
-  h = nacCopy(napGetCoeff(p));
+  h = nacCopy(pGetCoeff(p));
   pIter(p);
   do
   {
-    d=nacGcd(napGetCoeff(p), h, nacRing);
+    d=nacGcd(pGetCoeff(p), h, nacRing);
     if(nacIsOne(d))
     {
-      n_Delete(&h,nacRing);
-      n_Delete(&d,nacRing);
+      nacDelete(&h,nacRing);
+      nacDelete(&d,nacRing);
       return;
     }
-    n_Delete(&h,nacRing);
+    nacDelete(&h,nacRing);
     h = d;
     pIter(p);
@@ -604,14 +631,14 @@
   while (p!=NULL);
   h = nacInvers(d);
-  n_Delete(&d,nacRing);
+  nacDelete(&d,nacRing);
   p = ph;
   while (p!=NULL)
   {
-    d = nacMult(napGetCoeff(p), h);
-    n_Delete(&napGetCoeff(p),nacRing);
-    napGetCoeff(p) = d;
+    d = nacMult(pGetCoeff(p), h);
+    nacDelete(&pGetCoeff(p),nacRing);
+    pGetCoeff(p) = d;
     pIter(p);
   }
-  n_Delete(&h,nacRing);
+  nacDelete(&h,nacRing);
 }
 
@@ -627,6 +654,6 @@
   while (p!=NULL)
   {
-    d = nacLcm(h, napGetCoeff(p), nacRing);
-    n_Delete(&h,nacRing);
+    d = nacLcm(h, pGetCoeff(p), nacRing);
+    nacDelete(&h,nacRing);
     h = d;
     pIter(p);
@@ -635,6 +662,13 @@
   {
     p = ph;
-    p=p_Mult_nn(p,h,nacRing);p_Normalize(p,nacRing);
-    n_Delete(&h,nacRing);
+    while (p!=NULL)
+    {
+      d=nacMult(h, pGetCoeff(p));
+      nacDelete(&pGetCoeff(p),nacRing);
+      nacNormalize(d);
+      pGetCoeff(p) = d;
+      pIter(p);
+    }
+    nacDelete(&h,nacRing);
   }
   napContent(ph);
@@ -646,5 +680,5 @@
   if (!naIsChar0)
     return napInit(1);
-  x = nacCopy(napGetCoeff(a));
+  x = nacCopy(pGetCoeff(a));
   if (nacIsOne(x))
     return napInitz(x);
@@ -652,6 +686,6 @@
   {
     pIter(a);
-    y = nacGcd(x, napGetCoeff(a), nacRing);
-    n_Delete(&x,nacRing);
+    y = nacGcd(x, pGetCoeff(a), nacRing);
+    nacDelete(&x,nacRing);
     x = y;
     if (nacIsOne(x))
@@ -660,6 +694,6 @@
   do
   {
-    y = nacGcd(x, napGetCoeff(b), nacRing);
-    n_Delete(&x,nacRing);
+    y = nacGcd(x, pGetCoeff(b), nacRing);
+    nacDelete(&x,nacRing);
     x = y;
     if (nacIsOne(x))
@@ -679,8 +713,8 @@
   napoly g, x, y, h;
   if ((a==NULL)
-  || ((pNext(a)==NULL)&&(nacIsZero(napGetCoeff(a)))))
+  || ((pNext(a)==NULL)&&(nacIsZero(pGetCoeff(a)))))
   {
     if ((b==NULL)
-    || ((pNext(b)==NULL)&&(nacIsZero(napGetCoeff(b)))))
+    || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b)))))
     {
       return napInit(1);
@@ -690,5 +724,5 @@
   else
   if ((b==NULL)
-  || ((pNext(b)==NULL)&&(nacIsZero(napGetCoeff(b)))))
+  || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b)))))
   {
     return napCopy(a);
@@ -722,9 +756,6 @@
       {
         napCleardenom(y);
-        if (!nacIsOne(napGetCoeff(g)))
-	{
-          y=p_Mult_nn(y,napGetCoeff(g),nacRing);
-	  p_Normalize(y,nacRing);
-        }
+        if (!nacIsOne(pGetCoeff(g)))
+          napMultN(y, pGetCoeff(g));
         napDelete1(&g);
         return y;
@@ -747,5 +778,5 @@
   if (!naIsChar0) x = napInit(1);
   else            x = napGcd0(g,h);
-  for (i=(rPar(currRing)-1); i>=0; i--)
+  for (i=(naNumbOfPar-1); i>=0; i--)
   {
     napSetExp(x,i+1, napExpi(i,a,b));
@@ -767,6 +798,6 @@
     while (b!=NULL)
     {
-      d = nacLcm(h, napGetCoeff(b), nacRing);
-      n_Delete(&h,nacRing);
+      d = nacLcm(h, pGetCoeff(b), nacRing);
+      nacDelete(&h,nacRing);
       h = d;
       pIter(b);
@@ -789,5 +820,5 @@
   {
     j++;
-    if (j > rPar(currRing))
+    if (j > naNumbOfPar)
       return 1;
   }
@@ -811,6 +842,6 @@
     {
       /* h = lt(q)/lt(naI->liste[i])*/
-      napGetCoeff(h) = nacCopy(napGetCoeff(q));
-      for (j=rPar(currRing); j>0; j--)
+      pGetCoeff(h) = nacCopy(pGetCoeff(q));
+      for (j=naNumbOfPar; j>0; j--)
         napSetExp(h,j, napGetExp(q,j) - napGetExp(naI->liste[i],j));
       p_Setm(h,nacRing);
@@ -929,5 +960,5 @@
   if ((l!=NULL)&&(l->n==NULL)&&(napIsConstant(l->z)))
   {
-    return nacInt(napGetCoeff(l->z));
+    return nacInt(pGetCoeff(l->z));
   }
   return 0;
@@ -987,4 +1018,125 @@
 
 /*2
+*  addition; lu:= la + lb
+*/
+number naAdd(number la, number lb)
+{
+  napoly x, y;
+  lnumber lu;
+  lnumber a = (lnumber)la;
+  lnumber b = (lnumber)lb;
+  if (a==NULL) return naCopy(lb);
+  if (b==NULL) return naCopy(la);
+  omCheckAddrSize(a,sizeof(snumber));
+  omCheckAddrSize(b,sizeof(snumber));
+  lu = (lnumber)omAllocBin(rnumber_bin);
+  if (b->n!=NULL) x = napMultCopy(a->z, b->n);
+  else            x = napCopy(a->z);
+  if (a->n!=NULL) y = napMultCopy(b->z, a->n);
+  else            y = napCopy(b->z);
+  lu->z = napAdd(x, y);
+  if (lu->z==NULL)
+  {
+    omFreeBin((ADDRESS)lu,  rnumber_bin);
+    return (number)NULL;
+  }
+  if (a->n!=NULL)
+  {
+    if (b->n!=NULL) x = napMultCopy(a->n, b->n);
+    else            x = napCopy(a->n);
+  }
+  else
+  {
+    if (b->n!=NULL) x = napCopy(b->n);
+    else            x = NULL;
+  }
+  //if (x!=NULL)
+  //{
+  //  if (napIsConstant(x))
+  //  {
+  //    number inv=nacInvers(pGetCoeff(x));
+  //    napMultN(lu->z,inv);
+  //    nacDelete(&inv,nacRing);
+  //    napDelete(&x);
+  //  }
+  //}
+  lu->n = x;
+  lu->s = FALSE;
+  if (lu->n!=NULL)
+  {
+     number luu=(number)lu;
+     naNormalize0(luu);
+     lu=(lnumber)luu;
+  }
+  naTest((number)lu);
+  return (number)lu;
+}
+
+/*2
+*  subtraction; r:= la - lb
+*/
+number naSub(number la, number lb)
+{
+  lnumber lu;
+
+  if (lb==NULL) return naCopy(la);
+  if (la==NULL)
+  {
+    lu = (lnumber)naCopy(lb);
+    lu->z = napNeg(lu->z);
+    return (number)lu;
+  }
+
+  lnumber a = (lnumber)la;
+  lnumber b = (lnumber)lb;
+
+  omCheckAddrSize(a,sizeof(snumber));
+  omCheckAddrSize(b,sizeof(snumber));
+
+  napoly x, y;
+  lu = (lnumber)omAllocBin(rnumber_bin);
+  if (b->n!=NULL) x = napMultCopy(a->z, b->n);
+  else            x = napCopy(a->z);
+  if (a->n!=NULL) y = napMult(napCopy(b->z), napCopyNeg(a->n));
+  else            y = napCopyNeg(b->z);
+  lu->z = napAdd(x, y);
+  if (lu->z==NULL)
+  {
+    omFreeBin((ADDRESS)lu,  rnumber_bin);
+    return (number)NULL;
+  }
+  if (a->n!=NULL)
+  {
+    if (b->n!=NULL) x = napMultCopy(a->n, b->n);
+    else            x = napCopy(a->n);
+  }
+  else
+  {
+    if (b->n!=NULL) x = napCopy(b->n);
+    else            x = NULL;
+  }
+  //if (x!=NULL)
+  //{
+  //  if (napIsConstant(x))
+  //  {
+  //    number inv=nacInvers(pGetCoeff(x));
+  //    napMultN(lu->z,inv);
+  //    nacDelete(&inv,nacRing);
+  //    napDelete(&x);
+  //  }
+  //}
+  lu->n = x;
+  lu->s = FALSE;
+  if (lu->n!=NULL)
+  {
+     number luu=(number)lu;
+     naNormalize0(luu);
+     lu=(lnumber)luu;
+  }
+  naTest((number)lu);
+  return (number)lu;
+}
+
+/*2
 *  multiplication; r:= la * lb
 */
@@ -1044,5 +1196,5 @@
     }
   }
-  if ((x!=NULL) && (napIsConstant(x)) && nacIsOne(napGetCoeff(x)))
+  if ((x!=NULL) && (napIsConstant(x)) && nacIsOne(pGetCoeff(x)))
     p_Delete(&x,nacRing);
   lo->n = x;
@@ -1057,5 +1209,5 @@
     lo->s = 0;
     number luu=(number)lo;
-    naNormalize(luu);
+    naNormalize0(luu);
     lo=(lnumber)luu;
   }
@@ -1091,5 +1243,5 @@
   naNormalize(nres);
 
-  //p_Delete(&res->n,nacRing);
+  //napDelete(&res->n);
   naTest(nres);
   return nres;
@@ -1144,5 +1296,5 @@
     }
   }
-  if ((napIsConstant(x)) && nacIsOne(napGetCoeff(x)))
+  if ((napIsConstant(x)) && nacIsOne(pGetCoeff(x)))
     p_Delete(&x,nacRing);
   lo->n = x;
@@ -1196,5 +1348,5 @@
     lo->z = napInit(1);
   x = b->z;
-  if ((!napIsConstant(x)) || !nacIsOne(napGetCoeff(x)))
+  if ((!napIsConstant(x)) || !nacIsOne(pGetCoeff(x)))
     x = napCopy(x);
   else
@@ -1215,5 +1367,5 @@
     while (x!=NULL)
     {
-      nacNormalize(napGetCoeff(x));
+      nacNormalize(pGetCoeff(x));
       pIter(x);
     }
@@ -1224,5 +1376,5 @@
   {
      number luu=(number)lo;
-     naNormalize(luu);
+     naNormalize0(luu);
      lo=(lnumber)luu;
   }
@@ -1252,5 +1404,5 @@
   if ((zb!=NULL) && (zb->z!=NULL))
   {
-    return (nacGreaterZero(napGetCoeff(zb->z))||(!napIsConstant(zb->z)));
+    return (nacGreaterZero(pGetCoeff(zb->z))||(!napIsConstant(zb->z)));
   }
   /* else */ return FALSE;
@@ -1353,8 +1505,8 @@
     return NULL;
   int i;
-  char *s=(char *)omAlloc(4* rPar(currRing));
+  char *s=(char *)omAlloc(4* naNumbOfPar);
   char *t=(char *)omAlloc(8);
   s[0]='\0';
-  for (i = 0; i <= rPar(currRing) - 1; i++)
+  for (i = 0; i <= naNumbOfPar - 1; i++)
   {
     if (napGetExp(ph->z,i+1) > 0)
@@ -1417,11 +1569,11 @@
   if (a->n==NULL)
   {
-    if (napIsConstant(a->z))
+    if (napIsConstant(a->z)) 
     {
 #ifdef LDEBUG
        if (a->z==NULL) return FALSE;
-       else
-#endif
-         return nacIsOne(napGetCoeff(a->z));
+       else 
+#endif 
+         return nacIsOne(pGetCoeff(a->z));
     }
     else                 return FALSE;
@@ -1435,12 +1587,12 @@
     else
     {
-      t = nacSub(napGetCoeff(x), napGetCoeff(y));
+      t = nacSub(pGetCoeff(x), pGetCoeff(y));
       if (!nacIsZero(t))
       {
-        n_Delete(&t,nacRing);
+        nacDelete(&t,nacRing);
         return FALSE;
       }
       else
-        n_Delete(&t,nacRing);
+        nacDelete(&t,nacRing);
     }
     pIter(x);
@@ -1476,5 +1628,5 @@
   if (a->n==NULL)
   {
-    if (napIsConstant(a->z)) return nacIsMOne(napGetCoeff(a->z));
+    if (napIsConstant(a->z)) return nacIsMOne(pGetCoeff(a->z));
     /*else                   return FALSE;*/
   }
@@ -1504,5 +1656,5 @@
   if (a==NULL)  return naCopy(b);
   if (b==NULL)  return naCopy(a);
-
+  
   lnumber x, y;
   lnumber result = (lnumber)omAlloc0Bin(rnumber_bin);
@@ -1510,5 +1662,5 @@
   x = (lnumber)a;
   y = (lnumber)b;
-  if ((rPar(currRing) == 1) && (naMinimalPoly!=NULL))
+  if ((naNumbOfPar == 1) && (naMinimalPoly!=NULL))
   {
     if (pNext(x->z)!=NULL)
@@ -1528,17 +1680,17 @@
     napoly rz=napGcd(x->z, y->z);
     CanonicalForm F, G, R;
-    R=convSingPFactoryP(rz,nacRing);
-    p_Normalize(x->z,nacRing);
-    F=convSingPFactoryP(x->z,nacRing)/R;
-    p_Normalize(y->z,nacRing);
-    G=convSingPFactoryP(y->z,nacRing)/R;
+    R=convSingPFactoryP(rz,nacRing); 
+    napNormalize(x->z);
+    F=convSingPFactoryP(x->z,nacRing)/R; 
+    napNormalize(y->z);
+    G=convSingPFactoryP(y->z,nacRing)/R; 
     F = gcd( F, G );
-    if (F.isOne())
+    if (F.isOne()) 
       result->z= rz;
     else
     {
       p_Delete(&rz,nacRing);
-      result->z=convFactoryPSingP( F*R, nacRing );
-      p_Normalize(result->z,nacRing);
+      result->z=convFactoryPSingP( F*R,nacRing );
+      napNormalize(result->z);
     }
   }
@@ -1550,5 +1702,5 @@
 
 /*2
-* rPar(currRing) = 1:
+* naNumbOfPar = 1:
 * clears denominator         algebraic case;
 * tries to simplify ratio    transcendental case;
@@ -1556,7 +1708,11 @@
 * cancels monomials
 * occuring in denominator
-* and enumerator  ?          rPar(currRing) != 1;
+* and enumerator  ?          naNumbOfPar != 1;
 *
-*/
+* #defines for Factory:
+* FACTORY_GCD_TEST: do not apply built in gcd for
+*   univariate polynomials, always use Factory
+*/
+//#define FACTORY_GCD_TEST
 void naNormalize(number &pp)
 {
@@ -1592,5 +1748,5 @@
     while(x!=NULL)
     {
-      nacNormalize(napGetCoeff(x));
+      nacNormalize(pGetCoeff(x));
       pIter(x);
     }
@@ -1602,5 +1758,5 @@
     while(y!=NULL)
     {
-      nacNormalize(napGetCoeff(y));
+      nacNormalize(pGetCoeff(y));
       pIter(y);
     }
@@ -1609,10 +1765,10 @@
   /* collect all denoms from y and multiply x and y by it */
     number n=napLcm(y);
-    x=p_Mult_nn(x,n,nacRing);p_Normalize(x,nacRing);
-    y=p_Mult_nn(y,n,nacRing);p_Normalize(y,nacRing);
-    n_Delete(&n,nacRing);
+    napMultN(x,n);
+    napMultN(y,n);
+    nacDelete(&n,nacRing);
     while(x!=NULL)
     {
-      nacNormalize(napGetCoeff(x));
+      nacNormalize(pGetCoeff(x));
       pIter(x);
     }
@@ -1620,5 +1776,5 @@
     while(y!=NULL)
     {
-      nacNormalize(napGetCoeff(y));
+      nacNormalize(pGetCoeff(y));
       pIter(y);
     }
@@ -1628,5 +1784,5 @@
   {
     int i;
-    for (i=rPar(currRing)-1; i>=0; i--)
+    for (i=naNumbOfPar-1; i>=0; i--)
     {
       napoly xx=x;
@@ -1650,5 +1806,5 @@
   if (napIsConstant(y)) /* i.e. => simplify to (1/c)*z / monom */
   {
-    if (nacIsOne(napGetCoeff(y)))
+    if (nacIsOne(pGetCoeff(y)))
     {
       napDelete1(&y);
@@ -1657,8 +1813,8 @@
       return;
     }
-    number h1 = nacInvers(napGetCoeff(y));
+    number h1 = nacInvers(pGetCoeff(y));
     nacNormalize(h1);
-    x=p_Mult_nn(x,h1,nacRing);p_Normalize(x,nacRing);
-    n_Delete(&h1,nacRing);
+    napMultN(x, h1);
+    nacDelete(&h1,nacRing);
     napDelete1(&y);
     p->n = NULL;
@@ -1666,5 +1822,6 @@
     return;
   }
-  if (rPar(currRing) == 1) /* apply built-in gcd */
+#ifndef FACTORY_GCD_TEST
+  if (naNumbOfPar == 1) /* apply built-in gcd */
   {
     napoly x1,y1;
@@ -1704,10 +1861,10 @@
     {
       number n=napLcm(y);
-      x=p_Mult_nn(x,n,nacRing);p_Normalize(x,nacRing);
-      y=p_Mult_nn(y,n,nacRing);p_Normalize(y,nacRing);
-      n_Delete(&n,nacRing);
+      napMultN(x,n);
+      napMultN(y,n);
+      nacDelete(&n,nacRing);
       while(x!=NULL)
       {
-        nacNormalize(napGetCoeff(x));
+        nacNormalize(pGetCoeff(x));
         pIter(x);
       }
@@ -1715,5 +1872,5 @@
       while(y!=NULL)
       {
-        nacNormalize(napGetCoeff(y));
+        nacNormalize(pGetCoeff(y));
         pIter(y);
       }
@@ -1722,5 +1879,5 @@
     if (pNext(y)==NULL)
     {
-      if (nacIsOne(napGetCoeff(y)))
+      if (nacIsOne(pGetCoeff(y)))
       {
         if (napGetExp(y,1)==0)
@@ -1734,6 +1891,9 @@
     }
   }
+#endif /* FACTORY_GCD_TEST */
 #ifdef HAVE_FACTORY
+#ifndef FACTORY_GCD_TEST
   else
+#endif
   {
     napoly xx,yy;
@@ -1751,22 +1911,22 @@
   x=p->z;
   y=p->n;
-  if(!nacGreaterZero(napGetCoeff(y)))
+  if(!nacGreaterZero(pGetCoeff(y)))
   {
     x=napNeg(x);
     y=napNeg(y);
   }
-  number g=nacCopy(napGetCoeff(x));
+  number g=nacCopy(pGetCoeff(x));
   pIter(x);
   while (x!=NULL)
   {
-    number d=nacGcd(g,napGetCoeff(x), nacRing);
+    number d=nacGcd(g,pGetCoeff(x), nacRing);
     if(nacIsOne(d))
     {
-      n_Delete(&g,nacRing);
-      n_Delete(&d,nacRing);
+      nacDelete(&g,nacRing);
+      nacDelete(&d,nacRing);
       naTest(pp);
       return;
     }
-    n_Delete(&g,nacRing);
+    nacDelete(&g,nacRing);
     g = d;
     pIter(x);
@@ -1774,13 +1934,13 @@
   while (y!=NULL)
   {
-    number d=nacGcd(g,napGetCoeff(y), nacRing);
+    number d=nacGcd(g,pGetCoeff(y), nacRing);
     if(nacIsOne(d))
     {
-      n_Delete(&g,nacRing);
-      n_Delete(&d,nacRing);
+      nacDelete(&g,nacRing);
+      nacDelete(&d,nacRing);
       naTest(pp);
       return;
     }
-    n_Delete(&g,nacRing);
+    nacDelete(&g,nacRing);
     g = d;
     pIter(y);
@@ -1790,5 +1950,5 @@
   while (x!=NULL)
   {
-    number d = nacIntDiv(napGetCoeff(x),g);
+    number d = nacIntDiv(pGetCoeff(x),g);
     napSetCoeff(x,d);
     pIter(x);
@@ -1796,9 +1956,9 @@
   while (y!=NULL)
   {
-    number d = nacIntDiv(napGetCoeff(y),g);
+    number d = nacIntDiv(pGetCoeff(y),g);
     napSetCoeff(y,d);
     pIter(y);
   }
-  n_Delete(&g,nacRing);
+  nacDelete(&g,nacRing);
   naTest(pp);
 }
@@ -1830,15 +1990,15 @@
     while (xx!=NULL)
     {
-      bt = nacGcd(t, napGetCoeff(xx), nacRing);
-      r = nacMult(t, napGetCoeff(xx));
-      n_Delete(&napGetCoeff(xx),nacRing);
-      napGetCoeff(xx) = nacDiv(r, bt);
-      nacNormalize(napGetCoeff(xx));
-      n_Delete(&bt,nacRing);
-      n_Delete(&r,nacRing);
+      bt = nacGcd(t, pGetCoeff(xx), nacRing);
+      r = nacMult(t, pGetCoeff(xx));
+      nacDelete(&pGetCoeff(xx),nacRing);
+      pGetCoeff(xx) = nacDiv(r, bt);
+      nacNormalize(pGetCoeff(xx));
+      nacDelete(&bt,nacRing);
+      nacDelete(&r,nacRing);
       pIter(xx);
     }
   }
-  n_Delete(&t,nacRing);
+  nacDelete(&t,nacRing);
   result->z = x;
 #ifdef HAVE_FACTORY
@@ -1885,13 +2045,13 @@
       naI->liste[i]=napCopy(h->z);
       /* If it isn't normalized (lc = 1) do this */
-      if (!nacIsOne(napGetCoeff(naI->liste[i])))
+      if (!nacIsOne(pGetCoeff(naI->liste[i])))
       {
         x=naI->liste[i];
-        nacNormalize(napGetCoeff(x));
-        a=nacCopy(napGetCoeff(x));
+        nacNormalize(pGetCoeff(x));
+        a=nacCopy(pGetCoeff(x));
         number aa=nacInvers(a);
-        n_Delete(&a,nacRing);
-        x=p_Mult_nn(x,aa,nacRing);p_Normalize(x,nacRing);
-        n_Delete(&aa,nacRing);
+        nacDelete(&a,nacRing);
+        napMultN(x,aa);
+        nacDelete(&aa,nacRing);
       }
     }
@@ -1910,5 +2070,5 @@
   int i=(int)((long)c);
   if (i>(naPrimeM>>2)) i-=naPrimeM;
-  napGetCoeff(l->z)=nlInit(i);
+  pGetCoeff(l->z)=nlInit(i);
   l->n=NULL;
   return (number)l;
@@ -1924,5 +2084,5 @@
   l->s=0;
   l->z=(napoly)p_Init(nacRing);
-  napGetCoeff(l->z)=nlCopy(c);
+  pGetCoeff(l->z)=nlCopy(c);
   l->n=NULL;
   return (number)l;
@@ -1938,5 +2098,5 @@
   l->s=2;
   l->z=(napoly)p_Init(nacRing);
-  napGetCoeff(l->z)=c; /* omit npCopy, because npCopy is a no-op */
+  pGetCoeff(l->z)=c; /* omit npCopy, because npCopy is a no-op */
   l->n=NULL;
   return (number)l;
@@ -1956,5 +2116,5 @@
   l->s=2;
   l->z=(napoly)p_Init(nacRing);
-  napGetCoeff(l->z)=n;
+  pGetCoeff(l->z)=n;
   l->n=NULL;
   return (number)l;
@@ -1973,5 +2133,5 @@
   l->s=2;
   l->z=(napoly)p_Init(nacRing);
-  napGetCoeff(l->z)=n;
+  pGetCoeff(l->z)=n;
   l->n=NULL;
   return (number)l;
@@ -1991,5 +2151,5 @@
     napSetExp(a,i,napGetExpFrom(p,i,napMapRing));
   p_Setm(a,nacRing);
-  napGetCoeff(w) = nacMap(napGetCoeff(p));
+  pGetCoeff(w) = nacMap(pGetCoeff(p));
   loop
   {
@@ -2001,5 +2161,5 @@
       napSetExp(a,i,napGetExpFrom(p,i,napMapRing));
     p_Setm(a,nacRing);
-    napGetCoeff(a) = nacMap(napGetCoeff(p));
+    pGetCoeff(a) = nacMap(pGetCoeff(p));
   }
   pNext(a) = NULL;
@@ -2028,5 +2188,5 @@
         not_null=FALSE;
     }
-    napGetCoeff(w) = nMap(napGetCoeff(p));
+    pGetCoeff(w) = nMap(pGetCoeff(p));
     p_Setm(w,nacRing);
     pIter(p);
@@ -2039,5 +2199,5 @@
       }
       /* else continue*/
-      n_Delete(&(napGetCoeff(w)),nacRing);
+      nacDelete(&(pGetCoeff(w)),nacRing);
     }
     else
@@ -2080,5 +2240,5 @@
       if (napGetExp(erg->n,1) >= napGetExp(naMinimalPoly,1))
         erg->n = napRemainder(erg->n, naMinimalPoly);
-      if ((napIsConstant(erg->n)) && nacIsOne(napGetCoeff(erg->n)))
+      if ((napIsConstant(erg->n)) && nacIsOne(pGetCoeff(erg->n)))
         p_Delete(&(erg->n),nacRing);
     }
@@ -2201,10 +2361,10 @@
       pan=(lnumber)pGetCoeff(p);
       pan->s=2;
-      pan->z=napInitz(nMap(napGetCoeff(za)));
+      pan->z=napInitz(nMap(pGetCoeff(za)));
       pa=pan->z;
     }
     else
     {
-      pGetCoeff(p)=nMap(napGetCoeff(za));
+      pGetCoeff(p)=nMap(pGetCoeff(za));
     }
     for(i=0;i<P;i++)
@@ -2270,5 +2430,5 @@
   {
     lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin);
-    rr->z=nap_Copy(naGetDenom0(x),r);
+    rr->z=nap_Copy(x->n,r);
     rr->s = 2;
     return (number)rr;
@@ -2276,16 +2436,13 @@
   return r->cf->nInit(1);
 }
-number   naGetNumerator(number &n, const ring r)
+
+number   naNumerator(number &n, const ring r)
 {
   if (r==currRing) naNormalize(n);
   lnumber x=(lnumber)n;
-  if (x!=NULL)
-  {
-    lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin);
-    rr->z=nap_Copy(naGetNom0(x),r);
-    rr->s = 2;
-    return (number)rr;
-  }
-  return NULL;
+  lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin);
+  rr->z=nap_Copy(x->z,r);
+  rr->s = 2;
+  return (number)rr;
 }
 
@@ -2305,6 +2462,6 @@
   while(p!=NULL)
   {
-    if ((naIsChar0 && nlIsZero(napGetCoeff(p)))
-    || ((!naIsChar0) && npIsZero(napGetCoeff(p))))
+    if ((naIsChar0 && nlIsZero(pGetCoeff(p)))
+    || ((!naIsChar0) && npIsZero(pGetCoeff(p))))
     {
       Print("coeff 0 in %s:%d\n",f,l);
@@ -2322,12 +2479,12 @@
     //  return FALSE;
     //}
-    if (naIsChar0 && !(nlDBTest(napGetCoeff(p),f,l)))
+    if (naIsChar0 && !(nlDBTest(pGetCoeff(p),f,l)))
       return FALSE;
     pIter(p);
   }
-  p = naGetDenom0(x);
+  p = x->n;
   while(p!=NULL)
   {
-    if (naIsChar0 && !(nlDBTest(napGetCoeff(p),f,l)))
+    if (naIsChar0 && !(nlDBTest(pGetCoeff(p),f,l)))
       return FALSE;
     pIter(p);
@@ -2336,85 +2493,3 @@
 }
 #endif
-//-------------------------------------------------------------------------
-/// static: Normalize: case mipo==0, result: n->z, n->n integer
-static void naNormalize_0(number n)
-{
-  lnumber p = (lnumber) n;
-  napoly x = p->z;
-  napoly y = p->n;
-  if (nacRing->cf->nNormalize!=nDummy2)
-  {
-    /* collect all denoms from x and multiply x and y by it */
-    number n;
-    if (y!=NULL)
-    {
-      n=napLcm(y);
-      x=p_Mult_nn(x,n,nacRing); p_Normalize(x,nacRing);
-      y=p_Mult_nn(y,n,nacRing); p_Normalize(y,nacRing);
-      n_Delete(&n,nacRing);
-    }
-    /* collect all denoms from x and multiply x and y by it */
-    n=napLcm(y);
-    x=p_Mult_nn(x,n,nacRing);
-    if (y!=NULL)   { y=p_Mult_nn(y,n,nacRing); n_Delete(&n,nacRing); }
-    else           y=p_NSet(n,nacRing);
-    p->n=y;
-    // normalize all coeffs in x
-    p_Normalize(x,nacRing);
-    // normalize all coeffs in y
-    p_Normalize(y,nacRing);
-  }
-}
-/// return la+li
-number  naAdd(number la, number lb)               /* lu := la+lb */
-{
-  napoly x, y;
-  lnumber lu;
-  lnumber a = (lnumber)la;
-  lnumber b = (lnumber)lb;
-  if (a==NULL) return naCopy(lb);
-  if (b==NULL) return naCopy(la);
-  omCheckAddrSize(a,sizeof(snumber));
-  omCheckAddrSize(b,sizeof(snumber));
-  lu = (lnumber)omAllocBin(rnumber_bin);
-  if (b->n!=NULL) x = pp_Mult_qq(a->z, b->n, nacRing);
-  else            x = p_Copy(a->z,nacRing);
-  if (a->n!=NULL) y = pp_Mult_qq(b->z, a->n,nacRing);
-  else            y = p_Copy(b->z,nacRing);
-  lu->z = p_Add_q(x, y,nacRing);
-  if (lu->z==NULL)
-  {
-    omFreeBin((ADDRESS)lu,  rnumber_bin);
-    return (number)NULL;
-  }
-  if (a->n!=NULL)
-  {
-    if (b->n!=NULL) x = pp_Mult_qq(a->n, b->n,nacRing);
-    else            x = p_Copy(a->n,nacRing);
-  }
-  else
-  {
-    if (b->n!=NULL) x = p_Copy(b->n,nacRing);
-    else            x = NULL;
-  }
-  lu->n = x;
-  lu->s = FALSE;
-  if (lu->n!=NULL)
-  {
-     number luu=(number)lu;
-     naNormalize_0(luu);
-     lu=(lnumber)luu;
-  }
-  naTest((number)lu);
-  return (number)lu;
-}
-
-/// return la -lb
-number  naSub(number la, number lb)               /* lu := la-lb */
-{
-  number llb=naCopy(lb);
-  llb=naNeg(llb);
-  number res=naAdd(la,llb);
-  naDelete(&llb,currRing);
-  return res;
-}
+
Index: kernel/longalg.h
===================================================================
--- kernel/longalg.h	(revision 43c57185bbe2457782485ecda44d8025a86ca320)
+++ kernel/longalg.h	(revision b3af9332ce7b8a001aebc6b801c0baa452306ede)
@@ -4,5 +4,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: longalg.h,v 1.15 2009-08-14 17:14:30 Singular Exp $ */
+/* $Id: longalg.h,v 1.16 2009-08-21 10:55:46 Singular Exp $ */
 /*
 * ABSTRACT:   algebraic numbers
@@ -80,6 +80,4 @@
 #define napSetm(p)             p_Setm(p,currRing->algring)
 #define nanumber               lnumber
-#define naGetNom0(na)          (((nanumber)(na))->z)
-#define naGetDenom0(na)        (((nanumber)(na))->n)
 napoly napRemainder(napoly f, const napoly  g);
 void napWrite(napoly l,const BOOLEAN denom=TRUE);
