Changeset c28ecf in git


Ignore:
Timestamp:
May 19, 2011, 2:52:08 PM (12 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '00e2e9c41af3fde1273eb3633f4c0c7c3db2579d')
Children:
4a2260efc22c19ac8eaf58d529af8decbb9420bb
Parents:
f0b01f1bf67efed9ec49d9df0d55f75284f5d968
git-author:
Frank Seelisch <seelisch@mathematik.uni-kl.de>2011-05-19 14:52:08+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:36:12+01:00
Message:
alg ext implementation now passing all coeffs and polys tests
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    rf0b01f rc28ecf  
    102102ntl/src/gen_gmp_aux
    103103ntl/src/gen_lip_gmp_aux
     104libpolys/tests/gftables
     105libpolys/tests/p_Procs_*.so
    104106aclocal.m4
    105107autom4te.cache/
  • libpolys/coeffs/longrat.cc

    rf0b01f rc28ecf  
    223223    return FALSE;
    224224  }
    225   // only, if gmp memeory routine are from omalloc:
     225  /* TODO: If next line is active, then computations in algebraic field
     226           extensions over Q will throw a lot of assume violations although
     227           everything is computed correctly and no seg fault appears.
     228           Maybe the test is not appropriate in this case. */
    226229  //omCheckAddrSize(a->z[0]._mp_d,a->z[0]._mp_alloc*BYTES_PER_MP_LIMB);
    227230  if (a->z[0]._mp_alloc==0)
     
    230233  if (a->s<2)
    231234  {
    232     // only, if gmp memeory routine are from omalloc:
     235    /* TODO: If next line is active, then computations in algebraic field
     236             extensions over Q will throw a lot of assume violations although
     237             everything is computed correctly and no seg fault appears.
     238             Maybe the test is not appropriate in this case. */
    233239    //omCheckIf(omCheckAddrSize(a->n[0]._mp_d,a->n[0]._mp_alloc*BYTES_PER_MP_LIMB), return FALSE);
    234240    if (a->z[0]._mp_alloc==0)
  • libpolys/polys/ext_fields/algext.cc

    rf0b01f rc28ecf  
    7575  assume(getCoeffType(cf) == naID);
    7676  if (a == NULL) return TRUE;
    77   p_Test((poly)a, naRing); // cannot use omCheckAddrSize(a, sizeof(*a)) here
     77  p_Test((poly)a, naRing);
    7878  assume(p_Deg((poly)a, naRing) <= p_Deg(naMinpoly, naRing));
    7979  return TRUE;
     
    9090}
    9191
    92 void naDelete(number *a, const coeffs cf)
    93 {
    94   if (a == NULL) return;
    95   p_Delete((poly *)a, naRing);
     92void naDelete(number * a, const coeffs cf)
     93{
     94  if (*a == NULL) return;
     95  poly aAsPoly = (poly)(*a);
     96  p_Delete(&aAsPoly, naRing);
    9697  *a = NULL;
    9798}
     
    339340{
    340341  #ifdef LDEBUG
    341   omCheckAddr(p); omCheckAddr(reducer);
     342  p_Test((poly)p, naRing);
     343  p_Test((poly)reducer, naRing);
    342344  #endif
    343345  if (p_Deg(p, naRing) > 10 * p_Deg(reducer, naRing))
     
    427429{
    428430  #ifdef LDEBUG
    429   omCheckAddr(p); omCheckAddr(reducer);
     431  p_Test((poly)p, naRing);
     432  p_Test((poly)reducer, naRing);
    430433  #endif
    431434  p_PolyDiv(p, reducer, FALSE, naRing);
     
    443446  naTest(a);
    444447  if (a == NULL) WerrorS(nDivBy0);
    445   poly aFactor; poly mFactor;
     448  poly aFactor = NULL; poly mFactor = NULL;
    446449  poly theGcd = p_ExtGcd((poly)a, aFactor, naMinpoly, mFactor, naRing);
    447   /* the gcd must be one since naMinpoly is irreducible and a != NULL: */
     450  /* the gcd must be 1 since naMinpoly is irreducible and a != NULL: */
    448451  assume(naIsOne((number)theGcd, cf));     
    449452  p_Delete(&theGcd, naRing);
    450453  p_Delete(&mFactor, naRing);
     454  /* printf("naInvers\n");
     455     p_Write((poly)a, naRing);
     456     p_Write(aFactor, naRing); */
    451457  return (number)(aFactor);
    452458}
     
    566572 
    567573  #ifdef LDEBUG
    568   omCheckAddr(naMinpoly);
     574  p_Test((poly)naMinpoly, naRing);
    569575  #endif
    570576 
  • libpolys/polys/ext_fields/algext.h

    rf0b01f rc28ecf  
    6969number   naLcm(number a, number b, const coeffs cf);
    7070number   naSize(number a, const coeffs cf);
    71 void     naDelete(number *a, const coeffs cf);
     71void     naDelete(number * a, const coeffs cf);
    7272void     naCoeffWrite(const coeffs cf);
    7373number   naIntDiv(number a, number b, const coeffs cf);
  • libpolys/polys/monomials/p_polys.cc

    rf0b01f rc28ecf  
    14531453  int divisorLE = p_GetExp(divisor, 1, r);
    14541454//p_Write(p, r); p_Write(divisor, r);
    1455   while ((p != NULL) && (p_Deg(p, r) > p_Deg(divisor, r)))
     1455  while ((p != NULL) && (p_Deg(p, r) >= p_Deg(divisor, r)))
    14561456  {
    14571457    /* determine t = LT(p) / LT(divisor) */
     
    14621462    p_SetExp(t, 1, e, r);
    14631463    p_Setm(t, r);
    1464 //printf("t\n"); p_Write(t, r);
    14651464    if (needResult) result = p_Add_q(result, p_Copy(t, r), r);
    1466 //t = p_Mult_q(t, p_Copy(divisor, r), r); p_Write(t, r);
    1467 //t = p_Neg(t, r); p_Write(t, r);
    1468 //printf("p\n"); p_Write(p, r);
    1469 //t = p_Add_q(p, t, r); p_Write(t, r);
    1470 //p = t;
    14711465    p = p_Add_q(p, p_Neg(p_Mult_q(t, p_Copy(divisor, r), r), r), r);
    1472 //printf("EXECUTION STOPPED\n"); while (1) { };
    14731466  }
    14741467  n_Delete(&divisorLC, r->cf);
     1468//printf("p_PolyDiv result:\n");
     1469//p_Write(result, r);
    14751470  return result;
     1471}
     1472
     1473/* returns NULL if p == NULL, otherwise makes p monic by dividing
     1474   by its leading coefficient (only done if this is not already 1);
     1475   this assumes that we are over a ground field so that division
     1476   is well-defined;
     1477   modifies p */
     1478void p_Monic(poly &p, ring r)
     1479{
     1480  if (p == NULL) return;
     1481  poly pp = p;
     1482  number lc = p_GetCoeff(p, r);
     1483  if (n_IsOne(lc, r->cf)) return;
     1484  number n = n_Init(1, r->cf);
     1485  p_SetCoeff(p, n, r);
     1486  p = pIter(p);
     1487  while (p != NULL)
     1488  {
     1489    number c = p_GetCoeff(p, r);
     1490    number n = n_Div(c, lc, r->cf);
     1491    n_Delete(&c, r->cf);
     1492    p_SetCoeff(p, n, r);
     1493    p = pIter(p);
     1494  }
     1495  n_Delete(&lc, r->cf);
     1496  p = pp;
    14761497}
    14771498
     
    14811502poly p_GcdHelper(poly &p, poly &q, ring r)
    14821503{
    1483   if (q == NULL) return p;
     1504  if (q == NULL)
     1505  {
     1506    /* We have to make p monic before we return it, so that if the
     1507       gcd is a unit in the ground field, we will actually return 1. */
     1508    p_Monic(p, r);
     1509    return p;
     1510  }
    14841511  else
    14851512  {
     
    15111538                    ring r)
    15121539{
    1513 //printf("p_ExtGcdHelper:\n");
    15141540  if (q == NULL)
    15151541  {
    1516     qFactor = NULL; pFactor = p_ISet(1, r); return p;
     1542    qFactor = NULL;
     1543    pFactor = p_ISet(1, r);
     1544    number n = p_GetCoeff(pFactor, r);
     1545    p_SetCoeff(pFactor, n_Invers(p_GetCoeff(p, r), r->cf), r);
     1546    n_Delete(&n, r->cf);
     1547    p_Monic(p, r);
     1548    return p;
    15171549  }
    15181550  else
    15191551  {
     1552//printf("p_ExtGcdHelper1:\n");
    15201553//p_Write(p, r); p_Write(q, r);
    15211554    poly pDivQ = p_PolyDiv(p, q, TRUE, r);
    1522     poly ppFactor; poly qqFactor;
    1523     poly theGcd = p_ExtGcdHelper(q, ppFactor, p, qqFactor, r);
    1524     pFactor = qqFactor;
    1525     qFactor = p_Add_q(ppFactor,
    1526                       p_Neg(p_Mult_q(pDivQ, p_Copy(qqFactor, r), r), r),
     1555    poly ppFactor = NULL; poly qqFactor = NULL;
     1556//printf("p_ExtGcdHelper2:\n");
     1557//p_Write(p, r); p_Write(ppFactor, r);
     1558//p_Write(q, r); p_Write(qqFactor, r);
     1559    poly theGcd = p_ExtGcdHelper(q, qqFactor, p, ppFactor, r);
     1560//printf("p_ExtGcdHelper3:\n");
     1561//p_Write(q, r); p_Write(qqFactor, r);
     1562//p_Write(p, r); p_Write(ppFactor, r);
     1563//p_Write(theGcd, r);
     1564    pFactor = ppFactor;
     1565    qFactor = p_Add_q(qqFactor,
     1566                      p_Neg(p_Mult_q(pDivQ, p_Copy(ppFactor, r), r), r),
    15271567                      r);
     1568//printf("p_ExtGcdHelper4:\n");
     1569//p_Write(pFactor, r); p_Write(qFactor, r);
    15281570    return theGcd;
    15291571  }
     
    15401582poly p_ExtGcd(poly p, poly &pFactor, poly q, poly &qFactor, ring r)
    15411583{
    1542 //printf("p_ExtGcd:\n");
     1584//printf("p_ExtGcd1:\n");
    15431585//p_Write(p, r); p_Write(q, r);
    15441586  assume((p != NULL) || (q != NULL)); 
    1545   poly a = p; poly b = q;
    1546   poly aFactor = pFactor; poly bFactor = qFactor;
     1587  poly a = p; poly b = q; BOOLEAN aCorrespondsToP = TRUE;
    15471588  if (p_Deg(a, r) < p_Deg(b, r))
    1548   { a = q; b = p; aFactor = qFactor, bFactor = pFactor; }
     1589  { a = q; b = p; aCorrespondsToP = FALSE; }
    15491590  a = p_Copy(a, r); b = p_Copy(b, r);
    1550   return p_ExtGcdHelper(a, aFactor, b, bFactor, r);
     1591  poly aFactor = NULL; poly bFactor = NULL;
     1592  poly theGcd = p_ExtGcdHelper(a, aFactor, b, bFactor, r);
     1593  if (aCorrespondsToP) { pFactor = aFactor; qFactor = bFactor; }
     1594  else                 { pFactor = bFactor; qFactor = aFactor; }
     1595  return theGcd;
    15511596}
    15521597
  • libpolys/polys/monomials/p_polys.h

    rf0b01f rc28ecf  
    18391839poly      p_PolyDiv(poly &p, poly divisor, BOOLEAN needResult, ring r);
    18401840
     1841/* returns NULL if p == NULL, otherwise makes p monic by dividing
     1842   by its leading coefficient (only done if this is not already 1);
     1843   this assumes that we are over a ground field so that division
     1844   is well-defined;
     1845   modifies p */
     1846void      p_Monic(poly &p, ring r);
     1847
    18411848/* assumes that p and q are univariate polynomials in r,
    18421849   mentioning the same variable;
  • libpolys/tests/polys_test.h

    rf0b01f rc28ecf  
    208208class PolysTestSuite : public CxxTest::TestSuite
    209209{
     210private:
     211  void TestArithCf(const coeffs r)
     212  {
     213    clog << ("TEST: Simple Arithmetics: ");
     214    clog << endl;
     215
     216    number two = n_Init(2, r);
     217
     218    number t = n_Init(1, r); 
     219    ndInpAdd(t, t, r); 
     220    TS_ASSERT( n_Equal(two, t, r) );
     221    n_Delete(&t, r);
     222 
     223    if( getCoeffType(r) == n_Q )
     224    {
     225      number t = n_Init(1, r); 
     226      nlInpAdd(t, t, r);
     227      TS_ASSERT( n_Equal(two, t, r) );
     228      n_Delete(&t, r);
     229    }
     230 
     231    const int N = 66666;
     232
     233    number a = n_Init(N, r);
     234   
     235    clog<< "a: "; PrintSized(a, r);
     236
     237    clog<< "two: "; PrintSized(two, r);
     238
     239    number aa0 = n_Init(N*2, r);
     240
     241    number aa = n_Add(a, a, r);
     242
     243    clog<< "aa = a + a: "; PrintSized(aa, r);
     244 
     245    number aa2 = n_Mult(a, two, r);
     246
     247    clog<< "aa2 = a * 2: "; PrintSized(aa2, r);
     248
     249    number aa1 = n_Mult(two, a, r);
     250 
     251    clog<< "aa1 = 2 * a: "; PrintSized(aa1, r);
     252
     253    n_Delete(&a, r);
     254    n_Delete(&two, r);
     255
     256    a = n_Sub( aa, aa1, r );
     257 
     258    clog<< "a = aa - aa1: "; PrintSized(a, r);
     259
     260    TS_ASSERT( n_IsZero(a, r) );
     261
     262    n_Delete(&a, r);
     263
     264    a = n_Sub( aa, aa2, r );
     265
     266    clog<< "a = aa - aa2: "; PrintSized(a, r);
     267
     268    TS_ASSERT( n_IsZero(a, r) );
     269
     270    n_Delete(&a, r);
     271
     272    a = n_Sub( aa1, aa2, r );
     273
     274    clog<< "a = aa1 - aa2: "; PrintSized(a, r);
     275
     276    TS_ASSERT( n_IsZero(a, r) );
     277
     278    n_Delete(&a, r);
     279
     280    TS_ASSERT( n_Equal(aa, aa1, r) );
     281    TS_ASSERT( n_Equal(aa, aa2, r) );
     282    TS_ASSERT( n_Equal(aa1, aa2, r) );
     283 
     284    TS_ASSERT( n_Equal(aa0, aa, r) );
     285    TS_ASSERT( n_Equal(aa0, aa1, r) );
     286    TS_ASSERT( n_Equal(aa0, aa2, r) );
     287
     288    n_Delete(&aa, r);
     289    n_Delete(&aa1, r);
     290    n_Delete(&aa2, r);
     291
     292    n_Delete(&aa0, r);
     293
     294    clog << ( " >>> TEST DONE!" );
     295    clog << endl;
     296  }
     297  void TestSumCf(const coeffs r, const unsigned long N)
     298  {
     299    clog << ( _2S("TEST: sum[0..") + _2S(N) + "]: ");
     300    clog << endl;
     301
     302    assume( N > 0 ); // just for now...
     303
     304    const unsigned long ssss = (N * (N+1)) / 2;
     305   
     306    number sum1 = n_Init(ssss, r);
     307    clog<< "N*(N+1)/2 (int: " << ssss << "): "; PrintSized(sum1, r);
     308
     309    number s, ss, i, res;
     310
     311    s = n_Init(N  , r);
     312    i = n_Init(N+1, r);
     313    ndInpMult(s, i, r);
     314    n_Delete(&i, r);
     315   
     316    clog<< "N*(N+1): ("<< N*(N+1) << ")"; PrintSized(s, r); 
     317   
     318    i = n_Init(2, r);
     319    clog<< "2: "; PrintSized(i, r); 
     320
     321    if( !n_IsZero( i, r) )
     322    {
     323  #ifdef HAVE_RINGS
     324      TS_ASSERT( n_DivBy(s, i, r) );
     325  #endif
     326       
     327      res = n_Div(s, i, r);
     328   
     329      clog<< "N*(N+1)/2: "; PrintSized(res, r);
     330
     331
     332      number d = n_Sub(res, sum1, r);
     333      TS_ASSERT( n_IsZeroDivisor(d, r) );
     334      n_Delete(&d, r);
     335     
     336      if( n_GetChar(r) == 0 )
     337      {
     338        TS_ASSERT( n_Equal(sum1, res, r) );
     339        TS_ASSERT( n_Equal(res, sum1, r) );
     340      }
     341    } else
     342      TS_ASSERT_EQUALS( n_GetChar(r), 2);
     343   
     344
     345    n_Delete(&s, r);  n_Delete(&i, r);
     346   
     347    n_Delete(&sum1, r); n_Delete(&res, r);   
     348   
     349
     350    s = n_Init(0  , r);
     351    ss = n_Init(0 , r);
     352    for( int k = N; k >= 0; k-- )
     353    {
     354      i = n_Init(k, r);
     355      ndInpAdd(s, i, r); // s += i
     356
     357      i = n_Neg(i, r);
     358      ndInpAdd(ss, i, r); // ss -= i
     359     
     360      n_Delete(&i, r);   
     361    }
     362    clog<< "ss: "; PrintSized(ss, r); 
     363
     364    ss = n_Neg(ss, r); // ss = -ss
     365   
     366    clog<< "real sum    : "; PrintSized(s, r);
     367    clog<< "real sum(--): "; PrintSized(ss, r); 
     368
     369    TS_ASSERT( n_Equal(s, ss, r) );
     370    TS_ASSERT( n_Equal(ss, s, r) );
     371
     372    n_Delete(&s, r);   
     373    n_Delete(&ss, r);   
     374
     375    clog << ( " >>> TEST DONE!" );
     376    clog << endl;
     377
     378  }
    210379public:
    211380  void test_Z13_t()
     
    388557
    389558    TS_ASSERT_DIFFERS( cf->cfCoeffWrite, NULLp );
    390    
    391    
    392559 
    393560    if( cf->cfCoeffWrite != NULL )
     
    396563      n_CoeffWrite(cf); PrintLn();
    397564    }
     565   
     566    // some tests for the coefficient field represented by cf:
     567    TestArithCf(cf);
     568    TestSumCf(cf, 10);
     569    TestSumCf(cf, 100);
     570    TestSumCf(cf, 101);
     571    TestSumCf(cf, 1001);
     572    TestSumCf(cf, 9000);
    398573
    399574    clog << "Finally create the polynomial ring (Q[a]/<a2+1>)[x, y]..."
     
    416591    TS_ASSERT_EQUALS(rVar(s), 2);
    417592
    418     //Test(s);
     593    Test(s);
    419594
    420595    rDelete(s); // kills 'cf' and 'r' as well
Note: See TracChangeset for help on using the changeset viewer.