Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sage.topology: Move imports from sage.graphs, sage.homology into methods #35263

Merged
merged 2 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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