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, ExprTuple, Function, Lambda, f, i, n
from proveit.core_expr_types import a_i, v_i
from proveit.linear_algebra import ScalarMult, VecSum
from proveit.logic import Equals, Functions, 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 = [i]
sub_expr2 = Interval(one, n)
sub_expr3 = Qmult(Ket(v_i), Bra(v_i))
expr = ExprTuple(Lambda(f, Conditional(Equals(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)), InSet(f, Functions(Complex, Complex)))))
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 \mapsto \left\{f\left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right) = \left(\sum_{i=1}^{n} \left(f\left(a_{i}\right) \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right) \textrm{ if } f \in \left[\mathbb{C} \rightarrow \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
1Lambdaparameter: 33
body: 3
2ExprTuple33
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operands: 7
5Operationoperator: 31
operands: 8
6Literal
7ExprTuple9, 10
8ExprTuple33, 11
9Operationoperator: 33
operand: 16
10Operationoperator: 19
operand: 17
11Operationoperator: 14
operands: 15
12ExprTuple16
13ExprTuple17
14Literal
15ExprTuple18, 18
16Operationoperator: 19
operand: 22
17Lambdaparameter: 53
body: 21
18Literal
19Literal
20ExprTuple22
21Conditionalvalue: 23
condition: 27
22Lambdaparameter: 53
body: 24
23Operationoperator: 29
operands: 25
24Conditionalvalue: 26
condition: 27
25ExprTuple28, 35
26Operationoperator: 29
operands: 30
27Operationoperator: 31
operands: 32
28Operationoperator: 33
operand: 37
29Literal
30ExprTuple37, 35
31Literal
32ExprTuple53, 36
33Variable
34ExprTuple37
35Operationoperator: 38
operands: 39
36Operationoperator: 40
operands: 41
37IndexedVarvariable: 42
index: 53
38Literal
39ExprTuple43, 44
40Literal
41ExprTuple45, 46
42Variable
43Operationoperator: 47
operand: 50
44Operationoperator: 48
operand: 50
45Literal
46Variable
47Literal
48Literal
49ExprTuple50
50IndexedVarvariable: 51
index: 53
51Variable
52ExprTuple53
53Variable