logo

Expression of type Lambda

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, 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 = 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())
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..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 32
body: 2
1ExprTuple32
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 30
operands: 7
5Literal
6ExprTuple8, 9
7ExprTuple32, 10
8Operationoperator: 32
operand: 15
9Operationoperator: 18
operand: 16
10Operationoperator: 13
operands: 14
11ExprTuple15
12ExprTuple16
13Literal
14ExprTuple17, 17
15Operationoperator: 18
operand: 21
16Lambdaparameter: 52
body: 20
17Literal
18Literal
19ExprTuple21
20Conditionalvalue: 22
condition: 26
21Lambdaparameter: 52
body: 23
22Operationoperator: 28
operands: 24
23Conditionalvalue: 25
condition: 26
24ExprTuple27, 34
25Operationoperator: 28
operands: 29
26Operationoperator: 30
operands: 31
27Operationoperator: 32
operand: 36
28Literal
29ExprTuple36, 34
30Literal
31ExprTuple52, 35
32Variable
33ExprTuple36
34Operationoperator: 37
operands: 38
35Operationoperator: 39
operands: 40
36IndexedVarvariable: 41
index: 52
37Literal
38ExprTuple42, 43
39Literal
40ExprTuple44, 45
41Variable
42Operationoperator: 46
operand: 49
43Operationoperator: 47
operand: 49
44Literal
45Variable
46Literal
47Literal
48ExprTuple49
49IndexedVarvariable: 50
index: 52
50Variable
51ExprTuple52
52Variable