Changeset 1aa55bf in git


Ignore:
Timestamp:
Oct 16, 2000, 2:06:41 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
dc078459b7830eda29e3e82e01acd64423bbddc0
Parents:
b559f83182d4517c4869319c1caa185e21439112
Message:
* sparsemat.cc : faster smSelectCopy and relatives
* ring: VarL_* stuff
* divisiblity tests based on longs


git-svn-id: file:///usr/local/Singular/svn/trunk@4644 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • Singular/Makefile.in

    rb559f8 r1aa55bf  
    116116        pp_Mult_mm__Template.cc p_Mult_mm__Template.cc \
    117117        p_Minus_mm_Mult_qq__Template.cc p_Add_q__Template.cc \
    118         p_Neg__Template.cc kInline.cc
     118        p_Neg__Template.cc pp_Mult_Coeff_mm_DivSelect__Template.cc \
     119        kInline.cc utils.cc utils.h
    119120
    120121
     
    129130        fglm.h kstd1.h modulop.h sing_dbm.h weight.h \
    130131        fglmgauss.h fglmvec.h mpsr.h sing_mp.h \
    131         kstdfac.h mpsr_Get.h \
     132        kstdfac.h mpsr_Get.h kmatrix.h\
    132133        kutil.h mpsr_Put.h sing_dld.h\
    133134        ndbm.h polys-impl.h libparse.h \
  • Singular/extra.cc

    rb559f8 r1aa55bf  
    22*  Computer Algebra System SINGULAR      *
    33*****************************************/
    4 /* $Id: extra.cc,v 1.146 2000-09-25 12:26:30 obachman Exp $ */
     4/* $Id: extra.cc,v 1.147 2000-10-16 12:06:34 obachman Exp $ */
    55/*
    66* ABSTRACT: general interface to internals of Singular ("system" command)
     
    741741#endif
    742742/*==================== pDivStat =============================*/
    743 #ifdef PDEBUG
     743#if defined(PDEBUG) || defined(PDIV_DEBUG)
    744744    if(strcmp(sys_cmd,"pDivStat")==0)
    745745    {
  • Singular/kspoly.cc

    rb559f8 r1aa55bf  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: kspoly.cc,v 1.11 2000-10-04 13:12:01 obachman Exp $ */
     4/* $Id: kspoly.cc,v 1.12 2000-10-16 12:06:34 obachman Exp $ */
    55/*
    66*  ABSTRACT -  Routines for Spoly creation and reductions
     
    2222
    2323
    24 #define NEW_STUFF
    25 
    26 #ifdef NEW_STUFF
    2724/***************************************************************
    2825 *
     
    9996  p_LmDelete(lm, tailRing);
    10097}
    101 #endif
    10298
    10399/***************************************************************
     
    107103 *
    108104 ***************************************************************/
    109 #ifdef NEW_STUFF
    110105void ksCreateSpoly(LObject* Pair,poly spNoether,
    111106                   int use_buckets, ring tailRing)
     
    189184  }
    190185}
    191 #endif
    192 
    193 //////////////////////////////////////////////////////////////////////////
    194 // Reduces PR at Current->next with PW
    195 // Assumes PR != NULL, Current contained in PR
    196 //         Current->next != NULL, LM(PW) devides LM(Current->next)
    197 // Changes: PR
    198 // Const:   PW
    199 #ifdef NEW_STUFF
    200 void ksSpolyTail(LObject* PR, TObject* PW, poly Current, poly spNoether)
    201 {
    202   poly Lp = PR->p;
    203   number coef;
    204   poly Save = PW->p;
    205   ring lmRing = PR->lmRing;
    206  
    207   assume(Lp != NULL && Current != NULL && pNext(Current) != NULL);
    208   assume(PR->bucket == NULL);
    209   pAssume(pIsMonomOf(Lp, Current));
    210 
    211   if (Lp == Save)
    212     PW->p = p_Copy(Save, currRing, PR->tailRing);
    213 
    214  
    215   PR->p = pNext(Current);
    216   PR->lmRing = PR->tailRing;
    217   ksReducePoly(PR, PW, spNoether, &coef);
    218  
    219   if (! n_IsOne(coef, currRing))
    220   {
    221     pNext(Current) = NULL;
    222     p_Mult_nn(Lp, coef, currRing, PR->tailRing);
    223   }
    224   n_Delete(&coef, currRing);
    225   pNext(Current) = PR->p;
    226   PR->p = Lp;
    227   PR->lmRing = lmRing;
    228   if (PW->p != Save)
    229   {
    230     p_Delete(&(PW->p), currRing, PR->tailRing);
    231     PW->p = Save; // == Lp
    232   }
    233 }
    234 
    235 #endif
    236 
    237 #ifndef NEW_STUFF
    238 
    239 void ksReducePoly(LObject* PR,
    240                   TObject* PW,
    241                   poly spNoether,
    242                   number *coef)
    243 {
    244   poly p1 = PR->p;
    245   poly p2 = PW->p;
    246 
    247   assume(p2 != NULL && p1 != NULL && pDivisibleBy(p2,  p1));
    248   assume(pGetComp(p1) == pGetComp(p2) ||
    249          (pMaxComp(p2) == 0));
    250  
    251   poly a2 = pNext(p2), lm = p1;
    252 
    253   p1 = pNext(p1);
    254 
    255   if (a2==NULL)
    256   {
    257     pDeleteLm(&lm);
    258     PR->p = p1;
    259     if (coef != NULL) *coef = nInit(1);
    260     return;
    261   }
    262 
    263   if (! nIsOne(pGetCoeff(p2)))
    264   {
    265     number bn = pGetCoeff(lm);
    266     number an = pGetCoeff(p2);
    267     int ct = ksCheckCoeff(&an, &bn);
    268     pSetCoeff(lm, bn);
    269     if ((ct == 0) || (ct == 2))
    270       p1 = pMult_nn(p1, an);
    271     if (coef != NULL) *coef = an;
    272     else nDelete(&an);
    273   }
    274   else
    275   {
    276     if (coef != NULL) *coef = nInit(1);
    277   }
    278  
    279  
    280   // pMonSubFrom(lm, p2);
    281   pExpVectorSub(lm, p2);
    282   int dummy;
    283   PR->p = currRing->p_Procs->p_Minus_mm_Mult_qq(p1, lm, a2,
    284                                                 dummy, spNoether, currRing);
    285 
    286   pDeleteLm(&lm);
    287 }
    288 #endif
    289 
    290 #ifndef NEW_STUFF
    291 
    292 /***************************************************************
    293  *
    294  * Creates S-Poly of p1 and p2
    295  *
    296  *
    297  ***************************************************************/
    298 void ksCreateSpoly(LObject* Pair,
    299                    poly spNoether,
    300                    int use_buckets, ring tailRing)
    301 {
    302   assume(kTest_L(Pair));
    303   poly p1 = Pair->p1;
    304   poly p2 = Pair->p2;
    305 
    306   assume(p1 != NULL);
    307   assume(p2 != NULL);
    308 
    309   poly a1 = pNext(p1), a2 = pNext(p2);
    310   number lc1 = pGetCoeff(p1), lc2 = pGetCoeff(p2);
    311   poly m1, m2;
    312   int co=0, ct = ksCheckCoeff(&lc1, &lc2);
    313   int x, l1;
    314 
    315   if (pGetComp(p1)!=pGetComp(p2))
    316   {
    317     if (pGetComp(p1)==0)
    318     {
    319       co=1;
    320       pSetCompP(p1,pGetComp(p2));
    321     }
    322     else
    323     {
    324       co=2;
    325       pSetCompP(p2,pGetComp(p1));
    326     }
    327   }
    328 
    329   // get m1 = LCM(LM(p1), LM(p2))/LM(p1)
    330   //     m2 = LCM(LM(p1), LM(p2))/LM(p2)
    331   m1 = pInit();
    332   m2 = pInit();
    333   for (int i = pVariables; i; i--)
    334   {
    335     x = pGetExpDiff(p1, p2, i);
    336     if (x > 0)
    337     {
    338       pSetExp(m2,i,x);
    339       pSetExp(m1,i,0);
    340     }
    341     else
    342     {
    343       pSetExp(m1,i,-x);
    344       pSetExp(m2,i,0);
    345     }
    346   }
    347   pSetm(m1);
    348   pSetm(m2);           // now we have m1 * LM(p1) == m2 * LM(p2)
    349   pSetCoeff0(m1, lc2);
    350   pSetCoeff0(m2, lc1); // and now, m1 * LT(p1) == m2 * LT(p2)
    351 
    352   // get m2 * a2
    353   a2 = currRing->p_Procs->pp_Mult_mm(a2, m2, spNoether, currRing);
    354 
    355   // and, finally, the spoly
    356   int dummy;
    357   Pair->p = currRing->p_Procs->p_Minus_mm_Mult_qq(a2, m1, a1,
    358                                                   dummy, spNoether,
    359                                                   currRing);
    360  
    361   // Clean-up time
    362   pDeleteLm(&m1);
    363   pDeleteLm(&m2);
    364  
    365   if (co != 0)
    366   {
    367     if (co==1)
    368     {
    369       pSetCompP(p1,0);
    370     }
    371     else
    372     {
    373       pSetCompP(p2,0);
    374     }
    375   }
    376 }
    377 #endif
    378 
    379 #ifndef NEW_STUFF
     186
    380187//////////////////////////////////////////////////////////////////////////
    381188// Reduces PR at Current->next with PW
     
    389196  number coef;
    390197  poly Save = PW->p;
    391  
     198  ring lmRing = PR->lmRing;
     199 
     200  assume(Lp != NULL && Current != NULL && pNext(Current) != NULL);
     201  assume(PR->bucket == NULL);
     202  pAssume(pIsMonomOf(Lp, Current));
     203
    392204  if (Lp == Save)
    393     PW->p = pCopy(Save);
    394    
    395   assume(Lp != NULL && Current != NULL && pNext(Current) != NULL);
    396   assume(pIsMonomOf(Lp, Current));
     205    PW->p = p_Copy(Save, currRing, PR->tailRing);
     206
    397207 
    398208  PR->p = pNext(Current);
     209  PR->lmRing = PR->tailRing;
    399210  ksReducePoly(PR, PW, spNoether, &coef);
    400211 
    401   if (! nIsOne(coef))
     212  if (! n_IsOne(coef, currRing))
    402213  {
    403214    pNext(Current) = NULL;
    404     pMult_nn(Lp, coef);
    405   }
    406   nDelete(&coef);
     215    p_Mult_nn(Lp, coef, currRing, PR->tailRing);
     216  }
     217  n_Delete(&coef, currRing);
    407218  pNext(Current) = PR->p;
    408219  PR->p = Lp;
     220  PR->lmRing = lmRing;
    409221  if (PW->p != Save)
    410222  {
    411     pDelete(&(PW->p));
     223    p_Delete(&(PW->p), currRing, PR->tailRing);
    412224    PW->p = Save; // == Lp
    413225  }
    414226}
    415 
    416 #endif
    417227
    418228/***************************************************************
  • Singular/kstd2.cc

    rb559f8 r1aa55bf  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: kstd2.cc,v 1.49 2000-10-04 13:12:02 obachman Exp $ */
     4/* $Id: kstd2.cc,v 1.50 2000-10-16 12:06:35 obachman Exp $ */
    55/*
    66*  ABSTRACT -  Kernel: alg. of Buchberger
     
    188188
    189189  poly pi;
    190   int i,j,at,reddeg,d,pass,ei, ii;
     190  int i,j,at,reddeg,d,pass,ei, ii, h_d;
    191191  unsigned long not_sev;
    192192
     
    300300    h->sev = pGetShortExpVector(h->p);
    301301    not_sev = ~ h->sev;
     302    h_d = pFDeg(h->p);
    302303    /* compute the ecart */
    303304    if (ei <= (*h).ecart)
    304       (*h).ecart = d-pFDeg((*h).p);
     305      (*h).ecart = d-h_d;
    305306    else
    306       (*h).ecart = d-pFDeg((*h).p)+ei-(*h).ecart;
     307      (*h).ecart = d-h_d+ei-(*h).ecart;
    307308    /*
    308309     * try to reduce the s-polynomial h
     
    312313     */
    313314    pass++;
    314     d = pFDeg((*h).p)+(*h).ecart;
     315    d = h_d +(*h).ecart;
    315316    if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
    316317    {
  • Singular/kutil.cc

    rb559f8 r1aa55bf  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: kutil.cc,v 1.64 2000-10-04 13:12:03 obachman Exp $ */
     4/* $Id: kutil.cc,v 1.65 2000-10-16 12:06:35 obachman Exp $ */
    55/*
    66* ABSTRACT: kernel: utils for kStd
     
    2727#include "kutil.h"
    2828
    29 /* Hmm ... this should be inlined or made more efficient:
    30    see Long/mregular.tst */
    31 /*2
    32 *should return 1 if p divides q and p<q,
    33 *             -1 if q divides p and q<p
    34 *              0 otherwise
    35 */
    36 static inline int     pDivComp(poly p, poly q)
    37 {
    38   if (pGetComp(p) == pGetComp(q))
    39   {
    40     int i=pVariables;
    41     long d;
    42     BOOLEAN a=FALSE, b=FALSE;
    43     for (; i>0; i--)
    44     {
    45       d = pGetExpDiff(p, q, i);
    46       if (d)
    47       {
    48         if (d < 0)
    49         {
    50           if (b) return 0;
    51           a =TRUE;
    52         }
    53         else
    54         {
    55           if (a) return 0;
    56           b = TRUE;
    57         }
    58       }
    59     }
    60     if (a) return 1;
    61     else if (b)  return -1;
    62   }
    63   return 0;
    64 }
    6529
    6630static poly redMora (poly h,int maxIndex,kStrategy strat);
    6731static poly redBba (poly h,int maxIndex,kStrategy strat);
     32
     33static inline int pDivComp(poly p, poly q)
     34{
     35  if (pGetComp(p) == pGetComp(q))
     36  {
     37    BOOLEAN a=FALSE, b=FALSE;
     38    int i;
     39    unsigned long la, lb;
     40    unsigned long divmask = currRing->divmask;
     41    for (i=0; i<currRing->VarL_Size; i++)
     42    {
     43      la = p->exp[currRing->VarL_Offset[i]];
     44      lb = q->exp[currRing->VarL_Offset[i]];
     45      if (la != lb)
     46      {
     47        if (la < lb)
     48        {
     49          if (b) return 0;
     50          if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
     51            return 0;
     52          a = TRUE;
     53        }
     54        else
     55        {
     56          if (a) return 0;
     57          if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
     58            return 0;
     59          b = TRUE;
     60        }
     61      }
     62    }
     63    if (a) return 1;
     64    if (b) return -1;
     65  }
     66  return 0;
     67}
     68
    6869
    6970BITSET  test=(BITSET)0;
  • Singular/kutil.h

    rb559f8 r1aa55bf  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: kutil.h,v 1.32 2000-10-04 13:12:03 obachman Exp $ */
     6/* $Id: kutil.h,v 1.33 2000-10-16 12:06:36 obachman Exp $ */
    77/*
    88* ABSTRACT: kernel: utils for kStd
     
    3434    {
    3535      memset((void*) this, 0, sizeof(sTObject));
     36    }
     37  sTObject(poly _p)
     38    {
     39      memset((void*) this, 0, sizeof(sTObject));
     40      p = _p;
    3641    }
    3742};
     
    5257      memset((void*) this, 0, sizeof(sLObject));
    5358      lmRing = tailRing = currRing;
     59    }
     60  sLObject(poly _p)
     61    {
     62      memset((void*) this, 0, sizeof(sLObject));
     63      lmRing = tailRing = currRing;
     64      p = _p;
    5465    }
    5566  // spoly related things
  • Singular/pDebug.cc

    rb559f8 r1aa55bf  
    77 *  Author:  obachman (Olaf Bachmann)
    88 *  Created: 8/00
    9  *  Version: $Id: pDebug.cc,v 1.5 2000-09-25 12:26:35 obachman Exp $
     9 *  Version: $Id: pDebug.cc,v 1.6 2000-10-16 12:06:36 obachman Exp $
    1010 *******************************************************************/
    1111
     
    100100 *
    101101 ***************************************************************/
    102 static int pDivisibleBy_number = 1;
    103 static int pDivisibleBy_FALSE = 1;
    104 static int pDivisibleBy_ShortFalse = 1;
    105 BOOLEAN pDebugLmShortDivisibleBy(poly p1, unsigned long sev_1, ring r_1,
    106                                poly p2, unsigned long not_sev_2, ring r_2)
    107 {
    108   _pPolyAssume(p_GetShortExpVector(p1, r_1) == sev_1, p1, r_1);
    109   _pPolyAssume(p_GetShortExpVector(p2, r_2) == ~ not_sev_2, p2, r_2);
    110 
    111   pDivisibleBy_number++;
    112   BOOLEAN ret = p_LmDivisibleBy(p1, r_1, p2, r_2);
    113   if (! ret) pDivisibleBy_FALSE++;
    114   if (sev_1 & not_sev_2)
    115   {
    116     pDivisibleBy_ShortFalse++;
    117     if (ret)
    118       dReportError("p1 divides p2, but sev's are wrong");
    119   }
    120   return ret;
    121 }
    122 
    123 void pPrintDivisbleByStat()
    124 {
    125   Print("#Tests: %d; #FALSE %d(%d); #SHORT %d(%d)\n",
    126         pDivisibleBy_number,
    127         pDivisibleBy_FALSE, pDivisibleBy_FALSE*100/pDivisibleBy_number,
    128         pDivisibleBy_ShortFalse, pDivisibleBy_ShortFalse*100/pDivisibleBy_FALSE);
    129 }
     102BOOLEAN p_DebugLmDivisibleByNoComp(poly a, poly b, ring r)
     103{
     104  int i=r->N;
     105
     106  do
     107  {
     108    if (p_GetExp(a,i,r) > p_GetExp(b,i,r))
     109      return FALSE;
     110    i--;
     111  }
     112  while (i);
     113  return TRUE;
     114}
     115
    130116
    131117/***************************************************************
     
    297283 
    298284#endif // PDEBUG
     285
     286#include "pInline1.h"
     287
     288#if defined(PDEBUG) || defined(PDIV_DEBUG)
     289static unsigned long pDivisibleBy_number = 1;
     290static unsigned long pDivisibleBy_FALSE = 1;
     291static unsigned long pDivisibleBy_ShortFalse = 1;
     292BOOLEAN pDebugLmShortDivisibleBy(poly p1, unsigned long sev_1, ring r_1,
     293                               poly p2, unsigned long not_sev_2, ring r_2)
     294{
     295  _pPolyAssume(p_GetShortExpVector(p1, r_1) == sev_1, p1, r_1);
     296  _pPolyAssume(p_GetShortExpVector(p2, r_2) == ~ not_sev_2, p2, r_2);
     297
     298  pDivisibleBy_number++;
     299  BOOLEAN ret;
     300  if (r_1 == r_2)
     301    ret = p_LmDivisibleBy(p1, p2, r_1);
     302  else
     303    ret = p_LmDivisibleBy(p1, r_1, p2, r_2);
     304
     305  if (! ret) pDivisibleBy_FALSE++;
     306  if (sev_1 & not_sev_2)
     307  {
     308    pDivisibleBy_ShortFalse++;
     309    if (ret)
     310      dReportError("p1 divides p2, but sev's are wrong");
     311  }
     312  return ret;
     313}
     314
     315void pPrintDivisbleByStat()
     316{
     317  Print("#Tests: %d; #FALSE %d(%d); #SHORT %d(%d)\n",
     318        pDivisibleBy_number,
     319        pDivisibleBy_FALSE, (unsigned long) ((double)pDivisibleBy_FALSE*((double) 100)/(double)pDivisibleBy_number),
     320        pDivisibleBy_ShortFalse, (unsigned long) ((double)pDivisibleBy_ShortFalse*((double)100)/(double)pDivisibleBy_FALSE));
     321}
     322#endif
     323
    299324#endif // PDEBUG_CC
    300325
  • Singular/pInline1.h

    rb559f8 r1aa55bf  
    77 *  Author:  obachman (Olaf Bachmann)
    88 *  Created: 8/00
    9  *  Version: $Id: pInline1.h,v 1.5 2000-10-04 13:12:04 obachman Exp $
     9 *  Version: $Id: pInline1.h,v 1.6 2000-10-16 12:06:36 obachman Exp $
    1010 *******************************************************************/
    1111#ifndef PINLINE1_H
     
    4444#ifdef PDIV_DEBUG
    4545BOOLEAN pDebugLmShortDivisibleBy(poly p1, unsigned long sev_1, ring r_1,
    46                                poly p2, unsigned long not_sev_2, ring r_2);
     46                                 poly p2, unsigned long not_sev_2, ring r_2);
     47BOOLEAN p_DebugLmDivisibleByNoComp(poly a, poly b, ring r);
     48#define pDivAssume  pAssume
     49#else
     50#define pDivAssume(x)   ((void)0)
    4751#endif
    4852
     
    149153  p_MemSub_LengthGeneral(p1->exp, p2->exp, r->ExpLSize);
    150154}
     155// ExpVector(p1) += ExpVector(p2) - ExpVector(p3)
     156PINLINE1 void p_ExpVectorAddSub(poly p1, poly p2, poly p3, ring r)
     157{
     158  p_CheckPolyRing1(p1, r);
     159  p_CheckPolyRing1(p2, r);
     160  p_CheckPolyRing1(p3, r);
     161#if PDEBUG >= 1
     162  for (int i=1; i<=r->N; i++)
     163    pAssume1(p_GetExp(p1, i, r) + p_GetExp(p2, i, r) >= p_GetExp(p3, i, r));
     164  pAssume1(p_GetComp(p1, r) == 0 ||
     165           (p_GetComp(p2, r) - p_GetComp(p3, r) == 0) ||
     166           (p_GetComp(p1, r) == p_GetComp(p2, r) - p_GetComp(p3, r)));
     167#endif
     168 
     169  p_MemAddSub_LengthGeneral(p1->exp, p2->exp, p3->exp, r->ExpLSize);
     170}
    151171// ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
    152172PINLINE1 void p_ExpVectorSum(poly pr, poly p1, poly p2, ring r)
     
    249269 *
    250270 ***************************************************************/
     271// return: FALSE, if there exists i, such that a->exp[i] > b->exp[i]
     272//         TRUE, otherwise
     273// (1) Consider long vars, instead of single exponents
     274// (2) Clearly, if la > lb, then FALSE
     275// (3) Suppose la <= lb, and consider first bits of single exponents in l:
     276//     if TRUE, then value of these bits is la ^ lb
     277//     if FALSE, then la-lb causes an "overflow" into one of those bits, i.e.,
     278//               la ^ lb != la - lb
    251279static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, poly b, ring r)
    252280{
    253   int i=r->N;
    254 
    255   do
    256   {
    257     if (p_GetExp(a,i,r) > p_GetExp(b,i,r))
    258       return FALSE;
    259     i--;
    260   }
    261   while (i);
     281  int i=r->VarL_Size - 1;
     282  unsigned long divmask = r->divmask;
     283  unsigned long la, lb;
     284 
     285  if (r->VarL_LowIndex >= 0)
     286  {
     287    i += r->VarL_LowIndex;
     288    do
     289    {
     290      la = a->exp[i];
     291      lb = b->exp[i];
     292      if ((la > lb) ||
     293          (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
     294      {
     295        pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE);
     296        return FALSE;
     297      }
     298      i--;
     299    }
     300    while (i>=r->VarL_LowIndex);
     301  }
     302  else
     303  {
     304    do
     305    {
     306      la = a->exp[r->VarL_Offset[i]];
     307      lb = b->exp[r->VarL_Offset[i]];
     308      if ((la > lb) ||
     309          (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask)))
     310      {
     311        pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == FALSE);
     312        return FALSE;
     313      }
     314      i--;
     315    }
     316    while (i>=0);
     317  }
     318  pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == TRUE);
    262319  return TRUE;
    263320}
     321
    264322static inline BOOLEAN _p_LmDivisibleByNoComp(poly a, ring r_a, poly b, ring r_b)
    265323{
  • Singular/pInline2.h

    rb559f8 r1aa55bf  
    77 *  Author:  obachman (Olaf Bachmann)
    88 *  Created: 8/00
    9  *  Version: $Id: pInline2.h,v 1.7 2000-10-04 13:12:04 obachman Exp $
     9 *  Version: $Id: pInline2.h,v 1.8 2000-10-16 12:06:37 obachman Exp $
    1010 *******************************************************************/
    1111#ifndef PINLINE2_H
     
    387387}
    388388
     389PINLINE2 poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r)
     390{
     391  return r->p_Procs->pp_Mult_Coeff_mm_DivSelect(p, m, r);
     392}
     393
    389394// returns -p, destroys p
    390395PINLINE2 poly p_Neg(poly p, const ring r)
  • Singular/p_MemAdd.h

    rb559f8 r1aa55bf  
    77 *  Author:  obachman (Olaf Bachmann)
    88 *  Created: 8/00
    9  *  Version: $Id: p_MemAdd.h,v 1.2 2000-09-12 16:01:06 obachman Exp $
     9 *  Version: $Id: p_MemAdd.h,v 1.3 2000-10-16 12:06:37 obachman Exp $
    1010 *******************************************************************/
    1111#ifndef P_MEM_ADD_H
     
    366366while (0)
    367367
     368#define _p_MemAddSub_Declare(r, s, t)                \
     369  const unsigned long* _s = ((unsigned long*) s); \
     370  const unsigned long* _t = ((unsigned long*) t); \
     371  unsigned long* _r = ((unsigned long*) r)
     372
     373#define p_MemAddSub_LengthGeneral(r, s, t, length)  \
     374do                                                  \
     375{                                                   \
     376  _p_MemAddSub_Declare(r,s, t);                     \
     377  const unsigned long _l = (unsigned long) length;  \
     378  unsigned long _i = 0;                             \
     379                                                    \
     380  do                                                \
     381  {                                                 \
     382    _r[_i] += _s[_i] - _t[_i];                      \
     383    _i++;                                           \
     384  }                                                 \
     385  while (_i != _l);                                 \
     386}                                                   \
     387while (0)
     388
    368389#endif P_MEM_ADD_H
     390
  • Singular/p_Procs.cc

    rb559f8 r1aa55bf  
    77 *  Author:  obachman (Olaf Bachmann)
    88 *  Created: 8/00
    9  *  Version: $Id: p_Procs.cc,v 1.14 2000-10-04 15:37:54 obachman Exp $
     9 *  Version: $Id: p_Procs.cc,v 1.15 2000-10-16 12:06:37 obachman Exp $
    1010 *******************************************************************/
    1111#include <string.h>
     
    4646//   5 -- all Field*_Length*_Ord* procs
    4747#ifdef NDEBUG
    48 const int HAVE_FAST_P_PROCS = 2;
     48const int HAVE_FAST_P_PROCS = 3;
    4949#else
    5050const int HAVE_FAST_P_PROCS = 0;
     
    6464//   3 -- special cases for length <= 4
    6565//   4 -- special cases for length <= 8
    66 const int HAVE_FAST_LENGTH = 4;
     66const int HAVE_FAST_LENGTH = 3;
    6767
    6868// Set HAVE_FAST_ORD to:
     
    180180  p_Minus_mm_Mult_qq_Proc,
    181181  p_Neg_Proc,
     182  pp_Mult_Coeff_mm_DivSelect_Proc,
    182183  p_Unknown_Proc
    183184};
     
    268269      case p_Minus_mm_Mult_qq_Proc: return "p_Minus_mm_Mult_qq_Proc";
    269270      case p_Neg_Proc: return "p_Neg_Proc";
     271      case pp_Mult_Coeff_mm_DivSelect_Proc: return "pp_Mult_Coeff_mm_DivSelect_Proc";
    270272      case p_Unknown_Proc: return "p_Unknown_Proc";
    271273  }
     
    483485      case p_Mult_mm_Proc:
    484486      case pp_Mult_nn_Proc:
     487      case pp_Mult_Coeff_mm_DivSelect_Proc:
    485488        return index(field, length);
    486489
     
    636639    (p_Procs->p_Add_q != NULL) &&
    637640    (p_Procs->p_Neg != NULL) &&
     641    (p_Procs->pp_Mult_Coeff_mm_DivSelect != NULL) &&
    638642    (p_Procs->p_Minus_mm_Mult_qq != NULL));
    639643}
     
    901905  SetProc(p_Minus_mm_Mult_qq, field, length, ord);
    902906  SetProc(p_Neg, field, LengthGeneral, OrdGeneral);
    903 }
    904 
    905 
    906 
     907  SetProc(pp_Mult_Coeff_mm_DivSelect, field, length, OrdGeneral);
     908}
     909
     910
     911
  • Singular/p_Procs.h

    rb559f8 r1aa55bf  
    88 *  Author:  obachman (Olaf Bachmann)
    99 *  Created: 8/00
    10  *  Version: $Id: p_Procs.h,v 1.5 2000-09-18 09:19:27 obachman Exp $
     10 *  Version: $Id: p_Procs.h,v 1.6 2000-10-16 12:06:38 obachman Exp $
    1111 *******************************************************************/
    1212#ifndef P_PROCS_H
     
    2828                                                const ring r);
    2929typedef poly (*p_Neg_Proc_Ptr)(poly p, const ring r);
     30typedef poly (*pp_Mult_Coeff_mm_DivSelect_Proc_Ptr)(poly p, const poly m, const ring r);
    3031
    3132typedef struct p_Procs_s
     
    4142  p_Minus_mm_Mult_qq_Proc_Ptr   p_Minus_mm_Mult_qq;
    4243  p_Neg_Proc_Ptr                p_Neg;
     44  pp_Mult_Coeff_mm_DivSelect_Proc_Ptr pp_Mult_Coeff_mm_DivSelect;
    4345} pProcs_s;
    4446
  • Singular/p_polys.h

    rb559f8 r1aa55bf  
    88 *  Author:  obachman (Olaf Bachmann)
    99 *  Created: 9/00
    10  *  Version: $Id: p_polys.h,v 1.3 2000-10-04 13:12:05 obachman Exp $
     10 *  Version: $Id: p_polys.h,v 1.4 2000-10-16 12:06:38 obachman Exp $
    1111 *******************************************************************/
    1212#ifndef P_POLYS_H
     
    122122// ExpVector(p1) -= ExpVector(p2)
    123123PINLINE1 void p_ExpVectorSub(poly p1, poly p2, ring r);
     124// ExpVector(p1) += ExpVector(p2) - ExpVector(p3)
     125PINLINE1 void p_ExpVectorAddSub(poly p1, poly p2, poly p3, ring r);
    124126// ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
    125127PINLINE1 void p_ExpVectorSum(poly pr, poly p1, poly p2, ring r);
     
    232234PINLINE2 poly pp_Mult_qq(poly p, poly q, const ring r);
    233235
     236// returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
     237PINLINE2 poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r);
     238
    234239/***************************************************************
    235240 *
  • Singular/polys.cc

    rb559f8 r1aa55bf  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: polys.cc,v 1.62 2000-09-18 09:19:29 obachman Exp $ */
     4/* $Id: polys.cc,v 1.63 2000-10-16 12:06:38 obachman Exp $ */
    55
    66/*
     
    780780    }
    781781  }
    782   if (pFDeg!=pWTotaldegree) pFDeg=pTotaldegree;
     782  if (pFDeg!=pWTotaldegree)
     783  {
     784    if (rOrd_is_Totaldegree_Ordering(r))
     785    {
     786      pFDeg = pDeg;
     787    }
     788    else
     789    {
     790      pFDeg=pTotaldegree;
     791    }
     792  }
    783793}
    784794
  • Singular/polys.h

    rb559f8 r1aa55bf  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: polys.h,v 1.39 2000-09-20 12:56:37 obachman Exp $ */
     6/* $Id: polys.h,v 1.40 2000-10-16 12:06:39 obachman Exp $ */
    77/*
    88* ABSTRACT - all basic methods to manipulate polynomials of the
     
    125125#define pExpVectorAdd(p1, p2)       p_ExpVectorAdd(p1, p2, currRing)
    126126#define pExpVectorSub(p1, p2)       p_ExpVectorSub(p1, p2, currRing)
     127#define pExpVectorAddSub(p1, p2, p3)p_ExpVectorAddSub(p1, p2, p3, currRing)
    127128#define pExpVectorSum(pr, p1, p2)   p_ExpVectorSum(pr, p1, p2, currRing)
    128129#define pExpVectorDiff(pr, p1, p2)  p_ExpVectorDiff(pr, p1, p2, currRing)
     
    206207#define pMult(p, q)                 p_Mult_q(p, q, currRing)
    207208#define ppMult_qq(p, q)             pp_Mult_qq(p, q, currRing)
     209// p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
     210#define ppMult_Coeff_mm_DivSelect(p, m)   pp_Mult_Coeff_mm_DivSelect(p, m, currRing)
    208211
    209212/***************************************************************
  • Singular/pp_Mult_nn__Template.cc

    rb559f8 r1aa55bf  
    33****************************************/
    44/***************************************************************
    5  *  File:    pp_Mult_n__Template.cc
    6  *  Purpose: template for pp_Mult_n
     5 *  File:    pp_Mult_nn__Template.cc
     6 *  Purpose: template for pp_Mult_nn
    77 *  Author:  obachman (Olaf Bachmann)
    88 *  Created: 8/00
    9  *  Version: $Id: pp_Mult_nn__Template.cc,v 1.3 2000-09-18 09:19:31 obachman Exp $
     9 *  Version: $Id: pp_Mult_nn__Template.cc,v 1.4 2000-10-16 12:06:39 obachman Exp $
    1010 *******************************************************************/
    1111
  • Singular/ring.cc

    rb559f8 r1aa55bf  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: ring.cc,v 1.119 2000-09-20 12:33:29 obachman Exp $ */
     4/* $Id: ring.cc,v 1.120 2000-10-16 12:06:39 obachman Exp $ */
    55
    66/*
     
    6363// unconditionally deletes fields in r
    6464static void rDelete(ring r);
     65// set r->VarL_Size, r->VarL_Offset, r->VarL_LowIndex
     66static void rSetVarL(ring r);
     67// get r->divmask depending on bits per exponent
     68static unsigned long rGetDivMask(int bits);
    6569
    6670/*0 implementation*/
     
    19351939}
    19361940
     1941BOOLEAN rOrder_is_DegOrdering(rRingOrder_t order)
     1942{
     1943  switch(order)
     1944  {
     1945      case ringorder_dp:
     1946      case ringorder_Dp:
     1947      case ringorder_ds:
     1948      case ringorder_Ds:
     1949        return TRUE;
     1950       
     1951      default:
     1952        return FALSE;
     1953  }
     1954}
     1955
     1956// return TRUE if p->exp[r->pOrdIndex] holds total degree of p */
     1957BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing)
     1958{
     1959  // Hmm.... what about Syz orderings?
     1960  return (r->N > 1 &&
     1961          rHasSimpleOrder(r) &&
     1962          (rOrder_is_DegOrdering((rRingOrder_t)r->order[0]) ||
     1963           rOrder_is_DegOrdering(( rRingOrder_t)r->order[1])));
     1964}
     1965                             
    19371966BOOLEAN rIsPolyVar(int v)
    19381967{
     
    22102239}
    22112240
    2212 unsigned long rGetExpSize(unsigned long bitmask, int & bits)
     2241static unsigned long rGetExpSize(unsigned long bitmask, int & bits)
    22132242{
    22142243  if (bitmask == 0)
     
    22952324* optimize rGetExpSize for a block of N variables, exp <=bitmask
    22962325*/
    2297 unsigned long rGetExpSize(unsigned long bitmask, int & bits, int N)
     2326static unsigned long rGetExpSize(unsigned long bitmask, int & bits, int N)
    22982327{
    22992328#if SIZEOF_LONG == 8
     
    24492478  int bits;
    24502479  r->bitmask=rGetExpSize(r->bitmask,bits);
     2480  r->BitsPerExp = bits;
     2481  r->divmask=rGetDivMask(bits);
     2482 
    24512483  // will be used for ordsgn:
    24522484  long *tmp_ordsgn=(long *)omAlloc0(2*(n+r->N)*sizeof(long));
     
    27842816  r->p_Procs = (p_Procs_s*)omAlloc(sizeof(p_Procs_s));
    27852817  p_SetProcs(r, r->p_Procs);
     2818
     2819  // ----------------------------
     2820  // set VarL_*
     2821  rSetVarL(r);
    27862822  return FALSE;
    27872823}
     
    28122848    if (r->p_Procs != NULL)
    28132849      omFreeSize(r->p_Procs, sizeof(p_Procs_s));
    2814   }
     2850    omfreeSize(r->VarL_Offset, r->VarL_Size*sizeof(int));
     2851  }
     2852}
     2853
     2854// set r->VarL_Size, r->VarL_Offset, r->VarL_LowIndex
     2855static void rSetVarL(ring r)
     2856{
     2857  poly p = p_Init(r);
     2858  int* VarL_Offset = (int*) omAlloc0(r->ExpLSize*sizeof(int));
     2859  int i,j;
     2860 
     2861  for (i=1; i<=r->N; i++)
     2862    p_SetExp(p, i, 1, r);
     2863
     2864  r->VarL_LowIndex = 0;
     2865  for (i=0, j=0; i<r->ExpLSize; i++)
     2866  {
     2867    if (p->exp[i] != 0)
     2868    {
     2869      VarL_Offset[j] = i;
     2870      if (j > 0 && VarL_Offset[j-1] != VarL_Offset[j] - 1)
     2871        r->VarL_LowIndex = -1;
     2872      j++;
     2873    }
     2874  }
     2875  r->VarL_Size = j;
     2876  if (r->VarL_LowIndex >= 0)
     2877    r->VarL_LowIndex = VarL_Offset[0];
     2878  r->VarL_Offset = (int*) omReallocSize(VarL_Offset,r->ExpLSize*sizeof(int),
     2879                                        j*sizeof(int));
     2880  p_LmFree(p, r);
     2881}
     2882   
     2883// get r->divmask depending on bits per exponent
     2884static unsigned long rGetDivMask(int bits)
     2885{
     2886  unsigned long divmask = 1;
     2887  int i = bits;
     2888 
     2889  while (i < BIT_SIZEOF_LONG)
     2890  {
     2891    divmask |= (1 << (unsigned long) i);
     2892    i += bits;
     2893  }
     2894  return divmask;
    28152895}
    28162896
     
    28282908  for(j=0;j<=r->N;j++) Print("  v%d at e-pos %d, bit %d\n",
    28292909     j,r->VarOffset[j] & 0xffffff, r->VarOffset[j] >>24);
     2910  Print("BitsPerExp=%d\n", r->BitsPerExp);
    28302911  Print("bitmask=0x%x\n",r->bitmask);
     2912  Print("divmask=%p\n", r->divmask);
    28312913  PrintS("ordsgn:\n");
    28322914  for(j=0;j<r->pCompLSize;j++)
     
    28542936  Print("pVarLowIndex:%d ",r->pVarLowIndex);
    28552937  Print("pVarHighIndex:%d\n",r->pVarHighIndex);
     2938  Print("VarL_Size:%d\nVarL_LowIndex:%d\n", r->VarL_Size, r->VarL_LowIndex);
    28562939#ifdef LONG_MONOMS
    28572940  Print("pDivLow:%d ",r->pDivLow);
  • Singular/ring.h

    rb559f8 r1aa55bf  
    77* ABSTRACT - the interpreter related ring operations
    88*/
    9 /* $Id: ring.h,v 1.51 2000-09-19 15:22:25 Singular Exp $ */
     9/* $Id: ring.h,v 1.52 2000-10-16 12:06:40 obachman Exp $ */
    1010
    1111/* includes */
     
    210210// returns TRUE, if simple lp or ls ordering
    211211BOOLEAN rHasSimpleLexOrder(ring r);
     212// return TRUE if p->exp[r->pOrdIndex] holds total degree of p */
     213BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing);
    212214rOrderType_t    rGetOrderType(ring r);
    213215BOOLEAN rIsPolyVar(int i); /* returns TRUE if var(i) belongs to p-block */
    214 
    215 void rOptimizeOrder(ring r);
    216216
    217217#ifdef RDEBUG
     
    222222#endif
    223223
    224 unsigned long rGetExpSize(unsigned long bitmask, int & bits);
    225 unsigned long rGetExpSize(unsigned long bitmask, int & bits, int N);
    226224ring rModifyRing(ring r, BOOLEAN omit_degree,
    227225                         BOOLEAN omit_comp,
  • Singular/sparsmat.cc

    rb559f8 r1aa55bf  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: sparsmat.cc,v 1.40 2000-09-25 14:07:59 pohl Exp $ */
     4/* $Id: sparsmat.cc,v 1.41 2000-10-16 12:06:41 obachman Exp $ */
    55
    66/*
     
    3535};
    3636*/
     37
     38#if OLD > 0
     39static poly smSelectCopy(poly, const poly);
     40#else
     41#define smSelectCopy ppMult_Coeff_mm_DivSelect
     42#endif
     43
    3744/* declare internal 'C' stuff */
    3845static void smExactPolyDiv(poly, poly);
    3946static BOOLEAN smIsNegQuot(poly, const poly, const poly);
    40 static BOOLEAN smCheckLead(const poly, const poly);
    41 static poly smSelectCopy(poly, const poly);
    4247static void smExpMultDiv(poly, const poly, const poly);
    4348static void smPolyDivN(poly, const number);
     
    18051810    if (smIsNegQuot(e, b, c))
    18061811    {
    1807       lead = smCheckLead(a, e);
     1812      lead = pLmDivisibleByNoComp(e, a);
    18081813      r = smSelectCopy(a, e);
    18091814      smExpMultDiv(r, b, c);
     
    18431848      r = smSelectCopy(a, e);
    18441849      smExpMultDiv(r, b, c);
    1845       if (smCheckLead(a, e))
     1850      if (pLmDivisibleByNoComp(e, a))
    18461851        smCombineChain(&pa, r);
    18471852      else
     
    19021907}
    19031908
     1909// obachman --> Wilfried: check the following
    19041910static BOOLEAN smIsNegQuot(poly a, const poly b, const poly c)
    19051911{
    1906   int i=pVariables;
    1907 
    1908   while ((i>0) && (pGetExp(b,i) >= pGetExp(c,i))) i--;
    1909   if(i!=0)
    1910   {
     1912  if (pLmDivisibleByNoComp(c, b))
     1913  {
     1914    pExpVectorDiff(a, b, c);
     1915    // Hmm: here used to be a pSetm(a): but it is unnecessary,
     1916    // if b and c are correct
     1917    return FALSE;
     1918  }
     1919  else
     1920  {
     1921    int i;
    19111922    for (i=pVariables; i>0; i--)
    19121923    {
     
    19161927        pSetExp(a,i,0);
    19171928    }
     1929    // here we actually might need a pSetm, if a is to be used in
     1930    // comparisons
    19181931    return TRUE;
    19191932  }
    1920   else
    1921   {
    1922     for (i=pVariables; i>0; i--)
    1923     {
    1924       pSetExp(a,i, pGetExp(b,i)-pGetExp(c,i));
    1925     }
    1926     pSetm(a);
    1927     return FALSE;
    1928   }
    1929 }
    1930 
    1931 static BOOLEAN smCheckLead(const poly t, const poly e)
     1933}
     1934
     1935static void smExpMultDiv(poly t, const poly b, const poly c)
    19321936{
    19331937  int i;
    1934   Exponent_t w;
    1935   for (i=pVariables; i; i--)
    1936   {
    1937     w = pGetExp(e,i);
    1938     if (w&&(w>pGetExp(t,i)))
    1939       return FALSE;
    1940   }
    1941   return TRUE;
    1942 }
    1943 
    1944 /*
    1945 * e is a monomial with exponents e(i)
    1946 * t is a polynom with monomials t_j and
    1947 *   exponents t_j(i)
    1948 * make a copy of a part of t:
    1949 *   for the monomials t_j of t in the copy
    1950 *   we have
    1951 *     ((e(i)!=0)&&(e(i)<=t_j(i)) == TRUE
    1952 */
    1953 static poly smSelectCopy(poly t, const poly e)
    1954 {
    1955   const number y = pGetCoeff(e);
    1956   poly res, h;
    1957 
    1958   loop
    1959   {
    1960     if(smCheckLead(t,e)) break;
    1961     pIter(t);
    1962     if(t==NULL) return NULL;
    1963   }
    1964   h = res = pNew();
    1965   loop
    1966   {
    1967     pExpVectorCopy(h,t);
    1968     pSetCoeff0(h,nMult(y,pGetCoeff(t)));
    1969     loop
    1970     {
    1971       pIter(t);
    1972       if(t==NULL)
    1973       {
    1974         pNext(h)=NULL;
    1975         return res;
    1976       }
    1977       if(smCheckLead(t,e)) break;
    1978     }
    1979     h=pNext(h)=pNew();
    1980   }
    1981 }
    1982 
    1983 static void smExpMultDiv(poly t, const poly b, const poly c)
    1984 {
    1985   int i;
     1938  pTest(t);
     1939  pLmTest(b);
     1940  pLmTest(c);
    19861941  while(t!=NULL)
    19871942  {
    1988     pExpVectorAdd(t,b);
    1989     pExpVectorSub(t,c);
     1943    pExpVectorAddSub(t, b, c);
    19901944    pIter(t);
    19911945  }
  • Singular/structs.h

    rb559f8 r1aa55bf  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: structs.h,v 1.37 2000-09-19 15:22:25 Singular Exp $ */
     6/* $Id: structs.h,v 1.38 2000-10-16 12:06:41 obachman Exp $ */
    77/*
    88* ABSTRACT
     
    252252  ideal      qideal; /* extension to the ring structure: qring */
    253253
    254   unsigned long bitmask;
    255254
    256255  int      *VarOffset;
     
    283282  short      ExpLSize; /* size of exponent vector in long */
    284283  short      OrdSize; /* size of ord vector (in sro_ord) */
     284  short      BitsPerExp; /* number of bits per exponent */
     285
     286  short      ref; /* reference counter to the ring */
     287
     288  /* number of long vars in exp vector:
     289     long vars are those longs in the exponent vector which are
     290     occupied by variables, only */
     291  short     VarL_Size;   
     292  /* if >= 0, long vars in exp vector are consecutive and start there
     293     if <  0, long vars in exp vector are not consecutive */
     294  short     VarL_LowIndex;
     295  /* array of size VarL_Size,
     296     VarL_Offset[i] gets i-th long var in exp vector */
     297  int*      VarL_Offset;
     298
     299  /* mask for getting single exponents */
     300  unsigned long bitmask;
     301  /* mask used for divisiblity tests */
     302  unsigned long divmask;
    285303
    286304  p_Procs_s* p_Procs;
    287   short      ref; /* reference counter to the ring */
    288305};
    289306
Note: See TracChangeset for help on using the changeset viewer.