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 = [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 = 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_{X}~\left[\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]\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: 72
body: 4
3ExprTuple72
4Operationoperator: 24
operand: 6
5ExprTuple6
6Lambdaparameter: 63
body: 8
7ExprTuple63
8Conditionalvalue: 9
condition: 10
9Operationoperator: 24
operand: 13
10Operationoperator: 68
operands: 12
11ExprTuple13
12ExprTuple63, 14
13Lambdaparameters: 15
body: 16
14Operationoperator: 17
operands: 18
15ExprTuple57, 70
16Operationoperator: 19
operands: 20
17Literal
18ExprTuple72, 21
19Literal
20ExprTuple22, 23
21Variable
22Operationoperator: 24
operand: 27
23Operationoperator: 38
operands: 26
24Literal
25ExprTuple27
26ExprTuple28, 29
27Lambdaparameter: 60
body: 30
28Operationoperator: 50
operand: 35
29Operationoperator: 32
operands: 33
30Conditionalvalue: 34
condition: 53
31ExprTuple35
32Literal
33ExprTuple36, 37
34Operationoperator: 38
operands: 39
35Lambdaparameter: 60
body: 40
36Literal
37Operationoperator: 41
operand: 46
38Literal
39ExprTuple54, 43
40Conditionalvalue: 44
condition: 45
41Literal
42ExprTuple46
43Operationoperator: 47
operand: 52
44Operationoperator: 63
operand: 60
45Operationoperator: 64
operands: 49
46Operationoperator: 50
operand: 55
47Literal
48ExprTuple52
49ExprTuple53, 54
50Literal
51ExprTuple55
52Operationoperator: 70
operand: 60
53Operationoperator: 68
operands: 56
54Operationoperator: 57
operand: 60
55Lambdaparameter: 73
body: 59
56ExprTuple60, 72
57Variable
58ExprTuple60
59Conditionalvalue: 61
condition: 62
60Variable
61Operationoperator: 63
operand: 73
62Operationoperator: 64
operands: 65
63Variable
64Literal
65ExprTuple66, 67
66Operationoperator: 68
operands: 69
67Operationoperator: 70
operand: 73
68Literal
69ExprTuple73, 72
70Variable
71ExprTuple73
72Variable
73Variable