diff --git a/src/sage/geometry/cone.py b/src/sage/geometry/cone.py index 0d9689b4d2e..513907590f4 100644 --- a/src/sage/geometry/cone.py +++ b/src/sage/geometry/cone.py @@ -206,17 +206,17 @@ from copy import copy from warnings import warn +from sage.misc.lazy_import import lazy_import +lazy_import('sage.combinat.posets.posets', 'FinitePoset') from sage.arith.misc import GCD as gcd from sage.arith.functions import lcm -from sage.combinat.posets.posets import FinitePoset from sage.geometry.point_collection import PointCollection from sage.geometry.polyhedron.constructor import Polyhedron -from sage.geometry.hasse_diagram import lattice_from_incidences +lazy_import('sage.geometry.hasse_diagram', 'lattice_from_incidences') from sage.geometry.toric_lattice import (ToricLattice, is_ToricLattice, is_ToricLatticeQuotient) -from sage.geometry.toric_plotter import ToricPlotter, label_list +lazy_import('sage.geometry.toric_plotter', ['ToricPlotter', 'label_list']) from sage.geometry.relative_interior import RelativeInterior -from sage.graphs.digraph import DiGraph from sage.matrix.constructor import matrix from sage.matrix.matrix_space import MatrixSpace from sage.matrix.special import column_matrix @@ -229,11 +229,10 @@ from sage.rings.rational_field import QQ from sage.structure.all import SageObject, parent from sage.structure.richcmp import richcmp_method, richcmp -from sage.geometry.integral_points import parallelotope_points +lazy_import('sage.geometry.integral_points', 'parallelotope_points') from sage.geometry.convex_set import ConvexSet_closed import sage.geometry.abc -from sage.misc.lazy_import import lazy_import from sage.features import PythonModule lazy_import('ppl', ['C_Polyhedron', 'Generator_System', 'Constraint_System', 'Linear_Expression', 'Poly_Con_Relation'], @@ -627,10 +626,21 @@ def try_base_extend(ring): # If we don't have a lattice element, try successively # less-desirable ambient spaces until (as a last resort) we # attempt a numerical representation. - from sage.rings.qqbar import AA - from sage.rings.real_mpfr import RR + rings = [QQ] + try: + from sage.rings.qqbar import AA + except ImportError: + pass + else: + rings.append(AA) + try: + from sage.rings.real_mpfr import RR + except ImportError: + pass + else: + rings.append(RR) - for ring in [QQ, AA, RR]: + for ring in rings: p = try_base_extend(ring) if p is not None: return p @@ -1103,7 +1113,7 @@ def plot(self, **options): EXAMPLES:: sage: quadrant = Cone([(1,0), (0,1)]) - sage: quadrant.plot() # needs sage.plot + sage: quadrant.plot() # needs sage.plot sage.symbolic Graphics object consisting of 9 graphics primitives """ tp = ToricPlotter(options, self.lattice().degree(), self.rays()) @@ -2618,6 +2628,7 @@ def ConeFace(atoms, facets): else: # Get face lattice as a sublattice of the ambient one allowed_indices = frozenset(self._ambient_ray_indices) + from sage.graphs.digraph import DiGraph L = DiGraph() origin = \ self._ambient._face_lattice_function().bottom() @@ -3270,11 +3281,12 @@ def is_isomorphic(self, other): We check that :issue:`18613` is fixed:: + sage: # needs sage.graphs sage.groups sage: K = cones.trivial(0) - sage: K.is_isomorphic(K) # needs sage.graphs + sage: K.is_isomorphic(K) True sage: K = cones.trivial(1) - sage: K.is_isomorphic(K) # needs sage.graphs + sage: K.is_isomorphic(K) True sage: K = cones.trivial(2) sage: K.is_isomorphic(K) @@ -3498,7 +3510,7 @@ def plot(self, **options): EXAMPLES:: sage: quadrant = Cone([(1,0), (0,1)]) - sage: quadrant.plot() # needs sage.plot + sage: quadrant.plot() # needs sage.plot sage.symbolic Graphics object consisting of 9 graphics primitives """ # What to do with 3-d cones in 5-d? Use some projection method? diff --git a/src/sage/geometry/fan.py b/src/sage/geometry/fan.py index 0fffcdeb58c..56ce803b897 100644 --- a/src/sage/geometry/fan.py +++ b/src/sage/geometry/fan.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.graphs sage.combinat +# sage.doctest: needs sage.graphs sage.combinat r""" Rational polyhedral fans @@ -241,18 +241,18 @@ import sage.geometry.abc from sage.structure.richcmp import richcmp_method, richcmp -from sage.combinat.combination import Combinations -from sage.combinat.posets.posets import FinitePoset +from sage.misc.lazy_import import lazy_import +lazy_import('sage.combinat.combination', 'Combinations') +lazy_import('sage.combinat.posets.posets', 'FinitePoset') from sage.geometry.cone import (_ambient_space_point, Cone, ConvexRationalPolyhedralCone, IntegralRayCollection, normalize_rays) -from sage.geometry.hasse_diagram import lattice_from_incidences +lazy_import('sage.geometry.hasse_diagram', 'lattice_from_incidences') from sage.geometry.point_collection import PointCollection from sage.geometry.toric_lattice import ToricLattice, is_ToricLattice -from sage.geometry.toric_plotter import ToricPlotter -from sage.graphs.digraph import DiGraph +lazy_import('sage.geometry.toric_plotter', 'ToricPlotter') from sage.matrix.constructor import matrix from sage.misc.cachefunc import cached_method from sage.misc.timing import walltime @@ -1397,7 +1397,7 @@ def _compute_cone_lattice(self): not even need to check if it is complete:: sage: fan = toric_varieties.P1xP1().fan() # needs palp - sage: fan.cone_lattice() # indirect doctest # needs palp + sage: fan.cone_lattice() # indirect doctest # needs palp Finite lattice containing 10 elements with distinguished linear extension These 10 elements are: 1 origin, 4 rays, 4 generating cones, 1 fan. @@ -1467,6 +1467,7 @@ def FanFace(rays, cones): else: # For general fans we will "merge" face lattices of generating # cones. + from sage.graphs.digraph import DiGraph L = DiGraph() face_to_rays = {} # face |---> (indices of fan rays) rays_to_index = {} # (indices of fan rays) |---> face index diff --git a/src/sage/geometry/fan_morphism.py b/src/sage/geometry/fan_morphism.py index c12f8135027..f1b12612e25 100644 --- a/src/sage/geometry/fan_morphism.py +++ b/src/sage/geometry/fan_morphism.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.graphs, sage.combinat +# sage.doctest: needs sage.combinat sage.graphs r""" Morphisms between toric lattices compatible with fans @@ -85,8 +85,6 @@ from sage.matrix.special import identity_matrix from sage.structure.element import is_Matrix from sage.misc.cachefunc import cached_method -from sage.misc.latex import latex -from sage.misc.misc import walltime from sage.misc.misc_c import prod from sage.modules.free_module_morphism import FreeModuleMorphism from sage.rings.infinity import Infinity @@ -505,6 +503,7 @@ def _latex_(self): 0 & 1 \end{array}\right) : \Sigma^{2} \to \Sigma^{2} """ + from sage.misc.latex import latex return (r"%s : %s \to %s" % (latex(self.matrix()), latex(self.domain_fan()), latex(self.codomain_fan()))) diff --git a/src/sage/geometry/hyperplane_arrangement/arrangement.py b/src/sage/geometry/hyperplane_arrangement/arrangement.py index 19ae8698f8c..95464312388 100644 --- a/src/sage/geometry/hyperplane_arrangement/arrangement.py +++ b/src/sage/geometry/hyperplane_arrangement/arrangement.py @@ -1009,10 +1009,10 @@ def cocharacteristic_polynomial(self): EXAMPLES:: sage: A = hyperplane_arrangements.coordinate(2) - sage: A.cocharacteristic_polynomial() + sage: A.cocharacteristic_polynomial() # needs sage.graphs z^2 + 2*z + 1 sage: B = hyperplane_arrangements.braid(3) - sage: B.cocharacteristic_polynomial() + sage: B.cocharacteristic_polynomial() # needs sage.graphs 2*z^3 + 3*z^2 + z TESTS:: @@ -1059,26 +1059,26 @@ def primitive_eulerian_polynomial(self): EXAMPLES:: sage: A = hyperplane_arrangements.coordinate(2) - sage: A.primitive_eulerian_polynomial() + sage: A.primitive_eulerian_polynomial() # needs sage.graphs z^2 sage: B = hyperplane_arrangements.braid(3) - sage: B.primitive_eulerian_polynomial() + sage: B.primitive_eulerian_polynomial() # needs sage.graphs z^2 + z sage: H = hyperplane_arrangements.Shi(['B',2]).cone() sage: H.is_simplicial() False - sage: H.primitive_eulerian_polynomial() + sage: H.primitive_eulerian_polynomial() # needs sage.graphs z^3 + 11*z^2 + 4*z sage: H = hyperplane_arrangements.graphical(graphs.CycleGraph(4)) - sage: H.primitive_eulerian_polynomial() + sage: H.primitive_eulerian_polynomial() # needs sage.graphs z^3 + 3*z^2 - z We verify Example 2.4 in [BHS2023]_ for `k = 2,3,4,5`:: sage: R. = HyperplaneArrangements(QQ) - sage: for k in range(2,6): + sage: for k in range(2,6): # needs sage.graphs ....: H = R([x+j*y for j in range(k)]) ....: H.primitive_eulerian_polynomial() z^2 @@ -1088,6 +1088,7 @@ def primitive_eulerian_polynomial(self): We verify Equation (4) in [BHS2023]_ on some examples:: + sage: # needs sage.graphs sage: R. = ZZ[] sage: Arr = [hyperplane_arrangements.braid(n) for n in range(2,6)] sage: all(R(A.cocharacteristic_polynomial()(1/(x-1)) * (x-1)^A.dimension()) @@ -1096,10 +1097,11 @@ def primitive_eulerian_polynomial(self): We compute types `H_3` and `F_4` in Table 1 of [BHS2023]_:: + sage: # needs sage.libs.gap sage: W = CoxeterGroup(['H',3], implementation="matrix") sage: A = HyperplaneArrangements(W.base_ring(), tuple(f'x{s}' for s in range(W.rank()))) sage: H = A([[0] + list(r) for r in W.positive_roots()]) - sage: H.is_simplicial() + sage: H.is_simplicial() # needs sage.graphs True sage: H.primitive_eulerian_polynomial() z^3 + 28*z^2 + 16*z @@ -1107,7 +1109,7 @@ def primitive_eulerian_polynomial(self): sage: W = CoxeterGroup(['F',4], implementation="permutation") sage: A = HyperplaneArrangements(QQ, tuple(f'x{s}' for s in range(W.rank()))) sage: H = A([[0] + list(r) for r in W.positive_roots()]) - sage: H.primitive_eulerian_polynomial() # long time + sage: H.primitive_eulerian_polynomial() # long time # needs sage.graphs z^4 + 116*z^3 + 220*z^2 + 48*z We verify Proposition 2.5 in [BHS2023]_ on the braid arrangement @@ -1116,7 +1118,8 @@ def primitive_eulerian_polynomial(self): sage: B = [hyperplane_arrangements.braid(k) for k in range(2,6)] sage: all(H.is_simplicial() for H in B) True - sage: all(c > 0 for H in B for c in H.primitive_eulerian_polynomial().coefficients()) + sage: all(c > 0 for H in B # needs sage.graphs + ....: for c in H.primitive_eulerian_polynomial().coefficients()) True We verify Example 9.4 in [BHS2023]_ showing a hyperplane arrangement @@ -1124,6 +1127,7 @@ def primitive_eulerian_polynomial(self): general, the graphical arrangement of a cycle graph corresponds to the arrangements in Example 9.4):: + sage: # needs sage.graphs sage: H = hyperplane_arrangements.graphical(graphs.CycleGraph(5)) sage: pep = H.primitive_eulerian_polynomial(); pep z^4 + 6*z^3 - 4*z^2 + z diff --git a/src/sage/geometry/hyperplane_arrangement/check_freeness.py b/src/sage/geometry/hyperplane_arrangement/check_freeness.py index e99c8ee9b39..f1691634f69 100644 --- a/src/sage/geometry/hyperplane_arrangement/check_freeness.py +++ b/src/sage/geometry/hyperplane_arrangement/check_freeness.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.libs.singular +# sage.doctest: needs sage.libs.singular r""" Helper Functions For Freeness Of Hyperplane Arrangements diff --git a/src/sage/geometry/hyperplane_arrangement/library.py b/src/sage/geometry/hyperplane_arrangement/library.py index 98b03ceac70..085cdd32e21 100644 --- a/src/sage/geometry/hyperplane_arrangement/library.py +++ b/src/sage/geometry/hyperplane_arrangement/library.py @@ -12,20 +12,14 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.graphs.graph_generators import graphs +from sage.arith.misc import binomial +from sage.geometry.hyperplane_arrangement.arrangement import HyperplaneArrangements from sage.matrix.constructor import matrix, random_matrix +from sage.misc.misc_c import prod from sage.rings.integer_ring import ZZ +from sage.rings.polynomial.polynomial_ring import polygen from sage.rings.rational_field import QQ from sage.rings.semirings.non_negative_integer_semiring import NN -from sage.misc.misc_c import prod - -from sage.combinat.combinat import stirling_number2 -from sage.combinat.root_system.cartan_type import CartanType -from sage.combinat.root_system.root_system import RootSystem -from sage.arith.misc import binomial -from sage.rings.polynomial.polynomial_ring import polygen - -from sage.geometry.hyperplane_arrangement.arrangement import HyperplaneArrangements def make_parent(base_ring, dimension, names=None): @@ -93,9 +87,11 @@ def braid(self, n, K=QQ, names=None): sage: hyperplane_arrangements.braid(4) # needs sage.graphs Arrangement of 6 hyperplanes of dimension 4 and rank 3 """ + from sage.graphs.graph_generators import graphs + x = polygen(QQ, 'x') A = self.graphical(graphs.CompleteGraph(n), K, names=names) - charpoly = prod(x-i for i in range(n)) + charpoly = prod(x - i for i in range(n)) A.characteristic_polynomial.set_cache(charpoly) return A @@ -278,10 +274,11 @@ def Coxeter(self, data, K=QQ, names=None): If the Cartan type is not crystallographic, the Coxeter arrangement is not implemented yet:: - sage: hyperplane_arrangements.Coxeter("H3") + sage: hyperplane_arrangements.Coxeter("H3") # needs sage.libs.gap Traceback (most recent call last): ... - NotImplementedError: Coxeter arrangements are not implemented for non crystallographic Cartan types + NotImplementedError: Coxeter arrangements are not implemented + for non crystallographic Cartan types The characteristic polynomial is pre-computed using the results of Terao, see [Ath2000]_:: @@ -290,7 +287,10 @@ def Coxeter(self, data, K=QQ, names=None): sage: hyperplane_arrangements.Coxeter("A3").characteristic_polynomial() x^3 - 6*x^2 + 11*x - 6 """ + from sage.combinat.root_system.cartan_type import CartanType + from sage.combinat.root_system.root_system import RootSystem from sage.combinat.root_system.weyl_group import WeylGroup + if data in NN: cartan_type = CartanType(["A", data - 1]) else: @@ -492,6 +492,8 @@ def Ish(self, n, K=QQ, names=None): - [AR2012]_ """ + from sage.combinat.combinat import stirling_number2 + H = make_parent(K, n, names) x = H.gens() hyperplanes = [] @@ -541,7 +543,7 @@ def IshB(self, n, K=QQ, names=None): Hyperplane t0 + 0*t1 + 0, Hyperplane t0 + 0*t1 + 1, Hyperplane t0 + t1 + 0) - sage: a.cone().is_free() + sage: a.cone().is_free() # needs sage.libs.singular True .. PLOT:: @@ -664,6 +666,8 @@ def semiorder(self, n, K=QQ, names=None): sage: h.characteristic_polynomial() # long time x^5 - 20*x^4 + 180*x^3 - 790*x^2 + 1380*x """ + from sage.combinat.combinat import stirling_number2 + H = make_parent(K, n, names) x = H.gens() hyperplanes = [] @@ -778,6 +782,9 @@ def Shi(self, data, K=QQ, names=None, m=1): sage: h.characteristic_polynomial() x^3 - 54*x^2 + 972*x - 5832 """ + from sage.combinat.root_system.cartan_type import CartanType + from sage.combinat.root_system.root_system import RootSystem + if data in NN: cartan_type = CartanType(["A", data - 1]) else: diff --git a/src/sage/geometry/hyperplane_arrangement/plot.py b/src/sage/geometry/hyperplane_arrangement/plot.py index be468c111bc..c7b413114e6 100644 --- a/src/sage/geometry/hyperplane_arrangement/plot.py +++ b/src/sage/geometry/hyperplane_arrangement/plot.py @@ -115,7 +115,6 @@ lazy_import("sage.plot.text", "text") lazy_import("sage.plot.point", "point") lazy_import("sage.plot.plot", "parametric_plot") -from sage.symbolic.ring import SR def plot(hyperplane_arrangement, **kwds): @@ -423,6 +422,7 @@ def plot_hyperplane(hyperplane, **kwds): elif hyperplane.dimension() == 1: # a line in the plane pnt = hyperplane.point() w = hyperplane.linear_part().matrix() + from sage.symbolic.ring import SR t = SR.var('t') if ranges_set: if isinstance(ranges, (list, tuple)): @@ -443,6 +443,7 @@ def plot_hyperplane(hyperplane, **kwds): elif hyperplane.dimension() == 2: # a plane in 3-space pnt = hyperplane.point() w = hyperplane.linear_part().matrix() + from sage.symbolic.ring import SR s, t = SR.var('s t') if ranges_set: if isinstance(ranges, (list, tuple)): diff --git a/src/sage/geometry/lattice_polytope.py b/src/sage/geometry/lattice_polytope.py index 666548b9f39..7e22a5ac9da 100644 --- a/src/sage/geometry/lattice_polytope.py +++ b/src/sage/geometry/lattice_polytope.py @@ -121,18 +121,18 @@ # https://www.gnu.org/licenses/ # **************************************************************************** +from sage.misc.lazy_import import lazy_import +lazy_import('sage.combinat.posets.posets', 'FinitePoset') from sage.arith.misc import GCD as gcd -from sage.combinat.posets.posets import FinitePoset from sage.features.databases import DatabaseReflexivePolytopes from sage.geometry.cone import _ambient_space_point, integral_length -from sage.geometry.hasse_diagram import lattice_from_incidences +lazy_import('sage.geometry.hasse_diagram', 'lattice_from_incidences') from sage.geometry.point_collection import (PointCollection, is_PointCollection, read_palp_point_collection) from sage.geometry.toric_lattice import ToricLattice, is_ToricLattice -from sage.groups.perm_gps.permgroup_named import SymmetricGroup +lazy_import('sage.groups.perm_gps.permgroup_named', 'SymmetricGroup') -from sage.misc.lazy_import import lazy_import from sage.features import PythonModule from sage.features.palp import PalpExecutable lazy_import('ppl', ['C_Polyhedron', 'Generator_System', 'Linear_Expression'], @@ -146,7 +146,7 @@ from sage.misc.flatten import flatten from sage.misc.temporary_file import tmp_filename from sage.modules.free_module_element import vector -from sage.numerical.mip import MixedIntegerLinearProgram +lazy_import('sage.numerical.mip', 'MixedIntegerLinearProgram') lazy_import("sage.plot.plot3d.index_face_set", "IndexFaceSet") lazy_import("sage.plot.plot3d.all", ["line3d", "point3d"]) lazy_import("sage.plot.plot3d.shapes2", "text3d") diff --git a/src/sage/geometry/polyhedral_complex.py b/src/sage/geometry/polyhedral_complex.py index 981404eb174..586530ccdd8 100644 --- a/src/sage/geometry/polyhedral_complex.py +++ b/src/sage/geometry/polyhedral_complex.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.graphs +# sage.doctest: needs sage.graphs r""" Finite polyhedral complexes diff --git a/src/sage/geometry/polyhedron/backend_cdd_rdf.py b/src/sage/geometry/polyhedron/backend_cdd_rdf.py index 756e8df7b4a..72def8849ad 100644 --- a/src/sage/geometry/polyhedron/backend_cdd_rdf.py +++ b/src/sage/geometry/polyhedron/backend_cdd_rdf.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.rings.real_double +# sage.doctest: needs sage.rings.real_double r""" The cdd backend for polyhedral computations, floating point version diff --git a/src/sage/geometry/polyhedron/backend_polymake.py b/src/sage/geometry/polyhedron/backend_polymake.py index a2bce697e1c..0c19d8b5c91 100644 --- a/src/sage/geometry/polyhedron/backend_polymake.py +++ b/src/sage/geometry/polyhedron/backend_polymake.py @@ -96,8 +96,8 @@ class Polyhedron_polymake(Polyhedron_base): Quadratic fields work:: - sage: V = polytopes.dodecahedron().vertices_list() # needs sage.rings.number_field - sage: Polyhedron(vertices=V, backend='polymake') # optional - jupymake, needs sage.rings.number_field + sage: V = polytopes.dodecahedron().vertices_list() # needs sage.groups sage.rings.number_field + sage: Polyhedron(vertices=V, backend='polymake') # optional - jupymake, needs sage.groups sage.rings.number_field A 3-dimensional polyhedron in (Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?)^3 diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index 82e92b72bd3..67ac7d9ec9e 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -32,6 +32,7 @@ from sage.misc.cachefunc import cached_method +import sage.rings.abc from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.matrix.constructor import matrix @@ -239,7 +240,7 @@ def to_linear_program(self, solver=None, return_variable=False, base_ring=None): Irrational algebraic linear program over an embedded number field:: - sage: # needs sage.rings.number_field + sage: # needs sage.groups sage.rings.number_field sage: p = polytopes.icosahedron() sage: lp, x = p.to_linear_program(return_variable=True) sage: lp.set_objective(x[0] + x[1] + x[2]) @@ -248,21 +249,23 @@ def to_linear_program(self, solver=None, return_variable=False, base_ring=None): Same example with floating point:: + sage: # needs sage.groups sage.rings.number_field sage: lp, x = p.to_linear_program(return_variable=True, base_ring=RDF) sage: lp.set_objective(x[0] + x[1] + x[2]) - sage: lp.solve() # tol 1e-5 # needs sage.rings.number_field + sage: lp.solve() # tol 1e-5 1.3090169943749475 Same example with a specific floating point solver:: + sage: # needs sage.groups sage.rings.number_field sage: lp, x = p.to_linear_program(return_variable=True, solver='GLPK') sage: lp.set_objective(x[0] + x[1] + x[2]) - sage: lp.solve() # tol 1e-8 # needs sage.rings.number_field + sage: lp.solve() # tol 1e-8 1.3090169943749475 Irrational algebraic linear program over `AA`:: - sage: # needs sage.rings.number_field + sage: # needs sage.groups sage.rings.number_field sage: p = polytopes.icosahedron(base_ring=AA) sage: lp, x = p.to_linear_program(return_variable=True) sage: lp.set_objective(x[0] + x[1] + x[2]) @@ -277,8 +280,8 @@ def to_linear_program(self, solver=None, return_variable=False, base_ring=None): sage: p.to_linear_program().polyhedron() == p True - sage: p = polytopes.icosahedron() # needs sage.rings.number_field - sage: p.to_linear_program(solver='PPL') # needs sage.rings.number_field + sage: p = polytopes.icosahedron() # needs sage.groups sage.rings.number_field + sage: p.to_linear_program(solver='PPL') # needs sage.groups sage.rings.number_field Traceback (most recent call last): ... TypeError: The PPL backend only supports rational data. @@ -354,11 +357,11 @@ def boundary_complex(self): ... ValueError: self should be compact """ - from sage.topology.simplicial_complex import SimplicialComplex if not self.is_compact(): raise ValueError("self should be compact") if self.is_simplicial(): + from sage.topology.simplicial_complex import SimplicialComplex inc_mat_cols = self.incidence_matrix().columns() ineq_indices = [inc_mat_cols[i].nonzero_positions() for i in range(self.n_Hrepresentation()) @@ -772,8 +775,8 @@ def face_fan(self): The polytope has to have rational coordinates:: - sage: S = polytopes.dodecahedron() # needs sage.rings.number_field - sage: S.face_fan() # needs sage.rings.number_field + sage: S = polytopes.dodecahedron() # needs sage.groups sage.rings.number_field + sage: S.face_fan() # needs sage.groups sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: face fan handles only polytopes over the rationals @@ -1167,15 +1170,16 @@ def _polymake_init_(self): Algebraic polyhedron:: - sage: P = polytopes.dodecahedron(); P # needs sage.rings.number_field + sage: # needs sage.groups sage.rings.number_field + sage: P = polytopes.dodecahedron(); P A 3-dimensional polyhedron in (Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?)^3 defined as the convex hull of 20 vertices - sage: print("Maybe recompile warning"); PP = polymake(P); PP # optional - jupymake, needs sage.rings.number_field + sage: print("Maybe recompile warning"); PP = polymake(P); PP # optional - jupymake Maybe recompile warning... Polytope>[...] - sage: sorted(PP.VERTICES[:], key=repr)[0] # optional - jupymake, needs sage.rings.number_field + sage: sorted(PP.VERTICES[:], key=repr)[0] # optional - jupymake 1 -1+1r5 -4+2r5 0 Floating-point polyhedron:: diff --git a/src/sage/geometry/polyhedron/base0.py b/src/sage/geometry/polyhedron/base0.py index ea6a08837c5..b2e2ece5467 100644 --- a/src/sage/geometry/polyhedron/base0.py +++ b/src/sage/geometry/polyhedron/base0.py @@ -577,10 +577,10 @@ def is_compact(self): EXAMPLES:: - sage: p = polytopes.icosahedron() # needs sage.rings.number_field - sage: p.is_compact() # needs sage.rings.number_field + sage: p = polytopes.icosahedron() # needs sage.groups sage.rings.number_field + sage: p.is_compact() # needs sage.groups sage.rings.number_field True - sage: p = Polyhedron(ieqs = [[0,1,0,0],[0,0,1,0],[0,0,0,1],[1,-1,0,0]]) + sage: p = Polyhedron(ieqs=[[0,1,0,0],[0,0,1,0],[0,0,0,1],[1,-1,0,0]]) sage: p.is_compact() False """ @@ -1314,11 +1314,11 @@ def backend(self): EXAMPLES:: - sage: triangle = Polyhedron(vertices = [[1, 0], [0, 1], [1, 1]]) + sage: triangle = Polyhedron(vertices=[[1, 0], [0, 1], [1, 1]]) sage: triangle.backend() 'ppl' - sage: D = polytopes.dodecahedron() # needs sage.rings.number_field - sage: D.backend() # needs sage.rings.number_field + sage: D = polytopes.dodecahedron() # needs sage.groups sage.rings.number_field + sage: D.backend() # needs sage.groups sage.rings.number_field 'field' sage: P = Polyhedron([[1.23]]) sage: P.backend() diff --git a/src/sage/geometry/polyhedron/base4.py b/src/sage/geometry/polyhedron/base4.py index bc31ab76102..3f8fe215749 100644 --- a/src/sage/geometry/polyhedron/base4.py +++ b/src/sage/geometry/polyhedron/base4.py @@ -110,18 +110,18 @@ def vertex_facet_graph(self, labels=True): An inequality (0, 0, 1) x + 1 >= 0, An inequality (0, 1, 0) x + 1 >= 0, An inequality (1, 0, 0) x + 1 >= 0] - sage: G.automorphism_group().is_isomorphic(P.hasse_diagram().automorphism_group()) + sage: G.automorphism_group().is_isomorphic(P.hasse_diagram().automorphism_group()) # needs sage.groups True sage: O = polytopes.octahedron(); O A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 6 vertices sage: O.vertex_facet_graph() Digraph on 14 vertices sage: H = O.vertex_facet_graph() - sage: G.is_isomorphic(H) + sage: G.is_isomorphic(H) # needs sage.groups False sage: G2 = copy(G) sage: G2.reverse_edges(G2.edges(sort=True)) - sage: G2.is_isomorphic(H) + sage: G2.is_isomorphic(H) # needs sage.groups True TESTS: @@ -169,7 +169,7 @@ def vertex_graph(self, **kwds): sage: g3 = polytopes.hypercube(3).vertex_graph(); g3 Graph on 8 vertices - sage: g3.automorphism_group().cardinality() + sage: g3.automorphism_group().cardinality() # needs sage.groups 48 sage: s4 = polytopes.simplex(4).vertex_graph(); s4 Graph on 5 vertices @@ -645,21 +645,22 @@ def combinatorial_automorphism_group(self, vertex_graph_only=False): EXAMPLES:: sage: quadrangle = Polyhedron(vertices=[(0,0),(1,0),(0,1),(2,3)]) - sage: quadrangle.combinatorial_automorphism_group().is_isomorphic( + sage: quadrangle.combinatorial_automorphism_group().is_isomorphic( # needs sage.groups ....: groups.permutation.Dihedral(4)) True - sage: quadrangle.restricted_automorphism_group() + sage: quadrangle.restricted_automorphism_group() # needs sage.groups Permutation Group with generators [()] Permutations of the vertex graph only exchange vertices with vertices:: sage: P = Polyhedron(vertices=[(1,0), (1,1)], rays=[(1,0)]) - sage: P.combinatorial_automorphism_group(vertex_graph_only=True) + sage: P.combinatorial_automorphism_group(vertex_graph_only=True) # needs sage.groups Permutation Group with generators [(A vertex at (1,0),A vertex at (1,1))] This shows an example of two polytopes whose vertex-edge graphs are isomorphic, but their face lattices are not isomorphic:: + sage: # needs sage.groups sage: Q = Polyhedron([[-123984206864/2768850730773, -101701330976/922950243591, -64154618668/2768850730773, -2748446474675/2768850730773], ....: [-11083969050/98314591817, -4717557075/98314591817, -32618537490/98314591817, -91960210208/98314591817], ....: [-9690950/554883199, -73651220/554883199, 1823050/554883199, -549885101/554883199], @@ -680,6 +681,7 @@ def combinatorial_automorphism_group(self, vertex_graph_only=False): The automorphism group of the face lattice is isomorphic to the combinatorial automorphism group:: + sage: # needs sage.groups sage: CG = C.hasse_diagram().automorphism_group() sage: C.combinatorial_automorphism_group().is_isomorphic(CG) True @@ -799,6 +801,7 @@ def restricted_automorphism_group(self, output="abstract"): A cross-polytope example:: + sage: # needs sage.groups sage: P = polytopes.cross_polytope(3) sage: P.restricted_automorphism_group() == PermutationGroup([[(3,4)], [(2,3),(4,5)],[(2,5)],[(1,2),(5,6)],[(1,6)]]) True @@ -808,6 +811,7 @@ def restricted_automorphism_group(self, output="abstract"): We test groups for equality in a fool-proof way; they can have different generators, etc:: + sage: # needs sage.groups sage: poly_g = P.restricted_automorphism_group(output="matrix") sage: matrix_g = MatrixGroup([matrix(QQ,t) for t in mgens]) sage: all(t.matrix() in poly_g for t in matrix_g.gens()) @@ -817,6 +821,7 @@ def restricted_automorphism_group(self, output="abstract"): 24-cell example:: + sage: # needs sage.groups sage: P24 = polytopes.twenty_four_cell() sage: AutP24 = P24.restricted_automorphism_group() sage: PermutationGroup([ @@ -829,6 +834,7 @@ def restricted_automorphism_group(self, output="abstract"): Here is the quadrant example mentioned in the beginning:: + sage: # needs sage.groups sage: P = Polyhedron(rays=[(1,0),(0,1)]) sage: P.Vrepresentation() (A vertex at (0, 0), A ray in the direction (0, 1), A ray in the direction (1, 0)) @@ -837,11 +843,11 @@ def restricted_automorphism_group(self, output="abstract"): Also, the polyhedron need not be full-dimensional:: + sage: # needs sage.groups sage: P = Polyhedron(vertices=[(1,2,3,4,5),(7,8,9,10,11)]) sage: P.restricted_automorphism_group() Permutation Group with generators [(1,2)] - sage: G = P.restricted_automorphism_group(output="matrixlist") - sage: G + sage: G = P.restricted_automorphism_group(output="matrixlist"); G ( [1 0 0 0 0 0] [ -87/55 -82/55 -2/5 38/55 98/55 12/11] [0 1 0 0 0 0] [-142/55 -27/55 -2/5 38/55 98/55 12/11] @@ -850,8 +856,7 @@ def restricted_automorphism_group(self, output="abstract"): [0 0 0 0 1 0] [-142/55 -82/55 -2/5 38/55 153/55 12/11] [0 0 0 0 0 1], [ 0 0 0 0 0 1] ) - sage: g = AffineGroup(5, QQ)(G[1]) - sage: g + sage: g = AffineGroup(5, QQ)(G[1]); g [ -87/55 -82/55 -2/5 38/55 98/55] [12/11] [-142/55 -27/55 -2/5 38/55 98/55] [12/11] x |-> [-142/55 -82/55 3/5 38/55 98/55] x + [12/11] @@ -873,6 +878,7 @@ def restricted_automorphism_group(self, output="abstract"): dihedral group with 6 elements, `D_6`, as its automorphism group:: + sage: # needs sage.groups sage: initial_points = [vector([1,0]), vector([0,1]), vector([-2,-1])] sage: points = initial_points sage: Polyhedron(vertices=points).restricted_automorphism_group() @@ -890,8 +896,11 @@ def restricted_automorphism_group(self, output="abstract"): The ``output="matrixlist"`` can be used over fields without a complete implementation of matrix groups:: + sage: # needs sage.groups sage.rings.number_field sage: P = polytopes.dodecahedron(); P - A 3-dimensional polyhedron in (Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?)^3 defined as the convex hull of 20 vertices + A 3-dimensional polyhedron in (Number Field in sqrt5 with defining + polynomial x^2 - 5 with sqrt5 = 2.236067977499790?)^3 + defined as the convex hull of 20 vertices sage: G = P.restricted_automorphism_group(output="matrixlist") sage: len(G) 120 @@ -899,8 +908,9 @@ def restricted_automorphism_group(self, output="abstract"): Floating-point computations are supported with a simple fuzzy zero implementation:: - sage: P = Polyhedron(vertices=[(1/3,0,0,1),(0,1/4,0,1),(0,0,1/5,1)], base_ring=RDF) - sage: P.restricted_automorphism_group() + sage: P = Polyhedron(vertices=[(1/3,0,0,1),(0,1/4,0,1),(0,0,1/5,1)], + ....: base_ring=RDF) + sage: P.restricted_automorphism_group() # needs sage.groups Permutation Group with generators [(2,3), (1,2)] sage: len(P.restricted_automorphism_group(output="matrixlist")) 6 @@ -908,7 +918,7 @@ def restricted_automorphism_group(self, output="abstract"): TESTS:: sage: P = Polyhedron(vertices=[(1,0), (1,1)], rays=[(1,0)]) - sage: P.restricted_automorphism_group(output="permutation") + sage: P.restricted_automorphism_group(output="permutation") # needs sage.groups Permutation Group with generators [(1,2)] sage: P.restricted_automorphism_group(output="matrix") Matrix group over Rational Field with 1 generators ( @@ -919,7 +929,8 @@ def restricted_automorphism_group(self, output="abstract"): sage: P.restricted_automorphism_group(output="foobar") Traceback (most recent call last): ... - ValueError: unknown output 'foobar', valid values are ('abstract', 'permutation', 'matrix', 'matrixlist') + ValueError: unknown output 'foobar', valid values are + ('abstract', 'permutation', 'matrix', 'matrixlist') Check that :issue:`28828` is fixed:: diff --git a/src/sage/geometry/polyhedron/base6.py b/src/sage/geometry/polyhedron/base6.py index aaa18f5b541..f8a14fda49e 100644 --- a/src/sage/geometry/polyhedron/base6.py +++ b/src/sage/geometry/polyhedron/base6.py @@ -1548,13 +1548,16 @@ def _test_affine_hull_projection(self, tester=None, verbose=False, **options): orthogonal=True, extend=True)) if AA is not None: - data_sets.append(self.affine_hull_projection(return_all_data=True, - orthonormal=True, - extend=True)) - data_sets.append(self.affine_hull_projection(return_all_data=True, - orthonormal=True, - extend=True, - minimal=True)) + try: + data_sets.append(self.affine_hull_projection(return_all_data=True, + orthonormal=True, + extend=True)) + data_sets.append(self.affine_hull_projection(return_all_data=True, + orthonormal=True, + extend=True, + minimal=True)) + except ModuleNotFoundError: + pass for i, data in enumerate(data_sets): if verbose: diff --git a/src/sage/geometry/polyhedron/base7.py b/src/sage/geometry/polyhedron/base7.py index 55f9d23ea0b..aca38a58404 100644 --- a/src/sage/geometry/polyhedron/base7.py +++ b/src/sage/geometry/polyhedron/base7.py @@ -521,9 +521,9 @@ def volume(self, measure='ambient', engine='auto', **kwds): sage: P5.volume() # needs sage.rings.number_field 2.377641290737884? - sage: polytopes.icosahedron().volume() # needs sage.rings.number_field + sage: polytopes.icosahedron().volume() # needs sage.groups sage.rings.number_field 5/12*sqrt5 + 5/4 - sage: numerical_approx(_) # abs tol 1e9 # needs sage.rings.number_field + sage: numerical_approx(_) # abs tol 1e9 # needs sage.groups sage.rings.number_field 2.18169499062491 When considering lower-dimensional polytopes, we can ask for the @@ -861,8 +861,8 @@ def integrate(self, function, measure='ambient', **kwds): Testing a polytope with non-rational vertices:: - sage: P = polytopes.icosahedron() # needs sage.rings.number_field - sage: P.integrate(x^2*y^2*z^2) # optional - latte_int, needs sage.rings.number_field + sage: P = polytopes.icosahedron() # needs sage.groups sage.rings.number_field + sage: P.integrate(x^2*y^2*z^2) # optional - latte_int, needs sage.groups sage.rings.number_field Traceback (most recent call last): ... TypeError: the base ring must be ZZ, QQ, or RDF diff --git a/src/sage/geometry/polyhedron/base_QQ.py b/src/sage/geometry/polyhedron/base_QQ.py index ff0872b7dd7..c53797372f2 100644 --- a/src/sage/geometry/polyhedron/base_QQ.py +++ b/src/sage/geometry/polyhedron/base_QQ.py @@ -155,7 +155,7 @@ def integral_points_count(self, verbose=False, use_Hrepresentation=False, ....: x = lp.new_variable(nonnegative=True) ....: lp.add_constraint(lp.sum(fibonacci(i+3)*x[i] for i in range(d)) <= b) ....: return lp.polyhedron(backend=backend) - sage: fibonacci_knapsack(20, 12).integral_points_count() # does not finish with preprocess=False # needs sage.combinat + sage: fibonacci_knapsack(20, 12).integral_points_count() # does not finish with preprocess=False # needs sage.combinat 33 TESTS: diff --git a/src/sage/geometry/polyhedron/base_RDF.py b/src/sage/geometry/polyhedron/base_RDF.py index b3ba587746e..ddd11e997d1 100644 --- a/src/sage/geometry/polyhedron/base_RDF.py +++ b/src/sage/geometry/polyhedron/base_RDF.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.rings.real_double +# sage.doctest: needs sage.rings.real_double """ Base class for polyhedra over ``RDF`` diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx index ca5634d31a7..99cfef13db2 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx @@ -179,10 +179,14 @@ from cysignals.memory cimport check_allocarray, sig_free from cysignals.signals cimport sig_check from memory_allocator cimport MemoryAllocator +from sage.misc.lazy_import import LazyImport + from sage.geometry.polyhedron.combinatorial_polyhedron.base cimport CombinatorialPolyhedron from sage.geometry.polyhedron.combinatorial_polyhedron.conversions cimport bit_rep_to_Vrep_list from sage.geometry.polyhedron.combinatorial_polyhedron.face_list_data_structure cimport * -from sage.geometry.polyhedron.face import combinatorial_face_to_polyhedral_face, PolyhedronFace + +combinatorial_face_to_polyhedral_face = LazyImport('sage.geometry.polyhedron.face', 'combinatorial_face_to_polyhedral_face') +PolyhedronFace = LazyImport('sage.geometry.polyhedron.face', 'PolyhedronFace') cdef extern from "Python.h": @@ -635,7 +639,7 @@ cdef class FaceIterator_base(SageObject): If the iterator has already been used, it must be reset before:: - sage: # needs sage.rings.number_field + sage: # needs sage.groups sage.rings.number_field sage: P = polytopes.dodecahedron() sage: it = P.face_generator() sage: _ = next(it), next(it) @@ -721,7 +725,7 @@ cdef class FaceIterator_base(SageObject): If the iterator has already been used, it must be reset before:: - sage: # needs sage.rings.number_field + sage: # needs sage.groups sage.rings.number_field sage: P = polytopes.dodecahedron() sage: it = P.face_generator() sage: _ = next(it), next(it) @@ -846,7 +850,7 @@ cdef class FaceIterator_base(SageObject): The face iterator must not have the output dimension specified:: - sage: # needs sage.rings.number_field + sage: # needs sage.groups sage.rings.number_field sage: P = polytopes.dodecahedron() sage: it = P.face_generator(2) sage: it._meet_of_coatoms(1,2) @@ -956,7 +960,7 @@ cdef class FaceIterator_base(SageObject): If the iterator has already been used, it must be reset before:: - sage: # needs sage.rings.number_field + sage: # needs sage.groups sage.rings.number_field sage: P = polytopes.dodecahedron() sage: it = P.face_generator() sage: _ = next(it), next(it) @@ -972,7 +976,7 @@ cdef class FaceIterator_base(SageObject): The face iterator must not have the output dimension specified:: - sage: # needs sage.rings.number_field + sage: # needs sage.groups sage.rings.number_field sage: P = polytopes.dodecahedron() sage: it = P.face_generator(2) sage: it._join_of_atoms(1,2) diff --git a/src/sage/geometry/polyhedron/constructor.py b/src/sage/geometry/polyhedron/constructor.py index ef95c2fb457..5a5db0b43ae 100644 --- a/src/sage/geometry/polyhedron/constructor.py +++ b/src/sage/geometry/polyhedron/constructor.py @@ -297,8 +297,6 @@ import sage.geometry.abc from sage.rings.integer_ring import ZZ -from sage.rings.real_double import RDF -from sage.rings.real_mpfr import RR from .misc import _make_listlist, _common_length_of @@ -743,6 +741,14 @@ def Polyhedron(vertices=None, rays=None, lines=None, except ImportError: SR = None if base_ring is not SR and not base_ring.is_exact(): + try: + from sage.rings.real_double import RDF + except ImportError: + RDF = None + try: + from sage.rings.real_mpfr import RR + except ImportError: + RR = None # TODO: remove this hack? if base_ring is RR: base_ring = RDF diff --git a/src/sage/geometry/polyhedron/generating_function.py b/src/sage/geometry/polyhedron/generating_function.py index 7a33bd528b9..89d86058c2d 100644 --- a/src/sage/geometry/polyhedron/generating_function.py +++ b/src/sage/geometry/polyhedron/generating_function.py @@ -1,4 +1,4 @@ -# sage.doctest: optional - sage.combinat +# sage.doctest: needs sage.combinat r""" Generating Function of Polyhedron's Integral Points diff --git a/src/sage/geometry/toric_lattice.py b/src/sage/geometry/toric_lattice.py index 2759a2b1281..382c82a1e72 100644 --- a/src/sage/geometry/toric_lattice.py +++ b/src/sage/geometry/toric_lattice.py @@ -147,7 +147,8 @@ from sage.geometry.toric_lattice_element import (ToricLatticeElement, is_ToricLatticeElement) -from sage.geometry.toric_plotter import ToricPlotter +from sage.misc.lazy_import import lazy_import +lazy_import('sage.geometry.toric_plotter', 'ToricPlotter') from sage.misc.latex import latex from sage.structure.all import parent from sage.structure.richcmp import (richcmp_method, richcmp, rich_to_bool, diff --git a/src/sage/geometry/toric_lattice_element.pyx b/src/sage/geometry/toric_lattice_element.pyx index 8a2f87762eb..8d201ed5f86 100644 --- a/src/sage/geometry/toric_lattice_element.pyx +++ b/src/sage/geometry/toric_lattice_element.pyx @@ -96,7 +96,6 @@ Or you can create a homomorphism from one lattice to any other:: from sage.libs.gmp.mpz cimport * -from sage.geometry.toric_plotter import ToricPlotter from sage.modules.vector_integer_dense cimport Vector_integer_dense from sage.structure.coerce_exceptions import CoercionException from sage.structure.element cimport Vector @@ -397,6 +396,7 @@ cdef class ToricLatticeElement(Vector_integer_dense): sage: n.plot() # needs sage.plot Graphics3d Object """ + from sage.geometry.toric_plotter import ToricPlotter tp = ToricPlotter(options, self.parent().degree()) tp.adjust_options() return tp.plot_points([self]) diff --git a/src/sage/geometry/toric_plotter.py b/src/sage/geometry/toric_plotter.py index 2943daa49bd..0ee35b8b8c0 100644 --- a/src/sage/geometry/toric_plotter.py +++ b/src/sage/geometry/toric_plotter.py @@ -49,10 +49,10 @@ from copy import copy from math import pi -from sage.functions.all import arccos, arctan2, ceil, floor +from sage.arith.misc import integer_ceil as ceil, integer_floor as floor from sage.geometry.polyhedron.constructor import Polyhedron -from sage.modules.free_module_element import vector from sage.misc.lazy_import import lazy_import +from sage.modules.free_module_element import vector lazy_import("sage.plot.all", ["Color", "Graphics", "arrow", "disk", "line", "point", "polygon", "rainbow", "text"]) @@ -404,7 +404,7 @@ def plot_generators(self): thickness = self.generator_thickness zorder = self.generator_zorder for generator, ray, color in zip(generators, self.rays, colors): - if ray.norm() < generator.norm(): + if ray.dot_product(ray) < generator.dot_product(generator): result += line([origin, ray], color=color, thickness=thickness, zorder=zorder, **extra_options) @@ -496,7 +496,7 @@ def plot_lattice(self): for z in range(ceil(self.zmin), floor(self.zmax) + 1)) if self.mode == "round": r = 1.01 * self.radius # To make sure integer values work OK. - points = (pt for pt in points if vector(pt).norm() <= r) + points = (pt for pt in points if vector(pt).dot_product(vector(pt)) <= r) f = self.lattice_filter if f is not None: points = (pt for pt in points if f(pt)) @@ -1113,6 +1113,8 @@ def sector(ray1, ray2, **extra_options): sage: sector((3,2,1), (1,2,3)) # needs sage.plot Graphics3d Object """ + from sage.functions.all import arccos, arctan2 + ray1 = vector(RDF, ray1) ray2 = vector(RDF, ray2) r = ray1.norm() diff --git a/src/sage/geometry/triangulation/element.py b/src/sage/geometry/triangulation/element.py index e8c8d7e1a51..3e6e0ed152d 100644 --- a/src/sage/geometry/triangulation/element.py +++ b/src/sage/geometry/triangulation/element.py @@ -46,7 +46,6 @@ from sage.modules.free_module_element import vector from sage.misc.cachefunc import cached_method from sage.sets.set import Set -from sage.graphs.graph import Graph ######################################################################## @@ -922,5 +921,6 @@ def adjacency_graph(self): """ vertices = [Set(_) for _ in list(self)] + from sage.graphs.graph import Graph return Graph([vertices, lambda x,y: len(x-y) == 1]) diff --git a/src/sage/geometry/triangulation/point_configuration.py b/src/sage/geometry/triangulation/point_configuration.py index 89d486b1e4f..b71ae4cb348 100644 --- a/src/sage/geometry/triangulation/point_configuration.py +++ b/src/sage/geometry/triangulation/point_configuration.py @@ -182,10 +182,12 @@ # https://www.gnu.org/licenses/ ######################################################################## +import itertools + from sage.structure.unique_representation import UniqueRepresentation from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import -from sage.combinat.combination import Combinations from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.matrix.constructor import matrix @@ -1632,7 +1634,7 @@ def make_cotriang(basepts): triangulation.update([ frozenset([head]).union(tail) ]) nonminimal = set() - for rel in Combinations(triangulation, 2): + for rel in itertools.combinations(triangulation, 2): if rel[0].issubset(rel[1]): nonminimal.update([rel[1]]) if rel[1].issubset(rel[0]): diff --git a/src/sage/geometry/voronoi_diagram.py b/src/sage/geometry/voronoi_diagram.py index 0cea1e91377..a4c110ff647 100644 --- a/src/sage/geometry/voronoi_diagram.py +++ b/src/sage/geometry/voronoi_diagram.py @@ -19,8 +19,6 @@ import sage.rings.abc from sage.geometry.triangulation.point_configuration import PointConfiguration from sage.modules.free_module_element import vector -from sage.misc.lazy_import import lazy_import -lazy_import("sage.plot.all", ["line", "point", "rainbow", "plot"]) class VoronoiDiagram(SageObject): @@ -61,9 +59,9 @@ class VoronoiDiagram(SageObject): If the vertices are not converted to ``AA`` before, the method throws an error:: - sage: polytopes.dodecahedron().vertices_list()[0][0].parent() # needs sage.rings.number_field + sage: polytopes.dodecahedron().vertices_list()[0][0].parent() # needs sage.groups sage.rings.number_field Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790? - sage: VoronoiDiagram(polytopes.dodecahedron().vertices_list()) # needs sage.rings.number_field + sage: VoronoiDiagram(polytopes.dodecahedron().vertices_list()) # needs sage.groups sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: Base ring of the Voronoi diagram must be @@ -286,6 +284,7 @@ def plot(self, cell_colors=None, **kwds): NotImplementedError: Plotting of 3-dimensional Voronoi diagrams not implemented """ + from sage.plot.all import line, point, rainbow, plot if self.ambient_dim() == 2: S = line([])