logo

Expression of type Iff

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, 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 Commutator, Hspace, LinMap, OrthoNormBases, ScalarMult, VecSum, VecZero
from proveit.logic import And, 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 = Interval(one, n)
sub_expr3 = Qmult(Ket(v_i), Bra(v_i))
expr = Iff(Equals(Commutator(A, B), VecZero(LinMap(Hspace, Hspace))), 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_expr3), domain = sub_expr2)), Equals(B, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(b_i, sub_expr3), domain = sub_expr2))).with_wrapping_at(2), domain = Complex).with_wrapping(), condition = InSet(Set(v_1_to_n), OrthoNormBases(Hspace))).with_wrapping()).with_wrapping_at(2)
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())
\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}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()(2)('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 50
operands: 5
4Operationoperator: 20
operand: 9
5ExprTuple7, 8
6ExprTuple9
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operand: 15
9Lambdaparameters: 29
body: 14
10Literal
11ExprTuple54, 56
12Literal
13ExprTuple15
14Conditionalvalue: 16
condition: 17
15Operationoperator: 18
operands: 19
16Operationoperator: 20
operand: 23
17Operationoperator: 80
operands: 22
18Literal
19ExprTuple37, 37
20Literal
21ExprTuple23
22ExprTuple24, 25
23Lambdaparameters: 26
body: 27
24Operationoperator: 28
operands: 29
25Operationoperator: 30
operand: 37
26ExprTuple32, 33
27Conditionalvalue: 34
condition: 35
28Literal
29ExprTuple36
30Literal
31ExprTuple37
32ExprRangelambda_map: 38
start_index: 94
end_index: 95
33ExprRangelambda_map: 39
start_index: 94
end_index: 95
34Operationoperator: 41
operands: 40
35Operationoperator: 41
operands: 42
36ExprRangelambda_map: 43
start_index: 94
end_index: 95
37Variable
38Lambdaparameter: 76
body: 67
39Lambdaparameter: 76
body: 68
40ExprTuple44, 45
41Literal
42ExprTuple46, 47
43Lambdaparameter: 76
body: 48
44Operationoperator: 50
operands: 49
45Operationoperator: 50
operands: 51
46ExprRangelambda_map: 52
start_index: 94
end_index: 95
47ExprRangelambda_map: 53
start_index: 94
end_index: 95
48IndexedVarvariable: 100
index: 76
49ExprTuple54, 55
50Literal
51ExprTuple56, 57
52Lambdaparameter: 76
body: 58
53Lambdaparameter: 76
body: 59
54Variable
55Operationoperator: 61
operand: 65
56Variable
57Operationoperator: 61
operand: 66
58Operationoperator: 80
operands: 63
59Operationoperator: 80
operands: 64
60ExprTuple65
61Literal
62ExprTuple66
63ExprTuple67, 69
64ExprTuple68, 69
65Lambdaparameter: 102
body: 70
66Lambdaparameter: 102
body: 71
67IndexedVarvariable: 86
index: 76
68IndexedVarvariable: 87
index: 76
69Literal
70Conditionalvalue: 73
condition: 75
71Conditionalvalue: 74
condition: 75
72ExprTuple76
73Operationoperator: 78
operands: 77
74Operationoperator: 78
operands: 79
75Operationoperator: 80
operands: 81
76Variable
77ExprTuple82, 84
78Literal
79ExprTuple83, 84
80Literal
81ExprTuple102, 85
82IndexedVarvariable: 86
index: 102
83IndexedVarvariable: 87
index: 102
84Operationoperator: 88
operands: 89
85Operationoperator: 90
operands: 91
86Variable
87Variable
88Literal
89ExprTuple92, 93
90Literal
91ExprTuple94, 95
92Operationoperator: 96
operand: 99
93Operationoperator: 97
operand: 99
94Literal
95Variable
96Literal
97Literal
98ExprTuple99
99IndexedVarvariable: 100
index: 102
100Variable
101ExprTuple102
102Variable