5.1.1.1 FreeMonoid_class Objects

class FreeMonoid_class
The free monoid on $ n$ generators.
FreeMonoid_class( 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 (x_0, x_1, x_2)
sage: x = F.gens()
sage: x[0]*x[1]**5 * (x[0]*x[2])
x_0*x_1^5*x_0*x_2
sage: F = FreeMonoid(3, 'a')
sage: F
Free monoid on 3 generators (a_0, a_1, a_2)

Instances of class FreeMonoid_class have the following methods (in addition to inherited methods and special methods):

gen,$  $ ngens

Further documentation:

gen( i)

The $ i$ -th generator of the monoid.

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

ngens( )

The number of free generators of the monoid.

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

Instances of class FreeMonoid_class also have the following special methods:

__call__,$  $ __contains__,$  $ __repr__

Further documentation:

__call__( 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))
a_0
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)])
a_0^5*a_1^2*a_0^12*a_1^2

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