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 B, Conditional, ExprRange, IndexedVar, Lambda, Variable, i, lambda_, m, n, v
from proveit.core_expr_types import a_i, b_1_to_n, b_i, lambda_i
from proveit.linear_algebra import OrthoNormBases, ScalarMult, TensorProd, VecSum
from proveit.logic import Equals, Exists, 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([b_1_to_n], Conditional(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(), InSet(Set(b_1_to_n), OrthoNormBases(B))))
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(b_{1}, b_{2}, \ldots, b_{n}\right) \mapsto \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} \textrm{ if } \left\{b_{1}, b_{2}, \ldots, b_{n}\right\} \in \textrm{O.N.Bases}\left(B\right)\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 13
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 44
operands: 6
4Literal
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameters: 10
body: 11
8Operationoperator: 12
operands: 13
9Operationoperator: 14
operand: 20
10ExprTuple16
11Conditionalvalue: 17
condition: 18
12Literal
13ExprTuple19
14Literal
15ExprTuple20
16ExprRangelambda_map: 21
start_index: 58
end_index: 59
17Operationoperator: 22
operands: 23
18Operationoperator: 24
operands: 25
19ExprRangelambda_map: 26
start_index: 58
end_index: 67
20Variable
21Lambdaparameter: 50
body: 40
22Literal
23ExprTuple27, 28
24Literal
25ExprTuple29
26Lambdaparameter: 50
body: 30
27Variable
28Operationoperator: 31
operand: 34
29ExprRangelambda_map: 33
start_index: 58
end_index: 59
30IndexedVarvariable: 61
index: 50
31Literal
32ExprTuple34
33Lambdaparameter: 50
body: 35
34Lambdaparameter: 65
body: 36
35Operationoperator: 44
operands: 37
36Conditionalvalue: 38
condition: 39
37ExprTuple40, 41
38Operationoperator: 42
operands: 43
39Operationoperator: 44
operands: 45
40IndexedVarvariable: 51
index: 50
41Literal
42Literal
43ExprTuple47, 48
44Literal
45ExprTuple65, 49
46ExprTuple50
47IndexedVarvariable: 51
index: 65
48Operationoperator: 52
operands: 53
49Operationoperator: 54
operands: 55
50Variable
51Variable
52Literal
53ExprTuple56, 57
54Literal
55ExprTuple58, 59
56IndexedVarvariable: 60
index: 65
57IndexedVarvariable: 61
index: 65
58Literal
59Operationoperator: 63
operands: 64
60Variable
61Variable
62ExprTuple65
63Literal
64ExprTuple66, 67
65Variable
66Variable
67Variable