logo

Expression of type Conditional

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, Omega, Q, Qx, X, f, fx, x
from proveit.logic import Equals, Forall, InClass, Injections
from proveit.numbers import Sum
from proveit.statistics import Prob, ProbOfAll, SampleSpaces
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
expr = Conditional(Forall(instance_param_or_params = [X], instance_expr = Forall(instance_param_or_params = [f], instance_expr = Forall(instance_param_or_params = [Q], instance_expr = Equals(ProbOfAll(instance_param_or_params = sub_expr1, instance_element = fx, domain = X, condition = Qx), Sum(index_or_indices = sub_expr1, summand = Prob(fx), domain = X, condition = Qx)).with_wrapping_at(2)), domain = Injections(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())
\left\{\forall_{X}~\left[\forall_{f \in \left[X \xrightarrow[]{\text{1-to-1}} \Omega\right]}~\left[\forall_{Q}~\left(\begin{array}{c} \begin{array}{l} \left[\textrm{Prob}_{x \in X~|~Q\left(x\right)}~f\left(x\right)\right] =  \\ \left[\sum_{x \in X~|~Q\left(x\right)}~\textrm{Pr}\left(f\left(x\right)\right)\right] \end{array} \end{array}\right)\right]\right] \textrm{ if } \Omega \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces}\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 16
operand: 6
2Operationoperator: 4
operands: 5
3ExprTuple6
4Literal
5ExprTuple27, 7
6Lambdaparameter: 52
body: 9
7Literal
8ExprTuple52
9Operationoperator: 16
operand: 11
10ExprTuple11
11Lambdaparameter: 47
body: 13
12ExprTuple47
13Conditionalvalue: 14
condition: 15
14Operationoperator: 16
operand: 19
15Operationoperator: 48
operands: 18
16Literal
17ExprTuple19
18ExprTuple47, 20
19Lambdaparameter: 50
body: 22
20Operationoperator: 23
operands: 24
21ExprTuple50
22Operationoperator: 25
operands: 26
23Literal
24ExprTuple52, 27
25Literal
26ExprTuple28, 29
27Variable
28Operationoperator: 30
operand: 34
29Operationoperator: 32
operand: 35
30Literal
31ExprTuple34
32Literal
33ExprTuple35
34Lambdaparameter: 53
body: 36
35Lambdaparameter: 53
body: 37
36Conditionalvalue: 44
condition: 39
37Conditionalvalue: 38
condition: 39
38Operationoperator: 40
operand: 44
39Operationoperator: 42
operands: 43
40Literal
41ExprTuple44
42Literal
43ExprTuple45, 46
44Operationoperator: 47
operand: 53
45Operationoperator: 48
operands: 49
46Operationoperator: 50
operand: 53
47Variable
48Literal
49ExprTuple53, 52
50Variable
51ExprTuple53
52Variable
53Variable