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, 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 = Interval(one, n)
sub_expr3 = Qmult(Ket(v_i), Bra(v_i))
expr = Iff(Equals(Commutator(A, B), VecZero(MatrixSpace(field = Complex, rows = n, columns = n))), 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(CartExp(Complex, n)))).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(\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}
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: 52
operands: 5
4Operationoperator: 20
operand: 9
5ExprTuple7, 8
6ExprTuple9
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operand: 15
9Lambdaparameters: 29
body: 14
10Literal
11ExprTuple56, 58
12Literal
13ExprTuple15
14Conditionalvalue: 16
condition: 17
15Operationoperator: 18
operands: 19
16Operationoperator: 20
operand: 23
17Operationoperator: 82
operands: 22
18Literal
19NamedExprsfield: 71
rows: 97
columns: 97
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: 96
end_index: 97
33ExprRangelambda_map: 39
start_index: 96
end_index: 97
34Operationoperator: 41
operands: 40
35Operationoperator: 41
operands: 42
36ExprRangelambda_map: 43
start_index: 96
end_index: 97
37Operationoperator: 44
operands: 45
38Lambdaparameter: 78
body: 69
39Lambdaparameter: 78
body: 70
40ExprTuple46, 47
41Literal
42ExprTuple48, 49
43Lambdaparameter: 78
body: 50
44Literal
45ExprTuple71, 97
46Operationoperator: 52
operands: 51
47Operationoperator: 52
operands: 53
48ExprRangelambda_map: 54
start_index: 96
end_index: 97
49ExprRangelambda_map: 55
start_index: 96
end_index: 97
50IndexedVarvariable: 102
index: 78
51ExprTuple56, 57
52Literal
53ExprTuple58, 59
54Lambdaparameter: 78
body: 60
55Lambdaparameter: 78
body: 61
56Variable
57Operationoperator: 63
operand: 67
58Variable
59Operationoperator: 63
operand: 68
60Operationoperator: 82
operands: 65
61Operationoperator: 82
operands: 66
62ExprTuple67
63Literal
64ExprTuple68
65ExprTuple69, 71
66ExprTuple70, 71
67Lambdaparameter: 104
body: 72
68Lambdaparameter: 104
body: 73
69IndexedVarvariable: 88
index: 78
70IndexedVarvariable: 89
index: 78
71Literal
72Conditionalvalue: 75
condition: 77
73Conditionalvalue: 76
condition: 77
74ExprTuple78
75Operationoperator: 80
operands: 79
76Operationoperator: 80
operands: 81
77Operationoperator: 82
operands: 83
78Variable
79ExprTuple84, 86
80Literal
81ExprTuple85, 86
82Literal
83ExprTuple104, 87
84IndexedVarvariable: 88
index: 104
85IndexedVarvariable: 89
index: 104
86Operationoperator: 90
operands: 91
87Operationoperator: 92
operands: 93
88Variable
89Variable
90Literal
91ExprTuple94, 95
92Literal
93ExprTuple96, 97
94Operationoperator: 98
operand: 101
95Operationoperator: 99
operand: 101
96Literal
97Variable
98Literal
99Literal
100ExprTuple101
101IndexedVarvariable: 102
index: 104
102Variable
103ExprTuple104
104Variable