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, Dim, HilbertSpaces, 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 = [Hspace], instance_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(), domain = HilbertSpaces, condition = Equals(Dim(Hspace), n)).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_{\mathcal{H} \underset{{\scriptscriptstyle c}}{\in} \textrm{HilbertSpaces}~|~\textrm{Dim}\left(\mathcal{H}\right) = n}~\\
\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}\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: 6
operand: 2
1ExprTuple2
2Lambdaparameter: 71
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 9
5Operationoperator: 75
operands: 8
6Literal
7ExprTuple9
8ExprTuple10, 11
9Lambdaparameters: 42
body: 12
10Operationoperator: 13
operands: 14
11Operationoperator: 84
operands: 15
12Conditionalvalue: 16
condition: 17
13Literal
14ExprTuple71, 18
15ExprTuple19, 129
16Operationoperator: 20
operands: 21
17Operationoperator: 75
operands: 22
18Literal
19Operationoperator: 23
operand: 71
20Literal
21ExprTuple24, 25
22ExprTuple26, 27, 28, 29
23Literal
24Operationoperator: 84
operands: 30
25Operationoperator: 54
operand: 38
26Operationoperator: 114
operands: 32
27Operationoperator: 114
operands: 33
28Operationoperator: 84
operands: 34
29Operationoperator: 84
operands: 35
30ExprTuple36, 37
31ExprTuple38
32ExprTuple88, 49
33ExprTuple90, 49
34ExprTuple39, 88
35ExprTuple40, 90
36Operationoperator: 41
operands: 42
37Operationoperator: 43
operand: 49
38Lambdaparameters: 63
body: 45
39Operationoperator: 47
operand: 88
40Operationoperator: 47
operand: 90
41Literal
42ExprTuple88, 90
43Literal
44ExprTuple49
45Conditionalvalue: 50
condition: 51
46ExprTuple88
47Literal
48ExprTuple90
49Operationoperator: 52
operands: 53
50Operationoperator: 54
operand: 57
51Operationoperator: 114
operands: 56
52Literal
53ExprTuple71, 71
54Literal
55ExprTuple57
56ExprTuple58, 59
57Lambdaparameters: 60
body: 61
58Operationoperator: 62
operands: 63
59Operationoperator: 64
operand: 71
60ExprTuple66, 67
61Conditionalvalue: 68
condition: 69
62Literal
63ExprTuple70
64Literal
65ExprTuple71
66ExprRangelambda_map: 72
start_index: 128
end_index: 129
67ExprRangelambda_map: 73
start_index: 128
end_index: 129
68Operationoperator: 75
operands: 74
69Operationoperator: 75
operands: 76
70ExprRangelambda_map: 77
start_index: 128
end_index: 129
71Variable
72Lambdaparameter: 110
body: 101
73Lambdaparameter: 110
body: 102
74ExprTuple78, 79
75Literal
76ExprTuple80, 81
77Lambdaparameter: 110
body: 82
78Operationoperator: 84
operands: 83
79Operationoperator: 84
operands: 85
80ExprRangelambda_map: 86
start_index: 128
end_index: 129
81ExprRangelambda_map: 87
start_index: 128
end_index: 129
82IndexedVarvariable: 134
index: 110
83ExprTuple88, 89
84Literal
85ExprTuple90, 91
86Lambdaparameter: 110
body: 92
87Lambdaparameter: 110
body: 93
88Variable
89Operationoperator: 95
operand: 99
90Variable
91Operationoperator: 95
operand: 100
92Operationoperator: 114
operands: 97
93Operationoperator: 114
operands: 98
94ExprTuple99
95Literal
96ExprTuple100
97ExprTuple101, 103
98ExprTuple102, 103
99Lambdaparameter: 136
body: 104
100Lambdaparameter: 136
body: 105
101IndexedVarvariable: 120
index: 110
102IndexedVarvariable: 121
index: 110
103Literal
104Conditionalvalue: 107
condition: 109
105Conditionalvalue: 108
condition: 109
106ExprTuple110
107Operationoperator: 112
operands: 111
108Operationoperator: 112
operands: 113
109Operationoperator: 114
operands: 115
110Variable
111ExprTuple116, 118
112Literal
113ExprTuple117, 118
114Literal
115ExprTuple136, 119
116IndexedVarvariable: 120
index: 136
117IndexedVarvariable: 121
index: 136
118Operationoperator: 122
operands: 123
119Operationoperator: 124
operands: 125
120Variable
121Variable
122Literal
123ExprTuple126, 127
124Literal
125ExprTuple128, 129
126Operationoperator: 130
operand: 133
127Operationoperator: 131
operand: 133
128Literal
129Variable
130Literal
131Literal
132ExprTuple133
133IndexedVarvariable: 134
index: 136
134Variable
135ExprTuple136
136Variable