00001 // -*- c++ -*- 00002 //***************************************************************************** 00014 //***************************************************************************** 00015 00016 #ifndef polybori_groebner_contained_variables_h_ 00017 #define polybori_groebner_contained_variables_h_ 00018 00019 // include basic definitions 00020 #include "groebner_defs.h" 00021 00022 BEGIN_NAMESPACE_PBORIGB 00023 00024 inline MonomialSet 00025 contained_variables_cudd_style(const MonomialSet& m){ 00026 00027 MonomialSet::navigator nav=m.navigation(); 00028 MonomialSet::navigator orig=nav; 00029 typedef PBORI::CacheManager<CCacheTypes::contained_variables> 00030 cache_mgr_type; 00031 00032 cache_mgr_type cache_mgr(m.ring()); 00033 00034 00035 while (!(nav.isConstant())){ 00036 MonomialSet::navigator cached = 00037 cache_mgr.find(nav); 00038 if (cached.isValid()) return cache_mgr.generate(cached); 00039 idx_type v=*nav; 00040 MonomialSet::navigator check_nav=nav.thenBranch(); 00041 while(!(check_nav.isConstant())){ 00042 check_nav.incrementElse(); 00043 } 00044 if (check_nav.isTerminated()){ 00045 idx_type result_index=v; 00046 MonomialSet result=MonomialSet(result_index,Polynomial(cache_mgr.one()).diagram(),contained_variables_cudd_style(cache_mgr.generate(nav.elseBranch()))); 00047 MonomialSet::navigator r_nav=result.navigation(); 00048 while(1){ 00049 MonomialSet::navigator last=orig; 00050 cache_mgr.insert(orig, r_nav); 00051 orig.incrementElse(); 00052 if(last==nav) break; 00053 } 00054 return result; 00055 } 00056 nav.incrementElse(); 00057 00058 } 00059 return MonomialSet(cache_mgr.zero()); 00060 } 00061 00062 inline MonomialSet 00063 contained_deg2_cudd_style(const MonomialSet& m){ 00064 00065 MonomialSet::navigator nav=m.navigation(); 00066 00067 typedef PBORI::CacheManager<CCacheTypes::contained_deg2> 00068 cache_mgr_type; 00069 00070 cache_mgr_type cache_mgr(m.ring()); 00071 00072 00073 if (!(nav.isConstant())){ 00074 MonomialSet::navigator cached = 00075 cache_mgr.find(nav); 00076 if (cached.isValid()) return cache_mgr.generate(cached); 00077 MonomialSet::navigator then_branch=nav.thenBranch(); 00078 MonomialSet::navigator else_branch=nav.elseBranch(); 00079 MonomialSet then_res=contained_variables_cudd_style(cache_mgr.generate(then_branch)); 00080 MonomialSet else_res=contained_deg2_cudd_style(cache_mgr.generate(else_branch)); 00081 MonomialSet result=MonomialSet(*nav,then_res,else_res); 00082 cache_mgr.insert(nav,result.navigation()); 00083 return result; 00084 } 00085 else return MonomialSet(cache_mgr.zero()); 00086 } 00087 00088 00089 00090 inline std::vector<idx_type> 00091 contained_variables(const MonomialSet& m){ 00092 std::vector<idx_type> result; 00093 MonomialSet::navigator nav=m.navigation(); 00094 while (!(nav.isConstant())){ 00095 idx_type v=*nav; 00096 MonomialSet::navigator check_nav=nav.thenBranch(); 00097 while(!(check_nav.isConstant())){ 00098 check_nav.incrementElse(); 00099 } 00100 if (check_nav.isTerminated()){ 00101 result.push_back(v); 00102 } 00103 nav.incrementElse(); 00104 00105 } 00106 return result; 00107 } 00108 00109 00110 END_NAMESPACE_PBORIGB 00111 00112 #endif /* polybori_groebner_contained_variables_h_ */