Skip to content

Commit

Permalink
gh-35279: sage.categories: Modularization fixes for imports
Browse files Browse the repository at this point in the history
    
<!-- ^^^^^
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

<!-- Describe your changes here in detail -->
We should be able to import Python modules from `sage.categories` even
if implementation modules are not installed; that's the premise of the
distribution **sagemath-categories**.
Here we make changes to avoid module-level dependencies on some higher-
level functionality, such as symbolic functions, linear algebra, etc.
<!-- 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" -->

#35275 takes care of some other imports.

Part of
- #29705

### 📝 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.
- [ ] 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: #35279
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Mar 31, 2023
2 parents 8429622 + 8722462 commit 1d591ea
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/sage/categories/finite_complex_reflection_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from sage.misc.cachefunc import cached_method
from sage.categories.category_with_axiom import CategoryWithAxiom
from sage.categories.coxeter_groups import CoxeterGroups
from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet


class FiniteComplexReflectionGroups(CategoryWithAxiom):
Expand Down Expand Up @@ -758,6 +757,8 @@ def absolute_order_ideal(self, gens=None,
[1] 1
[] 0
"""
from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet

if gens is None:
seeds = [(self.coxeter_element(), self.rank())]
else:
Expand Down
20 changes: 18 additions & 2 deletions src/sage/categories/finite_dimensional_lie_algebras_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
from sage.categories.category_with_axiom import CategoryWithAxiom_over_base_ring
from sage.categories.lie_algebras import LieAlgebras
from sage.categories.subobjects import SubobjectsCategory
from sage.algebras.free_algebra import FreeAlgebra
from sage.sets.family import Family
from sage.matrix.constructor import matrix


class FiniteDimensionalLieAlgebrasWithBasis(CategoryWithAxiom_over_base_ring):
Expand Down Expand Up @@ -97,6 +95,8 @@ def _construct_UEA(self):
The 6-Witt Lie algebra over Ring of integers modulo 6
in the Poincare-Birkhoff-Witt basis
"""
from sage.algebras.free_algebra import FreeAlgebra

# Create the UEA relations
# We need to get names for the basis elements, not just the generators
I = self._basis_ordering
Expand Down Expand Up @@ -321,6 +321,8 @@ def killing_form_matrix(self):
sage: parent(m)
Full MatrixSpace of 0 by 0 dense matrices over Rational Field
"""
from sage.matrix.constructor import matrix

B = self.basis()
m = matrix(self.base_ring(),
[[self.killing_form(x, y) for x in B] for y in B])
Expand Down Expand Up @@ -420,6 +422,8 @@ def centralizer_basis(self, S):
D{1} + D{1, 2} + D{2, 3} + D{3},
D{1, 2, 3} + D{1, 3} + D{2})
"""
from sage.matrix.constructor import matrix

#from sage.algebras.lie_algebras.subalgebra import LieSubalgebra
#if isinstance(S, LieSubalgebra) or S is self:
if S is self:
Expand Down Expand Up @@ -541,6 +545,7 @@ def derivations_basis(self):
:wikipedia:`Derivation_(differential_algebra)`
"""
from sage.matrix.constructor import matrix

R = self.base_ring()
B = self.basis()
keys = list(B.keys())
Expand Down Expand Up @@ -581,6 +586,8 @@ def inner_derivations_basis(self):
[1 0 0], [0 1 0]
)
"""
from sage.matrix.constructor import matrix

R = self.base_ring()
IDer = matrix(R, [b.adjoint_matrix().list() for b in self.basis()])
N = self.dimension()
Expand Down Expand Up @@ -691,6 +698,9 @@ def is_ideal(self, A):
if A not in LieAlgebras(self.base_ring()).FiniteDimensional().WithBasis():
raise NotImplementedError("A must be a finite dimensional"
" Lie algebra with basis")

from sage.matrix.constructor import matrix

B = self.basis()
AB = A.basis()
try:
Expand Down Expand Up @@ -798,6 +808,8 @@ def product_space(self, L, submodule=False):
Subalgebra generated of Lie algebra on 2 generators (x, y) over Rational Field with basis:
()
"""
from sage.matrix.constructor import matrix

# Make sure we lift everything to the ambient space
if self in LieAlgebras(self.base_ring()).Subobjects():
A = self.ambient()
Expand Down Expand Up @@ -1373,6 +1385,8 @@ def as_finite_dimensional_algebra(self):
sage: X * Y
Z
"""
from sage.matrix.constructor import matrix

K = self._basis_ordering
mats = []
R = self.base_ring()
Expand Down Expand Up @@ -1606,6 +1620,8 @@ def adjoint_matrix(self, sparse=False): # In #11111 (more or less) by using matr
sage: E1 * E2 - E2 * E1 == e12.adjoint_matrix()
True
"""
from sage.matrix.constructor import matrix

P = self.parent()
basis = P.basis()
return matrix(self.base_ring(),
Expand Down
9 changes: 7 additions & 2 deletions src/sage/categories/loop_crystals.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from sage.categories.regular_crystals import RegularCrystals
from sage.categories.tensor import TensorProductsCategory
from sage.categories.map import Map
from sage.graphs.dot2tex_utils import have_dot2tex
from sage.functions.other import ceil


class LoopCrystals(Category_singleton):
r"""
Expand Down Expand Up @@ -117,6 +116,8 @@ def digraph(self, subset=None, index_set=None):
{...'edge_options': <function ... at ...>...}
sage: view(G, tightpage=True) # optional - dot2tex graphviz, not tested (opens external window)
"""
from sage.graphs.dot2tex_utils import have_dot2tex

G = Crystals().parent_class.digraph(self, subset, index_set)
if have_dot2tex():
def eopt(u_v_label):
Expand Down Expand Up @@ -959,6 +960,8 @@ def energy_function(self, algorithm=None):
....: for b in hw)
True
"""
from sage.functions.other import ceil

C = self.parent().crystals[0]
ell = ceil(C.s()/C.cartan_type().c()[C.r()])
is_perfect = all(ell == K.s()/K.cartan_type().c()[K.r()]
Expand Down Expand Up @@ -1090,6 +1093,8 @@ def e_string_to_ground_state(self):
....: for elt in hw)
True
"""
from sage.functions.other import ceil

ell = max(ceil(K.s()/K.cartan_type().c()[K.r()])
for K in self.parent().crystals)
if self.cartan_type().dual().type() == 'BC':
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/pushout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3463,8 +3463,8 @@ def merge(self, other):
# nothing else helps, hence, we move to the pushout of the codomains of the embeddings
try:
P = pushout(self.embeddings[0].parent(), other.embeddings[0].parent())
from sage.rings.number_field.number_field import is_NumberField
if is_NumberField(P):
from sage.rings.number_field.number_field_base import NumberField
if isinstance(P, NumberField):
return P.construction()[0]
except CoercionException:
return None
Expand Down
5 changes: 4 additions & 1 deletion src/sage/categories/rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,10 @@ def normalize_arg(arg):

if isinstance(arg, tuple):
from sage.categories.morphism import Morphism
from sage.rings.derivation import RingDerivation
try:
from sage.rings.derivation import RingDerivation
except ImportError:
RingDerivation = ()
if len(arg) == 2 and isinstance(arg[1], (Morphism, RingDerivation)):
from sage.rings.polynomial.ore_polynomial_ring import OrePolynomialRing
return OrePolynomialRing(self, arg[1], names=arg[0])
Expand Down

0 comments on commit 1d591ea

Please sign in to comment.