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.misc.misc, sage.combinat: Modularization fixes #35564

Merged
merged 13 commits into from
Jun 21, 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
2 changes: 1 addition & 1 deletion src/sage/algebras/quantum_clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from sage.rings.fraction_field import FractionField
from sage.sets.finite_enumerated_set import FiniteEnumeratedSet
from itertools import product
from sage.misc.misc import powerset
from sage.combinat.subset import powerset

class QuantumCliffordAlgebra(CombinatorialFreeModule):
r"""
Expand Down
3 changes: 2 additions & 1 deletion src/sage/arith/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import math
from collections.abc import Iterable

from sage.misc.misc import powerset
from sage.misc.misc_c import prod

from sage.structure.element import parent
Expand Down Expand Up @@ -6042,6 +6041,8 @@ def squarefree_divisors(x):
sage: list(squarefree_divisors(mpz(12)))
[1, 2, 3, 6]
"""
from sage.combinat.subset import powerset

for a in powerset(prime_divisors(x)):
yield prod(a, ZZ.one())

Expand Down
5 changes: 4 additions & 1 deletion src/sage/categories/coxeter_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,10 @@ def _test_coxeter_relations(self, **options):
one = self.one()
for si in s:
tester.assertEqual(si**2, one)
cox_mat = self.coxeter_matrix()
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change. It hides import errors

Copy link
Contributor Author

@mkoeppe mkoeppe Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These _test_... methods are invoked whenever TestSuite is run on a parent in this category. As of #35095 , most of the root system functionality is shipped as part of sagemath-modules ("because root systems are just sets of vectors"). But parts of the functionality goes through Dynkin diagrams, which are Graphs and therefore depend (at runtime) on parts of sagemath-graphs. The idea is that in the modularized test of sagemath-modules, we can still run the TestSuite and just skip the tests that can't be tested, rather than blaming the implementation class for sagemath-graphs not being installed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation.

cox_mat = self.coxeter_matrix()
except ImportError:
return
I = cox_mat.index_set()
for ii, i in enumerate(I):
for j in I[ii + 1:]:
Expand Down
15 changes: 9 additions & 6 deletions src/sage/categories/finite_coxeter_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# https://www.gnu.org/licenses/
# *****************************************************************************

import sage.rings.abc

from sage.misc.cachefunc import cached_method, cached_in_parent_method
from sage.misc.lazy_attribute import lazy_attribute
from sage.categories.category_with_axiom import CategoryWithAxiom
Expand Down Expand Up @@ -746,13 +748,14 @@ def permutahedron(self, point=None, base_ring=None):
from sage.rings.integer_ring import ZZ
point = [ZZ.one()] * n
v = sum(point[i-1] * weights[i] for i in weights.keys())
from sage.geometry.polyhedron.constructor import Polyhedron
from sage.rings.qqbar import AA, QQbar
from sage.rings.universal_cyclotomic_field import UniversalCyclotomicField
vertices = [v*w for w in self]
if base_ring is None and v.base_ring() in [UniversalCyclotomicField(), QQbar]:
vertices = [v.change_ring(AA) for v in vertices]
base_ring = AA
if base_ring is None:
if isinstance(v.base_ring(), (sage.rings.abc.UniversalCyclotomicField,
sage.rings.abc.AlgebraicField_common)):
from sage.rings.qqbar import AA
vertices = [v.change_ring(AA) for v in vertices]
base_ring = AA
from sage.geometry.polyhedron.constructor import Polyhedron
return Polyhedron(vertices=vertices, base_ring=base_ring)

class ElementMethods:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/loop_crystals.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ def energy_function(self, algorithm=None):
....: for b in hw)
True
"""
from sage.functions.other import ceil
from sage.arith.misc import integer_ceil as ceil

C = self.parent().crystals[0]
ell = ceil(C.s()/C.cartan_type().c()[C.r()])
Expand Down Expand Up @@ -1101,7 +1101,7 @@ def e_string_to_ground_state(self):
....: for elt in hw)
True
"""
from sage.functions.other import ceil
from sage.arith.misc import integer_ceil as ceil

ell = max(ceil(K.s()/K.cartan_type().c()[K.r()])
for K in self.parent().crystals)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
lazy_import('sage.combinat.multiset_partition_into_sets_ordered',
['OrderedMultisetPartitionIntoSets',
'OrderedMultisetPartitionsIntoSets'])
from .subset import Subsets
from .subset import Subsets, subsets, powerset, uniq
from .necklace import Necklaces
lazy_import('sage.combinat.dyck_word', ('DyckWords', 'DyckWord'))
lazy_import('sage.combinat.nu_dyck_word', ('NuDyckWords', 'NuDyckWord'))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/blob_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from sage.structure.richcmp import richcmp
#from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
from sage.misc.cachefunc import cached_method
from sage.misc.misc import powerset
from sage.combinat.subset import powerset
from sage.arith.misc import binomial
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.categories.algebras import Algebras
Expand Down
26 changes: 13 additions & 13 deletions src/sage/combinat/combinat.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,12 @@

**Implemented in other modules (listed for completeness):**

The ``sage.arith.all`` module contains the following
The package :mod:`sage.arith` contains the following
combinatorial functions:

- binomial the binomial coefficient (wrapped from PARI)
- :func:`binomial` the binomial coefficient (wrapped from PARI)

- factorial (wrapped from PARI)

- partition (from the Python Cookbook) Generator of the list of
all the partitions of the integer `n`.

- :func:`number_of_partitions` (wrapped from PARI) the
*number* of partitions:
- :func:`factorial` (wrapped from PARI)

- :func:`falling_factorial` Definition: for integer
`a \ge 0` we have `x(x-1) \cdots (x-a+1)`. In all
Expand All @@ -87,7 +81,12 @@
other cases we use the GAMMA-function:
`\frac {\Gamma(x+a)} {\Gamma(x)}`.

- gaussian_binomial the gaussian binomial
From other modules:

- :func:`number_of_partitions` (wrapped from PARI) the
*number* of partitions:

- :func:`sage.combinat.q_analogues.gaussian_binomial` the Gaussian binomial

.. MATH::

Expand Down Expand Up @@ -174,8 +173,6 @@
from sage.rings.infinity import infinity
from sage.rings.polynomial.polynomial_element import Polynomial
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.libs.pari.all import pari
from sage.misc.prandom import randint
from sage.misc.misc_c import prod
from sage.misc.cachefunc import cached_function
from sage.structure.sage_object import SageObject
Expand All @@ -187,7 +184,10 @@
from sage.misc.classcall_metaclass import ClasscallMetaclass
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
from sage.structure.element import Element

lazy_import('sage.interfaces.maxima_lib', 'maxima')
lazy_import('sage.libs.pari.all', 'pari')
lazy_import('sage.misc.prandom', 'randint')


def bell_number(n, algorithm='flint', **options) -> Integer:
Expand Down Expand Up @@ -2892,7 +2892,7 @@ def unshuffle_iterator(a, one=1) -> Iterator:
[(((), (3, 1)), 3/2), (((3,), (1,)), 3/2), (((1,), (3,)), -3/2),
(((3, 1), ()), 3/2)]
"""
from sage.misc.misc import powerset
from sage.combinat.subset import powerset
n = len(a)
for I in powerset(range(n)):
sorted_I = tuple(sorted(I))
Expand Down
10 changes: 6 additions & 4 deletions src/sage/combinat/designs/bibd.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@
---------
"""

from sage.arith.misc import binomial, is_prime_power, is_square
from sage.categories.sets_cat import EmptySetError
from sage.misc.lazy_import import lazy_import
from sage.misc.unknown import Unknown

from .design_catalog import transversal_design # type:ignore
from sage.arith.misc import binomial, is_prime_power
from .group_divisible_designs import GroupDivisibleDesign
from .designs_pyx import is_pairwise_balanced_design
from .group_divisible_designs import GroupDivisibleDesign

lazy_import('sage.schemes.plane_conics.constructor', 'Conic')


def biplane(n, existence=False):
Expand Down Expand Up @@ -413,8 +417,6 @@ def BruckRyserChowla_check(v, k, lambd):
True

"""
from sage.arith.misc import is_square
from sage.schemes.plane_conics.constructor import Conic
from sage.rings.rational_field import QQ

# design is not symmetric
Expand Down
10 changes: 4 additions & 6 deletions src/sage/combinat/designs/difference_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,6 @@ def relative_difference_set_from_homomorphism(q, N, d, check=True, return_group=
return G2, second_diff_set
return second_diff_set


def is_relative_difference_set(R, G, H, params, verbose=False):
r"""
Check if ``R`` is a difference set of ``G`` relative to ``H``, with the given parameters.
Expand Down Expand Up @@ -2040,9 +2039,6 @@ def skew_supplementary_difference_set_over_polynomial_ring(n, existence=False, c
...
NotImplementedError: skew SDS of order 7 not yet implemented
"""
from sage.symbolic.ring import SymbolicRing
from sage.rings.finite_rings.integer_mod_ring import Zmod

data = {
81: (3, lambda x: x**4 - x**3 - 1, 16, 5,
[1, 2, 4, 6, 8, 10, 12, 14], [1, 2, 3, 4, 10, 11, 13],
Expand All @@ -2060,9 +2056,11 @@ def skew_supplementary_difference_set_over_polynomial_ring(n, existence=False, c

mod, poly, exp, order, ind1, ind2, ind3, ind4 = data[n]

from sage.rings.finite_rings.integer_mod_ring import Zmod

Z3 = Zmod(mod)
R = SymbolicRing()
x = R.var('x')
R = ZZ['x']
x = R.gen()
F = Z3.extension(poly(x))

H = [F.gen() ** (exp * i) for i in range(order)]
Expand Down
9 changes: 6 additions & 3 deletions src/sage/combinat/designs/incidence_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
# https://www.gnu.org/licenses/ #
# **************************************************************************
from __future__ import annotations
from sage.rings.integer import Integer

from sage.misc.latex import latex
from sage.misc.lazy_import import lazy_import
from sage.rings.integer import Integer
from sage.sets.set import Set
from sage.libs.gap.libgap import libgap

lazy_import('sage.libs.gap.libgap', 'libgap')


class IncidenceStructure():
Expand Down Expand Up @@ -173,7 +176,6 @@ def __init__(self, points=None, blocks=None, incidence_matrix=None,
sage: IncidenceStructure([])
Incidence structure with 0 points and 0 blocks
"""
from sage.matrix.constructor import matrix
from sage.structure.element import Matrix

# Reformatting input
Expand All @@ -189,6 +191,7 @@ def __init__(self, points=None, blocks=None, incidence_matrix=None,
assert incidence_matrix is None, "'incidence_matrix' cannot be defined when 'points' is defined"

if incidence_matrix:
from sage.matrix.constructor import matrix
M = matrix(incidence_matrix)
v = M.nrows()
self._points = list(range(v))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def __iter__(self):
"""
from sage.sets.non_negative_integers import NonNegativeIntegers
from sage.categories.cartesian_product import cartesian_product
from sage.misc.misc import subsets
from sage.combinat.subset import subsets
# the product of positive integers automatically implements an
# an enumeration which allows us to get out of the first column
N = NonNegativeIntegers()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/diagram_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def planar_partitions_rec(X):
if len(X) > 1:
yield ([X[0]], [X[1]])
return
from sage.misc.misc import powerset
from sage.combinat.subset import powerset
from itertools import product
for S in powerset(range(len(X)-1)):
if not S:
Expand Down
4 changes: 3 additions & 1 deletion src/sage/combinat/integer_vector_weighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
from sage.categories.sets_with_grading import SetsWithGrading
from sage.misc.lazy_import import lazy_import
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.combinat.integer_vector import IntegerVector
from sage.combinat.words.word import Word
from sage.combinat.permutation import Permutation

lazy_import('sage.combinat.words.word', 'Word')


class WeightedIntegerVectors(Parent, UniqueRepresentation):
r"""
Expand Down
16 changes: 14 additions & 2 deletions src/sage/combinat/interval_posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3042,7 +3042,13 @@ def final_forest(element) -> TIP:
"""
if isinstance(element, TamariIntervalPoset):
return element.final_forest()
if element in DyckWords():

try:
DW = DyckWords()
except ImportError:
DW = ()

if element in DW:
binary_tree = element.to_binary_tree_tamari()
elif element in BinaryTrees() or element in LabelledBinaryTrees():
binary_tree = element
Expand Down Expand Up @@ -3149,7 +3155,13 @@ def initial_forest(element) -> TIP:
"""
if isinstance(element, TamariIntervalPoset):
return element.initial_forest()
if element in DyckWords():

try:
DW = DyckWords()
except ImportError:
DW = ()

if element in DW:
binary_tree = element.to_binary_tree_tamari()
elif element in BinaryTrees() or element in LabelledBinaryTrees():
binary_tree = element
Expand Down
Loading