Changeset 06df101 in git for libpolys/tests/polys_test.h


Ignore:
Timestamp:
Jul 6, 2011, 4:41:07 PM (12 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', '91fdef05f09f54b8d58d92a472e9c4a43aa4656f')
Children:
6c19d854882ab99fd19b9b972a32606106c2f2ee
Parents:
2d3091c7bb239cd4787574560ab475ac88621da7
git-author:
Frank Seelisch <seelisch@mathematik.uni-kl.de>2011-07-06 16:41:07+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:39:12+01:00
Message:
handled nested fractions (when over Q), found bug in longrat.cc (see coeffs_test.h:507)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/tests/polys_test.h

    r2d3091c r06df101  
    220220  {
    221221    poly t = p_ISet(c, r);
     222    if (exp > 0) { p_SetExp(t, i, exp, r); p_Setm(t, r); }
     223    p = p_Add_q(p, t, r);
     224  }
     225  /* assumes that r is over Q;
     226     replaces p by p + c1 / c2 * var(i)^exp (in-place);
     227     expects exp >= 0, and c2 != 0 */
     228  void plusTermOverQ(poly &p, int c1, int c2, int i, int exp, const ring r)
     229  {
     230    number c1AsN = n_Init(c1, r->cf);
     231    number c2AsN = n_Init(c2, r->cf);
     232    number c =  n_Div(c1AsN, c2AsN, r->cf);
     233    poly t = p_ISet(1, r); p_SetCoeff(t, c, r);
    222234    if (exp > 0) { p_SetExp(t, i, exp, r); p_Setm(t, r); }
    223235    p = p_Add_q(p, t, r);
     
    24932505    poly theProduct = p_Mult_q(entry, factor, s);
    24942506    p_Write(theProduct, s);
    2495     clog << "ending multiplication..." << endl;
     2507    clog << "...ending multiplication" << endl;
    24962508    n_Delete(&qfactorAsN, cf); p_Delete(&theProduct, s);
    24972509   
     
    25082520    /* The following multiplication + output of the product is very slow
    25092521       in the svn/trunk SINGULAR version; see trac ticket #308.
    2510        Here, in the Spielwiese, the result is instantaneous! */
     2522       Here, in the Spielwiese, the result is instantaneous. */
    25112523    theProduct = p_Mult_q(entry, factor, s);
    25122524    p_Write(theProduct, s);
    2513     clog << "ending very special multiplication..." << endl;
     2525    clog << "...ending very special multiplication" << endl;
    25142526    n_Delete(&qfactorAsN, cf); p_Delete(&theProduct, s);
     2527       
     2528    rDelete(s); // kills 'cf' and 'r' as well
     2529  }
     2530  void test_Q_Ext_s_t_NestedFractions()
     2531  {
     2532    clog << "Start by creating Q[s, t]..." << endl;
     2533
     2534    char* n[] = {"s", "t"};
     2535    ring r = rDefault( 0, 2, n);   // Q[s, t]
     2536    TS_ASSERT_DIFFERS( r, NULLp );
     2537
     2538    PrintRing(r);
     2539
     2540    TS_ASSERT( rField_is_Domain(r) );
     2541    TS_ASSERT( rField_is_Q(r) );
     2542
     2543    TS_ASSERT( !rField_is_Zp(r) );
     2544    TS_ASSERT( !rField_is_Zp(r, 17) );
     2545
     2546    TS_ASSERT_EQUALS( rVar(r), 2);
     2547
     2548    n_coeffType type = nRegister(n_transExt, ntInitChar);
     2549    TS_ASSERT(type == n_transExt);
     2550
     2551    TransExtInfo extParam;
     2552    extParam.r = r;
     2553
     2554    clog << "Next create the rational function field Q(s, t)..." << endl;
     2555
     2556    const coeffs cf = nInitChar(type, &extParam);   // Q(s, t)
     2557
     2558    if( cf == NULL )
     2559      TS_FAIL("Could not get needed coeff. domain");
     2560
     2561    TS_ASSERT_DIFFERS( cf->cfCoeffWrite, NULLp );
     2562
     2563    if( cf->cfCoeffWrite != NULL )
     2564    {
     2565      clog << "Coeff-domain: "  << endl;
     2566      n_CoeffWrite(cf); PrintLn();
     2567    }
     2568
     2569    TS_ASSERT( !nCoeff_is_algExt(cf) );
     2570    TS_ASSERT( nCoeff_is_transExt(cf) );
     2571
     2572    clog << "Finally create the polynomial ring Q(s, t)[x, y, z]..."
     2573         << endl;
     2574
     2575    char* m[] = {"x", "y", "z"};
     2576    ring s = rDefault(cf, 3, m);   // Q(s, t)[x, y, z]
     2577    TS_ASSERT_DIFFERS(s, NULLp);
     2578
     2579    PrintRing(s);
     2580
     2581    TS_ASSERT( rField_is_Domain(s) );
     2582    TS_ASSERT( !rField_is_Q(s) );
     2583    TS_ASSERT( !rField_is_Zp(s) );
     2584    TS_ASSERT( !rField_is_Zp(s, 11) );
     2585    TS_ASSERT( !rField_is_Zp(s, 17) );
     2586    TS_ASSERT( !rField_is_GF(s) );
     2587    TS_ASSERT( rField_is_Extension(s) );
     2588    TS_ASSERT( !rField_is_GF(s, 25) );
     2589    TS_ASSERT_EQUALS(rVar(s), 3);
     2590   
     2591    /* test 1 for nested fractions, i.e. fractional coefficients: */
     2592    poly v1 = NULL;
     2593    plusTermOverQ(v1, 21, 2, 1, 1, cf->extRing);       // 21/2*s
     2594    plusTermOverQ(v1, 14, 3, 1, 0, cf->extRing);       // 21/2*s + 14/3
     2595    number v1_n = toFractionNumber(v1, cf);
     2596    PrintSized(v1_n, cf);
     2597    poly v2 = NULL;
     2598    plusTermOverQ(v2, 7, 5, 1, 1, cf->extRing);       // 7/5*s
     2599    plusTermOverQ(v2, -49, 6, 2, 1, cf->extRing);     // 7/5*s - 49/6*t
     2600    number v2_n = toFractionNumber(v2, cf);
     2601    PrintSized(v2_n, cf);
     2602    number v3_n = n_Div(v1_n, v2_n, cf);   // (45*s + 20) / (6s - 35*t)
     2603    PrintSized(v3_n, cf);
     2604    n_Delete(&v1_n, cf); n_Delete(&v2_n, cf); n_Delete(&v3_n, cf);
     2605   
     2606    /* test 2 for nested fractions, i.e. fractional coefficients: */
     2607    v1 = NULL;
     2608    plusTermOverQ(v1, 1, 2, 1, 1, cf->extRing);       // 1/2*s
     2609    plusTermOverQ(v1, 1, 1, 1, 0, cf->extRing);       // 1/2*s + 1
     2610    v2 = NULL;
     2611    plusTermOverQ(v2, 1, 1, 1, 1, cf->extRing);       // s
     2612    plusTermOverQ(v2, 2, 3, 2, 1, cf->extRing);       // s + 2/3*t
     2613    poly v3 = p_Mult_q(v1, v2, cf->extRing);   // (1/2*s + 1) * (s + 2/3*t)
     2614    number v_n = toFractionNumber(v3, cf);
     2615    PrintSized(v_n, cf);
     2616    poly w1 = NULL;
     2617    plusTermOverQ(w1, 1, 2, 1, 1, cf->extRing);       // 1/2*s
     2618    plusTermOverQ(w1, 1, 1, 1, 0, cf->extRing);       // 1/2*s + 1
     2619    poly w2 = NULL;
     2620    plusTermOverQ(w2, -7, 5, 1, 0, cf->extRing);      // -7/5
     2621    poly w3 = p_Mult_q(w1, w2, cf->extRing);   // (1/2*s + 1) * (-7/5)
     2622    number w_n = toFractionNumber(w3, cf);
     2623    PrintSized(w_n, cf);
     2624    number z_n = n_Div(v_n, w_n, cf);          // -5/7*s - 10/21*t
     2625    PrintSized(z_n, cf);
     2626    n_Delete(&v_n, cf); n_Delete(&w_n, cf); n_Delete(&z_n, cf);
    25152627   
    25162628    rDelete(s); // kills 'cf' and 'r' as well
Note: See TracChangeset for help on using the changeset viewer.