remove_all_equalities: also remove equalities in context
[barvinok.git] / param_util.c
blob4aae82596f5fd400de1bd3cfa5b71bac7aa93f95
1 #include <barvinok/options.h>
2 #include "param_util.h"
4 void Param_Vertex_Common_Denominator(Param_Vertices *V)
6 unsigned dim;
7 Value lcm;
8 int i;
10 assert(V->Vertex->NbRows > 0);
11 dim = V->Vertex->NbColumns-2;
13 value_init(lcm);
15 value_assign(lcm, V->Vertex->p[0][dim+1]);
16 for (i = 1; i < V->Vertex->NbRows; ++i)
17 value_lcm(V->Vertex->p[i][dim+1], lcm, &lcm);
19 for (i = 0; i < V->Vertex->NbRows; ++i) {
20 if (value_eq(V->Vertex->p[i][dim+1], lcm))
21 continue;
22 value_division(V->Vertex->p[i][dim+1], lcm, V->Vertex->p[i][dim+1]);
23 Vector_Scale(V->Vertex->p[i], V->Vertex->p[i],
24 V->Vertex->p[i][dim+1], dim+1);
25 value_assign(V->Vertex->p[i][dim+1], lcm);
28 value_clear(lcm);
31 /* Plug in the parametric vertex Vertex (nvar x (nparam + 2))
32 * in the constraint constraint (1 + nvar + nparam + 1).
33 * The result is stored in row (1 + nparam + 1),
34 * with the denominator in position 0.
36 void Param_Inner_Product(Value *constraint, Matrix *Vertex, Value *row)
38 unsigned nparam = Vertex->NbColumns - 2;
39 unsigned nvar = Vertex->NbRows;
40 int j;
41 Value tmp, tmp2;
43 value_set_si(row[0], 1);
44 Vector_Set(row+1, 0, nparam+1);
46 value_init(tmp);
47 value_init(tmp2);
49 for (j = 0 ; j < nvar; ++j) {
50 value_set_si(tmp, 1);
51 value_assign(tmp2, constraint[1+j]);
52 if (value_ne(row[0], Vertex->p[j][nparam+1])) {
53 value_assign(tmp, row[0]);
54 value_lcm(row[0], Vertex->p[j][nparam+1], &row[0]);
55 value_division(tmp, row[0], tmp);
56 value_multiply(tmp2, tmp2, row[0]);
57 value_division(tmp2, tmp2, Vertex->p[j][nparam+1]);
59 Vector_Combine(row+1, Vertex->p[j], row+1, tmp, tmp2, nparam+1);
61 value_set_si(tmp, 1);
62 Vector_Combine(row+1, constraint+1+nvar, row+1, tmp, row[0], nparam+1);
64 value_clear(tmp);
65 value_clear(tmp2);
68 Param_Polyhedron *Polyhedron2Param_Polyhedron(Polyhedron *Din, Polyhedron *Cin,
69 struct barvinok_options *options)
71 unsigned MaxRays = options->MaxRays;
72 if (MaxRays & POL_NO_DUAL)
73 MaxRays = 0;
74 return Polyhedron2Param_Domain(Din, Cin, MaxRays);