logo

Expression of type Lambda

from the theory of proveit.statistics

In [1]:
import proveit
# Automation is not needed when building an expression:
proveit.defaults.automation = False # This will speed things up.
proveit.defaults.inline_pngs = False # Makes files smaller.
%load_expr # Load the stored expression as 'stored_expr'
# import Expression classes needed to build the expression
from proveit import Lambda, Omega, Q, Qx, X, f, fx, x
from proveit.logic import Equals, Forall, Injections
from proveit.numbers import Sum
from proveit.statistics import Prob, ProbOfAll
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
expr = Lambda(X, Forall(instance_param_or_params = [f], instance_expr = Forall(instance_param_or_params = [Q], instance_expr = Equals(ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = X, condition = Qx), Sum(index_or_indices = sub_expr1, summand = Prob(fx), domain = X, condition = Qx)).with_wrapping_at(2)), domain = Injections(X, Omega)))
expr:
In [3]:
# check that the built expression is the same as the stored expression
assert expr == stored_expr
assert expr._style_id == stored_expr._style_id
print("Passed sanity check: expr matches stored_expr")
Passed sanity check: expr matches stored_expr
In [4]:
# Show the LaTeX representation of the expression for convenience if you need it.
print(stored_expr.latex())
X \mapsto \left[\forall_{f \in \left[X \xrightarrow[]{\text{1-to-1}} \Omega\right]}~\left[\forall_{Q}~\left(\begin{array}{c} \begin{array}{l} \left[\textrm{Prob}_{x \in X~|~Q\left(x\right)}~f\left(x\right)\right] =  \\ \left[\sum_{x \in X~|~Q\left(x\right)}~\textrm{Pr}\left(f\left(x\right)\right)\right] \end{array} \end{array}\right)\right]\right]
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 45
body: 2
1ExprTuple45
2Operationoperator: 9
operand: 4
3ExprTuple4
4Lambdaparameter: 40
body: 6
5ExprTuple40
6Conditionalvalue: 7
condition: 8
7Operationoperator: 9
operand: 12
8Operationoperator: 41
operands: 11
9Literal
10ExprTuple12
11ExprTuple40, 13
12Lambdaparameter: 43
body: 15
13Operationoperator: 16
operands: 17
14ExprTuple43
15Operationoperator: 18
operands: 19
16Literal
17ExprTuple45, 20
18Literal
19ExprTuple21, 22
20Variable
21Operationoperator: 23
operand: 27
22Operationoperator: 25
operand: 28
23Literal
24ExprTuple27
25Literal
26ExprTuple28
27Lambdaparameter: 46
body: 29
28Lambdaparameter: 46
body: 30
29Conditionalvalue: 37
condition: 32
30Conditionalvalue: 31
condition: 32
31Operationoperator: 33
operand: 37
32Operationoperator: 35
operands: 36
33Literal
34ExprTuple37
35Literal
36ExprTuple38, 39
37Operationoperator: 40
operand: 46
38Operationoperator: 41
operands: 42
39Operationoperator: 43
operand: 46
40Variable
41Literal
42ExprTuple46, 45
43Variable
44ExprTuple46
45Variable
46Variable