The ChainCon Software (Release 0.03)
awdiag1cub.cpp
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A program for the computation of the Alexander-Whitney diagonal
6 /// for a single cubical cell.
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: April 11, 2013.
27 
28 
29 // include some standard C++ header files
30 #include <istream>
31 #include <ostream>
32 
33 // include selected header files from the CHomP library
34 #include "chomp/system/config.h"
35 #include "chomp/system/textfile.h"
36 #include "chomp/system/timeused.h"
37 #include "chomp/system/arg.h"
38 #include "chomp/struct/hashsets.h"
39 
40 // include relevant local header files
41 #include "chaincon/cubcell.h"
42 #include "chaincon/wrapping.h"
43 #include "chaincon/emptycell.h"
44 #include "chaincon/ringzp.h"
45 #include "chaincon/awdiagcub.h"
46 #include "chaincon/combtensor.h"
47 #include "chaincon/tensor.h"
48 
49 
50 // --------------------------------------------------
51 // -------------------- OVERTURE --------------------
52 // --------------------------------------------------
53 
54 /// The title of the program and licensing information.
55 const char *title = "\
56 Alexander-Whitney diagonal for a single cubical cell.\n\
57 Version 0.01 (April 11, 2013). Copyright (C) 1997-2016 by Pawel Pilarczyk.\n\
58 This is free software. No warranty. Consult 'license.txt' for details.";
59 
60 /// Brief help information on the program's usage.
61 const char *helpinfo = "\
62 This program computes the Alexander-Whitney diagonal for a single cube.\n\
63 Call with:\n\
64 -d N - choose the dimension of the cube.\n\
65 Switches and additional arguments:\n\
66 -pN - selection of the coefficients: p=0 for Z, p>1 for Z_p (default: 0);\n\
67 \tnote: one should use p <= 181.\n\
68 --log filename - save the output to a file (without progress indicators),\n\
69 --quiet - suppress data output to the screen (whcih can be still logged),\n\
70 --help - display this brief help information only and exit.\n\
71 For more information please consult the accompanying documentation\n\
72 or ask the program's author at http://www.PawelPilarczyk.com/.";
73 
74 
75 // --------------------------------------------------
76 // ---------------------- main ----------------------
77 // --------------------------------------------------
78 
79 /// The main procedure of the program.
80 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
81 int main (int argc, char *argv [])
82 {
83  using namespace chomp::homology;
84 
85  // turn on a message that will appear if the program does not finish
86  program_time = 0; //"Aborted after";
87 
88  // prepare user-configurable data
89  int dim = 0;
90  int p = 0;
91 
92  // analyze the command line
93  arguments a;
94  arg (a, "d", dim);
95  arg (a, "p", p);
96  arghelp (a);
97 
98  argstreamprepare (a);
99  int argresult = a. analyze (argc, argv);
100  argstreamset ();
101 
102  // show the program's title
103  if (argresult >= 0)
104  sout << title << '\n';
105 
106  // if something was incorrect, show an additional message and exit
107  if (argresult < 0)
108  {
109  sout << "Call with '--help' for help.\n";
110  return 2;
111  }
112 
113  // if help requested, show help information
114  if ((argresult > 0) || (dim <= 0))
115  {
116  sout << helpinfo << '\n';
117  return 1;
118  }
119 
120  // try running the main function and catch an error message if thrown
121  try
122  {
123  // prepare the ring of coefficients
124  typedef tZp<short> CoefT;
125  CoefT::setp (p);
126  p = CoefT::getp ();
127 
128  // prepare a single cubical cell
130  int *coord = new int [dim];
131  for (int i = 0; i < dim; ++ i)
132  coord [i] = 0;
133  CellT Q (dim, coord);
134  delete [] coord;
135 
136  // compute and show the combinatorial AW diagonal
137  tCombTensor<CellT,CellT> combDiag;
138  AWdiagonal (Q, combDiag);
139  sout << "Combinatorial Alexander-Whitney diagonal of " <<
140  Q << ":\n" << combDiag << "\n";
141 
142  // compute and show the general AW diagonal
144  AWdiagonal (Q, diag);
145  sout << "Alexander-Whitney diagonal over " <<
146  CoefT::ringsymbol () << " of " <<
147  Q << ":\n" << diag << "\n";
148 
149  // program_time = "Total time used:";
150  // program_time = 1;
151  return 0;
152  }
153  catch (const char *msg)
154  {
155  sout << "ERROR: " << msg << '\n';
156  return -1;
157  }
158  catch (const std::exception &e)
159  {
160  sout << "ERROR: " << e. what () << '\n';
161  return -1;
162  }
163  catch (...)
164  {
165  sout << "ABORT: An unknown error occurred.\n";
166  return -1;
167  }
168 } /* main */
169 
Elements of the ring Z_p.
A cubical version of the Alexander-Whitney diagonal.
int main(int argc, char *argv [])
The main procedure of the program.
Definition: awdiag1cub.cpp:81
A tensor of chains with coefficients in an arbitrary commutative ring.
Tools for coordinate wrapping, a.k.a.
A cubical cell.
Tensor of chains.
Definition: tensor.h:52
Combinatorial tensor of cells.
Definition: combtensor.h:53
A combinatorial tensor (for coefficients in Z_2).
void AWdiagonal(const tCombChain< CellT > &ch, tCombTensor< CellT, CellT > &t)
Computes the Alexander-Whitney diagonal of a chain, using the procedure defined for individual cells...
Definition: awdiag.h:51
The decision on whether the empty cell should be used as a valid cell of dimension -1...
const char * helpinfo
Brief help information on the program&#39;s usage.
Definition: awdiag1cub.cpp:61
An element of the ring Z_p, where p is globally set.
Definition: ringzp.h:179
An elementary cubical cell with vertex coordinates of integer type.
Definition: cubcell.h:63
const char * title
The title of the program and licensing information.
Definition: awdiag1cub.cpp:55
An empty cell existence decision class with the flag set to false.
Definition: emptycell.h:54