9.2 Monoid Elements

Module: sage.monoids.free_monoid_element

Author: David Kohel (kohel@maths.usyd.edu.au), 2005/09/29

Elements of free monoids are represented internally as lists of pairs of integers.

Module-level Functions

is_FreeMonoidElement( x)

Class: FreeMonoidElement

class FreeMonoidElement
Element of a free monoid.
FreeMonoidElement( self, F, x, [check=True])

Create the element $ x$ of the FreeMonoid $ F$ .

This should typically be called by a FreeMonoid.

Special Functions: __cmp__,$  $ __len__,$  $ __mul__,$  $ __pow__,$  $ __repr__,$  $ _latex_

__len__( self)

Return the number of products that occur in this monoid element. For example, the length of the identity is 0, and the length of the monoid $ x_0^2x_1$ is three.

sage: F = FreeMonoid(3, 'a')
sage: z = F(1)
sage: len(z)
0
sage: a = F.gens()
sage: len(a[0]**2 * a[1])
3

__mul__( self, y)

Multiply 2 free monoid elements.

sage: a = FreeMonoid(5, 'a').gens()
sage: x = a[0] * a[1] * a[4]**3
sage: y = a[4] * a[0] * a[1]
sage: x*y
a0*a1*a4^4*a0*a1

__pow__( self, n)

Return the $ n$ -th power of this monoid element.

sage: a = FreeMonoid(5, 'a').gens()
sage: x = a[0]*a[1]*a[4]**3
sage: x**3
a0*a1*a4^3*a0*a1*a4^3*a0*a1*a4^3
sage: x**0
1

Note that raising to a negative power is not a constructor for an element of the corresponding free group (yet).

sage: x**(-1)
Traceback (most recent call last):
...
IndexError: Argument n (= -1) must be non-negative.

_latex_( self)

Return latex representation of self.

sage: F = FreeMonoid(3, 'a')
sage: z = F([(0,5),(1,2),(0,10),(0,2),(1,2)])
sage: z._latex_()
'a0^{5}a1^{2}a0^{12}a1^{2}'

See About this document... for information on suggesting changes.