mqt.core.symbolic

Symbolic expressions and terms.

Module Contents

class Expression(terms: Sequence[Term], constant: float = 0.0)
class Expression(term: Term, constant: float = 0.0)
class Expression(constant: float = 0.0)

A symbolic expression which consists of a sum of terms and a constant.

The expression is of the form \(constant + term_1 + term_2 + \dots + term_n\).

Parameters:
  • terms – The list of terms.

  • constant – The constant.

Alternatively, an expression can be created with a single term and a constant or just a constant.

property terms: list[Term]

The terms of the expression.

property variables: set[Variable]

The variables in the expression.

constant: float

The constant of the expression.

__add__(arg0: Expression) Expression
__add__(arg0: Term) Expression
__add__(arg0: float) Expression
__eq__(arg0: object) bool

Return self==value.

__getitem__(idx: int) Term
__hash__() int

Return hash(self).

__iter__() Iterator[Term]
__len__() int
__mul__(arg0: float) Expression
__ne__(arg0: object) bool

Return self!=value.

__radd__(arg0: Term) Expression
__radd__(arg0: float) Expression
__rmul__(arg0: float) Expression
__rsub__(arg0: Term) Expression
__rsub__(arg0: float) Expression
__rtruediv__(arg0: float) Expression
__sub__(arg0: Expression) Expression
__sub__(arg0: Term) Expression
__sub__(arg0: float) Expression
__truediv__(arg0: float) Expression
evaluate(assignment: Mapping[Variable, float]) float

Evaluate the expression with a given variable assignment.

Parameters:

assignment – The variable assignment.

Returns:

The evaluated value of the expression.

is_constant() bool

Check if the expression is a constant.

is_zero() bool

Check if the expression is zero.

num_terms() int

The number of terms in the expression.

class Term(variable: Variable, coefficient: float = 1.0)

A symbolic term which consists of a variable with a given coefficient.

Parameters:
  • variable – The variable of the term.

  • coefficient – The coefficient of the term.

property coefficient: float

The coefficient of the term.

property variable: Variable

The variable of the term.

__eq__(arg0: object) bool

Return self==value.

__hash__() int

Return hash(self).

__mul__(arg0: float) Term
__ne__(arg0: object) bool

Return self!=value.

__rmul__(arg0: float) Term
__rtruediv__(arg0: float) Term
__truediv__(arg0: float) Term
add_coefficient(coeff: float) None

Add a coefficient to the coefficient of this term.

Parameters:

coeff – The coefficient to add.

evaluate(assignment: Mapping[Variable, float]) float

Evaluate the term with a given variable assignment.

Parameters:

assignment – The variable assignment.

Returns:

The evaluated value of the term.

has_zero_coefficient() bool

Check if the coefficient of the term is zero.

class Variable(name: str = '')

A symbolic variable.

Parameters:

name – The name of the variable.

Note

Variables are uniquely identified by their name, so if a variable with the same name already exists, the existing variable will be returned.

property name: str

The name of the variable.

__eq__(arg0: object) bool

Return self==value.

__gt__(arg0: Variable) bool

Return self>value.

__hash__() int

Return hash(self).

__lt__(arg0: Variable) bool

Return self<value.

__ne__(arg0: object) bool

Return self!=value.