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

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)) = w2+w3+w4w^2 + w^3 + w^4. When min = -1, it denotes 0, when max = -1, it denotes the infinity.

Preconditions:

  • min <= max

Examples

import vcsn weight = vcsn.context('law_char, q').weight

Simple Multiplication

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

weight('1/2') * weight('3')

32\frac{3}{2}

weight('1/2').multiply(weight('3'))

32\frac{3}{2}

Repeated Multiplication

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

half = weight('1/2') half ** 3

18\frac{1}{8}

half ** 0

11

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

half ** -1

22

half.star()

22

Sums of Repeated Multiplications

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

half ** (2, 2)

14\frac{1}{4}

half ** (2, 4)

716\frac{7}{16}

half ** 2 + half ** 3 + half ** 4

716\frac{7}{16}

half ** (0, 2)

74\frac{7}{4}

half ** (1, -1)

11