4 #include <NTL/mat_ZZ.h>
5 #include <barvinok/NTL_QQ.h>
6 #include <barvinok/options.h>
7 #include "decomposer.h"
16 extern struct OrthogonalException
{} Orthogonal
;
18 /* base for non-parametric counting */
19 struct np_base
: public signed_cone_consumer
{
23 np_base(unsigned dim
) {
28 virtual void handle(const mat_ZZ
& rays
, Value
*vertex
, QQ c
, int *closed
,
29 barvinok_options
*options
) = 0;
30 virtual void handle(const signed_cone
& sc
, barvinok_options
*options
);
31 virtual void start(Polyhedron
*P
, barvinok_options
*options
);
32 void do_vertex_cone(const QQ
& factor
, Polyhedron
*Cone
,
33 Value
*vertex
, barvinok_options
*options
) {
34 current_vertex
= vertex
;
35 this->factor
= factor
;
36 barvinok_decompose(Cone
, *this, options
);
38 virtual void init(Polyhedron
*P
) {
40 virtual void reset() {
43 virtual void get_count(Value
*result
) {
51 Value
*current_vertex
;
54 struct reducer
: public np_base
{
61 int lower
; // call base when only this many variables is left
63 reducer(unsigned dim
) : np_base(dim
) {
76 virtual void handle(const mat_ZZ
& rays
, Value
*vertex
, QQ c
, int *closed
,
77 barvinok_options
*options
);
78 void reduce(QQ c
, vec_ZZ
& num
, const mat_ZZ
& den_f
);
79 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
) = 0;
80 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
81 const mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
) = 0;
82 virtual gen_fun
*get_gf() {
88 struct ireducer
: public reducer
{
89 ireducer(unsigned dim
) : reducer(dim
) {}
91 virtual void split(vec_ZZ
& num
, ZZ
& num_s
, vec_ZZ
& num_p
,
92 const mat_ZZ
& den_f
, vec_ZZ
& den_s
, mat_ZZ
& den_r
);
95 void normalize(ZZ
& sign
, ZZ
& num_s
, vec_ZZ
& num_p
, vec_ZZ
& den_s
, vec_ZZ
& den_p
,
98 // incremental counter
99 struct icounter
: public ireducer
{
102 icounter(unsigned dim
) : ireducer(dim
) {
109 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);
110 virtual void get_count(Value
*result
) {
111 assert(value_one_p(&count
[0]._mp_den
));
112 value_assign(*result
, &count
[0]._mp_num
);
116 void normalize(ZZ
& sign
, ZZ
& num
, vec_ZZ
& den
);
118 /* An incremental counter for possibly infinite sets.
119 * Rather than just keeping track of the constant term
120 * of the Laurent expansions, we also keep track of the
121 * coefficients of negative powers.
122 * If any of these is non-zero, then the counted set is infinite.
124 struct infinite_icounter
: public ireducer
{
125 /* an array of coefficients; count[i] is the coeffient of
126 * the term with power -i.
131 infinite_icounter(unsigned dim
, unsigned maxlen
) : ireducer(dim
), len(maxlen
+1) {
132 /* Not sure whether it works for dim != 1 */
134 count
= new mpq_t
[len
];
135 for (int i
= 0; i
< len
; ++i
)
139 ~infinite_icounter() {
140 for (int i
= 0; i
< len
; ++i
)
144 virtual void base(QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den_f
);