Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 45897
Kernel: Python 3

expression.multiply

This function is overloaded, it supports these 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 multiplications of an expression: a.multiply((2,4)) => aa+aaa+aaaa. When min = -1, it denotes 0, when max = -1, it denotes the infinity.

Preconditions:

  • min <= max

See also:

Examples

import vcsn exp = vcsn.context('law_char, q').expression

Simple Multiplication

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

exp('a*b') * exp('ab*')

abab{\mathit{a}}^{*} \, \mathit{b} \, \mathit{a} \, {\mathit{b}}^{*}

Of course, trivial identities are applied.

exp('<2>a') * exp('<3>\e')

6a \left\langle 6 \right\rangle \,\mathit{a}

exp('<2>a') * exp('\z')

\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 aa and bb below, admittedly too discreet.

(exp('a') * exp('b')).SVG() # Two one-letter words
Image in a Jupyter notebook
exp('ab').SVG() # One two-letter word
Image in a Jupyter notebook
exp('(a)(b)').SVG() # Two one-letter words
Image in a Jupyter notebook

Repeated Multiplication

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

exp('ab') ** 3

(ab)3\left(\mathit{ab}\right)^{3}

exp('ab') ** 0

ε\varepsilon

Beware that a * 3 actually denotes a.rweight(3).

exp('a*') * 3

3a \left\langle 3 \right\rangle \,{\mathit{a}}^{*}

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

exp('ab') ** -1

(ab)\left(\mathit{ab}\right)^{*}

exp('ab').star()

(ab)\left(\mathit{ab}\right)^{*}

Sums of Repeated Multiplications

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

exp('ab') ** (2, 2)

(ab)2\left(\mathit{ab}\right)^{2}

exp('ab') ** (2, 4)

(ab)2(ε+ab+(ab)2)\left(\mathit{ab}\right)^{2} \, \left(\varepsilon + \mathit{ab} + \left(\mathit{ab}\right)^{2}\right)

exp('ab') ** (-1, 2)

ε+ab+(ab)2\varepsilon + \mathit{ab} + \left(\mathit{ab}\right)^{2}

exp('ab') ** (2, -1)

(ab)2(ab)\left(\mathit{ab}\right)^{2} \, \left(\mathit{ab}\right)^{*}