evalue.c: add evalue_add_constant
[barvinok.git] / doc / implementation.tex
blob8bd0e8c50cda9c2a1ecfee0a4eec42c570c99af8
1 \section{Implementation details}
3 \subsection{An interior point of a polyhedron}
4 \label{s:interior}
6 We often need a point that lies in the interior of a polyhedron.
7 The function \ai[\tt]{inner\_point} implements the following algorithm.
8 Each polyhedron $P$ can be written as the sum of a polytope $P'$ and a cone $C$
9 (the \ai{recession cone} or \ai{characteristic cone} of $P$).
10 Adding a positive multiple of the sum of the extremal rays of $C$ to
11 the \ai{barycenter}
13 \frac 1 N \sum_i \vec v_i(\vec p)
15 of $P'$, where $N$ is the number of vertices, results in a point
16 in the interior of $P$.
18 \subsection{The integer points in the fundamental parallelepiped of a simple cone}
20 \label{s:fundamental}
22 This section is based on \shortciteN[Lemma 5.1]{Barvinok1992volume} and
23 \shortciteN{Koeppe2006experiments}.
25 \sindex{simple}{cone}
26 \sindex{open}{facet}
27 \sindex{open}{ray}
28 \sindex{explicit}{representation}
29 In this section we will deal exclusively with \ai{simple cone}s,
30 i.e. $d$-dimensional cones with $d$ extremal rays and $d$ facets.
31 \index{open facet}%
32 Some of the facets of these cones may be open.
33 Since we will mostly be dealing with cones in their
34 \ai{explicit representation}, we will have occasion to speak of
35 ``\ai{open ray}s'', by which we will mean that the facet not
36 containing the ray is open. (There is only one such facet because the cone
37 is simple.)
39 \sindex{fundamental}{parallelepiped}
40 \begin{definition}[Fundamental parallelepiped]
41 Let $K = \vec v + \poshull \lb\, \vec u_i \,\rb$ be
42 a closed (shifted) cone, then the \defindex{fundamental parallelepiped} $\Pi$
43 of $K$ is
45 \Pi = \vec v +
46 \lb\, \sum_i \alpha_i \vec u_i \mid 0 \leq \alpha_i < 1 \,\rb
49 If some of the rays $\vec u_i$ of $K$ are open, then the constraints on
50 the corresponding coefficient $\alpha_i$ are such that $0 < \alpha_i \le 1$.
51 \end{definition}
53 \begin{lemma}[Integer points in the fundamental parallelepiped of a simple cone]
54 \label{l:fundamental}
55 Let $K = \vec v + \poshull \lb\, \vec u_i \,\rb$ be a closed simple cone
56 and let $A$ be the matrix with the generators $\vec u_i$ of $K$
57 as rows.
58 Furthermore let $V A W^{-1} = S = \diag \vec s$ be the \indac{SNF} of $A$.
59 Then the integer points in the fundamental parallelepiped of $K$ are given
61 \begin{eqnarray}
62 \label{eq:parallelepiped}
63 \vec w^\T & = & \vec v^\T + \fractional{(\vec k^\T W - \vec v^\T) A^{-1}} A
65 \nonumber
66 & = &
67 \vec v^T +
68 \sum_{i=1}^d
69 \fractional{\sps{\sum_{j=1}^d k_j \vec w^T_j - \vec v^\T}{\vec u^*_i}} \vec u_i,
70 \end{eqnarray}
71 where $\vec u^*_i$ are the columns of $A^{-1}$ and $k_j \in \ZZ$ ranges
72 over $0 \le k_j < s_j$.
73 \end{lemma}
75 \begin{proof}
76 Since $0 \le \fractional{x} < 1$, it is clear that each such $\vec w$
77 lies inside the fundamental parallelepiped.
78 Furthermore,
79 \begin{eqnarray*}
80 \vec w^\T & = & \vec v^\T + \fractional{(\vec k^\T W - \vec v^\T) A^{-1}} A
82 & = &
83 \vec v^T +
84 \left(
85 (\vec k^\T W - \vec v^\T) A^{-1} - \floor{(\vec k^\T W - \vec v^\T) A^{-1}}
86 \right) A
88 & = &
89 \underbrace{\vec k^\T W\mathstrut}_{\in \ZZ^{1\times d}}
91 \underbrace{\floor{(\vec k^\T W - \vec v^\T) A^{-1}}}_{\in \ZZ^{1\times d}}
92 \underbrace{A\mathstrut}_{\in \ZZ^{d\times d}} \in \ZZ^{1\times d}.
93 \end{eqnarray*}
94 Finally, if two such $\vec w$ are equal, i.e., $\vec w_1 = \vec w_2$,
95 then
96 \begin{eqnarray*}
97 \vec 0^\T = \vec w_1^\T - \vec w_2^\T
98 & = & \vec k_1^\T W - \vec k_2^\T W + \vec p^\T A
100 & = & \left(\vec k_1^\T - \vec k_2^\T \right) W + \vec p^\T V^{-1} S W,
101 \end{eqnarray*}
102 with $\vec p \in \ZZ^d$,
103 or $\vec k_1 \equiv \vec k_2 \mod \vec s$, i.e., $\vec k_1 = \vec k_2$.
104 Since $\det S = \det A$, we obtain all points in the fundamental parallelepiped
105 by taking all $\vec k \in \ZZ^d$ satisfying $0 \le k_j < s_j$.
106 \end{proof}
108 If the cone $K$ is not closed then the coefficients of the open rays
109 should be in $(0,1]$ rather than in $[0,1)$.
110 In (\ref{eq:parallelepiped}),
111 we therefore need to replace the fractional part $\fractional{x} = x - \floor{x}$
112 by $\cractional{x} = x - \ceil{x-1}$ for the open rays.
114 \begin{figure}
115 \intercol=1.2cm
116 \begin{xy}
117 <\intercol,0pt>:<0pt,\intercol>::
118 \POS@i@={(0,-3),(0,0),(4,2),(4,-3)},{0*[grey]\xypolyline{*}}
119 \POS@i@={(0,-3),(0,0),(4,2)},{0*[|(2)]\xypolyline{}}
120 \POS(-1,0)\ar(4.5,0)
121 \POS(0,-3)\ar(0,3)
122 \POS(0,0)\ar@[|(3)](0,-1)
123 \POS(0,0)\ar@[|(3)](2,1)
124 \POS(0,-1)\ar@{--}@[|(2)](2,0)
125 \POS(2,1)\ar@{--}@[|(2)](2,0)
126 \POS(0,0)*{\bullet}
127 \POS(1,0)*{\bullet}
128 \end{xy}
129 \caption{The integer points in the fundamental parallelepiped of $K$}
130 \label{f:parallelepiped}
131 \end{figure}
133 \begin{example}
134 Let $K$ be the cone
136 K = \sm{0 \\ 0} + \poshull \lb\, \sm{2 \\ 1}, \sm{0 \\ -1} \,\rb
139 shown in Figure~\ref{f:parallelepiped}.
140 Then
142 A = \sm{2 & 1\\0 & -1} \qquad A^{-1} = \sm{1/2 & 1/2 \\ 0 & -1 }
146 \sm{1 & 0 \\ 1 & 1 } \sm{2 & 1\\0 & -1} = \sm{1 & 0 \\ 0 & 2} \sm{2 & 1 \\ 1 & 0}.
148 We have $\det A = \det S = 2$ and
149 $\vec k_1^\T = \sm{0 & 0}$ and $\vec k_2^\T = \sm{0 & 1}$.
150 Therefore,
152 \vec w_1^\T = \fractional{\sm{0 & 0} \sm{2 & 1 \\ 1 & 0} \sm{1/2 & 1/2 \\ 0 & -1 }}
153 \sm{2 & 1\\0 & -1} = \sm{0 & 0}
156 \begin{eqnarray*}
157 \vec w_2^\T & = &
158 \fractional{\sm{0 & 1} \sm{2 & 1 \\ 1 & 0} \sm{1/2 & 1/2 \\ 0 & -1 }}
159 \sm{2 & 1\\0 & -1}
161 & = &
162 \sm{1/2 & 1/2} \sm{2 & 1\\0 & -1} = \sm{1 & 0}.
163 \end{eqnarray*}
164 \end{example}
169 \subsection{Barvinok's decomposition of simple cones in primal space}
170 \label{s:decomposition}
172 As described by \shortciteN{DeLoera2003effective}, the first
173 implementation of Barvinok's counting algorithm applied
174 \ai{Barvinok's decomposition} \shortcite{Barvinok1994} in the \ai{dual space}.
175 \ai{Brion's polarization trick} \shortcite{Brion88} then ensures that you
176 do not need to worry about lower-dimensional faces in the decomposition.
177 Another way of avoiding the lower-dimensional faces, in the \ai{primal space},
178 is to perturb the vertex of the cone such that none of the lower-dimensional
179 face encountered contain any integer points \shortcite{Koeppe2006primal}.
180 In this section, we describe another technique that is based on allowing
181 some of the facets of the cone to be open.
183 The basic step in Barvinok's decomposition is to replace a
184 $d$-dimensional simple cone
185 $K = \poshull \lb\, \vec u_i \,\rb_{i=1}^d \subset \QQ^d$
186 by a signed sum of (at most) $d$ cones $K_j$
187 with a smaller determinant (in absolute value).
188 The cones are obtained by successively replacing each generator
189 of $K$ by an appropriately chosen
190 $\vec w = \sum_{i=1}^d \alpha_i \vec u_i$, i.e.,
191 \begin{equation}
192 \label{eq:K_j}
193 K_j =
194 \poshull \left(\lb\, \vec u_i \,\rb_{i=1}^d
195 \setminus \{\, \vec u_j \,\} \cup \{\, \vec w \,\}\right)
197 \end{equation}
198 To see that we can use these $K_j$ to perform a decomposition,
199 rearrange the $\vec u_i$ such that for all $1 \le i \le k$ we have
200 $\alpha_i < 0$ and for all $k+1 \le i \le d'$ we have $\alpha_i > 0$,
201 with $d - d'$ the number of zero $\alpha_i$.
202 We may assume $k < d'$; otherwise replace $\vec w \in B$ by
203 $-\vec w \in B$. We have
205 \vec w + \sum_{i=1}^k (-\alpha_i) \vec u_i =
206 \sum_{i=k+1}^{d'} \alpha_i \vec u_i
209 \begin{equation}
210 \label{eq:sub}
211 \sum_{i=0}^k \beta_i \vec u_i =
212 \sum_{i=k+1}^{d'} \alpha_i \vec u_i
214 \end{equation}
215 with $\vec u_0 = \vec w$, $\beta_0 = 1$ and $\beta_i = -\alpha_i > 0$
216 for $1 \le i \le k$. Any two $\vec u_j$ and $\vec u_l$ on the same side
217 of the equality are on opposite sides of the linear hull $H$ of
218 the other $\vec u_i$s since there exists a convex combination
219 of $\vec u_j$ and $\vec u_l$ on this hyperplane.
220 In particular, since $\alpha_j$ and $\alpha_l$ have the same sign,
221 we have
222 \begin{equation}
223 \label{eq:opposite}
224 \frac {\alpha_j}{\alpha_j+\alpha_l} \vec u_j
226 \frac {\alpha_l}{\alpha_j+\alpha_l} \vec u_l
227 \in H
228 \qquad\text{for $\alpha_i \alpha_l > 0$}
230 \end{equation}
231 The corresponding cones $K_j$ and $K_l$ (with $K_0 = K$)
232 therefore intersect in a common face $F \subset H$.
233 Let
235 K' :=
236 \poshull \left(\lb\, \vec u_i \,\rb_{i=1}^d \cup \{\, \vec w \,\}\right)
239 then any $\vec x \in K'$ lies both in some cone $K_i$ with
240 $0 \le i \le k$ and in some cone $K_i$ with $k+1 \le i \le d'$.
241 (Just subtract an appropriate multiple of Equation~(\ref{eq:sub}).)
242 The cones
243 $\{\, K_i \,\}_{i=0}^k$
245 $\{\, K_i \,\}_{i=k+1}^{d'}$
246 therefore both form a triangulation of $K'$ and hence
247 \begin{equation}
248 \label{eq:triangulations}
249 \indf{K'}
251 \indf{K} + \sum_{i=1}^k \indf{K_i} - \sum_{j\in J_1} \indf{F_j}
253 \sum_{i=k+1}^{d'} \indf{K_i} - \sum_{j\in J_2} \indf{F_j}
254 \end{equation}
256 \begin{equation}
257 \label{eq:decomposition}
258 \indf{K} = \sum_{i=1}^{d'} \varepsilon_i \indf{K_i} + \sum_j \delta_j \indf{F_j}
260 \end{equation}
261 with $\varepsilon_i = -1$ for $1 \le i \le k$,
262 $\varepsilon_i = 1$ for $k+1 \le i \le d'$,
263 $\delta_j \in \{ -1, 1 \}$ and $F_j$ some lower-dimensional faces.
264 Figure~\ref{fig:w} shows the possible configurations
265 in the case of a $3$-dimensional cone.
267 \begin{figure}
268 \intercol=0.48cm
269 \begin{center}
270 \begin{minipage}{0cm}
271 \begin{xy}
272 <\intercol,0pt>:<0pt,\intercol>::
274 \xybox{
275 \POS(-2,-1)="a"*+!U{+}
276 \POS(2,0)="b"*+!L{+}
277 \POS(0,2)="c"*+!D{+}
278 \POS(0,0)="w"*+!DR{\vec w}
279 \POS"a"\ar@{-}"b"
280 \POS"b"\ar@{-}"c"
281 \POS"c"\ar@{-}"a"
282 \POS"a"\ar@{--}"w"
283 \POS"b"\ar@{--}"w"
284 \POS"c"\ar@{--}"w"
285 }="a"
286 +R+(2,0)*!L
287 \xybox{
288 \POS(-2,-1)="a"*+!U{+}
289 \POS(2,0)="b"*+!L{-}
290 \POS(0,2)="c"*+!D{+}
291 \POS(-3,1)="w"*+!DR{\vec w}
292 \POS"a"\ar@{-}"b"
293 \POS"b"\ar@{-}"c"
294 \POS"c"\ar@{-}"a"
295 \POS"a"\ar@{--}"w"
296 \POS"b"\ar@{--}"w"
297 \POS"c"\ar@{--}"w"
298 }="b"
299 +R+(2,0)*!L
300 \xybox{
301 \POS(-2,-1)="a"*+!U{-}
302 \POS(2,0)="b"*+!U{+}
303 \POS(0,2)="c"*+!D{-}
304 \POS(5,-1)="w"*+!L{\vec w}
305 \POS"a"\ar@{-}"b"
306 \POS"b"\ar@{-}"c"
307 \POS"c"\ar@{-}"a"
308 \POS"a"\ar@{--}"w"
309 \POS"b"\ar@{--}"w"
310 \POS"c"\ar@{--}"w"
312 \POS"a"
313 +D-(0,1)*!U
314 \xybox{
315 \POS(-2,-1)="a"*+!U{0}
316 \POS(2,0)="b"*+!L{+}
317 \POS(0,2)="c"*+!D{+}
318 \POS(1,1)="w"*+!DL{\vec w}
319 \POS"a"\ar@{-}"b"
320 \POS"b"\ar@{-}"c"
321 \POS"c"\ar@{-}"a"
322 \POS"a"\ar@{--}"w"
324 \POS"b"
325 +DL-(0,1)*!UL
326 \xybox{
327 \POS(-2,-1)="a"*+!U{0}
328 \POS(2,0)="b"*+!U{+}
329 \POS(0,2)="c"*+!D{-}
330 \POS(4,-2)="w"*+!L{\vec w}
331 \POS"a"\ar@{-}"b"
332 \POS"b"\ar@{-}"c"
333 \POS"c"\ar@{-}"a"
334 \POS"a"\ar@{--}"w"
335 \POS"b"\ar@{--}"w"
337 \end{xy}
338 \end{minipage}
339 \end{center}
340 \caption[Possible locations of the vector $\vec w$ with respect to the rays
341 of a $3$-dimensional cone.]
342 {Possible locations of $\vec w$ with respect to the rays
343 of a $3$-dimensional cone. The figure shows a section of the cones.}
344 \label{fig:w}
345 \end{figure}
347 As explained above there are several ways of avoiding the lower-dimensional
348 faces in (\ref{eq:decomposition}). Here we will apply the following proposition.
349 \begin{proposition}[\shortciteN{Koeppe2007parametric}]
350 \label{p:inclusion-exclusion}
351 Let
352 \begin{equation}
353 \label{eq:full-source-identity}
354 \sum_{i\in {I_1}} \epsilon_i [P_i] + \sum_{i\in {I_2}} \delta_k [P_i] = 0
355 \end{equation}
356 be a (finite) linear identity of indicator functions of closed
357 polyhedra~$P_i\subseteq\QQ^d$, where the
358 polyhedra~$P_i$ with $i \in I_1$ are full-dimensional and those with $i \in I_2$
359 lower-dimensional. Let each closed polyhedron be given as
361 P_i = \left\{\, \vec x \mid \sp{b^*_{i,j}}{x} \ge \beta_{i,j} \text{
362 for $j\in J_i$}\,\right\}
365 Let $\vec y\in\QQ^d$ be a vector such that $\langle \vec b^*_{i,j}, \vec
366 y\rangle \neq 0$ for all $i\in I_1\cup I_2$, $j\in J_i$.
367 For each $i\in I_1$, we define the half-open polyhedron
368 \begin{equation}
369 \label{eq:half-open-by-y}
370 \begin{aligned}
371 \tilde P_i = \Bigl\{\, \vec x\in\QQ^d \mid {}&
372 \sp{b^*_{i,j}}{x} \ge \beta_{i,j}
373 \text{ for $j\in J_i$ with $\sp{b^*_{i,j}}{y} > 0$,} \\
374 & \sp{b^*_{i,j}}{x} > \beta_{i,j}
375 \text{ for $j\in J_i$ with $\sp{b^*_{i,j}}{y} < 0$} \,\Bigr\}.
376 \end{aligned}
377 \end{equation}
378 Then
379 \begin{equation}
380 \label{eq:target-identity}
381 \sum_{i\in I_1} \epsilon_i [\tilde P_i] = 0.
382 \end{equation}
383 \end{proposition}
384 When applying this proposition to (\ref{eq:decomposition}), we obtain
385 \begin{equation}
386 \label{eq:decomposition:2}
387 \indf{\tilde K} = \sum_{i=1}^{d'} \varepsilon_i \indf{\tilde K_i}
389 \end{equation}
390 where we start out
391 from a given $\tilde K$, which may be $K$ itself, i.e., a fully closed cone,
392 or the result of a previous application of the proposition, either through
393 a triangulation (Section~\ref{s:triangulation}) or a previous decomposition.
394 In either case, a suitable $\vec y$ is available, either as an interior
395 point of the cone or as the vector used in the previous application
396 (which may require a slight perturbation if it happens to lie on one of
397 the new facets of the cones $K_i$).
398 We are, however, free to construct a new $\vec y$ on each application
399 of the proposition.
400 In fact, we will not even construct such a vector explicitly, but
401 rather apply a set of rules that is equivalent to a valid choice of $\vec y$.
402 Below, we will present an ``intuitive'' motivation for these rules.
403 For a more algebraic, shorter, and arguably simpler motivation we
404 refer to \shortciteN{Koeppe2007parametric}.
406 The vector $\vec y$ has to satisfy $\sp{b^*_j}y > 0$ for normals $\vec b^*_j$
407 of closed facets and $\sp{b^*_j}y < 0$ for normals $\vec b^*_j$ of open facets of
408 $\tilde K$.
409 These constraints delineate a non-empty open cone $R$ from which
410 $\vec y$ should be selected. For some of the new facets of the cones
411 $\tilde K_j$, the cone $R$ will not be cut by the affine hull of the facet.
412 The closedness of these facets is therefore predetermined by $\tilde K$.
413 For the other facets, a choice will have to be made.
414 To be able to make the choice based on local information and without
415 computing an explicit vector $\vec y$, we use the following convention.
416 We first assign an arbitrary total order to the rays.
417 If (the affine hull of) a facet separates the two rays not on the facet $\vec u_i$
418 and $\vec u_j$, i.e., $\alpha_i \alpha_j > 0$ (\ref{eq:opposite}), then
419 we choose $\vec y$ to lie on the side of the smallest ray, according
420 to the chosen order.
421 That is, $\sp{{\tilde n}_{ij}}y > 0$, for
422 $\vec {\tilde n}_{ij}$ the normal of the facet pointing towards this smallest ray.
423 Otherwise, i.e., if $\alpha_i \alpha_j < 0$,
424 the interior of $K$ will lie on one side
425 of the facet and then we choose $\vec y$ to lie on the other side.
426 That is, $\sp{{\tilde n}_{ij}}y > 0$, for
427 $\vec {\tilde n}_{ij}$ the normal of the facet pointing away from the cone $K$.
428 Figure~\ref{fig:primal:examples} shows some example decompositions with
429 an explicitly marked $\vec y$.
431 \begin{figure}
432 \begin{align*}
433 \intercol=0.48cm
434 \begin{xy}
435 <\intercol,0pt>:<0pt,\intercol>::
436 \POS(-2,-1)="a"*+!U{+}
437 \POS(2,0)="b"*+!L{+}
438 \POS(0,2)="c"*+!D{+}
439 \POS"a"\ar@{-}@[|(3)]"b"
440 \POS"b"\ar@{-}@[|(3)]"c"
441 \POS"c"\ar@{-}@[|(3)]"a"
442 \POS(0.3,0.6)*{\bullet},*+!L{\vec y}
443 \end{xy}
445 \intercol=0.48cm
446 \begin{xy}
447 <\intercol,0pt>:<0pt,\intercol>::
448 \POS(2,0)="b"*+!L{+}
449 \POS(0,2)="c"*+!D{+}
450 \POS(0,0)="w"*+!DR{\vec w}
451 \POS"b"\ar@{-}@[|(3)]"c"
452 \POS"b"\ar@{-}@[|(3)]"w"
453 \POS"c"\ar@{-}@[|(3)]"w"
454 \POS(0.3,0.6)*{\bullet},*+!L{\vec y}
455 \end{xy}
457 \begin{xy}
458 <\intercol,0pt>:<0pt,\intercol>::
459 \POS(-2,-1)="a"*+!U{+}
460 \POS(0,2)="c"*+!D{+}
461 \POS(0,0)="w"*+!DR{\vec w}
462 \POS"c"\ar@{-}@[|(3)]"a"
463 \POS"a"\ar@{-}@[|(3)]"w"
464 \POS"c"\ar@{--}@[|(3)]"w"
465 \POS(0.3,0.6)*{\bullet},*+!L{\vec y}
466 \end{xy}
468 \begin{xy}
469 <\intercol,0pt>:<0pt,\intercol>::
470 \POS(-2,-1)="a"*+!U{+}
471 \POS(2,0)="b"*+!L{+}
472 \POS(0,0)="w"*+!DR{\vec w}
473 \POS"a"\ar@{-}@[|(3)]"b"
474 \POS"a"\ar@{--}@[|(3)]"w"
475 \POS"b"\ar@{--}@[|(3)]"w"
476 \POS(0.3,0.6)*{\bullet},*+!L{\vec y}
477 \end{xy}
479 \intercol=0.48cm
480 \begin{xy}
481 <\intercol,0pt>:<0pt,\intercol>::
482 \POS(-2,-1)="a"*+!U{+}
483 \POS(2,0)="b"*+!L{+}
484 \POS(0,2)="c"*+!D{+}
485 \POS"a"\ar@{--}@[|(3)]"b"
486 \POS"b"\ar@{-}@[|(3)]"c"
487 \POS"c"\ar@{--}@[|(3)]"a"
488 \POS(-2.5,-1.5)*{\bullet},*+!U{\vec y}
489 \end{xy}
491 \intercol=0.48cm
492 \begin{xy}
493 <\intercol,0pt>:<0pt,\intercol>::
494 \POS(2,0)="b"*+!L{+}
495 \POS(0,2)="c"*+!D{+}
496 \POS(0,0)="w"*+!DR{\vec w}
497 \POS"b"\ar@{-}@[|(3)]"c"
498 \POS"b"\ar@{--}@[|(3)]"w"
499 \POS"c"\ar@{--}@[|(3)]"w"
500 \POS(-2.5,-1.5)*{\bullet},*+!U{\vec y}
501 \end{xy}
503 \begin{xy}
504 <\intercol,0pt>:<0pt,\intercol>::
505 \POS(-2,-1)="a"*+!U{+}
506 \POS(0,2)="c"*+!D{+}
507 \POS(0,0)="w"*+!DR{\vec w}
508 \POS"c"\ar@{--}@[|(3)]"a"
509 \POS"a"\ar@{--}@[|(3)]"w"
510 \POS"c"\ar@{-}@[|(3)]"w"
511 \POS(-2.5,-1.5)*{\bullet},*+!U{\vec y}
512 \end{xy}
514 \begin{xy}
515 <\intercol,0pt>:<0pt,\intercol>::
516 \POS(-2,-1)="a"*+!U{+}
517 \POS(2,0)="b"*+!L{+}
518 \POS(0,0)="w"*+!DR{\vec w}
519 \POS"a"\ar@{--}@[|(3)]"b"
520 \POS"a"\ar@{-}@[|(3)]"w"
521 \POS"b"\ar@{-}@[|(3)]"w"
522 \POS(-2.5,-1.5)*{\bullet},*+!U{\vec y}
523 \end{xy}
525 \intercol=0.48cm
526 \begin{xy}
527 <\intercol,0pt>:<0pt,\intercol>::
528 \POS(-2,-1)="a"*+!U{+}
529 \POS(2,0)="b"*+!L{+}
530 \POS(0,2)="c"*+!D{+}
531 \POS"a"\ar@{--}@[|(3)]"b"
532 \POS"b"\ar@{-}@[|(3)]"c"
533 \POS"c"\ar@{-}@[|(3)]"a"
534 \POS(1,-1.5)*{\bullet},*+!L{\vec y}
535 \end{xy}
537 \intercol=0.48cm
538 \begin{xy}
539 <\intercol,0pt>:<0pt,\intercol>::
540 \POS(2,0)="b"*+!L{+}
541 \POS(0,2)="c"*+!D{+}
542 \POS(0,0)="w"*+!DR{\vec w}
543 \POS"b"\ar@{-}@[|(3)]"c"
544 \POS"b"\ar@{--}@[|(3)]"w"
545 \POS"c"\ar@{-}@[|(3)]"w"
546 \POS(1,-1.5)*{\bullet},*+!L{\vec y}
547 \end{xy}
549 \begin{xy}
550 <\intercol,0pt>:<0pt,\intercol>::
551 \POS(-2,-1)="a"*+!U{+}
552 \POS(0,2)="c"*+!D{+}
553 \POS(0,0)="w"*+!DR{\vec w}
554 \POS"c"\ar@{-}@[|(3)]"a"
555 \POS"a"\ar@{--}@[|(3)]"w"
556 \POS"c"\ar@{--}@[|(3)]"w"
557 \POS(1,-1.5)*{\bullet},*+!L{\vec y}
558 \end{xy}
560 \begin{xy}
561 <\intercol,0pt>:<0pt,\intercol>::
562 \POS(-2,-1)="a"*+!U{+}
563 \POS(2,0)="b"*+!L{+}
564 \POS(0,0)="w"*+!DR{\vec w}
565 \POS"a"\ar@{--}@[|(3)]"b"
566 \POS"a"\ar@{-}@[|(3)]"w"
567 \POS"b"\ar@{-}@[|(3)]"w"
568 \POS(1,-1.5)*{\bullet},*+!L{\vec y}
569 \end{xy}
571 \intercol=0.48cm
572 \begin{xy}
573 <\intercol,0pt>:<0pt,\intercol>::
574 \POS(-2,-1)="a"*+!U{0}
575 \POS(2,0)="b"*+!L{+}
576 \POS(0,2)="c"*+!D{+}
577 \POS"a"\ar@{-}@[|(3)]"b"
578 \POS"b"\ar@{-}@[|(3)]"c"
579 \POS"c"\ar@{-}@[|(3)]"a"
580 \POS(1,0.2)*{\bullet},*+!R{\vec y}
581 \end{xy}
583 \intercol=0.48cm
584 \begin{xy}
585 <\intercol,0pt>:<0pt,\intercol>::
586 \POS(-2,-1)="a"*+!U{0}
587 \POS(2,0)="b"*+!L{+}
588 \POS(1,1)="w"*+!DL{\vec w}
589 \POS"a"\ar@{-}@[|(3)]"b"
590 \POS"a"\ar@{-}@[|(3)]"w"
591 \POS"b"\ar@{-}@[|(3)]"w"
592 \POS(1,0.2)*{\bullet},*+!R{\vec y}
593 \end{xy}
595 \begin{xy}
596 <\intercol,0pt>:<0pt,\intercol>::
597 \POS(-2,-1)="a"*+!U{0}
598 \POS(0,2)="c"*+!D{+}
599 \POS(1,1)="w"*+!DL{\vec w}
600 \POS"c"\ar@{-}@[|(3)]"a"
601 \POS"a"\ar@{--}@[|(3)]"w"
602 \POS"c"\ar@{-}@[|(3)]"w"
603 \POS(1,0.2)*{\bullet},*+!R{\vec y}
604 \end{xy}
606 \intercol=0.48cm
607 \begin{xy}
608 <\intercol,0pt>:<0pt,\intercol>::
609 \POS(-2,-1)="a"*+!U{0}
610 \POS(2,0)="b"*+!U{+}
611 \POS(0,2)="c"*+!D{-}
612 \POS"a"\ar@{-}@[|(3)]"b"
613 \POS"b"\ar@{--}@[|(3)]"c"
614 \POS"c"\ar@{-}@[|(3)]"a"
615 \POS(1.5,1.5)*{\bullet},*+!D{\vec y}
616 \end{xy}
618 \intercol=0.48cm
619 \begin{xy}
620 <\intercol,0pt>:<0pt,\intercol>::
621 \POS(-2,-1)="a"*+!U{0}
622 \POS(0,2)="c"*+!D{-}
623 \POS(4,-2)="w"*+!L{\vec w}
624 \POS"c"\ar@{-}@[|(3)]"a"
625 \POS"a"\ar@{-}@[|(3)]"w"
626 \POS"c"\ar@{--}@[|(3)]"w"
627 \POS(1.5,1.5)*{\bullet},*+!D{\vec y}
628 \end{xy}
630 \begin{xy}
631 <\intercol,0pt>:<0pt,\intercol>::
632 \POS(-2,-1)="a"*+!U{0}
633 \POS(2,0)="b"*+!U{+}
634 \POS(4,-2)="w"*+!L{\vec w}
635 \POS"a"\ar@{--}@[|(3)]"b"
636 \POS"a"\ar@{-}@[|(3)]"w"
637 \POS"b"\ar@{--}@[|(3)]"w"
638 \POS(1.5,1.5)*{\bullet},*+!D{\vec y}
639 \end{xy}
641 \intercol=0.48cm
642 \begin{xy}
643 <\intercol,0pt>:<0pt,\intercol>::
644 \POS(-2,-1)="a"*+!U{0}
645 \POS(2,0)="b"*+!U{+}
646 \POS(0,2)="c"*+!D{-}
647 \POS"a"\ar@{--}@[|(3)]"b"
648 \POS"b"\ar@{--}@[|(3)]"c"
649 \POS"c"\ar@{-}@[|(3)]"a"
650 \POS(4.7,-2.5)*{\bullet},*+!R{\vec y}
651 \end{xy}
653 \intercol=0.48cm
654 \begin{xy}
655 <\intercol,0pt>:<0pt,\intercol>::
656 \POS(-2,-1)="a"*+!U{0}
657 \POS(0,2)="c"*+!D{-}
658 \POS(4,-2)="w"*+!L{\vec w}
659 \POS"c"\ar@{-}@[|(3)]"a"
660 \POS"a"\ar@{--}@[|(3)]"w"
661 \POS"c"\ar@{--}@[|(3)]"w"
662 \POS(4.7,-2.5)*{\bullet},*+!R{\vec y}
663 \end{xy}
665 \begin{xy}
666 <\intercol,0pt>:<0pt,\intercol>::
667 \POS(-2,-1)="a"*+!U{0}
668 \POS(2,0)="b"*+!U{+}
669 \POS(4,-2)="w"*+!L{\vec w}
670 \POS"a"\ar@{-}@[|(3)]"b"
671 \POS"a"\ar@{--}@[|(3)]"w"
672 \POS"b"\ar@{--}@[|(3)]"w"
673 \POS(4.7,-2.5)*{\bullet},*+!R{\vec y}
674 \end{xy}
675 \end{align*}
676 \caption{Examples of decompositions in primal space.}
677 \label{fig:primal:examples}
678 \end{figure}
680 To see that there is a $\vec y$ satisfying the above constraints,
681 we need to show that $R \cap S$ is non-empty, with
682 $S = \{ \vec y \mid \sp{{\tilde n}_{i_kj_k}}y > 0 \text{ for all $k$}\}$.
683 It will be easier to show this set is non-empty when the $\vec u_i$ form
684 an orthogonal basis. Applying a non-singular linear transformation $T$
685 does not change the decomposition of $\vec w$ in terms of the $\vec u_i$ (i.e., the
686 $\alpha_i$ remain unchanged), nor does this change
687 any of the scalar products in the constraints that define $R \cap S$
688 (the normals are transformed by $\left(T^{-1}\right)^\T$).
689 Finding a vector $\vec y \in T(R \cap S)$ ensures that
690 $T^{-1}(\vec y) \in R \cap S$.
691 Without loss of generality, we can therefore assume for the purpose of
692 showing that $R \cap S$ is non-empty that
693 the $\vec u_i$ indeed form an orthogonal basis.
695 In the orthogonal basis, we have $\vec b_i^* = \vec u_i$
696 and the corresponding inward normal $\vec N_i$ is either
697 $\vec u_i$ or $-\vec u_i$.
698 Furthermore, each normal of a facet of $S$ of the first type is of the
699 form $\vec {\tilde n}_{i_kj_k} = a_k \vec u_{i_k} - b_k \vec u_{j_k}$, with
700 $a_k, b_k > 0$ and ${i_k} < {j_k}$,
701 while for the second type each normal is of the form
702 $\vec {\tilde n}_{i_kj_k} = -a_k \vec u_{i_k} - b_k \vec u_{j_k}$, with
703 $a_k, b_k > 0$.
704 If $\vec {\tilde n}_{i_kj_k} = a_k \vec u_{i_k} - b_k \vec u_{j_k}$
705 is the normal of a facet of $S$
706 then either
707 $(\vec N_{i_k}, \vec N_{j_k}) = (\vec u_{i_k}, \vec u_{j_k})$
709 $(\vec N_{i_k}, \vec N_{j_k}) = (-\vec u_{i_k}, -\vec u_{j_k})$.
710 Otherwise, the facet would not cut $R$.
711 Similarly,
712 if $\vec {\tilde n}_{i_kj_k} = -a_k \vec u_{i_k} - b_k \vec u_{j_k}$
713 is the normal of a facet of $S$
714 then either
715 $(\vec N_{i_k}, \vec N_{j_k}) = (\vec u_{i_k}, -\vec u_{j_k})$
717 $(\vec N_{i_k}, \vec N_{j_k}) = (-\vec u_{i_k}, \vec u_{j_k})$.
718 Assume now that $R \cap S$ is empty, then there exist
719 $\lambda_k, \mu_i \ge 0$ not all zero
720 such that
721 $\sum_k \lambda_k \vec {\tilde n}_{i_kj_k} + \sum_l \mu_i \vec N_i = \vec 0$.
722 Assume $\lambda_k > 0$ for some facet of the first type.
723 If $\vec N_{j_k} = -\vec u_{j_k}$, then $-b_k$ can only be canceled
724 by another facet $k'$ of the first type with $j_k = i_{k'}$, but then
725 also $\vec N_{j_{k'}} = -\vec u_{j_{k'}}$. Since the $j_k$ are strictly
726 increasing, this sequence has to stop with a strictly positive coefficient
727 for the largest $\vec u_{j_k}$ in this sequence.
728 If, on the other hand, $\vec N_{i_k} = \vec u_{i_k}$, then $a_k$ can only
729 be canceled by the normal of a facet $k'$ of the second kind
730 with $i_k = j_{k'}$, but then
731 $\vec N_{i_{k'}} = -\vec u_{i_{k'}}$ and we return to the first case.
732 Finally, if $\lambda_k > 0$ only for normals of facets of the second type,
733 then either $\vec N_{i_k} = -\vec u_{i_k}$ or $\vec N_{j_k} = -\vec u_{j_k}$
734 and so the coefficient of one of these basis vectors will be strictly
735 negative.
736 That is, the sum of the normals will never be zero and
737 the set $R \cap S$ is non-empty.
739 For each ray $\vec u_j$ of cone $K_i$, i.e., the cone with $\vec u_i$ replaced
740 by $\vec w$, we now need to determine whether the facet not containing this
741 ray is closed or not. We denote the (inward) normal of this cone by
742 $\vec n_{ij}$. Note that cone $K_j$ (if it appears in (\ref{eq:triangulations}),
743 i.e., $\alpha_j \ne 0$) has the same facet opposite $\vec u_i$
744 and its normal $\vec n_{ji}$ will be equal to either $\vec n_{ij}$ or
745 $-\vec n_{ij}$, depending on whether we are dealing with an ``external'' facet,
746 i.e., a facet of $K'$, or an ``internal'' facet.
747 If, on the other hand, $\alpha_j = 0$, then $\vec n_{ij} = \vec n_{0j}$.
748 If $\sp{n_{ij}}y > 0$, then the facet is closed.
749 Otherwise it is open.
750 It follows that the two (or more) occurrences of external facets are either all open
751 or all closed, while for internal facets, exactly one is closed.
753 First consider the facet not containing $\vec u_0 = \vec w$.
754 If $\alpha_i > 0$, then $\vec u_i$ and $\vec w$ are on the same side of the facet
755 and so $\vec n_{i0} = \vec n_{0i}$. Otherwise, $\vec n_{i0} = -\vec n_{i0}$.
756 Second, if $\alpha_j = 0$, then replacing $\vec u_i$ by $\vec w$ does not
757 change the affine hull of the facet and so $\vec n_{ij} = \vec n_{0j}$.
758 Now consider the case that $\alpha_i \alpha_j < 0$, i.e., $\vec u_i$
759 and $\vec u_j$ are on the same side of the hyperplane through the other rays.
760 If we project $\vec u_i$, $\vec u_j$ and $\vec w$ onto a plane orthogonal
761 to the ridge through the other rays, then the possible locations of $\vec w$
762 with respect to $\vec u_i$ and $\vec u_j$ are shown in Figure~\ref{fig:w:same}.
763 If both $\vec n_{0i}$ and $\vec n_{0j}$ are closed then $\vec y$ lies in region~1
764 and therefore $\vec n_{ij}$ (as well as $\vec n_{ji}$) is closed too.
765 Similarly, if both $\vec n_{0i}$ and $\vec n_{0j}$ are open then so is
766 $\vec n_{ij}$. If only one of the facets is closed, then, as explained above,
767 we choose $\vec n_{ij}$ to be open, i.e., we take $\vec y$ to lie in region~3
768 or~5.
769 Figure~\ref{fig:w:opposite} shows the possible configurations
770 for the case that $\alpha_i \alpha_j > 0$.
771 If exactly one of $\vec n_{0i}$ and $\vec n_{0j}$ is closed, then
772 $\vec y$ lies in region~3 or region~5 and therefore $\vec n_{ij}$ is closed iff
773 $\vec n_{0j}$ is closed.
774 Otherwise, as explained above, we choose $\vec n_{ij}$ to be closed if $i < j$.
776 \begin{figure}
777 \intercol=0.7cm
778 \begin{minipage}{0cm}
779 \begin{xy}
780 <\intercol,0pt>:<0pt,\intercol>::
781 \POS(-4,0)="a"\ar@[|(2)]@{-}(4,0)
782 \POS?(0)/\intercol/="b"\POS(2,0)*\xybox{"b"-"a":(0,0)\ar^{\vec n_{0i}}(0,0.75)}
783 \POS(2,0)*{\bullet},*+!U{\vec u_j}
784 \POS(-2,-3)="a"\ar@[|(2)]@{-}(2,3)
785 \POS?(0)/\intercol/="b"\POS(1,1.5)*\xybox{"b"-"a":(0,0)\ar^{\vec n_{0j}}(0,-0.75)}
786 \POS(1,1.5)*{\bullet},*+!R{\vec u_i}
787 \POS(-2,3)="a"\ar@{-}(2,-3)
788 \POS?(0)/\intercol/="b"\POS(1.5,-2.25)
789 *\xybox{"b"-"a":(0,0)\ar_{\vec n_{ji}}^{\vec n_{ij}}(0,+0.75)}
790 \POS(1.5,-2.25)*{\bullet},*+!R{\vec u_0 = \vec w}
791 \POS(0,0)*{\bullet}
792 \POS(3,1.5)*+[o][F]{\scriptstyle 1}
793 \POS(0,2.5)*+[o][F]{\scriptstyle 2}
794 \POS(-3,1.5)*+[o][F]{\scriptstyle 3}
795 \POS(-3,-1.5)*+[o][F]{\scriptstyle 4}
796 \POS(0,-3)*+[o][F]{\scriptstyle 5}
797 \POS(3,-1.5)*+[o][F]{\scriptstyle 6}
798 \end{xy}
799 \end{minipage}
800 \begin{minipage}{0cm}
801 \begin{xy}
802 <\intercol,0pt>:<0pt,\intercol>::
803 \POS(-4,0)="a"\ar@[|(2)]@{-}(4,0)
804 \POS?(0)/\intercol/="b"\POS(2,0)*\xybox{"b"-"a":(0,0)\ar^{\vec n_{0i}}(0,0.75)}
805 \POS(2,0)*{\bullet},*+!U{\vec u_j}
806 \POS(-2,-3)="a"\ar@[|(2)]@{-}(2,3)
807 \POS?(0)/\intercol/="b"\POS(1,1.5)*\xybox{"b"-"a":(0,0)\ar^{\vec n_{0j}}(0,-0.75)}
808 \POS(1,1.5)*{\bullet},*+!R{\vec u_i}
809 \POS(-2,3)="a"\ar@{-}(2,-3)
810 \POS?(0)/\intercol/="b"\POS(-1.5,2.25)
811 *\xybox{"b"-"a":(0,0)\ar_{\vec n_{ji}}^{\vec n_{ij}}(0,+0.75)}
812 \POS(-1.5,2.25)*{\bullet},*+!R{\vec u_0 = \vec w}
813 \POS(0,0)*{\bullet}
814 \POS(3,1.5)*+[o][F]{\scriptstyle 1}
815 \POS(0,2.5)*+[o][F]{\scriptstyle 2}
816 \POS(-3,1.5)*+[o][F]{\scriptstyle 3}
817 \POS(-3,-1.5)*+[o][F]{\scriptstyle 4}
818 \POS(0,-3)*+[o][F]{\scriptstyle 5}
819 \POS(3,-1.5)*+[o][F]{\scriptstyle 6}
820 \end{xy}
821 \end{minipage}
822 \caption{Possible locations of $\vec w$ with respect to $\vec u_i$ and
823 $\vec u_j$, projected onto a plane orthogonal to the other rays, when
824 $\alpha_i \alpha_j < 0$.}
825 \label{fig:w:same}
826 \end{figure}
828 \begin{figure}
829 \intercol=0.7cm
830 \begin{minipage}{0cm}
831 \begin{xy}
832 <\intercol,0pt>:<0pt,\intercol>::
833 \POS(-4,0)="a"\ar@[|(2)]@{-}(4,0)
834 \POS?(0)/\intercol/="b"\POS(2,0)*\xybox{"b"-"a":(0,0)\ar^{\vec n_{0i}}(0,0.75)}
835 \POS(2,0)*{\bullet},*+!U{\vec u_j}
836 \POS(-2,3)="a"\ar@[|(2)]@{-}(2,-3)
837 \POS?(0)/\intercol/="b"\POS(-1,1.5)*\xybox{"b"-"a":(0,0)\ar^{\vec n_{0j}}(0,+0.75)}
838 \POS(-1,1.5)*{\bullet},*+!R{\vec u_i}
839 \POS(-2,-3)="a"\ar@{-}(2,3)
840 \POS?(0)/\intercol/="b"\POS(1.5,2.25)
841 *\xybox{"b"-"a":(0,0)\ar^{\vec n_{ji}}(0,+0.75)
842 \POS(0,0)\ar_{\vec n_{ij}}(0,-0.75)}
843 \POS(1.5,2.25)*{\bullet},*+!L{\vec u_0 = \vec w}
844 \POS(0,0)*{\bullet}
845 \POS(3,1.5)*+[o][F]{\scriptstyle 1}
846 \POS(0,2.5)*+[o][F]{\scriptstyle 2}
847 \POS(-3,1.5)*+[o][F]{\scriptstyle 3}
848 \POS(-3,-1.5)*+[o][F]{\scriptstyle 4}
849 \POS(0,-3)*+[o][F]{\scriptstyle 5}
850 \POS(3,-1.5)*+[o][F]{\scriptstyle 6}
851 \end{xy}
852 \end{minipage}
853 \begin{minipage}{0cm}
854 \begin{xy}
855 <\intercol,0pt>:<0pt,\intercol>::
856 \POS(-4,0)="a"\ar@[|(2)]@{-}(4,0)
857 \POS?(0)/\intercol/="b"\POS(2,0)*\xybox{"b"-"a":(0,0)\ar^{\vec n_{0i}}(0,0.75)}
858 \POS(2,0)*{\bullet},*+!U{\vec u_j}
859 \POS(-2,3)="a"\ar@[|(2)]@{-}(2,-3)
860 \POS?(0)/\intercol/="b"\POS(-1,1.5)*\xybox{"b"-"a":(0,0)\ar^{\vec n_{0j}}(0,+0.75)}
861 \POS(-1,1.5)*{\bullet},*+!R{\vec u_i}
862 \POS(-2,-3)="a"\ar@{-}(2,3)
863 \POS?(0)/\intercol/="b"\POS(-1.5,-2.25)
864 *\xybox{"b"-"a":(0,0)\ar^{\vec n_{ji}}(0,+0.75)
865 \POS(0,0)\ar_{\vec n_{ij}}(0,-0.75)}
866 \POS(-1.5,-2.25)*{\bullet},*+!L{\vec u_0 = \vec w}
867 \POS(0,0)*{\bullet}
868 \POS(3,1.5)*+[o][F]{\scriptstyle 1}
869 \POS(0,2.5)*+[o][F]{\scriptstyle 2}
870 \POS(-3,1.5)*+[o][F]{\scriptstyle 3}
871 \POS(-3,-1.5)*+[o][F]{\scriptstyle 4}
872 \POS(0,-3)*+[o][F]{\scriptstyle 5}
873 \POS(3,-1.5)*+[o][F]{\scriptstyle 6}
874 \end{xy}
875 \end{minipage}
876 \caption{Possible locations of $\vec w$ with respect to $\vec u_i$ and
877 $\vec u_j$, projected onto a plane orthogonal to the other rays, when
878 $\alpha_i \alpha_j > 0$.}
879 \label{fig:w:opposite}
880 \end{figure}
882 The algorithm is summarized in Algorithm~\ref{alg:closed}, where
883 we use the convention that in cone $K_i$, $\vec u_i$ refers to
884 $\vec u_0 = \vec w$.
885 Note that we do not need any of the rays or normals in this code.
886 The only information we need is the closedness of the facets in the
887 original cone and the signs of the $\alpha_i$.
889 \begin{algorithm}
890 \begin{tabbing}
891 next \= next \= next \= \kill
892 if $\alpha_j = 0$ \\
893 \> closed[$K_i$][$\vec u_j$] := closed[$\tilde K$][$\vec u_j$] \\
894 else if $i = j$ \\
895 \> if $\alpha_j > 0$ \\
896 \> \> closed[$K_i$][$\vec u_j$] := closed[$\tilde K$][$\vec u_j$] \\
897 \> else \\
898 \> \> closed[$K_i$][$\vec u_j$] := $\lnot$closed[$\tilde K$][$\vec u_j$] \\
899 else if $\alpha_i \alpha_j > 0$ \\
900 \> if closed[$\tilde K$][$\vec u_i$] = closed[$\tilde K$][$\vec u_j$] \\
901 \> \> closed[$K_i$][$\vec u_j$] := $i < j$ \\
902 \> else \\
903 \> \> closed[$K_i$][$\vec u_j$] := closed[$\tilde K$][$\vec u_j$] \\
904 else \\
905 \> closed[$K_i$][$\vec u_j$] := closed[$\tilde K$][$\vec u_i$] and
906 closed[$\tilde K$][$\vec u_j$]
907 \end{tabbing}
908 \caption{Determine whether the facet opposite $\vec u_j$ is closed in $K_i$.}
909 \label{alg:closed}
910 \end{algorithm}
912 \subsection{Triangulation in primal space}
913 \label{s:triangulation}
915 As in the case for Barvinok's decomposition (Section~\ref{s:decomposition}),
916 we can transform a triangulation of a (closed) cone into closed simple cones
917 into a triangulation of half-open simple cones that fully partitions the
918 original cone, i.e., such that the half-open simple cones do not intersect at their
919 facets.
920 Again, we apply Proposition~\ref{p:inclusion-exclusion} with $\vec y$
921 an interior point of the cone (Section~\ref{s:interior}).
923 \subsection{Multivariate quasi-polynomials as lists of polynomials}
925 There are many definitions for a (univariate) \ai{quasi-polynomial}.
926 \shortciteN{Ehrhart1977} uses a definition based on {\em periodic number}s.
928 \begin{definition}
929 \label{d:periodic:1}
930 A rational \defindex{periodic number} $U(p)$
931 is a function $\ZZ \to \QQ$,
932 such that there exists a \defindex{period} $q$
933 such that $U(p) = U(p')$ whenever $p \equiv p' \mod q$.
934 \end{definition}
936 \begin{definition}
937 \label{d:qp:1}
938 A (univariate)
939 \defindex{quasi-polynomial}\/ $f$ of degree $d$ is
940 a function
942 f(n) = c_d(n) \, n^d + \cdots + c_1(n) \, n + c_0
945 where $c_i(n)$ are rational periodic numbers.
946 I.e., it is a polynomial expression of degree $d$
947 with rational periodic numbers for coefficients.
948 The \defindex{period} of a quasi-polynomial is the \ac{lcm}
949 of the periods of its coefficients.
950 \end{definition}
952 Other authors (e.g., \shortciteNP{Stanley1986})
953 use the following definition of a quasi-polynomial.
954 \begin{definition}
955 \label{d:qp:1:list}
956 A function $f : \ZZ \to \QQ$ is
957 a (univariate) \defindex{quasi-polynomial} of period $q$ if there
958 exists a list of $q$ polynomials $g_i \in \QQ[T]$ for $0 \le i < q$ such
959 that
961 f (s) = g_i(s) \qquad \hbox{if $s \equiv i \mod {q}$}
964 The functions $g_i$ are called the {\em constituents}.
965 \index{constituent}
966 \end{definition}
968 In our implementation, we use Definition~\ref{d:qp:1},
969 but whereas
970 \shortciteN{Ehrhart1977} uses a list of $q$ rational
971 numbers enclosed in square brackets to represent periodic
972 numbers, our periodic numbers are polynomial expressions
973 in fractional parts (Section~\ref{a:data}).
974 These fractional parts naturally extend to multivariate
975 quasi-polynomials.
976 The bracketed (``explicit'') periodic numbers can
977 be extended to multiple variables by nesting them
978 (e.g., \shortciteNP{Loechner1999}).
980 Definition~\ref{d:qp:1:list} could be extended in a similar way
981 by having a constituent for each residue modulo a vector period $\vec q$.
982 However, as pointed out by \citeN{Woods2006personal}, this may not result
983 in the minimum number of constituents.
984 A vector period can be considered as a lattice with orthogonal generators and
985 the number of constituents is equal to the index or determinant of that lattice.
986 By considering more general lattices, we can potentially reduce the number
987 of constituents.
988 \begin{definition}
989 \label{d:qp}
990 A function $f : \ZZ^n \to \QQ$ is
991 a (multivariate) \defindex{quasi-polynomial} of period $L$ if there
992 exists a list of $\det L$ polynomials $g_{\vec i} \in \QQ[T_1,\ldots,T_n]$
993 for $\vec i$ in the fundamental parallelepiped of $L$ such
994 that
996 f (\vec s) = g_{\vec i}(\vec s) \qquad \hbox{if $\vec s \equiv \vec i \mod L$}
999 \end{definition}
1001 To compute the period lattice from a fractional representation, we compute
1002 the appropriate lattice for each fractional part and then take their intersection.
1003 Recall that the argument of each fractional part is an affine expression
1004 in the parameters $(\sp a p + c)/m$,
1005 with $\vec a \in \ZZ^n$ and $c, m \in \ZZ$.
1006 Such a fractional part is translation invariant over
1007 any (integer) value of $\vec p$
1008 such that $\sp a p + m t = 0$, for some $\vec t \in \ZZ$.
1009 Solving this homogeneous equation over the integers (in our implementation,
1010 we use \PolyLib/'s \ai[\tt]{SolveDiophantine}) gives the general solution
1012 \begin{bmatrix}
1013 \vec p \\ t
1014 \end{bmatrix}
1016 \begin{bmatrix}
1017 U_1 \\ U_2
1018 \end{bmatrix}
1019 \vec x
1020 \qquad\text{for $\vec x \in \ZZ^n$}
1023 The matrix $U_1 \in \ZZ^{n \times n}$ then has the generators of
1024 the required lattice as columns.
1025 The constituents are computed by plugging in each integer point
1026 in the fundamental parallelepiped of the lattice.
1027 These points themselves are computed as explained in Section~\ref{s:fundamental}.
1028 Note that for computing the constituents, it is sufficient to take any
1029 representative of the residue class. For example, we could take
1030 $\vec w^\T = \vec k^\T W$ in the notations of Lemma~\ref{l:fundamental}.
1032 \begin{example}[\shortciteN{Woods2006personal}]
1033 Consider the parametric polytope
1035 P_{s,t}=\{\, x \mid 0 \le x \le (s+t)/2 \,\}
1038 The enumerator of $P_{s,t}$ is
1040 \begin{cases}
1041 \frac s 2 + \frac t 2 + 1 &
1042 \text{if $\begin{bmatrix}s \\ t \end{bmatrix} \in
1043 \begin{bmatrix}
1044 -1 & -2 \\ 1 & 0
1045 \end{bmatrix}
1046 \ZZ^2 +
1047 \begin{bmatrix}
1048 0 \\ 0
1049 \end{bmatrix}
1052 \frac s 2 + \frac t 2 + \frac 1 2 &
1053 \text{if $\begin{bmatrix}s \\ t \end{bmatrix} \in
1054 \begin{bmatrix}
1055 -1 & -2 \\ 1 & 0
1056 \end{bmatrix}
1057 \ZZ^2 +
1058 \begin{bmatrix}
1059 -1 \\ 0
1060 \end{bmatrix}
1063 \end{cases}
1065 The corresponding output of \ai[\tt]{barvinok\_enumerate} is
1066 \begin{verbatim}
1067 s + t >= 0
1068 1 >= 0
1070 Lattice:
1071 [[-1 1]
1072 [-2 0]
1074 [0 0]
1075 ( 1/2 * s + ( 1/2 * t + 1 )
1077 [-1 0]
1078 ( 1/2 * s + ( 1/2 * t + 1/2 )
1080 \end{verbatim}
1081 \end{example}
1083 \subsection{Left inverse of an affine embedding}
1084 \label{s:inverse}
1086 We often map a polytope onto a lower dimensional space to remove possible
1087 equalities in the polytope. These maps are typically represented
1088 by the inverse, mapping the coordinates $\vec x'$ of the lower-dimensional
1089 space to the coordinates $\vec x$ of (an affine subspace of) the original space,
1090 i.e.,
1092 \begin{bmatrix}
1093 \vec x \\ 1
1094 \end{bmatrix}
1096 \begin{bmatrix}
1097 T & \vec v \\ \vec 0^\T & 1
1098 \end{bmatrix}
1099 \begin{bmatrix}
1100 \vec x' \\ 1
1101 \end{bmatrix}
1104 where, as usual in \PolyLib/, we work with homogeneous coordinates.
1105 To obtain the transformation that maps the coordinates of the original
1106 space to the coordinates of the lower dimensional space,
1107 we need to compute the \ai{left inverse} of the above \ai{affine embedding},
1108 i.e., an $A$, $\vec b$ and $d$ such that
1111 \begin{bmatrix}
1112 \vec x' \\ 1
1113 \end{bmatrix}
1115 \begin{bmatrix}
1116 A & \vec b \\ \vec 0^\T & d
1117 \end{bmatrix}
1118 \begin{bmatrix}
1119 \vec x \\ 1
1120 \end{bmatrix}
1123 To compute this left inverse, we first compute the
1124 (right) \indac{HNF} of T,
1126 \begin{bmatrix}
1127 U_1 \\ U_2
1128 \end{bmatrix}
1131 \begin{bmatrix}
1132 H \\ 0
1133 \end{bmatrix}
1136 The left inverse is then simply
1138 \begin{bmatrix}
1139 d H^{-1}U_1 & -d H^{-1} \vec v \\ \vec 0^\T & d
1140 \end{bmatrix}
1143 We often also want a decription of the affine subspace that is the range
1144 of the affine embedding and this is given by
1146 \begin{bmatrix}
1147 U_2 & - U_2 \vec v \\ \vec 0^T & 1
1148 \end{bmatrix}
1149 \begin{bmatrix}
1150 \vec x \\ 1
1151 \end{bmatrix}
1153 \vec 0
1156 This computation is implemented in \ai[\tt]{left\_inverse}.
1158 \subsection{Integral basis of the orthogonal complement of a linear subspace}
1159 \label{s:completion}
1161 Let $M_1 \in \ZZ^{m \times n}$ be a basis of a linear subspace.
1162 We first extend $M_1$ with zero rows to obtain a square matrix $M'$
1163 and then compute the (left) \indac{HNF} of $M'$,
1165 \begin{bmatrix}
1166 M_1 \\ 0
1167 \end{bmatrix}
1169 \begin{bmatrix}
1170 H & 0 \\ 0 & 0
1171 \end{bmatrix}
1172 \begin{bmatrix}
1173 Q_1 \\ Q_2
1174 \end{bmatrix}
1177 The rows of $Q_2$ span the orthogonal complement of the given subspace.
1178 Since $Q_2$ can be extended to a unimodular matrix, these rows form
1179 an integral basis.
1181 If the entries on the diagonal of $H$ are all $1$ then $M_1$
1182 can be extended to a unimodular matrix, by concatenating $M_1$ and $Q_2$.
1183 The resulting matrix is unimodular, since
1185 \begin{bmatrix}
1186 M_1 \\ Q_2
1187 \end{bmatrix}
1189 \begin{bmatrix}
1190 H & 0 \\ 0 & I_{n-m,n-m}
1191 \end{bmatrix}
1192 \begin{bmatrix}
1193 Q_1 \\ Q_2
1194 \end{bmatrix}
1197 This method for extending a matrix of which
1198 only a few lines are known to a \ai{unimodular matrix}
1199 is more general than the method described by \shortciteN{Bik1996PhD},
1200 which only considers extending a matrix given by a single row.
1202 \subsection{Ensuring a polyhedron has only revlex-positive rays}
1203 \label{s:revlexpos}
1205 The \ai[\tt]{barvinok\_series\_with\_options} function and all
1206 further \ai[\tt]{gen\_fun} manipulations assume that the effective
1207 parameter domain has only \ai{revlex-positive} rays.
1208 When used to computer \rgf/s, the \ai[\tt]{barvinok\_enumerate}
1209 application will therefore transform the effective parameter domain
1210 of a problem if it has revlex-negative rays.
1211 It will then not compute the generating function
1213 f(\vec x) = \sum_{\vec p \in \ZZ^m} \#(P_{\vec p} \cap \ZZ^d) \, x^{\vec p}
1218 g(\vec z) = \sum_{\vec p' \in \ZZ^n}
1219 \#(P_{T \vec p' + \vec t} \cap \ZZ^d) \, x^{\vec p'}
1221 instead, where $\vec p = T \vec p' + \vec t$,
1222 with $T \in \ZZ^{m \times n}$ and $\vec t \in \ZZ^m$, is an affine transformation
1223 that maps the transformed parameter space back to the original parameter space.
1225 First assume that the parameter domain does not contain any lines and
1226 that there are no equalities in the description of $P_{\vec p}$ that force
1227 the values of $\vec p$ for which $P_{\vec p}$ contains integer points
1228 to lie on a non-standard lattice.
1229 Let the effective parameter domain be given as
1231 \{\, \vec p \mid A \vec p + \vec c \ge \vec 0 \,\}
1233 where $A \in \ZZ^{s \times d}$ of row rank $d$;
1234 otherwise the effective parameter domain would contain a line.
1235 Let $H$ be the (left) \indac{HNF} of $A$, i.e.,
1237 A = H Q
1240 with $H$ lower-triangular with positive diagonal elements and
1241 $Q$ unimodular.
1242 Let $\tilde Q$ be the matrix obtained from $Q$ by reversing its rows,
1243 and, similarly, $\tilde H$ from $H$ by reversing the columns.
1244 After performing the transformation
1245 $\vec p' = \tilde Q \vec p$, i.e.,
1246 $\vec p = \tilde Q^{-1} \vec p'$, the transformed parameter domain
1247 is given by
1249 \{\, \vec p' \mid A \tilde Q^{-1} \vec p' + \vec c \ge \vec 0 \,\}
1253 \{\, \vec p' \mid \tilde H \vec p' + \vec c \ge \vec 0 \,\}
1256 The first constraint of this domain is
1257 $h_{11} p'_m + c_1 \ge 0$. A ray with non-zero final coordinate
1258 therefore has a positive final coordinate.
1259 Similarly, the second constraint is
1260 $h_{22} p'_{m-1} h_{21} p'_m + c_2 \ge 0$.
1261 A ray with zero $n$th coordinate, but non-zero $n-1$st coordinate,
1262 will therefore have a positive $n-1$st coordinate.
1263 Continuing this reasoning, we see that all rays in the transformed
1264 domain are revlex-positive.
1266 If the parameter domain does contains lines, but is not restricted
1267 to a non-standard lattice, then the number of points in the parametric
1268 polytope is invariant over a translation along the lines.
1269 It is therefore sufficient to compute the number of points in the
1270 orthogonal complement of the linear subspace spanned by the lines.
1271 That is, we apply a prior transformation that maps a reduced parameter
1272 domain to this subspace,
1274 \vec p = L^\perp \vec p' =
1275 \begin{bmatrix}
1276 L & L^\perp
1277 \end{bmatrix}
1278 \begin{bmatrix}
1279 0 \\ I
1280 \end{bmatrix}
1281 \vec p'
1284 where $L$ has the lines as columns, and $L^\perp$ an integral basis
1285 for the orthogonal complement (Section~\ref{s:completion}).
1286 Note that the inverse transformation
1288 \vec p' =
1289 L^{-\perp}
1290 \vec p =
1291 \begin{bmatrix}
1292 0 & I
1293 \end{bmatrix}
1294 \begin{bmatrix}
1295 L & L^\perp
1296 \end{bmatrix}^{-1}
1297 \vec p
1299 has integral coefficients since $L^\perp$ can be extended to a unimodular matrix.
1301 If the parameter values $\vec p$ for which $P_{\vec p}$ contains integer points
1302 are restricted to a non-standard lattice, we first replace the parameters
1303 by a different set of parameters that lie on the standard lattice
1304 through ``\ai{parameter compression}''\shortcite{Meister2004PhD},
1306 \vec p = C \vec p'
1309 The (left) inverse of $C$ can be computes as explained in
1310 Section~\ref{s:inverse}, giving
1312 \vec p' = C^{-L} \vec p
1315 We have to be careful to only apply this transformation when
1316 both the equalities computed in Section~\ref{s:inverse} are satisfied
1317 and some additional divisibility constraints.
1318 In particular if $\vec a^\T/d$ is a row of $C^{-L}$, with $\vec a \in \ZZ^{n'}$
1319 and $d \in \ZZ$, the transformation can only be applied to parameter values
1320 $\vec p$ such that $d$ divides $\sp a p$.
1322 The complete transformation is given by
1324 \vec p = C L^\perp \hat Q^{-1} \vec p'
1328 \vec p' = \hat Q L^{-\perp} C^{-L} \vec p
1332 \subsection{Parametric Volume Computation}
1334 The \ai{volume} of a (parametric) polytope can serve as an approximation
1335 for the number of integer points in the polytope.
1336 We basically follow the description of~\shortciteN{Rabl2006} here, except that we
1337 focus on volume computation for {\em linearly}
1338 parametrized polytopes, which we exploit to determine the sign
1339 of the determinants we compute, as explained below.
1341 Note first that
1342 the vertices of a linearly parametrized polytope are affine expressions
1343 in the parameters that may be valid only in parts (chambers)
1344 of the parameter domain.
1345 Since the volume computation is based on the (active) vertices, we perform
1346 the computation in each chamber separately.
1347 Also note that since the vertices are affine expressions, it is
1348 easy to check whether they belong to a facet.
1350 The volume of a $d$-simplex, i.e., a $d$-dimensional polytope with
1351 $d+1$ vertices, is relatively easy to compute.
1352 In particular, if $\vec v_i(\vec p)$, for $0 \le i \le d$,
1353 are the (parametric) vertices
1354 of the simplex $P$ then
1355 \begin{equation}
1356 \label{eq:volume}
1357 \vol P =
1358 \frac 1 {d!}
1359 \left|
1360 \det
1361 \begin{bmatrix}
1362 v_{11}(\vec p) - v_{01}(\vec p) &
1363 v_{12}(\vec p) - v_{02}(\vec p) &
1364 \ldots &
1365 v_{1d}(\vec p) - v_{0d}(\vec p)
1367 v_{21}(\vec p) - v_{01}(\vec p) &
1368 v_{22}(\vec p) - v_{02}(\vec p) &
1369 \ldots &
1370 v_{2d}(\vec p) - v_{0d}(\vec p)
1372 \vdots & \vdots & \ddots & \vdots
1374 v_{d1}(\vec p) - v_{01}(\vec p) &
1375 v_{d2}(\vec p) - v_{02}(\vec p) &
1376 \ldots &
1377 v_{dd}(\vec p) - v_{0d}(\vec p)
1378 \end{bmatrix}
1379 \right|.
1380 \end{equation}
1382 If $P$ is not a simplex, i.e., $N > d+1$, with $N$ the number of
1383 vertices of $P$, then the standard way of computing the volume of $P$
1384 is to first {\em triangulate} $P$, i.e., subdivide $P$ into simplices,
1385 and then to compute and sum the volumes of the resulting simplices.
1386 One way of computing a triangulation is to
1387 compute the \ai{barycenter}
1389 \frac 1 N \sum_i \vec v_i(\vec p)
1391 of $P$
1392 and to perform a subdivision by computing the convex hulls
1393 of the barycenter with each of the facets of $P$.
1394 If a given facet of $P$ is itself a simplex, then this convex hull
1395 is also a simplex. Otherwise the facet is further subdivided.
1396 This recursive process terminates as every $1$-dimensional polytope
1397 is a simplex.
1399 The triangulation described above is known as
1400 the boundary triangulation~\shortcite{Bueler2000exact} and is used
1401 by \shortciteN{Rabl2006} in his implementation.
1402 The Cohen-Hickey triangulation~\shortcite{Cohen1979volumes,Bueler2000exact}
1403 is a much more efficient variation and uses one of the vertices
1404 instead of the barycenter. The facets incident on the vertex
1405 do not have to be considered in this case because the resulting subpolytopes
1406 would have zero volume.
1407 Another possibility is to use a
1408 ``lifting'' triangulation~\shortcite{Lee1991,DeLoera1995}.
1409 In this triangulation, each vertex is assigned a (random) ``height'' in
1410 an extra dimension.
1411 The projection of the ``lower envelope'' of the resulting polytope onto
1412 the original space results in a subdivision, which is a triangulation
1413 with very high probability.
1415 A complication with the lifting triangulation is that the constraint system
1416 of the lifted polytope will in general not be linearly parameterized,
1417 even if the original polytope is.
1418 It is, however, sufficient to perform the triangulation for a particular
1419 value of the parameters inside the chamber since the parametric polytope
1420 has the same combinatorial structure throughout the chamber.
1421 The triangulation obtained for the instantiated vertices can then
1422 be carried over to the corresponding parametric vertices.
1423 We only need to be careful to select a value for the parameters that
1424 does not lie on any facet of the chambers. On these chambers, some
1425 of the vertices may coincide.
1426 For linearly parametrized polytopes, it is easy to find a parameter
1427 point in the interior of a chamber, as explained in Section~\ref{s:interior}.
1428 Note that this point need not be integer.
1430 A direct application of the above algorithm, using any of the triangulations,
1431 would yield for each chamber
1432 a volume expressed as the sum of the absolute values of polynomials in
1433 the parameters. To remove the absolute value, we plug in a particular
1434 value of the parameters (not necessarily integer)
1435 belonging to the given chamber for which we know that the volume is non-zero.
1436 Again, it is sufficient to take any point in the interior of the chamber.
1437 The sign of the resulting value then determines the sign of the whole
1438 polynomial since polynomials are continuous functions and will not change
1439 sign without passing through zero.