logo

Expression of type ExprTuple

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 Conditional, ExprRange, ExprTuple, IndexedVar, Lambda, Variable, i, lambda_, m, n, v
from proveit.core_expr_types import a_i, b_i, lambda_i
from proveit.linear_algebra import ScalarMult, TensorProd, VecSum
from proveit.logic import And, Equals, InSet
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 = IndexedVar(lambda_, sub_expr1)
sub_expr3 = Min(m, n)
expr = ExprTuple(Lambda([ExprRange(sub_expr1, sub_expr2, one, sub_expr3)], Conditional(Equals(v, VecSum(index_or_indices = [i], summand = ScalarMult(lambda_i, TensorProd(a_i, b_i)), domain = Interval(one, sub_expr3))), And(ExprRange(sub_expr1, InSet(sub_expr2, RealNonNeg), one, sub_expr3)))))
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(\left(\lambda_{1}, \lambda_{2}, \ldots, \lambda_{{\rm Min}\left(m, n\right)}\right) \mapsto \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) \textrm{ if } \left(\lambda_{1} \in \mathbb{R}^{\ge 0}\right) \land  \left(\lambda_{2} \in \mathbb{R}^{\ge 0}\right) \land  \ldots \land  \left(\lambda_{{\rm Min}\left(m, n\right)} \in \mathbb{R}^{\ge 0}\right)\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameters: 2
body: 3
2ExprTuple4
3Conditionalvalue: 5
condition: 6
4ExprRangelambda_map: 7
start_index: 42
end_index: 43
5Operationoperator: 8
operands: 9
6Operationoperator: 10
operands: 11
7Lambdaparameter: 34
body: 24
8Literal
9ExprTuple12, 13
10Literal
11ExprTuple14
12Variable
13Operationoperator: 15
operand: 18
14ExprRangelambda_map: 17
start_index: 42
end_index: 43
15Literal
16ExprTuple18
17Lambdaparameter: 34
body: 19
18Lambdaparameter: 49
body: 20
19Operationoperator: 28
operands: 21
20Conditionalvalue: 22
condition: 23
21ExprTuple24, 25
22Operationoperator: 26
operands: 27
23Operationoperator: 28
operands: 29
24IndexedVarvariable: 35
index: 34
25Literal
26Literal
27ExprTuple31, 32
28Literal
29ExprTuple49, 33
30ExprTuple34
31IndexedVarvariable: 35
index: 49
32Operationoperator: 36
operands: 37
33Operationoperator: 38
operands: 39
34Variable
35Variable
36Literal
37ExprTuple40, 41
38Literal
39ExprTuple42, 43
40IndexedVarvariable: 44
index: 49
41IndexedVarvariable: 45
index: 49
42Literal
43Operationoperator: 47
operands: 48
44Variable
45Variable
46ExprTuple49
47Literal
48ExprTuple50, 51
49Variable
50Variable
51Variable