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, 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 = [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()
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[\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}
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: 60
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 9
5Operationoperator: 64
operands: 8
6Literal
7ExprTuple9
8ExprTuple10, 11
9Lambdaparameter: 68
body: 12
10Operationoperator: 13
operands: 14
11Operationoperator: 62
operands: 15
12Conditionalvalue: 16
condition: 17
13Literal
14ExprTuple60, 18
15ExprTuple19, 104
16Operationoperator: 20
operands: 21
17Operationoperator: 89
operands: 22
18Literal
19Operationoperator: 23
operand: 60
20Literal
21ExprTuple24, 25
22ExprTuple68, 26
23Literal
24Operationoperator: 62
operands: 27
25Operationoperator: 45
operand: 33
26Operationoperator: 29
operands: 30
27ExprTuple31, 32
28ExprTuple33
29Literal
30ExprTuple60, 60
31Operationoperator: 97
operands: 34
32Operationoperator: 97
operands: 35
33Lambdaparameters: 36
body: 37
34ExprTuple38, 68
35ExprTuple68, 38
36ExprTuple39
37Conditionalvalue: 40
condition: 41
38Operationoperator: 42
operand: 68
39ExprRangelambda_map: 44
start_index: 103
end_index: 104
40Operationoperator: 45
operand: 48
41Operationoperator: 89
operands: 47
42Literal
43ExprTuple68
44Lambdaparameter: 95
body: 86
45Literal
46ExprTuple48
47ExprTuple49, 50
48Lambdaparameters: 51
body: 52
49Operationoperator: 66
operand: 59
50Operationoperator: 54
operand: 60
51ExprTuple56
52Conditionalvalue: 57
condition: 58
53ExprTuple59
54Literal
55ExprTuple60
56ExprRangelambda_map: 61
start_index: 103
end_index: 104
57Operationoperator: 62
operands: 63
58Operationoperator: 64
operands: 65
59Operationoperator: 66
operands: 67
60Variable
61Lambdaparameter: 95
body: 84
62Literal
63ExprTuple68, 69
64Literal
65ExprTuple70
66Literal
67ExprTuple71
68Variable
69Operationoperator: 72
operand: 76
70ExprRangelambda_map: 74
start_index: 103
end_index: 104
71ExprRangelambda_map: 75
start_index: 103
end_index: 104
72Literal
73ExprTuple76
74Lambdaparameter: 95
body: 77
75Lambdaparameter: 95
body: 78
76Lambdaparameter: 111
body: 79
77Operationoperator: 89
operands: 80
78Operationoperator: 105
operand: 86
79Conditionalvalue: 82
condition: 83
80ExprTuple84, 85
81ExprTuple86
82Operationoperator: 87
operands: 88
83Operationoperator: 89
operands: 90
84IndexedVarvariable: 96
index: 95
85Literal
86IndexedVarvariable: 109
index: 95
87Literal
88ExprTuple92, 93
89Literal
90ExprTuple111, 94
91ExprTuple95
92IndexedVarvariable: 96
index: 111
93Operationoperator: 97
operands: 98
94Operationoperator: 99
operands: 100
95Variable
96Variable
97Literal
98ExprTuple101, 102
99Literal
100ExprTuple103, 104
101Operationoperator: 105
operand: 108
102Operationoperator: 106
operand: 108
103Literal
104Variable
105Literal
106Literal
107ExprTuple108
108IndexedVarvariable: 109
index: 111
109Variable
110ExprTuple111
111Variable