Changeset 152d55 in git for kernel/longtrans.cc


Ignore:
Timestamp:
Mar 28, 2011, 5:58:06 PM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
f3b4ae666e6d80d92f6a7b691937cf9d8d40b497
Parents:
83f30732a27330c9f9218cccbd4faeb2571b7c5f
Message:
minor changes in routines for alg+transc ext's

git-svn-id: file:///usr/local/Singular/svn/trunk@14077 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/longtrans.cc

    r83f3073 r152d55  
    518518   returns the minimum of the two exponents of the
    519519   first variable in la and lb;
     520   assumes a != NULL, b != NULL;
    520521   keeps a and b */
    521522int napExp(napoly a, napoly b)
    522523{
     524  assume(a != NULL);
     525  assume(b != NULL);
    523526  while (pNext(a) != NULL) pIter(a);
    524527  int m = p_GetExp(a, 1, nacRing);
     
    561564
    562565/* divides out the content of the given napoly;
    563    modifies the argument */
     566   assumes that ph != NULL;
     567   modifies ph */
    564568void napContent(napoly ph)
    565569{
     
    567571  napoly p;
    568572
    569   assume(p != NULL);
     573  assume(ph != NULL);
    570574  p = ph;
    571575  if (nacIsOne(pGetCoeff(p))) return;
    572576  h = nacCopy(pGetCoeff(p));
    573577  pIter(p);
    574   do
     578  while (p != NULL)
    575579  {
    576580    d = nacGcd(pGetCoeff(p), h, nacRing);
     
    585589    pIter(p);
    586590  }
    587   while (p != NULL);
    588591  h = nacInvers(d);
    589592  n_Delete(&d, nacRing);
     
    599602}
    600603
     604/* removes denominators of coefficients in ph
     605   by multiplication with lcm of those;
     606   if char != 0, then nothing is done;
     607   modifies ph */
    601608void napCleardenom(napoly ph)
    602609{
     
    609616  while (p!=NULL)
    610617  {
    611     d = nacLcm(h, pGetCoeff(p), nacRing);
     618    d = nacLcm(h, pGetCoeff(p), nacRing); // uses denominator of pGetCoeff(p)
    612619    n_Delete(&h,nacRing);
    613620    h = d;
     
    625632      pIter(p);
    626633    }
    627     n_Delete(&h,nacRing);
    628   }
     634  }
     635  n_Delete(&h,nacRing);
    629636  napContent(ph);
    630637}
    631638
     639/* returns the gcd of all coefficients in a and b;
     640   assumes a != NULL, b != NULL;
     641   keeps a, keeps b */
    632642napoly napGcd0(napoly a, napoly b)
    633643{
    634644  number x, y;
     645  assume(a != NULL);
     646  assume(b != NULL);
    635647  if (!ntIsChar0) return p_ISet(1, nacRing);
    636648  x = nacCopy(pGetCoeff(a));
    637   if (nacIsOne(x))
    638     return napInitz(x);
    639   while (pNext(a)!=NULL)
    640   {
    641     pIter(a);
     649  if (nacIsOne(x)) return napInitz(x);
     650  pIter(a);
     651  while (a!=NULL)
     652  {
    642653    y = nacGcd(x, pGetCoeff(a), nacRing);
    643654    n_Delete(&x,nacRing);
    644655    x = y;
    645     if (nacIsOne(x))
    646       return napInitz(x);
     656    if (nacIsOne(x)) return napInitz(x);
     657    pIter(a);
    647658  }
    648659  do
     
    651662    n_Delete(&x,nacRing);
    652663    x = y;
    653     if (nacIsOne(x))
    654       return napInitz(x);
     664    if (nacIsOne(x)) return napInitz(x);
    655665    pIter(b);
    656666  }
     
    659669}
    660670
    661 /*3
    662 * result =gcd(a,b)
    663 */
     671/* returns the gcd of a and b;
     672   if char != 0, then the constant poly 1 is returned;
     673   if a = b = 0, then the constant poly 1 is returned;
     674   if a = 0 != b, then b is returned;
     675   if a != 0 = b, then a is returned;
     676   keeps a, keeps b */
    664677napoly napGcd(napoly a, napoly b)
    665678{
    666679  int i;
    667680  napoly g, x, y, h;
    668   if ((a==NULL)
    669   || ((pNext(a)==NULL)&&(nacIsZero(pGetCoeff(a)))))
    670   {
    671     if ((b==NULL)
    672     || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b)))))
    673     {
    674       return p_ISet(1,nacRing);
    675     }
    676     return napCopy(b);
    677   }
    678   else
    679   if ((b==NULL)
    680   || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b)))))
    681   {
    682     return napCopy(a);
    683   }
     681  if (a == NULL)
     682  {
     683    if (b == NULL)    return p_ISet(1,nacRing);
     684    else              return napCopy(b);
     685  }
     686  else if (b == NULL) return napCopy(a);
     687 
    684688  if (naMinimalPoly != NULL)
    685   {
     689  { // we have an algebraic extension
    686690    if (p_GetExp(a,1,nacRing) >= p_GetExp(b,1,nacRing))
    687691    {
     
    726730    return g;
    727731  }
    728   // Hmm ... this is a memory leak
    729   // x = (napoly)p_Init(nacRing);
    730   g=a;
    731   h=b;
    732   if (!ntIsChar0) x = p_ISet(1,nacRing);
    733   else            x = napGcd0(g,h);
    734   for (i=(ntNumbOfPar-1); i>=0; i--)
    735   {
    736     napSetExp(x,i+1, napExpi(i,a,b));
    737     p_Setm(x,nacRing);
    738   }
    739   return x;
    740 }
    741 
    742 
     732  else
     733  { // we have ntNumbOfPar transcendental variables
     734    if (!ntIsChar0) x = p_ISet(1,nacRing);
     735    else            x = napGcd0(a,b);
     736    for (i=(ntNumbOfPar-1); i>=0; i--)
     737    {
     738      napSetExp(x,i+1, napExpi(i,a,b));
     739      p_Setm(x,nacRing);
     740    }
     741    return x;
     742  }
     743}
     744
     745/* returns the lcm of all denominators in the coefficients of a;
     746   if char != 0, then the constant poly 1 is returned;
     747   if a = 0, then the constant poly 1 is returned;
     748   keeps a */
    743749number napLcm(napoly a)
    744750{
    745751  number h = nacInit(1,nacRing);
    746 
    747752  if (ntIsChar0)
    748753  {
    749754    number d;
    750755    napoly b = a;
    751 
    752756    while (b!=NULL)
    753757    {
    754       d = nacLcm(h, pGetCoeff(b), nacRing);
     758      d = nacLcm(h, pGetCoeff(b), nacRing); // uses denominator of pGetCoeff(b)
    755759      n_Delete(&h,nacRing);
    756760      h = d;
     
    760764  return h;
    761765}
    762 
    763766
    764767/*2
Note: See TracChangeset for help on using the changeset viewer.