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 Omega, Q, Qx, R, Rx, Ry, X, f, fx, fy, x, y
from proveit.logic import Bijections, Equals, Forall, Implies, Not
from proveit.numbers import one, subtract
from proveit.statistics import ProbOfAll
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
expr = Forall(instance_param_or_params = [f], instance_expr = Forall(instance_param_or_params = [Q, R], instance_expr = Implies(Forall(instance_param_or_params = sub_expr1, instance_expr = Equals(Qx, Not(Rx)), domain = X), Equals(ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = X, condition = Qx), subtract(one, ProbOfAll(instance_param_or_params = [y], instance_element = fy, domain = X, condition = Ry))).with_wrapping_at(2)).with_wrapping_at(2)), domain = Bijections(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())
\forall_{f \in \left[X \xrightarrow[\text{onto}]{\text{1-to-1}} \Omega\right]}~\left[\forall_{Q, R}~\left(\begin{array}{c} \begin{array}{l} \left[\forall_{x \in X}~\left(Q\left(x\right) = (\lnot R\left(x\right))\right)\right] \Rightarrow  \\ \left(\begin{array}{c} \begin{array}{l} \left[\textrm{Prob}_{x \in X~|~Q\left(x\right)}~f\left(x\right)\right] =  \\ \left(1 - \left[\textrm{Prob}_{y \in X~|~R\left(y\right)}~f\left(y\right)\right]\right) \end{array} \end{array}\right) \end{array} \end{array}\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: 59
body: 4
3ExprTuple59
4Conditionalvalue: 5
condition: 6
5Operationoperator: 20
operand: 9
6Operationoperator: 64
operands: 8
7ExprTuple9
8ExprTuple59, 10
9Lambdaparameters: 11
body: 12
10Operationoperator: 13
operands: 14
11ExprTuple53, 66
12Operationoperator: 15
operands: 16
13Literal
14ExprTuple68, 17
15Literal
16ExprTuple18, 19
17Variable
18Operationoperator: 20
operand: 23
19Operationoperator: 34
operands: 22
20Literal
21ExprTuple23
22ExprTuple24, 25
23Lambdaparameter: 56
body: 26
24Operationoperator: 46
operand: 31
25Operationoperator: 28
operands: 29
26Conditionalvalue: 30
condition: 49
27ExprTuple31
28Literal
29ExprTuple32, 33
30Operationoperator: 34
operands: 35
31Lambdaparameter: 56
body: 36
32Literal
33Operationoperator: 37
operand: 42
34Literal
35ExprTuple50, 39
36Conditionalvalue: 40
condition: 41
37Literal
38ExprTuple42
39Operationoperator: 43
operand: 48
40Operationoperator: 59
operand: 56
41Operationoperator: 60
operands: 45
42Operationoperator: 46
operand: 51
43Literal
44ExprTuple48
45ExprTuple49, 50
46Literal
47ExprTuple51
48Operationoperator: 66
operand: 56
49Operationoperator: 64
operands: 52
50Operationoperator: 53
operand: 56
51Lambdaparameter: 69
body: 55
52ExprTuple56, 68
53Variable
54ExprTuple56
55Conditionalvalue: 57
condition: 58
56Variable
57Operationoperator: 59
operand: 69
58Operationoperator: 60
operands: 61
59Variable
60Literal
61ExprTuple62, 63
62Operationoperator: 64
operands: 65
63Operationoperator: 66
operand: 69
64Literal
65ExprTuple69, 68
66Variable
67ExprTuple69
68Variable
69Variable