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, M, Variable, a, i, n
from proveit.core_expr_types import a_1_to_n, a_i, v_i
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import And, Equals, InSet
from proveit.numbers import Complex, Interval, one
from proveit.physics.quantum import Bra, Ket, Qmult
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = ExprTuple(Lambda([a_1_to_n], Conditional(Equals(M, VecSum(index_or_indices = [i], summand = ScalarMult(a_i, Qmult(Ket(v_i), Bra(v_i))), domain = Interval(one, n))), And(ExprRange(sub_expr1, InSet(IndexedVar(a, sub_expr1), Complex), one, 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(\left(a_{1}, a_{2}, \ldots, a_{n}\right) \mapsto \left\{M = \left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right) \textrm{ if } \left(a_{1} \in \mathbb{C}\right) \land  \left(a_{2} \in \mathbb{C}\right) \land  \ldots \land  \left(a_{n} \in \mathbb{C}\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: 50
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
29ExprTuple50, 33
30ExprTuple34
31IndexedVarvariable: 35
index: 50
32Operationoperator: 36
operands: 37
33Operationoperator: 38
operands: 39
34Variable
35Variable
36Literal
37ExprTuple40, 41
38Literal
39ExprTuple42, 43
40Operationoperator: 44
operand: 47
41Operationoperator: 45
operand: 47
42Literal
43Variable
44Literal
45Literal
46ExprTuple47
47IndexedVarvariable: 48
index: 50
48Variable
49ExprTuple50
50Variable