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, InSet, 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 = Lambda(f, Conditional(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)), InSet(f, Bijections(X, Omega))))
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())
f \mapsto \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) \textrm{ if } f \in \left[X \xrightarrow[\text{onto}]{\text{1-to-1}} \Omega\right]\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 57
body: 2
1ExprTuple57
2Conditionalvalue: 3
condition: 4
3Operationoperator: 18
operand: 7
4Operationoperator: 62
operands: 6
5ExprTuple7
6ExprTuple57, 8
7Lambdaparameters: 9
body: 10
8Operationoperator: 11
operands: 12
9ExprTuple51, 64
10Operationoperator: 13
operands: 14
11Literal
12ExprTuple66, 15
13Literal
14ExprTuple16, 17
15Variable
16Operationoperator: 18
operand: 21
17Operationoperator: 32
operands: 20
18Literal
19ExprTuple21
20ExprTuple22, 23
21Lambdaparameter: 54
body: 24
22Operationoperator: 44
operand: 29
23Operationoperator: 26
operands: 27
24Conditionalvalue: 28
condition: 47
25ExprTuple29
26Literal
27ExprTuple30, 31
28Operationoperator: 32
operands: 33
29Lambdaparameter: 54
body: 34
30Literal
31Operationoperator: 35
operand: 40
32Literal
33ExprTuple48, 37
34Conditionalvalue: 38
condition: 39
35Literal
36ExprTuple40
37Operationoperator: 41
operand: 46
38Operationoperator: 57
operand: 54
39Operationoperator: 58
operands: 43
40Operationoperator: 44
operand: 49
41Literal
42ExprTuple46
43ExprTuple47, 48
44Literal
45ExprTuple49
46Operationoperator: 64
operand: 54
47Operationoperator: 62
operands: 50
48Operationoperator: 51
operand: 54
49Lambdaparameter: 67
body: 53
50ExprTuple54, 66
51Variable
52ExprTuple54
53Conditionalvalue: 55
condition: 56
54Variable
55Operationoperator: 57
operand: 67
56Operationoperator: 58
operands: 59
57Variable
58Literal
59ExprTuple60, 61
60Operationoperator: 62
operands: 63
61Operationoperator: 64
operand: 67
62Literal
63ExprTuple67, 66
64Variable
65ExprTuple67
66Variable
67Variable