3 #include <barvinok/barvinok.h>
4 #include <barvinok/set.h>
5 #include <barvinok/options.h>
6 #include <barvinok/evalue.h>
7 #include <barvinok/util.h>
8 #include "conversion.h"
9 #include "evalue_read.h"
11 #include "lattice_point.h"
13 #include "bernoulli.h"
17 #include "matrix_read.h"
18 #include "remove_equalities.h"
26 void set_from_string(T
& v
, const char *s
)
28 std::istringstream
str(s
);
32 static Matrix
*matrix_read_from_str(const char *s
)
34 std::istringstream
str(s
);
35 return Matrix_Read(str
);
38 static int test_equalities(struct barvinok_options
*options
)
40 Matrix
*M
= matrix_read_from_str(
42 " 0 23 0 0 -10 0 0 0 7 -44 -8 \n"
43 " 0 0 23 0 5 0 0 0 -15 114 27 \n"
44 " 0 0 0 1 0 0 0 0 0 -1 2 \n"
45 " 0 0 0 0 0 1 0 0 -1 8 0 \n"
46 " 0 0 0 0 0 0 1 0 0 -1 2 \n"
47 " 0 0 0 0 0 0 0 1 0 -1 -1 \n"
48 " 1 0 0 0 10 0 0 0 -7 44 8 \n"
49 " 1 0 0 0 -5 0 0 0 15 -114 -27 \n"
50 " 1 0 0 0 1 0 0 0 0 0 0 \n"
51 " 1 0 0 0 0 0 0 0 1 -8 0 \n"
52 " 1 0 0 0 0 0 0 0 0 1 -2 \n");
53 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
56 remove_all_equalities(&P
, NULL
, NULL
, NULL
, 2, options
->MaxRays
);
63 int test_evalue_read(struct barvinok_options
*options
)
65 unsigned nvar
, nparam
;
69 e1
= evalue_read_from_str("(1 * aa + 2 * a)",
70 NULL
, &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
71 Free_ParamNames(all_vars
, nvar
+nparam
);
72 e2
= evalue_read_from_str("(3 * aa)",
73 NULL
, &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
74 Free_ParamNames(all_vars
, nvar
+nparam
);
75 assert(!eequal(e1
, e2
));
80 static void evalue_check_disjoint(evalue
*e
)
86 if (EVALUE_IS_ZERO(*e
))
88 for (i
= 0; i
< e
->x
.p
->size
/2; ++i
) {
89 Polyhedron
*A
= EVALUE_DOMAIN(e
->x
.p
->arr
[2*i
]);
90 for (j
= i
+1; j
< e
->x
.p
->size
/2; ++j
) {
91 Polyhedron
*B
= EVALUE_DOMAIN(e
->x
.p
->arr
[2*j
]);
92 Polyhedron
*I
= DomainIntersection(A
, B
, 0);
99 static int test_eadd(struct barvinok_options
*options
)
101 unsigned nvar
, nparam
;
105 e1
= evalue_read_from_str(" d -1 = 0\n"
110 "d,h", &all_vars
, &nvar
, &nparam
,
112 Free_ParamNames(all_vars
, nvar
+nparam
);
113 e2
= evalue_read_from_str(
125 "d,h", &all_vars
, &nvar
, &nparam
,
127 Free_ParamNames(all_vars
, nvar
+nparam
);
129 evalue_check_disjoint(e1
);
134 int test_evalue(struct barvinok_options
*options
)
136 unsigned nvar
, nparam
;
138 evalue
*poly1
, poly2
;
140 poly1
= evalue_read_from_str("(1/4 * n^4 + 1/2 * n^3 + 1/4 * n^2)",
141 NULL
, &all_vars
, &nvar
, &nparam
,
143 Free_ParamNames(all_vars
, nvar
+nparam
);
146 evalue_copy(&poly2
, poly1
);
147 evalue_negate(poly1
);
149 reduce_evalue(poly1
);
150 assert(EVALUE_IS_ZERO(*poly1
));
152 free_evalue_refs(&poly2
);
155 int test_substitute(struct barvinok_options
*options
)
157 unsigned nvar
, nparam
;
159 const char *vars
= "a,b";
163 e1
= evalue_read_from_str("[ { 1/3 * a } = 0 ] * \n"
164 " ([ { 1/5 * b + 2/5 } = 0 ] * 5) + \n"
165 "[ { 1/3 * a } != 0 ] * 42",
166 vars
, &all_vars
, &nvar
, &nparam
,
168 Free_ParamNames(all_vars
, nvar
+nparam
);
170 subs
[0] = evalue_read_from_str("(2 * b + 5)",
171 vars
, &all_vars
, &nvar
, &nparam
,
173 Free_ParamNames(all_vars
, nvar
+nparam
);
174 subs
[1] = evalue_read_from_str("(a + 1)",
175 vars
, &all_vars
, &nvar
, &nparam
,
177 Free_ParamNames(all_vars
, nvar
+nparam
);
179 evalue_substitute(e1
, subs
);
180 evalue_free(subs
[0]);
181 evalue_free(subs
[1]);
184 e2
= evalue_read_from_str("[ { 2/3 * b + 2/3 } = 0 ] * \n"
185 " ([ { 1/5 * a + 3/5 } = 0 ] * 5) + \n"
186 "[ { 2/3 * b + 2/3 } != 0 ] * 42",
187 vars
, &all_vars
, &nvar
, &nparam
,
189 Free_ParamNames(all_vars
, nvar
+nparam
);
192 assert(eequal(e1
, e2
));
198 int test_split_periods(struct barvinok_options
*options
)
200 unsigned nvar
, nparam
;
204 e
= evalue_read_from_str("U + 2V + 3 >= 0\n- U -2V >= 0\n- U 10 >= 0\n"
205 "U >= 0\n\n({( 1/3 * U + ( 2/3 * V + 0 ))})",
206 NULL
, &all_vars
, &nvar
, &nparam
,
208 Free_ParamNames(all_vars
, nvar
+nparam
);
210 evalue_split_periods(e
, 2, options
->MaxRays
);
211 assert(value_zero_p(e
->d
));
212 assert(e
->x
.p
->type
== partition
);
213 assert(e
->x
.p
->size
== 4);
214 assert(value_zero_p(e
->x
.p
->arr
[1].d
));
215 assert(e
->x
.p
->arr
[1].x
.p
->type
== polynomial
);
216 assert(value_zero_p(e
->x
.p
->arr
[3].d
));
217 assert(e
->x
.p
->arr
[3].x
.p
->type
== polynomial
);
221 int test_specialization(struct barvinok_options
*options
)
230 assert(value_cmp_si(n
.coeff
->p
[0], 1) == 0);
231 assert(value_cmp_si(n
.coeff
->p
[1], 5) == 0);
232 assert(value_cmp_si(n
.coeff
->p
[2], 10) == 0);
239 assert(value_cmp_si(d
.coeff
->p
[0], 2) == 0);
240 assert(value_cmp_si(d
.coeff
->p
[1], 1) == 0);
241 assert(value_cmp_si(d
.coeff
->p
[2], 0) == 0);
244 mpq_canonicalize(count
);
245 assert(value_cmp_si(mpq_numref(count
), 31) == 0);
246 assert(value_cmp_si(mpq_denref(count
), 8) == 0);
250 assert(value_cmp_si(n2
.coeff
->p
[0], 1) == 0);
251 assert(value_cmp_si(n2
.coeff
->p
[1], -2) == 0);
252 assert(value_cmp_si(n2
.coeff
->p
[2], 3) == 0);
255 mpq_canonicalize(count
);
256 assert(value_cmp_si(mpq_numref(count
), 6) == 0);
257 assert(value_cmp_si(mpq_denref(count
), 1) == 0);
263 int test_lattice_points(struct barvinok_options
*options
)
267 set_from_string(tmp
, "[[0 0 0 0 4][0 0 0 0 4][-1 0 1 0 4]]");
268 V
.Vertex
= zz2matrix(tmp
);
270 set_from_string(lambda
, "[3 5 7]");
272 set_from_string(rays
, "[[0 1 0][4 0 1][0 0 -1]]");
276 unsigned nvar
, nparam
;
278 point
[0] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
279 "( 7 * {( 1/4 * a + ( 3/4 * c + 3/4 ) ) } + -21/4 ) ) )",
280 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
281 Free_ParamNames(all_vars
, nvar
+nparam
);
282 point
[1] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
283 "( 7 * {( 1/4 * a + ( 3/4 * c + 1/2 ) ) } + -1/2 ) ) )",
284 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
285 Free_ParamNames(all_vars
, nvar
+nparam
);
286 point
[2] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
287 "( 7 * {( 1/4 * a + ( 3/4 * c + 1/4 ) ) } + 17/4 ) ) )",
288 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
289 Free_ParamNames(all_vars
, nvar
+nparam
);
290 point
[3] = evalue_read_from_str("( -7/4 * a + ( 7/4 * c + "
291 "( 7 * {( 1/4 * a + ( 3/4 * c + 0 ) ) } + 9 ) ) )",
292 "a,b,c", &all_vars
, &nvar
, &nparam
, options
->MaxRays
);
293 Free_ParamNames(all_vars
, nvar
+nparam
);
295 lattice_point(&V
, rays
, lambda
, &num
, 4, options
);
296 Matrix_Free(V
.Vertex
);
298 for (int i
= 0; i
< 4; ++i
) {
299 assert(eequal(num
.E
[i
], point
[i
]));
300 evalue_free(point
[i
]);
301 free_evalue_refs(num
.E
[i
]);
307 static int test_icounter(struct barvinok_options
*options
)
313 set_from_string(n_coeff
, "[-2/1 1/1]");
314 set_from_string(n_power
, "[[2 6][3 6]]");
315 d_power
.SetDims(0, 2);
316 cnt
.reduce(n_coeff
, n_power
, d_power
);
317 assert(value_cmp_si(mpq_numref(cnt
.count
), -1) == 0);
318 assert(value_cmp_si(mpq_denref(cnt
.count
), 1) == 0);
321 static int test_infinite_counter(struct barvinok_options
*options
)
323 Matrix
*M
= matrix_read_from_str("1 3\n 1 1 0\n");
324 Polyhedron
*ctx
= Constraints2Polyhedron(M
, options
->MaxRays
);
327 /* (1 -1/2 x^5 - 1/2 x^7)/(1-x) */
328 infinite_counter
*cnt
= new infinite_counter(1, 1);
333 set_from_string(n_coeff
, "[1/1 -1/2 -1/2]");
334 set_from_string(n_power
, "[[0][5][7]]");
335 set_from_string(d_power
, "[[1]]");
336 cnt
->reduce(n_coeff
, n_power
, d_power
);
337 assert(value_cmp_si(mpq_numref(cnt
->count
[0]), 6) == 0);
338 assert(value_cmp_si(mpq_denref(cnt
->count
[0]), 1) == 0);
339 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) == 0);
340 assert(value_cmp_si(mpq_denref(cnt
->count
[1]), 1) == 0);
342 Polyhedron_Free(ctx
);
344 M
= matrix_read_from_str("2 4\n 1 1 0 0\n 1 0 1 0\n");
345 ctx
= Constraints2Polyhedron(M
, options
->MaxRays
);
348 /* (1 - xy)/((1-x)(1-xy)) */
349 cnt
= new infinite_counter(2, 3);
351 set_from_string(n_coeff
, "[1/1 -1/1]");
352 set_from_string(n_power
, "[[0 0][1 1]]");
353 set_from_string(d_power
, "[[1 0][1 1]]");
354 cnt
->reduce(n_coeff
, n_power
, d_power
);
355 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) != 0);
356 assert(value_cmp_si(mpq_numref(cnt
->count
[2]), 0) == 0);
357 assert(value_cmp_si(mpq_denref(cnt
->count
[2]), 1) == 0);
358 assert(value_cmp_si(mpq_numref(cnt
->count
[3]), 0) == 0);
359 assert(value_cmp_si(mpq_denref(cnt
->count
[3]), 1) == 0);
362 cnt
= new infinite_counter(2, 2);
364 set_from_string(n_coeff
, "[-1/2 1/1 -1/3]");
365 set_from_string(n_power
, "[[2 6][3 6]]");
366 d_power
.SetDims(0, 2);
367 cnt
->reduce(n_coeff
, n_power
, d_power
);
368 assert(value_cmp_si(mpq_numref(cnt
->count
[0]), 1) == 0);
369 assert(value_cmp_si(mpq_denref(cnt
->count
[0]), 6) == 0);
370 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) == 0);
371 assert(value_cmp_si(mpq_denref(cnt
->count
[1]), 1) == 0);
372 assert(value_cmp_si(mpq_numref(cnt
->count
[2]), 0) == 0);
373 assert(value_cmp_si(mpq_denref(cnt
->count
[2]), 1) == 0);
376 cnt
= new infinite_counter(2, 2);
378 set_from_string(n_coeff
, "[1/1]");
379 set_from_string(n_power
, "[[0 11]]");
380 set_from_string(d_power
, "[[0 1]]");
381 cnt
->reduce(n_coeff
, n_power
, d_power
);
382 assert(value_cmp_si(mpq_numref(cnt
->count
[1]), 0) != 0);
383 assert(value_cmp_si(mpq_numref(cnt
->count
[2]), 0) == 0);
384 assert(value_cmp_si(mpq_denref(cnt
->count
[2]), 1) == 0);
387 Polyhedron_Free(ctx
);
392 static int test_series(struct barvinok_options
*options
)
394 Matrix
*M
= matrix_read_from_str(
396 " 0 1 0 0 0 0 0 1 0 0 3 \n"
397 " 0 0 1 0 0 0 0 -1 1 0 -5 \n"
398 " 0 0 0 1 0 0 0 0 -2 -1 6 \n"
399 " 0 0 0 0 1 0 0 1 1 0 5 \n"
400 " 0 0 0 0 0 1 0 0 -1 0 0 \n"
401 " 0 0 0 0 0 0 1 -2 0 -1 -3 \n"
402 " 1 0 0 0 0 0 0 2 0 1 3 \n"
403 " 1 0 0 0 0 0 0 1 -1 0 5 \n"
404 " 1 0 0 0 0 0 0 -1 -1 0 -5 \n"
405 " 1 0 0 0 0 0 0 -1 0 0 -3 \n"
406 " 1 0 0 0 0 0 0 0 2 1 -6 \n"
407 " 1 0 0 0 0 0 0 0 1 0 0 \n");
408 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
410 Polyhedron
*C
= Universe_Polyhedron(3);
411 gen_fun
*gf
= barvinok_series_with_options(P
, C
, options
);
416 M
= matrix_read_from_str(
418 " 0 1 1 0 0 1 0 2 \n"
419 " 0 0 0 1 0 -2 0 6 \n"
420 " 0 0 0 0 1 -1 0 -1 \n"
421 " 0 0 0 0 0 0 1 0 \n"
422 " 1 0 1 0 0 0 0 0 \n"
423 " 1 0 -1 0 0 -1 0 -2 \n"
424 " 1 0 0 0 0 1 0 -3 \n");
425 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
427 C
= Universe_Polyhedron(2);
428 gf
= barvinok_series_with_options(P
, C
, options
);
433 M
= matrix_read_from_str(
437 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
439 C
= Universe_Polyhedron(1);
440 gf
= barvinok_series_with_options(P
, C
, options
);
443 gen_fun
*sum
= gf
->summate(1, options
);
450 int test_todd(struct barvinok_options
*options
)
452 tcounter
t(2, options
->max_index
);
453 assert(value_cmp_si(t
.todd
.coeff
->p
[0], 1) == 0);
454 assert(value_cmp_si(t
.todd
.coeff
->p
[1], -3) == 0);
455 assert(value_cmp_si(t
.todd
.coeff
->p
[2], 3) == 0);
456 assert(value_cmp_si(t
.todd_denom
->p
[0], 1) == 0);
457 assert(value_cmp_si(t
.todd_denom
->p
[1], 6) == 0);
458 assert(value_cmp_si(t
.todd_denom
->p
[2], 36) == 0);
461 set_from_string(lambda
, "[1 -1]");
462 zz2values(lambda
, t
.lambda
->p
);
465 set_from_string(rays
, "[[-1 0][-1 1]]");
470 set_from_string(v
, "[2 0 1]");
471 Vector
*vertex
= Vector_Alloc(3);
472 zz2values(v
, vertex
->p
);
474 t
.handle(rays
, vertex
->p
, one
, 1, options
);
475 assert(value_cmp_si(mpq_numref(t
.count
), 71) == 0);
476 assert(value_cmp_si(mpq_denref(t
.count
), 24) == 0);
478 set_from_string(rays
, "[[0 -1][1 -1]]");
479 set_from_string(v
, "[0 2 1]");
480 zz2values(v
, vertex
->p
);
482 t
.handle(rays
, vertex
->p
, one
, 1, options
);
483 assert(value_cmp_si(mpq_numref(t
.count
), 71) == 0);
484 assert(value_cmp_si(mpq_denref(t
.count
), 12) == 0);
486 set_from_string(rays
, "[[1 0][0 1]]");
487 set_from_string(v
, "[0 0 1]");
488 zz2values(v
, vertex
->p
);
490 t
.handle(rays
, vertex
->p
, one
, 1, options
);
491 assert(value_cmp_si(mpq_numref(t
.count
), 6) == 0);
492 assert(value_cmp_si(mpq_denref(t
.count
), 1) == 0);
497 int test_bernoulli(struct barvinok_options
*options
)
499 struct bernoulli_coef
*bernoulli_coef
;
500 struct poly_list
*faulhaber
, *bernoulli
;
501 bernoulli_coef
= bernoulli_coef_compute(2);
502 faulhaber
= faulhaber_compute(4);
503 bernoulli_coef
= bernoulli_coef_compute(8);
504 assert(value_cmp_si(bernoulli_coef
->num
->p
[6], 1) == 0);
505 assert(value_cmp_si(bernoulli_coef
->den
->p
[6], 42) == 0);
506 assert(value_cmp_si(faulhaber
->poly
[3]->p
[0], 0) == 0);
507 assert(value_cmp_si(faulhaber
->poly
[3]->p
[1], 0) == 0);
508 assert(value_cmp_si(faulhaber
->poly
[3]->p
[2], 1) == 0);
509 assert(value_cmp_si(faulhaber
->poly
[3]->p
[3], -2) == 0);
510 assert(value_cmp_si(faulhaber
->poly
[3]->p
[4], 1) == 0);
511 assert(value_cmp_si(faulhaber
->poly
[3]->p
[5], 4) == 0);
513 bernoulli
= bernoulli_compute(6);
514 assert(value_cmp_si(bernoulli
->poly
[6]->p
[0], 1) == 0);
515 assert(value_cmp_si(bernoulli
->poly
[6]->p
[1], 0) == 0);
516 assert(value_cmp_si(bernoulli
->poly
[6]->p
[2], -21) == 0);
517 assert(value_cmp_si(bernoulli
->poly
[6]->p
[3], 0) == 0);
518 assert(value_cmp_si(bernoulli
->poly
[6]->p
[4], 105) == 0);
519 assert(value_cmp_si(bernoulli
->poly
[6]->p
[5], -126) == 0);
520 assert(value_cmp_si(bernoulli
->poly
[6]->p
[6], 42) == 0);
521 assert(value_cmp_si(bernoulli
->poly
[6]->p
[7], 42) == 0);
523 unsigned nvar
, nparam
;
525 evalue
*base
, *sum1
, *sum2
;
526 base
= evalue_read_from_str("(1 * n + 1)", NULL
, &all_vars
, &nvar
, &nparam
,
529 sum1
= evalue_polynomial(faulhaber
->poly
[3], base
);
530 Free_ParamNames(all_vars
, nvar
+nparam
);
532 sum2
= evalue_read_from_str("(1/4 * n^4 + 1/2 * n^3 + 1/4 * n^2)",
533 NULL
, &all_vars
, &nvar
, &nparam
,
535 Free_ParamNames(all_vars
, nvar
+nparam
);
536 assert(eequal(sum1
, sum2
));
542 int test_bernoulli_sum(struct barvinok_options
*options
)
544 unsigned nvar
, nparam
;
546 evalue
*e
, *sum1
, *sum2
;
547 e
= evalue_read_from_str("i + -1 >= 0\n -i + n >= 0\n\n 1 + (-1 *i) + i^2",
548 "i", &all_vars
, &nvar
, &nparam
,
550 Free_ParamNames(all_vars
, nvar
+nparam
);
552 sum1
= Bernoulli_sum_evalue(e
, 1, options
);
553 sum2
= evalue_read_from_str("n -1 >= 0\n\n (1/3 * n^3 + 2/3 * n)",
554 NULL
, &all_vars
, &nvar
, &nparam
,
556 Free_ParamNames(all_vars
, nvar
+nparam
);
560 assert(EVALUE_IS_ZERO(*sum1
));
564 e
= evalue_read_from_str("-i + -1 >= 0\n i + n >= 0\n\n 1 + i + i^2",
565 "i", &all_vars
, &nvar
, &nparam
,
567 Free_ParamNames(all_vars
, nvar
+nparam
);
568 sum1
= Bernoulli_sum_evalue(e
, 1, options
);
572 assert(EVALUE_IS_ZERO(*sum1
));
578 e
= evalue_read_from_str("i + 4 >= 0\n -i + n >= 0\n\n i",
579 "i", &all_vars
, &nvar
, &nparam
,
581 Free_ParamNames(all_vars
, nvar
+nparam
);
582 sum1
= Bernoulli_sum_evalue(e
, 1, options
);
583 sum2
= evalue_read_from_str("n + 0 >= 0\n\n (1/2 * n^2 + 1/2 * n + (-10))\n"
584 "n + 4 >= 0\n -n -1 >= 0\n\n (1/2 * n^2 + 1/2 * n + (-10))",
585 NULL
, &all_vars
, &nvar
, &nparam
,
587 Free_ParamNames(all_vars
, nvar
+nparam
);
591 assert(EVALUE_IS_ZERO(*sum1
));
596 e
= evalue_read_from_str("i -5 >= 0\n -i + n >= 0\n j -1 >= 0\n i -j >= 0\n"
597 "k -1 >= 0\n j -k >= 0\n\n1",
598 "i,j,k", &all_vars
, &nvar
, &nparam
,
600 Free_ParamNames(all_vars
, nvar
+nparam
);
601 sum1
= Bernoulli_sum_evalue(e
, 3, options
);
602 sum2
= evalue_read_from_str("n -5 >= 0\n\n"
603 "1/6 * n^3 + 1/2 * n^2 + 1/3 * n + -20",
604 NULL
, &all_vars
, &nvar
, &nparam
,
606 Free_ParamNames(all_vars
, nvar
+nparam
);
610 assert(EVALUE_IS_ZERO(*sum1
));
616 int test_hilbert(struct barvinok_options
*options
)
619 Matrix
*M
= matrix_read_from_str(
623 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
626 M
= Cone_Hilbert_Basis(P
, options
->MaxRays
);
627 assert(M
->NbRows
= 5);
628 assert(M
->NbColumns
= 3);
631 M
= Cone_Integer_Hull(P
, NULL
, 0, options
);
632 assert(M
->NbRows
= 4);
633 assert(M
->NbColumns
= 3);
640 int test_ilp(struct barvinok_options
*options
)
642 Matrix
*M
= matrix_read_from_str(
646 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
648 Vector
*obj
= Vector_Alloc(2);
649 value_set_si(obj
->p
[0], 7);
650 value_set_si(obj
->p
[1], -1);
655 value_set_si(min
, 1);
656 value_set_si(max
, 17);
657 Vector
*opt
= Polyhedron_Integer_Minimum(P
, obj
->p
, min
, max
,
660 assert(value_cmp_si(opt
->p
[0], 1) == 0);
661 assert(value_cmp_si(opt
->p
[1], 1) == 0);
662 assert(value_cmp_si(opt
->p
[2], 1) == 0);
671 int test_hull(struct barvinok_options
*options
)
673 Matrix
*M
= matrix_read_from_str(
679 Polyhedron
*P
= Constraints2Polyhedron(M
, options
->MaxRays
);
682 Matrix
*hull
= Polyhedron_Integer_Hull(P
, options
);
684 assert(hull
->NbRows
== 4);
685 M
= Matrix_Alloc(hull
->NbRows
, 1+hull
->NbColumns
);
686 for (int i
= 0; i
< hull
->NbRows
; ++i
) {
687 value_set_si(M
->p
[i
][0], 1);
688 Vector_Copy(hull
->p
[i
], M
->p
[i
]+1, hull
->NbColumns
);
691 Polyhedron
*H
= Constraints2Polyhedron(M
, options
->MaxRays
);
694 M
= matrix_read_from_str(
700 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
702 assert(PolyhedronIncludes(P
, H
) && PolyhedronIncludes(H
, P
));
706 M
= matrix_read_from_str(
711 P
= Constraints2Polyhedron(M
, options
->MaxRays
);
714 hull
= Polyhedron_Integer_Hull(P
, options
);
716 assert(hull
->NbRows
== 0);
720 int main(int argc
, char **argv
)
722 struct barvinok_options
*options
= barvinok_options_new_with_defaults();
723 test_equalities(options
);
724 test_evalue_read(options
);
726 test_evalue(options
);
727 test_substitute(options
);
728 test_split_periods(options
);
729 test_specialization(options
);
730 test_lattice_points(options
);
731 test_icounter(options
);
732 test_infinite_counter(options
);
733 test_series(options
);
735 test_bernoulli(options
);
736 test_bernoulli_sum(options
);
737 test_hilbert(options
);
740 barvinok_options_free(options
);