Changeset 495328 in git


Ignore:
Timestamp:
Aug 2, 2012, 8:11:43 PM (10 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '96ce329119711a2b80858c8365abd29f8460bbfa')
Children:
5cecde90d96d1acc0cbd216cf0037bd2db293c31
Parents:
dd24e5dded66979eda13e955b93fc284cbb341e7
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-08-02 20:11:43+02:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2014-05-07 04:41:46+02:00
Message:
made all classes inherit from SchreyerSyzygyComputationFlags

chg: moved the base ring into attributes (no need in extra ring argument)
chg: removed __SYZCHECK__ (only relevant for schreyer.lib)
Location:
dyn_modules/syzextra
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • dyn_modules/syzextra/mod_main.cc

    rdd24e5 r495328  
    517517//  const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    518518
    519   const ring r = currRing;
     519  const ring r = attributes.m_rBaseRing;
    520520  NoReturn(res);
    521521
     
    544544    h = h->Next(); assume (h == NULL);
    545545
    546     const ideal newid = ComputeLeadingSyzygyTerms(id, r, attributes);
     546    const ideal newid = ComputeLeadingSyzygyTerms(id, attributes);
    547547   
    548548    res->data = newid; res->rtyp = MODUL_CMD;
     
    569569  NoReturn(res);
    570570
    571   const ring r = currRing;
     571  const ring r = attributes.m_rBaseRing;
    572572  NoReturn(res);
    573573
     
    629629//  const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    630630
    631   const ring r = currRing;
     631  const ring r = attributes.m_rBaseRing;
    632632  NoReturn(res);
    633633
     
    656656    h = h->Next(); assume (h == NULL);
    657657
    658     res->data = Compute2LeadingSyzygyTerms(id, r, attributes);
     658    res->data = Compute2LeadingSyzygyTerms(id, attributes);
    659659    res->rtyp = MODUL_CMD;
    660660
     
    680680
    681681  const char* usage = "`FindReducer(<poly/vector>, <vector/0>, <ideal/module>[,<module>])` expected";
    682   const ring r = currRing;
     682  const ring r = attributes.m_rBaseRing;
    683683
    684684  NoReturn(res);
     
    750750
    751751  res->rtyp = VECTOR_CMD;
    752   res->data = FindReducer(product, syzterm, L, LS, r, attributes);
     752  res->data = FindReducer(product, syzterm, L, LS, attributes);
    753753
    754754  if( __DEBUG__ )
     
    774774
    775775  const char* usage = "`SchreyerSyzygyNF(<vector>, <vector>, <ideal/module>, <ideal/module>[,<module>])` expected";
    776   const ring r = currRing;
     776  const ring r = attributes.m_rBaseRing;
    777777
    778778  NoReturn(res);
     
    852852 
    853853  res->rtyp = VECTOR_CMD;
    854   res->data = SchreyerSyzygyNF(syz_lead, syz_2, L, T, LS, r, attributes);
     854  res->data = SchreyerSyzygyNF(syz_lead, syz_2, L, T, LS, attributes);
    855855
    856856  if( __DEBUG__ )
     
    873873
    874874  const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    875   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
     875//  const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
    876876//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
    877877//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
     
    879879
    880880  const char* usage = "`ReduceTerm(<poly>, <poly/vector>, <vector/0>, <ideal/module>, <ideal/module>[,<module>])` expected";
    881   const ring r = currRing;
     881  const ring r = attributes.m_rBaseRing;
    882882
    883883  NoReturn(res);
     
    970970
    971971
    972   if (__SYZCHECK__ && syztermCheck != NULL)
     972  if (__DEBUG__ && syztermCheck != NULL)
    973973  {
    974974    const int c = p_GetComp(syztermCheck, r) - 1;
     
    992992
    993993  res->rtyp = VECTOR_CMD;
    994   res->data = ReduceTerm(multiplier, term4reduction, syztermCheck, L, T, LS, r, attributes);
     994  res->data = ReduceTerm(multiplier, term4reduction, syztermCheck, L, T, LS, attributes);
    995995
    996996
     
    10211021
    10221022  const char* usage = "`TraverseTail(<poly>, <poly/vector>, <ideal/module>, <ideal/module>[,<module>])` expected";
    1023   const ring r = currRing;
     1023  const ring r = attributes.m_rBaseRing;
    10241024
    10251025  NoReturn(res);
     
    10991099
    11001100  res->rtyp = VECTOR_CMD;
    1101   res->data = TraverseTail(multiplier, tail, L, T, LS, r, attributes);
     1101  res->data = TraverseTail(multiplier, tail, L, T, LS, attributes);
    11021102
    11031103
     
    11261126
    11271127  const char* usage = "`ComputeSyzygy(<ideal/module>, <ideal/module>])` expected";
    1128   const ring r = currRing;
     1128  const ring r = attributes.m_rBaseRing;
    11291129
    11301130  NoReturn(res);
     
    11631163  ideal LL, TT;
    11641164
    1165   ComputeSyzygy(L, T, LL, TT, r, attributes);
     1165  ComputeSyzygy(L, T, LL, TT, attributes);
    11661166
    11671167  lists l = (lists)omAllocBin(slists_bin); l->Init(2);
  • dyn_modules/syzextra/syzextra.cc

    rdd24e5 r495328  
    227227  const ideal& id = m_idLeads;
    228228  const ring& r = m_rBaseRing;
    229   const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
    230 
    231 
    232   //   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
     229//  const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
     230
     231//   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    233232//   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
    234   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
     233//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
    235234//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    236235//   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
     
    342341  const ideal& id = m_idLeads;
    343342  const ring& r = m_rBaseRing;
    344   const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
     343//  const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
    345344 
    346345//   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
     
    348347//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
    349348//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    350   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
     349//  const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    351350 
    352351
     
    488487}
    489488
    490 
    491 CReducerFinder::CLeadingTerm::CLeadingTerm(unsigned int _label,  const poly _lt, const ring R):
    492     m_sev( p_GetShortExpVector(_lt, R) ),  m_label( _label ),  m_lt( _lt )
    493     { }
    494 
    495 
    496 CReducerFinder::~CReducerFinder()
    497 {
    498   for( CReducersHash::const_iterator it = m_hash.begin(); it != m_hash.end(); it++ )
    499   {
    500     const TReducers& v = it->second;
    501     for(TReducers::const_iterator vit = v.begin(); vit != v.end(); vit++ )
    502       delete const_cast<CLeadingTerm*>(*vit);
    503   }
    504 }
    505                                    
    506 CReducerFinder::CReducerFinder(const SchreyerSyzygyComputation& data): m_data(data), m_hash()
    507 {
    508 
    509   const ideal& L = data.m_idLeads;
    510   const ring&  R = data.m_rBaseRing;
    511 //   const SchreyerSyzygyComputationFlags& attributes = data.m_atttributes;
    512 //
    513 //   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    514 //   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
    515 //   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    516 //   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    517 
    518 
    519   assume( L != NULL );
    520   assume( R != NULL );
    521   assume( R == currRing );
    522 
    523   for( int k = IDELEMS(L) - 1; k >= 0; k-- )
    524   {
    525     const poly a = L->m[k]; assume( a != NULL );
    526 
    527     // NOTE: label is k \in 0 ... |L|-1!!!
    528     m_hash[p_GetComp(a, R)].push_back( new CLeadingTerm(k, a, R) );
    529   }
    530 }
    531 
    532 
    533 CLCM::CLCM(const SchreyerSyzygyComputation& data): std::vector<bool>(), m_data(data), m_compute(false)
    534 {
    535   const ideal& L = data.m_idLeads;
    536   const ring&  R = data.m_rBaseRing;
    537   const SchreyerSyzygyComputationFlags& attributes = data.m_atttributes;
    538 
    539 //  const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    540 //  const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
    541   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    542   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    543 
    544 
    545   assume( L != NULL );
    546   assume( R != NULL );
    547   assume( R == currRing );
    548 
    549   if( __TAILREDSYZ__ && !__HYBRIDNF__ )
    550   {
    551     const int l = IDELEMS(L);
    552 
    553     resize(l, false);
    554 
    555     const unsigned int N = rVar(R);
    556 
    557     for( int k = l - 1; k >= 0; k-- )
    558     {
    559       const poly a = L->m[k]; assume( a != NULL );
    560 
    561       for (unsigned int j = N; j > 0; j--)
    562         if ( !(*this)[j] )
    563           (*this)[j] = (p_GetExp(a, j, R) > 0);
    564     }
    565 
    566     m_compute = true;   
    567   }
    568 }
    569 
    570 
    571 bool CLCM::Check(const poly m) const
    572 {
    573   assume( m != NULL );
    574   if( m_compute && (m != NULL))
    575   { 
    576     const ring& R = m_data.m_rBaseRing;
    577     const SchreyerSyzygyComputationFlags& attributes = m_data.m_atttributes;
    578 
    579   //  const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    580   //  const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
    581     const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    582     const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    583 
    584     assume( R != NULL );
    585     assume( R == currRing );
    586 
    587     assume( __TAILREDSYZ__ && !__HYBRIDNF__ );
    588    
    589     const unsigned int N = rVar(R);
    590 
    591     for (unsigned int j = N; j > 0; j--)
    592       if ( (*this)[j] )
    593         if(p_GetExp(m, j, R) > 0)
    594           return true;
    595 
    596     return false;
    597    
    598   } else return true;
    599 }
    600 
    601489void SchreyerSyzygyComputation::ComputeSyzygy()
    602490{
     
    611499  ideal& TT = m_syzTails;
    612500  const ring& R = m_rBaseRing;
    613   const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
     501//  const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
    614502
    615503//  const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    616504//  const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
    617   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
    618   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
     505//  const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
     506//  const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    619507//  const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    620508
     
    692580void SchreyerSyzygyComputation::ComputeLeadingSyzygyTerms(bool bComputeSecondTerms)
    693581{
    694   const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
    695 
    696   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
    697   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
     582//  const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
     583
     584//  const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
     585//  const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    698586
    699587  if( bComputeSecondTerms )
     
    718606  (void)( __LEAD2SYZ__ );
    719607}
     608
     609poly SchreyerSyzygyComputation::SchreyerSyzygyNF(poly syz_lead, poly syz_2) const
     610{
     611// return FROM_NAMESPACE(INTERNAL, _SchreyerSyzygyNF(syz_lead, syz_2, m_idLeads, m_idTails, m_LS, m_rBaseRing, m_atttributes));
     612// poly _SchreyerSyzygyNF(poly syz_lead, poly syz_2,
     613//                       ideal L, ideal T, ideal LS,
     614//                       const ring r,
     615//                       const SchreyerSyzygyComputationFlags attributes)
     616// {
     617
     618  const ideal& L = m_idLeads;
     619  const ideal& T = m_idTails;
     620//  const ideal& LS = m_LS;
     621  const ring& r = m_rBaseRing;
     622
     623//   const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
     624//   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
     625//   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
     626//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
     627//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
     628//   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
     629
     630  assume( syz_lead != NULL );
     631  assume( syz_2 != NULL );
     632
     633  assume( L != NULL );
     634  assume( T != NULL );
     635
     636  assume( IDELEMS(L) == IDELEMS(T) );
     637
     638  int  c = p_GetComp(syz_lead, r) - 1;
     639
     640  assume( c >= 0 && c < IDELEMS(T) );
     641
     642  poly p = leadmonom(syz_lead, r); // :( 
     643  poly spoly = pp_Mult_qq(p, T->m[c], r);
     644  p_Delete(&p, r);
     645
     646
     647  c = p_GetComp(syz_2, r) - 1;
     648  assume( c >= 0 && c < IDELEMS(T) );
     649
     650  p = leadmonom(syz_2, r); // :(
     651  spoly = p_Add_q(spoly, pp_Mult_qq(p, T->m[c], r), r);
     652  p_Delete(&p, r);
     653
     654  poly tail = p_Copy(syz_2, r); // TODO: use bucket!?
     655
     656  while (spoly != NULL)
     657  {
     658    poly t = m_div.FindReducer(spoly, NULL);
     659
     660    p_LmDelete(&spoly, r);
     661
     662    if( t != NULL )
     663    {
     664      p = leadmonom(t, r); // :(
     665      c = p_GetComp(t, r) - 1;
     666
     667      assume( c >= 0 && c < IDELEMS(T) );
     668
     669      spoly = p_Add_q(spoly, pp_Mult_qq(p, T->m[c], r), r);
     670
     671      p_Delete(&p, r);
     672
     673      tail = p_Add_q(tail, t, r);
     674    }   
     675  }
     676
     677  return tail;
     678}
     679
     680
     681poly SchreyerSyzygyComputation::TraverseTail(poly multiplier, poly tail) const
     682{
     683  const ideal& L = m_idLeads;
     684  const ideal& T = m_idTails;
     685//  const ideal& LS = m_LS;
     686  const ring& r = m_rBaseRing;
     687//  const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
     688
     689//  return FROM_NAMESPACE(INTERNAL, _TraverseTail(multiplier, tail, m_idLeads, m_idTails, m_LS, m_rBaseRing, m_atttributes));
     690// poly _TraverseTail(poly multiplier, poly tail,
     691//                    ideal L, ideal T, ideal LS,
     692//                    const ring r,
     693//                    const SchreyerSyzygyComputationFlags attributes)
     694// {
     695
     696
     697//   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
     698//   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
     699//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
     700//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
     701//   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
     702
     703  assume( multiplier != NULL );
     704
     705  assume( L != NULL );
     706  assume( T != NULL );
     707
     708  poly s = NULL;
     709
     710  if( (!__TAILREDSYZ__) || m_lcm.Check(multiplier) )
     711    for(poly p = tail; p != NULL; p = pNext(p))   // iterate over the tail
     712      s = p_Add_q(s, ReduceTerm(multiplier, p, NULL), r); 
     713
     714  return s;
     715}
     716
     717
     718
     719
     720poly SchreyerSyzygyComputation::ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck) const
     721{
     722  const ideal& L = m_idLeads;
     723  const ideal& T = m_idTails;
     724//  const ideal& LS = m_LS;
     725  const ring& r = m_rBaseRing;
     726//  const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
     727
     728//  return FROM_NAMESPACE(INTERNAL, _ReduceTerm(multiplier, term4reduction, syztermCheck, m_idLeads, m_idTails, m_LS, m_rBaseRing, m_atttributes));
     729// poly _ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck,
     730//                 ideal L, ideal T, ideal LS,
     731//                 const ring r,
     732//                 const SchreyerSyzygyComputationFlags attributes)
     733
     734
     735
     736//   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
     737//   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
     738//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
     739//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
     740//  const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
     741
     742  assume( multiplier != NULL );
     743  assume( term4reduction != NULL );
     744
     745
     746  assume( L != NULL );
     747  assume( T != NULL );
     748
     749  // assume(r == currRing); // ?
     750
     751  // simple implementation with FindReducer:
     752  poly s = NULL;
     753
     754  if( (!__TAILREDSYZ__) || m_lcm.Check(multiplier) )
     755  {
     756    // NOTE: only LT(term4reduction) should be used in the following:
     757    poly product = pp_Mult_mm(multiplier, term4reduction, r);
     758    s = m_div.FindReducer(product, syztermCheck);
     759    p_Delete(&product, r);
     760  }
     761
     762  if( s == NULL ) // No Reducer?
     763    return s;
     764
     765  poly b = leadmonom(s, r);
     766
     767  const int c = p_GetComp(s, r) - 1;
     768  assume( c >= 0 && c < IDELEMS(T) );
     769
     770  const poly tail = T->m[c];
     771
     772  if( tail != NULL )
     773    s = p_Add_q(s, TraverseTail(b, tail), r); 
     774
     775  return s;
     776}
     777
     778
     779
     780
     781
     782BEGIN_NAMESPACE_NONAME
     783   
     784static inline int atGetInt(idhdl rootRingHdl, const char* attribute, long def)
     785{
     786  return ((int)(long)(atGet(rootRingHdl, attribute, INT_CMD, (void*)def)));
     787}
     788
     789END_NAMESPACE   
     790
     791SchreyerSyzygyComputationFlags::SchreyerSyzygyComputationFlags(idhdl rootRingHdl):
     792#ifndef NDEBUG
     793    __DEBUG__( (BOOLEAN)atGetInt(rootRingHdl,"DEBUG", TRUE) ),
     794#else
     795    __DEBUG__( (BOOLEAN)atGetInt(rootRingHdl,"DEBUG", FALSE) ),
     796#endif
     797//    __SYZCHECK__( (BOOLEAN)atGetInt(rootRingHdl, "SYZCHECK", __DEBUG__) ),
     798    __LEAD2SYZ__( (BOOLEAN)atGetInt(rootRingHdl, "LEAD2SYZ", 1) ),
     799    __TAILREDSYZ__( (BOOLEAN)atGetInt(rootRingHdl, "TAILREDSYZ", 1) ),
     800    __HYBRIDNF__( (BOOLEAN)atGetInt(rootRingHdl, "HYBRIDNF", 0) ),
     801    m_rBaseRing( rootRingHdl->data.uring )
     802{   
     803  if( __DEBUG__ )
     804  {
     805    PrintS("SchreyerSyzygyComputationFlags: \n");
     806    Print("   DEBUG     : \t%d\n", __DEBUG__);
     807//    Print("   SYZCHECK  : \t%d\n", __SYZCHECK__);
     808    Print("   LEAD2SYZ  : \t%d\n", __LEAD2SYZ__);
     809    Print("   TAILREDSYZ: \t%d\n", __TAILREDSYZ__);
     810  }
     811
     812  // TODO: just current setting!
     813  assume( rootRingHdl == currRingHdl );
     814  assume( rootRingHdl->typ == RING_CMD );
     815  assume( m_rBaseRing == currRing );
     816  // move the global ring here inside???
     817}
     818
     819   
     820
     821CReducerFinder::CLeadingTerm::CLeadingTerm(unsigned int _label,  const poly _lt, const ring R):
     822    m_sev( p_GetShortExpVector(_lt, R) ),  m_label( _label ),  m_lt( _lt )
     823{ }
     824
     825
     826CReducerFinder::~CReducerFinder()
     827{
     828  for( CReducersHash::const_iterator it = m_hash.begin(); it != m_hash.end(); it++ )
     829  {
     830    const TReducers& v = it->second;
     831    for(TReducers::const_iterator vit = v.begin(); vit != v.end(); vit++ )
     832      delete const_cast<CLeadingTerm*>(*vit);
     833  }
     834}
     835
     836CReducerFinder::CReducerFinder(const SchreyerSyzygyComputation& data):
     837    SchreyerSyzygyComputationFlags(data),
     838    m_data(data),
     839    m_hash()
     840{
     841  const ring&  R = m_rBaseRing;
     842  assume( data.m_rBaseRing == R );
     843  assume( R != NULL );
     844//   const SchreyerSyzygyComputationFlags& attributes = data.m_atttributes;
     845//
     846//   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
     847//   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
     848//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
     849//   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
     850
     851
     852  const ideal& L = data.m_idLeads; assume( L != NULL );
     853
     854  for( int k = IDELEMS(L) - 1; k >= 0; k-- )
     855  {
     856    const poly a = L->m[k]; assume( a != NULL );
     857
     858    // NOTE: label is k \in 0 ... |L|-1!!!
     859    m_hash[p_GetComp(a, R)].push_back( new CLeadingTerm(k, a, R) );
     860  }
     861}
     862
    720863
    721864poly CReducerFinder::FindReducer(const poly product, const poly syzterm) const
     
    729872  const ideal& L = m_data.m_idLeads;
    730873  const ideal& LS = m_data.m_LS;
    731   const ring& r = m_data.m_rBaseRing;
    732   const SchreyerSyzygyComputationFlags& attributes = m_data.m_atttributes;
    733 
    734 
    735   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    736   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
     874  const ring& r = m_rBaseRing;
     875//  const SchreyerSyzygyComputationFlags& attributes = m_data.m_atttributes;
     876
     877
     878//  const BOOLEAN __DEBUG__      = m_data.__DEBUG__;
     879//  const BOOLEAN __SYZCHECK__   = m_data.__SYZCHECK__;
    737880//   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
    738881//   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    739   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
     882//  const BOOLEAN __TAILREDSYZ__ = m_data.__TAILREDSYZ__;
    740883
    741884  assume( product != NULL );
     
    748891
    749892  assume( c >= 0 && c < IDELEMS(L) );
    750  
     893
    751894  if (__DEBUG__ && (syzterm != NULL))
    752895  {
     
    772915#if 1
    773916  CReducersHash::const_iterator it = m_hash.find(p_GetComp(product, r)); // same module component
    774    
     917
    775918  if( it == m_hash.end() )
    776919    return NULL;
    777920
    778921  const TReducers& reducers = it->second; 
    779  
     922
    780923  for(TReducers::const_iterator vit = reducers.begin(); vit != reducers.end(); vit++ )
    781924  {
    782      const poly p = (*vit)->m_lt;
    783 
    784      assume( p_GetComp(p, r) == comp );
    785      
    786      const int k = (*vit)->m_label;
    787 
    788      assume( L->m[k] == p );
    789      
    790      const unsigned long p_sev = (*vit)->m_sev;
    791 
    792      assume( p_sev == p_GetShortExpVector(p, r) );     
     925    const poly p = (*vit)->m_lt;
     926
     927    assume( p_GetComp(p, r) == comp );
     928
     929    const int k = (*vit)->m_label;
     930
     931    assume( L->m[k] == p );
     932
     933    const unsigned long p_sev = (*vit)->m_sev;
     934
     935    assume( p_sev == p_GetShortExpVector(p, r) );     
    793936#else 
    794    for( int k = IDELEMS(L)-1; k>= 0; k-- )
    795    {
    796      const poly p = L->m[k];
    797      
    798      if ( p_GetComp(p, r) != comp )
    799        continue;
    800        
    801      const unsigned long p_sev = p_GetShortExpVector(p, r); // to be stored in m_hash!!!
     937  for( int k = IDELEMS(L)-1; k>= 0; k-- )
     938  {
     939    const poly p = L->m[k];
     940
     941    if ( p_GetComp(p, r) != comp )
     942      continue;
     943
     944    const unsigned long p_sev = p_GetShortExpVector(p, r); // to be stored in m_hash!!!
    802945#endif
    803      
    804      if( !p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r) )
    805        continue;     
     946
     947    if( !p_LmShortDivisibleByNoComp(p, p_sev, product, not_sev, r) )
     948      continue;     
    806949
    807950//     // ... which divides the product, looking for the _1st_ appropriate one!
     
    8721015
    8731016
    874 poly SchreyerSyzygyComputation::SchreyerSyzygyNF(poly syz_lead, poly syz_2) const
    875 {
    876 // return FROM_NAMESPACE(INTERNAL, _SchreyerSyzygyNF(syz_lead, syz_2, m_idLeads, m_idTails, m_LS, m_rBaseRing, m_atttributes));
    877 // poly _SchreyerSyzygyNF(poly syz_lead, poly syz_2,
    878 //                       ideal L, ideal T, ideal LS,
    879 //                       const ring r,
    880 //                       const SchreyerSyzygyComputationFlags attributes)
    881 // {
    882 
    883   const ideal& L = m_idLeads;
    884   const ideal& T = m_idTails;
    885 //  const ideal& LS = m_LS;
    886   const ring& r = m_rBaseRing;
    887 
    888 //   const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
    889 //   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    890 //   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
    891 //   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
    892 //   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    893 //   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    894 
    895   assume( syz_lead != NULL );
    896   assume( syz_2 != NULL );
    897 
    898   assume( L != NULL );
    899   assume( T != NULL );
    900 
    901   assume( IDELEMS(L) == IDELEMS(T) );
    902 
    903   int  c = p_GetComp(syz_lead, r) - 1;
    904 
    905   assume( c >= 0 && c < IDELEMS(T) );
    906 
    907   poly p = leadmonom(syz_lead, r); // :( 
    908   poly spoly = pp_Mult_qq(p, T->m[c], r);
    909   p_Delete(&p, r);
    910 
    911 
    912   c = p_GetComp(syz_2, r) - 1;
    913   assume( c >= 0 && c < IDELEMS(T) );
    914 
    915   p = leadmonom(syz_2, r); // :(
    916   spoly = p_Add_q(spoly, pp_Mult_qq(p, T->m[c], r), r);
    917   p_Delete(&p, r);
    918 
    919   poly tail = p_Copy(syz_2, r); // TODO: use bucket!?
    920 
    921   while (spoly != NULL)
    922   {
    923     poly t = m_div.FindReducer(spoly, NULL);
    924 
    925     p_LmDelete(&spoly, r);
    926 
    927     if( t != NULL )
     1017
     1018  CLCM::CLCM(const SchreyerSyzygyComputation& data):
     1019      SchreyerSyzygyComputationFlags(data), std::vector<bool>(), m_data(data), m_compute(false)
     1020  {
     1021
     1022    const ring&  R = m_rBaseRing;
     1023    assume( data.m_rBaseRing == R );
     1024    assume( R != NULL );
     1025//  const SchreyerSyzygyComputationFlags& attributes = data.m_atttributes;
     1026
     1027//  const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
     1028//  const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
     1029//    const BOOLEAN __HYBRIDNF__   = m_data.__HYBRIDNF__;
     1030//    const BOOLEAN __TAILREDSYZ__ = m_data.__TAILREDSYZ__;
     1031
     1032
     1033    const ideal& L = data.m_idLeads;
     1034    assume( L != NULL );
     1035
     1036    if( __TAILREDSYZ__ && !__HYBRIDNF__ )
    9281037    {
    929       p = leadmonom(t, r); // :(
    930       c = p_GetComp(t, r) - 1;
    931 
    932       assume( c >= 0 && c < IDELEMS(T) );
    933 
    934       spoly = p_Add_q(spoly, pp_Mult_qq(p, T->m[c], r), r);
    935 
    936       p_Delete(&p, r);
    937 
    938       tail = p_Add_q(tail, t, r);
    939     }   
    940   }
    941 
    942   return tail;
    943 }
    944 
    945 
    946 poly SchreyerSyzygyComputation::TraverseTail(poly multiplier, poly tail) const
    947 {
    948   const ideal& L = m_idLeads;
    949   const ideal& T = m_idTails;
    950 //  const ideal& LS = m_LS;
    951   const ring& r = m_rBaseRing;
    952   const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
    953 
    954 //  return FROM_NAMESPACE(INTERNAL, _TraverseTail(multiplier, tail, m_idLeads, m_idTails, m_LS, m_rBaseRing, m_atttributes));
    955 // poly _TraverseTail(poly multiplier, poly tail,
    956 //                    ideal L, ideal T, ideal LS,
    957 //                    const ring r,
    958 //                    const SchreyerSyzygyComputationFlags attributes)
    959 // {
    960 
    961 
    962 //   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    963 //   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
    964 //   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
    965 //   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    966    const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    967 
    968   assume( multiplier != NULL );
    969 
    970   assume( L != NULL );
    971   assume( T != NULL );
    972 
    973   poly s = NULL;
    974 
    975   if( (!__TAILREDSYZ__) || m_lcm.Check(multiplier) )
    976     for(poly p = tail; p != NULL; p = pNext(p))   // iterate over the tail
    977       s = p_Add_q(s, ReduceTerm(multiplier, p, NULL), r); 
    978 
    979   return s;
    980 }
    981 
    982 
    983 
    984 
    985 poly SchreyerSyzygyComputation::ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck) const
    986 {
    987   const ideal& L = m_idLeads;
    988   const ideal& T = m_idTails;
    989 //  const ideal& LS = m_LS;
    990   const ring& r = m_rBaseRing;
    991   const SchreyerSyzygyComputationFlags& attributes = m_atttributes;
    992 
    993 //  return FROM_NAMESPACE(INTERNAL, _ReduceTerm(multiplier, term4reduction, syztermCheck, m_idLeads, m_idTails, m_LS, m_rBaseRing, m_atttributes));
    994 // poly _ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck,
    995 //                 ideal L, ideal T, ideal LS,
    996 //                 const ring r,
    997 //                 const SchreyerSyzygyComputationFlags attributes)
    998 
    999 
    1000 
    1001 //   const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
    1002 //   const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
    1003 //   const BOOLEAN __LEAD2SYZ__   = attributes.__LEAD2SYZ__;
    1004 //   const BOOLEAN __HYBRIDNF__   = attributes.__HYBRIDNF__;
    1005   const BOOLEAN __TAILREDSYZ__ = attributes.__TAILREDSYZ__;
    1006 
    1007   assume( multiplier != NULL );
    1008   assume( term4reduction != NULL );
    1009 
    1010 
    1011   assume( L != NULL );
    1012   assume( T != NULL );
    1013 
    1014   // assume(r == currRing); // ?
    1015 
    1016   // simple implementation with FindReducer:
    1017   poly s = NULL;
    1018 
    1019   if( (!__TAILREDSYZ__) || m_lcm.Check(multiplier) )
    1020   {
    1021     // NOTE: only LT(term4reduction) should be used in the following:
    1022     poly product = pp_Mult_mm(multiplier, term4reduction, r);
    1023     s = m_div.FindReducer(product, syztermCheck);
    1024     p_Delete(&product, r);
    1025   }
    1026 
    1027   if( s == NULL ) // No Reducer?
    1028     return s;
    1029 
    1030   poly b = leadmonom(s, r);
    1031 
    1032   const int c = p_GetComp(s, r) - 1;
    1033   assume( c >= 0 && c < IDELEMS(T) );
    1034 
    1035   const poly tail = T->m[c];
    1036 
    1037   if( tail != NULL )
    1038     s = p_Add_q(s, TraverseTail(b, tail), r); 
    1039 
    1040   return s;
    1041 }
    1042 
    1043 
    1044 
    1045 
    1046 
    1047 BEGIN_NAMESPACE_NONAME
    1048    
    1049 static inline int atGetInt(idhdl rootRingHdl, const char* attribute, long def)
    1050 {
    1051   return ((int)(long)(atGet(rootRingHdl, attribute, INT_CMD, (void*)def)));
    1052 }
    1053 
    1054 END_NAMESPACE   
    1055 
    1056 SchreyerSyzygyComputationFlags::SchreyerSyzygyComputationFlags(idhdl rootRingHdl):
    1057 #ifndef NDEBUG
    1058     __DEBUG__( (BOOLEAN)atGetInt(rootRingHdl,"DEBUG", TRUE) ),
    1059 #else
    1060     __DEBUG__( (BOOLEAN)atGetInt(rootRingHdl,"DEBUG", FALSE) ),
    1061 #endif
    1062     __SYZCHECK__( (BOOLEAN)atGetInt(rootRingHdl, "SYZCHECK", __DEBUG__) ),
    1063     __LEAD2SYZ__( (BOOLEAN)atGetInt(rootRingHdl, "LEAD2SYZ", 1) ),
    1064     __TAILREDSYZ__( (BOOLEAN)atGetInt(rootRingHdl, "TAILREDSYZ", 1) ),
    1065     __HYBRIDNF__( (BOOLEAN)atGetInt(rootRingHdl, "HYBRIDNF", 0) )
    1066 {   
    1067   if( __DEBUG__ )
    1068   {
    1069     PrintS("SchreyerSyzygyComputationFlags: \n");
    1070     Print("   DEBUG     : \t%d\n", __DEBUG__);
    1071     Print("   SYZCHECK  : \t%d\n", __SYZCHECK__);
    1072     Print("   LEAD2SYZ  : \t%d\n", __LEAD2SYZ__);
    1073     Print("   TAILREDSYZ: \t%d\n", __TAILREDSYZ__);
    1074   }
    1075 
    1076   // TODO: just current setting!
    1077   assume( rootRingHdl == currRingHdl );
    1078   assume( rootRingHdl->typ == RING_CMD );
    1079   assume( rootRingHdl->data.uring == currRing );
    1080   // move the global ring here inside???
    1081 }
    1082 
    1083    
     1038      const int l = IDELEMS(L);
     1039
     1040      resize(l, false);
     1041
     1042      const unsigned int N = rVar(R);
     1043
     1044      for( int k = l - 1; k >= 0; k-- )
     1045      {
     1046        const poly a = L->m[k]; assume( a != NULL );
     1047
     1048        for (unsigned int j = N; j > 0; j--)
     1049          if ( !(*this)[j] )
     1050            (*this)[j] = (p_GetExp(a, j, R) > 0);
     1051      }
     1052
     1053      m_compute = true;   
     1054    }
     1055  }
     1056
     1057
     1058  bool CLCM::Check(const poly m) const
     1059  {
     1060    assume( m != NULL );
     1061    if( m_compute && (m != NULL))
     1062    { 
     1063      const ring& R = m_data.m_rBaseRing;
     1064//    const SchreyerSyzygyComputationFlags& attributes = m_data.m_atttributes;
     1065
     1066  //  const BOOLEAN __DEBUG__      = attributes.__DEBUG__;
     1067  //  const BOOLEAN __SYZCHECK__   = attributes.__SYZCHECK__;
     1068//      const BOOLEAN __HYBRIDNF__   = m_data.__HYBRIDNF__;
     1069//      const BOOLEAN __TAILREDSYZ__ = m_data.__TAILREDSYZ__;
     1070
     1071      assume( R != NULL );
     1072      assume( R == currRing );
     1073
     1074      assume( __TAILREDSYZ__ && !__HYBRIDNF__ );
     1075
     1076      const unsigned int N = rVar(R);
     1077
     1078      for (unsigned int j = N; j > 0; j--)
     1079        if ( (*this)[j] )
     1080          if(p_GetExp(m, j, R) > 0)
     1081            return true;
     1082
     1083      return false;
     1084
     1085    } else return true;
     1086  }
     1087
     1088
    10841089
    10851090
  • dyn_modules/syzextra/syzextra.h

    rdd24e5 r495328  
    6363{
    6464  SchreyerSyzygyComputationFlags(idhdl rootRingHdl);
    65  
     65  SchreyerSyzygyComputationFlags(const SchreyerSyzygyComputationFlags& attr):
     66      __DEBUG__(attr.__DEBUG__),
     67//      __SYZCHECK__(attr.__SYZCHECK__),
     68      __LEAD2SYZ__(attr.__LEAD2SYZ__),  __TAILREDSYZ__(attr.__TAILREDSYZ__),
     69      __HYBRIDNF__(attr.__HYBRIDNF__),  m_rBaseRing(attr.m_rBaseRing)
     70  {}
     71     
     72
    6673  /// output all the intermediate states
    6774  const bool __DEBUG__; // DebugOutput;
    6875
    69   /// ?
    70   const bool __SYZCHECK__; // CheckSyzygyProperty;
     76//  const bool __SYZCHECK__; // CheckSyzygyProperty: never tested here...
    7177
    7278  /// ?
     
    7985  const bool __HYBRIDNF__; // UseHybridNF
    8086
     87  /// global base ring
     88  const ring m_rBaseRing;
     89
    8190};
    8291
    8392class SchreyerSyzygyComputation;
    8493
    85 class CLCM: public std::vector<bool>
     94class CLCM: public SchreyerSyzygyComputationFlags, public std::vector<bool>
    8695{
    8796  public:
     
    97106
    98107
    99 class CReducerFinder
     108class CReducerFinder: public SchreyerSyzygyComputationFlags
    100109{
    101110  private:
     
    148157 * @sa Schreyer Syzygy Computation Paper & Talk & Python prototype
    149158 */
    150 class SchreyerSyzygyComputation
     159class SchreyerSyzygyComputation: public SchreyerSyzygyComputationFlags
    151160{
    152161  friend class CLCM;
     
    156165
    157166    /// Construct a global object for given input data (separated into leads & tails)
    158     SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const ring rBaseRing, const SchreyerSyzygyComputationFlags attribues):
    159         m_rBaseRing(rBaseRing),
     167    SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const SchreyerSyzygyComputationFlags setting):
     168        SchreyerSyzygyComputationFlags(setting),
    160169        m_idLeads(idLeads), m_idTails(idTails),
    161         m_syzLeads(NULL), m_syzTails(NULL), m_LS(NULL), m_atttributes(attribues),
     170        m_syzLeads(NULL), m_syzTails(NULL), m_LS(NULL),
    162171        m_lcm(*this), m_div(*this)
    163172    {
     
    166175
    167176    /// Construct a global object for given input data (separated into leads & tails)
    168     SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const ideal syzLeads, const ring rBaseRing, const SchreyerSyzygyComputationFlags attribues):
    169         m_rBaseRing(rBaseRing),
     177    SchreyerSyzygyComputation(const ideal idLeads, const ideal idTails, const ideal syzLeads, const SchreyerSyzygyComputationFlags setting):
     178        SchreyerSyzygyComputationFlags(setting),
    170179        m_idLeads(idLeads), m_idTails(idTails),
    171         m_syzLeads(NULL), m_syzTails(NULL), m_LS(syzLeads), m_atttributes(attribues),
     180        m_syzLeads(NULL), m_syzTails(NULL), m_LS(syzLeads),
    172181        m_lcm(*this), m_div(*this)
    173182    {
     
    219228
    220229  private:
    221     /// global base ring
    222     const ring  m_rBaseRing;
    223 
    224230    /// input leading terms
    225231    const ideal m_idLeads;
     
    235241
    236242    /*mutable?*/ ideal m_LS; ///< leading syzygy terms used for reducing syzygy tails
    237 
    238     const SchreyerSyzygyComputationFlags m_atttributes;
    239243
    240244    /// Bitmask for variables occuring in leading terms
     
    248252// The following wrappers are just for testing separate functions on highest level (within schreyer.lib)
    249253
    250 static inline void ComputeSyzygy(const ideal L, const ideal T, ideal& LL, ideal& TT, const ring R, const SchreyerSyzygyComputationFlags A)
    251 {
    252   SchreyerSyzygyComputation syz(L, T, R, A);
     254static inline void ComputeSyzygy(const ideal L, const ideal T, ideal& LL, ideal& TT, const SchreyerSyzygyComputationFlags A)
     255{
     256  SchreyerSyzygyComputation syz(L, T, A);
    253257  syz.ComputeSyzygy();
    254258  syz.ReadOffResult(LL, TT);
    255259}
    256260
    257 static inline ideal ComputeLeadingSyzygyTerms(const ideal& L, const ring R, const SchreyerSyzygyComputationFlags A)
    258 {
    259   SchreyerSyzygyComputation syz(L, NULL, R, A);
     261static inline ideal ComputeLeadingSyzygyTerms(const ideal& L, const SchreyerSyzygyComputationFlags A)
     262{
     263  SchreyerSyzygyComputation syz(L, NULL, A);
    260264  syz.ComputeLeadingSyzygyTerms(false);
    261265  ideal LL, TT;
     
    264268}
    265269
    266 static inline ideal Compute2LeadingSyzygyTerms(const ideal& L, const ring R, const SchreyerSyzygyComputationFlags A)
    267 {
    268   SchreyerSyzygyComputation syz(L, NULL, R, A);
     270static inline ideal Compute2LeadingSyzygyTerms(const ideal& L, const SchreyerSyzygyComputationFlags A)
     271{
     272  SchreyerSyzygyComputation syz(L, NULL, A);
    269273  syz.ComputeLeadingSyzygyTerms(true);
    270274  ideal LL, TT;
     
    274278
    275279static inline poly FindReducer(poly product, poly syzterm,
    276                                ideal L, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A)
    277 {
    278   SchreyerSyzygyComputation syz(L, NULL, LS, R, A);
     280                               ideal L, ideal LS, const SchreyerSyzygyComputationFlags A)
     281{
     282  SchreyerSyzygyComputation syz(L, NULL, LS, A);
    279283  return syz._FindReducer(product, syzterm);
    280284}
    281285
    282286static inline poly TraverseTail(poly multiplier, poly tail,
    283                                 ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A)
    284 {
    285   SchreyerSyzygyComputation syz(L, T, LS, R, A);
     287                                ideal L, ideal T, ideal LS, const SchreyerSyzygyComputationFlags A)
     288{
     289  SchreyerSyzygyComputation syz(L, T, LS, A);
    286290  return syz.TraverseTail(multiplier, tail);
    287291}
    288292
    289293static inline poly ReduceTerm(poly multiplier, poly term4reduction, poly syztermCheck,
    290                               ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A)
    291 {
    292   SchreyerSyzygyComputation syz(L, T, LS, R, A);
     294                              ideal L, ideal T, ideal LS, const SchreyerSyzygyComputationFlags A)
     295{
     296  SchreyerSyzygyComputation syz(L, T, LS, A);
    293297  return syz.ReduceTerm(multiplier, term4reduction, syztermCheck);
    294298}
     
    296300
    297301static inline poly SchreyerSyzygyNF(poly syz_lead, poly syz_2,
    298                                     ideal L, ideal T, ideal LS, const ring R, const SchreyerSyzygyComputationFlags A)
    299 {
    300   SchreyerSyzygyComputation syz(L, T, LS, R, A);
     302                                    ideal L, ideal T, ideal LS, const SchreyerSyzygyComputationFlags A)
     303{
     304  SchreyerSyzygyComputation syz(L, T, LS, A);
    301305  return syz.SchreyerSyzygyNF(syz_lead, syz_2);
    302306}
Note: See TracChangeset for help on using the changeset viewer.