From ec2f889d2da661333b91609ce6d1bcee418dea16 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 10 Jun 2024 21:57:40 -0700 Subject: [PATCH 1/6] src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py: Doctest cosmetics --- .../finite_dimensional_algebra_ideal.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py index 100a3d335f3..72744da3904 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py @@ -39,7 +39,8 @@ class FiniteDimensionalAlgebraIdeal(Ideal_generic): EXAMPLES:: - sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]) + sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), + ....: Matrix([[0, 1], [0, 0]])]) sage: A.ideal(A([0,1])) Ideal (e1) of Finite-dimensional algebra of degree 2 over Finite Field of size 3 """ @@ -47,9 +48,10 @@ def __init__(self, A, gens=None, given_by_matrix=False): """ EXAMPLES:: - sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]) + sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), + ....: Matrix([[0, 1], [0, 0]])]) sage: I = A.ideal(A([0,1])) - sage: TestSuite(I).run(skip="_test_category") # Currently ideals are not using the category framework + sage: TestSuite(I).run(skip="_test_category") # Currently ideals are not using the category framework """ k = A.base_ring() n = A.degree() @@ -76,7 +78,8 @@ def _richcmp_(self, other, op): TESTS:: - sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]) + sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), + ....: Matrix([[0, 1], [0, 0]])]) sage: I = A.ideal(A([1,1])) sage: J = A.ideal(A([0,1])) sage: I == J @@ -86,7 +89,8 @@ def _richcmp_(self, other, op): sage: I == I + J True - sage: A2 = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]) + sage: A2 = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), + ....: Matrix([[0, 1], [0, 0]])]) sage: A is A2 True sage: A == A2 @@ -130,7 +134,8 @@ def __contains__(self, elt): """ EXAMPLES:: - sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]) + sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), + ....: Matrix([[0, 1], [0, 0]])]) sage: J = A.ideal(A([0,1])) sage: A([0,1]) in J True @@ -147,7 +152,8 @@ def basis_matrix(self): EXAMPLES:: - sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]) + sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), + ....: Matrix([[0, 1], [0, 0]])]) sage: I = A.ideal(A([1,1])) sage: I.basis_matrix() [1 0] @@ -162,7 +168,8 @@ def vector_space(self): EXAMPLES:: - sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]) + sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), + ....: Matrix([[0, 1], [0, 0]])]) sage: I = A.ideal(A([1,1])) sage: I.vector_space() Vector space of degree 2 and dimension 2 over Finite Field of size 3 From 52ccee5a3c3c09a92a490f91fcb26013e956226c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 10 Jun 2024 21:59:53 -0700 Subject: [PATCH 2/6] sage.algebras: Doctest cosmetics, # needs --- src/sage/arith/functions.pyx | 10 +++++----- src/sage/arith/misc.py | 4 ++-- src/sage/arith/srange.pyx | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/sage/arith/functions.pyx b/src/sage/arith/functions.pyx index 6e8f3db88a5..92dbc709897 100644 --- a/src/sage/arith/functions.pyx +++ b/src/sage/arith/functions.pyx @@ -39,17 +39,17 @@ def lcm(a, b=None): EXAMPLES:: - sage: lcm(97,100) + sage: lcm(97, 100) 9700 - sage: LCM(97,100) + sage: LCM(97, 100) 9700 - sage: LCM(0,2) + sage: LCM(0, 2) 0 - sage: LCM(-3,-5) + sage: LCM(-3, -5) 15 sage: LCM([1,2,3,4,5]) 60 - sage: v = LCM(range(1,10000)) # *very* fast! + sage: v = LCM(range(1, 10000)) # *very* fast! sage: len(str(v)) 4349 diff --git a/src/sage/arith/misc.py b/src/sage/arith/misc.py index 310f2b0b189..28f81d7b798 100644 --- a/src/sage/arith/misc.py +++ b/src/sage/arith/misc.py @@ -3748,9 +3748,9 @@ def binomial(x, m, **kwds): Some floating point cases -- see :issue:`7562`, :issue:`9633`, and :issue:`12448`:: - sage: binomial(1., 3) + sage: binomial(1., 3) # needs sage.rings.real_mpfr 0.000000000000000 - sage: binomial(-2., 3) + sage: binomial(-2., 3) # needs sage.rings.real_mpfr -4.00000000000000 sage: binomial(0.5r, 5) 0.02734375 diff --git a/src/sage/arith/srange.pyx b/src/sage/arith/srange.pyx index 59c39d8fc2a..51855f9646d 100644 --- a/src/sage/arith/srange.pyx +++ b/src/sage/arith/srange.pyx @@ -234,16 +234,21 @@ def srange(*args, **kwds): sage: srange(1, 10, 1/2) [1, 3/2, 2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2, 8, 17/2, 9, 19/2] + + sage: # needs sage.rings.real_mpfr sage: srange(1, 5, 0.5) - [1.00000000000000, 1.50000000000000, 2.00000000000000, 2.50000000000000, 3.00000000000000, 3.50000000000000, 4.00000000000000, 4.50000000000000] + [1.00000000000000, 1.50000000000000, 2.00000000000000, 2.50000000000000, + 3.00000000000000, 3.50000000000000, 4.00000000000000, 4.50000000000000] sage: srange(0, 1, 0.4) [0.000000000000000, 0.400000000000000, 0.800000000000000] sage: srange(1.0, 5.0, include_endpoint=True) - [1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000, 5.00000000000000] + [1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000, + 5.00000000000000] sage: srange(1.0, 1.1) [1.00000000000000] sage: srange(1.0, 1.0) [] + sage: V = VectorSpace(QQ, 2) # needs sage.modules sage: srange(V([0,0]), V([5,5]), step=V([2,2])) # needs sage.modules [(0, 0), (2, 2), (4, 4)] @@ -264,7 +269,8 @@ def srange(*args, **kwds): sage: srange(0.5, 0.9, 0.1, universe=RDF, include_endpoint=False) [0.5, 0.6, 0.7, 0.7999999999999999] sage: srange(0, 1.1, 0.1, universe=RDF, include_endpoint=True) - [0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999, 1.1] + [0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, + 0.7999999999999999, 0.8999999999999999, 0.9999999999999999, 1.1] sage: srange(0, 0.2, 0.1, universe=RDF, include_endpoint=True) [0.0, 0.1, 0.2] sage: srange(0, 0.3, 0.1, universe=RDF, include_endpoint=True) @@ -275,9 +281,10 @@ def srange(*args, **kwds): sage: Q = RationalField() sage: srange(1, 10, Q('1/2')) [1, 3/2, 2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2, 8, 17/2, 9, 19/2] - sage: srange(1, 5, 0.5) - [1.00000000000000, 1.50000000000000, 2.00000000000000, 2.50000000000000, 3.00000000000000, 3.50000000000000, 4.00000000000000, 4.50000000000000] - sage: srange(0, 1, 0.4) + sage: srange(1, 5, 0.5) # needs sage.rings.real_mpfr + [1.00000000000000, 1.50000000000000, 2.00000000000000, 2.50000000000000, + 3.00000000000000, 3.50000000000000, 4.00000000000000, 4.50000000000000] + sage: srange(0, 1, 0.4) # needs sage.rings.real_mpfr [0.000000000000000, 0.400000000000000, 0.800000000000000] Negative steps are also allowed:: @@ -512,7 +519,7 @@ def ellipsis_range(*args, step=None): Examples in which the step determines the parent of the elements:: - sage: [1..3, step=0.5] + sage: [1..3, step=0.5] # needs sage.rings.real_mpfr [1.00000000000000, 1.50000000000000, 2.00000000000000, 2.50000000000000, 3.00000000000000] sage: v = [1..5, step=1/1]; v [1, 2, 3, 4, 5] From 9e1c2ab81002967eef19461fe27e24668930f13d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 10 Jun 2024 22:06:18 -0700 Subject: [PATCH 3/6] sage.game_theory: Add # needs --- src/sage/game_theory/matching_game.py | 7 ++++--- src/sage/game_theory/normal_form_game.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sage/game_theory/matching_game.py b/src/sage/game_theory/matching_game.py index 11c04f6e5b1..8efa2c2acfa 100644 --- a/src/sage/game_theory/matching_game.py +++ b/src/sage/game_theory/matching_game.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.graphs """ Matching games @@ -124,7 +125,7 @@ class MatchingGame(SageObject): Matchings have a natural representations as bipartite graphs:: - sage: plot(m) + sage: plot(m) # needs sage.plot Graphics object consisting of 13 graphics primitives The above plots the bipartite graph associated with the matching. @@ -508,14 +509,14 @@ def plot(self): sage: revr = {3: (0, 1), ....: 4: (1, 0)} sage: g = MatchingGame([suit, revr]) - sage: plot(g) + sage: plot(g) # needs sage.plot Traceback (most recent call last): ... ValueError: game has not been solved yet sage: g.solve() {0: 3, 1: 4} - sage: plot(g) + sage: plot(g) # needs sage.plot Graphics object consisting of 7 graphics primitives """ pl = self.bipartite_graph() diff --git a/src/sage/game_theory/normal_form_game.py b/src/sage/game_theory/normal_form_game.py index e2220fc7f0a..2b1e592c4e8 100644 --- a/src/sage/game_theory/normal_form_game.py +++ b/src/sage/game_theory/normal_form_game.py @@ -157,11 +157,11 @@ `(Ay)_i`, ie element in position `i` of the matrix/vector multiplication `Ay`) :: - sage: y = var('y') + sage: y = var('y') # needs sage.symbolic sage: A = matrix([[1, -1], [-1, 1]]) - sage: p = plot((A * vector([y, 1 - y]))[0], y, 0, 1, color='blue', + sage: p = plot((A * vector([y, 1 - y]))[0], y, 0, 1, color='blue', # needs sage.symbolic ....: legend_label='$u_1(r_1, (y, 1-y))$', axes_labels=['$y$', '']) - sage: p += plot((A * vector([y, 1 - y]))[1], y, 0, 1, color='red', + sage: p += plot((A * vector([y, 1 - y]))[1], y, 0, 1, color='red', # needs sage.symbolic ....: legend_label='$u_1(r_2, (y, 1-y))$'); p Graphics object consisting of 2 graphics primitives From 23fc8831a4dbf49a87c247962eadb2384c0fa928 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 10 Jun 2024 22:22:48 -0700 Subject: [PATCH 4/6] src/sage/structure/formal_sum.py: Add # needs --- src/sage/structure/formal_sum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/structure/formal_sum.py b/src/sage/structure/formal_sum.py index ee333decd4b..f037f71042e 100644 --- a/src/sage/structure/formal_sum.py +++ b/src/sage/structure/formal_sum.py @@ -203,7 +203,7 @@ def _latex_(self): r""" EXAMPLES:: - sage: latex(FormalSum([(1,2), (5, 8/9), (-3, 7)])) + sage: latex(FormalSum([(1,2), (5, 8/9), (-3, 7)])) # needs sage.rings.real_mpfr 2 + 5\cdot \frac{8}{9} - 3\cdot 7 """ from sage.misc.latex import repr_lincomb @@ -441,7 +441,7 @@ def _get_action_(self, other, op, self_is_left): """ EXAMPLES:: - sage: A = FormalSums(RR); A.get_action(RR) # indirect doctest + sage: A = FormalSums(RR); A.get_action(RR) # indirect doctest # needs sage.rings.real_mpfr Right scalar multiplication by Real Field with 53 bits of precision on Abelian Group of all Formal Finite Sums over Real Field with 53 bits of precision From 928b53233623b397651cd25ae3a8c5fc2a8cc5ea Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 10 Jun 2024 22:25:03 -0700 Subject: [PATCH 5/6] src/sage/topology/cell_complex.py: Add # needs --- src/sage/topology/cell_complex.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sage/topology/cell_complex.py b/src/sage/topology/cell_complex.py index 963cf44c36c..48f5eb66f6f 100644 --- a/src/sage/topology/cell_complex.py +++ b/src/sage/topology/cell_complex.py @@ -227,6 +227,8 @@ def _n_cells_sorted(self, n, subcomplex=None): sage: K = SimplicialComplex([[1,2,3], [2,3,4]]) sage: Z._n_cells_sorted(2, subcomplex=K) [(1, 2, 4), (1, 3, 4)] + + sage: # needs sage.symbolic sage: S = SimplicialComplex([[complex(i), complex(1)]]) sage: S._n_cells_sorted(0) [((1+0j),), (1j,)] From ed9cca503a9761ca665bb25b6dc8eca2097a6c5c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 10 Jun 2024 22:26:50 -0700 Subject: [PATCH 6/6] src/sage/topology/moment_angle_complex.py: Use lazy_import, add # needs --- src/sage/topology/moment_angle_complex.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/sage/topology/moment_angle_complex.py b/src/sage/topology/moment_angle_complex.py index b4c4231d835..d2b986a6a1d 100644 --- a/src/sage/topology/moment_angle_complex.py +++ b/src/sage/topology/moment_angle_complex.py @@ -18,9 +18,9 @@ from itertools import combinations from sage.categories.fields import Fields -from sage.homology.homology_group import HomologyGroup from sage.misc.cachefunc import cached_method from sage.misc.lazy_attribute import lazy_attribute +from sage.misc.lazy_import import lazy_import from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.structure.sage_object import SageObject @@ -29,6 +29,8 @@ from sage.topology.cubical_complex import CubicalComplex, cubical_complexes from sage.topology.simplicial_complex import SimplicialComplex, copy +lazy_import('sage.homology.homology_group', 'HomologyGroup') + def _cubical_complex_union(c1, c2): """ @@ -130,11 +132,11 @@ class MomentAngleComplex(UniqueRepresentation, SageObject): We can perform a number of operations, such as find the dimension or compute the homology:: - sage: M.homology() + sage: M.homology() # needs sage.modules {0: 0, 1: 0, 2: 0, 3: Z} sage: Z.dimension() 6 - sage: Z.homology() + sage: Z.homology() # needs sage.modules {0: 0, 1: 0, 2: 0, 3: Z x Z, 4: Z, 5: Z, 6: Z} If the associated simplicial complex is an `n`-simplex, then the @@ -403,9 +405,9 @@ def components(self): sage: S3 = simplicial_complexes.Sphere(3) sage: product_of_spheres = S3.product(S3) - sage: Z.cohomology() + sage: Z.cohomology() # needs sage.modules {0: 0, 1: 0, 2: 0, 3: Z x Z, 4: 0, 5: 0, 6: Z} - sage: Z.cohomology() == product_of_spheres.cohomology() # long time + sage: Z.cohomology() == product_of_spheres.cohomology() # long time # needs sage.modules True """ return self._components @@ -453,6 +455,7 @@ def _homology_group(self, i, base_ring, cohomology, algorithm, verbose, reduced) TESTS:: + sage: # needs sage.modules sage: Z = MomentAngleComplex([[0,1,2], [1,2,3]]); Z Moment-angle complex of Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)} @@ -550,6 +553,7 @@ def homology(self, dim=None, base_ring=ZZ, cohomology=False, EXAMPLES:: + sage: # needs sage.modules sage: Z = MomentAngleComplex([[0,1,2], [1,2,3], [3,0]]); Z Moment-angle complex of Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 3), (0, 1, 2), (1, 2, 3)} @@ -580,13 +584,14 @@ def homology(self, dim=None, base_ring=ZZ, cohomology=False, (0, 1, 2) and facets {(0, 1), (0, 2), (1, 2)} sage: Z.cubical_complex() Cubical complex with 64 vertices and 729 cubes - sage: Z.cubical_complex().homology() == Z.homology() + sage: Z.cubical_complex().homology() == Z.homology() # needs sage.modules True Meanwhile, the homology computation used here is quite efficient and works well even with significantly larger underlying simplicial complexes:: + sage: # needs sage.modules sage: Z = MomentAngleComplex([[0,1,2,3,4,5], [0,1,2,3,4,6], ....: [0,1,2,3,5,7], [0,1,2,3,6,8,9]]) sage: Z.homology() # long time @@ -656,6 +661,7 @@ def cohomology(self, dim=None, base_ring=ZZ, algorithm='pari', to a product of two 3-spheres (which can be seen by looking at the output of ``components()``):: + sage: # needs sage.modules sage: S3 = simplicial_complexes.Sphere(3) sage: product_of_spheres = S3.product(S3) sage: Z.cohomology() @@ -684,6 +690,7 @@ def betti(self, dim=None): EXAMPLES:: + sage: # needs sage.modules sage: Z = MomentAngleComplex([[0,1], [1,2], [2,0], [1,2,3]]) sage: Z.betti() {0: 1, 1: 0, 2: 0, 3: 1, 4: 0, 5: 1, 6: 1, 7: 0} @@ -714,6 +721,7 @@ def euler_characteristic(self): EXAMPLES:: + sage: # needs sage.modules sage: X = SimplicialComplex([[0,1,2,3,4,5], [0,1,2,3,4,6], ....: [0,1,2,3,5,7], [0,1,2,3,6,8,9]]) sage: M = MomentAngleComplex(X)