Changeset 86016d in git for kernel/sca.cc


Ignore:
Timestamp:
Feb 1, 2007, 12:51:25 AM (17 years ago)
Author:
Motsak Oleksandr <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
c591ad0eb4ed9f5be86c0c85d2412be2ad6be556
Parents:
1cc61e18c0d6c70b177099c23a52159afb280bb4
Message:
*motsak:
 !+!: factors of SCA, debug print for SCA, "kill squares" in std.
  * : ncRingType, naming, formatting, unified NC setup.


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

Legend:

Unmodified
Added
Removed
  • kernel/sca.cc

    r1cc61e r86016d  
    77 *  Author:  motsak (Oleksandr Motsak)
    88 *  Created: 2006/12/18
    9  *  Version: $Id: sca.cc,v 1.7 2007-01-25 16:36:50 Singular Exp $
     9 *  Version: $Id: sca.cc,v 1.8 2007-01-31 23:51:25 motsak Exp $
    1010 *******************************************************************/
    1111
     
    4343
    4444
    45 //   scaFirstAltVar( r, 0 );
    46 //   scaLastAltVar( r, 0 );
     45// poly functions defined in p_Procs :
     46
     47// return pPoly * pMonom; preserve pPoly and pMonom.
     48poly sca_pp_Mult_mm(const poly pPoly, const poly pMonom, const ring rRing, poly &);
     49
     50// return pMonom * pPoly; preserve pPoly and pMonom.
     51poly sca_mm_Mult_pp(const poly pMonom, const poly pPoly, const ring rRing);
     52
     53// return pPoly * pMonom; preserve pMonom, destroy or reuse pPoly.
     54poly sca_p_Mult_mm(poly pPoly, const poly pMonom, const ring rRing);
     55
     56// return pMonom * pPoly; preserve pMonom, destroy or reuse pPoly.
     57poly sca_mm_Mult_p(const poly pMonom, poly pPoly, const ring rRing);
     58
     59
     60// compute the spolynomial of p1 and p2
     61poly sca_SPoly(const poly p1, const poly p2, const ring r);
     62poly sca_ReduceSpoly(const poly p1, poly p2, const ring r);
     63
     64// Modified Plural's Buchberger's algorithmus.
     65ideal sca_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat);
     66
     67// Modified modern Sinuglar Buchberger's algorithm.
     68ideal sca_bba(const ideal F, const ideal Q, const intvec *w, const intvec *, kStrategy strat);
     69
     70// Modified modern Sinuglar Mora's algorithm.
     71ideal sca_mora(const ideal F, const ideal Q, const intvec *w, const intvec *, kStrategy strat);
    4772
    4873
     
    280305    assume( scaFirstAltVar(rRing) <= i );
    281306
    282     if( p_GetExp(pMonom, i, rRing) ) // result is zero!
     307    if( p_GetExp(pMonom, i, rRing) != 0 ) // => result is zero!
    283308      return NULL;
    284309
     
    939964  assume(rIsSCA(currRing));
    940965
    941   BOOLEAN bIdHomog = id_IsYHomogeneous(F, currRing);
     966  const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
     967  const unsigned int m_iLastAltVar  = scaLastAltVar(currRing);
     968 
     969  ideal tempF = id_KillSquares(F, m_iFirstAltVar, m_iLastAltVar, currRing);
     970  const ideal tempQ = currRing->nc->SCAQuotient();
     971
     972  BOOLEAN bIdHomog = id_IsBiHomogeneous(tempF, m_iFirstAltVar, m_iLastAltVar, currRing);
     973
     974  assume( !bIdHomog || strat->homog ); //  bIdHomog =====[implies]>>>>> strat->homog
    942975
    943976  strat->homog = strat->homog && bIdHomog;
     
    952985  {
    953986    Print("ideal F: \n");
    954     for (int i = 0; i < F->idelems(); i++)
     987    for (int i = 0; i < tempF->idelems(); i++)
    955988    {
    956989      Print("; F[%d] = ", i+1);
    957       p_Write(F->m[i], currRing);
     990      p_Write(tempF->m[i], currRing);
    958991    }
    959992    Print(";\n");
     
    9761009  initBuchMoraCrit(strat); // set Gebauer, honey, sugarCrit
    9771010
    978   gr_initBba(F,strat); // set enterS, red, initEcart, initEcartPair
     1011  nc_gr_initBba(tempF,strat); // set enterS, red, initEcart, initEcartPair
    9791012
    9801013  initBuchMoraPos(strat);
     
    9831016  // ?? set spSpolyShort, reduce ???
    9841017
    985   initBuchMora(F, NULL, strat); // Q  = squares!!!!!!!
     1018  initBuchMora(tempF, tempQ, strat); // currRing->nc->SCAQuotient() instead of Q == squares!!!!!!!
    9861019
    9871020  strat->posInT=posInT110; // !!!
     
    9891022  srmax = strat->sl;
    9901023  reduc = olddeg = lrmax = 0;
    991 
    992 
    993   const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
    994   const unsigned int m_iLastAltVar  = scaLastAltVar(currRing);
    995 
    996 
    9971024
    9981025
     
    10611088    if (strat->sl > srmax) srmax = strat->sl;
    10621089
    1063     ////////////// children !!!!!!!!!!!!!
    1064 
    10651090    const poly save = strat->P.p;
    10661091
    1067 //     if( save != NULL )
    1068     {
    1069 
    10701092#ifdef PDEBUG
    10711093      p_Test(save, currRing);
    10721094#endif
    1073 
     1095    assume( save != NULL );
     1096   
     1097    // SCA Specials:
     1098
     1099    {
    10741100      const poly pNext = pNext(save);
    1075 
     1101     
     1102      if( pNext != NULL )
    10761103      for( unsigned int i = m_iFirstAltVar; i <= m_iLastAltVar; i++ )
    1077       if( pGetExp(save, i)!=0 )
     1104      if( p_GetExp(save, i, currRing) != 0 )
    10781105      {
     1106        assume(p_GetExp(save, i, currRing) == 1);
     1107       
    10791108        const poly tt = sca_pp_Mult_xi_pp(i, pNext, currRing);
    10801109
     
    11141143//         if(h.IsNull()) continue;
    11151144
    1116 
    1117   //       poly save = p_Copy(h.p, currRing);
     1145//         poly save = p_Copy(h.p, currRing);
    11181146
    11191147        int pos;
     
    11581186  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
    11591187
    1160 //  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
     1188  if (tempQ!=NULL) updateResult(strat->Shdl,tempQ,strat);
     1189 
     1190  id_Delete(&tempF, currRing);
    11611191
    11621192
     
    11661196
    11671197    ideal I = strat->Shdl;
    1168     ideal erg = kInterRed(I,NULL);
     1198    ideal erg = kInterRed(I,tempQ);
    11691199    assume(I!=erg);
    11701200    id_Delete(&I, currRing);
     
    11741204
    11751205#if 0
    1176   {
    1177     Print("ideal S: \n");
    1178     for (int i = 0; i < F->idelems(); i++)
    1179     {
    1180       Print("; S[%d] = ", 1+i);
    1181       p_Write(F->m[i], currRing);
    1182     }
    1183     Print(";\n");
    1184     PrintLn();
    1185   }
    1186 
    11871206   PrintS("</sca::bba>\n");
    11881207#endif
     
    11921211
    11931212
    1194 // is this an exterior algebra or a commuunative polynomial ring \otimes exterior algebra?
    1195 // we should check whether qr->qideal is of the form: y_i^2, y_{i+1}^2, \ldots, y_j^2 (j > i)
    1196 //.if yes, setup qr->nc->type, etc.
    1197 bool sca_SetupSCA(ring& rGR, const ring rG)
     1213// should be used only inside nc_SetupQuotient!
     1214// Check whether this our case:
     1215//  1. rG is  a commutative polynomial ring \otimes anticommutative algebra
     1216//  2. factor ideal rGR->qideal contains squares of all alternating variables.
     1217//
     1218// if yes, make rGR a super-commutative algebra!
     1219// NOTE: Factors of SuperCommutative Algebras are supported this way!
     1220bool sca_SetupQuotient(ring rGR, const ring rG)
    11981221{
    11991222//   return false; // test Plural
     
    12081231
    12091232  const int N = rG->N;
     1233
    12101234  if(N < 2)
    12111235    return false;
    12121236
    1213   // skew-commutative + constant skew? => no tensor products at the moment!!! Only exterior algebras are supported!
    1214 
    1215 //   if( rG->nc->D != NULL )
    1216 //     return false;
    1217 
    12181237  if(ncRingType(rG) != nc_skew)
    12191238    return false;
    12201239
    1221 //   if(rG->nc->IsSkewConstant != 1)
    1222 //     return false;
    1223 //
    1224 //   if(!n_IsMOne(p_GetCoeff(MATELEM(rG->nc->COM,1,2),rG->nc->basering), rG->nc->basering)) // COM live in basering!
    1225 //     return false;
    1226 
    1227 
    1228   assume(rGR->qideal != NULL);
    1229 
    1230   // sort qr->qideal:
    1231 
    1232   // for sanity
    1233   ring rSaveRing = currRing;
    1234 
    1235   bool bWeChangeRing = false;
    1236   if(currRing != rG)
    1237   {
    1238     rChangeCurrRing(rG);
    1239     bWeChangeRing = true;
    1240   }
    1241 
    1242   const ideal idQuotient = rGR->qideal;
    1243   const int   iQSize = idQuotient->idelems();
    1244 
    1245   intvec *iv = idSort(idQuotient, FALSE); // by lex, currRing dependent!!! :(
    1246   assume(iv != NULL);
    1247 
    1248   // check for y_{iAltVarStart}^2, y_{iAltVarStart+1}^2, \ldots, y_{iAltVarEnd}^2 (iAltVarEnd > iAltVarStart)
    1249   bool bSCA = true;
    1250 
    1251   int iAltVarStart = -1;
    1252   int iAltVarEnd   = -1;
    1253 
    1254   for(int i = 0; i < iQSize; i++)
    1255   {
    1256     const poly t = idQuotient->m[(*iv)[i]-1];
    1257 
    1258     if( pNext(t) != NULL )
    1259     {
    1260       bSCA = false;
    1261       break;
    1262     }
    1263 
    1264     const int iComp = p_GetComp(t, rG);
    1265 
    1266     if( iComp > 0 )
    1267     {
    1268       bSCA = false;
    1269       break;
    1270     }
    1271 
    1272     int iV = -1;
    1273 
    1274     for (int j = N; j; j--)
    1275     {
    1276       const int e = p_GetExp (t, j, rGR);
    1277 
    1278       if( e > 0 )
    1279       {
    1280         if( (e != 2) || (iV != -1) )
    1281         {
    1282           bSCA = false;
    1283           break;
    1284         }
    1285 
    1286         iV = j;
    1287       }
    1288     }
    1289 
    1290     if(!bSCA) break;
    1291 
    1292     if(iV == -1)
    1293     {
    1294       bSCA = false;
    1295       break;
    1296     }
    1297 
    1298     if(iAltVarStart == -1)
    1299     {
    1300       iAltVarStart = iV;
    1301       iAltVarEnd   = iV;
    1302     } else
    1303     {
    1304       if((iAltVarStart-1) == iV)
    1305       {
    1306         iAltVarStart = iV;
    1307       } else
    1308       if((iAltVarEnd+1) == iV)
    1309       {
    1310         iAltVarEnd = iV;
     1240  if(rGR->qideal == NULL) // there will be a factor!
     1241    return false;
     1242
     1243  if(rG->qideal != NULL) // we cannot change from factor to factor!
     1244    return false;
     1245
     1246
     1247  int iAltVarEnd = -1;
     1248  int iAltVarStart   = N+1;
     1249
     1250  const ring rBase = rG->nc->basering;
     1251  const matrix C   = rG->nc->C; // live in rBase!
     1252
     1253  for(int i = 1; i < N; i++)
     1254  {
     1255    for(int j = i + 1; j <= N; j++)
     1256    {
     1257      assume(MATELEM(C,i,j) != NULL); // after CallPlural!
     1258      number c = p_GetCoeff(MATELEM(C,i,j), rBase);
     1259     
     1260      if( n_IsMOne(c, rBase) )
     1261      {       
     1262        if( i < iAltVarStart)
     1263          iAltVarStart = i;
     1264         
     1265        if( j > iAltVarEnd)
     1266          iAltVarEnd = j;
    13111267      } else
    13121268      {
    1313         bSCA = false;
    1314         break;
     1269        if( !n_IsOne(c, rBase) )
     1270        {
     1271#ifdef PDEBUG
     1272//           Print("Wrong Coeff at: [%d, %d]\n", i, j);
     1273#endif
     1274          return false;
     1275        }
    13151276      }
    13161277    }
    13171278  }
    13181279
    1319   // cleanup:
    1320   delete iv;
    1321 
    1322   if (bWeChangeRing)
    1323   {
    1324     rChangeCurrRing(rSaveRing);
    1325   }
    1326 
    1327 
    1328   if(!bSCA) return false;
    1329 
    1330   assume( 1            <= iAltVarStart );
    1331   assume( iAltVarStart <= iAltVarEnd   );
    1332   assume( iAltVarEnd   <= N            );
    1333 
    1334 #ifdef PDEBUG
    1335 //   Print("AltVars: [%d, %d]\n", iAltVarStart, iAltVarEnd);
    1336 #endif
    1337 
    1338   const ring rBase = rG->nc->basering;
    1339   const matrix C   = rG->nc->C; // live in rBase!
    1340 
     1280  if( (iAltVarEnd == -1) || (iAltVarStart == (N+1)) )
     1281    return false; // either no alternating varables, or a single one => we are in commutative case!
     1282 
    13411283  for(int i = 1; i < N; i++)
    13421284  {
     
    13441286    {
    13451287      assume(MATELEM(C,i,j) != NULL); // after CallPlural!
    1346       number c = p_GetCoeff(MATELEM(C,i,j), rBase);
     1288      number c = p_GetCoeff(MATELEM(C,i,j), rBase);     
    13471289
    13481290      if( (iAltVarStart <= i) && (j <= iAltVarEnd) ) // S <= i < j <= E
     
    13681310  }
    13691311
     1312  assume( 1            <= iAltVarStart );
     1313  assume( iAltVarStart < iAltVarEnd   );
     1314  assume( iAltVarEnd   <= N            );
     1315
     1316  bool bWeChangeRing = false;
     1317  // for sanity
     1318  ring rSaveRing = currRing;
     1319
     1320  if(rSaveRing != rG)
     1321  {
     1322    rChangeCurrRing(rG);
     1323    bWeChangeRing = true;
     1324  }
     1325
     1326  assume(rGR->qideal != NULL);
     1327  assume(rG->qideal == NULL);
     1328 
     1329  const ideal idQuotient = rGR->qideal;
     1330
     1331  // check for
     1332  // y_{iAltVarStart}^2, y_{iAltVarStart+1}^2, \ldots, y_{iAltVarEnd}^2  (iAltVarEnd > iAltVarStart)
     1333  // to be within quotient ideal.
     1334
     1335  bool bSCA = true;
     1336
     1337  for ( int i = iAltVarStart; (i <= iAltVarEnd) && bSCA; i++ )
     1338  {
     1339    poly square = p_ISet(1, rSaveRing);
     1340    p_SetExp(square, i, 2, rSaveRing); // square = var(i)^2.
     1341    p_Setm(square, rSaveRing);
     1342
     1343    // square = NF( var(i)^2 | Q )
     1344    // NOTE: rSaveRing == currRing now!
     1345    // NOTE: there is no better way to check this in general!
     1346    square = kNF(idQuotient, NULL, square, 0, 0);
     1347   
     1348    if( square != NULL ) // var(i)^2 is not in Q?
     1349    {
     1350      p_Delete(&square, rSaveRing);
     1351      bSCA = false;     
     1352    }   
     1353  }
     1354 
     1355
     1356  if (bWeChangeRing)
     1357  {
     1358    rChangeCurrRing(rSaveRing);
     1359  }
     1360
     1361  if(!bSCA) return false;
     1362 
     1363
     1364
     1365#ifdef PDEBUG
     1366//  Print("AltVars: [%d, %d]\n", iAltVarStart, iAltVarEnd);
     1367#endif
     1368
     1369
    13701370  //////////////////////////////////////////////////////////////////////////
    1371   // ok... let's setup it!!!
     1371  // ok... here we go. let's setup it!!!
    13721372  //////////////////////////////////////////////////////////////////////////
     1373  ideal tempQ = id_KillSquares(idQuotient, iAltVarStart, iAltVarEnd, rG); // in rG!!!
     1374
     1375  rGR->nc->SCAQuotient() = idrMoveR(tempQ, rG, rGR); // deletes tempQ!
    13731376
    13741377  ncRingType( rGR, nc_exterior );
     
    13771380  scaLastAltVar( rGR, iAltVarEnd );
    13781381
    1379   // ????????????????????????????????????????????????????????????????????????????????
    1380   // check ordering!!! alternating variables must be bigger than all other variables?
    1381 
    1382   SetProcsSCA(rGR, rGR->p_Procs);
    1383 
     1382
     1383
     1384  sca_p_ProcsSet(rGR, rGR->p_Procs);
     1385
     1386 
    13841387  return true;
    13851388}
     
    14181421  assume(rIsSCA(currRing));
    14191422
    1420   BOOLEAN bIdHomog = id_IsYHomogeneous(F, currRing);
     1423  const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
     1424  const unsigned int m_iLastAltVar  = scaLastAltVar(currRing);
     1425
     1426  BOOLEAN bIdHomog = id_IsBiHomogeneous(F, m_iFirstAltVar, m_iLastAltVar, currRing);
     1427
     1428  assume( !bIdHomog || strat->homog ); //  bIdHomog =====[implies]>>>>> strat->homog
    14211429
    14221430  strat->homog = strat->homog && bIdHomog;
     
    14421450//   initHilbCrit(F, Q, &hilb, strat);
    14431451
    1444 //  gr_initBba(F,strat);
     1452//  nc_gr_initBba(F,strat);
    14451453  initBba(F, strat); // set enterS, red, initEcart, initEcartPair
    14461454
     
    14761484  ///////////////////////////////////////////////////////////////
    14771485  // SCA:
    1478   const unsigned short m_iFirstAltVar = scaFirstAltVar(currRing);
    1479   const unsigned short m_iLastAltVar  = scaLastAltVar(currRing);
    1480 
    1481 
    14821486
    14831487  /* compute------------------------------------------------------- */
     
    16431647
    16441648//       if(0)
    1645       for( unsigned short i = m_iFirstAltVar; i <= m_iLastAltVar; i++ )
    1646       if( p_GetExp(pSave, i, currRing) )
     1649      for( unsigned int i = m_iFirstAltVar; i <= m_iLastAltVar; i++ )
     1650      if( p_GetExp(pSave, i, currRing) != 0 )
    16471651      {
     1652        assume(p_GetExp(pSave, i, currRing) == 1);
     1653       
    16481654        const poly pNew = sca_pp_Mult_xi_pp(i, pNext, currRing);
    16491655
     
    17831789
    17841790
    1785 
    1786 // y-Degree
    1787 inline long p_yDegree(const poly p, const ring r)
    1788 {
    1789   assume(rIsSCA(r));
    1790 
    1791   const unsigned short m_iFirstAltVar = scaFirstAltVar(r);
    1792   const unsigned short m_iLastAltVar  = scaLastAltVar(r);
    1793 
    1794   long sum = 0;
    1795 
    1796   for(int i = m_iFirstAltVar; i <= m_iLastAltVar; i++)
    1797     sum += p_GetExp(p, i, r);
    1798 
    1799   return sum;
    1800 }
    1801 
    1802 
    1803 
    1804 
    1805 /**2
    1806  * tests whether p is sca-homogeneous without respect to the actual weigths(=>all ones)
    1807  */
    1808 BOOLEAN p_IsYHomogeneous(const poly p, const ring r)
    1809 {
    1810   assume(rIsSCA(r));
    1811 
    1812   if( p == NULL ) return TRUE;
    1813 
    1814   poly q = p;
    1815 
    1816   const long o = p_yDegree(q, r);
    1817   pIter(q);
    1818 
    1819   while( q != NULL )
    1820   {
    1821     if (p_yDegree(q,r) != o) return FALSE;
    1822     pIter(q);
    1823   }
    1824 
    1825   return TRUE;
    1826 }
    1827 
    1828 
    1829 /*2
    1830 *returns true if id is y-homogenous without respect to the aktual weights(=> all ones)
    1831 */
    1832 BOOLEAN id_IsYHomogeneous(const ideal id, const ring r)
    1833 {
    1834   if (id == NULL) return TRUE;
    1835 
    1836   const int iSize = IDELEMS(id);
    1837 
    1838   if (iSize == 0) return TRUE;
    1839 
    1840   BOOLEAN b = TRUE;
    1841 
    1842   for(int i = iSize - 1; (i >= 0 ) && b; i--)
    1843     b = p_IsYHomogeneous(id->m[i], r);
    1844 
    1845   return b;
    1846 }
    1847 
    18481791// //////////////////////////////////////////////////////////////////////////////
    18491792// sca mora...
     
    18841827ideal sca_mora(const ideal F, const ideal Q, const intvec *w, const intvec *, kStrategy strat)
    18851828{
    1886   BOOLEAN bIdHomog = id_IsYHomogeneous(F, currRing);
     1829  assume(rIsSCA(currRing));
     1830
     1831  const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
     1832  const unsigned int m_iLastAltVar  = scaLastAltVar(currRing);
     1833 
     1834  ideal tempF = id_KillSquares(F, m_iFirstAltVar, m_iLastAltVar, currRing);
     1835 
     1836  const ideal tempQ = currRing->nc->SCAQuotient();
     1837
     1838  BOOLEAN bIdHomog = id_IsBiHomogeneous(tempF, m_iFirstAltVar, m_iLastAltVar, currRing);
     1839
     1840  assume( !bIdHomog || strat->homog ); //  bIdHomog =====[implies]>>>>> strat->homog
    18871841
    18881842  strat->homog = strat->homog && bIdHomog;
     
    18911845  assume( strat->homog == bIdHomog );
    18921846#endif /*PDEBUG*/
    1893 
    18941847
    18951848#ifdef HAVE_ASSUME
     
    18971850  sca_mora_loop_count = 0;
    18981851#endif
     1852
    18991853#ifdef KDEBUG
    19001854  om_Opts.MinTrack = 5;
     
    19111865  initBuchMoraCrit(strat);
    19121866//   initHilbCrit(F,NULL,&hilb,strat); // no Q!
    1913   initMora(F,strat);
     1867  initMora(tempF, strat);
    19141868  initBuchMoraPos(strat);
    1915   /*Shdl=*/initBuchMora(F,NULL,strat); // no Q!
     1869  /*Shdl=*/initBuchMora(tempF, tempQ, strat); // temp Q, F!
    19161870//   if (TEST_OPT_FASTHC) missingAxis(&strat->lastAxis,strat);
    19171871  /*updateS in initBuchMora has Hecketest
     
    19511905#endif
    19521906
    1953 
    1954   // 4SCA:
    1955   const unsigned short m_iFirstAltVar = scaFirstAltVar(currRing);
    1956   const unsigned short m_iLastAltVar  = scaLastAltVar(currRing);
    19571907
    19581908  while (strat->Ll >= 0)
     
    20522002      const poly pNext = pNext(pSave);
    20532003
    2054 //       if(0)
    2055       for( unsigned short i = m_iFirstAltVar; i <= m_iLastAltVar; i++ )
    2056       if( p_GetExp(pSave, i, currRing) )
     2004      if(pNext != NULL)
     2005      for( unsigned int i = m_iFirstAltVar; i <= m_iLastAltVar; i++ )
     2006      if( p_GetExp(pSave, i, currRing) != 0 )
    20572007      {
    20582008
     
    21422092    }
    21432093  }
    2144 //   if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
     2094  if (tempQ!=NULL) updateResult(strat->Shdl,tempQ,strat);
    21452095  idTest(strat->Shdl);
     2096 
     2097  id_Delete( &tempF, currRing);
     2098 
    21462099  return (strat->Shdl);
    21472100}
     
    21522105
    21532106
    2154 void SetProcsSCA(ring& rGR, p_Procs_s* p_Procs)
     2107void sca_p_ProcsSet(ring rGR, p_Procs_s* p_Procs)
    21552108{
    21562109
     
    22142167#endif
    22152168}
    2216 #endif
     2169
     2170
     2171// bi-Degree (x, y) of lm(p)
     2172// Y are ones from iFirstAltVar up to iLastAltVar
     2173inline void p_GetSCADegree(const poly p,
     2174  const unsigned int iFirstAltVar, const unsigned int iLastAltVar,
     2175  long& dx, long& dy, const ring r)
     2176{
     2177  const unsigned int N  = r->N;
     2178
     2179  int i = 1;
     2180 
     2181  dx = 0;
     2182  dy = 0;
     2183 
     2184  for(; i < iFirstAltVar; i++)
     2185    dx += p_GetExp(p, i, r);
     2186
     2187  for(; i <= iLastAltVar; i++)
     2188    dy += p_GetExp(p, i, r);
     2189
     2190  for(; i <= N; i++)
     2191    dx += p_GetExp(p, i, r);
     2192}
     2193
     2194// tests whether p is bi-homogeneous without respect to the actual weigths(=>all ones)
     2195// Polynomial is bi-homogeneous iff all monomials have the same bi-degree (x,y).
     2196// Y are ones from iFirstAltVar up to iLastAltVar
     2197bool p_IsBiHomogeneous(const poly p,
     2198  const unsigned int iFirstAltVar, const unsigned int iLastAltVar,
     2199  const ring r)
     2200{
     2201  if( p == NULL ) return true;
     2202
     2203  poly q = p;
     2204
     2205
     2206  long dx, dy;
     2207
     2208  p_GetSCADegree( q, iFirstAltVar, iLastAltVar, dx, dy, r); // get bi degree of lm(p)
     2209
     2210  pIter(q);
     2211
     2212  for(; q != NULL; pIter(q) )
     2213  {
     2214    long x, y;   
     2215   
     2216    p_GetSCADegree( q, iFirstAltVar, iLastAltVar, x, y, r); // get bi degree of q
     2217   
     2218    if ( (x != dx) || (y != dy) ) return false;
     2219  }
     2220
     2221  return true;
     2222}
     2223
     2224
     2225// returns true if id is bi-homogenous without respect to the aktual weights(=> all ones)
     2226bool id_IsBiHomogeneous(const ideal id,
     2227  const unsigned int iFirstAltVar, const unsigned int iLastAltVar,
     2228  const ring r)
     2229{
     2230  if (id == NULL) return true; // zero ideal
     2231
     2232  const int iSize = IDELEMS(id);
     2233
     2234  if (iSize == 0) return true;
     2235
     2236  bool b = true;
     2237
     2238  for(int i = iSize - 1; (i >= 0 ) && b; i--)
     2239    b = p_IsBiHomogeneous(id->m[i], iFirstAltVar, iLastAltVar, r);
     2240
     2241  return b;
     2242}
     2243
     2244
     2245
     2246
     2247// reduce term lt(m) modulo <y_i^2> , i = iFirstAltVar .. iLastAltVar:
     2248// either create a copy of m or return NULL
     2249inline poly m_KillSquares(const poly m,
     2250  const unsigned int iFirstAltVar, const unsigned int iLastAltVar,
     2251  const ring r)
     2252
     2253#ifdef PDEBUG
     2254  p_Test(m, r);
     2255
     2256#if 0
     2257  Print("m_KillSquares, m = "); // !
     2258  p_Write(m, r);
     2259#endif
     2260#endif
     2261
     2262  assume( m != NULL );
     2263
     2264  for(int k = iFirstAltVar; k <= iLastAltVar; k++)
     2265    if( p_GetExp(m, k, r) > 1 )
     2266      return NULL; 
     2267 
     2268  return p_Head(m, r);
     2269}
     2270
     2271
     2272// reduce polynomial p modulo <y_i^2> , i = iFirstAltVar .. iLastAltVar
     2273poly p_KillSquares(const poly p,
     2274  const unsigned int iFirstAltVar, const unsigned int iLastAltVar,
     2275  const ring r)
     2276
     2277#ifdef PDEBUG
     2278  p_Test(p, r);
     2279
     2280#if 0
     2281  Print("p_KillSquares, p = "); // !
     2282  p_Write(p, r);
     2283#endif
     2284#endif
     2285
     2286
     2287  if( p == NULL )
     2288    return NULL;
     2289
     2290  poly pResult = NULL;
     2291  poly* ppPrev = &pResult;
     2292
     2293  for( poly q = p; q!= NULL; pIter(q) )
     2294  {
     2295#ifdef PDEBUG
     2296    p_Test(q, r);
     2297#endif
     2298
     2299    // terms will be in the same order because of quasi-ordering!   
     2300    poly v = m_KillSquares(q, iFirstAltVar, iLastAltVar, r);
     2301
     2302    if( v != NULL )
     2303    {
     2304      *ppPrev = v;
     2305      ppPrev = &pNext(v);
     2306    }
     2307
     2308  }
     2309
     2310#ifdef PDEBUG
     2311  p_Test(pResult, r);
     2312#if 0
     2313  Print("p_KillSquares => "); // !
     2314  p_Write(pResult, r);
     2315#endif
     2316#endif
     2317
     2318  return(pResult);
     2319}
     2320 
     2321
     2322
     2323
     2324// reduces ideal id modulo <y_i^2> , i = iFirstAltVar .. iLastAltVar
     2325// returns the reduced ideal or zero ideal.
     2326ideal id_KillSquares(const ideal id,
     2327  const unsigned int iFirstAltVar, const unsigned int iLastAltVar,
     2328  const ring r)
     2329{
     2330  if (id == NULL) return id; // zero ideal
     2331
     2332  const int iSize = id->idelems();
     2333
     2334  if (iSize == 0) return id;
     2335 
     2336  ideal temp = idInit(iSize, 1);
     2337 
     2338#if 0
     2339   PrintS("<id_KillSquares>\n");
     2340  {
     2341    Print("ideal id: \n");
     2342    for (int i = 0; i < id->idelems(); i++)
     2343    {
     2344      Print("; id[%d] = ", i+1);
     2345      p_Write(id->m[i], r);
     2346    }
     2347    Print(";\n");
     2348    PrintLn();
     2349  }
     2350#endif
     2351 
     2352
     2353  for (int j = 0; j < iSize; j++)
     2354    temp->m[j] = p_KillSquares(id->m[j], iFirstAltVar, iLastAltVar, r);
     2355
     2356  idSkipZeroes(temp);
     2357
     2358#if 0
     2359   PrintS("<id_KillSquares>\n");
     2360  {
     2361    Print("ideal temp: \n");
     2362    for (int i = 0; i < temp->idelems(); i++)
     2363    {
     2364      Print("; temp[%d] = ", i+1);
     2365      p_Write(temp->m[i], r);
     2366    }
     2367    Print(";\n");
     2368    PrintLn();
     2369  }
     2370   PrintS("</id_KillSquares>\n");
     2371#endif
     2372
     2373  return temp;
     2374}
     2375
     2376
     2377
     2378
     2379#endif
Note: See TracChangeset for help on using the changeset viewer.