Skip to content

semiring.py

from pymwp.semiring import KEYS, ZERO_MWP, UNIT_MWP, prod_mwp, sum_mwp

INFTY_MWP module-attribute

INFTY_MWP: str = 'i'

Scalar that represents failure in the analysis ('i'), .

KEYS module-attribute

KEYS: List[str] = [ZERO_MWP, UNIT_MWP, WEAK_MWP, POLY_MWP, INFTY_MWP]

Different scalar values: "o", "m", "w", "p", "i"

POLY_MWP module-attribute

POLY_MWP: str = 'p'

Scalar that represents a polynomial flow in the analysis ('p').

UNIT_MWP module-attribute

UNIT_MWP: str = 'm'

Scalar that represents maximally linear flow in the analysis ('m').

WEAK_MWP module-attribute

WEAK_MWP: str = 'w'

Scalar that represents weak polynomial flow in the analysis ('w').

ZERO_MWP module-attribute

ZERO_MWP: str = 'o'

Scalar that represents no dependency (0) in the analysis ('o').

mwp_sort

mwp_sort(scalars: List[str])

Ascending sort of scalars (o < m < w < p < ).

prod_mwp

prod_mwp(scalar1: str, scalar2: str) -> str

Compute product of two scalars.

× 0 m w p
0 0 0 0 0
m 0 m w p
w 0 w w p
p 0 p p p

Parameters:

Name Type Description Default
scalar1 str

scalar value.

required
scalar2 str

scalar value.

required

Raises:

Type Description
Exception

if scalar1 or scalar2 is not in KEYS.

Returns:

Type Description
str

Product of scalar1 * scalar2.

sum_mwp

sum_mwp(scalar1: str, scalar2: str) -> str

Compute sum of two scalars.

+ 0 m w p
0 0 m w p
m m m w p
w w w w p
p p p p p

Parameters:

Name Type Description Default
scalar1 str

scalar value.

required
scalar2 str

scalar value.

required

Raises:

Type Description
Exception

if scalar1 or scalar2 is not in KEYS.

Returns:

Type Description
str

Sum of scalar1 + scalar2.