The ChainCon Software (Release 0.03)
awdiagsim.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A simplicial version of the Alexander-Whitney diagonal.
6 ///
7 /////////////////////////////////////////////////////////////////////////////
8 
9 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
10 //
11 // This file is part of my research software package. This is free software:
12 // you can redistribute it and/or modify it under the terms of the GNU
13 // General Public License as published by the Free Software Foundation,
14 // either version 3 of the License, or (at your option) any later version.
15 //
16 // This software is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this software; see the file "license.txt". If not,
23 // please, see <http://www.gnu.org/licenses/>.
24 
25 // Started on March 24, 2009. Last revision: December 2, 2014.
26 
27 
28 #ifndef _CHAINCON_AWDIAGSIM_H_
29 #define _CHAINCON_AWDIAGSIM_H_
30 
31 
32 // include some standard C++ header files
33 #include <istream>
34 #include <ostream>
35 
36 // include selected header files from the CHomP library
37 #include "chomp/system/config.h"
38 
39 // include relevant local header files
40 #include "chaincon/simplex.h"
41 #include "chaincon/combtensor.h"
42 #include "chaincon/tensor.h"
43 
44 
45 // --------------------------------------------------
46 // ------------------ AW diagonal -------------------
47 // --------------------------------------------------
48 
49 /// Computes the Alexander-Whitney diagonal of a simplex.
50 template <class VertexT, class EmptyT>
51 inline void AWdiagonal (const tSimplex<VertexT,EmptyT> &s,
53 {
54  typedef tSimplex<VertexT,EmptyT> SimplexType;
55  int dim = s. dim ();
56  VertexT *left = new VertexT [dim + 1];
57  VertexT *right = new VertexT [dim + 1];
58  for (int n = 0; n <= dim; ++ n)
59  {
60  for (int i = 0; i <= n; ++ i)
61  left [i] = s [i];
62  for (int i = n; i <= dim; ++ i)
63  right [i - n] = s [i];
64  t. add (SimplexType (n, left),
65  SimplexType (dim - n, right));
66  }
67  delete [] right;
68  delete [] left;
69  return;
70 } /* AWdiagonal */
71 
72 /// Computes the sign in the A-W formula for a simplex
73 /// (see the paper for details).
74 inline int AW_kappa (int n, int dim)
75 {
76  // TODO: a more efficient version?
77 // int sum = (dim * (dim + 1)) / 2 - n;
78 /* int sum = 0;
79  for (int i = 0; i < n; ++ i)
80  {
81  sum += i;
82  }
83  for (int i = n + 1; i <= dim; ++ i)
84  {
85  sum += i;
86  }
87 */
88 // return (sum & 1) ? -1 : 1;
89  return 1;
90 } /* AW_kappa */
91 
92 /// Computes the Alexander-Whitney diagonal of a simplex.
93 template <class VertexT, class EmptyT, class CoefT>
94 inline void AWdiagonal (const tSimplex<VertexT,EmptyT> &s,
96  tSimplex<VertexT,EmptyT>,CoefT> &t)
97 {
98  typedef tSimplex<VertexT,EmptyT> SimplexType;
99  int dim = s. dim ();
100  VertexT *left = new VertexT [dim + 1];
101  VertexT *right = new VertexT [dim + 1];
102  for (int n = 0; n <= dim; ++ n)
103  {
104  for (int i = 0; i <= n; ++ i)
105  left [i] = s [i];
106  for (int i = n; i <= dim; ++ i)
107  right [i - n] = s [i];
108  CoefT coef (1);
109  if (AW_kappa (n, dim) == -1)
110  coef. negate ();
111  t. add (SimplexType (n, left),
112  SimplexType (dim - n, right), coef);
113  }
114  delete [] right;
115  delete [] left;
116  return;
117 } /* AWdiagonal */
118 
119 
120 #endif // _CHAINCON_AWDIAGSIM_H_
121 
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 tSimplex< VertexT, EmptyT > &s, tCombTensor< tSimplex< VertexT, EmptyT >, tSimplex< VertexT, EmptyT > > &t)
Computes the Alexander-Whitney diagonal of a simplex.
Definition: awdiagsim.h:51
int AW_kappa(int n, int dim)
Computes the sign in the A-W formula for a simplex (see the paper for details).
Definition: awdiagsim.h:74