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, InClass, 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 = LinMap(Hspace, Hspace)
sub_expr3 = Interval(one, n)
sub_expr4 = Qmult(Ket(v_i), Bra(v_i))
expr = Lambda(Hspace, Conditional(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(), And(InClass(Hspace, HilbertSpaces), Equals(Dim(Hspace), n))))
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())
\mathcal{H} \mapsto \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} \textrm{ if } \mathcal{H} \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces} ,  \textrm{Dim}\left(\mathcal{H}\right) = 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: 69
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 73
operands: 6
4Literal
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameters: 40
body: 10
8Operationoperator: 11
operands: 12
9Operationoperator: 82
operands: 13
10Conditionalvalue: 14
condition: 15
11Literal
12ExprTuple69, 16
13ExprTuple17, 127
14Operationoperator: 18
operands: 19
15Operationoperator: 73
operands: 20
16Literal
17Operationoperator: 21
operand: 69
18Literal
19ExprTuple22, 23
20ExprTuple24, 25, 26, 27
21Literal
22Operationoperator: 82
operands: 28
23Operationoperator: 52
operand: 36
24Operationoperator: 112
operands: 30
25Operationoperator: 112
operands: 31
26Operationoperator: 82
operands: 32
27Operationoperator: 82
operands: 33
28ExprTuple34, 35
29ExprTuple36
30ExprTuple86, 47
31ExprTuple88, 47
32ExprTuple37, 86
33ExprTuple38, 88
34Operationoperator: 39
operands: 40
35Operationoperator: 41
operand: 47
36Lambdaparameters: 61
body: 43
37Operationoperator: 45
operand: 86
38Operationoperator: 45
operand: 88
39Literal
40ExprTuple86, 88
41Literal
42ExprTuple47
43Conditionalvalue: 48
condition: 49
44ExprTuple86
45Literal
46ExprTuple88
47Operationoperator: 50
operands: 51
48Operationoperator: 52
operand: 55
49Operationoperator: 112
operands: 54
50Literal
51ExprTuple69, 69
52Literal
53ExprTuple55
54ExprTuple56, 57
55Lambdaparameters: 58
body: 59
56Operationoperator: 60
operands: 61
57Operationoperator: 62
operand: 69
58ExprTuple64, 65
59Conditionalvalue: 66
condition: 67
60Literal
61ExprTuple68
62Literal
63ExprTuple69
64ExprRangelambda_map: 70
start_index: 126
end_index: 127
65ExprRangelambda_map: 71
start_index: 126
end_index: 127
66Operationoperator: 73
operands: 72
67Operationoperator: 73
operands: 74
68ExprRangelambda_map: 75
start_index: 126
end_index: 127
69Variable
70Lambdaparameter: 108
body: 99
71Lambdaparameter: 108
body: 100
72ExprTuple76, 77
73Literal
74ExprTuple78, 79
75Lambdaparameter: 108
body: 80
76Operationoperator: 82
operands: 81
77Operationoperator: 82
operands: 83
78ExprRangelambda_map: 84
start_index: 126
end_index: 127
79ExprRangelambda_map: 85
start_index: 126
end_index: 127
80IndexedVarvariable: 132
index: 108
81ExprTuple86, 87
82Literal
83ExprTuple88, 89
84Lambdaparameter: 108
body: 90
85Lambdaparameter: 108
body: 91
86Variable
87Operationoperator: 93
operand: 97
88Variable
89Operationoperator: 93
operand: 98
90Operationoperator: 112
operands: 95
91Operationoperator: 112
operands: 96
92ExprTuple97
93Literal
94ExprTuple98
95ExprTuple99, 101
96ExprTuple100, 101
97Lambdaparameter: 134
body: 102
98Lambdaparameter: 134
body: 103
99IndexedVarvariable: 118
index: 108
100IndexedVarvariable: 119
index: 108
101Literal
102Conditionalvalue: 105
condition: 107
103Conditionalvalue: 106
condition: 107
104ExprTuple108
105Operationoperator: 110
operands: 109
106Operationoperator: 110
operands: 111
107Operationoperator: 112
operands: 113
108Variable
109ExprTuple114, 116
110Literal
111ExprTuple115, 116
112Literal
113ExprTuple134, 117
114IndexedVarvariable: 118
index: 134
115IndexedVarvariable: 119
index: 134
116Operationoperator: 120
operands: 121
117Operationoperator: 122
operands: 123
118Variable
119Variable
120Literal
121ExprTuple124, 125
122Literal
123ExprTuple126, 127
124Operationoperator: 128
operand: 131
125Operationoperator: 129
operand: 131
126Literal
127Variable
128Literal
129Literal
130ExprTuple131
131IndexedVarvariable: 132
index: 134
132Variable
133ExprTuple134
134Variable