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, M, i, n
from proveit.core_expr_types import a_1_to_n, a_i, v_1_to_n, v_i
from proveit.linear_algebra import Hspace, OrthoNormBases, ScalarMult, VecSum
from proveit.logic import Equals, Exists, 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
In [2]:
# build up the expression from sub-expressions
expr = Lambda([v_1_to_n], Conditional(Exists(instance_param_or_params = [a_1_to_n], instance_expr = Equals(M, VecSum(index_or_indices = [i], summand = ScalarMult(a_i, Qmult(Ket(v_i), Bra(v_i))), domain = Interval(one, n))), domain = Complex).with_wrapping(), InSet(Set(v_1_to_n_kets), 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} \in \mathbb{C}}~\\
\left(M = \left(\sum_{i=1}^{n} \left(a_{i} \cdot \left(\lvert v_{i} \rangle \thinspace \langle v_{i} \rvert\right)\right)\right)\right)\end{array} \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(\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: 1
body: 2
1ExprTuple3
2Conditionalvalue: 4
condition: 5
3ExprRangelambda_map: 6
start_index: 65
end_index: 66
4Operationoperator: 7
operand: 10
5Operationoperator: 51
operands: 9
6Lambdaparameter: 57
body: 48
7Literal
8ExprTuple10
9ExprTuple11, 12
10Lambdaparameters: 13
body: 14
11Operationoperator: 28
operand: 21
12Operationoperator: 16
operand: 22
13ExprTuple18
14Conditionalvalue: 19
condition: 20
15ExprTuple21
16Literal
17ExprTuple22
18ExprRangelambda_map: 23
start_index: 65
end_index: 66
19Operationoperator: 24
operands: 25
20Operationoperator: 26
operands: 27
21Operationoperator: 28
operands: 29
22Variable
23Lambdaparameter: 57
body: 46
24Literal
25ExprTuple30, 31
26Literal
27ExprTuple32
28Literal
29ExprTuple33
30Variable
31Operationoperator: 34
operand: 38
32ExprRangelambda_map: 36
start_index: 65
end_index: 66
33ExprRangelambda_map: 37
start_index: 65
end_index: 66
34Literal
35ExprTuple38
36Lambdaparameter: 57
body: 39
37Lambdaparameter: 57
body: 40
38Lambdaparameter: 73
body: 41
39Operationoperator: 51
operands: 42
40Operationoperator: 67
operand: 48
41Conditionalvalue: 44
condition: 45
42ExprTuple46, 47
43ExprTuple48
44Operationoperator: 49
operands: 50
45Operationoperator: 51
operands: 52
46IndexedVarvariable: 58
index: 57
47Literal
48IndexedVarvariable: 71
index: 57
49Literal
50ExprTuple54, 55
51Literal
52ExprTuple73, 56
53ExprTuple57
54IndexedVarvariable: 58
index: 73
55Operationoperator: 59
operands: 60
56Operationoperator: 61
operands: 62
57Variable
58Variable
59Literal
60ExprTuple63, 64
61Literal
62ExprTuple65, 66
63Operationoperator: 67
operand: 70
64Operationoperator: 68
operand: 70
65Literal
66Variable
67Literal
68Literal
69ExprTuple70
70IndexedVarvariable: 71
index: 73
71Variable
72ExprTuple73
73Variable