Expectation¶
- class pqp.symbols.Expectation(sub, expr)¶
Bases:
AbstractExpression
,_NamespaceModifier
Represents an expectation or a random variable
Equivalent to $sum_{domain(sub)} sub * expr$
- Parameters:
sub (Variable) – The variable to sum over
expr (AbstractExpression) – The expression to sum
Methods Summary
copy
()Returns a copy of the expression (variables are not copied).
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)
to_latex
()Methods Documentation
- copy()¶
Returns a copy of the expression (variables are not copied).
- 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)
- 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)
- to_latex()¶