Changeset 109e13a in git


Ignore:
Timestamp:
Aug 11, 2016, 4:41:59 PM (8 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
75b12a8379e8fdc352f1ced846ad6cb2ee44ec22
Parents:
bb3cb8b3f5a0460e54db71baaf57c4d2aa2fd75c
Message:
Singular_4_1: n_polyExt
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Singular/table.h

    rbb3cb8b r109e13a  
    918918  { "close",       0, CLOSE_CMD ,         CMD_1},
    919919#ifdef SINGULAR_4_1
    920   { "cmatrix",     0, CMATRIX_CMD ,       ROOT_DECL_LIST},
    921   { "cnumber",     0, CNUMBER_CMD ,       ROOT_DECL_LIST},
     920  { "Matrix",     0, CMATRIX_CMD ,       ROOT_DECL_LIST},
     921  { "Number",     0, CNUMBER_CMD ,       ROOT_DECL_LIST},
    922922#endif
    923923  { "coef",        0, COEF_CMD ,          CMD_M},
  • libpolys/coeffs/coeffs.h

    rbb3cb8b r109e13a  
    3333  n_GF, /**< \GF{p^n < 2^16} */
    3434  n_long_R, /**< real floating point (GMP) numbers */
     35  n_polyExt, /**< used to represent polys as coeffcients */
    3536  n_algExt,  /**< used for all algebraic extensions, i.e.,
    3637                the top-most extension in an extension tower
  • libpolys/polys/ext_fields/algext.cc

    rbb3cb8b r109e13a  
    6565#endif
    6666
    67 /// Our own type!
    68 static const n_coeffType ID = n_algExt;
    69 
    7067/* polynomial ring in which our numbers live */
    7168#define naRing cf->extRing
     
    8683BOOLEAN  naIsOne(number a, const coeffs cf);
    8784BOOLEAN  naIsMOne(number a, const coeffs cf);
    88 BOOLEAN  naIsZero(number a, const coeffs cf);
    8985number   naInit(long i, const coeffs cf);
    90 long     naInt(number &a, const coeffs cf);
    9186number   naNeg(number a, const coeffs cf);
    9287number   naInvers(number a, const coeffs cf);
     
    10297number   naGetNumerator(number &a, const coeffs cf);
    10398number   naGcd(number a, number b, const coeffs cf);
    104 int      naSize(number a, const coeffs cf);
    10599void     naDelete(number *a, const coeffs cf);
    106100void     naCoeffWrite(const coeffs cf, BOOLEAN details);
     
    10371031{
    10381032  /* dst is expected to be an algebraic field extension */
    1039   assume(getCoeffType(dst) == ID);
     1033  assume(getCoeffType(dst) == n_algExt);
    10401034
    10411035  if( src == dst ) return ndCopyMap;
     
    10871081}
    10881082
    1089 static int naParDeg(number a, const coeffs cf)
     1083int naParDeg(number a, const coeffs cf)
    10901084{
    10911085  if (a == NULL) return -1;
     
    10951089
    10961090/// return the specified parameter as a number in the given alg. field
    1097 static number naParameter(const int iParameter, const coeffs cf)
    1098 {
    1099   assume(getCoeffType(cf) == ID);
     1091number naParameter(const int iParameter, const coeffs cf)
     1092{
     1093  assume(getCoeffType(cf) == n_algExt);
    11001094
    11011095  const ring R = cf->extRing;
     
    11121106int naIsParam(number m, const coeffs cf)
    11131107{
    1114   assume(getCoeffType(cf) == ID);
     1108  assume((getCoeffType(cf) == n_algExt)||(getCoeffType(cf) == n_polyExt));
    11151109
    11161110  const ring R = cf->extRing;
     
    11211115
    11221116
    1123 static void naClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
     1117void naClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
    11241118{
    11251119  assume(cf != NULL);
    1126   assume(getCoeffType(cf) == ID);
     1120  assume(getCoeffType(cf) == n_algExt);
    11271121  assume(nCoeff_is_Q_algext(cf)); // only over (Q[a]/m(a)), while the default impl. is used over Zp[a]/m(a) !
    11281122
     
    13221316
    13231317
    1324 static void naClearDenominators(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
     1318void naClearDenominators(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
    13251319{
    13261320  assume(cf != NULL);
    1327   assume(getCoeffType(cf) == ID);
     1321  assume((getCoeffType(cf) == n_algExt)||(getCoeffType(cf) == n_polyExt));
    13281322  assume(nCoeff_is_Q_algext(cf)); // only over (Q[a]/m(a)), while the default impl. is used over Zp[a]/m(a) !
    13291323
     
    14021396
    14031397  assume( cf != NULL );
    1404   assume(getCoeffType(cf) == ID);                     // coeff type;
     1398  assume(getCoeffType(cf) == n_algExt);                     // coeff type;
    14051399
    14061400  e->r->ref ++; // increase the ref.counter for the ground poly. ring!
     
    14881482template class IAccessor<snumber*>;
    14891483
     1484#ifdef SINGULAR_4_1
    14901485/* --------------------------------------------------------------------*/
    1491 #if 0
    1492 void npolyCoeffWrite(const coeffs cf, BOOLEAN details)
     1486/****************************************
     1487*  Computer Algebra System SINGULAR     *
     1488****************************************/
     1489/**
     1490  * ABSTRACT: numbers as polys in the ring K[a]
     1491  *           Assuming that we have a coeffs object cf, then these numbers
     1492  *           are polynomials in the polynomial ring K[a] represented by
     1493  *           cf->extRing.
     1494  *           IMPORTANT ASSUMPTIONS:
     1495  *           1.) So far we assume that cf->extRing is a valid polynomial
     1496  *               ring
     1497  **/
     1498
     1499#ifdef LDEBUG
     1500#define n2pTest(a) n2pDBTest(a,__FILE__,__LINE__,cf)
     1501BOOLEAN  n2pDBTest(number a, const char *f, const int l, const coeffs r);
     1502#else
     1503#define n2pTest(a) do {} while (0)
     1504#endif
     1505
     1506/* polynomial ring in which our numbers live */
     1507#define n2pRing cf->extRing
     1508
     1509/* coeffs object in which the coefficients of our numbers live;
     1510 * methods attached to n2pCoeffs may be used to compute with the
     1511 * coefficients of our numbers, e.g., use n2pCoeffs->nAdd to add
     1512 * coefficients of our numbers */
     1513#define n2pCoeffs cf->extRing->cf
     1514
     1515#ifdef LDEBUG
     1516BOOLEAN n2pDBTest(number a, const char *f, const int l, const coeffs cf)
     1517{
     1518  if (a == NULL) return TRUE;
     1519  return p_DBTest((poly)a, n2pRing,f,l);
     1520}
     1521#endif
     1522
     1523void  n2pNormalize(number &a, const coeffs cf)
     1524{
     1525  poly aa=(poly)a;
     1526  p_Normalize(aa,n2pRing);
     1527}
     1528
     1529/* TRUE iff (a != 0 and (b == 0 or deg(a) > deg(b) or (deg(a)==deg(b) && lc(a)>lc(b))) */
     1530number n2pMult(number a, number b, const coeffs cf)
     1531{
     1532  n2pTest(a); n2pTest(b);
     1533  if ((a == NULL)||(b == NULL)) return NULL;
     1534  poly aTimesB = p_Mult_q(p_Copy((poly)a, n2pRing),
     1535                          p_Copy((poly)b, n2pRing), n2pRing);
     1536  return (number)aTimesB;
     1537}
     1538
     1539number n2pDiv(number a, number b, const coeffs cf)
     1540{
     1541  n2pTest(a); n2pTest(b);
     1542  if (b == NULL) WerrorS(nDivBy0);
     1543  if (a == NULL) return NULL;
     1544  poly p=singclap_pdivide((poly)a,(poly)b,n2pRing);
     1545  return (number)p;
     1546}
     1547
     1548void n2pPower(number a, int exp, number *b, const coeffs cf)
     1549{
     1550  n2pTest(a);
     1551 
     1552  *b= (number)p_Power((poly)a,exp,n2pRing);
     1553}
     1554
     1555const char * n2pRead(const char *s, number *a, const coeffs cf)
     1556{
     1557  poly aAsPoly;
     1558  const char * result = p_Read(s, aAsPoly, n2pRing);
     1559  *a = (number)aAsPoly;
     1560  return result;
     1561}
     1562
     1563/* expects *param to be castable to AlgExtInfo */
     1564static BOOLEAN n2pCoeffIsEqual(const coeffs cf, n_coeffType n, void * param)
     1565{
     1566  if (n_polyExt != n) return FALSE;
     1567  AlgExtInfo *e = (AlgExtInfo *)param;
     1568  /* for extension coefficient fields we expect the underlying
     1569     polynomial rings to be IDENTICAL, i.e. the SAME OBJECT;
     1570     this expectation is based on the assumption that we have properly
     1571     registered cf and perform reference counting rather than creating
     1572     multiple copies of the same coefficient field/domain/ring */
     1573  if (n2pRing == e->r)
     1574    return TRUE;
     1575  // NOTE: Q(a)[x] && Q(a)[y] should better share the _same_ Q(a)...
     1576  if( rEqual(n2pRing, e->r, TRUE) ) // also checks the equality of qideals
     1577  {
     1578    rDelete(e->r);
     1579    return TRUE;
     1580  }
     1581  return FALSE;
     1582}
     1583
     1584void n2pKillChar(coeffs cf)
     1585{
     1586   if ((--cf->extRing->ref) == 0)
     1587     rDelete(cf->extRing);
     1588}
     1589
     1590char* n2pCoeffString(const coeffs r) // currently also for tranext.
     1591{
     1592  const char* const* p=n_ParameterNames(r);
     1593  int l=0;
     1594  int i;
     1595  for(i=0; i<n_NumberOfParameters(r);i++)
     1596  {
     1597    l+=(strlen(p[i])+1);
     1598  }
     1599  char *s=(char *)omAlloc(l+10+1);
     1600  s[0]='\0';
     1601  snprintf(s,10+1,"%d",r->ch); /* Fp(a) or Q(a) */
     1602  char tt[2];
     1603  tt[0]=',';
     1604  tt[1]='\0';
     1605  for(i=0; i<n_NumberOfParameters(r);i++)
     1606  {
     1607    strcat(s,tt);
     1608    strcat(s,p[i]);
     1609  }
     1610  return s;
     1611}
     1612
     1613void n2pCoeffWrite(const coeffs cf, BOOLEAN details)
    14931614{
    14941615  assume( cf != NULL );
     
    15011622  PrintLn();
    15021623}
    1503 number npolyMult(number a, number b, const coeffs cf)
    1504 {
    1505   naTest(a); naTest(b);
    1506   if ((a == NULL)||(b == NULL)) return NULL;
    1507   poly aTimesB = p_Mult_q(p_Copy((poly)a, naRing),
    1508                           p_Copy((poly)b, naRing), naRing);
    1509   return (number)aTimesB;
    1510 }
    1511 
    1512 void npolyPower(number a, int exp, number *b, const coeffs cf)
    1513 {
    1514   naTest(a);
    1515 
    1516   /* special cases first */
    1517   if (a == NULL)
    1518   {
    1519     if (exp >= 0) *b = NULL;
    1520     else          WerrorS(nDivBy0);
    1521     return;
    1522   }
    1523   else if (exp ==  0) { *b = naInit(1, cf); return; }
    1524   else if (exp ==  1) { *b = naCopy(a, cf); return; }
    1525   else if (exp == -1) { *b = naInvers(a, cf); return; }
    1526 
    1527   int expAbs = exp; if (expAbs < 0) expAbs = -expAbs;
    1528 
    1529   /* now compute a^expAbs */
    1530   poly pow; poly aAsPoly = (poly)a;
    1531   if (expAbs <= 7)
    1532   {
    1533     pow = p_Copy(aAsPoly, naRing);
    1534     for (int i = 2; i <= expAbs; i++)
    1535     {
    1536       pow = p_Mult_q(pow, p_Copy(aAsPoly, naRing), naRing);
    1537     }
     1624
     1625number  n2pInvers(number a, const coeffs cf)
     1626{
     1627  poly aa=(poly)a;
     1628  if(p_IsConstant(aa, n2pRing))
     1629  {
     1630    poly p=p_Init(n2pRing);
     1631    p_SetCoeff0(p,n_Invers(pGetCoeff(aa),n2pCoeffs),n2pRing);
     1632    return (number)p;
    15381633  }
    15391634  else
    15401635  {
    1541     pow = p_ISet(1, naRing);
    1542     poly factor = p_Copy(aAsPoly, naRing);
    1543     while (expAbs != 0)
    1544     {
    1545       if (expAbs & 1)
    1546       {
    1547         pow = p_Mult_q(pow, p_Copy(factor, naRing), naRing);
    1548       }
    1549       expAbs = expAbs / 2;
    1550       if (expAbs != 0)
    1551       {
    1552         factor = p_Mult_q(factor, p_Copy(factor, naRing), naRing);
    1553       }
    1554     }
    1555     p_Delete(&factor, naRing);
    1556   }
    1557 
    1558   /* invert if original exponent was negative */
    1559   number n = (number)pow;
    1560   if (exp < 0)
    1561   {
    1562     number m = npolyInvers(n, cf);
    1563     naDelete(&n, cf);
    1564     n = m;
    1565   }
    1566   *b = n;
    1567 }
    1568 
    1569 number npolyDiv(number a, number b, const coeffs cf)
    1570 {
    1571   naTest(a); naTest(b);
    1572   if (b == NULL) WerrorS(nDivBy0);
    1573   if (a == NULL) return NULL;
    1574   poly p=singclap_pdivide((poly)a,(poly)b,naRing);
    1575   return (number)p;
    1576 }
    1577 
    1578 
    1579 BOOLEAN npolyInitChar(coeffs cf, void * infoStruct)
     1636    WerrorS("not invertible");
     1637    return NULL;
     1638  }
     1639}
     1640
     1641BOOLEAN n2pInitChar(coeffs cf, void * infoStruct)
    15801642{
    15811643  assume( infoStruct != NULL );
     
    15991661  cf->is_domain=TRUE;
    16001662
    1601   cf->cfCoeffString = naCoeffString;
     1663  cf->cfCoeffString = n2pCoeffString;
    16021664
    16031665  cf->cfGreaterZero  = naGreaterZero;
     
    16091671  cf->cfInit         = naInit;
    16101672  cf->cfFarey        = naFarey;
    1611   cf->cfChineseRemainderSym= naChineseRemainder;
     1673  cf->cfChineseRemainder= naChineseRemainder;
    16121674  cf->cfInt          = naInt;
    16131675  cf->cfInpNeg       = naNeg;
    16141676  cf->cfAdd          = naAdd;
    16151677  cf->cfSub          = naSub;
    1616   cf->cfMult         = npolyMult;
    1617   cf->cfDiv          = npolyDiv;
    1618   cf->cfPower        = naPower;
     1678  cf->cfMult         = n2pMult;
     1679  cf->cfDiv          = n2pDiv;
     1680  cf->cfPower        = n2pPower;
    16191681  cf->cfCopy         = naCopy;
    16201682
    16211683  cf->cfWriteLong        = naWriteLong;
    16221684
    1623   if( rCanShortOut(naRing) )
     1685  if( rCanShortOut(n2pRing) )
    16241686    cf->cfWriteShort = naWriteShort;
    16251687  else
    16261688    cf->cfWriteShort = naWriteLong;
    16271689
    1628   cf->cfRead         = naRead;
     1690  cf->cfRead         = n2pRead;
    16291691  cf->cfDelete       = naDelete;
    16301692  cf->cfSetMap       = naSetMap;
     
    16321694  cf->cfGetNumerator = naGetNumerator;
    16331695  cf->cfRePart       = naCopy;
    1634   cf->cfCoeffWrite   = npolyCoeffWrite;
    1635   cf->cfNormalize    = npolyNormalize;
     1696  cf->cfCoeffWrite   = n2pCoeffWrite;
     1697  cf->cfNormalize    = n2pNormalize;
    16361698  cf->cfKillChar     = naKillChar;
    16371699#ifdef LDEBUG
     
    16411703  cf->cfNormalizeHelper          = naLcmContent;
    16421704  cf->cfSize         = naSize;
    1643   cf->nCoeffIsEqual  = naCoeffIsEqual;
    1644   cf->cfInvers       = npolyInvers;
     1705  cf->nCoeffIsEqual  = n2pCoeffIsEqual;
     1706  cf->cfInvers       = n2pInvers;
    16451707  cf->convFactoryNSingN=naConvFactoryNSingN;
    16461708  cf->convSingNFactoryN=naConvSingNFactoryN;
  • libpolys/polys/ext_fields/algext.h

    rbb3cb8b r109e13a  
    4545/// Initialize the coeffs object
    4646BOOLEAN  naInitChar(coeffs cf, void* infoStruct);
     47BOOLEAN n2pInitChar(coeffs cf, void * infoStruct);
    4748
    4849/// if m == var(i)/1 => return i,
  • libpolys/polys/monomials/ring.cc

    rbb3cb8b r109e13a  
    56465646  const n_coeffType _filed_type = getCoeffType(C);
    56475647
    5648   if( _filed_type == n_algExt )
     5648  if(( _filed_type == n_algExt )||( _filed_type == n_polyExt ))
    56495649    return naIsParam(m, C);
    56505650
Note: See TracChangeset for help on using the changeset viewer.