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 Q, Qx, R, Rx, Ry, X, fx, fy, x, y
from proveit.logic import 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 = [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))
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_{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)
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: 9
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple42, 55
4Operationoperator: 5
operands: 6
5Literal
6ExprTuple7, 8
7Operationoperator: 9
operand: 12
8Operationoperator: 23
operands: 11
9Literal
10ExprTuple12
11ExprTuple13, 14
12Lambdaparameter: 45
body: 15
13Operationoperator: 35
operand: 20
14Operationoperator: 17
operands: 18
15Conditionalvalue: 19
condition: 38
16ExprTuple20
17Literal
18ExprTuple21, 22
19Operationoperator: 23
operands: 24
20Lambdaparameter: 45
body: 25
21Literal
22Operationoperator: 26
operand: 31
23Literal
24ExprTuple39, 28
25Conditionalvalue: 29
condition: 30
26Literal
27ExprTuple31
28Operationoperator: 32
operand: 37
29Operationoperator: 48
operand: 45
30Operationoperator: 49
operands: 34
31Operationoperator: 35
operand: 40
32Literal
33ExprTuple37
34ExprTuple38, 39
35Literal
36ExprTuple40
37Operationoperator: 55
operand: 45
38Operationoperator: 53
operands: 41
39Operationoperator: 42
operand: 45
40Lambdaparameter: 58
body: 44
41ExprTuple45, 57
42Variable
43ExprTuple45
44Conditionalvalue: 46
condition: 47
45Variable
46Operationoperator: 48
operand: 58
47Operationoperator: 49
operands: 50
48Variable
49Literal
50ExprTuple51, 52
51Operationoperator: 53
operands: 54
52Operationoperator: 55
operand: 58
53Literal
54ExprTuple58, 57
55Variable
56ExprTuple58
57Variable
58Variable