Skip to content

Commit

Permalink
gh-35263: sage.topology: Move imports from sage.graphs, `sage.hom…
Browse files Browse the repository at this point in the history
…ology` into methods

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes #1234" use "Introduce new method to
calculate 1+1"
-->
### 📚 Description
Part of:
- #29705

<!-- Describe your changes here in detail -->
<!-- Why is this change required? What problem does it solve? -->
<!-- If it resolves an open issue, please link to the issue here. For
example "Closes #1337" -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] I have made sure that the title is self-explanatory and the
description concisely explains the PR.
- [x] I have linked an issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies
<!-- List all open pull requests that this PR logically depends on -->
<!--
- #xyz: short description why this is a dependency
- #abc: ...
-->
    
URL: #35263
Reported by: Matthias Köppe
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Mar 31, 2023
2 parents 65c89ec + 8d79ca8 commit 45e98cb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/sage/topology/cubical_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.matrix.constructor import matrix
from sage.homology.chain_complex import ChainComplex
from sage.graphs.graph import Graph
from sage.misc.cachefunc import cached_method
from sage.misc.superseded import deprecation
from functools import total_ordering
Expand Down Expand Up @@ -1192,6 +1190,8 @@ def chain_complex(self, subcomplex=None, augmented=False,
sage: Square.homology(subcomplex=EdgesLTR)[2] == Square.homology(subcomplex=EdgesLBR)[2]
True
"""
from sage.homology.chain_complex import ChainComplex

# initialize subcomplex
if subcomplex is None:
subcomplex = CubicalComplex()
Expand Down Expand Up @@ -1333,6 +1333,8 @@ def graph(self):
sage: cubical_complexes.Sphere(2).graph()
Graph on 8 vertices
"""
from sage.graphs.graph import Graph

data = {}
vertex_dict = {}
i = 0
Expand Down
9 changes: 6 additions & 3 deletions src/sage/topology/delta_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@

from copy import copy
from sage.topology.cell_complex import GenericCellComplex
from sage.homology.chains import Chains, Cochains
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.integer import Integer
from sage.matrix.constructor import matrix
from .simplicial_complex import Simplex, lattice_paths, SimplicialComplex
from sage.homology.chain_complex import ChainComplex
from sage.graphs.graph import Graph
from sage.arith.misc import binomial
from sage.misc.cachefunc import cached_method

Expand Down Expand Up @@ -630,6 +627,8 @@ def chain_complex(self, subcomplex=None, augmented=False,
sage: T.homology(subcomplex=A)
{0: 0, 1: 0, 2: Z}
"""
from sage.homology.chain_complex import ChainComplex

if subcomplex is not None:
# relative chain complex, so don't augment the chain complex
augmented = False
Expand Down Expand Up @@ -776,6 +775,8 @@ def graph(self):
sage: delta_complexes.Simplex(4).graph() == graphs.CompleteGraph(5)
True
"""
from sage.graphs.graph import Graph

data = {}
for vertex in range(len(self.n_cells(0))):
data[vertex] = []
Expand Down Expand Up @@ -1523,6 +1524,8 @@ def n_chains(self, n, base_ring=None, cochains=False):
sage: list(T.n_chains(1, QQ, cochains=True).basis())
[\chi_(0, (0, 0)), \chi_(1, (0, 0)), \chi_(2, (0, 0))]
"""
from sage.homology.chains import Chains, Cochains

n_cells = tuple(enumerate(self.n_cells(n)))
if cochains:
return Cochains(self, n, n_cells, base_ring)
Expand Down
17 changes: 10 additions & 7 deletions src/sage/topology/simplicial_complex_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@
#
# ****************************************************************************

from .simplicial_complex import Simplex, SimplicialComplex
from sage.matrix.constructor import matrix, zero_matrix
from sage.rings.integer_ring import ZZ
from sage.homology.chain_complex_morphism import ChainComplexMorphism
from sage.combinat.permutation import Permutation
from sage.algebras.steenrod.steenrod_algebra_misc import convert_perm
from sage.categories.morphism import Morphism
from sage.categories.homset import Hom
from sage.categories.morphism import Morphism
from sage.categories.simplicial_complexes import SimplicialComplexes
from sage.matrix.constructor import matrix, zero_matrix
from sage.rings.integer_ring import ZZ

from .simplicial_complex import Simplex, SimplicialComplex


def is_SimplicialComplexMorphism(x):
Expand Down Expand Up @@ -252,6 +250,9 @@ def __call__(self,x,orientation=False):
for j in tup:
fx.append(self._vertex_dictionary[j])
if orientation:
from sage.algebras.steenrod.steenrod_algebra_misc import convert_perm
from sage.combinat.permutation import Permutation

if len(set(fx)) == len(tup):
oriented = Permutation(convert_perm(fx)).signature()
else:
Expand Down Expand Up @@ -371,6 +372,8 @@ def associated_chain_complex_morphism(self,base_ring=ZZ,augmented=False,cochain=
{0: [0 1]
[1 0], 1: [-1]}
"""
from sage.homology.chain_complex_morphism import ChainComplexMorphism

max_dim = max(self.domain().dimension(),self.codomain().dimension())
min_dim = min(self.domain().dimension(),self.codomain().dimension())
matrices = {}
Expand Down
13 changes: 9 additions & 4 deletions src/sage/topology/simplicial_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@

import copy

from sage.graphs.graph import Graph
from sage.matrix.constructor import matrix
from sage.misc.cachefunc import cached_method
from sage.misc.fast_methods import WithEqualityById
Expand All @@ -263,9 +262,6 @@
from sage.rings.rational_field import QQ
from sage.structure.parent import Parent
from sage.structure.sage_object import SageObject
from sage.homology.algebraic_topological_model import algebraic_topological_model_delta_complex
from sage.homology.chain_complex import ChainComplex
from sage.homology.chains import Chains, Cochains

from .cell_complex import GenericCellComplex
from .delta_complex import DeltaComplex
Expand Down Expand Up @@ -1686,6 +1682,8 @@ def graph(self):
sage: Sigma3.nerve().is_connected()
True
"""
from sage.graphs.graph import Graph

G = Graph(loops=True, multiedges=True)
for e in self.n_cells(1):
G.add_edge(self.face(e,0), self.face(e,1), e)
Expand Down Expand Up @@ -2153,6 +2151,9 @@ def n_chains(self, n, base_ring=ZZ, cochains=False):
return GenericCellComplex.n_chains(self, n=n,
base_ring=base_ring,
cochains=cochains)

from sage.homology.chains import Chains, Cochains

n_cells = tuple(self.n_cells(n))
if cochains:
return Cochains(self, n, n_cells, base_ring)
Expand Down Expand Up @@ -3634,6 +3635,8 @@ def chain_complex(self, dimensions=None, base_ring=ZZ, augmented=False,
sage: RP2.cohomology(base_ring=GF(2)) == SimplicialSet(RP2).cohomology(base_ring=GF(2))
True
"""
from sage.homology.chain_complex import ChainComplex

if dimensions is None:
if not self.cells(): # Empty
if cochain:
Expand Down Expand Up @@ -3782,6 +3785,8 @@ def algebraic_topological_model(self, base_ring=None):
1: Vector space of dimension 2 over Rational Field,
2: Vector space of dimension 1 over Rational Field}
"""
from sage.homology.algebraic_topological_model import algebraic_topological_model_delta_complex

if base_ring is None:
base_ring = QQ
return algebraic_topological_model_delta_complex(self, base_ring)
Expand Down
3 changes: 2 additions & 1 deletion src/sage/topology/simplicial_set_constructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@

import itertools

from sage.graphs.graph import Graph
from sage.misc.latex import latex
from sage.sets.set import Set
from sage.structure.parent import Parent
Expand Down Expand Up @@ -1417,6 +1416,8 @@ def __init__(self, maps=None, vertex_name=None):
sage: PushoutOfSimplicialSets_finite([T.base_point_map(), S2.base_point_map()], vertex_name='v').n_cells(0)[0]
v
"""
from sage.graphs.graph import Graph

# Import this here to prevent circular imports.
from sage.topology.simplicial_set_morphism import SimplicialSetMorphism
if maps and any(not isinstance(f, SimplicialSetMorphism) for f in maps):
Expand Down
3 changes: 2 additions & 1 deletion src/sage/topology/simplicial_set_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from pyparsing import OneOrMore, nestedExpr

from sage.env import SAGE_ENV
from sage.groups.abelian_gps.abelian_group import AbelianGroup
from sage.misc.cachefunc import cached_method, cached_function
from sage.misc.latex import latex
from sage.rings.infinity import Infinity
Expand Down Expand Up @@ -363,6 +362,8 @@ def RealProjectiveSpace(n):
RP^{\infty}
"""
if n == Infinity:
from sage.groups.abelian_gps.abelian_group import AbelianGroup

X = AbelianGroup([2]).nerve()
X.rename('RP^oo')
X.rename_latex('RP^{\\infty}')
Expand Down
6 changes: 4 additions & 2 deletions src/sage/topology/simplicial_set_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
from sage.misc.latex import latex
from sage.rings.integer_ring import ZZ

from sage.homology.chain_complex_morphism import ChainComplexMorphism
from sage.homology.homology_morphism import InducedHomologyMorphism
from .simplicial_set import SimplicialSet_arbitrary

class SimplicialSetHomset(Homset):
Expand Down Expand Up @@ -1312,6 +1310,8 @@ def associated_chain_complex_morphism(self, base_ring=ZZ,
[-+-]
[0|0]
"""
from sage.homology.chain_complex_morphism import ChainComplexMorphism

# One or the other chain complex is trivial between these
# dimensions:
max_dim = max(self.domain().dimension(), self.codomain().dimension())
Expand Down Expand Up @@ -1394,6 +1394,8 @@ def induced_homology_morphism(self, base_ring=None, cohomology=False):
[-+-]
[0|2]
"""
from sage.homology.homology_morphism import InducedHomologyMorphism

return InducedHomologyMorphism(self, base_ring, cohomology)

def _repr_type(self):
Expand Down

0 comments on commit 45e98cb

Please sign in to comment.