Skip to content

Commit 362d8f1

Browse files
committed
Being more careful with the parent in from_finite_word().
1 parent 64cae73 commit 362d8f1

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/sage/combinat/chas/wqsym.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ def __init__(self, alg, graded=True):
6969
sage: M = algebras.WQSym(QQ).M()
7070
sage: TestSuite(M).run() # long time
7171
"""
72+
def sorting_key(X):
73+
return (sum(map(len, X)), X)
7274
CombinatorialFreeModule.__init__(self, alg.base_ring(),
7375
OrderedSetPartitions(),
7476
category=WQSymBases(alg, graded),
77+
sorting_key=sorting_key,
7578
bracket="", prefix=self._prefix)
7679

7780
def _repr_term(self, osp):
@@ -2224,7 +2227,7 @@ def algebraic_complement(self):
22242227
sage: M[[1,4],[2,5],[3,6]].algebraic_complement()
22252228
M[{3, 6}, {2, 5}, {1, 4}]
22262229
sage: (3*M[[1]] - 4*M[[]] + 5*M[[1],[2]]).algebraic_complement()
2227-
3*M[{1}] - 4*M[] + 5*M[{2}, {1}]
2230+
-4*M[] + 3*M[{1}] + 5*M[{2}, {1}]
22282231
sage: X = WQSym.X()
22292232
sage: X[[1,3],[2]].algebraic_complement()
22302233
X[{2}, {1, 3}]
@@ -2389,7 +2392,7 @@ def coalgebraic_complement(self):
23892392
sage: M[[1,4],[2,5],[3,6]].coalgebraic_complement()
23902393
M[{3, 6}, {2, 5}, {1, 4}]
23912394
sage: (3*M[[1]] - 4*M[[]] + 5*M[[1],[2]]).coalgebraic_complement()
2392-
3*M[{1}] - 4*M[] + 5*M[{2}, {1}]
2395+
-4*M[] + 3*M[{1}] + 5*M[{2}, {1}]
23932396
sage: X = WQSym.X()
23942397
sage: X[[1,3],[2]].coalgebraic_complement()
23952398
X[{1, 3}, {2}]
@@ -2500,7 +2503,7 @@ def star_involution(self):
25002503
sage: M[[1,4],[2,5],[3,6]].star_involution()
25012504
M[{1, 4}, {2, 5}, {3, 6}]
25022505
sage: (3*M[[1]] - 4*M[[]] + 5*M[[1],[2]]).star_involution()
2503-
3*M[{1}] - 4*M[] + 5*M[{1}, {2}]
2506+
-4*M[] + 3*M[{1}] + 5*M[{1}, {2}]
25042507
sage: X = WQSym.X()
25052508
sage: X[[1,3],[2]].star_involution()
25062509
X[{2}, {1, 3}]

src/sage/combinat/set_partition_ordered.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ def __contains__(self, x):
10301030
# sets is the original set
10311031
return len(u) == len(self._set)
10321032

1033-
def from_finite_word(self, w):
1033+
def from_finite_word(self, w, check=True):
10341034
r"""
10351035
Return the unique ordered set partition of `\{1, 2, \ldots, n\}` corresponding
10361036
to a word `w` of length `n`.
@@ -1051,14 +1051,24 @@ def from_finite_word(self, w):
10511051
10521052
sage: A = OrderedSetPartitions().from_finite_word('abcabca')
10531053
sage: A.parent()
1054+
Ordered set partitions
1055+
1056+
sage: A = OrderedSetPartitions(7).from_finite_word('abcabca')
1057+
sage: A.parent()
10541058
Ordered set partitions of {1, 2, 3, 4, 5, 6, 7}
10551059
"""
10561060
# TODO: fix this if statement.
10571061
# In fact, what we need is for the underlying alphabet to be sortable.
10581062
if isinstance(w, (list, tuple, str, FiniteWord_class)):
10591063
W = Words(infinite=False)
1060-
s = frozenset(range(1, len(w) + 1))
1061-
return self.element_class(self.subset(s), W(w).to_ordered_set_partition())
1064+
if check:
1065+
try:
1066+
X = self._set
1067+
if len(X) != len(w) or X != frozenset(range(1, len(w) + 1)):
1068+
raise ValueError(f"result not in {self}")
1069+
except AttributeError:
1070+
pass
1071+
return self.element_class(self, W(w).to_ordered_set_partition())
10621072
raise TypeError(f"`from_finite_word` expects an object of type list/tuple/str/Word "
10631073
f"representing a finite word, received {w}")
10641074

0 commit comments

Comments
 (0)