Skip to content

Commit 6745cf1

Browse files
committed
Some last details and optimizations to Stream_plethysm.
1 parent 94219d4 commit 6745cf1

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

src/sage/data_structures/stream.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
from sage.rings.integer_ring import ZZ
9898
from sage.rings.infinity import infinity
9999
from sage.arith.misc import divisors
100+
from sage.misc.misc_c import prod
100101
from sage.combinat.integer_vector_weighted import iterator_fast as wt_int_vec_iter
101102
from sage.combinat.sf.sfa import _variables_recursive, _raise_variables
102103
from sage.categories.hopf_algebras_with_basis import HopfAlgebrasWithBasis
@@ -1814,21 +1815,21 @@ def get_coefficient(self, n):
18141815
if self._right[0]:
18151816
assert self._degree_f is not None, "the plethysm with a lazy symmetric function of valuation 0 is defined only for symmetric functions of finite support"
18161817

1817-
return sum((c * self._compute_product(n, la)
1818+
return sum((c * self.compute_product(n, la)
18181819
for k in range(self._left._approximate_order, self._degree_f)
18191820
for la, c in self._left[k]),
18201821
self._basis.zero())
18211822

1822-
return sum((c * self._compute_product(n, la)
1823+
return sum((c * self.compute_product(n, la)
18231824
for k in range(self._left._approximate_order, n+1)
18241825
for la, c in self._left[k]),
18251826
self._basis.zero())
18261827

1827-
def _compute_product(self, n, la):
1828-
"""
1828+
def compute_product(self, n, la):
1829+
r"""
18291830
Compute the product ``c * p[la](self._right)`` in degree ``n``.
18301831
1831-
TESTS::
1832+
EXAMPLES::
18321833
18331834
sage: from sage.data_structures.stream import Stream_plethysm, Stream_exact, Stream_function, Stream_zero
18341835
sage: s = SymmetricFunctions(QQ).s()
@@ -1859,27 +1860,34 @@ def _compute_product(self, n, la):
18591860
sage: all(h._compute_product(k, Partition([2, 2, 1])) == B.restrict_degree(k) for k in range(7))
18601861
True
18611862
"""
1863+
# This is the approximate order of the result
1864+
rao = self._right._approximate_order
1865+
ret_approx_order = rao * sum(la)
18621866
ret = self._basis.zero()
1867+
if n < ret_approx_order:
1868+
return ret
1869+
18631870
la_exp = la.to_exp()
18641871
wgt = [i for i, m in enumerate(la_exp, 1) if m]
18651872
exp = [m for m in la_exp if m]
1866-
for k in wt_int_vec_iter(n, wgt):
1873+
wgt.reverse()
1874+
exp.reverse()
1875+
for k in wt_int_vec_iter(n - ret_approx_order, wgt):
18671876
# TODO: it may make a big difference here if the
1868-
# approximate order would be updated
1869-
if any(d < self._right._approximate_order * m
1870-
for m, d in zip(exp, k)):
1871-
continue
1872-
prod = self._basis.one()
1873-
for i, m, d in zip(wgt, exp, k):
1874-
prod *= self._stretched_power_restrict_degree(i, m, d)
1875-
ret += prod
1877+
# approximate order would be updated.
1878+
# The test below is based off not removing the flxed block
1879+
#if any(d < self._right._approximate_order * m
1880+
# for m, d in zip(exp, k)):
1881+
# continue
1882+
ret += prod(self.stretched_power_restrict_degree(i, m, rao * m + d)
1883+
for i, m, d in zip(wgt, exp, k))
18761884
return ret
18771885

1878-
def _stretched_power_restrict_degree(self, i, m, d):
1879-
"""
1886+
def stretched_power_restrict_degree(self, i, m, d):
1887+
r"""
18801888
Return the degree ``d*i`` part of ``p([i]*m)(g)``.
18811889
1882-
TESTS::
1890+
EXAMPLES::
18831891
18841892
sage: from sage.data_structures.stream import Stream_plethysm, Stream_exact, Stream_function, Stream_zero
18851893
sage: s = SymmetricFunctions(QQ).s()
@@ -1908,11 +1916,11 @@ def _stretched_power_restrict_degree(self, i, m, d):
19081916
# integer and not a symmetric function
19091917
if power_d:
19101918
if self._tensor_power is None:
1911-
terms = {m.stretch(i): raised_c for m, c in power_d
1919+
terms = {mon.stretch(i): raised_c for mon, c in power_d
19121920
if (raised_c := _raise_variables(c, i, self._degree_one))}
19131921
else:
1914-
terms = {tuple((mu.stretch(i) for mu in m)): raised_c
1915-
for m, c in power_d
1922+
terms = {tuple((mu.stretch(i) for mu in mon)): raised_c
1923+
for mon, c in power_d
19161924
if (raised_c := _raise_variables(c, i, self._degree_one))}
19171925
return self._p.element_class(self._p, terms)
19181926

0 commit comments

Comments
 (0)