]> www.ginac.de Git - ginac.git/commitdiff
Added `degree_vector' utility function.
authorAlexei Sheplyakov <alexei.sheplyakov@gmail.com>
Mon, 17 May 2010 22:21:53 +0000 (00:21 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Mon, 17 May 2010 22:21:53 +0000 (00:21 +0200)
It's a generalization of degree(expr, var) for multivariate polynomials.

ginac/polynomial/collect_vargs.cpp
ginac/polynomial/collect_vargs.h

index 259326873bf1da4fd6866a8d2267ec0a13665264..c4368fb2a5d2c1849f1b8d377ba5fddd3b8ecd7a 100644 (file)
@@ -177,6 +177,18 @@ ex lcoeff_wrt(ex e, const exvector& x)
        return ec.rbegin()->second;
 }
 
        return ec.rbegin()->second;
 }
 
+exp_vector_t degree_vector(ex e, const exvector& vars)
+{
+       e = e.expand();
+       exp_vector_t dvec(vars.size());
+       for (std::size_t i = vars.size(); i-- != 0; ) {
+               const int deg_i = e.degree(vars[i]);
+               e = e.coeff(vars[i], deg_i);
+               dvec[i] = deg_i;
+       }
+       return dvec;
+}
+
 cln::cl_I integer_lcoeff(const ex& e, const exvector& vars)
 {
        ex_collect_t ec;
 cln::cl_I integer_lcoeff(const ex& e, const exvector& vars)
 {
        ex_collect_t ec;
index 44c3d72cae16b654c0b53e8f5a6e4585fa624aeb..a927c3f5ed1f410d67eb256bef2e9b09172f4fbf 100644 (file)
 #include <cln/integer.h>
 #include <utility> // for std::pair
 #include <vector>
 #include <cln/integer.h>
 #include <utility> // for std::pair
 #include <vector>
+#include <algorithm> // std::lexicographical_compare
 
 namespace GiNaC {
 
 typedef std::vector<int> exp_vector_t;
 
 namespace GiNaC {
 
 typedef std::vector<int> exp_vector_t;
+
+static inline bool operator<(const exp_vector_t& v1, const exp_vector_t& v2)
+{
+       return std::lexicographical_compare(v1.rbegin(), v1.rend(),
+                                           v2.rbegin(), v2.rend());
+}
+
+static inline bool operator>(const exp_vector_t& v1, const exp_vector_t& v2)
+{
+       if (v1 == v2)
+               return false;
+       return !(v1 < v2);
+}
+
+static inline bool zerop(const exp_vector_t& v)
+{
+       for (exp_vector_t::const_reverse_iterator i = v.rbegin(); i != v.rend(); ++i) {
+               if (*i != 0) 
+                       return false;
+       }
+       return true;
+}
+
 typedef std::vector<std::pair<exp_vector_t, ex> > ex_collect_t;
 
 extern void
 typedef std::vector<std::pair<exp_vector_t, ex> > ex_collect_t;
 
 extern void
@@ -46,6 +70,13 @@ ex_collect_to_ex(const ex_collect_t& ec, const exvector& x);
  */
 extern ex lcoeff_wrt(ex e, const exvector& x);
 
  */
 extern ex lcoeff_wrt(ex e, const exvector& x);
 
+
+/**
+ * Degree vector of a leading term of a multivariate polynomial.
+ * (generalization of degree(expr, var))
+ */
+extern exp_vector_t degree_vector(ex e, const exvector& vars);
+
 /**
  * Leading coefficient c \in R (where R = Z or Z_p) of a multivariate
  * polynomial e \in R[x_0, \ldots, x_n]
 /**
  * Leading coefficient c \in R (where R = Z or Z_p) of a multivariate
  * polynomial e \in R[x_0, \ldots, x_n]