logo

Expression of type Forall

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 Omega, x
from proveit.logic import And, Equals, Forall, InClass, InSet
from proveit.numbers import Sum, one
from proveit.statistics import Prob, SampleSpaces, prob_domain
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [x]
sub_expr2 = Prob(x)
expr = Forall(instance_param_or_params = [Omega], instance_expr = Equals(InClass(Omega, SampleSpaces), And(Forall(instance_param_or_params = sub_expr1, instance_expr = InSet(sub_expr2, prob_domain), domain = Omega), Equals(Sum(index_or_indices = sub_expr1, summand = sub_expr2, domain = Omega), one))).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())
\forall_{\Omega}~\left(\begin{array}{c} \begin{array}{l} \left(\Omega \underset{{\scriptscriptstyle c}}{\in} \textrm{SampleSpaces}\right) =  \\ \left(\left[\forall_{x \in \Omega}~\left(\textrm{Pr}\left(x\right) \in \left[0,1\right]\right)\right] \land \left(\left[\sum_{x \in \Omega}~\textrm{Pr}\left(x\right)\right] = 1\right)\right) \end{array} \end{array}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 15
operand: 2
1ExprTuple2
2Lambdaparameter: 40
body: 4
3ExprTuple40
4Operationoperator: 17
operands: 5
5ExprTuple6, 7
6Operationoperator: 8
operands: 9
7Operationoperator: 10
operands: 11
8Literal
9ExprTuple40, 12
10Literal
11ExprTuple13, 14
12Literal
13Operationoperator: 15
operand: 19
14Operationoperator: 17
operands: 18
15Literal
16ExprTuple19
17Literal
18ExprTuple20, 38
19Lambdaparameter: 39
body: 21
20Operationoperator: 22
operand: 25
21Conditionalvalue: 24
condition: 30
22Literal
23ExprTuple25
24Operationoperator: 35
operands: 26
25Lambdaparameter: 39
body: 27
26ExprTuple29, 28
27Conditionalvalue: 29
condition: 30
28Operationoperator: 31
operands: 32
29Operationoperator: 33
operand: 39
30Operationoperator: 35
operands: 36
31Literal
32ExprTuple37, 38
33Literal
34ExprTuple39
35Literal
36ExprTuple39, 40
37Literal
38Literal
39Variable
40Variable