9.1 Free Monoids

Module: sage.monoids.free_monoid

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

SAGE supports free monoids on any prescribed finite number $ n \geq 0$ of generators. Use the FreeMonoid function to create a free monoid, and the gen and gens functions to obtain the corresponding generators. You can print the generators as arbitrary strings using the optional names argument to the FreeMonoid function.

Module-level Functions

FreeMonoid( n, [names=None])

Returns a free monoid on $ n$ generators.

INPUT:
    n -- integer
    names -- (optional) names of generators

OUTPUT:
    free abelian monoid

sage: FreeMonoid(0)
Free monoid on 0 generators ()
sage: F = FreeMonoid(5, names = list("abcde"))
sage: F
Free monoid on 5 generators (a, b, c, d, e)
sage: F(1)
1
sage: (a, b, c, d, e) = F.gens()
sage: mul([ a, b, a, c, b, d, c, d ])
a*b*a*c*b*d*c*d

is_FreeMonoid( x)

Return True if $ x$ is a free monoid.

sage: is_FreeMonoid(5)
False
sage: is_FreeMonoid(FreeMonoid(7))
True
sage: is_FreeMonoid(FreeAbelianMonoid(7))
False
sage: is_FreeMonoid(FreeAbelianMonoid(0))
False

Class: FreeMonoid_class

class FreeMonoid_class
The free monoid on $ n$ generators.
FreeMonoid_class( self, n, [names=None])

Create free monoid on $ n$ generators.

INPUT:
    n -- integer
    names -- (optional) variable name or list of variable names

sage: F = FreeMonoid(3)
sage: F
Free monoid on 3 generators (x0, x1, x2)
sage: x = F.gens()
sage: x[0]*x[1]**5 * (x[0]*x[2])
x0*x1^5*x0*x2
sage: F = FreeMonoid(3, 'a')
sage: F
Free monoid on 3 generators (a0, a1, a2)

sage: M = FreeMonoid(3, names=['a','b','c'])
sage: loads(M.dumps()) == M
True

Functions: gen,$  $ ngens

gen( self, [i=0])

The $ i$ -th generator of the monoid.

INPUT:
    i -- integer (default: 0)

sage: F = FreeMonoid(3, 'a')
sage: F.gen(1)
a1
sage: F.gen(2)
a2
sage: F.gen(5)
Traceback (most recent call last):
...
IndexError: Argument i (= 5) must be between 0 and 2.

ngens( self)

The number of free generators of the monoid.

sage: F = FreeMonoid(2005)
sage: F.ngens()
2005

Special Functions: __call__,$  $ __cmp__,$  $ __contains__,$  $ __repr__

__call__( self, x, [check=True])

Return $ x$ coerced into this free monoid.

One can create a free monoid from the integer 1 and from a list of 2-tuples of integers $ (i,j)$ , where $ (i,j)$ corresponds to $ x_i^j$ , where $ x_i$ is the $ i$ th generator.

sage: F = FreeMonoid(3, 'a')
sage: F(1)
1
sage: F(F.gen(0))
a0
sage: F(0)
Traceback (most recent call last):
...
TypeError: Argument x (= 0) is of the wrong type.

sage: F([(0,5),(1,2),(0,10),(0,2),(1,2)])
a0^5*a1^2*a0^12*a1^2

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