3 #include <barvinok/barvinok.h>
4 #include <barvinok/set.h>
5 #include <barvinok/options.h>
6 #include <barvinok/basis_reduction.h>
7 #include <barvinok/evalue.h>
8 #include <barvinok/util.h>
9 #include "conversion.h"
10 #include "evalue_read.h"
12 #include "lattice_point.h"
14 #include "bernoulli.h"
19 #include "matrix_read.h"
20 #include "remove_equalities.h"
28 void set_from_string(T
& v
, const char *s
)
30 std::istringstream
str(s
);
34 static Matrix
*matrix_read_from_str(const char *s
)
36 std::istringstream
str(s
);
37 return Matrix_Read(str
);
40 static int test_equalities(struct barvinok_options
*options
)
42 Matrix
*M
= matrix_read_from_str(
44 " 0 23 0 0 -10 0 0 0 7 -44 -8 \n"
45 " 0 0 23 0 5 0 0 0 -15 114 27 \n"
46 " 0 0 0 1 0 0 0 0 0 -1 2 \n"
47 " 0 0 0 0 0 1 0 0 -1 8 0 \n"
48 " 0 0 0 0 0 0 1 0 0 -1 2 \n"
49 " 0 0 0 0 0 0 0 1 0 -1 -1 \n"
50 " 1 0 0 0 10 0 0 0 -7 44 8 \n"
51 " 1 0 0 0 -5 0 0 0 15 -114 -27 \n"
52 " 1 0 0 0 1 0 0 0 0 0 0 \n"
53 " 1 0 0 0 0 0 0 0 1 -8 0 \n"
54 " 1 0 0 0 0 0 0 0 0 1 -2 \n");
55 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
58 remove_all_equalities(&P
, NULL
, NULL
, NULL
, 2, options
->MaxRays
);
66 int test_evalue_read(struct barvinok_options
*options
)
68 unsigned nvar
, nparam
;
69 const char **all_vars
;
72 e1
= evalue_read_from_str("(1 * aa + 2 * a)",
73 NULL
, &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
74 Free_ParamNames(all_vars
, nvar
+nparam
);
75 e2
= evalue_read_from_str("(3 * aa)",
76 NULL
, &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
77 Free_ParamNames(all_vars
, nvar
+nparam
);
78 assert(!eequal(e1
, e2
));
84 static void evalue_check_disjoint(evalue
*e
)
90 if (EVALUE_IS_ZERO(*e
))
92 for (i
= 0; i
< e
->x
.p
->size
/2; ++i
) {
93 Polyhedron
*A
= EVALUE_DOMAIN(e
->x
.p
->arr
[2*i
]);
94 for (j
= i
+1; j
< e
->x
.p
->size
/2; ++j
) {
95 Polyhedron
*B
= EVALUE_DOMAIN(e
->x
.p
->arr
[2*j
]);
96 Polyhedron
*I
= DomainIntersection(A
, B
, 0);
103 static int test_eadd(struct barvinok_options
*options
)
105 unsigned nvar
, nparam
;
106 const char **all_vars
;
109 e1
= evalue_read_from_str(" d -1 = 0\n"
114 "d,h", &all_vars
, &nvar
, &nparam
,
116 Free_ParamNames(all_vars
, nvar
+nparam
);
117 e2
= evalue_read_from_str(
129 "d,h", &all_vars
, &nvar
, &nparam
,
131 Free_ParamNames(all_vars
, nvar
+nparam
);
133 evalue_check_disjoint(e1
);
139 int test_evalue(struct barvinok_options
*options
)
141 unsigned nvar
, nparam
;
142 const char **all_vars
;
143 evalue
*poly1
, poly2
;
145 poly1
= evalue_read_from_str("(1/4 * n^4 + 1/2 * n^3 + 1/4 * n^2)",
146 NULL
, &all_vars
, &nvar
, &nparam
,
148 Free_ParamNames(all_vars
, nvar
+nparam
);
151 evalue_copy(&poly2
, poly1
);
152 evalue_negate(poly1
);
154 reduce_evalue(poly1
);
155 assert(EVALUE_IS_ZERO(*poly1
));
157 free_evalue_refs(&poly2
);
161 int test_substitute(struct barvinok_options
*options
)
163 unsigned nvar
, nparam
;
164 const char **all_vars
;
165 const char *vars
= "a,b";
169 e1
= evalue_read_from_str("[ { 1/3 * a } = 0 ] * \n"
170 " ([ { 1/5 * b + 2/5 } = 0 ] * 5) + \n"
171 "[ { 1/3 * a } != 0 ] * 42",
172 vars
, &all_vars
, &nvar
, &nparam
,
174 Free_ParamNames(all_vars
, nvar
+nparam
);
176 subs
[0] = evalue_read_from_str("(2 * b + 5)",
177 vars
, &all_vars
, &nvar
, &nparam
,
179 Free_ParamNames(all_vars
, nvar
+nparam
);
180 subs
[1] = evalue_read_from_str("(a + 1)",
181 vars
, &all_vars
, &nvar
, &nparam
,
183 Free_ParamNames(all_vars
, nvar
+nparam
);
185 evalue_substitute(e1
, subs
);
186 evalue_free(subs
[0]);
187 evalue_free(subs
[1]);
190 e2
= evalue_read_from_str("[ { 2/3 * b + 2/3 } = 0 ] * \n"
191 " ([ { 1/5 * a + 3/5 } = 0 ] * 5) + \n"
192 "[ { 2/3 * b + 2/3 } != 0 ] * 42",
193 vars
, &all_vars
, &nvar
, &nparam
,
195 Free_ParamNames(all_vars
, nvar
+nparam
);
198 assert(eequal(e1
, e2
));
205 int test_specialization(struct barvinok_options
*options
)
214 assert(value_cmp_si(n
.coeff
->p
[0], 1) == 0);
215 assert(value_cmp_si(n
.coeff
->p
[1], 5) == 0);
216 assert(value_cmp_si(n
.coeff
->p
[2], 10) == 0);
223 assert(value_cmp_si(d
.coeff
->p
[0], 2) == 0);
224 assert(value_cmp_si(d
.coeff
->p
[1], 1) == 0);
225 assert(value_cmp_si(d
.coeff
->p
[2], 0) == 0);
228 mpq_canonicalize(count
);
229 assert(value_cmp_si(mpq_numref(count
), 31) == 0);
230 assert(value_cmp_si(mpq_denref(count
), 8) == 0);
234 assert(value_cmp_si(n2
.coeff
->p
[0], 1) == 0);
235 assert(value_cmp_si(n2
.coeff
->p
[1], -2) == 0);
236 assert(value_cmp_si(n2
.coeff
->p
[2], 3) == 0);
239 mpq_canonicalize(count
);
240 assert(value_cmp_si(mpq_numref(count
), 6) == 0);
241 assert(value_cmp_si(mpq_denref(count
), 1) == 0);
248 int test_lattice_points(struct barvinok_options
*options
)
252 set_from_string(tmp
, "[[0 0 0 0 4][0 0 0 0 4][-1 0 1 0 4]]");
253 V
.Vertex
= zz2matrix(tmp
);
255 set_from_string(lambda
, "[3 5 7]");
257 set_from_string(rays
, "[[0 1 0][4 0 1][0 0 -1]]");
261 unsigned nvar
, nparam
;
262 const char **all_vars
;
263 point
[0] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
264 "( 7 * {( 1/4 * a + ( 3/4 * c + 3/4 ) ) } + -21/4 ) ) )",
265 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
266 Free_ParamNames(all_vars
, nvar
+nparam
);
267 point
[1] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
268 "( 7 * {( 1/4 * a + ( 3/4 * c + 1/2 ) ) } + -1/2 ) ) )",
269 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
270 Free_ParamNames(all_vars
, nvar
+nparam
);
271 point
[2] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
272 "( 7 * {( 1/4 * a + ( 3/4 * c + 1/4 ) ) } + 17/4 ) ) )",
273 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
274 Free_ParamNames(all_vars
, nvar
+nparam
);
275 point
[3] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
276 "( 7 * {( 1/4 * a + ( 3/4 * c + 0 ) ) } + 9 ) ) )",
277 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
278 Free_ParamNames(all_vars
, nvar
+nparam
);
280 lattice_point(&V
, rays
, lambda
, &num
, 4, options
);
281 Matrix_Free(V
.Vertex
);
283 for (int i
= 0; i
< 4; ++i
) {
284 assert(eequal(num
.E
[i
], point
[i
]));
285 evalue_free(point
[i
]);
286 evalue_free(num
.E
[i
]);
292 static int test_icounter(struct barvinok_options
*options
)
298 set_from_string(n_coeff
, "[-2/1 1/1]");
299 set_from_string(n_power
, "[[2 6][3 6]]");
300 d_power
.SetDims(0, 2);
301 cnt
.reduce(n_coeff
, n_power
, d_power
);
302 assert(value_cmp_si(mpq_numref(cnt
.count
), -1) == 0);
303 assert(value_cmp_si(mpq_denref(cnt
.count
), 1) == 0);
307 static int test_infinite_counter(struct barvinok_options
*options
)
309 Matrix
*M
= matrix_read_from_str("1 3\n 1 1 0\n");
310 Polyhedron
*ctx
= Constraints2Polyhedron(M
, options
->MaxRays
);
313 /* (1 -1/2 x^5 - 1/2 x^7)/(1-x) */
314 infinite_counter
*cnt
= new infinite_counter(1, 1);
319 set_from_string(n_coeff
, "[1/1 -1/2 -1/2]");
320 set_from_string(n_power
, "[[0][5][7]]");
321 set_from_string(d_power
, "[[1]]");
322 cnt
->reduce(n_coeff
, n_power
, d_power
);
323 assert(value_cmp_si(mpq_numref(cnt
->count
[0]), 6) == 0);
324 assert(value_cmp_si(mpq_denref(cnt
->count
[0]), 1) == 0);
325 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) == 0);
326 assert(value_cmp_si(mpq_denref(cnt
->count
[1]), 1) == 0);
328 Polyhedron_Free(ctx
);
330 M
= matrix_read_from_str("2 4\n 1 1 0 0\n 1 0 1 0\n");
331 ctx
= Constraints2Polyhedron(M
, options
->MaxRays
);
334 /* (1 - xy)/((1-x)(1-xy)) */
335 cnt
= new infinite_counter(2, 3);
337 set_from_string(n_coeff
, "[1/1 -1/1]");
338 set_from_string(n_power
, "[[0 0][1 1]]");
339 set_from_string(d_power
, "[[1 0][1 1]]");
340 cnt
->reduce(n_coeff
, n_power
, d_power
);
341 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) != 0);
342 assert(value_cmp_si(mpq_numref(cnt
->count
[2]), 0) == 0);
343 assert(value_cmp_si(mpq_denref(cnt
->count
[2]), 1) == 0);
344 assert(value_cmp_si(mpq_numref(cnt
->count
[3]), 0) == 0);
345 assert(value_cmp_si(mpq_denref(cnt
->count
[3]), 1) == 0);
348 cnt
= new infinite_counter(2, 2);
350 set_from_string(n_coeff
, "[-1/2 1/1 -1/3]");
351 set_from_string(n_power
, "[[2 6][3 6]]");
352 d_power
.SetDims(0, 2);
353 cnt
->reduce(n_coeff
, n_power
, d_power
);
354 assert(value_cmp_si(mpq_numref(cnt
->count
[0]), 1) == 0);
355 assert(value_cmp_si(mpq_denref(cnt
->count
[0]), 6) == 0);
356 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) == 0);
357 assert(value_cmp_si(mpq_denref(cnt
->count
[1]), 1) == 0);
358 assert(value_cmp_si(mpq_numref(cnt
->count
[2]), 0) == 0);
359 assert(value_cmp_si(mpq_denref(cnt
->count
[2]), 1) == 0);
362 cnt
= new infinite_counter(2, 2);
364 set_from_string(n_coeff
, "[1/1]");
365 set_from_string(n_power
, "[[0 11]]");
366 set_from_string(d_power
, "[[0 1]]");
367 cnt
->reduce(n_coeff
, n_power
, d_power
);
368 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) != 0);
369 assert(value_cmp_si(mpq_numref(cnt
->count
[2]), 0) == 0);
370 assert(value_cmp_si(mpq_denref(cnt
->count
[2]), 1) == 0);
373 Polyhedron_Free(ctx
);
378 static int test_series(struct barvinok_options
*options
)
380 Matrix
*M
= matrix_read_from_str(
382 " 0 1 0 0 0 0 0 1 0 0 3 \n"
383 " 0 0 1 0 0 0 0 -1 1 0 -5 \n"
384 " 0 0 0 1 0 0 0 0 -2 -1 6 \n"
385 " 0 0 0 0 1 0 0 1 1 0 5 \n"
386 " 0 0 0 0 0 1 0 0 -1 0 0 \n"
387 " 0 0 0 0 0 0 1 -2 0 -1 -3 \n"
388 " 1 0 0 0 0 0 0 2 0 1 3 \n"
389 " 1 0 0 0 0 0 0 1 -1 0 5 \n"
390 " 1 0 0 0 0 0 0 -1 -1 0 -5 \n"
391 " 1 0 0 0 0 0 0 -1 0 0 -3 \n"
392 " 1 0 0 0 0 0 0 0 2 1 -6 \n"
393 " 1 0 0 0 0 0 0 0 1 0 0 \n");
394 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
396 Polyhedron
*C
= Universe_Polyhedron(3);
397 gen_fun
*gf
= barvinok_series_with_options(P
, C
, options
);
402 M
= matrix_read_from_str(
404 " 0 1 1 0 0 1 0 2 \n"
405 " 0 0 0 1 0 -2 0 6 \n"
406 " 0 0 0 0 1 -1 0 -1 \n"
407 " 0 0 0 0 0 0 1 0 \n"
408 " 1 0 1 0 0 0 0 0 \n"
409 " 1 0 -1 0 0 -1 0 -2 \n"
410 " 1 0 0 0 0 1 0 -3 \n");
411 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
413 C
= Universe_Polyhedron(2);
414 gf
= barvinok_series_with_options(P
, C
, options
);
419 M
= matrix_read_from_str(
423 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
425 C
= Universe_Polyhedron(1);
426 gf
= barvinok_series_with_options(P
, C
, options
);
429 gen_fun
*sum
= gf
->summate(1, options
);
436 int test_todd(struct barvinok_options
*options
)
438 tcounter
t(2, options
->max_index
);
439 assert(value_cmp_si(t
.todd
.coeff
->p
[0], 1) == 0);
440 assert(value_cmp_si(t
.todd
.coeff
->p
[1], -3) == 0);
441 assert(value_cmp_si(t
.todd
.coeff
->p
[2], 3) == 0);
442 assert(value_cmp_si(t
.todd_denom
->p
[0], 1) == 0);
443 assert(value_cmp_si(t
.todd_denom
->p
[1], 6) == 0);
444 assert(value_cmp_si(t
.todd_denom
->p
[2], 36) == 0);
447 set_from_string(lambda
, "[1 -1]");
448 zz2values(lambda
, t
.lambda
->p
);
451 set_from_string(rays
, "[[-1 0][-1 1]]");
456 set_from_string(v
, "[2 0 1]");
457 Vector
*vertex
= Vector_Alloc(3);
458 zz2values(v
, vertex
->p
);
460 t
.handle(rays
, vertex
->p
, one
, 1, options
);
461 assert(value_cmp_si(mpq_numref(t
.count
), 71) == 0);
462 assert(value_cmp_si(mpq_denref(t
.count
), 24) == 0);
464 set_from_string(rays
, "[[0 -1][1 -1]]");
465 set_from_string(v
, "[0 2 1]");
466 zz2values(v
, vertex
->p
);
468 t
.handle(rays
, vertex
->p
, one
, 1, options
);
469 assert(value_cmp_si(mpq_numref(t
.count
), 71) == 0);
470 assert(value_cmp_si(mpq_denref(t
.count
), 12) == 0);
472 set_from_string(rays
, "[[1 0][0 1]]");
473 set_from_string(v
, "[0 0 1]");
474 zz2values(v
, vertex
->p
);
476 t
.handle(rays
, vertex
->p
, one
, 1, options
);
477 assert(value_cmp_si(mpq_numref(t
.count
), 6) == 0);
478 assert(value_cmp_si(mpq_denref(t
.count
), 1) == 0);
484 int test_bernoulli(struct barvinok_options
*options
)
486 struct bernoulli_coef
*bernoulli_coef
;
487 struct poly_list
*faulhaber
, *bernoulli
;
488 bernoulli_coef
= bernoulli_coef_compute(2);
489 faulhaber
= faulhaber_compute(4);
490 bernoulli_coef
= bernoulli_coef_compute(8);
491 assert(value_cmp_si(bernoulli_coef
->num
->p
[6], 1) == 0);
492 assert(value_cmp_si(bernoulli_coef
->den
->p
[6], 42) == 0);
493 assert(value_cmp_si(faulhaber
->poly
[3]->p
[0], 0) == 0);
494 assert(value_cmp_si(faulhaber
->poly
[3]->p
[1], 0) == 0);
495 assert(value_cmp_si(faulhaber
->poly
[3]->p
[2], 1) == 0);
496 assert(value_cmp_si(faulhaber
->poly
[3]->p
[3], -2) == 0);
497 assert(value_cmp_si(faulhaber
->poly
[3]->p
[4], 1) == 0);
498 assert(value_cmp_si(faulhaber
->poly
[3]->p
[5], 4) == 0);
500 bernoulli
= bernoulli_compute(6);
501 assert(value_cmp_si(bernoulli
->poly
[6]->p
[0], 1) == 0);
502 assert(value_cmp_si(bernoulli
->poly
[6]->p
[1], 0) == 0);
503 assert(value_cmp_si(bernoulli
->poly
[6]->p
[2], -21) == 0);
504 assert(value_cmp_si(bernoulli
->poly
[6]->p
[3], 0) == 0);
505 assert(value_cmp_si(bernoulli
->poly
[6]->p
[4], 105) == 0);
506 assert(value_cmp_si(bernoulli
->poly
[6]->p
[5], -126) == 0);
507 assert(value_cmp_si(bernoulli
->poly
[6]->p
[6], 42) == 0);
508 assert(value_cmp_si(bernoulli
->poly
[6]->p
[7], 42) == 0);
510 unsigned nvar
, nparam
;
511 const char **all_vars
;
512 evalue
*base
, *sum1
, *sum2
;
513 base
= evalue_read_from_str("(1 * n + 1)", NULL
, &all_vars
, &nvar
, &nparam
,
516 sum1
= evalue_polynomial(faulhaber
->poly
[3], base
);
517 Free_ParamNames(all_vars
, nvar
+nparam
);
519 sum2
= evalue_read_from_str("(1/4 * n^4 + 1/2 * n^3 + 1/4 * n^2)",
520 NULL
, &all_vars
, &nvar
, &nparam
,
522 Free_ParamNames(all_vars
, nvar
+nparam
);
523 assert(eequal(sum1
, sum2
));
530 int test_bernoulli_sum(struct barvinok_options
*options
)
532 int summation
= options
->summation
;
533 options
->summation
= BV_SUM_BERNOULLI
;
535 unsigned nvar
, nparam
;
536 const char **all_vars
;
537 evalue
*e
, *sum1
, *sum2
;
538 e
= evalue_read_from_str("i + -1 >= 0\n -i + n >= 0\n\n 1 + (-1 *i) + i^2",
539 "i", &all_vars
, &nvar
, &nparam
,
541 Free_ParamNames(all_vars
, nvar
+nparam
);
543 sum1
= barvinok_summate(e
, 1, options
);
544 sum2
= evalue_read_from_str("n -1 >= 0\n\n (1/3 * n^3 + 2/3 * n)",
545 NULL
, &all_vars
, &nvar
, &nparam
,
547 Free_ParamNames(all_vars
, nvar
+nparam
);
551 assert(EVALUE_IS_ZERO(*sum1
));
555 e
= evalue_read_from_str("-i + -1 >= 0\n i + n >= 0\n\n 1 + i + i^2",
556 "i", &all_vars
, &nvar
, &nparam
,
558 Free_ParamNames(all_vars
, nvar
+nparam
);
559 sum1
= barvinok_summate(e
, 1, options
);
563 assert(EVALUE_IS_ZERO(*sum1
));
569 e
= evalue_read_from_str("i + 4 >= 0\n -i + n >= 0\n\n i",
570 "i", &all_vars
, &nvar
, &nparam
,
572 Free_ParamNames(all_vars
, nvar
+nparam
);
573 sum1
= barvinok_summate(e
, 1, options
);
574 sum2
= evalue_read_from_str("n + 0 >= 0\n\n (1/2 * n^2 + 1/2 * n + (-10))\n"
575 "n + 4 >= 0\n -n -1 >= 0\n\n (1/2 * n^2 + 1/2 * n + (-10))",
576 NULL
, &all_vars
, &nvar
, &nparam
,
578 Free_ParamNames(all_vars
, nvar
+nparam
);
582 assert(EVALUE_IS_ZERO(*sum1
));
587 e
= evalue_read_from_str("i -5 >= 0\n -i + n >= 0\n j -1 >= 0\n i -j >= 0\n"
588 "k -1 >= 0\n j -k >= 0\n\n1",
589 "i,j,k", &all_vars
, &nvar
, &nparam
,
591 Free_ParamNames(all_vars
, nvar
+nparam
);
592 sum1
= barvinok_summate(e
, 3, options
);
593 sum2
= evalue_read_from_str("n -5 >= 0\n\n"
594 "1/6 * n^3 + 1/2 * n^2 + 1/3 * n + -20",
595 NULL
, &all_vars
, &nvar
, &nparam
,
597 Free_ParamNames(all_vars
, nvar
+nparam
);
601 assert(EVALUE_IS_ZERO(*sum1
));
606 options
->summation
= summation
;
610 int test_hilbert(struct barvinok_options
*options
)
613 Matrix
*M
= matrix_read_from_str(
617 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
620 M
= Cone_Hilbert_Basis(P
, options
->MaxRays
);
621 assert(M
->NbRows
== 5);
622 assert(M
->NbColumns
== 3);
625 M
= Cone_Integer_Hull(P
, NULL
, 0, options
);
626 assert(M
->NbRows
== 4);
627 assert(M
->NbColumns
== 3);
635 int test_ilp(struct barvinok_options
*options
)
637 Matrix
*M
= matrix_read_from_str(
641 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
643 Vector
*obj
= Vector_Alloc(2);
644 value_set_si(obj
->p
[0], 7);
645 value_set_si(obj
->p
[1], -1);
650 value_set_si(min
, 1);
651 value_set_si(max
, 17);
652 Vector
*opt
= Polyhedron_Integer_Minimum(P
, obj
->p
, min
, max
,
655 assert(value_cmp_si(opt
->p
[0], 1) == 0);
656 assert(value_cmp_si(opt
->p
[1], 1) == 0);
657 assert(value_cmp_si(opt
->p
[2], 1) == 0);
667 int test_hull(struct barvinok_options
*options
)
669 Matrix
*M
= matrix_read_from_str(
675 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
678 Matrix
*hull
= Polyhedron_Integer_Hull(P
, options
);
680 assert(hull
->NbRows
== 4);
681 M
= Matrix_Alloc(hull
->NbRows
, 1+hull
->NbColumns
);
682 for (int i
= 0; i
< hull
->NbRows
; ++i
) {
683 value_set_si(M
->p
[i
][0], 1);
684 Vector_Copy(hull
->p
[i
], M
->p
[i
]+1, hull
->NbColumns
);
687 Polyhedron
*H
= Constraints2Polyhedron(M
, options
->MaxRays
);
690 M
= matrix_read_from_str(
696 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
698 assert(PolyhedronIncludes(P
, H
) && PolyhedronIncludes(H
, P
));
702 M
= matrix_read_from_str(
707 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
710 hull
= Polyhedron_Integer_Hull(P
, options
);
712 assert(hull
->NbRows
== 0);
717 static int test_laurent(struct barvinok_options
*options
)
719 unsigned nvar
, nparam
;
720 const char **all_vars
;
721 evalue
*e
, *sum
, *res
;
723 e
= evalue_read_from_str(" x1 >= 0\n"
725 " -x1 -x2 + 2 >= 0\n"
728 "x1,x2", &all_vars
, &nvar
, &nparam
,
730 Free_ParamNames(all_vars
, nvar
+nparam
);
732 int summation
= options
->summation
;
733 options
->summation
= BV_SUM_LAURENT
;
734 sum
= barvinok_summate(e
, nvar
, options
);
735 options
->summation
= summation
;
737 res
= evalue_read_from_str("(6 * N + 4 * M)",
738 "", &all_vars
, &nvar
, &nparam
,
740 Free_ParamNames(all_vars
, nvar
+nparam
);
742 assert(value_zero_p(sum
->d
));
743 assert(sum
->x
.p
->type
== partition
);
744 assert(sum
->x
.p
->size
== 2);
746 assert(eequal(res
, &sum
->x
.p
->arr
[1]));
754 /* Check that Polyhedron_Reduced_Basis produces a result
755 * of the expected dimensions (without crashing).
757 static int test_basis_reduction(struct barvinok_options
*options
)
762 M
= matrix_read_from_str(
768 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
771 M
= Polyhedron_Reduced_Basis(P
, options
);
774 assert(M
->NbRows
== 2);
775 assert(M
->NbColumns
== 2);
783 int main(int argc
, char **argv
)
785 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
786 test_equalities(options
);
787 test_evalue_read(options
);
789 test_evalue(options
);
790 test_substitute(options
);
791 test_specialization(options
);
792 test_lattice_points(options
);
793 test_icounter(options
);
794 test_infinite_counter(options
);
795 test_series(options
);
797 test_bernoulli(options
);
798 test_bernoulli_sum(options
);
799 test_hilbert(options
);
802 test_laurent(options
);
803 test_basis_reduction(options
);
804 barvinok_options_free(options
);