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 A, B, Function, Omega, Q, Qx, f, fx, g, gy, x, y
from proveit.logic import Bijections, Equals, Forall, Injections
from proveit.statistics import ProbOfAll
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [gy]
expr = Forall(instance_param_or_params = [f, g], instance_expr = Equals(ProbOfAll(instance_param_or_params = [x], instance_element = fx, domain = A, condition = Qx), ProbOfAll(instance_param_or_params = [y], instance_element = Function(f, sub_expr1), domain = B, condition = Function(Q, sub_expr1))), domains = [Injections(A, Omega), Bijections(B, A)]).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[A \xrightarrow[]{\text{1-to-1}} \Omega\right], g \in \left[B \xrightarrow[\text{onto}]{\text{1-to-1}} A\right]}~\\
\left(\left[\textrm{Prob}_{x \in A~|~Q\left(x\right)}~f\left(x\right)\right] = \left[\textrm{Prob}_{y \in B~|~Q\left(g\left(y\right)\right)}~f\left(g\left(y\right)\right)\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: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameters: 4
body: 5
4ExprTuple36, 53
5Conditionalvalue: 6
condition: 7
6Operationoperator: 8
operands: 9
7Operationoperator: 37
operands: 10
8Literal
9ExprTuple11, 12
10ExprTuple13, 14
11Operationoperator: 16
operand: 20
12Operationoperator: 16
operand: 21
13Operationoperator: 45
operands: 18
14Operationoperator: 45
operands: 19
15ExprTuple20
16Literal
17ExprTuple21
18ExprTuple36, 22
19ExprTuple53, 23
20Lambdaparameter: 50
body: 24
21Lambdaparameter: 55
body: 25
22Operationoperator: 26
operands: 27
23Operationoperator: 28
operands: 29
24Conditionalvalue: 30
condition: 31
25Conditionalvalue: 32
condition: 33
26Literal
27ExprTuple49, 34
28Literal
29ExprTuple51, 49
30Operationoperator: 36
operand: 50
31Operationoperator: 37
operands: 35
32Operationoperator: 36
operand: 52
33Operationoperator: 37
operands: 38
34Variable
35ExprTuple39, 40
36Variable
37Literal
38ExprTuple41, 42
39Operationoperator: 45
operands: 43
40Operationoperator: 47
operand: 50
41Operationoperator: 45
operands: 46
42Operationoperator: 47
operand: 52
43ExprTuple50, 49
44ExprTuple50
45Literal
46ExprTuple55, 51
47Variable
48ExprTuple52
49Variable
50Variable
51Variable
52Operationoperator: 53
operand: 55
53Variable
54ExprTuple55
55Variable