Opened 23 months ago

## #30400 needs_work enhancement

Reported by: Owned by: gh-jcuevas-rozo gh-jcuevas-rozo major sage-9.7 algebraic topology Finite topological spaces jhpalmieri Julián Cuevas-Rozo N/A Rework on top of #31925 u/gh-jcuevas-rozo/add_finite_topological_spaces 3c2e0d4ce41d764d3d413e81b430087aeed41d7b #31925

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 23 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 23 months ago by gh-jcuevas-rozo

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

### comment:4 Changed 23 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 23 months ago by gh-jcuevas-rozo

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

### comment:6 Changed 23 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 23 months ago by jhpalmieri

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

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

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

### comment:9 Changed 23 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 23 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 23 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 23 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 23 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 23 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 23 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 23 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 23 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 22 months ago by chapoton

maybe you could get rid of dict_to_matrix, used only once

### comment:19 Changed 22 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 22 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 21 months 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 21 months ago by mkoeppe

• Milestone changed from sage-9.2 to sage-9.3

### comment:23 Changed 21 months 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 21 months 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 21 months ago by gh-jcuevas-rozo

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

### comment:26 Changed 21 months 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 21 months 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 20 months 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 20 months 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 20 months ago by git

• Commit changed from a6face57b0e9c6a56c7ba9230e8066fddce1d54a to 8a123d6cbc464d6cffc8a7202e003dbb640c22f5

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

 ​8a123d6 Fixing 'blocks' warnings

### comment:31 Changed 18 months ago by gh-bollu

What's the SAGE etiquette for review? I'm interested to understand what's going on here, but don't know anything in particular about finite topologies. Am I expected to be an expert in the subject matter? Do comments on the code/general structure help?

### comment:32 Changed 18 months ago by jhpalmieri

I think that any feedback would be good. General comments are good, and if you can delve at all into the mathematics, that would also be good. I hope I can get back to this to help with the review myself, but I haven't had the time yet.

### comment:33 follow-up: ↓ 34 Changed 18 months ago by gh-kliem

Maybe a stupid comment, but isn't the singular of matrices "matrix"? Or is this something special about Kenzo.

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

Maybe a stupid comment, but isn't the singular of matrices "matrix"? Or is this something special about Kenzo.

Don´t worry, it is a good question. The term 'matrice', used in Kenzo, comes from French and it means matrix (as you noticed). In Kenzo, the type 'matrice' is used for sparse matrices.

### comment:35 follow-up: ↓ 38 Changed 17 months ago by jhpalmieri

My apologies for the delay, I am going to try working on this ticket. Some style comments:

• Preferred Sage style is to keep lines under 80 characters when possible. One place that violates this is in the docstrings. Don't work too hard to get the doctests under 80 characters, but the paragraphs of text should satisfy this.
• I don't know if it's officially a Sage style, but it is in general better to not use assert statements for error checking, because they can be ignored when Python is run with optimization flags turned on. The Python documentation says that assert statements should be used for debugging. (I think these statements are currently used throughout the Sage library, and maybe we should start a campaign to eliminate them. In the meantime, we shouldn't add more.)
• I'm getting doctest failures of the form cannot import name '__convertarray__' from .... I do not have Kenzo installed; I think those doctests should be marked optional - kenzo. See below for some fixes, although I may have been too aggressive in applying the tags.
• I'm getting other doctest failures from E = random.sample(X, k) with a deprecation warning:
    DeprecationWarning: Sampling from a set deprecated
since Python 3.9 and will be removed in a subsequent version.

• The documentation isn't building, but I think I've fixed that. See below.
• ## 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 5307dbbad1..61285a8e06 100644
 a def quotient_group_matrices(*matrices, left_null=False, right_null=False, check= EXAMPLES:: sage: from sage.homology.finite_topological_spaces import quotient_group_matrices, __convertarray__ sage: from sage.interfaces.kenzo import s2k_matrix sage: quotient_group_matrices() sage: from sage.homology.finite_topological_spaces import quotient_group_matrices, __convertarray__ # optional - kenzo sage: from sage.interfaces.kenzo import s2k_matrix # optional - kenzo sage: quotient_group_matrices() # optional - kenzo 0 sage: s_M1 = matrix(2, 3, [1, 2, 3, 4, 5, 6]) sage: M1 = __convertarray__(s2k_matrix(s_M1)) sage: quotient_group_matrices(M1, left_null=True) sage: s_M1 = matrix(2, 3, [1, 2, 3, 4, 5, 6]) # optional - kenzo sage: M1 = __convertarray__(s2k_matrix(s_M1)) # optional - kenzo sage: quotient_group_matrices(M1, left_null=True) # optional - kenzo C3 sage: quotient_group_matrices(M1, right_null=True) sage: quotient_group_matrices(M1, right_null=True) # optional - kenzo Z sage: s_M2 = matrix(2, 2, [1, -1, 1, -1]) sage: M2 = __convertarray__(s2k_matrix(s_M2)) sage: s_M3 = matrix(2, 2, [1, 0, 1, 0]) sage: M3 = __convertarray__(s2k_matrix(s_M3)) sage: quotient_group_matrices(M2, M3) sage: s_M2 = matrix(2, 2, [1, -1, 1, -1]) # optional - kenzo sage: M2 = __convertarray__(s2k_matrix(s_M2)) # optional - kenzo sage: s_M3 = matrix(2, 2, [1, 0, 1, 0]) # optional - kenzo sage: M3 = __convertarray__(s2k_matrix(s_M3)) # optional - kenzo sage: quotient_group_matrices(M2, M3) # optional - kenzo 0 sage: s_M4 = matrix(2, 2, [0, 0, 1, 0]) sage: M4 = __convertarray__(s2k_matrix(s_M4)) sage: quotient_group_matrices(M2, M4) sage: s_M4 = matrix(2, 2, [0, 0, 1, 0]) # optional - kenzo sage: M4 = __convertarray__(s2k_matrix(s_M4)) # optional - kenzo sage: quotient_group_matrices(M2, M4) # optional - kenzo Traceback (most recent call last): ... AssertionError: m1*m2 must be zero def k2s_binary_matrix_sparse(kmatrix): EXAMPLES:: sage: from sage.homology.finite_topological_spaces import k2s_binary_matrix_sparse, \ s2k_binary_matrix_sparse, __randomtop__ sage: KM2 = __randomtop__(6,1) sage: k2s_binary_matrix_sparse(KM2) s2k_binary_matrix_sparse, __randomtop__ # optional - kenzo sage: KM2 = __randomtop__(6,1) # optional - kenzo sage: k2s_binary_matrix_sparse(KM2) # optional - kenzo [1 1 1 1 1 1] [0 1 1 1 1 1] [0 0 1 1 1 1] [0 0 0 1 1 1] [0 0 0 0 1 1] [0 0 0 0 0 1] sage: KM = __randomtop__(100, float(0.8)) sage: SM = k2s_binary_matrix_sparse(KM) sage: SM == k2s_binary_matrix_sparse(s2k_binary_matrix_sparse(SM)) sage: KM = __randomtop__(100, float(0.8)) # optional - kenzo sage: SM = k2s_binary_matrix_sparse(KM) # optional - kenzo sage: SM == k2s_binary_matrix_sparse(s2k_binary_matrix_sparse(SM)) # optional - kenzo True """ data = __vector_to_list__(__matrice_to_lmtrx__(kmatrix)).python() def s2k_binary_matrix_sparse(smatrix): EXAMPLES:: sage: from sage.homology.finite_topological_spaces import k2s_binary_matrix_sparse, \ s2k_binary_matrix_sparse sage: SM2 = matrix.ones(5) sage: s2k_binary_matrix_sparse(SM2) s2k_binary_matrix_sparse # optional - kenzo sage: SM2 = matrix.ones(5) # optional - kenzo sage: s2k_binary_matrix_sparse(SM2) # optional - kenzo

### comment:36 follow-up: ↓ 39 Changed 17 months ago by jhpalmieri

Two more things about the documentation: \minus and \im are not standard LaTeX commands and they do not render properly. Should \minus be replaced by - or \setminus? I'm not sure what to do about \im: replace it every time by \mathrm{im} or similar?

### comment:37 Changed 17 months ago by jhpalmieri

Maybe \mathop{\mathrm{im}} or \mathrm{im}\,.

### comment:38 in reply to: ↑ 35 Changed 16 months ago by gh-jcuevas-rozo

• Preferred Sage style is to keep lines under 80 characters when possible. One place that violates this is in the docstrings. Don't work too hard to get the doctests under 80 characters, but the paragraphs of text should satisfy this.

I tried my best to do it, I have shortened the lines that didn't satisfy the rule.

• I don't know if it's officially a Sage style, but it is in general better to not use assert statements for error checking, because they can be ignored when Python is run with optimization flags turned on. The Python documentation says that assert statements should be used for debugging. (I think these statements are currently used throughout the Sage library, and maybe we should start a campaign to eliminate them. In the meantime, we shouldn't add more.)

The assert statements have been completely changed to conditional statements.

• I'm getting doctest failures of the form cannot import name '__convertarray__' from .... I do not have Kenzo installed; I think those doctests should be marked optional - kenzo. See below for some fixes, although I may have been too aggressive in applying the tags.

The optional - kenzo mark has been added to the required lines. Also, some functions have been added directly to src/sage/interfaces.kenzo.py.

• I'm getting other doctest failures from E = random.sample(X, k) with a deprecation warning:
    DeprecationWarning: Sampling from a set deprecated
since Python 3.9 and will be removed in a subsequent version.


I have changed "sampling from a set X" by "sampling from a list(X)" in order to fix these warnings.

### comment:39 in reply to: ↑ 36 Changed 16 months ago by gh-jcuevas-rozo

Two more things about the documentation: \minus and \im are not standard LaTeX commands and they do not render properly. Should \minus be replaced by - or \setminus? I'm not sure what to do about \im: replace it every time by \mathrm{im} or similar?

I have replaced \minus by - and \im by \mathrm{im}\ .

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

• Commit changed from 8a123d6cbc464d6cffc8a7202e003dbb640c22f5 to a06a949ec873dd72fc54f26cb5829289111400d9

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

 ​a06a949 Style suggestions added

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

• Commit changed from a06a949ec873dd72fc54f26cb5829289111400d9 to 481bef5cd865492f547cea19f705b62793661415

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

 ​481bef5 two pyflakes errors fixed

### comment:42 Changed 16 months ago by gh-jcuevas-rozo

I have seen the pyflakes errors here, but I don't know how to fix them, since the undefined names mentioned there depends on the installation of Kenzo (up to I understand)...

### comment:43 Changed 16 months ago by jhpalmieri

Thank you for checking those pyflakes errors. I agree that they don't need to be fixed.

### comment:44 follow-up: ↓ 49 Changed 16 months ago by jhpalmieri

In the example

    sage: T = FiniteSpace([{0, 3}, {1, 3}, {2, 3}, {3}]) ; T
Finite T0 topological space of 4 points with minimal basis
{0: {3, 0}, 1: {3, 1}, 2: {3, 2}, 3: {3}}
sage: T.elements()
[3, 0, 1, 2]


I would have expected T.elements() to be [0, 1, 2, 3], so I found the topogeneous matrix confusing. Even more with the following, I expect the elements to be sorted the way I enter them:

    sage: T = FiniteSpace([{0, 3}, {1, 3}, {2, 3}, {3}], elements=[0,1,2,3])
sage: T.elements()
[3, 0, 1, 2]


Should they be sorted in some cases? If the sets of elements are likely to be large, I can understand not wanting to sort by default, but if the user supplies a list of elements, shouldn't we use that?

I have no experience with finite topological spaces, so maybe users won't expect this sorting. From the Python/Sage point of view, the current situation seems odd, though. Looking at the code, is the point to have an upper triangulate topogeneous matrix? If so, please add a comment about this to the documentation, pointing out an example. However, the example constructed from matrix data does not have an upper triangular topogeneous matrix, so maybe I'm confused. Or is it only upper triangular if the space is T0? The comment in the code could be clarified. Is this right:

• ## 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 80f0b32fd1..ddab80d6f1 100644
 a def FiniteSpace(data, elements=None, is_T0=False): {0: {3, 0}, 1: {3, 1}, 2: {3, 2}, 3: {3}} sage: type(T) Note that the set of elements is sorted in perhaps an unexpected way. This is to ensure that in the case of a T0 space, the topogenous matrix is upper triangular:: sage: T.elements() [3, 0, 1, 2] sage: T.topogenous_matrix() [1 1 1 1] [0 1 0 0] [0 0 1 0] [0 0 0 1] sage: FiniteSpace(({0, 2}, {0, 2})) Traceback (most recent call last): ... def FiniteSpace(data, elements=None, is_T0=False): basis[j] = Uj eltos = range(n) # This fixes a topological sort (it guarantees an upper triangular topogenous matrix) # This fixes a topological sort (it guarantees an upper triangular topogenous matrix # in the T0 case) eltos = list(eltos) sorted_str_eltos = sorted([str(x) for x in eltos]) eltos.sort(key = lambda x: (len(basis[x]), sorted_str_eltos.index(str(x))))
Last edited 16 months ago by jhpalmieri (previous) (diff)

### comment:45 Changed 16 months ago by jhpalmieri

After installing kenzo 1.1.9 (via make kenzo), I get doctest failures from the optional kenzo doctests. For example:

File "src/sage/homology/finite_topological_spaces.py", line 300, in sage.homology.finite_topological_spaces.RandomFiniteT0Space
Failed example:
RandomFiniteT0Space(5, 0)                                # optional - kenzo
Exception raised:
Traceback (most recent call last):
File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.beta7/local/lib/python3.9/site-packages/sage/doctest/forker.py", line 714, in _run
self.compile_and_execute(example, compiler, test.globs)
File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.beta7/local/lib/python3.9/site-packages/sage/doctest/forker.py", line 1133, in compile_and_execute
exec(compiled, globs)
File "<doctest sage.homology.finite_topological_spaces.RandomFiniteT0Space[1]>", line 1, in <module>
RandomFiniteT0Space(Integer(5), Integer(0))                                # optional - kenzo
File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.beta7/local/lib/python3.9/site-packages/sage/homology/finite_topological_spaces.py", line 327, in RandomFiniteT0Space
topogenous = kenzo.k2s_binary_matrix_sparse(kenzo_top)
File "/Users/palmieri/Desktop/Sage/sage_builds/TESTING/sage-9.3.beta7/local/lib/python3.9/site-packages/sage/interfaces/kenzo.py", line 2130, in k2s_binary_matrix_sparse
data = __vector_to_list__(__matrice_to_lmtrx__(kmatrix)).python()
File "sage/libs/ecl.pyx", line 854, in sage.libs.ecl.EclObject.__call__ (build/cythonized/sage/libs/ecl.c:8614)
return ecl_wrap(ecl_safe_apply(self.obj,(<EclObject>lispargs).obj))
File "sage/libs/ecl.pyx", line 365, in sage.libs.ecl.ecl_safe_apply (build/cythonized/sage/libs/ecl.c:5896)
raise RuntimeError("ECL says: {}".format(
RuntimeError: ECL says: The function VECTOR-TO-LIST is undefined.


### comment:46 Changed 16 months ago by jhpalmieri

I also get failures in src/sage/interfaces/kenzo.py when kenzo is installed. Do I need to do more than ./configure --enable-kenzo=yes && make?

### comment:47 Changed 16 months ago by tscrim

All of the interface tests pass for me without this branch, and I am getting similar failures with the branch. These failures are happening on my Ubuntu machine.

### comment:48 Changed 16 months ago by gh-jcuevas-rozo

I apologize for the delay, but I was looking for the answer to the raised questions. By now, this ticket is working by using the following commands in order to load a testing branch of Kenzo:

git clone https://github.com/miguelmarco/kenzo/
cd kenzo
git checkout testing
sage -ecl < compile.lisp
mv kenzo--all-systems.fasb \$HOME/sage/local/lib/ecl/kenzo.fas

The changes made in this branch will be added in a future release of Kenzo.

### comment:49 in reply to: ↑ 44 Changed 16 months ago by gh-jcuevas-rozo

In the example

    sage: T = FiniteSpace([{0, 3}, {1, 3}, {2, 3}, {3}]) ; T
Finite T0 topological space of 4 points with minimal basis
{0: {3, 0}, 1: {3, 1}, 2: {3, 2}, 3: {3}}
sage: T.elements()
[3, 0, 1, 2]


I would have expected T.elements() to be [0, 1, 2, 3], so I found the topogeneous matrix confusing. Even more with the following, I expect the elements to be sorted the way I enter them:

    sage: T = FiniteSpace([{0, 3}, {1, 3}, {2, 3}, {3}], elements=[0,1,2,3])
sage: T.elements()
[3, 0, 1, 2]


Should they be sorted in some cases? If the sets of elements are likely to be large, I can understand not wanting to sort by default, but if the user supplies a list of elements, shouldn't we use that?

I think the attribute T.elements() has no a good name, I think I should change it to T.topogenous_sorting() or something like that. If the user want to obtain the set of elements of the space, the attribute T.underlying_set() could be the best option.

I have no experience with finite topological spaces, so maybe users won't expect this sorting. From the Python/Sage point of view, the current situation seems odd, though. Looking at the code, is the point to have an upper triangulate topogeneous matrix? If so, please add a comment about this to the documentation, pointing out an example. However, the example constructed from matrix data does not have an upper triangular topogeneous matrix, so maybe I'm confused. Or is it only upper triangular if the space is T0? The comment in the code could be clarified. Is this right:

• ## 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 80f0b32fd1..ddab80d6f1 100644
 a def FiniteSpace(data, elements=None, is_T0=False): {0: {3, 0}, 1: {3, 1}, 2: {3, 2}, 3: {3}} sage: type(T) Note that the set of elements is sorted in perhaps an unexpected way. This is to ensure that in the case of a T0 space, the topogenous matrix is upper triangular:: sage: T.elements() [3, 0, 1, 2] sage: T.topogenous_matrix() [1 1 1 1] [0 1 0 0] [0 0 1 0] [0 0 0 1] sage: FiniteSpace(({0, 2}, {0, 2})) Traceback (most recent call last): ... def FiniteSpace(data, elements=None, is_T0=False): basis[j] = Uj eltos = range(n) # This fixes a topological sort (it guarantees an upper triangular topogenous matrix) # This fixes a topological sort (it guarantees an upper triangular topogenous matrix # in the T0 case) eltos = list(eltos) sorted_str_eltos = sorted([str(x) for x in eltos]) eltos.sort(key = lambda x: (len(basis[x]), sorted_str_eltos.index(str(x))))

The comments in the code are absolutely right, thanks for the suggestions!

### comment:50 Changed 16 months ago by mkoeppe

• Milestone changed from sage-9.3 to sage-9.4

Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review of ticket status, priority, and last modification date.

### comment:51 Changed 13 months ago by git

• Commit changed from 481bef5cd865492f547cea19f705b62793661415 to 103698cd85f446f420c447eee00d6c0200680884

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

 ​103698c .elements() changed by .topogenous_sorting()

### comment:52 follow-up: ↓ 53 Changed 13 months ago by dimpase

This only adds to confusion one gets upon looking at what's in sage/homology/. IMHO this needs a restructuring (not on this ticket), maybe introducing something like sage/topology with parts such as spaces, homology, etc

### comment:53 in reply to: ↑ 52 ; follow-up: ↓ 54 Changed 13 months ago by jhpalmieri

This only adds to confusion one gets upon looking at what's in sage/homology/. IMHO this needs a restructuring (not on this ticket), maybe introducing something like sage/topology with parts such as spaces, homology, etc

I created #31925 for this.

### comment:54 in reply to: ↑ 53 ; follow-up: ↓ 55 Changed 13 months ago by dimpase

This only adds to confusion one gets upon looking at what's in sage/homology/. IMHO this needs a restructuring (not on this ticket), maybe introducing something like sage/topology with parts such as spaces, homology, etc

I created #31925 for this.

perhaps this ticket, i.e. #30400, can be a start for sage/topology ?

### comment:55 in reply to: ↑ 54 ; follow-up: ↓ 56 Changed 13 months ago by jhpalmieri

This only adds to confusion one gets upon looking at what's in sage/homology/. IMHO this needs a restructuring (not on this ticket), maybe introducing something like sage/topology with parts such as spaces, homology, etc

I created #31925 for this.

perhaps this ticket, i.e. #30400, can be a start for sage/topology ?

This and also #31748.

### comment:56 in reply to: ↑ 55 ; follow-up: ↓ 57 Changed 13 months ago by jhpalmieri

This only adds to confusion one gets upon looking at what's in sage/homology/. IMHO this needs a restructuring (not on this ticket), maybe introducing something like sage/topology with parts such as spaces, homology, etc

I created #31925 for this.

perhaps this ticket, i.e. #30400, can be a start for sage/topology ?

This and also #31748.

I'm working on #31925, and if it's in good enough shape, it can be a dependency for this ticket, and the file here would get added to sage/topology. My understanding is that this ticket requires an upgrade to Kenzo anyway, so this one is not immediately ready for merging. Is there a ticket for the new Kenzo?

### comment:57 in reply to: ↑ 56 ; follow-up: ↓ 58 Changed 13 months ago by slelievre

Is there a ticket for the new Kenzo?

The Trac query for tickets whose summary includes "kenzo" reveals:

• #29617: Support system installations of ECL and fix the kenzo SPKG build

which upgrades from Kenzo 1.1.9 to Kenzo 1.1.10 and udates the "upstream" info to point to

It got positive review in early April 2021, and was rebased on 9.4.beta0 in late May 2021.

Other Kenzo sources seem more outdated, mentioning only Kenzo 1.1.7:

Thankfully,

### comment:58 in reply to: ↑ 57 Changed 13 months ago by jhpalmieri

Is there a ticket for the new Kenzo?

The Trac query for tickets whose summary includes "kenzo" reveals:

• #29617: Support system installations of ECL and fix the kenzo SPKG build

which upgrades from Kenzo 1.1.9 to Kenzo 1.1.10 and udates the "upstream" info to point to

It got positive review in early April 2021, and was rebased on 9.4.beta0 in late May 2021.

Other Kenzo sources seem more outdated, mentioning only Kenzo 1.1.7:

Thankfully,

### comment:59 Changed 13 months ago by jhpalmieri

In any case, #31925 is ready for review, and this ticket could go in after it.

### comment:60 Changed 13 months ago by mkoeppe

• Dependencies set to #31925
• Status changed from needs_review to needs_work
• Work issues set to Rework on top of #31925

### comment:61 Changed 12 months ago by mkoeppe

• Milestone changed from sage-9.4 to sage-9.5

Setting a new milestone for this ticket based on a cursory review.

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

• Commit changed from 103698cd85f446f420c447eee00d6c0200680884 to d266e725c593e92b80be9871cbff1bc69b60d381

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

 ​0491dd2 Merge branch 't/31925/f641bbb597fbf58103ed8c84867bab207a10ffde' into t/30400/add_finite_topological_spaces ​d266e72 finite spaces moved to topology folder

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

• Commit changed from d266e725c593e92b80be9871cbff1bc69b60d381 to 3c2e0d4ce41d764d3d413e81b430087aeed41d7b

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

 ​3c2e0d4 references updated`

### comment:64 Changed 11 months ago by gh-jcuevas-rozo

• Status changed from needs_work to needs_review

It has been merged with ticket #31925.

### comment:65 Changed 11 months ago by jhpalmieri

I think there needs to be a ticket with the appropriate upgrade to Kenzo (comment:48), and this ticket should depend on that one. I think that we cannot really test this one without the Kenzo upgrade.

### comment:66 Changed 9 months ago by chapoton

red branch => needs work

### comment:67 Changed 9 months ago by chapoton

• Status changed from needs_review to needs_work

### comment:68 Changed 7 months ago by mkoeppe

• Milestone changed from sage-9.5 to sage-9.6

### comment:69 Changed 3 months ago by mkoeppe

• Milestone changed from sage-9.6 to sage-9.7
Note: See TracTickets for help on using tickets.