AbstractExpression¶
- class pqp.symbols.AbstractExpression¶
Bases:
AbstractMath
,ABC
Abstract class defining needed recursive operations for relations
Methods Summary
assign
(var[, val])Assigns a value to a variable in an expression.
copy
()Returns a copy of the expression (variables are not copied).
Returns the set of free variables in an expression.
intervene
(var)Intervenes on a variable in an expression.
r_adapt_map
(func)Recursive map where the func decides callables used to transform children
r_map
(func)Recursively maps a function over the expression tree
sorted
()Returns a sorted copy of an expression for structural comparison.
syntactic_eq
(other)Test whether two Expressions are syntactically identical (structural compare without sorting first)
Methods Documentation
- assign(var, val=None)¶
Assigns a value to a variable in an expression.
Note that assignment will not propogate downwards through a sum over a variable.
- Parameters:
var (Variable) – The variable to assign to
val (AbstractMath) – The value to assign, if this is P.unassigned, the expression is copied and returned
- Returns:
a new expression where the assignment has occured
- Return type:
- abstract copy()¶
Returns a copy of the expression (variables are not copied).
- free_variables()¶
Returns the set of free variables in an expression.
- intervene(var)¶
Intervenes on a variable in an expression.
Note that intervention will not propogate downwards through a sum over a variable.
- Parameters:
var (Variable or list) – The variable(s) to intervene on
- Returns:
a new expression where the intervention has occured
- Return type:
- abstract r_adapt_map(func)¶
Recursive map where the func decides callables used to transform children
DO NOT USE! This is a powerful and necessary method but it results in almost unreadable code.
So, func takes an AbstractExpression and needs to return a tuple of two things. First, a function A which maps from AbstractExpression to AbstractExpression. Second, a function B of the same time as func.
At each level of recursion, func will be called on an expression E to get A and B. This method, r_adapt_map will then be called on the children of E with B as input (if B is None, recursion terminates). An expression of the same type as E is then constructed with the results of the recursive calls using B, and A is applied to the result.
- Parameters:
func (function) – A function that takes an AbstractExpression and returns two functions (see desc)
- abstract r_map(func)¶
Recursively maps a function over the expression tree
- abstract sorted()¶
Returns a sorted copy of an expression for structural comparison.
- abstract syntactic_eq(other)¶
Test whether two Expressions are syntactically identical (structural compare without sorting first)