28 #ifndef _CHAINCON_HOMCOHOM_H_ 29 #define _CHAINCON_HOMCOHOM_H_ 41 #include "chomp/system/config.h" 55 template <
class CellT,
class CoefT,
class CellArray1,
class CellArray2,
56 class CellArray3,
class CoefArray>
58 const CellArray3 &B,
const CoefArray &Q,
59 std::vector<std::vector<CellT> > *representants,
60 std::vector<int> *bettiNumbers,
61 std::vector<std::vector<CoefT> > *torsion,
65 int_t Hsize = H. size ();
66 for (int_t i = 0; i < Hsize; ++ i)
69 int dim = H [i]. dim ();
74 while (static_cast<int> ((*representants). size ())
77 std::vector<CellT> empty;
78 (*representants). push_back (empty);
82 (*representants) [dim]. push_back (H [i]);
88 while (static_cast<int> ((*bettiNumbers). size ())
91 (*bettiNumbers). push_back (0);
95 ++ (*bettiNumbers) [dim];
100 int_t Bsize = B. size ();
101 if ((Bsize != static_cast<int_t> (A. size ())) ||
102 (Bsize != static_cast<int_t> (Q. size ())))
104 throw "Mismatched sizes of torsion arrays.";
106 for (int_t i = 0; i < Bsize; ++ i)
109 int dim = cohomology ? A [i]. dim () : B [i]. dim ();
114 while (static_cast<int> ((*representants). size ())
117 std::vector<CellT> empty;
118 (*representants). push_back (empty);
122 (*representants) [dim]. push_back
123 (cohomology ? A [i] : B [i]);
129 while (static_cast<int> ((*torsion). size ()) <= dim)
131 std::vector<CoefT> empty;
132 (*torsion). push_back (empty);
136 (*torsion) [dim]. push_back (Q [i]);
147 template <
class CoefT>
149 const std::vector<CoefT> &torsion,
bool torsion_subscript)
152 if (!bettiNumber && !torsion. size ())
153 return std::string (
"0");
156 std::ostringstream s;
157 std::string ring (CoefT::ringsymbol ());
160 if (bettiNumber == 1)
162 else if (bettiNumber > 1)
163 s << ring <<
"^" << bettiNumber;
166 if (torsion. size ())
168 int size = torsion. size ();
169 for (
int i = 0; i < size; ++ i)
171 if (bettiNumber || i)
173 if (torsion_subscript)
174 s << ring <<
"_" << torsion [i];
176 s << ring <<
"/" << torsion [i] << ring;
187 template <
class CoefT>
189 const std::vector<std::vector<CoefT> > &torsion,
190 const std::string &symbol,
bool torsion_subscript)
192 std::ostringstream s;
193 int maxCounter = std::max (bettiNumbers. size (), torsion. size ());
194 std::vector<CoefT> empty;
195 for (
int dim = 0; dim < maxCounter; ++ dim)
197 int bettiNumber ((static_cast<int> (bettiNumbers. size ())
198 <= dim) ? 0 : bettiNumbers [dim]);
199 const std::vector<CoefT> &tor
200 ((static_cast<int> (torsion. size ()) <= dim) ?
201 empty : torsion [dim]);
203 (bettiNumber, tor, torsion_subscript) <<
"\n";
209 #endif // _CHAINCON_HOMCOHOM_H_ std::string homcohom2text(int bettiNumber, const std::vector< CoefT > &torsion, bool torsion_subscript)
Returns a text description of one (co)homology group.
void getHomCohom(const CellArray1 &H, const CellArray2 &A, const CellArray3 &B, const CoefArray &Q, std::vector< std::vector< CellT > > *representants, std::vector< int > *bettiNumbers, std::vector< std::vector< CoefT > > *torsion, bool cohomology)
Computes Betti numbers and torsion coefficients for (co)homology from an algebraic minimal model (set...