58#ifndef _CHOMP_HOMOLOGY_HOMOLOGY_H_
59#define _CHOMP_HOMOLOGY_HOMOLOGY_H_
103template <
class eucl
idom>
107 for (
int i = 0; i < c. size (); ++ i)
109 if (c. coef (i). delta () == 1)
119template <
class eucl
idom>
124 while (start < c. size ())
126 if (c. coef (start). delta () != 1)
136template <
class eucl
idom>
140 bool writeplus =
false;
143 for (
int i = 0; i < c. size (); ++ i)
146 if (c. coef (i). delta () == 1)
151 sout << (writeplus ?
" + " :
"") <<
158 if (countfree && ((i == c. size () - 1) ||
159 (c. coef (i + 1). delta () != 1)))
161 sout << (writeplus ?
" + " :
"") <<
164 sout <<
"^" << countfree;
179template <
class eucl
idom>
185 for (
int q = 0; q <= maxlevel; ++ q)
187 sout <<
"H_" << q <<
" = ";
196template <
class eucl
idom>
199 hmap. show (
sout,
"\tf",
"x",
"y");
207template <
class eucl
idom>
217template <
class eucl
idom>
220 for (
int i = 0; i < count; ++ i)
222 sout <<
'g' << (i + 1) <<
" = ";
232template <
class eucl
idom>
236 for (
int q = 0; q <= maxlevel; ++ q)
238 if (!hom [q]. size ())
240 sout <<
"[H_" << q <<
"]\n";
250template <
class eucl
idom>
254 for (
int q = 0; q <= maxlevel; ++ q)
256 if (!hom [q]. size ())
258 sout <<
"[H_" << q <<
"]\n";
259 for (
int i = 0; i < hom [q]. size (); ++ i)
271template <
class cell,
class eucl
idom>
276 for (
int i = 0; i < c. size (); ++ i)
278 euclidom e = c. coef (i);
280 sout << (i ?
" + " :
"") << s [c. num (i)];
282 sout << (i ?
" - " :
"-") << s [c. num (i)];
285 sout << (i ?
" + " :
"") << e <<
" * " <<
295template <
class cell,
class eucl
idom>
299 for (
int i = 0; i < count; ++ i)
301 sout <<
'g' << (i + 1) <<
" = ";
310template <
class eucl
idom,
class cell>
315 for (
int q = 0; q <= maxlevel; ++ q)
317 if (!hom [q]. size ())
319 sout <<
"[H_" << q <<
"]\n";
338template <
class eucl
idom>
352 for (
int q = 0; q <= maxlevel; ++ q)
355 gen [q] = (hom [q]. size ()) ?
359 for (
int i = 0; i < hom [q]. size (); ++ i)
362 cx. gethomgen (q, hom [q]. num (i));
378template <
class eucl
idom>
388 int Xdim = cx. dim ();
393 sout <<
"Computing the homology of " << Xname <<
" over " <<
394 euclidom::ringname () <<
"...\n";
395 cx. simple_form ((
int *) 0,
false);
396 cx. simple_homology (hom);
400 while ((maxlevel >= 0) && (hom [maxlevel]. size () <= 0))
404 if (hom && (maxlevel < 0))
424template <
class cell,
class eucl
idom>
434 int Xdim = Xcompl. dim ();
441 sout <<
"Creating the chain complex of " << Xname <<
"... ";
453 int maxlevel =
Homology (cx, Xname, hom);
468template <
class eucl
idom,
class cubetype>
479 typedef typename cubetype::CellType celltype;
485 if (Xcubes. empty ())
489 int Xspacedim = Xcubes [0]. dim ();
495 cubsettype emptycubes;
496 reducepair (Xcubes, emptycubes, emptycubes, Xname, 0);
508 if (Xcompl -> empty ())
515 int Xdim = Xcompl -> dim ();
516 if (Xdim != Xspacedim)
518 sout <<
"Note: The dimension of " << Xname <<
519 " decreased from " << Xspacedim <<
520 " to " << Xdim <<
".\n";
524 int maxlevel =
Homology (*Xcompl, Xname, hom, gen);
543template <
class cell,
class eucl
idom>
555 int Xdim = Xcompl. dim ();
561 if (!Acompl. empty ())
562 pairname <<
'(' << Xname <<
"," << Aname <<
')';
568 collapse (Xcompl, Acompl, Xname, Aname);
575 if (Xdim != Xcompl. dim ())
577 sout <<
"Note: The dimension of " << Xname <<
578 " decreased from " << Xdim <<
" to " <<
579 Xcompl. dim () <<
".\n";
583 int maxlevel =
Homology (Xcompl, pairname, hom, gen);
598template <
class eucl
idom,
class cubetype>
611 typedef typename cubetype::CellType celltype;
617 if (Acubes. empty ())
618 return Homology (Xcubes, Xname, hom, gen, gcompl);
624 if (Xcubes. empty ())
631 int Xspacedim = Xcubes [0]. dim ();
641 if (Xcubes. empty ())
648 cubsettype emptycubes;
649 reducepair (Xcubes, Acubes, emptycubes, Xname, Aname);
652 if (Xcubes. empty ())
657 diffname << Xname <<
'\\' << Aname;
671 int maxlevel =
Homology (*Xcompl, Xname, Acompl, Aname, hom, gen);
705template <
class eucl
idom>
722 hx. take_homology (hom_cx);
723 hy. take_homology (hom_cy);
726 hmap -> take_homology (cmap, hom_cx, hom_cy);
733template <
class eucl
idom>
748 hx. take_homology (hom_cx);
751 hmap -> take_homology (cmap, hom_cx, hom_cx);
767template <
class eucl
idom,
class cubetype>
776 bool inclusion =
false,
int careful = 0x01,
786 typedef typename cubetype::CellType celltype;
792 bool verify = careful & 0x01;
793 bool checkacyclic = careful & 0x02;
797 if (!Acubes. empty ())
798 XAname << Xname <<
'\\' << Aname;
801 if (!Bcubes. empty ())
802 YBname << Yname <<
'\\' << Bname;
809 if (&Xcubes == &Ycubes)
810 throw "You must clone the sets passed to Homology.";
822 if (Xcubes. empty () || Ycubes. empty ())
826 int_t origAsize = Acubes. size ();
827 int_t origXsize = Xcubes. size ();
830 int Xspacedim = Xcubes [0]. dim ();
831 int Yspacedim = Ycubes [0]. dim ();
839 if (verify && !Acubes. empty ())
843 if (verify && !Acubes. empty ())
863 reducepair (Xcubes, Acubes, empty, Xname, Aname);
866 if (Xcubes. empty ())
871 if (!Acubes. empty () && !gfgen && !gygen)
873 expandAinX (Xcubes, Acubes, Ycubes, Bcubes, Fcubmap,
874 Xname, Aname, Bname,
inclusion, checkacyclic);
884 cubsettype emptycubes;
885 reducepair (Xcubes, Acubes, Fcubmap, emptycubes,
889 if (Xcubes. empty ())
894 if (!checkacyclic && !Acubes. empty ())
901 reducepair (Xcubes, Acubes, empty, Xname, Aname);
907 if (!checkacyclic && ((origAsize != Acubes. size ()) ||
908 (origXsize != Xcubes. size ())))
910 sout <<
"*** Important note: " << Xname <<
" or " <<
911 Aname <<
" changed. You must make sure\n"
912 "*** that the restriction of " << Fname <<
913 " to the new sets is acyclic.\n";
917 sout <<
"*** Note: The program assumes "
918 "that the input map is acyclic.\n";
924 cubsettype Ykeepcubes;
925 sout <<
"Computing the image of the map... ";
926 for (
int_t i = 0; i < Xcubes. size (); ++ i)
927 Ykeepcubes. add (Fcubmap (Xcubes [i]));
928 for (
int_t i = 0; i < Acubes. size (); ++ i)
929 Ykeepcubes. add (Fcubmap (Acubes [i]));
932 sout <<
"and of the inclusion... ";
933 Ykeepcubes. add (Xcubes);
934 Ykeepcubes. add (Acubes);
936 sout << Ykeepcubes. size () <<
" cubes.\n";
939 if (Xspacedim == Yspacedim)
945 reducepair (Ycubes, Bcubes, Ykeepcubes, Yname, Bname);
949 if (!Ykeepcubes. empty ())
975 int Xdim = Xcompl. dim ();
976 int Ydim = Ycompl -> dim ();
983 collapse (Xcompl, Acompl, emptycompl, Xname, Aname,
987 if (Xcompl. empty ())
991 if (Xdim != Xcompl. dim ())
993 sout <<
"Note: The dimension of " << Xname <<
" decreased "
994 "from " << Xdim <<
" to " << Xcompl. dim () <<
".\n";
996 Xdim = Xcompl. dim ();
1003 sout <<
"Creating the map " << Fname <<
" on cells in " <<
1007 sout << countimages <<
" cubes added.\n";
1011 if (!Acompl. empty ())
1013 sout <<
"Creating the map " << Fname <<
" on cells in " <<
1016 sout << count <<
" cubes added.\n";
1022 cubsettype emptycubes;
1023 Acubes = emptycubes;
1024 Xcubes = emptycubes;
1025 cubmaptype emptymap;
1030 sout <<
"Creating a cell map for " << Fname <<
"... ";
1037 sout <<
"*** SERIOUS PROBLEM: The map is not "
1038 "acyclic. THE RESULT WILL BE WRONG.\n"
1039 "*** You must verify the acyclicity of the "
1040 "initial map with 'chkmvmap'\n"
1041 "*** and, if successful, set the "
1042 "'careful reduction' bit.\n";
1046 sout <<
"Note: It has been verified successfully "
1047 "that the map is acyclic.\n";
1050 sout <<
"Creating the graph of " << Fname <<
"... ";
1054 sout << Fcompl -> size () <<
" cells added.\n";
1058 Fcellcubmap = emptycellcubmap;
1059 FcellcubmapA = emptycellcubmap;
1061 Fcellmap = emptycellmap;
1062 Xcompl = emptycompl;
1073 if (!Bcompl. empty ())
1075 sout <<
"Forgetting " << Bcompl. size () <<
" cells from " <<
1083 sout <<
"Computing the image of " << Fname <<
"... ";
1084 project (*Fcompl, Ykeepcompl, *Ycompl, Xspacedim, Yspacedim,
1088 project (*Fcompl, Ykeepcompl, *Ycompl, 0, Xspacedim,
1089 Yspacedim, 0,
false);
1091 sout << Ykeepcompl. size () <<
" cells.\n";
1093 sout <<
"Collapsing " << Yname <<
" to img of " << Xname <<
"... ";
1094 int_t countremoved = Ycompl ->
collapse (emptycompl, Ykeepcompl,
1096 sout << 2 * countremoved <<
" cells removed, " <<
1097 Ycompl -> size () <<
" left.\n";
1100 if (!Ykeepcompl. empty ())
1107 if (Ydim != Ycompl -> dim ())
1109 sout <<
"Note: The dimension of " << Yname <<
" decreased "
1110 "from " << Ydim <<
" to " << Ycompl -> dim () <<
1113 Ydim = Ycompl -> dim ();
1120 sout <<
"Creating the chain complex of the graph of " << Fname <<
1127 sout <<
"Creating the chain complex of " << Yname <<
"... ";
1133 sout <<
"Creating the chain map of the projection... ";
1142 sout <<
"Creating the chain map of the inclusion... ";
1150 (*gfcompl) = Fcompl;
1156 (*gycompl) = Ycompl;
1164 gFname <<
"the graph of " << Fname;
1167 maxlevel_cx =
Homology (cgraph, gFname, hom_cx);
1174 maxlevel_cy =
Homology (cy, Yname, hom_cy);
1191 sout <<
"The map induced in homology is as follows:\n";
1192 hgraph. take_homology (hom_cx);
1193 hy. take_homology (hom_cy);
1194 hmap -> take_homology (cmap, hom_cx, hom_cy);
1195 hmap -> show (
sout,
"\tf",
"x",
"y");
1198 bool invertible =
true;
1201 sout <<
"The map induced in homology by the inclusion:\n";
1202 hincl. take_homology (imap, hom_cx, hom_cy);
1203 hincl. show (
sout,
"\ti",
"x",
"y");
1211 sout <<
"Oh, my goodness! This map is apparently "
1212 "not invertible.\n";
1218 sout <<
"The inverse of the map "
1219 "induced by the inclusion:\n";
1220 hincl. show (
sout,
"\tI",
"y",
"x");
1224 hincl1. take_homology (imap, hom_cx, hom_cy);
1226 hident. compose (hincl1, hincl);
1227 sbug <<
"The composition of the inclusion and "
1228 "its inverse (should be the identity):\n";
1229 hident. show (
sbug,
"\tid",
"y",
"y");
1230 for (
int i = 0; i <= hident. dim (); ++ i)
1233 if (m. getnrows () != m. getncols ())
1234 throw "INV: Inequal rows and cols.";
1238 for (
int c = 0; c < m. getncols (); ++ c)
1240 for (
int r = 0; r < m. getnrows ();
1243 if ((r == c) && (m. get
1248 if (m. get (r, c) == zero)
1250 throw "INV: Non-identity.";
1256 sout <<
"The composition of F and the inverse "
1257 "of the map induced by the inclusion:\n";
1259 hcomp -> compose (*hmap, hincl);
1261 hcomp -> show (
sout,
"\tF",
"y",
"y");
1279 throw "Unable to invert the inclusion map.";
1281 return ((maxlevel_cx < maxlevel_cy) ? maxlevel_cx : maxlevel_cy);
1285template <
class eucl
idom,
class cubetype>
1292 bool inclusion =
false,
int careful = 0x01,
1298 return Homology (Fcubmap,
"F", Xcubes,
"X", Acubes,
"A",
1299 Ycubes,
"Y", Bcubes,
"B", hom_cx, maxlevel_cx,
1300 hom_cy, maxlevel_cy, hom_f,
inclusion, careful,
1301 gfgen, gfcompl, gygen, gycompl);
1307template <
class eucl
idom,
class cubetype>
1321 int result =
Homology (Fcubmap, Fname, Xcubes, Xname, Acubes, Aname,
1322 Ycubes, Xname, Bcubes, Aname, hom, maxlevel,
1323 hom_cy, maxlevel_cy, hom_f,
true, careful,
1324 gfgen, gfcompl, gygen, gycompl);
1330template <
class eucl
idom,
class cubetype>
1340 return Homology (Fcubmap,
"F", Xcubes,
"X", Acubes,
"A", hom,
1341 maxlevel, hom_f, careful, gfgen, gfcompl, gygen, gycompl);
1352template <
class eucl
idom,
class cubetype>
1366 typedef typename cube2ltype::CellType cell2ltype;
1372 bool verify = careful & 0x01;
1373 bool checkacyclic = careful & 0x02;
1374 bool keepacyclic = careful & 0x04;
1383 if (Xcubes0. empty ())
1385 sout <<
"X is a subset of A. The homology of (X,A) "
1386 "is trivial and the map is 0.";
1393 sout <<
"Defining the two-layer structure... ";
1394 cube2ltype::setlayers (Xcubes0, Acubes0);
1398 for (
int_t i = 0; i < Xcubes0. size (); ++ i)
1399 Xcubes. add (cube2ltype (Xcubes0 [i], 1));
1401 for (
int_t i = 0; i < Acubes0. size (); ++ i)
1402 Acubes. add (cube2ltype (Acubes0 [i], 0));
1405 sout << cube2ltype::layer1 (). size () <<
"+" <<
1406 cube2ltype::layer0 (). size () <<
" cubes, " <<
1407 cell2ltype::identify (). size () <<
" cells.\n";
1412 sout <<
"Creating the sets Y and B... ";
1415 for (
int_t i = 0; i < Xcubes0. size (); ++ i)
1418 for (
int_t j = 0; j < img. size (); ++ j)
1420 if (!Xcubes0. check (img [j]))
1421 Bcubes. add (cube2ltype (img [j], 0));
1424 for (
int_t i = 0; i < Acubes0. size (); ++ i)
1427 for (
int_t j = 0; j < img. size (); ++ j)
1428 Bcubes. add (cube2ltype (img [j], 0));
1430 sout << Ycubes. size () <<
" cubes in Y\\B, " <<
1431 Bcubes. size () <<
" in B.\n";
1435 for (
int_t i = 0; i < Xcubes0. size (); ++ i)
1440 throw "Empty image of a box in X.\n";
1441 for (
int_t j = 0; j < img. size (); ++ j)
1443 int layer = Xcubes0. check (img [j]) ? 1 : 0;
1444 Fcubmap [Xcubes [i]]. add
1445 (cube2ltype (img [j], layer));
1448 for (
int_t i = 0; i < Acubes0. size (); ++ i)
1453 throw "Empty image of a box in A.\n";
1454 for (
int_t j = 0; j < img. size (); ++ j)
1455 Fcubmap [Acubes [i]]. add
1456 (cube2ltype (img [j], 0));
1471 int_t origAsize = Acubes. size ();
1472 int_t origXsize = Xcubes. size ();
1475 int Xspacedim = Xcubes. empty () ? -1 : Xcubes [0]. dim ();
1476 int Yspacedim = Ycubes. empty () ? -1 : Ycubes [0]. dim ();
1488 if (!Acubes. empty () && !checkacyclic)
1491 reducepair (Xcubes, Acubes, Xkeepcubes,
"X",
"A");
1494 if (Xcubes. empty ())
1496 sout <<
"There are no cubes left "
1497 "in X\\A. The homology of (X,A) "
1498 "is trivial and the map is 0.";
1504 bool inclFABchecked =
false;
1505 bool inclFXYchecked =
false;
1514 Xcubes, Ycubes, Bcubes,
1515 Acubes. empty () ?
"X" :
"X\\A",
"Y");
1516 inclFXYchecked =
true;
1519 if (verify && !Acubes. empty ())
1525 inclFABchecked =
true;
1528 else if (!Acubes. empty ())
1534 Xcubes, Ycubes, Bcubes,
1535 Acubes. empty () ?
"X" :
"X\\A",
"Y");
1536 inclFXYchecked =
true;
1541 if (!Acubes. empty ())
1544 expandAinX (Xcubes, Acubes, Ycubes, Bcubes, Fcubmap,
1545 "X",
"A",
"B",
true , checkacyclic);
1561 Xkeepcubes,
"X",
"A");
1565 if (Xcubes. empty ())
1567 sout <<
"There are no cubes left "
1568 "in X\\A. The homology of (X,A) "
1569 "is trivial and the map is 0.";
1575 if (!checkacyclic && !Acubes. empty ())
1581 reducepair (Xcubes, Acubes, Xkeepcubes,
"X",
"A");
1587 if (!checkacyclic && ((origAsize != Acubes. size ()) ||
1588 (origXsize != Xcubes. size ())))
1590 sout <<
"*** Important note: X or A changed. "
1591 "You must make sure\n"
1592 "*** that the restriction of F "
1593 "to the new sets is acyclic.\n";
1597 sout <<
"*** Note: The program assumes "
1598 "that the input map is acyclic.\n";
1603 if (verify && !inclFXYchecked)
1606 Acubes. empty () ?
"X" :
"X\\A",
"Y");
1607 inclFXYchecked =
true;
1611 if (verify && !inclFABchecked && !Acubes. empty ())
1615 inclFABchecked =
true;
1621 addmapimg (Fcubmap, Xcubes, Acubes, Ykeepcubes,
1625 if (Xspacedim == Yspacedim)
1629 reducepair (Ycubes, Bcubes, Ykeepcubes,
"Y",
"B");
1637 cubes2cells (Xcubes, Xcompl, Acubes. size () ?
"X\\A" :
"X",
false);
1645 if (Xcompl. empty ())
1647 if (!Acompl. empty ())
1648 sout <<
"The set X is contained in A. "
1649 "The homology of (X,A) is trivial.";
1651 sout <<
"The set X is empty. "
1652 "The homology of X is trivial.";
1659 cubes2cells (Ycubes, *Ycompl, Bcubes. empty () ?
"Y" :
"Y\\B");
1660 if (!Ycubes. empty ())
1669 if (!Bcubes. empty ())
1678 if (!Ykeepcubes. empty ())
1685 int Xdim = Xcompl. dim ();
1686 if ((Xspacedim < 0) && (Xdim >= 0))
1687 Xspacedim = Xcompl [Xdim] [0]. spacedim ();
1688 int Ydim = Ycompl -> dim ();
1689 if ((Yspacedim < 0) && (Ydim >= 0))
1690 Yspacedim = (*Ycompl) [Ydim] [0]. spacedim ();
1699 collapse (Xcompl, Acompl, Xkeepcompl,
"X",
"A",
1703 if (Xcompl. empty ())
1705 sout <<
"Nothing remains in X. "
1706 "The homology of (X,A) is trivial.";
1711 if (!Xkeepcompl. empty ())
1718 if (Xdim != Xcompl. dim ())
1720 sout <<
"Note: The dimension of X decreased from " <<
1721 Xdim <<
" to " << Xcompl. dim () <<
".\n";
1723 Xdim = Xcompl. dim ();
1730 sout <<
"Creating the map F on cells in X... ";
1733 sout << countimages <<
" cubes added.\n";
1736 if (Xcubes. size ())
1744 if (!Acompl. empty ())
1746 sout <<
"Creating the map F on cells in A... ";
1748 sout << count <<
" cubes added.\n";
1752 if (Acubes. size ())
1761 sout <<
"Creating a cell map for F... ";
1768 sout <<
"*** SERIOUS PROBLEM: The map is not "
1769 "acyclic. THE RESULT WILL BE WRONG.\n"
1770 "*** You must verify the acyclicity of the "
1771 "initial map with 'chkmvmap'\n"
1772 "*** and, if successful, run this program "
1773 "with the '-a' switch.\n";
1777 sout <<
"Note: It has been verified successfully "
1778 "that the map is acyclic.\n";
1781 sout <<
"Creating the graph of F... ";
1783 sout << Fcompl -> size () <<
" cells added.\n";
1788 Fcellcubmap = empty;
1789 FcellcubmapA = empty;
1798 if (!Ycompl -> empty ())
1803 if (!Bcompl. empty ())
1805 sout <<
"Forgetting " << Bcompl. size () <<
1814 sout <<
"Computing the image of F... ";
1815 int_t prev = Ykeepcompl. size ();
1816 project (*Fcompl, Ykeepcompl, *Ycompl, Xspacedim, Yspacedim,
1818 project (*Fcompl, Ykeepcompl, *Ycompl, 0, Xspacedim,
1819 Yspacedim, 0,
false);
1820 sout << (Ykeepcompl. size () - prev) <<
" cells added.\n";
1822 sout <<
"Collapsing Y towards F(X)... ";
1826 sout << 2 * count <<
" cells removed, " <<
1827 Ycompl -> size () <<
" left.\n";
1831 if (!Ykeepcompl. empty ())
1838 if (Ydim != Ycompl -> dim ())
1840 sout <<
"Note: The dimension of Y decreased from " <<
1841 Ydim <<
" to " << Ycompl -> dim () <<
".\n";
1843 Ydim = Ycompl -> dim ();
1853 sout <<
"Creating the chain complex of the graph of F... ";
1859 sout <<
"Creating the chain complex of Y... ";
1865 sout <<
"Creating the chain map of the projection... ";
1873 sout <<
"Creating the chain map of the inclusion... ";
1879 (*gfcompl) = Fcompl;
1885 (*gycompl) = Ycompl;
1893 gFname <<
"the graph of " << Fname;
1896 int maxlevel_cx =
Homology (cgraph, gFname, hom_cx);
1904 int maxlevel_cy =
Homology (cy, Xname, hom_cy);
1913 int homdimgraph = maxlevel_cx;
1916 int homdimy = maxlevel_cy;
1930 sout <<
"The map induced in homology is as follows:\n";
1931 hgraph. take_homology (hom_cx);
1932 hy. take_homology (hom_cy);
1933 hmap -> take_homology (cmap, hom_cx, hom_cy);
1934 hmap -> show (
sout,
"\tf",
"x",
"y");
1937 sout <<
"The map induced in homology by the inclusion:\n";
1938 hincl. take_homology (imap, hom_cx, hom_cy);
1939 hincl. show (
sout,
"\ti",
"x",
"y");
1941 sout <<
"The inverse of the map induced by the inclusion:\n";
1942 bool invertible =
true;
1949 sout <<
"Oh, my goodness! This map is apparently "
1950 "not invertible.\n";
1956 hincl. show (
sout,
"\tI",
"y",
"x");
1958 sout <<
"The composition of F and the inverse "
1959 "of the map induced by the inclusion:\n";
1960 hcomp -> compose (hincl, *hmap);
1961 hcomp -> show (
sout,
"\tF",
"x",
"x");
1978 throw "Unable to invert the inclusion map.";
1980 maxlevel = (maxlevel_cx < maxlevel_cy) ? maxlevel_cx : maxlevel_cy;
1985template <
class eucl
idom,
class cubetype>
1996 return Homology2l (Fcubmap,
"F", Xcubes,
"X", Acubes,
"A", hom,
1997 maxlevel, hom_f, careful, gfgen, gfcompl, gygen, gycompl);
2009 int dim = q. dim ();
2012 b. allocate (maxneighbors);
2013 bool result =
acyclic (q, dim, X, &b, maxneighbors);
2027template <
int dim,
int twoPower>
2036 sout <<
"Reducing the binary cube";
2037 int prev = b. count ();
2039 sout << (prev - b. count ()) <<
" cubes removed, " <<
2040 b. count () <<
" left.\n";
2047 bool setwrapping =
false;
2048 for (
int i = 0; i < dim; ++ i)
2052 wrap [i] = 1 << twoPower;
2063 for (
int i = 0; i <= dim; ++ i)
2067 bool first_run =
true;
2068 while (!b. empty ())
2079 s. push (
static_cast<int> (b. begin ()));
2080 while (!s. empty ())
2082 int n = s. front ();
2084 neighbortype cur = b. neighborhood_begin (n);
2085 neighbortype end = b. neighborhood_end (n);
2088 s. push (
static_cast<int> (cur));
2096 if (c. count () == 1)
2102 cubetype cur (c. begin ()), end (c. end ());
2105 X. add (cube_cast<Cube> (cur));
2110 sout <<
"Connected component no. " << *result <<
2111 " (" << X. size () <<
" cubes):\n";
2115 int_t number = X. size () - 1;
2116 A. add (X [number]);
2117 X. removenum (number);
2121 int maxlevel =
Homology (X,
"X", A,
"A", chn);
2127 for (
int i = 1; i <= maxlevel; ++ i)
2135 sout <<
"Computed Betti numbers:";
2136 for (
int i = 0; i <= dim; ++ i)
2137 sout <<
" " << result [i];
2151template <
int dim,
int twoPower,
class coordtype>
2153 const coordtype *space_wrapping = 0)
2163 for (
int i = 0; i < dim; ++ i)
2165 if (!space_wrapping [i])
2167 int w = space_wrapping [i];
2168 if (w != (1 << twoPower))
2169 sout <<
"WARNING: Wrapping [" << i <<
2170 "] set to " << (1 << twoPower) <<
2193template <
class coordtype>
2201 coordtype
const *coordpointer = coord;
2202 for (
int i = 0; i < n; ++ i)
2204 for (
int j = 0; j < dim; ++ j)
2205 c [j] =
static_cast<coordtype
> (*(coordpointer ++));
2206 X. add (
Cube (c, dim));
2210 bool soutput =
sout. show;
2212 bool coutput =
scon. show;
2217 int maxlevel =
Homology (X,
"X", hom);
2220 for (
int j = 0; j <= dim; ++ j)
2221 result [j] = (j <= maxlevel) ?
BettiNumber (hom [j]) : 0;
2226 sout. show = soutput;
2227 scon. show = coutput;
2236template <
class coordtype>
2244 for (
int j = 0; j < dim; ++ j)
2246 ((wrap [j] >= 0) ? wrap [j] : -wrap [j]);
This file contains the definition of a class which can be used to parse the command line of a program...
This file contains the definition of a cubical set represented as a bitmap.
This class defines a bit field that is part of some larger array or that uses an allocated piece of m...
The iterator of the set of cubes within a bitmap.
The neighborhood of a cube.
A binary n-dimensional hypercube for storing cubes as bits.
This class defines objects which represent chains as finite sequences of elements identified by integ...
This is an implementation of a chain complex over an arbitrary ring.
This class defines a chain map between two chain complexes.
The class that defines a geometric complex - a set of cells (cubes, simplices, etc).
This is a template for a set of objects of the given type.
A class for representing sparse matrices containing elements of the 'euclidom' type.
This class represents a multivalued map whose domain is a geometric complex.
This class defines a multivalued map.
A general cubical cell with additional information about the layer number.
A (hyper)cube with additional information about the layer number.
This class defines a hypercube in R^n with edges parallel to the axes and with size 1 in each directi...
static const int MaxDim
The maximal dimension of a cube.
static void setwrapping(const coordtype *c, int mindim=1, int maxdim=MaxBasDim)
Sets space wrapping for all the dimensions in the range starting with 'mindim' and strictly smaller t...
A word, that is, a string with very few properties.
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
int int_t
Index type for indexing arrays, counting cubes, etc.
This file contains the definition of a template of a class whose object can define a local value of a...
const char * ringsymbol()
This namespace contains the core of the homology computation procedures and related classes and templ...
void ShowHomology(const chain< euclidom > &c)
Shows (that is, writes to 'sout') one level of the homology module encoded in the given chain.
int MaxBddDim
The maximal dimension for which binary decision diagrams are used.
bool acyclic(int dim, BitField &b)
Checks whether this cube's nieghbors form an acyclic set.
bool checkimagecontained(const maptype &Fcubmap, const cubsettype &Xcubes, const cubsettype &Ycubes, const cubsettype &Bcubes, const char *Xname, const char *Yname)
Checks if the image of X by F is contained in the union of Y and B.
hashedset< simplex > SetOfSimplices
A class for representing a set of simplices.
chaincomplex< integer > ChainComplex
A class for representing a chain complex with integral coefficients.
chain< euclidom > ** ExtractGenerators(const chaincomplex< euclidom > &cx, chain< euclidom > *hom, int maxlevel)
Extracts homology generators from a chain complex in the simple form.
outputstream sout
A replacement for standard output stream, with optional logging and other features provided by the cl...
int TorsionCoefficient(const chain< euclidom > &c, int start=0)
Returns the next position in the chain containing a torsion coefficient.
void ShowGenerators(const chain< euclidom > *c, int count)
Shows (that is, writes to 'sout') all the generators of one level of the homology module of a chain c...
void wrapcoord(coordtype *destination, const coordtype *source, const coordtype *wrap, int dim)
Wraps coordinates stored in 'c' accordint to the wrap table 'wrap' and store the result in the table ...
int Homology2l(mvmap< cubetype, cubetype > &Fcubmap0, const char *Fname, hashedset< cubetype > &Xcubes0, const char *Xname, hashedset< cubetype > &Acubes0, const char *Aname, chain< euclidom > *&hom_cx, int &maxlevel, chainmap< euclidom > *&hom_f, int careful=0x01, chain< euclidom > ***gfgen=0, gcomplex< tCell2l< typename cubetype::CellType >, euclidom > **gfcompl=0, chain< euclidom > ***gygen=0, gcomplex< tCell2l< typename cubetype::CellType >, euclidom > **gycompl=0)
Computes the endomorphism induced in homology by a combinatorial cubical multivalued map using the tw...
void reducepair(cubsettype &Xcubes, cubsettype &Acubes, const cubsettype &Xkeepcubes, const char *Xname, const char *Aname)
Reduces the pair of sets of cubes. Keeps the given cubes untouched.
bool inclusion(const HSet &X, const HSet &Y)
Verifies if X is a subset of Y. Returns true if yes, false if not.
outputstream sbug
An output stream for writing additional debug messages.
void project(const gcomplex< tCell, euclidom > &c, gcomplex< tCell, euclidom > &img, const gcomplex< tCell, euclidom > &only, int offset, int outdim, int discarddim, const int *level, bool watchforimages)
Creates the image of the projection from the set of cubical cells in the given geometric complex to t...
void cubes2cells(tCubes &Xcubes, gcomplex< tCell, tCoef > &Xcompl, const char *Xname, bool deletecubes=true)
Transforms cubes to full-dimensional cells.
int_t getmaxneighbors(int dim)
Returns the maximal number of neighbors of a cube: 3^dim - 1.
void createprojection(const gcomplex< tCell, euclidom > &Fcompl, const gcomplex< tCell, euclidom > &Ycompl, chainmap< euclidom > &cmap, int offset, int outdim, int discarddim, int *level=NULL)
Creates the chain map of the projection from a cell complex of the graph of a map to a cell complex o...
BitFields knownbits
The global table of BitFields which store the acyclicity information for reducing full cubical sets.
void addboundaries(gcomplex< cell, euclidom > &Xcompl, gcomplex< cell, euclidom > &Acompl, int minlevel, bool bothsets, const char *Xname, const char *Aname)
Adds boundaries to the geometric complex X or to both X and A.
bool checkinclusion(const cubsettype &Xcubes, const cubsettype &Ycubes, const cubsettype &Bcubes, const char *Xname, const char *YBname)
Checks if X is a subset of the union of Y and B.
int_t createimages(mvcellmap< tCell, euclidom, tCube > &m, const mvmap< tCube, tCube > &f1, const mvmap< tCube, tCube > &f2, const hashedset< tCube > &dom1, const hashedset< tCube > &dom2)
Creates images of cells in 'm' as unions of cubes determined by f1 and f2.
void SetSpaceWrapping(int dim, const coordtype *wrap)
Sets space wrapping in each direction separately.
void collapse(gcomplex< cell, euclidom > &Xcompl, gcomplex< cell, euclidom > &Acompl, gcomplex< cell, euclidom > &Xkeepcompl, const char *Xname, const char *Aname, bool addbd=true, bool addcob=false, bool disjoint=true, const int *level=NULL)
Collapses a pair of geometric complexes.
void createcellmap(const mvcellmap< cell, euclidom, element > &m, mvcellmap< cell, euclidom, cell > &cm)
Creates the graph of the map as a cell complex while reducing as possible.
chainmap< euclidom > * HomologyMap(const chainmap< euclidom > &cmap, const chain< euclidom > *hom_cx, const chain< euclidom > *hom_cy, int maxlevel)
Extracts the homomorphism induced in homology from the chain map on two chain complexes whose homolog...
short int coordinate
The default type of coordinates.
chain< integer > Chain
A class for representing a chain with integral coefficients.
void expandAinX(cubsettype &Xcubes, cubsettype &Acubes, const char *Xname, const char *Aname)
Expands the other element of the pair into the main portion of the set.
chainmap< integer > ChainMap
A class for representing a chain map with integral coefficients.
void ShowGenerator(const chain< euclidom > &c)
Shows (that is, writes to 'sout') one generator of the homology module of a chain complex.
bool checkimagedisjoint(const maptype &Fcubmap, const cubsettype &Acubes, const cubsettype &Ycubes, const char *Aname, const char *Yname)
Checks if the image of A by F is disjoint from Y (actually, from Y\B).
int BettiNumber(const chain< euclidom > &c)
Returns the Betti number that corresponds to the given chain which describes one homology group.
void decreasedimension(gcomplex< cell, euclidom > &Acompl, int dim, const char *name)
Decreases the dimension of the geometric complex by adding boundary cells to all the cells on higher ...
outputstream scon
The console output stream to which one should put all the junk that spoils the log file,...
chaincomplex< euclidom > & createchaincomplex(chaincomplex< euclidom > &c, const gcomplex< cell, euclidom > &g, bool quiet=false)
Creates an algebraic chain complex based on the data from the given geometric cell complex.
gcomplex< simplex, integer > SimplicialComplex
A class for representing a simplicial complex.
int reduceFullCubes(FullCubSet &X, bool quiet=false)
Reduces the set of full cubes.
void ComputeBettiNumbers(bincube< dim, twoPower > &b, int *result)
Computes the Betti Numbers of a set of full cubes in a bincube.
int Homology(chaincomplex< euclidom > &cx, const char *Xname, chain< euclidom > *&hom)
Transforms the chain complex into a simple form and compute its homology.
void restrictAtoneighbors(const cubsettype &Xcubes, cubsettype &Acubes, const char *Xname, const char *Aname, const cubsettype *keepcubes=0)
Restricts the set of cubes 'Acubes' to these cubes which are neighbors of any of the cubes in 'Xcubes...
void removeAfromX(cubsettype &Xcubes, const cubsettype &Acubes, const char *Xname, const char *Aname)
Removes 'Acubes' from 'Xcubes' and shows messages.
void addmapimg(const maptype &Fcubmap, const maptype &FcubmapA, const cubsettype &Xcubes, const cubsettype &Acubes, cubsettype &Ykeepcubes, bool indexmap)
Adds the images of both maps to the set of cubes to be kept.
gcomplex< cell, euclidom > & creategraph(const mvmap< cell, cell > &m, gcomplex< cell, euclidom > &graph)
Add a graph of a multivalued cell map to the cell complex.
This namespace contains the entire CHomP library interface.
This file contains some useful functions related to the text input/output procedures.
This file defines a simple data structure which can be used to measure time used by the program (or s...
This file contains the definition of two-layer cubical sets, as introduced in the paper "Excision-pre...
This file contains a definition of the class "word" which is used to store a string and has some addi...