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 ExprTuple, Function, f, i, n
from proveit.core_expr_types import a_i, v_i
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.numbers import Interval, one
from proveit.physics.quantum import Bra, Ket, Qmult
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [i]
sub_expr2 = Interval(one, n)
sub_expr3 = Qmult(Ket(v_i), Bra(v_i))
expr = ExprTuple(Function(f, [VecSum(index_or_indices = sub_expr1, summand = ScalarMult(a_i, sub_expr3), domain = sub_expr2)]), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(Function(f, [a_i]), sub_expr3), domain = sub_expr2))
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(f\left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right), \sum_{i=1}^{n} \left(f\left(a_{i}\right) \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1Operationoperator: 21
operand: 5
2Operationoperator: 7
operand: 6
3ExprTuple5
4ExprTuple6
5Operationoperator: 7
operand: 10
6Lambdaparameter: 41
body: 9
7Literal
8ExprTuple10
9Conditionalvalue: 11
condition: 15
10Lambdaparameter: 41
body: 12
11Operationoperator: 17
operands: 13
12Conditionalvalue: 14
condition: 15
13ExprTuple16, 23
14Operationoperator: 17
operands: 18
15Operationoperator: 19
operands: 20
16Operationoperator: 21
operand: 25
17Literal
18ExprTuple25, 23
19Literal
20ExprTuple41, 24
21Variable
22ExprTuple25
23Operationoperator: 26
operands: 27
24Operationoperator: 28
operands: 29
25IndexedVarvariable: 30
index: 41
26Literal
27ExprTuple31, 32
28Literal
29ExprTuple33, 34
30Variable
31Operationoperator: 35
operand: 38
32Operationoperator: 36
operand: 38
33Literal
34Variable
35Literal
36Literal
37ExprTuple38
38IndexedVarvariable: 39
index: 41
39Variable
40ExprTuple41
41Variable