# 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.
# import Expression classes needed to build the expression
from proveit import 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, SampleSpaces

In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
expr = Forall(instance_param_or_params = [Omega], instance_expr = Forall(instance_param_or_params = [X], instance_expr = 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))), domain = SampleSpaces)

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())

\forall_{\Omega \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces}}~\left[\forall_{X}~\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]\right]

In [5]:
stored_expr.style_options()

namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()

core typesub-expressionsexpression
0Operationoperator: 20
operand: 2
1ExprTuple2
2Lambdaparameter: 31
body: 4
3ExprTuple31
4Conditionalvalue: 5
condition: 6
5Operationoperator: 20
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple31, 11
10Lambdaparameter: 56
body: 13
11Literal
12ExprTuple56
13Operationoperator: 20
operand: 15
14ExprTuple15
15Lambdaparameter: 51
body: 17
16ExprTuple51
17Conditionalvalue: 18
condition: 19
18Operationoperator: 20
operand: 23
19Operationoperator: 52
operands: 22
20Literal
21ExprTuple23
22ExprTuple51, 24
23Lambdaparameter: 54
body: 26
24Operationoperator: 27
operands: 28
25ExprTuple54
26Operationoperator: 29
operands: 30
27Literal
28ExprTuple56, 31
29Literal
30ExprTuple32, 33
31Variable
32Operationoperator: 34
operand: 38
33Operationoperator: 36
operand: 39
34Literal
35ExprTuple38
36Literal
37ExprTuple39
38Lambdaparameter: 57
body: 40
39Lambdaparameter: 57
body: 41
40Conditionalvalue: 48
condition: 43
41Conditionalvalue: 42
condition: 43
42Operationoperator: 44
operand: 48
43Operationoperator: 46
operands: 47
44Literal
45ExprTuple48
46Literal
47ExprTuple49, 50
48Operationoperator: 51
operand: 57
49Operationoperator: 52
operands: 53
50Operationoperator: 54
operand: 57
51Variable
52Literal
53ExprTuple57, 56
54Variable
55ExprTuple57
56Variable
57Variable