logo

Expression of type ExprTuple

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, ExprTuple, IndexedVar, Lambda, Variable, i, lambda_, m, n
from proveit.core_expr_types import a_i, b_i, lambda_i
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import And, Equals, InSet
from proveit.numbers import Interval, Min, RealNonNeg, one
from proveit.physics.quantum import Ket, Qmult, var_ket_psi
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(lambda_, sub_expr1)
sub_expr3 = Min(m, n)
expr = ExprTuple(Lambda([ExprRange(sub_expr1, sub_expr2, one, sub_expr3)], Conditional(Equals(var_ket_psi, VecSum(index_or_indices = [i], summand = ScalarMult(lambda_i, Qmult(Ket(a_i), Ket(b_i))), domain = Interval(one, sub_expr3))), And(ExprRange(sub_expr1, InSet(sub_expr2, RealNonNeg), one, 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(\left(\lambda_{1}, \lambda_{2}, \ldots, \lambda_{{\rm Min}\left(m, n\right)}\right) \mapsto \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) \textrm{ if } \left(\lambda_{1} \in \mathbb{R}^{\ge 0}\right) \land  \left(\lambda_{2} \in \mathbb{R}^{\ge 0}\right) \land  \ldots \land  \left(\lambda_{{\rm Min}\left(m, n\right)} \in \mathbb{R}^{\ge 0}\right)\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameters: 2
body: 3
2ExprTuple4
3Conditionalvalue: 5
condition: 6
4ExprRangelambda_map: 7
start_index: 42
end_index: 43
5Operationoperator: 8
operands: 9
6Operationoperator: 10
operands: 11
7Lambdaparameter: 34
body: 24
8Literal
9ExprTuple12, 13
10Literal
11ExprTuple14
12Variable
13Operationoperator: 15
operand: 18
14ExprRangelambda_map: 17
start_index: 42
end_index: 43
15Literal
16ExprTuple18
17Lambdaparameter: 34
body: 19
18Lambdaparameter: 56
body: 20
19Operationoperator: 28
operands: 21
20Conditionalvalue: 22
condition: 23
21ExprTuple24, 25
22Operationoperator: 26
operands: 27
23Operationoperator: 28
operands: 29
24IndexedVarvariable: 35
index: 34
25Literal
26Literal
27ExprTuple31, 32
28Literal
29ExprTuple56, 33
30ExprTuple34
31IndexedVarvariable: 35
index: 56
32Operationoperator: 36
operands: 37
33Operationoperator: 38
operands: 39
34Variable
35Variable
36Literal
37ExprTuple40, 41
38Literal
39ExprTuple42, 43
40Operationoperator: 45
operand: 49
41Operationoperator: 45
operand: 50
42Literal
43Operationoperator: 47
operands: 48
44ExprTuple49
45Literal
46ExprTuple50
47Literal
48ExprTuple51, 52
49IndexedVarvariable: 53
index: 56
50IndexedVarvariable: 54
index: 56
51Variable
52Variable
53Variable
54Variable
55ExprTuple56
56Variable