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 ExprRange, IndexedVar, Variable, i, lambda_, m, n
from proveit.core_expr_types import a_1_to_m, a_i, b_1_to_n, b_i, lambda_i
from proveit.linear_algebra import OrthoNormBases, ScalarMult, TensorProd, VecSum
from proveit.logic import CartExp, Equals, Exists, Forall, InSet, Set
from proveit.numbers import Complex, Interval, Min, RealNonNeg, one
from proveit.physics.quantum import Ket, Qmult, var_ket_psi
from proveit.physics.quantum.algebra import a_1_to_m_kets, b_1_to_n_kets
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Min(m, n)
sub_expr3 = CartExp(Complex, n)
sub_expr4 = CartExp(Complex, m)
expr = Forall(instance_param_or_params = [var_ket_psi], instance_expr = Exists(instance_param_or_params = [a_1_to_m], instance_expr = Exists(instance_param_or_params = [b_1_to_n], instance_expr = Exists(instance_param_or_params = [ExprRange(sub_expr1, IndexedVar(lambda_, sub_expr1), one, sub_expr2)], instance_expr = Equals(var_ket_psi, VecSum(index_or_indices = [i], summand = ScalarMult(lambda_i, Qmult(Ket(a_i), Ket(b_i))), domain = Interval(one, sub_expr2))), domain = RealNonNeg).with_wrapping(), condition = InSet(Set(b_1_to_n_kets), OrthoNormBases(sub_expr3))).with_wrapping(), condition = InSet(Set(a_1_to_m_kets), OrthoNormBases(sub_expr4))).with_wrapping(), domain = TensorProd(sub_expr4, sub_expr3)).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_{\lvert \psi \rangle \in \mathbb{C}^{m} {\otimes} \mathbb{C}^{n}}~\\
\left[\begin{array}{l}\exists_{a_{1}, a_{2}, \ldots, a_{m}~|~\left\{\left\{\lvert a_{1} \rangle, \lvert a_{2} \rangle, \ldots, \lvert a_{m} \rangle\right\}\right\} \in \textrm{O.N.Bases}\left(\mathbb{C}^{m}\right)}~\\
\left[\begin{array}{l}\exists_{b_{1}, b_{2}, \ldots, b_{n}~|~\left\{\left\{\lvert b_{1} \rangle, \lvert b_{2} \rangle, \ldots, \lvert b_{n} \rangle\right\}\right\} \in \textrm{O.N.Bases}\left(\mathbb{C}^{n}\right)}~\\
\left[\begin{array}{l}\exists_{\lambda_{1}, \lambda_{2}, \ldots, \lambda_{{\rm Min}\left(m, n\right)} \in \mathbb{R}^{\ge 0}}~\\
\left(\lvert \psi \rangle = \left(\sum_{i=1}^{{\rm Min}\left(m, n\right)} \left(\lambda_{i} \cdot \left(\lvert a_{i} \rangle \thinspace \lvert b_{i} \rangle\right)\right)\right)\right)\end{array}\right]\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: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 66
body: 5
4ExprTuple66
5Conditionalvalue: 6
condition: 7
6Operationoperator: 35
operand: 10
7Operationoperator: 89
operands: 9
8ExprTuple10
9ExprTuple66, 11
10Lambdaparameters: 12
body: 13
11Operationoperator: 14
operands: 15
12ExprTuple16
13Conditionalvalue: 17
condition: 18
14Literal
15ExprTuple33, 54
16ExprRangelambda_map: 19
start_index: 103
end_index: 112
17Operationoperator: 35
operand: 22
18Operationoperator: 89
operands: 21
19Lambdaparameter: 95
body: 71
20ExprTuple22
21ExprTuple23, 24
22Lambdaparameters: 25
body: 26
23Operationoperator: 61
operand: 32
24Operationoperator: 47
operand: 33
25ExprTuple29
26Conditionalvalue: 30
condition: 31
27ExprTuple32
28ExprTuple33
29ExprRangelambda_map: 34
start_index: 103
end_index: 113
30Operationoperator: 35
operand: 40
31Operationoperator: 89
operands: 37
32Operationoperator: 61
operands: 38
33Operationoperator: 63
operands: 39
34Lambdaparameter: 95
body: 86
35Literal
36ExprTuple40
37ExprTuple41, 42
38ExprTuple43
39ExprTuple70, 112
40Lambdaparameters: 44
body: 45
41Operationoperator: 61
operand: 53
42Operationoperator: 47
operand: 54
43ExprRangelambda_map: 49
start_index: 103
end_index: 112
44ExprTuple50
45Conditionalvalue: 51
condition: 52
46ExprTuple53
47Literal
48ExprTuple54
49Lambdaparameter: 95
body: 55
50ExprRangelambda_map: 56
start_index: 103
end_index: 104
51Operationoperator: 57
operands: 58
52Operationoperator: 59
operands: 60
53Operationoperator: 61
operands: 62
54Operationoperator: 63
operands: 64
55Operationoperator: 106
operand: 71
56Lambdaparameter: 95
body: 84
57Literal
58ExprTuple66, 67
59Literal
60ExprTuple68
61Literal
62ExprTuple69
63Literal
64ExprTuple70, 113
65ExprTuple71
66Variable
67Operationoperator: 72
operand: 76
68ExprRangelambda_map: 74
start_index: 103
end_index: 104
69ExprRangelambda_map: 75
start_index: 103
end_index: 113
70Literal
71IndexedVarvariable: 114
index: 95
72Literal
73ExprTuple76
74Lambdaparameter: 95
body: 77
75Lambdaparameter: 95
body: 78
76Lambdaparameter: 117
body: 79
77Operationoperator: 89
operands: 80
78Operationoperator: 106
operand: 86
79Conditionalvalue: 82
condition: 83
80ExprTuple84, 85
81ExprTuple86
82Operationoperator: 87
operands: 88
83Operationoperator: 89
operands: 90
84IndexedVarvariable: 96
index: 95
85Literal
86IndexedVarvariable: 115
index: 95
87Literal
88ExprTuple92, 93
89Literal
90ExprTuple117, 94
91ExprTuple95
92IndexedVarvariable: 96
index: 117
93Operationoperator: 97
operands: 98
94Operationoperator: 99
operands: 100
95Variable
96Variable
97Literal
98ExprTuple101, 102
99Literal
100ExprTuple103, 104
101Operationoperator: 106
operand: 110
102Operationoperator: 106
operand: 111
103Literal
104Operationoperator: 108
operands: 109
105ExprTuple110
106Literal
107ExprTuple111
108Literal
109ExprTuple112, 113
110IndexedVarvariable: 114
index: 117
111IndexedVarvariable: 115
index: 117
112Variable
113Variable
114Variable
115Variable
116ExprTuple117
117Variable