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, 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 = MatrixSpace(field = Complex, rows = n, columns = n)
sub_expr3 = Interval(one, n)
sub_expr4 = Qmult(Ket(v_i), Bra(v_i))
expr = 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(CartExp(Complex, n)))).with_wrapping()).with_wrapping_at(2), domain = sub_expr2, conditions = [Equals(Adj(A), A), Equals(Adj(B), B)]).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\{\begin{array}{l}\forall_{A, B \in \mathbb{C}^{n \times n}~|~A^{\dagger} = A, B^{\dagger} = B}~\\
\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}\right)\end{array} \textrm{ if } n \in \mathbb{N}^+\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
operand: 6
2Operationoperator: 106
operands: 5
3Literal
4ExprTuple6
5ExprTuple121, 7
6Lambdaparameters: 32
body: 8
7Literal
8Conditionalvalue: 9
condition: 10
9Operationoperator: 11
operands: 12
10Operationoperator: 65
operands: 13
11Literal
12ExprTuple14, 15
13ExprTuple16, 17, 18, 19
14Operationoperator: 76
operands: 20
15Operationoperator: 44
operand: 28
16Operationoperator: 106
operands: 22
17Operationoperator: 106
operands: 23
18Operationoperator: 76
operands: 24
19Operationoperator: 76
operands: 25
20ExprTuple26, 27
21ExprTuple28
22ExprTuple80, 39
23ExprTuple82, 39
24ExprTuple29, 80
25ExprTuple30, 82
26Operationoperator: 31
operands: 32
27Operationoperator: 33
operand: 39
28Lambdaparameters: 53
body: 35
29Operationoperator: 37
operand: 80
30Operationoperator: 37
operand: 82
31Literal
32ExprTuple80, 82
33Literal
34ExprTuple39
35Conditionalvalue: 40
condition: 41
36ExprTuple80
37Literal
38ExprTuple82
39Operationoperator: 42
operands: 43
40Operationoperator: 44
operand: 47
41Operationoperator: 106
operands: 46
42Literal
43NamedExprsfield: 95
rows: 121
columns: 121
44Literal
45ExprTuple47
46ExprTuple48, 49
47Lambdaparameters: 50
body: 51
48Operationoperator: 52
operands: 53
49Operationoperator: 54
operand: 61
50ExprTuple56, 57
51Conditionalvalue: 58
condition: 59
52Literal
53ExprTuple60
54Literal
55ExprTuple61
56ExprRangelambda_map: 62
start_index: 120
end_index: 121
57ExprRangelambda_map: 63
start_index: 120
end_index: 121
58Operationoperator: 65
operands: 64
59Operationoperator: 65
operands: 66
60ExprRangelambda_map: 67
start_index: 120
end_index: 121
61Operationoperator: 68
operands: 69
62Lambdaparameter: 102
body: 93
63Lambdaparameter: 102
body: 94
64ExprTuple70, 71
65Literal
66ExprTuple72, 73
67Lambdaparameter: 102
body: 74
68Literal
69ExprTuple95, 121
70Operationoperator: 76
operands: 75
71Operationoperator: 76
operands: 77
72ExprRangelambda_map: 78
start_index: 120
end_index: 121
73ExprRangelambda_map: 79
start_index: 120
end_index: 121
74IndexedVarvariable: 126
index: 102
75ExprTuple80, 81
76Literal
77ExprTuple82, 83
78Lambdaparameter: 102
body: 84
79Lambdaparameter: 102
body: 85
80Variable
81Operationoperator: 87
operand: 91
82Variable
83Operationoperator: 87
operand: 92
84Operationoperator: 106
operands: 89
85Operationoperator: 106
operands: 90
86ExprTuple91
87Literal
88ExprTuple92
89ExprTuple93, 95
90ExprTuple94, 95
91Lambdaparameter: 128
body: 96
92Lambdaparameter: 128
body: 97
93IndexedVarvariable: 112
index: 102
94IndexedVarvariable: 113
index: 102
95Literal
96Conditionalvalue: 99
condition: 101
97Conditionalvalue: 100
condition: 101
98ExprTuple102
99Operationoperator: 104
operands: 103
100Operationoperator: 104
operands: 105
101Operationoperator: 106
operands: 107
102Variable
103ExprTuple108, 110
104Literal
105ExprTuple109, 110
106Literal
107ExprTuple128, 111
108IndexedVarvariable: 112
index: 128
109IndexedVarvariable: 113
index: 128
110Operationoperator: 114
operands: 115
111Operationoperator: 116
operands: 117
112Variable
113Variable
114Literal
115ExprTuple118, 119
116Literal
117ExprTuple120, 121
118Operationoperator: 122
operand: 125
119Operationoperator: 123
operand: 125
120Literal
121Variable
122Literal
123Literal
124ExprTuple125
125IndexedVarvariable: 126
index: 128
126Variable
127ExprTuple128
128Variable