logo

Expression of type Lambda

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, Conditional, ExprRange, IndexedVar, Lambda, 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 And, Equals, Exists, Forall, InClass, 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 = Lambda([A, B], Conditional(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)), And(InClass(A, HilbertSpaces), InClass(B, HilbertSpaces), Equals(Dim(A), m), Equals(Dim(B), n))))
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(A, B\right) \mapsto \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] \textrm{ if } A \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces} ,  B \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces} ,  \textrm{Dim}\left(A\right) = m ,  \textrm{Dim}\left(B\right) = n\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 30
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 67
operands: 6
4Literal
5ExprTuple7
6ExprTuple8, 9, 10, 11
7Lambdaparameter: 70
body: 13
8Operationoperator: 15
operands: 14
9Operationoperator: 15
operands: 16
10Operationoperator: 65
operands: 17
11Operationoperator: 65
operands: 18
12ExprTuple70
13Conditionalvalue: 19
condition: 20
14ExprTuple44, 21
15Literal
16ExprTuple63, 21
17ExprTuple22, 109
18ExprTuple23, 110
19Operationoperator: 45
operand: 27
20Operationoperator: 87
operands: 25
21Literal
22Operationoperator: 26
operand: 44
23Operationoperator: 26
operand: 63
24ExprTuple27
25ExprTuple70, 28
26Literal
27Lambdaparameters: 39
body: 29
28Operationoperator: 95
operands: 30
29Conditionalvalue: 31
condition: 32
30ExprTuple44, 63
31Operationoperator: 45
operand: 35
32Operationoperator: 87
operands: 34
33ExprTuple35
34ExprTuple36, 37
35Lambdaparameters: 56
body: 38
36Operationoperator: 55
operands: 39
37Operationoperator: 57
operand: 44
38Conditionalvalue: 41
condition: 42
39ExprTuple43
40ExprTuple44
41Operationoperator: 45
operand: 49
42Operationoperator: 87
operands: 47
43ExprRangelambda_map: 48
start_index: 101
end_index: 109
44Variable
45Literal
46ExprTuple49
47ExprTuple50, 51
48Lambdaparameter: 93
body: 52
49Lambdaparameters: 53
body: 54
50Operationoperator: 55
operands: 56
51Operationoperator: 57
operand: 63
52IndexedVarvariable: 103
index: 93
53ExprTuple59
54Conditionalvalue: 60
condition: 61
55Literal
56ExprTuple62
57Literal
58ExprTuple63
59ExprRangelambda_map: 64
start_index: 101
end_index: 102
60Operationoperator: 65
operands: 66
61Operationoperator: 67
operands: 68
62ExprRangelambda_map: 69
start_index: 101
end_index: 110
63Variable
64Lambdaparameter: 93
body: 83
65Literal
66ExprTuple70, 71
67Literal
68ExprTuple72
69Lambdaparameter: 93
body: 73
70Variable
71Operationoperator: 74
operand: 77
72ExprRangelambda_map: 76
start_index: 101
end_index: 102
73IndexedVarvariable: 104
index: 93
74Literal
75ExprTuple77
76Lambdaparameter: 93
body: 78
77Lambdaparameter: 108
body: 79
78Operationoperator: 87
operands: 80
79Conditionalvalue: 81
condition: 82
80ExprTuple83, 84
81Operationoperator: 85
operands: 86
82Operationoperator: 87
operands: 88
83IndexedVarvariable: 94
index: 93
84Literal
85Literal
86ExprTuple90, 91
87Literal
88ExprTuple108, 92
89ExprTuple93
90IndexedVarvariable: 94
index: 108
91Operationoperator: 95
operands: 96
92Operationoperator: 97
operands: 98
93Variable
94Variable
95Literal
96ExprTuple99, 100
97Literal
98ExprTuple101, 102
99IndexedVarvariable: 103
index: 108
100IndexedVarvariable: 104
index: 108
101Literal
102Operationoperator: 106
operands: 107
103Variable
104Variable
105ExprTuple108
106Literal
107ExprTuple109, 110
108Variable
109Variable
110Variable