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 = [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())
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[\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]
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: 24
operand: 2
1ExprTuple2
2Lambdaparameter: 54
body: 4
3ExprTuple54
4Operationoperator: 24
operand: 6
5ExprTuple6
6Lambdaparameter: 43
body: 8
7ExprTuple43
8Conditionalvalue: 9
condition: 10
9Operationoperator: 24
operand: 13
10Operationoperator: 50
operands: 12
11ExprTuple13
12ExprTuple43, 14
13Lambdaparameters: 15
body: 16
14Operationoperator: 17
operands: 18
15ExprTuple49, 52
16Operationoperator: 19
operands: 20
17Literal
18ExprTuple54, 21
19Literal
20ExprTuple22, 23
21Variable
22Operationoperator: 24
operand: 28
23Operationoperator: 26
operands: 27
24Literal
25ExprTuple28
26Literal
27ExprTuple29, 30
28Lambdaparameter: 55
body: 31
29Operationoperator: 33
operand: 35
30Operationoperator: 33
operand: 36
31Conditionalvalue: 48
condition: 39
32ExprTuple35
33Literal
34ExprTuple36
35Lambdaparameter: 55
body: 37
36Lambdaparameter: 55
body: 38
37Conditionalvalue: 40
condition: 39
38Conditionalvalue: 40
condition: 41
39Operationoperator: 44
operands: 42
40Operationoperator: 43
operand: 55
41Operationoperator: 44
operands: 45
42ExprTuple47, 46
43Variable
44Literal
45ExprTuple47, 48
46Operationoperator: 49
operand: 55
47Operationoperator: 50
operands: 51
48Operationoperator: 52
operand: 55
49Variable
50Literal
51ExprTuple55, 54
52Variable
53ExprTuple55
54Variable
55Variable