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, 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 = 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(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..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 25
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operands: 5
3Operationoperator: 58
operands: 6
4Literal
5ExprTuple7, 8
6ExprTuple9, 10, 11, 12
7Operationoperator: 69
operands: 13
8Operationoperator: 37
operand: 21
9Operationoperator: 99
operands: 15
10Operationoperator: 99
operands: 16
11Operationoperator: 69
operands: 17
12Operationoperator: 69
operands: 18
13ExprTuple19, 20
14ExprTuple21
15ExprTuple73, 32
16ExprTuple75, 32
17ExprTuple22, 73
18ExprTuple23, 75
19Operationoperator: 24
operands: 25
20Operationoperator: 26
operand: 32
21Lambdaparameters: 46
body: 28
22Operationoperator: 30
operand: 73
23Operationoperator: 30
operand: 75
24Literal
25ExprTuple73, 75
26Literal
27ExprTuple32
28Conditionalvalue: 33
condition: 34
29ExprTuple73
30Literal
31ExprTuple75
32Operationoperator: 35
operands: 36
33Operationoperator: 37
operand: 40
34Operationoperator: 99
operands: 39
35Literal
36NamedExprsfield: 88
rows: 114
columns: 114
37Literal
38ExprTuple40
39ExprTuple41, 42
40Lambdaparameters: 43
body: 44
41Operationoperator: 45
operands: 46
42Operationoperator: 47
operand: 54
43ExprTuple49, 50
44Conditionalvalue: 51
condition: 52
45Literal
46ExprTuple53
47Literal
48ExprTuple54
49ExprRangelambda_map: 55
start_index: 113
end_index: 114
50ExprRangelambda_map: 56
start_index: 113
end_index: 114
51Operationoperator: 58
operands: 57
52Operationoperator: 58
operands: 59
53ExprRangelambda_map: 60
start_index: 113
end_index: 114
54Operationoperator: 61
operands: 62
55Lambdaparameter: 95
body: 86
56Lambdaparameter: 95
body: 87
57ExprTuple63, 64
58Literal
59ExprTuple65, 66
60Lambdaparameter: 95
body: 67
61Literal
62ExprTuple88, 114
63Operationoperator: 69
operands: 68
64Operationoperator: 69
operands: 70
65ExprRangelambda_map: 71
start_index: 113
end_index: 114
66ExprRangelambda_map: 72
start_index: 113
end_index: 114
67IndexedVarvariable: 119
index: 95
68ExprTuple73, 74
69Literal
70ExprTuple75, 76
71Lambdaparameter: 95
body: 77
72Lambdaparameter: 95
body: 78
73Variable
74Operationoperator: 80
operand: 84
75Variable
76Operationoperator: 80
operand: 85
77Operationoperator: 99
operands: 82
78Operationoperator: 99
operands: 83
79ExprTuple84
80Literal
81ExprTuple85
82ExprTuple86, 88
83ExprTuple87, 88
84Lambdaparameter: 121
body: 89
85Lambdaparameter: 121
body: 90
86IndexedVarvariable: 105
index: 95
87IndexedVarvariable: 106
index: 95
88Literal
89Conditionalvalue: 92
condition: 94
90Conditionalvalue: 93
condition: 94
91ExprTuple95
92Operationoperator: 97
operands: 96
93Operationoperator: 97
operands: 98
94Operationoperator: 99
operands: 100
95Variable
96ExprTuple101, 103
97Literal
98ExprTuple102, 103
99Literal
100ExprTuple121, 104
101IndexedVarvariable: 105
index: 121
102IndexedVarvariable: 106
index: 121
103Operationoperator: 107
operands: 108
104Operationoperator: 109
operands: 110
105Variable
106Variable
107Literal
108ExprTuple111, 112
109Literal
110ExprTuple113, 114
111Operationoperator: 115
operand: 118
112Operationoperator: 116
operand: 118
113Literal
114Variable
115Literal
116Literal
117ExprTuple118
118IndexedVarvariable: 119
index: 121
119Variable
120ExprTuple121
121Variable