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, Lambda, U, i, n
from proveit.core_expr_types import v_1_to_n, v_i, w_1_to_n, w_i
from proveit.linear_algebra import OrthoNormBases, VecSum
from proveit.logic import And, CartExp, Equals, InSet, Set
from proveit.numbers import Complex, Interval, one
from proveit.physics.quantum import Bra, Ket, Qmult
from proveit.physics.quantum.algebra import v_1_to_n_kets, w_1_to_n_kets
In [2]:
# build up the expression from sub-expressions
sub_expr1 = OrthoNormBases(CartExp(Complex, n))
expr = Lambda([v_1_to_n, w_1_to_n], Conditional(Equals(U, VecSum(index_or_indices = [i], summand = Qmult(Ket(v_i), Bra(w_i)), domain = Interval(one, n))), And(InSet(Set(v_1_to_n_kets), sub_expr1), InSet(Set(w_1_to_n_kets), sub_expr1))))
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(v_{1}, v_{2}, \ldots, v_{n}, w_{1}, w_{2}, \ldots, w_{n}\right) \mapsto \left\{U = \left(\sum_{i=1}^{n} \left(\lvert v_{i} \rangle \thinspace \langle w_{i} \rvert\right)\right) \textrm{ if } \left\{\left\{\lvert v_{1} \rangle, \lvert v_{2} \rangle, \ldots, \lvert v_{n} \rangle\right\}\right\} \in \textrm{O.N.Bases}\left(\mathbb{C}^{n}\right) ,  \left\{\left\{\lvert w_{1} \rangle, \lvert w_{2} \rangle, \ldots, \lvert w_{n} \rangle\right\}\right\} \in \textrm{O.N.Bases}\left(\mathbb{C}^{n}\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: 59
end_index: 60
4ExprRangelambda_map: 8
start_index: 59
end_index: 60
5Operationoperator: 9
operands: 10
6Operationoperator: 11
operands: 12
7Lambdaparameter: 73
body: 68
8Lambdaparameter: 73
body: 69
9Literal
10ExprTuple13, 14
11Literal
12ExprTuple15, 16
13Variable
14Operationoperator: 17
operand: 21
15Operationoperator: 37
operands: 19
16Operationoperator: 37
operands: 20
17Literal
18ExprTuple21
19ExprTuple22, 24
20ExprTuple23, 24
21Lambdaparameter: 67
body: 25
22Operationoperator: 40
operand: 32
23Operationoperator: 40
operand: 33
24Operationoperator: 28
operand: 34
25Conditionalvalue: 30
condition: 31
26ExprTuple32
27ExprTuple33
28Literal
29ExprTuple34
30Operationoperator: 35
operands: 36
31Operationoperator: 37
operands: 38
32Operationoperator: 40
operands: 39
33Operationoperator: 40
operands: 41
34Operationoperator: 42
operands: 43
35Literal
36ExprTuple44, 45
37Literal
38ExprTuple67, 46
39ExprTuple47
40Literal
41ExprTuple48
42Literal
43ExprTuple49, 60
44Operationoperator: 65
operand: 57
45Operationoperator: 51
operand: 58
46Operationoperator: 53
operands: 54
47ExprRangelambda_map: 55
start_index: 59
end_index: 60
48ExprRangelambda_map: 56
start_index: 59
end_index: 60
49Literal
50ExprTuple57
51Literal
52ExprTuple58
53Literal
54ExprTuple59, 60
55Lambdaparameter: 73
body: 61
56Lambdaparameter: 73
body: 62
57IndexedVarvariable: 70
index: 67
58IndexedVarvariable: 71
index: 67
59Literal
60Variable
61Operationoperator: 65
operand: 68
62Operationoperator: 65
operand: 69
63ExprTuple67
64ExprTuple68
65Literal
66ExprTuple69
67Variable
68IndexedVarvariable: 70
index: 73
69IndexedVarvariable: 71
index: 73
70Variable
71Variable
72ExprTuple73
73Variable