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, InSet, Set
from proveit.numbers import Interval, Min, NaturalPos, 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([m, n], Conditional(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(), And(InSet(m, NaturalPos), InSet(n, NaturalPos))))
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(m, n\right) \mapsto \left\{\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} \textrm{ if } m \in \mathbb{N}^+ ,  n \in \mathbb{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: 118
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 15
operand: 6
3Operationoperator: 78
operands: 5
4ExprTuple6
5ExprTuple7, 8
6Lambdaparameters: 41
body: 9
7Operationoperator: 98
operands: 10
8Operationoperator: 98
operands: 11
9Conditionalvalue: 12
condition: 13
10ExprTuple120, 14
11ExprTuple121, 14
12Operationoperator: 15
operand: 18
13Operationoperator: 78
operands: 17
14Literal
15Literal
16ExprTuple18
17ExprTuple19, 20, 21, 22
18Lambdaparameter: 81
body: 24
19Operationoperator: 26
operands: 25
20Operationoperator: 26
operands: 27
21Operationoperator: 76
operands: 28
22Operationoperator: 76
operands: 29
23ExprTuple81
24Conditionalvalue: 30
condition: 31
25ExprTuple55, 32
26Literal
27ExprTuple74, 32
28ExprTuple33, 120
29ExprTuple34, 121
30Operationoperator: 56
operand: 38
31Operationoperator: 98
operands: 36
32Literal
33Operationoperator: 37
operand: 55
34Operationoperator: 37
operand: 74
35ExprTuple38
36ExprTuple81, 39
37Literal
38Lambdaparameters: 50
body: 40
39Operationoperator: 106
operands: 41
40Conditionalvalue: 42
condition: 43
41ExprTuple55, 74
42Operationoperator: 56
operand: 46
43Operationoperator: 98
operands: 45
44ExprTuple46
45ExprTuple47, 48
46Lambdaparameters: 67
body: 49
47Operationoperator: 66
operands: 50
48Operationoperator: 68
operand: 55
49Conditionalvalue: 52
condition: 53
50ExprTuple54
51ExprTuple55
52Operationoperator: 56
operand: 60
53Operationoperator: 98
operands: 58
54ExprRangelambda_map: 59
start_index: 112
end_index: 120
55Variable
56Literal
57ExprTuple60
58ExprTuple61, 62
59Lambdaparameter: 104
body: 63
60Lambdaparameters: 64
body: 65
61Operationoperator: 66
operands: 67
62Operationoperator: 68
operand: 74
63IndexedVarvariable: 114
index: 104
64ExprTuple70
65Conditionalvalue: 71
condition: 72
66Literal
67ExprTuple73
68Literal
69ExprTuple74
70ExprRangelambda_map: 75
start_index: 112
end_index: 113
71Operationoperator: 76
operands: 77
72Operationoperator: 78
operands: 79
73ExprRangelambda_map: 80
start_index: 112
end_index: 121
74Variable
75Lambdaparameter: 104
body: 94
76Literal
77ExprTuple81, 82
78Literal
79ExprTuple83
80Lambdaparameter: 104
body: 84
81Variable
82Operationoperator: 85
operand: 88
83ExprRangelambda_map: 87
start_index: 112
end_index: 113
84IndexedVarvariable: 115
index: 104
85Literal
86ExprTuple88
87Lambdaparameter: 104
body: 89
88Lambdaparameter: 119
body: 90
89Operationoperator: 98
operands: 91
90Conditionalvalue: 92
condition: 93
91ExprTuple94, 95
92Operationoperator: 96
operands: 97
93Operationoperator: 98
operands: 99
94IndexedVarvariable: 105
index: 104
95Literal
96Literal
97ExprTuple101, 102
98Literal
99ExprTuple119, 103
100ExprTuple104
101IndexedVarvariable: 105
index: 119
102Operationoperator: 106
operands: 107
103Operationoperator: 108
operands: 109
104Variable
105Variable
106Literal
107ExprTuple110, 111
108Literal
109ExprTuple112, 113
110IndexedVarvariable: 114
index: 119
111IndexedVarvariable: 115
index: 119
112Literal
113Operationoperator: 117
operands: 118
114Variable
115Variable
116ExprTuple119
117Literal
118ExprTuple120, 121
119Variable
120Variable
121Variable