logo

Expression of type Conditional

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 A, B, C, Conditional, Omega, Q, Qx, X, f, fx, x
from proveit.logic import Disjoint, Equals, Forall, InClass, Injections, SubsetEq, Union
from proveit.numbers import Add
from proveit.statistics import ProbOfAll, SampleSpaces
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
expr = Conditional(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(), InClass(Omega, 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())
\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} \textrm{ if } \Omega \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces}\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 12
operand: 6
2Operationoperator: 4
operands: 5
3ExprTuple6
4Literal
5ExprTuple45, 7
6Lambdaparameters: 8
body: 9
7Literal
8ExprTuple74, 75, 65, 44, 72
9Conditionalvalue: 10
condition: 11
10Operationoperator: 12
operand: 15
11Operationoperator: 63
operands: 14
12Literal
13ExprTuple15
14ExprTuple16, 17, 18
15Lambdaparameter: 62
body: 20
16Operationoperator: 21
operands: 22
17Operationoperator: 28
operands: 23
18Operationoperator: 24
operands: 32
19ExprTuple62
20Conditionalvalue: 25
condition: 26
21Literal
22ExprTuple65, 44
23ExprTuple65, 27
24Literal
25Operationoperator: 28
operands: 29
26Operationoperator: 70
operands: 30
27Operationoperator: 31
operands: 32
28Literal
29ExprTuple33, 34
30ExprTuple62, 35
31Literal
32ExprTuple74, 75
33Operationoperator: 48
operand: 41
34Operationoperator: 37
operands: 38
35Operationoperator: 39
operands: 40
36ExprTuple41
37Literal
38ExprTuple42, 43
39Literal
40ExprTuple44, 45
41Lambdaparameter: 76
body: 46
42Operationoperator: 48
operand: 51
43Operationoperator: 48
operand: 52
44Variable
45Variable
46Conditionalvalue: 58
condition: 50
47ExprTuple51
48Literal
49ExprTuple52
50Operationoperator: 63
operands: 53
51Lambdaparameter: 76
body: 54
52Lambdaparameter: 76
body: 55
53ExprTuple56, 68
54Conditionalvalue: 58
condition: 57
55Conditionalvalue: 58
condition: 59
56Operationoperator: 70
operands: 60
57Operationoperator: 63
operands: 61
58Operationoperator: 62
operand: 76
59Operationoperator: 63
operands: 64
60ExprTuple76, 65
61ExprTuple66, 68
62Variable
63Literal
64ExprTuple67, 68
65Variable
66Operationoperator: 70
operands: 69
67Operationoperator: 70
operands: 71
68Operationoperator: 72
operand: 76
69ExprTuple76, 74
70Literal
71ExprTuple76, 75
72Variable
73ExprTuple76
74Variable
75Variable
76Variable