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_i, b_i, lambda_i
from proveit.linear_algebra import OrthoNormBases, ScalarMult, 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 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)
expr = Conditional(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(), InSet(Set(b_1_to_n_kets), OrthoNormBases(CartExp(Complex, n))))
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_{\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} \textrm{ if } \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)\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: 50
operands: 5
3Literal
4ExprTuple6
5ExprTuple7, 8
6Lambdaparameters: 9
body: 10
7Operationoperator: 24
operand: 17
8Operationoperator: 12
operand: 18
9ExprTuple14
10Conditionalvalue: 15
condition: 16
11ExprTuple17
12Literal
13ExprTuple18
14ExprRangelambda_map: 19
start_index: 64
end_index: 65
15Operationoperator: 20
operands: 21
16Operationoperator: 22
operands: 23
17Operationoperator: 24
operands: 25
18Operationoperator: 26
operands: 27
19Lambdaparameter: 56
body: 45
20Literal
21ExprTuple28, 29
22Literal
23ExprTuple30
24Literal
25ExprTuple31
26Literal
27ExprTuple32, 74
28Variable
29Operationoperator: 33
operand: 37
30ExprRangelambda_map: 35
start_index: 64
end_index: 65
31ExprRangelambda_map: 36
start_index: 64
end_index: 74
32Literal
33Literal
34ExprTuple37
35Lambdaparameter: 56
body: 38
36Lambdaparameter: 56
body: 39
37Lambdaparameter: 78
body: 40
38Operationoperator: 50
operands: 41
39Operationoperator: 67
operand: 47
40Conditionalvalue: 43
condition: 44
41ExprTuple45, 46
42ExprTuple47
43Operationoperator: 48
operands: 49
44Operationoperator: 50
operands: 51
45IndexedVarvariable: 57
index: 56
46Literal
47IndexedVarvariable: 76
index: 56
48Literal
49ExprTuple53, 54
50Literal
51ExprTuple78, 55
52ExprTuple56
53IndexedVarvariable: 57
index: 78
54Operationoperator: 58
operands: 59
55Operationoperator: 60
operands: 61
56Variable
57Variable
58Literal
59ExprTuple62, 63
60Literal
61ExprTuple64, 65
62Operationoperator: 67
operand: 71
63Operationoperator: 67
operand: 72
64Literal
65Operationoperator: 69
operands: 70
66ExprTuple71
67Literal
68ExprTuple72
69Literal
70ExprTuple73, 74
71IndexedVarvariable: 75
index: 78
72IndexedVarvariable: 76
index: 78
73Variable
74Variable
75Variable
76Variable
77ExprTuple78
78Variable