The ChainCon Software (Release 0.03)
ez_shi.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// The Shih operator as a component
6 /// of the Eilenberg-Zilber chain contraction.
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: December 4, 2014.
27 
28 
29 #ifndef _CHAINCON_EZ_SHI_H_
30 #define _CHAINCON_EZ_SHI_H_
31 
32 
33 // include some standard C++ header files
34 #include <istream>
35 #include <ostream>
36 
37 // include selected header files from the CHomP library
38 #include "chomp/system/config.h"
39 //#include "chomp/system/textfile.h"
40 
41 // include relevant local header files
42 #include "chaincon/combtensor.h"
43 #include "chaincon/tensor.h"
44 #include "chaincon/prodcell.h"
45 #include "chaincon/shuffles.h"
46 
47 
48 // --------------------------------------------------
49 // ------------------ SHI operator ------------------
50 // --------------------------------------------------
51 
52 /// Computes the Shih operator on a product of two simplicial cells.
53 /// Combinatorial version (coefficients in Z_2).
54 template <class SimCellT, class ProdCellT>
55 inline void EZ_SHI (const SimCellT &s1, const SimCellT &s2,
57 {
58  int m (s1. dim ());
59  if (m != s2. dim ())
60  throw "Different dimensions of cells for the SHI operator.";
61 
62  for (int q = 0; q < m; ++ q)
63  {
64  for (int p = 0; p < m - q; ++ p)
65  {
66  Shuffles sh (p + 1, q);
67  std::vector<int> alpha (p + 1);
68  std::vector<int> beta (q);
69  int sig (0);
70  while (1)
71  {
72  int mBar (m - p - q);
73 
74  // get the next shuffle
75  bool moreAvailable =
76  sh. get (alpha, beta, sig);
77 
78  // compute the appropriate cells
79  SimCellT cell1 (s1);
80  for (int i = 0; i < q; ++ i)
81  {
82  SimCellT cell1new (cell1, m - i);
83  cell1. swap (cell1new);
84  }
85  {
86  SimCellT cell1new (cell1,
87  -1 - (mBar - 1));
88  cell1. swap (cell1new);
89  }
90  for (int i = 0; i < q; ++ i)
91  {
92  SimCellT cell1new (cell1,
93  -1 - (beta [i] + mBar));
94  cell1. swap (cell1new);
95  }
96  SimCellT cell2 (s2);
97  for (int i = 0; i < p; ++ i)
98  {
99  SimCellT cell2new (cell2,
100  m - q - i - 1);
101  cell2. swap (cell2new);
102  }
103  for (int i = 0; i <= p; ++ i)
104  {
105  SimCellT cell2new (cell2,
106  -1 - (alpha [i] + mBar));
107  cell2. swap (cell2new);
108  }
109 
110  // add the product to the result
111  ProdCellT prod (cell1, cell2);
112  if (!prod. degenerate ())
113  t. add (prod);
114 
115  // finish if no more shuffles are available
116  if (!moreAvailable)
117  break;
118  }
119  }
120  }
121 
122  return;
123 } /* EZ_SHI */
124 
125 /// Computes the Shih operator on a product of two simplicial cells.
126 template <class SimCellT, class ProdCellT, class CoefT>
127 inline void EZ_SHI (const SimCellT &s1, const SimCellT &s2,
129 {
130 // using chomp::homology::sbug;
131 
132  int m (s1. dim ());
133  if (m != s2. dim ())
134  throw "Different dimensions of cells for the SHI operator.";
135 
136  for (int q = 0; q < m; ++ q)
137  {
138  for (int p = 0; p < m - q; ++ p)
139  {
140  Shuffles sh (p + 1, q);
141  std::vector<int> alpha (p + 1);
142  std::vector<int> beta (q);
143  int sig (0);
144  while (1)
145  {
146  int mBar (m - p - q);
147 
148  // get the next shuffle
149  bool moreAvailable =
150  sh. get (alpha, beta, sig);
151 
152  // compute the appropriate cells
153  SimCellT cell1 (s1);
154  for (int i = 0; i < q; ++ i)
155  {
156  SimCellT cell1new (cell1, m - i);
157  cell1. swap (cell1new);
158  }
159  {
160  SimCellT cell1new (cell1,
161  -1 - (mBar - 1));
162  cell1. swap (cell1new);
163  }
164  for (int i = 0; i < q; ++ i)
165  {
166  SimCellT cell1new (cell1,
167  -1 - (beta [i] + mBar));
168  cell1. swap (cell1new);
169  }
170  SimCellT cell2 (s2);
171  for (int i = 0; i < p; ++ i)
172  {
173  SimCellT cell2new (cell2,
174  m - q - i - 1);
175  cell2. swap (cell2new);
176  }
177  for (int i = 0; i <= p; ++ i)
178  {
179  SimCellT cell2new (cell2,
180  -1 - (alpha [i] + mBar));
181  cell2. swap (cell2new);
182  }
183 
184  // determine the correct coefficient
185  CoefT coef (1);
186  if ((mBar + sig) & 1)
187  coef. negate ();
188 
189  // add the product to the result
190  ProdCellT prod (cell1, cell2);
191  if (!prod. degenerate ())
192  t. add (prod, coef);
193  // sbug << "DEBUG EZ_SHI: p = " << p <<
194  // ", q = " << q << ": " <<
195  // coef << " * " <<
196  // cell1 << " X " << cell2 << "\n";
197 
198  // finish if no more shuffles are available
199  if (!moreAvailable)
200  break;
201  }
202  }
203  }
204 
205  return;
206 } /* EZ_SHI */
207 
208 // --------------------------------------------------
209 
210 /// Computes the Shih operator on a product of two simplicial cells.
211 /// Combinatorial version (coefficients in Z_2).
212 template <class ProdCellT>
213 inline void EZ_SHI (const ProdCellT &s, tCombChain<ProdCellT> &t)
214 {
215  EZ_SHI (s. getLeft (), s. getRight (), t);
216 
217  return;
218 } /* EZ_SHI */
219 
220 /// Computes the Shih operator on a product of two simplicial cells.
221 template <class ProdCellT, class CoefT>
222 inline void EZ_SHI (const ProdCellT &s, tChain<ProdCellT,CoefT> &t)
223 {
224  EZ_SHI (s. getLeft (), s. getRight (), t);
225 
226  return;
227 } /* EZ_SHI */
228 
229 // --------------------------------------------------
230 
231 /// Computes the Shih operator on a chain of products of simplicial cells.
232 /// Combinatorial version (coefficients in Z_2).
233 template <class ProdCellT>
234 inline void EZ_SHI (const tCombChain<ProdCellT> &s,
236 {
237  for (int_t n = 0; n < s. size (); ++ n)
238  {
239  tCombChain<ProdCellT> result;
240  EZ_SHI (s. getCell (n), result);
241  t += result;
242  }
243 
244  return;
245 } /* EZ_SHI */
246 
247 /// Computes the Shih operator on a chain of products of simplicial cells.
248 template <class ProdCellT, class CoefT>
249 inline void EZ_SHI (const tChain<ProdCellT,CoefT> &s,
251 {
252  for (int_t n = 0; n < s. size (); ++ n)
253  {
255  EZ_SHI (s. getCell (n), result);
256  result *= s. getCoef (n);
257  t += result;
258  }
259 
260  return;
261 } /* EZ_SHI */
262 
263 
264 #endif // _CHAINCON_EZ_SHI_H_
265 
An iterator of shuffles.
An iterator of all the (p,q)-shuffles.
Definition: shuffles.h:51
A Cartesian product of simplicial cells of arbitrary type.
A chain with coefficients in an arbitrary ring.
Definition: chain.h:50
A tensor of chains with coefficients in an arbitrary commutative ring.
void EZ_SHI(const SimCellT &s1, const SimCellT &s2, tCombChain< ProdCellT > &t)
Computes the Shih operator on a product of two simplicial cells.
Definition: ez_shi.h:55
A combinatorial chain.
Definition: combchain.h:49
A combinatorial tensor (for coefficients in Z_2).