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, e, 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, f_1_to_k
from proveit.linear_algebra import TensorProd, VecSpaces, VecZero
from proveit.logic import And, Equals, Forall, Implies, InClass, NotEquals
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, f_1_to_k], instance_expr = Forall(instance_param_or_params = [b, e], instance_expr = Implies(Equals(TensorProd(a_1_to_i, b, c_1_to_k), TensorProd(d_1_to_i, e, f_1_to_k)).with_wrapping_at(2), Equals(TensorProd(a_1_to_i, c_1_to_k), TensorProd(d_1_to_i, f_1_to_k)).with_wrapping_at(2)).with_wrapping_at(2), domain = V, conditions = [Equals(b, e), NotEquals(b, VecZero(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(f_{1} \in W_{1}\right), \left(f_{2} \in W_{2}\right), \ldots, \left(f_{k} \in W_{k}\right)}~\\
\left[\forall_{b, e \in V~|~b = e, b \neq \vec{0}\left(V\right)}~\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} 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} e{\otimes} f_{1} {\otimes}  f_{2} {\otimes}  \ldots {\otimes}  f_{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} c_{1} {\otimes}  c_{2} {\otimes}  \ldots {\otimes}  c_{k}\right) =  \\ \left(d_{1} {\otimes}  d_{2} {\otimes}  \ldots {\otimes}  d_{i}{\otimes} f_{1} {\otimes}  f_{2} {\otimes}  \ldots {\otimes}  f_{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, 95, 4
2Conditionalvalue: 5
condition: 6
3ExprRangelambda_map: 7
start_index: 101
end_index: 99
4ExprRangelambda_map: 8
start_index: 101
end_index: 102
5Operationoperator: 24
operand: 11
6Operationoperator: 52
operands: 10
7Lambdaparameter: 112
body: 64
8Lambdaparameter: 112
body: 65
9ExprTuple11
10ExprTuple12, 13, 14
11Lambdaparameters: 15
body: 16
12ExprRangelambda_map: 17
start_index: 101
end_index: 99
13Operationoperator: 28
operands: 18
14ExprRangelambda_map: 19
start_index: 101
end_index: 102
15ExprTuple91, 92, 93, 94
16Conditionalvalue: 20
condition: 21
17Lambdaparameter: 112
body: 22
18ExprTuple95, 35
19Lambdaparameter: 112
body: 23
20Operationoperator: 24
operand: 30
21Operationoperator: 52
operands: 26
22Operationoperator: 28
operands: 27
23Operationoperator: 28
operands: 29
24Literal
25ExprTuple30
26ExprTuple31, 32, 33, 34
27ExprTuple64, 35
28Literal
29ExprTuple65, 35
30Lambdaparameters: 72
body: 36
31ExprRangelambda_map: 37
start_index: 101
end_index: 99
32ExprRangelambda_map: 38
start_index: 101
end_index: 102
33ExprRangelambda_map: 39
start_index: 101
end_index: 99
34ExprRangelambda_map: 40
start_index: 101
end_index: 102
35Operationoperator: 41
operand: 49
36Conditionalvalue: 43
condition: 44
37Lambdaparameter: 112
body: 45
38Lambdaparameter: 112
body: 46
39Lambdaparameter: 112
body: 47
40Lambdaparameter: 112
body: 48
41Literal
42ExprTuple49
43Operationoperator: 50
operands: 51
44Operationoperator: 52
operands: 53
45Operationoperator: 69
operands: 54
46Operationoperator: 69
operands: 55
47Operationoperator: 69
operands: 56
48Operationoperator: 69
operands: 57
49Variable
50Literal
51ExprTuple58, 59
52Literal
53ExprTuple60, 61, 62, 63
54ExprTuple103, 64
55ExprTuple104, 65
56ExprTuple105, 64
57ExprTuple106, 65
58Operationoperator: 71
operands: 66
59Operationoperator: 71
operands: 67
60Operationoperator: 69
operands: 68
61Operationoperator: 69
operands: 70
62Operationoperator: 71
operands: 72
63Operationoperator: 73
operands: 74
64IndexedVarvariable: 75
index: 112
65IndexedVarvariable: 76
index: 112
66ExprTuple77, 78
67ExprTuple79, 80
68ExprTuple89, 95
69Literal
70ExprTuple90, 95
71Literal
72ExprTuple89, 90
73Literal
74ExprTuple89, 81
75Variable
76Variable
77Operationoperator: 85
operands: 82
78Operationoperator: 85
operands: 83
79Operationoperator: 85
operands: 84
80Operationoperator: 85
operands: 86
81Operationoperator: 87
operand: 95
82ExprTuple91, 89, 92
83ExprTuple93, 90, 94
84ExprTuple91, 92
85Literal
86ExprTuple93, 94
87Literal
88ExprTuple95
89Variable
90Variable
91ExprRangelambda_map: 96
start_index: 101
end_index: 99
92ExprRangelambda_map: 97
start_index: 101
end_index: 102
93ExprRangelambda_map: 98
start_index: 101
end_index: 99
94ExprRangelambda_map: 100
start_index: 101
end_index: 102
95Variable
96Lambdaparameter: 112
body: 103
97Lambdaparameter: 112
body: 104
98Lambdaparameter: 112
body: 105
99Variable
100Lambdaparameter: 112
body: 106
101Literal
102Variable
103IndexedVarvariable: 107
index: 112
104IndexedVarvariable: 108
index: 112
105IndexedVarvariable: 109
index: 112
106IndexedVarvariable: 110
index: 112
107Variable
108Variable
109Variable
110Variable
111ExprTuple112
112Variable