expression.multiply

This function is overloaded, it supports three different signatures:

  • expression.multiply(exp)

    The product (i.e., the concatenation) of two expressions: a.multiply(b) => ab.

  • expression.multiply(num)

    The repeated multiplication (concatenation) of an expression with itself: a.multiply(3) => aaa. Exponent -1 denotes the infinity: the Kleene star.

  • expression.multiply((min,max))

    The sum of repeated multiplication of an expressions: a.multiply((2,4)) => aa+aaa+aaaa.

Preconditions:

  • min <= max
  • None

See also:

Examples

In [1]:
import vcsn
ctx = vcsn.context('law_char, z')
def exp(e):
    return ctx.expression(e)

Simple Multiplication

Instead of a.multiply(b), you may write a * b.

In [2]:
exp('a*b') * exp('ab*')
Out[2]:
${\mathit{a}}^{*} \, \mathit{b} \, \mathit{a} \, {\mathit{b}}^{*}$

Of course, trivial identities are applied.

In [3]:
exp('<2>a') * exp('<3>\e')
Out[3]:
$ \left\langle 6 \right\rangle \,\mathit{a}$
In [4]:
exp('<2>a') * exp('\z')
Out[4]:
$\emptyset$

In the case of word labels, adjacent words are not fused: concatenation of two expressions behaves as if the expressions were parenthetized. Pay attention to the space between $a$ and $b$ below, admittedly too discreet.

In [5]:
exp('a') * exp('b') # Two one-letter words
Out[5]:
$\mathit{a} \, \mathit{b}$
In [6]:
exp('ab') # One two-letter word
Out[6]:
$\mathit{ab}$
In [7]:
exp('(a)(b)') # Two one-letter words
Out[7]:
$\mathit{a} \, \mathit{b}$

Repeated Multiplication

Instead of a.multiply(3), you may write a ** 3. Beware that a * 3 actually denotes a.right_mult(3).

In [8]:
exp('ab') ** 3
Out[8]:
$\left(\mathit{ab}\right) \, \left(\mathit{ab}\right) \, \left(\mathit{ab}\right)$
In [9]:
exp('a*') * 3
Out[9]:
$ \left\langle 3 \right\rangle \,{\mathit{a}}^{*}$

Use the exponent -1 to mean infinity. Alternatively, you may invoke a.star instead of a ** -1.

In [10]:
exp('ab') ** -1
Out[10]:
$\left(\mathit{ab}\right)^{*}$
In [11]:
exp('ab').star()
Out[11]:
$\left(\mathit{ab}\right)^{*}$

Sums of Repeated Multiplication

Instead of a.multiply((2, 4)), you may write a ** (2, 4). Again, use exponent -1 to mean infinity.

In [12]:
exp('ab') ** (2, 2)
Out[12]:
$\left(\mathit{ab}\right) \, \left(\mathit{ab}\right)$
In [13]:
exp('ab') ** (2, 4)
Out[13]:
$\left(\mathit{ab}\right) \, \left(\mathit{ab}\right) \, \left(\varepsilon + \mathit{ab} + \left(\mathit{ab}\right) \, \left(\mathit{ab}\right)\right)$
In [14]:
exp('ab') ** (-1, 2)
Out[14]:
$\varepsilon + \mathit{ab} + \left(\mathit{ab}\right) \, \left(\mathit{ab}\right)$
In [15]:
exp('ab') ** (2, -1)
Out[15]:
$\left(\mathit{ab}\right) \, \left(\mathit{ab}\right) \, \left(\mathit{ab}\right)^{*}$