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, Hspace, LinMap, OrthoNormBases, ScalarMult, VecSum, VecZero
from proveit.logic import And, 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 = LinMap(Hspace, Hspace)
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(Hspace))).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 \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}
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: 70
operands: 16
11Operationoperator: 40
operand: 24
12Operationoperator: 100
operands: 18
13Operationoperator: 100
operands: 19
14Operationoperator: 70
operands: 20
15Operationoperator: 70
operands: 21
16ExprTuple22, 23
17ExprTuple24
18ExprTuple74, 35
19ExprTuple76, 35
20ExprTuple25, 74
21ExprTuple26, 76
22Operationoperator: 27
operands: 28
23Operationoperator: 29
operand: 35
24Lambdaparameters: 49
body: 31
25Operationoperator: 33
operand: 74
26Operationoperator: 33
operand: 76
27Literal
28ExprTuple74, 76
29Literal
30ExprTuple35
31Conditionalvalue: 36
condition: 37
32ExprTuple74
33Literal
34ExprTuple76
35Operationoperator: 38
operands: 39
36Operationoperator: 40
operand: 43
37Operationoperator: 100
operands: 42
38Literal
39ExprTuple57, 57
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: 114
end_index: 115
53ExprRangelambda_map: 59
start_index: 114
end_index: 115
54Operationoperator: 61
operands: 60
55Operationoperator: 61
operands: 62
56ExprRangelambda_map: 63
start_index: 114
end_index: 115
57Variable
58Lambdaparameter: 96
body: 87
59Lambdaparameter: 96
body: 88
60ExprTuple64, 65
61Literal
62ExprTuple66, 67
63Lambdaparameter: 96
body: 68
64Operationoperator: 70
operands: 69
65Operationoperator: 70
operands: 71
66ExprRangelambda_map: 72
start_index: 114
end_index: 115
67ExprRangelambda_map: 73
start_index: 114
end_index: 115
68IndexedVarvariable: 120
index: 96
69ExprTuple74, 75
70Literal
71ExprTuple76, 77
72Lambdaparameter: 96
body: 78
73Lambdaparameter: 96
body: 79
74Variable
75Operationoperator: 81
operand: 85
76Variable
77Operationoperator: 81
operand: 86
78Operationoperator: 100
operands: 83
79Operationoperator: 100
operands: 84
80ExprTuple85
81Literal
82ExprTuple86
83ExprTuple87, 89
84ExprTuple88, 89
85Lambdaparameter: 122
body: 90
86Lambdaparameter: 122
body: 91
87IndexedVarvariable: 106
index: 96
88IndexedVarvariable: 107
index: 96
89Literal
90Conditionalvalue: 93
condition: 95
91Conditionalvalue: 94
condition: 95
92ExprTuple96
93Operationoperator: 98
operands: 97
94Operationoperator: 98
operands: 99
95Operationoperator: 100
operands: 101
96Variable
97ExprTuple102, 104
98Literal
99ExprTuple103, 104
100Literal
101ExprTuple122, 105
102IndexedVarvariable: 106
index: 122
103IndexedVarvariable: 107
index: 122
104Operationoperator: 108
operands: 109
105Operationoperator: 110
operands: 111
106Variable
107Variable
108Literal
109ExprTuple112, 113
110Literal
111ExprTuple114, 115
112Operationoperator: 116
operand: 119
113Operationoperator: 117
operand: 119
114Literal
115Variable
116Literal
117Literal
118ExprTuple119
119IndexedVarvariable: 120
index: 122
120Variable
121ExprTuple122
122Variable