Index: kernel/clapconv.cc
===================================================================
--- kernel/clapconv.cc	(revision ab33f6e148aa2f8f6099e5a25a55a07f1e7fdd2b)
+++ kernel/clapconv.cc	(revision 6620d757775d0859e2fea065552c5016ad0a0089)
@@ -3,5 +3,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-// $Id: clapconv.cc,v 1.14 2009-08-13 12:48:39 Singular Exp $
+// $Id: clapconv.cc,v 1.15 2009-08-13 15:17:02 Singular Exp $
 /*
 * ABSTRACT: convert data between Singular and factory
@@ -31,7 +31,5 @@
 static void conv_RecPP ( const CanonicalForm & f, int * exp, sBucket_pt result, ring r );
 
-static void convRecPTr ( const CanonicalForm & f, int * exp, napoly & result );
-
-static void convRecTrP ( const CanonicalForm & f, int * exp, poly & result, int offs );
+static void convRecTrP ( const CanonicalForm & f, int * exp, poly & result, int offs, const ring r );
 
 static void convRecGFGF ( const CanonicalForm & f, int * exp, poly & result );
@@ -97,68 +95,8 @@
 }
 
-CanonicalForm convSingPFactoryP( poly p, const ring r )
-{
-  CanonicalForm result = 0;
-  int e, n = r->N;
-  assume( rPar(r)==0);
-
-  if ( getCharacteristic() != 0 )
-  {
-    /* does only work for finite fields Z/p*/
-    while ( p != NULL )
-    {
-      CanonicalForm term = npInt( pGetCoeff( p ) );
-      for ( int i = n; i >0; i-- )
-      {
-        if ( (e = p_GetExp( p, i, r )) != 0 )
-           term *= power( Variable( i ), e );
-      }
-      result += term;
-      pIter( p );
-    }
-  }
-  else
-  {
-    while ( p != NULL )
-    {
-      CanonicalForm term;
-      if ( SR_HDL(pGetCoeff( p )) & SR_INT )
-      {
-        term = SR_TO_INT( pGetCoeff( p ) );
-      }
-      else
-      {
-        if ( pGetCoeff( p )->s == 3 )
-        {
-          MP_INT dummy;
-          mpz_init_set( &dummy, &(pGetCoeff( p )->z) );
-          term = make_cf( dummy );
-        }
-        else
-        {
-          // assume s==1 or s==0
-          MP_INT num, den;
-          On(SW_RATIONAL);
-          mpz_init_set( &num, &(pGetCoeff( p )->z) );
-          mpz_init_set( &den, &(pGetCoeff( p )->n) );
-          term = make_cf( num, den, ( pGetCoeff( p )->s != 1 ));
-        }
-      }
-      for ( int i = n; i >0; i-- )
-      {
-        if ( (e = p_GetExp( p, i, r )) != 0 )
-           term *= power( Variable( i ), e );
-      }
-      result += term;
-      pIter( p );
-    }
-  }
-  return result;
-}
-
 poly convFactoryPSingP ( const CanonicalForm & f, const ring r )
 {
 //    cerr << " f = " << f << endl;
-  int n = r->N+1;
+  int n = rVar(r)+1;
   /* ASSERT( level( f ) <= pVariables, "illegal number of variables" ); */
   int * exp = (int*)omAlloc0(n*sizeof(int));
@@ -224,8 +162,8 @@
 
 
-CanonicalForm convSingTrFactoryP( napoly p )
+CanonicalForm convSingPFactoryP( poly p, const int off, const ring r )
 {
   CanonicalForm result = 0;
-  int e, n = rPar(currRing);
+  int e, n = rVar(r);
 
   while ( p!=NULL)
@@ -233,9 +171,9 @@
     CanonicalForm term;
     /* does only work for finite fields */
-    if ( getCharacteristic() != 0 )
+    if ( rField_is_Zp(r) )
     {
       term = npInt( pGetCoeff( p ) );
     }
-    else
+    else if (rField_is_Q(r))
     {
       if ( SR_HDL(pGetCoeff( p )) & SR_INT )
@@ -260,8 +198,13 @@
       }
     }
+    else
+    {
+      WerrorS("conversion error");
+      return result;
+    }
     for ( int i = n; i >0; i-- )
     {
-      if ( (e = p_GetExp( p, i, currRing->algring )) != 0 )
-        term *= power( Variable( i ), e );
+      if ( (e = p_GetExp( p, i, r)) != 0 )
+        term *= power( Variable( i+off ), e );
     }
     result += term;
@@ -269,77 +212,4 @@
   }
   return result;
-}
-
-napoly convFactoryPSingTr ( const CanonicalForm & f )
-{
-//    cerr << " f = " << f << endl;
-  int n = rPar(currRing)+1;
-  /* ASSERT( level( f ) <= rPar(currRing), "illegal number of variables" ); */
-  int * exp = (int *)omAlloc0(n*sizeof(int));
-  napoly result = NULL;
-  convRecPTr( f, exp, result );
-  omFreeSize((ADDRESS)exp,n*sizeof(int));
-  return result;
-}
-
-static void convRecPTr ( const CanonicalForm & f, int * exp, napoly & result )
-{
-  if (f.isZero())
-    return;
-  if ( ! f.inCoeffDomain() )
-  {
-    int l = f.level();
-    for ( CFIterator i = f; i.hasTerms(); i++ )
-    {
-        exp[l] = i.exp();
-        convRecPTr( i.coeff(), exp, result );
-    }
-    exp[l] = 0;
-  }
-  else
-  {
-    napoly term = napNew();
-    // napNext( term ) = NULL; //already done by napNew
-    for ( int i = rPar(currRing); i>=1; i-- )
-      p_SetExp( term, i , exp[i],currRing->algring);
-    p_Setm(term, currRing->algring);
-    if ( f.isImm() )
-      pGetCoeff( term ) = n_Init( f.intval(), currRing->algring );
-    else
-    {
-      number z=(number)omAllocBin(rnumber_bin);
-#if defined(LDEBUG)
-      z->debug=123456;
-#endif
-      z->z = gmp_numerator( f );
-      if ( f.den().isOne() )
-      {
-        z->s = 3;
-      }
-      else
-      {
-        z->n = gmp_denominator( f );
-        if (mpz_cmp_si(&z->n,(long)1)==0)
-        {
-          mpz_clear(&z->n);
-          z->s=3;
-        }
-        else
-        {
-          z->s = 0;
-          n_Normalize(z,currRing->algring);
-        }
-      }
-      pGetCoeff( term ) = z;
-    }
-    if (n_IsZero(pGetCoeff(term),currRing->algring))
-    {
-      napDelete(&term);
-    }
-    else
-    {
-      result = napAdd( result, term );
-    }
-  }
 }
 
@@ -530,14 +400,14 @@
 }
 
-CanonicalForm convSingTrPFactoryP ( poly p )
+CanonicalForm convSingTrPFactoryP ( poly p, const ring r )
 {
   CanonicalForm result = 0;
-  int e, n = pVariables;
-  int offs = rPar(currRing);
+  int e, n = rVar(r);
+  int offs = rPar(r);
 
   while ( p!=NULL )
   {
-    nNormalize(pGetCoeff(p));
-    CanonicalForm term=convSingTrFactoryP(((lnumber)pGetCoeff(p))->z);
+    n_Normalize(pGetCoeff(p),r);
+    CanonicalForm term=convSingPFactoryP(((lnumber)pGetCoeff(p))->z,0,r->algring);
 
     if ((((lnumber)pGetCoeff(p))->n!=NULL)
@@ -549,5 +419,5 @@
     for ( int i = n; i > 0; i-- )
     {
-      if ( (e = pGetExp( p, i )) != 0 )
+      if ( (e = p_GetExp( p, i,r )) != 0 )
         term = term * power( Variable( i + offs ), e );
     }
@@ -558,10 +428,10 @@
 }
 
-poly convFactoryPSingTrP ( const CanonicalForm & f )
-{
-  int n = pVariables+1;
+poly convFactoryPSingTrP ( const CanonicalForm & f, const ring r )
+{
+  int n = rVar(r)+1;
   int * exp = (int*)omAlloc0(n*sizeof(int));
   poly result = NULL;
-  convRecTrP( f, exp, result , rPar(currRing) );
+  convRecTrP( f, exp, result , rPar(r), r );
   omFreeSize((ADDRESS)exp,n*sizeof(int));
   return result;
@@ -569,5 +439,5 @@
 
 static void
-convRecTrP ( const CanonicalForm & f, int * exp, poly & result , int offs)
+convRecTrP ( const CanonicalForm & f, int * exp, poly & result , int offs, const ring r)
 {
   if (f.isZero())
@@ -579,5 +449,5 @@
     {
       exp[l-offs] = i.exp();
-      convRecTrP( i.coeff(), exp, result, offs );
+      convRecTrP( i.coeff(), exp, result, offs, r );
     }
     exp[l-offs] = 0;
@@ -585,13 +455,13 @@
   else
   {
-    poly term = pInit();
+    poly term = p_Init(r);
     pNext( term ) = NULL;
-    for ( int i = 1; i <= pVariables; i++ )
-      pSetExp( term, i ,exp[i]);
+    for ( int i = rVar(r); i>0; i-- )
+      p_SetExp( term, i ,exp[i], r);
     //if (rRing_has_Comp(currRing)) p_SetComp(term, 0, currRing); // done by pInit
     pGetCoeff(term)=(number)omAlloc0Bin(rnumber_bin);
-    ((lnumber)pGetCoeff(term))->z=convFactoryPSingTr( f );
-    pSetm( term );
-    result = pAdd( result, term );
+    ((lnumber)pGetCoeff(term))->z=convFactoryPSingP( f, r->algring );
+    p_Setm( term,r );
+    result = p_Add_q( result, term,r );
   }
 }
Index: kernel/clapconv.h
===================================================================
--- kernel/clapconv.h	(revision ab33f6e148aa2f8f6099e5a25a55a07f1e7fdd2b)
+++ kernel/clapconv.h	(revision 6620d757775d0859e2fea065552c5016ad0a0089)
@@ -3,5 +3,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-// $Id: clapconv.h,v 1.4 2009-08-13 12:48:39 Singular Exp $
+// $Id: clapconv.h,v 1.5 2009-08-13 15:17:02 Singular Exp $
 /*
 * ABSTRACT: convert data between Singular and factory
@@ -16,9 +16,6 @@
 #include <factory.h>
 
-napoly convFactoryPSingTr ( const CanonicalForm & f );
-CanonicalForm convSingTrFactoryP( napoly p );
-
 poly convFactoryPSingP ( const CanonicalForm & f, const ring r=currRing );
-CanonicalForm convSingPFactoryP( poly p, const ring r=currRing );
+CanonicalForm convSingPFactoryP( poly p, const int off=0, const ring r=currRing );
 
 CanonicalForm convSingAPFactoryAP ( poly p , const Variable & a );
@@ -32,6 +29,6 @@
 napoly convFactoryASingA ( const CanonicalForm & f );
 
-CanonicalForm convSingTrPFactoryP ( poly p );
-poly convFactoryPSingTrP ( const CanonicalForm & f );
+CanonicalForm convSingTrPFactoryP ( poly p, const ring r=currRing );
+poly convFactoryPSingTrP ( const CanonicalForm & f, const ring r=currRing );
 
 CanonicalForm convSingNFactoryN( number n );
Index: kernel/clapsing.cc
===================================================================
--- kernel/clapsing.cc	(revision ab33f6e148aa2f8f6099e5a25a55a07f1e7fdd2b)
+++ kernel/clapsing.cc	(revision 6620d757775d0859e2fea065552c5016ad0a0089)
@@ -3,5 +3,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-// $Id: clapsing.cc,v 1.41 2009-08-13 12:48:39 Singular Exp $
+// $Id: clapsing.cc,v 1.42 2009-08-13 15:17:02 Singular Exp $
 /*
 * ABSTRACT: interface between Singular and factory
@@ -27,100 +27,4 @@
 void out_cf(char *s1,const CanonicalForm &f,char *s2);
 
-poly singclap_gcd ( poly f, poly g )
-{
-  poly res=NULL;
-
-  if (f!=NULL) pCleardenom(f);
-  if (g!=NULL) pCleardenom(g);
-  else         return f; // g==0 => gcd=f (but do a pCleardenom)
-  if (f==NULL) return g; // f==0 => gcd=g (but do a pCleardenom)
-
-  if (pIsConstantPoly(f) || pIsConstantPoly(g))
-  {
-    pDelete(&f);
-    pDelete(&g);
-    return pOne();
-  }
-
-  // for now there is only the possibility to handle polynomials over
-  // Q and Fp ...
-  Off(SW_RATIONAL);
-  if (( nGetChar() == 0 || nGetChar() > 1 )
-  && (currRing->parameter==NULL))
-  {
-    CanonicalForm newGCD(const CanonicalForm & A, const CanonicalForm & B);
-    setCharacteristic( nGetChar() );
-    CanonicalForm F( convSingPFactoryP( f ) ), G( convSingPFactoryP( g ) );
-    //if (nGetChar() > 1 )
-    //{
-    //  res=convFactoryPSingP( newGCD( F,G ));
-    //  if (!nGreaterZero(pGetCoeff(res))) res=pNeg(res);
-    //}
-    //else
-      res=convFactoryPSingP( gcd( F, G ) );
-  }
-  // and over Q(a) / Fp(a)
-  else if (( nGetChar()==1 ) /* Q(a) */
-  || (nGetChar() <-1))       /* Fp(a) */
-  {
-    if (nGetChar()==1) setCharacteristic( 0 );
-    else               setCharacteristic( -nGetChar() );
-    if (currRing->minpoly!=NULL)
-    {
-    #if 0
-      if (( nGetChar()==1 ) /* Q(a) */ && (!isOn(SW_USE_QGCD)))
-      {
-      //  WerrorS( feNotImplemented );
-        CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
-        //Varlist ord;
-        //ord.append(mipo.mvar());
-        CFList as(mipo);
-        Variable a=rootOf(mipo);
-        //CanonicalForm F( convSingAPFactoryAP( f,a ) ), G( convSingAPFactoryAP( g,a ) );
-        CanonicalForm F( convSingTrPFactoryP(f) ), G( convSingTrPFactoryP(g) );
-        //res= convFactoryAPSingAP( algcd( F, G, as, ord) );
-        //res= convFactoryAPSingAP( alg_gcd( F, G, as) );
-        res= convFactoryAPSingAP( alg_gcd( F, G, as) );
-      }
-      else
-      #endif
-      {
-        bool b=isOn(SW_USE_QGCD);
-        if ( nGetChar()==1 ) On(SW_USE_QGCD);
-        CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
-        Variable a=rootOf(mipo);
-        CanonicalForm F( convSingAPFactoryAP( f,a ) ), G( convSingAPFactoryAP( g,a ) );
-        res= convFactoryAPSingAP( gcd( F, G ) );
-        if (!b) Off(SW_USE_QGCD);
-      }
-    }
-    else
-    {
-      CanonicalForm F( convSingTrPFactoryP( f ) ), G( convSingTrPFactoryP( g ) );
-      res= convFactoryPSingTrP( gcd( F, G ) );
-    }
-  }
-  #if 0
-  else if (( nGetChar()>1 )&&(currRing->parameter!=NULL)) /* GF(q) */
-  {
-    int p=rChar(currRing);
-    int n=2;
-    int t=p*p;
-    while (t!=nChar) { t*=p;n++; }
-    setCharacteristic(p,n,'a');
-    CanonicalForm F( convSingGFFactoryGF( f ) ), G( convSingGFFactoryGF( g ) );
-    res= convFactoryGFSingGF( gcd( F, G ) );
-  }
-  #endif
-  else
-    WerrorS( feNotImplemented );
-
-  Off(SW_RATIONAL);
-  pDelete(&f);
-  pDelete(&g);
-  pTest(res);
-  return res;
-}
-
 poly singclap_gcd_r ( poly f, poly g, const ring r )
 {
@@ -141,5 +45,5 @@
     CanonicalForm newGCD(const CanonicalForm & A, const CanonicalForm & B);
     setCharacteristic( n_GetChar(r) );
-    CanonicalForm F( convSingPFactoryP( f,r ) ), G( convSingPFactoryP( g, r ) );
+    CanonicalForm F( convSingPFactoryP( f,0,r ) ), G( convSingPFactoryP( g,0, r ) );
     //if (nGetChar() > 1 )
     //{
@@ -150,8 +54,78 @@
       res=convFactoryPSingP( gcd( F, G ) , r);
   }
+  // and over Q(a) / Fp(a)
+  else if (( n_GetChar(r)==1 ) /* Q(a) */
+  || (n_GetChar(r) <-1))       /* Fp(a) */
+  {
+    if (n_GetChar(r)==1) setCharacteristic( 0 );
+    else                 setCharacteristic( -n_GetChar(r) );
+    if (r->minpoly!=NULL)
+    {
+    #if 0
+      if (( n_GetChar(r)==1 ) /* Q(a) */ && (!isOn(SW_USE_QGCD)))
+      {
+      //  WerrorS( feNotImplemented );
+        CanonicalForm mipo=convSingPFactoryP(((lnumber)r->minpoly)->z,0,r->algring);
+        //Varlist ord;
+        //ord.append(mipo.mvar());
+        CFList as(mipo);
+        Variable a=rootOf(mipo);
+        //CanonicalForm F( convSingAPFactoryAP( f,a,r ) ), G( convSingAPFactoryAP( g,a,r ) );
+        CanonicalForm F( convSingTrPFactoryP(f,r) ), G( convSingTrPFactoryP(g,r) );
+        //res= convFactoryAPSingAP( algcd( F, G, as, ord) );
+        //res= convFactoryAPSingAP( alg_gcd( F, G, as) );
+        res= convFactoryAPSingAP( alg_gcd( F, G, as),r );
+      }
+      else
+      #endif
+      {
+        bool b=isOn(SW_USE_QGCD);
+        if ( nGetChar()==1 ) On(SW_USE_QGCD);
+        CanonicalForm mipo=convSingPFactoryP(((lnumber)r->minpoly)->z,
+                                           0,r->algring);
+        Variable a=rootOf(mipo);
+        CanonicalForm F( convSingAPFactoryAP( f,a ) ),
+                      G( convSingAPFactoryAP( g,a ) );
+        res= convFactoryAPSingAP( gcd( F, G ) );
+        if (!b) Off(SW_USE_QGCD);
+      }
+    }
+    else
+    {
+      CanonicalForm F( convSingTrPFactoryP( f,r ) ), G( convSingTrPFactoryP( g,r ) );
+      res= convFactoryPSingTrP( gcd( F, G ),r );
+    }
+  }
+  #if 0
+  else if (( n_GetChar(r)>1 )&&(r->parameter!=NULL)) /* GF(q) */
+  {
+    int p=rChar(r);
+    int n=2;
+    int t=p*p;
+    while (t!=n_Char(r)) { t*=p;n++; }
+    setCharacteristic(p,n,'a');
+    CanonicalForm F( convSingGFFactoryGF( f,r ) ), G( convSingGFFactoryGF( g,r ) );
+    res= convFactoryGFSingGF( gcd( F, G ),r );
+  }
+  #endif
   else
     WerrorS( feNotImplemented );
 
   Off(SW_RATIONAL);
+  return res;
+}
+
+poly singclap_gcd ( poly f, poly g )
+{
+  poly res=NULL;
+
+  if (f!=NULL) pCleardenom(f);
+  if (g!=NULL) pCleardenom(g);
+  else         return f; // g==0 => gcd=f (but do a pCleardenom)
+  if (f==NULL) return g; // f==0 => gcd=g (but do a pCleardenom)
+
+  res=singclap_gcd_r(f,g,currRing);
+  pDelete(&f);
+  pDelete(&g);
   return res;
 }
@@ -204,5 +178,6 @@
     {
       //Variable X(i);
-      CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+      CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+                                                 0,currRing->algring);
       Variable a=rootOf(mipo);
       CanonicalForm F( convSingAPFactoryAP( f,a ) ), G( convSingAPFactoryAP( g,a ) );
@@ -345,5 +320,6 @@
     if (currRing->minpoly!=NULL)
     {
-      CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+      CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+                                                 0,currRing->algring);
       Variable a=rootOf(mipo);
       CanonicalForm F( convSingAPFactoryAP( f,a ) ), G( convSingAPFactoryAP( g,a ) );
@@ -373,4 +349,81 @@
       pa=convFactoryPSingTrP(Fa);
       pb=convFactoryPSingTrP(Gb);
+    }
+    Off(SW_RATIONAL);
+  }
+  else
+  {
+    WerrorS( feNotImplemented );
+    return TRUE;
+  }
+  return FALSE;
+}
+
+BOOLEAN singclap_extgcd_r ( poly f, poly g, poly &res, poly &pa, poly &pb, const ring r )
+{
+  // for now there is only the possibility to handle univariate
+  // polynomials over
+  // Q and Fp ...
+  res=NULL;pa=NULL;pb=NULL;
+  On(SW_SYMMETRIC_FF);
+  if (( n_GetChar(r) == 0 || n_GetChar(r) > 1 )
+  && (r->parameter==NULL))
+  {
+    setCharacteristic( n_GetChar(r) );
+    CanonicalForm F( convSingPFactoryP( f,0,r ) ), G( convSingPFactoryP( g,0,r) );
+    CanonicalForm FpG=F+G;
+    if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
+    //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
+    {
+      Off(SW_RATIONAL);
+      WerrorS("not univariate");
+      return TRUE;
+    }
+    CanonicalForm Fa,Gb;
+    On(SW_RATIONAL);
+    res=convFactoryPSingP( extgcd( F, G, Fa, Gb ),r );
+    pa=convFactoryPSingP(Fa,r);
+    pb=convFactoryPSingP(Gb,r);
+    Off(SW_RATIONAL);
+  }
+  // and over Q(a) / Fp(a)
+  else if (( n_GetChar(r)==1 ) /* Q(a) */
+  || (n_GetChar(r) <-1))       /* Fp(a) */
+  {
+    if (n_GetChar(r)==1) setCharacteristic( 0 );
+    else                 setCharacteristic( -n_GetChar(r) );
+    CanonicalForm Fa,Gb;
+    if (r->minpoly!=NULL)
+    {
+      CanonicalForm mipo=convSingPFactoryP(((lnumber)r->minpoly)->z,
+                                            0,r->algring);
+      Variable a=rootOf(mipo);
+      CanonicalForm F( convSingAPFactoryAP( f,a ) ),
+                    G( convSingAPFactoryAP( g,a ) );
+      CanonicalForm FpG=F+G;
+      if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
+      //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
+      {
+        WerrorS("not univariate");
+        return TRUE;
+      }
+      res= convFactoryAPSingAP( extgcd( F, G, Fa, Gb ) );
+      pa=convFactoryAPSingAP(Fa);
+      pb=convFactoryAPSingAP(Gb);
+    }
+    else
+    {
+      CanonicalForm F( convSingTrPFactoryP( f, r ) ), G( convSingTrPFactoryP( g, r ) );
+      CanonicalForm FpG=F+G;
+      if (!(FpG.isUnivariate()|| FpG.inCoeffDomain()))
+      //if (!F.isUnivariate() || !G.isUnivariate() || F.mvar()!=G.mvar())
+      {
+        Off(SW_RATIONAL);
+        WerrorS("not univariate");
+        return TRUE;
+      }
+      res= convFactoryPSingTrP( extgcd( F, G, Fa, Gb ), r );
+      pa=convFactoryPSingTrP(Fa, r);
+      pb=convFactoryPSingTrP(Gb, r);
     }
     Off(SW_RATIONAL);
@@ -405,5 +458,6 @@
     if (currRing->minpoly!=NULL)
     {
-      CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+      CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+                                                 0,currRing->algring);
       Variable a=rootOf(mipo);
       CanonicalForm F( convSingAPFactoryAP( f,a ) ), G( convSingAPFactoryAP( g,a ) );
@@ -492,6 +546,6 @@
       pIter(p);
     }
-    g = convSingTrFactoryP( ((lnumber)g1)->z );
-    g = gcd( g, convSingTrFactoryP( ((lnumber)g2)->z ));
+    g = convSingPFactoryP( ((lnumber)g1)->z, 0,currRing->algring );
+    g = gcd( g, convSingPFactoryP( ((lnumber)g2)->z , 0,currRing->algring));
 
     // second run: gcd's
@@ -500,5 +554,5 @@
     while ( (p != NULL) && (g != 1)  && ( g != 0))
     {
-      h = convSingTrFactoryP( ((lnumber)pGetCoeff(p))->z );
+      h = convSingPFactoryP( ((lnumber)pGetCoeff(p))->z, 0,currRing->algring );
       pIter( p );
 
@@ -519,5 +573,5 @@
         lnumber c=(lnumber)pGetCoeff(p);
         napDelete(&c->z);
-        c->z=convFactoryPSingTr( i.getItem() / g );
+        c->z=convFactoryPSingP( i.getItem() / g, currRing->algring );
         //nTest((number)c);
         //#ifdef LDEBUG
@@ -566,5 +620,6 @@
       if (currRing->minpoly!=NULL)
       {
-        CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+        CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+                                    0,currRing->algring);
         a=rootOf(mipo);
         F=convSingAPFactoryAP( f,a );
@@ -789,5 +844,6 @@
     if (currRing->minpoly!=NULL)
     {
-      CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+      CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+                   0,currRing->algring);
       Variable a=rootOf(mipo);
       CanonicalForm F( convSingAPFactoryAP( f,a ) );
@@ -1133,5 +1189,6 @@
     if (currRing->minpoly!=NULL)
     {
-      CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+      CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+                    0,currRing->algring);
       Variable a=rootOf(mipo);
       CanonicalForm F( convSingAPFactoryAP( f,a ) );
@@ -1386,5 +1443,6 @@
     //if (currRing->minpoly!=NULL)
     //{
-    //  CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+    //  CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+    //                                             0,currRing->algring);
     //  Variable a=rootOf(mipo);
     //  CanonicalForm F( convSingAPFactoryAP( f,a ) );
@@ -1440,5 +1498,6 @@
     if (currRing->minpoly!=NULL)
     {
-      CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+      CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+                                            0,currRing->algring);
       Variable a=rootOf(mipo);
       int i,j;
@@ -1497,5 +1556,6 @@
  if (currRing->minpoly!=NULL)
  {
-   CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+   CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+                                         0,currRing->algring);
    Variable a=rootOf(mipo);
    CanonicalForm F( convSingAFactoryA( f,a ) ), G( convSingAFactoryA( g,a ) );
@@ -1510,5 +1570,6 @@
  else
  {
-   CanonicalForm F( convSingTrFactoryP( f ) ), G( convSingTrFactoryP( g ) );
+   CanonicalForm F( convSingPFactoryP( f,0,currRing->algring ) ),
+                 G( convSingPFactoryP( g,0,currRing->algring ) );
    CanonicalForm GCD;
    // calculate gcd
@@ -1516,5 +1577,5 @@
 
    // calculate lcm
-   res= convFactoryPSingTr( (F/GCD)*G );
+   res= convFactoryPSingP( (F/GCD)*G, currRing->algring );
  }
 
@@ -1533,5 +1594,6 @@
  if (currRing->minpoly!=NULL)
  {
-   CanonicalForm mipo=convSingTrFactoryP(((lnumber)currRing->minpoly)->z);
+   CanonicalForm mipo=convSingPFactoryP(((lnumber)currRing->minpoly)->z,
+                         0,currRing->algring);
    Variable a=rootOf(mipo);
    CanonicalForm F( convSingAFactoryA( f,a ) ), G( convSingAFactoryA( g,a ) );
@@ -1548,5 +1610,6 @@
  else
  {
-   CanonicalForm F( convSingTrFactoryP( f ) ), G( convSingTrFactoryP( g ) );
+   CanonicalForm F( convSingPFactoryP( f,0,currRing->algring ) ),
+                 G( convSingPFactoryP( g,0,currRing->algring ) );
    CanonicalForm GCD;
 
@@ -1555,6 +1618,6 @@
    if ((GCD!=1) && (GCD!=0))
    {
-     ff= convFactoryPSingTr( F/ GCD );
-     gg= convFactoryPSingTr( G/ GCD );
+     ff= convFactoryPSingP( F/ GCD, currRing->algring );
+     gg= convFactoryPSingP( G/ GCD, currRing->algring );
    }
  }
Index: kernel/clapsing.h
===================================================================
--- kernel/clapsing.h	(revision ab33f6e148aa2f8f6099e5a25a55a07f1e7fdd2b)
+++ kernel/clapsing.h	(revision 6620d757775d0859e2fea065552c5016ad0a0089)
@@ -3,5 +3,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-// $Id: clapsing.h,v 1.3 2009-08-05 17:29:12 Singular Exp $
+// $Id: clapsing.h,v 1.4 2009-08-13 15:17:03 Singular Exp $
 /*
 * ABSTRACT: interface between Singular and factory
@@ -26,4 +26,5 @@
 
 BOOLEAN singclap_extgcd ( poly f, poly g, poly &res, poly &pa, poly &pb );
+BOOLEAN singclap_extgcd_r ( poly f, poly g, poly &res, poly &pa, poly &pb, const ring r );
 
 poly singclap_pdivide ( poly f, poly g );
Index: kernel/longalg.cc
===================================================================
--- kernel/longalg.cc	(revision ab33f6e148aa2f8f6099e5a25a55a07f1e7fdd2b)
+++ kernel/longalg.cc	(revision 6620d757775d0859e2fea065552c5016ad0a0089)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: longalg.cc,v 1.44 2009-08-07 13:55:21 Singular Exp $ */
+/* $Id: longalg.cc,v 1.45 2009-08-13 15:17:03 Singular Exp $ */
 /*
 * ABSTRACT:   algebraic numbers
@@ -34,5 +34,4 @@
 napoly naMinimalPoly;
 #define naParNames (currRing->parameter)
-#define napNormalize(p) p_Normalize(p,nacRing)
 static int naIsChar0;
 static int naPrimeM;
@@ -204,6 +203,6 @@
   qq = (napoly)p_Init(nacRing);
   napNext(qq) = NULL;
-  napNormalize(g);
-  napNormalize(f);
+  p_Normalize(g,nacRing);
+  p_Normalize(f,nacRing);
   a = f;
   do
@@ -216,5 +215,5 @@
     h = napCopy(g);
     napMultT(h, qq);
-    napNormalize(h);
+    p_Normalize(h,nacRing);
     n_Delete(&napGetCoeff(qq),nacRing);
     a = napAdd(a, h);
@@ -234,6 +233,6 @@
   qq = (napoly)p_Init(nacRing);
   napNext(qq) = b = NULL;
-  napNormalize(g);
-  napNormalize(f);
+  p_Normalize(g,nacRing);
+  p_Normalize(f,nacRing);
   a = f;
   do
@@ -247,5 +246,5 @@
     h = napCopy(g);
     napMultT(h, qq);
-    napNormalize(h);
+    p_Normalize(h,nacRing);
     n_Delete(&napGetCoeff(qq),nacRing);
     a = napAdd(a, h);
@@ -297,5 +296,5 @@
     qa=p_Mult_nn(qa,t,nacRing); p_Normalize(qa,nacRing);
     n_Delete(&t,nacRing);
-    napNormalize(qa);
+    p_Normalize(qa,nacRing);
     napDelete(&x);
     napDelete(&r);
@@ -316,5 +315,5 @@
     t = nacInvers(napGetCoeff(r));
     q=p_Mult_nn(q,t,nacRing); p_Normalize(q,nacRing);
-    napNormalize(q);
+    p_Normalize(q,nacRing);
     n_Delete(&t,nacRing);
     napDelete(&x);
@@ -345,5 +344,5 @@
       //nacNormalize(t);
       q=p_Mult_nn(q,t,nacRing); p_Normalize(q,nacRing);
-      napNormalize(q);
+      p_Normalize(q,nacRing);
       n_Delete(&t,nacRing);
       napDelete(&x);
@@ -1531,9 +1530,9 @@
     napoly rz=napGcd(x->z, y->z);
     CanonicalForm F, G, R;
-    R=convSingTrFactoryP(rz);
-    napNormalize(x->z);
-    F=convSingTrFactoryP(x->z)/R;
-    napNormalize(y->z);
-    G=convSingTrFactoryP(y->z)/R;
+    R=convSingPFactoryP(rz,0,nacRing);
+    p_Normalize(x->z,nacRing);
+    F=convSingPFactoryP(x->z,0,nacRing)/R;
+    p_Normalize(y->z,nacRing);
+    G=convSingPFactoryP(y->z,0,nacRing)/R;
     F = gcd( F, G );
     if (F.isOne())
@@ -1542,6 +1541,6 @@
     {
       napDelete(&rz);
-      result->z=convFactoryPSingTr( F*R );
-      napNormalize(result->z);
+      result->z=convFactoryPSingP( F*R, nacRing );
+      p_Normalize(result->z,nacRing);
     }
   }
