Expression Simplifier Module
SRToolkit.utils.expression_simplifier
simplify(expr, symbol_library=SymbolLibrary.default_symbols())
Simplifies a mathematical expression by
- making use of sympy's simplification functions
- simplifying constants, e.g. C*C + C -> C
Examples:
>>> expr = ["C", "+", "C" "*", "C", "+", "X_0", "*", "X_1", "/", "X_0"]
>>> print("".join(simplify(expr)))
C+X_1
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
Union[List[str], Node]
|
The expression given as a list of tokens in the infix notation or as an instance of SRToolkit.utils.expression_tree.Node |
required |
symbol_library
|
SymbolLibrary
|
The symbol library to use. Defaults to SymbolLibrary.default_symbols(). |
default_symbols()
|
Returns:
Type | Description |
---|---|
Union[List[str], Node]
|
The simplified expression |