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, Lambda, i, n
from proveit.core_expr_types import a_1_to_n, a_i, b_1_to_n, b_i, v_1_to_n, v_i
from proveit.linear_algebra import Hspace, OrthoNormBases, ScalarMult, VecSum
from proveit.logic import And, Equals, Exists, InSet, Set
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([v_1_to_n], Conditional(Exists(instance_param_or_params = [a_1_to_n, b_1_to_n], instance_expr = And(Equals(A, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(a_i, sub_expr3), domain = sub_expr2)), Equals(B, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(b_i, sub_expr3), domain = sub_expr2))).with_wrapping_at(2), domain = Complex).with_wrapping(), InSet(Set(v_1_to_n), OrthoNormBases(Hspace))))
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}\right) \mapsto \left\{\begin{array}{l}\exists_{a_{1}, a_{2}, \ldots, a_{n}, b_{1}, b_{2}, \ldots, b_{n} \in \mathbb{C}}~\\
\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}\right)\end{array} \textrm{ if } \left\{v_{1}, v_{2}, \ldots, v_{n}\right\} \in \textrm{O.N.Bases}\left(\mathcal{H}\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: 13
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 64
operands: 6
4Literal
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameters: 10
body: 11
8Operationoperator: 12
operands: 13
9Operationoperator: 14
operand: 21
10ExprTuple16, 17
11Conditionalvalue: 18
condition: 19
12Literal
13ExprTuple20
14Literal
15ExprTuple21
16ExprRangelambda_map: 22
start_index: 78
end_index: 79
17ExprRangelambda_map: 23
start_index: 78
end_index: 79
18Operationoperator: 25
operands: 24
19Operationoperator: 25
operands: 26
20ExprRangelambda_map: 27
start_index: 78
end_index: 79
21Variable
22Lambdaparameter: 60
body: 51
23Lambdaparameter: 60
body: 52
24ExprTuple28, 29
25Literal
26ExprTuple30, 31
27Lambdaparameter: 60
body: 32
28Operationoperator: 34
operands: 33
29Operationoperator: 34
operands: 35
30ExprRangelambda_map: 36
start_index: 78
end_index: 79
31ExprRangelambda_map: 37
start_index: 78
end_index: 79
32IndexedVarvariable: 84
index: 60
33ExprTuple38, 39
34Literal
35ExprTuple40, 41
36Lambdaparameter: 60
body: 42
37Lambdaparameter: 60
body: 43
38Variable
39Operationoperator: 45
operand: 49
40Variable
41Operationoperator: 45
operand: 50
42Operationoperator: 64
operands: 47
43Operationoperator: 64
operands: 48
44ExprTuple49
45Literal
46ExprTuple50
47ExprTuple51, 53
48ExprTuple52, 53
49Lambdaparameter: 86
body: 54
50Lambdaparameter: 86
body: 55
51IndexedVarvariable: 70
index: 60
52IndexedVarvariable: 71
index: 60
53Literal
54Conditionalvalue: 57
condition: 59
55Conditionalvalue: 58
condition: 59
56ExprTuple60
57Operationoperator: 62
operands: 61
58Operationoperator: 62
operands: 63
59Operationoperator: 64
operands: 65
60Variable
61ExprTuple66, 68
62Literal
63ExprTuple67, 68
64Literal
65ExprTuple86, 69
66IndexedVarvariable: 70
index: 86
67IndexedVarvariable: 71
index: 86
68Operationoperator: 72
operands: 73
69Operationoperator: 74
operands: 75
70Variable
71Variable
72Literal
73ExprTuple76, 77
74Literal
75ExprTuple78, 79
76Operationoperator: 80
operand: 83
77Operationoperator: 81
operand: 83
78Literal
79Variable
80Literal
81Literal
82ExprTuple83
83IndexedVarvariable: 84
index: 86
84Variable
85ExprTuple86
86Variable