logo

Expression of type Forall

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, Omega, Q, Qx, X, f, fx, x
from proveit.logic import Disjoint, Equals, Forall, Injections, SubsetEq, Union
from proveit.numbers import Add
from proveit.statistics import ProbOfAll
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
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()
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())
\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}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('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: 7
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple69, 70, 60, 39, 67
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 10
6Operationoperator: 58
operands: 9
7Literal
8ExprTuple10
9ExprTuple11, 12, 13
10Lambdaparameter: 57
body: 15
11Operationoperator: 16
operands: 17
12Operationoperator: 23
operands: 18
13Operationoperator: 19
operands: 27
14ExprTuple57
15Conditionalvalue: 20
condition: 21
16Literal
17ExprTuple60, 39
18ExprTuple60, 22
19Literal
20Operationoperator: 23
operands: 24
21Operationoperator: 65
operands: 25
22Operationoperator: 26
operands: 27
23Literal
24ExprTuple28, 29
25ExprTuple57, 30
26Literal
27ExprTuple69, 70
28Operationoperator: 43
operand: 36
29Operationoperator: 32
operands: 33
30Operationoperator: 34
operands: 35
31ExprTuple36
32Literal
33ExprTuple37, 38
34Literal
35ExprTuple39, 40
36Lambdaparameter: 71
body: 41
37Operationoperator: 43
operand: 46
38Operationoperator: 43
operand: 47
39Variable
40Variable
41Conditionalvalue: 53
condition: 45
42ExprTuple46
43Literal
44ExprTuple47
45Operationoperator: 58
operands: 48
46Lambdaparameter: 71
body: 49
47Lambdaparameter: 71
body: 50
48ExprTuple51, 63
49Conditionalvalue: 53
condition: 52
50Conditionalvalue: 53
condition: 54
51Operationoperator: 65
operands: 55
52Operationoperator: 58
operands: 56
53Operationoperator: 57
operand: 71
54Operationoperator: 58
operands: 59
55ExprTuple71, 60
56ExprTuple61, 63
57Variable
58Literal
59ExprTuple62, 63
60Variable
61Operationoperator: 65
operands: 64
62Operationoperator: 65
operands: 66
63Operationoperator: 67
operand: 71
64ExprTuple71, 69
65Literal
66ExprTuple71, 70
67Variable
68ExprTuple71
69Variable
70Variable
71Variable