mqt.core.ir.symbolic

Module Contents

class Variable(name: str = '')

A symbolic 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.

Parameters:

name – The name of the variable.

property name: str

The name of the variable.

__eq__(arg: object, /) bool
__ne__(arg: object, /) bool
__hash__() int
__lt__(arg: Variable, /) bool
__gt__(arg: Variable, /) bool
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 variable: Variable

The variable of the term.

property coefficient: float

The coefficient of the term.

has_zero_coefficient() bool

Check if the coefficient of the term is zero.

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.

__mul__(arg: float, /) Term
__rmul__(arg: float, /) Term
__truediv__(arg: float, /) Term
__eq__(arg: object, /) bool
__ne__(arg: object, /) bool
__hash__() int
class Expression(constant: float = 0.0)
class Expression(terms: Sequence[Term], constant: float = 0.0)
class Expression(term: Term, 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\). Alternatively, an expression can be created with a single term and a constant or just a constant.

Parameters:
  • terms – The list of terms.

  • constant – The constant.

property constant: float

The constant of the expression.

__iter__() Iterator[Term]
__getitem__(index: int) Term
is_zero() bool

Check if the expression is zero.

is_constant() bool

Check if the expression is a constant.

num_terms() int

The number of terms in the expression.

__len__() int
property terms: list[Term]

The terms of the expression.

property variables: set[Variable]

The variables in the 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.

__add__(arg: Expression, /) Expression
__add__(arg: float, /) Expression
__add__(arg: Term, /) Expression
__radd__(arg: Term, /) Expression
__radd__(arg: float, /) Expression
__sub__(arg: Expression, /) Expression
__sub__(arg: float, /) Expression
__sub__(arg: Term, /) Expression
__rsub__(arg: float, /) Expression
__rsub__(arg: Term, /) Expression
__mul__(arg: float, /) Expression
__rmul__(arg: float, /) Expression
__truediv__(arg: float, /) Expression
__eq__(arg: object, /) bool
__ne__(arg: object, /) bool
__hash__() int