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
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 = 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()
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_{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}
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: 20
operand: 2
1ExprTuple2
2Lambdaparameter: 39
body: 4
3ExprTuple39
4Conditionalvalue: 5
condition: 6
5Operationoperator: 20
operand: 9
6Operationoperator: 46
operands: 8
7ExprTuple9
8ExprTuple39, 10
9Lambdaparameters: 11
body: 12
10Operationoperator: 13
operands: 14
11ExprTuple45, 48
12Operationoperator: 15
operands: 16
13Literal
14ExprTuple50, 17
15Literal
16ExprTuple18, 19
17Variable
18Operationoperator: 20
operand: 24
19Operationoperator: 22
operands: 23
20Literal
21ExprTuple24
22Literal
23ExprTuple25, 26
24Lambdaparameter: 51
body: 27
25Operationoperator: 29
operand: 31
26Operationoperator: 29
operand: 32
27Conditionalvalue: 44
condition: 35
28ExprTuple31
29Literal
30ExprTuple32
31Lambdaparameter: 51
body: 33
32Lambdaparameter: 51
body: 34
33Conditionalvalue: 36
condition: 35
34Conditionalvalue: 36
condition: 37
35Operationoperator: 40
operands: 38
36Operationoperator: 39
operand: 51
37Operationoperator: 40
operands: 41
38ExprTuple43, 42
39Variable
40Literal
41ExprTuple43, 44
42Operationoperator: 45
operand: 51
43Operationoperator: 46
operands: 47
44Operationoperator: 48
operand: 51
45Variable
46Literal
47ExprTuple51, 50
48Variable
49ExprTuple51
50Variable
51Variable