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, X, f, fx, x
from proveit.logic import Equals, Forall, Injections
from proveit.numbers import Sum
from proveit.statistics import Prob, ProbOfAll
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
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)))
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_{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]
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: 11
operand: 2
1ExprTuple2
2Lambdaparameter: 47
body: 4
3ExprTuple47
4Operationoperator: 11
operand: 6
5ExprTuple6
6Lambdaparameter: 42
body: 8
7ExprTuple42
8Conditionalvalue: 9
condition: 10
9Operationoperator: 11
operand: 14
10Operationoperator: 43
operands: 13
11Literal
12ExprTuple14
13ExprTuple42, 15
14Lambdaparameter: 45
body: 17
15Operationoperator: 18
operands: 19
16ExprTuple45
17Operationoperator: 20
operands: 21
18Literal
19ExprTuple47, 22
20Literal
21ExprTuple23, 24
22Variable
23Operationoperator: 25
operand: 29
24Operationoperator: 27
operand: 30
25Literal
26ExprTuple29
27Literal
28ExprTuple30
29Lambdaparameter: 48
body: 31
30Lambdaparameter: 48
body: 32
31Conditionalvalue: 39
condition: 34
32Conditionalvalue: 33
condition: 34
33Operationoperator: 35
operand: 39
34Operationoperator: 37
operands: 38
35Literal
36ExprTuple39
37Literal
38ExprTuple40, 41
39Operationoperator: 42
operand: 48
40Operationoperator: 43
operands: 44
41Operationoperator: 45
operand: 48
42Variable
43Literal
44ExprTuple48, 47
45Variable
46ExprTuple48
47Variable
48Variable