logo

Expression of type Conditional

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, 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 = 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\{\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()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operands: 4
2Operationoperator: 57
operands: 5
3Literal
4ExprTuple6, 7
5ExprTuple8, 9, 10, 11
6Operationoperator: 68
operands: 12
7Operationoperator: 36
operand: 20
8Operationoperator: 98
operands: 14
9Operationoperator: 98
operands: 15
10Operationoperator: 68
operands: 16
11Operationoperator: 68
operands: 17
12ExprTuple18, 19
13ExprTuple20
14ExprTuple72, 31
15ExprTuple74, 31
16ExprTuple21, 72
17ExprTuple22, 74
18Operationoperator: 23
operands: 24
19Operationoperator: 25
operand: 31
20Lambdaparameters: 45
body: 27
21Operationoperator: 29
operand: 72
22Operationoperator: 29
operand: 74
23Literal
24ExprTuple72, 74
25Literal
26ExprTuple31
27Conditionalvalue: 32
condition: 33
28ExprTuple72
29Literal
30ExprTuple74
31Operationoperator: 34
operands: 35
32Operationoperator: 36
operand: 39
33Operationoperator: 98
operands: 38
34Literal
35NamedExprsfield: 87
rows: 113
columns: 113
36Literal
37ExprTuple39
38ExprTuple40, 41
39Lambdaparameters: 42
body: 43
40Operationoperator: 44
operands: 45
41Operationoperator: 46
operand: 53
42ExprTuple48, 49
43Conditionalvalue: 50
condition: 51
44Literal
45ExprTuple52
46Literal
47ExprTuple53
48ExprRangelambda_map: 54
start_index: 112
end_index: 113
49ExprRangelambda_map: 55
start_index: 112
end_index: 113
50Operationoperator: 57
operands: 56
51Operationoperator: 57
operands: 58
52ExprRangelambda_map: 59
start_index: 112
end_index: 113
53Operationoperator: 60
operands: 61
54Lambdaparameter: 94
body: 85
55Lambdaparameter: 94
body: 86
56ExprTuple62, 63
57Literal
58ExprTuple64, 65
59Lambdaparameter: 94
body: 66
60Literal
61ExprTuple87, 113
62Operationoperator: 68
operands: 67
63Operationoperator: 68
operands: 69
64ExprRangelambda_map: 70
start_index: 112
end_index: 113
65ExprRangelambda_map: 71
start_index: 112
end_index: 113
66IndexedVarvariable: 118
index: 94
67ExprTuple72, 73
68Literal
69ExprTuple74, 75
70Lambdaparameter: 94
body: 76
71Lambdaparameter: 94
body: 77
72Variable
73Operationoperator: 79
operand: 83
74Variable
75Operationoperator: 79
operand: 84
76Operationoperator: 98
operands: 81
77Operationoperator: 98
operands: 82
78ExprTuple83
79Literal
80ExprTuple84
81ExprTuple85, 87
82ExprTuple86, 87
83Lambdaparameter: 120
body: 88
84Lambdaparameter: 120
body: 89
85IndexedVarvariable: 104
index: 94
86IndexedVarvariable: 105
index: 94
87Literal
88Conditionalvalue: 91
condition: 93
89Conditionalvalue: 92
condition: 93
90ExprTuple94
91Operationoperator: 96
operands: 95
92Operationoperator: 96
operands: 97
93Operationoperator: 98
operands: 99
94Variable
95ExprTuple100, 102
96Literal
97ExprTuple101, 102
98Literal
99ExprTuple120, 103
100IndexedVarvariable: 104
index: 120
101IndexedVarvariable: 105
index: 120
102Operationoperator: 106
operands: 107
103Operationoperator: 108
operands: 109
104Variable
105Variable
106Literal
107ExprTuple110, 111
108Literal
109ExprTuple112, 113
110Operationoperator: 114
operand: 117
111Operationoperator: 115
operand: 117
112Literal
113Variable
114Literal
115Literal
116ExprTuple117
117IndexedVarvariable: 118
index: 120
118Variable
119ExprTuple120
120Variable