iscc: add "lb" operation
[barvinok/uuh.git] / lattice_point.cc
blob1ea6b001b666bdf3f8d407d79abf28c29a32f21a
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 = ALLOC(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 value_gcd(gcd, gcd, *m);
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 evalue_free(E);
243 free_evalue_refs(&tmp);
245 value_clear(m);
247 return EP;
250 /* Computes the ceil of the affine expression specified
251 * by coef (of length nvar+1) and the denominator denom.
252 * If PD is not NULL, then it specifies additional constraints
253 * on the variables that may be used to simplify the resulting
254 * ceil expression.
256 * Modifies coef argument !
258 evalue *ceiling(Value *coef, Value denom, int nvar, Polyhedron *PD)
260 evalue *EP, *f;
261 EP = affine2evalue(coef, denom, nvar);
262 Vector_Oppose(coef, coef, nvar+1);
263 f = fractional_part(coef, denom, nvar, PD);
264 eadd(f, EP);
265 evalue_free(f);
266 return EP;
269 static evalue *ceil(Value *coef, int len, Value d,
270 barvinok_options *options)
272 evalue *c;
274 Vector_Oppose(coef, coef, len);
275 c = fractional_part(coef, d, len-1, NULL);
276 if (options->lookup_table)
277 evalue_mod2table(c, len-1);
278 return c;
281 void lattice_point_fixed(Value *vertex, Value *vertex_res,
282 Matrix *Rays, Matrix *Rays_res,
283 Value *point)
285 unsigned dim = Rays->NbRows;
286 if (value_one_p(vertex[dim]))
287 Vector_Copy(vertex_res, point, Rays_res->NbColumns);
288 else {
289 Matrix *R2 = Matrix_Copy(Rays);
290 Matrix *inv = Matrix_Alloc(Rays->NbRows, Rays->NbColumns);
291 int ok = Matrix_Inverse(R2, inv);
292 assert(ok);
293 Matrix_Free(R2);
294 Vector *lambda = Vector_Alloc(dim);
295 Vector_Matrix_Product(vertex, inv, lambda->p);
296 Matrix_Free(inv);
297 for (int j = 0; j < dim; ++j)
298 mpz_cdiv_q(lambda->p[j], lambda->p[j], vertex[dim]);
299 Vector_Matrix_Product(lambda->p, Rays_res, point);
300 Vector_Free(lambda);
304 static Matrix *Matrix_AddRowColumn(Matrix *M)
306 Matrix *M2 = Matrix_Alloc(M->NbRows+1, M->NbColumns+1);
307 for (int i = 0; i < M->NbRows; ++i)
308 Vector_Copy(M->p[i], M2->p[i], M->NbColumns);
309 value_set_si(M2->p[M->NbRows][M->NbColumns], 1);
310 return M2;
313 #define FORALL_COSETS(det,D,i,k) \
314 do { \
315 Vector *k = Vector_Alloc(D->NbRows+1); \
316 value_set_si(k->p[D->NbRows], 1); \
317 for (unsigned long i = 0; i < det; ++i) { \
318 if (i) \
319 for (int j = D->NbRows-1; j >= 0; --j) { \
320 value_increment(k->p[j], k->p[j]); \
321 if (value_eq(k->p[j], D->p[j][j])) \
322 value_set_si(k->p[j], 0); \
323 else \
324 break; \
327 #define END_FORALL_COSETS \
330 Vector_Free(k); \
331 } while(0);
333 /* Compute the lattice points in the vertex cone at "values" with rays "rays".
334 * The lattice points are returned in "vertex".
336 * Rays has the generators as rows and so does W.
337 * We first compute { m-v, u_i^* } with m = k W, where k runs through
338 * the cosets.
339 * We compute
340 * [k 1] [ d1*W 0 ] [ U' 0 ] = [k 1] T2
341 * [ -v d1 ] [ 0 d2 ]
342 * where d1 and d2 are the denominators of v and U^{-1}=U'/d2.
343 * Then lambda = { k } (componentwise)
344 * We compute x - floor(x) = {x} = { a/b } as fdiv_r(a,b)/b
345 * For open rays/facets, we need values in (0,1] rather than [0,1),
346 * so we compute {{x}} = x - ceil(x-1) = a/b - ceil((a-b)/b)
347 * = (a - b cdiv_q(a-b,b) - b + b)/b
348 * = (cdiv_r(a,b)+b)/b
349 * Finally, we compute v + lambda * U
350 * The denominator of lambda can be d1*d2, that of lambda2 = lambda*U
351 * can be at most d1, since it is integer if v = 0.
352 * The denominator of v + lambda2 is 1.
354 * The _res variants of the input variables may have been multiplied with
355 * a (list of) nonorthogonal vector(s) and may therefore have fewer columns
356 * than their original counterparts.
358 void lattice_points_fixed(Value *vertex, Value *vertex_res,
359 Matrix *Rays, Matrix *Rays_res, Matrix *points,
360 unsigned long det)
362 unsigned dim = Rays->NbRows;
363 if (det == 1) {
364 lattice_point_fixed(vertex, vertex_res, Rays, Rays_res,
365 points->p[0]);
366 return;
368 Matrix *U, *W, *D;
369 Smith(Rays, &U, &W, &D);
370 Matrix_Free(U);
372 /* Sanity check */
373 unsigned long det2 = 1;
374 for (int i = 0 ; i < D->NbRows; ++i)
375 det2 *= mpz_get_ui(D->p[i][i]);
376 assert(det == det2);
378 Matrix *T = Matrix_Alloc(W->NbRows+1, W->NbColumns+1);
379 for (int i = 0; i < W->NbRows; ++i)
380 Vector_Scale(W->p[i], T->p[i], vertex[dim], W->NbColumns);
381 Matrix_Free(W);
382 Vector_Oppose(vertex, T->p[dim], dim);
383 value_assign(T->p[dim][dim], vertex[dim]);
385 Matrix *R2 = Matrix_AddRowColumn(Rays);
386 Matrix *inv = Matrix_Alloc(R2->NbRows, R2->NbColumns);
387 int ok = Matrix_Inverse(R2, inv);
388 assert(ok);
389 Matrix_Free(R2);
391 Matrix *T2 = Matrix_Alloc(dim+1, dim+1);
392 Matrix_Product(T, inv, T2);
393 Matrix_Free(T);
395 Vector *lambda = Vector_Alloc(dim+1);
396 Vector *lambda2 = Vector_Alloc(Rays_res->NbColumns);
397 FORALL_COSETS(det, D, i, k)
398 Vector_Matrix_Product(k->p, T2, lambda->p);
399 for (int j = 0; j < dim; ++j)
400 mpz_fdiv_r(lambda->p[j], lambda->p[j], lambda->p[dim]);
401 Vector_Matrix_Product(lambda->p, Rays_res, lambda2->p);
402 for (int j = 0; j < lambda2->Size; ++j)
403 assert(mpz_divisible_p(lambda2->p[j], inv->p[dim][dim]));
404 Vector_AntiScale(lambda2->p, lambda2->p, inv->p[dim][dim], lambda2->Size);
405 Vector_Add(lambda2->p, vertex_res, lambda2->p, lambda2->Size);
406 for (int j = 0; j < lambda2->Size; ++j)
407 assert(mpz_divisible_p(lambda2->p[j], vertex[dim]));
408 Vector_AntiScale(lambda2->p, points->p[i], vertex[dim], lambda2->Size);
409 END_FORALL_COSETS
410 Vector_Free(lambda);
411 Vector_Free(lambda2);
412 Matrix_Free(D);
413 Matrix_Free(inv);
415 Matrix_Free(T2);
418 /* Returns the power of (t+1) in the term of a rational generating function,
419 * i.e., the scalar product of the actual lattice point and lambda.
420 * The lattice point is the unique lattice point in the fundamental parallelepiped
421 * of the unimodual cone i shifted to the parametric vertex W/lcm.
423 * The rows of W refer to the coordinates of the vertex
424 * The first nparam columns are the coefficients of the parameters
425 * and the final column is the constant term.
426 * lcm is the common denominator of all coefficients.
428 static evalue **lattice_point_fractional(const mat_ZZ& rays, vec_ZZ& lambda,
429 Matrix *V,
430 unsigned long det)
432 unsigned nparam = V->NbColumns-2;
433 evalue **E = new evalue *[det];
435 Matrix* Rays = zz2matrix(rays);
436 Matrix *T = Transpose(Rays);
437 Matrix *T2 = Matrix_Copy(T);
438 Matrix *inv = Matrix_Alloc(T2->NbRows, T2->NbColumns);
439 int ok = Matrix_Inverse(T2, inv);
440 assert(ok);
441 Matrix_Free(T2);
442 mat_ZZ vertex;
443 matrix2zz(V, vertex, V->NbRows, V->NbColumns-1);
445 vec_ZZ num;
446 num = lambda * vertex;
448 evalue *EP = multi_monom(num);
450 evalue_div(EP, V->p[0][nparam+1]);
452 Matrix *L = Matrix_Alloc(inv->NbRows, V->NbColumns);
453 Matrix_Product(inv, V, L);
455 mat_ZZ RT;
456 matrix2zz(T, RT, T->NbRows, T->NbColumns);
457 Matrix_Free(T);
459 vec_ZZ p = lambda * RT;
461 Value tmp;
462 value_init(tmp);
464 if (det == 1) {
465 for (int i = 0; i < L->NbRows; ++i) {
466 evalue *f;
467 Vector_Oppose(L->p[i], L->p[i], nparam+1);
468 f = fractional_part(L->p[i], V->p[i][nparam+1], nparam, NULL);
469 zz2value(p[i], tmp);
470 evalue_mul(f, tmp);
471 eadd(f, EP);
472 evalue_free(f);
474 E[0] = EP;
475 } else {
476 for (int i = 0; i < L->NbRows; ++i)
477 value_assign(L->p[i][nparam+1], V->p[i][nparam+1]);
479 Value denom;
480 value_init(denom);
481 mpz_set_ui(denom, det);
482 value_multiply(denom, L->p[0][nparam+1], denom);
484 Matrix *U, *W, *D;
485 Smith(Rays, &U, &W, &D);
486 Matrix_Free(U);
488 /* Sanity check */
489 unsigned long det2 = 1;
490 for (int i = 0 ; i < D->NbRows; ++i)
491 det2 *= mpz_get_ui(D->p[i][i]);
492 assert(det == det2);
494 Matrix_Transposition(inv);
495 Matrix *T2 = Matrix_Alloc(W->NbRows, inv->NbColumns);
496 Matrix_Product(W, inv, T2);
497 Matrix_Free(W);
499 unsigned dim = D->NbRows;
500 Vector *lambda = Vector_Alloc(dim);
502 Vector *row = Vector_Alloc(nparam+1);
503 FORALL_COSETS(det, D, i, k)
504 Vector_Matrix_Product(k->p, T2, lambda->p);
505 E[i] = ALLOC(evalue);
506 value_init(E[i]->d);
507 evalue_copy(E[i], EP);
508 for (int j = 0; j < L->NbRows; ++j) {
509 evalue *f;
510 Vector_Oppose(L->p[j], row->p, nparam+1);
511 value_addmul(row->p[nparam], L->p[j][nparam+1], lambda->p[j]);
512 f = fractional_part(row->p, denom, nparam, NULL);
513 zz2value(p[j], tmp);
514 evalue_mul(f, tmp);
515 eadd(f, E[i]);
516 evalue_free(f);
518 END_FORALL_COSETS
519 Vector_Free(row);
521 Vector_Free(lambda);
522 Matrix_Free(T2);
523 Matrix_Free(D);
525 value_clear(denom);
526 evalue_free(EP);
528 value_clear(tmp);
530 Matrix_Free(Rays);
531 Matrix_Free(L);
532 Matrix_Free(inv);
534 return E;
537 static evalue **lattice_point(const mat_ZZ& rays, vec_ZZ& lambda,
538 Param_Vertices *V,
539 unsigned long det,
540 barvinok_options *options)
542 evalue **lp = lattice_point_fractional(rays, lambda, V->Vertex, det);
543 if (options->lookup_table) {
544 for (int i = 0; i < det; ++i)
545 evalue_mod2table(lp[i], V->Vertex->NbColumns-2);
547 return lp;
550 Matrix *relative_coordinates(Param_Vertices *V, Matrix *basis)
552 unsigned nparam = V->Vertex->NbColumns - 2;
553 Matrix *T = Matrix_Copy(basis);
554 Matrix *inv = Matrix_Alloc(T->NbRows, T->NbColumns);
555 int ok = Matrix_Inverse(T, inv);
556 assert(ok);
557 Matrix_Free(T);
559 Param_Vertex_Common_Denominator(V);
560 /* temporarily ignore (common) denominator */
561 V->Vertex->NbColumns--;
562 Matrix *L = Matrix_Alloc(inv->NbRows, V->Vertex->NbColumns);
563 Matrix_Product(inv, V->Vertex, L);
564 V->Vertex->NbColumns++;
565 Matrix_Free(inv);
567 return L;
570 /* returns the unique lattice point in the fundamental parallelepiped
571 * of the unimodual cone C shifted to the parametric vertex V.
573 * The return values num and E_vertex are such that
574 * coordinate i of this lattice point is equal to
576 * num[i] + E_vertex[i]
578 void lattice_point(Param_Vertices *V, const mat_ZZ& rays, vec_ZZ& num,
579 evalue **E_vertex, barvinok_options *options)
581 unsigned nparam = V->Vertex->NbColumns - 2;
582 unsigned dim = rays.NumCols();
584 /* It doesn't really make sense to call lattice_point when dim == 0,
585 * but apparently it happens from indicator_constructor in lexmin.
587 if (!dim)
588 return;
590 vec_ZZ vertex;
591 vertex.SetLength(nparam+1);
593 Value tmp;
594 value_init(tmp);
596 assert(V->Vertex->NbRows > 0);
597 Param_Vertex_Common_Denominator(V);
599 if (value_notone_p(V->Vertex->p[0][nparam+1])) {
600 Matrix* Rays = zz2matrix(rays);
601 Matrix *T = Transpose(Rays);
602 Matrix_Free(Rays);
603 Matrix *L = relative_coordinates(V, T);
605 evalue f;
606 value_init(f.d);
607 value_init(f.x.n);
609 evalue **remainders = new evalue *[dim];
610 for (int i = 0; i < dim; ++i)
611 remainders[i] = ceil(L->p[i], nparam+1, V->Vertex->p[0][nparam+1],
612 options);
613 Matrix_Free(L);
616 for (int i = 0; i < V->Vertex->NbRows; ++i) {
617 values2zz(V->Vertex->p[i], vertex, nparam+1);
618 E_vertex[i] = multi_monom(vertex);
619 num[i] = 0;
621 value_set_si(f.x.n, 1);
622 value_assign(f.d, V->Vertex->p[0][nparam+1]);
624 emul(&f, E_vertex[i]);
626 for (int j = 0; j < dim; ++j) {
627 if (value_zero_p(T->p[i][j]))
628 continue;
629 evalue cp;
630 value_init(cp.d);
631 evalue_copy(&cp, remainders[j]);
632 if (value_notone_p(T->p[i][j])) {
633 value_set_si(f.d, 1);
634 value_assign(f.x.n, T->p[i][j]);
635 emul(&f, &cp);
637 eadd(&cp, E_vertex[i]);
638 free_evalue_refs(&cp);
641 for (int i = 0; i < dim; ++i)
642 evalue_free(remainders[i]);
643 delete [] remainders;
645 free_evalue_refs(&f);
647 Matrix_Free(T);
648 value_clear(tmp);
649 return;
651 value_clear(tmp);
653 for (int i = 0; i < V->Vertex->NbRows; ++i) {
654 /* fixed value */
655 if (First_Non_Zero(V->Vertex->p[i], nparam) == -1) {
656 E_vertex[i] = 0;
657 value2zz(V->Vertex->p[i][nparam], num[i]);
658 } else {
659 values2zz(V->Vertex->p[i], vertex, nparam+1);
660 E_vertex[i] = multi_monom(vertex);
661 num[i] = 0;
666 static int lattice_point_fixed(Param_Vertices* V, const mat_ZZ& rays,
667 vec_ZZ& lambda, term_info* term, unsigned long det)
669 unsigned nparam = V->Vertex->NbColumns - 2;
670 unsigned dim = rays.NumCols();
672 for (int i = 0; i < dim; ++i)
673 if (First_Non_Zero(V->Vertex->p[i], nparam) != -1)
674 return 0;
676 Vector *fixed = Vector_Alloc(dim+1);
677 for (int i = 0; i < dim; ++i)
678 value_assign(fixed->p[i], V->Vertex->p[i][nparam]);
679 value_assign(fixed->p[dim], V->Vertex->p[0][nparam+1]);
681 mat_ZZ vertex;
682 Matrix *points = Matrix_Alloc(det, dim);
683 Matrix* Rays = zz2matrix(rays);
684 lattice_points_fixed(fixed->p, fixed->p, Rays, Rays, points, det);
685 Matrix_Free(Rays);
686 matrix2zz(points, vertex, points->NbRows, points->NbColumns);
687 Matrix_Free(points);
688 term->E = NULL;
689 term->constant = vertex * lambda;
690 Vector_Free(fixed);
692 return 1;
695 /* Returns the power of (t+1) in the term of a rational generating function,
696 * i.e., the scalar product of the actual lattice point and lambda.
697 * The lattice point is the unique lattice point in the fundamental parallelepiped
698 * of the unimodual cone i shifted to the parametric vertex V.
700 * The result is returned in term.
702 void lattice_point(Param_Vertices* V, const mat_ZZ& rays, vec_ZZ& lambda,
703 term_info* term, unsigned long det,
704 barvinok_options *options)
706 unsigned nparam = V->Vertex->NbColumns - 2;
707 unsigned dim = rays.NumCols();
708 mat_ZZ vertex;
709 vertex.SetDims(V->Vertex->NbRows, nparam+1);
711 Param_Vertex_Common_Denominator(V);
713 if (lattice_point_fixed(V, rays, lambda, term, det))
714 return;
716 if (det != 1 || value_notone_p(V->Vertex->p[0][nparam+1])) {
717 term->E = lattice_point(rays, lambda, V, det, options);
718 return;
720 for (int i = 0; i < V->Vertex->NbRows; ++i) {
721 assert(value_one_p(V->Vertex->p[i][nparam+1])); // for now
722 values2zz(V->Vertex->p[i], vertex[i], nparam+1);
725 vec_ZZ num;
726 num = lambda * vertex;
728 int nn = 0;
729 for (int j = 0; j < nparam; ++j)
730 if (num[j] != 0)
731 ++nn;
732 if (nn >= 1) {
733 term->E = new evalue *[1];
734 term->E[0] = multi_monom(num);
735 } else {
736 term->E = NULL;
737 term->constant.SetLength(1);
738 term->constant[0] = num[nparam];