Skip to content

Commit

Permalink
sagemathgh-38170: sage.categories: Update # needs, modularization…
Browse files Browse the repository at this point in the history
… fixes (imports)

    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

- In part cherry-picked from sagemath#35095.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [ ] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#38170
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Jun 16, 2024
2 parents f9c02f2 + bbc1a6f commit d7b69ea
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 81 deletions.
12 changes: 6 additions & 6 deletions src/sage/categories/chain_complexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def homology(self, n=None):
::
sage: # needs sage.combinat sage.modules
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3))
sage: C = A.cdg_algebra({z: x*y})
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # needs sage.libs.singular
sage: C = A.cdg_algebra({z: x*y}) # needs sage.libs.singular
sage: C.homology(0)
Free module generated by {[1]} over Rational Field
sage: C.homology(1)
Expand Down Expand Up @@ -110,8 +110,8 @@ def differential(self, *args, **kwargs):
::
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # needs sage.combinat sage.modules
sage: C = A.cdg_algebra({z: x*y}) # needs sage.combinat sage.modules
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # needs sage.combinat sage.libs.singular sage.modules
sage: C = A.cdg_algebra({z: x*y}) # needs sage.combinat sage.libs.singular sage.modules
sage: C.differential() # needs sage.combinat sage.modules
Differential of Commutative Differential Graded Algebra with
generators ('x', 'y', 'z') in degrees (2, 2, 3) over Rational Field
Expand Down Expand Up @@ -183,8 +183,8 @@ class HomologyFunctor(Functor):
::
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # needs sage.combinat sage.modules
sage: C = A.cdg_algebra({z: x*y}) # needs sage.combinat sage.modules
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3)) # needs sage.combinat sage.libs.singular sage.modules
sage: C = A.cdg_algebra({z: x*y}) # needs sage.combinat sage.libs.singular sage.modules
sage: H = HomologyFunctor(ChainComplexes(QQ), 2)
sage: H(C) # needs sage.combinat sage.modules
Free module generated by {[x], [y]} over Rational Field
Expand Down
6 changes: 3 additions & 3 deletions src/sage/categories/examples/lie_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __classcall_private__(cls, gens):
EXAMPLES::
sage: # needs sage.combinat
sage: # needs sage.combinat sage.groups
sage: S3 = SymmetricGroupAlgebra(QQ, 3)
sage: L1 = LieAlgebras(QQ).example()
sage: gens = list(S3.algebra_generators())
Expand All @@ -85,8 +85,8 @@ def __init__(self, gens):
"""
EXAMPLES::
sage: L = LieAlgebras(QQ).example() # needs sage.combinat
sage: TestSuite(L).run() # needs sage.combinat
sage: L = LieAlgebras(QQ).example() # needs sage.combinat sage.groups
sage: TestSuite(L).run() # needs sage.combinat sage.groups
"""
if not gens:
raise ValueError("need at least one generator")
Expand Down
34 changes: 20 additions & 14 deletions src/sage/categories/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,31 @@ def __contains__(self, x):
in other doctests, we introduced a strong reference to all previously created
uncollected objects in :issue:`19244`. ::
sage: # needs sage.libs.pari
sage: import gc
sage: _ = gc.collect()
sage: permstore = [X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]
sage: permstore = [X for X in gc.get_objects()
....: if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]
sage: n = len(permstore)
sage: for i in prime_range(100): # needs sage.libs.pari
sage: for i in prime_range(100):
....: R = ZZ.quotient(i)
....: t = R in Fields()
First, we show that there are now more quotient rings in cache than before::
sage: len([X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]) > n
sage: # needs sage.libs.pari
sage: len([X for X in gc.get_objects()
....: if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]) > n
True
When we delete the last quotient ring created in the loop and then do a garbage
collection, all newly created rings vanish::
sage: # needs sage.libs.pari
sage: del R
sage: _ = gc.collect()
sage: len([X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]) - n
sage: len([X for X in gc.get_objects()
....: if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]) - n
0
"""
Expand Down Expand Up @@ -624,15 +630,15 @@ def gcd(self,other):
For field of characteristic zero, the gcd of integers is considered
as if they were elements of the integer ring::
sage: gcd(15.0,12.0)
sage: gcd(15.0,12.0) # needs sage.rings.real_mpfr
3.00000000000000
But for other floating point numbers, the gcd is just `0.0` or `1.0`::
sage: gcd(3.2, 2.18)
sage: gcd(3.2, 2.18) # needs sage.rings.real_mpfr
1.00000000000000
sage: gcd(0.0, 0.0)
sage: gcd(0.0, 0.0) # needs sage.rings.real_mpfr
0.000000000000000
AUTHOR:
Expand Down Expand Up @@ -678,15 +684,15 @@ def lcm(self, other):
For field of characteristic zero, the lcm of integers is considered
as if they were elements of the integer ring::
sage: lcm(15.0,12.0)
sage: lcm(15.0, 12.0) # needs sage.rings.real_mpfr
60.0000000000000
But for others floating point numbers, it is just `0.0` or `1.0`::
sage: lcm(3.2, 2.18)
sage: lcm(3.2, 2.18) # needs sage.rings.real_mpfr
1.00000000000000
sage: lcm(0.0, 0.0)
sage: lcm(0.0, 0.0) # needs sage.rings.real_mpfr
0.000000000000000
AUTHOR:
Expand Down Expand Up @@ -748,13 +754,13 @@ def xgcd(self, other):
the result is a floating point version of the standard gcd on
`\ZZ`::
sage: xgcd(12.0, 8.0)
sage: xgcd(12.0, 8.0) # needs sage.rings.real_mpfr
(4.00000000000000, 1.00000000000000, -1.00000000000000)
sage: xgcd(3.1, 2.98714)
sage: xgcd(3.1, 2.98714) # needs sage.rings.real_mpfr
(1.00000000000000, 0.322580645161290, 0.000000000000000)
sage: xgcd(0.0, 1.1)
sage: xgcd(0.0, 1.1) # needs sage.rings.real_mpfr
(1.00000000000000, 0.000000000000000, 0.909090909090909)
"""
P = self.parent()
Expand Down Expand Up @@ -787,7 +793,7 @@ def factor(self):
sage: x = GF(7)(5)
sage: x.factor()
5
sage: RR(0).factor()
sage: RR(0).factor() # needs sage.rings.real_mpfr
Traceback (most recent call last):
...
ArithmeticError: factorization of 0.000000000000000 is not defined
Expand Down
14 changes: 9 additions & 5 deletions src/sage/categories/finite_dimensional_modules_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ def _repr_matrix(self):
EXAMPLES::
sage: # needs sage.modules
sage: M = matrix(ZZ, [[1, 0, 0], [0, 1, 0]],
....: column_keys=['a', 'b', 'c'],
....: row_keys=['v', 'w']); M
Expand Down Expand Up @@ -714,6 +715,7 @@ def _ascii_art_matrix(self):
EXAMPLES::
sage: # needs sage.modules
sage: M = matrix(ZZ, [[1, 0, 0], [0, 1, 0]],
....: column_keys=['a', 'b', 'c'],
....: row_keys=['v', 'w']); M
Expand Down Expand Up @@ -745,6 +747,7 @@ def _unicode_art_matrix(self):
EXAMPLES::
sage: # needs sage.modules
sage: M = matrix(ZZ, [[1, 0, 0], [0, 1, 0]],
....: column_keys=['a', 'b', 'c'],
....: row_keys=['v', 'w']); M
Expand Down Expand Up @@ -910,6 +913,7 @@ def characteristic_polynomial(self):
EXAMPLES::
sage: # needs sage.modules
sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1])
sage: phi.characteristic_polynomial()
x^2 - 3*x + 2
Expand All @@ -919,7 +923,6 @@ def characteristic_polynomial(self):
x^2 - 3*x + 2
sage: phi.charpoly('T')
T^2 - 3*T + 2
sage: W = CombinatorialFreeModule(ZZ, ['x', 'y'])
sage: M = matrix(ZZ, [[1, 0], [1, 2]])
sage: psi = W.module_morphism(matrix=M, codomain=W)
Expand All @@ -939,12 +942,12 @@ def determinant(self):
EXAMPLES::
sage: # needs sage.modules
sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1])
sage: phi.determinant()
2
sage: phi.det()
2
sage: W = CombinatorialFreeModule(ZZ, ['x', 'y'])
sage: M = matrix(ZZ, [[1, 0], [1, 2]])
sage: psi = W.module_morphism(matrix=M, codomain=W)
Expand All @@ -966,12 +969,12 @@ def fcp(self):
EXAMPLES::
sage: # needs sage.modules
sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1])
sage: phi.fcp() # needs sage.libs.pari
(x - 2) * (x - 1)
sage: phi.fcp('T') # needs sage.libs.pari
(T - 2) * (T - 1)
sage: W = CombinatorialFreeModule(ZZ, ['x', 'y'])
sage: M = matrix(ZZ, [[1, 0], [1, 2]])
sage: psi = W.module_morphism(matrix=M, codomain=W)
Expand All @@ -995,6 +998,7 @@ def minimal_polynomial(self):
Compute the minimal polynomial, and check it. ::
sage: # needs sage.modules
sage: V = GF(7)^3
sage: H = V.Hom(V)([[0,1,2], [-1,0,3], [2,4,1]]); H
Vector space morphism represented by the matrix:
Expand All @@ -1015,7 +1019,7 @@ def minimal_polynomial(self):
Domain: Vector space of dimension 3 over Finite Field of size 7
Codomain: Vector space of dimension 3 over Finite Field of size 7
sage: # needs sage.rings.finite_rings
sage: # needs sage.modules sage.rings.finite_rings
sage: k = GF(9, 'c')
sage: V = CombinatorialFreeModule(k, ['x', 'y', 'z', 'w'])
sage: A = matrix(k, 4, [1,1,0,0, 0,1,0,0, 0,0,5,0, 0,0,0,5])
Expand All @@ -1038,10 +1042,10 @@ def trace(self):
EXAMPLES::
sage: # needs sage.modules
sage: V = ZZ^2; phi = V.hom([V.0 + V.1, 2*V.1])
sage: phi.trace()
3
sage: W = CombinatorialFreeModule(ZZ, ['x', 'y'])
sage: M = matrix(ZZ, [[1, 0], [1, 2]])
sage: psi = W.module_morphism(matrix=M, codomain=W)
Expand Down
10 changes: 5 additions & 5 deletions src/sage/categories/finite_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def cardinality(self):
We need to use a finite group which uses this default
implementation of cardinality::
sage: G = groups.misc.SemimonomialTransformation(GF(5), 3); G
sage: G = groups.misc.SemimonomialTransformation(GF(5), 3); G # needs sage.rings.number_field
Semimonomial transformation group over Finite Field of size 5 of degree 3
sage: G.cardinality.__module__
sage: G.cardinality.__module__ # needs sage.rings.number_field
'sage.categories.finite_groups'
sage: G.cardinality()
sage: G.cardinality() # needs sage.rings.number_field
384
"""
if hasattr(self, 'order'):
Expand Down Expand Up @@ -173,7 +173,7 @@ def conjugacy_classes_representatives(self):
EXAMPLES::
sage: G = SymmetricGroup(3)
sage: G.conjugacy_classes_representatives()
sage: G.conjugacy_classes_representatives() # needs sage.combinat
[(), (1,2), (1,2,3)]
"""
return [C.representative() for C in self.conjugacy_classes()]
Expand Down Expand Up @@ -232,7 +232,7 @@ def __init_extra__(self):
sage: A in Algebras.Semisimple
False
sage: G = groups.misc.AdditiveCyclic(4)
sage: G = groups.misc.AdditiveCyclic(4) # needs sage.rings.number_field
sage: Cat = CommutativeAdditiveGroups().Finite()
sage: A = G.algebra(GF(5), category=Cat)
sage: A in Algebras.Semisimple
Expand Down
14 changes: 7 additions & 7 deletions src/sage/categories/group_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init_extra__(self):
EXAMPLES::
sage: # needs sage.groups sage.modules
sage: # needs sage.combinat sage.groups sage.modules
sage: A = GroupAlgebra(SymmetricGroup(4), QQ)
sage: B = GroupAlgebra(SymmetricGroup(3), ZZ)
sage: A.has_coerce_map_from(B)
Expand Down Expand Up @@ -173,7 +173,7 @@ def group(self):
sage: GroupAlgebras(QQ).example(GL(3, GF(11))).group() # needs sage.groups sage.modules
General Linear Group of degree 3 over Finite Field of size 11
sage: SymmetricGroup(10).algebra(QQ).group() # needs sage.groups sage.modules
sage: SymmetricGroup(10).algebra(QQ).group() # needs sage.combinat sage.groups sage.modules
Symmetric group of order 10! as a permutation group
"""
return self.basis().keys()
Expand Down Expand Up @@ -201,7 +201,7 @@ def center_basis(self):
EXAMPLES::
sage: SymmetricGroup(3).algebra(QQ).center_basis() # needs sage.groups sage.modules
sage: SymmetricGroup(3).algebra(QQ).center_basis() # needs sage.combinat sage.groups sage.modules
((), (2,3) + (1,2) + (1,3), (1,2,3) + (1,3,2))
.. SEEALSO::
Expand Down Expand Up @@ -319,12 +319,12 @@ def is_integral_domain(self, proof=True):
sage: # needs sage.groups sage.modules
sage: S2 = SymmetricGroup(2)
sage: GroupAlgebra(S2).is_integral_domain()
sage: GroupAlgebra(S2).is_integral_domain() # needs sage.combinat
False
sage: S1 = SymmetricGroup(1)
sage: GroupAlgebra(S1).is_integral_domain()
sage: GroupAlgebra(S1).is_integral_domain() # needs sage.combinat
True
sage: GroupAlgebra(S1, IntegerModRing(4)).is_integral_domain()
sage: GroupAlgebra(S1, IntegerModRing(4)).is_integral_domain() # needs sage.combinat
False
sage: GroupAlgebra(AbelianGroup(1)).is_integral_domain()
True
Expand Down Expand Up @@ -400,7 +400,7 @@ def central_form(self):
EXAMPLES::
sage: # needs sage.groups sage.modules
sage: # needs sage.combinat sage.groups sage.modules
sage: QS3 = SymmetricGroup(3).algebra(QQ)
sage: A = QS3([2,3,1]) + QS3([3,1,2])
sage: A.central_form()
Expand Down
Loading

0 comments on commit d7b69ea

Please sign in to comment.