]> www.ginac.de Git - ginac.git/blob - ginac/polynomial/collect_vargs.h
Merge branch 'c++11' in preparation for version 1.7.0.
[ginac.git] / ginac / polynomial / collect_vargs.h
1 /** @file collect_vargs.h
2  *
3  *  Interface to utility functions. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #ifndef GINAC_COLLECT_VARGS_H
24 #define GINAC_COLLECT_VARGS_H
25
26 #include "ex.h"
27
28 #include <cln/integer.h>
29 #include <utility> // for std::pair
30 #include <vector>
31 #include <algorithm> // std::lexicographical_compare
32
33 namespace GiNaC {
34
35 typedef std::vector<int> exp_vector_t;
36
37 static inline bool operator<(const exp_vector_t& v1, const exp_vector_t& v2)
38 {
39         return std::lexicographical_compare(v1.rbegin(), v1.rend(),
40                                             v2.rbegin(), v2.rend());
41 }
42
43 static inline bool operator>(const exp_vector_t& v1, const exp_vector_t& v2)
44 {
45         if (v1 == v2)
46                 return false;
47         return !(v1 < v2);
48 }
49
50 static inline bool zerop(const exp_vector_t& v)
51 {
52         for (auto & i : v) {
53                 if (i != 0)
54                         return false;
55         }
56         return true;
57 }
58
59 typedef std::vector<std::pair<exp_vector_t, ex>> ex_collect_t;
60
61 extern void
62 collect_vargs(ex_collect_t& ec, const ex& e, const exvector& x);
63 extern ex
64 ex_collect_to_ex(const ex_collect_t& ec, const exvector& x);
65
66 /**
67  * Leading coefficient of a multivariate polynomial e, considering it
68  * as a multivariate polynomial in x_0, \ldots x_{n-1} with coefficients
69  * being univariate polynomials in R[x_n] (where R is some ring)
70  */
71 extern ex lcoeff_wrt(ex e, const exvector& x);
72
73
74 /**
75  * Degree vector of a leading term of a multivariate polynomial.
76  * (generalization of degree(expr, var))
77  */
78 extern exp_vector_t degree_vector(ex e, const exvector& vars);
79
80 /**
81  * Leading coefficient c \in R (where R = Z or Z_p) of a multivariate
82  * polynomial e \in R[x_0, \ldots, x_n]
83  */
84 extern cln::cl_I integer_lcoeff(const ex& e, const exvector& vars);
85
86 } // namespace GiNaC
87
88 #endif // ndef GINAC_COLLECT_VARGS_H