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, 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 = 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\{\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..
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: 10
operand: 5
2Operationoperator: 118
operands: 4
3ExprTuple5
4ExprTuple133, 6
5Lambdaparameter: 75
body: 7
6Literal
7Conditionalvalue: 8
condition: 9
8Operationoperator: 10
operand: 13
9Operationoperator: 79
operands: 12
10Literal
11ExprTuple13
12ExprTuple14, 15
13Lambdaparameters: 46
body: 16
14Operationoperator: 17
operands: 18
15Operationoperator: 88
operands: 19
16Conditionalvalue: 20
condition: 21
17Literal
18ExprTuple75, 22
19ExprTuple23, 133
20Operationoperator: 24
operands: 25
21Operationoperator: 79
operands: 26
22Literal
23Operationoperator: 27
operand: 75
24Literal
25ExprTuple28, 29
26ExprTuple30, 31, 32, 33
27Literal
28Operationoperator: 88
operands: 34
29Operationoperator: 58
operand: 42
30Operationoperator: 118
operands: 36
31Operationoperator: 118
operands: 37
32Operationoperator: 88
operands: 38
33Operationoperator: 88
operands: 39
34ExprTuple40, 41
35ExprTuple42
36ExprTuple92, 53
37ExprTuple94, 53
38ExprTuple43, 92
39ExprTuple44, 94
40Operationoperator: 45
operands: 46
41Operationoperator: 47
operand: 53
42Lambdaparameters: 67
body: 49
43Operationoperator: 51
operand: 92
44Operationoperator: 51
operand: 94
45Literal
46ExprTuple92, 94
47Literal
48ExprTuple53
49Conditionalvalue: 54
condition: 55
50ExprTuple92
51Literal
52ExprTuple94
53Operationoperator: 56
operands: 57
54Operationoperator: 58
operand: 61
55Operationoperator: 118
operands: 60
56Literal
57ExprTuple75, 75
58Literal
59ExprTuple61
60ExprTuple62, 63
61Lambdaparameters: 64
body: 65
62Operationoperator: 66
operands: 67
63Operationoperator: 68
operand: 75
64ExprTuple70, 71
65Conditionalvalue: 72
condition: 73
66Literal
67ExprTuple74
68Literal
69ExprTuple75
70ExprRangelambda_map: 76
start_index: 132
end_index: 133
71ExprRangelambda_map: 77
start_index: 132
end_index: 133
72Operationoperator: 79
operands: 78
73Operationoperator: 79
operands: 80
74ExprRangelambda_map: 81
start_index: 132
end_index: 133
75Variable
76Lambdaparameter: 114
body: 105
77Lambdaparameter: 114
body: 106
78ExprTuple82, 83
79Literal
80ExprTuple84, 85
81Lambdaparameter: 114
body: 86
82Operationoperator: 88
operands: 87
83Operationoperator: 88
operands: 89
84ExprRangelambda_map: 90
start_index: 132
end_index: 133
85ExprRangelambda_map: 91
start_index: 132
end_index: 133
86IndexedVarvariable: 138
index: 114
87ExprTuple92, 93
88Literal
89ExprTuple94, 95
90Lambdaparameter: 114
body: 96
91Lambdaparameter: 114
body: 97
92Variable
93Operationoperator: 99
operand: 103
94Variable
95Operationoperator: 99
operand: 104
96Operationoperator: 118
operands: 101
97Operationoperator: 118
operands: 102
98ExprTuple103
99Literal
100ExprTuple104
101ExprTuple105, 107
102ExprTuple106, 107
103Lambdaparameter: 140
body: 108
104Lambdaparameter: 140
body: 109
105IndexedVarvariable: 124
index: 114
106IndexedVarvariable: 125
index: 114
107Literal
108Conditionalvalue: 111
condition: 113
109Conditionalvalue: 112
condition: 113
110ExprTuple114
111Operationoperator: 116
operands: 115
112Operationoperator: 116
operands: 117
113Operationoperator: 118
operands: 119
114Variable
115ExprTuple120, 122
116Literal
117ExprTuple121, 122
118Literal
119ExprTuple140, 123
120IndexedVarvariable: 124
index: 140
121IndexedVarvariable: 125
index: 140
122Operationoperator: 126
operands: 127
123Operationoperator: 128
operands: 129
124Variable
125Variable
126Literal
127ExprTuple130, 131
128Literal
129ExprTuple132, 133
130Operationoperator: 134
operand: 137
131Operationoperator: 135
operand: 137
132Literal
133Variable
134Literal
135Literal
136ExprTuple137
137IndexedVarvariable: 138
index: 140
138Variable
139ExprTuple140
140Variable