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 Lambda, Q, Qx, R, Rx, Ry, X, fx, fy, x, y
from proveit.logic import Equals, Forall, Implies, 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([Q, R], 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))
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())
\left(Q, R\right) \mapsto \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)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple40, 53
2Operationoperator: 3
operands: 4
3Literal
4ExprTuple5, 6
5Operationoperator: 7
operand: 10
6Operationoperator: 21
operands: 9
7Literal
8ExprTuple10
9ExprTuple11, 12
10Lambdaparameter: 43
body: 13
11Operationoperator: 33
operand: 18
12Operationoperator: 15
operands: 16
13Conditionalvalue: 17
condition: 36
14ExprTuple18
15Literal
16ExprTuple19, 20
17Operationoperator: 21
operands: 22
18Lambdaparameter: 43
body: 23
19Literal
20Operationoperator: 24
operand: 29
21Literal
22ExprTuple37, 26
23Conditionalvalue: 27
condition: 28
24Literal
25ExprTuple29
26Operationoperator: 30
operand: 35
27Operationoperator: 46
operand: 43
28Operationoperator: 47
operands: 32
29Operationoperator: 33
operand: 38
30Literal
31ExprTuple35
32ExprTuple36, 37
33Literal
34ExprTuple38
35Operationoperator: 53
operand: 43
36Operationoperator: 51
operands: 39
37Operationoperator: 40
operand: 43
38Lambdaparameter: 56
body: 42
39ExprTuple43, 55
40Variable
41ExprTuple43
42Conditionalvalue: 44
condition: 45
43Variable
44Operationoperator: 46
operand: 56
45Operationoperator: 47
operands: 48
46Variable
47Literal
48ExprTuple49, 50
49Operationoperator: 51
operands: 52
50Operationoperator: 53
operand: 56
51Literal
52ExprTuple56, 55
53Variable
54ExprTuple56
55Variable
56Variable