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 CartExp, Equals, Exists, 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 = Conditional(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(), InSet(var_ket_psi, TensorProd(sub_expr4, sub_expr3)))
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}\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} \textrm{ if } \lvert \psi \rangle \in \left(\mathbb{C}^{m} {\otimes} \mathbb{C}^{n}\right)\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: 30
operand: 5
2Operationoperator: 84
operands: 4
3ExprTuple5
4ExprTuple61, 6
5Lambdaparameters: 7
body: 8
6Operationoperator: 9
operands: 10
7ExprTuple11
8Conditionalvalue: 12
condition: 13
9Literal
10ExprTuple28, 49
11ExprRangelambda_map: 14
start_index: 98
end_index: 107
12Operationoperator: 30
operand: 17
13Operationoperator: 84
operands: 16
14Lambdaparameter: 90
body: 66
15ExprTuple17
16ExprTuple18, 19
17Lambdaparameters: 20
body: 21
18Operationoperator: 56
operand: 27
19Operationoperator: 42
operand: 28
20ExprTuple24
21Conditionalvalue: 25
condition: 26
22ExprTuple27
23ExprTuple28
24ExprRangelambda_map: 29
start_index: 98
end_index: 108
25Operationoperator: 30
operand: 35
26Operationoperator: 84
operands: 32
27Operationoperator: 56
operands: 33
28Operationoperator: 58
operands: 34
29Lambdaparameter: 90
body: 81
30Literal
31ExprTuple35
32ExprTuple36, 37
33ExprTuple38
34ExprTuple65, 107
35Lambdaparameters: 39
body: 40
36Operationoperator: 56
operand: 48
37Operationoperator: 42
operand: 49
38ExprRangelambda_map: 44
start_index: 98
end_index: 107
39ExprTuple45
40Conditionalvalue: 46
condition: 47
41ExprTuple48
42Literal
43ExprTuple49
44Lambdaparameter: 90
body: 50
45ExprRangelambda_map: 51
start_index: 98
end_index: 99
46Operationoperator: 52
operands: 53
47Operationoperator: 54
operands: 55
48Operationoperator: 56
operands: 57
49Operationoperator: 58
operands: 59
50Operationoperator: 101
operand: 66
51Lambdaparameter: 90
body: 79
52Literal
53ExprTuple61, 62
54Literal
55ExprTuple63
56Literal
57ExprTuple64
58Literal
59ExprTuple65, 108
60ExprTuple66
61Variable
62Operationoperator: 67
operand: 71
63ExprRangelambda_map: 69
start_index: 98
end_index: 99
64ExprRangelambda_map: 70
start_index: 98
end_index: 108
65Literal
66IndexedVarvariable: 109
index: 90
67Literal
68ExprTuple71
69Lambdaparameter: 90
body: 72
70Lambdaparameter: 90
body: 73
71Lambdaparameter: 112
body: 74
72Operationoperator: 84
operands: 75
73Operationoperator: 101
operand: 81
74Conditionalvalue: 77
condition: 78
75ExprTuple79, 80
76ExprTuple81
77Operationoperator: 82
operands: 83
78Operationoperator: 84
operands: 85
79IndexedVarvariable: 91
index: 90
80Literal
81IndexedVarvariable: 110
index: 90
82Literal
83ExprTuple87, 88
84Literal
85ExprTuple112, 89
86ExprTuple90
87IndexedVarvariable: 91
index: 112
88Operationoperator: 92
operands: 93
89Operationoperator: 94
operands: 95
90Variable
91Variable
92Literal
93ExprTuple96, 97
94Literal
95ExprTuple98, 99
96Operationoperator: 101
operand: 105
97Operationoperator: 101
operand: 106
98Literal
99Operationoperator: 103
operands: 104
100ExprTuple105
101Literal
102ExprTuple106
103Literal
104ExprTuple107, 108
105IndexedVarvariable: 109
index: 112
106IndexedVarvariable: 110
index: 112
107Variable
108Variable
109Variable
110Variable
111ExprTuple112
112Variable