Changeset 010f3b in git


Ignore:
Timestamp:
Jun 29, 2011, 5:54:28 PM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', '5b153614cbc72bfa198d75b1e9e33dab2645d9fe')
Children:
df43d9eede47de2604d4c0ff334af81427c1ec57
Parents:
de90c019d739dd11bb7004ab4f6d1147833c69bc
git-author:
Frank Seelisch <seelisch@mathematik.uni-kl.de>2011-06-29 17:54:28+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:39:10+01:00
Message:
more tests for transcendental case
Location:
libpolys
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/ext_fields/transext.cc

    rde90c01 r010f3b  
    6666
    6767void heuristicGcdCancellation(number a, const coeffs cf);
    68 void definiteGcdCancellation(number a, const coeffs cf);
     68void definiteGcdCancellation(number a, const coeffs cf,
     69                             BOOLEAN skipSimpleTests);
    6970
    7071#ifdef LDEBUG
     
    175176{
    176177  ntTest(a);
    177   definiteGcdCancellation(a, cf);
     178  definiteGcdCancellation(a, cf, FALSE);
    178179  if (is0(a)) return NULL;
    179180  fraction f = (fraction)a;
     
    189190{
    190191  ntTest(a);
    191   definiteGcdCancellation(a, cf);
     192  definiteGcdCancellation(a, cf, FALSE);
    192193  fraction f = (fraction)a;
    193194  poly g;
     
    204205{
    205206  ntTest(a);
    206   definiteGcdCancellation(a, cf);
    207   fraction f = (fraction)a;
    208   if (!denIs1(f)) return FALSE;
    209   poly g = num(f);
    210   if (!p_IsConstant(g, ntRing)) return FALSE;
    211   return n_IsOne(p_GetCoeff(g, ntRing), ntCoeffs);
     207  definiteGcdCancellation(a, cf, FALSE);
     208  fraction f = (fraction)a;
     209  return denIs1(f) && numIs1(f);
    212210}
    213211
     
    215213{
    216214  ntTest(a);
    217   definiteGcdCancellation(a, cf);
     215  definiteGcdCancellation(a, cf, FALSE);
    218216  fraction f = (fraction)a;
    219217  if (!denIs1(f)) return FALSE;
     
    258256  ntTest(a);
    259257  if (is0(a)) return 0;
    260   definiteGcdCancellation(a, cf);
     258  definiteGcdCancellation(a, cf, FALSE);
    261259  fraction f = (fraction)a;
    262260  if (!denIs1(f)) return 0;
     
    532530  ntTest(a);
    533531  if (is0(a)) return;
    534   fraction f = (fraction)a;
    535   if (denIs1(f) || n_IsOne(p_GetCoeff(num(f), ntRing), ntCoeffs))
    536   { c(f) = 0; return; }
     532 
     533  fraction f = (fraction)a;
     534  if (denIs1(f) || numIs1(f)) { c(f) = 0; return; }
     535 
     536  /* check whether num(f) = den(f), and - if so - replace 'a' by 1 */
     537  poly difference = p_Add_q(p_Copy(num(f), ntRing),
     538                            p_Neg(p_Copy(den(f), ntRing), ntRing),
     539                            ntRing);
     540  if (difference == NULL)
     541  { /* we also know that numerator and denominator are both != 1 */
     542    p_Delete(&num(f), ntRing); num(f) = p_ISet(1, ntRing);
     543    p_Delete(&den(f), ntRing); den(f) = NULL;
     544    c(f) = 0;
     545    return;
     546  }
     547  else p_Delete(&difference, ntRing);
     548 
    537549  if (c(f) <= BOUND_COMPLEXITY) return;
    538   else definiteGcdCancellation(a, cf);
     550  else definiteGcdCancellation(a, cf, TRUE);
    539551}
    540552
    541553/* modifies a */
    542 void definiteGcdCancellation(number a, const coeffs cf)
    543 {
    544   ntTest(a);
    545   if (is0(a)) return;
    546   fraction f = (fraction)a;
    547   if (denIs1(f) || n_IsOne(p_GetCoeff(num(f), ntRing), ntCoeffs))
    548   { c(f) = 0; return; }
    549   if (c(f) > BOUND_COMPLEXITY)
    550   {
    551     /* TO BE IMPLEMENTED!
    552        for the time, cancellation of gcd's does not take place */
    553     Print("// TO BE IMPLEMENTED: transext.cc:definiteGcdCancellation\n");
    554     Print("// (complexity of number = %d exceeds the bound = %d\n",
    555           c(f), BOUND_COMPLEXITY);
    556   }
     554void definiteGcdCancellation(number a, const coeffs cf,
     555                             BOOLEAN skipSimpleTests)
     556{
     557  ntTest(a);
     558 
     559  fraction f = (fraction)a;
     560 
     561  if (!skipSimpleTests)
     562  {
     563    if (is0(a)) return;
     564    if (denIs1(f) || numIs1(f)) { c(f) = 0; return; }
     565 
     566    /* check whether num(f) = den(f), and - if so - replace 'a' by 1 */
     567    poly difference = p_Add_q(p_Copy(num(f), ntRing),
     568                              p_Neg(p_Copy(den(f), ntRing), ntRing),
     569                              ntRing);
     570    if (difference == NULL)
     571    { /* we also know that numerator and denominator are both != 1 */
     572      p_Delete(&num(f), ntRing); num(f) = p_ISet(1, ntRing);
     573      p_Delete(&den(f), ntRing); den(f) = NULL;
     574      c(f) = 0;
     575      return;
     576    }
     577    else p_Delete(&difference, ntRing);
     578  }
     579 
     580  /* TO BE IMPLEMENTED!
     581     for the time being, cancellation of gcd's does not take place */
     582  Print("// TO BE IMPLEMENTED: transext.cc:definiteGcdCancellation\n");
     583  Print("// (complexity of number = %d, bound = %d)\n",
     584        c(f), BOUND_COMPLEXITY);
    557585}
    558586
     
    560588{
    561589  ntTest(a);
    562   definiteGcdCancellation(a, cf);
     590  definiteGcdCancellation(a, cf, FALSE);
    563591  if (is0(a))
    564592    StringAppendS("0");
  • libpolys/polys/ext_fields/transext.h

    rde90c01 r010f3b  
    6363#define den(f) f->denominator
    6464#define denIs1(f) (f->denominator == NULL) /**< TRUE iff den. represents 1 */
     65#define numIs1(f) (p_IsConstant(f->numerator, cf->extRing) && \
     66                   n_IsOne(p_GetCoeff(num(f), cf->extRing), cf->extRing->cf))
     67                   /**< TRUE iff num. represents 1 */
    6568#define c(f) f->complexity
    6669
  • libpolys/tests/polys_test.h

    rde90c01 r010f3b  
    231231    TS_ASSERT( n_IsOne(n2, cf) );
    232232    n_Delete(&n1, cf); n_Delete(&n2, cf);
     233  }
     234  /* assumes that cf represents a rational function field;
     235     does NOT copy p, i.e. uses p directly inside the resulting number */
     236  number toFractionNumber(poly p, const coeffs cf)
     237  {
     238    number n = n_Init(1, cf);
     239    fraction f = (fraction)n;
     240    p_Delete(&(f->numerator), cf->extRing);
     241    f->numerator = p;
     242    return n;
    233243  }
    234244  void TestArithCf(const coeffs r)
     
    933943    Test(s);
    934944   
     945    /* some special tests: */
     946    poly v1 = NULL;
     947    plusTerm(v1, 1, 1, 1, cf->extRing);       // s
     948    plusTerm(v1, 1, 1, 0, cf->extRing);       // s + 1
     949    poly v2 = NULL;
     950    plusTerm(v2, 1, 1, 1, cf->extRing);       // s
     951    plusTerm(v2, 2, 2, 1, cf->extRing);       // s + 2t
     952    poly v = p_Mult_q(v1, v2, cf->extRing);   // (s + 1) * (s + 2t)
     953    number v_n = toFractionNumber(v, cf);
     954    PrintSized(v_n, cf);
     955    poly w = NULL;
     956    plusTerm(w, 1, 1, 1, cf->extRing);        // s
     957    plusTerm(w, 1, 1, 0, cf->extRing);        // s + 1
     958    number w_n = toFractionNumber(w, cf);
     959    PrintSized(w_n, cf);
     960    number vOverW_n = n_Div(v_n, w_n, cf);
     961    PrintSized(vOverW_n, cf);
     962    number wOverV_n = n_Invers(vOverW_n, cf);
     963    PrintSized(wOverV_n, cf);
     964    number prod = n_Mult(vOverW_n, wOverV_n, cf);
     965    PrintSized(prod, cf);
     966    number tmp; number nn = n_Copy(vOverW_n, cf);
     967    for (int i = 1; i <= 20; i++)
     968    {
     969      tmp = n_Div(nn, v_n, cf);
     970      n_Delete(&nn, cf);
     971      nn = tmp;
     972      clog << i << ". "; PrintSized(nn, cf);
     973    }
     974    n_Delete(&prod, cf); n_Delete(&nn, cf);
     975    n_Delete(&v_n, cf); n_Delete(&w_n, cf);
     976    n_Delete(&vOverW_n, cf); n_Delete(&wOverV_n, cf);
     977   
    935978    rDelete(s); // kills 'cf' and 'r' as well
    936979  }
Note: See TracChangeset for help on using the changeset viewer.