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 = [A, B, Q], instance_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())
\forall_{A, B, Q}~\left[\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}\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: 5
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple53, 55, 51
4Operationoperator: 5
operand: 7
5Literal
6ExprTuple7
7Lambdaparameters: 8
body: 9
8ExprTuple40, 57
9Conditionalvalue: 10
condition: 11
10Operationoperator: 12
operands: 13
11Operationoperator: 41
operands: 14
12Literal
13ExprTuple15, 16
14ExprTuple17, 18
15Operationoperator: 20
operand: 24
16Operationoperator: 20
operand: 25
17Operationoperator: 49
operands: 22
18Operationoperator: 49
operands: 23
19ExprTuple24
20Literal
21ExprTuple25
22ExprTuple40, 26
23ExprTuple57, 27
24Lambdaparameter: 54
body: 28
25Lambdaparameter: 59
body: 29
26Operationoperator: 30
operands: 31
27Operationoperator: 32
operands: 33
28Conditionalvalue: 34
condition: 35
29Conditionalvalue: 36
condition: 37
30Literal
31ExprTuple53, 38
32Literal
33ExprTuple55, 53
34Operationoperator: 40
operand: 54
35Operationoperator: 41
operands: 39
36Operationoperator: 40
operand: 56
37Operationoperator: 41
operands: 42
38Variable
39ExprTuple43, 44
40Variable
41Literal
42ExprTuple45, 46
43Operationoperator: 49
operands: 47
44Operationoperator: 51
operand: 54
45Operationoperator: 49
operands: 50
46Operationoperator: 51
operand: 56
47ExprTuple54, 53
48ExprTuple54
49Literal
50ExprTuple59, 55
51Variable
52ExprTuple56
53Variable
54Variable
55Variable
56Operationoperator: 57
operand: 59
57Variable
58ExprTuple59
59Variable