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, X, f, fx, x
from proveit.logic import Forall, Functions, Implies
from proveit.numbers import LessEq
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 = [X], instance_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 = Rx, domain = X, condition = Qx), LessEq(ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = X, condition = Qx), ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = X, condition = Rx)).with_wrapping_at(2)).with_wrapping_at(2)), domain = Functions(X, Omega)).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[\forall_{X}~\left[\begin{array}{l}\forall_{f \in \left[X \rightarrow \Omega\right]}~\\
\left[\forall_{Q, R}~\left(\begin{array}{c} \begin{array}{l} \left[\forall_{x \in X~|~Q\left(x\right)}~R\left(x\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] \leq  \\ \left[\textrm{Prob}_{x \in X~|~R\left(x\right)}~f\left(x\right)\right] \end{array} \end{array}\right) \end{array} \end{array}\right)\right]\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: 33
operand: 2
1ExprTuple2
2Lambdaparameter: 30
body: 4
3ExprTuple30
4Conditionalvalue: 5
condition: 6
5Operationoperator: 33
operand: 10
6Operationoperator: 8
operands: 9
7ExprTuple10
8Literal
9ExprTuple30, 11
10Lambdaparameter: 63
body: 13
11Literal
12ExprTuple63
13Operationoperator: 33
operand: 15
14ExprTuple15
15Lambdaparameter: 52
body: 17
16ExprTuple52
17Conditionalvalue: 18
condition: 19
18Operationoperator: 33
operand: 22
19Operationoperator: 59
operands: 21
20ExprTuple22
21ExprTuple52, 23
22Lambdaparameters: 24
body: 25
23Operationoperator: 26
operands: 27
24ExprTuple58, 61
25Operationoperator: 28
operands: 29
26Literal
27ExprTuple63, 30
28Literal
29ExprTuple31, 32
30Variable
31Operationoperator: 33
operand: 37
32Operationoperator: 35
operands: 36
33Literal
34ExprTuple37
35Literal
36ExprTuple38, 39
37Lambdaparameter: 64
body: 40
38Operationoperator: 42
operand: 44
39Operationoperator: 42
operand: 45
40Conditionalvalue: 57
condition: 48
41ExprTuple44
42Literal
43ExprTuple45
44Lambdaparameter: 64
body: 46
45Lambdaparameter: 64
body: 47
46Conditionalvalue: 49
condition: 48
47Conditionalvalue: 49
condition: 50
48Operationoperator: 53
operands: 51
49Operationoperator: 52
operand: 64
50Operationoperator: 53
operands: 54
51ExprTuple56, 55
52Variable
53Literal
54ExprTuple56, 57
55Operationoperator: 58
operand: 64
56Operationoperator: 59
operands: 60
57Operationoperator: 61
operand: 64
58Variable
59Literal
60ExprTuple64, 63
61Variable
62ExprTuple64
63Variable
64Variable