The ChainCon Software (Release 0.03)
ssqcomp.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A generic procedure for the computation of the Steenrod squares
6 /// for an algebraic topological model.
7 /// This is a complete procedure good for simplicial, cubical,
8 /// or other complexes.
9 ///
10 /////////////////////////////////////////////////////////////////////////////
11 
12 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
13 //
14 // This file is part of my research software package. This is free software:
15 // you can redistribute it and/or modify it under the terms of the GNU
16 // General Public License as published by the Free Software Foundation,
17 // either version 3 of the License, or (at your option) any later version.
18 //
19 // This software is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this software; see the file "license.txt". If not,
26 // please, see <http://www.gnu.org/licenses/>.
27 
28 // Started on July 4, 2013. Last revision: January 23, 2016.
29 
30 
31 #ifndef _SSQCOMP_H_
32 #define _SSQCOMP_H_
33 
34 
35 // include some standard C++ header files
36 #include <istream>
37 #include <ostream>
38 #include <string>
39 
40 // include the string hashing definitions (before including "hashsets.h")
41 #include "chaincon/stringhash.h"
42 
43 // include selected header files from the CHomP library
44 #include "chomp/system/config.h"
45 #include "chomp/system/textfile.h"
46 #include "chomp/system/timeused.h"
47 #include "chomp/system/arg.h"
48 #include "chomp/struct/hashsets.h"
49 
50 // include relevant local header files
51 #include "chaincon/chain.h"
52 #include "chaincon/linmap.h"
53 //#include "chaincon/cellnames.h"
54 #include "chaincon/homcohom.h"
55 #include "chaincon/pair.h"
56 #include "chaincon/cring.h"
57 
58 
59 // --------------------------------------------------
60 // ------------ compute Steenrod squares ------------
61 // --------------------------------------------------
62 
63 /// Computes the Steenrod squares, given an AT model of a cell complex.
64 template <class SimCellT, class CoefT, class CellArray1, class CellArray2,
65  class CellArray3, class CoefArray, class CellNames>
66 inline void computeSteenrodSquares (const CellArray1 &H,
67  const CellArray2 &A, const CellArray3 &B, const CoefArray &Q,
70  CellNames &cohomCellNames, int ssquareVersion, bool verify)
71 {
72  using chomp::homology::timeused;
73  using chomp::homology::sout;
74  using chomp::homology::sbug;
75  using chomp::homology::hashedset;
76  using chomp::homology::multitable;
77 
78  // determine cohomology generators
79  sout << "Determining cohomology generators "
80  "from the algebraic topological model...\n";
81  std::vector<std::vector<SimCellT> > cohomRepresentants;
82  std::vector<int> cohomBettiNumbers;
83  std::vector<std::vector<CoefT> > cohomTorsion;
84  getHomCohom (H, A, B, Q, &cohomRepresentants, &cohomBettiNumbers,
85  &cohomTorsion, true);
86 
87  // prepare correct cell names (in case it was not done before)
88  sout << "Setting up names of the representants...\n";
89  int cohomReprSize = cohomRepresentants. size ();
90  for (int dim = 0; dim < cohomReprSize; ++ dim)
91  {
92  int size = cohomRepresentants [dim]. size ();
93  for (int i = 0; i < size; ++ i)
94  cohomCellNames (cohomRepresentants [dim] [i]);
95  }
96 
97  // ==========================================
98 
99 #if CUBES_NOT_SIMPLICES && !DIRECT_CUBICAL_FORMULA
100 #else
101  sout << "\nComputing the cup products...\n";
102 
103  // prepare a time measurement object
104  timeused cupCompTime;
105  cupCompTime = 0;
106 
107  // prepare a data structure for the cup products
108  typedef tPair<SimCellT,SimCellT> CellPair;
109  hashedset<CellPair> cellPairs;
110  multitable<tChain<SimCellT,CoefT> > cupProducts;
111 
112  // compute all the cup products
113  cring (cohomRepresentants, pi, incl, cellPairs, cupProducts);
114 
115  // show the computed nonzero cup products
116  // in the ascending order by the dimension of the "big" cells
117  bool cupNonzeroFound = false;
118  int_t cupSize = cellPairs. size ();
119  for (int_t n = 0; n < cupSize; ++ n)
120  {
121  if (cupProducts [n]. empty ())
122  continue;
123  if (!cupNonzeroFound)
124  {
125  sout << "The computed nonzero cup products are:\n";
126  cupNonzeroFound = true;
127  }
128  sout << cohomCellNames (cellPairs [n]. left) << " u " <<
129  cohomCellNames (cellPairs [n]. right) << " = " <<
130  cells2names (cupProducts [n], cohomCellNames) << ".\n";
131  }
132  if (!cupNonzeroFound)
133  sout << "All the computed cup products are trivial.\n";
134 
135  // show information on the total computation time
136  sout << "The cup products were computed in " << cupCompTime << ".\n";
137 #endif
138 
139  // ==========================================
140 
141  sout << "\nComputing the Steenrod squares...\n";
142 
143  // prepare a time measurement object
144  timeused compTime;
145  compTime = 0;
146 
147  // prepare an array for the results
148  typedef tPair<SimCellT,int> CellSquareT;
149  hashedset<CellSquareT> cellsSquares;
150  multitable<tChain<SimCellT,CoefT> > squareValues;
151 
152  // for each of the cohomology generators,
153  // compute all of its Steenrod squares
154  switch (ssquareVersion)
155  {
156  case 1:
157  ssquares1 (cohomRepresentants, pi, incl,
158  cellsSquares, squareValues);
159  break;
160  case 2:
161  ssquares2 (cohomRepresentants, pi, incl,
162  cellsSquares, squareValues);
163  break;
164  default:
165  throw "Invalid algorithm version "
166  "for Steenrod squares requested.";
167  }
168 
169  // show the computed nonzero Steenrod squares
170  bool nonzeroFound = false;
171  int_t size = cellsSquares. size ();
172  for (int_t n = 0; n < size; ++ n)
173  {
174  if (squareValues [n]. empty ())
175  continue;
176  if (!nonzeroFound)
177  {
178  sout << "The nonzero Steenrod squares are:\n";
179  nonzeroFound = true;
180  }
181  sout << "Sq^" << cellsSquares [n]. right << " (" <<
182  cohomCellNames (cellsSquares [n]. left) << ") = " <<
183  cells2names (squareValues [n], cohomCellNames) <<
184  ".\n";
185  }
186  if (!nonzeroFound)
187  sout << "All the computed Steenrod squares are trivial.\n";
188 
189  // show information on the total computation time
190  sout << "The Steenrod squares were computed in " << compTime <<
191  ".\n";
192 
193  return;
194 } /* computeSteenrodSquares */
195 
196 
197 #endif // _SSQCOMP_H_
198 
A pair of elements of two (possibly different) types.
Definition: pair.h:48
void cring(const std::vector< std::vector< CellT > > &cohomRepresentants, const tLinMap< CellT, CellT, CoefT > &pi, const tLinMap< CellT, CellT, CoefT > &incl, chomp::homology::hashedset< tPair< CellT, CellT > > &cellPairs, chomp::homology::multitable< tChain< CellT, CoefT > > &cupProducts)
Computes the cohomology ring, given a minimal model and cohomology representants. ...
Definition: cring.h:59
A linear map for coefficients in an arbitrary commutative ring.
A linear map.
Definition: linmap.h:55
void ssquares1(const std::vector< std::vector< CubCellT > > &cohomRepresentants, const tLinMap< CubCellT, CubCellT, CoefT > &pi, const tLinMap< CubCellT, CubCellT, CoefT > &incl, chomp::homology::hashedset< tPair< CubCellT, int > > &cellsSquares, chomp::homology::multitable< tChain< CubCellT, CoefT > > &squareValues)
Computes the Steenrod squares using the only procedure in this case.
Definition: ssquarescub.h:398
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...
Definition: homcohom.h:57
Computation of the cohomology ring.
Hashing keys for std::string.
NamesT::NameType cells2names(const CellT &in, NamesT &names)
Returns the name of a cell according to the given naming object.
Definition: cellnames.h:343
A chain with coefficients in an arbitrary commutative ring.
void computeSteenrodSquares(const CellArray1 &H, const CellArray2 &A, const CellArray3 &B, const CoefArray &Q, const tLinMap< SimCellT, SimCellT, CoefT > &pi, const tLinMap< SimCellT, SimCellT, CoefT > &incl, CellNames &cohomCellNames, int ssquareVersion, bool verify)
Computes the Steenrod squares, given an AT model of a cell complex.
Definition: ssqcomp.h:66
A pair of elements.
void ssquares2(const std::vector< std::vector< CubCellT > > &cohomRepresentants, const tLinMap< CubCellT, CubCellT, CoefT > &pi, const tLinMap< CubCellT, CubCellT, CoefT > &incl, chomp::homology::hashedset< tPair< CubCellT, int > > &cellsSquares, chomp::homology::multitable< tChain< CubCellT, CoefT > > &squareValues)
Computes the Steenrod squares using the only procedure in this case.
Definition: ssquarescub.h:411
Computation of the (co)homology groups of an algebraic minimal model.