logo

Expression of type Forall

from the theory of proveit.linear_algebra.inner_products

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 A, B, ExprRange, IndexedVar, Variable, i, lambda_, m, n, v
from proveit.core_expr_types import a_1_to_m, a_i, b_1_to_n, b_i, lambda_i
from proveit.linear_algebra import Dim, HilbertSpaces, OrthoNormBases, ScalarMult, TensorProd, VecSum
from proveit.logic import Equals, Exists, Forall, InSet, Set
from proveit.numbers import Interval, Min, RealNonNeg, one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Min(m, n)
expr = Forall(instance_param_or_params = [A, B], instance_expr = Forall(instance_param_or_params = [v], instance_expr = Exists(instance_param_or_params = [a_1_to_m], instance_expr = Exists(instance_param_or_params = [b_1_to_n], instance_expr = Exists(instance_param_or_params = [ExprRange(sub_expr1, IndexedVar(lambda_, sub_expr1), one, sub_expr2)], instance_expr = Equals(v, VecSum(index_or_indices = [i], summand = ScalarMult(lambda_i, TensorProd(a_i, b_i)), domain = Interval(one, sub_expr2))), domain = RealNonNeg).with_wrapping(), condition = InSet(Set(b_1_to_n), OrthoNormBases(B))).with_wrapping(), condition = InSet(Set(a_1_to_m), OrthoNormBases(A))).with_wrapping(), domain = TensorProd(A, B)), domain = HilbertSpaces, conditions = [Equals(Dim(A), m), Equals(Dim(B), n)]).with_wrapping()
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())
\begin{array}{l}\forall_{A, B \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces}~|~\textrm{Dim}\left(A\right) = m, \textrm{Dim}\left(B\right) = n}~\\
\left[\forall_{v \in A {\otimes} B}~\left[\begin{array}{l}\exists_{a_{1}, a_{2}, \ldots, a_{m}~|~\left\{a_{1}, a_{2}, \ldots, a_{m}\right\} \in \textrm{O.N.Bases}\left(A\right)}~\\
\left[\begin{array}{l}\exists_{b_{1}, b_{2}, \ldots, b_{n}~|~\left\{b_{1}, b_{2}, \ldots, b_{n}\right\} \in \textrm{O.N.Bases}\left(B\right)}~\\
\left[\begin{array}{l}\exists_{\lambda_{1}, \lambda_{2}, \ldots, \lambda_{{\rm Min}\left(m, n\right)} \in \mathbb{R}^{\ge 0}}~\\
\left(v = \left(\sum_{i=1}^{{\rm Min}\left(m, n\right)} \left(\lambda_{i} \cdot \left(a_{i} {\otimes} b_{i}\right)\right)\right)\right)\end{array}\right]\end{array}\right]\end{array}\right]\right]\end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('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: 6
operand: 2
1ExprTuple2
2Lambdaparameters: 32
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 9
5Operationoperator: 69
operands: 8
6Literal
7ExprTuple9
8ExprTuple10, 11, 12, 13
9Lambdaparameter: 72
body: 15
10Operationoperator: 17
operands: 16
11Operationoperator: 17
operands: 18
12Operationoperator: 67
operands: 19
13Operationoperator: 67
operands: 20
14ExprTuple72
15Conditionalvalue: 21
condition: 22
16ExprTuple46, 23
17Literal
18ExprTuple65, 23
19ExprTuple24, 111
20ExprTuple25, 112
21Operationoperator: 47
operand: 29
22Operationoperator: 89
operands: 27
23Literal
24Operationoperator: 28
operand: 46
25Operationoperator: 28
operand: 65
26ExprTuple29
27ExprTuple72, 30
28Literal
29Lambdaparameters: 41
body: 31
30Operationoperator: 97
operands: 32
31Conditionalvalue: 33
condition: 34
32ExprTuple46, 65
33Operationoperator: 47
operand: 37
34Operationoperator: 89
operands: 36
35ExprTuple37
36ExprTuple38, 39
37Lambdaparameters: 58
body: 40
38Operationoperator: 57
operands: 41
39Operationoperator: 59
operand: 46
40Conditionalvalue: 43
condition: 44
41ExprTuple45
42ExprTuple46
43Operationoperator: 47
operand: 51
44Operationoperator: 89
operands: 49
45ExprRangelambda_map: 50
start_index: 103
end_index: 111
46Variable
47Literal
48ExprTuple51
49ExprTuple52, 53
50Lambdaparameter: 95
body: 54
51Lambdaparameters: 55
body: 56
52Operationoperator: 57
operands: 58
53Operationoperator: 59
operand: 65
54IndexedVarvariable: 105
index: 95
55ExprTuple61
56Conditionalvalue: 62
condition: 63
57Literal
58ExprTuple64
59Literal
60ExprTuple65
61ExprRangelambda_map: 66
start_index: 103
end_index: 104
62Operationoperator: 67
operands: 68
63Operationoperator: 69
operands: 70
64ExprRangelambda_map: 71
start_index: 103
end_index: 112
65Variable
66Lambdaparameter: 95
body: 85
67Literal
68ExprTuple72, 73
69Literal
70ExprTuple74
71Lambdaparameter: 95
body: 75
72Variable
73Operationoperator: 76
operand: 79
74ExprRangelambda_map: 78
start_index: 103
end_index: 104
75IndexedVarvariable: 106
index: 95
76Literal
77ExprTuple79
78Lambdaparameter: 95
body: 80
79Lambdaparameter: 110
body: 81
80Operationoperator: 89
operands: 82
81Conditionalvalue: 83
condition: 84
82ExprTuple85, 86
83Operationoperator: 87
operands: 88
84Operationoperator: 89
operands: 90
85IndexedVarvariable: 96
index: 95
86Literal
87Literal
88ExprTuple92, 93
89Literal
90ExprTuple110, 94
91ExprTuple95
92IndexedVarvariable: 96
index: 110
93Operationoperator: 97
operands: 98
94Operationoperator: 99
operands: 100
95Variable
96Variable
97Literal
98ExprTuple101, 102
99Literal
100ExprTuple103, 104
101IndexedVarvariable: 105
index: 110
102IndexedVarvariable: 106
index: 110
103Literal
104Operationoperator: 108
operands: 109
105Variable
106Variable
107ExprTuple110
108Literal
109ExprTuple111, 112
110Variable
111Variable
112Variable