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, 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 = 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())
\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()
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: 72
operands: 5
3Literal
4ExprTuple6
5ExprTuple7, 8
6Lambdaparameters: 39
body: 9
7Operationoperator: 10
operands: 11
8Operationoperator: 81
operands: 12
9Conditionalvalue: 13
condition: 14
10Literal
11ExprTuple68, 15
12ExprTuple16, 126
13Operationoperator: 17
operands: 18
14Operationoperator: 72
operands: 19
15Literal
16Operationoperator: 20
operand: 68
17Literal
18ExprTuple21, 22
19ExprTuple23, 24, 25, 26
20Literal
21Operationoperator: 81
operands: 27
22Operationoperator: 51
operand: 35
23Operationoperator: 111
operands: 29
24Operationoperator: 111
operands: 30
25Operationoperator: 81
operands: 31
26Operationoperator: 81
operands: 32
27ExprTuple33, 34
28ExprTuple35
29ExprTuple85, 46
30ExprTuple87, 46
31ExprTuple36, 85
32ExprTuple37, 87
33Operationoperator: 38
operands: 39
34Operationoperator: 40
operand: 46
35Lambdaparameters: 60
body: 42
36Operationoperator: 44
operand: 85
37Operationoperator: 44
operand: 87
38Literal
39ExprTuple85, 87
40Literal
41ExprTuple46
42Conditionalvalue: 47
condition: 48
43ExprTuple85
44Literal
45ExprTuple87
46Operationoperator: 49
operands: 50
47Operationoperator: 51
operand: 54
48Operationoperator: 111
operands: 53
49Literal
50ExprTuple68, 68
51Literal
52ExprTuple54
53ExprTuple55, 56
54Lambdaparameters: 57
body: 58
55Operationoperator: 59
operands: 60
56Operationoperator: 61
operand: 68
57ExprTuple63, 64
58Conditionalvalue: 65
condition: 66
59Literal
60ExprTuple67
61Literal
62ExprTuple68
63ExprRangelambda_map: 69
start_index: 125
end_index: 126
64ExprRangelambda_map: 70
start_index: 125
end_index: 126
65Operationoperator: 72
operands: 71
66Operationoperator: 72
operands: 73
67ExprRangelambda_map: 74
start_index: 125
end_index: 126
68Variable
69Lambdaparameter: 107
body: 98
70Lambdaparameter: 107
body: 99
71ExprTuple75, 76
72Literal
73ExprTuple77, 78
74Lambdaparameter: 107
body: 79
75Operationoperator: 81
operands: 80
76Operationoperator: 81
operands: 82
77ExprRangelambda_map: 83
start_index: 125
end_index: 126
78ExprRangelambda_map: 84
start_index: 125
end_index: 126
79IndexedVarvariable: 131
index: 107
80ExprTuple85, 86
81Literal
82ExprTuple87, 88
83Lambdaparameter: 107
body: 89
84Lambdaparameter: 107
body: 90
85Variable
86Operationoperator: 92
operand: 96
87Variable
88Operationoperator: 92
operand: 97
89Operationoperator: 111
operands: 94
90Operationoperator: 111
operands: 95
91ExprTuple96
92Literal
93ExprTuple97
94ExprTuple98, 100
95ExprTuple99, 100
96Lambdaparameter: 133
body: 101
97Lambdaparameter: 133
body: 102
98IndexedVarvariable: 117
index: 107
99IndexedVarvariable: 118
index: 107
100Literal
101Conditionalvalue: 104
condition: 106
102Conditionalvalue: 105
condition: 106
103ExprTuple107
104Operationoperator: 109
operands: 108
105Operationoperator: 109
operands: 110
106Operationoperator: 111
operands: 112
107Variable
108ExprTuple113, 115
109Literal
110ExprTuple114, 115
111Literal
112ExprTuple133, 116
113IndexedVarvariable: 117
index: 133
114IndexedVarvariable: 118
index: 133
115Operationoperator: 119
operands: 120
116Operationoperator: 121
operands: 122
117Variable
118Variable
119Literal
120ExprTuple123, 124
121Literal
122ExprTuple125, 126
123Operationoperator: 127
operand: 130
124Operationoperator: 128
operand: 130
125Literal
126Variable
127Literal
128Literal
129ExprTuple130
130IndexedVarvariable: 131
index: 133
131Variable
132ExprTuple133
133Variable