Skip to content

Commit

Permalink
sage.{homology,topology}: Doctest cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Apr 28, 2023
1 parent 82301a9 commit f806616
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 274 deletions.
95 changes: 51 additions & 44 deletions src/sage/homology/chain_complex.py

Large diffs are not rendered by default.

167 changes: 84 additions & 83 deletions src/sage/homology/chain_complex_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@
EXAMPLES::
sage: S = simplicial_complexes.Sphere(1) # optional - sage.graphs
sage: S # optional - sage.graphs
sage: S = simplicial_complexes.Sphere(1); S # optional - sage.graphs
Minimal triangulation of the 1-sphere
sage: C = S.chain_complex() # optional - sage.graphs
sage: C.differential() # optional - sage.graphs
{0: [], 1: [-1 -1 0]
[ 1 0 -1]
[ 0 1 1], 2: []}
sage: f = {0:zero_matrix(ZZ,3,3),1:zero_matrix(ZZ,3,3)}
sage: G = Hom(C,C) # optional - sage.graphs
sage: x = G(f) # optional - sage.graphs
sage: x # optional - sage.graphs
Chain complex endomorphism of Chain complex with at most 2 nonzero terms over Integer Ring
sage: f = {0: zero_matrix(ZZ,3,3), 1: zero_matrix(ZZ,3,3)}
sage: G = Hom(C, C) # optional - sage.graphs
sage: x = G(f); x # optional - sage.graphs
Chain complex endomorphism of
Chain complex with at most 2 nonzero terms over Integer Ring
sage: x._matrix_dictionary # optional - sage.graphs
{0: [0 0 0]
[0 0 0]
[0 0 0], 1: [0 0 0]
[0 0 0]
[0 0 0]}
[0 0 0]
[0 0 0],
1: [0 0 0]
[0 0 0]
[0 0 0]}
"""

#*****************************************************************************
Expand Down Expand Up @@ -91,31 +91,33 @@ def __init__(self, matrices, C, D, check=True):
EXAMPLES::
sage: S = simplicial_complexes.Sphere(1) # optional - sage.graphs
sage: S # optional - sage.graphs
sage: S = simplicial_complexes.Sphere(1); S # optional - sage.graphs
Minimal triangulation of the 1-sphere
sage: C = S.chain_complex() # optional - sage.graphs
sage: C.differential() # optional - sage.graphs
{0: [], 1: [-1 -1 0]
[ 1 0 -1]
[ 0 1 1], 2: []}
{0: [],
1: [-1 -1 0]
[ 1 0 -1]
[ 0 1 1],
2: []}
sage: f = {0:zero_matrix(ZZ,3,3),1:zero_matrix(ZZ,3,3)}
sage: G = Hom(C,C) # optional - sage.graphs
sage: x = G(f) # optional - sage.graphs
sage: x # optional - sage.graphs
Chain complex endomorphism of Chain complex with at most 2 nonzero terms over Integer Ring
sage: x = G(f); x # optional - sage.graphs
Chain complex endomorphism of
Chain complex with at most 2 nonzero terms over Integer Ring
sage: x._matrix_dictionary # optional - sage.graphs
{0: [0 0 0]
[0 0 0]
[0 0 0], 1: [0 0 0]
[0 0 0]
[0 0 0]}
[0 0 0]
[0 0 0],
1: [0 0 0]
[0 0 0]
[0 0 0]}
Check that the bug in :trac:`13220` has been fixed::
sage: X = simplicial_complexes.Simplex(1) # optional - sage.graphs
sage: Y = simplicial_complexes.Simplex(0) # optional - sage.graphs
sage: g = Hom(X,Y)({0:0, 1:0}) # optional - sage.graphs
sage: g = Hom(X,Y)({0: 0, 1: 0}) # optional - sage.graphs
sage: g.associated_chain_complex_morphism() # optional - sage.graphs
Chain complex morphism:
From: Chain complex with at most 2 nonzero terms over Integer Ring
Expand Down Expand Up @@ -189,7 +191,7 @@ def __init__(self, matrices, C, D, check=True):

def in_degree(self, n):
"""
The matrix representing this morphism in degree n
The matrix representing this morphism in degree `n`.
INPUT:
Expand Down Expand Up @@ -273,7 +275,7 @@ def dual(self):
sage: f.dual() # optional - sage.graphs
Chain complex morphism:
From: Chain complex with at most 1 nonzero terms over Integer Ring
To: Chain complex with at most 2 nonzero terms over Integer Ring
To: Chain complex with at most 2 nonzero terms over Integer Ring
sage: f.dual().in_degree(0) # optional - sage.graphs
[1]
[1]
Expand Down Expand Up @@ -302,19 +304,19 @@ def __neg__(self):
sage: w = -x # optional - sage.graphs
sage: w._matrix_dictionary # optional - sage.graphs
{0: [-1 0 0 0]
[ 0 -1 0 0]
[ 0 0 -1 0]
[ 0 0 0 -1],
[ 0 -1 0 0]
[ 0 0 -1 0]
[ 0 0 0 -1],
1: [-1 0 0 0 0 0]
[ 0 -1 0 0 0 0]
[ 0 0 -1 0 0 0]
[ 0 0 0 -1 0 0]
[ 0 0 0 0 -1 0]
[ 0 0 0 0 0 -1],
[ 0 -1 0 0 0 0]
[ 0 0 -1 0 0 0]
[ 0 0 0 -1 0 0]
[ 0 0 0 0 -1 0]
[ 0 0 0 0 0 -1],
2: [-1 0 0 0]
[ 0 -1 0 0]
[ 0 0 -1 0]
[ 0 0 0 -1]}
[ 0 -1 0 0]
[ 0 0 -1 0]
[ 0 0 0 -1]}
"""
f = dict()
Expand All @@ -335,19 +337,19 @@ def __add__(self,x):
sage: z = x+x # optional - sage.graphs
sage: z._matrix_dictionary # optional - sage.graphs
{0: [2 0 0 0]
[0 2 0 0]
[0 0 2 0]
[0 0 0 2],
[0 2 0 0]
[0 0 2 0]
[0 0 0 2],
1: [2 0 0 0 0 0]
[0 2 0 0 0 0]
[0 0 2 0 0 0]
[0 0 0 2 0 0]
[0 0 0 0 2 0]
[0 0 0 0 0 2],
[0 2 0 0 0 0]
[0 0 2 0 0 0]
[0 0 0 2 0 0]
[0 0 0 0 2 0]
[0 0 0 0 0 2],
2: [2 0 0 0]
[0 2 0 0]
[0 0 2 0]
[0 0 0 2]}
[0 2 0 0]
[0 0 2 0]
[0 0 0 2]}
"""
if not isinstance(x, ChainComplexMorphism) or self.codomain() != x.codomain() or self.domain() != x.domain() or self._matrix_dictionary.keys() != x._matrix_dictionary.keys():
raise TypeError("unsupported operation")
Expand All @@ -370,35 +372,35 @@ def __mul__(self, x):
sage: y = x*2 # optional - sage.graphs
sage: y._matrix_dictionary # optional - sage.graphs
{0: [2 0 0 0]
[0 2 0 0]
[0 0 2 0]
[0 0 0 2],
[0 2 0 0]
[0 0 2 0]
[0 0 0 2],
1: [2 0 0 0 0 0]
[0 2 0 0 0 0]
[0 0 2 0 0 0]
[0 0 0 2 0 0]
[0 0 0 0 2 0]
[0 0 0 0 0 2],
[0 2 0 0 0 0]
[0 0 2 0 0 0]
[0 0 0 2 0 0]
[0 0 0 0 2 0]
[0 0 0 0 0 2],
2: [2 0 0 0]
[0 2 0 0]
[0 0 2 0]
[0 0 0 2]}
[0 2 0 0]
[0 0 2 0]
[0 0 0 2]}
sage: z = y*y # optional - sage.graphs
sage: z._matrix_dictionary # optional - sage.graphs
{0: [4 0 0 0]
[0 4 0 0]
[0 0 4 0]
[0 0 0 4],
[0 4 0 0]
[0 0 4 0]
[0 0 0 4],
1: [4 0 0 0 0 0]
[0 4 0 0 0 0]
[0 0 4 0 0 0]
[0 0 0 4 0 0]
[0 0 0 0 4 0]
[0 0 0 0 0 4],
[0 4 0 0 0 0]
[0 0 4 0 0 0]
[0 0 0 4 0 0]
[0 0 0 0 4 0]
[0 0 0 0 0 4],
2: [4 0 0 0]
[0 4 0 0]
[0 0 4 0]
[0 0 0 4]}
[0 4 0 0]
[0 0 4 0]
[0 0 0 4]}
TESTS:
Expand Down Expand Up @@ -477,7 +479,7 @@ def __sub__(self,x):
sage: H = Hom(S,S) # optional - sage.graphs
sage: i = H.identity() # optional - sage.graphs
sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs
sage: y = x-x # optional - sage.graphs
sage: y = x - x # optional - sage.graphs
sage: y._matrix_dictionary # optional - sage.graphs
{0: [0 0 0 0]
[0 0 0 0]
Expand Down Expand Up @@ -505,8 +507,7 @@ def __eq__(self,x):
sage: S = SimplicialComplex(is_mutable=False) # optional - sage.graphs
sage: H = Hom(S,S) # optional - sage.graphs
sage: i = H.identity() # optional - sage.graphs
sage: x = i.associated_chain_complex_morphism() # optional - sage.graphs
sage: x # optional - sage.graphs
sage: x = i.associated_chain_complex_morphism(); x # optional - sage.graphs
Chain complex morphism:
From: Trivial chain complex over Integer Ring
To: Trivial chain complex over Integer Ring
Expand All @@ -524,7 +525,7 @@ def __eq__(self,x):

def is_identity(self):
"""
True if this is the identity map.
Return ``True`` if this is the identity map.
EXAMPLES::
Expand All @@ -539,7 +540,7 @@ def is_identity(self):

def is_surjective(self):
"""
True if this map is surjective.
Return ``True`` if this map is surjective.
EXAMPLES::
Expand All @@ -561,19 +562,19 @@ def is_surjective(self):

def is_injective(self):
"""
True if this map is injective.
Return ``True`` if this map is injective.
EXAMPLES::
sage: S1 = simplicial_complexes.Sphere(1) # optional - sage.graphs
sage: H = Hom(S1, S1) # optional - sage.graphs
sage: flip = H({0:0, 1:2, 2:1}) # optional - sage.graphs
sage: flip.associated_chain_complex_morphism().is_injective() # optional - sage.graphs
sage: S1 = simplicial_complexes.Sphere(1) # optional - sage.graphs
sage: H = Hom(S1, S1) # optional - sage.graphs
sage: flip = H({0:0, 1:2, 2:1}) # optional - sage.graphs
sage: flip.associated_chain_complex_morphism().is_injective() # optional - sage.graphs
True
sage: pt = simplicial_complexes.Simplex(0) # optional - sage.graphs
sage: inclusion = Hom(pt, S1)({0:2}) # optional - sage.graphs
sage: inclusion.associated_chain_complex_morphism().is_injective() # optional - sage.graphs
sage: pt = simplicial_complexes.Simplex(0) # optional - sage.graphs
sage: inclusion = Hom(pt, S1)({0:2}) # optional - sage.graphs
sage: inclusion.associated_chain_complex_morphism().is_injective() # optional - sage.graphs
True
sage: inclusion.associated_chain_complex_morphism(cochain=True).is_injective() # optional - sage.graphs
False
Expand Down
46 changes: 31 additions & 15 deletions src/sage/homology/chain_homotopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,23 @@ def is_algebraic_gradient_vector_field(self):
`\ZZ` in degree 0. Two chain maps `C \to C` will be chain
homotopic as long as they agree in degree 0. ::
sage: f = Hom(C,C)({0: identity_matrix(ZZ, 1), 1: matrix(ZZ, 1, 1, [3]), 2: matrix(ZZ, 1, 1, [3])})
sage: g = Hom(C,C)({0: identity_matrix(ZZ, 1), 1: matrix(ZZ, 1, 1, [2]), 2: matrix(ZZ, 1, 1, [2])})
sage: H = ChainHomotopy({0: zero_matrix(ZZ, 0, 1), 1: zero_matrix(ZZ, 1), 2: identity_matrix(ZZ, 1)}, f, g)
sage: f = Hom(C,C)({0: identity_matrix(ZZ, 1),
....: 1: matrix(ZZ, 1, 1, [3]),
....: 2: matrix(ZZ, 1, 1, [3])})
sage: g = Hom(C,C)({0: identity_matrix(ZZ, 1),
....: 1: matrix(ZZ, 1, 1, [2]),
....: 2: matrix(ZZ, 1, 1, [2])})
sage: H = ChainHomotopy({0: zero_matrix(ZZ, 0, 1),
....: 1: zero_matrix(ZZ, 1),
....: 2: identity_matrix(ZZ, 1)}, f, g)
sage: H.is_algebraic_gradient_vector_field()
True
A chain homotopy which is not an algebraic gradient vector field::
sage: H = ChainHomotopy({0: zero_matrix(ZZ, 0, 1), 1: identity_matrix(ZZ, 1), 2: identity_matrix(ZZ, 1)}, f, g)
sage: H = ChainHomotopy({0: zero_matrix(ZZ, 0, 1),
....: 1: identity_matrix(ZZ, 1),
....: 2: identity_matrix(ZZ, 1)}, f, g)
sage: H.is_algebraic_gradient_vector_field()
False
"""
Expand Down Expand Up @@ -252,9 +260,15 @@ def is_homology_gradient_vector_field(self):
sage: from sage.homology.chain_homotopy import ChainHomotopy
sage: C = ChainComplex({0: zero_matrix(ZZ, 1), 1: identity_matrix(ZZ, 1)})
sage: f = Hom(C,C)({0: identity_matrix(ZZ, 1), 1: matrix(ZZ, 1, 1, [3]), 2: matrix(ZZ, 1, 1, [3])})
sage: g = Hom(C,C)({0: identity_matrix(ZZ, 1), 1: matrix(ZZ, 1, 1, [2]), 2: matrix(ZZ, 1, 1, [2])})
sage: H = ChainHomotopy({0: zero_matrix(ZZ, 0, 1), 1: zero_matrix(ZZ, 1), 2: identity_matrix(ZZ, 1)}, f, g)
sage: f = Hom(C,C)({0: identity_matrix(ZZ, 1),
....: 1: matrix(ZZ, 1, 1, [3]),
....: 2: matrix(ZZ, 1, 1, [3])})
sage: g = Hom(C,C)({0: identity_matrix(ZZ, 1),
....: 1: matrix(ZZ, 1, 1, [2]),
....: 2: matrix(ZZ, 1, 1, [2])})
sage: H = ChainHomotopy({0: zero_matrix(ZZ, 0, 1),
....: 1: zero_matrix(ZZ, 1),
....: 2: identity_matrix(ZZ, 1)}, f, g)
sage: H.is_homology_gradient_vector_field()
True
"""
Expand Down Expand Up @@ -282,8 +296,8 @@ def in_degree(self, n):
EXAMPLES::
sage: from sage.homology.chain_homotopy import ChainHomotopy
sage: C = ChainComplex({1: matrix(ZZ, 0, 2)}) # one nonzero term in degree 1
sage: D = ChainComplex({0: matrix(ZZ, 0, 1)}) # one nonzero term in degree 0
sage: C = ChainComplex({1: matrix(ZZ, 0, 2)}) # one nonzero term in degree 1
sage: D = ChainComplex({0: matrix(ZZ, 0, 1)}) # one nonzero term in degree 0
sage: f = Hom(C, D)({})
sage: H = ChainHomotopy({1: matrix(ZZ, 1, 2, (3,1))}, f, f)
sage: H.in_degree(1)
Expand Down Expand Up @@ -317,8 +331,8 @@ def dual(self):
EXAMPLES::
sage: from sage.homology.chain_homotopy import ChainHomotopy
sage: C = ChainComplex({1: matrix(ZZ, 0, 2)}) # one nonzero term in degree 1
sage: D = ChainComplex({0: matrix(ZZ, 0, 1)}) # one nonzero term in degree 0
sage: C = ChainComplex({1: matrix(ZZ, 0, 2)}) # one nonzero term in degree 1
sage: D = ChainComplex({0: matrix(ZZ, 0, 1)}) # one nonzero term in degree 0
sage: f = Hom(C, D)({})
sage: H = ChainHomotopy({1: matrix(ZZ, 1, 2, (3,1))}, f, f)
sage: H.in_degree(1)
Expand All @@ -337,8 +351,8 @@ def __hash__(self):
TESTS::
sage: from sage.homology.chain_homotopy import ChainHomotopy
sage: C = ChainComplex({1: matrix(ZZ, 0, 2)}) # one nonzero term in degree 1
sage: D = ChainComplex({0: matrix(ZZ, 0, 1)}) # one nonzero term in degree 0
sage: C = ChainComplex({1: matrix(ZZ, 0, 2)}) # one nonzero term in degree 1
sage: D = ChainComplex({0: matrix(ZZ, 0, 1)}) # one nonzero term in degree 0
sage: f = Hom(C, D)({})
sage: H = ChainHomotopy({1: matrix(ZZ, 1, 2, (3,1))}, f, f)
sage: hash(H) # random
Expand All @@ -348,7 +362,7 @@ def __hash__(self):

def _repr_(self):
"""
String representation
String representation.
EXAMPLES::
Expand Down Expand Up @@ -404,7 +418,9 @@ class ChainContraction(ChainHomotopy):
sage: pi = Hom(C,D)({0: identity_matrix(ZZ, 1)})
sage: iota = Hom(D,C)({0: identity_matrix(ZZ, 1)})
sage: H = ChainContraction({0: zero_matrix(ZZ, 0, 1), 1: zero_matrix(ZZ, 1), 2: identity_matrix(ZZ, 1)}, pi, iota)
sage: H = ChainContraction({0: zero_matrix(ZZ, 0, 1),
....: 1: zero_matrix(ZZ, 1),
....: 2: identity_matrix(ZZ, 1)}, pi, iota)
"""
def __init__(self, matrices, pi, iota):
r"""
Expand Down
Loading

0 comments on commit f806616

Please sign in to comment.