logo

Expression of type ExprTuple

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, ExprTuple, 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, MatrixSpace, OrthoNormBases, ScalarMult, VecSum, VecZero
from proveit.logic import And, CartExp, Equals, Exists, Iff, InSet, Set
from proveit.numbers import Complex, Interval, one
from proveit.physics.quantum import Bra, Ket, Qmult
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [i]
sub_expr2 = MatrixSpace(field = Complex, rows = n, columns = n)
sub_expr3 = Interval(one, n)
sub_expr4 = Qmult(Ket(v_i), Bra(v_i))
expr = ExprTuple(Lambda([A, B], Conditional(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(CartExp(Complex, n)))).with_wrapping()).with_wrapping_at(2), And(InSet(A, sub_expr2), InSet(B, sub_expr2), Equals(Adj(A), A), Equals(Adj(B), B)))))
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(A, B\right) \mapsto \left\{\begin{array}{c} \begin{array}{l} \left(\left[A, B\right] = \vec{0}\left(\mathbb{C}^{n \times n}\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(\mathbb{C}^{n}\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} \textrm{ if } A \in \mathbb{C}^{n \times n} ,  B \in \mathbb{C}^{n \times n} ,  A^{\dagger} = A ,  B^{\dagger} = B\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: 26
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 59
operands: 7
5Literal
6ExprTuple8, 9
7ExprTuple10, 11, 12, 13
8Operationoperator: 70
operands: 14
9Operationoperator: 38
operand: 22
10Operationoperator: 100
operands: 16
11Operationoperator: 100
operands: 17
12Operationoperator: 70
operands: 18
13Operationoperator: 70
operands: 19
14ExprTuple20, 21
15ExprTuple22
16ExprTuple74, 33
17ExprTuple76, 33
18ExprTuple23, 74
19ExprTuple24, 76
20Operationoperator: 25
operands: 26
21Operationoperator: 27
operand: 33
22Lambdaparameters: 47
body: 29
23Operationoperator: 31
operand: 74
24Operationoperator: 31
operand: 76
25Literal
26ExprTuple74, 76
27Literal
28ExprTuple33
29Conditionalvalue: 34
condition: 35
30ExprTuple74
31Literal
32ExprTuple76
33Operationoperator: 36
operands: 37
34Operationoperator: 38
operand: 41
35Operationoperator: 100
operands: 40
36Literal
37NamedExprsfield: 89
rows: 115
columns: 115
38Literal
39ExprTuple41
40ExprTuple42, 43
41Lambdaparameters: 44
body: 45
42Operationoperator: 46
operands: 47
43Operationoperator: 48
operand: 55
44ExprTuple50, 51
45Conditionalvalue: 52
condition: 53
46Literal
47ExprTuple54
48Literal
49ExprTuple55
50ExprRangelambda_map: 56
start_index: 114
end_index: 115
51ExprRangelambda_map: 57
start_index: 114
end_index: 115
52Operationoperator: 59
operands: 58
53Operationoperator: 59
operands: 60
54ExprRangelambda_map: 61
start_index: 114
end_index: 115
55Operationoperator: 62
operands: 63
56Lambdaparameter: 96
body: 87
57Lambdaparameter: 96
body: 88
58ExprTuple64, 65
59Literal
60ExprTuple66, 67
61Lambdaparameter: 96
body: 68
62Literal
63ExprTuple89, 115
64Operationoperator: 70
operands: 69
65Operationoperator: 70
operands: 71
66ExprRangelambda_map: 72
start_index: 114
end_index: 115
67ExprRangelambda_map: 73
start_index: 114
end_index: 115
68IndexedVarvariable: 120
index: 96
69ExprTuple74, 75
70Literal
71ExprTuple76, 77
72Lambdaparameter: 96
body: 78
73Lambdaparameter: 96
body: 79
74Variable
75Operationoperator: 81
operand: 85
76Variable
77Operationoperator: 81
operand: 86
78Operationoperator: 100
operands: 83
79Operationoperator: 100
operands: 84
80ExprTuple85
81Literal
82ExprTuple86
83ExprTuple87, 89
84ExprTuple88, 89
85Lambdaparameter: 122
body: 90
86Lambdaparameter: 122
body: 91
87IndexedVarvariable: 106
index: 96
88IndexedVarvariable: 107
index: 96
89Literal
90Conditionalvalue: 93
condition: 95
91Conditionalvalue: 94
condition: 95
92ExprTuple96
93Operationoperator: 98
operands: 97
94Operationoperator: 98
operands: 99
95Operationoperator: 100
operands: 101
96Variable
97ExprTuple102, 104
98Literal
99ExprTuple103, 104
100Literal
101ExprTuple122, 105
102IndexedVarvariable: 106
index: 122
103IndexedVarvariable: 107
index: 122
104Operationoperator: 108
operands: 109
105Operationoperator: 110
operands: 111
106Variable
107Variable
108Literal
109ExprTuple112, 113
110Literal
111ExprTuple114, 115
112Operationoperator: 116
operand: 119
113Operationoperator: 117
operand: 119
114Literal
115Variable
116Literal
117Literal
118ExprTuple119
119IndexedVarvariable: 120
index: 122
120Variable
121ExprTuple122
122Variable