weight.multiply

This function is overloaded, it supports these signatures:

  • weight.multiply(w)

    The product of two weights.

  • weight.multiply(num)

    The repeated multiplication (power) of a weight with itself. Exponent -1 denotes the infinity.

  • weight.multiply((min,max))

    The sum of repeated multiplications of an expression: w.multiply((2,4)) = $w^2 + w^3 + w^4$. When min = -1, it denotes 0, when max = -1, it denotes the infinity.

Preconditions:

  • min <= max

Examples

In [1]:
import vcsn
weight = vcsn.context('law_char, q').weight

Simple Multiplication

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

In [2]:
weight('1/2') * weight('3')
Out[2]:
$\frac{3}{2}$
In [3]:
weight('1/2').multiply(weight('3'))
Out[3]:
$\frac{3}{2}$

Repeated Multiplication

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

In [4]:
half = weight('1/2')
half ** 3
Out[4]:
$\frac{1}{8}$
In [5]:
half ** 0
Out[5]:
$1$

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

In [6]:
half ** -1
Out[6]:
$2$
In [7]:
half.star()
Out[7]:
$2$

Sums of Repeated Multiplications

Instead of w.multiply((2, 4)), you may write w ** (2, 4). Again, use exponent max = -1 to denotes infinity.

In [8]:
half ** (2, 2)
Out[8]:
$\frac{1}{4}$
In [9]:
half ** (2, 4)
Out[9]:
$\frac{7}{16}$
In [10]:
half ** 2 + half ** 3 + half ** 4
Out[10]:
$\frac{7}{16}$
In [11]:
half ** (0, 2)
Out[11]:
$\frac{7}{4}$
In [12]:
half ** (1, -1)
Out[12]:
$1$