Opened 3 months ago

## #30400 needs_review enhancement

Reported by: Owned by: gh-jcuevas-rozo gh-jcuevas-rozo major sage-9.3 algebraic topology Finite topological spaces jhpalmieri Julián Cuevas-Rozo N/A u/gh-jcuevas-rozo/add_finite_topological_spaces (Commits) 8a123d6cbc464d6cffc8a7202e003dbb640c22f5

This ticket provides a class for finite topological spaces and methods dealing with properties in general topology. It is expected to create a second ticket to add algebraic topology properties (see ticket #30447).

Principal reference: Algebraic topology of finite topological spaces and applications by Jonathan Barmak.

### comment:2 Changed 3 months ago by gh-jcuevas-rozo

• Commit set to f1045dbe82ab5effd639d8489536bff267d5fbf4

I have added the file finite_topological_spaces.py in ~/sage/src/sage/homology. I think this is a correct place to put it because different methods dealing with homotopy types and weak homotopy types will be added in next commits, but the discussion is open and I accept other suggestions in order to put it in the correct place.

New commits:

 ​f1045db FiniteTopologicalSpace class and methods in general topology added

### comment:3 Changed 3 months ago by gh-jcuevas-rozo

• Owner changed from (none) to gh-jcuevas-rozo

### comment:4 Changed 3 months ago by git

• Commit changed from f1045dbe82ab5effd639d8489536bff267d5fbf4 to 1cbdd3f968554b5f3bd7049b728c2cfa3950ca83

Branch pushed to git repo; I updated commit sha1. New commits:

 ​1cbdd3f Documentation added

### comment:5 Changed 3 months ago by gh-jcuevas-rozo

• Description modified (diff)
• Status changed from new to needs_review

### comment:6 Changed 3 months ago by gh-jcuevas-rozo

I have changed the status to needs_review. I have created a ticket #30447 where I will continue to working about the changes made in this ticket #30400, but... how can I import such changes to the new ticket? (how to link #30447 to #30400?)

### comment:7 Changed 3 months ago by jhpalmieri

Add #30400 in the dependency field on #30447. (I've done that.)

### comment:8 Changed 3 months ago by gh-jcuevas-rozo

Thank you so much, I've learned it for next tickets.

### comment:9 Changed 3 months ago by git

• Commit changed from 1cbdd3f968554b5f3bd7049b728c2cfa3950ca83 to e51800dfe3c0a5e36ea32c0073b3e40a61e5ba5c

Branch pushed to git repo; I updated commit sha1. New commits:

 ​e51800d Failures in tests repaired

### comment:10 follow-up: ↓ 13 Changed 3 months ago by jhpalmieri

I'm getting some doctest failures. Also, it would be nice to add this to the reference manual. Here are changes to fix some of these:

• ## src/doc/en/reference/homology/index.rst

diff --git a/src/doc/en/reference/homology/index.rst b/src/doc/en/reference/homology/index.rst
index bf98e0841f..148dc4bae0 100644
 a cell complexes. sage/homology/algebraic_topological_model sage/homology/homology_morphism sage/homology/matrix_utils sage/homology/finite_topological_spaces sage/interfaces/chomp .. include:: ../footer.txt
• ## src/sage/homology/finite_topological_spaces.py

diff --git a/src/sage/homology/finite_topological_spaces.py b/src/sage/homology/finite_topological_spaces.py
index 3a43eabed4..430e2a84ad 100644
 a from sage.combinat.posets.hasse_diagram import HasseDiagram def dict_to_matrix(ordered_eltos, dictionary): r""" Return a matrix from the information given by dictionary. INPUT: - ordered_eltos -- a list. def dict_to_matrix(ordered_eltos, dictionary): - dictionary -- a dict whose key list is ordered_eltos and its values are sets of elements in ordered_eltos. OUTPUT:: OUTPUT: - A binary matrix whose (i,j) entry is equal to 1 if and only if ordered_eltos[i] is in dictionary[ordered_eltos[j]]. def FiniteSpace(data, elements=None, is_T0=False): - elements -- it is ignored when data is of type 1, 2 or 4. When data is a topogenous matrix, this parameter gives the underlying set of the space. EXAMPLES:: EXAMPLES: A dictionary as data:: def FiniteSpace(data, elements=None, is_T0=False): sage: type(T) sage: FiniteSpace({'a': {'a', 'b'}}) Traceback (most recent call last) Traceback (most recent call last): ... ValueError: The data does not correspond to a valid dictionary sage: FiniteSpace({'a': {'a', 'b'}, 'b': {'a', 'b'}, 'c': {'a', 'c'}}) Traceback (most recent call last) Traceback (most recent call last): ... ValueError: The introduced data does not define a topology When data is a tuple or a list, the elements are in range(n) where n is the lenght of data:: n is the length of data:: sage: from sage.homology.finite_topological_spaces import FiniteSpace sage: T = FiniteSpace([{0, 3}, {1, 3}, {2, 3}, {3}]) ; T def FiniteSpace(data, elements=None, is_T0=False): sage: T.elements() [3, 0, 1, 2] sage: FiniteSpace(({0, 2}, {0, 2})) Traceback (most recent call last) Traceback (most recent call last): ... ValueError: This kind of data assume the elements are in range(2) def FiniteSpace(data, elements=None, is_T0=False): sage: M.elements() [5, 'e', 'h', 0, 'c'] sage: FiniteSpace(mat, elements=[5, 'e', 'h', 0, 0]) Traceback (most recent call last) Traceback (most recent call last): ... AssertionError: Not valid list of elements class FiniteTopologicalSpace(Parent): sage: from sage.homology.finite_topological_spaces import FiniteSpace sage: T = FiniteSpace(({0}, {1}, {2, 3}, {3})) sage: T.underlying_set() {0, 1, 2, 3} """ return set(self._elements) class FiniteTopologicalSpace(Parent): sage: T.Ux(4) {3, 4} sage: T.Ux(5) Traceback (most recent call last) Traceback (most recent call last): ... ValueError: The point 5 is not an element of the space """ class FiniteTopologicalSpace(Parent): True sage: T.boundary(T.boundary(Fr)) == T.boundary(Fr) True sage: X == Fr.union(T.interior(E), T.exterior(E))||| sage: X == Fr.union(T.interior(E), T.exterior(E)) True """ X = self.underlying_set()

sage -t --warn-long 80.8 --random-seed=0 src/sage/homology/finite_topological_spaces.py
**********************************************************************
File "src/sage/homology/finite_topological_spaces.py", line 133, in sage.homology.finite_topological_spaces.FiniteSpace
Failed example:
T = FiniteSpace({'a': {'a', 'c'}, 'b': {'b'}, 'c':{'a', 'c'}}) ; T
Expected:
Finite topological space of 3 points with minimal basis
{'a': {'c', 'a'}, 'b': {'b'}, 'c': {'c', 'a'}}
Got:
Finite topological space of 3 points with minimal basis
{'a': {'a', 'c'}, 'b': {'b'}, 'c': {'a', 'c'}}
**********************************************************************
File "src/sage/homology/finite_topological_spaces.py", line 180, in sage.homology.finite_topological_spaces.FiniteSpace
Failed example:
M = FiniteSpace(mat, elements=(5, 'e', 'h', 0, 'c')) ; M
Expected:
Finite topological space of 5 points with minimal basis
{5: {5}, 'e': {'h', 'e'}, 'h': {'h', 'e'}, 0: {0, 'c', 5}, 'c': {0, 'c', 5}}
Got:
Finite topological space of 5 points with minimal basis
{5: {5}, 'e': {'e', 'h'}, 'h': {'e', 'h'}, 0: {0, 'c', 5}, 'c': {0, 'c', 5}}
**********************************************************************
File "src/sage/homology/finite_topological_spaces.py", line 319, in sage.homology.finite_topological_spaces.FiniteTopologicalSpace.__init__
Failed example:
T = FiniteTopologicalSpace(elements, minimal_basis, matrix(mat_dict)) ; T
Expected:
Finite topological space of 4 points with minimal basis
{'a': {3, 'a'}, 3: {3, 'a'}, 2: {1, 2}, 1: {1}}
Got:
Finite topological space of 4 points with minimal basis
{'a': {'a', 3}, 3: {'a', 3}, 2: {1, 2}, 1: {1}}
**********************************************************************
2 of  24 in sage.homology.finite_topological_spaces.FiniteSpace
1 of   7 in sage.homology.finite_topological_spaces.FiniteTopologicalSpace.__init__
[231 tests, 3 failures, 0.13 s]
----------------------------------------------------------------------
sage -t --warn-long 80.8 --random-seed=0 src/sage/homology/finite_topological_spaces.py  # 3 doctests failed
----------------------------------------------------------------------


The issue is that these sets may print in different orders, and I think it's more or less random.

By the way, it's better to say if E is None instead of if E == None.

New commits:

 ​e51800d Failures in tests repaired

### comment:11 Changed 3 months ago by git

• Commit changed from e51800dfe3c0a5e36ea32c0073b3e40a61e5ba5c to 7b777873dae08b042218aad1299c49479926823c

Branch pushed to git repo; I updated commit sha1. New commits:

 ​7b77787 Failure tests repaired

### comment:12 Changed 3 months ago by git

• Commit changed from 7b777873dae08b042218aad1299c49479926823c to 124dc44a4ae468033867502116ab71b4ab0b5e8b

Branch pushed to git repo; I updated commit sha1. New commits:

 ​124dc44 Repairing failures shown in comment 10 from jhpalmieri

### comment:13 in reply to: ↑ 10 Changed 3 months ago by gh-jcuevas-rozo

I'm getting some doctest failures. Also, it would be nice to add this to the reference manual. Here are changes to fix some of these:

Thanks for the suggestions, I have changed the files in order to include the improvements.

The issue is that these sets may print in different orders, and I think it's more or less random.

I see... I think it depends on the implementation of sets in SageMath, do I have to impose an specific order for printing or it is not necessary?

### comment:14 Changed 3 months ago by jhpalmieri

Doctests have to pass, so something has to change. Here are suggestions, but if you can think of meaningful doctests that don't rely on the ordering (one example is the test T._minimal_basis['a'] == ... below), it's better than just marking everything # random.

• ## src/sage/homology/finite_topological_spaces.py

diff --git a/src/sage/homology/finite_topological_spaces.py b/src/sage/homology/finite_topological_spaces.py
index 5c40fe26ce..548322f174 100644
 a def FiniteSpace(data, elements=None, is_T0=False): A dictionary as data:: sage: from sage.homology.finite_topological_spaces import FiniteSpace sage: T = FiniteSpace({'a': {'a', 'c'}, 'b': {'b'}, 'c':{'a', 'c'}}) ; T sage: T = FiniteSpace({'a': {'a', 'c'}, 'b': {'b'}, 'c':{'a', 'c'}}) sage: T # random Finite topological space of 3 points with minimal basis {'a': {'c', 'a'}, 'b': {'b'}, 'c': {'c', 'a'}} sage: T._minimal_basis # random {'a': {'c', 'a'}, 'b': {'b'}, 'c': {'c', 'a'}} sage: T._minimal_basis['a'] == set(['a', 'c']) True sage: type(T) sage: FiniteSpace({'a': {'a', 'b'}}) def FiniteSpace(data, elements=None, is_T0=False): {0: {0}, 1: {1, 2}, 2: {1, 2}, 3: {0, 3, 4}, 4: {0, 3, 4}} sage: T.elements() [0, 1, 2, 3, 4] sage: M = FiniteSpace(mat, elements=(5, 'e', 'h', 0, 'c')) ; M sage: M = FiniteSpace(mat, elements=(5, 'e', 'h', 0, 'c')) sage: M # random Finite topological space of 5 points with minimal basis {5: {5}, 'e': {'h', 'e'}, 'h': {'h', 'e'}, 0: {0, 'c', 5}, 'c': {0, 'c', 5}} sage: M.elements() class FiniteTopologicalSpace(Parent): sage: minimal_basis = {'a': {3, 'a'}, 3: {3, 'a'}, 2: {2, 1}, 1: {1}} sage: mat_dict = {(0, 0): 1, (0, 1): 1, (1, 1): 1, (2, 2): 1, \ ....:             (2, 3): 1, (3, 2): 1, (3, 3): 1} sage: T = FiniteTopologicalSpace(elements, minimal_basis, matrix(mat_dict)) ; T sage: T = FiniteTopologicalSpace(elements, minimal_basis, matrix(mat_dict)) sage: T # random Finite topological space of 4 points with minimal basis {'a': {3, 'a'}, 3: {3, 'a'}, 2: {1, 2}, 1: {1}} sage: T.topogenous_matrix() == matrix(mat_dict) class FiniteTopologicalSpace(Parent): self._minimal_basis = minimal_basis self._topogenous = topogenous def __repr__(self): def _repr_(self): r""" Print representation. class FiniteTopologicalSpace_T0(FiniteTopologicalSpace): self._poset = poset self._T0 = True def __repr__(self): def _repr_(self): r""" Print representation.

By the way, for classes which inherit from SageObject, like Parent, it is better to define _repr_ rather than __repr__. See https://doc.sagemath.org/html/en/developer/coding_in_python.html#print-representation.

### comment:15 Changed 3 months ago by jhpalmieri

More suggestions:

• ## src/doc/en/reference/references/index.rst

diff --git a/src/doc/en/reference/references/index.rst b/src/doc/en/reference/references/index.rst
index c58f1acbb9..96157140c4 100644
 a REFERENCES: of the Slovak Academy of Sciences. Mathematica Slovaca vol 30, n 4, pages 405--417, 1980 .. [Ale1937] \P. Alexandroff, *Diskrete Raume*, Mat. Sb. (N.S.) 2, 501--518 (1937). .. [Al1947] \A. A. Albert, *A Structure Theory for Jordan Algebras*. Annals of Mathematics, Second Series, Vol. 48, No. 3 (Jul., 1947), pp. 546--567. REFERENCES: Four Russians'. Cryptography E-Print Archive (http://eprint.iacr.org/2006/251.pdf), 2006. .. [Bar2011] \J. A. Barmak, *Algebraic topology of finite topological spaces and applications*. Lecture Notes in Mathematics Vol. 2032 (2011). .. [Bat1991] \V. V. Batyrev, *On the classification of smooth projective toric varieties*, Tohoku Math. J. **43** (1991), 569-585 REFERENCES: *Generation of random chordal graphs using subtrees of a tree*, :arxiv:1810.13326v1. .. [Shi1968] \M. Shiraki, *On finite topological spaces*, Rep. Fac. Sci. Kagoshima Univ.  1, 1--8 (1968). .. [Shi2002] \M. Shimozono *Affine type A crystal structure on tensor products of rectangles, Demazure characters, and nilpotent varieties*,
• ## src/sage/homology/finite_topological_spaces.py

diff --git a/src/sage/homology/finite_topological_spaces.py b/src/sage/homology/finite_topological_spaces.py
index 5c40fe26ce..c01c344ca2 100644
 a A *finite topological space* is a topological space with finitely many points an a *finite preordered set* is a finite set with a transitive and reflexive relation. Finite spaces and finite preordered sets are basically the same objects considered from different perspectives. Given a finite topological space X, for every point x\in X the *minimal open set* U_x as the intersection of all the open sets x\in X, define the *minimal open set* U_x as the intersection of all the open sets which contain x (it is an open set since arbitrary intersections of open sets in finite spaces are open). The minimal open sets constitute a basis for the topology of X. Indeed, any open set U of X is the union of the sets U_x with x\in U. This basis is called the *minimal basis of X*. A preorder on X by x\leqslant y This basis is called the *minimal basis of* X. A preorder on X is given by x\leqslant y if x\in U_y. If X is now a finite preordered set, one can define a topology on X given by then y is contained in every basic set containing x, and therefore y\in U_x Conversely, if y\in U_x, then y\in\lbrace z\in X\vert z\leqslant x\rbrace. Therefore y\leqslant x if and only if y\in U_x. This shows that these two applications, relating topologies and preorders on a finite set, are mutually inverse. This simple remark, made in first place by Alexandroff [1], allows us to study inverse. This simple remark, made in first place by Alexandroff [Ale1937]_, allows us to study finite spaces by combining Algebraic Topology with the combinatorics arising from their intrinsic preorder structures. The antisymmetry of a finite preorder corresponds exactly to the T_0 separation axiom. Recall that a topological space X is said to be *T_0* if for any pair of points in X there exists an open X is said to be T_0 if for any pair of points in X there exists an open set containing one and only one of them. Therefore finite T_0-spaces are in correspondence with finite partially ordered sets (posets) [2]. correspondence with finite partially ordered sets (posets) [Bar2011]_. Now, if X = \lbrace x_1, x_2, \ldots , x_n\rbrace is a finite space and for each i the unique minimal open set containing x_i is denoted by U_i, a *topogenous matrix* of the space is a n \times n matrix A = \left[a_{ij}\right] *topogenous matrix* of the space is the n \times n matrix A = \left[a_{ij}\right] defined by a_{ij} = 1 if x_i \in U_j and a_{ij} = 0 otherwise (this is the transposed matrix of the Definition 1 in [3]). A finite space X is T_0 if and transposed matrix of the Definition 1 in [Shi1968]_). A finite space X is T_0 if and only if the topogenous matrix A defined above is similar (via a permutation matrix) to a certain upper triangular matrix [3]. This is the reason one can assume that to a certain upper triangular matrix [Shi1968]_. This is the reason one can assume that the topogenous matrix of a finite T_0-space is upper triangular. AUTHOR:: REFERENCES: - [1] Alexandroff P., *Diskrete Raume*, Mat. Sb. (N.S.) 2, 501--518 (1937). - [2] Barmak, J.A., *Algebraic topology of finite topological spaces and applications*. Lecture Notes in Mathematics Vol. 2032 (2011). - [3] Shiraki M., *On finite topological spaces*, Rep. Fac. Sci. Kagoshima Univ. 1, 1--8 (1968). - [Ale1937]_ - [Bar2011]_ - [Shi1968]_ """ # **************************************************************************** class FiniteTopologicalSpace(Parent): ... ValueError: Parameter 'points' is not a valid set of representatives """ if self._T0==True: if self._T0 is True: return self else: if points is None: points = [list(A)[0] for A in self._T0] elif check==True: elif check: assert isinstance(points, (tuple, list, set)), \ "Parameter 'points' must be of type tuple, list or set" assert len(points)==len(self._T0), \

### comment:16 Changed 3 months ago by git

• Commit changed from 124dc44a4ae468033867502116ab71b4ab0b5e8b to 6efd9ed73aa50508bf28a3af876e7143357eeb7f

Branch pushed to git repo; I updated commit sha1. New commits:

 ​6efd9ed Reparing failures shown in comments 14 and 15 ticket 30400

### comment:17 Changed 3 months ago by gh-jcuevas-rozo

I have fixed some failures shown in comments 14 and 15. I have added a method space_sorting, which allows to sort the print representation of finite spaces (I have learned to run doctests and I had not got failures after defining such method).

### comment:18 follow-up: ↓ 20 Changed 3 months ago by chapoton

maybe you could get rid of dict_to_matrix, used only once

### comment:19 Changed 2 months ago by git

• Commit changed from 6efd9ed73aa50508bf28a3af876e7143357eeb7f to 38c2e84aebdc349988a8e59c91d3dcd832e18792

Branch pushed to git repo; I updated commit sha1. New commits:

 ​38c2e84 dict_to_matrix function removed

### comment:20 in reply to: ↑ 18 Changed 2 months ago by gh-jcuevas-rozo

maybe you could get rid of dict_to_matrix, used only once

Thanks for the suggestion.

### comment:21 follow-up: ↓ 24 Changed 5 weeks ago by gh-jcuevas-rozo

What could be the reason why this ticket passed the tests on October 18 but not on October 22? It has not been modified in recent weeks...

### comment:22 Changed 5 weeks ago by mkoeppe

• Milestone changed from sage-9.2 to sage-9.3

### comment:23 Changed 5 weeks ago by git

• Commit changed from 38c2e84aebdc349988a8e59c91d3dcd832e18792 to db381f24619e001d0ca42b59ff6f599b318782c2

Branch pushed to git repo; I updated commit sha1. New commits:

 ​f7ea792 Merge branch 'master' of git://github.com/sagemath/sage into t/30400/add_finite_topological_spaces ​db381f2 Order complex and barycentric subdivision added

### comment:24 in reply to: ↑ 21 Changed 5 weeks ago by chapoton

What could be the reason why this ticket passed the tests on October 18 but not on October 22? It has not been modified in recent weeks...

Because sage itself is moving, and the patchbots always use the latest develop branch, which sometimes does not pass all the tests.

By the way, you should pul your real full name in the "Authors" fields here above.

### comment:25 Changed 5 weeks ago by gh-jcuevas-rozo

• Authors changed from gh-jcuevas-rozo to Julián Cuevas-Rozo

### comment:26 Changed 4 weeks ago by git

• Commit changed from db381f24619e001d0ca42b59ff6f599b318782c2 to 538a6ab776feb0b53037aa3752b38a01a3adde2f

Branch pushed to git repo; I updated commit sha1. New commits:

 ​538a6ab beat points and weak points added

### comment:27 Changed 4 weeks ago by git

• Commit changed from 538a6ab776feb0b53037aa3752b38a01a3adde2f to 3bbc6e20b897ea89fb3c86518cabd989795818bd

Branch pushed to git repo; I updated commit sha1. New commits:

 ​3bbc6e2 Fixing tests

### comment:28 Changed 3 weeks ago by git

• Commit changed from 3bbc6e20b897ea89fb3c86518cabd989795818bd to 6fc8b088789e7fbaf73a3a7a440c2643b7902b55

Branch pushed to git repo; I updated commit sha1. New commits:

 ​5dfbe89 Merge branch 'u/gh-jcuevas-rozo/add_finite_topological_spaces' of git://trac.sagemath.org/sage into t/30862/dvf_and_homology_of_h_regular_finite_topological_spaces ​d860bee hregular homology added (missing documentation) ​6fc8b08 kenzo.py restored and some methods added to finite_topological_spaces.py

### comment:29 Changed 3 weeks ago by git

• Commit changed from 6fc8b088789e7fbaf73a3a7a440c2643b7902b55 to a6face57b0e9c6a56c7ba9230e8066fddce1d54a

Branch pushed to git repo; I updated commit sha1. New commits:

 ​a6face5 Non-ascii character deleted

### comment:30 Changed 7 days ago by git

• Commit changed from a6face57b0e9c6a56c7ba9230e8066fddce1d54a to 8a123d6cbc464d6cffc8a7202e003dbb640c22f5

Branch pushed to git repo; I updated commit sha1. New commits:

 ​8a123d6 Fixing 'blocks' warnings`
Note: See TracTickets for help on using tickets.