1 \section{Internal Representation of the
\protect\ai[\tt]{barvinok
} library
}
3 Our
\barvinok/ library is built on top of
\PolyLib/
4 \shortcite{Wilde1993,Loechner1999
}.
5 In particular, it reuses the implementations
7 \shortciteN{Loechner97parameterized
}
8 for computing parametric vertices
10 \shortciteN{Clauss1998parametric
}
11 for computing chamber decompositions.
12 Initially, our library was meant to be a replacement
13 for the algorithm of
\shortciteN{Clauss1998parametric
},
14 also implemented in
\PolyLib/, for computing quasi-polynomials.
15 To ease the transition of application programs we
16 tried to reuse the existing data structures as much as possible.
18 \subsection{Existing Data Structures
}
21 Inside
\PolyLib/ integer values are represented by the
22 \ai[\tt]{Value
} data type.
23 Depending on a configure option, the data type may
24 either by a
32-bit integer, a
64-bit integer
25 or an arbitrary precision integer using
\ai[\tt]{GMP
}.
26 The
\barvinok/ library requires that
\PolyLib/ is compiled
27 with support for arbitrary precision integers.
29 The basic structure for representing (unions of) polyhedra is a
32 typedef struct polyhedron
{
33 unsigned Dimension, NbConstraints, NbRays, NbEq, NbBid;
38 struct polyhedron *next;
41 The attribute
\ai[\tt]{Dimension
} is the dimension
42 of the ambient space, i.e., the number of variables.
43 The attributes
\ai[\tt]{Constraint
}
44 and
\ai[\tt]{Ray
} point to two-dimensional arrays
45 of constraints and generators, respectively.
46 The number of rows is stored in
47 \ai[\tt]{NbConstraints
} and
48 \ai[\tt]{NbRays
}, respectively.
49 The number of columns in both arrays is equal
50 to
\verb!
1+Dimension+
1!.
51 The first column of
\ai[\tt]{Constraint
} is either
52 $
0$ or $
1$ depending on whether the constraint
53 is an equality ($
0$) or an inequality ($
1$).
54 The number of equalities is stored in
\ai[\tt]{NbEq
}.
55 If the constraint is $
\sp a x + c
\ge 0$, then
56 the next columns contain the coefficients $a_i$
57 and the final column contains the constant $c$.
58 The first column of
\ai[\tt]{Ray
} is either
59 $
0$ or $
1$ depending on whether the generator
60 is a line ($
0$) or a vertex or ray ($
1$).
61 The number of lines is stored in
\ai[\tt]{NbBid
}.
62 Let $d$ be the
\ac{lcm
} of the denominators of the coordinates
63 of a vertex $
\vec v$, then the next columns contain
64 $d v_i$ and the final column contains $d$.
65 For a ray, the final column contains $
0$.
66 The field
\ai[\tt]{next
} points to the next polyhedron in
67 the union of polyhedra.
68 It is
\verb+
0+ if this is the last (or only) polyhedron in the union.
69 For more information on this structure, we refer to
\shortciteN{Wilde1993
}.
71 Quasi-polynomials are represented using the
72 \ai[\tt]{evalue
} and
\ai[\tt]{enode
} structures.
74 typedef enum
{ polynomial, periodic, evector
} enode_type;
76 typedef struct _evalue
{
77 Value d; /* denominator */
79 Value n; /* numerator (if denominator !=
0) */
80 struct _enode *p; /* pointer (if denominator ==
0) */
84 typedef struct _enode
{
85 enode_type type; /* polynomial or periodic or evector */
86 int size; /* number of attached pointers */
87 int pos; /* parameter position */
88 evalue arr
[1]; /* array of rational/pointer */
91 If the field
\ai[\tt]{d
} of an
\ai[\tt]{evalue
} is zero, then
92 the
\ai[\tt]{evalue
} is a placeholder for a pointer to
93 an
\ai[\tt]{enode
}, stored in
\ai[\tt]{x.p
}.
94 Otherwise, the
\ai[\tt]{evalue
} is a rational number with
95 numerator
\ai[\tt]{x.n
} and denominator
\ai[\tt]{d
}.
96 An
\ai[\tt]{enode
} is either a
\ai[\tt]{polynomial
}
97 or a
\ai[\tt]{periodic
}, depending on the value
99 The length of the array
\ai[\tt]{arr
} is stored in
\ai[\tt]{size
}.
100 For a
\ai[\tt]{polynomial
},
\ai[\tt]{arr
} contains the coefficients.
101 For a
\ai[\tt]{periodic
}, it contains the values for the different
102 residue classes modulo the parameter indicated by
\ai[\tt]{pos
}.
103 For a polynomial,
\ai[\tt]{pos
} refers to the variable
105 The value of
\ai[\tt]{pos
} is
\verb+
1+ for the first parameter.
106 That is, if the value of
\ai[\tt]{pos
} is
\verb+
1+ and the first
107 parameter is $p$, and if the length of the array is $l$,
108 then in case it is a polynomial, the
109 \ai[\tt]{enode
} represents
111 \verb+arr
[0]+ +
\verb+arr
[1]+ p +
\verb+arr
[2]+ p^
2 +
\cdots +
112 \verb+arr
[l-
1]+ p^
{l-
1}
115 If it is a periodic, then it represents
118 \verb+arr
[0]+,
\verb+arr
[1]+,
\verb+arr
[2]+,
\ldots,
123 Note that the elements of a
\ai[\tt]{periodic
} may themselves
124 be other
\ai[\tt]{periodic
}s or even
\ai[\tt]{polynomial
}s.
125 In our library, we only allow the elements of a
\ai[\tt]{periodic
}
126 to be other
\ai[\tt]{periodic
}s or rational numbers.
127 The chambers and their corresponding quasi-polynomial are
128 stored in
\ai[\tt]{Enumeration
} structures.
130 typedef struct _enumeration
{
131 Polyhedron *ValidityDomain; /* constraints on the parameters */
132 evalue EP; /* dimension = combined space */
133 struct _enumeration *next; /* Ehrhart Polynomial,
134 corresponding to parameter
135 values inside the domain
136 ValidityDomain above */
139 For more information on these structures, we refer to
\shortciteN{Loechner1999
}.
142 Figure~
\ref{f:Loechner
} is a skillful reconstruction
143 of Figure~
2 from
\shortciteN{Loechner1999
}.
144 It shows the contents of the
\ai[\tt]{enode
} structures
145 representing the quasi-polynomial
147 [1,
2]_p p^
2 +
3 p +
\frac 5 2
154 \begin{tabular
}{|c|c|c|
}
156 \multicolumn{2}{|c|
}{type
} & polynomial \\
158 \multicolumn{2}{|c|
}{size
} &
3 \\
160 \multicolumn{2}{|c|
}{pos
} &
1 \\
162 \smash{\lower 6.25pt
\hbox{arr
[0]}} & d &
2 \\
166 \smash{\lower 6.25pt
\hbox{arr
[1]}} & d &
1 \\
170 \smash{\lower 6.25pt
\hbox{arr
[2]}} & d &
0 \\
177 +DR*!DR
\hbox{\strut\hskip 1.5\tabcolsep\phantom{\tt polynomial
}\hskip 1.5\tabcolsep}+C="a"
178 \POS(
60,-
15)*!UL
{\hbox{
180 \begin{tabular
}{|c|c|c|
}
182 \multicolumn{2}{|c|
}{type
} & periodic \\
184 \multicolumn{2}{|c|
}{size
} &
2 \\
186 \multicolumn{2}{|c|
}{pos
} &
1 \\
188 \smash{\lower 6.25pt
\hbox{arr
[0]}} & d &
1 \\
192 \smash{\lower 6.25pt
\hbox{arr
[1]}} & d &
1 \\
199 +UL+<
0.5\tabcolsep,
0pt>*!UL
\hbox{\strut}+CL="b"
201 \POS"box1"+UC*++!D
\hbox{\tt enode
}
202 \POS"box2"+UC*++!D
\hbox{\tt enode
}
204 \caption{The quasi-polynomial $
[1,
2]_p p^
2 +
3 p +
\frac 5 2$.
}
212 The
\ai[\tt]{barvinok
\_options} structure contains various
213 options that influence the behavior of the library.
216 struct barvinok_options
{
217 struct barvinok_stats *stats;
219 /* PolyLib options */
223 /* LLL reduction parameter delta=LLL_a/LLL_b */
227 /* barvinok options */
228 #define BV_SPECIALIZATION_BF
2
229 #define BV_SPECIALIZATION_DF
1
230 #define BV_SPECIALIZATION_RANDOM
0
231 int incremental_specialization;
233 unsigned long max_index;
236 int count_sample_infinite;
238 int try_Delaunay_triangulation;
240 #define BV_APPROX_SIGN_NONE
0
241 #define BV_APPROX_SIGN_APPROX
1
242 #define BV_APPROX_SIGN_LOWER
2
243 #define BV_APPROX_SIGN_UPPER
3
244 int polynomial_approximation;
245 #define BV_APPROX_NONE
0
246 #define BV_APPROX_DROP
1
247 #define BV_APPROX_SCALE
2
248 #define BV_APPROX_VOLUME
3
249 int approximation_method;
250 #define BV_APPROX_SCALE_FAST (
1 <<
0)
251 #define BV_APPROX_SCALE_NARROW (
1 <<
1)
252 #define BV_APPROX_SCALE_NARROW2 (
1 <<
2)
253 #define BV_APPROX_SCALE_CHAMBER (
1 <<
3)
255 #define BV_VOL_LIFT
0
256 #define BV_VOL_VERTEX
1
257 #define BV_VOL_BARYCENTER
2
258 int volume_triangulate;
260 /* basis reduction options */
261 #define BV_GBR_NONE
0
262 #define BV_GBR_GLPK
1
266 /* bernstein options */
267 #define BV_BERNSTEIN_NONE
0
268 #define BV_BERNSTEIN_MAX
1
269 #define BV_BERNSTEIN_MIN -
1
270 int bernstein_optimize;
272 #define BV_BERNSTEIN_FACTORS
1
273 #define BV_BERNSTEIN_INTERVALS
2
274 int bernstein_recurse;
277 struct barvinok_options *barvinok_options_new_with_defaults();
280 The function
\ai[\tt]{barvinok
\_options\_new\_with\_defaults}
281 can be used to create a
\ai[\tt]{barvinok
\_options} structure
285 \item \PolyLib/ options
289 \item \ai[\tt]{MaxRays
}
291 The value of
\ai[\tt]{MaxRays
} is passed to various
\PolyLib/
292 functions and defines the
293 maximum size of a table used in the
\ai{double description
} computation
294 in the
\PolyLib/ function
\ai[\tt]{Chernikova
}.
295 In earlier versions of
\PolyLib/,
296 this parameter had to be conservatively set
297 to a high number to ensure successful operation,
298 resulting in significant memory overhead.
299 Our change to allow this table to grow
300 dynamically is available in recent versions of
\PolyLib/.
301 In these versions, the value no longer indicates the maximal
302 table size, but rather the size of the initial allocation.
303 This value may be set to
\verb+
0+ or left as set
304 by
\ai[\tt]{barvinok
\_options\_new\_with\_defaults}.
308 \item \ai[\tt]{NTL
} options
312 \item \ai[\tt]{LLL
\_a}
313 \item \ai[\tt]{LLL
\_b}
315 The values used for the
\ai{reduction parameter
}
316 in the call to
\ai[\tt]{NTL
}'s implementation of
\indac{LLL
}.
320 \item \ai[\tt]{barvinok
} specific options
324 \item \ai[\tt]{incremental
\_specialization}
326 Selects the
\ai{specialization
} algorithm to be used.
327 If set to
{\tt 0} then a direct specialization is performed
328 using a random vector.
329 Value
{\tt 1} selects a depth first incremental specialization,
330 while value
{\tt 2} selects a breadth first incremental specialization.
331 The default is selected by the
\ai[\tt]{--enable-incremental
}
332 \ai[\tt]{configure
} option.
333 For more information we refer to~
\citeN[Section~
4.4.3]{Verdoolaege2005PhD
}.
339 \subsection{Data Structures for Quasi-polynomials
}
342 Internally, we do not represent our
\ai{quasi-polynomial
}s
343 as step-polynomials, but, similarly to
\shortciteN{Loechner1999
},
344 as polynomials with periodic numbers for coefficients.
345 However, we also allow our periodic numbers to be represented by
346 fractional parts of degree-$
1$ polynomials rather than
347 an explicit enumeration using the
\ai[\tt]{periodic
} type.
348 By default, the current version of
\barvinok/ uses
349 \ai[\tt]{periodic
}s, but this can be changed through
350 the
\ai[\tt]{--enable-fractional
} configure option.
351 In the latter case, the quasi-polynomial using fractional
352 parts can also be converted to an actual step-polynomial
353 using
\ai[\tt]{evalue
\_frac2floor}, but this is not fully
356 For reasons of compatibility,
%
357 \footnote{Also known as laziness.
}
358 we shoehorned our representations for piecewise quasi-polynomials
359 into the existing data structures.
360 To this effect, we introduced four new types,
361 \ai[\tt]{fractional
},
\ai[\tt]{relation
},
362 \ai[\tt]{partition
} and
\ai[\tt]{flooring
}.
364 typedef enum
{ polynomial, periodic, evector, fractional,
365 relation, partition, flooring
} enode_type;
367 The field
\ai[\tt]{pos
} is not used in most of these
368 additional types and is therefore set to
\verb+-
1+.
370 The types
\ai[\tt]{fractional
} and
\ai[\tt]{flooring
}
371 represent polynomial expressions in a fractional part or a floor respectively.
372 The generator is stored in
\verb+arr
[0]+, while the
373 coefficients are stored in the remaining array elements.
374 That is, an
\ai[\tt]{enode
} of type
\ai[\tt]{fractional
}
377 \verb+arr
[1]+ +
\verb+arr
[2]+ \
{\verb+arr
[0]+\
} +
378 \verb+arr
[3]+ \
{\verb+arr
[0]+\
}^
2 +
\cdots +
379 \verb+arr
[l-
1]+ \
{\verb+arr
[0]+\
}^
{l-
2}
382 An
\ai[\tt]{enode
} of type
\ai[\tt]{flooring
}
385 \verb+arr
[1]+ +
\verb+arr
[2]+
\lfloor\verb+arr
[0]+
\rfloor +
386 \verb+arr
[3]+
\lfloor\verb+arr
[0]+
\rfloor^
2 +
\cdots +
387 \verb+arr
[l-
1]+
\lfloor\verb+arr
[0]+
\rfloor^
{l-
2}
392 The internal representation of the quasi-polynomial
393 $$
\left(
1+
2 \left\
{\frac p
2\right\
}\right) p^
2 +
3 p +
\frac 5 2$$
394 is shown in Figure~
\ref{f:fractional
}.
400 \begin{tabular
}{|c|c|c|
}
402 \multicolumn{2}{|c|
}{type
} & polynomial \\
404 \multicolumn{2}{|c|
}{size
} &
3 \\
406 \multicolumn{2}{|c|
}{pos
} &
1 \\
408 \smash{\lower 6.25pt
\hbox{arr
[0]}} & d &
2 \\
412 \smash{\lower 6.25pt
\hbox{arr
[1]}} & d &
1 \\
416 \smash{\lower 6.25pt
\hbox{arr
[2]}} & d &
0 \\
423 +DR*!DR
\hbox{\strut\hskip 1.5\tabcolsep\phantom{\tt polynomial
}\hskip 1.5\tabcolsep}+C="a"
424 \POS(
60,
0)*!UL
{\hbox{
426 \begin{tabular
}{|c|c|c|
}
428 \multicolumn{2}{|c|
}{type
} & fractional \\
430 \multicolumn{2}{|c|
}{size
} &
3 \\
432 \multicolumn{2}{|c|
}{pos
} & -
1 \\
434 \smash{\lower 6.25pt
\hbox{arr
[0]}} & d &
0 \\
438 \smash{\lower 6.25pt
\hbox{arr
[1]}} & d &
1 \\
442 \smash{\lower 6.25pt
\hbox{arr
[2]}} & d &
1 \\
449 +UL+<
0.5\tabcolsep,
0pt>*!UL
\hbox{\strut}+CL="b"
451 \POS"box2"+UR*!UR
{\hbox{
465 }+CD*!U
{\strut}+C="c"
466 \POS(
60,-
50)*!UL
{\hbox{
468 \begin{tabular
}{|c|c|c|
}
470 \multicolumn{2}{|c|
}{type
} & polynomial \\
472 \multicolumn{2}{|c|
}{size
} &
2 \\
474 \multicolumn{2}{|c|
}{pos
} &
1 \\
476 \smash{\lower 6.25pt
\hbox{arr
[0]}} & d &
1 \\
480 \smash{\lower 6.25pt
\hbox{arr
[1]}} & d &
2 \\
487 +UR-<
0.8\tabcolsep,
0pt>*!UR
\hbox{\strut}+CR="d"
489 \POS"box1"+UC*++!D
\hbox{\tt enode
}
490 \POS"box2"+UC*++!D
\hbox{\tt enode
}
491 \POS"box3"+UC*++!D
\hbox{\tt enode
}
493 \caption{The quasi-polynomial
494 $
\left(
1+
2 \left\
{\frac p
2\right\
}\right) p^
2 +
3 p +
\frac 5 2$.
}
500 The
\ai[\tt]{relation
} type is used to represent
\ai{stride
}s.
501 In particular, if the value of
\ai[\tt]{size
} is
2, then
502 the value of a
\ai[\tt]{relation
} is (in pseudo-code):
504 (value(arr
[0]) ==
0) ? value(arr
[1]) :
0
506 If the size is
3, then the value is:
508 (value(arr
[0]) ==
0) ? value(arr
[1]) : value(arr
[2])
510 The type of
\verb+arr
[0]+ is typically
\ai[\tt]{fractional
}.
512 Finally, the
\ai[\tt]{partition
} type is used to
513 represent piecewise quasi-polynomials.
514 We prefer to encode this information inside
\ai[\tt]{evalue
}s
516 rather than using
\ai[\tt]{Enumeration
}s since we want
517 to perform the same kinds of operations on both quasi-polynomials
518 and piecewise quasi-polynomials.
519 An
\ai[\tt]{enode
} of type
\ai[\tt]{partition
} may not be nested
520 inside another
\ai[\tt]{enode
}.
521 The size of the array is twice the number of ``chambers''.
522 Pointers to chambers are stored in the even slots,
523 whereas pointer to the associated quasi-polynomials
524 are stored in the odd slots.
525 To be able to store pointers to chambers, the
526 definition of
\ai[\tt]{evalue
} was changed as follows.
528 typedef struct _evalue
{
529 Value d; /* denominator */
531 Value n; /* numerator (if denominator >
0) */
532 struct _enode *p; /* pointer (if denominator ==
0) */
533 Polyhedron *D; /* domain (if denominator == -
1) */
537 Note that we allow a ``chamber'' to be a union of polyhedra
538 as discussed in
\citeN[Section~
4.5.1]{Verdoolaege2005PhD
}.
539 Chambers with extra variables, i.e., those of
540 \citeN[Section~
4.6.5]{Verdoolaege2005PhD
},
541 are only partially supported.
542 The field
\ai[\tt]{pos
} is set to the actual dimension,
543 i.e., the number of parameters.
545 \subsection{Operations on Quasi-polynomials
}
548 In this section we discuss some of the more important
549 operations on
\ai[\tt]{evalue
}s provided by the
551 Some of these operations are extensions
552 of the functions from
\PolyLib/ with the same name.
555 void eadd(const evalue *e1,evalue *res);
556 void emul (evalue *e1, evalue *res );
558 The functions
\ai[\tt]{eadd
} and
\ai[\tt]{emul
} takes
559 two (pointers to)
\ai[\tt]{evalue
}s
\verb+e1+ and
\verb+res+
560 and computes their sum and product respectively.
561 The result is stored in
\verb+res+, overwriting (and deallocating)
562 the original value of
\verb+res+.
563 It is an error if exactly one of
564 the arguments of
\ai[\tt]{eadd
} is of type
\ai[\tt]{partition
}
565 (unless the other argument is
\verb+
0+).
566 The addition and multiplication operations are described
567 in
\citeN[Section~
4.5.1]{Verdoolaege2005PhD
}
568 and~
\citeN[Section~
4.5.2]{Verdoolaege2005PhD
}
571 The function
\ai[\tt]{eadd
} is an extension of the function
572 \ai[\tt]{new
\_eadd} from
\shortciteN{Seghir2002
}.
573 Apart from supporting the additional types from Section~
\ref{a:data
},
574 the new version also additionally imposes an order on the nesting of
575 different
\ai[\tt]{enode
}s.
576 Without such an ordering,
\ai[\tt]{evalue
}s could be constructed
577 representing for example
579 (
0 y^
0 + (
0 x^
0 +
1 x^
1 ) y^
1 ) x^
0 + (
0 y^
0 -
1 y^
1) x^
1
582 which is just a funny way of saying $
0$.
585 void eor(evalue *e1, evalue *res);
587 The function
\ai[\tt]{eor
} implements the
\ai{union
}
588 operation from
\citeN[Section~
4.5.3]{Verdoolaege2005PhD
}. Both arguments
589 are assumed to correspond to indicator functions.
592 evalue *esum(evalue *E, int nvar);
594 The function
\ai[\tt]{esum
} performs the summation
595 operation from
\citeN[Section~
4.5.4]{Verdoolaege2005PhD
}.
596 The piecewise step-polynomial represented by
\verb+E+ is summated
597 over its first
\verb+nvar+ variables.
598 Note that
\verb+E+ must be zero or of type
\ai[\tt]{partition
}.
599 The function returns the result in a newly allocated
601 Note also that
\verb+E+ needs to have been converted
602 from
\ai[\tt]{fractional
}s to
\ai[\tt]{flooring
}s using
603 the function
\ai[\tt]{evalue
\_frac2floor}.
605 void evalue_frac2floor(evalue *e);
607 This function also ensures that the arguments of the
608 \ai[\tt]{flooring
}s are positive in the relevant chambers.
609 It currently assumes that the argument of each
610 \ai[\tt]{fractional
} in the original
\ai[\tt]{evalue
}
611 has a minimum in the corresponding chamber.
614 double compute_evalue(const evalue *e, Value *list_args);
615 Value *compute_poly(Enumeration *en,Value *list_args);
616 evalue *evalue_eval(const evalue *e, Value *values);
618 The functions
\ai[\tt]{compute
\_evalue},
619 \ai[\tt]{compute
\_poly} and
620 \ai[\tt]{evalue
\_eval}
621 evaluate a (piecewise) quasi-polynomial
622 at a certain point. The argument
\verb+list_args+
623 points to an array of
\ai[\tt]{Value
}s that is assumed
625 The
\verb+double+ return value of
\ai[\tt]{compute
\_evalue}
626 is inherited from
\PolyLib/.
629 void print_evalue(FILE *DST, const evalue *e, char **pname);
631 The function
\ai[\tt]{print
\_evalue} dumps a human-readable
632 representation to the stream pointed to by
\verb+DST+.
633 The argument
\verb+pname+ points
634 to an array of character strings representing the parameter names.
635 The array is assumed to be long enough.
638 int eequal(const evalue *e1, const evalue *e2);
640 The function
\ai[\tt]{eequal
} return true (
\verb+
1+) if its
641 two arguments are structurally identical.
642 I.e., it does
{\em not\/
} check whether the two
643 (piecewise) quasi-polynomial represent the same function.
646 void reduce_evalue (evalue *e);
648 The function
\ai[\tt]{reduce
\_evalue} performs some
649 simplifications on
\ai[\tt]{evalue
}s.
650 Here, we only describe the simplifications that are directly
651 related to the internal representation.
652 Some other simplifications are explained in
653 \citeN[Section~
4.7.2]{Verdoolaege2005PhD
}.
654 If the highest order coefficients of a
\ai[\tt]{polynomial
},
655 \ai[\tt]{fractional
} or
\ai[\tt]{flooring
} are zero (possibly
656 after some other simplifications), then the size of the array
657 is reduced. If only the constant term remains, i.e.,
658 the size is reduced to $
1$ for
\ai[\tt]{polynomial
} or to $
2$
659 for the other types, then the whole node is replaced by
661 Additionally, if the argument of a
\ai[\tt]{fractional
}
662 has been reduced to a constant, then the whole node
663 is replaced by its partial evaluation.
664 A
\ai[\tt]{relation
} is similarly reduced if its second
665 branch or both its branches are zero.
666 Chambers with zero associated quasi-polynomials are
667 discarded from a
\ai[\tt]{partition
}.
669 \subsection{Generating Functions
}
671 The representation of
\rgf/s uses
672 some basic types from the
\ai[\tt]{NTL
} library
\shortcite{NTL
}
673 for representing arbitrary precision integers
675 as well as vectors (
\ai[\tt]{vec
\_ZZ}) and matrices (
\ai[\tt]{mat
\_ZZ})
677 We further introduces a type
\ai[\tt]{QQ
} for representing a rational
678 number and use vectors (
\ai[\tt]{vec
\_QQ}) of such numbers.
685 NTL_vector_decl(QQ,vec_QQ);
688 Each term in a
\rgf/ is represented by a
\ai[\tt]{short
\_rat}
693 /* rows: terms in numerator */
698 /* rows: factors in denominator */
703 The fields
\ai[\tt]{n
} and
\ai[\tt]{d
} represent the
704 numerator and the denominator respectively.
705 Note that in our implementation we combine terms
706 with the same denominator.
707 In the numerator, each element of
\ai[\tt]{coeff
} and each row of
\ai[\tt]{power
}
708 represents a single such term.
709 The vector
\ai[\tt]{coeff
} contains the rational coefficients
710 $
\alpha_i$ of each term.
711 The columns of
\ai[\tt]{power
} correspond to the powers
713 In the denominator, each row of
\ai[\tt]{power
}
714 corresponds to the power $
\vec b_
{ij
}$ of a
715 factor in the denominator.
719 shows the internal representation of
721 \frac{\frac 3 2 \, x_0^
2 x_1^
3 +
2 \, x_0^
5 x_1^
{-
7}}
722 { (
1 - x_0 x_1^
{-
3}) (
1 - x_1^
2)
}
728 \begin{minipage
}{0cm
}
732 \begin{tabular
}{|c|c|c|
}
747 }+UC*++!D
\hbox{\tt short
\_rat}
751 \caption{Representation of
753 \left(
\frac 3 2 \, x_0^
2 x_1^
3 +
2 \, x_0^
5 x_1^
{-
7}\right)
754 /
\left( (
1 - x_0 x_1^
{-
3}) (
1 - x_1^
2)
\right)
761 The whole
\rgf/ is represented by a
\ai[\tt]{gen
\_fun}
764 typedef std::set<short_rat *,
765 short_rat_lex_smaller_denominator > short_rat_list;
771 void add(const QQ& c, const vec_ZZ& num, const mat_ZZ& den);
772 void add(short_rat *r);
773 void add(const QQ& c, const gen_fun *gf);
774 void substitute(Matrix *CP);
775 gen_fun *Hadamard_product(const gen_fun *gf,
776 barvinok_options *options);
777 void print(std::ostream& os,
778 unsigned int nparam, char **param_name) const;
779 operator evalue *() const;
780 ZZ coefficient(Value* params, barvinok_options *options) const;
781 void coefficient(Value* params, Value* c) const;
783 gen_fun(Polyhedron *C = NULL);
785 gen_fun(const gen_fun *gf);
789 A new
\ai[\tt]{gen
\_fun} can be constructed either as empty
\rgf/ (possibly
790 with a given context
\verb+C+), as a copy of an existing
\rgf/
\verb+gf+, or as
791 constant
\rgf/ with value for the constant term specified by
\verb+c+.
793 The first
\ai[\tt]{gen
\_fun::add
} method adds a new term to the
\rgf/,
794 described by the coefficient
\verb+c+, the numerator
\verb+num+ and the
795 denominator
\verb+den+.
796 It makes all powers in the denominator lexico-positive,
797 orders them in lexicographical order and inserts the new
798 term in
\ai[\tt]{term
} according to the lexicographical
799 order of the combined powers in the denominator.
800 The second
\ai[\tt]{gen
\_fun::add
} method adds
\verb+c+ times
\verb+gf+
803 The method
\ai[\tt]{gen
\_fun::operator evalue *
} performs
804 the conversion from
\rgf/ to
\psp/ explained in
805 \citeN[Section~
4.5.5]{Verdoolaege2005PhD
}.
806 The
\ai[\tt]{Polyhedron
} \ai[\tt]{context
} is the superset
807 of all points where the enumerator is non-zero used during this conversion,
808 i.e., it is the set $Q$ from
\citeN[Equation~
4.31]{Verdoolaege2005PhD
}.
809 If
\ai[\tt]{context
} is
\verb+NULL+ the maximal
810 allowed context is assumed, i.e., the maximal
811 region with lexico-positive rays.
813 The method
\ai[\tt]{gen
\_fun::coefficient
} computes the coefficient
814 of the term with power given by
\verb+params+ and stores the result
816 This method performs essentially the same computations as
817 \ai[\tt]{gen
\_fun::operator evalue *
}, except that it adds extra
818 equality constraints based on the specified values for the power.
820 The method
\ai[\tt]{gen
\_fun::substitute
} performs the
821 \ai{monomial substitution
} specified by the homogeneous matrix
\verb+CP+
822 that maps a set of ``
\ai{compressed parameter
}s''
\shortcite{Meister2004PhD
}
823 to the original set of parameters.
824 That is, if we are given a
\rgf/ $G(
\vec z)$ that encodes the
825 explicit function $g(
\vec i')$, where $
\vec i'$ are the coordinates of
826 the transformed space, and
\verb+CP+ represents the map
827 $
\vec i = A
\vec i' +
\vec a$ back to the original space with coordinates $
\vec i$,
828 then this method transforms the
\rgf/ to $F(
\vec x)$ encoding the
829 same explicit function $f(
\vec i)$, i.e.,
830 $$f(
\vec i) = f(A
\vec i' +
\vec a) = g(
\vec i ').$$
831 This means that the coefficient of the term
832 $
\vec x^
{\vec i
} =
\vec x^
{A
\vec i' +
\vec a
}$ in $F(
\vec x)$ should be equal to the
833 coefficient of the term $
\vec z^
{\vec i'
}$ in $G(
\vec z)$.
837 \sum_i \epsilon_i \frac{\vec z^
{\vec v_i
}}{\prod_j (
1-
\vec z^
{\vec b_
{ij
}})
}
842 \sum_i \epsilon_i \frac{\vec x^
{A
\vec v_i +
\vec a
}}
843 {\prod_j (
1-
\vec x^
{A
\vec b_
{ij
}})
}
847 The method
\ai[\tt]{gen
\_fun::Hadamard
\_product} computes the
848 \ai{Hadamard product
} of the current
\rgf/ with the
\rgf/
\verb+gf+,
849 as explained in
\citeN[Section~
4.5.2]{Verdoolaege2005PhD
}.
851 \subsection{Counting Functions
}
852 \label{a:counting:functions
}
854 Our library provides essentially three different counting functions:
855 one for non-parametric polytopes, one for parametric polytopes
856 and one for parametric sets with existential variables.
857 The old versions of these functions have a ``
\ai[\tt]{MaxRays
}''
858 argument, while the new versions have a more general
859 \ai[\tt]{barvinok
\_options} argument.
860 For more information on
\ai[\tt]{barvinok
\_options}, see Section~
\ref{a:options
}.
863 void barvinok_count(Polyhedron *P, Value* result,
865 void barvinok_count_with_options(Polyhedron *P, Value* result,
866 struct barvinok_options *options);
868 The function
\ai[\tt]{barvinok
\_count} or
869 \ai[\tt]{barvinok
\_count\_with\_options} enumerates the non-parametric
870 polytope
\verb+P+ and returns the result in the
\ai[\tt]{Value
}
871 pointed to by
\verb+result+, which needs to have been allocated
873 If
\verb+P+ is a union, then only the first set in the union will
874 be taken into account.
875 For the meaning of the argument
\verb+NbMaxCons+, see
876 the discussion on
\ai[\tt]{MaxRays
} in Section~
\ref{a:options
}.
878 The function
\ai[\tt]{barvinok
\_enumerate} for enumerating
879 parametric polytopes was meant to be
880 a drop-in replacement of
\PolyLib/'s
\ai[\tt]{Polyhedron
\_Enumerate}
882 Unfortunately, the latter has been changed to
883 accept an extra argument in recent versions of
\PolyLib/ as shown below.
885 Enumeration* barvinok_enumerate(Polyhedron *P, Polyhedron* C,
887 extern Enumeration *Polyhedron_Enumerate(Polyhedron *P,
888 Polyhedron *C, unsigned MAXRAYS, char **pname);
890 The argument
\verb+MaxRays+ has the same meaning as the argument
891 \verb+NbMaxCons+ above.
892 The argument
\verb+P+ refers to the $(d+n)$-dimensional
893 polyhedron defining the parametric polytope.
894 The argument
\verb+C+ is an $n$-dimensional polyhedron containing
895 extra constraints on the parameter space.
896 Its primary use is to indicate how many of the dimensions
897 in
\verb+P+ refer to parameters as any constraint in
\verb+C+
898 could equally well have been added to
\verb+P+ itself.
899 Note that the dimensions referring to the parameters should
901 If either
\verb+P+ or
\verb+C+ is a union,
902 then only the first set in the union will be taken into account.
903 The result is a newly allocated
\ai[\tt]{Enumeration
}.
904 As an alternative we also provide a function
905 (
\ai[\tt]{barvinok
\_enumerate\_ev} or
906 \ai[\tt]{barvinok
\_enumerate\_with\_options}) that returns
909 evalue* barvinok_enumerate_ev(Polyhedron *P, Polyhedron* C,
911 evalue* barvinok_enumerate_with_options(Polyhedron *P,
912 Polyhedron* C, struct barvinok_options *options);
915 For enumerating parametric sets with existentially quantified variables,
916 we provide two functions:
917 \ai[\tt]{barvinok
\_enumerate\_e}
919 \ai[\tt]{barvinok
\_enumerate\_pip}.
921 evalue* barvinok_enumerate_e(Polyhedron *P,
922 unsigned exist, unsigned nparam, unsigned MaxRays);
923 evalue* barvinok_enumerate_e_with_options(Polyhedron *P,
924 unsigned exist, unsigned nparam,
925 struct barvinok_options *options);
926 evalue *barvinok_enumerate_pip(Polyhedron *P,
927 unsigned exist, unsigned nparam, unsigned MaxRays);
928 evalue* barvinok_enumerate_pip_with_options(Polyhedron *P,
929 unsigned exist, unsigned nparam,
930 struct barvinok_options *options);
931 evalue *barvinok_enumerate_scarf(Polyhedron *P,
932 unsigned exist, unsigned nparam,
933 struct barvinok_options *options);
935 The first function tries the simplification rules from
936 \citeN[Section~
4.6.2]{Verdoolaege2005PhD
} before resorting to the method
937 based on
\indac{PIP
} from
\citeN[Section~
4.6.3]{Verdoolaege2005PhD
}.
938 The second function immediately applies the technique from
939 \citeN[Section~
4.6.3]{Verdoolaege2005PhD
}.
940 The argument
\verb+exist+ refers to the number of existential variables,
942 the argument
\verb+nparam+ refers to the number of parameters.
943 The order of the dimensions in
\verb+P+ is:
944 counted variables first, then existential variables and finally
946 The function
\ai[\tt]{barvinok
\_enumerate\_scarf} performs the same
947 computation as the function
\ai[\tt]{barvinok
\_enumerate\_scarf\_series}
948 below, but produces an explicit representation instead of a generating function.
951 gen_fun * barvinok_series(Polyhedron *P, Polyhedron* C,
953 gen_fun * barvinok_series_with_options(Polyhedron *P,
954 Polyhedron* C, barvinok_options *options);
955 gen_fun *barvinok_enumerate_scarf_series(Polyhedron *P,
956 unsigned exist, unsigned nparam,
957 barvinok_options *options);
960 \ai[\tt]{barvinok
\_series} or
961 \ai[\tt]{barvinok
\_series\_with\_options} enumerates parametric polytopes
962 in the form of a
\rgf/.
963 The polyhedron
\verb+P+ is assumed to have only
964 revlex-positive rays.
966 The function
\ai[\tt]{barvinok
\_enumerate\_scarf\_series} computes a
967 generating function for the number of point in the parametric set
968 defined by
\verb+P+ with
\verb+exist+ existentially quantified
969 variables, which is assumed to be
2.
970 This function implements the technique of
971 \shortciteN{Scarf2006Neighborhood
} using the
\ai{neighborhood complex
}
972 description of
\shortciteN{Scarf1981indivisibilities:II
}.
973 It is currently restricted to problems with
3 or
4 constraints involving
974 the existentially quantified variables.
976 \subsection{Auxiliary Functions
}
978 In this section we briefly mention some auxiliary functions
979 available in the
\barvinok/ library.
982 void Polyhedron_Polarize(Polyhedron *P);
984 The function
\ai[\tt]{Polyhedron
\_Polarize}
985 polarizes its argument and is explained
986 in
\citeN[Section~
4.4.2]{Verdoolaege2005PhD
}.
989 int unimodular_complete(Matrix *M, int row);
991 The function
\ai[\tt]{unimodular
\_complete} extends
992 the first
\verb+row+ rows of
993 \verb+M+ with an integral basis of the orthogonal complement
994 as explained in Section~
\ref{s:completion
}.
996 if the resulting matrix is unimodular
\index{unimodular matrix
}.
999 int DomainIncludes(Polyhedron *D1, Polyhedron *D2);
1001 The function
\ai[\tt]{DomainIncludes
} extends
1002 the function
\ai[\tt]{PolyhedronIncludes
}
1003 provided by
\PolyLib/
1004 to unions of polyhedra.
1005 It checks whether every polyhedron in the union
{\tt D2
}
1006 is included in some polyhedron of
{\tt D1
}.
1009 Polyhedron *DomainConstraintSimplify(Polyhedron *P,
1012 The value returned by
1013 \ai[\tt]{DomainConstraintSimplify
} is a pointer to
1014 a newly allocated
\ai[\tt]{Polyhedron
} that contains the
1015 same integer points as its first argument but possibly
1016 has simpler constraints.
1017 Each constraint $ g
\sp a x
\ge c $
1018 is replaced by $
\sp a x
\ge \ceil{ \frac c g
} $,
1019 where $g$ is the
\ac{gcd
} of the coefficients in the original
1021 The
\ai[\tt]{Polyhedron
} pointed to by
\verb+P+ is destroyed.
1024 Polyhedron* Polyhedron_Project(Polyhedron *P, int dim);
1026 The function
\ai[\tt]{Polyhedron
\_Project} projects
1027 \verb+P+ onto its last
\verb+dim+ dimensions.
1030 Matrix *left_inverse(Matrix *M, Matrix **Eq);
1032 The
\ai[\tt]{left
\_inverse} function computes the left inverse
1033 of
\verb+M+ as explained in Section~
\ref{s:inverse
}.
1035 \sindex{reduced
}{basis
}
1036 \sindex{generalized
}{reduced basis
}
1038 Matrix *Polyhedron_Reduced_Basis(Polyhedron *P,
1039 struct barvinok_options *options);
1041 \ai[\tt]{Polyhedron
\_Reduced\_Basis} computes
1042 a
\ai{generalized reduced basis
} of
{\tt P
}, which
1043 is assumed to be a polytope, using the algorithm
1044 of~
\shortciteN{Cook1993implementation
}.
1045 The basis vectors are stored in the rows of the matrix returned.
1046 This function currently uses
\ai[\tt]{GLPK
}~
\shortcite{GLPK
}
1047 to perform the linear optimizations and so is only available
1048 if you have
\ai[\tt]{GLPK
}.
1051 Vector *Polyhedron_Sample(Polyhedron *P,
1052 struct barvinok_options *options);
1054 \ai[\tt]{Polyhedron
\_Sample} returns an
\ai{integer point
} of
{\tt P
}
1055 or
{\tt NULL
} if
{\tt P
} contains no integer points.
1056 The integer point is found using the algorithm
1057 of~
\shortciteN{Cook1993implementation
} and uses
1058 \ai[\tt]{Polyhedron
\_Reduced\_Basis} to compute the reduced bases
1059 and therefore also requires
\ai[\tt]{GLPK
}.
1061 \subsection{\protect\ai[\tt]{bernstein
} Data Structures and Functions
}
1063 The
\bernstein/ library used
\ai[\tt]{GiNaC
} data structures to
1064 represent the data it manipulates.
1065 In particular, a polynomial is stored in a
\ai[\tt]{GiNaC::ex
},
1066 a list of variable or parameter names is stored in a
\ai[\tt]{GiNaC::exvector
},
1067 while the parametric vertices or generators are stored in a
\ai[\tt]{GiNaC::matrix
},
1068 where the rows refer to the generators and the columns to the coordinates
1072 namespace bernstein
{
1073 GiNaC::exvector constructParameterVector(
1074 const char * const *param_names, unsigned nbParams);
1075 GiNaC::exvector constructVariableVector(unsigned nbVariables,
1076 const char *prefix);
1079 The functions
\ai[\tt]{constructParameterVector
}
1080 and
\ai[\tt]{constructVariableVector
} construct a list of variable
1081 names either from a list of
{\tt char *
}s or
1082 by suffixing
{\tt prefix
} with a number starting from
0.
1083 Such lists are needed for the functions
1084 \ai[\tt]{domainVertices
},
\ai[\tt]{bernsteinExpansion
}
1085 and
\ai[\tt]{evalue
\_bernstein\_coefficients}.
1088 namespace bernstein
{
1089 GiNaC::matrix domainVertices(Param_Polyhedron *PP, Param_Domain *Q,
1090 const GiNaC::exvector& params);
1093 The function
\ai[\tt]{domainVertices
} constructs a matrix representing the
1094 generators (in this case vertices) of the
\ai[\tt]{Param
\_Polyhedron} {\tt PP
}
1095 for the
\ai[\tt]{Param
\_Domain} {\tt Q
}, to be used
1096 in a call to
\ai[\tt]{bernsteinExpansion
}.
1097 The elements of
{\tt params
} are used in the resulting matrix
1098 to refer to the parameters.
1101 namespace bernstein
{
1102 GiNaC::lst bernsteinExpansion(const GiNaC::matrix& vert,
1103 const GiNaC::ex& poly,
1104 const GiNaC::exvector& vars,
1105 const GiNaC::exvector& params);
1108 The function
\ai[\tt]{bernsteinExpansion
} computes the
1109 \ai{Bernstein coefficient
}s of the polynomial
\verb+poly+
1110 over the
\ai{parametric polytope
} that is the
\ai{convex hull
}
1111 of the rows in
\verb+vert+. The vectors
\verb+vars+
1112 and
\verb+params+ identify the variables (i.e., the coordinates
1113 of the space in which the parametric polytope lives) and
1114 the parameters, respectively.
1117 namespace bernstein
{
1119 typedef std::pair< Polyhedron *, GiNaC::lst > guarded_lst;
1121 struct piecewise_lst
{
1122 const GiNaC::exvector vars;
1123 std::vector<guarded_lst> list;
1124 /*
0: just collect terms
1125 *
1: remove obviously smaller terms (maximize)
1126 * -
1: remove obviously bigger terms (minimize)
1130 piecewise_lst(const GiNaC::exvector& vars);
1131 piecewise_lst& combine(const piecewise_lst& other);
1133 void simplify_domains(Polyhedron *ctx, unsigned MaxRays);
1134 GiNaC::numeric evaluate(const GiNaC::exvector& values);
1135 void add(const GiNaC::ex& poly);
1140 A
\ai[\tt]{piecewise
\_list} structure represents a list of (disjoint)
1141 polyhedral domains, each with an associated
\ai[\tt]{GiNaC::lst
}
1143 The
\ai[\tt]{vars
} member contains the variable names of the
1144 dimensions of the polyhedral domains.
1146 \ai[\tt]{piecewise
\_lst::combine
} computes the
\ai{common refinement
}
1147 of the polyhedral domains in
\verb+this+ and
\verb+other+ and associates
1148 to each of the resulting subdomains the union of the sets of polynomials
1149 associated to the domains from
\verb+this+ and
\verb+other+ that contain
1151 If the
\verb+sign+s of the
\ai[\tt]{piecewise
\_list}s are not zero,
1152 then the (obviously) redundant elements of these sets are removed
1154 The result is stored in
\verb+this+.
1156 \ai[\tt]{piecewise
\_lst::maximize
} removes polynomials from domains that evaluate
1157 to a value that is smaller than or equal to the value of some
1158 other polynomial associated to the same domain for each point in the domain.
1160 \ai[\tt]{piecewise
\_lst::evaluate
} ``evaluates'' the
\ai[\tt]{piecewise
\_list}
1161 by looking for the domain (if any) that contains the point given by
1162 \verb+values+ and computing the maximal value attained by any of the
1163 associated polynomials evaluated at that point.
1165 \ai[\tt]{piecewise
\_lst::add
} adds the polynomial
\verb+poly+
1166 to each of the polynomial associated to each of the domains.
1168 \ai[\tt]{piecewise
\_lst::simplify
\_domains} ``simplifies'' the domains
1169 by removing the constraints that are implied by the constraints
1170 in
\verb+ctx+, basically by calling
\PolyLib/'s
1171 \ai[\tt]{DomainSimplify
}. Note that you should only do this
1172 at the end of your computation. In particular, you do not
1173 want to call this method before calling
1174 \ai[\tt]{piecewise
\_lst::maximize
}, since this method will then
1175 have less information on the domains to exploit.
1179 namespace barvinok
{
1180 bernstein::piecewise_lst *evalue_bernstein_coefficients(
1181 bernstein::piecewise_lst *pl_all, evalue *e,
1182 Polyhedron *ctx, const GiNaC::exvector& params);
1183 bernstein::piecewise_lst *evalue_bernstein_coefficients(
1184 bernstein::piecewise_lst *pl_all, evalue *e,
1185 Polyhedron *ctx, const GiNaC::exvector& params,
1186 barvinok_options *options);
1189 The
\ai[\tt]{evalue
\_bernstein\_coefficients} function will compute the
1190 \ai{Bernstein coefficient
}s of the piecewise parametric polynomial stored in the
1191 \ai[\tt]{evalue
} \verb+e+.
1192 The
\verb+params+ vector specifies the names to be used for the parameters,
1193 while the context
\ai[\tt]{Polyhedron
} \verb+ctx+ specifies extra constraints
1195 The dimension of
\verb+ctx+ needs to be the same as the length of
\verb+params+.
1196 The
\ai[\tt]{evalue
} \verb+e+ is assumed to be of type
\ai[\tt]{partition
}
1197 and each of the domains in this
\ai[\tt]{partition
} is interpreted
1198 as a parametric polytope in the given parameters. The procedure
1199 will compute the
\ai{Bernstein coefficient
}s of the associated polynomial
1200 over each such parametric polytope.
1201 The resulting
\ai[\tt]{bernstein::piecewise
\_lst} collects the
1202 Bernstein coefficients over all parametric polytopes in
\verb+e+.
1203 If
\verb+pl_all+ is not
\verb+NULL+ then this list will be combined
1204 with the list computed by calling
\ai[\tt]{piecewise
\_lst::combine
}.
1205 If
\ai[\tt]{bernstein
\_optimize} is set to
\ai[\tt]{BV
\_BERNSTEIN\_MAX}
1206 in
\verb+options+, then this combination will remove obviously
1207 redundant Bernstein coefficients with respect to upper bound computation
1208 and similarly for
\ai[\tt]{BV
\_BERNSTEIN\_MIN}.
1209 The default (
\ai[\tt]{BV
\_BERNSTEIN\_NONE}) is to only remove duplicate
1210 Bernstein coefficients.