00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef DJC_COROPA_LIBALGEBRA_POLYBASISH_SEEN
00019 #define DJC_COROPA_LIBALGEBRA_POLYBASISH_SEEN
00020
00022
00034 template<typename SCA, typename RAT>
00035 class poly_basis : public basis_traits<With_Degree>
00036 {
00037 public:
00039 typedef std::map<LET, DEG> KEY;
00041 const KEY empty_key;
00043 typedef RAT RATIONAL;
00044 struct KEY_LESS;
00046 typedef std::map<KEY, SCA, KEY_LESS> MAP;
00048 typedef poly<SCA, RAT> POLY;
00049 public:
00051 poly_basis(void) {}
00052 public:
00053
00054
00056 inline SCA eval_key(const KEY& k, const std::map<LET, SCA>& values) const
00057 {
00058 SCA result(1);
00059 typename KEY::const_iterator it;
00060 for (it = k.begin(); it != k.end(); ++it)
00061 if (it->second > 0)
00062 {
00063 typename std::map<LET, SCA>::const_iterator iit;
00064 iit = values.find(it->first);
00065 try
00066 {
00067 if (iit != values.end())
00068 {
00069 for (DEG j = 1; j <= it->second; ++j)
00070 result *= iit->second;
00071 }
00072 else
00073 {
00074 throw "not all variables have values!";
00075 }
00076
00077 }
00078 catch (char* str)
00079 {
00080 std::cerr << "Exception raised: " << str << '\n';
00081 abort();
00082 }
00083
00084 }
00085
00086
00087 return result;
00088 }
00090 inline static KEY prod2(const KEY& k1, const KEY& k2)
00091 {
00092 KEY k(k1);
00093 typename KEY::const_iterator it;
00094 for (it = k2.begin(); it != k2.end(); ++it)
00095 {
00096 k[it->first] += it->second;
00097 }
00098 return k;
00099 }
00101
00107 inline static POLY prod(const KEY& k1, const KEY& k2)
00108 {
00109 POLY result;
00110 result[prod2(k1, k2)] = ((SCA)+1);
00111 return result;
00112 }
00114 inline KEY keyofletter(LET letter) const
00115 {
00116 KEY result;
00117 result[letter] = +1;
00118 return result;
00119 }
00121 inline static DEG degree(const KEY& k)
00122 {
00123 DEG result (0);
00124 typename KEY::const_iterator it;
00125 for (it = k.begin(); it != k.end(); ++it)
00126 {
00127 result += DEG(it->second);
00128 }
00129 return result;
00130 }
00131
00132 struct KEY_LESS
00133 {
00134 bool inline operator()(const KEY& lhs, const KEY& rhs) const
00135 {
00136 return ((degree(lhs) < degree(rhs)) || ((degree(lhs) == degree(rhs)) && lhs < rhs));
00137 }
00138 };
00139
00140
00142 inline KEY begin(void) const
00143 {
00144 return empty_key;
00145 }
00148
00149
00150
00151
00152
00153
00156
00157
00158
00159
00160
00161
00162
00163
00165 inline friend
00166 std::ostream& operator<<(std::ostream& os, const std::pair<poly_basis*, KEY>& t)
00167 {
00168 bool first(true);
00169 typename KEY::const_iterator it;
00170 for (it = t.second.begin(); it != t.second.end(); ++it)
00171 if (it->second > 0)
00172 {
00173 if (!first)
00174 os << ' ';
00175 else
00176 first = false;
00177 os << "x" << it->first;
00178 if (it->second > 1)
00179 os << '^' << it->second;
00180 }
00181 return os;
00182 }
00183 };
00184
00185
00186 #endif // DJC_COROPA_LIBALGEBRA_POLYBASISH_SEEN
00187
00188