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 Conditional, Lambda, Omega, Q, Qx, R, Rx, Ry, X, f, fx, fy, x, y
from proveit.logic import Bijections, Equals, Forall, Implies, InClass, Not
from proveit.numbers import one, subtract
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 = [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))), 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\{\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] \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: 28
body: 2
1ExprTuple28
2Conditionalvalue: 3
condition: 4
3Operationoperator: 31
operand: 8
4Operationoperator: 6
operands: 7
5ExprTuple8
6Literal
7ExprTuple28, 9
8Lambdaparameter: 79
body: 11
9Literal
10ExprTuple79
11Operationoperator: 31
operand: 13
12ExprTuple13
13Lambdaparameter: 70
body: 15
14ExprTuple70
15Conditionalvalue: 16
condition: 17
16Operationoperator: 31
operand: 20
17Operationoperator: 75
operands: 19
18ExprTuple20
19ExprTuple70, 21
20Lambdaparameters: 22
body: 23
21Operationoperator: 24
operands: 25
22ExprTuple64, 77
23Operationoperator: 26
operands: 27
24Literal
25ExprTuple79, 28
26Literal
27ExprTuple29, 30
28Variable
29Operationoperator: 31
operand: 34
30Operationoperator: 45
operands: 33
31Literal
32ExprTuple34
33ExprTuple35, 36
34Lambdaparameter: 67
body: 37
35Operationoperator: 57
operand: 42
36Operationoperator: 39
operands: 40
37Conditionalvalue: 41
condition: 60
38ExprTuple42
39Literal
40ExprTuple43, 44
41Operationoperator: 45
operands: 46
42Lambdaparameter: 67
body: 47
43Literal
44Operationoperator: 48
operand: 53
45Literal
46ExprTuple61, 50
47Conditionalvalue: 51
condition: 52
48Literal
49ExprTuple53
50Operationoperator: 54
operand: 59
51Operationoperator: 70
operand: 67
52Operationoperator: 71
operands: 56
53Operationoperator: 57
operand: 62
54Literal
55ExprTuple59
56ExprTuple60, 61
57Literal
58ExprTuple62
59Operationoperator: 77
operand: 67
60Operationoperator: 75
operands: 63
61Operationoperator: 64
operand: 67
62Lambdaparameter: 80
body: 66
63ExprTuple67, 79
64Variable
65ExprTuple67
66Conditionalvalue: 68
condition: 69
67Variable
68Operationoperator: 70
operand: 80
69Operationoperator: 71
operands: 72
70Variable
71Literal
72ExprTuple73, 74
73Operationoperator: 75
operands: 76
74Operationoperator: 77
operand: 80
75Literal
76ExprTuple80, 79
77Variable
78ExprTuple80
79Variable
80Variable