Skip to content

normalizer

Defines a normalizer to transform mG expressions in normal form.

This package defines the functions to normalize mG expressions when provided either as strings or expression trees.

The package contains the following objects:

  • mg_normalizer

mg_normalizer module-attribute

mg_normalizer = Normalizer()

Normalizer instance on which to call normalize.

Examples:

>>> mg_normalizer.normalize('fix Y = a in (fix X = b in (Y || c))')
"fix Y = a in (Y || c)"

Normalizer

Normalizer()

Bases: Interpreter[Token, Tree]

Normalizer for mG expression trees.

Transforms a mG expression in normal form, by acting on its parse tree. Currently, this class only removes fixpoint/repeat expressions in which the fixpoint variable does not occur in the fixpoint body, and rewrites expressions so that fixpoint variables never occur on the right hand side of a sequential composition expression.

Attributes:

  • bound_vars

    The dictionary of local variables encountered during traversal of the tree.

  • bound_funs

    The dictionary of local functions encountered during traversal of the tree.

Source code in libmg/normalizer/normalizer.py
def __init__(self):
    """Initializes the instance.
    """
    self.bound_vars = {}
    self.bound_funs = {}

normalize

normalize(expr: Any) -> Any

Normalizes a mG expression.

If the expression is provided as a parse tree, a normalized parse tree is returned. If the expression is provided as string, a normalized string is returned.

Parameters:

  • expr (Any) –

    The expression to normalize.

Returns:

  • Any

    The normalized expression.

Source code in libmg/normalizer/normalizer.py
@singledispatchmethod
def normalize(self, expr: Any) -> Any:
    """Normalizes a mG expression.

    If the expression is provided as a parse tree, a normalized parse tree is returned.
    If the expression is provided as string, a normalized string is returned.

    Args:
        expr: The expression to normalize.

    Returns:
        The normalized expression.

    """
    raise NotImplementedError(f"Cannot format value of type {type(expr)}")