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