CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418425
1
/*
2
* Normaliz
3
* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*
17
* As an exception, when this program is distributed through (i) the App Store
18
* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play
19
* by Google Inc., then that store may impose any digital rights management,
20
* device limits and/or redistribution restrictions that are required by its
21
* terms of service.
22
*/
23
24
#ifndef CONE_H_
25
#define CONE_H_
26
27
#include <vector>
28
#include <map>
29
#include <utility> //for pair
30
//#include <boost/dynamic_bitset.hpp>
31
32
#include <libQnormaliz/libQnormaliz.h>
33
#include <libQnormaliz/Qcone_property.h>
34
#include <libQnormaliz/Qsublattice_representation.h>
35
#include <libQnormaliz/Qmatrix.h>
36
// #include <libQnormaliz/QHilbertSeries.h>
37
38
namespace libQnormaliz {
39
using std::vector;
40
using std::map;
41
using std::pair;
42
43
template<typename Number> class Full_Cone;
44
//template<typename Number> class Matrix;
45
46
// type for simplex, short in contrast to class Simplex
47
template<typename Number> struct SHORTSIMPLEX {
48
vector<key_t> key; // full key of simplex
49
Number height; // height of last vertex over opposite facet
50
Number vol; // volume if computed, 0 else
51
vector<bool> Excluded; // for disjoint decomposition of cone
52
// true in position i indictate sthat the facet
53
// opposite of generator i must be excluded
54
};
55
56
57
template<typename Number>
58
class Cone {
59
60
//---------------------------------------------------------------------------
61
// public methods
62
//---------------------------------------------------------------------------
63
public:
64
65
//---------------------------------------------------------------------------
66
// Constructors, they preprocess the input
67
//---------------------------------------------------------------------------
68
69
/* give up to 3 matrices as input
70
* the types must be pairwise different
71
*/
72
Cone(InputType type, const vector< vector<Number> >& input_data);
73
74
Cone(InputType type1, const vector< vector<Number> >& input_data1,
75
InputType type2, const vector< vector<Number> >& input_data2);
76
77
Cone(InputType type1, const vector< vector<Number> >& input_data1,
78
InputType type2, const vector< vector<Number> >& input_data2,
79
InputType type3, const vector< vector<Number> >& input_data3);
80
81
/* give multiple input */
82
Cone(const map< InputType , vector< vector<Number> > >& multi_input_data);
83
84
// Now with Matrix
85
Cone(InputType type, const Matrix<Number>& input_data);
86
87
Cone(InputType type1, const Matrix<Number>& input_data1,
88
InputType type2, const Matrix<Number>& input_data2);
89
90
Cone(InputType type1, const Matrix<Number>& input_data1,
91
InputType type2, const Matrix<Number>& input_data2,
92
InputType type3, const Matrix<Number>& input_data3);
93
94
/* give multiple input */
95
Cone(const map< InputType , Matrix<Number> >& multi_input_data);
96
//---------------------------------------------------------------------------
97
// Destructor
98
//---------------------------------------------------------------------------
99
100
~Cone();
101
102
//---------------------------------------------------------------------------
103
// give additional data
104
//---------------------------------------------------------------------------
105
106
/* Sets if the Cone prints verbose output.
107
* The default value for the Cone is the global verbose.
108
* returns the old value
109
*/
110
bool setVerbose (bool v);
111
112
//---------------------------------------------------------------------------
113
// make computations
114
//---------------------------------------------------------------------------
115
116
// return what was NOT computed
117
// ConeProperties compute(ComputationMode mode = Mode::hilbertBasisSeries); //default: everything
118
ConeProperties compute(ConeProperties ToCompute);
119
// special case for up to 3 CPs
120
ConeProperties compute(ConeProperty::Enum);
121
ConeProperties compute(ConeProperty::Enum, ConeProperty::Enum);
122
ConeProperties compute(ConeProperty::Enum, ConeProperty::Enum, ConeProperty::Enum);
123
124
//---------------------------------------------------------------------------
125
// check what is computed
126
//---------------------------------------------------------------------------
127
128
bool isComputed(ConeProperty::Enum prop) const;
129
//returns true, when ALL properties in CheckComputed are computed
130
bool isComputed(ConeProperties CheckComputed) const;
131
132
//---------------------------------------------------------------------------
133
// get the results, these methods will start a computation if necessary
134
// throws an NotComputableException if not succesful
135
//---------------------------------------------------------------------------
136
137
// dimension and rank invariants
138
size_t getEmbeddingDim() const { return dim; }; // is always known
139
size_t getRank(); // depends on ExtremeRays
140
Number getIndex(); // depends on OriginalMonoidGenerators
141
Number getInternalIndex(); // = getIndex()
142
Number getUnitGroupIndex(); // ditto
143
// only for inhomogeneous case:
144
size_t getRecessionRank();
145
long getAffineDim();
146
size_t getModuleRank();
147
148
const Matrix<Number>& getGeneratorsMatrix();
149
const vector< vector<Number> >& getGenerators();
150
size_t getNrGenerators();
151
152
const Matrix<Number>& getExtremeRaysMatrix();
153
const vector< vector<Number> >& getExtremeRays();
154
size_t getNrExtremeRays();
155
156
const Matrix<Number>& getVerticesOfPolyhedronMatrix();
157
const vector< vector<Number> >& getVerticesOfPolyhedron();
158
size_t getNrVerticesOfPolyhedron();
159
160
const Matrix<Number>& getSupportHyperplanesMatrix();
161
const vector< vector<Number> >& getSupportHyperplanes();
162
size_t getNrSupportHyperplanes();
163
164
const Matrix<Number>& getMaximalSubspaceMatrix();
165
const vector< vector<Number> >& getMaximalSubspace();
166
size_t getDimMaximalSubspace();
167
168
// depends on the ConeProperty::s SupportHyperplanes and Sublattice
169
map< InputType, vector< vector<Number> > > getConstraints();
170
171
size_t getTriangulationSize();
172
Number getTriangulationDetSum();
173
174
// the actual grading is Grading/GradingDenom
175
vector<Number> getGrading();
176
Number getGradingDenom();
177
178
vector<Number> getDehomogenization();
179
180
bool inequalities_present;
181
182
bool isPointed();
183
bool isInhomogeneous();
184
bool isDeg1ExtremeRays();
185
186
const Matrix<Number>& getOriginalMonoidGeneratorsMatrix();
187
const vector< vector<Number> >& getOriginalMonoidGenerators();
188
size_t getNrOriginalMonoidGenerators();
189
190
const Sublattice_Representation<Number>& getSublattice();
191
// the following 2 methods give information about the last used triangulation
192
// if no triangulation was computed so far they return false
193
bool isTriangulationNested();
194
bool isTriangulationPartial();
195
const vector< pair<vector<key_t>, Number> >& getTriangulation();
196
const vector< vector<bool> >& getOpenFacets();
197
198
//---------------------------------------------------------------------------
199
// private part
200
//---------------------------------------------------------------------------
201
202
private:
203
size_t dim;
204
205
Sublattice_Representation<Number> BasisChange; //always use compose_basis_change() !
206
Sublattice_Representation<Number> BasisChangePointed; // to the pointed cone
207
bool BC_set;
208
bool verbose;
209
ConeProperties is_Computed;
210
// Matrix<Number> GeneratorsOfToricRing;
211
Matrix<Number> OriginalMonoidGenerators;
212
Matrix<Number> Generators;
213
Matrix<Number> ExtremeRays;
214
vector<bool> ExtremeRaysIndicator;
215
Matrix<Number> VerticesOfPolyhedron;
216
Matrix<Number> SupportHyperplanes;
217
Matrix<Number> ExcludedFaces;
218
Matrix<Number> PreComputedSupportHyperplanes;
219
size_t TriangulationSize;
220
Number TriangulationDetSum;
221
bool triangulation_is_nested;
222
bool triangulation_is_partial;
223
vector< pair<vector<key_t>, Number> > Triangulation;
224
vector<vector<bool> > OpenFacets;
225
vector< pair<vector<key_t>, long> > InExData;
226
// mpq_class multiplicity;
227
vector<Number> WitnessNotIntegrallyClosed;
228
Matrix<Number> HilbertBasis;
229
Matrix<Number> BasisMaxSubspace;
230
Matrix<Number> ModuleGeneratorsOverOriginalMonoid;
231
Matrix<Number> Deg1Elements;
232
233
vector<Number> Grading;
234
vector<Number> Dehomogenization;
235
Number GradingDenom;
236
Number index; // the internal index
237
Number unit_group_index;
238
239
bool pointed;
240
bool inhomogeneous;
241
242
int affine_dim; //dimension of polyhedron
243
size_t recession_rank; // rank of recession monoid
244
size_t module_rank; // for the inhomogeneous case
245
Matrix<Number> ModuleGenerators;
246
247
bool explicit_HilbertSeries;
248
bool naked_dual;
249
250
Matrix<Number> WeightsGrad;
251
vector<bool> GradAbs;
252
253
bool no_lattice_restriction; // true if cine generators are known to be in the relevant lattice
254
bool normalization; // true if input type normalization is used
255
256
// if this is true we allow to change to a smaller integer type in the computation
257
bool change_integer_type;
258
259
260
void compose_basis_change(const Sublattice_Representation<Number>& SR); // composes SR
261
262
// main input processing
263
void process_multi_input(const map< InputType, vector< vector<Number> > >& multi_input_data);
264
void prepare_input_lattice_ideal(map< InputType, vector< vector<Number> > >& multi_input_data);
265
void prepare_input_constraints(const map< InputType, vector< vector<Number> > >& multi_input_data,
266
Matrix<Number>& equations, Matrix<Number>& congruence, Matrix<Number>& Inequalities);
267
void prepare_input_generators(map< InputType, vector< vector<Number> > >& multi_input_data,
268
Matrix<Number>& LatticeGenerators);
269
void homogenize_input(map< InputType, vector< vector<Number> > >& multi_input_data);
270
void check_precomputed_support_hyperplanes();
271
272
273
void setWeights ();
274
void setDehomogenization (const vector<Number>& lf);
275
276
void checkDehomogenization();
277
void check_vanishing_of_grading_and_dehom();
278
void process_lattice_data(const Matrix<Number>& LatticeGenerators, Matrix<Number>& Congruences, Matrix<Number>& Equations);
279
280
ConeProperties recursive_compute(ConeProperties ToCompute);
281
282
Matrix<Number> prepare_input_type_2(const vector< vector<Number> >& Input);
283
Matrix<Number> prepare_input_type_3(const vector< vector<Number> >& Input);
284
void prepare_input_type_4(Matrix<Number>& Inequalities);
285
286
/* only used by the constructors */
287
void initialize();
288
289
template<typename NumberFC>
290
void compute_inner(ConeProperties& ToCompute);
291
292
/* compute the generators using the support hyperplanes */
293
void compute_generators();
294
template<typename NumberFC>
295
void compute_generators_inner();
296
297
/* compute method for the dual_mode, used in compute(mode) */
298
void compute_dual(ConeProperties& ToCompute);
299
template<typename NumberFC>
300
void compute_dual_inner(ConeProperties& ToCompute);
301
302
void set_implicit_dual_mode(ConeProperties& ToCompute);
303
304
/* extract the data from Full_Cone, this may remove data from Full_Cone!*/
305
template<typename NumberFC>
306
void extract_data(Full_Cone<NumberFC>& FC);
307
template<typename NumberFC>
308
void extract_supphyps(Full_Cone<NumberFC>& FC);
309
310
void extract_supphyps(Full_Cone<Number>& FC);
311
312
313
/* set OriginalMonoidGenerators */
314
void set_original_monoid_generators(const Matrix<Number>&);
315
316
/* set ExtremeRays, in inhomogeneous case also VerticesOfPolyhedron */
317
void set_extreme_rays(const vector<bool>&);
318
319
/* If the Hilbert basis and the original monoid generators are computed,
320
* use them to check whether the original monoid is integrally closed. */
321
void check_integrally_closed();
322
void compute_unit_group_index();
323
/* try to find a witness for not integrally closed in the Hilbert basis */
324
void find_witness();
325
326
Number compute_primary_multiplicity();
327
template<typename NumberFC>
328
Number compute_primary_multiplicity_inner();
329
330
void compute_integer_hull();
331
void complete_sublattice_comp(ConeProperties& ToCompute); // completes the sublattice computations
332
void complete_HilbertSeries_comp(ConeProperties& ToCompute);
333
334
};
335
336
// helpers
337
338
template<typename Number>
339
vector<vector<Number> > find_input_matrix(const map< InputType, vector< vector<Number> > >& multi_input_data,
340
const InputType type);
341
342
template<typename Number>
343
void insert_zero_column(vector< vector<Number> >& mat, size_t col);
344
345
template<typename Number>
346
void insert_column(vector< vector<Number> >& mat, size_t col, Number entry);
347
348
} //end namespace libQnormaliz
349
350
#endif /* CONE_H_ */
351
352