Changeset ca326f in git


Ignore:
Timestamp:
Jan 10, 2014, 2:27:58 PM (10 years ago)
Author:
Yue Ren <ren@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
ebb19d318b56f966c9f0bc2e03181ad64ed395f1
Parents:
5222d2aaa879330d2c8daa004f176ee41aed4b78
git-author:
Yue Ren <ren@mathematik.uni-kl.de>2014-01-10 14:27:58+01:00
git-committer:
Yue Ren <ren@mathematik.uni-kl.de>2015-02-06 13:47:03+01:00
Message:
new: containsMonomial
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • Singular/dyn_modules/gfanlib/Makefile.am

    r5222d2a rca326f  
    11ACLOCAL_AMFLAGS = -I ../../m4
    22
    3 SOURCES = bbcone.cc bbcone.h bbfan.cc bbfan.h bbpolytope.cc bbpolytope.h gfan.h gitfan.cc gitfan.h gfanlib.cc
     3SOURCES = bbcone.cc bbcone.h bbfan.cc bbfan.h bbpolytope.cc bbpolytope.h gfan.h gitfan.cc gitfan.h ppinitialReduction.cc ppinitialReduction.h ttinitialReduction.cc ttinitialReduction.h containsMonomial.cc containsMonomial.h tropical.cc tropical.h gfanlib.cc
    44
    55MY_CPPFLAGS =  -I${top_srcdir} -I${top_builddir} \
  • Singular/dyn_modules/gfanlib/tropical.cc

    r5222d2a rca326f  
    1 #include <kernel/polys.h>
    2 #include <kernel/kstd1.h>
    3 #include <libpolys/coeffs/longrat.h>
    4 #include <libpolys/polys/clapsing.h>
     1#include <libpolys/polys/monomials/p_polys.h>
     2#include <libpolys/coeffs/coeffs.h>
     3
    54#include <bbcone.h>
    6 
    75#include <ppinitialReduction.h>
    86#include <ttinitialReduction.h>
     7#include <containsMonomial.h>
    98
    109poly initial(poly p)
     
    204203}
    205204
    206 /***
    207  * If 1, replaces all occuring t with prime p,
    208  * where theoretically feasable.
    209  * Also computes GCD over integers than
    210  * over univariate polynomials
    211  **/
    212 #define T_TO_P 0
    213 
    214 /***
    215  * Suppose I=g_0,...,g_{n-1}.
    216  * This function uses bubble sort to sorts g_1,...,g_{n-1}
    217  * such that lm(g_1)>...>lm(g_{n-1})
    218  **/
    219 static inline void sortingLaterGenerators(ideal I)
    220 {
    221   poly cache; int i; int n=IDELEMS(I); int newn;
    222   do
    223   {
    224     newn=0;
    225     for (i=2; i<n; i++)
    226     {
    227       if (pLmCmp(I->m[i-1],I->m[i])<0)
    228       {
    229         cache=I->m[i-1];
    230         I->m[i-1]=I->m[i];
    231         I->m[i]=cache;
    232         newn = i;
    233       }
    234     }
    235     n=newn;
    236   } while(n);
    237 }
    238 
    239 
    240 #if 0
    241 /***
    242  * Given a general ring r with any ordering,
    243  * changes the ordering to a(v),ws(-w)
    244  **/
    245 bool changetoAWSRing(ring r, gfan::ZVector v, gfan::ZVector w)
    246 {
    247   omFree(r->order);
    248   r->order  = (int*) omAlloc0(4*sizeof(int));
    249   omFree(r->block0);
    250   r->block0 = (int*) omAlloc0(4*sizeof(int));
    251   omFree(r->block1);
    252   r->block1 = (int*) omAlloc0(4*sizeof(int));
    253   for (int i=0; r->wvhdl[i]; i++)
    254   { omFree(r->wvhdl[i]); }
    255   omFree(r->wvhdl);
    256   r->wvhdl  = (int**) omAlloc0(4*sizeof(int*));
    257 
    258   bool ok = false;
    259   r->order[0]  = ringorder_a;
    260   r->block0[0] = 1;
    261   r->block1[0] = r->N;
    262   r->wvhdl[0]  = ZVectorToIntStar(v,ok);
    263   r->order[1]  = ringorder_ws;
    264   r->block0[1] = 1;
    265   r->block1[1] = r->N;
    266   r->wvhdl[1]  = ZVectorToIntStar(w,ok);
    267   r->order[2]=ringorder_C;
    268   return ok;
    269 }
    270 
    271 
    272 /***
    273  * Given a ring with ordering a(v'),ws(w'),
    274  * changes the weights to v,w
    275  **/
    276 bool changeAWSWeights(ring r, gfan::ZVector v, gfan::ZVector w)
    277 {
    278   omFree(r->wvhdl[0]);
    279   omFree(r->wvhdl[1]);
    280   bool ok = false;
    281   r->wvhdl[0]  = ZVectorToIntStar(v,ok);
    282   r->wvhdl[1]  = ZVectorToIntStar(w,ok);
    283   return ok;
    284 }
    285 
    286 
    287 // /***
    288 //  * Creates an int* representing the transposition of the last two variables
    289 //  **/
    290 // static inline int* createPermutationVectorForSaturation(static const ring &r)
     205
     206// gfan::ZCone* startingCone(ideal I)
    291207// {
    292 //   int* w = (int*) omAlloc0((rVar(r)+1)*sizeof(int));
    293 //   for (int i=1; i<=rVar(r)-2; i++)
    294 //     w[i] = i;
    295 //   w[rVar(r)-1] = rVar(r);
    296 //   w[rVar(r)] = rVar(r)-1;
     208//   I = kStd(I,NULL,isNotHomog,NULL);
     209//   gfan::ZCone* zc = maximalGroebnerCone(currRing,I);
     210//   gfan::ZMatrix rays = zc->extremeRays();
     211//   gfan::ZVector v;
     212//   for (int i=0; i<rays.getHeight(); i++)
     213//   {
     214//     v = rays[i];
     215//   }
     216//   return zc;
    297217// }
    298 
    299 
    300 /***
    301  * Creates an int* representing the permutation
    302  * 1 -> 1, ..., i-1 -> i-1, i -> n, i+1 -> n-1, ... , n -> i
    303  **/
    304 static inline int* createPermutationVectorForSaturation(const ring &r, const int i)
    305 {
    306   int* sigma = (int*) omAlloc0((rVar(r)+1)*sizeof(int));
    307   int j;
    308   for (j=1; j<i; j++)
    309     sigma[j] = j;
    310   for (; j<=rVar(r); j++)
    311     sigma[j] = rVar(r)-j+i;
    312   return(sigma);
    313 }
    314 
    315 
    316 /***
    317  * Changes the int* representing the permutation
    318  * 1 -> 1, ..., i -> i, i+1 -> n, i+2 -> n-1, ... , n -> i+1
    319  * to an int* representing the permutation
    320  * 1 -> 1, ..., i-1 -> i-1, i -> n, i+1 -> n-1, ... , n -> i
    321  **/
    322 static void changePermutationVectorForSaturation(int* sigma, const ring &r, const int i)
    323 {
    324   for (int j=i; j<rVar(r); j++)
    325     sigma[j] = rVar(r)-j+i;
    326   sigma[rVar(r)] = i;
    327 }
    328 
    329 
    330 /***
    331  * returns a ring in which the weights of the ring variables are permuted
    332  * if handed over a poly in which the variables are permuted, this is basically
    333  * as good as permuting the variables of the ring itself.
    334  **/
    335 static ring permuteWeighstOfRingVariables(const ring &r, const int* const sigma)
    336 {
    337   ring s = rCopy0(r);
    338   for (int j=0; j<rVar(r); j++)
    339   {
    340     s->wvhdl[0][j] = r->wvhdl[0][sigma[j+1]];
    341     s->wvhdl[1][j] = r->wvhdl[1][sigma[j+1]];
    342   }
    343   rComplete(s,1);
    344   return s;
    345 }
    346 
    347 
    348 /***
    349  * creates a ring s that is a copy of r except with ordering wp(w)
    350  **/
    351 static inline ring createInitialRingForSaturation(const ring &r, const gfan::ZVector &w, bool &ok)
    352 {
    353   assume(rVar(r) == (int) w.size());
    354 
    355   ring s = rCopy0(r); int i;
    356   for (i=0; s->order[i]; i++)
    357     omFreeSize(s->wvhdl[i],rVar(r)*sizeof(int));
    358   i++;
    359   omFreeSize(s->order,i*sizeof(int));
    360   s->order  = (int*) omAlloc0(3*sizeof(int));
    361   omFreeSize(s->block0,i*sizeof(int));
    362   s->block0 = (int*) omAlloc0(3*sizeof(int));
    363   omFreeSize(s->block1,i*sizeof(int));
    364   s->block1 = (int*) omAlloc0(3*sizeof(int));
    365   omFreeSize(s->wvhdl,i*sizeof(int*));
    366   s->wvhdl  = (int**) omAlloc0(3*sizeof(int*));
    367 
    368   s->order[0]  = ringorder_wp;
    369   s->block0[0] = 1;
    370   s->block1[0] = rVar(r);
    371   s->wvhdl[0]  = ZVectorToIntStar(w,ok);
    372   s->order[1]=ringorder_C;
    373 
    374   rComplete(s,1);
    375   return s;
    376 }
    377 
    378 
    379 /***
    380  * Given an weighted homogeneous ideal I with respect to weight w
    381  * that in standard basis form with respect to the ordering ws(-w),
    382  * derives the standard basis of I:<x_n>^\infty
    383  * and returns a long k such that I:<x_n>^\infty=I:<x_n>^k
    384  **/
    385 static long deriveStandardBasisOfSaturation(ideal &I, ring &r)
    386 {
    387   long k=0, l; poly current;
    388   for (int i=0; i<IDELEMS(I); i++)
    389   {
    390     current = I->m[i];
    391     l = p_GetExp(current,rVar(r),r);
    392     if (k<l) k=l;
    393     while (current)
    394     {
    395       p_SubExp(current,rVar(r),l,r); p_Setm(current,r);
    396       pIter(current);
    397     }
    398   }
    399   return k;
    400 }
    401 
    402 
    403 /***
    404  * Given a weighted homogeneous ideal I with respect to weight w
    405  * with constant first element,
    406  * returns NULL if I does not contain a monomial
    407  * otherwise returns the monomial contained in I
    408  **/
    409 poly containsMonomial(const ideal &I, const gfan::ZVector &w)
    410 {
    411   assume(rField_is_Ring_Z(currRing));
    412 
    413   // first we switch to the ground field currRing->cf / I->m[0]
    414   ring r = rCopy0(currRing);
    415   nKillChar(r->cf);
    416   r->cf = nInitChar(n_Zp,(void*)(long)n_Int(p_GetCoeff(I->m[0],currRing),currRing->cf));
    417   rComplete(r);
    418 
    419   ideal J = id_Copy(I, currRing); poly cache; number temp;
    420   for (int i=0; i<IDELEMS(I); i++)
    421   {
    422     cache = J->m[i];
    423     while (cache)
    424     {
    425       // TODO: temp = npMapGMP(p_GetCoeff(cache,currRing),currRing->cf,r->cf);
    426       p_SetCoeff(cache,temp,r); pIter(cache);
    427     }
    428   }
    429 
    430 
    431   J = kStd(J,NULL,isHomog,NULL);
    432 
    433   bool b = false;
    434   ring s = createInitialRingForSaturation(currRing, w, b);
    435   if (b)
    436   {
    437     WerrorS("containsMonomial: overflow in weight vector");
    438     return NULL;
    439   }
    440 
    441   return NULL;
    442 }
    443 
    444 
    445 gfan::ZCone* startingCone(ideal I)
    446 {
    447   I = kStd(I,NULL,isNotHomog,NULL);
    448   gfan::ZCone* zc = maximalGroebnerCone(currRing,I);
    449   gfan::ZMatrix rays = zc->extremeRays();
    450   gfan::ZVector v;
    451   for (int i=0; i<rays.getHeight(); i++)
    452   {
    453     v = rays[i];
    454   }
    455   return zc;
    456 }
    457 #endif
    458218
    459219
     
    464224  p->iiAddCproc("","initial",FALSE,initial);
    465225#ifndef NDEBUG
    466   p->iiAddCproc("","pReduce",FALSE,pReduce);
    467   p->iiAddCproc("","reduceInitially0",FALSE,reduceInitially0);
    468   p->iiAddCproc("","reduceInitially1",FALSE,reduceInitially1);
    469   p->iiAddCproc("","reduceInitially2",FALSE,reduceInitially2);
    470   p->iiAddCproc("","reduceInitially3",FALSE,reduceInitially3);
    471   p->iiAddCproc("","reduceInitially4",FALSE,reduceInitially4);
    472   p->iiAddCproc("","ttpReduce",FALSE,pReduce);
     226  p->iiAddCproc("","pppReduce",FALSE,pppReduce);
     227  p->iiAddCproc("","ppreduceInitially0",FALSE,ppreduceInitially0);
     228  p->iiAddCproc("","ppreduceInitially1",FALSE,ppreduceInitially1);
     229  p->iiAddCproc("","ppreduceInitially2",FALSE,ppreduceInitially2);
     230  p->iiAddCproc("","ppreduceInitially3",FALSE,ppreduceInitially3);
     231  p->iiAddCproc("","ppreduceInitially4",FALSE,ppreduceInitially4);
     232  p->iiAddCproc("","ttpReduce",FALSE,ttpReduce);
     233  p->iiAddCproc("","ttreduceInitially0",FALSE,ttreduceInitially0);
     234  p->iiAddCproc("","ttreduceInitially1",FALSE,ttreduceInitially1);
     235  p->iiAddCproc("","ttreduceInitially2",FALSE,ttreduceInitially2);
     236  p->iiAddCproc("","ttreduceInitially3",FALSE,ttreduceInitially3);
     237  p->iiAddCproc("","ttreduceInitially4",FALSE,ttreduceInitially4);
    473238#endif //NDEBUG
    474   p->iiAddCproc("","reduceInitially",FALSE,reduceInitially);
     239  p->iiAddCproc("","ppreduceInitially",FALSE,ppreduceInitially);
     240  p->iiAddCproc("","ttreduceInitially",FALSE,ttreduceInitially);
    475241  p->iiAddCproc("","homogeneitySpace",FALSE,homogeneitySpace);
    476 }
     242  p->iiAddCproc("","containsMonomial",FALSE,containsMonomial);
     243}
  • dyn_modules/callgfanlib/ppinitialReduction.cc

    r5222d2a rca326f  
    7272
    7373#ifndef NDEBUG
    74 BOOLEAN pReduce(leftv res, leftv args)
     74BOOLEAN pppReduce(leftv res, leftv args)
    7575{
    7676  leftv u = args;
     
    103103 * assumes that h and g are in pReduced form and homogeneous in x of the same degree
    104104 **/
    105 bool reduceInitially(poly &h, const poly g)
     105bool ppreduceInitially(poly &h, const poly g)
    106106{
    107107  pTest(h); pTest(g); poly hCache;
     
    129129
    130130#ifndef NDEBUG
    131 BOOLEAN reduceInitially0(leftv res, leftv args)
     131BOOLEAN ppreduceInitially0(leftv res, leftv args)
    132132{
    133133  leftv u = args;
     
    142142      h = (poly) u->CopyD();
    143143      g = (poly) v->CopyD();
    144       (void)reduceInitially(h,g);
     144      (void)ppreduceInitially(h,g);
    145145      p_Delete(&h,currRing);
    146146      p_Delete(&g,currRing);
     
    149149      h = (poly) u->CopyD();
    150150      g = (poly) v->CopyD();
    151       (void)reduceInitially(h,g);
     151      (void)ppreduceInitially(h,g);
    152152      p_Delete(&g,currRing);
    153153      res->rtyp = POLY_CMD;
     
    166166 * assumes that I is generated by elements which are homogeneous in x of the same degree.
    167167 **/
    168 bool reduceInitially(ideal I, const number p)
     168bool ppreduceInitially(ideal I, const number p)
    169169{
    170170  int m=idSize(I),n=m; poly cache;
     
    192192  for (int i=0; i<m-1; i++)
    193193    for (int j=i+1; j<m; j++)
    194       if (reduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;
     194      if (ppreduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;
    195195
    196196  /***
     
    199199  for (int i=0; i<m-1; i++)
    200200    for (int j=i+1; j<m; j++)
    201       if (reduceInitially(I->m[i], I->m[j]) && pReduce(I->m[i],p)) return true;
     201      if (ppreduceInitially(I->m[i], I->m[j]) && pReduce(I->m[i],p)) return true;
    202202  return false;
    203203}
     
    205205
    206206#ifndef NDEBUG
    207 BOOLEAN reduceInitially1(leftv res, leftv args)
     207BOOLEAN ppreduceInitially1(leftv res, leftv args)
    208208{
    209209  leftv u = args;
     
    218218      I = (ideal) u->CopyD();
    219219      p = (number) v->CopyD();
    220       (void) reduceInitially(I,p);
     220      (void) ppreduceInitially(I,p);
    221221      id_Delete(&I,currRing);
    222222      n_Delete(&p,currRing->cf);
     
    225225      I = (ideal) u->CopyD();
    226226      p = (number) v->CopyD();
    227       (void) reduceInitially(I,p);
     227      (void) ppreduceInitially(I,p);
    228228      n_Delete(&p,currRing->cf);
    229229      res->rtyp = IDEAL_CMD;
     
    241241 * assumes that I was already sorted and initially reduced in the first place
    242242 **/
    243 bool reduceInitially(ideal I, const number p, const poly g)
     243bool ppreduceInitially(ideal I, const number p, const poly g)
    244244{
    245245  int n=idSize(I);
     
    263263   **/
    264264  for (int i=0; i<j; i++)
    265     if (reduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;
     265    if (ppreduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;
    266266  for (int k=j+1; k<n; k++)
    267     if (reduceInitially(I->m[k], I->m[j]) && pReduce(I->m[k],p)) return true;
     267    if (ppreduceInitially(I->m[k], I->m[j]) && pReduce(I->m[k],p)) return true;
    268268
    269269  /***
     
    273273  for (int i=0; i<j; i++)
    274274    for (int k=j; k<n; k++)
    275       if (reduceInitially(I->m[i], I->m[k]) && pReduce(I->m[i],p)) return true;
     275      if (ppreduceInitially(I->m[i], I->m[k]) && pReduce(I->m[i],p)) return true;
    276276  for (int k=j+1; k<n; k++)
    277     if (reduceInitially(I->m[j],I->m[k]) && pReduce(I->m[j],p)) return true;
     277    if (ppreduceInitially(I->m[j],I->m[k]) && pReduce(I->m[j],p)) return true;
    278278
    279279  return false;
     
    282282
    283283#ifndef NDEBUG
    284 BOOLEAN reduceInitially2(leftv res, leftv args)
     284BOOLEAN ppreduceInitially2(leftv res, leftv args)
    285285{
    286286  leftv u = args;
     
    299299        p = (number) v->CopyD();
    300300        g = (poly) w->CopyD();
    301         (void) reduceInitially(I,p,g);
     301        (void) ppreduceInitially(I,p,g);
    302302        id_Delete(&I,currRing);
    303303        n_Delete(&p,currRing->cf);
     
    307307        p = (number) v->CopyD();
    308308        g = (poly) w->CopyD();
    309         (void) reduceInitially(I,p,g);
     309        (void) ppreduceInitially(I,p,g);
    310310        n_Delete(&p,currRing->cf);
    311311        res->rtyp = IDEAL_CMD;
     
    326326 * assumes that the generators of G are homogeneous in x of lesser degree.
    327327 **/
    328 bool reduceInitially(ideal H, const number p, const ideal G)
     328bool ppreduceInitially(ideal H, const number p, const ideal G)
    329329{
    330330  /***
    331331   * Step 1: reduce H initially with respect to itself and with respect to p-t
    332332   **/
    333   if (reduceInitially(H,p)) return true;
     333  if (ppreduceInitially(H,p)) return true;
    334334
    335335  /***
     
    376376      p_SetCoeff(g,n_Init(1,currRing->cf),currRing); p_Setm(g,currRing);
    377377      g = p_Mult_q(g,p_Copy(G->m[i],currRing),currRing);
    378       reduceInitially(I,p,g);
     378      ppreduceInitially(I,p,g);
    379379    }
    380380    else
     
    431431
    432432#ifndef NDEBUG
    433 BOOLEAN reduceInitially3(leftv res, leftv args)
     433BOOLEAN ppreduceInitially3(leftv res, leftv args)
    434434{
    435435  leftv u = args;
     
    448448        p = (number) v->CopyD();
    449449        G = (ideal) w->CopyD();
    450         (void) reduceInitially(H,p,G);
     450        (void) ppreduceInitially(H,p,G);
    451451        id_Delete(&H,currRing);
    452452        id_Delete(&G,currRing);
     
    457457        p = (number) v->CopyD();
    458458        G = (ideal) w->CopyD();
    459         (void) reduceInitially(H,p,G);
     459        (void) ppreduceInitially(H,p,G);
    460460        n_Delete(&p,currRing->cf);
    461461        id_Delete(&G,currRing);
     
    475475 * assumes that the generators of I are homogeneous in x and that p-t is in I.
    476476 **/
    477 bool reduceInitially(ideal I)
     477bool ppreduceInitially(ideal I)
    478478{
    479479  /***
     
    512512   **/
    513513  it++; Hi = it->second; n--;
    514   if (reduceInitially(Hi,p)) return true;
     514  if (ppreduceInitially(Hi,p)) return true;
    515515
    516516  ideal G = idInit(n); int m=0;
     
    550550    }
    551551    m += l; IDELEMS(GG) = m; GG->m = &G->m[n-m];
    552     if (reduceInitially(it->second,p,GG)) return true;
     552    if (ppreduceInitially(it->second,p,GG)) return true;
    553553    idShallowDelete(&Hi); Hi = it->second;
    554554  }
     
    561561
    562562#ifndef NDEBUG
    563 BOOLEAN reduceInitially4(leftv res, leftv args)
     563BOOLEAN ppreduceInitially4(leftv res, leftv args)
    564564{
    565565  leftv u = args;
     
    570570    Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
    571571    I = (ideal) u->CopyD();
    572     (void) reduceInitially(I);
     572    (void) ppreduceInitially(I);
    573573    id_Delete(&I,currRing);
    574574    omUpdateInfo();
    575575    Print("usedBytesAfter=%ld\n",om_Info.UsedBytes);
    576576    I = (ideal) u->CopyD();
    577     (void) reduceInitially(I);
     577    (void) ppreduceInitially(I);
    578578    res->rtyp = IDEAL_CMD;
    579579    res->data = (char*) I;
     
    585585
    586586
    587 BOOLEAN reduceInitially(leftv res, leftv args)
     587BOOLEAN ppreduceInitially(leftv res, leftv args)
    588588{
    589589  leftv u = args;
     
    591591  {
    592592    ideal I = (ideal) u->CopyD();
    593     (void) reduceInitially(I);
     593    (void) ppreduceInitially(I);
    594594    res->rtyp = IDEAL_CMD;
    595595    res->data = (char*) I;
  • dyn_modules/callgfanlib/ppinitialReduction.h

    r5222d2a rca326f  
    1 #ifndef INITIALREDUCTION_H
    2 #define INITIALREDUCTION_H
     1#ifndef PPINITIALREDUCTION_H
     2#define PPINITIALREDUCTION_H
    33
    44#include <kernel/structs.h>
    55
    6 #ifndef N_DEBUG
    7 BOOLEAN pReduce(leftv res, leftv args);
    8 BOOLEAN reduceInitially0(leftv res, leftv args);
    9 BOOLEAN reduceInitially1(leftv res, leftv args);
    10 BOOLEAN reduceInitially2(leftv res, leftv args);
    11 BOOLEAN reduceInitially3(leftv res, leftv args);
    12 BOOLEAN reduceInitially4(leftv res, leftv args);
     6#ifndef NDEBUG
     7BOOLEAN pppReduce(leftv res, leftv args);
     8BOOLEAN ppreduceInitially0(leftv res, leftv args);
     9BOOLEAN ppreduceInitially1(leftv res, leftv args);
     10BOOLEAN ppreduceInitially2(leftv res, leftv args);
     11BOOLEAN ppreduceInitially3(leftv res, leftv args);
     12BOOLEAN ppreduceInitially4(leftv res, leftv args);
    1313#endif
    1414
    15 BOOLEAN reduceInitially(leftv res, leftv args);
     15BOOLEAN ppreduceInitially(leftv res, leftv args);
    1616
    1717#endif
  • dyn_modules/callgfanlib/ttinitialReduction.cc

    r5222d2a rca326f  
    1 #include <kernel/polys.h>
    21#include <Singular/ipid.h>
    32
    43#include <libpolys/polys/monomials/p_polys.h>
     4#include <libpolys/polys/clapsing.h>
    55#include <singularWishlist.h>
    66
     
    88#include <set>
    99
    10 #define KEEP_COEFF_SMALL 1
     10#define KEEP_COEFF_SMALL 0
    1111
    1212/***
    13  * changes a polynomial g with the help p-t such that
    14  * 1) each term of g has a distinct monomial in x
    15  * 2) no term of g has a coefficient divisible by p
    16  * in particular, this means that all g_\alpha can be obtained
    17  * by reading the coefficients and that g is initially reduced
    18  * with respect to p-t
     13 * if KEEP_COEFF_SMALL is set, alters all coefficients of a polynomial g
     14 * to be in range between 0 and p-1 with the help of p-t.
     15 * In particular the result will be reduced with respect to p-t.
     16 * if KEEP_COEFF_SMALL is not set, reduces g initially with respect to p-t.
    1917 **/
    2018static bool pReduce(poly g, const number p)
     
    2422  poly gCache;
    2523
    26   number coeff, pPower; int power; poly subst;
     24  number coeff; int power; poly subst;
    2725  while(toBeChecked)
    2826  {
     27#if KEEP_COEFF_SMALL
     28    if (n_Greater(p_GetCoeff(toBeChecked,currRing),p,currRing->cf) ||
     29        n_Equal(p_GetCoeff(toBeChecked,currRing),p,currRing->cf))
     30    {
     31      coeff = n_IntDiv(p_GetCoeff(toBeChecked,currRing),p,currRing->cf);
     32      p_SetCoeff(toBeChecked,
     33                 n_IntMod(p_GetCoeff(toBeChecked,currRing),p,currRing->cf),
     34                 currRing);
     35      subst = p_LmInit(toBeChecked,currRing);
     36      p_AddExp(subst,1,1,currRing);
     37      p_SetCoeff(subst,coeff,currRing);
     38      p_Setm(subst,currRing); pTest(subst);
     39      pNext(toBeChecked)=p_Add_q(pNext(toBeChecked),subst,currRing);
     40      pTest(toBeChecked);
     41    }
     42    else
     43    {
     44      number negcoeff = n_Neg(p_GetCoeff(toBeChecked,currRing),currRing->cf);
     45      if (n_GreaterZero(negcoeff,currRing->cf))
     46      {
     47        number coeffdiv = n_IntDiv(p_GetCoeff(toBeChecked,currRing),p,currRing->cf);
     48        number coeffmod = n_IntMod(p_GetCoeff(toBeChecked,currRing),p,currRing->cf);
     49        if (n_IsZero(coeffmod,currRing->cf))
     50        {
     51          poly subst = p_LmInit(toBeChecked,currRing);
     52        }
     53      }
     54      n_Delete(negcoeff,currRing->cf);
     55    }
     56#else
    2957    for (gCache = g; gCache; pIter(gCache))
    3058      if (p_LeadmonomDivisibleBy(gCache,toBeChecked,currRing)) break;
     
    5583      else
    5684      {
    57 #ifdef KEEP_COEFF_SMALL
    58         if (n_Greater(p_GetCoeff(toBeChecked,currRing),p,currRing->cf))
    59         {
    60           coeff = n_IntDiv(p_GetCoeff(toBeChecked,currRing),p,currRing->cf);
    61           p_SetCoeff(toBeChecked,
    62                      n_IntMod(p_GetCoeff(toBeChecked,currRing),p,currRing->cf),
    63                      currRing);
    64           subst = p_LmInit(toBeChecked,currRing);
    65           p_AddExp(subst,1,1,currRing);
    66           p_SetCoeff(subst,coeff,currRing);
    67           p_Setm(subst,currRing); pTest(subst);
    68           pNext(toBeChecked)=p_Add_q(pNext(toBeChecked),subst,currRing);
    69           pTest(toBeChecked);
    70         }
    71 #endif
    7285        pNext(gEnd)=toBeChecked;
    7386        pIter(gEnd); pIter(toBeChecked);
     
    7588      }
    7689    }
    77   }
     90    else
     91    {
     92      pNext(gEnd)=toBeChecked;
     93      pIter(gEnd); pIter(toBeChecked);
     94      pNext(gEnd)=NULL;
     95    }
     96  }
     97#endif
    7898  return false;
    7999}
     
    106126
    107127
    108 #if 0
    109128/***
    110129 * reduces h initially with respect to g,
     
    113132 * assumes that h and g are in pReduced form and homogeneous in x of the same degree
    114133 **/
    115 bool reduceInitially(poly &h, const poly g)
     134bool ttreduceInitially(poly &h, const poly g)
    116135{
    117136  pTest(h); pTest(g); poly hCache;
     
    139158
    140159#ifndef NDEBUG
    141 BOOLEAN reduceInitially0(leftv res, leftv args)
     160BOOLEAN ttreduceInitially0(leftv res, leftv args)
    142161{
    143162  leftv u = args;
     
    152171      h = (poly) u->CopyD();
    153172      g = (poly) v->CopyD();
    154       (void)reduceInitially(h,g);
     173      (void)ttreduceInitially(h,g);
    155174      p_Delete(&h,currRing);
    156175      p_Delete(&g,currRing);
     
    159178      h = (poly) u->CopyD();
    160179      g = (poly) v->CopyD();
    161       (void)reduceInitially(h,g);
     180      (void)ttreduceInitially(h,g);
    162181      p_Delete(&g,currRing);
    163182      res->rtyp = POLY_CMD;
     
    176195 * assumes that I is generated by elements which are homogeneous in x of the same degree.
    177196 **/
    178 bool reduceInitially(ideal I, const number p)
     197bool ttreduceInitially(ideal I, const number p)
    179198{
    180199  int m=idSize(I),n=m; poly cache;
     
    202221  for (int i=0; i<m-1; i++)
    203222    for (int j=i+1; j<m; j++)
    204       if (reduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;
     223      if (ttreduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;
    205224
    206225  /***
     
    209228  for (int i=0; i<m-1; i++)
    210229    for (int j=i+1; j<m; j++)
    211       if (reduceInitially(I->m[i], I->m[j]) && pReduce(I->m[i],p)) return true;
     230      if (ttreduceInitially(I->m[i], I->m[j]) && pReduce(I->m[i],p)) return true;
    212231  return false;
    213232}
     
    215234
    216235#ifndef NDEBUG
    217 BOOLEAN reduceInitially1(leftv res, leftv args)
     236BOOLEAN ttreduceInitially1(leftv res, leftv args)
    218237{
    219238  leftv u = args;
     
    228247      I = (ideal) u->CopyD();
    229248      p = (number) v->CopyD();
    230       (void) reduceInitially(I,p);
     249      (void) ttreduceInitially(I,p);
    231250      id_Delete(&I,currRing);
    232251      n_Delete(&p,currRing->cf);
     
    235254      I = (ideal) u->CopyD();
    236255      p = (number) v->CopyD();
    237       (void) reduceInitially(I,p);
     256      (void) ttreduceInitially(I,p);
    238257      n_Delete(&p,currRing->cf);
    239258      res->rtyp = IDEAL_CMD;
     
    251270 * assumes that I was already sorted and initially reduced in the first place
    252271 **/
    253 bool reduceInitially(ideal I, const number p, const poly g)
     272bool ttreduceInitially(ideal I, const number p, const poly g)
    254273{
    255274  int n=idSize(I);
     
    273292   **/
    274293  for (int i=0; i<j; i++)
    275     if (reduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;
     294    if (ttreduceInitially(I->m[j], I->m[i]) && pReduce(I->m[j],p)) return true;
    276295  for (int k=j+1; k<n; k++)
    277     if (reduceInitially(I->m[k], I->m[j]) && pReduce(I->m[k],p)) return true;
     296    if (ttreduceInitially(I->m[k], I->m[j]) && pReduce(I->m[k],p)) return true;
    278297
    279298  /***
     
    283302  for (int i=0; i<j; i++)
    284303    for (int k=j; k<n; k++)
    285       if (reduceInitially(I->m[i], I->m[k]) && pReduce(I->m[i],p)) return true;
     304      if (ttreduceInitially(I->m[i], I->m[k]) && pReduce(I->m[i],p)) return true;
    286305  for (int k=j+1; k<n; k++)
    287     if (reduceInitially(I->m[j],I->m[k]) && pReduce(I->m[j],p)) return true;
     306    if (ttreduceInitially(I->m[j],I->m[k]) && pReduce(I->m[j],p)) return true;
    288307
    289308  return false;
     
    292311
    293312#ifndef NDEBUG
    294 BOOLEAN reduceInitially2(leftv res, leftv args)
     313BOOLEAN ttreduceInitially2(leftv res, leftv args)
    295314{
    296315  leftv u = args;
     
    309328        p = (number) v->CopyD();
    310329        g = (poly) w->CopyD();
    311         (void) reduceInitially(I,p,g);
     330        (void) ttreduceInitially(I,p,g);
    312331        id_Delete(&I,currRing);
    313332        n_Delete(&p,currRing->cf);
     
    317336        p = (number) v->CopyD();
    318337        g = (poly) w->CopyD();
    319         (void) reduceInitially(I,p,g);
     338        (void) ttreduceInitially(I,p,g);
    320339        n_Delete(&p,currRing->cf);
    321340        res->rtyp = IDEAL_CMD;
     
    336355 * assumes that the generators of G are homogeneous in x of lesser degree.
    337356 **/
    338 bool reduceInitially(ideal H, const number p, const ideal G)
     357bool ttreduceInitially(ideal H, const number p, const ideal G)
    339358{
    340359  /***
    341360   * Step 1: reduce H initially with respect to itself and with respect to p-t
    342361   **/
    343   if (reduceInitially(H,p)) return true;
     362  if (ttreduceInitially(H,p)) return true;
    344363
    345364  /***
     
    386405      p_SetCoeff(g,n_Init(1,currRing->cf),currRing); p_Setm(g,currRing);
    387406      g = p_Mult_q(g,p_Copy(G->m[i],currRing),currRing);
    388       reduceInitially(I,p,g);
     407      ttreduceInitially(I,p,g);
    389408    }
    390409    else
     
    441460
    442461#ifndef NDEBUG
    443 BOOLEAN reduceInitially3(leftv res, leftv args)
     462BOOLEAN ttreduceInitially3(leftv res, leftv args)
    444463{
    445464  leftv u = args;
     
    458477        p = (number) v->CopyD();
    459478        G = (ideal) w->CopyD();
    460         (void) reduceInitially(H,p,G);
     479        (void) ttreduceInitially(H,p,G);
    461480        id_Delete(&H,currRing);
    462481        id_Delete(&G,currRing);
     
    467486        p = (number) v->CopyD();
    468487        G = (ideal) w->CopyD();
    469         (void) reduceInitially(H,p,G);
     488        (void) ttreduceInitially(H,p,G);
    470489        n_Delete(&p,currRing->cf);
    471490        id_Delete(&G,currRing);
     
    485504 * assumes that the generators of I are homogeneous in x and that p-t is in I.
    486505 **/
    487 bool reduceInitially(ideal I)
     506bool ttreduceInitially(ideal I)
    488507{
    489508  /***
     
    522541   **/
    523542  it++; Hi = it->second; n--;
    524   if (reduceInitially(Hi,p)) return true;
     543  if (ttreduceInitially(Hi,p)) return true;
    525544
    526545  ideal G = idInit(n); int m=0;
     
    560579    }
    561580    m += l; IDELEMS(GG) = m; GG->m = &G->m[n-m];
    562     if (reduceInitially(it->second,p,GG)) return true;
     581    if (ttreduceInitially(it->second,p,GG)) return true;
    563582    idShallowDelete(&Hi); Hi = it->second;
    564583  }
     
    571590
    572591#ifndef NDEBUG
    573 BOOLEAN reduceInitially4(leftv res, leftv args)
     592BOOLEAN ttreduceInitially4(leftv res, leftv args)
    574593{
    575594  leftv u = args;
     
    580599    Print("usedBytesBefore=%ld\n",om_Info.UsedBytes);
    581600    I = (ideal) u->CopyD();
    582     (void) reduceInitially(I);
     601    (void) ttreduceInitially(I);
    583602    id_Delete(&I,currRing);
    584603    omUpdateInfo();
    585604    Print("usedBytesAfter=%ld\n",om_Info.UsedBytes);
    586605    I = (ideal) u->CopyD();
    587     (void) reduceInitially(I);
     606    (void) ttreduceInitially(I);
    588607    res->rtyp = IDEAL_CMD;
    589608    res->data = (char*) I;
     
    595614
    596615
    597 BOOLEAN reduceInitially(leftv res, leftv args)
     616BOOLEAN ttreduceInitially(leftv res, leftv args)
    598617{
    599618  leftv u = args;
     
    601620  {
    602621    ideal I = (ideal) u->CopyD();
    603     (void) reduceInitially(I);
     622    (void) ttreduceInitially(I);
    604623    res->rtyp = IDEAL_CMD;
    605624    res->data = (char*) I;
     
    608627  return TRUE;
    609628}
    610 
    611 #endif
  • dyn_modules/callgfanlib/ttinitialReduction.h

    r5222d2a rca326f  
    1 #ifndef INITIALREDUCTION_H
    2 #define INITIALREDUCTION_H
     1#ifndef TTINITIALREDUCTION_H
     2#define TTINITIALREDUCTION_H
    33
    44#include <kernel/structs.h>
    55
    6 #ifndef N_DEBUG
     6#ifndef NDEBUG
    77BOOLEAN ttpReduce(leftv res, leftv args);
    8 /* BOOLEAN reduceInitially0(leftv res, leftv args); */
    9 /* BOOLEAN reduceInitially1(leftv res, leftv args); */
    10 /* BOOLEAN reduceInitially2(leftv res, leftv args); */
    11 /* BOOLEAN reduceInitially3(leftv res, leftv args); */
    12 /* BOOLEAN reduceInitially4(leftv res, leftv args); */
     8BOOLEAN ttreduceInitially0(leftv res, leftv args);
     9BOOLEAN ttreduceInitially1(leftv res, leftv args);
     10BOOLEAN ttreduceInitially2(leftv res, leftv args);
     11BOOLEAN ttreduceInitially3(leftv res, leftv args);
     12BOOLEAN ttreduceInitially4(leftv res, leftv args);
    1313#endif
    1414
    15 /* BOOLEAN reduceInitially(leftv res, leftv args); */
     15BOOLEAN ttreduceInitially(leftv res, leftv args);
    1616
    1717#endif
Note: See TracChangeset for help on using the changeset viewer.