logo

Expression of type Forall

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 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, 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 = 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()
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}{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}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameters: 28
body: 4
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operands: 8
6Operationoperator: 61
operands: 9
7Literal
8ExprTuple10, 11
9ExprTuple12, 13, 14, 15
10Operationoperator: 72
operands: 16
11Operationoperator: 40
operand: 24
12Operationoperator: 102
operands: 18
13Operationoperator: 102
operands: 19
14Operationoperator: 72
operands: 20
15Operationoperator: 72
operands: 21
16ExprTuple22, 23
17ExprTuple24
18ExprTuple76, 35
19ExprTuple78, 35
20ExprTuple25, 76
21ExprTuple26, 78
22Operationoperator: 27
operands: 28
23Operationoperator: 29
operand: 35
24Lambdaparameters: 49
body: 31
25Operationoperator: 33
operand: 76
26Operationoperator: 33
operand: 78
27Literal
28ExprTuple76, 78
29Literal
30ExprTuple35
31Conditionalvalue: 36
condition: 37
32ExprTuple76
33Literal
34ExprTuple78
35Operationoperator: 38
operands: 39
36Operationoperator: 40
operand: 43
37Operationoperator: 102
operands: 42
38Literal
39NamedExprsfield: 91
rows: 117
columns: 117
40Literal
41ExprTuple43
42ExprTuple44, 45
43Lambdaparameters: 46
body: 47
44Operationoperator: 48
operands: 49
45Operationoperator: 50
operand: 57
46ExprTuple52, 53
47Conditionalvalue: 54
condition: 55
48Literal
49ExprTuple56
50Literal
51ExprTuple57
52ExprRangelambda_map: 58
start_index: 116
end_index: 117
53ExprRangelambda_map: 59
start_index: 116
end_index: 117
54Operationoperator: 61
operands: 60
55Operationoperator: 61
operands: 62
56ExprRangelambda_map: 63
start_index: 116
end_index: 117
57Operationoperator: 64
operands: 65
58Lambdaparameter: 98
body: 89
59Lambdaparameter: 98
body: 90
60ExprTuple66, 67
61Literal
62ExprTuple68, 69
63Lambdaparameter: 98
body: 70
64Literal
65ExprTuple91, 117
66Operationoperator: 72
operands: 71
67Operationoperator: 72
operands: 73
68ExprRangelambda_map: 74
start_index: 116
end_index: 117
69ExprRangelambda_map: 75
start_index: 116
end_index: 117
70IndexedVarvariable: 122
index: 98
71ExprTuple76, 77
72Literal
73ExprTuple78, 79
74Lambdaparameter: 98
body: 80
75Lambdaparameter: 98
body: 81
76Variable
77Operationoperator: 83
operand: 87
78Variable
79Operationoperator: 83
operand: 88
80Operationoperator: 102
operands: 85
81Operationoperator: 102
operands: 86
82ExprTuple87
83Literal
84ExprTuple88
85ExprTuple89, 91
86ExprTuple90, 91
87Lambdaparameter: 124
body: 92
88Lambdaparameter: 124
body: 93
89IndexedVarvariable: 108
index: 98
90IndexedVarvariable: 109
index: 98
91Literal
92Conditionalvalue: 95
condition: 97
93Conditionalvalue: 96
condition: 97
94ExprTuple98
95Operationoperator: 100
operands: 99
96Operationoperator: 100
operands: 101
97Operationoperator: 102
operands: 103
98Variable
99ExprTuple104, 106
100Literal
101ExprTuple105, 106
102Literal
103ExprTuple124, 107
104IndexedVarvariable: 108
index: 124
105IndexedVarvariable: 109
index: 124
106Operationoperator: 110
operands: 111
107Operationoperator: 112
operands: 113
108Variable
109Variable
110Literal
111ExprTuple114, 115
112Literal
113ExprTuple116, 117
114Operationoperator: 118
operand: 121
115Operationoperator: 119
operand: 121
116Literal
117Variable
118Literal
119Literal
120ExprTuple121
121IndexedVarvariable: 122
index: 124
122Variable
123ExprTuple124
124Variable