logo

Expression of type Conditional

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 Conditional, 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 And, CartExp, Equals, Exists, Forall, InSet, Set
from proveit.numbers import Complex, Interval, Min, NaturalPos, 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 = Conditional(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(), And(InSet(m, NaturalPos), InSet(n, 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())
\left\{\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} \textrm{ if } m \in \mathbb{N}^+ ,  n \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operand: 6
2Operationoperator: 67
operands: 5
3Literal
4ExprTuple6
5ExprTuple7, 8
6Lambdaparameter: 74
body: 10
7Operationoperator: 97
operands: 11
8Operationoperator: 97
operands: 12
9ExprTuple74
10Conditionalvalue: 13
condition: 14
11ExprTuple120, 15
12ExprTuple121, 15
13Operationoperator: 43
operand: 18
14Operationoperator: 97
operands: 17
15Literal
16ExprTuple18
17ExprTuple74, 19
18Lambdaparameters: 20
body: 21
19Operationoperator: 22
operands: 23
20ExprTuple24
21Conditionalvalue: 25
condition: 26
22Literal
23ExprTuple41, 62
24ExprRangelambda_map: 27
start_index: 111
end_index: 120
25Operationoperator: 43
operand: 30
26Operationoperator: 97
operands: 29
27Lambdaparameter: 103
body: 79
28ExprTuple30
29ExprTuple31, 32
30Lambdaparameters: 33
body: 34
31Operationoperator: 69
operand: 40
32Operationoperator: 55
operand: 41
33ExprTuple37
34Conditionalvalue: 38
condition: 39
35ExprTuple40
36ExprTuple41
37ExprRangelambda_map: 42
start_index: 111
end_index: 121
38Operationoperator: 43
operand: 48
39Operationoperator: 97
operands: 45
40Operationoperator: 69
operands: 46
41Operationoperator: 71
operands: 47
42Lambdaparameter: 103
body: 94
43Literal
44ExprTuple48
45ExprTuple49, 50
46ExprTuple51
47ExprTuple78, 120
48Lambdaparameters: 52
body: 53
49Operationoperator: 69
operand: 61
50Operationoperator: 55
operand: 62
51ExprRangelambda_map: 57
start_index: 111
end_index: 120
52ExprTuple58
53Conditionalvalue: 59
condition: 60
54ExprTuple61
55Literal
56ExprTuple62
57Lambdaparameter: 103
body: 63
58ExprRangelambda_map: 64
start_index: 111
end_index: 112
59Operationoperator: 65
operands: 66
60Operationoperator: 67
operands: 68
61Operationoperator: 69
operands: 70
62Operationoperator: 71
operands: 72
63Operationoperator: 114
operand: 79
64Lambdaparameter: 103
body: 92
65Literal
66ExprTuple74, 75
67Literal
68ExprTuple76
69Literal
70ExprTuple77
71Literal
72ExprTuple78, 121
73ExprTuple79
74Variable
75Operationoperator: 80
operand: 84
76ExprRangelambda_map: 82
start_index: 111
end_index: 112
77ExprRangelambda_map: 83
start_index: 111
end_index: 121
78Literal
79IndexedVarvariable: 122
index: 103
80Literal
81ExprTuple84
82Lambdaparameter: 103
body: 85
83Lambdaparameter: 103
body: 86
84Lambdaparameter: 125
body: 87
85Operationoperator: 97
operands: 88
86Operationoperator: 114
operand: 94
87Conditionalvalue: 90
condition: 91
88ExprTuple92, 93
89ExprTuple94
90Operationoperator: 95
operands: 96
91Operationoperator: 97
operands: 98
92IndexedVarvariable: 104
index: 103
93Literal
94IndexedVarvariable: 123
index: 103
95Literal
96ExprTuple100, 101
97Literal
98ExprTuple125, 102
99ExprTuple103
100IndexedVarvariable: 104
index: 125
101Operationoperator: 105
operands: 106
102Operationoperator: 107
operands: 108
103Variable
104Variable
105Literal
106ExprTuple109, 110
107Literal
108ExprTuple111, 112
109Operationoperator: 114
operand: 118
110Operationoperator: 114
operand: 119
111Literal
112Operationoperator: 116
operands: 117
113ExprTuple118
114Literal
115ExprTuple119
116Literal
117ExprTuple120, 121
118IndexedVarvariable: 122
index: 125
119IndexedVarvariable: 123
index: 125
120Variable
121Variable
122Variable
123Variable
124ExprTuple125
125Variable