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 M, i, n
from proveit.core_expr_types import a_1_to_n, a_i, v_1_to_n, v_i
from proveit.linear_algebra import Adj, Dim, HilbertSpaces, Hspace, LinMap, OrthoNormBases, ScalarMult, VecSum
from proveit.logic import Equals, Exists, Forall, Iff, InSet, Set
from proveit.numbers import Complex, Interval, NaturalPos, one
from proveit.physics.quantum import Bra, Ket, Qmult
from proveit.physics.quantum.algebra import v_1_to_n_kets
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Adj(M)
expr = Forall(instance_param_or_params = [n], instance_expr = Forall(instance_param_or_params = [Hspace], instance_expr = Forall(instance_param_or_params = [M], instance_expr = Iff(Equals(Qmult(sub_expr1, M), Qmult(M, sub_expr1)), Exists(instance_param_or_params = [v_1_to_n], instance_expr = Exists(instance_param_or_params = [a_1_to_n], instance_expr = Equals(M, VecSum(index_or_indices = [i], summand = ScalarMult(a_i, Qmult(Ket(v_i), Bra(v_i))), domain = Interval(one, n))), domain = Complex).with_wrapping(), condition = InSet(Set(v_1_to_n_kets), OrthoNormBases(Hspace))).with_wrapping()).with_wrapping_at(2), domain = LinMap(Hspace, Hspace)), 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[\forall_{M \in \mathcal{L}\left(\mathcal{H}, \mathcal{H}\right)}~\left(\begin{array}{c} \begin{array}{l} \left(\left(M^{\dagger} \thinspace M\right) = \left(M \thinspace M^{\dagger}\right)\right) \Leftrightarrow  \\ \left[\begin{array}{l}\exists_{v_{1}, v_{2}, \ldots, v_{n}~|~\left\{\left\{\lvert v_{1} \rangle, \lvert v_{2} \rangle, \ldots, \lvert v_{n} \rangle\right\}\right\} \in \textrm{O.N.Bases}\left(\mathcal{H}\right)}~\\
\left[\begin{array}{l}\exists_{a_{1}, a_{2}, \ldots, a_{n} \in \mathbb{C}}~\\
\left(M = \left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right)\end{array}\right]\end{array}\right] \end{array} \end{array}\right)\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: 112
body: 4
3ExprTuple112
4Conditionalvalue: 5
condition: 6
5Operationoperator: 14
operand: 9
6Operationoperator: 97
operands: 8
7ExprTuple9
8ExprTuple112, 10
9Lambdaparameter: 68
body: 11
10Literal
11Conditionalvalue: 12
condition: 13
12Operationoperator: 14
operand: 17
13Operationoperator: 72
operands: 16
14Literal
15ExprTuple17
16ExprTuple18, 19
17Lambdaparameter: 76
body: 20
18Operationoperator: 21
operands: 22
19Operationoperator: 70
operands: 23
20Conditionalvalue: 24
condition: 25
21Literal
22ExprTuple68, 26
23ExprTuple27, 112
24Operationoperator: 28
operands: 29
25Operationoperator: 97
operands: 30
26Literal
27Operationoperator: 31
operand: 68
28Literal
29ExprTuple32, 33
30ExprTuple76, 34
31Literal
32Operationoperator: 70
operands: 35
33Operationoperator: 53
operand: 41
34Operationoperator: 37
operands: 38
35ExprTuple39, 40
36ExprTuple41
37Literal
38ExprTuple68, 68
39Operationoperator: 105
operands: 42
40Operationoperator: 105
operands: 43
41Lambdaparameters: 44
body: 45
42ExprTuple46, 76
43ExprTuple76, 46
44ExprTuple47
45Conditionalvalue: 48
condition: 49
46Operationoperator: 50
operand: 76
47ExprRangelambda_map: 52
start_index: 111
end_index: 112
48Operationoperator: 53
operand: 56
49Operationoperator: 97
operands: 55
50Literal
51ExprTuple76
52Lambdaparameter: 103
body: 94
53Literal
54ExprTuple56
55ExprTuple57, 58
56Lambdaparameters: 59
body: 60
57Operationoperator: 74
operand: 67
58Operationoperator: 62
operand: 68
59ExprTuple64
60Conditionalvalue: 65
condition: 66
61ExprTuple67
62Literal
63ExprTuple68
64ExprRangelambda_map: 69
start_index: 111
end_index: 112
65Operationoperator: 70
operands: 71
66Operationoperator: 72
operands: 73
67Operationoperator: 74
operands: 75
68Variable
69Lambdaparameter: 103
body: 92
70Literal
71ExprTuple76, 77
72Literal
73ExprTuple78
74Literal
75ExprTuple79
76Variable
77Operationoperator: 80
operand: 84
78ExprRangelambda_map: 82
start_index: 111
end_index: 112
79ExprRangelambda_map: 83
start_index: 111
end_index: 112
80Literal
81ExprTuple84
82Lambdaparameter: 103
body: 85
83Lambdaparameter: 103
body: 86
84Lambdaparameter: 119
body: 87
85Operationoperator: 97
operands: 88
86Operationoperator: 113
operand: 94
87Conditionalvalue: 90
condition: 91
88ExprTuple92, 93
89ExprTuple94
90Operationoperator: 95
operands: 96
91Operationoperator: 97
operands: 98
92IndexedVarvariable: 104
index: 103
93Literal
94IndexedVarvariable: 117
index: 103
95Literal
96ExprTuple100, 101
97Literal
98ExprTuple119, 102
99ExprTuple103
100IndexedVarvariable: 104
index: 119
101Operationoperator: 105
operands: 106
102Operationoperator: 107
operands: 108
103Variable
104Variable
105Literal
106ExprTuple109, 110
107Literal
108ExprTuple111, 112
109Operationoperator: 113
operand: 116
110Operationoperator: 114
operand: 116
111Literal
112Variable
113Literal
114Literal
115ExprTuple116
116IndexedVarvariable: 117
index: 119
117Variable
118ExprTuple119
119Variable