# 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 A, B, C, Omega, Q, Qx, X, f, fx, x
from proveit.logic import Disjoint, Equals, Forall, Injections, SubsetEq, Union
from proveit.statistics import 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 = [A, B, C, X, Q], instance_expr = Forall(instance_param_or_params = [f], instance_expr = Equals(ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = C, condition = Qx), Add(ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = A, condition = Qx), ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = B, condition = Qx))), domain = Injections(X, Omega)), conditions = [SubsetEq(C, X), Equals(C, Union(A, B)), Disjoint(A, B)]).with_wrapping(), 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[\begin{array}{l}\forall_{A, B, C, X, Q~|~C \subseteq X, C = \left(A \cup B\right), \textrm{disjoint}\left(A, B\right)}~\\
\left[\forall_{f \in \left[X \xrightarrow[]{\text{1-to-1}} \Omega\right]}~\left(\left[\textrm{Prob}_{x \in C~|~Q\left(x\right)}~f\left(x\right)\right] = \left(\left[\textrm{Prob}_{x \in A~|~Q\left(x\right)}~f\left(x\right)\right] + \left[\textrm{Prob}_{x \in B~|~Q\left(x\right)}~f\left(x\right)\right]\right)\right)\right]\end{array}\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: 16
operand: 2
1ExprTuple2
2Lambdaparameter: 49
body: 4
3ExprTuple49
4Conditionalvalue: 5
condition: 6
5Operationoperator: 16
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple49, 11
10Lambdaparameters: 12
body: 13
11Literal
12ExprTuple78, 79, 69, 48, 76
13Conditionalvalue: 14
condition: 15
14Operationoperator: 16
operand: 19
15Operationoperator: 67
operands: 18
16Literal
17ExprTuple19
18ExprTuple20, 21, 22
19Lambdaparameter: 66
body: 24
20Operationoperator: 25
operands: 26
21Operationoperator: 32
operands: 27
22Operationoperator: 28
operands: 36
23ExprTuple66
24Conditionalvalue: 29
condition: 30
25Literal
26ExprTuple69, 48
27ExprTuple69, 31
28Literal
29Operationoperator: 32
operands: 33
30Operationoperator: 74
operands: 34
31Operationoperator: 35
operands: 36
32Literal
33ExprTuple37, 38
34ExprTuple66, 39
35Literal
36ExprTuple78, 79
37Operationoperator: 52
operand: 45
38Operationoperator: 41
operands: 42
39Operationoperator: 43
operands: 44
40ExprTuple45
41Literal
42ExprTuple46, 47
43Literal
44ExprTuple48, 49
45Lambdaparameter: 80
body: 50
46Operationoperator: 52
operand: 55
47Operationoperator: 52
operand: 56
48Variable
49Variable
50Conditionalvalue: 62
condition: 54
51ExprTuple55
52Literal
53ExprTuple56
54Operationoperator: 67
operands: 57
55Lambdaparameter: 80
body: 58
56Lambdaparameter: 80
body: 59
57ExprTuple60, 72
58Conditionalvalue: 62
condition: 61
59Conditionalvalue: 62
condition: 63
60Operationoperator: 74
operands: 64
61Operationoperator: 67
operands: 65
62Operationoperator: 66
operand: 80
63Operationoperator: 67
operands: 68
64ExprTuple80, 69
65ExprTuple70, 72
66Variable
67Literal
68ExprTuple71, 72
69Variable
70Operationoperator: 74
operands: 73
71Operationoperator: 74
operands: 75
72Operationoperator: 76
operand: 80
73ExprTuple80, 78
74Literal
75ExprTuple80, 79
76Variable
77ExprTuple80
78Variable
79Variable
80Variable