Elements of Free Monoids - Monoids

Skip to content
Back to top
View this page
Edit this page

# Elements of Free Monoids

AUTHORS:

- David Kohel (2005-09-29)

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

class sage.monoids.free_monoid_element.FreeMonoidElement(F, x, check=True)

  Bases: `MonoidElement`

  Element of a free monoid.

  EXAMPLES:

  Sage

      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
      sage: x**(-1)
      Traceback (most recent call last):
      ...
      NotImplementedError

  Python

      >>> from sage.all import *
      >>> a = FreeMonoid(Integer(5), 'a').gens()
      >>> x = a[Integer(0)]*a[Integer(1)]*a[Integer(4)]**Integer(3)
      >>> x**Integer(3)
      a0*a1*a4^3*a0*a1*a4^3*a0*a1*a4^3
      >>> x**Integer(0)
      1
      >>> x**(-Integer(1))
      Traceback (most recent call last):
      ...
      NotImplementedError

  to_list(indices=False)

    Return `self` as a list of generators.

    If `self` equals \(x_{i_1} x_{i_2} \cdots x_{i_n}\), with \(x_{i_1}, x_{i_2}, \ldots, x_{i_n}\) being some of the generators of the free monoid, then this method returns the list \([x_{i_1}, x_{i_2}, \ldots, x_{i_n}]\).

    If the optional argument `indices` is set to `True`, then the list \([i_1, i_2, \ldots, i_n]\) is returned instead.

    EXAMPLES:

    Sage

        sage: M.<x,y,z> = FreeMonoid(3)
        sage: a = x * x * y * x
        sage: w = a.to_list(); w
        [x, x, y, x]
        sage: M.prod(w) == a
        True
        sage: w = a.to_list(indices=True); w
        [0, 0, 1, 0]
        sage: a = M.one()
        sage: a.to_list()
        []

    Python

        >>> from sage.all import *
        >>> M = FreeMonoid(Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = M._first_ngens(3)
        >>> a = x * x * y * x
        >>> w = a.to_list(); w
        [x, x, y, x]
        >>> M.prod(w) == a
        True
        >>> w = a.to_list(indices=True); w
        [0, 0, 1, 0]
        >>> a = M.one()
        >>> a.to_list()
        []

    See also

    `to_word()`

  to_word(alph=None)

    Return `self` as a word.

    INPUT:

    - `alph` – (optional) the alphabet which the result should be specified in

    EXAMPLES:

    Sage

        sage: M.<x,y,z> = FreeMonoid(3)
        sage: a = x * x * y * x
        sage: w = a.to_word(); w
        word: xxyx
        sage: w.to_monoid_element() == a
        True

    Python

        >>> from sage.all import *
        >>> M = FreeMonoid(Integer(3), names=('x', 'y', 'z',)); (x, y, z,) = M._first_ngens(3)
        >>> a = x * x * y * x
        >>> w = a.to_word(); w
        word: xxyx
        >>> w.to_monoid_element() == a
        True

    See also

    `to_list()`

sage.monoids.free_monoid_element.is_FreeMonoidElement(x)