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, NaturalPos, 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 = [n], instance_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(), domain = NaturalPos)
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())
\forall_{n \in \mathbb{N}^+}~\left[\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}\right]
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('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: 14
operand: 2
1ExprTuple2
2Lambdaparameter: 137
body: 4
3ExprTuple137
4Conditionalvalue: 5
condition: 6
5Operationoperator: 14
operand: 9
6Operationoperator: 122
operands: 8
7ExprTuple9
8ExprTuple137, 10
9Lambdaparameter: 79
body: 11
10Literal
11Conditionalvalue: 12
condition: 13
12Operationoperator: 14
operand: 17
13Operationoperator: 83
operands: 16
14Literal
15ExprTuple17
16ExprTuple18, 19
17Lambdaparameters: 50
body: 20
18Operationoperator: 21
operands: 22
19Operationoperator: 92
operands: 23
20Conditionalvalue: 24
condition: 25
21Literal
22ExprTuple79, 26
23ExprTuple27, 137
24Operationoperator: 28
operands: 29
25Operationoperator: 83
operands: 30
26Literal
27Operationoperator: 31
operand: 79
28Literal
29ExprTuple32, 33
30ExprTuple34, 35, 36, 37
31Literal
32Operationoperator: 92
operands: 38
33Operationoperator: 62
operand: 46
34Operationoperator: 122
operands: 40
35Operationoperator: 122
operands: 41
36Operationoperator: 92
operands: 42
37Operationoperator: 92
operands: 43
38ExprTuple44, 45
39ExprTuple46
40ExprTuple96, 57
41ExprTuple98, 57
42ExprTuple47, 96
43ExprTuple48, 98
44Operationoperator: 49
operands: 50
45Operationoperator: 51
operand: 57
46Lambdaparameters: 71
body: 53
47Operationoperator: 55
operand: 96
48Operationoperator: 55
operand: 98
49Literal
50ExprTuple96, 98
51Literal
52ExprTuple57
53Conditionalvalue: 58
condition: 59
54ExprTuple96
55Literal
56ExprTuple98
57Operationoperator: 60
operands: 61
58Operationoperator: 62
operand: 65
59Operationoperator: 122
operands: 64
60Literal
61ExprTuple79, 79
62Literal
63ExprTuple65
64ExprTuple66, 67
65Lambdaparameters: 68
body: 69
66Operationoperator: 70
operands: 71
67Operationoperator: 72
operand: 79
68ExprTuple74, 75
69Conditionalvalue: 76
condition: 77
70Literal
71ExprTuple78
72Literal
73ExprTuple79
74ExprRangelambda_map: 80
start_index: 136
end_index: 137
75ExprRangelambda_map: 81
start_index: 136
end_index: 137
76Operationoperator: 83
operands: 82
77Operationoperator: 83
operands: 84
78ExprRangelambda_map: 85
start_index: 136
end_index: 137
79Variable
80Lambdaparameter: 118
body: 109
81Lambdaparameter: 118
body: 110
82ExprTuple86, 87
83Literal
84ExprTuple88, 89
85Lambdaparameter: 118
body: 90
86Operationoperator: 92
operands: 91
87Operationoperator: 92
operands: 93
88ExprRangelambda_map: 94
start_index: 136
end_index: 137
89ExprRangelambda_map: 95
start_index: 136
end_index: 137
90IndexedVarvariable: 142
index: 118
91ExprTuple96, 97
92Literal
93ExprTuple98, 99
94Lambdaparameter: 118
body: 100
95Lambdaparameter: 118
body: 101
96Variable
97Operationoperator: 103
operand: 107
98Variable
99Operationoperator: 103
operand: 108
100Operationoperator: 122
operands: 105
101Operationoperator: 122
operands: 106
102ExprTuple107
103Literal
104ExprTuple108
105ExprTuple109, 111
106ExprTuple110, 111
107Lambdaparameter: 144
body: 112
108Lambdaparameter: 144
body: 113
109IndexedVarvariable: 128
index: 118
110IndexedVarvariable: 129
index: 118
111Literal
112Conditionalvalue: 115
condition: 117
113Conditionalvalue: 116
condition: 117
114ExprTuple118
115Operationoperator: 120
operands: 119
116Operationoperator: 120
operands: 121
117Operationoperator: 122
operands: 123
118Variable
119ExprTuple124, 126
120Literal
121ExprTuple125, 126
122Literal
123ExprTuple144, 127
124IndexedVarvariable: 128
index: 144
125IndexedVarvariable: 129
index: 144
126Operationoperator: 130
operands: 131
127Operationoperator: 132
operands: 133
128Variable
129Variable
130Literal
131ExprTuple134, 135
132Literal
133ExprTuple136, 137
134Operationoperator: 138
operand: 141
135Operationoperator: 139
operand: 141
136Literal
137Variable
138Literal
139Literal
140ExprTuple141
141IndexedVarvariable: 142
index: 144
142Variable
143ExprTuple144
144Variable