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, 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, d_1_to_i, e_1_to_k
from proveit.linear_algebra import TensorProd, VecSpaces
from proveit.logic import And, Equals, Forall, Implies, 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)
expr = Lambda([U_1_to_i, V, W_1_to_k], Conditional(Forall(instance_param_or_params = [a_1_to_i, c_1_to_k, d_1_to_i, e_1_to_k], instance_expr = Forall(instance_param_or_params = [b], instance_expr = Implies(Equals(TensorProd(a_1_to_i, c_1_to_k), TensorProd(d_1_to_i, e_1_to_k)).with_wrapping_at(2), Equals(TensorProd(a_1_to_i, b, c_1_to_k), TensorProd(d_1_to_i, b, e_1_to_k)).with_wrapping_at(2)).with_wrapping_at(2), domain = V), domains = [U_1_to_i, W_1_to_k, U_1_to_i, W_1_to_k]).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),\left(c_{1} \in W_{1}\right), \left(c_{2} \in W_{2}\right), \ldots, \left(c_{k} \in W_{k}\right),\left(d_{1} \in U_{1}\right), \left(d_{2} \in U_{2}\right), \ldots, \left(d_{i} \in U_{i}\right),\left(e_{1} \in W_{1}\right), \left(e_{2} \in W_{2}\right), \ldots, \left(e_{k} \in W_{k}\right)}~\\
\left[\forall_{b \in V}~\left(\begin{array}{c} \begin{array}{l} \left(\begin{array}{c} \begin{array}{l} \left(a_{1} {\otimes}  a_{2} {\otimes}  \ldots {\otimes}  a_{i}{\otimes} c_{1} {\otimes}  c_{2} {\otimes}  \ldots {\otimes}  c_{k}\right) =  \\ \left(d_{1} {\otimes}  d_{2} {\otimes}  \ldots {\otimes}  d_{i}{\otimes} e_{1} {\otimes}  e_{2} {\otimes}  \ldots {\otimes}  e_{k}\right) \end{array} \end{array}\right) \Rightarrow  \\ \left(\begin{array}{c} \begin{array}{l} \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) =  \\ \left(d_{1} {\otimes}  d_{2} {\otimes}  \ldots {\otimes}  d_{i} {\otimes} b{\otimes} e_{1} {\otimes}  e_{2} {\otimes}  \ldots {\otimes}  e_{k}\right) \end{array} \end{array}\right) \end{array} \end{array}\right)\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, 62, 4
2Conditionalvalue: 5
condition: 6
3ExprRangelambda_map: 7
start_index: 89
end_index: 87
4ExprRangelambda_map: 8
start_index: 89
end_index: 90
5Operationoperator: 24
operand: 11
6Operationoperator: 26
operands: 10
7Lambdaparameter: 100
body: 63
8Lambdaparameter: 100
body: 64
9ExprTuple11
10ExprTuple12, 13, 14
11Lambdaparameters: 15
body: 16
12ExprRangelambda_map: 17
start_index: 89
end_index: 87
13Operationoperator: 29
operands: 18
14ExprRangelambda_map: 19
start_index: 89
end_index: 90
15ExprTuple79, 80, 81, 83
16Conditionalvalue: 20
condition: 21
17Lambdaparameter: 100
body: 22
18ExprTuple62, 36
19Lambdaparameter: 100
body: 23
20Operationoperator: 24
operand: 31
21Operationoperator: 26
operands: 27
22Operationoperator: 29
operands: 28
23Operationoperator: 29
operands: 30
24Literal
25ExprTuple31
26Literal
27ExprTuple32, 33, 34, 35
28ExprTuple63, 36
29Literal
30ExprTuple64, 36
31Lambdaparameter: 82
body: 38
32ExprRangelambda_map: 39
start_index: 89
end_index: 87
33ExprRangelambda_map: 40
start_index: 89
end_index: 90
34ExprRangelambda_map: 41
start_index: 89
end_index: 87
35ExprRangelambda_map: 42
start_index: 89
end_index: 90
36Operationoperator: 43
operand: 51
37ExprTuple82
38Conditionalvalue: 45
condition: 46
39Lambdaparameter: 100
body: 47
40Lambdaparameter: 100
body: 48
41Lambdaparameter: 100
body: 49
42Lambdaparameter: 100
body: 50
43Literal
44ExprTuple51
45Operationoperator: 52
operands: 53
46Operationoperator: 58
operands: 54
47Operationoperator: 58
operands: 55
48Operationoperator: 58
operands: 56
49Operationoperator: 58
operands: 57
50Operationoperator: 58
operands: 59
51Variable
52Literal
53ExprTuple60, 61
54ExprTuple82, 62
55ExprTuple91, 63
56ExprTuple92, 64
57ExprTuple93, 63
58Literal
59ExprTuple94, 64
60Operationoperator: 66
operands: 65
61Operationoperator: 66
operands: 67
62Variable
63IndexedVarvariable: 68
index: 100
64IndexedVarvariable: 69
index: 100
65ExprTuple70, 71
66Literal
67ExprTuple72, 73
68Variable
69Variable
70Operationoperator: 77
operands: 74
71Operationoperator: 77
operands: 75
72Operationoperator: 77
operands: 76
73Operationoperator: 77
operands: 78
74ExprTuple79, 80
75ExprTuple81, 83
76ExprTuple79, 82, 80
77Literal
78ExprTuple81, 82, 83
79ExprRangelambda_map: 84
start_index: 89
end_index: 87
80ExprRangelambda_map: 85
start_index: 89
end_index: 90
81ExprRangelambda_map: 86
start_index: 89
end_index: 87
82Variable
83ExprRangelambda_map: 88
start_index: 89
end_index: 90
84Lambdaparameter: 100
body: 91
85Lambdaparameter: 100
body: 92
86Lambdaparameter: 100
body: 93
87Variable
88Lambdaparameter: 100
body: 94
89Literal
90Variable
91IndexedVarvariable: 95
index: 100
92IndexedVarvariable: 96
index: 100
93IndexedVarvariable: 97
index: 100
94IndexedVarvariable: 98
index: 100
95Variable
96Variable
97Variable
98Variable
99ExprTuple100
100Variable