logo

Expression of type Lambda

from the theory of proveit.linear_algebra.tensors

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, IndexedVar, K, Lambda, U, V, Variable, W, alpha, b, i, k
from proveit.core_expr_types import U_1_to_i, W_1_to_k, a_1_to_i, c_1_to_k
from proveit.linear_algebra import ScalarMult, TensorProd, VecSpaces
from proveit.logic import And, Equals, Forall, InClass
from proveit.numbers import one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = VecSpaces(K)
sub_expr3 = [U_1_to_i, V, W_1_to_k]
expr = Lambda(sub_expr3, Conditional(Forall(instance_param_or_params = [a_1_to_i, b, c_1_to_k], instance_expr = Equals(TensorProd(a_1_to_i, ScalarMult(alpha, b), c_1_to_k), ScalarMult(alpha, TensorProd(a_1_to_i, b, c_1_to_k))).with_wrapping_at(1), domains = sub_expr3).with_wrapping(), And(ExprRange(sub_expr1, InClass(IndexedVar(U, sub_expr1), sub_expr2), one, i), InClass(V, sub_expr2), ExprRange(sub_expr1, InClass(IndexedVar(W, sub_expr1), sub_expr2), one, k))))
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(U_{1}, U_{2}, \ldots, U_{i}, V, W_{1}, W_{2}, \ldots, W_{k}\right) \mapsto \left\{\begin{array}{l}\forall_{\left(a_{1} \in U_{1}\right), \left(a_{2} \in U_{2}\right), \ldots, \left(a_{i} \in U_{i}\right), b \in V,\left(c_{1} \in W_{1}\right), \left(c_{2} \in W_{2}\right), \ldots, \left(c_{k} \in W_{k}\right)}~\\
\left(\begin{array}{c} \begin{array}{l} \left(a_{1} {\otimes}  a_{2} {\otimes}  \ldots {\otimes}  a_{i} {\otimes} \left(\alpha \cdot b\right){\otimes} c_{1} {\otimes}  c_{2} {\otimes}  \ldots {\otimes}  c_{k}\right) \\  = \left(\alpha \cdot \left(a_{1} {\otimes}  a_{2} {\otimes}  \ldots {\otimes}  a_{i} {\otimes} b{\otimes} c_{1} {\otimes}  c_{2} {\otimes}  \ldots {\otimes}  c_{k}\right)\right) \end{array} \end{array}\right)\end{array} \textrm{ if } \left(U_{1} \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(K\right)\right) ,  \left(U_{2} \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(K\right)\right) ,  \ldots ,  \left(U_{i} \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(K\right)\right) ,  V \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(K\right), \left(W_{1} \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(K\right)\right) ,  \left(W_{2} \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(K\right)\right) ,  \ldots ,  \left(W_{k} \underset{{\scriptscriptstyle c}}{\in} \textrm{VecSpaces}\left(K\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
0Lambdaparameters: 1
body: 2
1ExprTuple3, 47, 4
2Conditionalvalue: 5
condition: 6
3ExprRangelambda_map: 7
start_index: 66
end_index: 64
4ExprRangelambda_map: 8
start_index: 66
end_index: 67
5Operationoperator: 9
operand: 12
6Operationoperator: 26
operands: 11
7Lambdaparameter: 75
body: 61
8Lambdaparameter: 75
body: 62
9Literal
10ExprTuple12
11ExprTuple13, 14, 15
12Lambdaparameters: 53
body: 16
13ExprRangelambda_map: 17
start_index: 66
end_index: 64
14Operationoperator: 29
operands: 18
15ExprRangelambda_map: 19
start_index: 66
end_index: 67
16Conditionalvalue: 20
condition: 21
17Lambdaparameter: 75
body: 22
18ExprTuple47, 36
19Lambdaparameter: 75
body: 23
20Operationoperator: 24
operands: 25
21Operationoperator: 26
operands: 27
22Operationoperator: 29
operands: 28
23Operationoperator: 29
operands: 30
24Literal
25ExprTuple31, 32
26Literal
27ExprTuple33, 34, 35
28ExprTuple61, 36
29Literal
30ExprTuple62, 36
31Operationoperator: 52
operands: 37
32Operationoperator: 50
operands: 38
33ExprRangelambda_map: 39
start_index: 66
end_index: 64
34Operationoperator: 55
operands: 40
35ExprRangelambda_map: 41
start_index: 66
end_index: 67
36Operationoperator: 42
operand: 49
37ExprTuple58, 44, 60
38ExprTuple57, 45
39Lambdaparameter: 75
body: 46
40ExprTuple59, 47
41Lambdaparameter: 75
body: 48
42Literal
43ExprTuple49
44Operationoperator: 50
operands: 51
45Operationoperator: 52
operands: 53
46Operationoperator: 55
operands: 54
47Variable
48Operationoperator: 55
operands: 56
49Variable
50Literal
51ExprTuple57, 59
52Literal
53ExprTuple58, 59, 60
54ExprTuple70, 61
55Literal
56ExprTuple71, 62
57Variable
58ExprRangelambda_map: 63
start_index: 66
end_index: 64
59Variable
60ExprRangelambda_map: 65
start_index: 66
end_index: 67
61IndexedVarvariable: 68
index: 75
62IndexedVarvariable: 69
index: 75
63Lambdaparameter: 75
body: 70
64Variable
65Lambdaparameter: 75
body: 71
66Literal
67Variable
68Variable
69Variable
70IndexedVarvariable: 72
index: 75
71IndexedVarvariable: 73
index: 75
72Variable
73Variable
74ExprTuple75
75Variable