logo

Expression of type Function

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 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
expr = Function(f, [VecSum(index_or_indices = [i], summand = ScalarMult(a_i, Qmult(Ket(v_i), Bra(v_i))), domain = Interval(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())
f\left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\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
0Operationoperator: 1
operand: 3
1Variable
2ExprTuple3
3Operationoperator: 4
operand: 6
4Literal
5ExprTuple6
6Lambdaparameter: 32
body: 7
7Conditionalvalue: 8
condition: 9
8Operationoperator: 10
operands: 11
9Operationoperator: 12
operands: 13
10Literal
11ExprTuple14, 15
12Literal
13ExprTuple32, 16
14IndexedVarvariable: 17
index: 32
15Operationoperator: 18
operands: 19
16Operationoperator: 20
operands: 21
17Variable
18Literal
19ExprTuple22, 23
20Literal
21ExprTuple24, 25
22Operationoperator: 26
operand: 29
23Operationoperator: 27
operand: 29
24Literal
25Variable
26Literal
27Literal
28ExprTuple29
29IndexedVarvariable: 30
index: 32
30Variable
31ExprTuple32
32Variable