The Original CHomP Software
algstruct.h
Go to the documentation of this file.
1
3
14
15// This file copyright (C) 1997-2016 by Pawel Pilarczyk.
16//
17// This file is part of the "chomp" program. It is free software;
18// you can redistribute it and/or modify it under the terms of the GNU
19// General Public License as published by the Free Software Foundation,
20// either version 3 of the License, or (at your option) any later version.
21//
22// This software is distributed in the hope that it will be useful,
23// but WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25// GNU General Public License for more details.
26//
27// You should have received a copy of the GNU General Public License
28// along with this software; see the file "license.txt". If not,
29// please, see <https://www.gnu.org/licenses/>.
30
31// Started in March 2006. Last revision: April 19, 2006.
32
33
34#ifndef _CAPD_HOMENGIN_ALGSTRUCT_H_
35#define _CAPD_HOMENGIN_ALGSTRUCT_H_
36
37#include "chomp/system/config.h"
40#include "chomp/system/arg.h"
42
43#include "capd/auxil/CRef.h"
44#include "capd/homologicalAlgebra/HomologySignature.h"
45
46#include <cstdlib>
47#include <ctime>
48#include <new>
49#include <exception>
50#include <iostream>
51#include <fstream>
52#include <iomanip>
53#include <vector>
54#include <sstream>
55
56
57namespace chomp {
58namespace homengin {
59
60// --------------------------------------------------
61// -------------- ALGEBRAIC STRUCTURE ---------------
62// --------------------------------------------------
63
66template<class euclidom>
68{
69public:
71 algstruct ();
72
74 ~algstruct ();
75
78 int countLevels () const;
79
81 void setBetti (int level, int number);
82
84 void addBetti (int level, int howmuch);
85
87 int getBetti (int level) const;
88
90 void addTorsion (int level, euclidom coef);
91
93 const euclidom &getTorsion (int level, int n) const;
94
96 int countTorsion (int level) const;
97
99 std::ostream &describe (std::ostream &out) const;
100
102 std::ostream &showBetti (std::ostream &out) const;
103
104private:
106 std::vector<int> betti;
107
109 std::vector<std::vector<euclidom> > torsion;
110}; /* class algstruct */
111
112// --------------------------------------------------
113
114template <class euclidom>
116{
117 return;
118} /* algstruct::algstruct */
119
120template <class euclidom>
122{
123 return;
124} /* algstruct::~algstruct */
125
126// --------------------------------------------------
127
128template <class euclidom>
130{
131 int nBetti = betti. size ();
132 int nTorsion = torsion. size ();
133 return (nBetti > nTorsion) ? nBetti : nTorsion;
134} /* algstruct::countLevels */
135
136template <class euclidom>
137inline void algstruct<euclidom>::setBetti (int level, int number)
138{
139 if (level < 0)
140 return;
141 if (number <= 0)
142 return;
143 for (int nBetti = betti. size (); nBetti < level; ++ nBetti)
144 betti. push_back (0);
145 if (static_cast<unsigned> (level) < betti. size ())
146 betti [level] = number;
147 else
148 betti. push_back (number);
149 return;
150} /* algstruct::setBetti */
151
152template <class euclidom>
153inline void algstruct<euclidom>::addBetti (int level, int howmuch)
154{
155 if (level < 0)
156 return;
157 if (static_cast<unsigned> (level) < betti. size ())
158 betti [level] += howmuch;
159 else
160 setBetti (level, howmuch);
161 return;
162} /* algstruct::addBetti */
163
164template <class euclidom>
165inline int algstruct<euclidom>::getBetti (int level) const
166{
167 if (level < 0)
168 return 0;
169 if (static_cast<unsigned> (level) < betti. size ())
170 return betti [level];
171 else
172 return 0;
173} /* algstruct::getBetti */
174
175template <class euclidom>
176inline void algstruct<euclidom>::addTorsion (int level, euclidom coef)
177{
178 if (level < 0)
179 return;
180 std::vector<euclidom> empty;
181 for (int nTorsion = torsion. size (); nTorsion <= level; ++ nTorsion)
182 torsion. push_back (empty);
183 torsion [level]. push_back (coef);
184 return;
185} /* algstruct::addTorsion */
186
187template <class euclidom>
188inline const euclidom &algstruct<euclidom>::getTorsion (int level, int n)
189 const
190{
191 static euclidom e;
192
193 if ((level < 0) || (n < 0))
194 return e;
195 if ((static_cast<unsigned> (level) < torsion. size ()) &&
196 (static_cast<unsigned> (n) < torsion [level]. size ()))
197 return torsion [level] [n];
198 else
199 return e;
200} /* algstruct::getTorsion */
201
202template <class euclidom>
203inline int algstruct<euclidom>::countTorsion (int level) const
204{
205 if (level < 0)
206 return 0;
207 if (static_cast<unsigned> (level) < torsion. size ())
208 return torsion [level]. size ();
209 return 0;
210} /* algstruct::countTorsion */
211
212
213// --------------------------------------------------
214
215template <class euclidom>
216inline const char *ringsymbol ()
217{
218 return euclidom::ringsymbol ();
219} /* ringsymbol */
220
221template <>
222inline const char *ringsymbol<int> ()
223{
224 return "Z";
225} /* ringsymbol */
226
227template <class euclidom>
228std::ostream &algstruct<euclidom>::describe (std::ostream &out) const
229{
230 int nBetti = betti. size ();
231 int nTorsion = torsion. size ();
232 for (int i = 0; (i < nBetti) || (i < nTorsion); ++ i)
233 {
234 if (i)
235 out << ", ";
236 else
237 out << '(';
238 bool zero = true;
239 if ((i < nBetti) && (betti [i] > 0))
240 {
241 zero = false;
242 out << ringsymbol<euclidom> ();
243 if (betti [i] > 1)
244 out << '^' << betti [i];
245 if ((i < nTorsion) && (torsion [i]. size ()))
246 out << " + ";
247 }
248 if (i < nTorsion)
249 {
250 std::vector<euclidom> tor = torsion [i];
251 for (unsigned j = 0; j < tor. size (); ++ j)
252 {
253 zero = false;
254 if (j)
255 out << " + ";
256 out << ringsymbol<euclidom> () <<
257 '_' << tor [j];
258 }
259 }
260 if (zero)
261 out << 0;
262 }
263 if (nBetti || nTorsion)
264 out << ')';
265 else
266 out << '0';
267 return out;
268} /* algstruct::describe */
269
270template <class euclidom>
271std::ostream &algstruct<euclidom>::showBetti (std::ostream &out) const
272{
273 bool first = true;
274 for (std::vector<int>::const_iterator it = betti. begin ();
275 it != betti. end (); ++ it)
276 {
277 if (first)
278 first = false;
279 else
280 out << ' ';
281 out << *it;
282 }
283 return out;
284} /* algstruct::showBetti */
285
287template <class euclidom>
288inline std::ostream &operator << (std::ostream &out,
289 const algstruct<euclidom> &s)
290{
291 return s. describe (out);
292} /* operator << */
293
295template <class euclidom>
296void hom2struct (const chomp::homology::chain<euclidom> *hom, int maxlevel,
298{
299 for (int q = 0; q <= maxlevel; ++ q)
300 {
301 const chomp::homology::chain<euclidom> &c = hom [q];
302 for (int i = 0; i < c. size (); ++ i)
303 {
304 const euclidom &e = c. coef (i);
305 if (e. delta () == 1)
306 h. addBetti (q, 1);
307 else
308 h. addTorsion (q, e);
309 }
310 }
311 return;
312} /* hom2struct */
313
314template <class euclidom>
315void sign2struct (const CRef<HomologySignature<int> > &homSignCR,
317{
318 int dim = (*homSignCR). topDim ();
319 for (int i = 0; i <= dim; ++ i)
320 {
321 h. setBetti (i, (*homSignCR). bettiNumber (i));
322 FGAGrpSignature<int> &s = (*homSignCR) [i];
323 for (int j = 0; j < s. numberOfTorsionCoefs (); ++ j)
324 {
325 euclidom e;
326 e = s. torsionCoef (j);
327 h. addTorsion (i, e);
328 }
329 }
330 return;
331} /* sign2struct */
332
333
334} // namespace homengin
335} // namespace chomp
336
337#endif // _CAPD_HOMENGIN_ALGSTRUCT_H_
338
340
This file contains the definition of a class which can be used to parse the command line of a program...
An algebraic structure that represents a finitely generated Abelian group with gradation.
Definition: algstruct.h:68
int countLevels() const
Returns the number of levels of gradation stored in the structure.
Definition: algstruct.h:129
void setBetti(int level, int number)
Sets a specific Betti number.
Definition: algstruct.h:137
int getBetti(int level) const
Returns a specific Betti number.
Definition: algstruct.h:165
std::ostream & showBetti(std::ostream &out) const
Shows the Betti numbers as a space-sperated sequence.
Definition: algstruct.h:271
std::vector< int > betti
The Betti numbers.
Definition: algstruct.h:106
std::ostream & describe(std::ostream &out) const
Describes the homology group in a human-readable way.
Definition: algstruct.h:228
void addBetti(int level, int howmuch)
Increases a specific Betti number.
Definition: algstruct.h:153
std::vector< std::vector< euclidom > > torsion
The torsion coefficients.
Definition: algstruct.h:109
~algstruct()
The destructor.
Definition: algstruct.h:121
int countTorsion(int level) const
Says how many torsion coefficients exist at the given level.
Definition: algstruct.h:203
void addTorsion(int level, euclidom coef)
Adds a torsion coefficient.
Definition: algstruct.h:176
algstruct()
The default constructor.
Definition: algstruct.h:115
const euclidom & getTorsion(int level, int n) const
Returns a torsion coefficient.
Definition: algstruct.h:188
This class defines objects which represent chains as finite sequences of elements identified by integ...
Definition: chains.h:94
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
This file contains various small procedures that might be useful in programs which compute homology.
void sign2struct(const CRef< HomologySignature< int > > &homSignCR, algstruct< euclidom > &h)
Definition: algstruct.h:315
const char * ringsymbol< int >()
Definition: algstruct.h:222
const char * ringsymbol()
Definition: algstruct.h:216
std::ostream & operator<<(std::ostream &out, const algstruct< euclidom > &s)
Outputs the structure to the output stream in a human-readable form.
Definition: algstruct.h:288
void hom2struct(const chomp::homology::chain< euclidom > *hom, int maxlevel, algstruct< euclidom > &h)
Translates the PP's homology representation to the algebraic structure.
Definition: algstruct.h:296
This namespace contains the entire CHomP library interface.
Definition: bitmaps.h:51
This file contains some useful functions related to the text input/output procedures.
This file defines a simple data structure which can be used to measure time used by the program (or s...