Skip to content

Commit

Permalink
Trac #16125: Implement method _an_element_ for Words
Browse files Browse the repository at this point in the history
{{{
sage: W = Words(4)
sage: w = W([3,1,2,1])
sage: w in ZZ
NotImplementedError                       Traceback (most recent call
last)
[...]
NotImplementedError: please implement _an_element_ for Words over {1, 2,
3, 4}
}}}

URL: http://trac.sagemath.org/16125
Reported by: virmaux
Ticket author(s): Aladin Virmaux
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager authored and vbraun committed Apr 14, 2014
2 parents 5ba81fc + 1af525d commit d1f7862
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/sage/algebras/shuffle_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ def coproduct(self, S):
sage: F = ShuffleAlgebra(QQ,'ab')
sage: S = F.an_element(); S
B[word: ] + 2*B[word: a] + 3*B[word: b]
2*B[word: ] + 2*B[word: a] + 3*B[word: b]
sage: F.coproduct(S)
B[word: ] # B[word: ] + 2*B[word: ] # B[word: a] + 3*B[word: ] # B[word: b]
2*B[word: ] # B[word: ] + 2*B[word: ] # B[word: a] + 3*B[word: ] # B[word: b]
+ 2*B[word: a] # B[word: ] + 3*B[word: b] # B[word: ]
sage: F.coproduct(F.one())
B[word: ] # B[word: ]
Expand All @@ -319,9 +319,9 @@ def counit(self,S):
sage: F = ShuffleAlgebra(QQ,'ab')
sage: S = F.an_element(); S
B[word: ] + 2*B[word: a] + 3*B[word: b]
2*B[word: ] + 2*B[word: a] + 3*B[word: b]
sage: F.counit(S)
1
2
"""
return S.monomial_coefficients().get(Word(), 0)

Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/modules_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ def _an_element_(self):
sage: B = HopfAlgebrasWithBasis(QQ).example(); B
An example of Hopf algebra with basis: the group algebra of the Dihedral group of order 6 as a permutation group over Rational Field
sage: A.an_element(), B.an_element()
(B[word: ] + 2*B[word: a] + 3*B[word: b], B[()] + 2*B[(2,3)] + 3*B[(1,2)] + B[(1,2,3)])
(2*B[word: ] + 2*B[word: a] + 3*B[word: b], B[()] + 2*B[(2,3)] + 3*B[(1,2)] + B[(1,2,3)])
sage: cartesian_product((A, B, A)).an_element() # indirect doctest
2*B[(0, word: )] + 2*B[(0, word: a)] + 3*B[(0, word: b)]
"""
Expand Down
21 changes: 21 additions & 0 deletions src/sage/combinat/words/words.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,27 @@ def _element_classes(self):
'Word_iter': word.Word_iter
}

def _an_element_(self):
r"""
Return an element of self.
EXAMPLES::
sage: W = Words(4)
sage: W.an_element()
word:
TESTS:
Check that :trac:`16125` is fixed::
sage: W = Words(4)
sage: w = W([3,1,2,1])
sage: w in ZZ
False
"""
return self([])

def __call__(self, data=None, length=None, datatype=None, caching=True, **kwds):
r"""
Construct a new word object with parent self.
Expand Down

0 comments on commit d1f7862

Please sign in to comment.