The ChainCon Software (Release 0.03)
cubsimprod.cpp
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// An experimental program for the computation of certain invariants
6 /// of cubical sets represented by means of simplicial product sets.
7 ///
8 /////////////////////////////////////////////////////////////////////////////
9 
10 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
11 //
12 // This file is part of my research software package. This is free software:
13 // you can redistribute it and/or modify it under the terms of the GNU
14 // General Public License as published by the Free Software Foundation,
15 // either version 3 of the License, or (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this software; see the file "license.txt". If not,
24 // please, see <http://www.gnu.org/licenses/>.
25 
26 // Started on March 24, 2009. Last revision: June 10, 2015.
27 
28 
29 // include the string hashing definitions (before including "hashsets.h")
30 #include "chaincon/stringhash.h"
31 
32 // include selected header files from the CHomP library
33 #include "chomp/system/config.h"
34 #include "chomp/system/textfile.h"
35 #include "chomp/system/timeused.h"
36 #include "chomp/system/arg.h"
37 #include "chomp/struct/hashsets.h"
38 
39 // include relevant local header files
40 #include "chaincon/linmap.h"
41 #include "chaincon/ringzp.h"
42 #include "chaincon/cellnames.h"
43 #include "chaincon/simplex.h"
44 #include "chaincon/cubcell.h"
45 #include "chaincon/emptycell.h"
46 #include "chaincon/wrapping.h"
47 #include "chaincon/prodcell.h"
48 #include "chaincon/cubproduct.h"
49 #include "chaincon/setfilter.h"
50 //#define SPACE_WRAPPING
51 #include "chaincon/awdiagsimgen.h"
52 #include "chaincon/ez_aw.h"
53 #include "chaincon/ez_eml.h"
54 #include "chaincon/ez_shi.h"
55 #include "ammodcomp.h"
56 #include "cringcomp.h"
57 
58 
59 // --------------------------------------------------
60 // -------------------- OVERTURE --------------------
61 // --------------------------------------------------
62 
63 /// The title of the program and licensing information.
64 const char *title = "\
65 * * * UNDER CONSTRUCTION * * *\n\
66 Certain experimental computations of cubical sets by means of their\n\
67 simplicial subdivision.\n\
68 Version 0.00 (June 10, 2015). Copyright (C) 1997-2016 by Pawel Pilarczyk.\n\
69 This is free software. No warranty. Consult 'license.txt' for details.";
70 
71 /// Brief help information on the program's usage.
72 const char *helpinfo = "\
73 This program does some experimental computations on cubical sets\n\
74 using their representation by means of the Cartesian product\n\
75 of the simplicial sets that correspond to the faces of the cubes.\n\
76 The ring of coefficients for cohomology computation can be either set to Z\n\
77 or to Z_p (the integers modulo prime number p).\n\
78 Call with:\n\
79 filename - the name of a file that contains a list of cubical cells,\n\
80 Switches and additional arguments:\n\
81 -pN - selection of the coefficients: p=0 for Z, p>1 for Z_p (default: 0);\n\
82 \tnote: one should use p <= 181,\n\
83 -dpi, -dincl, -dphi - display the computed maps: pi, incl, phi,\n\
84 -dd - display the boundary map in the minimal model (the nontrivial part),\n\
85 --verify - do additional verification of the computed maps,\n\
86 --log filename - save the output to a file (without progress indicators),\n\
87 --quiet - suppress data output to the screen (whcih can be still logged),\n\
88 --help - display this brief help information only and exit.\n\
89 For more information please consult the accompanying documentation\n\
90 or ask the program's author at http://www.PawelPilarczyk.com/.";
91 
92 
93 // --------------------------------------------------
94 // ---------------------- main ----------------------
95 // --------------------------------------------------
96 
97 /// The main procedure of the program.
98 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
99 int main (int argc, char *argv [])
100 {
101  using namespace chomp::homology;
102 
103  // prepare the types for coordinates, cubes, and simplices
104  typedef short int CoordT;
106  CubCellT;
108 
109  // turn on a message that will appear if the program does not finish
110  program_time = "Aborted after";
111 
112  // prepare user-configurable data
113  char *Xname = 0;
114  char *Aname = 0;
115  int p = 0;
116  bool reduced = false;
117  bool displayPi = false;
118  bool displayIncl = false;
119  bool displayPhi = false;
120  bool displayD = false;
121  bool verify = false;
122 #ifdef SPACE_WRAPPING
123  const int maxWrapping = 100;
124  char *wrapping [maxWrapping];
125  int nWrapping = 0;
126 #endif
127 
128  // analyze the command line
129  arguments a;
130  arg (a, NULL, Xname);
131  arg (a, NULL, Aname);
132  arg (a, "p", p);
133 #ifdef SPACE_WRAPPING
134  arg (a, "w", wrapping, nWrapping, maxWrapping);
135 #endif
136  argswitch (a, "r", reduced, true);
137  argswitch (a, "dpi", displayPi, true);
138  argswitch (a, "dincl", displayIncl, true);
139  argswitch (a, "dphi", displayPhi, true);
140  argswitch (a, "dd", displayD, true);
141  argswitch (a, "-verify", verify, true);
142  arghelp (a);
143 
144  argstreamprepare (a);
145  int argresult = a. analyze (argc, argv);
146  argstreamset ();
147 
148  // show the program's title
149  if (argresult >= 0)
150  sout << title << '\n';
151 
152  // if something was incorrect, show an additional message and exit
153  if (argresult < 0)
154  {
155  sout << "Call with '--help' for help.\n";
156  return 2;
157  }
158 
159  // if help requested or no filename present, show help information
160  if ((argresult > 0) || !Xname || (p < 0))
161  {
162  sout << helpinfo << '\n';
163  return 1;
164  }
165 
166  // try running the main function and catch an error message if thrown
167  try
168  {
169  if (Aname)
170  throw "Relative chains not supported yet.";
171 
172  // set the existence of the empty cell if desired
173  if (reduced)
174  {
175  throw "Reduced homology not supported yet.";
176  // CubCellT::EmptyType::setExistence (true);
177  }
178 
179 #ifdef SPACE_WRAPPING
180  if (nWrapping)
181  throw "Space wrapping not supported yet.";
182 
183  // set wrapping as desired
184  for (int i = 0; i < nWrapping; ++ i)
185  {
186  setWrapping<typename CubCellT::WrapType>
187  (std::string (wrapping [i]));
188  }
189 #endif
190 
191  // prepare the ring of coefficients
192  typedef tZp<short> CoefT;
193  CoefT::setp (p);
194  p = CoefT::getp ();
195 
196  // read the cubical set
197  sout << "Reading cubical cells from '" << Xname << "'...\n";
198  hashedset<CubCellT> Xcubes;
199  std::ifstream in (Xname);
200  if (!in)
201  fileerror (Xname);
202  in >> Xcubes;
203  in. close ();
204  if (Xcubes. empty ())
205  throw "No cubical cells read from the input file.";
206  sout << Xcubes. size () << " cubical cells read.\n";
207 
208  // transform the cubes into products of simplices
209  sout << "Transforming the cubical cells into products "
210  "of simplices...\n";
211  tSimplSet<CellT> Xsimpl;
212  for (int_t i = 0; i < Xcubes. size (); ++ i)
213  cube2product (Xcubes [i], Xsimpl);
214  sout << Xsimpl. size () << " products created.\n";
215  // sbug << "DEBUG: Xsimpl:\n" << Xsimpl;
216 
217  // add faces of all the cells in the product
218  // sout << "Adding faces of cells in the product...\n";
219  // int_t nAddedFaces = Xsimpl. addFaces ();
220  // sout << nAddedFaces << " faces added.\n";
221 
222  // normalize the constructed simplicial set
223  sout << "Normalizing the constructed simplicial set...\n";
224  int_t nDegenerate = Xsimpl. normalize ();
225  sout << nDegenerate << " degenerate cells removed.\n";
226  // sbug << "DEBUG: Xsimpl:\n" << Xsimpl;
227 
228  // transform the simplicial set to a filtered complex
229  sout << "Transforming the simplicial set "
230  "into a filtered complex...\n";
232  set2filter (Xsimpl, K, Xsimpl. dim ());
233  // sbug << "DEBUG: K:\n" << K;
234 
235  // prepare the data for storing the result of computations
236  chomp::homology::hashedset<CellT> H, A, B;
237  std::vector<CoefT> Q;
238 
239  // compute the homology groups and generators
240  sout << "Carrying out computations in the ring " <<
241  CoefT::ringsymbol () << ".\n";
242  tLinMap<CellT,CellT,CoefT> pi, incl, phi;
243  tCellNames<CellT> dummyCellNames;
244  tCellNames<CellT> cellNames;
245  // cellNames. setPrefix ("g");
246 
247  sout << "=== Computing the minimal model ===\n";
248  computeAlgMinModel (K, false, H, A, B, Q, pi, incl, phi,
249  dummyCellNames, cellNames,
250  displayPi, displayIncl, displayPhi, displayD,
251  verify);
252 
253  sout << "=== Computing the cohomology ring ===\n";
254  computeCohomRing (H, A, B, Q, pi, incl, cellNames, verify);
255 
256  program_time = "Total time used:";
257  program_time = 1;
258  return 0;
259  }
260  catch (const char *msg)
261  {
262  sout << "ERROR: " << msg << '\n';
263  return -1;
264  }
265  catch (const std::exception &e)
266  {
267  sout << "ERROR: " << e. what () << '\n';
268  return -1;
269  }
270  catch (...)
271  {
272  sout << "ABORT: An unknown error occurred.\n";
273  return -1;
274  }
275 } /* main */
276 
void computeCohomRing(const CellArray1 &H, const CellArray2 &A, const CellArray3 &B, const CoefArray &Q, const tLinMap< CellT, CellT, CoefT > &pi, const tLinMap< CellT, CellT, CoefT > &incl, CellNames &cellNames, bool verify)
Computes the cohomology ring, given a minimal model of a cell complex, and shows the result...
Definition: cringcomp.h:63
Elements of the ring Z_p.
A function that creates a filter from a set of cells of different dimensions.
A generic procedure for the computation of the cohomology ring structure for an algebraic minimal mod...
A generic procedure for the computation of an algebraic minimal model of a filtered cell complex stor...
A function that converts a cubical cell into a simplicial set that corresponds to the cartesian produ...
A linear map for coefficients in an arbitrary commutative ring.
The Shih operator as a component of the Eilenberg-Zilber chain contraction.
A Cartesian product of simplicial cells of arbitrary type.
void cube2product(const CubCellT &q, SetT &cells)
Transforms an elementary cube into a simplicial set that represents the Cartesian product of the simp...
Definition: cubproduct.h:57
A class whose instances can be used to generate names of cells with subsequent numbers, in each dimension separately.
Definition: cellnames.h:61
Tools for coordinate wrapping, a.k.a.
const char * helpinfo
Brief help information on the program&#39;s usage.
Definition: cubsimprod.cpp:72
void set2filter(const SetT &set, FilterT &filter, int maxDim)
Transforms a collection of cells to a filter by adding them in the order of decreasing dimension...
Definition: setfilter.h:49
A linear map.
Definition: linmap.h:55
A cubical cell.
A filtered complex.
Definition: filtcomplex.h:53
A class for naming cells for nice text data output.
int main(int argc, char *argv [])
The main procedure of the program.
Definition: cubsimprod.cpp:99
Hashing keys for std::string.
A simplex class with arbitrary vertices.
The Alexander-Whitney operator as a component of the Eilenberg-Zilber chain contraction.
The decision on whether the empty cell should be used as a valid cell of dimension -1...
void computeAlgMinModel(const tFilteredComplex< CellT > &K, bool relativeComplex, CellArray1 &H, CellArray2 &A, CellArray3 &B, CoefArray &Q, tLinMap< CellT, CellT, CoefT > &pi, tLinMap< CellT, CellT, CoefT > &incl, tLinMap< CellT, CellT, CoefT > &phi, CellNames &homCellNames, CellNames &cohomCellNames, bool displayPi, bool displayIncl, bool displayPhi, bool displayD, bool verify)
Computes the homology of a cellular complex.
Definition: ammodcomp.h:68
A Cartesian product of simplicial cells as a simplicial cell.
Definition: prodcell.h:48
An empty cell existence decision class with settable global flag.
Definition: emptycell.h:70
An element of the ring Z_p, where p is globally set.
Definition: ringzp.h:179
A simplicial set.
Definition: simplset.h:51
A version of the Alexander-Whitney diagonal for general simplicial sets.
const char * title
The title of the program and licensing information.
Definition: cubsimprod.cpp:64
The Eilenberg-Mac Lane operator as a component of the Eilenberg-Zilber chain contraction.
An elementary cubical cell with vertex coordinates of integer type.
Definition: cubcell.h:63