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