Skip to content

bound.py

from pymwp import Bound

Bound

Bound(bounds: dict[str, str] = None)

Represents a mwp-bound for a relation. If derivation succeeds, there is one mwp-bound expression for each input variable.

Attributes:

Name Type Description
bound_dict Dict[str, MwpBound]

Variable bounds.

Create a bound.

Parameters:

Name Type Description Default
bounds dict[str, str]

Dictionary of mwp-bounds.

None

variables property

variables: List[str]

List of variables.

calculate

calculate(relation: SimpleRelation) -> Bound

Calculate bound from a simple-valued matrix.

Parameters:

Name Type Description Default
relation SimpleRelation

A simple-valued relation.

required

Returns:

Type Description
Bound

The bound for the relation.

show

show(
    compact: bool = False,
    significant: bool = False,
    variables: Tuple[str] = None,
) -> str

Formatted display-string of a bound.

Parameters:

Name Type Description Default
compact bool

reduce whitespace in the output

False
significant bool

omit bounds that depend only on self

False
variables Tuple[str]

list of variables to display

None

Returns:

Type Description
str

A formatted string of the bound.

to_dict

to_dict() -> dict

A dictionary representation of a bound.

HonestPoly

HonestPoly(operator: str, *init_vars: str)

Models an honest polynomial.

Attributes:

Name Type Description
variables set[str]

List of variables.

var_fmt(Callable) set[str]

Variable formatter.

op str

Operator.

Creates a honest polynomial.

Parameters:

Name Type Description Default
operator str

Operator.

required
*init_vars str

Arbitrary variables.

()

empty property

empty: bool

True if honest polynomial is empty.

value property

value: Union[int, str]

String representation of HP value.

vars property

vars: List[str]

Sorted list of variables.

add

add(*identifier: str)

Add variables to HP.

MaxVar

MaxVar(*init_vars: str)

Bases: HonestPoly

Representation for m-variables.

MwpBound

MwpBound(triple: str = None)

Represents a mwp-bound.

Attributes:

Name Type Description
x Tuple[str]

List of m-variables.

y Tuple[str]

List of w-variables.

z Tuple[str]

List of p-variables.

Create mwp-bound.

Parameters:

Name Type Description Default
triple str

Bound expression as bound_str.

None

bound_str property

bound_str: str

Alternative bounds representation, as a ;-separated string.

Returns:

Type Description
str

Current bound as \(m;w;p\) where the first section contains list of variables in m, second contains variables in w, and last in p (if any). Multiple elements in the lists are separated by commas.

bound_triple property

bound_triple: B_TRIPLE

Alternative bounds representation, as three tuples.

Returns:

Type Description
B_TRIPLE

Current bound as \((m_1,...m_n), (w_1,...w_n), (p_1,...p_n)\) where the first contains list of variables in m, second contains variables in w, and last in p (if any).

append

append(scalar: str, var_name: str)

Append variable dependency in the right list by scalar.

parse staticmethod

parse(value: str = None) -> B_TRIPLE

Restore a bound from string-triple format.