Ignore:
Timestamp:
Feb 12, 2013, 6:46:45 PM (11 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
31a08c219875a2199e6c67adcf1eef18ba4a3a4f
Parents:
13a431151fe0f14cbbed84bbf95df65eff7bc567
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2013-02-12 18:46:45+01:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2014-05-07 04:41:47+02:00
Message:
Syzygy preprocessing + more testing/benchmarking

TODO: remote benchmarking output...
File:
1 edited

Legend:

Unmodified
Added
Removed
  • dyn_modules/syzextra/syzextra.cc

    r13a431 r9936d6  
    3030#include <polys/monomials/p_polys.h>
    3131#include <polys/monomials/ring.h>
     32#include <polys/simpleideals.h>
    3233
    3334#include <kernel/kstd1.h>
     
    3637#include <kernel/ideals.h>
    3738
     39#include <kernel/timer.h>
    3840
    3941
     
    152154/// return a new term: leading coeff * leading monomial of p
    153155/// with 0 leading component!
    154 poly leadmonom(const poly p, const ring r)
     156poly leadmonom(const poly p, const ring r, const bool bSetZeroComp)
    155157{
    156158  poly m = NULL;
     
    164166    p_SetCoeff0(m, n_Copy(p_GetCoeff(p, r), r), r);
    165167
    166     p_SetComp(m, 0, r);
     168    if( bSetZeroComp )
     169      p_SetComp(m, 0, r);
    167170    p_Setm(m, r);
    168171
    169     assume( p_GetComp(m, r) == 0 );
     172   
    170173    assume( m != NULL );
    171174    assume( pNext(m) == NULL );
    172175    assume( p_LmTest(m, r) );
     176   
     177    if( bSetZeroComp )
     178      assume( p_GetComp(m, r) == 0 );
    173179  }
    174180
     
    225231void SchreyerSyzygyComputation::CleanUp()
    226232{
     233  extern void id_Delete (ideal*, const ring);
     234   
     235 id_Delete(const_cast<ideal*>(&m_idTails), m_rBaseRing); // TODO!!!   
     236}
    227237  /*
    228238  for( TTailTerms::const_iterator it = m_idTailTerms.begin(); it != m_idTailTerms.end(); it++ )
     
    233243  }
    234244  */
    235 }
    236 
    237 
    238 
    239 void SchreyerSyzygyComputation::SetUpTailTerms(const ideal idTails)
    240 {
     245
     246
     247
     248bool CReducerFinder::PreProcessTerm(const poly t, CReducerFinder& syzChecker) const
     249{
     250   assume( t != NULL );
     251   
     252   if( __DEBUG__ && __TAILREDSYZ__ )
     253     assume( !IsDivisible(t) ); // each input term should NOT be in <L>
     254   
     255   const ring r = m_rBaseRing;
     256
     257   
     258   if( __TAILREDSYZ__ )
     259     if( p_LmIsConstant(t, r) ) // most basic case of baing coprime with L, whatever that is...
     260       return true; // TODO: prove this...?
     261   
     262//   return false; // appears to be fine
     263
     264   const long comp = p_GetComp(t, r);
     265   
     266   CReducersHash::const_iterator itr = m_hash.find(comp);
     267   
     268   if ( itr == m_hash.end() )
     269     return true; // no such leading component!!!
     270   
     271  const bool bIdealCase = (comp == 0);   
     272  const bool bSyzCheck = syzChecker.IsNonempty(); // need to check even in ideal case????? proof?  "&& !bIdealCase"
     273   
     274//   return false;
     275   if( __TAILREDSYZ__ && (bIdealCase || bSyzCheck) )
     276   {
     277   const TReducers& v = itr->second;
     278   const int N = rVar(r);
     279   // TODO: extract exps of t beforehand?!
     280   bool coprime = true;
     281   for(TReducers::const_iterator vit = v.begin(); (vit != v.end()) && coprime; ++vit )
     282   {
     283     assume( m_L->m[(*vit)->m_label] == (*vit)->m_lt );
     284     
     285     const poly p = (*vit)->m_lt;
     286     
     287     assume( p_GetComp(p, r) == comp );
     288     
     289      // TODO: check if coprime with Leads... if __TAILREDSYZ__ !
     290     for( int var = N; var > 0; --var )
     291       if( (p_GetExp(p, var, r) != 0) && (p_GetExp(t, var, r) != 0) )
     292       {             
     293               if( __DEBUG__ || 0)
     294                 {             
     295                    PrintS("CReducerFinder::PreProcessTerm, 't' is NOT co-prime with the following leading term: \n");
     296                    dPrint(p, r, r, 1);
     297                 }
     298               coprime = false; // t not coprime with p!
     299               break;
     300       }
     301     
     302     if( bSyzCheck && coprime )
     303     {
     304        poly ss = p_LmInit(t, r);
     305        p_SetCoeff0(ss, n_Init(1, r), r); // for delete & printout only!...
     306        p_SetComp(ss, (*vit)->m_label + 1, r); // coeff?
     307        p_Setm(ss, r);
     308       
     309        coprime = ( syzChecker.IsDivisible(ss) );
     310
     311        if( __DEBUG__ && !coprime)
     312          {           
     313             PrintS("CReducerFinder::PreProcessTerm, 't' is co-prime with p but may lead to NOT divisible syz.term: \n");
     314             dPrint(ss, r, r, 1);
     315          }
     316       
     317        p_LmDelete(&ss, r); // deletes coeff as well???
     318     }
     319     
     320   }
     321     
     322   if( __DEBUG__ && coprime )
     323     PrintS("CReducerFinder::PreProcessTerm, the following 't' is 'co-prime' with all of leading terms! \n");
     324     
     325   return coprime; // t was coprime with all of leading terms!!!
     326     
     327   }
     328//   return true; // delete the term
     329   
     330   return false;
     331
     332
     333}
     334 
     335   
     336void SchreyerSyzygyComputation::SetUpTailTerms()
     337{
     338  const ideal idTails = m_idTails;
    241339  assume( idTails != NULL );
    242340  assume( idTails->m != NULL );
     341  const ring r = m_rBaseRing;
     342
     343   if( __DEBUG__ || 0)
     344   {
     345     PrintS("SchreyerSyzygyComputation::SetUpTailTerms(): Tails: \n");
     346     dPrint(idTails, r, r, 0);
     347   }
     348   
     349  unsigned long pp = 0; // count preprocessed terms...
     350
     351  for( int p = IDELEMS(idTails) - 1; p >= 0; --p )
     352    for( poly* tt = &(idTails->m[p]); (*tt) != NULL;  )
     353       {   
     354          const poly t = *tt;
     355       if( m_div.PreProcessTerm(t, m_checker) )
     356       {
     357          if( __DEBUG__ || 0)
     358          {           
     359            PrintS("SchreyerSyzygyComputation::SetUpTailTerms(): PP the following TT: \n");
     360            dPrint(t, r, r, 1);
     361          }
     362          ++pp;
     363           
     364         (*tt) = p_LmDeleteAndNext(t, r); // delete the lead and next...
     365       }   
     366       else
     367         tt = &pNext(t); // go next?
     368 
     369       }
     370
     371   if( TEST_OPT_PROT || 1)
     372     Print("**!!** SchreyerSyzygyComputation::SetUpTailTerms()::PreProcessing has eliminated %u terms!\n", pp);
     373   
     374
     375   if( __DEBUG__ || 0)
     376   {
     377     PrintS("SchreyerSyzygyComputation::SetUpTailTerms(): Preprocessed Tails: \n");
     378     dPrint(idTails, r, r, 0);
     379   }
     380}
    243381/* 
    244382  m_idTailTerms.resize( IDELEMS(idTails) );
     
    265403  }
    266404*/
    267 }
    268405
    269406
     
    568705
    569706
    570 
    571707void SchreyerSyzygyComputation::ComputeSyzygy()
    572708{
     
    581717
    582718  assume( IDELEMS(L) == IDELEMS(T) );
     719  int t, r;
    583720
    584721  if( m_syzLeads == NULL )
     722  {   
     723    if( TEST_OPT_PROT && 1)
     724    {
     725/*       initTimer();
     726       initRTimer();
     727       startTimer();
     728       startRTimer();*/
     729   
     730      t = getTimer();
     731      r = getRTimer();
     732      Print("%d **!TIME4!** SchreyerSyzygyComputation::ComputeSyzygy::ComputeLeadingSyzygyTerms: t: %d, r: %d\n", getRTimer(), t, r);
     733    }
     734     
    585735    ComputeLeadingSyzygyTerms( __LEAD2SYZ__ && !__IGNORETAILS__ ); // 2 terms OR 1 term!
     736    if( TEST_OPT_PROT && 1)
     737    {
     738      t = getTimer() - t;
     739      r = getRTimer() - r;
     740         
     741      Print("%d **!TIME4!** SchreyerSyzygyComputation::ComputeSyzygy::ComputeLeadingSyzygyTerms: t: %d, r: %d\n", getRTimer(), t, r);
     742    }
     743     
     744  }
     745     
    586746
    587747  assume( m_syzLeads != NULL );
     
    596756  if( size == 1 && LL->m[0] == NULL )
    597757    return;
    598 
     758   
     759  if(  !__IGNORETAILS__)
     760  {
     761    if( T != NULL )
     762    {
     763
     764       if( TEST_OPT_PROT && 1 )
     765         {
     766//       initTimer();
     767//       initRTimer();
     768//       startTimer();
     769//       startRTimer(); 
     770   
     771            t = getTimer();
     772            r = getRTimer();
     773          Print("%d **!TIME4!** SchreyerSyzygyComputation::ComputeSyzygy::SetUpTailTerms(): t: %d, r: %d\n", getRTimer(), t, r);
     774         }
     775
     776       SetUpTailTerms();
     777       
     778       if( TEST_OPT_PROT && 1)
     779       {
     780          t = getTimer() - t;
     781          r = getRTimer()  - r;
     782         
     783          Print("%d **!TIME4!** SchreyerSyzygyComputation::ComputeSyzygy::SetUpTailTerms(): t: %d, r: %d\n", getRTimer(), t, r);
     784       }
     785       
     786 
     787
     788    }     
     789  }
     790
     791       if( TEST_OPT_PROT && 1)
     792         {
     793//       initTimer();
     794//       initRTimer();
     795//       startTimer();
     796//       startRTimer(); 
     797   
     798            t = getTimer();
     799            r = getRTimer();
     800          Print("%d **!TIME4!** SchreyerSyzygyComputation::ComputeSyzygy::SyzygyLift: t: %d, r: %d\n", getRTimer(), t, r);
     801         }
    599802
    600803  for( int k = size - 1; k >= 0; k-- )
     
    631834
    632835  }
    633 
    634   TT->rank = id_RankFreeModule(TT, R);
     836   
     837       if( TEST_OPT_PROT && 1)
     838       {
     839          t = getTimer() - t;
     840          r = getRTimer();  - r;
     841         
     842          Print("%d **!TIME4!** SchreyerSyzygyComputation::ComputeSyzygy::SyzygyLift: t: %d, r: %d\n", getRTimer(), t, r);
     843       }
     844
     845   
     846
     847  TT->rank = id_RankFreeModule(TT, R); 
    635848}
    636849
     
    772985  assume( tail >= 0 && tail < IDELEMS(m_idTails) );
    773986
    774   const poly t = m_idTails->m[tail];
     987  const poly t = m_idTails->m[tail]; // !!!
    775988
    776989  if(t != NULL)
     
    13351548    poly lm = p_Mult_mm(leadmonom(syzterm, r), m, r);
    13361549
    1337     poly pr = p_Mult_q( p_LmInit(multiplier, r), p_LmInit(t, r), r);
     1550    poly pr = p_Mult_q( leadmonom(multiplier, r, false), leadmonom(t, r, false), r);
    13381551   
    13391552    assume( p_EqualPolys(lm, pr, r) );
     
    13941607    return q;
    13951608  }
    1396 
    1397   p_LmFree(q, r);
    1398 
    1399   return NULL;
    1400 
    1401    
    1402  
    1403    
    1404    
    1405 #if 0
     1609   
     1610/*
    14061611  const long comp = p_GetComp(t, r); assume( comp >= 0 );
    14071612  const unsigned long not_sev = ~p_GetShortExpVector(multiplier, t, r); // !
     
    14841689    return q;
    14851690  }
     1691*/
    14861692
    14871693  p_LmFree(q, r);
    14881694
    14891695  return NULL;
    1490 #endif
     1696 
    14911697}
    14921698
     
    14941700poly CReducerFinder::FindReducer(const poly product, const poly syzterm, const CReducerFinder& syz_checker) const
    14951701{
     1702  CDivisorEnumerator itr(*this, product);
     1703  if( !itr.Reset() )
     1704    return NULL;
     1705
     1706
    14961707  const ring& r = m_rBaseRing;
    14971708
     
    15221733  }
    15231734
    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;
    15471735
    15481736  const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ &&
     
    15521740  if( __DEBUG__ )
    15531741    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 
     1742
     1743  while( itr.MoveNext() )
     1744  {
     1745    const poly p = itr.Current().m_lt;
     1746    const int k  = itr.Current().m_label;
     1747     
    15761748    p_ExpVectorDiff(q, product, p, r); // (LM(product) / LM(L[k]))
    15771749    p_SetComp(q, k + 1, r);
     
    15981770        PrintS("_FindReducer::Test LS: q is divisible by LS[?] !:((: ");
    15991771      }
     1772
     1773      continue;
     1774    }
     1775
     1776    p_SetCoeff0(q, n_Neg( n_Div( p_GetCoeff(product, r), p_GetCoeff(p, r), r), r), r);
     1777   
     1778    return q;
     1779  }
     1780   
     1781   
     1782   
     1783/*   
     1784  const long comp = p_GetComp(product, r);
     1785  const unsigned long not_sev = ~p_GetShortExpVector(product, r);
     1786
     1787  assume( comp >= 0 );
     1788
     1789//   for( int k = IDELEMS(L)-1; k>= 0; k-- )
     1790//   {
     1791//     const poly p = L->m[k];
     1792//
     1793//     if ( p_GetComp(p, r) != comp )
     1794//       continue;
     1795//
     1796//     const unsigned long p_sev = p_GetShortExpVector(p, r); // to be stored in m_hash!!!
     1797 
     1798   // looking for an appropriate diviser p = L[k]...
     1799  CReducersHash::const_iterator it = m_hash.find(comp); // same module component
     1800
     1801  if( it == m_hash.end() )
     1802    return NULL;
     1803
     1804  assume( m_L != NULL );
     1805
     1806  const TReducers& reducers = it->second;
     1807
     1808  const BOOLEAN to_check = (syz_checker.IsNonempty()); // __TAILREDSYZ__ &&
     1809
     1810  const poly q = p_New(r); pNext(q) = NULL;
     1811
     1812  if( __DEBUG__ )
     1813    p_SetCoeff0(q, 0, r); // for printing q
     1814 
     1815  for(TReducers::const_iterator vit = reducers.begin(); vit != reducers.end(); vit++ )
     1816  {
     1817    const poly p = (*vit)->m_lt;
     1818
     1819    assume( p_GetComp(p, r) == comp );
     1820
     1821    const int k = (*vit)->m_label;
     1822
     1823    assume( L->m[k] == p );
     1824
     1825    const unsigned long p_sev = (*vit)->m_sev;
     1826
     1827    assume( p_sev == p_GetShortExpVector(p, r) );     
     1828
     1829    if( !p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r) )
     1830      continue;     
     1831
     1832//     // ... which divides the product, looking for the _1st_ appropriate one!
     1833//     if( !p_LmDivisibleByNoComp(p, product, r) ) // included inside  p_LmShortDivisibleBy!
     1834//       continue;
     1835
     1836    p_ExpVectorDiff(q, product, p, r); // (LM(product) / LM(L[k]))
     1837    p_SetComp(q, k + 1, r);
     1838    p_Setm(q, r);
     1839
     1840    // cannot allow something like: a*gen(i) - a*gen(i)
     1841    if (syzterm != NULL && (k == c))
     1842      if (p_ExpVectorEqual(syzterm, q, r))
     1843      {
     1844        if( __DEBUG__ )
     1845        {
     1846          Print("_FindReducer::Test SYZTERM: q == syzterm !:((, syzterm is: ");
     1847          dPrint(syzterm, r, r, 1);
     1848        }   
     1849
     1850        continue;
     1851      }
     1852
     1853    // while the complement (the fraction) is not reducible by leading syzygies
     1854    if( to_check && syz_checker.IsDivisible(q) )
     1855    {
     1856      if( __DEBUG__ )
     1857      {
     1858        PrintS("_FindReducer::Test LS: q is divisible by LS[?] !:((: ");
     1859      }
    16001860     
    16011861      continue;
     
    16051865    return q;
    16061866  }
     1867*/
    16071868
    16081869  p_LmFree(q, r);
Note: See TracChangeset for help on using the changeset viewer.