Changeset 6bfd78 in git


Ignore:
Timestamp:
Feb 12, 2013, 6:33:16 PM (10 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
Children:
13a431151fe0f14cbbed84bbf95df65eff7bc567
Parents:
1a4c34381788487464977b182596acb57f904d2f
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2013-02-12 18:33:16+01:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2014-05-07 04:41:47+02:00
Message:
Added CDivisorEnumerator(2) - to be used by CReducerFinder

add: FindReducer + multiplier!
Location:
dyn_modules/syzextra
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • dyn_modules/syzextra/syzextra.cc

    r1a4c343 r6bfd78  
    10191019
    10201020  assume( p_GetComp(p, r) == p_GetComp(t, r) );
    1021   assume( p_GetComp(m, r) == 0 );
     1021// assume( p_GetComp(m, r) == 0 );
    10221022
    10231023//  const int k = m_label;
     
    10361036}
    10371037
     1038
     1039
     1040/// TODO:
     1041class CDivisorEnumerator: public SchreyerSyzygyComputationFlags
     1042{
     1043  private:
     1044    const CReducerFinder& m_reds;
     1045    const poly m_product;
     1046    const unsigned long m_not_sev;
     1047    const unsigned long m_comp;
     1048
     1049    CReducerFinder::CReducersHash::const_iterator m_itr;
     1050    CReducerFinder::TReducers::const_iterator m_current, m_finish;
     1051
     1052    bool m_active;
     1053
     1054  public:
     1055    CDivisorEnumerator(const CReducerFinder& self, const poly product):
     1056        SchreyerSyzygyComputationFlags(self),
     1057        m_reds(self),
     1058        m_product(product),
     1059        m_not_sev(~p_GetShortExpVector(product, m_rBaseRing)),
     1060        m_comp(p_GetComp(product, m_rBaseRing)),
     1061        m_itr(), m_current(), m_finish(),
     1062        m_active(false)
     1063    {
     1064      assume( m_comp >= 0 );
     1065      assume( m_reds.m_L != NULL ); 
     1066    }
     1067
     1068    inline bool Reset()
     1069    {
     1070      m_active = false;
     1071     
     1072      m_itr = m_reds.m_hash.find(m_comp);
     1073
     1074      if( m_itr == m_reds.m_hash.end() )
     1075        return false;
     1076
     1077      assume( m_itr->first == m_comp );
     1078
     1079      m_current = (m_itr->second).begin();
     1080      m_finish = (m_itr->second).end();
     1081
     1082      if (m_current == m_finish)
     1083        return false;
     1084
     1085//      m_active = true;
     1086      return true;     
     1087    }
     1088
     1089    const CLeadingTerm& Current() const
     1090    {
     1091      assume( m_active );
     1092      assume( m_current != m_finish );
     1093
     1094      return *(*m_current);
     1095    }
     1096 
     1097    inline bool MoveNext()
     1098    {
     1099      assume( m_current != m_finish );
     1100
     1101      if( m_active )
     1102        ++m_current;
     1103      else
     1104        m_active = true; // for Current()
     1105     
     1106      // looking for the next good entry
     1107      for( ; m_current != m_finish; ++m_current )
     1108      {
     1109        assume( m_reds.m_L->m[Current().m_label] == Current().m_lt );
     1110
     1111        if( Current().DivisibilityCheck(m_product, m_not_sev, m_rBaseRing) )
     1112        {
     1113          if( __DEBUG__ )
     1114          {
     1115            Print("CDivisorEnumerator::MoveNext::est LS: q is divisible by LS[%d] !:((, diviser is: ", 1 + Current().m_label);
     1116            dPrint(Current().m_lt, m_rBaseRing, m_rBaseRing, 1);
     1117          }
     1118
     1119//          m_active = true;
     1120          return true;
     1121        }
     1122      }
     1123
     1124      // the end... :(
     1125      assume( m_current == m_finish );
     1126     
     1127      m_active = false;
     1128      return false;
     1129    }
     1130};
     1131
     1132
     1133
    10381134bool CReducerFinder::IsDivisible(const poly product) const
    10391135{
     1136  CDivisorEnumerator itr(*this, product);
     1137  if( !itr.Reset() )
     1138    return false;
     1139
     1140  return itr.MoveNext();
     1141 
     1142/* 
    10401143  const ring& r = m_rBaseRing;
    10411144 
     
    10471150  CReducersHash::const_iterator it = m_hash.find(comp); // same module component
    10481151
     1152  assume( m_L != NULL ); 
     1153
    10491154  if( it == m_hash.end() )
    10501155    return false;
    1051 
    1052   assume( m_L != NULL ); 
    10531156
    10541157  const TReducers& reducers = it->second;
     
    10711174
    10721175  return false;
     1176*/ 
    10731177}
    10741178
     
    11041208#endif
    11051209
     1210/// TODO:
     1211class CDivisorEnumerator2: public SchreyerSyzygyComputationFlags
     1212{
     1213  private:
     1214    const CReducerFinder& m_reds;
     1215    const poly m_multiplier, m_term;
     1216    const unsigned long m_not_sev;
     1217    const unsigned long m_comp;
     1218
     1219    CReducerFinder::CReducersHash::const_iterator m_itr;
     1220    CReducerFinder::TReducers::const_iterator m_current, m_finish;
     1221
     1222    bool m_active;
     1223
     1224  public:
     1225    CDivisorEnumerator2(const CReducerFinder& self, const poly m, const poly t):
     1226        SchreyerSyzygyComputationFlags(self),
     1227        m_reds(self),
     1228        m_multiplier(m), m_term(t),
     1229        m_not_sev(~p_GetShortExpVector(m, t, m_rBaseRing)),
     1230        m_comp(p_GetComp(t, m_rBaseRing)),
     1231        m_itr(), m_current(), m_finish(),
     1232        m_active(false)
     1233    {
     1234      assume( m_comp >= 0 );
     1235      assume( m_reds.m_L != NULL ); 
     1236      assume( m_multiplier != NULL );
     1237      assume( m_term != NULL );
     1238//      assume( p_GetComp(m_multiplier, m_rBaseRing) == 0 );
     1239    }
     1240
     1241    inline bool Reset()
     1242    {
     1243      m_active = false;
     1244     
     1245      m_itr = m_reds.m_hash.find(m_comp);
     1246
     1247      if( m_itr == m_reds.m_hash.end() )
     1248        return false;
     1249
     1250      assume( m_itr->first == m_comp );
     1251
     1252      m_current = (m_itr->second).begin();
     1253      m_finish = (m_itr->second).end();
     1254
     1255      if (m_current == m_finish)
     1256        return false;
     1257
     1258      return true;     
     1259    }
     1260
     1261    const CLeadingTerm& Current() const
     1262    {
     1263      assume( m_active );
     1264      assume( m_current != m_finish );
     1265
     1266      return *(*m_current);
     1267    }
     1268 
     1269    inline bool MoveNext()
     1270    {
     1271      assume( m_current != m_finish );
     1272
     1273      if( m_active )
     1274        ++m_current;
     1275      else
     1276        m_active = true;
     1277         
     1278     
     1279      // looking for the next good entry
     1280      for( ; m_current != m_finish; ++m_current )
     1281      {
     1282        assume( m_reds.m_L->m[Current().m_label] == Current().m_lt );
     1283
     1284        if( Current().DivisibilityCheck(m_multiplier, m_term, m_not_sev, m_rBaseRing) )
     1285        {
     1286          if( __DEBUG__ )
     1287          {
     1288            Print("CDivisorEnumerator::MoveNext::est LS: q is divisible by LS[%d] !:((, diviser is: ", 1 + Current().m_label);
     1289            dPrint(Current().m_lt, m_rBaseRing, m_rBaseRing, 1);
     1290          }
     1291
     1292//          m_active = true;
     1293          return true;
     1294         
     1295        }
     1296      }
     1297
     1298      // the end... :(
     1299      assume( m_current == m_finish );
     1300     
     1301      m_active = false;
     1302      return false;
     1303    }
     1304};
     1305   
    11061306poly CReducerFinder::FindReducer(const poly multiplier, const poly t,
    1107                                  const poly syzterm, const CReducerFinder& syz_checker) const
    1108 {
    1109   // don't case about the module component of multiplier (as it may be
    1110   // the syzygy term)
     1307                                 const poly syzterm,
     1308                                 const CReducerFinder& syz_checker) const
     1309{
     1310  CDivisorEnumerator2 itr(*this, multiplier, t);
     1311  if( !itr.Reset() )
     1312    return NULL;
     1313
     1314  // don't care about the module component of multiplier (as it may be the syzygy term)
    11111315  // product = multiplier * t?
    11121316  const ring& r = m_rBaseRing;
     
    11411345    p_Delete(&pr, r);   
    11421346  }
    1143 
    1144   const long comp = p_GetComp(t, r);
    1145  
    1146   const unsigned long not_sev = ~p_GetShortExpVector(multiplier, t, r); // !
    1147 
    1148   assume( comp >= 0 );
    1149 
    1150 //   for( int k = IDELEMS(L)-1; k>= 0; k-- )
    1151 //   {
    1152 //     const poly p = L->m[k];
    1153 //
    1154 //     if ( p_GetComp(p, r) != comp )
    1155 //       continue;
    1156 //
    1157 //     const unsigned long p_sev = p_GetShortExpVector(p, r); // to be stored in m_hash!!!
    1158 
    1159    // looking for an appropriate diviser p = L[k]...
    1160   CReducersHash::const_iterator it = m_hash.find(comp); // same module component
    1161 
    1162   if( it == m_hash.end() )
    1163     return NULL;
    1164 
    1165   assume( m_L != NULL );
    1166 
    1167   const TReducers& reducers = it->second;
    1168 
     1347   
    11691348  const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ &&
    11701349
     
    11741353    p_SetCoeff0(q, 0, r); // for printing q
    11751354
    1176   for(TReducers::const_iterator vit = reducers.begin(); vit != reducers.end(); vit++ )
    1177   {
    1178 
    1179     const poly p = (*vit)->m_lt;
    1180     const int k = (*vit)->m_label;
    1181 
    1182     assume( L->m[k] == p );
    1183 
    1184 //    const unsigned long p_sev = (*vit)->m_sev;
    1185 //    assume( p_sev == p_GetShortExpVector(p, r) );     
    1186 
    1187 //    if( !p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r) )
    1188 //      continue;     
    1189 
    1190     if( !(*vit)->DivisibilityCheck(multiplier, t, not_sev, r) )
    1191       continue;
    1192    
    1193    
    1194 //    if (p_sev & not_sev) continue;
    1195 //    if( !_p_LmDivisibleByNoComp(p, multiplier, t, r) ) continue;     
    1196 
    1197 
    1198     p_ExpVectorSum(q, multiplier, t, r); // q == product == multiplier * t       
     1355  while( itr.MoveNext() )
     1356  {
     1357    const poly p = itr.Current().m_lt;
     1358    const int k  = itr.Current().m_label;
     1359     
     1360    p_ExpVectorSum(q, multiplier, t, r); // q == product == multiplier * t // TODO: do it once?
    11991361    p_ExpVectorDiff(q, q, p, r); // (LM(product) / LM(L[k]))
    12001362   
     
    12361398
    12371399  return NULL;
    1238 }
    1239 
    1240 
    1241 poly CReducerFinder::FindReducer(const poly product, const poly syzterm, const CReducerFinder& syz_checker) const
    1242 {
    1243   const ring& r = m_rBaseRing;
    1244 
    1245   assume( product != NULL );
    1246 
    1247   const ideal& L = m_L; assume( L != NULL ); // for debug/testing only!
    1248 
    1249   long c = 0;
    1250 
    1251   if (syzterm != NULL)
    1252     c = p_GetComp(syzterm, r) - 1;
    1253 
    1254   assume( c >= 0 && c < IDELEMS(L) );
    1255 
    1256   if (__DEBUG__ && (syzterm != NULL))
    1257   {
    1258     const poly m = L->m[c];
    1259 
    1260     assume( m != NULL ); assume( pNext(m) == NULL );
    1261 
    1262     poly lm = p_Mult_mm(leadmonom(syzterm, r), m, r);
    1263     assume( p_EqualPolys(lm, product, r) );
    1264 
    1265     //  def @@c = leadcomp(syzterm); int @@r = int(@@c);
    1266     //  def @@product = leadmonomial(syzterm) * L[@@r];
    1267 
    1268     p_Delete(&lm, r);   
    1269   }
    1270 
    1271   const long comp = p_GetComp(product, r);
    1272   const unsigned long not_sev = ~p_GetShortExpVector(product, r);
    1273 
    1274   assume( comp >= 0 );
     1400
     1401   
     1402 
     1403   
     1404   
     1405#if 0
     1406  const long comp = p_GetComp(t, r); assume( comp >= 0 );
     1407  const unsigned long not_sev = ~p_GetShortExpVector(multiplier, t, r); // !
    12751408
    12761409//   for( int k = IDELEMS(L)-1; k>= 0; k-- )
     
    12821415//
    12831416//     const unsigned long p_sev = p_GetShortExpVector(p, r); // to be stored in m_hash!!!
    1284  
     1417
    12851418   // looking for an appropriate diviser p = L[k]...
    12861419  CReducersHash::const_iterator it = m_hash.find(comp); // same module component
     
    12931426  const TReducers& reducers = it->second;
    12941427
    1295   const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ &&
    1296 
    1297   const poly q = p_New(r); pNext(q) = NULL;
    1298 
    1299   if( __DEBUG__ )
    1300     p_SetCoeff0(q, 0, r); // for printing q
    1301  
    13021428  for(TReducers::const_iterator vit = reducers.begin(); vit != reducers.end(); vit++ )
    13031429  {
     1430
    13041431    const poly p = (*vit)->m_lt;
    1305 
    1306     assume( p_GetComp(p, r) == comp );
    1307 
    13081432    const int k = (*vit)->m_label;
    13091433
    13101434    assume( L->m[k] == p );
    13111435
    1312     const unsigned long p_sev = (*vit)->m_sev;
    1313 
    1314     assume( p_sev == p_GetShortExpVector(p, r) );     
    1315 
    1316     if( !p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r) )
    1317       continue;     
    1318 
    1319 //     // ... which divides the product, looking for the _1st_ appropriate one!
    1320 //     if( !p_LmDivisibleByNoComp(p, product, r) ) // included inside  p_LmShortDivisibleBy!
    1321 //       continue;
    1322 
    1323     p_ExpVectorDiff(q, product, p, r); // (LM(product) / LM(L[k]))
     1436//    const unsigned long p_sev = (*vit)->m_sev;
     1437//    assume( p_sev == p_GetShortExpVector(p, r) );     
     1438
     1439//    if( !p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r) )
     1440//      continue;     
     1441
     1442    if( !(*vit)->DivisibilityCheck(multiplier, t, not_sev, r) )
     1443      continue;
     1444   
     1445   
     1446//    if (p_sev & not_sev) continue;
     1447//    if( !_p_LmDivisibleByNoComp(p, multiplier, t, r) ) continue;     
     1448
     1449
     1450    p_ExpVectorSum(q, multiplier, t, r); // q == product == multiplier * t       
     1451    p_ExpVectorDiff(q, q, p, r); // (LM(product) / LM(L[k]))
     1452   
    13241453    p_SetComp(q, k + 1, r);
    13251454    p_Setm(q, r);
     
    13451474        PrintS("_FindReducer::Test LS: q is divisible by LS[?] !:((: ");
    13461475      }
     1476
     1477      continue;
     1478    }
     1479
     1480    number n = n_Mult( p_GetCoeff(multiplier, r), p_GetCoeff(t, r), r);
     1481    p_SetCoeff0(q, n_Neg( n_Div(n, p_GetCoeff(p, r), r), r), r);
     1482    n_Delete(&n, r);
     1483   
     1484    return q;
     1485  }
     1486
     1487  p_LmFree(q, r);
     1488
     1489  return NULL;
     1490#endif
     1491}
     1492
     1493
     1494poly CReducerFinder::FindReducer(const poly product, const poly syzterm, const CReducerFinder& syz_checker) const
     1495{
     1496  const ring& r = m_rBaseRing;
     1497
     1498  assume( product != NULL );
     1499
     1500  const ideal& L = m_L; assume( L != NULL ); // for debug/testing only!
     1501
     1502  long c = 0;
     1503
     1504  if (syzterm != NULL)
     1505    c = p_GetComp(syzterm, r) - 1;
     1506
     1507  assume( c >= 0 && c < IDELEMS(L) );
     1508
     1509  if (__DEBUG__ && (syzterm != NULL))
     1510  {
     1511    const poly m = L->m[c];
     1512
     1513    assume( m != NULL ); assume( pNext(m) == NULL );
     1514
     1515    poly lm = p_Mult_mm(leadmonom(syzterm, r), m, r);
     1516    assume( p_EqualPolys(lm, product, r) );
     1517
     1518    //  def @@c = leadcomp(syzterm); int @@r = int(@@c);
     1519    //  def @@product = leadmonomial(syzterm) * L[@@r];
     1520
     1521    p_Delete(&lm, r);   
     1522  }
     1523
     1524  const long comp = p_GetComp(product, r);
     1525  const unsigned long not_sev = ~p_GetShortExpVector(product, r);
     1526
     1527  assume( comp >= 0 );
     1528
     1529//   for( int k = IDELEMS(L)-1; k>= 0; k-- )
     1530//   {
     1531//     const poly p = L->m[k];
     1532//
     1533//     if ( p_GetComp(p, r) != comp )
     1534//       continue;
     1535//
     1536//     const unsigned long p_sev = p_GetShortExpVector(p, r); // to be stored in m_hash!!!
     1537 
     1538   // looking for an appropriate diviser p = L[k]...
     1539  CReducersHash::const_iterator it = m_hash.find(comp); // same module component
     1540
     1541  if( it == m_hash.end() )
     1542    return NULL;
     1543
     1544  assume( m_L != NULL );
     1545
     1546  const TReducers& reducers = it->second;
     1547
     1548  const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ &&
     1549
     1550  const poly q = p_New(r); pNext(q) = NULL;
     1551
     1552  if( __DEBUG__ )
     1553    p_SetCoeff0(q, 0, r); // for printing q
     1554 
     1555  for(TReducers::const_iterator vit = reducers.begin(); vit != reducers.end(); vit++ )
     1556  {
     1557    const poly p = (*vit)->m_lt;
     1558
     1559    assume( p_GetComp(p, r) == comp );
     1560
     1561    const int k = (*vit)->m_label;
     1562
     1563    assume( L->m[k] == p );
     1564
     1565    const unsigned long p_sev = (*vit)->m_sev;
     1566
     1567    assume( p_sev == p_GetShortExpVector(p, r) );     
     1568
     1569    if( !p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r) )
     1570      continue;     
     1571
     1572//     // ... which divides the product, looking for the _1st_ appropriate one!
     1573//     if( !p_LmDivisibleByNoComp(p, product, r) ) // included inside  p_LmShortDivisibleBy!
     1574//       continue;
     1575
     1576    p_ExpVectorDiff(q, product, p, r); // (LM(product) / LM(L[k]))
     1577    p_SetComp(q, k + 1, r);
     1578    p_Setm(q, r);
     1579
     1580    // cannot allow something like: a*gen(i) - a*gen(i)
     1581    if (syzterm != NULL && (k == c))
     1582      if (p_ExpVectorEqual(syzterm, q, r))
     1583      {
     1584        if( __DEBUG__ )
     1585        {
     1586          Print("_FindReducer::Test SYZTERM: q == syzterm !:((, syzterm is: ");
     1587          dPrint(syzterm, r, r, 1);
     1588        }   
     1589
     1590        continue;
     1591      }
     1592
     1593    // while the complement (the fraction) is not reducible by leading syzygies
     1594    if( to_check && syz_checker.IsDivisible(q) )
     1595    {
     1596      if( __DEBUG__ )
     1597      {
     1598        PrintS("_FindReducer::Test LS: q is divisible by LS[?] !:((: ");
     1599      }
    13471600     
    13481601      continue;
  • dyn_modules/syzextra/syzextra.h

    r1a4c343 r6bfd78  
    139139class CReducerFinder: public SchreyerSyzygyComputationFlags
    140140{
     141  friend class CDivisorEnumerator;
     142  friend class CDivisorEnumerator2;
    141143  private:
    142144    typedef long TComponentKey;
     
    144146    typedef std::map< TComponentKey, TReducers> CReducersHash;
    145147
    146 /*
    147     /// TODO:
    148     class const_iterator: public TReducers::const_iterator
    149     {
    150       typedef TReducers::const_iterator TBase;
    151       private:
    152 //        const TReducers& m_reds;
    153         const TBase m_the_end;
    154 
    155         const_iterator(TBase start, TBase end):
    156             TBase(start), m_the_end(end)
    157         { find_proper(); }
    158                    
    159       public:       
    160         inline bool at_end() const { return m_the_end == (*this); }
    161 
    162         inline const_iterator& operator++()
    163         {
    164           find_next();
    165           return *this;
    166         }
    167        
    168         inline const_iterator operator++(int)
    169         {
    170           const_iterator tmp(*this);
    171           find_next();
    172           return tmp;
    173         }
    174 
    175       protected:
    176         bool is_proper() const; // difficult - needs all of CReducerFinder internals!?
    177        
    178         inline void find_next()
    179         {
    180           while (!at_end())
    181           {
    182             static_cast<TBase*>(this)->operator++();
    183             if( is_proper() ) break;
    184           }
    185         }
    186     };
    187 */
    188    
    189148  public:
    190149    /// goes over all leading terms
Note: See TracChangeset for help on using the changeset viewer.