5 #include <barvinok/genfun.h>
6 #include <barvinok/barvinok.h>
7 #include "conversion.h"
8 #include "genfun_constructor.h"
17 bool short_rat_lex_smaller_denominator::operator()(const short_rat
* r1
,
18 const short_rat
* r2
) const
20 return lex_cmp(r1
->d
.power
, r2
->d
.power
) < 0;
23 static void lex_order_terms(struct short_rat
* rat
)
25 for (int i
= 0; i
< rat
->n
.power
.NumRows(); ++i
) {
27 for (int j
= i
+1; j
< rat
->n
.power
.NumRows(); ++j
)
28 if (lex_cmp(rat
->n
.power
[j
], rat
->n
.power
[m
]) < 0)
31 vec_ZZ tmp
= rat
->n
.power
[m
];
32 rat
->n
.power
[m
] = rat
->n
.power
[i
];
33 rat
->n
.power
[i
] = tmp
;
34 QQ tmp_coeff
= rat
->n
.coeff
[m
];
35 rat
->n
.coeff
[m
] = rat
->n
.coeff
[i
];
36 rat
->n
.coeff
[i
] = tmp_coeff
;
41 short_rat::short_rat(Value c
)
44 value2zz(c
, n
.coeff
[0].n
);
46 n
.power
.SetDims(1, 0);
47 d
.power
.SetDims(0, 0);
50 short_rat::short_rat(const QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den
)
56 n
.power
.SetDims(1, num
.length());
62 void short_rat::normalize()
64 /* Make all powers in denominator reverse-lexico-positive */
65 for (int i
= 0; i
< d
.power
.NumRows(); ++i
) {
67 for (j
= d
.power
.NumCols()-1; j
>= 0; --j
)
68 if (d
.power
[i
][j
] != 0)
71 if (d
.power
[i
][j
] < 0) {
72 d
.power
[i
] = -d
.power
[i
];
73 for (int k
= 0; k
< n
.coeff
.length(); ++k
) {
74 n
.coeff
[k
].n
= -n
.coeff
[k
].n
;
75 n
.power
[k
] += d
.power
[i
];
80 /* Order powers in denominator */
81 lex_order_rows(d
.power
);
84 void short_rat::add(short_rat
*r
)
86 for (int i
= 0; i
< r
->n
.power
.NumRows(); ++i
) {
87 int len
= n
.coeff
.length();
89 for (j
= 0; j
< len
; ++j
)
90 if (r
->n
.power
[i
] == n
.power
[j
])
93 n
.coeff
[j
] += r
->n
.coeff
[i
];
94 if (n
.coeff
[j
].n
== 0) {
96 n
.power
[j
] = n
.power
[len
-1];
97 n
.coeff
[j
] = n
.coeff
[len
-1];
99 int dim
= n
.power
.NumCols();
100 n
.coeff
.SetLength(len
-1);
101 n
.power
.SetDims(len
-1, dim
);
104 int dim
= n
.power
.NumCols();
105 n
.coeff
.SetLength(len
+1);
106 n
.power
.SetDims(len
+1, dim
);
107 n
.coeff
[len
] = r
->n
.coeff
[i
];
108 n
.power
[len
] = r
->n
.power
[i
];
113 bool short_rat::reduced()
115 int dim
= n
.power
.NumCols();
116 lex_order_terms(this);
117 if (n
.power
.NumRows() % 2 == 0) {
118 if (n
.coeff
[0].n
== -n
.coeff
[1].n
&&
119 n
.coeff
[0].d
== n
.coeff
[1].d
) {
120 vec_ZZ step
= n
.power
[1] - n
.power
[0];
122 for (k
= 1; k
< n
.power
.NumRows()/2; ++k
) {
123 if (n
.coeff
[2*k
].n
!= -n
.coeff
[2*k
+1].n
||
124 n
.coeff
[2*k
].d
!= n
.coeff
[2*k
+1].d
)
126 if (step
!= n
.power
[2*k
+1] - n
.power
[2*k
])
129 if (k
== n
.power
.NumRows()/2) {
130 for (k
= 0; k
< d
.power
.NumRows(); ++k
)
131 if (d
.power
[k
] == step
)
133 if (k
< d
.power
.NumRows()) {
134 for (++k
; k
< d
.power
.NumRows(); ++k
)
135 d
.power
[k
-1] = d
.power
[k
];
136 d
.power
.SetDims(k
-1, dim
);
137 for (k
= 1; k
< n
.power
.NumRows()/2; ++k
) {
138 n
.coeff
[k
] = n
.coeff
[2*k
];
139 n
.power
[k
] = n
.power
[2*k
];
141 n
.coeff
.SetLength(k
);
142 n
.power
.SetDims(k
, dim
);
151 gen_fun::gen_fun(Value c
)
153 short_rat
*r
= new short_rat(c
);
154 context
= Universe_Polyhedron(0);
158 void gen_fun::add(const QQ
& c
, const vec_ZZ
& num
, const mat_ZZ
& den
)
163 short_rat
* r
= new short_rat(c
, num
, den
);
165 short_rat_list::iterator i
= term
.find(r
);
166 while (i
!= term
.end()) {
168 if ((*i
)->n
.coeff
.length() == 0) {
171 } else if ((*i
)->reduced()) {
173 /* we've modified term[i], so remove it
174 * and add it back again
188 void gen_fun::add(const QQ
& c
, const gen_fun
*gf
)
191 for (short_rat_list::iterator i
= gf
->term
.begin(); i
!= gf
->term
.end(); ++i
) {
192 for (int j
= 0; j
< (*i
)->n
.power
.NumRows(); ++j
) {
194 p
*= (*i
)->n
.coeff
[j
];
195 add(p
, (*i
)->n
.power
[j
], (*i
)->d
.power
);
200 static void split_param_compression(Matrix
*CP
, mat_ZZ
& map
, vec_ZZ
& offset
)
202 Matrix
*T
= Transpose(CP
);
203 matrix2zz(T
, map
, T
->NbRows
-1, T
->NbColumns
-1);
204 values2zz(T
->p
[T
->NbRows
-1], offset
, T
->NbColumns
-1);
209 * Perform the substitution specified by CP
211 * CP is a homogeneous matrix that maps a set of "compressed parameters"
212 * to the original set of parameters.
214 * This function is applied to a gen_fun computed with the compressed parameters
215 * and adapts it to refer to the original parameters.
217 * That is, if y are the compressed parameters and x = A y + b are the original
218 * parameters, then we want the coefficient of the monomial t^y in the original
219 * generating function to be the coefficient of the monomial u^x in the resulting
220 * generating function.
221 * The original generating function has the form
223 * a t^m/(1-t^n) = a t^m + a t^{m+n} + a t^{m+2n} + ...
225 * Since each term t^y should correspond to a term u^x, with x = A y + b, we want
227 * a u^{A m + b} + a u^{A (m+n) + b} + a u^{A (m+2n) +b} + ... =
229 * = a u^{A m + b}/(1-u^{A n})
231 * Therefore, we multiply the powers m and n in both numerator and denominator by A
232 * and add b to the power in the numerator.
233 * Since the above powers are stored as row vectors m^T and n^T,
234 * we compute, say, m'^T = m^T A^T to obtain m' = A m.
236 * The pair (map, offset) contains the same information as CP.
237 * map is the transpose of the linear part of CP, while offset is the constant part.
239 void gen_fun::substitute(Matrix
*CP
)
243 split_param_compression(CP
, map
, offset
);
244 Polyhedron
*C
= Polyhedron_Image(context
, CP
, 0);
245 Polyhedron_Free(context
);
248 short_rat_list new_term
;
249 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
) {
253 for (int j
= 0; j
< r
->n
.power
.NumRows(); ++j
)
254 r
->n
.power
[j
] += offset
;
263 vector
<pair
<Vector
*, QQ
> > vertices
;
264 cone(int *pos
) : pos(pos
) {}
267 #ifndef HAVE_COMPRESS_PARMS
268 static Matrix
*compress_parms(Matrix
*M
, unsigned nparam
)
274 struct parallel_polytopes
{
282 barvinok_options
*options
;
284 parallel_polytopes(int n
, Polyhedron
*context
, int nparam
,
285 barvinok_options
*options
) :
286 context(context
), dim(-1), nparam(nparam
),
293 bool add(const QQ
& c
, Polyhedron
*P
) {
296 for (i
= 0; i
< P
->NbEq
; ++i
)
297 if (First_Non_Zero(P
->Constraint
[i
]+1,
298 P
->Dimension
-nparam
) == -1)
303 Polyhedron
*Q
= remove_equalities_p(Polyhedron_Copy(P
), P
->Dimension
-nparam
,
305 POL_ENSURE_VERTICES(Q
);
315 M
= Matrix_Alloc(Q
->NbEq
, Q
->Dimension
+2);
316 Vector_Copy(Q
->Constraint
[0], M
->p
[0], Q
->NbEq
* (Q
->Dimension
+2));
317 CP
= compress_parms(M
, nparam
);
318 T
= align_matrix(CP
, Q
->Dimension
+1);
321 R
= Polyhedron_Preimage(Q
, T
, options
->MaxRays
);
323 Q
= remove_equalities_p(R
, R
->Dimension
-nparam
, NULL
);
325 assert(Q
->NbEq
== 0);
327 if (First_Non_Zero(Q
->Constraint
[Q
->NbConstraints
-1]+1, Q
->Dimension
) == -1)
332 red
= gf_base::create(Polyhedron_Copy(context
), dim
, nparam
, options
);
334 Constraints
= Matrix_Alloc(Q
->NbConstraints
, Q
->Dimension
);
335 for (int i
= 0; i
< Q
->NbConstraints
; ++i
) {
336 Vector_Copy(Q
->Constraint
[i
]+1, Constraints
->p
[i
], Q
->Dimension
);
339 assert(Q
->Dimension
== dim
);
340 for (int i
= 0; i
< Q
->NbConstraints
; ++i
) {
342 for (j
= 0; j
< Constraints
->NbRows
; ++j
)
343 if (Vector_Equal(Q
->Constraint
[i
]+1, Constraints
->p
[j
],
346 assert(j
< Constraints
->NbRows
);
350 for (int i
= 0; i
< Q
->NbRays
; ++i
) {
351 if (!value_pos_p(Q
->Ray
[i
][dim
+1]))
354 Polyhedron
*C
= supporting_cone(Q
, i
);
356 if (First_Non_Zero(C
->Constraint
[C
->NbConstraints
-1]+1,
360 int *pos
= new int[1+C
->NbConstraints
];
361 pos
[0] = C
->NbConstraints
;
363 for (int k
= 0; k
< Constraints
->NbRows
; ++k
) {
364 for (int j
= 0; j
< C
->NbConstraints
; ++j
) {
365 if (Vector_Equal(C
->Constraint
[j
]+1, Constraints
->p
[k
],
372 assert(l
== C
->NbConstraints
);
375 for (j
= 0; j
< cones
.size(); ++j
)
376 if (!memcmp(pos
, cones
[j
].pos
, (1+C
->NbConstraints
)*sizeof(int)))
378 if (j
== cones
.size())
379 cones
.push_back(cone(pos
));
386 for (k
= 0; k
< cones
[j
].vertices
.size(); ++k
)
387 if (Vector_Equal(Q
->Ray
[i
]+1, cones
[j
].vertices
[k
].first
->p
,
391 if (k
== cones
[j
].vertices
.size()) {
392 Vector
*vertex
= Vector_Alloc(Q
->Dimension
+1);
393 Vector_Copy(Q
->Ray
[i
]+1, vertex
->p
, Q
->Dimension
+1);
394 cones
[j
].vertices
.push_back(pair
<Vector
*,QQ
>(vertex
, c
));
396 cones
[j
].vertices
[k
].second
+= c
;
397 if (cones
[j
].vertices
[k
].second
.n
== 0) {
398 int size
= cones
[j
].vertices
.size();
399 Vector_Free(cones
[j
].vertices
[k
].first
);
401 cones
[j
].vertices
[k
] = cones
[j
].vertices
[size
-1];
402 cones
[j
].vertices
.pop_back();
413 for (int i
= 0; i
< cones
.size(); ++i
) {
414 Matrix
*M
= Matrix_Alloc(cones
[i
].pos
[0], 1+Constraints
->NbColumns
+1);
416 for (int j
= 0; j
<cones
[i
].pos
[0]; ++j
) {
417 value_set_si(M
->p
[j
][0], 1);
418 Vector_Copy(Constraints
->p
[cones
[i
].pos
[1+j
]], M
->p
[j
]+1,
419 Constraints
->NbColumns
);
421 Cone
= Constraints2Polyhedron(M
, options
->MaxRays
);
423 for (int j
= 0; j
< cones
[i
].vertices
.size(); ++j
) {
424 red
->base
->do_vertex_cone(cones
[i
].vertices
[j
].second
,
425 Polyhedron_Copy(Cone
),
426 cones
[i
].vertices
[j
].first
->p
, options
);
428 Polyhedron_Free(Cone
);
431 red
->gf
->substitute(CP
);
434 void print(std::ostream
& os
) const {
435 for (int i
= 0; i
< cones
.size(); ++i
) {
437 for (int j
= 0; j
< cones
[i
].pos
[0]; ++j
) {
440 os
<< cones
[i
].pos
[1+j
];
443 for (int j
= 0; j
< cones
[i
].vertices
.size(); ++j
) {
444 Vector_Print(stderr
, P_VALUE_FMT
, cones
[i
].vertices
[j
].first
);
445 os
<< cones
[i
].vertices
[j
].second
<< endl
;
449 ~parallel_polytopes() {
450 for (int i
= 0; i
< cones
.size(); ++i
) {
451 delete [] cones
[i
].pos
;
452 for (int j
= 0; j
< cones
[i
].vertices
.size(); ++j
)
453 Vector_Free(cones
[i
].vertices
[j
].first
);
456 Matrix_Free(Constraints
);
465 gen_fun
*gen_fun::Hadamard_product(const gen_fun
*gf
, barvinok_options
*options
)
468 Polyhedron
*C
= DomainIntersection(context
, gf
->context
, options
->MaxRays
);
469 Polyhedron
*U
= Universe_Polyhedron(C
->Dimension
);
470 gen_fun
*sum
= new gen_fun(C
);
471 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
) {
472 for (short_rat_list::iterator i2
= gf
->term
.begin(); i2
!= gf
->term
.end();
474 int d
= (*i
)->d
.power
.NumCols();
475 int k1
= (*i
)->d
.power
.NumRows();
476 int k2
= (*i2
)->d
.power
.NumRows();
477 assert((*i
)->d
.power
.NumCols() == (*i2
)->d
.power
.NumCols());
479 parallel_polytopes
pp((*i
)->n
.power
.NumRows() *
480 (*i2
)->n
.power
.NumRows(),
481 sum
->context
, d
, options
);
483 for (int j
= 0; j
< (*i
)->n
.power
.NumRows(); ++j
) {
484 for (int j2
= 0; j2
< (*i2
)->n
.power
.NumRows(); ++j2
) {
485 Matrix
*M
= Matrix_Alloc(k1
+k2
+d
+d
, 1+k1
+k2
+d
+1);
486 for (int k
= 0; k
< k1
+k2
; ++k
) {
487 value_set_si(M
->p
[k
][0], 1);
488 value_set_si(M
->p
[k
][1+k
], 1);
490 for (int k
= 0; k
< d
; ++k
) {
491 value_set_si(M
->p
[k1
+k2
+k
][1+k1
+k2
+k
], -1);
492 zz2value((*i
)->n
.power
[j
][k
], M
->p
[k1
+k2
+k
][1+k1
+k2
+d
]);
493 for (int l
= 0; l
< k1
; ++l
)
494 zz2value((*i
)->d
.power
[l
][k
], M
->p
[k1
+k2
+k
][1+l
]);
496 for (int k
= 0; k
< d
; ++k
) {
497 value_set_si(M
->p
[k1
+k2
+d
+k
][1+k1
+k2
+k
], -1);
498 zz2value((*i2
)->n
.power
[j2
][k
],
499 M
->p
[k1
+k2
+d
+k
][1+k1
+k2
+d
]);
500 for (int l
= 0; l
< k2
; ++l
)
501 zz2value((*i2
)->d
.power
[l
][k
],
502 M
->p
[k1
+k2
+d
+k
][1+k1
+l
]);
504 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
507 QQ c
= (*i
)->n
.coeff
[j
];
508 c
*= (*i2
)->n
.coeff
[j2
];
510 gen_fun
*t
= barvinok_series(P
, U
, options
->MaxRays
);
519 gen_fun
*t
= pp
.compute();
530 void gen_fun::add_union(gen_fun
*gf
, barvinok_options
*options
)
532 QQ
one(1, 1), mone(-1, 1);
534 gen_fun
*hp
= Hadamard_product(gf
, options
);
540 static void Polyhedron_Shift(Polyhedron
*P
, Vector
*offset
)
544 for (int i
= 0; i
< P
->NbConstraints
; ++i
) {
545 Inner_Product(P
->Constraint
[i
]+1, offset
->p
, P
->Dimension
, &tmp
);
546 value_subtract(P
->Constraint
[i
][1+P
->Dimension
],
547 P
->Constraint
[i
][1+P
->Dimension
], tmp
);
549 for (int i
= 0; i
< P
->NbRays
; ++i
) {
550 if (value_notone_p(P
->Ray
[i
][0]))
552 if (value_zero_p(P
->Ray
[i
][1+P
->Dimension
]))
554 Vector_Combine(P
->Ray
[i
]+1, offset
->p
, P
->Ray
[i
]+1,
555 P
->Ray
[i
][0], P
->Ray
[i
][1+P
->Dimension
], P
->Dimension
);
560 void gen_fun::shift(const vec_ZZ
& offset
)
562 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
)
563 for (int j
= 0; j
< (*i
)->n
.power
.NumRows(); ++j
)
564 (*i
)->n
.power
[j
] += offset
;
566 Vector
*v
= Vector_Alloc(offset
.length());
567 zz2values(offset
, v
->p
);
568 Polyhedron_Shift(context
, v
);
572 /* Divide the generating functin by 1/(1-z^power).
573 * The effect on the corresponding explicit function f(x) is
574 * f'(x) = \sum_{i=0}^\infty f(x - i * power)
576 void gen_fun::divide(const vec_ZZ
& power
)
578 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
) {
579 int r
= (*i
)->d
.power
.NumRows();
580 int c
= (*i
)->d
.power
.NumCols();
581 (*i
)->d
.power
.SetDims(r
+1, c
);
582 (*i
)->d
.power
[r
] = power
;
585 Vector
*v
= Vector_Alloc(1+power
.length()+1);
586 value_set_si(v
->p
[0], 1);
587 zz2values(power
, v
->p
+1);
588 Polyhedron
*C
= AddRays(v
->p
, 1, context
, context
->NbConstraints
+1);
590 Polyhedron_Free(context
);
594 static void print_power(std::ostream
& os
, QQ
& c
, vec_ZZ
& p
,
595 unsigned int nparam
, char **param_name
)
599 for (int i
= 0; i
< p
.length(); ++i
) {
603 if (c
.n
== -1 && c
.d
== 1)
605 else if (c
.n
!= 1 || c
.d
!= 1) {
621 os
<< "^(" << p
[i
] << ")";
632 void gen_fun::print(std::ostream
& os
, unsigned int nparam
, char **param_name
) const
635 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
) {
636 if (i
!= term
.begin())
639 for (int j
= 0; j
< (*i
)->n
.coeff
.length(); ++j
) {
640 if (j
!= 0 && (*i
)->n
.coeff
[j
].n
> 0)
642 print_power(os
, (*i
)->n
.coeff
[j
], (*i
)->n
.power
[j
],
646 for (int j
= 0; j
< (*i
)->d
.power
.NumRows(); ++j
) {
650 print_power(os
, mone
, (*i
)->d
.power
[j
], nparam
, param_name
);
657 gen_fun::operator evalue
*() const
661 value_init(factor
.d
);
662 value_init(factor
.x
.n
);
663 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
) {
664 unsigned nvar
= (*i
)->d
.power
.NumRows();
665 unsigned nparam
= (*i
)->d
.power
.NumCols();
666 Matrix
*C
= Matrix_Alloc(nparam
+ nvar
, 1 + nvar
+ nparam
+ 1);
667 mat_ZZ
& d
= (*i
)->d
.power
;
668 Polyhedron
*U
= context
? context
: Universe_Polyhedron(nparam
);
670 for (int j
= 0; j
< (*i
)->n
.coeff
.length(); ++j
) {
671 for (int r
= 0; r
< nparam
; ++r
) {
672 value_set_si(C
->p
[r
][0], 0);
673 for (int c
= 0; c
< nvar
; ++c
) {
674 zz2value(d
[c
][r
], C
->p
[r
][1+c
]);
676 Vector_Set(&C
->p
[r
][1+nvar
], 0, nparam
);
677 value_set_si(C
->p
[r
][1+nvar
+r
], -1);
678 zz2value((*i
)->n
.power
[j
][r
], C
->p
[r
][1+nvar
+nparam
]);
680 for (int r
= 0; r
< nvar
; ++r
) {
681 value_set_si(C
->p
[nparam
+r
][0], 1);
682 Vector_Set(&C
->p
[nparam
+r
][1], 0, nvar
+ nparam
+ 1);
683 value_set_si(C
->p
[nparam
+r
][1+r
], 1);
685 Polyhedron
*P
= Constraints2Polyhedron(C
, 0);
686 evalue
*E
= barvinok_enumerate_ev(P
, U
, 0);
688 if (EVALUE_IS_ZERO(*E
)) {
693 zz2value((*i
)->n
.coeff
[j
].n
, factor
.x
.n
);
694 zz2value((*i
)->n
.coeff
[j
].d
, factor
.d
);
697 Matrix_Print(stdout, P_VALUE_FMT, C);
698 char *test[] = { "A", "B", "C", "D", "E", "F", "G" };
699 print_evalue(stdout, E, test);
713 value_clear(factor
.d
);
714 value_clear(factor
.x
.n
);
718 void gen_fun::coefficient(Value
* params
, Value
* c
) const
720 if (context
&& !in_domain(context
, params
)) {
727 value_init(part
.x
.n
);
730 evalue_set_si(&sum
, 0, 1);
734 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
) {
735 unsigned nvar
= (*i
)->d
.power
.NumRows();
736 unsigned nparam
= (*i
)->d
.power
.NumCols();
737 Matrix
*C
= Matrix_Alloc(nparam
+ nvar
, 1 + nvar
+ 1);
738 mat_ZZ
& d
= (*i
)->d
.power
;
740 for (int j
= 0; j
< (*i
)->n
.coeff
.length(); ++j
) {
741 C
->NbRows
= nparam
+nvar
;
742 for (int r
= 0; r
< nparam
; ++r
) {
743 value_set_si(C
->p
[r
][0], 0);
744 for (int c
= 0; c
< nvar
; ++c
) {
745 zz2value(d
[c
][r
], C
->p
[r
][1+c
]);
747 zz2value((*i
)->n
.power
[j
][r
], C
->p
[r
][1+nvar
]);
748 value_subtract(C
->p
[r
][1+nvar
], C
->p
[r
][1+nvar
], params
[r
]);
750 for (int r
= 0; r
< nvar
; ++r
) {
751 value_set_si(C
->p
[nparam
+r
][0], 1);
752 Vector_Set(&C
->p
[nparam
+r
][1], 0, nvar
+ 1);
753 value_set_si(C
->p
[nparam
+r
][1+r
], 1);
755 Polyhedron
*P
= Constraints2Polyhedron(C
, 0);
760 barvinok_count(P
, &tmp
, 0);
762 if (value_zero_p(tmp
))
764 zz2value((*i
)->n
.coeff
[j
].n
, part
.x
.n
);
765 zz2value((*i
)->n
.coeff
[j
].d
, part
.d
);
766 value_multiply(part
.x
.n
, part
.x
.n
, tmp
);
772 assert(value_one_p(sum
.d
));
773 value_assign(*c
, sum
.x
.n
);
777 value_clear(part
.x
.n
);
779 value_clear(sum
.x
.n
);
782 gen_fun
*gen_fun::summate(int nvar
, barvinok_options
*options
) const
784 int dim
= context
->Dimension
;
785 int nparam
= dim
- nvar
;
789 if (options
->incremental_specialization
== 1) {
790 red
= new partial_ireducer(Polyhedron_Project(context
, nparam
), dim
, nparam
);
792 red
= new partial_reducer(Polyhedron_Project(context
, nparam
), dim
, nparam
);
794 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
)
795 for (int j
= 0; j
< (*i
)->n
.power
.NumRows(); ++j
)
796 red
->reduce((*i
)->n
.coeff
[j
], (*i
)->n
.power
[j
], (*i
)->d
.power
);
802 /* returns true if the set was finite and false otherwise */
803 bool gen_fun::summate(Value
*sum
) const
805 if (term
.size() == 0) {
806 value_set_si(*sum
, 0);
811 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
)
812 if ((*i
)->d
.power
.NumRows() > maxlen
)
813 maxlen
= (*i
)->d
.power
.NumRows();
815 infinite_icounter
cnt((*term
.begin())->d
.power
.NumCols(), maxlen
);
816 for (short_rat_list::iterator i
= term
.begin(); i
!= term
.end(); ++i
)
817 for (int j
= 0; j
< (*i
)->n
.power
.NumRows(); ++j
)
818 cnt
.reduce((*i
)->n
.coeff
[j
], (*i
)->n
.power
[j
], (*i
)->d
.power
);
820 for (int i
= 1; i
<= maxlen
; ++i
)
821 if (value_notzero_p(mpq_numref(cnt
.count
[i
]))) {
822 value_set_si(*sum
, -1);
826 assert(value_one_p(mpq_denref(cnt
.count
[0])));
827 value_assign(*sum
, mpq_numref(cnt
.count
[0]));