realroot_doc 0.1.1
|
00001 /****************************************************************************** 00002 * MODULE : monomial_glue.hpp 00003 * DESCRIPTION: Glue for monomials 00004 * COPYRIGHT : (C) 2008 Bernard Mourrain 00005 ******************************************************************************* 00006 * This software falls under the GNU general public license and comes WITHOUT 00007 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details. 00008 * If you don't have this file, write to the Free Software Foundation, Inc., 00009 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00010 ******************************************************************************/ 00011 #ifndef __MMX_MONOMIAL_GLUE_HPP 00012 #define __MMX_MONOMIAL_GLUE_HPP 00013 #include <basix/category_meta.hpp> 00014 #include <basix/tuple.hpp> 00015 #include <basix/vector.hpp> 00016 #include <realroot/monomial.hpp> 00017 00018 #define TMPL 00019 //template<typename C> 00020 #define MONOMIAL monom<int> 00021 00022 namespace mmx { 00023 TMPL bool exact_eq (const Monomial& v1, const Monomial& v2) {return v1==v2;} 00024 TMPL bool exact_neq(const Monomial& v1, const Monomial& v2) {return v1!=v2;} 00025 00026 TMPL unsigned hash (const Monomial& v) { 00027 register unsigned i, h= 214365^hash(v.coeff()), n= v.size(); 00028 for (i=0; i<n; i++) 00029 h= (h<<1) ^ (h<<5) ^ (h>>27) ^ hash(v[i]); 00030 return h; 00031 } 00032 TMPL unsigned exact_hash (const Monomial& m) {return hash(m);} 00033 TMPL unsigned soft_hash (const Monomial& m) {return hash(m);} 00034 00035 TMPL syntactic 00036 flatten (const MONOMIAL& v) { 00037 syntactic m= flatten(v.coeff()); 00038 for(unsigned i=0;i<v.nbvar();i++) 00039 m = m*pow(syntactic(MONOMIAL::var[i].data()),v[i]); 00040 return m; 00041 } 00042 00043 00044 TMPL MONOMIAL 00045 monomial_from_vector (const vector<int> & t) { 00046 nat sz=N(t); 00047 MONOMIAL r(1,sz, AsSize()); 00048 for(nat i=0;i<sz;i++) 00049 r.set_expt(i,t[i]); 00050 return r; 00051 } 00052 00053 TMPL vector<int> 00054 vector_from_monomial (const MONOMIAL& m) { 00055 vector<int> res; 00056 for(nat i=0;i<m.size();i++) res<<m[i]; 00057 return res; 00058 } 00059 00060 TMPL inline int N(const MONOMIAL& v) { return v.size(); } 00061 TMPL inline int size (const MONOMIAL& v) { return N(v); } 00062 00063 template<typename T, typename F, typename TR, typename FR> 00064 struct as_helper<monom<T,TR>, monom<F,FR> > 00065 { 00066 static inline monom<T,TR> 00067 cv (const monom<F,FR>& x) { 00068 monom<T,TR> r(as<T>(x.coeff()),x.size(),AsSize()); 00069 for (unsigned i=0; i<x.size(); i++) 00070 r.set_expt(i,x[i]); 00071 return r; 00072 } 00073 }; 00074 00075 //==================================================================== 00076 } // namespace mmx 00077 #undef TMPL 00078 #undef Monomial 00079 #endif // __MMX_MONOMIAL_GLUE_HPP