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 A, B, Conditional, ExprRange, IndexedVar, Lambda, Variable, a, b, i, n
from proveit.core_expr_types import a_1_to_n, a_i, b_1_to_n, b_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}")
sub_expr2 = [i]
sub_expr3 = Interval(one, n)
sub_expr4 = Qmult(Ket(v_i), Bra(v_i))
expr = Lambda([a_1_to_n, b_1_to_n], Conditional(And(Equals(A, VecSum(index_or_indices = sub_expr2, summand = ScalarMult(a_i, sub_expr4), domain = sub_expr3)), Equals(B, VecSum(index_or_indices = sub_expr2, summand = ScalarMult(b_i, sub_expr4), domain = sub_expr3))).with_wrapping_at(2), And(ExprRange(sub_expr1, InSet(IndexedVar(a, sub_expr1), Complex), one, n), ExprRange(sub_expr1, InSet(IndexedVar(b, 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}, b_{1}, b_{2}, \ldots, b_{n}\right) \mapsto \left\{\begin{array}{c} \left(A = \left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right) \land  \\ \left(B = \left(\sum_{i=1}^{n} \left(b_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right) \end{array} \textrm{ if } \left(a_{1} \in \mathbb{C}\right) ,  \left(a_{2} \in \mathbb{C}\right) ,  \ldots ,  \left(a_{n} \in \mathbb{C}\right), \left(b_{1} \in \mathbb{C}\right) ,  \left(b_{2} \in \mathbb{C}\right) ,  \ldots ,  \left(b_{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, 4
2Conditionalvalue: 5
condition: 6
3ExprRangelambda_map: 7
start_index: 61
end_index: 62
4ExprRangelambda_map: 8
start_index: 61
end_index: 62
5Operationoperator: 10
operands: 9
6Operationoperator: 10
operands: 11
7Lambdaparameter: 43
body: 34
8Lambdaparameter: 43
body: 35
9ExprTuple12, 13
10Literal
11ExprTuple14, 15
12Operationoperator: 17
operands: 16
13Operationoperator: 17
operands: 18
14ExprRangelambda_map: 19
start_index: 61
end_index: 62
15ExprRangelambda_map: 20
start_index: 61
end_index: 62
16ExprTuple21, 22
17Literal
18ExprTuple23, 24
19Lambdaparameter: 43
body: 25
20Lambdaparameter: 43
body: 26
21Variable
22Operationoperator: 28
operand: 32
23Variable
24Operationoperator: 28
operand: 33
25Operationoperator: 47
operands: 30
26Operationoperator: 47
operands: 31
27ExprTuple32
28Literal
29ExprTuple33
30ExprTuple34, 36
31ExprTuple35, 36
32Lambdaparameter: 69
body: 37
33Lambdaparameter: 69
body: 38
34IndexedVarvariable: 53
index: 43
35IndexedVarvariable: 54
index: 43
36Literal
37Conditionalvalue: 40
condition: 42
38Conditionalvalue: 41
condition: 42
39ExprTuple43
40Operationoperator: 45
operands: 44
41Operationoperator: 45
operands: 46
42Operationoperator: 47
operands: 48
43Variable
44ExprTuple49, 51
45Literal
46ExprTuple50, 51
47Literal
48ExprTuple69, 52
49IndexedVarvariable: 53
index: 69
50IndexedVarvariable: 54
index: 69
51Operationoperator: 55
operands: 56
52Operationoperator: 57
operands: 58
53Variable
54Variable
55Literal
56ExprTuple59, 60
57Literal
58ExprTuple61, 62
59Operationoperator: 63
operand: 66
60Operationoperator: 64
operand: 66
61Literal
62Variable
63Literal
64Literal
65ExprTuple66
66IndexedVarvariable: 67
index: 69
67Variable
68ExprTuple69
69Variable