Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Abelian Monoid Elements
AUTHORS:
- David Kohel (2005-09)
EXAMPLES:
Recall the example from abelian monoids::
sage: F = FreeAbelianMonoid(5,names = list("abcde")) sage: (a,b,c,d,e) = F.gens() sage: a*b^2*e*d a*b^2*d*e sage: x = b^2*e*d*a^7 sage: x a^7*b^2*d*e sage: x.list() [7, 2, 0, 1, 1]
The list is a copy, so changing the list does not change the element::
sage: x.list()[0] = 0 sage: x a^7*b^2*d*e """
#***************************************************************************** # Copyright (C) 2006 William Stein <wstein@gmail.com> # Copyright (C) 2005 David Kohel <kohel@maths.usyd.edu> # # Distributed under the terms of the GNU General Public License (GPL) # http://www.gnu.org/licenses/ #***************************************************************************** from six import integer_types
from sage.structure.richcmp import richcmp from sage.rings.integer import Integer from sage.structure.element import MonoidElement
def is_FreeAbelianMonoidElement(x): r""" Queries whether ``x`` is an object of type ``FreeAbelianMonoidElement``.
INPUT:
- ``x`` -- an object.
OUTPUT:
- ``True`` if ``x`` is an object of type ``FreeAbelianMonoidElement``; ``False`` otherwise. """ return isinstance(x, FreeAbelianMonoidElement)
class FreeAbelianMonoidElement(MonoidElement): def __init__(self, F, x): """ Create the element x of the FreeAbelianMonoid F.
EXAMPLES::
sage: F = FreeAbelianMonoid(5, 'abcde') sage: F Free abelian monoid on 5 generators (a, b, c, d, e) sage: F(1) 1 sage: a, b, c, d, e = F.gens() sage: a^2 * b^3 * a^2 * b^4 a^4*b^7 sage: F = FreeAbelianMonoid(5, 'abcde') sage: a, b, c, d, e = F.gens() sage: a in F True sage: a*b in F True """ raise IndexError("argument length (= %s) must be %s"%(len(x), n)) else:
def _repr_(self): """ Return a string representation of ``self``.
EXAMPLES::
sage: F = FreeAbelianMonoid(5, 'abcde') sage: F(1) 1 sage: a, b, c, d, e = F.gens() sage: a^2 * b^3 * a^2 * b^4 a^4*b^7 """ else:
def _richcmp_(self, other, op): """ Rich comparison.
EXAMPLES::
sage: F = FreeAbelianMonoid(5, 'abcde') sage: F(1) 1 sage: a, b, c, d, e = F.gens() sage: x = a^2 * b^3 sage: F(1) < x True sage: x > b True sage: x <= a^4 True sage: x != a*b True sage: a*b == b*a True sage: x > a^3*b^2 False """
def __mul__(self, y): raise TypeError("argument y (= %s) is of wrong type"%y)
def __pow__(self, n): """ Raises self to the power of `n`.
AUTHORS:
- Tom Boothby (2007-08): Replaced O(log n) time, O(n) space algorithm with O(1) time and space"algorithm".
EXAMPLES::
sage: F = FreeAbelianMonoid(5,names = list("abcde")) sage: (a,b,c,d,e) = F.gens() sage: x = a*b^2*e*d; x a*b^2*d*e sage: x^3 a^3*b^6*d^3*e^3 sage: x^0 1 """ raise TypeError("argument n (= %s) must be an integer"%(n,)) raise IndexError("argument n (= %s) must be positive"%n) return self else:
def __hash__(self): """ Return the hash of ``self``.
EXAMPLES::
sage: F = FreeAbelianMonoid(5,names = list("abcde")) sage: (a,b,c,d,e) = F.gens() sage: x = a*b^2*e*d sage: hash(x) == hash(x) True """
def list(self): """ Return (a reference to) the underlying list used to represent this element. If this is a monoid in an abelian monoid on `n` generators, then this is a list of nonnegative integers of length `n`.
EXAMPLES::
sage: F = FreeAbelianMonoid(5, 'abcde') sage: (a, b, c, d, e) = F.gens() sage: a.list() [1, 0, 0, 0, 0] """
|