barvinok_summate: correct options description
[barvinok.git] / lattice_point.cc
blob6f040ac64c8c4902abe62ea88b22e75b31a7da79
1 #include <assert.h>
2 #include <NTL/mat_ZZ.h>
3 #include <NTL/vec_ZZ.h>
4 #include <barvinok/barvinok.h>
5 #include <barvinok/evalue.h>
6 #include <barvinok/util.h>
7 #include "config.h"
8 #include "conversion.h"
9 #include "lattice_point.h"
10 #include "param_util.h"
12 using std::cerr;
13 using std::endl;
15 #define ALLOC(type) (type*)malloc(sizeof(type))
17 /* returns an evalue that corresponds to
19 * c/(*den) x_param
21 static evalue *term(int param, ZZ& c, Value *den = NULL)
23 evalue *EP = new evalue();
24 value_init(EP->d);
25 value_set_si(EP->d,0);
26 EP->x.p = new_enode(polynomial, 2, param + 1);
27 evalue_set_si(&EP->x.p->arr[0], 0, 1);
28 value_init(EP->x.p->arr[1].x.n);
29 if (den == NULL)
30 value_set_si(EP->x.p->arr[1].d, 1);
31 else
32 value_assign(EP->x.p->arr[1].d, *den);
33 zz2value(c, EP->x.p->arr[1].x.n);
34 return EP;
37 /* returns an evalue that corresponds to
39 * sum_i p[i] * x_i
41 evalue *multi_monom(vec_ZZ& p)
43 evalue *X = new evalue();
44 value_init(X->d);
45 value_init(X->x.n);
46 unsigned nparam = p.length()-1;
47 zz2value(p[nparam], X->x.n);
48 value_set_si(X->d, 1);
49 for (int i = 0; i < nparam; ++i) {
50 if (p[i] == 0)
51 continue;
52 evalue *T = term(i, p[i]);
53 eadd(T, X);
54 free_evalue_refs(T);
55 delete T;
57 return X;
61 * Check whether mapping polyhedron P on the affine combination
62 * num yields a range that has a fixed quotient on integer
63 * division by d
64 * If zero is true, then we are only interested in the quotient
65 * for the cases where the remainder is zero.
66 * Returns NULL if false and a newly allocated value if true.
68 static Value *fixed_quotient(Polyhedron *P, vec_ZZ& num, Value d, bool zero)
70 Value* ret = NULL;
71 int len = num.length();
72 Matrix *T = Matrix_Alloc(2, len);
73 zz2values(num, T->p[0]);
74 value_set_si(T->p[1][len-1], 1);
75 Polyhedron *I = Polyhedron_Image(P, T, P->NbConstraints);
76 Matrix_Free(T);
78 int i;
79 for (i = 0; i < I->NbRays; ++i)
80 if (value_zero_p(I->Ray[i][2])) {
81 Polyhedron_Free(I);
82 return NULL;
85 Value min, max;
86 value_init(min);
87 value_init(max);
88 int bounded = line_minmax(I, &min, &max);
89 assert(bounded);
91 if (zero)
92 mpz_cdiv_q(min, min, d);
93 else
94 mpz_fdiv_q(min, min, d);
95 mpz_fdiv_q(max, max, d);
97 if (value_eq(min, max)) {
98 ret = ALLOC(Value);
99 value_init(*ret);
100 value_assign(*ret, min);
102 value_clear(min);
103 value_clear(max);
104 return ret;
108 * Normalize linear expression coef modulo m
109 * Removes common factor and reduces coefficients
110 * Returns index of first non-zero coefficient or len
112 int normal_mod(Value *coef, int len, Value *m)
114 Value gcd;
115 value_init(gcd);
117 Vector_Gcd(coef, len, &gcd);
118 Gcd(gcd, *m, &gcd);
119 Vector_AntiScale(coef, coef, gcd, len);
121 value_division(*m, *m, gcd);
122 value_clear(gcd);
124 if (value_one_p(*m))
125 return len;
127 int j;
128 for (j = 0; j < len; ++j)
129 mpz_fdiv_r(coef[j], coef[j], *m);
130 for (j = 0; j < len; ++j)
131 if (value_notzero_p(coef[j]))
132 break;
134 return j;
137 static bool mod_needed(Polyhedron *PD, vec_ZZ& num, Value d, evalue *E)
139 Value *q = fixed_quotient(PD, num, d, false);
141 if (!q)
142 return true;
144 value_oppose(*q, *q);
145 evalue EV;
146 value_init(EV.d);
147 value_set_si(EV.d, 1);
148 value_init(EV.x.n);
149 value_multiply(EV.x.n, *q, d);
150 eadd(&EV, E);
151 free_evalue_refs(&EV);
152 value_clear(*q);
153 free(q);
154 return false;
157 /* Computes the fractional part of the affine expression specified
158 * by coef (of length nvar+1) and the denominator denom.
159 * If PD is not NULL, then it specifies additional constraints
160 * on the variables that may be used to simplify the resulting
161 * fractional part expression.
163 * Modifies coef argument !
165 evalue *fractional_part(Value *coef, Value denom, int nvar, Polyhedron *PD)
167 Value m;
168 value_init(m);
169 evalue *EP = evalue_zero();
170 int sign = 1;
172 value_assign(m, denom);
173 int j = normal_mod(coef, nvar+1, &m);
175 if (j == nvar+1) {
176 value_clear(m);
177 return EP;
180 vec_ZZ num;
181 values2zz(coef, num, nvar+1);
183 ZZ g;
184 value2zz(m, g);
186 evalue tmp;
187 value_init(tmp.d);
188 evalue_set_si(&tmp, 0, 1);
190 int p = j;
191 if (g % 2 == 0)
192 while (j < nvar && (num[j] == g/2 || num[j] == 0))
193 ++j;
194 if ((j < nvar && num[j] > g/2) || (j == nvar && num[j] >= (g+1)/2)) {
195 for (int k = j; k < nvar; ++k)
196 if (num[k] != 0)
197 num[k] = g - num[k];
198 num[nvar] = g - 1 - num[nvar];
199 value_assign(tmp.d, m);
200 ZZ t = sign*(g-1);
201 zz2value(t, tmp.x.n);
202 eadd(&tmp, EP);
203 sign = -sign;
206 if (p >= nvar) {
207 ZZ t = num[nvar] * sign;
208 zz2value(t, tmp.x.n);
209 value_assign(tmp.d, m);
210 eadd(&tmp, EP);
211 } else {
212 evalue *E = multi_monom(num);
213 evalue EV;
214 value_init(EV.d);
216 if (PD && !mod_needed(PD, num, m, E)) {
217 value_init(EV.x.n);
218 value_set_si(EV.x.n, sign);
219 value_assign(EV.d, m);
220 emul(&EV, E);
221 eadd(E, EP);
222 } else {
223 value_init(EV.x.n);
224 value_set_si(EV.x.n, 1);
225 value_assign(EV.d, m);
226 emul(&EV, E);
227 value_clear(EV.x.n);
228 value_set_si(EV.d, 0);
229 EV.x.p = new_enode(fractional, 3, -1);
230 evalue_copy(&EV.x.p->arr[0], E);
231 evalue_set_si(&EV.x.p->arr[1], 0, 1);
232 value_init(EV.x.p->arr[2].x.n);
233 value_set_si(EV.x.p->arr[2].x.n, sign);
234 value_set_si(EV.x.p->arr[2].d, 1);
236 eadd(&EV, EP);
239 free_evalue_refs(&EV);
240 free_evalue_refs(E);
241 delete E;
244 free_evalue_refs(&tmp);
246 out:
247 value_clear(m);
249 return EP;
252 static evalue *ceil(Value *coef, int len, Value d,
253 barvinok_options *options)
255 evalue *c;
257 Vector_Oppose(coef, coef, len);
258 c = fractional_part(coef, d, len-1, NULL);
259 if (options->lookup_table)
260 evalue_mod2table(c, len-1);
261 return c;
264 evalue* bv_ceil3(Value *coef, int len, Value d, Polyhedron *P)
266 Vector *val = Vector_Alloc(len);
268 Value t;
269 value_init(t);
270 value_set_si(t, -1);
271 Vector_Scale(coef, val->p, t, len);
272 value_absolute(t, d);
274 vec_ZZ num;
275 values2zz(val->p, num, len);
276 evalue *EP = multi_monom(num);
278 evalue tmp;
279 value_init(tmp.d);
280 value_init(tmp.x.n);
281 value_set_si(tmp.x.n, 1);
282 value_assign(tmp.d, t);
284 emul(&tmp, EP);
286 Vector_Oppose(val->p, val->p, len);
287 evalue *f = fractional_part(val->p, t, len-1, P);
288 value_clear(t);
290 eadd(f, EP);
291 free_evalue_refs(f);
292 free(f);
294 /* copy EP to malloc'ed evalue */
295 evalue *E = ALLOC(evalue);
296 *E = *EP;
297 delete EP;
299 free_evalue_refs(&tmp);
300 Vector_Free(val);
302 return E;
305 void lattice_point_fixed(Value *vertex, Value *vertex_res,
306 Matrix *Rays, Matrix *Rays_res,
307 Value *point)
309 unsigned dim = Rays->NbRows;
310 if (value_one_p(vertex[dim]))
311 Vector_Copy(vertex_res, point, Rays_res->NbColumns);
312 else {
313 Matrix *R2 = Matrix_Copy(Rays);
314 Matrix *inv = Matrix_Alloc(Rays->NbRows, Rays->NbColumns);
315 int ok = Matrix_Inverse(R2, inv);
316 assert(ok);
317 Matrix_Free(R2);
318 Vector *lambda = Vector_Alloc(dim);
319 Vector_Matrix_Product(vertex, inv, lambda->p);
320 Matrix_Free(inv);
321 for (int j = 0; j < dim; ++j)
322 mpz_cdiv_q(lambda->p[j], lambda->p[j], vertex[dim]);
323 Vector_Matrix_Product(lambda->p, Rays_res, point);
324 Vector_Free(lambda);
328 static Matrix *Matrix_AddRowColumn(Matrix *M)
330 Matrix *M2 = Matrix_Alloc(M->NbRows+1, M->NbColumns+1);
331 for (int i = 0; i < M->NbRows; ++i)
332 Vector_Copy(M->p[i], M2->p[i], M->NbColumns);
333 value_set_si(M2->p[M->NbRows][M->NbColumns], 1);
334 return M2;
337 #define FORALL_COSETS(det,D,i,k) \
338 do { \
339 Vector *k = Vector_Alloc(D->NbRows+1); \
340 value_set_si(k->p[D->NbRows], 1); \
341 for (unsigned long i = 0; i < det; ++i) { \
342 unsigned long _fc_val = i; \
343 for (int j = 0; j < D->NbRows; ++j) { \
344 value_set_si(k->p[j], _fc_val % mpz_get_ui(D->p[j][j]));\
345 _fc_val /= mpz_get_ui(D->p[j][j]); \
347 #define END_FORALL_COSETS \
349 Vector_Free(k); \
350 } while(0);
352 /* Compute the lattice points in the vertex cone at "values" with rays "rays".
353 * The lattice points are returned in "vertex".
355 * Rays has the generators as rows and so does W.
356 * We first compute { m-v, u_i^* } with m = k W, where k runs through
357 * the cosets.
358 * We compute
359 * [k 1] [ d1*W 0 ] [ U' 0 ] = [k 1] T2
360 * [ -v d1 ] [ 0 d2 ]
361 * where d1 and d2 are the denominators of v and U^{-1}=U'/d2.
362 * Then lambda = { k } (componentwise)
363 * We compute x - floor(x) = {x} = { a/b } as fdiv_r(a,b)/b
364 * For open rays/facets, we need values in (0,1] rather than [0,1),
365 * so we compute {{x}} = x - ceil(x-1) = a/b - ceil((a-b)/b)
366 * = (a - b cdiv_q(a-b,b) - b + b)/b
367 * = (cdiv_r(a,b)+b)/b
368 * Finally, we compute v + lambda * U
369 * The denominator of lambda can be d1*d2, that of lambda2 = lambda*U
370 * can be at most d1, since it is integer if v = 0.
371 * The denominator of v + lambda2 is 1.
373 * The _res variants of the input variables may have been multiplied with
374 * a (list of) nonorthogonal vector(s) and may therefore have fewer columns
375 * than their original counterparts.
377 void lattice_points_fixed(Value *vertex, Value *vertex_res,
378 Matrix *Rays, Matrix *Rays_res, Matrix *points,
379 unsigned long det)
381 unsigned dim = Rays->NbRows;
382 if (det == 1) {
383 lattice_point_fixed(vertex, vertex_res, Rays, Rays_res,
384 points->p[0]);
385 return;
387 Matrix *U, *W, *D;
388 Smith(Rays, &U, &W, &D);
389 Matrix_Free(U);
391 /* Sanity check */
392 unsigned long det2 = 1;
393 for (int i = 0 ; i < D->NbRows; ++i)
394 det2 *= mpz_get_ui(D->p[i][i]);
395 assert(det == det2);
397 Matrix *T = Matrix_Alloc(W->NbRows+1, W->NbColumns+1);
398 for (int i = 0; i < W->NbRows; ++i)
399 Vector_Scale(W->p[i], T->p[i], vertex[dim], W->NbColumns);
400 Matrix_Free(W);
401 Value tmp;
402 value_init(tmp);
403 value_set_si(tmp, -1);
404 Vector_Scale(vertex, T->p[dim], tmp, dim);
405 value_clear(tmp);
406 value_assign(T->p[dim][dim], vertex[dim]);
408 Matrix *R2 = Matrix_AddRowColumn(Rays);
409 Matrix *inv = Matrix_Alloc(R2->NbRows, R2->NbColumns);
410 int ok = Matrix_Inverse(R2, inv);
411 assert(ok);
412 Matrix_Free(R2);
414 Matrix *T2 = Matrix_Alloc(dim+1, dim+1);
415 Matrix_Product(T, inv, T2);
416 Matrix_Free(T);
418 Vector *lambda = Vector_Alloc(dim+1);
419 Vector *lambda2 = Vector_Alloc(Rays_res->NbColumns);
420 FORALL_COSETS(det, D, i, k)
421 Vector_Matrix_Product(k->p, T2, lambda->p);
422 for (int j = 0; j < dim; ++j)
423 mpz_fdiv_r(lambda->p[j], lambda->p[j], lambda->p[dim]);
424 Vector_Matrix_Product(lambda->p, Rays_res, lambda2->p);
425 for (int j = 0; j < lambda2->Size; ++j)
426 assert(mpz_divisible_p(lambda2->p[j], inv->p[dim][dim]));
427 Vector_AntiScale(lambda2->p, lambda2->p, inv->p[dim][dim], lambda2->Size);
428 Vector_Add(lambda2->p, vertex_res, lambda2->p, lambda2->Size);
429 for (int j = 0; j < lambda2->Size; ++j)
430 assert(mpz_divisible_p(lambda2->p[j], vertex[dim]));
431 Vector_AntiScale(lambda2->p, points->p[i], vertex[dim], lambda2->Size);
432 END_FORALL_COSETS
433 Vector_Free(lambda);
434 Vector_Free(lambda2);
435 Matrix_Free(D);
436 Matrix_Free(inv);
438 Matrix_Free(T2);
441 /* Returns the power of (t+1) in the term of a rational generating function,
442 * i.e., the scalar product of the actual lattice point and lambda.
443 * The lattice point is the unique lattice point in the fundamental parallelepiped
444 * of the unimodual cone i shifted to the parametric vertex W/lcm.
446 * The rows of W refer to the coordinates of the vertex
447 * The first nparam columns are the coefficients of the parameters
448 * and the final column is the constant term.
449 * lcm is the common denominator of all coefficients.
451 static evalue **lattice_point_fractional(const mat_ZZ& rays, vec_ZZ& lambda,
452 Matrix *V,
453 unsigned long det)
455 unsigned nparam = V->NbColumns-2;
456 evalue **E = new evalue *[det];
458 Matrix* Rays = zz2matrix(rays);
459 Matrix *T = Transpose(Rays);
460 Matrix *T2 = Matrix_Copy(T);
461 Matrix *inv = Matrix_Alloc(T2->NbRows, T2->NbColumns);
462 int ok = Matrix_Inverse(T2, inv);
463 assert(ok);
464 Matrix_Free(T2);
465 mat_ZZ vertex;
466 matrix2zz(V, vertex, V->NbRows, V->NbColumns-1);
468 vec_ZZ num;
469 num = lambda * vertex;
471 evalue *EP = multi_monom(num);
473 evalue_div(EP, V->p[0][nparam+1]);
475 Matrix *L = Matrix_Alloc(inv->NbRows, V->NbColumns);
476 Matrix_Product(inv, V, L);
478 mat_ZZ RT;
479 matrix2zz(T, RT, T->NbRows, T->NbColumns);
480 Matrix_Free(T);
482 vec_ZZ p = lambda * RT;
484 Value tmp;
485 value_init(tmp);
487 if (det == 1) {
488 for (int i = 0; i < L->NbRows; ++i) {
489 evalue *f;
490 Vector_Oppose(L->p[i], L->p[i], nparam+1);
491 f = fractional_part(L->p[i], V->p[i][nparam+1], nparam, NULL);
492 zz2value(p[i], tmp);
493 evalue_mul(f, tmp);
494 eadd(f, EP);
495 free_evalue_refs(f);
496 free(f);
498 E[0] = EP;
499 } else {
500 for (int i = 0; i < L->NbRows; ++i)
501 value_assign(L->p[i][nparam+1], V->p[i][nparam+1]);
503 Value denom;
504 value_init(denom);
505 mpz_set_ui(denom, det);
506 value_multiply(denom, L->p[0][nparam+1], denom);
508 Matrix *U, *W, *D;
509 Smith(Rays, &U, &W, &D);
510 Matrix_Free(U);
512 /* Sanity check */
513 unsigned long det2 = 1;
514 for (int i = 0 ; i < D->NbRows; ++i)
515 det2 *= mpz_get_ui(D->p[i][i]);
516 assert(det == det2);
518 Matrix_Transposition(inv);
519 Matrix *T2 = Matrix_Alloc(W->NbRows, inv->NbColumns);
520 Matrix_Product(W, inv, T2);
521 Matrix_Free(W);
523 unsigned dim = D->NbRows;
524 Vector *lambda = Vector_Alloc(dim);
526 Vector *row = Vector_Alloc(nparam+1);
527 FORALL_COSETS(det, D, i, k)
528 Vector_Matrix_Product(k->p, T2, lambda->p);
529 E[i] = new evalue();
530 value_init(E[i]->d);
531 evalue_copy(E[i], EP);
532 for (int j = 0; j < L->NbRows; ++j) {
533 evalue *f;
534 Vector_Oppose(L->p[j], row->p, nparam+1);
535 value_addmul(row->p[nparam], L->p[j][nparam+1], lambda->p[j]);
536 f = fractional_part(row->p, denom, nparam, NULL);
537 zz2value(p[j], tmp);
538 evalue_mul(f, tmp);
539 eadd(f, E[i]);
540 free_evalue_refs(f);
541 free(f);
543 END_FORALL_COSETS
544 Vector_Free(row);
546 Vector_Free(lambda);
547 Matrix_Free(T2);
548 Matrix_Free(D);
550 value_clear(denom);
551 free_evalue_refs(EP);
552 delete EP;
554 value_clear(tmp);
556 Matrix_Free(Rays);
557 Matrix_Free(L);
558 Matrix_Free(inv);
560 return E;
563 static evalue **lattice_point(const mat_ZZ& rays, vec_ZZ& lambda,
564 Param_Vertices *V,
565 unsigned long det,
566 barvinok_options *options)
568 evalue **lp = lattice_point_fractional(rays, lambda, V->Vertex, det);
569 if (options->lookup_table) {
570 for (int i = 0; i < det; ++i)
571 evalue_mod2table(lp[i], V->Vertex->NbColumns-2);
573 return lp;
576 /* returns the unique lattice point in the fundamental parallelepiped
577 * of the unimodual cone C shifted to the parametric vertex V.
579 * The return values num and E_vertex are such that
580 * coordinate i of this lattice point is equal to
582 * num[i] + E_vertex[i]
584 void lattice_point(Param_Vertices *V, const mat_ZZ& rays, vec_ZZ& num,
585 evalue **E_vertex, barvinok_options *options)
587 unsigned nparam = V->Vertex->NbColumns - 2;
588 unsigned dim = rays.NumCols();
590 /* It doesn't really make sense to call lattice_point when dim == 0,
591 * but apparently it happens from indicator_constructor in lexmin.
593 if (!dim)
594 return;
596 vec_ZZ vertex;
597 vertex.SetLength(nparam+1);
599 Value tmp;
600 value_init(tmp);
602 assert(V->Vertex->NbRows > 0);
603 Param_Vertex_Common_Denominator(V);
605 if (value_notone_p(V->Vertex->p[0][nparam+1])) {
606 Matrix* Rays = zz2matrix(rays);
607 Matrix *T = Transpose(Rays);
608 Matrix *T2 = Matrix_Copy(T);
609 Matrix *inv = Matrix_Alloc(T2->NbRows, T2->NbColumns);
610 int ok = Matrix_Inverse(T2, inv);
611 assert(ok);
612 Matrix_Free(Rays);
613 Matrix_Free(T2);
614 /* temporarily ignore (common) denominator */
615 V->Vertex->NbColumns--;
616 Matrix *L = Matrix_Alloc(inv->NbRows, V->Vertex->NbColumns);
617 Matrix_Product(inv, V->Vertex, L);
618 V->Vertex->NbColumns++;
619 Matrix_Free(inv);
621 evalue f;
622 value_init(f.d);
623 value_init(f.x.n);
625 evalue *remainders[dim];
626 for (int i = 0; i < dim; ++i)
627 remainders[i] = ceil(L->p[i], nparam+1, V->Vertex->p[0][nparam+1],
628 options);
629 Matrix_Free(L);
632 for (int i = 0; i < V->Vertex->NbRows; ++i) {
633 values2zz(V->Vertex->p[i], vertex, nparam+1);
634 E_vertex[i] = multi_monom(vertex);
635 num[i] = 0;
637 value_set_si(f.x.n, 1);
638 value_assign(f.d, V->Vertex->p[0][nparam+1]);
640 emul(&f, E_vertex[i]);
642 for (int j = 0; j < dim; ++j) {
643 if (value_zero_p(T->p[i][j]))
644 continue;
645 evalue cp;
646 value_init(cp.d);
647 evalue_copy(&cp, remainders[j]);
648 if (value_notone_p(T->p[i][j])) {
649 value_set_si(f.d, 1);
650 value_assign(f.x.n, T->p[i][j]);
651 emul(&f, &cp);
653 eadd(&cp, E_vertex[i]);
654 free_evalue_refs(&cp);
657 for (int i = 0; i < dim; ++i) {
658 free_evalue_refs(remainders[i]);
659 free(remainders[i]);
662 free_evalue_refs(&f);
664 Matrix_Free(T);
665 value_clear(tmp);
666 return;
668 value_clear(tmp);
670 for (int i = 0; i < V->Vertex->NbRows; ++i) {
671 /* fixed value */
672 if (First_Non_Zero(V->Vertex->p[i], nparam) == -1) {
673 E_vertex[i] = 0;
674 value2zz(V->Vertex->p[i][nparam], num[i]);
675 } else {
676 values2zz(V->Vertex->p[i], vertex, nparam+1);
677 E_vertex[i] = multi_monom(vertex);
678 num[i] = 0;
683 static int lattice_point_fixed(Param_Vertices* V, const mat_ZZ& rays,
684 vec_ZZ& lambda, term_info* term, unsigned long det)
686 unsigned nparam = V->Vertex->NbColumns - 2;
687 unsigned dim = rays.NumCols();
689 for (int i = 0; i < dim; ++i)
690 if (First_Non_Zero(V->Vertex->p[i], nparam) != -1)
691 return 0;
693 Vector *fixed = Vector_Alloc(dim+1);
694 for (int i = 0; i < dim; ++i)
695 value_assign(fixed->p[i], V->Vertex->p[i][nparam]);
696 value_assign(fixed->p[dim], V->Vertex->p[0][nparam+1]);
698 mat_ZZ vertex;
699 Matrix *points = Matrix_Alloc(det, dim);
700 Matrix* Rays = zz2matrix(rays);
701 lattice_points_fixed(fixed->p, fixed->p, Rays, Rays, points, det);
702 Matrix_Free(Rays);
703 matrix2zz(points, vertex, points->NbRows, points->NbColumns);
704 Matrix_Free(points);
705 term->E = NULL;
706 term->constant = vertex * lambda;
707 Vector_Free(fixed);
709 return 1;
712 /* Returns the power of (t+1) in the term of a rational generating function,
713 * i.e., the scalar product of the actual lattice point and lambda.
714 * The lattice point is the unique lattice point in the fundamental parallelepiped
715 * of the unimodual cone i shifted to the parametric vertex V.
717 * The result is returned in term.
719 void lattice_point(Param_Vertices* V, const mat_ZZ& rays, vec_ZZ& lambda,
720 term_info* term, unsigned long det,
721 barvinok_options *options)
723 unsigned nparam = V->Vertex->NbColumns - 2;
724 unsigned dim = rays.NumCols();
725 mat_ZZ vertex;
726 vertex.SetDims(V->Vertex->NbRows, nparam+1);
728 Param_Vertex_Common_Denominator(V);
730 if (lattice_point_fixed(V, rays, lambda, term, det))
731 return;
733 if (det != 1 || value_notone_p(V->Vertex->p[0][nparam+1])) {
734 term->E = lattice_point(rays, lambda, V, det, options);
735 return;
737 for (int i = 0; i < V->Vertex->NbRows; ++i) {
738 assert(value_one_p(V->Vertex->p[i][nparam+1])); // for now
739 values2zz(V->Vertex->p[i], vertex[i], nparam+1);
742 vec_ZZ num;
743 num = lambda * vertex;
745 int nn = 0;
746 for (int j = 0; j < nparam; ++j)
747 if (num[j] != 0)
748 ++nn;
749 if (nn >= 1) {
750 term->E = new evalue *[1];
751 term->E[0] = multi_monom(num);
752 } else {
753 term->E = NULL;
754 term->constant.SetLength(1);
755 term->constant[0] = num[nparam];