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, 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 = ExprTuple(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())
\left(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..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameter: 136
body: 3
2ExprTuple136
3Conditionalvalue: 4
condition: 5
4Operationoperator: 13
operand: 8
5Operationoperator: 121
operands: 7
6ExprTuple8
7ExprTuple136, 9
8Lambdaparameter: 78
body: 10
9Literal
10Conditionalvalue: 11
condition: 12
11Operationoperator: 13
operand: 16
12Operationoperator: 82
operands: 15
13Literal
14ExprTuple16
15ExprTuple17, 18
16Lambdaparameters: 49
body: 19
17Operationoperator: 20
operands: 21
18Operationoperator: 91
operands: 22
19Conditionalvalue: 23
condition: 24
20Literal
21ExprTuple78, 25
22ExprTuple26, 136
23Operationoperator: 27
operands: 28
24Operationoperator: 82
operands: 29
25Literal
26Operationoperator: 30
operand: 78
27Literal
28ExprTuple31, 32
29ExprTuple33, 34, 35, 36
30Literal
31Operationoperator: 91
operands: 37
32Operationoperator: 61
operand: 45
33Operationoperator: 121
operands: 39
34Operationoperator: 121
operands: 40
35Operationoperator: 91
operands: 41
36Operationoperator: 91
operands: 42
37ExprTuple43, 44
38ExprTuple45
39ExprTuple95, 56
40ExprTuple97, 56
41ExprTuple46, 95
42ExprTuple47, 97
43Operationoperator: 48
operands: 49
44Operationoperator: 50
operand: 56
45Lambdaparameters: 70
body: 52
46Operationoperator: 54
operand: 95
47Operationoperator: 54
operand: 97
48Literal
49ExprTuple95, 97
50Literal
51ExprTuple56
52Conditionalvalue: 57
condition: 58
53ExprTuple95
54Literal
55ExprTuple97
56Operationoperator: 59
operands: 60
57Operationoperator: 61
operand: 64
58Operationoperator: 121
operands: 63
59Literal
60ExprTuple78, 78
61Literal
62ExprTuple64
63ExprTuple65, 66
64Lambdaparameters: 67
body: 68
65Operationoperator: 69
operands: 70
66Operationoperator: 71
operand: 78
67ExprTuple73, 74
68Conditionalvalue: 75
condition: 76
69Literal
70ExprTuple77
71Literal
72ExprTuple78
73ExprRangelambda_map: 79
start_index: 135
end_index: 136
74ExprRangelambda_map: 80
start_index: 135
end_index: 136
75Operationoperator: 82
operands: 81
76Operationoperator: 82
operands: 83
77ExprRangelambda_map: 84
start_index: 135
end_index: 136
78Variable
79Lambdaparameter: 117
body: 108
80Lambdaparameter: 117
body: 109
81ExprTuple85, 86
82Literal
83ExprTuple87, 88
84Lambdaparameter: 117
body: 89
85Operationoperator: 91
operands: 90
86Operationoperator: 91
operands: 92
87ExprRangelambda_map: 93
start_index: 135
end_index: 136
88ExprRangelambda_map: 94
start_index: 135
end_index: 136
89IndexedVarvariable: 141
index: 117
90ExprTuple95, 96
91Literal
92ExprTuple97, 98
93Lambdaparameter: 117
body: 99
94Lambdaparameter: 117
body: 100
95Variable
96Operationoperator: 102
operand: 106
97Variable
98Operationoperator: 102
operand: 107
99Operationoperator: 121
operands: 104
100Operationoperator: 121
operands: 105
101ExprTuple106
102Literal
103ExprTuple107
104ExprTuple108, 110
105ExprTuple109, 110
106Lambdaparameter: 143
body: 111
107Lambdaparameter: 143
body: 112
108IndexedVarvariable: 127
index: 117
109IndexedVarvariable: 128
index: 117
110Literal
111Conditionalvalue: 114
condition: 116
112Conditionalvalue: 115
condition: 116
113ExprTuple117
114Operationoperator: 119
operands: 118
115Operationoperator: 119
operands: 120
116Operationoperator: 121
operands: 122
117Variable
118ExprTuple123, 125
119Literal
120ExprTuple124, 125
121Literal
122ExprTuple143, 126
123IndexedVarvariable: 127
index: 143
124IndexedVarvariable: 128
index: 143
125Operationoperator: 129
operands: 130
126Operationoperator: 131
operands: 132
127Variable
128Variable
129Literal
130ExprTuple133, 134
131Literal
132ExprTuple135, 136
133Operationoperator: 137
operand: 140
134Operationoperator: 138
operand: 140
135Literal
136Variable
137Literal
138Literal
139ExprTuple140
140IndexedVarvariable: 141
index: 143
141Variable
142ExprTuple143
143Variable