Changeset cfb500 in git for libpolys/tests/polys_test.h


Ignore:
Timestamp:
May 20, 2011, 1:07:49 PM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'd25190065115c859833252500a64cfb7b11e3a50')
Children:
502f5f6f3100e91a41cf8b3762727582bcdcc2fa
Parents:
09ed7738e7d4dd96c01950a6f0736d8581f333d2
git-author:
Frank Seelisch <seelisch@mathematik.uni-kl.de>2011-05-20 13:07:49+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:36:13+01:00
Message:
ending tests for alg field ext impl (all tests ok)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/tests/polys_test.h

    r09ed77 rcfb500  
    209209{
    210210private:
     211  /* replaces n by n + c * var^exp (in-place);
     212     expects exp >= 0 */
     213  void plusTerm(number &n, int c, int exp, const coeffs cf)
     214  {
     215    number x = n_Par(1, cf);
     216    number pow = n_Init(1, cf);
     217    number temp;
     218    for (int i = 1; i <= exp; i++)
     219    {
     220      temp = n_Mult(pow, x, cf);
     221      n_Delete(&pow, cf);
     222      pow = temp;
     223    }
     224    n_Delete(&x, cf);
     225    number m = n_Init(c, cf);
     226    number t = n_Mult(m, pow, cf);
     227    n_Delete(&m, cf); n_Delete(&pow, cf);
     228    temp = n_Add(n, t, cf);
     229    n_Delete(&n, cf); n_Delete(&t, cf);
     230    n = temp;
     231  }
    211232  void checkInverse(number n, const coeffs cf)
    212233  {
     
    216237    number n2 = n_Mult(n, n1, cf);
    217238    clog << "(check: n * n^(-1) = "; n_Write(n2, cf);
     239    TS_ASSERT( n_IsOne(n2, cf) );
    218240    n_Delete(&n1, cf); n_Delete(&n2, cf);
    219241  }
     
    603625   
    604626    clog << endl
    605          << "Now let's compute some inverses in Q[a]/<a2+1>..."
     627         << "Now let's compute some inverses in Q[a]/<a^2+1>..."
     628         << endl;
     629   
     630    number u;
     631    u = NULL; plusTerm(u, 1, 1, cf); plusTerm(u, 1, 0, cf);  // a + 1
     632    checkInverse(u, cf); n_Delete(&u, cf);
     633    u = NULL; plusTerm(u, 1, 1, cf); plusTerm(u, -1, 0, cf); // a - 1
     634    checkInverse(u, cf); n_Delete(&u, cf);
     635    u = NULL; plusTerm(u, 1, 1, cf); plusTerm(u, 5, 0, cf);  // a + 5
     636    checkInverse(u, cf); n_Delete(&u, cf);
     637    u = NULL; plusTerm(u, 1, 1, cf); plusTerm(u, -5, 0, cf); // a - 5
     638    checkInverse(u, cf); n_Delete(&u, cf);
     639    u = NULL; plusTerm(u, 17, 1, cf); plusTerm(u, 5, 0, cf); // 17a + 5
     640    checkInverse(u, cf); n_Delete(&u, cf);
     641
     642    rDelete(s); // kills 'cf' and 'r' as well
     643  }
     644  void test_Q_Ext_b()
     645  {
     646    clog << "Start by creating Q[b]..." << endl;
     647
     648    char* n[] = {"b"};
     649    ring r = rDefault( 0, 1, n);   // Q[b]
     650    TS_ASSERT_DIFFERS( r, NULLp );
     651
     652    PrintRing(r);
     653
     654    TS_ASSERT( rField_is_Domain(r) );
     655    TS_ASSERT( rField_is_Q(r) );
     656   
     657    TS_ASSERT( !rField_is_Zp(r) );
     658    TS_ASSERT( !rField_is_Zp(r, 11) );
     659
     660    TS_ASSERT_EQUALS( rVar(r), 1);
     661
     662    poly minPoly = p_ISet(1, r);                    // minPoly = 1
     663    p_SetExp(minPoly, 1, 7, r); p_Setm(minPoly, r); // minPoly = b^7
     664    minPoly = p_Add_q(minPoly, p_ISet(17, r), r);   // minPoly = b^7 + 17
     665    ideal minIdeal = idInit(1);                     // minIdeal = < 0 >
     666    minIdeal->m[0] = minPoly;                       // minIdeal = < b^7 + 17 >
     667
     668    n_coeffType type = nRegister(n_Ext, naInitChar);
     669    TS_ASSERT(type == n_Ext);
     670
     671    ExtInfo extParam;
     672    extParam.r = r;
     673    extParam.i = minIdeal;
     674   
     675    clog << "Next create the extension field Q[b]/<b^7+17>..." << endl;
     676
     677    const coeffs cf = nInitChar(type, &extParam);   // Q[b]/<b^7+17>
     678   
     679    if( cf == NULL )
     680      TS_FAIL("Could not get needed coeff. domain");
     681
     682    TS_ASSERT_DIFFERS( cf->cfCoeffWrite, NULLp );
     683 
     684    if( cf->cfCoeffWrite != NULL )
     685    {
     686      clog << "Coeff-domain: "  << endl;
     687      n_CoeffWrite(cf); PrintLn();
     688    }
     689   
     690    // some tests for the coefficient field represented by cf:
     691    TestArithCf(cf);
     692    TestSumCf(cf, 10);
     693    TestSumCf(cf, 100);
     694    TestSumCf(cf, 101);
     695    TestSumCf(cf, 1001);
     696    TestSumCf(cf, 9000);
     697
     698    clog << "Finally create the polynomial ring (Q[b]/<b^7+17>)[u, v, w]..."
     699         << endl;
     700   
     701    char* m[] = {"u", "v", "w"};
     702    ring s = rDefault(cf, 3, m);   // (Q[b]/<b^7+17>)[u, v, w]
     703    TS_ASSERT_DIFFERS(s, NULLp);
     704
     705    PrintRing(s);
     706
     707    TS_ASSERT( rField_is_Domain(s) );
     708    TS_ASSERT( !rField_is_Q(s) );
     709    TS_ASSERT( !rField_is_Zp(s) );
     710    TS_ASSERT( !rField_is_Zp(s, 11) );
     711    TS_ASSERT( !rField_is_Zp(s, 13) );
     712    TS_ASSERT( !rField_is_GF(s) );
     713    TS_ASSERT( rField_is_Extension(s) );
     714    TS_ASSERT( !rField_is_GF(s, 25) );
     715    TS_ASSERT_EQUALS(rVar(s), 3);
     716
     717    Test(s);
     718   
     719    clog << endl
     720         << "Now let's compute some inverses in Q[b]/<b^7+17>..."
    606721         << endl;
    607722         
    608     number a = n_Par(1, cf);
    609     number n1 = n_Init(1, cf);
    610     number n5 = n_Init(5, cf);
    611     number n17 = n_Init(17, cf);
    612     number u; number v;
    613    
    614     u = n_Add(a, n1, cf); checkInverse(u, cf); n_Delete(&u, cf); // a + 1
    615     u = n_Sub(a, n1, cf); checkInverse(u, cf); n_Delete(&u, cf); // a - 1
    616     u = n_Add(a, n5, cf); checkInverse(u, cf); n_Delete(&u, cf); // a + 5
    617     u = n_Sub(a, n5, cf); checkInverse(u, cf); n_Delete(&u, cf); // a - 5
    618     v = n_Mult(a, n17, cf);
    619     u = n_Add(v, n5, cf); n_Delete(&v, cf);                      // 17a + 5
    620        checkInverse(u, cf); n_Delete(&u, cf);
    621    
    622     n_Delete(&a, cf); n_Delete(&n1, cf); n_Delete(&n5, cf);
    623     n_Delete(&n17, cf);
     723    number u;
     724    u = NULL; plusTerm(u, 1, 2, cf); plusTerm(u, 33, 0, cf);    // b^2 + 33
     725    checkInverse(u, cf); n_Delete(&u, cf);
     726    u = NULL; plusTerm(u, 1, 5, cf); plusTerm(u, -137, 0, cf);  // b^5 - 137
     727    checkInverse(u, cf); n_Delete(&u, cf);
     728
     729    clog << endl
     730         << "Now let's check a gcd computation in Q[b]..."
     731         << endl;
     732   
     733    number v;
     734    v = NULL; plusTerm(v, 1, 2, cf); plusTerm(v, 7, 1, cf);
     735    plusTerm(v, 1, 0, cf);        // b^2 + 7b + 1
     736    number w = n_Mult(v, v, cf);  // (b^2 + 7b + 1)^2
     737    number y = n_Mult(v, w, cf);  // (b^2 + 7b + 1)^3
     738    n_Delete(&v, cf);
     739    v = NULL; plusTerm(v, 2, 2, cf); plusTerm(v, -61, 1, cf);   // 2b^2 - 61b
     740    number z = n_Mult(w, v, cf);   // (b^2 + 7b + 1)^2 * (2b^2 - 61b)
     741    n_Delete(&v, cf);
     742   
     743    clog << "z = "; n_Write(z, cf);
     744    clog << "y = "; n_Write(y, cf);
     745    number theGcd = n_Gcd(z, y, cf);   // should yield w = (b^2 + 7b + 1)^2
     746    clog << "gcd(z, y) = "; n_Write(theGcd, cf);
     747   
     748    v = n_Sub(theGcd, w, cf);
     749    TS_ASSERT( v == NULL );
     750    n_Delete(&v, cf);
     751   
     752    clog << endl
     753         << "Now let's check an ext_gcd computation in Q[b]..."
     754         << endl;
     755         
     756    poly zFactor; poly yFactor;
     757    poly ppp = p_ExtGcd((poly)z, zFactor, (poly)y, yFactor, cf->algring);
     758    v = n_Sub(theGcd, (number)ppp, cf);
     759    TS_ASSERT( v == NULL );
     760    clog << "z = "; n_Write(z, cf);
     761    clog << "zFactor = "; p_Write(zFactor, cf->algring);
     762    clog << "y = "; n_Write(y, cf);
     763    clog << "yFactor = "; p_Write(yFactor, cf->algring);
     764    number v1 = n_Mult(z, (number)zFactor, cf);
     765    number v2 = n_Mult(y, (number)yFactor, cf);
     766    number v3 = n_Add(v1, v2, cf);
     767    clog << "z * zFactor + y * yFactor = "; n_Write(v3, cf);
     768    clog << "gcd(z, y) = "; p_Write(ppp, cf->algring);
     769    number v4 = n_Sub(v3, w, cf);
     770    TS_ASSERT( v4 == NULL );
     771   
     772    p_Delete(&ppp, cf->algring); p_Delete(&zFactor, cf->algring);
     773    p_Delete(&yFactor, cf->algring);
     774    n_Delete(&z, cf); n_Delete(&y, cf); n_Delete(&w, cf);
     775    n_Delete(&theGcd, cf); n_Delete(&v, cf); n_Delete(&v1, cf);
     776    n_Delete(&v2, cf); n_Delete(&v3, cf); n_Delete(&v4, cf);
    624777
    625778    rDelete(s); // kills 'cf' and 'r' as well
Note: See TracChangeset for help on using the changeset viewer.