logo

Expression of type Lambda

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, C, Conditional, Lambda, Omega, Q, Qx, X, f, fx, x
from proveit.logic import Disjoint, Equals, Forall, InClass, Injections, SubsetEq, Union
from proveit.numbers import Add
from proveit.statistics import ProbOfAll, SampleSpaces
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
expr = Lambda(Omega, Conditional(Forall(instance_param_or_params = [A, B, C, X, Q], instance_expr = Forall(instance_param_or_params = [f], instance_expr = Equals(ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = C, condition = Qx), Add(ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = A, condition = Qx), ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = B, condition = Qx))), domain = Injections(X, Omega)), conditions = [SubsetEq(C, X), Equals(C, Union(A, B)), Disjoint(A, B)]).with_wrapping(), InClass(Omega, SampleSpaces)))
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())
\Omega \mapsto \left\{\begin{array}{l}\forall_{A, B, C, X, Q~|~C \subseteq X, C = \left(A \cup B\right), \textrm{disjoint}\left(A, B\right)}~\\
\left[\forall_{f \in \left[X \xrightarrow[]{\text{1-to-1}} \Omega\right]}~\left(\left[\textrm{Prob}_{x \in C~|~Q\left(x\right)}~f\left(x\right)\right] = \left(\left[\textrm{Prob}_{x \in A~|~Q\left(x\right)}~f\left(x\right)\right] + \left[\textrm{Prob}_{x \in B~|~Q\left(x\right)}~f\left(x\right)\right]\right)\right)\right]\end{array} \textrm{ if } \Omega \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces}\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 47
body: 2
1ExprTuple47
2Conditionalvalue: 3
condition: 4
3Operationoperator: 14
operand: 8
4Operationoperator: 6
operands: 7
5ExprTuple8
6Literal
7ExprTuple47, 9
8Lambdaparameters: 10
body: 11
9Literal
10ExprTuple76, 77, 67, 46, 74
11Conditionalvalue: 12
condition: 13
12Operationoperator: 14
operand: 17
13Operationoperator: 65
operands: 16
14Literal
15ExprTuple17
16ExprTuple18, 19, 20
17Lambdaparameter: 64
body: 22
18Operationoperator: 23
operands: 24
19Operationoperator: 30
operands: 25
20Operationoperator: 26
operands: 34
21ExprTuple64
22Conditionalvalue: 27
condition: 28
23Literal
24ExprTuple67, 46
25ExprTuple67, 29
26Literal
27Operationoperator: 30
operands: 31
28Operationoperator: 72
operands: 32
29Operationoperator: 33
operands: 34
30Literal
31ExprTuple35, 36
32ExprTuple64, 37
33Literal
34ExprTuple76, 77
35Operationoperator: 50
operand: 43
36Operationoperator: 39
operands: 40
37Operationoperator: 41
operands: 42
38ExprTuple43
39Literal
40ExprTuple44, 45
41Literal
42ExprTuple46, 47
43Lambdaparameter: 78
body: 48
44Operationoperator: 50
operand: 53
45Operationoperator: 50
operand: 54
46Variable
47Variable
48Conditionalvalue: 60
condition: 52
49ExprTuple53
50Literal
51ExprTuple54
52Operationoperator: 65
operands: 55
53Lambdaparameter: 78
body: 56
54Lambdaparameter: 78
body: 57
55ExprTuple58, 70
56Conditionalvalue: 60
condition: 59
57Conditionalvalue: 60
condition: 61
58Operationoperator: 72
operands: 62
59Operationoperator: 65
operands: 63
60Operationoperator: 64
operand: 78
61Operationoperator: 65
operands: 66
62ExprTuple78, 67
63ExprTuple68, 70
64Variable
65Literal
66ExprTuple69, 70
67Variable
68Operationoperator: 72
operands: 71
69Operationoperator: 72
operands: 73
70Operationoperator: 74
operand: 78
71ExprTuple78, 76
72Literal
73ExprTuple78, 77
74Variable
75ExprTuple78
76Variable
77Variable
78Variable