Changeset e7676a in git for factory/cfNewtonPolygon.cc


Ignore:
Timestamp:
May 7, 2012, 3:55:50 PM (12 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
517530b37f04ee705b7b271243a265748c447cf5dccd6db99cc44c93669e843ddb6e06d2682769b8
Parents:
a034968a1bff5f6e4e9ad126551a2e9a377d9f6060cc1289a79586c1732ba3885997c3cb49bc01d9
Message:
Merge pull request #100 from mmklee/ezgcd_sw

Ezgcd sw
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/cfNewtonPolygon.cc

    ra03496 re7676a  
    222222}
    223223
     224int **
     225merge (int ** points1, int sizePoints1, int ** points2, int sizePoints2,
     226       int& sizeResult)
     227{
     228  int i, j;
     229  sizeResult= sizePoints1+sizePoints2;
     230  for (i= 0; i < sizePoints1; i++)
     231  {
     232    for (j= 0; j < sizePoints2; j++)
     233    {
     234      if (points1[i][0] != points2[j][0])
     235        continue;
     236      else
     237      {
     238        if (points1[i][1] != points2[j][1])
     239          continue;
     240        else
     241        {
     242          points2[j][0]= -1;
     243          points2[j][1]= -1;
     244          sizeResult--;
     245        }
     246      }
     247    }
     248  }
     249  if (sizeResult == 0)
     250    return points1;
     251
     252  int ** result= new int *[sizeResult];
     253  for (i= 0; i < sizeResult; i++)
     254    result [i]= new int [2];
     255
     256  int k= 0;
     257  for (i= 0; i < sizePoints1; i++, k++)
     258  {
     259    result[k][0]= points1[i][0];
     260    result[k][1]= points1[i][1];
     261  }
     262  for (i= 0; i < sizePoints2; i++)
     263  {
     264    if (points2[i][0] < 0)
     265      continue;
     266    else
     267    {
     268      result[k][0]= points2[i][0];
     269      result[k][1]= points2[i][1];
     270      k++;
     271    }
     272  }
     273  return result;
     274}
     275
    224276// assumes a bivariate poly as input
    225277int ** newtonPolygon (const CanonicalForm& F, int& sizeOfNewtonPoly)
     
    257309    delete [] points[i];
    258310  delete [] points;
     311
     312  return result;
     313}
     314
     315// assumes a bivariate polys as input
     316int ** newtonPolygon (const CanonicalForm& F, const CanonicalForm& G,
     317                      int& sizeOfNewtonPoly)
     318{
     319  int sizeF= size (F);
     320  int ** pointsF= new int* [sizeF];
     321  for (int i= 0; i < sizeF; i++)
     322    pointsF [i]= new int [2];
     323  int j= 0;
     324  int * buf;
     325  int bufSize;
     326  for (CFIterator i= F; i.hasTerms(); i++)
     327  {
     328    buf= getDegrees (i.coeff(), bufSize);
     329    for (int k= 0; k < bufSize; k++, j++)
     330    {
     331      pointsF [j] [0]= i.exp();
     332      pointsF [j] [1]= buf [k];
     333    }
     334    delete [] buf;
     335  }
     336
     337  int sizeG= size (G);
     338  int ** pointsG= new int* [sizeG];
     339  for (int i= 0; i < sizeG; i++)
     340    pointsG [i]= new int [2];
     341  j= 0;
     342  for (CFIterator i= G; i.hasTerms(); i++)
     343  {
     344    buf= getDegrees (i.coeff(), bufSize);
     345    for (int k= 0; k < bufSize; k++, j++)
     346    {
     347      pointsG [j] [0]= i.exp();
     348      pointsG [j] [1]= buf [k];
     349    }
     350    delete [] buf;
     351  }
     352
     353  int sizePoints;
     354  int ** points= merge (pointsF, sizeF, pointsG, sizeG, sizePoints);
     355
     356  int n= polygon (points, sizePoints);
     357
     358  int ** result= new int* [n];
     359  for (int i= 0; i < n; i++)
     360  {
     361    result [i]= new int [2];
     362    result [i] [0]= points [i] [0];
     363    result [i] [1]= points [i] [1];
     364  }
     365
     366  sizeOfNewtonPoly= n;
     367  for (int i= 0; i < sizeF; i++)
     368    delete [] pointsF[i];
     369  delete [] pointsF;
     370  for (int i= 0; i < sizeG; i++)
     371    delete [] pointsG[i];
     372  delete [] pointsG;
    259373
    260374  return result;
     
    484598
    485599CanonicalForm
    486 compress (const CanonicalForm& F, mat_ZZ& M, vec_ZZ& A)
     600compress (const CanonicalForm& F, mat_ZZ& M, vec_ZZ& A, bool computeMA)
    487601{
    488602  int n;
    489   int ** newtonPolyg= newtonPolygon (F, n);
    490   convexDense (newtonPolyg, n, M, A);
     603  int ** newtonPolyg;
     604  if (computeMA)
     605  {
     606    newtonPolyg= newtonPolygon (F, n);
     607    convexDense (newtonPolyg, n, M, A);
     608  }
    491609  CanonicalForm result= 0;
    492610  ZZ expX, expY;
     
    565683  }
    566684
    567   for (int i= 0; i < n; i++)
    568     delete [] newtonPolyg [i];
    569   delete [] newtonPolyg;
    570 
    571   M= inv (M);
     685  if (computeMA)
     686  {
     687    for (int i= 0; i < n; i++)
     688      delete [] newtonPolyg [i];
     689    delete [] newtonPolyg;
     690    M= inv (M);
     691  }
     692
    572693  return result;
    573694}
Note: See TracChangeset for help on using the changeset viewer.