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: 418427
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
/**
25
* The class Sublattice_Representation represents a sublattice of Z^n as Z^r.
26
* To transform vectors of the sublattice use:
27
* Z^r --> Z^n and Z^n --> Z^r
28
* v |-> vA u |-> (uB)/c
29
* A r x n matrix
30
* B n x r matrix
31
* c Integer
32
*/
33
34
#ifndef SUBLATTICE_REPRESENTATION_H
35
#define SUBLATTICE_REPRESENTATION_H
36
37
#include <vector>
38
#include <libnormaliz/libnormaliz.h>
39
#include <libnormaliz/matrix.h>
40
41
//---------------------------------------------------------------------------
42
43
namespace libnormaliz {
44
45
template<typename Integer> class Matrix;
46
// template<typename Integer> class Lineare_Transformation;
47
using std::vector;
48
49
50
template<typename Integer>
51
class Sublattice_Representation {
52
53
template<typename> friend class Sublattice_Representation;
54
55
size_t dim, rank;
56
bool is_identity;
57
Matrix<Integer> A;
58
Matrix<Integer> B;
59
Integer c;
60
mutable mpz_class external_index;
61
mutable Matrix<Integer> Equations;
62
mutable bool Equations_computed;
63
mutable Matrix<Integer> Congruences;
64
mutable bool Congruences_computed;
65
66
void make_equations() const;
67
void make_congruences() const;
68
69
//---------------------------------------------------------------------------
70
public:
71
//---------------------------------------------------------------------------
72
// Construction and destruction
73
//---------------------------------------------------------------------------
74
75
/**
76
* creates a dummy object
77
*/
78
Sublattice_Representation() {}
79
80
/**
81
* creates a representation of Z^n as a sublattice of itself
82
*/
83
Sublattice_Representation(size_t n);
84
85
/**
86
* Main Constructor
87
* creates a representation of a sublattice of Z^n
88
* if direct_summand is false the sublattice is generated by the rows of M
89
* otherwise it is a direct summand of Z^n containing the rows of M
90
*/
91
Sublattice_Representation(const Matrix<Integer>& M, bool take_saturation);
92
// Sublattice_Representation(const Lineare_Transformation<Integer>& LT, bool take_saturation);
93
94
template<typename IntegerFC>
95
Sublattice_Representation(const Sublattice_Representation<IntegerFC>& Original);
96
//---------------------------------------------------------------------------
97
// Manipulation operations
98
//---------------------------------------------------------------------------
99
100
/* like the matching constructor */
101
void initialize(const Matrix<Integer>& M, bool take_saturation, bool& success);
102
103
/* first this then SR when going from Z^n to Z^r */
104
void compose(const Sublattice_Representation<Integer>& SR);
105
106
/* compose with the dual of SR */
107
void compose_dual(const Sublattice_Representation<Integer>& SR);
108
109
//---------------------------------------------------------------------------
110
// Transformations
111
//---------------------------------------------------------------------------
112
113
Matrix<Integer> to_sublattice (const Matrix<Integer>& M) const;
114
Matrix<Integer> from_sublattice (const Matrix<Integer>& M) const;
115
Matrix<Integer> to_sublattice_dual (const Matrix<Integer>& M) const;
116
Matrix<Integer> from_sublattice_dual (const Matrix<Integer>& M) const;
117
118
vector<Integer> to_sublattice (const vector<Integer>& V) const;
119
vector<Integer> from_sublattice (const vector<Integer>& V) const;
120
vector<Integer> to_sublattice_dual (const vector<Integer>& M) const;
121
vector<Integer> from_sublattice_dual (const vector<Integer>& V) const;
122
123
vector<Integer> to_sublattice_dual_no_div (const vector<Integer>& M) const;
124
125
// and with integrated type conversion
126
// Note: the "to" conversions assume that val has the same integer type as the SLR
127
// whereas the "from" versions assume that ret has the same integer type as the SLR.
128
template<typename ToType, typename FromType>
129
void convert_to_sublattice(ToType& ret, const FromType& val) const {
130
convert(ret, to_sublattice(val));
131
}
132
133
template<typename ToType>
134
void convert_to_sublattice(Matrix<ToType>& ret, const Matrix<Integer> & val) const {
135
ret=Matrix<ToType>(val.nr_of_rows(),rank);
136
vector<Integer> v;
137
for(size_t i=0;i<val.nr_of_rows();++i){
138
v=to_sublattice(val[i]);
139
convert(ret[i],v);
140
}
141
}
142
143
template<typename ToType, typename FromType>
144
void convert_from_sublattice(ToType& ret, const FromType& val) const {
145
ret = from_sublattice(convertTo<ToType>(val));
146
}
147
148
template<typename FromType>
149
void convert_from_sublattice(Matrix<Integer>& ret, const Matrix<FromType> & val) const {
150
ret=Matrix<Integer>(val.nr_of_rows(),dim);
151
vector<Integer> v;
152
for(size_t i=0;i<val.nr_of_rows();++i){
153
154
INTERRUPT_COMPUTATION_BY_EXCEPTION
155
156
convert(v,val[i]);
157
ret[i]=from_sublattice(v);
158
}
159
}
160
161
template<typename ToType, typename FromType>
162
void convert_to_sublattice_dual(ToType& ret, const FromType& val) const {
163
convert(ret, to_sublattice_dual(val));
164
}
165
166
template<typename ToType>
167
void convert_to_sublattice_dual(Matrix<ToType>& ret, const Matrix<Integer> & val) const {
168
ret=Matrix<ToType>(val.nr_of_rows(),rank);
169
vector<Integer> v;
170
for(size_t i=0;i<val.nr_of_rows();++i){
171
v=to_sublattice_dual(val[i]);
172
convert(ret[i],v);
173
}
174
}
175
176
template<typename ToType, typename FromType>
177
void convert_from_sublattice_dual(ToType& ret, const FromType& val) const {
178
ret = from_sublattice_dual(convertTo<ToType>(val));
179
}
180
181
template<typename FromType>
182
void convert_from_sublattice_dual(Matrix<Integer>& ret, const Matrix<FromType> & val) const {
183
ret=Matrix<Integer>(val.nr_of_rows(),dim);
184
vector<Integer> v;
185
for(size_t i=0;i<val.nr_of_rows();++i){
186
187
INTERRUPT_COMPUTATION_BY_EXCEPTION
188
189
convert(v,val[i]);
190
ret[i]=from_sublattice_dual(v);
191
}
192
}
193
194
template<typename ToType, typename FromType>
195
void convert_to_sublattice_dual_no_div(ToType& ret, const FromType& val) const {
196
convert(ret, to_sublattice_dual_no_div(val));
197
}
198
199
template<typename ToType>
200
void convert_to_sublattice_dual_no_div(Matrix<ToType>& ret, const Matrix<Integer> & val) const {
201
ret=Matrix<ToType>(val.nr_of_rows(),rank);
202
vector<Integer> v;
203
for(size_t i=0;i<val.nr_of_rows();++i){
204
v=to_sublattice_dual_no_div(val[i]);
205
convert(ret[i],v);
206
}
207
}
208
209
210
//---------------------------------------------------------------------------
211
// Data acces
212
//---------------------------------------------------------------------------
213
214
/* returns the dimension of the ambient space */
215
size_t getDim() const;
216
217
/* returns the rank of the sublattice */
218
size_t getRank() const;
219
220
Integer getAnnihilator() const;
221
bool IsIdentity()const;
222
223
const Matrix<Integer>& getEquationsMatrix() const;
224
const vector<vector<Integer> >& getEquations() const;
225
const Matrix<Integer>& getCongruencesMatrix() const;
226
const vector<vector<Integer> >& getCongruences() const;
227
mpz_class getExternalIndex() const;
228
const Matrix<Integer>& getEmbeddingMatrix() const;
229
const vector<vector<Integer> >& getEmbedding() const;
230
const Matrix<Integer>& getProjectionMatrix() const;
231
const vector<vector<Integer> >& getProjection() const;
232
233
};
234
235
}
236
237
//---------------------------------------------------------------------------
238
#endif
239
//---------------------------------------------------------------------------
240
241