logo

Expression of type Forall

from the theory of proveit.linear_algebra.inner_products

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, x_1_to_n, x_i
from proveit.linear_algebra import Adj, Commutator, Hspace, LinMap, OrthoNormBases, OrthoProj, ScalarMult, Span, VecSum, VecZero
from proveit.logic import And, Equals, Exists, Forall, Iff, InSet, Set
from proveit.numbers import Complex, Interval, one
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [i]
sub_expr2 = LinMap(Hspace, Hspace)
sub_expr3 = Interval(one, n)
sub_expr4 = OrthoProj(Hspace, Span(Set(x_i)))
expr = Forall(instance_param_or_params = [A, B], instance_expr = Iff(Equals(Commutator(A, B), VecZero(sub_expr2)), Exists(instance_param_or_params = [x_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(x_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_{x_{1}, x_{2}, \ldots, x_{n}~|~\left\{x_{1}, x_{2}, \ldots, x_{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 \textrm{OrthoProj}\left(\mathcal{H}, \textrm{Span}\left(\left\{x_{i}\right\}\right)\right)\right)\right)\right) \land  \\ \left(B = \left(\sum_{i=1}^{n} \left(b_{i} \cdot \textrm{OrthoProj}\left(\mathcal{H}, \textrm{Span}\left(\left\{x_{i}\right\}\right)\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: 59
operands: 9
7Literal
8ExprTuple10, 11
9ExprTuple12, 13, 14, 15
10Operationoperator: 68
operands: 16
11Operationoperator: 40
operand: 24
12Operationoperator: 98
operands: 18
13Operationoperator: 98
operands: 19
14Operationoperator: 68
operands: 20
15Operationoperator: 68
operands: 21
16ExprTuple22, 23
17ExprTuple24
18ExprTuple72, 35
19ExprTuple74, 35
20ExprTuple25, 72
21ExprTuple26, 74
22Operationoperator: 27
operands: 28
23Operationoperator: 29
operand: 35
24Lambdaparameters: 48
body: 31
25Operationoperator: 33
operand: 72
26Operationoperator: 33
operand: 74
27Literal
28ExprTuple72, 74
29Literal
30ExprTuple35
31Conditionalvalue: 36
condition: 37
32ExprTuple72
33Literal
34ExprTuple74
35Operationoperator: 38
operands: 39
36Operationoperator: 40
operand: 43
37Operationoperator: 98
operands: 42
38Literal
39ExprTuple110, 110
40Literal
41ExprTuple43
42ExprTuple44, 45
43Lambdaparameters: 46
body: 47
44Operationoperator: 117
operands: 48
45Operationoperator: 49
operand: 110
46ExprTuple51, 52
47Conditionalvalue: 53
condition: 54
48ExprTuple55
49Literal
50ExprTuple110
51ExprRangelambda_map: 56
start_index: 112
end_index: 113
52ExprRangelambda_map: 57
start_index: 112
end_index: 113
53Operationoperator: 59
operands: 58
54Operationoperator: 59
operands: 60
55ExprRangelambda_map: 61
start_index: 112
end_index: 113
56Lambdaparameter: 94
body: 85
57Lambdaparameter: 94
body: 86
58ExprTuple62, 63
59Literal
60ExprTuple64, 65
61Lambdaparameter: 94
body: 66
62Operationoperator: 68
operands: 67
63Operationoperator: 68
operands: 69
64ExprRangelambda_map: 70
start_index: 112
end_index: 113
65ExprRangelambda_map: 71
start_index: 112
end_index: 113
66IndexedVarvariable: 120
index: 94
67ExprTuple72, 73
68Literal
69ExprTuple74, 75
70Lambdaparameter: 94
body: 76
71Lambdaparameter: 94
body: 77
72Variable
73Operationoperator: 79
operand: 83
74Variable
75Operationoperator: 79
operand: 84
76Operationoperator: 98
operands: 81
77Operationoperator: 98
operands: 82
78ExprTuple83
79Literal
80ExprTuple84
81ExprTuple85, 87
82ExprTuple86, 87
83Lambdaparameter: 122
body: 88
84Lambdaparameter: 122
body: 89
85IndexedVarvariable: 104
index: 94
86IndexedVarvariable: 105
index: 94
87Literal
88Conditionalvalue: 91
condition: 93
89Conditionalvalue: 92
condition: 93
90ExprTuple94
91Operationoperator: 96
operands: 95
92Operationoperator: 96
operands: 97
93Operationoperator: 98
operands: 99
94Variable
95ExprTuple100, 102
96Literal
97ExprTuple101, 102
98Literal
99ExprTuple122, 103
100IndexedVarvariable: 104
index: 122
101IndexedVarvariable: 105
index: 122
102Operationoperator: 106
operands: 107
103Operationoperator: 108
operands: 109
104Variable
105Variable
106Literal
107ExprTuple110, 111
108Literal
109ExprTuple112, 113
110Variable
111Operationoperator: 114
operand: 116
112Literal
113Variable
114Literal
115ExprTuple116
116Operationoperator: 117
operand: 119
117Literal
118ExprTuple119
119IndexedVarvariable: 120
index: 122
120Variable
121ExprTuple122
122Variable