2 #include <polylib/polylibgmp.h>
3 #include <barvinok/genfun.h>
4 #include <barvinok/util.h>
5 #include "basis_reduction.h"
13 #ifdef HAVE_GROWING_CHERNIKOVA
14 #define MAXRAYS (POL_NO_DUAL | POL_INTEGER)
19 static Polyhedron
*uncone(Polyhedron
*C
, unsigned MaxRays
)
25 Constraints
= Matrix_Alloc(C
->NbConstraints
, 1+(C
->Dimension
-1)+1);
26 for (i
= 0; i
< C
->NbConstraints
; ++i
) {
27 /* positivity constraints */
28 if (First_Non_Zero(C
->Constraint
[i
]+1, C
->Dimension
) == -1) {
29 assert(i
== C
->NbConstraints
-1);
30 Constraints
->NbRows
= i
;
33 assert(value_zero_p(C
->Constraint
[i
][1+C
->Dimension
]));
34 Vector_Copy(C
->Constraint
[i
], Constraints
->p
[i
], 1+C
->Dimension
);
36 P
= Constraints2Polyhedron(Constraints
, MaxRays
);
37 Matrix_Free(Constraints
);
42 void static scan(gen_fun
*S
)
47 params
= Vector_Alloc(2);
48 for (int j
= 19; j
<= 39; ++j
) {
49 value_set_si(params
->p
[1], j
);
50 for (int i
= 8; i
<= 17; ++i
) {
51 value_set_si(params
->p
[0], i
);
52 S
->coefficient(params
->p
, &c
);
53 fprintf(stderr
, "%d %d: ", i
, j
);
54 value_print(stderr
, VALUE_FMT
, c
);
55 fprintf(stderr
, "\n");
62 bool is_indicator(gen_fun
*gf
, unsigned MaxRays
)
67 test
= gf
->Hadamard_product(gf
, MaxRays
);
70 test
->print(std::cerr
, 0, NULL
);
74 int main(int argc
, char **argv
)
77 Polyhedron
*P
, *C
, *B
, *Pold
;
80 gen_fun
*S
, *S_shift
, *hp
, *S_divide
, *frob
;
87 coins
= Vector_Read();
89 assert(coins
->Size
== 4);
91 M
= Matrix_Alloc(5, 7);
92 Vector_Copy(coins
->p
, M
->p
[0]+1, 4);
94 value_set_si(M
->p
[0][1+4], -1);
95 for (int i
= 0; i
< 4; ++i
) {
96 value_set_si(M
->p
[1+i
][0], 1);
97 value_set_si(M
->p
[1+i
][1+i
], 1);
99 C
= Constraints2Polyhedron(M
, MAXRAYS
);
101 C
= remove_equalities_p(C
, 4, NULL
);
102 assert(C
->NbEq
== 0);
103 Polyhedron_Print(stderr
, P_VALUE_FMT
, C
);
105 B
= uncone(C
, MAXRAYS
);
107 basis
= reduced_basis(B
);
108 small
= Vector_Alloc(B
->Dimension
+ 2);
109 Vector_Copy(basis
->p
[0], small
->p
, B
->Dimension
);
113 T
= unimodular_complete(small
);
115 Vector_Exchange(T
->p
[0], T
->p
[2], T
->NbColumns
);
116 Matrix_Print(stderr
, P_VALUE_FMT
, T
);
118 Polyhedron_Print(stderr
, P_VALUE_FMT
, C
);
119 P
= Polyhedron_Image(C
, T
, MAXRAYS
);
123 Polyhedron_Print(stderr
, P_VALUE_FMT
, P
);
129 S
= barvinok_enumerate_scarf_series(P
, 2, 2, MAXRAYS
);
130 S
->print(std::cerr
, 0, NULL
);
133 S_shift
= new gen_fun(S
);
134 S_divide
= new gen_fun(S
);
135 S_divide
->divide(up
);
142 hp
= S
->Hadamard_product(S_shift
, MAXRAYS
);
147 hp
= S
->Hadamard_product(S_divide
, MAXRAYS
);
148 ok
= hp
->summate(&c
);
150 assert(value_zero_p(c
));
156 frob
= S
->summate(1);
157 frob
->print(std::cout
, 0, NULL
);