logo

Expression of type Lambda

from the theory of proveit.physics.quantum.algebra

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 A, B, Conditional, Lambda, i, n
from proveit.core_expr_types import a_1_to_n, a_i, b_1_to_n, b_i, v_1_to_n, v_i
from proveit.linear_algebra import Adj, Commutator, Dim, HilbertSpaces, Hspace, LinMap, OrthoNormBases, ScalarMult, VecSum, VecZero
from proveit.logic import And, Equals, Exists, Forall, Iff, InSet, Set
from proveit.numbers import Complex, Interval, NaturalPos, one
from proveit.physics.quantum import Bra, Ket, Qmult
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [i]
sub_expr2 = LinMap(Hspace, Hspace)
sub_expr3 = Interval(one, n)
sub_expr4 = Qmult(Ket(v_i), Bra(v_i))
expr = Lambda(n, Conditional(Forall(instance_param_or_params = [Hspace], instance_expr = Forall(instance_param_or_params = [A, B], instance_expr = Iff(Equals(Commutator(A, B), VecZero(sub_expr2)), Exists(instance_param_or_params = [v_1_to_n], instance_expr = Exists(instance_param_or_params = [a_1_to_n, b_1_to_n], instance_expr = And(Equals(A, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(a_i, sub_expr4), domain = sub_expr3)), Equals(B, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(b_i, sub_expr4), domain = sub_expr3))).with_wrapping_at(2), domain = Complex).with_wrapping(), condition = InSet(Set(v_1_to_n), OrthoNormBases(Hspace))).with_wrapping()).with_wrapping_at(2), domain = sub_expr2, conditions = [Equals(Adj(A), A), Equals(Adj(B), B)]).with_wrapping(), domain = HilbertSpaces, condition = Equals(Dim(Hspace), n)).with_wrapping(), InSet(n, NaturalPos)))
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())
n \mapsto \left\{\begin{array}{l}\forall_{\mathcal{H} \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces}~|~\textrm{Dim}\left(\mathcal{H}\right) = n}~\\
\left[\begin{array}{l}\forall_{A, B \in \mathcal{L}\left(\mathcal{H}, \mathcal{H}\right)~|~A^{\dagger} = A, B^{\dagger} = B}~\\
\left(\begin{array}{c} \begin{array}{l} \left(\left[A, B\right] = \vec{0}\left(\mathcal{L}\left(\mathcal{H}, \mathcal{H}\right)\right)\right) \Leftrightarrow  \\ \left[\begin{array}{l}\exists_{v_{1}, v_{2}, \ldots, v_{n}~|~\left\{v_{1}, v_{2}, \ldots, v_{n}\right\} \in \textrm{O.N.Bases}\left(\mathcal{H}\right)}~\\
\left[\begin{array}{l}\exists_{a_{1}, a_{2}, \ldots, a_{n}, b_{1}, b_{2}, \ldots, b_{n} \in \mathbb{C}}~\\
\left(\begin{array}{c} \left(A = \left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right) \land  \\ \left(B = \left(\sum_{i=1}^{n} \left(b_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right) \end{array}\right)\end{array}\right]\end{array}\right] \end{array} \end{array}\right)\end{array}\right]\end{array} \textrm{ if } n \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 135
body: 2
1ExprTuple135
2Conditionalvalue: 3
condition: 4
3Operationoperator: 12
operand: 7
4Operationoperator: 120
operands: 6
5ExprTuple7
6ExprTuple135, 8
7Lambdaparameter: 77
body: 9
8Literal
9Conditionalvalue: 10
condition: 11
10Operationoperator: 12
operand: 15
11Operationoperator: 81
operands: 14
12Literal
13ExprTuple15
14ExprTuple16, 17
15Lambdaparameters: 48
body: 18
16Operationoperator: 19
operands: 20
17Operationoperator: 90
operands: 21
18Conditionalvalue: 22
condition: 23
19Literal
20ExprTuple77, 24
21ExprTuple25, 135
22Operationoperator: 26
operands: 27
23Operationoperator: 81
operands: 28
24Literal
25Operationoperator: 29
operand: 77
26Literal
27ExprTuple30, 31
28ExprTuple32, 33, 34, 35
29Literal
30Operationoperator: 90
operands: 36
31Operationoperator: 60
operand: 44
32Operationoperator: 120
operands: 38
33Operationoperator: 120
operands: 39
34Operationoperator: 90
operands: 40
35Operationoperator: 90
operands: 41
36ExprTuple42, 43
37ExprTuple44
38ExprTuple94, 55
39ExprTuple96, 55
40ExprTuple45, 94
41ExprTuple46, 96
42Operationoperator: 47
operands: 48
43Operationoperator: 49
operand: 55
44Lambdaparameters: 69
body: 51
45Operationoperator: 53
operand: 94
46Operationoperator: 53
operand: 96
47Literal
48ExprTuple94, 96
49Literal
50ExprTuple55
51Conditionalvalue: 56
condition: 57
52ExprTuple94
53Literal
54ExprTuple96
55Operationoperator: 58
operands: 59
56Operationoperator: 60
operand: 63
57Operationoperator: 120
operands: 62
58Literal
59ExprTuple77, 77
60Literal
61ExprTuple63
62ExprTuple64, 65
63Lambdaparameters: 66
body: 67
64Operationoperator: 68
operands: 69
65Operationoperator: 70
operand: 77
66ExprTuple72, 73
67Conditionalvalue: 74
condition: 75
68Literal
69ExprTuple76
70Literal
71ExprTuple77
72ExprRangelambda_map: 78
start_index: 134
end_index: 135
73ExprRangelambda_map: 79
start_index: 134
end_index: 135
74Operationoperator: 81
operands: 80
75Operationoperator: 81
operands: 82
76ExprRangelambda_map: 83
start_index: 134
end_index: 135
77Variable
78Lambdaparameter: 116
body: 107
79Lambdaparameter: 116
body: 108
80ExprTuple84, 85
81Literal
82ExprTuple86, 87
83Lambdaparameter: 116
body: 88
84Operationoperator: 90
operands: 89
85Operationoperator: 90
operands: 91
86ExprRangelambda_map: 92
start_index: 134
end_index: 135
87ExprRangelambda_map: 93
start_index: 134
end_index: 135
88IndexedVarvariable: 140
index: 116
89ExprTuple94, 95
90Literal
91ExprTuple96, 97
92Lambdaparameter: 116
body: 98
93Lambdaparameter: 116
body: 99
94Variable
95Operationoperator: 101
operand: 105
96Variable
97Operationoperator: 101
operand: 106
98Operationoperator: 120
operands: 103
99Operationoperator: 120
operands: 104
100ExprTuple105
101Literal
102ExprTuple106
103ExprTuple107, 109
104ExprTuple108, 109
105Lambdaparameter: 142
body: 110
106Lambdaparameter: 142
body: 111
107IndexedVarvariable: 126
index: 116
108IndexedVarvariable: 127
index: 116
109Literal
110Conditionalvalue: 113
condition: 115
111Conditionalvalue: 114
condition: 115
112ExprTuple116
113Operationoperator: 118
operands: 117
114Operationoperator: 118
operands: 119
115Operationoperator: 120
operands: 121
116Variable
117ExprTuple122, 124
118Literal
119ExprTuple123, 124
120Literal
121ExprTuple142, 125
122IndexedVarvariable: 126
index: 142
123IndexedVarvariable: 127
index: 142
124Operationoperator: 128
operands: 129
125Operationoperator: 130
operands: 131
126Variable
127Variable
128Literal
129ExprTuple132, 133
130Literal
131ExprTuple134, 135
132Operationoperator: 136
operand: 139
133Operationoperator: 137
operand: 139
134Literal
135Variable
136Literal
137Literal
138ExprTuple139
139IndexedVarvariable: 140
index: 142
140Variable
141ExprTuple142
142Variable