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, ExprRange, 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 = 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(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..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple3
2Conditionalvalue: 4
condition: 5
3ExprRangelambda_map: 6
start_index: 41
end_index: 42
4Operationoperator: 7
operands: 8
5Operationoperator: 9
operands: 10
6Lambdaparameter: 33
body: 23
7Literal
8ExprTuple11, 12
9Literal
10ExprTuple13
11Variable
12Operationoperator: 14
operand: 17
13ExprRangelambda_map: 16
start_index: 41
end_index: 42
14Literal
15ExprTuple17
16Lambdaparameter: 33
body: 18
17Lambdaparameter: 49
body: 19
18Operationoperator: 27
operands: 20
19Conditionalvalue: 21
condition: 22
20ExprTuple23, 24
21Operationoperator: 25
operands: 26
22Operationoperator: 27
operands: 28
23IndexedVarvariable: 34
index: 33
24Literal
25Literal
26ExprTuple30, 31
27Literal
28ExprTuple49, 32
29ExprTuple33
30IndexedVarvariable: 34
index: 49
31Operationoperator: 35
operands: 36
32Operationoperator: 37
operands: 38
33Variable
34Variable
35Literal
36ExprTuple39, 40
37Literal
38ExprTuple41, 42
39Operationoperator: 43
operand: 46
40Operationoperator: 44
operand: 46
41Literal
42Variable
43Literal
44Literal
45ExprTuple46
46IndexedVarvariable: 47
index: 49
47Variable
48ExprTuple49
49Variable